358 lines
12 KiB
PHP
358 lines
12 KiB
PHP
<?php
|
|
// --------------------------------------------------------------------------- //
|
|
// international_commandes.php
|
|
// --------------------------------------------------------------------------- //
|
|
if ( isset($_POST['action']) == true) {
|
|
$action = $_POST['action'];
|
|
$commande_id = $_POST['commande_id'];
|
|
} else {
|
|
$action = '';
|
|
}
|
|
if ( isset($_REQUEST['etat_enq']) == true) {
|
|
$etat_enq = $_REQUEST['etat_enq'];
|
|
} else {
|
|
$etat_enq = 'Toutes';
|
|
}
|
|
if ( isset($_REQUEST['p']) == true) {
|
|
$page_num = $_REQUEST['p'];
|
|
} else {
|
|
$page_num = 1;
|
|
}
|
|
|
|
require_once 'dbbootstrap.php';
|
|
setDbConn('giantclient');
|
|
|
|
$etatsEnq = array('Toutes' => 'Toutes',
|
|
'Pending' => 'En attente ', // Espace pour le pluriel
|
|
'Completed' => 'Completées',
|
|
'Delivered' => 'Délivrées',
|
|
'Undeliverable' => 'Non délivrables',
|
|
'NonD' => 'Non délivrées');
|
|
|
|
define('NB_PAR_PAGE', 10);
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// afficheElem
|
|
// --------------------------------------------------------------------------- //
|
|
function afficheElem($obj, $retrait = '')
|
|
{
|
|
if (is_object($obj) == true) {
|
|
$tab = get_object_vars($obj);
|
|
} else if (is_array($obj) == true) {
|
|
$tab = $obj;
|
|
} else {
|
|
$obj = str_replace('&', '&', $obj);
|
|
print "$retrait$obj\n";
|
|
return;
|
|
}
|
|
foreach ($tab as $label => $valeur) {
|
|
if (is_object($valeur) == true) {
|
|
print "$retrait<$label>\n";
|
|
afficheElem($valeur, $retrait.' ');
|
|
print "$retrait</$label>\n";
|
|
} else if (is_array($valeur) == true) {
|
|
foreach ($valeur as $indice => $elem) {
|
|
print "$retrait<$label>\n";
|
|
afficheElem($elem, $retrait.' ');
|
|
print "$retrait</$label>\n";
|
|
}
|
|
} else {
|
|
$valeur = str_replace('&', '&', $valeur);
|
|
print "$retrait<$label>$valeur</$label>\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// Affichage du document
|
|
// --------------------------------------------------------------------------- //
|
|
if ($action == 'xml' ||
|
|
$action == 'txt') {
|
|
$commande = Doctrine_Query::create()
|
|
->from('Commandes')
|
|
->where('OrderId = ?', $commande_id)
|
|
->andWhere('User = ?', $_SESSION['tabInfo']['login'])
|
|
->fetchOne();
|
|
$nom = $commande->CompanyName.'.'.$action;
|
|
$rapport = Doctrine_Query::create()
|
|
->from('Rapports')
|
|
->where('OrderId = ?', $commande_id)
|
|
->andWhere('User = ?', $_SESSION['tabInfo']['login'])
|
|
->fetchOne();
|
|
$obj = unserialize($rapport->DataSet);
|
|
if ($action == 'xml') {
|
|
header('Content-type: text/xml');
|
|
header('Content-Disposition: attachment; filename="'.$nom.'"');
|
|
afficheElem($obj);
|
|
} else {
|
|
header('Content-type: text/plain');
|
|
header('Content-Disposition: attachment; filename="'.$nom.'"');
|
|
print_r($obj);
|
|
}
|
|
if ($commande->OrderStatus == 'Completed') {
|
|
$commande->OrderStatus = 'Delivered';
|
|
$commande->save();
|
|
}
|
|
exit;
|
|
}
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// Affichage du document HTML
|
|
// --------------------------------------------------------------------------- //
|
|
if ($action == 'html') {
|
|
$commande = Doctrine_Query::create()
|
|
->from('Commandes')
|
|
->where('OrderId = ?', $commande_id)
|
|
->andWhere('User = ?', $_SESSION['tabInfo']['login'])
|
|
->fetchOne();
|
|
if ($commande->OrderStatus == 'Completed') {
|
|
$commande->OrderStatus = 'Delivered';
|
|
$commande->save();
|
|
}
|
|
$r = Doctrine_Query::create()
|
|
->from('Rapports')
|
|
->where('OrderId = ?', $commande_id)
|
|
->andWhere('User = ?', $_SESSION['tabInfo']['login'])
|
|
->fetchOne();
|
|
header('Location: /?page=giant_rapport&OrderId='.$commande_id);
|
|
print '<a href="/?page=giant_rapport&OrderId='.$commande_id.
|
|
'">Veuillez suivre ce lien</a>';
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<div id="center" style="width:625px">
|
|
<h1>Commandes Internationales</h1>
|
|
|
|
<?php
|
|
// --------------------------------------------------------------------------- //
|
|
// Suppression
|
|
// --------------------------------------------------------------------------- //
|
|
if ($action == 'Supprimer') {
|
|
Doctrine_Query::create()
|
|
->update('Commandes')
|
|
->set('OrderStatus', '?', 'Unlinked')
|
|
->where('OrderId = ?', $commande_id)
|
|
->execute();
|
|
}
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// Choix de l'etat des commandes a afficher
|
|
// --------------------------------------------------------------------------- //
|
|
if (isset($_GET['OrderId']) == false) {
|
|
print '<form method="post" action="?page=giant_commandes">';
|
|
print '<label> Enquêtes:</label>';
|
|
print '<select name="etat_enq" onchange="this.form.submit();">';
|
|
foreach ($etatsEnq as $index => $valeur) {
|
|
print '<option value="'.$index.'"';
|
|
if ($etat_enq == $index) {
|
|
print ' selected';
|
|
}
|
|
print '>'.$etatsEnq[$index].'</option>';
|
|
}
|
|
print '</select>';
|
|
print '</form>';
|
|
print '<br/>';
|
|
}
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// tableDebut
|
|
// --------------------------------------------------------------------------- //
|
|
function tableDebut()
|
|
{
|
|
print '<table>';
|
|
}
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// tableLigne
|
|
// --------------------------------------------------------------------------- //
|
|
function tableLigne($c1, $c2)
|
|
{
|
|
print '<tr><td>'.$c1.'</td><td>'.$c2.'</td></tr>';
|
|
}
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// tableFin
|
|
// --------------------------------------------------------------------------- //
|
|
function tableFin()
|
|
{
|
|
print '</table>';
|
|
}
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// boutonPost
|
|
// --------------------------------------------------------------------------- //
|
|
function boutonPost($action, $nom, $valeur, $etat_enq)
|
|
{
|
|
if ($action == 'xml' ||
|
|
$action == 'txt') {
|
|
print '<form method="post" action="pages/giant_commandes.php" ';
|
|
} else {
|
|
print '<form method="post" action="./?page=giant_commandes" ';
|
|
}
|
|
print 'style="float:left">'.
|
|
'<input type="hidden" name="action" value="'.$action.'" />'.
|
|
'<input type="hidden" name="'.$nom.'" value="'.$valeur.'" />'.
|
|
'<input type="hidden" name="etat_enq" value="'.$etat_enq.'" />'.
|
|
'<input type="submit" value="'.
|
|
((ctype_lower($action)) ? strtoupper($action) : $action).'" />'.
|
|
'</form>';
|
|
}
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// datetime2date
|
|
// --------------------------------------------------------------------------- //
|
|
function datetime2date($datetime)
|
|
{
|
|
return preg_replace('/([0-9]{4}-[0-9]{2}-[0-9]{2}).*$/', '$1',
|
|
$datetime);
|
|
}
|
|
|
|
// --------------------------------------------------------------------------- //
|
|
// Affichage des commandes
|
|
// --------------------------------------------------------------------------- //
|
|
if (isset($_GET['OrderId']) == true) {
|
|
$tabCommandes = Doctrine_Query::create()
|
|
->from('Commandes')
|
|
->where('OrderId = ?', $_GET['OrderId'])
|
|
->andWhere('User = ?', $_SESSION['tabInfo']['login'])
|
|
->execute();
|
|
if (isset($_GET['action']) == true &&
|
|
$_GET['action'] == 'Verifier') {
|
|
require_once 'giant/config.php';
|
|
require_once 'giant/client.php';
|
|
|
|
$status = giantEtatDeCommande($tabCommandes[0]);
|
|
if ($status == 'Pending') {
|
|
print 'Le rapport n\'est pas encore disponible.<br/>';
|
|
} else if ($status == 'Undeliverable') {
|
|
print 'Le rapport n\'est pas délivrable.<br/>';
|
|
}
|
|
}
|
|
} else {
|
|
$tabCommandes = Doctrine_Query::create()
|
|
->from('Commandes')
|
|
->where('User = ?', $_SESSION['tabInfo']['login'])
|
|
->orderby('OrderId desc')
|
|
->execute();
|
|
}
|
|
$count = 0;
|
|
foreach ($tabCommandes as $commande) {
|
|
if (($etat_enq != 'Toutes' &&
|
|
$etat_enq != 'NonD' &&
|
|
$etat_enq != $commande->OrderStatus) ||
|
|
($etat_enq == 'NonD' &&
|
|
$commande->OrderStatus == 'Delivered') ||
|
|
$commande->OrderStatus == 'Unlinked') {
|
|
continue;
|
|
}
|
|
if ($count < ($page_num - 1) * NB_PAR_PAGE) {
|
|
++$count;
|
|
continue;
|
|
}
|
|
if ($commande->OrderStatus == 'Completed' ||
|
|
$commande->OrderStatus == 'Delivered') {
|
|
$delivree = true;
|
|
} else {
|
|
$delivree = false;
|
|
}
|
|
print '<table border="1" cellspacing="0"'.
|
|
' style="margin:10px;background-color:#E7EFF8">'.
|
|
'<td width="390px" valign="top">';
|
|
if ($delivree == true) {
|
|
print '<font color="#000000"><b>';
|
|
}
|
|
print $commande->CompanyName;
|
|
if ($delivree == true) {
|
|
print '</b></font>';
|
|
}
|
|
print '<br/>'.
|
|
'Type d\'enquête: '.
|
|
'<i>'.$commande->ServiceLevelName.'</i>, '.
|
|
'<i>'.$commande->DataSetType.'</i>. '.
|
|
'Langage: '.
|
|
'<i>'.$commande->LanguageCode.'</i><br/>'.
|
|
'État: ';
|
|
if ($delivree == true) {
|
|
print '<font color="#31659C"><b>';
|
|
}
|
|
print substr($etatsEnq[$commande->OrderStatus], 0, -1);
|
|
if ($delivree == true) {
|
|
print '</b></font><br/>';
|
|
$reports = Doctrine_Query::create()
|
|
->from('Rapports')
|
|
->where('OrderId = ?', $commande->OrderId)
|
|
->andWhere('User = ?', $_SESSION['tabInfo']['login'])
|
|
->orderby('ReportId')
|
|
->execute();
|
|
foreach ($reports as $report) {
|
|
boutonPost('html', 'commande_id',
|
|
$commande->OrderId, $etat_enq);
|
|
boutonPost('xml', 'commande_id',
|
|
$commande->OrderId, $etat_enq);
|
|
boutonPost('txt', 'commande_id',
|
|
$commande->OrderId, $etat_enq);
|
|
}
|
|
if (count($reports) > 0) {
|
|
boutonPost('Supprimer', 'commande_id',
|
|
$commande->OrderId, $etat_enq);
|
|
} else {
|
|
$delivree = false;
|
|
}
|
|
}
|
|
print '</td><td valign="top">';
|
|
tableDebut();
|
|
tableLigne('Date de commande:', datetime2date($commande->OrderDateTime));
|
|
$dueDate = datetime2date($commande->DueDateTime);
|
|
if ($delivree == false) {
|
|
$date = date('Y-m-d');
|
|
if ($dueDate <= $date) {
|
|
$dueDate = '<a href="./?page=giant_commandes'.
|
|
'&OrderId='.$commande->OrderId.
|
|
'&action=Verifier"'.
|
|
' title="Vérifier">'.$dueDate.'</a>';
|
|
}
|
|
}
|
|
tableLigne('Date de réception prévue:', $dueDate);
|
|
if ($delivree == true) {
|
|
tableLigne('Date de mise à jour:',
|
|
datetime2date($commande->DateTimeCompleted));
|
|
}
|
|
tableFin();
|
|
print '</td></table>';
|
|
++$count;
|
|
if ($count == NB_PAR_PAGE) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
$nb_pages = ceil(count($tabCommandes) / NB_PAR_PAGE);
|
|
if ($nb_pages > 1) {
|
|
print '<table><tr>';
|
|
print '<td width="40%" align="right">';
|
|
if ($page_num > 1) {
|
|
print '<a href="./?page=giant_commandes&p='.($page_num-1).'"'.
|
|
' title="Page précédente...">';
|
|
print '<img src="./img/boutton_precedent_off.gif"'.
|
|
' onmouseover="this.src=\'./img/boutton_precedent_on.gif\'"'.
|
|
' onmouseout="this.src=\'./img/boutton_precedent_off.gif\'"/>';
|
|
print '</a>';
|
|
}
|
|
print '</td>';
|
|
print '<td width="20%" align="center">Page '.$page_num.'/'.$nb_pages.'</td>';
|
|
print '<td width="40%" align="left">';
|
|
if ($page_num < $nb_pages) {
|
|
print '<a href="./?page=giant_commandes&p='.($page_num+1).'"'.
|
|
' title="Page suivante...">';
|
|
print '<img src="./img/boutton_suivant_off.gif"'.
|
|
' onmouseover="this.src=\'./img/boutton_suivant_on.gif\'"'.
|
|
' onmouseout="this.src=\'./img/boutton_suivant_off.gif\'"/>';
|
|
print '</a>';
|
|
}
|
|
print '</td>';
|
|
print '</tr></table>';
|
|
}
|
|
?>
|
|
|
|
</div>
|