
<?php
require("config/koneksi.php");
require("config/function.php");
require("config/crud.php");
$tanggal = date('Y-m-d');
 $tglabsen = date('d M Y H:i:s');  
  $target_dir = "photo/"; 
  $date   = new DateTime(); 
  $date_string = $date->format('Y-m-d_His');
  $target_file = $target_dir . $date_string. basename($_FILES["imageFile"]["name"]);
  $uploadOk = 1;
  $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
  $file_name = pathinfo($target_file,PATHINFO_BASENAME) ; 
   $link = $setting['web']."photo/".$file_name;
 
    $absen = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM absensi WHERE tanggal='$tanggal' ORDER BY id DESC LIMIT 1"));
	$data = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_siswa='$absen[idsiswa]'"));
	$nowa = $data['nowa'];
	
	
	
  if(isset($_POST["imageFile"])) {	
    $check = getimagesize($_FILES["imageFile"]["tmp_name"]);
      if($check !== false) {
      echo "File is an image - " . $check["mime"] . ".";
      $uploadOk = 1;
      } else {
      echo "File is not an image.";
      $uploadOk = 0;
      }
  }

  
  if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
  }

 
  if ($_FILES["imageFile"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
  }

  
  if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
  }

  if ($uploadOk == 0) {
   
  } else {
    if (move_uploaded_file($_FILES["imageFile"]["tmp_name"], $target_file)) {
		   
			mysqli_query($koneksi, "update absensi set foto='$file_name',link='$link' where id='$absen[id]'");
		     $abs = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM absensi WHERE tanggal='$tanggal' ORDER BY id DESC LIMIT 1"));
		    $status = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM status"));	
			if($status['mode']=='1'):
			$curl = curl_init();
			 curl_setopt_array($curl, array(
			  CURLOPT_URL => $setting['url_api'].'/send-message',
			  CURLOPT_RETURNTRANSFER => true,
			  CURLOPT_ENCODING => '',
			  CURLOPT_MAXREDIRS => 10,
			  CURLOPT_TIMEOUT => 0,
			  CURLOPT_FOLLOWLOCATION => true,
			  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
			  CURLOPT_CUSTOMREQUEST => 'POST',
			  CURLOPT_POSTFIELDS => array('message' =>"Assalamualaikum wr.wb\n\n". $masuk['info1']." *".$data['nama']."* ".$masuk['info2']." ".$tglabsen." ".$masuk['info3']." Untuk melihat foto klik link berikut ".$abs['link'],'number' => $nowa)
			));
			curl_exec($curl);
			curl_close($curl);
		   else:
				$curl = curl_init();
				curl_setopt_array($curl, array(
			  CURLOPT_URL => $setting['url_api'].'/send-message',
			  CURLOPT_RETURNTRANSFER => true,
			  CURLOPT_ENCODING => '',
			  CURLOPT_MAXREDIRS => 10,
			  CURLOPT_TIMEOUT => 0,
			  CURLOPT_FOLLOWLOCATION => true,
			  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
			  CURLOPT_CUSTOMREQUEST => 'POST',
			  CURLOPT_POSTFIELDS => array('message' =>"Assalamualaikum wr.wb\n\n". $pulang['info1']." *".$data['nama']."* ".$pulang['info2']." ".$tglabsen." ".$pulang['info3']." Untuk melihat foto klik link berikut ".$abs['link'],'number' => $nowa)
			));
			curl_exec($curl);
			curl_close($curl);	
		   endif;
    } else {
     
    }
  }
?>
		