extranet/www/pages/giant_enquete.php
2010-10-21 13:10:04 +00:00

290 lines
9.4 KiB
PHP

<?php
// --------------------------------------------------------------------------- //
// giant_enquete.php
// --------------------------------------------------------------------------- //
require_once 'giant/config.php';
require_once 'giant/client.php';
require_once 'dbbootstrap.php';
setDbConn('giantclient');
define('VERSION', '1.0');
$pays = $_GET['pays'];
$company = $_GET['company'];
$level = $_GET['level'];
$type = $_GET['type' ];
$lang = $_GET['lang' ];
// --------------------------------------------------------------------------- //
// giantCopieDuRapports
// --------------------------------------------------------------------------- //
function giantCopieDuRapport($rapport_a_copier)
{
$r = new Rapports;
$r->CountryCode = $rapport_a_copier->CountryCode;
$r->ProviderId = $rapport_a_copier->ProviderId;
$r->CompanyId = $rapport_a_copier->CompanyId;
$r->ServiceLevelName = 'Immediate';
$r->DataSetType = $rapport_a_copier->DataSetType;
$r->LanguageCode = $rapport_a_copier->LanguageCode;
$r->DataSet = $rapport_a_copier->DataSet;
$r->User = $_SESSION['tabInfo']['login'];
$r->DateTime = date('Y-m-d\ H:i:s');
$r->save();
envoieCourriel('Copie de rapport',
'Copie du rapport '.$rapport_a_copier->ReportId.
' du '.$rapport_a_copier->DateTime.
' vers le rapport '.$r->ReportId);
$name = Doctrine_Query::create()
->from('Commandes')
->where('OrderId = ?', $rapport_a_copier->OrderId)
->fetchOne()
->CompanyName;
$c = new Commandes;
$c->CountryCode = $r->CountryCode;
$c->ProviderId = $r->ProviderId;
$c->CompanyId = $r->CompanyId;
$c->CompanyName = $name;
$c->ServiceLevelName = $r->ServiceLevelName;
$c->DataSetType = $r->DataSetType;
$c->LanguageCode = $r->LanguageCode;
$c->OrderStatus = 'Completed';
$c->OrderDateTime = $r->DateTime;
$c->DueDateTime = $r->DateTime;
$c->DateTimeCompleted = $r->DateTime;
$c->ReportId = $r->ReportId;
$c->User = $r->User;
$c->save();
$r->OrderId = $c->OrderId;
$r->save();
return $c->OrderId;
}
// --------------------------------------------------------------------------- //
// giantGetIdentite
// --------------------------------------------------------------------------- //
function giantGetIdentite($pays, $company, $level, $type, $lang)
{
$c = new Commandes;
$c->CountryCode = $pays;
$c->ProviderId = getProviderId($pays);
$c->CompanyId = $company;
$c->ServiceLevelName = 'Immediate';
$c->DataSetType = $type;
$c->LanguageCode = $lang;
$c->OrderStatus = 'Pending';
$c->OrderDateTime = date('Y-m-d\TH:i:s');
$c->DueDateTime = $c->OrderDateTime;
$c->User = $_SESSION['tabInfo']['login'];
$c->save();
$soap_client = getClient($pays, 'credit-data');
$o = new StdClass;
$o->CompanyId = $company;
$o->DataSetType = new StdClass;
$o->DataSetType->_ = $type;
$o->LanguageCode = $lang;
$o->DataSetVersion = VERSION;
try {
$O = $soap_client->__call('OrderDataSet', array($o));
} catch (SoapFault $f) {
giantErreurSoap($soap_client, $f);
}
$c->OrderStatus = $O->Order->OrderStatus;
$c->ProviderOrderId = $O->Order->ProviderOrderId;
$c->InternalOrderId = $O->Order->InternalOrderId;
$c->save();
if ($O->Order->OrderStatus != 'Completed') {
print 'Service momentanément indisponible';
return 0;
}
$o = new StdClass;
$o->ProviderOrderId = $O->Order->ProviderOrderId;
$o->InternalOrderId = $O->Order->InternalOrderId;
try {
$O = $soap_client->__call('RetrieveDataSet', array($o));
} catch (SoapFault $f) {
giantErreurSoap($soap_client, $f);
}
$r = new Rapports;
$r->CountryCode = $c->CountryCode;
$r->ProviderId = $c->ProviderId;
$r->CompanyId = $company;
$r->ServiceLevelName = $level;
$r->DataSetType = $type;
$r->LanguageCode = $lang;
$r->DataSet = serialize($O->DataSet);
$r->OrderId = $c->OrderId;
$r->User = $c->User;
$r->DateTime = date('Y-m-d\TH:i:s');
$r->save();
$c->CompanyName = $O->DataSet->Company->CompanyName->_;
$c->OrderStatus = 'Completed';
$c->DateTimeCompleted = $r->DateTime;
$c->ReportId = $r->ReportId;
$c->save();
return $c->OrderId;
}
// --------------------------------------------------------------------------- //
// dueDateTime
// --------------------------------------------------------------------------- //
function dueDateTime($company, $dateTime, &$soapClient, $dataSetType, $level)
{
$o = new StdClass;
$o->CompanyId = $company;
try {
$O = $soapClient->__call('RetrieveOptions', array($o));
} catch (SoapFault $f) {
giantErreurSoap($soap_client, $f);
}
foreach ($O->InvestigationOptions->InvestigationOption as $op) {
if ($op->DataSetType->_ == $dataSetType) {
foreach ($op->ServiceLevels->ServiceLevel as $lv) {
if ($lv->Name == $level) {
return date('Y-m-d\TH:i:s',
strtotime($dateTime.' +'.$lv->Duration.' '.
$lv->DurationMetric));
}
}
}
}
return $dateTime;
}
// --------------------------------------------------------------------------- //
// companyName
// --------------------------------------------------------------------------- //
function companyName($pays, $company)
{
$soap_client = getClient($pays, 'search');
$o = new StdClass;
$o->Query = new StdClass;
$o->Query->CompanyId = $company;
$o->IncludePhoneticMatches = 'false';
$o->IncludeSuggestions = 'false';
try {
$O = $soap_client->__call('AdvancedSearch', array($o));
} catch (SoapFault $f) {
giantErreurSoap($soap_client, $f);
}
if (is_array($O->Results->Company) == true) {
$c = $O->Results->Company[0];
} else {
$c = $O->Results->Company;
}
return $c->RegisteredName;
}
// --------------------------------------------------------------------------- //
// Rapport Immediat
// --------------------------------------------------------------------------- //
if ($level == 'Immediate') {
print '<div id="center">';
// Si on a un rapport
$rapports = Doctrine_Query::create()
->from('Rapports')
->andWhere('CountryCode = ?', $pays)
->andWhere('ProviderId = ?', getProviderId($pays))
->andwhere('CompanyId = ?', $company)
->andWhere('ServiceLevelName = ?', 'Immediate')
->andWhere('DataSetType = ?', $type)
->andWhere('LanguageCode = ?', $lang)
->orderby('ReportId desc')
->execute();
$commande_id = 0;
if ($rapports != false && count($rapports) > 0) {
// Si une commande appartient a cet utilisateur
foreach ($rapports as $r) {
if ($r->User == $_SESSION['tabInfo']['login']) {
$commande_id = $r->OrderId;
break;
}
}
if ($commande_id == 0) {
$commande_id = giantCopieDuRapport($rapports[0]);
}
} else {
$commande_id =
giantGetIdentite($pays, $company, $level, $type, $lang);
}
if ($commande_id > 0) {
header('Location: ?page=giant_commandes&OrderId='.$commande_id);
print '<a href="?page=giant_commandes&OrderId='.$commande_id.
'">Veuillez suivre ce lien</a>';
}
print '</div>';
exit;
}
// --------------------------------------------------------------------------- //
// Commande de rapport
// --------------------------------------------------------------------------- //
$soap_client = getClient($pays, 'credit-data');
$c = new Commandes;
$c->CountryCode = $pays;
$c->ProviderId = getProviderId($pays);
$c->CompanyId = $company;
$c->CompanyName = companyName($pays, $company);
$c->ServiceLevelName = $level;
$c->DataSetType = $type;
$c->LanguageCode = $lang;
$c->OrderStatus = 'Pending';
$c->OrderDateTime = date('Y-m-d\TH:i:s');
$c->DueDateTime = dueDateTime($company, $c->OrderDateTime,
$soap_client, $type, $level);
$c->User = $_SESSION['tabInfo']['login'];
$c->save();
$o = new StdClass;
$o->CompanyId = $company;
$o->DataSetType = new StdClass;
$o->DataSetType->_ = $type;
$o->LanguageCode = $lang;
$o->DataSetVersion = VERSION;
$o->ServiceLevelName = $level;
try {
$O = $soap_client->__call('StartInvestigation', array($o));
} catch (SoapFault $f) {
giantErreurSoap($soap_client, $f);
}
$c->OrderStatus = $O->Order->OrderStatus;
$c->ProviderOrderId = $O->Order->ProviderOrderId;
$c->InternalOrderId = $O->Order->InternalOrderId;
$c->save();
if ($O->Order->OrderStatus != 'Pending') {
print 'Service momentanément indisponible';
} else {
header('Location: ?page=giant_commandes&OrderId='.$c->OrderId);
print '<a href="?page=giant_commandes&OrderId='.$c->OrderId.
'">Veuillez suivre ce lien</a>';
}
?>