<?php
/*
 * Liste des commandes passées sur infogreffe
 *
 */

?>
<style type="text/css">
table {width:100%; border-collapse:collapse; margin:5px 0;}
table tr.odd {background-color:#e6eeee;}
table tr.even {}
table tr.un {
	border-top:2px solid;
}
table tr.deux {
	vertical-align:top;
	border-bottom:2px solid;
}
table th, table td {border:1px dashed; padding:5px;}
select {font-size:11px;}
</style>
<div id="center">
<h1>Commandes INFOGREFFE<?=hasModeEdition()?' - Interface de production':''?></h1>
<?php
if (!$_SESSION['connected'])
{
	echo 'Vous devez être connecté afin de pouvoir utiliser cette fonctionnalité';
}
elseif(!hasModeEdition())
{
	echo 'L\'accès à cette page est restreint';
}
//Affichage des commandes
else
{
	require_once 'infogreffe/gestion.php';

	isset($_REQUEST['num'])?
		$num = trim($_REQUEST['num']) :
		$num = '';
	isset($_REQUEST['siren'])?
		$siren = trim(preg_replace('/[^0-9]/','', $_REQUEST['siren'])) :
		$siren = '';
	$siren = str_replace(' ', '',$siren);
	$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';

	isset($_REQUEST['cmd'])?
		$cmd = $_REQUEST['cmd'] :
		$cmd = '';

	if (isset($_REQUEST['cmd_recherche'])){
		$num = strtoupper($_REQUEST['num']);
		$commandes = commandesRecherche($num, $siren, $type);
	} elseif (isset($_REQUEST['cmd_liste'])){
		$etat = isset($_REQUEST['etat']) ? $_REQUEST['etat'] : '';
		$date = isset($_REQUEST['date']) ? $_REQUEST['date'] : '';
		$typeCommande = isset($_REQUEST['typeCommande'])? $_REQUEST['typeCommande'] : '';
		$commandes = commandesListe($type, $etat, $date, $typeCommande);
	}

?>
<h2>Rechercher une commande</h2>
<div class="blockh2">

<form name="cmd_recherche" method="post" action="./?page=greffescmd">
<label>Commande</label>&nbsp;
<input type="text" name="num" value="<?=$num?>"/>
 ou <label>SIREN</label>&nbsp;
<input type="text" name="siren" size="9" value="<?=$siren?>" />
<label>Type</label>
<select name="type">
<option value="greffe-bilans"<?=($type=='greffe-bilans')? ' selected':'';?>>
Comptes annuels</option>
<option value="greffe-actes"<?=($type=='greffe-actes')? ' selected':'';?>>
Actes &amp; Statuts</option>
<!--
<option value="pieces-kbis">Kbis</option>
<option value="pieces-priv">Privilèges</option>
-->
</select>
&nbsp;<input type="submit" name="cmd_recherche" value="Rechercher"/>
</form>
<br/>

<form name="cmd_liste" method="post" action="./?page=greffescmd">
<label>Lister les commandes de</label>
<select name="type">
<option value="greffe-bilans"<?=($type=='greffe-bilans')? ' selected':'';?>>
comptes annuels</option>
<option value="greffe-actes"<?=($type=='greffe-actes')? ' selected':'';?>>
actes &amp; statuts</option>
<option value="greffe-kbis"<?=($type=='greffe-kbis')? ' selected':'';?>>
Kbis</option>
<!--
<option value="pieces-priv">Privilèges</option>
-->
</select>
<?php
$cStatuts = listStatus();
?>
<select name="etat">
<option value="commande"<?=($etat=='commande')? ' selected' : '';?>>
en cours</option>
<option value="reception"<?=($etat=='reception')? ' selected' : '';?>>
envoyés</option>
<option value="erreur"<?=($etat=='erreur')? ' selected' : '';?>>
en erreur</option>
<?php
if (count($cStatuts)>0 && hasModeEdition()){
?>
<option value="-">-</option>
<?php
	foreach($cStatuts as $cStatut){
		$select = '';
		if ($etat == 'C-'.$cStatut->id){
			$select = ' selected';
		}
?>
	<option value="C-<?=$cStatut->id?>"<?=$select?>><?=$cStatut->libStatut?></option>
<?php
	}
}
?>
</select>

<?php
if ( hasModeEdition() ){
?>
<label>demandé par</label>
<select name="typeCommande">
<option value="-">-</option>
<option value="G"<?=($typeCommande=='G')? ' selected':'';?>>courrier infogreffe</option>
<option value="C"<?=($typeCommande=='C')? ' selected':'';?>>courrier S&amp;D</option>
<option value="E"<?=($typeCommande=='E')? ' selected':'';?>>e-mail</option>
</select>
<?php
}
?>

<label>commandé au mois de</label>
<select name="date">
<?php
$dateToday = date('m');
$dateIntervalle = 12;
if (hasModeEdition()){ $dateIntervalle = 24;}
for($i=$dateToday-$dateIntervalle; $i<=$dateToday; $i++)
{
	$dateTime = mktime(0, 0, 0, $i+1, 0, date('Y'));
	$selected = '';
	if ($date=='' && $i==$dateToday ){ $selected = 'selected'; }
	if ($date!='' && $dateTime==$date){ $selected = 'selected'; }
	?>
	<option value="<?=$dateTime?>" <?=$selected?>>
	<?=date('m/Y', $dateTime)?>
	</option>
	<?php
}
?>
</select>
<input type="submit" name="cmd_liste" value="Afficher"/>
</form>

</div>

<h2>Commandes</h2>
<div class="blockh2">
<?php
if (count($commandes)>0){
?>
	<table>
	<tbody>
	<?php
	foreach($commandes as $commande){
		echo afficheCommande($commande, $type);
	}
	?>
	</tbody>
	</table>
<?php
} else {
?>
Aucune commande.
<?php
}

} // Fin permission d'accès
?>
</div>
</div>