<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

include("./access.php");

if(isset($_GET['cle']) && ($_GET['cle']!='')){
 $qda = "SELECT * FROM planning WHERE cle='".$_GET['cle']."' LIMIT 1";
$resultat = mysqli_query($connect,$qda);
list($cle,$jour,$heure,$heurefin,$lieu,$theme,$intervenant,$titre,$description,$valid,$onoff,$type,$referent,$secretaire,$rapporteur,$online) = mysqli_fetch_array($resultat);
}

if($_GET['type']!='') $lasuite = " AND type='".$_GET['type']."' ";
elseif($_GET['theme']!='') $lasuite = " AND theme='".$_GET['theme']."' ";
elseif($_GET['lieu']!='') $lasuite = " AND lieu='".$_GET['lieu']."' ";
elseif($_GET['intervenant']!='') $lasuite = " AND intervenant='".$_GET['intervenant']."' ";
elseif($_GET['secretaire']!='') $lasuite = " AND secretaire='".$_GET['secretaire']."' ";
elseif($_GET['rapporteur']!='') $lasuite = " AND rapporteur='".$_GET['rapporteur']."' ";
elseif($_GET['referent']!='') $lasuite = " AND referent='".$_GET['referent']."' ";
elseif($_GET['quoi']!='') $lasuite = "AND theme='".$_GET['quoi']."'";
else $lasuite = "";

$malistec = "";
foreach($tablojourmax as $lejour=>$lemax){

  $malistec .= "<tr><td colspan='4' style='background:#090;color:#fff;height:80%;line-height:80%;border-bottom:solid 1px #444;border-top:solid 1px #666;width:100%;font-variant:small-caps'>".$lemax."</td></tr>";

     $qd = "SELECT * FROM planning WHERE jour='".$lejour."' ".$lasuite." ORDER BY jour, CAST(heure AS UNSIGNED)";
    $resultd = mysqli_query($connect,$qd);
    while($row = mysqli_fetch_array($resultd))
    {
      if($row['valid']!='0') $color='#def';
      else $color='#fff';
      if($row['online']!='0') $bull="font-size:1em;color:#c00;";
      else $bull="";
      $malistec .= "<tr>
      <td style='width:15%'><a name='".$row['cle']."'></a>".$row['heure']." &agrave; ".$row['heurefin']." <i style='color:#0c0'>".$lejour."</i></td>
      <td style='width:30%;".$bull."'> <a href='index.php?intervenant=".$row['intervenant']."' class='staff'>".$tablointervenant[$row['intervenant']]['prenom']." ".$tablointervenant[$row['intervenant']]['nom']."</a></td>
      <td style='width:30%'><b><a href='index.php?theme=".$row['theme']."' class='staff'>".$tablotheme[$row['theme']]."</a></b></td>
      <td style='width:25%;text-align:right;'>";
      if($row['lieu'] != 0) $malistec .= "<a href='index.php?lieu=".$row['lieu']."' class='staff'>".$tablolieux[$row['lieu']]."</a>";
      $malistec .= "</td>
      </tr>
      <tr>
      <td colspan='3' style='background:".$color.";width:75%'><b>".$row['titre']."</b> ".substr($row['description'],0,50)." <span id='a".$row['cle']."' class='nonblock'>".substr($row['description'],50)."</span> <a href='javascript:;' onclick='tagel(`".$row['cle']."`);'><i style='font-size:.85em' id='b".$row['cle']."'>plus</i></a></td>
      <td style='background:".$color.";width:25%;text-align:right;'><a href='index.php?cle=".$row['cle']."#".$row['cle']."'>Modifier</a></td>
      </tr>
      <tr style='border-bottom:solid 1px #444;background:#fff;text-align:right'>
      <td style='width:15%'><a href='index.php?referent=".$row['referent']."' class='staff'>".$tabloreferent[$row['referent']]['nom']."</a></td>
      <td style='width:30%'><a href='index.php?secretaire=".$row['secretaire']."' class='staff'>".$tablosecretaire[$row['secretaire']]."</a></td>
      <td style='width:30%'><a href='index.php?rapporteur=".$row['rapporteur']."' class='staff'>".$tablorapporteur[$row['rapporteur']]."</a></td>
      <td style='width:25%'><a href='index.php?type=".$row['type']."' class='staff'><i>".$tablotypeinsc[$row['type']]."</i></a></td>
      </tr>";
    }
}

?>
<!doctype html>
<head>
<title>Back Office TDC 2019</title>
<link rel="stylesheet" media="all" href="css.css" />
<script>
function tagel(div) {
  var element = document.getElementById("a"+div);
  var lebout = document.getElementById("b"+div);
if(element.className == "nonblock"){
   element.classList.remove("nonblock");
   element.classList.add("disblock");
   lebout.innerHTML = "moins";
}
else{
   element.classList.remove("disblock");
   element.classList.add("nonblock");
   lebout.innerHTML = "plus";
}
}
function duplik(){
  var cle = document.getElementById("cle");
  cle.value = '';
  document.formfiche.submit();
}
function redim(){var e=document.documentElement.clientHeight-130;document.getElementById("content").style.height=e+"px"}

</script>
</head>
<body>
<br/>
<?php include("nav.php"); ?>

<div>


<div style='float:left;width:20%;min-width:240px;'>
<div style='padding:1em .5em;'>
<div class='lebloc divscrol'>
<h5>LIEU</h5>
<form action='add_lieu.php' method='post'>
<br/>
<?php if(isset($_GET['lieu']) && ($_GET['lieu']!='')) echo "<input type='hidden' name='cle' value='".$_GET['lieu']."'/>"; ?>
Nom du lieu<br/>
<input type='text' name='nom' value="<?php if(isset($_GET['lieu']) && ($_GET['lieu']!='')) echo $tablolieux[$_GET['lieu']]; ?>" placeholder="obligatoire" required/>
<br/>
<?php
if(isset($_GET['lieu']) && ($_GET['lieu']!='')) echo "<input type='submit' value=' MODIFIER ce lieu ' style='background:#fed'/>";
else echo "<input type='submit' value=' ENREGISTRER ' />";
?>
<ul>
<?php
foreach($tablolieux as $cle=>$val){
      echo " &bull; <a href='index.php?lieu=".$cle."'>".$val."</a><br/>";
    }
?>
</ul></form></div>

<br/>
<div class='lebloc'>
<h5>R&Eacute;F&Eacute;RENT</h5>
<form action='add_referent.php' method='post'>
<br/>
<?php if(isset($_GET['referent']) && ($_GET['referent']!='')) echo "<input type='hidden' name='cle' value='".$_GET['referent']."'/>"; ?>
Nom du r&eacute;f&eacute;rent<br/>
<input type='text' name='nom' value="<?php if(isset($_GET['referent']) && ($_GET['referent']!='')) echo $tabloreferent[$_GET['referent']]['nom']; ?>" placeholder="obligatoire" required/>
<br/>
T&eacute;l&eacute;phone<br/>
<input type='text' name='mobile' value="<?php if(isset($_GET['referent']) && ($_GET['referent']!='')) echo $tabloreferent[$_GET['referent']]['mobile']; ?>" />
<br/>
<?php
if(isset($_GET['referent']) && ($_GET['referent']!='')) echo "<input type='submit' value=' MODIFIER ce r&eacute;f&eacute;rent ' style='background:#fed' />";
else echo "<input type='submit' value=' ENREGISTRER ' />";
?>

<ul>
<?php
foreach($tabloreferent as $cle=>$val){
      echo "<li><a href='index.php?referent=".$cle."'>".$val['nom']."</a> &bull; </li>";
    }
?>
</ul>
</form>
</div>

<br/>

<div class='lebloc'>
<h5>SECR&Eacute;TAIRE</h5>
<form action='add_secretaire.php' method='post'>
<br/>
<?php if(isset($_GET['secretaire']) && ($_GET['secretaire']!='')) echo "<input type='hidden' name='cle' value='".$_GET['secretaire']."'/>"; ?>
Nom du secr&eacute;taire<br/>
<input type='text' name='nom' value="<?php if(isset($_GET['secretaire']) && ($_GET['secretaire']!='')) echo $tablosecretaire[$_GET['secretaire']]; ?>" placeholder="obligatoire" required/>
<br/>
<?php
if(isset($_GET['secretaire']) && ($_GET['secretaire']!='')) echo "<input type='submit' value=' MODIFIER ce secr&eacute;taire ' style='background:#fed' />";
else echo "<input type='submit' value=' ENREGISTRER ' />";
?>

<ul>
<?php
foreach($tablosecretaire as $cle=>$val){
      echo "<li><a href='index.php?secretaire=".$cle."'>".$val."</a> &bull; </li>";
    }
?>
</ul>
</form></div>


<br/>
<div class='lebloc'>

<h5>RAPPORTEUR</h5>
<form action='add_rapporteur.php' method='post'>
<br/>
<?php if(isset($_GET['rapporteur']) && ($_GET['rapporteur']!='')) echo "<input type='hidden' name='cle' value='".$_GET['rapporteur']."'/>"; ?>
Nom du rapporteur<br/>
<input type='text' name='nom' value="<?php if(isset($_GET['rapporteur']) && ($_GET['rapporteur']!='')) echo $tablorapporteur[$_GET['rapporteur']]; ?>" placeholder="obligatoire" required/>
<br/>
<?php
if(isset($_GET['rapporteur']) && ($_GET['rapporteur']!='')) echo "<input type='submit' value=' MODIFIER ce rapporteur ' style='background:#fed' />";
else echo "<input type='submit' value=' ENREGISTRER ' />";
?>

<ul>
<?php
foreach($tablorapporteur as $cle=>$val){
      echo "<li><a href='index.php?rapporteur=".$cle."'>".$val."</a> &bull; </li>";
    }
?>
</ul>
</form></div>

</div>
</div>



<div style='float:left;width:40%;min-width:480px;'>
<div style='padding:1em .5em;'>
<div class='lebloc' style='background:#fff'>

<h5>AGENDA EN COURS</h5>
<!-- div style='width:50%;margin:0 auto 0 auto;'>
<select name='quoi' id='quoi' onchange='if (this.value) window.location.href=this.value'>
<option value='index.php'>S&eacute;lectionner un th&egrave;me</option>
<?php foreach($tablotheme as $cle=>$val) { echo "<option value='index.php?quoi=".$cle."'>".$val."</option>"; } ?>
</select>
</div -->
<br/>
<div id='content' style='overflow-y:scroll;scrollbar-color:#060 #fff;'>
<table border='1' bordercolor='#eee' align='center' style='border-collapse:collapse;width:98%;font-size:.85em;background:#fafafa;'>
<?php
echo $malistec;
?>
</table>
<br/>
</div>
</div>
</div>
</div>








<div style='float:left;width:20%;min-width:240px;'>
<div style='padding:1em .5em;'>
<div class='lebloc divscrol' style='height:320px;'>
<h5>INTERVENANT</h5>
<form action='add_intervenant.php' method='post'>
<br/>
<?php 
if(isset($_GET['intervenant']) && ($_GET['intervenant']!='')) echo "<input type='hidden' name='cle' value='".$_GET['intervenant']."'/>"; 
?>
Nom<br/>
<input type='text' name='nom' value="<?php if(isset($_GET['intervenant']) && ($_GET['intervenant']!='')) echo $tablointervenant[$_GET['intervenant']]['nom']; ?>" placeholder="obligatoire" required/>
<br/>
Pr&eacute;nom<br/>
<input type='text' name='prenom' value="<?php if(isset($_GET['intervenant']) && ($_GET['intervenant']!='')) echo $tablointervenant[$_GET['intervenant']]['prenom']; ?>"/>
<br/>
T&eacute;l&eacute;phone<br/>
<input type='text' name='mobile' value="<?php if(isset($_GET['intervenant']) && ($_GET['intervenant']!='')) echo $tablointervenant[$_GET['intervenant']]['mobile']; ?>"/>
<br/>
Email<br/>
<input type='text' name='email' value="<?php if(isset($_GET['intervenant']) && ($_GET['intervenant']!='')) echo $tablointervenant[$_GET['intervenant']]['email']; ?>"/>
<br/>
<?php
if(isset($_GET['intervenant']) && ($_GET['intervenant']!='')) echo "<input type='submit' value=' MODIFIER cet intervenant ' style='background:#fed' />";
else echo "<input type='submit' value=' ENREGISTRER ' />";
?>
<ul>
<?php
foreach($tablointervenant as $cle=>$val){
      echo " &bull; <a href='index.php?intervenant=".$cle."'>".$val['nom']." ".$val['prenom']."</a><br/>";
    }
?>
</ul>
</form>
</div>


<br/>

<div class='lebloc divscrol'>
<h5>TH&Egrave;ME</h5>
<form action='add_theme.php' method='post'>
<br/>
<?php if(isset($_GET['theme']) && ($_GET['theme']!='')) echo "<input type='hidden' name='cle' value='".$_GET['theme']."'/>"; ?>
Titre du th&egrave;me<br/>
<input type='text' name='nom' value="<?php if(isset($_GET['theme']) && ($_GET['theme']!='')) echo $tablotheme[$_GET['theme']]; ?>" placeholder="obligatoire" required/>
<br/>
<?php
if(isset($_GET['theme']) && ($_GET['theme']!='')) echo "<input type='submit' value=' MODIFIER ce th&egrave;me ' style='background:#fed' />";
else echo "<input type='submit' value=' ENREGISTRER ' />";
?>

<ul>
<?php
foreach($tablotheme as $cle=>$val){
      echo "<li style='display:block'> &bull; <a href='index.php?theme=".$cle."'>".$val."</a></li>";
    }
?>
</ul>
</form></div>

<br/>

<div class='lebloc divscrol'>
<h5>TYPE</h5>
<form action='add_type.php' method='post'>
<br/>
<?php if(isset($_GET['type']) && ($_GET['type']!='')) echo "<input type='hidden' name='cle' value='".$_GET['type']."'/>"; ?>
Titre du type<br/>
<input type='text' name='nom' value="<?php if(isset($_GET['type']) && ($_GET['type']!='')) echo $tablotypeinsc[$_GET['type']]; ?>" placeholder="obligatoire" required/>
<br/>
<?php
if(isset($_GET['type']) && ($_GET['type']!='')) echo "<input type='submit' value=' MODIFIER ce type ' style='background:#fed' />";
else echo "<input type='submit' value=' ENREGISTRER ' />";
?>

<ul>
<?php
foreach($tablotypeinsc as $cle=>$val){
      echo "<li style='display:block'> &bull; <a href='index.php?type=".$cle."'>".$val."</a></li>";
    }
?>
</ul>
</form></div>
</div>
</div>




<div style='float:left;width:20%;min-width:240px;'>
<div style='padding:1em .5em;'>
<div class='lebloc'>
<h5>ADD/MOD UNE INTERVENTION</h5>
<form action='add_fiche.php' method='post' name='formfiche'>
<br/>
<?php if(isset($_GET['cle']) && ($_GET['cle']!='')) echo "<input type='hidden' name='cle' id='cle' value='".$_GET['cle']."'/>"; ?>
<table border='0' style='width:100%'>
<tr><td style='width:34%;padding:0px;'>
Jour
<br/>
<select name='jour'>
<?php
if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$jour."' selected>".$jour."</option>";
foreach($tablojour as $val) { echo "<option value='".$val."'>".$val."</option>"; } ?>
</select>
</td><td style='width:33%;padding:0px;'>
D&eacute;but
<br/>
<select name='heure'>
<?php 
if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$heure."' selected>".$heure."</option>";
foreach($tabloheure as $val) { echo "<option value='".$val."'>".$val."</option>"; } ?>
</select>
</td><td style='width:33%;padding:0px;'>
Fin
<br/>
<select name='heurefin'>
<?php 
if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$heurefin."' selected>".$heurefin."</option>";
foreach($tabloheure as $val) { echo "<option value='".$val."'>".$val."</option>"; } ?>
</select>
</td></tr>
</table>

<?php 
    $qd = "SELECT intervenant,datehoraire FROM datesup WHERE cle='".$_GET['cle']."' LIMIT 1";
    $resultd = mysqli_query($connect,$qd);
    list($intervenantx,$datehorairex) = mysqli_fetch_array($resultd);

if($datehorairex!='') echo "<br/>Annexe<br/><textarea name='vide'>".$datehorairex."</textarea><br/>";
?>



<br/>
Lieu
<br/>
<select name='lieu'>
<option></option>
<?php
if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$lieu."' selected>".$tablolieux[$lieu]."</option>";
foreach($tablolieux as $cle=>$val) { echo "<option value='".$cle."'>".$val."</option>"; } ?>
</select>
<br/>
Th&egrave;me
<br/>
<select name='theme'>
<option></option>
<?php
if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$theme."' selected>".$tablotheme[$theme]."</option>";
foreach($tablotheme as $cle=>$val) { echo "<option value='".$cle."'>".$val."</option>"; } ?>
</select>
<br/>
Intervenant
<br/>
<select name='intervenant'>
<option></option>
<?php
if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$intervenant."' selected>".$tablointervenant[$intervenant]['prenom']." ".$tablointervenant[$intervenant]['nom']."</option>";
foreach($tablointervenant as $cle=>$val) { echo "<option value='".$cle."'>".$val['prenom']." ".$val['nom']."</option>"; } ?>
</select>
<br/>
R&eacute;f&eacute;rent
<br/>
<select name='referent'>
<option></option>
<?php
if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$referent."' selected>".$tabloreferent[$referent]['nom']."</option>";
foreach($tabloreferent as $cle=>$val) { echo "<option value='".$cle."'>".$val['nom']."</option>"; } ?>
</select>

<br/>
Secr&eacute;taire
<br/>
<select name='secretaire'>
<option></option>
<?php
if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$secretaire."' selected>".$tablosecretaire[$secretaire]."</option>";
foreach($tablosecretaire as $cle=>$val) { echo "<option value='".$cle."'>".$val."</option>"; } ?>
</select>
<br/>
Rapporteur
<br/>
<select name='rapporteur'>
<option></option>
<?php
if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$rapporteur."' selected>".$tablorapporteur[$rapporteur]."</option>";
foreach($tablorapporteur as $cle=>$val) { echo "<option value='".$cle."'>".$val."</option>"; } ?>
</select>
<br/>

<br/>
Titre
<br/>
<textarea name='titre' required rows='1'><?php if(isset($_GET['cle']) && ($_GET['cle']!=''))echo $titre; ?></textarea>
<br/>
Description
<br/>
<textarea name='description' rows='4'><?php if(isset($_GET['cle']) && ($_GET['cle']!='')) echo stripslashes($description); ?></textarea>
<br/>
<br/>
Type d'intervention
<br/>
<select name='type'>
<option></option>
<?php if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$type."' selected>".$tablotypeinsc[$type]."</option>";
foreach($tablotypeinsc as $cle=>$val) { echo "<option value='".$cle."'>".$val."</option>"; } ?>
</select>
<br/>

Validit&eacute;
<br/>
<select name='valid'>
<option></option>
<?php if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$valid."' selected>".$tablovalid[$valid]."</option>";
foreach($tablovalid as $cle=>$val) { echo "<option value='".$cle."'>".$val."</option>"; } ?>
</select>
<br/>
Public / Priv&eacute;
<br/>
<select name='onoff'>
<option></option>
<?php if(isset($_GET['cle']) && ($_GET['cle']!=''))echo "<option value='".$onoff."' selected>".$tabloonoff[$onoff]."</option>"; 
foreach($tabloonoff as $cle=>$val) { echo "<option value='".$cle."'>".$val."</option>"; } ?>
</select>

<br/><br/>
<?php
if(isset($_GET['cle']) && ($_GET['cle']!='')) echo "<input type='submit' value=' MODIFIER ' style='background:#fed' /><br/><br/><input type='button' value=' DUPLIQUER ' style='background:#efd' onclick='duplik();'/></form><br/><form action='del_fiche.php' method='post' name='formsup'><input type='hidden' name='cle' value='".$_GET['cle']."'><input type='submit' value=' SUPPRIMER ' style='background:#def'/></form>";
else echo "<input type='submit' value=' ENREGISTRER ' /></form>";
?>

<br/>
</div>
</div>
</div>


<div style='clear:both;'></div>


</div>
<script>
redim();
</script>
</body>
</html>