<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="w3.css">

<title>Absences</title>
</head>

<body bgcolor="#B5F5FD">
<form method='post' action='continuerdeactivatef.php' >
<?php
include("_serveur.php");
include 'header.php';
$classeid=$_SESSION['classeid'];
$classe1=$_SESSION['classe1'];
$date1=$_SESSION['date1'];
echo '<div class="w3-padding-32 w3-green w3-circle">
  <div class="w3-padding-32 w3-red w3-circle w3-center" style="width:55%">
    <p class="w3-xlarge">'.$classe1.'&ensp;'.$date1.'</p>
  </div>
</div>';
$sql = 'SELECT * FROM students  JOIN users on  users.id= students.userID where classID="'.$classeid.'" Order by students.firstName, students.lastName,users.firstName ASC';

   if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
$req=  mysqli_query($link, $sql);
$i=1;
$z=1; 
echo "<table width='95%' border=1 bordercolor='#D1FAFC'>"; 
while ($data = mysqli_fetch_array($req)) {
   
if($z==1) echo "<tr>";
?>

        <td width="50%"><input type='checkbox' name='plat[]' value='<?php echo $i.";". $data['0'].";". $data['1'].";".$data['2'].";".$data['3'].";".$data['10'] ?>' >
         <?php echo $i.' '.$data['2'].' '.$data['7'].' '.$data['3'] ?>

      </td>
  <?php
     $z=$z+1;    
     if($z==3) {echo "</tr>";$z=1;}
	  $i=$i+1;
	    }
 
	   ?>  
</table>
 
   
  <input type="reset"  bgcolor="#ffccff" class="style7" value="Effacer" />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input name="envoyer" bgcolor="#ffccff" type="submit" class="style7" value="Envoyer" />
</p>
</fieldset>
</form>
<?php
$j=0;
$k=1;
$l=2;
$m=3;
$n=4;
$o=5;
$jt=0;
	//echo $plat;
if (isset ($_POST['envoyer'])){

    $plat=implode(';',$_POST['plat']);
	$plat1=array();
		$plat1=explode(";",$plat);

	while($jt<=sizeof($plat1)){
	$numero[$jt]=$plat1[$j];
	$studentid[$jt]=$plat1[$k];
	$userID[$jt]=$plat1[$l];
	$prenom[$jt]=$plat1[$m];
    $family[$jt]=$plat1[$n];
    $userType[$jt]=$plat1[$o];

	$message[$jt]=$prenom[$jt].' '.$family[$jt].' en classe ' .$classe1.' EST DESACTIVE(E) DE L\'APPLICATION';
		$j=$j+6;$k=$k+6;$l=$l+6;$m=$m+6;$n=$n+6;$o=$o+6;
		 $jt=$jt+1;
	
}
	
for($p=0;$p<=$jt;$p++){
$sql1 = 'UPDATE users SET active=0 where id= "'.$userID[$p].'"';
 if(!(mysqli_query($link, $sql1))){
    echo "ERROR: Could not able to execute $sql1. " . mysqli_error($link);
        }

                                    
}
	
include("sjmSendPush.php");
for($p=0;$p<=$jt;$p++){
	if($prenom[$p]<>""){
$sql = 'SELECT * from devices where userID="'.$userID[$p].'" or userID=230100 or userID=10055 or userID=232024 or userID=10001';
   if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                          }
$req=  mysqli_query($link, $sql);

echo "<table width='95%' border=1 bordercolor='#D1FAFC'>"; 
while ($data = mysqli_fetch_array($req)) {
	                 $deviceType=$data[2];
					 $pushid=$data[0];
					 $pushid=(string)$pushid;
					 echo $deviceType;
                     if($deviceType=="ios") $deviceType="iOS";
					 $title="Désactivé(e)";
					 $dataa=array();
					 $dataa=array("title" => $title, "body" => $message[$p]);
					 $regid=array();
					 $regid=array($pushid);
					// $payload = array('type' =>$deviceType,'data'=>array("title" => $title, "body" => $message[$p]),'devices' =>$pushid);
					$payload = array('type' =>$deviceType,
					           'data'=>["title" => $title, "body" => $message[$p]],
							   'devices' =>[$pushid]);
					 
                     echo sendPush(json_encode($payload));

					   
                          }
					
           }
}
		echo "Désactivation Faite!!! ";

}
	 

 
	

	
//On se connecte
//On prépare la commande sql d'insertion

?>


</body>
</html>