<?php
// --------------------------------------------------------------------------- //
// giant_identite.php
// --------------------------------------------------------------------------- //

$pays    = $_GET['pays'];
$company = $_GET['company'];

require_once 'giant/config.php';
require_once 'giant/client.php';

$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);
}

$soap_client2 = getClient($pays, 'credit-data');
$o            = new StdClass;
$o->CompanyId = $company;

try {
    $O2 = $soap_client2->__call('RetrieveOptions', array($o));
} catch (SoapFault $f) {
    giantErreurSoap($soap_client2, $f);
}

// --------------------------------------------------------------------------- //
// afficheChamp
// --------------------------------------------------------------------------- //
function afficheChamp(&$obj, $champ)
{
    if (isset($obj->$champ) == false) {
        return;
    }
    print '<tr>';
    print '<td width="30">&nbsp;</td>';
    print '<td width="200" class="StyleInfoLib">'.$champ.'</td>';
    if (is_object($obj->$champ) == true) {
        $texte = '';
        foreach ($obj->$champ as $c) {
            $texte .= $c.' ';
        }
        print '<td width="350" class="StyleInfoData">'.$texte.'</td>';
    } else {
        print '<td width="350" class="StyleInfoData">'.$obj->$champ.'</td>';
    }
    print '</tr>';
}

// --------------------------------------------------------------------------- //
// Affichage identite simplifiee
// --------------------------------------------------------------------------- //
?>
<div id="center">
  <h1 class="titre">IDENTIT&Eacute; INTERNATIONALE DE L&#039;ENTREPRISE</h1>
  <table>
    <tr>
	  <td width="30">&nbsp;</td>
      <td width="200" class="StyleInfoLib">Fiche identité simplifiée<br/></td>
	  <td>
        <u><b>Accès à la fiche identité approfondie :</b></u><br/><br/>
<?php
if (isset($O2->InvestigationOptions->InvestigationOption) == true) {
    print '<b>Commandes de rapport :</b><br/><br/>';
    print '<table>';
    foreach ($O2->InvestigationOptions->InvestigationOption as $op) {
        foreach ($op->ServiceLevels->ServiceLevel as $lv) {
            print '<tr>';
            print '<td>';
            print $op->DataSetType->_;
            print '</td>';
            print '<td>';
            print $lv->Name.' '.$lv->Duration.' '.$lv->DurationMetric.' : ';
            print '</td>';
            print '<td>';
            foreach ($op->LanguageCodes->LanguageCode as $lang) {
                print '<a href="?page=giant_enquete'.
                    '&pays='.$pays.
                    '&company='.$company.
                    '&level='.$lv->Name.
                    '&type=Full'.
                    '&lang='.$lang.'"><code>'.$lang.'&nbsp;&nbsp;</code></a>';
            }
            print '</td>';
            print '</tr>';
        }
    }
    print '</table>';
    print '<br/>';
}
print '<b>Rapports immediats :</b><br/><br/>';
print '<table>';
foreach ($O2->DataSetOptions->DataSetOption as $op) {
    print '<tr>';
    print '<td>';
    print $op->DataSetType->_.' : ';
    print '</td>';
    print '<td>';
    foreach ($op->LanguageCodes->LanguageCode as $lang) {
        print '<a href="?page=giant_enquete'.
            '&pays='.$pays.
            '&company='.$company.
            '&level=Immediate'.
            '&type='.$op->DataSetType->_.
            '&lang='.$lang.'"><code>'.$lang.'&nbsp;&nbsp;</code></a>';
    }
    print '</td>';
    print '</tr>';
}
print '</table>';
?>
      </td>
    </tr>
    <tr><td colspan="3">&nbsp;</td></tr>
  </table>

  <h2>Raison sociale et coordonnées :</h2>

  <table>
<?php
if (isset($O->Results->Company) == true) {
    if (is_array($O->Results->Company) == true) {
        $c = $O->Results->Company[0];
    } else {
        $c = $O->Results->Company;
    }
    afficheChamp($c, 'RegisteredName');
    afficheChamp($c, 'Building');
    afficheChamp($c, 'Street');
    afficheChamp($c, 'HouseNumber');
    afficheChamp($c, 'HouseNumberAdd');
    afficheChamp($c, 'City');
    afficheChamp($c, 'Postcode');
    afficheChamp($c, 'State');
    afficheChamp($c, 'Country');
    afficheChamp($c, 'EntireAddress');
    afficheChamp($c, 'VatNumber');
    afficheChamp($c, 'CompanyRegisterNumber');
    afficheChamp($c, 'CompanyWebSite');
    afficheChamp($c, 'CompanyEmail');
    afficheChamp($c, 'ParentCompany');
    afficheChamp($c, 'LegalForm');
    afficheChamp($c, 'NaceCodes');
    afficheChamp($c, 'PreviousRegisteredName');
    afficheChamp($c, 'TelephoneNumbers');
    afficheChamp($c, 'AddressType');
}
?>
  </table>
</div>