<!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">
<title>Remplir coefficient</title>
<link rel="stylesheet" href="w3.css">
<!--<script src="https://sscc-bikfaya.com/Mob_app/tinymce/js/tinymce/tinymce.min.js" referrerpolicy="origin"></script> 
  
<script>tinymce.init({selector:'textarea'});</script> -->
</head>
<style>
body {width:100%;}
</style>
<body>

<div class="w3-card-4">
<form method="post" action="_ecriresubsujects.php" >

<?php
include 'header.php';
$classeid=$subjectId=0;
$coef=$ordre=0;
$classeErr=$subSubjectErr=$coefErr=$ordreErr="";
//include("_serveur.php");
//include("_serveur.php");
include '_serveur.php';?>
<?php

$sql = 'SELECT * from subjects JOIN subSubjects on subjects.id=subSubjects.subjectID';
   if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
$req=  mysqli_query($link, $sql);
echo '</p><label class="w3-text-teal">Matière:</label>';
echo '<div class="w3-panel w3-round-xxlarge w3-blue">
    <p>';
	$i=0;
	$j=0;
 while($data = mysqli_fetch_array($req)) {
$subjectID=$data[0];	
$subject[$j]=$data[1]; 
$matiere=$data[5];
$subSubjectID=$data[3];
if($subject[$j]<>$subject[$j-1]) echo "<br><br>";
 echo $subject[$j].' - ' .$matiere.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
 $i++;
 if($i==3) {echo "<br>";$i=0;}
 $j++;
        };

echo '</p></div>';
$sql = 'SELECT * from subjects  order by ordering ASC';
   if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
$req=  mysqli_query($link, $sql);
echo '<p><label class="w3-text-teal" >Matières:</label>';
//echo'<select name="cla" class="w3-select 3-border w3-light-grey">';

 while($data = mysqli_fetch_array($req)) {
$id=$data['id'];
$matiere=$data['name'];
$ordering=$data['ordering'];

// echo' <option value="'.$classeid.'">'.$classe.'</option>';
echo ' <input class="w3-check" type="checkbox" name="cla[]"  value="'.$id.'">
  <label>'.$matiere.'</label>';
        };

//echo '</select>';

echo '<label class="w3-text-teal">Sous-Matière:</label> 
<input class="w3-input w3-border w3-light-grey" type="text" name="subsubject" />';

                 
 echo'  <input name="envoyer" type="submit" class="style19" value="Envoyer" bgcolor="#CC99FF" /></form></div>';
               
if (isset ($_POST['envoyer'])){
	$cla1=array();
$cla1=$_POST['cla'];
$subSubject=$_POST['subsubject'];

$j=0;
while($j<sizeof($cla1))
{

	$sql="select * from subSubjects where name='".$subSubject."' and subjectID='".$cla1[$j]."'";
	if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                                 }
$req=mysqli_query($link, $sql);
  while($data = mysqli_fetch_array($req)){
                  $souma=$data['name'];
                                         }
if($souma==""){
	$sql = 'INSERT INTO subSubjects VALUES(DEFAULT,"'.$cla1[$j].'","'.$subSubject.'")';
 if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                              }
	echo $subSubject." Sous-Matière Remplis avec succès!!";


              }
			  else
			  {
				  	echo $subSubject." Sous-Matière exist!!";

			  }
			  $j++;
}

}
//On se connecte
// on ferme la connexion

?>



</body>
</html>