/** Show groups of a user * * @param $user User object **/ static function showForUser(User $user) { global $CFG_GLPI; $ID = $user->fields['id']; if (!Group::canView() || !$user->can($ID, READ)) { return false; } $canedit = $user->can($ID, UPDATE); $rand = mt_rand(); $groups = self::getUserGroups($ID); $used = array(); if (!empty($groups)) { foreach ($groups as $data) { $used[$data["id"]] = $data["id"]; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='groupuser_form{$rand}' id='groupuser_form{$rand}' method='post'"; echo " action='" . Toolbox::getItemTypeFormURL('User') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Associate to a group') . "</th></tr>"; echo "<tr class='tab_bg_2'><td class='center'>"; echo "<input type='hidden' name='users_id' value='{$ID}'>"; // All entities "edited user" have access $strict_entities = Profile_User::getUserEntities($ID, true); // Keep only entities "connected user" have access foreach ($strict_entities as $key => $val) { if (!Session::haveAccessToEntity($val)) { unset($strict_entities[$key]); } } $nb = countElementsInTableForEntity("glpi_groups", $strict_entities, '`is_usergroup`'); if ($nb > count($used)) { Group::dropdown(array('entity' => $strict_entities, 'used' => $used, 'condition' => '`is_usergroup`')); echo "</td><td>" . __('Manager') . "</td><td>"; Dropdown::showYesNo('is_manager'); echo "</td><td>" . __('Delegatee') . "</td><td>"; Dropdown::showYesNo('is_userdelegate'); echo "</td><td class='tab_bg_2 center'>"; echo "<input type='submit' name='addgroup' value=\"" . _sx('button', 'Add') . "\"\n class='submit'>"; } else { _e('None'); } echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && count($used)) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); echo "<input type='hidden' name='users_id' value='" . $user->fields['id'] . "'>"; $massiveactionparams = array('num_displayed' => count($used), 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov table-striped table-hover'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && count($used)) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } $header_end .= "<th>" . Group::getTypeName(1) . "</th>"; $header_end .= "<th>" . __('Dynamic') . "</th>"; $header_end .= "<th>" . __('Manager') . "</th>"; $header_end .= "<th>" . __('Delegatee') . "</th></tr>"; echo $header_begin . $header_top . $header_end; $group = new Group(); if (!empty($groups)) { Session::initNavigateListItems('Group', sprintf(__('%1$s = %2$s'), User::getTypeName(1), $user->getName())); foreach ($groups as $data) { if (!$group->getFromDB($data["id"])) { continue; } Session::addToNavigateListItems('Group', $data["id"]); echo "<tr class='tab_bg_1'>"; if ($canedit && count($used)) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]); echo "</td>"; } $link = $data["completename"]; if ($_SESSION["glpiis_ids_visible"]) { $link = sprintf(__('%1$s (%2$s)'), $link, $data["id"]); } $href = "<a href='" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["id"] . "'>" . $link . "</a>"; if ($data["is_dynamic"]) { $href = sprintf(__('%1$s (%2$s)'), $href, "<span class='b'>" . __('D') . "</span>"); } echo "<td>" . $group->getLink() . "</td>"; echo "<td class='center'>"; if ($data['is_dynamic']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Dynamic') . "\">"; } echo "<td class='center'>"; if ($data['is_manager']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Manager') . "\">"; } echo "</td><td class='center'>"; if ($data['is_userdelegate']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Delegatee') . "\">"; } echo "</td></tr>"; } echo $header_begin . $header_bottom . $header_end; } else { echo "<tr class='tab_bg_1'>"; echo "<td colspan='5' class='center'>" . __('None') . "</td></tr>"; } echo "</table>"; if ($canedit && count($used)) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * get SQL condition for filtered dropdown assign groups * @param int $tickets_id * @param int $itilcategories_id * @return string */ static function getSQLCondition($tickets_id, $itilcategories_id) { $ticket = new Ticket(); $group = new Group(); $params = array('entities_id' => $_SESSION['glpiactive_entity'], 'is_recursive' => 1); if (!empty($tickets_id) && $ticket->getFromDB($tickets_id)) { // == UPDATE EXISTING TICKET == $params['entities_id'] = $ticket->fields['entities_id']; $params['condition'] = " AND " . ($ticket->fields['type'] == Ticket::DEMAND_TYPE ? "`is_request`='1'" : "`is_incident`='1'"); } $found_groups = self::getGroupsForCategory($itilcategories_id, $params); $groups_id_toshow = array(); //init if (!empty($found_groups)) { for ($lvl = 1; $lvl <= 4; $lvl++) { if (isset($found_groups['groups_id_level' . $lvl])) { if ($found_groups['groups_id_level' . $lvl] === "all") { foreach (PluginItilcategorygroupsGroup_Level::getAllGroupForALevel($lvl, $params['entities_id']) as $groups_id) { if ($group->getFromDB($groups_id)) { $groups_id_toshow[] = $group->getID(); } } } else { foreach ($found_groups['groups_id_level' . $lvl] as $groups_id) { if (countElementsInTableForEntity("glpi_groups", $ticket->getEntityID(), "`id`='{$groups_id}'") > 0) { $group->getFromDB($groups_id); $groups_id_toshow[] = $group->getID(); } } } } } } $condition = ""; if (count($groups_id_toshow) > 0) { // transform found groups (2 dimensions) in a flat array $groups_id_toshow_flat = array(); array_walk_recursive($groups_id_toshow, function ($v, $k) use(&$groups_id_toshow_flat) { array_push($groups_id_toshow_flat, $v); }); $newarray = implode(", ", $groups_id_toshow_flat); $condition = " id IN ({$newarray})"; } return $condition; }
/** * @covers ::countElementsInTableForEntity */ public function testCountElementsInTableForEntity() { $e = getItemByTypeName('Entity', '_test_child_1', true); $this->assertEquals(2, countElementsInTableForEntity('glpi_computers', $e)); $this->assertEquals(1, countElementsInTableForEntity('glpi_computers', $e, 'name="_test_pc11"')); $this->assertEquals(0, countElementsInTableForEntity('glpi_computers', $e, 'name="_test_pc01"')); $e = getItemByTypeName('Entity', '_test_root_entity', true); $this->assertEquals(1, countElementsInTableForEntity('glpi_computers', $e, 'name="_test_pc01"')); }
public function transfer($ID, $entity) { global $DB; if ($ID <= 0 || !$this->getFromDB($ID)) { return 0; } //If reference is not visible in the target entity : transfer it! if (!countElementsInTableForEntity($this->getTable(), $entity, "`id`='" . $this->getID() . "'")) { $input = $this->fields; $input['entities_id'] = $entity; $oldref = $input['id']; unset($input['id']); $input['transfert'] = 1; $newid = $this->add($input); $reference_supplier = new PluginOrderReference_Supplier(); $reference_supplier->getFromDBByReference($oldref); $input = $reference_supplier->fields; $input['entities_id'] = $entity; $input['plugin_order_references_id'] = $newid; unset($input['id']); $reference_supplier->add($input); $PluginOrderOrder_Item = new PluginOrderOrder_Item(); $query = "SELECT `id`\n FROM `glpi_plugin_order_orders_items`\n WHERE `plugin_order_references_id` = '{$oldref}'"; $result = $DB->query($query); $num = $DB->numrows($result); if ($num) { while ($dataref = $DB->fetch_array($result)) { $values["id"] = $dataref['id']; $values["plugin_order_references_id"] = $newid; $PluginOrderOrder_Item->update($values); } } } }
/** * Print out an HTML "<select>" for a dropdown with preselected value * * @param $itemtype itemtype used for create dropdown * @param $options array of possible options: * - name : string / name of the select (default is depending itemtype) * - value : integer / preselected value (default -1) * - comments : boolean / is the comments displayed near the dropdown (default true) * - toadd : array / array of specific values to add at the begining * - entity : integer or array / restrict to a defined entity or array of entities * (default -1 : no restriction) * - entity_sons : boolean / if entity restrict specified auto select its sons * only available if entity is a single value not an array * (default false) * - toupdate : array / Update a specific item on select change on dropdown * (need value_fieldname, to_update, * url (see Ajax::updateItemOnSelectEvent for information) * and may have moreparams) * - used : array / Already used items ID: not to display in dropdown * (default empty) * - on_change : string / value to transmit to "onChange" * - rand : integer / already computed rand value * - condition : string / aditional SQL condition to limit display * - displaywith : array / array of field to display with request * - emptylabel : Empty choice's label (default self::EMPTY_VALUE) * - display_emptychoice : Display emptychoice ? (default true) * - display : boolean / display or get string (default true) * - permit_select_parent : boolean / for tree dropdown permit to see parent items not available by default (default false) * * @return boolean : false if error and random id if OK **/ static function show($itemtype, $options = array()) { global $DB, $CFG_GLPI; if ($itemtype && !($item = getItemForItemtype($itemtype))) { return false; } $table = $item->getTable(); $params['name'] = $item->getForeignKeyField(); $params['value'] = $itemtype == 'Entity' ? $_SESSION['glpiactive_entity'] : ''; $params['comments'] = true; $params['entity'] = -1; $params['entity_sons'] = false; $params['toupdate'] = ''; $params['used'] = array(); $params['toadd'] = array(); $params['on_change'] = ''; $params['condition'] = ''; $params['rand'] = mt_rand(); $params['displaywith'] = array(); //Parameters about choice 0 //Empty choice's label $params['emptylabel'] = self::EMPTY_VALUE; //Display emptychoice ? $params['display_emptychoice'] = $itemtype != 'Entity'; $params['display'] = true; $params['permit_select_parent'] = false; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } $output = ''; $name = $params['emptylabel']; $comment = ""; $limit_length = $_SESSION["glpidropdown_chars_limit"]; // Check default value for dropdown : need to be a numeric if (strlen($params['value']) == 0 || !is_numeric($params['value'])) { $params['value'] = 0; } if ($params['value'] > 0 || $itemtype == "Entity" && $params['value'] >= 0) { $tmpname = self::getDropdownName($table, $params['value'], 1); if ($tmpname["name"] != " ") { $name = $tmpname["name"]; $comment = $tmpname["comment"]; if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) { if ($item instanceof CommonTreeDropdown) { $pos = strrpos($name, ">"); $limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]); if (Toolbox::strlen($name) > $limit_length) { $name = "…" . Toolbox::substr($name, -$limit_length); } } else { $limit_length = Toolbox::strlen($name); } } else { $limit_length = $_SESSION["glpidropdown_chars_limit"]; } } } // Manage entity_sons if (!($params['entity'] < 0) && $params['entity_sons']) { if (is_array($params['entity'])) { // translation not needed - only for debug $output .= "entity_sons options is not available with entity option as array"; } else { $params['entity'] = getSonsOf('glpi_entities', $params['entity']); } } $use_ajax = false; if ($CFG_GLPI["use_ajax"]) { $nb = 0; if ($item->isEntityAssign()) { if (!($params['entity'] < 0)) { $nb = countElementsInTableForEntity($table, $params['entity'], $params['condition']); } else { $nb = countElementsInTableForMyEntities($table, $params['condition']); } } else { $nb = countElementsInTable($table, $params['condition']); } $nb -= count($params['used']); if ($nb > $CFG_GLPI["ajax_limit_count"]) { $use_ajax = true; } } $param = array('searchText' => '__VALUE__', 'value' => $params['value'], 'itemtype' => $itemtype, 'myname' => $params['name'], 'limit' => $limit_length, 'toadd' => $params['toadd'], 'comment' => $params['comments'], 'rand' => $params['rand'], 'entity_restrict' => $params['entity'], 'update_item' => $params['toupdate'], 'used' => $params['used'], 'on_change' => $params['on_change'], 'condition' => $params['condition'], 'emptylabel' => $params['emptylabel'], 'display_emptychoice' => $params['display_emptychoice'], 'displaywith' => $params['displaywith'], 'display' => false, 'permit_select_parent' => $params['permit_select_parent']); if ($item->canView()) { $param['update_link'] = 1; } $default = "<select name='" . $params['name'] . "' id='dropdown_" . $params['name'] . $params['rand'] . "'>"; $default .= "<option value='" . $params['value'] . "'>{$name}</option></select>"; $output .= Ajax::dropdown($use_ajax, "/ajax/dropdownValue.php", $param, $default, $params['rand'], false); // Display comment if ($params['comments']) { $options_tooltip = array('contentid' => "comment_" . $params['name'] . $params['rand'], 'display' => false); if ($item->canView()) { if ($params['value'] && $item->getFromDB($params['value']) && $item->canViewItem()) { $options_tooltip['link'] = $item->getLinkURL(); } else { $options_tooltip['link'] = $item->getSearchURL(); } $options_tooltip['linkid'] = "comment_link_" . $params['name'] . $params['rand']; $options_tooltip['linktarget'] = '_blank'; } $output .= Html::showToolTip($comment, $options_tooltip); if ($item instanceof CommonDropdown && $item->canCreate() && !isset($_GET['popup'])) { $output .= "<img alt='' title=\"" . __s('Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n onClick=\"var w = window.open('" . $item->getFormURL() . "?popup=1&rand=" . $params['rand'] . "' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">"; } // Display specific Links if ($itemtype == "Supplier") { if ($item->getFromDB($params['value'])) { $output .= $item->getLinks(); } } if ($itemtype == 'ITILCategory' && Session::haveRight('knowbase', 'r')) { if ($params['value'] && $item->getFromDB($params['value'])) { $output .= ' ' . $item->getLinks(); } } } if ($params['display']) { echo $output; return $params['rand']; } else { return $output; } }
/** * Print out an HTML "<select>" for a dropdown with preselected value * * @param $myname the name of the HTML select * @param $value the preselected value we want (default 0) * @param $locations_id default location ID for search (default -1) * @param $display_comment display the comment near the dropdown (default 1) * @param $entity_restrict Restrict to a defined entity(default -1) * @param $devtype (default '') * * @return nothing (display the select box) **/ static function dropdownNetpoint($myname, $value = 0, $locations_id = -1, $display_comment = 1, $entity_restrict = -1, $devtype = '') { global $CFG_GLPI; $rand = mt_rand(); $name = Dropdown::EMPTY_VALUE; $comment = ""; $limit_length = $_SESSION["glpidropdown_chars_limit"]; if (empty($value)) { $value = 0; } if ($value > 0) { $tmpname = Dropdown::getDropdownName("glpi_netpoints", $value, 1); if ($tmpname["name"] != " ") { $name = $tmpname["name"]; $comment = $tmpname["comment"]; $limit_length = max(Toolbox::strlen($name), $_SESSION["glpidropdown_chars_limit"]); } } $use_ajax = false; if ($CFG_GLPI["use_ajax"]) { if ($locations_id < 0 || $devtype == 'NetworkEquipment') { $nb = countElementsInTableForEntity("glpi_netpoints", $entity_restrict); } else { if ($locations_id > 0) { $nb = countElementsInTable("glpi_netpoints", "locations_id={$locations_id} "); } else { $nb = countElementsInTable("glpi_netpoints", "locations_id=0 " . getEntitiesRestrictRequest(" AND ", "glpi_netpoints", '', $entity_restrict)); } } if ($nb > $CFG_GLPI["ajax_limit_count"]) { $use_ajax = true; } } $params = array('searchText' => '__VALUE__', 'value' => $value, 'locations_id' => $locations_id, 'myname' => $myname, 'limit' => $limit_length, 'comment' => $display_comment, 'rand' => $rand, 'entity_restrict' => $entity_restrict, 'devtype' => $devtype); $default = "<select name='{$myname}'><option value='{$value}'>{$name}</option></select>"; Ajax::dropdown($use_ajax, "/ajax/dropdownNetpoint.php", $params, $default, $rand); // Display comment if ($display_comment) { Html::showToolTip($comment); $item = new self(); if ($item->canCreate()) { echo "<img alt='' title=\"" . __s('Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;' " . "onClick=\"var w = window.open('" . $item->getFormURL() . "?popup=1&rand={$rand}' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">"; } } return $rand; }
/** * Make a select box for connections * * @param $itemtype type to connect * @param $fromtype from where the connection is * @param $myname select name * @param $entity_restrict Restrict to a defined entity (default = -1) * @param $onlyglobal display only global devices (used for templates) (default 0) * @param $used array Already used items ID: not to display in dropdown * * @return nothing (print out an HTML select box) */ static function dropdownConnect($itemtype, $fromtype, $myname, $entity_restrict = -1, $onlyglobal = 0, $used = array()) { global $CFG_GLPI; $rand = mt_rand(); $use_ajax = false; if ($CFG_GLPI["use_ajax"]) { $nb = 0; if ($entity_restrict >= 0) { $nb = countElementsInTableForEntity(getTableForItemType($itemtype), $entity_restrict); } else { $nb = countElementsInTableForMyEntities(getTableForItemType($itemtype)); } if ($nb > $CFG_GLPI["ajax_limit_count"]) { $use_ajax = true; } } $params = array('searchText' => '__VALUE__', 'fromtype' => $fromtype, 'itemtype' => $itemtype, 'myname' => $myname, 'onlyglobal' => $onlyglobal, 'entity_restrict' => $entity_restrict, 'used' => $used); $default = "<select name='{$myname}'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option>\n </select>\n"; Ajax::dropdown($use_ajax, "/ajax/dropdownConnect.php", $params, $default, $rand); return $rand; }
/** * Show projet associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated projet must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_projet_haveRight('projet', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginProjetProjet'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_projet_projets_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_projet_projets`.`name` AS assocName,\n `glpi_plugin_projet_projets`.*\n FROM `glpi_plugin_projet_projets_items`\n LEFT JOIN `glpi_plugin_projet_projets`\n ON (`glpi_plugin_projet_projets_items`.`plugin_projet_projets_id`=`glpi_plugin_projet_projets`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_projet_projets`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_projet_projets_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_projet_projets", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $projets = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $projets[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } $projet = new PluginProjetProjet(); if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_projet_projets`\n WHERE `is_deleted` = '0'\n AND `is_template` = '0' "; if ($item->getType() != 'User') { $q .= " {$limit}"; } $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_projet_haveRight('projet', 'r') && $nb > count($used)) { echo "<form name='projet_form{$rand}' id='projet_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginProjetProjet') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } if ($item->getType() != 'User') { $projet->dropdownProjet("plugin_projet_projets_id", $entities, $used); } else { $strict_entities = Profile_User::getUserEntities($ID, true); if (!Session::haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) { $canedit = false; } if (countElementsInTableForEntity("glpi_plugin_projet_projets", $strict_entities) > count($used)) { Dropdown::show('PluginProjetProjet', array('name' => "plugin_projet_projets_id", 'used' => $used, 'entity' => $strict_entities)); } } echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a project', 'projet') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($item->getType() == "Group" || $item->getType() == "User") { echo "<tr><th colspan='" . (7 + $colsup) . "'>" . _n('Associated project', 'Associated projects', 2, 'projet') . ":</th></tr>"; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Description') . "</th>"; echo "<th>" . __('Progress') . "</th>"; echo "<th>" . __('Start date') . "</th>"; echo "<th>" . __('End date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginProjetProjet', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($projets as $data) { $projetID = $data["id"]; $link = NOT_AVAILABLE; if ($projet->getFromDB($projetID)) { $link = $projet->getLink(); } Session::addToNavigateListItems('PluginProjetProjet', $projetID); $used[$projetID] = $projetID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>"; echo "<td align='center'>" . PluginProjetProjet::displayProgressBar('100', $data["advance"]) . "</td>"; echo "<td class='center'>" . Html::convdate($data["date_begin"]) . "</td>"; if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) { echo "<td class='center'><span class='red'>" . Html::convdate($data["date_end"]) . "</span></td>"; } else { echo "<td class='center'><span class='green'>" . Html::convdate($data["date_end"]) . "</span></td>"; } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $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; }
/** Show groups of a user * * @param $user the user **/ static function showForUser(User $user) { global $CFG_GLPI, $LANG; $ID = $user->fields['id']; if (!haveRight("group", "r") || !$user->can($ID, 'r')) { return false; } $canedit = $user->can($ID, 'w'); $rand = mt_rand(); $nb_per_line = 3; if ($canedit) { $headerspan = $nb_per_line * 2; echo "<form name='groupuser_form{$rand}' id='groupuser_form{$rand}' method='post'"; echo " action='" . getItemTypeFormURL('User') . "'>"; } else { $headerspan = $nb_per_line; } $groups = self::getUserGroups($ID); $used = array(); if (!empty($groups)) { foreach ($groups as $data) { $used[$data["id"]] = $data["id"]; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . $LANG['setup'][604] . "</th></tr>"; echo "<tr><td class='tab_bg_2 center'>"; echo "<input type='hidden' name='users_id' value='{$ID}'>"; // All entities "edited user" have access $strict_entities = Profile_User::getUserEntities($ID, true); // Keep only entities "connected user" have access foreach ($strict_entities as $key => $val) { if (!haveAccessToEntity($val)) { unset($strict_entities[$key]); } } if (countElementsInTableForEntity("glpi_groups", $strict_entities) > count($used)) { Dropdown::show('Group', array('entity' => $strict_entities, 'used' => $used)); echo "</td><td class='tab_bg_2 center'>"; echo "<input type='submit' name='addgroup' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; } else { echo $LANG['common'][49]; } echo "</td></tr>"; echo "</table></div>"; } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixehov'><tr>"; echo "<th colspan='{$headerspan}'>" . $LANG['Menu'][36] . " (D=" . $LANG['profiles'][29] . ")</th>"; echo "</tr>"; if (!empty($groups)) { initNavigateListItems('Group', $user->getTypeName() . " = " . $user->getName()); $i = 0; foreach ($groups as $data) { addToNavigateListItems('Group', $data["id"]); if ($i % $nb_per_line == 0) { if ($i != 0) { echo "</tr>"; } echo "<tr class='tab_bg_1'>"; } if ($canedit) { echo "<td width='10'>"; $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1' {$sel}>"; echo "</td>"; } echo "<td><a href='" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["id"] . "'>" . $data["name"] . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["id"] . ")" : "") . "</a>"; echo " "; if ($data["is_dynamic"]) { echo "<strong> (D)</strong>"; } echo "</td>"; $i++; } while ($i % $nb_per_line != 0) { if ($canedit) { echo "<td> </td>"; } echo "<td> </td>"; $i++; } echo "</tr>"; } else { echo "<tr class='tab_bg_1'>"; echo "<td colspan='{$headerspan}' class='center'>" . $LANG['common'][49] . "</td></tr>"; } echo "</table>"; if ($canedit) { if (count($used)) { openArrowMassive("groupuser_form{$rand}", true); closeArrowMassive('deletegroup', $LANG['buttons'][6]); } echo "</form>"; } 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")); $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; }
/** * Print the HTML array for entreprises on the current contact * *@return Nothing (display) * **/ function showSuppliers() { global $DB, $CFG_GLPI, $LANG; $instID = $this->fields['id']; if (!$this->can($instID, 'r')) { return false; } $canedit = $this->can($instID, 'w'); $query = "SELECT `glpi_contacts_suppliers`.`id`,\n `glpi_suppliers`.`id` AS entID,\n `glpi_suppliers`.`name` AS name,\n `glpi_suppliers`.`website` AS website,\n `glpi_suppliers`.`fax` AS fax,\n `glpi_suppliers`.`phonenumber` AS phone,\n `glpi_suppliers`.`suppliertypes_id` AS type,\n `glpi_suppliers`.`is_deleted`,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contacts_suppliers`, `glpi_suppliers`\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_suppliers`.`entities_id`)\n WHERE `glpi_contacts_suppliers`.`contacts_id` = '{$instID}'\n AND `glpi_contacts_suppliers`.`suppliers_id` = `glpi_suppliers`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_suppliers", '', '', true) . "\n ORDER BY `glpi_entities`.`completename`, `name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/contact.form.php\">"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='7'>"; if ($DB->numrows($result) == 0) { echo $LANG['financial'][67]; } else { if ($DB->numrows($result) == 1) { echo $LANG['financial'][64]; } else { echo $LANG['financial'][65]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['financial'][26] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['financial'][79] . "</th>"; echo "<th>" . $LANG['help'][35] . "</th>"; echo "<th>" . $LANG['financial'][30] . "</th>"; echo "<th>" . $LANG['financial'][45] . "</th>"; echo "<th> </th></tr>"; $used = array(); if ($number > 0) { initNavigateListItems('Supplier', $LANG['common'][92] . " = " . $this->fields['name']); while ($data = $DB->fetch_array($result)) { $ID = $data["id"]; addToNavigateListItems('Supplier', $data["entID"]); $used[$data["entID"]] = $data["entID"]; $website = $data["website"]; if (!empty($website)) { $website = $data["website"]; if (!preg_match("?https*://?", $website)) { $website = "http://" . $website; } $website = "<a target=_blank href='{$website}'>" . $data["website"] . "</a>"; } echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/supplier.form.php?id=" . $data["entID"] . "'>" . Dropdown::getDropdownName("glpi_suppliers", $data["entID"]) . "</a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_suppliertypes", $data["type"]); echo "</td>"; echo "<td class='center' width='80'>" . $data["phone"] . "</td>"; echo "<td class='center' width='80'>" . $data["fax"] . "</td>"; echo "<td class='center'>" . $website . "</td>"; echo "<td class='tab_bg_2 center'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contact.form.php?deletecontactsupplier=1" . "&id={$ID}&contacts_id={$instID}'><strong>" . $LANG['buttons'][6] . "</strong></a>"; } else { echo " "; } echo "</td></tr>"; } } if ($canedit) { if ($this->fields["is_recursive"]) { $nb = countElementsInTableForEntity("glpi_suppliers", getSonsOf("glpi_entities", $this->fields["entities_id"])); } else { $nb = countElementsInTableForEntity("glpi_suppliers", $this->fields["entities_id"]); } if ($nb > count($used)) { echo "<tr class='tab_bg_1'><td> </td><td class='center' colspan='4'>"; echo "<input type='hidden' name='contacts_id' value='{$instID}'>"; Dropdown::show('Supplier', array('used' => $used, 'entity' => $this->fields["entities_id"], 'entity_sons' => $this->fields["is_recursive"])); echo " <input type='submit' name='addcontactsupplier' value='" . $LANG['buttons'][8] . "' class='submit'>"; echo "</td><td> </td><td> </td>"; echo "</tr>"; } } echo "</table></div></form>"; }
/** * Permet l'affichage dynamique d'une liste déroulante imbriquee * * @static * @param array ($itemtype,$myname,$value,$entity_restrict,$action,$span) */ static function showGenericDropdown($itemtype, $options = array()) { global $DB, $CFG_GLPI; $item = getItemForItemtype($itemtype); if ($itemtype && !($item = getItemForItemtype($itemtype))) { return false; } $table = $item->getTable(); /*$options["table"] = $table; $options["rand"] = $rand; $params['name'] = $item->getForeignKeyField(); $params['value'] = ($itemtype=='Entity' ? $_SESSION['glpiactive_entity'] : ''); $params['entity'] = -1; $params['entity_sons'] = false; $params['toupdate'] = ''; $params['used'] = array(); $params['toadd'] = array(); $params['on_change'] = ''; $params['condition'] = ''; $params['rand'] = mt_rand(); $params['displaywith'] = array(); //Parameters about choice 0 //Empty choice's label $params['emptylabel'] = self::EMPTY_VALUE;*/ $params['comments'] = true; $params['condition'] = ''; $params['entity'] = -1; $params['entity_sons'] = false; $params['rand'] = mt_rand(); $params['used'] = array(); $params['table'] = $table; $params['emptylabel'] = Dropdown::EMPTY_VALUE; //Display emptychoice ? $params['display_emptychoice'] = true; //In case of Entity dropdown, display root entity ? $params['display_rootentity'] = false; //specific $params['action'] = ""; $params['span'] = ""; $params['sort'] = false; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } $name = $params['emptylabel']; $comment = ""; $limit_length = $_SESSION["glpidropdown_chars_limit"]; if (strlen($params['value']) == 0 || !is_numeric($params['value'])) { $params['value'] = 0; } if ($params['value'] > 0) { $tmpname = Dropdown::getDropdownName($table, $params['value'], 1); if ($tmpname["name"] != " ") { $name = $tmpname["name"]; $comment = $tmpname["comment"]; if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) { if ($item instanceof CommonTreeDropdown) { $pos = strrpos($name, ">"); $limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]); if (Toolbox::strlen($name) > $limit_length) { $name = "…" . Toolbox::substr($name, -$limit_length); } } else { $limit_length = Toolbox::strlen($name); } } else { $limit_length = $_SESSION["glpidropdown_chars_limit"]; } } } // Manage entity_sons if (!($params['entity'] < 0) && $params['entity_sons']) { if (is_array($params['entity'])) { echo "entity_sons options is not available with array of entity"; } else { $params['entity'] = getSonsOf('glpi_entities', $params['entity']); } } $use_ajax = false; if ($CFG_GLPI["use_ajax"]) { $nb = 0; if ($item->isEntityAssign()) { if (!($params['entity'] < 0)) { $nb = countElementsInTableForEntity($table, $params['entity'], $params['condition']); } else { $nb = countElementsInTableForMyEntities($table, $params['condition']); } } else { $nb = countElementsInTable($table, $params['condition']); } $nb -= count($params['used']); if ($nb > $CFG_GLPI["ajax_limit_count"]) { $use_ajax = true; } } $param = array('searchText' => '__VALUE__', 'value' => $params['value'], 'itemtype' => $itemtype, 'myname' => $params['name'], 'limit' => $limit_length, 'comment' => $params['comments'], 'rand' => $params['rand'], 'entity_restrict' => $params['entity'], 'used' => $params['used'], 'condition' => $params['condition'], 'emptylabel' => $params['emptylabel'], 'display_emptychoice' => $params['display_emptychoice'], 'display_rootentity' => $params['display_rootentity'], 'action' => $params['action'], 'span' => $params['span'], 'sort' => $params['sort']); $default = "<select name='" . $params['name'] . "' id='dropdown_" . $params['name'] . $params['rand'] . "'>"; $default .= "<option value='" . $params['value'] . "'>{$name}</option></select>"; Ajax::dropdown($use_ajax, "/plugins/resources/ajax/dropdownValue.php", $param, $default, $params['rand']); // Display comment if ($params['comments']) { $options_tooltip = array('contentid' => "comment_" . $param['myname'] . $params['rand']); if ($params['value'] && $item->getFromDB($params['value'])) { $options_tooltip['link'] = $item->getLinkURL(); $options_tooltip['linktarget'] = '_blank'; } Html::showToolTip($comment, $options_tooltip); if ($item instanceof CommonDropdown && $item->canCreate() && !isset($_GET['popup'])) { echo "<img alt='' title=\"" . _sx('button', 'Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n onClick=\"var w = window.open('" . $item->getFormURL() . "?popup=1&rand=" . $params['rand'] . "' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">"; } } return $params['rand']; }
static function uninstall($type, $model_id, $tab_ids, $location) { global $UNINSTALL_DIRECT_CONNECTIONS_TYPE; //Get the model $model = new PluginUninstallModel(); $model->getConfig($model_id); //Then destroy all the connexions $transfer = new Transfer(); $transfer->getFromDB($model->fields["transfers_id"]); echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'><tr><th>" . __('Uninstall', 'uninstall') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>"; $count = 0; $tot = count($tab_ids[$type]); Html::createProgressBar(__('Please wait, uninstallation is running...', 'uninstall')); foreach ($tab_ids[$type] as $id => $value) { $count++; $item = new $type(); $item->getFromDB($id); //First clean object and change location and status if needed $entity = $item->fields["entities_id"]; $input = array(); $input["id"] = $id; $input["entities_id"] = $entity; $fields = array(); //Hook to perform actions before item is being uninstalled $item->fields['_uninstall_event'] = $model->getID(); $item->fields['_action'] = 'uninstall'; Plugin::doHook("plugin_uninstall_before", $item); //--------------------// //Direct connections // //------------------// if (in_array($type, $UNINSTALL_DIRECT_CONNECTIONS_TYPE)) { $conn = new Computer_Item(); $conn->deleteByCriteria(array('computers_id' => $id), true); } //--------------------// //-- Common fields --// //------------------// //RAZ contact and contactnumber if ($item->isField('contact') && $model->fields["raz_contact"] == 1) { $fields["contact"] = ''; if ($item->isField('contact_num')) { $fields["contact_num"] = ''; } } //RAZ user if ($model->fields["raz_user"] == 1 && $item->isField('users_id')) { $fields["users_id"] = 0; } //RAZ status if ($model->fields["states_id"] > 0 && $item->isField('states_id')) { $fields["states_id"] = $model->fields["states_id"]; } //RAZ machine's name if ($item->isField('name') && $model->fields["raz_name"] == 1) { $fields["name"] = ''; } if ($item->isField('locations_id')) { if ($location == '') { $location = 0; } switch ($location) { case -1: break; default: $fields["locations_id"] = $location; break; } } if ($item->isField('groups_id')) { $nbgroup = countElementsInTableForEntity("glpi_groups", $entity, "`id`='" . $item->fields['groups_id'] . "'"); if ($model->fields["groups_id"] > -1 && $nbgroup == 1) { // If a new group is defined and if the group is accessible in the object's entity $fields["groups_id"] = $model->fields["groups_id"]; } } //------------------------------// //-- Computer specific fields --// //------------------------------// if ($type == 'Computer') { //RAZ all OS related informations if ($model->fields["raz_os"] == 1) { $fields["operatingsystems_id"] = 0; $fields["operatingsystemversions_id"] = 0; $fields["operatingsystemservicepacks_id"] = 0; $fields["os_licenseid"] = ''; $fields["os_license_number"] = ''; $fields["autoupdatesystems_id"] = 0; } $plug = new Plugin(); if ($plug->isActivated('ocsinventoryng')) { if ($item->fields["is_dynamic"] && ($model->fields["remove_from_ocs"] || $model->fields["delete_ocs_link"])) { $input["is_dynamic"] = 0; } } if ($item->isField('domains_id') && $model->fields["raz_domain"]) { $fields["domains_id"] = 0; } //RAZ network if ($item->isField('networks_id') && $model->fields["raz_network"] == 1) { $fields["networks_id"] = 0; } } //RAZ IPs from all the network cards if ($model->fields["raz_ip"] == 1) { self::razPortInfos($type, $id); // For NetworkEquiment if ($item->isField('ip')) { $fields['ip'] = ''; } if ($item->isField('mac')) { $fields['mac'] = ''; } } foreach ($fields as $name => $value) { if (!($item->getField($name) != NOT_AVAILABLE) || $item->getField($name) != $value) { $input[$name] = $value; } } $item->dohistory = true; $item->update($input); if ($model->fields["raz_budget"] == 1) { $infocom_id = self::getInfocomPresentForDevice($type, $id); if ($infocom_id > 0) { $infocom = new InfoCom(); $tmp["id"] = $infocom_id; $tmp["budgets_id"] = 0; $infocom->dohistory = false; $infocom->update($tmp); } } //Delete machine from glpi_ocs_link if ($type == 'Computer') { //Delete computer's volumes self::purgeComputerVolumes($id); if ($model->fields["raz_history"] == 1) { //Delete history related to software self::deleteHistory($id, false); } else { if ($model->fields["raz_soft_history"] == 1) { //Delete history related to software self::deleteHistory($id, true); } } $plug = new Plugin(); if ($plug->isActivated('ocsinventoryng')) { //Delete computer from OCS if ($model->fields["remove_from_ocs"] == 1) { self::deleteComputerInOCSByGlpiID($id); } //Delete link in glpi_ocs_link if ($model->fields["delete_ocs_link"] || $model->fields["remove_from_ocs"]) { self::deleteOcsLink($id); } } //Should never happend that transfer_id = 0, but just in case if ($model->fields["transfers_id"] > 0) { $transfer->moveItems(array($type => array($id => $id)), $entity, $transfer->fields); } } if ($model->fields['raz_fusioninventory'] == 1) { self::deleteFusionInventoryLink($type, $id); } //Plugin hook after uninstall Plugin::doHook("plugin_uninstall_after", $item); Html::changeProgressBarPosition($count, $tot + 1); } //Add line in machine's history to say that machine was uninstalled self::addUninstallLog($type, $id); Html::changeProgressBarPosition($count, $tot, __('Uninstallation successful', 'uninstall')); echo "</td></tr>"; echo "</table></div>"; }
/** * Print an HTML array with contracts associated to the enterprise * *@return Nothing (display) **/ function showContracts() { global $DB, $CFG_GLPI, $LANG; $ID = $this->fields['id']; if (!haveRight("contract", "r") || !$this->can($ID, 'r')) { return false; } $canedit = $this->can($ID, 'w'); $query = "SELECT `glpi_contracts`.*,\n `glpi_contracts_suppliers`.`id` AS assocID,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contracts_suppliers`, `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contracts`.`entities_id`)\n WHERE `glpi_contracts_suppliers`.`suppliers_id` = '{$ID}'\n AND `glpi_contracts_suppliers`.`contracts_id`=`glpi_contracts`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_entities`.`completename`,\n `glpi_contracts`.`name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='7'>"; if ($DB->numrows($result) == 0) { echo $LANG['financial'][58]; } else { if ($DB->numrows($result) == 1) { echo $LANG['financial'][63]; } else { echo $LANG['financial'][66]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['financial'][4] . "</th>"; echo "<th>" . $LANG['financial'][6] . "</th>"; echo "<th>" . $LANG['search'][8] . "</th>"; echo "<th>" . $LANG['financial'][8] . "</th>"; echo "<th> </th>"; echo "</tr>"; $used = array(); while ($data = $DB->fetch_array($result)) { $cID = $data["id"]; $used[$cID] = $cID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>\n <a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>"; echo "<strong>" . $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { echo " (" . $data["id"] . ")"; } echo "</strong></a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "</td><td class='center'>" . $data["num"] . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contracttypes", $data["contracttypes_id"]) . "</td>"; echo "<td class='center'>" . convDate($data["begin_date"]) . "</td>"; echo "<td class='center'>" . $data["duration"] . " " . $LANG['financial'][57]; if ($data["begin_date"] != '' && !empty($data["begin_date"])) { echo " -> " . getWarrantyExpir($data["begin_date"], $data["duration"]); } echo "</td>"; echo "<td class='tab_bg_2 center'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?deletecontractsupplier=" . "1&id={$assocID}&contracts_id={$cID}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>"; } else { echo " "; } echo "</td></tr>"; $i++; } if ($canedit) { if ($this->fields["is_recursive"]) { $nb = countElementsInTableForEntity("glpi_contracts", getSonsOf("glpi_entities", $this->fields["entities_id"])); } else { $nb = countElementsInTableForEntity("glpi_contracts", $this->fields["entities_id"]); } if ($nb > count($used)) { echo "<tr class='tab_bg_1'><td class='center' colspan='5'>"; echo "<input type='hidden' name='suppliers_id' value='{$ID}'>"; Contract::dropdown(array('used' => $used, 'entity' => $this->fields["entities_id"], 'entity_sons' => $this->fields["is_recursive"], 'nochecklimit' => true)); echo "</td><td class='center'>"; echo "<input type='submit' name='addcontractsupplier' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td>"; echo "<td> </td></tr>"; } } echo "</table></div></form>"; }
/** * Make a select box for license software to associate * * @param $myname select name * @param $entity_restrict restrict to a defined entity * @param $massiveaction is it a massiveaction select ? (default 0) * * @return nothing (print out an HTML select box) **/ static function dropdownLicenseToInstall($myname, $entity_restrict, $massiveaction = 0) { global $CFG_GLPI; $rand = mt_rand(); $use_ajax = false; if ($CFG_GLPI["use_ajax"]) { if (countElementsInTableForEntity("glpi_softwarelicenses", $entity_restrict) > $CFG_GLPI["ajax_limit_count"]) { $use_ajax = true; } } $params = array('searchText' => '__VALUE__', 'myname' => $myname, 'entity_restrict' => $entity_restrict); $default = "<select name='{$myname}'><option value='0'>" . Dropdown::EMPTY_VALUE . " </option>\n </select>"; Ajax::dropdown($use_ajax, "/ajax/dropdownSelectSoftwareLicense.php", $params, $default, $rand); return $rand; }
/** * Print the HTML array of suppliers for this contract * *@return Nothing (HTML display) * **/ function showSuppliers() { global $DB, $CFG_GLPI, $LANG; $instID = $this->fields['id']; if (!$this->can($instID, 'r') || !haveRight("contact_enterprise", "r")) { return false; } $canedit = $this->can($instID, 'w'); $query = "SELECT `glpi_contracts_suppliers`.`id`,\n `glpi_suppliers`.`id` AS entID,\n `glpi_suppliers`.`name` AS name,\n `glpi_suppliers`.`website` AS website,\n `glpi_suppliers`.`phonenumber` AS phone,\n `glpi_suppliers`.`suppliertypes_id` AS type,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contracts_suppliers`,\n `glpi_suppliers`\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_suppliers`.`entities_id`)\n WHERE `glpi_contracts_suppliers`.`contracts_id` = '{$instID}'\n AND `glpi_contracts_suppliers`.`suppliers_id`=`glpi_suppliers`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_suppliers", '', '', true) . "\n ORDER BY `glpi_entities`.`completename`, `name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/contract.form.php\">"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='6'>"; if ($DB->numrows($result) == 0) { echo $LANG['financial'][67]; } else { if ($DB->numrows($result) == 1) { echo $LANG['financial'][64]; } else { echo $LANG['financial'][65]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['financial'][26] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['financial'][79] . "</th>"; echo "<th>" . $LANG['help'][35] . "</th>"; echo "<th>" . $LANG['financial'][45] . "</th>"; echo "<th> </th></tr>"; $used = array(); while ($i < $number) { $ID = $DB->result($result, $i, "id"); $website = $DB->result($result, $i, "glpi_suppliers.website"); if (!empty($website)) { $website = $DB->result($result, $i, "website"); if (!preg_match("?https*://?", $website)) { $website = "http://" . $website; } $website = "<a target=_blank href='{$website}'>" . $DB->result($result, $i, "website") . "</a>"; } $entID = $DB->result($result, $i, "entID"); $entity = $DB->result($result, $i, "entity"); $used[$entID] = $entID; $entname = Dropdown::getDropdownName("glpi_suppliers", $entID); echo "<tr class='tab_bg_1'><td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/supplier.form.php?id={$entID}'>" . $entname; if ($_SESSION["glpiis_ids_visible"] || empty($entname)) { echo " ({$entID})"; } echo "</a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $entity) . "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_suppliertypes", $DB->result($result, $i, "type")) . "</td>"; echo "<td class='center'>" . $DB->result($result, $i, "phone") . "</td>"; echo "<td class='center'>" . $website . "</td>"; echo "<td class='tab_bg_2 center'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?deletecontractsupplier=1&id={$ID}&contracts_id=" . $instID . "'><img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>"; } else { echo " "; } echo "</td></tr>"; $i++; } if ($canedit) { if ($this->fields["is_recursive"]) { $nb = countElementsInTableForEntity("glpi_suppliers", getSonsOf("glpi_entities", $this->fields["entities_id"])); } else { $nb = countElementsInTableForEntity("glpi_suppliers", $this->fields["entities_id"]); } if ($nb > count($used)) { echo "<tr class='tab_bg_1'><td class='right' colspan='2'>"; echo "<input type='hidden' name='contracts_id' value='{$instID}'>"; Dropdown::show('Supplier', array('used' => $used, 'entity' => $this->fields["entities_id"], 'entity_sons' => $this->fields["is_recursive"])); echo "</td><td class='center'>"; echo "<input type='submit' name='addcontractsupplier' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td><td> </td><td> </td><td> </td>"; echo "</tr>"; } } echo "</table></div></form>"; }