public static function processDatafeed(Supplier $supplier, array $data) { $base = dirname(__FILE__); if (file_exists($file_name = $base . '/datafeed/' . strtolower($supplier->getName()) . '.php') === true) { require_once $file_name; } $class = ucfirst($supplier->getName()) . 'Connector'; return $class::run($data); }
/** * TreeUpdate constructor. * * @param Channel $chan * @param array $updateData */ public function __construct(Channel $chan, array $updateData) { /** * This represents data from the base64urlsafe encoded JSON blob that is signed by the channel. */ $this->channelId = (int) $updateData['id']; $this->channelName = $chan->getName(); $this->merkleRoot = $updateData['root']; $this->stored = $updateData['stored']; $this->action = $this->stored['action']; $packageRelatedActions = [self::ACTION_CORE_UPDATE, self::ACTION_PACKAGE_UPDATE]; if (\in_array($this->action, $packageRelatedActions)) { // This is a package-related update: $this->checksum = $this->stored['checksum']; // This is the JSON message from the tree node, stored as an array: $data = \json_decode($updateData['data'], true); $this->updateMessage = $data; // What action are we performing? if ($this->action === self::ACTION_PACKAGE_UPDATE) { $this->packageType = $data['pkg_type']; $this->packageName = $data['name']; } else { $this->packageType = 'Core'; $this->packageName = 'Airship'; } if ($this->action === self::ACTION_CORE_UPDATE) { $state = State::instance(); $trustedSupplier = (string) ($state->universal['airship']['trusted-supplier'] ?? 'paragonie'); $this->supplier = $chan->getSupplier($trustedSupplier); } else { $this->supplier = $chan->getSupplier($data['supplier']); } } else { // This is a key-related update: if (!empty($updateData['master_signature'])) { $this->masterSig = $updateData['master_signature']; } $data = \json_decode($updateData['data'], true); try { $this->unpackMessageUpdate($chan, $data); } catch (NoSupplier $ex) { $this->isNewSupplier = true; $chan->createSupplier($data); $this->supplier = $chan->getSupplier($data['supplier']); } $this->keyType = $data['type']; $this->newPublicKey = $data['public_key']; } $this->supplierName = $this->supplier->getName(); }
/** * 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(); }
$mlistchunk = explode('<||>', $miscitems); $j = 0; for ($i = 0; $i < count($mlistchunk); $i++) { $dqr_list[$j] = explode('<|>', $mlistchunk[$i]); $j++; } $supp = new Supplier(); $supp->setSID($_POST['Supplier_ID']); $supp->setSupplierDetails(); $pdf = new PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); //$pdf->AliasNbPages(); $pdf->setAutoPageBreak(TRUE, 45); $pdf->AddPage('P', 'A4'); $pdf->SetFont('helvetica', 'B', 13); $pdf->SetY(56); $pdf->Cell(125, 8, $supp->getName(), 0, 0, 'L'); $pdf->SetFont('helvetica', 'B', 14); $pdf->Cell(100, 8, "DC NO: {$dcno}", 0, 1, 'L'); $pdf->SetFont('helvetica', '', 13); $pdf->Cell(125, 8, $supp->getAddressl1(), 0, 0, 'L'); $pdf->Cell(100, 8, "Date: {$dcdate}", 0, 1, 'L'); $pdf->Cell(125, 8, $supp->getAddressl2(), 0, 0, 'L'); $pdf->Cell(100, 8, "Your Ref: {$cref}", 0, 1, 'L'); $pdf->Cell(125, 8, "Phone No: " . $supp->getPhoneNo(), 0, 0, 'L'); $pdf->Cell(100, 8, "Date: {$crefdate}", 0, 1, 'L'); $pdf->ln(); $pdf->line(0, 87, 220, 87); //line before mode of dispatch $pdf->setY(86); $pdf->MultiCell(125, 16, "Please receive the following materials and acknowledge the receipt", 0, 'L', 0, 0, '', '', true, 0, false, true, 16, 'M', true); $pdf->Cell(100, 8, "Mode Of Dispatch: {$dmode}", 0, 1, 'L');
/** * Show webapplications associated to an item * * @since version 0.84 * * @param $item Supplier object for which associated webapplications must be displayed * @param $withtemplate (default '') **/ static function showForSupplier(Supplier $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!Session::haveRight("plugin_webapplications", READ)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_entities`.`id` AS entity,\n `glpi_plugin_webapplications_webapplications`.`id` AS assocID,\n `glpi_plugin_webapplications_webapplications`.`name` AS assocName,\n `glpi_plugin_webapplications_webapplications`.*\n FROM `glpi_plugin_webapplications_webapplications`\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_webapplications_webapplications`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_webapplications_webapplications`.`suppliers_id` = '{$ID}' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_webapplications_webapplications", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $webs = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $webs[$data['assocID']] = $data; } } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . PluginWebapplicationsWebapplicationType::getTypeName(1) . "</th>"; echo "<th>" . __('URL') . "</th>"; echo "<th>" . __('Server') . "</th>"; echo "<th>" . __('Language') . "</th>"; echo "<th>" . __('Version') . "</th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginWebapplicationsWebapplication', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); $web = new PluginWebapplicationsWebapplication(); foreach ($webs as $data) { $webID = $data["id"]; $link = NOT_AVAILABLE; if ($web->getFromDB($webID)) { $link = $web->getLink(); } Session::addToNavigateListItems('PluginWebapplicationsWebapplication', $webID); $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtypes", $data["plugin_webapplications_webapplicationtypes_id"]) . "</td>"; $link = Toolbox::substr($data["address"], 0, 30) . "..."; echo "<td class='center'>" . "<a href=\"" . str_replace("&", "&", $data["address"]) . "\" target=\"_blank\">" . "<u>" . $link . "</u></a></td>"; echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationservertypes", $data["plugin_webapplications_webapplicationservertypes_id"]) . "</td>"; echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtechnics", $data["plugin_webapplications_webapplicationtechnics_id"]) . "</td>"; echo "<td>" . $data["version"] . "</td>"; echo "<td>" . $data["comment"] . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; echo "</div>"; }
} if (isset($_POST['previewok'])) { $previewok = $_POST['previewok']; } else { $previewok = ''; } if (isset($_POST['opid'])) { $po->setValue('potermid', $_POST['opid']); $potermid = $_POST['opid']; } $popath = '/home/www/divyaeng2/popdfs/'; // $popath='/www/divyaeng2/popdfs/'; $supp = new Supplier(); $supp->setSID($_POST['Supplier_ID']); $supp->setSupplierDetails(); $sname = $supp->getName(); $addli = $supp->getAddressl1(); $addl2 = $supp->getAddressl2(); $phoneno = $supp->getPhoneNo(); class PDF extends TCPDF { // Page header function Header() { $sname = $GLOBALS['sname']; $addli = $GLOBALS['addli']; $addl2 = $GLOBALS['addl2']; $podate = $GLOBALS['podate']; $suppref = $GLOBALS['suppref']; $phoneno = $GLOBALS['phoneno']; $supprefdate = $GLOBALS['supprefdate'];
/** * 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)); } } }
/** * Show contacts asociated to an enterprise **/ static function showForSupplier(Supplier $supplier) { global $DB, $CFG_GLPI; $instID = $supplier->fields['id']; if (!$supplier->can($instID, READ)) { return false; } $canedit = $supplier->can($instID, UPDATE); $rand = mt_rand(); $query = "SELECT `glpi_contacts`.*,\n `glpi_contacts_suppliers`.`id` AS ID_ent,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contacts_suppliers`, `glpi_contacts`\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contacts`.`entities_id`)\n WHERE `glpi_contacts_suppliers`.`contacts_id`=`glpi_contacts`.`id`\n AND `glpi_contacts_suppliers`.`suppliers_id` = '{$instID}'" . getEntitiesRestrictRequest(" AND", "glpi_contacts", '', '', true) . "\n ORDER BY `glpi_entities`.`completename`, `glpi_contacts`.`name`"; $result = $DB->query($query); $contacts = array(); $used = array(); if ($number = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $contacts[$data['ID_ent']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='contactsupplier_form{$rand}' id='contactsupplier_form{$rand}'\n method='post' action='"; echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . __('Add a contact') . "</tr>"; echo "<tr class='tab_bg_2'><td class='center'>"; echo "<input type='hidden' name='suppliers_id' value='{$instID}'>"; Contact::dropdown(array('used' => $used, 'entity' => $supplier->fields["entities_id"], 'entity_sons' => $supplier->fields["is_recursive"])); 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, '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) { $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>" . __('Phone') . "</th>"; $header_end .= "<th>" . __('Phone 2') . "</th>"; $header_end .= "<th>" . __('Mobile phone') . "</th>"; $header_end .= "<th>" . __('Fax') . "</th>"; $header_end .= "<th>" . _n('Email', 'Emails', 1) . "</th>"; $header_end .= "<th>" . __('Type') . "</th>"; $header_end .= "</tr>"; echo $header_begin . $header_top . $header_end; $used = array(); if ($number) { Session::initNavigateListItems('Contact', sprintf(__('%1$s = %2$s'), Supplier::getTypeName(1), $supplier->getName())); foreach ($contacts as $data) { $ID = $data["ID_ent"]; $used[$data["id"]] = $data["id"]; Session::addToNavigateListItems('Contact', $data["id"]); echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["ID_ent"]) . "</td>"; } echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contact.form.php?id=" . $data["id"] . "'>" . sprintf(__('%1$s %2$s'), $data["name"], $data["firstname"]) . "</a></td>"; echo "<td class='center' width='100'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "</td>"; echo "<td class='center' width='100'>" . $data["phone"] . "</td>"; echo "<td class='center' width='100'>" . $data["phone2"] . "</td>"; echo "<td class='center' width='100'>" . $data["mobile"] . "</td>"; echo "<td class='center' width='100'>" . $data["fax"] . "</td>"; echo "<td class='center'>"; echo "<a href='mailto:" . $data["email"] . "'>" . $data["email"] . "</a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contacttypes", $data["contacttypes_id"]) . "</td>"; echo "</tr>"; } echo $header_begin . $header_bottom . $header_end; } echo "</table>"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * @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; }