本文整理汇总了PHP中Contract::getFromDB方法的典型用法代码示例。如果您正苦于以下问题:PHP Contract::getFromDB方法的具体用法?PHP Contract::getFromDB怎么用?PHP Contract::getFromDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contract
的用法示例。
在下文中一共展示了Contract::getFromDB方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pdfForItem
static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
{
global $DB, $CFG_GLPIG;
if (!Session::haveRight("contract", "r")) {
return false;
}
$type = $item->getType();
$ID = $item->getField('id');
$con = new Contract();
$query = "SELECT *\n FROM `glpi_contracts_items`\n WHERE `glpi_contracts_items`.`items_id` = '" . $ID . "'\n AND `glpi_contracts_items`.`itemtype` = '" . $type . "'";
$result = $DB->query($query);
$number = $DB->numrows($result);
$i = $j = 0;
$pdf->setColumnsSize(100);
if ($number > 0) {
$pdf->displayTitle('<b>' . _N('Associated contract', 'Associated contracts', 2) . '</b>');
$pdf->setColumnsSize(19, 19, 19, 16, 11, 16);
$pdf->displayTitle(__('Name'), _x('phone', 'Number'), __('Contract type'), __('Supplier'), __('Start date'), __('Initial contract period'));
$i++;
while ($j < $number) {
$cID = $DB->result($result, $j, "contracts_id");
$assocID = $DB->result($result, $j, "id");
if ($con->getFromDB($cID)) {
$pdf->displayLine(empty($con->fields["name"]) ? "(" . $con->fields["id"] . ")" : $con->fields["name"], $con->fields["num"], Html::clean(Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"])), str_replace("<br>", " ", $con->getSuppliersNames()), Html::convDate($con->fields["begin_date"]), sprintf(_n('%d month', '%d months', $con->fields["duration"]), $con->fields["duration"]));
}
$j++;
}
} else {
$pdf->displayTitle("<b>" . __('No item found') . "</b>");
}
$pdf->displaySpace();
}
示例2: can
/**
* Check right on an contract - overloaded to check max_links_allowed
*
* @param $ID ID of the item (-1 if new item)
* @param $right Right to check : r / w / recursive
* @param $input array of input data (used for adding item)
*
* @return boolean
**/
function can($ID, $right, &$input = NULL)
{
if ($ID < 0) {
// Ajout
$contract = new Contract();
if (!$contract->getFromDB($input['contracts_id'])) {
return false;
}
if ($contract->fields['max_links_allowed'] > 0 && countElementsInTable($this->getTable(), "`contracts_id`='" . $input['contracts_id'] . "'") >= $contract->fields['max_links_allowed']) {
return false;
}
}
return parent::can($ID, $right, $input);
}
示例3: transferContracts
/**
* Transfer contracts
*
* @param $itemtype original type of transfered item
* @param $ID original ID of the contract
* @param $newID new ID of the contract
**/
function transferContracts($itemtype, $ID, $newID)
{
global $DB;
$need_clean_process = false;
// if keep
if ($this->options['keep_contract']) {
$contract = new Contract();
// Get contracts for the item
$query = "SELECT *\n FROM `glpi_contracts_items`\n WHERE `items_id` = '{$ID}'\n AND `itemtype` = '{$itemtype}'\n AND `contracts_id` NOT IN " . $this->item_recurs['Contract'];
if ($result = $DB->query($query)) {
if ($DB->numrows($result) > 0) {
// Foreach get item
while ($data = $DB->fetch_array($result)) {
$need_clean_process = false;
$item_ID = $data['contracts_id'];
$newcontractID = -1;
// is already transfer ?
if (isset($this->already_transfer['Contract'][$item_ID])) {
$newcontractID = $this->already_transfer['Contract'][$item_ID];
if ($newcontractID != $item_ID) {
$need_clean_process = true;
}
} else {
// No
// Can be transfer without copy ? = all linked items need to be transfer (so not copy)
$canbetransfer = true;
$query = "SELECT DISTINCT `itemtype`\n FROM `glpi_contracts_items`\n WHERE `contracts_id` = '{$item_ID}'";
if ($result_type = $DB->query($query)) {
if ($DB->numrows($result_type) > 0) {
while (($data_type = $DB->fetch_array($result_type)) && $canbetransfer) {
$dtype = $data_type['itemtype'];
if (isset($this->item_search[$dtype])) {
// No items to transfer -> exists links
$query_search = "SELECT count(*) AS CPT\n FROM `glpi_contracts_items`\n WHERE `contracts_id` = '{$item_ID}'\n AND `itemtype` = '{$dtype}'\n AND `items_id`\n NOT IN " . $this->item_search[$dtype];
$result_search = $DB->query($query_search);
if ($DB->result($result_search, 0, 'CPT') > 0) {
$canbetransfer = false;
}
} else {
$canbetransfer = false;
}
}
}
}
// Yes : transfer
if ($canbetransfer) {
$this->transferItem('Contract', $item_ID, $item_ID);
$newcontractID = $item_ID;
} else {
$need_clean_process = true;
$contract->getFromDB($item_ID);
// No : search contract
$query = "SELECT *\n FROM `glpi_contracts`\n WHERE `entities_id` = '" . $this->to . "'\n AND `name` = '" . addslashes($contract->fields['name']) . "'";
if ($result_search = $DB->query($query)) {
if ($DB->numrows($result_search) > 0) {
$newcontractID = $DB->result($result_search, 0, 'id');
$this->addToAlreadyTransfer('Contract', $item_ID, $newcontractID);
}
}
// found : use it
// not found : copy contract
if ($newcontractID < 0) {
// 1 - create new item
unset($contract->fields['id']);
$input = $contract->fields;
$input['entities_id'] = $this->to;
unset($contract->fields);
$newcontractID = $contract->add($input);
// 2 - transfer as copy
$this->transferItem('Contract', $item_ID, $newcontractID);
}
}
}
// Update links
if ($ID == $newID) {
if ($item_ID != $newcontractID) {
$query = "UPDATE `glpi_contracts_items`\n SET `contracts_id` = '{$newcontractID}'\n WHERE `id` = '" . $data['id'] . "'";
$DB->query($query);
}
// Same Item -> update links
} else {
// Copy Item -> copy links
if ($item_ID != $newcontractID) {
$query = "INSERT\n INTO `glpi_contracts_items`\n (`contracts_id`, `items_id`, `itemtype`)\n VALUES ('{$newcontractID}', '{$newID}', '{$itemtype}')";
$DB->query($query);
} else {
// same contract for new item update link
$query = "UPDATE `glpi_contracts_items`\n SET `items_id` = '{$newID}'\n WHERE `id` = '" . $data['id'] . "'";
$DB->query($query);
}
}
// If clean and unused ->
if ($need_clean_process && $this->options['clean_contract']) {
//.........这里部分代码省略.........
示例4: showForContract
/**
* Print the contract costs
*
* @param $contract Contract object
* @param $withtemplate boolean Template or basic item (default '')
*
* @return Nothing (call to classes members)
**/
static function showForContract(Contract $contract, $withtemplate = '')
{
global $DB, $CFG_GLPI;
$ID = $contract->fields['id'];
if (!$contract->getFromDB($ID) || !$contract->can($ID, READ)) {
return false;
}
$canedit = $contract->can($ID, UPDATE);
echo "<div class='center'>";
$query = "SELECT *\n FROM `glpi_contractcosts`\n WHERE `contracts_id` = '{$ID}'\n ORDER BY `begin_date`";
$rand = mt_rand();
if ($canedit) {
echo "<div id='viewcost" . $ID . "_{$rand}'></div>\n";
echo "<script type='text/javascript' >\n";
echo "function viewAddCost" . $ID . "_{$rand}() {\n";
$params = array('type' => __CLASS__, 'parenttype' => 'Contract', 'contracts_id' => $ID, 'id' => -1);
Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
echo "};";
echo "</script>\n";
echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddCost" . $ID . "_{$rand}();'>";
echo __('Add a new cost') . "</a></div>\n";
}
if ($result = $DB->query($query)) {
echo "<table class='tab_cadre_fixehov'>";
echo "<tr><th colspan='5'>" . self::getTypeName($DB->numrows($result)) . "</th></tr>";
if ($DB->numrows($result)) {
echo "<tr><th>" . __('Name') . "</th>";
echo "<th>" . __('Begin date') . "</th>";
echo "<th>" . __('End date') . "</th>";
echo "<th>" . __('Budget') . "</th>";
echo "<th>" . __('Cost') . "</th>";
echo "</tr>";
Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Contract::getTypeName(1), $contract->getName()));
$total = 0;
while ($data = $DB->fetch_assoc($result)) {
echo "<tr class='tab_bg_2' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditCost" . $data['contracts_id'] . "_" . $data['id'] . "_{$rand}();\"" : '') . ">";
$name = empty($data['name']) ? sprintf(__('%1$s (%2$s)'), $data['name'], $data['id']) : $data['name'];
echo "<td>";
printf(__('%1$s %2$s'), $name, Html::showToolTip($data['comment'], array('display' => false)));
if ($canedit) {
echo "\n<script type='text/javascript' >\n";
echo "function viewEditCost" . $data['contracts_id'] . "_" . $data["id"] . "_{$rand}() {\n";
$params = array('type' => __CLASS__, 'parenttype' => 'Contract', 'contracts_id' => $data["contracts_id"], 'id' => $data["id"]);
Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
echo "};";
echo "</script>\n";
}
echo "</td>";
echo "<td>" . Html::convDate($data['begin_date']) . "</td>";
echo "<td>" . Html::convDate($data['end_date']) . "</td>";
echo "<td>" . Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']) . "</td>";
echo "<td class='numeric'>" . Html::formatNumber($data['cost']) . "</td>";
$total += $data['cost'];
echo "</tr>";
Session::addToNavigateListItems(__CLASS__, $data['id']);
}
echo "<tr class='b noHover'><td colspan='3'> </td>";
echo "<td class='right'>" . __('Total cost') . '</td>';
echo "<td class='numeric'>" . Html::formatNumber($total) . '</td></tr>';
} else {
echo "<tr><th colspan='5'>" . __('No item found') . "</th></tr>";
}
echo "</table>";
}
echo "</div><br>";
}
示例5: ContractCost
}
if (!isset($_GET["contracts_id"])) {
$_GET["contracts_id"] = "";
}
$cost = new ContractCost();
if (isset($_POST["add"])) {
$cost->check(-1, CREATE, $_POST);
if ($newID = $cost->add($_POST)) {
Event::log($_POST['contracts_id'], "contracts", 4, "financial", sprintf(__('%s adds a cost'), $_SESSION["glpiname"]));
}
Html::back();
} else {
if (isset($_POST["purge"])) {
$cost->check($_POST["id"], PURGE);
if ($cost->delete($_POST, 1)) {
Event::log($cost->fields['contracts_id'], "contracts", 4, "financial", sprintf(__('%s purges a cost'), $_SESSION["glpiname"]));
}
$contract = new Contract();
$contract->getFromDB($cost->fields['contracts_id']);
Html::redirect(Toolbox::getItemTypeFormURL('Contract') . '?id=' . $cost->fields['contracts_id'] . ($contract->fields['is_template'] ? "&withtemplate=1" : ""));
} else {
if (isset($_POST["update"])) {
$cost->check($_POST["id"], UPDATE);
if ($cost->update($_POST)) {
Event::log($cost->fields['contracts_id'], "contracts", 4, "financial", sprintf(__('%s updates a cost'), $_SESSION["glpiname"]));
}
Html::back();
}
}
}
Html::displayErrorAndDie('Lost');
示例6: showForItem
/**
* Print an HTML array of contract associated to an object
*
* @since version 0.84
*
* @param $item CommonDBTM object wanted
* @param $withtemplate not used (to be deleted) (default '')
*
* @return Nothing (display)
**/
static function showForItem(CommonDBTM $item, $withtemplate = '')
{
global $DB, $CFG_GLPI;
$itemtype = $item->getType();
$ID = $item->fields['id'];
if (!Contract::canView() || !$item->can($ID, READ)) {
return false;
}
$canedit = $item->can($ID, UPDATE);
$rand = mt_rand();
$query = "SELECT `glpi_contracts_items`.*\n FROM `glpi_contracts_items`,\n `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n AND `glpi_contracts_items`.`items_id` = '{$ID}'\n AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_contracts`.`name`";
$result = $DB->query($query);
$contracts = array();
$used = array();
if ($number = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$contracts[$data['id']] = $data;
$used[$data['contracts_id']] = $data['contracts_id'];
}
}
if ($canedit && $withtemplate != 2) {
echo "<div class='firstbloc'>";
echo "<form name='contractitem_form{$rand}' id='contractitem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
echo "<input type='hidden' name='items_id' value='{$ID}'>";
echo "<input type='hidden' name='itemtype' value='{$itemtype}'>";
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>";
Contract::dropdown(array('entity' => $item->getEntityID(), 'used' => $used));
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 ($withtemplate != 2) {
if ($canedit && $number) {
Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
$massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand);
Html::showMassiveActions($massiveactionparams);
}
}
echo "<table class='tab_cadre_fixehov'>";
$header_begin = "<tr>";
$header_top = '';
$header_bottom = '';
$header_end = '';
if ($canedit && $number && $withtemplate != 2) {
$header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
$header_top .= "</th>";
$header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
$header_bottom .= "</th>";
}
$header_end .= "<th>" . __('Name') . "</th>";
$header_end .= "<th>" . __('Entity') . "</th>";
$header_end .= "<th>" . _x('phone', 'Number') . "</th>";
$header_end .= "<th>" . __('Contract type') . "</th>";
$header_end .= "<th>" . __('Supplier') . "</th>";
$header_end .= "<th>" . __('Start date') . "</th>";
$header_end .= "<th>" . __('Initial contract period') . "</th>";
$header_end .= "</tr>";
echo $header_begin . $header_top . $header_end;
if ($number > 0) {
Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
foreach ($contracts as $data) {
$cID = $data["contracts_id"];
Session::addToNavigateListItems(__CLASS__, $cID);
$contracts[] = $cID;
$assocID = $data["id"];
$con = new Contract();
$con->getFromDB($cID);
echo "<tr class='tab_bg_1" . ($con->fields["is_deleted"] ? "_2" : "") . "'>";
if ($canedit && $withtemplate != 2) {
echo "<td width='10'>";
Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
echo "</td>";
}
echo "<td class='center b'>";
$name = $con->fields["name"];
if ($_SESSION["glpiis_ids_visible"] || empty($con->fields["name"])) {
$name = sprintf(__('%1$s (%2$s)'), $name, $con->fields["id"]);
}
echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>" . $name;
echo "</a></td>";
echo "<td class='center'>";
echo Dropdown::getDropdownName("glpi_entities", $con->fields["entities_id"]) . "</td>";
echo "<td class='center'>" . $con->fields["num"] . "</td>";
echo "<td class='center'>";
//.........这里部分代码省略.........
示例7: methodgetItemContracts
/**
* Return Infocom for an object
*
* @param $protocol the commonication protocol used
* @param $params array
*
* @return a hasdtable, fields of glpi_infocoms
**/
static function methodgetItemContracts($params, $protocol)
{
global $DB;
if (isset($params['help'])) {
$params = array('itemtype' => 'string, mandatory', 'id' => 'integer, mandatory', 'id2name' => 'bool,optional', 'help' => 'bool,optional');
}
$check = self::checkStandardParameters($params, $protocol);
if (!$check == 1) {
exit;
}
$item = new $params['itemtype']();
if (!$item->getFromDB($params['id']) || !Session::haveRight('contract', READ) || !$item->can($params['id'], READ)) {
return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND);
}
$contract = new Contract();
$query = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts_items`, `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id` = `glpi_entities`.`id`)\n WHERE `glpi_contracts`.`id` = `glpi_contracts_items`.`contracts_id`\n AND `glpi_contracts_items`.`items_id` = '" . $params['id'] . "'\n AND `glpi_contracts_items`.`itemtype` = '" . $params['itemtype'] . "'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_contracts`.`name`";
$result = $DB->query($query);
$resp = array();
while ($datas = $DB->fetch_array($result)) {
$contract->getFromDB($datas['id']);
$resp[$datas['id']] = $contract->fields;
if ($id2name) {
$resp[$datas['id']]['contracttypes_name'] = Html::clean(Dropdown::getDropdownName('glpi_contracttypes', $contract->fields['contracttypes_id']));
}
}
return $resp;
}
示例8: doMassiveActions
/**
* Do the standard massive actions
*
* @since version 0.84
*
* This must not be overloaded in Class
* @param $input array of input datas
*
* @return an array of results (ok, ko, noright counts, may include REDIRECT field to set REDIRECT page)
**/
function doMassiveActions($input = array())
{
global $CFG_GLPI;
if (!isset($input["item"]) || count($input["item"]) == 0) {
return false;
}
$res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
switch ($input['action']) {
case 'add_document':
case 'remove_document':
$doc = new Document();
return $doc->doSpecificMassiveActions($input);
case "add_transfer_list":
if (!isset($_SESSION['glpitransfer_list'])) {
$_SESSION['glpitransfer_list'] = array();
}
if (!isset($_SESSION['glpitransfer_list'][$input["itemtype"]])) {
$_SESSION['glpitransfer_list'][$input["itemtype"]] = array();
}
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
$_SESSION['glpitransfer_list'][$input["itemtype"]][$key] = $key;
$res['ok']++;
}
}
$res['REDIRECT'] = $CFG_GLPI['root_doc'] . '/front/transfer.action.php';
break;
case "delete":
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
if ($this->can($key, 'd')) {
if ($this->delete(array("id" => $key))) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
}
break;
case "purge":
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
if ($this->can($key, 'd')) {
$force = 1;
// Only mark deletion for
if ($this->maybeDeleted() && $this->useDeletedToLockIfDynamic() && $this->isDynamic()) {
$force = 0;
}
if ($this->delete(array("id" => $key), $force)) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
}
break;
case "restore":
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
if ($this->can($key, 'd')) {
if ($this->restore(array("id" => $key))) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
}
break;
case "update":
$searchopt = Search::getCleanedOptions($input["itemtype"], 'w');
if (isset($searchopt[$input["id_field"]])) {
/// Infocoms case
if (!isPluginItemType($input["itemtype"]) && Search::isInfocomOption($input["itemtype"], $input["id_field"])) {
$ic = new Infocom();
$link_entity_type = -1;
/// Specific entity item
if ($searchopt[$input["id_field"]]["table"] == "glpi_suppliers") {
$ent = new Supplier();
if ($ent->getFromDB($input[$input["field"]])) {
$link_entity_type = $ent->fields["entities_id"];
}
//.........这里部分代码省略.........
示例9: dropdownTaskItems
function dropdownTaskItems($ID, $name, $used = array())
{
global $DB, $CFG_GLPI;
$restrict = "`plugin_projet_projets_id` = '{$ID}'";
$items = getAllDatasFromTable("glpi_plugin_projet_projets_items", $restrict);
$restrictdoc = "`items_id` = '{$ID}' AND `itemtype` = 'PluginProjetProjet'";
$docs = getAllDatasFromTable("glpi_documents_items", $restrictdoc);
$restrictcontract = "`items_id` = '{$ID}' AND `itemtype` = 'PluginProjetProjet'";
$contracts = getAllDatasFromTable("glpi_contracts_items", $restrictcontract);
echo "<select name='{$name}'>";
echo "<option value='0' selected>" . Dropdown::EMPTY_VALUE . "</option>";
if (!empty($items)) {
foreach ($items as $item) {
$table = getTableForItemType($item["itemtype"]);
$query = "SELECT `" . $table . "`.*\n FROM `glpi_plugin_projet_projets_items`\n INNER JOIN `" . $table . "` ON (`" . $table . "`.`id` = `glpi_plugin_projet_projets_items`.`items_id`)\n WHERE `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item["itemtype"] . "'\n AND `glpi_plugin_projet_projets_items`.`items_id` = '" . $item["items_id"] . "' ";
if (count($used)) {
$query .= " AND `" . $table . "`.`id` NOT IN (0";
foreach ($used as $ID) {
$query .= ",{$ID}";
}
$query .= ")";
}
$query .= " GROUP BY `" . $table . "`.`name`";
$query .= " ORDER BY `" . $table . "`.`name`";
$result_linked = $DB->query($query);
if ($DB->numrows($result_linked)) {
while ($data = $DB->fetch_assoc($result_linked)) {
$name = $data["name"];
$itemclass = new $item["itemtype"]();
if ($item["itemtype"] == 'User') {
$name = getUserName($data["id"]);
}
echo "<option value='" . $data["id"] . "," . $item["itemtype"] . "'>" . $itemclass->getTypeName() . " - " . $name;
if (empty($data["name"]) || $_SESSION["glpiis_ids_visible"] == 1) {
echo " (";
echo $data["id"] . ")";
}
echo "</option>";
}
}
}
}
if (!empty($docs)) {
foreach ($docs as $doc) {
$docclass = new Document();
if ($docclass->getFromDB($doc["documents_id"])) {
$name = $docclass->fields["name"];
echo "<option value='" . $doc["documents_id"] . ",Document'>" . $docclass->getTypeName() . " - " . $name;
if (empty($name) || $_SESSION["glpiis_ids_visible"] == 1) {
echo " (";
echo $doc["documents_id"] . ")";
}
echo "</option>";
}
}
}
if (!empty($contracts)) {
foreach ($contracts as $contract) {
$contractclass = new Contract();
if ($contractclass->getFromDB($contract["contracts_id"])) {
$name = $contractclass->fields["name"];
echo "<option value='" . $contract["contracts_id"] . ",Contract'>" . $contractclass->getTypeName() . " - " . $name;
if (empty($name) || $_SESSION["glpiis_ids_visible"] == 1) {
echo " (";
echo $contract["contracts_id"] . ")";
}
echo "</option>";
}
}
}
echo "</select>";
}
示例10: showAssociated
/**
* Print an HTML array of contract associated to an object
*
*
*@param $item CommonDBTM : object wanted
*@param $withtemplate='' not used (to be deleted)
*
*@return Nothing (display)
*
**/
static function showAssociated(CommonDBTM $item, $withtemplate = '')
{
global $DB, $CFG_GLPI, $LANG;
$itemtype = $item->getType();
$ID = $item->fields['id'];
if (!haveRight("contract", "r") || !$item->can($ID, "r")) {
return false;
}
$canedit = $item->can($ID, "w");
$query = "SELECT `glpi_contracts_items`.*\n FROM `glpi_contracts_items`,\n `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n AND `glpi_contracts_items`.`items_id` = '{$ID}'\n AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_contracts`.`name`";
$result = $DB->query($query);
$number = $DB->numrows($result);
$i = 0;
echo "<div class='spaced'>";
if ($withtemplate != 2) {
echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/contract.form.php\">";
}
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='8'>";
if ($number == 0) {
echo $LANG['financial'][58];
} else {
if ($number == 1) {
echo $LANG['financial'][63];
} else {
echo $LANG['financial'][66];
}
}
echo "</th></tr>";
echo "<tr><th>" . $LANG['common'][16] . "</th>";
echo "<th>" . $LANG['entity'][0] . "</th>";
echo "<th>" . $LANG['financial'][4] . "</th>";
echo "<th>" . $LANG['financial'][6] . "</th>";
echo "<th>" . $LANG['financial'][26] . "</th>";
echo "<th>" . $LANG['search'][8] . "</th>";
echo "<th>" . $LANG['financial'][8] . "</th>";
if ($withtemplate != 2) {
echo "<th> </th>";
}
echo "</tr>";
if ($number > 0) {
initNavigateListItems('Contract', $item->getTypeName() . " = " . $item->getName());
}
$contracts = array();
while ($i < $number) {
$cID = $DB->result($result, $i, "contracts_id");
addToNavigateListItems('Contract', $cID);
$contracts[] = $cID;
$assocID = $DB->result($result, $i, "id");
$con = new Contract();
$con->getFromDB($cID);
echo "<tr class='tab_bg_1" . ($con->fields["is_deleted"] ? "_2" : "") . "'>";
echo "<td class='center'>";
echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>";
echo "<strong>" . $con->fields["name"];
if ($_SESSION["glpiis_ids_visible"] || empty($con->fields["name"])) {
echo " (" . $con->fields["id"] . ")";
}
echo "</strong></a></td>";
echo "<td class='center'>";
echo Dropdown::getDropdownName("glpi_entities", $con->fields["entities_id"]) . "</td>";
echo "<td class='center'>" . $con->fields["num"] . "</td>";
echo "<td class='center'>";
echo Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"]) . "</td>";
echo "<td class='center'>" . $con->getSuppliersNames() . "</td>";
echo "<td class='center'>" . convDate($con->fields["begin_date"]) . "</td>";
echo "<td class='center'>" . $con->fields["duration"] . " " . $LANG['financial'][57];
if ($con->fields["begin_date"] != '' && !empty($con->fields["begin_date"])) {
echo " -> " . getWarrantyExpir($con->fields["begin_date"], $con->fields["duration"]);
}
echo "</td>";
if ($withtemplate != 2) {
echo "<td class='tab_bg_2 center'>";
if ($canedit) {
echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?deleteitem=deleteitem&id={$assocID}&contracts_id={$cID}'>";
echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>";
} else {
echo " ";
}
echo "</td>";
}
echo "</tr>";
$i++;
}
$q = "SELECT *\n FROM `glpi_contracts`\n WHERE `is_deleted` = '0' " . getEntitiesRestrictRequest("AND", "glpi_contracts", "entities_id", $item->getEntityID(), true);
$result = $DB->query($q);
$nb = $DB->numrows($result);
if ($canedit) {
if ($withtemplate != 2 && $nb > count($contracts)) {
echo "<tr class='tab_bg_1'><td class='right' colspan='3'>";
//.........这里部分代码省略.........