/** * Transfer an enterprise * * @param $ID ID of the enterprise **/ function transferSingleSupplier($ID) { global $DB; // TODO clean system : needed ? $ent = new Supplier(); if ($this->options['keep_supplier'] && $ent->getFromDB($ID)) { if (isset($this->noneedtobe_transfer['Supplier'][$ID])) { // recursive enterprise return $ID; } else { if (isset($this->already_transfer['Supplier'][$ID])) { // Already transfer return $this->already_transfer['Supplier'][$ID]; } else { $newID = -1; // Not already transfer $links_remaining = 0; // All linked items need to be transfer so transfer enterprise ? // Search for contract $query = "SELECT count(*) AS CPT\n FROM `glpi_contracts_suppliers`\n WHERE `suppliers_id` = '{$ID}'\n AND `contracts_id` NOT IN " . $this->item_search['Contract']; $result_search = $DB->query($query); $links_remaining = $DB->result($result_search, 0, 'CPT'); if ($links_remaining == 0) { // Search for infocoms if ($this->options['keep_infocom']) { foreach ($this->INFOCOMS_TYPES as $itemtype) { $query = "SELECT count(*) AS CPT\n FROM `glpi_infocoms`\n WHERE `suppliers_id` = '{$ID}'\n AND `itemtype` = '{$itemtype}'\n AND `items_id` NOT IN " . $this->item_search[$itemtype]; if ($result_search = $DB->query($query)) { $links_remaining += $DB->result($result_search, 0, 'CPT'); } } } } // All linked items need to be transfer -> use unique transfer system if ($links_remaining == 0) { $this->transferItem('Supplier', $ID, $ID); $newID = $ID; } else { // else Transfer by Copy // Is existing item in the destination entity ? $query = "SELECT *\n FROM `glpi_suppliers`\n WHERE `entities_id` = '" . $this->to . "'\n AND `name` = '" . addslashes($ent->fields['name']) . "'"; if ($result_search = $DB->query($query)) { if ($DB->numrows($result_search) > 0) { $newID = $DB->result($result_search, 0, 'id'); $this->addToAlreadyTransfer('Supplier', $ID, $newID); } } // Not found -> transfer copy if ($newID < 0) { // 1 - create new item unset($ent->fields['id']); $input = $ent->fields; $input['entities_id'] = $this->to; unset($ent->fields); $newID = $ent->add($input); // 2 - transfer as copy $this->transferItem('Supplier', $ID, $newID); } // Founded -> use to link : nothing to do } return $newID; } } } return 0; }
/** * Print the object user form for notification * * @since version 0.85 * * @param $ID integer ID of the item * @param $options array * * @return Nothing (display) **/ function showSupplierNotificationForm($ID, $options = array()) { global $CFG_GLPI; $this->check($ID, UPDATE); if (!isset($this->fields['suppliers_id'])) { return false; } $item = new static::$itemtype_1(); echo "<br><form method='post' action='" . $_SERVER['PHP_SELF'] . "'>"; echo "<div class='center'>"; echo "<table class='tab_cadre' width='80%'>"; echo "<tr class='tab_bg_2'><td>" . $item->getTypeName(1) . "</td>"; echo "<td>"; if ($item->getFromDB($this->fields[static::getItilObjectForeignKey()])) { echo $item->getField('name'); } echo "</td></tr>"; $supplier = new Supplier(); $default_email = ""; if ($supplier->getFromDB($this->fields["suppliers_id"])) { $default_email = $supplier->fields['email']; } echo "<tr class='tab_bg_2'><td>" . __('User') . "</td>"; echo "<td>" . $supplier->getName() . "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Email Followup') . "</td>"; echo "<td>"; Dropdown::showYesNo('use_notification', $this->fields['use_notification']); echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Email') . "</td>"; echo "<td>"; if (empty($this->fields['alternative_email'])) { $this->fields['alternative_email'] = $default_email; } echo "<input type='text' size='40' name='alternative_email' value='" . $this->fields['alternative_email'] . "'>"; echo "</td></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='2'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>"; echo "<input type='hidden' name='id' value='{$ID}'>"; echo "</td></tr>"; echo "</table></div>"; Html::closeForm(); }
/** * show suppliers associated * * @since version 0.84 * * @param $type integer : user type * @param $canedit boolean : can edit ? * @param $options array options for default values ($options of showForm) * * @return nothing display **/ function showSuppliersAssociated($type, $canedit, array $options = array()) { global $CFG_GLPI; $showsupplierlink = 0; if (Session::haveRight('contact_enterprise', READ)) { $showsupplierlink = 2; } $suppliericon = self::getActorIcon('supplier', $type); $supplier = new Supplier(); $linksupplier = new $this->supplierlinkclass(); $itemtype = $this->getType(); $typename = self::getActorFieldNameType($type); $candelete = true; $mandatory = ''; // For ticket templates : mandatories if ($itemtype == 'Ticket' && isset($options['_tickettemplate'])) { $mandatory = $options['_tickettemplate']->getMandatoryMark("_suppliers_id_" . $typename); if ($options['_tickettemplate']->isMandatoryField("_suppliers_id_" . $typename) && isset($this->suppliers[$type]) && count($this->suppliers[$type]) == 1) { $candelete = false; } } if (isset($this->suppliers[$type]) && count($this->suppliers[$type])) { foreach ($this->suppliers[$type] as $d) { $k = $d['suppliers_id']; echo "{$mandatory}{$suppliericon} "; if ($supplier->getFromDB($k)) { echo $supplier->getLink(array('comments' => $showsupplierlink)); echo " "; $tmpname = Dropdown::getDropdownName($supplier->getTable(), $k, 1); Html::showToolTip($tmpname['comment']); if ($CFG_GLPI['use_mailing']) { $text = __('Email followup') . " " . Dropdown::getYesNo($d['use_notification']) . '<br>'; if ($d['use_notification']) { $supemail = $d['alternative_email']; if (empty($supemail)) { $supemail = $supplier->fields['email']; } $text .= sprintf(__('%1$s: %2$s'), __('Email'), $supemail); } echo " "; if ($canedit) { $opt = array('img' => $CFG_GLPI['root_doc'] . '/pics/edit.png', 'popup' => $linksupplier->getFormURL() . "?id=" . $d['id']); Html::showToolTip($text, $opt); } } } if ($canedit && $candelete) { echo " "; Html::showSimpleForm($linksupplier->getFormURL(), 'delete', _x('button', 'Delete permanently'), array('id' => $d['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png"); } echo '<br>'; } } }
public function generateOrder($params) { global $DB; $ID = $params['id']; $template = $params['template']; $signature = $params['sign']; if ($template) { $config = array('PATH_TO_TMP' => GLPI_DOC_DIR . '/_tmp'); $odf = new Odtphp\Odf(PLUGIN_ORDER_TEMPLATE_DIR . "{$template}", $config); $this->getFromDB($ID); if (file_exists(PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR . "custom.php")) { include_once PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR . "custom.php"; } if (function_exists("plugin_order_getCustomFieldsForODT")) { plugin_order_getCustomFieldsForODT($ID, $template, $odf, $signature); } else { $PluginOrderOrder_Item = new PluginOrderOrder_Item(); $PluginOrderReference_Supplier = new PluginOrderReference_Supplier(); try { $odf->setImage('logo', PLUGIN_ORDER_TEMPLATE_LOGO_DIR . '/logo.jpg'); } catch (\Odtphp\Exceptions\OdfException $e) { } $values = array(); $values['title_order'] = __("Order number", "order"); $values['num_order'] = $this->fields["num_order"]; $values['title_invoice_address'] = __("Invoice address", "order"); $values['comment_order'] = $this->fields["comment"]; $entity = new Entity(); $entity->getFromDB($this->fields["entities_id"]); $town = ''; if ($this->fields["entities_id"] != 0) { $name_entity = $entity->fields["name"]; } else { $name_entity = __("Root entity"); } $values['entity_name'] = $name_entity; if ($entity->getFromDB($this->fields["entities_id"])) { $town = $entity->fields["town"]; $values['entity_address'] = $entity->fields["address"]; $values['entity_postcode'] = $entity->fields["postcode"]; $values['entity_town'] = $entity->fields["town"]; $values['entity_country'] = $entity->fields["country"]; } $supplier = new Supplier(); if ($supplier->getFromDB($this->fields["suppliers_id"])) { $values['supplier_name'] = $supplier->fields["name"]; $values['supplier_address'] = $supplier->fields["address"]; $values['supplier_postcode'] = $supplier->fields["postcode"]; $values['supplier_town'] = $supplier->fields["town"]; $values['supplier_country'] = $supplier->fields["country"]; } $location = new Location(); if ($location->getFromDB($this->fields["locations_id"])) { $values['title_delivery_address'] = __("Delivery address", "order"); $values['comment_delivery_address'] = $location->fields['comment']; } if ($town) { $town = $town . ", "; } $order_date = Html::convDate($this->fields["order_date"]); $username = Html::clean(getUserName(Session::getLoginUserID())); $values['title_date_order'] = $town . __("The", "order") . " "; $values['date_order'] = $order_date; $values['title_sender'] = __("Issuer order", "order"); $values['sender'] = $username; $values['title_budget'] = __("Budget"); $budget = new Budget(); if ($budget->getFromDB($this->fields["budgets_id"])) { $values['budget'] = $budget->fields['name']; } else { $values['budget'] = ''; } $output = ''; $contact = new Contact(); if ($contact->getFromDB($this->fields["contacts_id"])) { $output = formatUserName($contact->fields["id"], "", $contact->fields["name"], $contact->fields["firstname"]); } $values['title_recipient'] = __("Recipient", "order"); $values['recipient'] = Html::clean($output); $values['nb'] = __("Quantity", "order"); $values['title_item'] = __("Designation", "order"); $values['title_ref'] = __("Reference"); $values['HTPrice_item'] = __("Unit price", "order"); $values['TVA_item'] = __("VAT", "order"); $values['title_discount'] = __("Discount rate", "order"); $values['HTPriceTotal_item'] = __("Sum tax free", "order"); $values['ATIPriceTotal_item'] = __("Price ATI", "order"); $listeArticles = array(); $result = $PluginOrderOrder_Item->queryDetail($ID); $num = $DB->numrows($result); while ($data = $DB->fetch_array($result)) { $quantity = $PluginOrderOrder_Item->getTotalQuantityByRefAndDiscount($ID, $data["id"], $data["price_taxfree"], $data["discount"]); $listeArticles[] = array('quantity' => $quantity, 'ref' => utf8_decode($data["name"]), 'taxe' => Dropdown::getDropdownName(getTableForItemType("PluginOrderOrderTax"), $data["plugin_order_ordertaxes_id"]), 'refnumber' => $PluginOrderReference_Supplier->getReferenceCodeByReferenceAndSupplier($data["id"], $this->fields["suppliers_id"]), 'price_taxfree' => $data["price_taxfree"], 'discount' => $data["discount"], false, 0, 'price_discounted' => $data["price_discounted"] * $quantity, 'price_ati' => $data["price_ati"]); } $article = $odf->setSegment('articles'); foreach ($listeArticles as $element) { $article->nbA($element['quantity']); $article->titleArticle($element['ref']); $article->refArticle($element['refnumber']); $article->TVAArticle($element['taxe']); $article->HTPriceArticle(Html::clean(Html::formatNumber($element['price_taxfree']))); if ($element['discount'] != 0) { $article->discount(Html::clean(Html::formatNumber($element['discount'])) . " %"); } else { $article->discount(""); } $article->HTPriceTotalArticle(Html::clean(Html::formatNumber($element['price_discounted']))); $total_TTC_Article = $element['price_discounted'] * (1 + $element['taxe'] / 100); $article->ATIPriceTotalArticle(Html::clean(Html::formatNumber($total_TTC_Article))); $article->merge(); } $odf->mergeSegment($article); $prices = $PluginOrderOrder_Item->getAllPrices($ID); // total price (with postage) $postagewithTVA = $PluginOrderOrder_Item->getPricesATI($this->fields["port_price"], Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $this->fields["plugin_order_ordertaxes_id"])); $total_HT = $prices["priceHT"] + $this->fields["port_price"]; $total_TVA = $prices["priceTVA"] + $postagewithTVA - $this->fields["port_price"]; $total_TTC = $prices["priceTTC"] + $postagewithTVA; if ($signature) { try { $odf->setImage('sign', PLUGIN_ORDER_SIGNATURE_DIR . $signature); } catch (\Odtphp\Exceptions\OdfException $e) { } } else { try { $odf->setImage('sign', '../pics/nothing.gif'); } catch (\Odtphp\Exceptions\OdfException $e) { } } $name = Dropdown::getDropdownName("glpi_plugin_order_orderpayments", $this->fields["plugin_order_orderpayments_id"]); $values['title_totalht'] = __("Price tax free", "order"); $values['totalht'] = Html::clean(Html::formatNumber($prices['priceHT'])); $values['title_port'] = __("Price tax free with postage", "order"); $values['totalht_port_price'] = Html::clean(Html::formatNumber($total_HT)); $values['title_price_port'] = __("Postage", "order"); $values['price_port_tva'] = " (" . Html::clean(Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $this->fields["plugin_order_ordertaxes_id"])) . "%)"; $values['port_price'] = Html::clean(Html::formatNumber($postagewithTVA)); $values['title_tva'] = __("VAT", "order"); $values['totaltva'] = Html::clean(Html::formatNumber($total_TVA)); $values['title_totalttc'] = __("Price ATI", "order"); $values['totalttc'] = Html::clean(Html::formatNumber($total_TTC)); $values['title_money'] = __("€", "order"); $values['title_sign'] = __("Signature of issuing order", "order"); $values['title_conditions'] = __("Payment conditions", "order"); $values['payment_conditions'] = $name; // Set variables in odt template foreach ($values as $field => $val) { try { $odf->setVars($field, $val, true, 'UTF-8'); } catch (\Odtphp\Exceptions\OdfException $e) { } } } $message = "_"; if (Session::isMultiEntitiesMode()) { $entity = new Entity(); $entity->getFromDB($this->fields['entities_id']); $message .= $entity->getName(); } $message .= "_" . $this->fields['num_order'] . "_"; $message .= Html::convDateTime($_SESSION['glpi_currenttime']); $message = str_replace(" ", "_", $message); $outputfile = str_replace(".odt", $message . ".odt", $template); // We export the file $odf->exportAsAttachedFile($outputfile); } }
static function showListForSupplier($entID) { global $DB, $CFG_GLPI, $LANG; if (!haveRight("show_all_ticket", "1")) { return false; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE (`suppliers_id_assign` = '{$entID}') " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n ORDER BY `glpi_tickets`.`date_mod` DESC\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; if ($number > 0) { $ent = new Supplier(); $ent->getFromDB($entID); initNavigateListItems('Ticket', $LANG['financial'][26] . " = " . $ent->fields['name']); $options['field'][0] = 6; $options['searchtype'][0] = 'equals'; $options['contains'][0] = $entID; $options['link'][0] = 'AND'; $options['reset'] = 'reset'; echo "<tr><th colspan='11'>"; if ($number == 1) { echo $LANG['job'][10] . " : " . $number; echo "<span class='small_space'><a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($options, '&') . "'>" . $LANG['buttons'][40] . "</a></span>"; } else { echo $LANG['job'][8] . " : " . $number; echo "<span class='small_space'><a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($options, '&') . "'>" . $LANG['buttons'][40] . "</a></span>"; } echo "</th></tr>"; self::commonListHeader(HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { addToNavigateListItems('Ticket', $data["id"]); self::showShort($data["id"], 0); } } else { echo "<tr><th>" . $LANG['joblist'][8] . "</th></tr>"; } echo "</table></div>"; }
/** * show suppliers associated * * @since version 0.84 * * @param $type integer : user type * @param $canedit boolean : can edit ? * * @return nothing display **/ function showSuppliersAssociated($type, $canedit, array $options = array()) { global $CFG_GLPI; $showsupplierlink = 0; if (Session::haveRight('contact_enterprise', 'r')) { $showsupplierlink = 1; } $suppliericon = self::getActorIcon('supplier', $type); $supplier = new Supplier(); $itemtype = $this->getType(); $typename = self::getActorFieldNameType($type); $candelete = true; $mandatory = ''; // For ticket templates : mandatories if ($itemtype == 'Ticket' && isset($options['_tickettemplate'])) { $mandatory = $options['_tickettemplate']->getMandatoryMark("_suppliers_id_" . $typename); if ($options['_tickettemplate']->isMandatoryField("_suppliers_id_" . $typename) && isset($this->suppliers[$type]) && count($this->suppliers[$type]) == 1) { $candelete = false; } } if (isset($this->suppliers[$type]) && count($this->suppliers[$type])) { foreach ($this->suppliers[$type] as $d) { $k = $d['suppliers_id']; echo "{$mandatory}{$suppliericon} "; if ($supplier->getFromDB($k)) { echo $supplier->getLink(array('comments' => $showsupplierlink)); echo " "; $tmpname = Dropdown::getDropdownName($supplier->getTable(), $k, 1); Html::showToolTip($tmpname['comment']); } if ($canedit && $candelete) { echo " "; Html::showSimpleForm($this->getFormURL(), 'delete_supplier', _x('button', 'Delete permanently'), array('id' => $d['id'], $this->getForeignKeyField() => $this->fields['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png"); } echo '<br>'; } } }
$AJAX_INCLUDE = 1; if (strpos($_SERVER['PHP_SELF'], "uemailUpdate.php")) { include '../inc/includes.php'; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); } Session::checkLoginUser(); if (isset($_POST['field']) && $_POST["value"] > 0 || isset($_POST['allow_email']) && $_POST['allow_email']) { if (preg_match('/[^a-z_\\-0-9]/i', $_POST['field'])) { throw new \RuntimeException('Invalid field provided!'); } $default_email = ""; $emails = array(); if (isset($_POST['typefield']) && $_POST['typefield'] == 'supplier') { $supplier = new Supplier(); if ($supplier->getFromDB($_POST["value"])) { $default_email = $supplier->fields['email']; } } else { $user = new User(); if ($user->getFromDB($_POST["value"])) { $default_email = $user->getDefaultEmail(); $emails = $user->getAllEmails(); } } $user_index = 0; if (isset($_POST['_user_index'])) { $user_index = $_POST['_user_index']; } echo __('Email followup') . ' '; $default_notif = true;
/** * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $CFG_GLPI; $action = $ma->getAction(); switch ($action) { case 'delete': foreach ($ids as $id) { if ($item->can($id, DELETE)) { if ($item->delete(array("id" => $id))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } break; case 'restore': foreach ($ids as $id) { if ($item->can($id, PURGE)) { if ($item->restore(array("id" => $id))) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } break; case 'purge_item_but_devices': case 'purge_but_item_linked': case 'purge': foreach ($ids as $id) { if ($item->can($id, PURGE)) { $force = 1; // Only mark deletion for if ($item->maybeDeleted() && $item->useDeletedToLockIfDynamic() && $item->isDynamic()) { $force = 0; } $delete_array = array('id' => $id); if ($action == 'purge_item_but_devices') { $delete_array['keep_devices'] = true; } if ($item instanceof CommonDropdown) { if ($item->haveChildren()) { if ($action != 'purge_but_item_linked') { $force = 0; $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage(__("You can't delete that item by massive actions, because it has sub-items")); $ma->addMessage(__("but you can do it by the form of the item")); continue; } } if ($item->isUsed()) { if ($action != 'purge_but_item_linked') { $force = 0; $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage(__("You can't delete that item, because it is used for one or more items")); $ma->addMessage(__("but you can do it by the form of the item")); continue; } } } if ($item->delete($delete_array, $force)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } break; case 'update': if (!isset($ma->POST['search_options']) || !isset($ma->POST['search_options'][$item->getType()])) { return false; } $index = $ma->POST['search_options'][$item->getType()]; $searchopt = Search::getCleanedOptions($item->getType(), UPDATE); $input = $ma->POST; if (isset($searchopt[$index])) { /// Infocoms case if (!isPluginItemType($item->getType()) && Search::isInfocomOption($item->getType(), $index)) { $ic = new Infocom(); $link_entity_type = -1; /// Specific entity item if ($searchopt[$index]["table"] == "glpi_suppliers") { $ent = new Supplier(); if ($ent->getFromDB($input[$input["field"]])) { $link_entity_type = $ent->fields["entities_id"]; } } foreach ($ids as $key) { if ($item->getFromDB($key)) { if ($link_entity_type < 0 || $link_entity_type == $item->getEntityID() || $ent->fields["is_recursive"] && in_array($link_entity_type, getAncestorsOf("glpi_entities", $item->getEntityID()))) { $input2["items_id"] = $key; $input2["itemtype"] = $item->getType(); if ($ic->can(-1, CREATE, $input2)) { // Add infocom if not exists if (!$ic->getFromDBforDevice($item->getType(), $key)) { $input2["items_id"] = $key; $input2["itemtype"] = $item->getType(); unset($ic->fields); $ic->add($input2); $ic->getFromDBforDevice($item->getType(), $key); } $id = $ic->fields["id"]; unset($ic->fields); if ($ic->update(array('id' => $id, $input["field"] => $input[$input["field"]]))) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_COMPAT)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } else { /// Not infocoms $link_entity_type = array(); /// Specific entity item $itemtable = getTableForItemType($item->getType()); $itemtype2 = getItemTypeForTable($searchopt[$index]["table"]); if ($item2 = getItemForItemtype($itemtype2)) { if ($index != 80 && $searchopt[$index]["table"] != $itemtable && $item2->isEntityAssign() && $item->isEntityAssign()) { if ($item2->getFromDB($input[$input["field"]])) { if (isset($item2->fields["entities_id"]) && $item2->fields["entities_id"] >= 0) { if (isset($item2->fields["is_recursive"]) && $item2->fields["is_recursive"]) { $link_entity_type = getSonsOf("glpi_entities", $item2->fields["entities_id"]); } else { $link_entity_type[] = $item2->fields["entities_id"]; } } } } } foreach ($ids as $key) { if ($item->canEdit($key) && $item->canMassiveAction($action, $input['field'], $input[$input["field"]])) { if (count($link_entity_type) == 0 || in_array($item->fields["entities_id"], $link_entity_type)) { if ($item->update(array('id' => $key, $input["field"] => $input[$input["field"]]))) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_COMPAT)); } } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } } } break; case 'add_transfer_list': $itemtype = $item->getType(); if (!isset($_SESSION['glpitransfer_list'])) { $_SESSION['glpitransfer_list'] = array(); } if (!isset($_SESSION['glpitransfer_list'][$itemtype])) { $_SESSION['glpitransfer_list'][$itemtype] = array(); } foreach ($ids as $id) { $_SESSION['glpitransfer_list'][$itemtype][$id] = $id; $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } $ma->setRedirect($CFG_GLPI['root_doc'] . '/front/transfer.action.php'); break; } }
/** * Add team suppliers to the notified user list **/ function getTeamSuppliers() { global $DB, $CFG_GLPI; $query = "SELECT `items_id`\n FROM `glpi_projecttaskteams`\n WHERE `glpi_projecttaskteams`.`itemtype` = 'Supplier'\n AND `glpi_projecttaskteams`.`projecttasks_id` = '" . $this->obj->fields["id"] . "'"; $supplier = new Supplier(); foreach ($DB->request($query) as $data) { if ($supplier->getFromDB($data['items_id'])) { $this->addToAddressesList(array("email" => $supplier->fields["email"], "name" => $supplier->getName(), "language" => $CFG_GLPI["language"], 'usertype' => NotificationTarget::ANONYMOUS_USER)); } } }
if ($val == 1) { $item->restore(array("id" => $key)); } } break; case "update": $searchopt = Search::getCleanedOptions($_POST["itemtype"], 'w'); if (isset($searchopt[$_POST["id_field"]])) { /// Infocoms case if (!isPluginItemType($_POST["itemtype"]) && Search::isInfocomOption($_POST["itemtype"], $_POST["id_field"])) { $ic = new Infocom(); $link_entity_type = -1; /// Specific entity item if ($searchopt[$_POST["id_field"]]["table"] == "glpi_suppliers") { $ent = new Supplier(); if ($ent->getFromDB($_POST[$_POST["field"]])) { $link_entity_type = $ent->fields["entities_id"]; } } foreach ($_POST["item"] as $key => $val) { if ($val == 1) { if ($item->getFromDB($key)) { if ($link_entity_type < 0 || $link_entity_type == $item->getEntityID() || $ent->fields["is_recursive"] && in_array($link_entity_type, getAncestorsOf("glpi_entities", $item->getEntityID()))) { // Add infocom if not exists if (!$ic->getFromDBforDevice($_POST["itemtype"], $key)) { $input2["items_id"] = $key; $input2["itemtype"] = $_POST["itemtype"]; unset($ic->fields); $ic->add($input2); $ic->getFromDBforDevice($_POST["itemtype"], $key); }
/** * show suppliers associated * * @since version 0.84 * * @param $type integer : user type * @param $canedit boolean : can edit ? * * @return nothing display **/ function showSuppliersAssociated($type, $canedit) { global $CFG_GLPI; $showsupplierlink = 0; if (Session::haveRight('contact_enterprise', 'r')) { $showsupplierlink = 1; } $suppliericon = self::getActorIcon('supplier', $type); $supplier = new Supplier(); if (isset($this->suppliers[$type]) && count($this->suppliers[$type])) { foreach ($this->suppliers[$type] as $d) { $k = $d['suppliers_id']; echo "{$suppliericon} "; if ($supplier->getFromDB($k)) { echo $supplier->getLink(array('comments' => $showsupplierlink)); } if ($canedit) { echo " "; Html::showSimpleForm($this->getFormURL(), 'delete_supplier', _x('button', 'Delete permanently'), array('id' => $d['id'], $this->getForeignKeyField() => $this->fields['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png"); } echo '<br>'; } } }
public function showForm($ID, $options = array()) { global $DB; $plugin_order_references_id = -1; if (isset($options['plugin_order_references_id'])) { $plugin_order_references_id = $options['plugin_order_references_id']; } $this->initForm($ID, $options); $this->showFormHeader($options); $PluginOrderReference = new PluginOrderReference(); $PluginOrderReference->getFromDB($plugin_order_references_id); echo "<input type='hidden' name='plugin_order_references_id' value='{$plugin_order_references_id}'>"; echo "<input type='hidden' name='entities_id' value='" . $PluginOrderReference->getEntityID() . "'>"; echo "<input type='hidden' name='is_recursive' value='" . $PluginOrderReference->isRecursive() . "'>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __("Supplier") . ": </td>"; echo "<td>"; if ($ID > 0) { $supplier = new Supplier(); $supplier->getFromDB($this->fields['suppliers_id']); echo $supplier->getLink(Session::haveRight('supplier', READ)); } else { $suppliers = array(); $query = "SELECT `suppliers_id`\n FROM `" . $this->getTable() . "`\n WHERE `plugin_order_references_id` = '{$plugin_order_references_id}'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $suppliers[] = $data["suppliers_id"]; } Supplier::Dropdown(array('name' => 'suppliers_id', 'used' => $suppliers, 'entity' => $PluginOrderReference->getEntityID())); } echo "</td>"; echo "<td>" . __("Manufacturer's product reference", "order") . ": </td>"; echo "<td>"; Html::autocompletionTextField($this, "reference_code"); echo "</td></tr>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __("Unit price tax free", "order") . ": </td>"; echo "<td>"; echo "<input type='text' name='price_taxfree' value=\"" . Html::formatNumber($this->fields["price_taxfree"], true) . "\" size='7'>"; echo "</td>"; echo "<td></td>"; echo "<td></td>"; echo "</tr>"; $options['candel'] = false; $this->showFormButtons($options); return true; }
/** * 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"]; } } foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($this->getFromDB($key)) { if ($link_entity_type < 0 || $link_entity_type == $this->getEntityID() || $ent->fields["is_recursive"] && in_array($link_entity_type, getAncestorsOf("glpi_entities", $this->getEntityID()))) { $input2["items_id"] = $key; $input2["itemtype"] = $input["itemtype"]; if ($ic->can(-1, 'w', $input2)) { // Add infocom if not exists if (!$ic->getFromDBforDevice($input["itemtype"], $key)) { $input2["items_id"] = $key; $input2["itemtype"] = $input["itemtype"]; unset($ic->fields); $ic->add($input2); $ic->getFromDBforDevice($input["itemtype"], $key); } $id = $ic->fields["id"]; unset($ic->fields); if ($ic->update(array('id' => $id, $input["field"] => $input[$input["field"]]))) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } else { $res['ko']++; } } else { $res['ko']++; } } } } else { /// Not infocoms $link_entity_type = array(); /// Specific entity item $itemtable = getTableForItemType($input["itemtype"]); $itemtype2 = getItemTypeForTable($searchopt[$input["id_field"]]["table"]); if ($item2 = getItemForItemtype($itemtype2)) { if ($input["id_field"] != 80 && $searchopt[$input["id_field"]]["table"] != $itemtable && $item2->isEntityAssign() && $this->isEntityAssign()) { if ($item2->getFromDB($input[$input["field"]])) { if (isset($item2->fields["entities_id"]) && $item2->fields["entities_id"] >= 0) { if (isset($item2->fields["is_recursive"]) && $item2->fields["is_recursive"]) { $link_entity_type = getSonsOf("glpi_entities", $item2->fields["entities_id"]); } else { $link_entity_type[] = $item2->fields["entities_id"]; } } } } } foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($this->can($key, 'w') && $this->canMassiveAction($input['action'], $input['field'], $input[$input["field"]])) { if (count($link_entity_type) == 0 || in_array($this->fields["entities_id"], $link_entity_type)) { if ($this->update(array('id' => $key, $input["field"] => $input[$input["field"]]))) { $res['ok']++; } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['noright']++; } } } } } break; case "activate_infocoms": $ic = new Infocom(); if ($ic->canCreate()) { foreach ($input["item"] as $key => $val) { $input = array('itemtype' => $input['itemtype'], 'items_id' => $key); if (!$ic->getFromDBforDevice($input['itemtype'], $key)) { if ($ic->can(-1, 'w', $input)) { if ($ic->add($input)) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } else { $res['ko']++; } } } break; case "add_contract_item": $contractitem = new Contract_Item(); foreach ($input["item"] as $key => $val) { if (isset($input['items_id'])) { // Add items to contracts $input = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'contracts_id' => $key); } if (isset($input['contracts_id'])) { // Add contract to item $input = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'contracts_id' => $input['contracts_id']); } else { return false; } if ($contractitem->can(-1, 'w', $input)) { if ($contractitem->add($input)) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } break; case "remove_contract_item": foreach ($input["item"] as $key => $val) { if (isset($input['items_id'])) { // Remove item to contracts $input = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'contracts_id' => $key); } else { // Remove contract to items $input = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'contracts_id' => $input['contracts_id']); } $contractitem = new Contract_Item(); if ($contractitem->can(-1, 'w', $input)) { if ($item = getItemForItemtype($input["itemtype"])) { if ($item->getFromDB($input['items_id'])) { $contract = new Contract(); if ($contract->getFromDB($input['contracts_id'])) { if ($contractitem->getFromDBForItems($contract, $item)) { if ($contractitem->delete(array('id' => $contractitem->getID()))) { $res['ok']++; } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['noright']++; } } break; //Lock management //Lock management case 'unlock_Printer': case 'unlock_Monitor': case 'unlock_NetworkPort': case 'unlock_NetworkName': case 'unlock_IPAddress': case 'unlock_ComputerDisk': case 'unlock_ComputerVirtualMachine': case 'unlock_Peripheral': case 'unlock_SoftwareVersion': $itemtype = Lock::getItemTypeForMassiveAction($input["action"]); if ($itemtype) { $res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]); } break; case 'unlock_Device': foreach (Item_Devices::getDeviceTypes() as $itemtype) { $res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]); } break; default: // Plugin specific actions $split = explode('_', $input["action"]); $res = ''; if ($split[0] == 'plugin' && isset($split[1])) { // Normalized name plugin_name_action // Allow hook from any plugin on any (core or plugin) type $res = Plugin::doOneHook($split[1], 'MassiveActionsProcess', $input); // } else if ($plug=isPluginItemType($input["itemtype"])) { // non-normalized name // hook from the plugin defining the type // $res = Plugin::doOneHook($plug['plugin'], 'MassiveActionsProcess', $input); } else { $res = $this->doSpecificMassiveActions($input); } break; } return $res; }
/** * @param $item CommonDBTM object * @param $options array * @param $simple (false by default) **/ function getDatasForObject(CommonDBTM $item, array $options, $simple = false) { global $CFG_GLPI, $DB; $objettype = strtolower($item->getType()); $datas["##{$objettype}.title##"] = $item->getField('name'); $datas["##{$objettype}.content##"] = $item->getField('content'); $datas["##{$objettype}.description##"] = $item->getField('content'); $datas["##{$objettype}.id##"] = sprintf("%07d", $item->getField("id")); if ($_SESSION['glpiticket_timeline'] == 1) { $datas["##{$objettype}.url##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . "_" . $item->getType() . '$1'); } else { $datas["##{$objettype}.url##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id")); } $tab = '$2'; if ($_SESSION['glpiticket_timeline'] == 1) { $tab = '$1'; } $datas["##{$objettype}.urlapprove##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . "_" . $item->getType() . $tab); $entity = new Entity(); if ($entity->getFromDB($this->getEntity())) { $datas["##{$objettype}.entity##"] = $entity->getField('completename'); $datas["##{$objettype}.shortentity##"] = $entity->getField('name'); } $datas["##{$objettype}.storestatus##"] = $item->getField('status'); $datas["##{$objettype}.status##"] = $item->getStatus($item->getField('status')); $datas["##{$objettype}.urgency##"] = $item->getUrgencyName($item->getField('urgency')); $datas["##{$objettype}.impact##"] = $item->getImpactName($item->getField('impact')); $datas["##{$objettype}.priority##"] = $item->getPriorityName($item->getField('priority')); $datas["##{$objettype}.time##"] = $item->getActionTime($item->getField('actiontime')); $datas["##{$objettype}.creationdate##"] = Html::convDateTime($item->getField('date')); $datas["##{$objettype}.closedate##"] = Html::convDateTime($item->getField('closedate')); $datas["##{$objettype}.solvedate##"] = Html::convDateTime($item->getField('solvedate')); $datas["##{$objettype}.duedate##"] = Html::convDateTime($item->getField('due_date')); $datas["##{$objettype}.category##"] = ''; if ($item->getField('itilcategories_id')) { $datas["##{$objettype}.category##"] = Dropdown::getDropdownName('glpi_itilcategories', $item->getField('itilcategories_id')); } $datas["##{$objettype}.authors##"] = ''; $datas['authors'] = array(); if ($item->countUsers(CommonITILActor::REQUESTER)) { $users = array(); foreach ($item->getUsers(CommonITILActor::REQUESTER) as $tmpusr) { $uid = $tmpusr['users_id']; $user_tmp = new User(); if ($uid && $user_tmp->getFromDB($uid)) { $users[] = $user_tmp->getName(); $tmp = array(); $tmp['##author.id##'] = $uid; $tmp['##author.name##'] = $user_tmp->getName(); if ($user_tmp->getField('locations_id')) { $tmp['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id')); } else { $tmp['##author.location##'] = ''; } if ($user_tmp->getField('usertitles_id')) { $tmp['##author.title##'] = Dropdown::getDropdownName('glpi_usertitles', $user_tmp->getField('usertitles_id')); } else { $tmp['##author.title##'] = ''; } if ($user_tmp->getField('usercategories_id')) { $tmp['##author.category##'] = Dropdown::getDropdownName('glpi_usercategories', $user_tmp->getField('usercategories_id')); } else { $tmp['##author.category##'] = ''; } $tmp['##author.email##'] = $user_tmp->getDefaultEmail(); $tmp['##author.mobile##'] = $user_tmp->getField('mobile'); $tmp['##author.phone##'] = $user_tmp->getField('phone'); $tmp['##author.phone2##'] = $user_tmp->getField('phone2'); $datas['authors'][] = $tmp; } else { // Anonymous users only in xxx.authors, not in authors $users[] = $tmpusr['alternative_email']; } } $datas["##{$objettype}.authors##"] = implode(', ', $users); } $datas["##{$objettype}.openbyuser##"] = ''; if ($item->getField('users_id_recipient')) { $user_tmp = new User(); $user_tmp->getFromDB($item->getField('users_id_recipient')); $datas["##{$objettype}.openbyuser##"] = $user_tmp->getName(); } $datas["##{$objettype}.lastupdater##"] = ''; if ($item->getField('users_id_lastupdater')) { $user_tmp = new User(); $user_tmp->getFromDB($item->getField('users_id_lastupdater')); $datas["##{$objettype}.lastupdater##"] = $user_tmp->getName(); } $datas["##{$objettype}.assigntousers##"] = ''; if ($item->countUsers(CommonITILActor::ASSIGN)) { $users = array(); foreach ($item->getUsers(CommonITILActor::ASSIGN) as $tmp) { $uid = $tmp['users_id']; $user_tmp = new User(); if ($user_tmp->getFromDB($uid)) { $users[$uid] = $user_tmp->getName(); } } $datas["##{$objettype}.assigntousers##"] = implode(', ', $users); } $datas["##{$objettype}.assigntosupplier##"] = ''; if ($item->countSuppliers(CommonITILActor::ASSIGN)) { $suppliers = array(); foreach ($item->getSuppliers(CommonITILActor::ASSIGN) as $tmp) { $uid = $tmp['suppliers_id']; $supplier_tmp = new Supplier(); if ($supplier_tmp->getFromDB($uid)) { $suppliers[$uid] = $supplier_tmp->getName(); } } $datas["##{$objettype}.assigntosupplier##"] = implode(', ', $suppliers); } $datas["##{$objettype}.groups##"] = ''; if ($item->countGroups(CommonITILActor::REQUESTER)) { $groups = array(); foreach ($item->getGroups(CommonITILActor::REQUESTER) as $tmp) { $gid = $tmp['groups_id']; $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $datas["##{$objettype}.groups##"] = implode(', ', $groups); } $datas["##{$objettype}.observergroups##"] = ''; if ($item->countGroups(CommonITILActor::OBSERVER)) { $groups = array(); foreach ($item->getGroups(CommonITILActor::OBSERVER) as $tmp) { $gid = $tmp['groups_id']; $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $datas["##{$objettype}.observergroups##"] = implode(', ', $groups); } $datas["##{$objettype}.observerusers##"] = ''; if ($item->countUsers(CommonITILActor::OBSERVER)) { $users = array(); foreach ($item->getUsers(CommonITILActor::OBSERVER) as $tmp) { $uid = $tmp['users_id']; $user_tmp = new User(); if ($uid && $user_tmp->getFromDB($uid)) { $users[] = $user_tmp->getName(); } else { $users[] = $tmp['alternative_email']; } } $datas["##{$objettype}.observerusers##"] = implode(', ', $users); } $datas["##{$objettype}.assigntogroups##"] = ''; if ($item->countGroups(CommonITILActor::ASSIGN)) { $groups = array(); foreach ($item->getGroups(CommonITILActor::ASSIGN) as $tmp) { $gid = $tmp['groups_id']; $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $datas["##{$objettype}.assigntogroups##"] = implode(', ', $groups); } $datas["##{$objettype}.solution.type##"] = ''; if ($item->getField('solutiontypes_id')) { $datas["##{$objettype}.solution.type##"] = Dropdown::getDropdownName('glpi_solutiontypes', $item->getField('solutiontypes_id')); } $datas["##{$objettype}.solution.description##"] = Toolbox::unclean_cross_side_scripting_deep($item->getField('solution')); // Complex mode if (!$simple) { $datas['log'] = array(); // Use list_limit_max or load the full history ? foreach (Log::getHistoryData($item, 0, $CFG_GLPI['list_limit_max']) as $data) { $tmp = array(); $tmp["##{$objettype}.log.date##"] = $data['date_mod']; $tmp["##{$objettype}.log.user##"] = $data['user_name']; $tmp["##{$objettype}.log.field##"] = $data['field']; $tmp["##{$objettype}.log.content##"] = $data['change']; $datas['log'][] = $tmp; } $datas["##{$objettype}.numberoflogs##"] = count($datas['log']); // Get unresolved items $restrict = "`" . $item->getTable() . "`.`status`\n NOT IN ('" . implode("', '", array_merge($item->getSolvedStatusArray(), $item->getClosedStatusArray())) . "'\n )"; if ($item->maybeDeleted()) { $restrict .= " AND `" . $item->getTable() . "`.`is_deleted` = '0' "; } $datas["##{$objettype}.numberofunresolved##"] = countElementsInTableForEntity($item->getTable(), $this->getEntity(), $restrict); // Document $query = "SELECT `glpi_documents`.*\n FROM `glpi_documents`\n LEFT JOIN `glpi_documents_items`\n ON (`glpi_documents`.`id` = `glpi_documents_items`.`documents_id`)\n WHERE `glpi_documents_items`.`itemtype` = '" . $item->getType() . "'\n AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'"; $datas["documents"] = array(); $addtodownloadurl = ''; if ($item->getType() == 'Ticket') { $addtodownloadurl = "%2526tickets_id=" . $item->fields['id']; } if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $tmp = array(); $tmp['##document.id##'] = $data['id']; $tmp['##document.name##'] = $data['name']; $tmp['##document.weblink##'] = $data['link']; $tmp['##document.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "document_" . $data['id']); $downloadurl = "/front/document.send.php?docid=" . $data['id']; $tmp['##document.downloadurl##'] = $this->formatURL($options['additionnaloption']['usertype'], $downloadurl . $addtodownloadurl); $tmp['##document.heading##'] = Dropdown::getDropdownName('glpi_documentcategories', $data['documentcategories_id']); $tmp['##document.filename##'] = $data['filename']; $datas['documents'][] = $tmp; } } $datas["##{$objettype}.urldocument##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . '_Document_Item$1'); $datas["##{$objettype}.numberofdocuments##"] = count($datas['documents']); //costs infos $costtype = $item->getType() . 'Cost'; $costs = $costtype::getCostsSummary($costtype, $item->getField("id")); $datas["##{$objettype}.costfixed##"] = $costs['costfixed']; $datas["##{$objettype}.costmaterial##"] = $costs['costmaterial']; $datas["##{$objettype}.costtime##"] = $costs['costtime']; $datas["##{$objettype}.totalcost##"] = $costs['totalcost']; $restrict = "`" . $item->getForeignKeyField() . "`='" . $item->getField('id') . "'"; $restrict .= " ORDER BY `begin_date` DESC, `id` ASC"; $costs = getAllDatasFromTable(getTableForItemType($costtype), $restrict); $datas['costs'] = array(); foreach ($costs as $cost) { $tmp = array(); $tmp['##cost.name##'] = $cost['name']; $tmp['##cost.comment##'] = $cost['comment']; $tmp['##cost.datebegin##'] = Html::convDate($cost['begin_date']); $tmp['##cost.dateend##'] = Html::convDate($cost['end_date']); $tmp['##cost.time##'] = $item->getActionTime($cost['actiontime']); $tmp['##cost.costtime##'] = Html::formatNumber($cost['cost_time']); $tmp['##cost.costfixed##'] = Html::formatNumber($cost['cost_fixed']); $tmp['##cost.costmaterial##'] = Html::formatNumber($cost['cost_material']); $tmp['##cost.totalcost##'] = CommonITILCost::computeTotalCost($cost['actiontime'], $cost['cost_time'], $cost['cost_fixed'], $cost['cost_material']); $tmp['##cost.budget##'] = Dropdown::getDropdownName('glpi_budgets', $cost['budgets_id']); $datas['costs'][] = $tmp; } $datas["##{$objettype}.numberofcosts##"] = count($datas['costs']); //Task infos $tasktype = $item->getType() . 'Task'; $taskobj = new $tasktype(); $restrict = "`" . $item->getForeignKeyField() . "`='" . $item->getField('id') . "'"; if ($taskobj->maybePrivate() && (!isset($options['additionnaloption']['show_private']) || !$options['additionnaloption']['show_private'])) { $restrict .= " AND `is_private` = '0'"; } $restrict .= " ORDER BY `date` DESC, `id` ASC"; $tasks = getAllDatasFromTable($taskobj->getTable(), $restrict); $datas['tasks'] = array(); foreach ($tasks as $task) { $tmp = array(); $tmp['##task.id##'] = $task['id']; if ($taskobj->maybePrivate()) { $tmp['##task.isprivate##'] = Dropdown::getYesNo($task['is_private']); } $tmp['##task.author##'] = Html::clean(getUserName($task['users_id'])); $tmp_taskcatinfo = Dropdown::getDropdownName('glpi_taskcategories', $task['taskcategories_id'], true, true, false); $tmp['##task.categoryid##'] = $task['taskcategories_id']; $tmp['##task.category##'] = $tmp_taskcatinfo['name']; $tmp['##task.categorycomment##'] = $tmp_taskcatinfo['comment']; $tmp['##task.date##'] = Html::convDateTime($task['date']); $tmp['##task.description##'] = $task['content']; $tmp['##task.time##'] = Ticket::getActionTime($task['actiontime']); $tmp['##task.status##'] = Planning::getState($task['state']); $tmp['##task.user##'] = Html::clean(getUserName($task['users_id_tech'])); $tmp['##task.group##'] = Html::clean(Toolbox::clean_cross_side_scripting_deep(Dropdown::getDropdownName("glpi_groups", $task['groups_id_tech'])), true, 2, false); $tmp['##task.begin##'] = ""; $tmp['##task.end##'] = ""; if (!is_null($task['begin'])) { $tmp['##task.begin##'] = Html::convDateTime($task['begin']); $tmp['##task.end##'] = Html::convDateTime($task['end']); } $datas['tasks'][] = $tmp; } $datas["##{$objettype}.numberoftasks##"] = count($datas['tasks']); } return $datas; }
/** * @param $item CommonDBTM object * @param $options array * @param $simple (false by default) **/ function getDatasForObject(CommonDBTM $item, array $options, $simple = false) { global $CFG_GLPI, $DB; $objettype = strtolower($item->getType()); $datas["##{$objettype}.title##"] = $item->getField('name'); $datas["##{$objettype}.content##"] = $item->getField('content'); $datas["##{$objettype}.description##"] = $item->getField('content'); $datas["##{$objettype}.id##"] = sprintf("%07d", $item->getField("id")); $datas["##{$objettype}.url##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id")); $datas["##{$objettype}.urlapprove##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . "_" . $item->getType() . '$2'); $entity = new Entity(); if ($entity->getFromDB($this->getEntity())) { $datas["##{$objettype}.entity##"] = $entity->getField('completename'); $datas["##{$objettype}.shortentity##"] = $entity->getField('name'); } $datas["##{$objettype}.storestatus##"] = $item->getField('status'); $datas["##{$objettype}.status##"] = $item->getStatus($item->getField('status')); $datas["##{$objettype}.urgency##"] = $item->getUrgencyName($item->getField('urgency')); $datas["##{$objettype}.impact##"] = $item->getImpactName($item->getField('impact')); $datas["##{$objettype}.priority##"] = $item->getPriorityName($item->getField('priority')); $datas["##{$objettype}.time##"] = $item->getActionTime($item->getField('actiontime')); $datas["##{$objettype}.creationdate##"] = Html::convDateTime($item->getField('date')); $datas["##{$objettype}.closedate##"] = Html::convDateTime($item->getField('closedate')); $datas["##{$objettype}.solvedate##"] = Html::convDateTime($item->getField('solvedate')); $datas["##{$objettype}.duedate##"] = Html::convDateTime($item->getField('due_date')); $datas["##{$objettype}.category##"] = ''; if ($item->getField('itilcategories_id')) { $datas["##{$objettype}.category##"] = Dropdown::getDropdownName('glpi_itilcategories', $item->getField('itilcategories_id')); } $datas["##{$objettype}.authors##"] = ''; $datas['authors'] = array(); if ($item->countUsers(CommonITILActor::REQUESTER)) { $users = array(); foreach ($item->getUsers(CommonITILActor::REQUESTER) as $tmpusr) { $uid = $tmpusr['users_id']; $user_tmp = new User(); if ($uid && $user_tmp->getFromDB($uid)) { $users[] = $user_tmp->getName(); $tmp = array(); $tmp['##author.id##'] = $uid; $tmp['##author.name##'] = $user_tmp->getName(); if ($user_tmp->getField('locations_id')) { $tmp['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id')); } else { $tmp['##author.location##'] = ''; } if ($user_tmp->getField('usertitles_id')) { $tmp['##author.title##'] = Dropdown::getDropdownName('glpi_usertitles', $user_tmp->getField('usertitles_id')); } else { $tmp['##author.title##'] = ''; } if ($user_tmp->getField('usercategories_id')) { $tmp['##author.category##'] = Dropdown::getDropdownName('glpi_usercategories', $user_tmp->getField('usercategories_id')); } else { $tmp['##author.category##'] = ''; } $tmp['##author.email##'] = $user_tmp->getDefaultEmail(); $tmp['##author.mobile##'] = $user_tmp->getField('mobile'); $tmp['##author.phone##'] = $user_tmp->getField('phone'); $tmp['##author.phone2##'] = $user_tmp->getField('phone2'); $datas['authors'][] = $tmp; } else { // Anonymous users only in xxx.authors, not in authors $users[] = $tmpusr['alternative_email']; } } $datas["##{$objettype}.authors##"] = implode(', ', $users); } $datas["##{$objettype}.openbyuser##"] = ''; if ($item->getField('users_id_recipient')) { $user_tmp = new User(); $user_tmp->getFromDB($item->getField('users_id_recipient')); $datas["##{$objettype}.openbyuser##"] = $user_tmp->getName(); } $datas["##{$objettype}.lastupdater##"] = ''; if ($item->getField('users_id_lastupdater')) { $user_tmp = new User(); $user_tmp->getFromDB($item->getField('users_id_lastupdater')); $datas["##{$objettype}.lastupdater##"] = $user_tmp->getName(); } $datas["##{$objettype}.assigntousers##"] = ''; if ($item->countUsers(CommonITILActor::ASSIGN)) { $users = array(); foreach ($item->getUsers(CommonITILActor::ASSIGN) as $tmp) { $uid = $tmp['users_id']; $user_tmp = new User(); if ($user_tmp->getFromDB($uid)) { $users[$uid] = $user_tmp->getName(); } } $datas["##{$objettype}.assigntousers##"] = implode(', ', $users); } $datas["##{$objettype}.assigntosupplier##"] = ''; if ($item->countSuppliers(CommonITILActor::ASSIGN)) { $suppliers = array(); foreach ($item->getSuppliers(CommonITILActor::ASSIGN) as $tmp) { $uid = $tmp['suppliers_id']; $supplier_tmp = new Supplier(); if ($supplier_tmp->getFromDB($uid)) { $suppliers[$uid] = $supplier_tmp->getName(); } } $datas["##{$objettype}.assigntosupplier##"] = implode(', ', $suppliers); } $datas["##{$objettype}.groups##"] = ''; if ($item->countGroups(CommonITILActor::REQUESTER)) { $groups = array(); foreach ($item->getGroups(CommonITILActor::REQUESTER) as $tmp) { $gid = $tmp['groups_id']; $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $datas["##{$objettype}.groups##"] = implode(', ', $groups); } $datas["##{$objettype}.observergroups##"] = ''; if ($item->countGroups(CommonITILActor::OBSERVER)) { $groups = array(); foreach ($item->getGroups(CommonITILActor::OBSERVER) as $tmp) { $gid = $tmp['groups_id']; $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $datas["##{$objettype}.observergroups##"] = implode(', ', $groups); } $datas["##{$objettype}.observerusers##"] = ''; if ($item->countUsers(CommonITILActor::OBSERVER)) { $users = array(); foreach ($item->getUsers(CommonITILActor::OBSERVER) as $tmp) { $uid = $tmp['users_id']; $user_tmp = new User(); if ($uid && $user_tmp->getFromDB($uid)) { $users[] = $user_tmp->getName(); } else { $users[] = $tmp['alternative_email']; } } $datas["##{$objettype}.observerusers##"] = implode(', ', $users); } $datas["##{$objettype}.assigntogroups##"] = ''; if ($item->countGroups(CommonITILActor::ASSIGN)) { $groups = array(); foreach ($item->getGroups(CommonITILActor::ASSIGN) as $tmp) { $gid = $tmp['groups_id']; $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $datas["##{$objettype}.assigntogroups##"] = implode(', ', $groups); } $datas["##{$objettype}.solution.type##"] = ''; if ($item->getField('solutiontypes_id')) { $datas["##{$objettype}.solution.type##"] = Dropdown::getDropdownName('glpi_solutiontypes', $item->getField('solutiontypes_id')); } $datas["##{$objettype}.solution.description##"] = Toolbox::unclean_cross_side_scripting_deep($item->getField('solution')); $datas['log'] = array(); // Use list_limit_max or load the full history ? foreach (Log::getHistoryData($item, 0, $CFG_GLPI['list_limit_max']) as $data) { $tmp = array(); $tmp["##{$objettype}.log.date##"] = $data['date_mod']; $tmp["##{$objettype}.log.user##"] = $data['user_name']; $tmp["##{$objettype}.log.field##"] = $data['field']; $tmp["##{$objettype}.log.content##"] = $data['change']; $datas['log'][] = $tmp; } $datas["##{$objettype}.numberoflogs##"] = count($datas['log']); // Get unresolved items $restrict = "`" . $item->getTable() . "`.`status`\n NOT IN ('" . implode("', '", array_merge($item->getSolvedStatusArray(), $item->getClosedStatusArray())) . "'\n )"; if ($item->maybeDeleted()) { $restrict .= " AND `" . $item->getTable() . "`.`is_deleted` = '0' "; } $datas["##{$objettype}.numberofunresolved##"] = countElementsInTableForEntity($item->getTable(), $this->getEntity(), $restrict); // Document $query = "SELECT `glpi_documents`.*\n FROM `glpi_documents`\n LEFT JOIN `glpi_documents_items`\n ON (`glpi_documents`.`id` = `glpi_documents_items`.`documents_id`)\n WHERE `glpi_documents_items`.`itemtype` = '{$objettype}'\n AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'"; $datas["documents"] = array(); if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $tmp = array(); $tmp['##document.id##'] = $data['id']; $tmp['##document.name##'] = $data['name']; $tmp['##document.weblink##'] = $data['link']; $tmp['##document.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "document_" . $data['id']); $tmp['##document.heading##'] = Dropdown::getDropdownName('glpi_documentcategories', $data['documentcategories_id']); $tmp['##document.filename##'] = $data['filename']; $datas['documents'][] = $tmp; } } $datas["##{$objettype}.urldocument##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . '_Document_Item$1'); $datas["##{$objettype}.numberofdocuments##"] = count($datas['documents']); return $datas; }
static function showImport($row_num, $item_num, $line, $output_type, $configID, $status, $imported) { global $DB, $CFG_GLPI; $infocom = new Infocom(); $canedit = Session::haveRight(static::$rightname, UPDATE) && $infocom->canUpdate(); $config = new PluginManufacturersimportsConfig(); $config->getFromDB($configID); $suppliername = $config->fields["name"]; $supplierUrl = $config->fields["supplier_url"]; $supplierId = $config->fields["suppliers_id"]; $supplierWarranty = $config->fields["warranty_duration"]; $supplierkey = $config->fields["supplier_key"]; $supplierclass = "PluginManufacturersimports" . $suppliername; $supplier = new $supplierclass(); $row_num++; if ($suppliername) { $model = new PluginManufacturersimportsModel(); $otherSerial = $model->checkIfModelNeeds($line["itemtype"], $line["id"]); echo Search::showNewLine($output_type, $row_num % 2); $ic = new Infocom(); $output_check = ""; if ($canedit && $output_type == Search::HTML_OUTPUT) { $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } $output_check = $supplier->showCheckbox($line["id"], $sel, $otherSerial); } echo Search::showItem($output_type, $output_check, $item_num, $row_num); $link = Toolbox::getItemTypeFormURL($line["itemtype"]); $ID = ""; if ($_SESSION["glpiis_ids_visible"] || empty($line["name"])) { $ID .= " (" . $line["id"] . ")"; } $output_link = "<a href='" . $link . "?id=" . $line["id"] . "'>" . $line["name"] . $ID . "</a><br>" . $line["model_name"]; echo Search::showItem($output_type, $output_link, $item_num, $row_num); if (Session::isMultiEntitiesMode()) { echo Search::showItem($output_type, Dropdown::getDropdownName("glpi_entities", $line['entities_id']), $item_num, $row_num); } $url = self::selectSupplier($suppliername, $line["serial"], $otherSerial, $supplierkey); //serial echo Search::showItem($output_type, $line["serial"], $item_num, $row_num); //otherserial echo $supplier->showItem($output_type, $otherSerial, $item_num, $row_num); //display infocoms $output_ic = ""; if ($ic->getfromDBforDevice($line["itemtype"], $line["id"])) { $output_ic .= _n('Supplier', 'Suppliers', 1) . ":" . Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]) . "<br>"; $output_ic .= __('Date of purchase') . " : " . Html::convdate($ic->fields["buy_date"]) . "<br>"; $output_ic .= __('Start date of warranty') . ":" . Html::convdate($ic->fields["warranty_date"]) . "<br>"; if ($ic->fields["warranty_duration"] == -1) { $output_ic .= __('Warranty duration') . ":" . __('Lifelong') . "<br>"; } else { $output_ic .= __('Warranty duration') . ":" . $ic->fields["warranty_duration"] . " " . __('month') . "<br>"; } $tmpdat = Infocom::getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"]); $output_ic .= sprintf(__('Valid to %s'), $tmpdat); } else { $output_ic .= ""; } echo Search::showItem($output_type, $output_ic, $item_num, $row_num); if ($imported != self::IMPORTED) { //display enterprise and warranty selection echo "<td>"; if (Session::isMultiEntitiesMode() && $supplierId) { $item = new Supplier(); $item->getFromDB($supplierId); if ($item->fields["is_recursive"] || $item->fields["entities_id"] == $line['entities_id']) { Dropdown::show('Supplier', array('name' => "to_suppliers_id" . $line["id"], 'value' => $supplierId, 'comments' => 0, 'entity' => $line['entities_id'])); } else { echo "<span class='plugin_manufacturersimports_import_KO'>"; echo __('The choosen supplier is not recursive', 'manufacturersimports') . "</span>"; echo "<input type='hidden' name='to_suppliers_id" . $line["id"] . "' value='-1'>"; } } else { Dropdown::show('Supplier', array('name' => "to_suppliers_id" . $line["id"], 'value' => $supplierId, 'comments' => 0, 'entity' => $line['entities_id'])); } echo "</td>"; $supplier->showWarrantyItem($line["id"], $supplierWarranty); } else { //display enterprise and warranty selection echo "<td>" . Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]) . "</td>"; if ($ic->fields["warranty_duration"] == -1) { echo "<td>" . __('Lifelong') . "</td>"; } else { echo "<td>" . $ic->fields["warranty_duration"] . "</td>"; } } //supplier url //url to supplier $output_url = "<a href='" . $url . "' target='_blank'>" . __('Manufacturer information', 'manufacturersimports') . "</a>"; echo Search::showItem($output_type, $output_url, $item_num, $row_num); //status if ($imported != self::IMPORTED) { if ($status != 2) { $output_doc = __('Not yet imported', 'manufacturersimports'); } else { $output_doc = "<span class='plugin_manufacturersimports_import_KO'>" . __('Problem during the importation', 'manufacturersimports'); if (!empty($data["date_import"])) { $output_doc .= " (" . Html::convdate($data["date_import"]) . ")"; } $output_doc .= "</span>"; } } else { $output_doc = "<span class='plugin_manufacturersimports_import_OK'>" . __('Already imported', 'manufacturersimports'); if (!empty($line["date_import"])) { $output_doc .= " (" . Html::convdate($line["date_import"]) . ")"; } $output_doc .= "</span>"; } echo Search::showItem($output_type, $output_doc, $item_num, $row_num); //no associated doc echo $supplier->showDocItem($output_type, $item_num, $row_num, $line["documents_id"]); } }