extranet/www/pages/giant_commandes.php
2010-08-31 13:55:19 +00:00

276 lines
9.6 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']) == false) {
$etat_enq = 'Toutes';
} else {
$etat_enq = $_REQUEST['etat_enq'];
}
require_once 'dbbootstrap.php';
setDbConn('giantclient');
$etatsEnq = array('Toutes' => 'Toutes',
'Pending' => 'En attente',
'Completed' => 'Complet&eacute;es',
'Delivered' => 'D&eacute;livr&eacute;es',
'Undeliverable' => 'Non d&eacute;livrables',
'NonD' => 'Non d&eacute;livr&eacute;es');
// --------------------------------------------------------------------------- //
// 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('&', '&amp;', $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('&', '&amp;', $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)
->fetchOne();
$nom = $commande->CompanyName.'.'.$action;
$rapport = Doctrine_Query::create()
->from('Rapports')
->where('OrderId = ?', $commande_id)
->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') {
$r = Doctrine_Query::create()
->from('Rapports')
->where('OrderId = ?', $commande_id)
->fetchOne();
switch ($r->DataSetType) {
case 'Full':
header('Location: /?page=giant_rapport&OrderId='.$commande_id);
print '<a href="/?page=giant_rapport&OrderId='.$commande_id.
'">Veuillez suivre ce lien</a>';
break;
}
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>&nbsp;&nbsp;&nbsp;&nbsp;Enqu&ecirc;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) {
print '<form method="post" action="pages/giant_commandes.php" '.
'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('User = ?', $_SESSION['tabInfo']['login'])
->andWhere('OrderId = ?', $_GET['OrderId'])
->execute();
} else {
$tabCommandes = Doctrine_Query::create()
->from('Commandes')
->where('User = ?', $_SESSION['tabInfo']['login'])
->orderby('OrderId')
->execute();
}
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 ($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&ecirc;te: '.$commande->ServiceLevelName.'<br/>'.
'&Eacute;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)
->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));
if ($commande->DueDateTime == '0000-00-00 00:00:00' &&
$commande->ServiceLevelName != 'Immediate') {
$datedue = '<a href="?page=international_commandes&maj='.
$commande->OrderId.'&etat_enq='.$etat_enq.'">M&agrave;J</a>';
} else {
$datedue = datetime2date($commande->DueDateTime);
}
tableLigne('Date de r&eacute;ception pr&eacute;vue:', $datedue);
if ($delivree == true) {
tableLigne('Date de mise &agrave; jour:',
datetime2date($commande->DateTimeCompleted));
}
tableFin();
print '</td></table>';
}
?>
</div>