/**
* Print an HTML array with contracts associated to the enterprise
*
* @since version 0.84
*
* @param $supplier Supplier object
*
* @return Nothing (display)
**/
static function showForSupplier(Supplier $supplier)
{
global $DB, $CFG_GLPI;
$ID = $supplier->fields['id'];
if (!Session::haveRight("contract", "r") || !$supplier->can($ID, 'r')) {
return false;
}
$canedit = $supplier->can($ID, 'w');
$rand = mt_rand();
$query = "SELECT `glpi_contracts`.*,\n `glpi_contracts_suppliers`.`id` AS assocID,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contracts_suppliers`, `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contracts`.`entities_id`)\n WHERE `glpi_contracts_suppliers`.`suppliers_id` = '{$ID}'\n AND `glpi_contracts_suppliers`.`contracts_id`=`glpi_contracts`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_entities`.`completename`,\n `glpi_contracts`.`name`";
$result = $DB->query($query);
$contracts = array();
$used = array();
if ($number = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$contracts[$data['assocID']] = $data;
$used[$data['id']] = $data['id'];
}
}
if ($canedit) {
echo "<div class='firstbloc'>";
echo "<form name='contractsupplier_form{$rand}' id='contractsupplier_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
echo "<input type='hidden' name='suppliers_id' value='{$ID}'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a contract') . "</th></tr>";
echo "<tr class='tab_bg_1'><td class='right'>";
Contract::dropdown(array('used' => $used, 'entity' => $supplier->fields["entities_id"], 'entity_sons' => $supplier->fields["is_recursive"], 'nochecklimit' => true));
echo "</td><td class='center'>";
echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
echo "</td></tr>";
echo "</table>";
Html::closeForm();
echo "</div>";
}
echo "<div class='spaced'>";
if ($canedit && $number) {
Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
$massiveactionparams = array('num_displayed' => $number);
Html::showMassiveActions(__CLASS__, $massiveactionparams);
}
echo "<table class='tab_cadre_fixe'>";
echo "<tr>";
if ($canedit && $number) {
echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
}
echo "<th>" . __('Name') . "</th>";
echo "<th>" . __('Entity') . "</th>";
echo "<th>" . _x('phone', 'Number') . "</th>";
echo "<th>" . __('Contract type') . "</th>";
echo "<th>" . __('Start date') . "</th>";
echo "<th>" . __('Initial contract period') . "</th>";
echo "</tr>";
$used = array();
foreach ($contracts as $data) {
$cID = $data["id"];
$used[$cID] = $cID;
$assocID = $data["assocID"];
echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
if ($canedit) {
echo "<td>";
Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
echo "</td>";
}
$name = $data["name"];
if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
$name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
}
echo "<td class='center b'>\n <a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>" . $name . "</a>";
echo "</td>";
echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]);
echo "</td><td class='center'>" . $data["num"] . "</td>";
echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contracttypes", $data["contracttypes_id"]) . "</td>";
echo "<td class='center'>" . Html::convDate($data["begin_date"]) . "</td>";
echo "<td class='center'>";
sprintf(_n('%d month', '%d months', $data["duration"]), $data["duration"]);
if ($data["begin_date"] != '' && !empty($data["begin_date"])) {
echo " -> " . Infocom::getWarrantyExpir($data["begin_date"], $data["duration"], 0, true);
}
echo "</td>";
echo "</tr>";
}
echo "</table>";
if ($canedit && $number) {
$paramsma['ontop'] = false;
Html::showMassiveActions(__CLASS__, $paramsma);
Html::closeForm();
}
echo "</div>";
}