function getSqlSubRequest($itemtype, $loc, $obj) { $table = getTableForItemType($itemtype); $models_id = getForeignKeyFieldForTable(getTableForItemType($itemtype . 'Model')); $types_id = getForeignKeyFieldForTable(getTableForItemType($itemtype . 'Type')); $fields = array('name' => 'name', 'serial' => 'serial', 'otherserial' => 'otherserial', $models_id => 'models_id', $types_id => 'types_id'); $query_where = "SELECT '{$itemtype}' AS itemtype,\n `{$table}`.`id` AS items_id,\n `{$table}`.`locations_id`"; foreach ($fields as $field => $alias) { if ($obj->isField($field)) { $query_where .= ", `{$table}`.`{$field}` AS {$alias}"; } else { $query_where .= ", '' AS {$alias}"; } } $query_where .= " FROM `{$table}` "; if ($obj->isEntityAssign()) { $query_where .= getEntitiesRestrictRequest('WHERE', "{$table}"); } else { $query_where .= 'WHERE 1'; } if ($obj->maybeTemplate()) { $query_where .= " AND `is_template`='0'"; } if ($obj->maybeDeleted()) { $query_where .= " AND `is_deleted`='0'"; } $query_where .= $loc->getSqlCriteriasRestriction(); return $query_where; }
static function pdfForSoftware(PluginPdfSimplePDF $pdf, Software $software, $infocom = false) { global $DB; $sID = $software->getField('id'); $license = new SoftwareLicense(); $query = "SELECT `id`\n FROM `glpi_softwarelicenses`\n WHERE `softwares_id` = '" . $sID . "' " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n ORDER BY `name`"; $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . _n('License', 'Licenses', 2) . '</b>'); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { for ($tot = 0; $data = $DB->fetch_assoc($result);) { if ($license->getFromDB($data['id'])) { self::pdfMain($pdf, $license, false); if ($infocom) { PluginPdfInfocom::pdfForItem($pdf, $license); } } } } else { $pdf->displayLine(__('No item found')); } } else { $pdf->displayLine(__('No item found')); } $pdf->displaySpace(); }
/** * Initialize all classes and generic variables of the plugin */ function plugin_init_formcreator() { global $PLUGIN_HOOKS; // Set the plugin CSRF compliance (required since GLPI 0.84) $PLUGIN_HOOKS['csrf_compliant']['formcreator'] = true; $plugin = new Plugin(); if (isset($_SESSION['glpiID']) && $plugin->isInstalled('formcreator') && $plugin->isActivated('formcreator')) { // Massive Action definition $PLUGIN_HOOKS['use_massive_action']['formcreator'] = 1; // If user have acces to one form or more, add link $form_table = getTableForItemType('PluginFormcreatorForm'); $table_fp = getTableForItemType('PluginFormcreatorFormprofiles'); $where = getEntitiesRestrictRequest("", $form_table, "", "", true, false); $query = "SELECT COUNT({$form_table}.id)\n FROM {$form_table}\n WHERE {$form_table}.`is_active` = 1\n AND {$form_table}.`is_deleted` = 0\n AND {$form_table}.`helpdesk_home` = 1\n AND ({$form_table}.`language` = '{$_SESSION['glpilanguage']}' OR {$form_table}.`language` = '')\n AND {$where}\n AND ({$form_table}.`access_rights` != " . PluginFormcreatorForm::ACCESS_RESTRICTED . " OR {$form_table}.`id` IN (\n SELECT plugin_formcreator_forms_id\n FROM {$table_fp}\n WHERE plugin_formcreator_profiles_id = " . (int) $_SESSION['glpiactiveprofile']['id'] . "))"; $result = $GLOBALS['DB']->query($query); list($nb) = $GLOBALS['DB']->fetch_array($result); if ($nb > 0) { $PLUGIN_HOOKS['menu_toadd']['formcreator']['helpdesk'] = 'PluginFormcreatorFormlist'; } if (strpos($_SERVER['REQUEST_URI'], "plugins/formcreator") !== false || strpos($_SERVER['REQUEST_URI'], "central.php") !== false || isset($_SESSION['glpiactiveprofile']) && $_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') { // Add specific CSS $PLUGIN_HOOKS['add_css']['formcreator'][] = "css/styles.css"; $PLUGIN_HOOKS['add_css']['formcreator'][] = 'lib/pqselect/pqselect.min.css'; $PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'lib/pqselect/pqselect.min.js'; // Add specific JavaScript $PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'scripts/forms-validation.js.php'; $PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'scripts/scripts.js.php'; } // Add a link in the main menu plugins for technician and admin panel $PLUGIN_HOOKS['menu_entry']['formcreator'] = 'front/formlist.php'; // Config page $plugin = new Plugin(); $links = array(); if (Session::haveRight('entity', UPDATE)) { $PLUGIN_HOOKS['config_page']['formcreator'] = 'front/form.php'; $PLUGIN_HOOKS['menu_toadd']['formcreator']['admin'] = 'PluginFormcreatorForm'; $links['config'] = '/plugins/formcreator/front/form.php'; $links['add'] = '/plugins/formcreator/front/form.form.php'; } $img = '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/check.png" title="' . __('Forms waiting for validation', 'formcreator') . '" alt="Waiting forms list" />'; $links[$img] = '/plugins/formcreator/front/formanswer.php'; // Set options for pages (title, links, buttons...) $links['search'] = '/plugins/formcreator/front/formlist.php'; $PLUGIN_HOOKS['submenu_entry']['formcreator']['options'] = array('config' => array('title' => __('Setup'), 'page' => '/plugins/formcreator/front/form.php', 'links' => $links), 'options' => array('title' => _n('Form', 'Forms', 2, 'formcreator'), 'links' => $links)); // Load field class and all its method to manage fields Plugin::registerClass('PluginFormcreatorFields'); // Notification Plugin::registerClass('PluginFormcreatorFormanswer', array('notificationtemplates_types' => true)); if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE && isset($_SESSION['glpimenu'])) { unset($_SESSION['glpimenu']); } } }
function listTemplates($itemtype, $target, $add = 0) { global $DB, $CFG_GLPI, $LANG; if (!class_exists($itemtype)) { return false; } $item = new $itemtype(); //Check is user have minimum right r if (!$item->canView() && !$item->canCreate()) { return false; } $query = "SELECT * FROM `" . $item->getTable() . "`\n WHERE `is_template` = '1' "; if ($item->isEntityAssign()) { $query .= getEntitiesRestrictRequest('AND', $item->getTable(), 'entities_id', $_SESSION['glpiactive_entity'], $item->maybeRecursive()); } $query .= " ORDER by `template_name`"; if ($result = $DB->query($query)) { echo "<div class='center'><table class='tab_cadre' width='50%'>"; if ($add) { echo "<tr><th>" . $LANG['common'][7] . " - " . $item->getTypeName() . " :</th></tr>"; echo "<tr><td class='tab_bg_1 center'>"; echo "<a href=\"{$target}?id=-1&withtemplate=2\"> " . $LANG['common'][31] . " </a></td>"; echo "</tr>"; } else { echo "<tr><th colspan='2'>" . $LANG['common'][14] . " - " . $item->getTypeName() . " :</th></tr>"; } while ($data = $DB->fetch_array($result)) { $templname = $data["template_name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["template_name"])) { $templname .= "(" . $data["id"] . ")"; } echo "<tr><td class='tab_bg_1 center'>"; if ($item->canCreate() && !$add) { echo "<a href=\"{$target}?id=" . $data["id"] . "&withtemplate=1\">"; echo " {$templname} </a></td>"; echo "<td class='tab_bg_2 center b'>"; echo "<a href=\"{$target}?id=" . $data["id"] . "&purge=purge&withtemplate=1\">" . $LANG['buttons'][6] . "</a></td>"; } else { echo "<a href=\"{$target}?id=" . $data["id"] . "&withtemplate=2\">"; echo " {$templname} </a></td>"; } echo "</tr>"; } if ($item->canCreate() && !$add) { echo "<tr><td colspan='2' class='tab_bg_2 center b'>"; echo "<a href=\"{$target}?withtemplate=1\">" . $LANG['common'][9] . "</a>"; echo "</td></tr>"; } echo "</table></div>\n"; } }
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { $header = new self(); $found = $header->find('entities_id = ' . $_SESSION['glpiactive_entity']); if (count($found) > 0) { echo '<div class="tab_cadre_pager" style="padding: 2px; margin: 5px 0"> <h3 class="tab_bg_2" style="padding: 5px"> <img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/menu_add_off.png" alt="+" align="absmiddle" /> ' . __('Add an header', 'formcreator') . '<br /><br /> <em><i><img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/warning.png" alt="/!\\" align="absmiddle" height="16" /> ' . __('An header already exists for this entity! You can have only one header per entity.', 'formcreator') . '</i></em> </h3> </div>'; } else { $table = getTableForItemType('PluginFormcreatorHeader'); $where = getEntitiesRestrictRequest("", $table, "", "", true, false); $found = $header->find($where); if (count($found) > 0) { echo '<div class="tab_cadre_pager" style="padding: 2px; margin: 5px 0"> <h3 class="tab_bg_2" style="padding: 5px"> <a href="' . Toolbox::getItemTypeFormURL(__CLASS__) . '" class="submit"> <img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/menu_add.png" alt="+" align="absmiddle" /> ' . __('Add an header', 'formcreator') . ' </a><br /><br /> <em><i><img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/warning.png" alt="/!\\" align="absmiddle" height="16" /> ' . __('An header exists for a parent entity! Another header will overwrite the previous one.', 'formcreator') . '</i></em> </h3> </div>'; } else { echo '<div class="tab_cadre_pager" style="padding: 2px; margin: 5px 0"> <h3 class="tab_bg_2" style="padding: 5px"> <a href="' . Toolbox::getItemTypeFormURL(__CLASS__) . '" class="submit"> <img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/menu_add.png" alt="+" align="absmiddle" /> ' . __('Add an header', 'formcreator') . ' </a> </h3> </div>'; } } $params['sort'] = !empty($_POST['sort']) ? (int) $_POST['sort'] : 0; $params['order'] = !empty($_POST['order']) && in_array($_POST['order'], array('ASC', 'DESC')) ? $_POST['order'] : 'ASC'; $params['start'] = !empty($_POST['start']) ? (int) $_POST['start'] : 0; Search::manageGetValues(__CLASS__); //Search::showGenericSearch(__CLASS__, $_GET); Search::showList(__CLASS__, $params); }
private static function getUserGroup($entity, $userid, $filter = '', $first = true) { global $DB; $query = "SELECT glpi_groups.id\n FROM glpi_groups_users\n INNER JOIN glpi_groups ON (glpi_groups.id = glpi_groups_users.groups_id)\n WHERE glpi_groups_users.users_id='{$userid}'" . getEntitiesRestrictRequest(' AND ', 'glpi_groups', '', $entity, true, true); if ($filter) { $query .= "AND ({$filter})"; } $query .= " ORDER BY glpi_groups_users.id"; $rep = array(); foreach ($DB->request($query) as $data) { if ($first) { return $data['id']; } $rep[] = $data['id']; } return $first ? 0 : array_pop($rep); }
private static function getUserGroup($entity, $userid, $filter = '', $first = true) { global $DB; $config = PluginBehaviorsConfig::getInstance(); $query = "SELECT glpi_groups.id\n FROM glpi_groups_users\n INNER JOIN glpi_groups ON (glpi_groups.id = glpi_groups_users.groups_id)\n WHERE glpi_groups_users.users_id = '" . $userid . "'" . getEntitiesRestrictRequest(' AND ', 'glpi_groups', '', $entity, true); if ($filter) { $query .= "AND (" . $filter . ")"; } $rep = array(); foreach ($DB->request($query) as $data) { if ($first) { return $data['id']; } $rep[] = $data['id']; } return $first ? 0 : $rep; }
/** * Show OcsLink of an item * * @param $item CommonDBTM object * * @return nothing **/ static function showForItem(CommonDBTM $item) { global $DB, $LANG; if (in_array($item->getType(), array('Computer'))) { $items_id = $item->getField('id'); $query = "SELECT `glpi_ocslinks`.`tag` AS tag\n FROM `glpi_ocslinks`\n WHERE `glpi_ocslinks`.`computers_id` = '{$items_id}' " . getEntitiesRestrictRequest("AND", "glpi_ocslinks"); $result = $DB->query($query); if ($DB->numrows($result) > 0) { $data = $DB->fetch_assoc($result); $data = clean_cross_side_scripting_deep(addslashes_deep($data)); echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['ocsng'][0] . "</th>"; echo "<tr class='tab_bg_2'>"; echo "<td class='center'>" . $LANG['ocsconfig'][39] . " : " . $data['tag'] . "</td></tr>"; } } }
static function countForItem(CommonDBTM $item) { $restrict = "`glpi_documents_items`.`documents_id` = `glpi_documents`.`id`\n AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "'"; if (getLoginUserID()) { $restrict .= getEntitiesRestrictRequest(" AND ", "glpi_documents", '', '', true); } else { // Anonymous access from FAQ $restrict .= " AND `glpi_documents`.`entities_id` = '0' "; } $nb = countElementsInTable(array('glpi_documents_items', 'glpi_documents'), $restrict); // Document case : search in both if ($item->getType() == 'Document') { $restrict = "`glpi_documents_items`.`items_id` = `glpi_documents`.`id`\n AND `glpi_documents_items`.`documents_id` = '" . $item->getField('id') . "'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "'"; if (getLoginUserID()) { $restrict .= getEntitiesRestrictRequest(" AND ", "glpi_documents", '', '', true); } else { // Anonymous access from FAQ $restrict .= " AND `glpi_documents`.`entities_id` = '0' "; } $nb += countElementsInTable(array('glpi_documents_items', 'glpi_documents'), $restrict); } return $nb; }
public static function queryAccountsList($values) { global $DB; $ID = $values["id"]; $aeskey = $values["aeskey"]; $PluginAccountsHash = new PluginAccountsHash(); $PluginAccountsHash->getFromDB($ID); $hash = $PluginAccountsHash->fields["hash"]; if ($PluginAccountsHash->isRecursive()) { $entities = getSonsOf('glpi_entities', $PluginAccountsHash->getEntityID()); } else { $entities = $PluginAccountsHash->getEntityID(); } if ($aeskey) { $query = "SELECT `glpi_plugin_accounts_accounts`.*,\n `glpi_plugin_accounts_accounttypes`.`name` AS type\n FROM `glpi_plugin_accounts_accounts`\n LEFT JOIN `glpi_plugin_accounts_accounttypes`\n ON (`glpi_plugin_accounts_accounts`.`plugin_accounts_accounttypes_id` = `glpi_plugin_accounts_accounttypes`.`id`)\n WHERE `is_deleted`= '0'"; $query .= getEntitiesRestrictRequest(" AND ", "glpi_plugin_accounts_accounts", '', $entities, $PluginAccountsHash->maybeRecursive()); $query .= " ORDER BY `type`,`name`"; foreach ($DB->request($query) as $data) { $accounts[] = $data; } $list = array(); if (!empty($accounts)) { foreach ($accounts as $account) { $ID = $account["id"]; $list[$ID]["id"] = $account["id"]; $list[$ID]["name"] = $account["name"]; if (Session::isMultiEntitiesMode()) { $list[$ID]["entities_id"] = Dropdown::getDropdownName("glpi_entities", $account["entities_id"]); } $list[$ID]["type"] = $account["type"]; $list[$ID]["login"] = $account["login"]; $list[$ID]["password"] = $account["encrypted_password"]; } } } return $list; }
/** * Show Licenses of a software * * @param $software Software object * * @return nothing **/ static function showForSoftware(Software $software) { global $DB, $CFG_GLPI; $softwares_id = $software->getField('id'); $license = new self(); $computer = new Computer(); if (!$software->can($softwares_id, READ)) { return false; } $columns = array('name' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'number' => _x('quantity', 'Number'), '_affected' => __('Affected computers'), 'typename' => __('Type'), 'buyname' => __('Purchase version'), 'usename' => __('Version in use'), 'expire' => __('Expiration')); if (!$software->isRecursive()) { unset($columns['entity']); } if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) { $sort = "`" . $_GET["sort"] . "`"; } else { $sort = "`entity` {$order}, `name`"; } // Righ type is enough. Can add a License on a software we have Read access $canedit = Software::canUpdate(); $showmassiveactions = $canedit; // Total Number of events $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true)); echo "<div class='spaced'>"; Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $software->getName())); if ($canedit) { echo "<div class='center firstbloc'>"; echo "<a class='vsubmit' href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . _x('button', 'Add a license') . "</a>"; echo "</div>"; } $rand = mt_rand(); $query = "SELECT `glpi_softwarelicenses`.*,\n `buyvers`.`name` AS buyname,\n `usevers`.`name` AS usename,\n `glpi_entities`.`completename` AS entity,\n `glpi_softwarelicensetypes`.`name` AS typename\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_softwareversions` AS buyvers\n ON (`buyvers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_buy`)\n LEFT JOIN `glpi_softwareversions` AS usevers\n ON (`usevers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_use`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `glpi_softwarelicenses`.`entities_id`)\n LEFT JOIN `glpi_softwarelicensetypes`\n ON (`glpi_softwarelicensetypes`.`id`\n = `glpi_softwarelicenses`.`softwarelicensetypes_id`)\n WHERE (`glpi_softwarelicenses`.`softwares_id` = '{$softwares_id}') " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); if ($result = $DB->query($query)) { if ($num_displayed = $DB->numrows($result)) { // Display the pager Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number); if ($showmassiveactions) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $num_displayed, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('options' => array('glpi_softwareversions.name' => array('condition' => "`glpi_softwareversions`.`softwares_id`\n = {$softwares_id}"), 'glpi_softwarelicenses.name' => array('itemlink_as_string' => true)))); Html::showMassiveActions($massiveactionparams); } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr><th>"; $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end = ''; foreach ($columns as $key => $val) { // Non order column if ($key[0] == '_') { $header_end .= "<th>{$val}</th>"; } else { $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>"; } } $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; $tot_assoc = 0; for ($tot = 0; $data = $DB->fetch_assoc($result);) { Session::addToNavigateListItems('SoftwareLicense', $data['id']); $expired = true; if (is_null($data['expire']) || $data['expire'] > date('Y-m-d')) { $expired = false; } echo "<tr class='tab_bg_2" . ($expired ? '_2' : '') . "'>"; if ($license->canEdit($data['id'])) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } else { echo "<td> </td>"; } echo "<td><a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a></td>"; if (isset($columns['entity'])) { echo "<td>"; echo $data['entity']; echo "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td class='numeric'>" . ($data['number'] > 0 ? $data['number'] : __('Unlimited')) . "</td>"; $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']); $tot_assoc += $nb_assoc; $color = $data['is_valid'] ? 'green' : 'red'; echo "<td class='numeric {$color}'>" . $nb_assoc . "</td>"; echo "<td>" . $data['typename'] . "</td>"; echo "<td>" . $data['buyname'] . "</td>"; echo "<td>" . $data['usename'] . "</td>"; echo "<td class='center'>" . Html::convDate($data['expire']) . "</td>"; echo "</tr>"; if ($data['number'] < 0) { // One illimited license, total is illimited $tot = -1; } else { if ($tot >= 0) { // Expire license not count if (!$expired) { // Not illimited, add the current number $tot += $data['number']; } } } } echo "<tr class='tab_bg_1 noHover'>"; echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . __('Total') . "</td>"; echo "<td class='numeric'>" . ($tot > 0 ? $tot . "" : __('Unlimited')) . "</td>"; $color = $software->fields['is_valid'] ? 'green' : 'red'; echo "<td class='numeric {$color}'>" . $tot_assoc . "</td><td></td><td></td><td></td><td></td>"; echo "</tr>"; echo "</table>\n"; if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number); } else { echo "<table class='tab_cadre_fixe'><tr><th>" . __('No item found') . "</th></tr></table>"; } } echo "</div>"; }
// Show categories wicth have at least one form user can access $cat_table = getTableForItemType('PluginFormcreatorCategory'); $form_table = getTableForItemType('PluginFormcreatorForm'); $table_fp = getTableForItemType('PluginFormcreatorFormprofiles'); $where = getEntitiesRestrictRequest("", $form_table, "", "", true, false); $query = "SELECT {$cat_table}.`name`, {$cat_table}.`id`\n FROM {$cat_table}\n WHERE 0 < (\n SELECT COUNT({$form_table}.id)\n FROM {$form_table}\n WHERE {$form_table}.`plugin_formcreator_categories_id` = {$cat_table}.`id`\n AND {$form_table}.`is_active` = 1\n AND {$form_table}.`is_deleted` = 0\n AND ({$form_table}.`language` = '{$_SESSION['glpilanguage']}' OR {$form_table}.`language` = '')\n AND {$where}\n AND ({$form_table}.`access_rights` != " . PluginFormcreatorForm::ACCESS_RESTRICTED . " OR {$form_table}.`id` IN (\n SELECT plugin_formcreator_forms_id\n FROM {$table_fp}\n WHERE plugin_formcreator_profiles_id = " . (int) $_SESSION['glpiactiveprofile']['id'] . "))\n )\n ORDER BY {$cat_table}.`name` ASC"; $result = $GLOBALS['DB']->query($query); if (!empty($result)) { echo '<table class="tab_cadrehov">'; echo '<tr class="noHover">'; echo '<th><a href="../plugins/formcreator/front/formlist.php">' . _n('Form', 'Forms', 2, 'formcreator') . '</a></th>'; echo '</tr>'; // For each categories, show the list of forms the user can fill while ($category = $GLOBALS['DB']->fetch_array($result)) { echo '<tr class="noHover"><th>' . $category['name'] . '</th></tr>'; $where = getEntitiesRestrictRequest("", $form_table, "", "", true, false); $table_fp = getTableForItemType('PluginFormcreatorFormprofiles'); $query_forms = "SELECT {$form_table}.id, {$form_table}.name, {$form_table}.description\n FROM {$form_table}\n WHERE {$form_table}.`plugin_formcreator_categories_id` = {$category['id']}\n AND {$form_table}.`is_active` = 1\n AND {$form_table}.`is_deleted` = 0\n AND ({$form_table}.`language` = '{$_SESSION['glpilanguage']}' OR {$form_table}.`language` = '')\n AND {$where}\n AND (`access_rights` != " . PluginFormcreatorForm::ACCESS_RESTRICTED . " OR {$form_table}.`id` IN (\n SELECT plugin_formcreator_forms_id\n FROM {$table_fp}\n WHERE plugin_formcreator_profiles_id = " . (int) $_SESSION['glpiactiveprofile']['id'] . "))\n ORDER BY {$form_table}.name ASC"; $result_forms = $GLOBALS['DB']->query($query_forms); $i = 0; while ($form = $GLOBALS['DB']->fetch_array($result_forms)) { $i++; echo '<tr class="line' . $i % 2 . ' tab_bg_' . ($i % 2 + 1) . '">'; echo '<td>'; echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/plus.png" alt="+" title="" onclick="showDescription(' . $form['id'] . ', this)" align="absmiddle" style="cursor: pointer">'; echo ' '; echo '<a href="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/showform.php?id=' . $form['id'] . '" title="' . plugin_formcreator_encode($form['description']) . '">' . $form['name'] . '</a></td>'; echo '</tr>'; echo '<tr id="desc' . $form['id'] . '" class="line' . $i % 2 . ' form_description">';
static function showListSimple() { global $DB, $CFG_GLPI; if (!Session::haveRight(self::$rightname, self::RESERVEANITEM)) { return false; } $ri = new self(); $ok = false; $showentity = Session::isMultiEntitiesMode(); $values = array(); if (isset($_SESSION['glpi_saved']['ReservationItem'])) { $_POST = $_SESSION['glpi_saved']['ReservationItem']; } if (isset($_POST['reserve'])) { echo "<div id='viewresasearch' class='center'>"; Toolbox::manageBeginAndEndPlanDates($_POST['reserve']); echo "<div id='nosearch' class='center firstbloc'>" . "<a href=\"" . $CFG_GLPI['root_doc'] . "/front/reservationitem.php\">"; echo __('See all reservable items') . "</a></div>\n"; } else { echo "<div id='makesearch' class='center firstbloc'>" . "<a class='pointer' onClick=\"javascript:showHideDiv('viewresasearch','','','');" . "showHideDiv('makesearch','','','')\">"; echo __('Find a free item in a specific period') . "</a></div>\n"; echo "<div id='viewresasearch' style=\"display:none;\" class='center'>"; $begin_time = time(); $begin_time -= $begin_time % HOUR_TIMESTAMP; $_POST['reserve']["begin"] = date("Y-m-d H:i:s", $begin_time); $_POST['reserve']["end"] = date("Y-m-d H:i:s", $begin_time + HOUR_TIMESTAMP); $_POST['reservation_types'] = ''; } echo "<form method='post' name='form' action='" . Toolbox::getItemTypeSearchURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2'>"; echo "<th colspan='3'>" . __('Find a free item in a specific period') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>"; Html::showDateTimeField("reserve[begin]", array('value' => $_POST['reserve']["begin"], 'maybeempty' => false)); echo "</td><td rowspan='3'>"; echo "<input type='submit' class='submit' name='submit' value=\"" . _sx('button', 'Search') . "\">"; echo "</td></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Duration') . "</td><td>"; $default_delay = floor((strtotime($_POST['reserve']["end"]) - strtotime($_POST['reserve']["begin"])) / $CFG_GLPI['time_step'] / MINUTE_TIMESTAMP) * $CFG_GLPI['time_step'] * MINUTE_TIMESTAMP; $rand = Dropdown::showTimeStamp("reserve[_duration]", array('min' => 0, 'max' => 48 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date'))); echo "<br><div id='date_end{$rand}'></div>"; $params = array('duration' => '__VALUE__', 'end' => $_POST['reserve']["end"], 'name' => "reserve[end]"); Ajax::updateItemOnSelectEvent("dropdown_reserve[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); echo "</td></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Item type') . "</td><td>"; $sql = "SELECT DISTINCT(`itemtype`)\n FROM `glpi_reservationitems`\n WHERE `is_active` = 1" . getEntitiesRestrictRequest(" AND", 'glpi_reservationitems', 'entities_id', $_SESSION['glpiactiveentities']); $result = $DB->query($sql); while ($data = $DB->fetch_assoc($result)) { $values[$data['itemtype']] = $data['itemtype']::getTypeName(); } $query = "SELECT `glpi_peripheraltypes`.`name`, `glpi_peripheraltypes`.`id`\n FROM `glpi_peripheraltypes`\n LEFT JOIN `glpi_peripherals`\n ON `glpi_peripherals`.`peripheraltypes_id` = `glpi_peripheraltypes`.`id`\n LEFT JOIN `glpi_reservationitems`\n ON `glpi_reservationitems`.`items_id` = `glpi_peripherals`.`id`\n WHERE `itemtype` = 'Peripheral'\n AND `is_active` = 1\n AND `peripheraltypes_id`" . getEntitiesRestrictRequest(" AND", 'glpi_reservationitems', 'entities_id', $_SESSION['glpiactiveentities']) . "\n ORDER BY `glpi_peripheraltypes`.`name`"; foreach ($DB->request($query) as $ptype) { $id = $ptype['id']; $values["Peripheral#{$id}"] = $ptype['name']; } Dropdown::showFromArray("reservation_types", $values, array('value' => $_POST['reservation_types'], 'display_emptychoice' => true)); echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; // GET method passed to form creation echo "<div id='nosearch' class='center'>"; echo "<form name='form' method='GET' action='reservation.form.php'>"; echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='" . ($showentity ? "5" : "4") . "'>" . self::getTypeName(1) . "</th></tr>\n"; foreach ($CFG_GLPI["reservation_types"] as $itemtype) { if (!($item = getItemForItemtype($itemtype))) { continue; } $itemtable = getTableForItemType($itemtype); $otherserial = "'' AS otherserial"; if ($item->isField('otherserial')) { $otherserial = "`{$itemtable}`.`otherserial`"; } $begin = $_POST['reserve']["begin"]; $end = $_POST['reserve']["end"]; $left = ""; $where = ""; if (isset($_POST['submit']) && isset($begin) && isset($end)) { $left = "LEFT JOIN `glpi_reservations`\n ON (`glpi_reservationitems`.`id` = `glpi_reservations`.`reservationitems_id`\n AND '" . $begin . "' < `glpi_reservations`.`end`\n AND '" . $end . "' > `glpi_reservations`.`begin`)"; $where = " AND `glpi_reservations`.`id` IS NULL "; } if (isset($_POST["reservation_types"]) && !empty($_POST["reservation_types"])) { $tmp = explode('#', $_POST["reservation_types"]); $where .= " AND `glpi_reservationitems`.`itemtype` = '" . $tmp[0] . "'"; if (isset($tmp[1]) && $tmp[0] == 'Peripheral' && $itemtype == 'Peripheral') { $left .= " LEFT JOIN `glpi_peripheraltypes`\n ON (`glpi_peripherals`.`peripheraltypes_id` = `glpi_peripheraltypes`.`id`)"; $where .= " AND `{$itemtable}`.`peripheraltypes_id` = '" . $tmp[1] . "'"; } } $query = "SELECT `glpi_reservationitems`.`id`,\n `glpi_reservationitems`.`comment`,\n `{$itemtable}`.`name` AS name,\n `{$itemtable}`.`entities_id` AS entities_id,\n {$otherserial},\n `glpi_locations`.`id` AS location,\n `glpi_reservationitems`.`items_id` AS items_id\n FROM `glpi_reservationitems`\n INNER JOIN `{$itemtable}`\n ON (`glpi_reservationitems`.`itemtype` = '{$itemtype}'\n AND `glpi_reservationitems`.`items_id` = `{$itemtable}`.`id`)\n {$left}\n LEFT JOIN `glpi_locations`\n ON (`{$itemtable}`.`locations_id` = `glpi_locations`.`id`)\n WHERE `glpi_reservationitems`.`is_active` = '1'\n AND `glpi_reservationitems`.`is_deleted` = '0'\n AND `{$itemtable}`.`is_deleted` = '0'\n {$where} " . getEntitiesRestrictRequest(" AND", $itemtable, '', $_SESSION['glpiactiveentities'], $item->maybeRecursive()) . "\n ORDER BY `{$itemtable}`.`entities_id`,\n `{$itemtable}`.`name`"; if ($result = $DB->query($query)) { while ($row = $DB->fetch_assoc($result)) { echo "<tr class='tab_bg_2'><td>"; echo "<input type='checkbox' name='item[" . $row["id"] . "]' value='" . $row["id"] . "'>" . "</td>"; $typename = $item->getTypeName(); if ($itemtype == 'Peripheral') { $item->getFromDB($row['items_id']); if (isset($item->fields["peripheraltypes_id"]) && $item->fields["peripheraltypes_id"] != 0) { $typename = Dropdown::getDropdownName("glpi_peripheraltypes", $item->fields["peripheraltypes_id"]); } } echo "<td><a href='reservation.php?reservationitems_id=" . $row['id'] . "'>" . sprintf(__('%1$s - %2$s'), $typename, $row["name"]) . "</a></td>"; echo "<td>" . Dropdown::getDropdownName("glpi_locations", $row["location"]) . "</td>"; echo "<td>" . nl2br($row["comment"]) . "</td>"; if ($showentity) { echo "<td>" . Dropdown::getDropdownName("glpi_entities", $row["entities_id"]) . "</td>"; } echo "</tr>\n"; $ok = true; } } } if ($ok) { echo "<tr class='tab_bg_1 center'><td colspan='" . ($showentity ? "5" : "4") . "'>"; if (isset($_POST['reserve'])) { echo Html::hidden('begin', array('value' => $_POST['reserve']["begin"])); echo Html::hidden('end', array('value' => $_POST['reserve']["end"])); } echo "<input type='submit' value=\"" . _sx('button', 'Add') . "\" class='submit'></td></tr>\n"; } echo "</table>\n"; echo "<input type='hidden' name='id' value=''>"; echo "</form>"; // No CSRF token needed echo "</div>\n"; }
/** * @param $target * @param $date1 * @param $date2 * @param $start **/ static function showItems($target, $date1, $date2, $start) { global $DB, $CFG_GLPI; $view_entities = Session::isMultiEntitiesMode(); if ($view_entities) { $entities = getAllDatasFromTable('glpi_entities'); } $output_type = Search::HTML_OUTPUT; if (isset($_GET["display_type"])) { $output_type = $_GET["display_type"]; } if (empty($date2)) { $date2 = date("Y-m-d"); } $date2 .= " 23:59:59"; // 1 an par defaut if (empty($date1)) { $date1 = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y") - 1)); } $date1 .= " 00:00:00"; $query = "SELECT `glpi_items_tickets`.`itemtype`,\n `glpi_items_tickets`.`items_id`,\n COUNT(*) AS NB\n FROM `glpi_tickets`\n LEFT JOIN `glpi_items_tickets`\n ON (`glpi_tickets`.`id` = `glpi_items_tickets`.`tickets_id`)\n WHERE `date` <= '{$date2}'\n AND `glpi_tickets`.`date` >= '{$date1}' " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n AND `glpi_items_tickets`.`itemtype` <> ''\n AND `glpi_items_tickets`.`items_id` > 0\n GROUP BY `glpi_items_tickets`.`itemtype`, `glpi_items_tickets`.`items_id`\n ORDER BY NB DESC"; $result = $DB->query($query); $numrows = $DB->numrows($result); if ($numrows > 0) { if ($output_type == Search::HTML_OUTPUT) { Html::printPager($start, $numrows, $target, "date1=" . $date1 . "&date2=" . $date2 . "&type=hardwares&start={$start}", 'Stat'); echo "<div class='center'>"; } $end_display = $start + $_SESSION['glpilist_limit']; if (isset($_GET['export_all'])) { $end_display = $numrows; } echo Search::showHeader($output_type, $end_display - $start + 1, 2, 1); $header_num = 1; echo Search::showNewLine($output_type); echo Search::showHeaderItem($output_type, _n('Associated element', 'Associated elements', 2), $header_num); if ($view_entities) { echo Search::showHeaderItem($output_type, __('Entity'), $header_num); } echo Search::showHeaderItem($output_type, __('Number of tickets'), $header_num); echo Search::showEndLine($output_type); $DB->data_seek($result, $start); $i = $start; if (isset($_GET['export_all'])) { $start = 0; } for ($i = $start; $i < $numrows && $i < $end_display; $i++) { $item_num = 1; // Get data and increment loop variables $data = $DB->fetch_assoc($result); if (!($item = getItemForItemtype($data["itemtype"]))) { continue; } if ($item->getFromDB($data["items_id"])) { echo Search::showNewLine($output_type, $i % 2); echo Search::showItem($output_type, sprintf(__('%1$s - %2$s'), $item->getTypeName(), $item->getLink()), $item_num, $i - $start + 1, "class='center'" . " " . ($item->isDeleted() ? " class='deleted' " : "")); if ($view_entities) { $ent = $item->getEntityID(); $ent = $entities[$ent]['completename']; echo Search::showItem($output_type, $ent, $item_num, $i - $start + 1, "class='center'" . " " . ($item->isDeleted() ? " class='deleted' " : "")); } echo Search::showItem($output_type, $data["NB"], $item_num, $i - $start + 1, "class='center'" . " " . ($item->isDeleted() ? " class='deleted' " : "")); } } echo Search::showFooter($output_type); if ($output_type == Search::HTML_OUTPUT) { echo "</div>"; } } }
/** * Execute the query to select box with all glpi users where select key = name * * Internaly used by showGroup_Users, dropdownUsers and ajax/dropdownUsers.php * * @param $count true if execute an count(*) (true by default) * @param $right limit user who have specific right (default 'all') * @param $entity_restrict Restrict to a defined entity (default -1) * @param $value default value (default 0) * @param $used array Already used items ID: not to display in dropdown * @param $search pattern (default '') * * @return mysql result set. **/ static function getSqlSearchResult($count = true, $right = "all", $entity_restrict = -1, $value = 0, $used = array(), $search = '') { global $DB, $CFG_GLPI; // No entity define : use active ones if ($entity_restrict < 0) { $entity_restrict = $_SESSION["glpiactiveentities"]; } $joinprofile = false; switch ($right) { case "interface": $joinprofile = true; $where = " `glpi_profiles`.`interface` = 'central' " . getEntitiesRestrictRequest("AND", "glpi_profiles_users", '', $entity_restrict, 1); break; case "id": $where = " `glpi_users`.`id` = '" . Session::getLoginUserID() . "' "; break; case "delegate": $groups = self::getDelegateGroupsForUser($entity_restrict); $users = array(); if (count($groups)) { $query = "SELECT `glpi_users`.`id`\n FROM `glpi_groups_users`\n LEFT JOIN `glpi_users`\n ON (`glpi_users`.`id` = `glpi_groups_users`.`users_id`)\n WHERE `glpi_groups_users`.`groups_id` IN ('" . implode("','", $groups) . "')\n AND `glpi_groups_users`.`users_id` <> '" . Session::getLoginUserID() . "'"; $result = $DB->query($query); if ($DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $users[$data["id"]] = $data["id"]; } } } // Add me to users list for central if ($_SESSION['glpiactiveprofile']['interface'] == 'central') { $users[Session::getLoginUserID()] = Session::getLoginUserID(); } if (count($users)) { $where = " `glpi_users`.`id` IN ('" . implode("','", $users) . "')"; } else { $where = '0'; } break; case "all": $where = " `glpi_users`.`id` > '1' " . getEntitiesRestrictRequest("AND", "glpi_profiles_users", '', $entity_restrict, 1); break; default: $joinprofile = true; if (!is_array($right)) { $right = array($right); } $forcecentral = true; $where = array(); foreach ($right as $r) { // Check read or active for rights $where[] = " (`glpi_profiles`.`" . $r . "` IN ('1', 'r', 'w') " . getEntitiesRestrictRequest("AND", "glpi_profiles_users", '', $entity_restrict, 1) . ") "; if (in_array($r, Profile::$helpdesk_rights)) { $forcecentral = false; } } $where = '(' . implode(' OR ', $where); if ($forcecentral) { $where .= " AND `glpi_profiles`.`interface` = 'central' "; } $where .= ')'; } $where .= " AND `glpi_users`.`is_deleted` = '0'\n AND `glpi_users`.`is_active` = '1' "; if (is_numeric($value) && $value || count($used)) { $where .= " AND `glpi_users`.`id` NOT IN ("; if (is_numeric($value)) { $first = false; $where .= $value; } else { $first = true; } foreach ($used as $val) { if ($first) { $first = false; } else { $where .= ","; } $where .= $val; } $where .= ")"; } if ($count) { $query = "SELECT COUNT(DISTINCT `glpi_users`.`id` ) AS CPT\n FROM `glpi_users` "; } else { $query = "SELECT DISTINCT `glpi_users`.*\n FROM `glpi_users` "; } $query .= " LEFT JOIN `glpi_useremails`\n ON (`glpi_users`.`id` = `glpi_useremails`.`users_id`)\n LEFT JOIN `glpi_profiles_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)"; if ($joinprofile) { $query .= " LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id`) "; } if ($count) { $query .= " WHERE {$where} "; } else { if (strlen($search) > 0 && $search != $CFG_GLPI["ajax_wildcard"]) { $where .= " AND (`glpi_users`.`name` " . Search::makeTextSearch($search) . "\n OR `glpi_users`.`realname` " . Search::makeTextSearch($search) . "\n OR `glpi_users`.`firstname` " . Search::makeTextSearch($search) . "\n OR `glpi_users`.`phone` " . Search::makeTextSearch($search) . "\n OR `glpi_useremails`.`email` " . Search::makeTextSearch($search) . "\n OR CONCAT(`glpi_users`.`realname`,' ',`glpi_users`.`firstname`) " . Search::makeTextSearch($search) . ")"; } $query .= " WHERE {$where} "; if ($_SESSION["glpinames_format"] == self::FIRSTNAME_BEFORE) { $query .= " ORDER BY `glpi_users`.`firstname`,\n `glpi_users`.`realname`,\n `glpi_users`.`name` "; } else { $query .= " ORDER BY `glpi_users`.`realname`,\n `glpi_users`.`firstname`,\n `glpi_users`.`name` "; } if ($search != $CFG_GLPI["ajax_wildcard"]) { $query .= " LIMIT 0," . $CFG_GLPI["dropdown_max"]; } } return $DB->query($query); }
function generateContactsCfg($file=0, $tag='') { global $DB; $pmEntity = new PluginMonitoringEntity(); $calendar = new Calendar(); PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Starting generateContactsCfg ($tag) ...\n" ); $a_users_used = array(); $a_contacts = array(); // Add default contact 'monitoring' for fake hosts // $a_calendars = current($calendar->find("", "", 1)); // $cal = '24x7'; // if (isset($a_calendars['name'])) { // $cal = $a_calendars['name']; // } // $a_contacts[-1] = array( // 'contact_name' => 'monitoring', // 'alias' => 'monitoring', // 'host_notifications_enabled' => '0', // 'service_notifications_enabled' => '0', // 'service_notification_period' => $cal, // 'host_notification_period' => $cal, // 'service_notification_options' => '', // 'host_notification_options' => '', // 'service_notification_commands' => '', // 'host_notification_commands' => '', // 'email' => '', // 'pager' => '', // ); $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); $a_entities_list = array(); foreach ($a_entities_allowed as $entity) { $a_entities_list = getSonsOf("glpi_entities", $entity); } // Always add root entity $a_entities_list[] = '0'; $where = ''; if (! isset($a_entities_allowed['-1'])) { $where = getEntitiesRestrictRequest("WHERE", "glpi_plugin_monitoring_contacts_items", '', $a_entities_list); } $i=0; $query = "SELECT * FROM `glpi_plugin_monitoring_contacts_items` $where"; // Toolbox::logInFile("pm-shinken", "- Contacts query: $query\n"); $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { if ($data['users_id'] > 0) { if ((!isset($a_users_used[$data['users_id']]))) { $a_contacts = $this->_addContactUser($a_contacts, $data['users_id'], $i); $i++; $a_users_used[$data['users_id']] = 1; } } else if ($data['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if ((!isset($a_users_used[$datag['users_id']]))) { $a_contacts = $this->_addContactUser($a_contacts, $datag['users_id'], $i); $i++; $a_users_used[$datag['users_id']] = 1; } } } } // Add user monitoring $user = new User(); $a_monit_user = current($user->find("`name`='monitoring'", '', 1)); if ((!isset($a_users_used[$a_monit_user['id']]))) { $a_contacts = $this->_addContactUser($a_contacts, $a_monit_user['id'], $i); } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateContactsCfg\n" ); if ($file == "1") { $config = "# Generated by plugin monitoring for GLPI\n# on ".date("Y-m-d H:i:s")."\n\n"; foreach ($a_contacts as $data) { $config .= $this->writeFile("contact", $data); } return array('contacts.cfg', $config); } else { return $a_contacts; } }
/** * Print the HTML array of suppliers for this contract * * @since version 0.84 * * @param $contract Contract object * * @return Nothing (HTML display) **/ static function showForContract(Contract $contract) { global $DB, $CFG_GLPI; $instID = $contract->fields['id']; if (!$contract->can($instID, 'r') || !Session::haveRight("contact_enterprise", "r")) { return false; } $canedit = $contract->can($instID, 'w'); $rand = mt_rand(); $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); $suppliers = array(); $used = array(); if ($number = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $suppliers[$data['id']] = $data; $used[$data['entID']] = $data['entID']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='contractsupplier_form{$rand}' id='contractsupplier_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<input type='hidden' name='contracts_id' value='{$instID}'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a supplier') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='right'>"; Supplier::dropdown(array('used' => $used, 'entity' => $contract->fields["entities_id"], 'entity_sons' => $contract->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); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Supplier') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Third party type') . "</th>"; echo "<th>" . __('Phone') . "</th>"; echo "<th>" . __('Website') . "</th>"; echo "</tr>"; $used = array(); foreach ($suppliers as $data) { $ID = $data['id']; $website = $data['website']; if (!empty($website)) { if (!preg_match("?https*://?", $website)) { $website = "http://" . $website; } $website = "<a target=_blank href='{$website}'>" . $data['website'] . "</a>"; } $entID = $data['entID']; $entity = $data['entity']; $used[$entID] = $entID; $entname = Dropdown::getDropdownName("glpi_suppliers", $entID); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td>"; Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); echo "</td>"; } echo "<td class='center'>"; if ($_SESSION["glpiis_ids_visible"] || empty($entname)) { $entname = sprintf(__('%1$s (%2$s)'), $entname, $entID); } echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/supplier.form.php?id={$entID}'>" . $entname; echo "</a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $entity) . "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_suppliertypes", $data['type']) . "</td>"; echo "<td class='center'>" . $data['phone'] . "</td>"; echo "<td class='center'>" . $website . "</td>"; echo "</tr>"; } echo "</table>"; if ($canedit && $number) { $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); Html::closeForm(); } echo "</div>"; }
/** * Display changes for an item * * Will also display changes of linked items * * @param $item CommonDBTM object * * @return nothing (display a table) **/ static function showListForItem(CommonDBTM $item) { global $DB, $CFG_GLPI; if (!Session::haveRight(self::$rightname, self::READALL)) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = ''; $order = ''; $options['reset'] = 'reset'; switch ($item->getType()) { case 'User': $restrict = "(`glpi_changes_users`.`users_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 4; // status $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'OR'; $options['criteria'][1]['field'] = 66; // status $options['criteria'][1]['searchtype'] = 'equals'; $options['criteria'][1]['value'] = $item->getID(); $options['criteria'][1]['link'] = 'OR'; $options['criteria'][5]['field'] = 5; // status $options['criteria'][5]['searchtype'] = 'equals'; $options['criteria'][5]['value'] = $item->getID(); $options['criteria'][5]['link'] = 'OR'; break; case 'Supplier': $restrict = "(`glpi_changes_suppliers`.`suppliers_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 6; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Group': // Mini search engine if ($item->haveChildren()) { $tree = Session::getSavedOption(__CLASS__, 'tree', 0); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th>" . __('Last changes') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; _e('Child groups'); Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } echo "</td></tr></table>"; if ($tree) { $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")"; } else { $restrict = "='" . $item->getID() . "'"; } $restrict = "(`glpi_changes_groups`.`groups_id` {$restrict}\n AND `glpi_changes_groups`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 71; $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; default: $restrict = "(`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; break; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n ORDER BY {$order}\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); // Ticket for the item echo "<div class='firstbloc'><table class='tab_cadre_fixe'>"; $colspan = 11; if (count($_SESSION["glpiactiveentities"]) > 1) { $colspan++; } if ($number > 0) { Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); echo "<tr><th colspan='{$colspan}'>"; //TRANS : %d is the number of problems echo sprintf(_n('Last %d change', 'Last %d changes', $number), $number); // echo "<span class='small_space'><a href='".$CFG_GLPI["root_doc"]."/front/ticket.php?". // Toolbox::append_params($options,'&')."'>".__('Show all')."</a></span>"; echo "</th></tr>"; } else { echo "<tr><th>" . __('No change found.') . "</th></tr>"; } // Ticket list if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('Problem', $data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } echo "</table></div>"; // Tickets for linked items $linkeditems = $item->getLinkedItems(); $restrict = array(); if (count($linkeditems)) { foreach ($linkeditems as $ltype => $tab) { foreach ($tab as $lID) { $restrict[] = "(`itemtype` = '{$ltype}' AND `items_id` = '{$lID}')"; } } } if (count($restrict)) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_changes') . "\n ORDER BY `glpi_changes`.`date_mod` DESC\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='{$colspan}'>"; _e('Changes on linked items'); echo "</th></tr>"; if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } else { echo "<tr><th>" . __('No change found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }
/** * @since version 0.85 **/ static function getSearchOptionsToAdd() { $tab = array(); $tab[145]['table'] = 'glpi_links'; $tab[145]['field'] = '_virtual'; $tab[145]['name'] = _n('External link', 'External links', Session::getPluralNumber()); $tab[145]['datatype'] = 'specific'; $tab[145]['additionalfields'] = array('id', 'link', 'name', 'data', 'open_window'); $tab[145]['nosearch'] = true; $tab[145]['forcegroupby'] = true; $tab[145]['nosort'] = true; $tab[145]['joinparams'] = array('beforejoin' => array('table' => 'glpi_links_itemtypes', 'joinparams' => array('jointype' => 'itemtypeonly'))); if (!Session::isCron() && !isCommandLine()) { $tab[145]['joinparams']['condition'] = getEntitiesRestrictRequest('AND', 'NEWTABLE'); } return $tab; }
$conditionAll = getEntitiesRestrictRequest('AND', 'glpi_plugin_resources_resources', '', '', true); $query .= $conditionAll . " " . getOrderBy('entity', $columns); $result = $DB->query($query); for ($row_num = 0; $data = $DB->fetch_assoc($result); $row_num++) { $dataAll[$row_num] = $data; } //case employment $queryEmploy = "SELECT `glpi_plugin_resources_employments`.`entities_id` AS entity,\n 'Employment' AS typeName,\n `glpi_plugin_resources_employments`.`name` AS name,\n `glpi_plugin_resources_employments`.`id` AS ID,\n NULL AS firstname,\n NULL AS registration_number,\n `glpi_plugin_resources_professions`.`id` AS profID,\n `glpi_plugin_resources_professions`.`name` AS profession,\n `glpi_plugin_resources_employments`.`begin_date` AS date_begin,\n `glpi_plugin_resources_employments`.`end_date` AS date_end,\n `glpi_plugin_resources_professions`.`begin_date`,\n `glpi_plugin_resources_professions`.`end_date`\n FROM `glpi_plugin_resources_employments`\n LEFT JOIN `glpi_plugin_resources_professions`\n ON (`glpi_plugin_resources_employments`.`plugin_resources_professions_id` = `glpi_plugin_resources_professions`.`id`)\n WHERE ((`glpi_plugin_resources_employments`.`begin_date` < '" . $date . "'\n AND (`glpi_plugin_resources_employments`.`end_date` IS NULL\n OR `glpi_plugin_resources_employments`.`end_date` > '" . $date . "'))\n AND `glpi_plugin_resources_professions`.`id` IS NOT NULL)\n AND ((`glpi_plugin_resources_employments`.`begin_date` > `glpi_plugin_resources_professions`.`end_date`\n OR `glpi_plugin_resources_employments`.`end_date` < `glpi_plugin_resources_professions`.`begin_date`)\n OR (`glpi_plugin_resources_professions`.`end_date` < '" . $date . "'\n OR `glpi_plugin_resources_professions`.`begin_date` > '" . $date . "'))"; // WHERE ((`glpi_plugin_resources_employments`.`begin_date` > `glpi_plugin_resources_ranks`.`end_date` // OR `glpi_plugin_resources_employments`.`end_date` < `glpi_plugin_resources_professions`.`begin_date` // OR `glpi_plugin_resources_employments`.`begin_date` < '".$date."') // AND `glpi_plugin_resources_employments`.`end_date` IS NULL // AND (`glpi_plugin_resources_professions`.`end_date` < '".$date."' // OR `glpi_plugin_resources_professions`.`begin_date` > '".$date."')) // AND `glpi_plugin_resources_professions`.`id` IS NOT NULL)"; $conditionAll = getEntitiesRestrictRequest('AND', 'glpi_plugin_resources_employments', '', '', true); $queryEmploy .= $conditionAll . " " . getOrderBy('entity', $columns); foreach ($DB->request($queryEmploy) as $dataEmploy) { $dataAll[$row_num] = $dataEmploy; $row_num++; } $nbtot = count($dataAll); if ($limit) { $start = isset($_GET["start"]) ? $_GET["start"] : 0; if ($start >= $nbtot) { $start = 0; } } else { $start = 0; } if ($nbtot == 0) {
static function showListSimple() { global $DB, $CFG_GLPI; if (!Session::haveRight("reservation_helpdesk", "1")) { return false; } $ri = new self(); $ok = false; $showentity = Session::isMultiEntitiesMode(); // GET method passed to form creation echo "<div class='center'><form name='form' method='GET' action='reservation.form.php'>"; echo "<table class='tab_cadre'>"; echo "<tr><th colspan='" . ($showentity ? "5" : "4") . "'>" . self::getTypeName(1) . "</th></tr>\n"; foreach ($CFG_GLPI["reservation_types"] as $itemtype) { if (!($item = getItemForItemtype($itemtype))) { continue; } $itemtable = getTableForItemType($itemtype); $query = "SELECT `glpi_reservationitems`.`id`,\n `glpi_reservationitems`.`comment`,\n `{$itemtable}`.`name` AS name,\n `{$itemtable}`.`entities_id` AS entities_id,\n `glpi_locations`.`completename` AS location,\n `glpi_reservationitems`.`items_id` AS items_id\n FROM `glpi_reservationitems`\n INNER JOIN `{$itemtable}`\n ON (`glpi_reservationitems`.`itemtype` = '{$itemtype}'\n AND `glpi_reservationitems`.`items_id` = `{$itemtable}`.`id`)\n LEFT JOIN `glpi_locations`\n ON (`{$itemtable}`.`locations_id` = `glpi_locations`.`id`)\n WHERE `glpi_reservationitems`.`is_active` = '1'\n AND `glpi_reservationitems`.`is_deleted` = '0'\n AND `{$itemtable}`.`is_deleted` = '0'" . getEntitiesRestrictRequest(" AND", $itemtable, '', $_SESSION['glpiactiveentities'], $item->maybeRecursive()) . "\n ORDER BY `{$itemtable}`.`entities_id`,\n `{$itemtable}`.`name`"; if ($result = $DB->query($query)) { while ($row = $DB->fetch_assoc($result)) { echo "<tr class='tab_bg_2'><td>"; echo "<input type='checkbox' name='item[" . $row["id"] . "]' value='" . $row["id"] . "'>" . "</td>"; $typename = $item->getTypeName(); if ($itemtype == 'Peripheral') { $item->getFromDB($row['items_id']); if (isset($item->fields["peripheraltypes_id"]) && $item->fields["peripheraltypes_id"] != 0) { $typename = Dropdown::getDropdownName("glpi_peripheraltypes", $item->fields["peripheraltypes_id"]); } } echo "<td><a href='reservation.php?reservationitems_id=" . $row['id'] . "'>" . sprintf(__('%1$s - %2$s'), $typename, $row["name"]) . "</a></td>"; echo "<td>" . $row["location"] . "</td>"; echo "<td>" . nl2br($row["comment"]) . "</td>"; if ($showentity) { echo "<td>" . Dropdown::getDropdownName("glpi_entities", $row["entities_id"]) . "</td>"; } echo "</tr>\n"; $ok = true; } } } if ($ok) { echo "<tr class='tab_bg_1 center'><td colspan='" . ($showentity ? "5" : "4") . "'>"; echo "<input type='submit' value=\"" . _sx('button', 'Add') . "\" class='submit'></td></tr>\n"; } echo "</table>\n"; echo "<input type='hidden' name='id' value=''>"; echo "</form>"; // No CSRF token needed echo "</div>\n"; }
function showCentral($who) { global $DB, $CFG_GLPI; echo "<table class='tab_cadre_central'><tr><td>"; if ($this->canView()) { $who = Session::getLoginUserID(); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } $ASSIGN = ""; if ($who > 0) { $ASSIGN = " AND ((`" . $this->getTable() . "`.`users_id` = '{$who}')"; } //if ($who_group>0) { $ASSIGN .= " OR (`" . $this->getTable() . "`.`groups_id` IN (SELECT `groups_id` \n FROM `glpi_groups_users` \n WHERE `users_id` = '{$who}') )"; //} $query = "SELECT `" . $this->getTable() . "`.`id` AS plugin_resources_tasks_id, `" . $this->getTable() . "`.`name` AS name_task, `" . $this->getTable() . "`.`plugin_resources_tasktypes_id` AS plugin_resources_tasktypes_id,`" . $this->getTable() . "`.`is_deleted` AS is_deleted, "; $query .= "`" . $this->getTable() . "`.`users_id` AS users_id_task, `glpi_plugin_resources_resources`.`id` as id, `glpi_plugin_resources_resources`.`name` AS name, `glpi_plugin_resources_resources`.`firstname` AS firstname, `glpi_plugin_resources_resources`.`entities_id`, `glpi_plugin_resources_resources`.`users_id` as users_id "; $query .= " FROM `" . $this->getTable() . "`,`glpi_plugin_resources_resources` "; $query .= " WHERE `glpi_plugin_resources_resources`.`is_template` = '0' \n AND `glpi_plugin_resources_resources`.`is_deleted` = '0' \n AND `" . $this->getTable() . "`.`is_deleted` = '0' \n AND `" . $this->getTable() . "`.`is_finished` = '0' \n AND `" . $this->getTable() . "`.`plugin_resources_resources_id` = `glpi_plugin_resources_resources`.`id` \n {$ASSIGN} ) "; // Add Restrict to current entities $PluginResourcesResource = new PluginResourcesResource(); $itemtable = "glpi_plugin_resources_resources"; if ($PluginResourcesResource->isEntityAssign()) { $LINK = " AND "; $query .= getEntitiesRestrictRequest($LINK, $itemtable); } $query .= " ORDER BY `glpi_plugin_resources_resources`.`name` DESC LIMIT 10;"; $result = $DB->query($query); $number = $DB->numrows($result); if ($number > 0) { echo "<div align='center'><table class='tab_cadre' width='100%'>"; echo "<tr><th colspan='" . (7 + $colsup) . "'>" . PluginResourcesResource::getTypeName(2) . ": " . __('Tasks in progress', 'resources') . " <a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.php?contains%5B0%5D=0&field%5B0%5D=9&sort=1&is_deleted=0&start=0'>" . __('All') . "</a></th></tr>"; echo "<tr><th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . PluginResourcesTaskType::getTypeName(2) . "</th>"; echo "<th>" . __('Planning') . "</th>"; echo "<th>" . PluginResourcesResource::getTypeName(1) . "</th>"; echo "<th>" . __('Resource manager', 'resources') . "</th>"; echo "<th>" . __('User') . "</th>"; echo "</tr>"; while ($data = $DB->fetch_array($result)) { echo "<tr class='tab_bg_1" . ($data["is_deleted"] == '1' ? "_2" : "") . "'>"; echo "<td class='center'><a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.form.php?id=" . $data["plugin_resources_tasks_id"] . "'>" . $data["name_task"]; if ($_SESSION["glpiis_ids_visible"]) { echo " (" . $data["plugin_resources_tasks_id"] . ")"; } echo "</a></td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_resources_tasktypes", $data["plugin_resources_tasktypes_id"]) . "</td>"; echo "<td align='center'>"; $restrict = " `plugin_resources_tasks_id` = '" . $data['plugin_resources_tasks_id'] . "' "; $plans = getAllDatasFromTable("glpi_plugin_resources_taskplannings", $restrict); if (!empty($plans)) { foreach ($plans as $plan) { echo Html::convDateTime($plan["begin"]) . " -> " . Html::convDateTime($plan["end"]); } } else { _e('None'); } echo "</td>"; echo "<td class='center'><a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/resource.form.php?id=" . $data["id"] . "'>" . $data["name"] . " " . $data["firstname"]; if ($_SESSION["glpiis_ids_visible"]) { echo " (" . $data["id"] . ")"; } echo "</a></td>"; echo "<td class='center'>" . getUserName($data["users_id"]) . "</td>"; echo "<td class='center'>" . getUserName($data["users_id_task"]) . "</td>"; echo "</tr>"; } echo "</table></div><br>"; } } $PluginResourcesChecklist = new PluginResourcesChecklist(); $PluginResourcesChecklist->showOnCentral(false); echo "<br>"; $PluginResourcesChecklist->showOnCentral(true); echo "</td></tr></table>"; }
/** * function to check one right of a user * * @since version 0.84 * * @param $user integer id of the user to check rights * @param $right string right to check * @param $valright integer/string/array value of the rights searched * @param $entity integer id of the entity * * @return boolean */ static function haveUserRight($user, $right, $valright, $entity) { global $DB; $query = "SELECT {$right}\n FROM `glpi_profiles`\n INNER JOIN `glpi_profiles_users`\n ON (`glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id`)\n WHERE `glpi_profiles_users`.`users_id` = '{$user}'\n AND {$right} IN ('{$valright}') " . getEntitiesRestrictRequest(" AND ", "glpi_profiles_users", '', $entity, true); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { return true; } } return false; }
/** * Print the HTML array for infocoms linked * *@return Nothing (display) * **/ function showInfocoms() { global $DB, $CFG_GLPI; $instID = $this->fields['id']; if (!$this->can($instID, 'r')) { return false; } $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_infocoms`\n WHERE `suppliers_id` = '{$instID}'\n AND `itemtype` NOT IN ('ConsumableItem', 'CartridgeItem', 'Software')\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>"; Html::printPagerForm(); echo "</th><th colspan='3'>"; if ($DB->numrows($result) == 0) { _e('No associated item'); } else { echo _n('Associated item', 'Associated items', $DB->numrows($result)); } echo "</th></tr>"; echo "<tr><th>" . __('Type') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; $num = 0; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $linktype = $itemtype; $linkfield = 'id'; $itemtable = getTableForItemType($itemtype); $query = "SELECT `glpi_infocoms`.`entities_id`, `name`, `{$itemtable}`.*\n FROM `glpi_infocoms`\n INNER JOIN `{$itemtable}` ON (`{$itemtable}`.`id` = `glpi_infocoms`.`items_id`) "; // Set $linktype for entity restriction AND link to search engine if ($itemtype == 'Cartridge') { $query .= "INNER JOIN `glpi_cartridgeitems`\n ON (`glpi_cartridgeitems`.`id`=`glpi_cartridges`.`cartridgeitems_id`) "; $linktype = 'CartridgeItem'; $linkfield = 'cartridgeitems_id'; } if ($itemtype == 'Consumable') { $query .= "INNER JOIN `glpi_consumableitems`\n ON (`glpi_consumableitems`.`id`=`glpi_consumables`.`consumableitems_id`) "; $linktype = 'ConsumableItem'; $linkfield = 'consumableitems_id'; } $linktable = getTableForItemType($linktype); $query .= "WHERE `glpi_infocoms`.`itemtype` = '{$itemtype}'\n AND `glpi_infocoms`.`suppliers_id` = '{$instID}'" . getEntitiesRestrictRequest(" AND", $linktable) . "\n ORDER BY `glpi_infocoms`.`entities_id`,\n `{$linktable}`.`name`"; $result_linked = $DB->query($query); $nb = $DB->numrows($result_linked); // Set $linktype for link to search engine pnly if ($itemtype == 'SoftwareLicense' && $nb > $_SESSION['glpilist_limit']) { $linktype = 'Software'; $linkfield = 'softwares_id'; } if ($nb > $_SESSION['glpilist_limit']) { echo "<tr class='tab_bg_1'>"; $title = $item->getTypeName($nb); if ($nb > 0) { $title = sprintf(__('%1$s: %2$s'), $title, $nb); } echo "<td class='center'>" . $title . "</td>"; echo "<td class='center' colspan='2'>"; echo "<a href='" . Toolbox::getItemTypeSearchURL($linktype) . "?" . rawurlencode("contains[0]") . "=" . rawurlencode('$$$$' . $instID) . "&" . rawurlencode("field[0]") . "=53&sort=80&order=ASC&is_deleted=0&start=0" . "'>" . __('Device list') . "</a></td>"; echo "<td class='center'>-</td><td class='center'>-</td></tr>"; } else { if ($nb) { for ($prem = true; $data = $DB->fetch_assoc($result_linked); $prem = false) { $name = $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]); } $link = Toolbox::getItemTypeFormURL($linktype); $name = "<a href=\"" . $link . "?id=" . $data[$linkfield] . "\">" . $name . "</a>"; echo "<tr class='tab_bg_1'>"; if ($prem) { $title = $item->getTypeName($nb); if ($nb > 0) { $title = sprintf(__('%1$s: %2$s'), $title, $nb); } echo "<td class='center top' rowspan='{$nb}'>" . $title . "</td>"; } echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entities_id"]) . "</td>"; echo "<td class='center"; echo (isset($data['is_deleted']) && $data['is_deleted'] ? " tab_bg_2_2'" : "'") . ">"; echo $name . "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } $num += $nb; } } echo "<tr class='tab_bg_2'>"; echo "<td class='center'>" . ($num > 0 ? sprintf(__('%1$s = %2$s'), __('Total'), $num) : " ") . "</td>"; echo "<td colspan='4'> </td></tr> "; echo "</table></div>"; }
/** Get recipient of tickets between 2 dates * * @param $date1 date : begin date * @param $date2 date : end date * @param title : indicates if stat if by title (true) or type (false) * * @return array contains the distinct recipents which have tickets **/ function getUsedUserTitleOrTypeBetween($date1 = '', $date2 = '', $title = true) { global $DB; if ($title) { $table = "glpi_usertitles"; $field = "usertitles_id"; } else { $table = "glpi_usercategories"; $field = "usercategories_id"; } $query = "SELECT DISTINCT `glpi_users`.`{$field}`\n FROM `glpi_tickets`\n INNER JOIN `glpi_tickets_users`\n ON (`glpi_tickets`.`id` = `glpi_tickets_users`.`tickets_id`\n AND `glpi_tickets_users`.`type` = '" . CommonITILActor::REQUESTER . "')\n INNER JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_tickets_users`.`users_id`)\n LEFT JOIN `{$table}` ON (`{$table}`.`id` = `glpi_users`.`{$field}`) " . getEntitiesRestrictRequest("WHERE", "glpi_tickets"); if (!empty($date1) || !empty($date2)) { $query .= " AND (" . getDateRequest("`glpi_tickets`.`date`", $date1, $date2) . "\n OR " . getDateRequest("`glpi_tickets`.`closedate`", $date1, $date2) . ") "; } $query .= " ORDER BY `glpi_users`.`{$field}`"; $result = $DB->query($query); $tab = array(); if ($DB->numrows($result) >= 1) { while ($line = $DB->fetch_assoc($result)) { $tmp['id'] = $line[$field]; $tmp['link'] = Dropdown::getDropdownName($table, $line[$field]); $tab[] = $tmp; } } return $tab; }
/** Get groups assigned to itil object between 2 dates * * @param $date1 date : begin date (default '') * @param $date2 date : end date (default '') * * @return array contains the distinct groups assigned to a tickets **/ function getUsedAssignGroupBetween($date1 = '', $date2 = '') { global $DB; $linkclass = new $this->grouplinkclass(); $linktable = $linkclass->getTable(); $query = "SELECT DISTINCT `glpi_groups`.`id`, `glpi_groups`.`completename`\n FROM `" . $this->getTable() . "`\n LEFT JOIN `{$linktable}`\n ON (`{$linktable}`.`" . $this->getForeignKeyField() . "` = `" . $this->getTable() . "`.`id`\n AND `{$linktable}`.`type` = '" . CommonITILActor::ASSIGN . "')\n LEFT JOIN `glpi_groups` ON (`{$linktable}`.`groups_id` = `glpi_groups`.`id`)\n WHERE NOT `" . $this->getTable() . "`.`is_deleted` " . getEntitiesRestrictRequest("AND", $this->getTable()); if (!empty($date1) || !empty($date2)) { $query .= " AND (" . getDateRequest("`" . $this->getTable() . "`.`date`", $date1, $date2) . "\n OR " . getDateRequest("`" . $this->getTable() . "`.`closedate`", $date1, $date2) . ") "; } $query .= " ORDER BY `glpi_groups`.`completename`"; $result = $DB->query($query); $tab = array(); if ($DB->numrows($result) >= 1) { while ($line = $DB->fetch_assoc($result)) { $tmp['id'] = $line["id"]; $tmp['link'] = $line["completename"]; $tab[] = $tmp; } } return $tab; }
function constructSQL($itemtype, $params, $items_id_check = 0) { global $CFG_GLPI; // Instanciate an object to access method $item = NULL; if ($itemtype != 'States' && class_exists($itemtype)) { $item = new $itemtype(); } // Default values of parameters $p = array(); $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } if ($p['export_all']) { $p['start'] = 0; } // Manage defautll seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } // $target = Toolbox::getItemTypeSearchURL($itemtype); $limitsearchopt = Search::getCleanedOptions($itemtype); if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $itemtable = $CFG_GLPI['union_search_type'][$itemtype]; } else { $itemtable = getTableForItemType($itemtype); } $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == GLOBAL_SEARCH) { $LIST_LIMIT = GLOBAL_SEARCH_DISPLAY_COUNT; } } // hack for States if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $entity_restrict = true; } else { $entity_restrict = $item->isEntityAssign(); } // $metanames = array(); // Get the items to display // $toview = Search::addDefaultToView($itemtype); // // Add items to display depending of personal prefs // $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::getLoginUserID()); // if (count($displaypref)) { // foreach ($displaypref as $val) { // array_push($toview,$val); // } // } /* =========== Add for plugin Monitoring ============ */ $toview = array(); array_push($toview, 1); // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // // Special case for Ticket : put ID in front // if ($itemtype=='Ticket') { // array_unshift($toview, 2); // } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } // $toview_count = count($toview); // Construct the request //// 1 - SELECT // request currentuser for SQL supervision, not displayed $SELECT = "SELECT " . Search::addDefaultSelect($itemtype); // Add select for all toview item foreach ($toview as $key => $val) { $SELECT .= Search::addSelect($itemtype, $val, $key, 0); } //// 2 - FROM AND LEFT JOIN // Set reference table $FROM = " FROM `{$itemtable}`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables); $FROM .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt[$itemtype] =& Search::getOptions($itemtype); // Add all table for toview items foreach ($toview as $key => $val) { $FROM .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]); } // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { $FROM .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]); } } } //// 3 - WHERE // default string $COMMONWHERE = Search::addDefaultWhere($itemtype); $first = empty($COMMONWHERE); // Add deleted if item have it if ($item && $item->maybeDeleted()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_deleted` = '" . $p['is_deleted'] . "' "; } // Remove template items if ($item && $item->maybeTemplate()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_template` = '0' "; } // Add Restrict to current entities if ($entity_restrict) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } if ($itemtype == 'Entity') { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, 'id', '', true); } else { if (isset($CFG_GLPI["union_search_type"][$itemtype])) { // Will be replace below in Union/Recursivity Hack $COMMONWHERE .= $LINK . " ENTITYRESTRICT "; } else { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, '', '', $item->maybeRecursive()); } } } $WHERE = ""; $HAVING = ""; // Add search conditions // If there is search items if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { // if real search (strlen >0) and not all and view search if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) { // common search if ($p['field'][$key] != "all" && $p['field'][$key] != "view") { $LINK = " "; $NOT = 0; $tmplink = ""; if (is_array($p['link']) && isset($p['link'][$key])) { if (strstr($p['link'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link'][$key]; } } else { $tmplink = " AND "; } if (isset($searchopt[$itemtype][$p['field'][$key]]["usehaving"])) { // Manage Link if not first item if (!empty($HAVING)) { $LINK = $tmplink; } // Find key $item_num = array_search($p['field'][$key], $toview); $HAVING .= Search::addHaving($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num); } else { // Manage Link if not first item if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= Search::addWhere($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]); } // view and all search } else { $LINK = " OR "; $NOT = 0; $globallink = " AND "; if (is_array($p['link']) && isset($p['link'][$key])) { switch ($p['link'][$key]) { case "AND": $LINK = " OR "; $globallink = " AND "; break; case "AND NOT": $LINK = " AND "; $NOT = 1; $globallink = " AND "; break; case "OR": $LINK = " OR "; $globallink = " OR "; break; case "OR NOT": $LINK = " AND "; $NOT = 1; $globallink = " OR "; break; } } else { $tmplink = " AND "; } // Manage Link if not first item if (!empty($WHERE)) { $WHERE .= $globallink; } $WHERE .= " ( "; $first2 = true; $items = array(); if ($p['field'][$key] == "all") { $items = $searchopt[$itemtype]; } else { // toview case : populate toview foreach ($toview as $key2 => $val2) { $items[$val2] = $searchopt[$itemtype][$val2]; } } foreach ($items as $key2 => $val2) { if (is_array($val2)) { // Add Where clause if not to be done in HAVING CLAUSE if (!isset($val2["usehaving"])) { $tmplink = $LINK; if ($first2) { $tmplink = " "; $first2 = false; } $WHERE .= Search::addWhere($tmplink, $NOT, $itemtype, $key2, $p['searchtype'][$key], $p['contains'][$key]); } } } $WHERE .= " ) "; } } } } //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } //// 5 - META SEARCH // Preprocessing if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { // a - SELECT for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { $SELECT .= Search::addSelect($p['itemtype2'][$i], $p['field2'][$i], $i, 1, $p['itemtype2'][$i]); } } // b - ADD LEFT JOIN // Already link meta table in order not to linked a table several times $already_link_tables2 = array(); // Link reference tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!in_array(getTableForItemType($p['itemtype2'][$i]), $already_link_tables2)) { $FROM .= Search::addMetaLeftJoin($itemtype, $p['itemtype2'][$i], $already_link_tables2, $p['contains2'][$i] == "NULL" || strstr($p['link2'][$i], "NOT")); } } } // Link items tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!isset($searchopt[$p['itemtype2'][$i]])) { $searchopt[$p['itemtype2'][$i]] =& Search::getOptions($p['itemtype2'][$i]); } if (!in_array($searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"] . "_" . $p['itemtype2'][$i], $already_link_tables2)) { $FROM .= Search::addLeftJoin($p['itemtype2'][$i], getTableForItemType($p['itemtype2'][$i]), $already_link_tables2, $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["linkfield"], 1, $p['itemtype2'][$i], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["joinparams"]); } } } } //// 6 - Add item ID // Add ID to the select if (!empty($itemtable)) { $SELECT .= "`{$itemtable}`.`id` AS id "; } //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if ($_SESSION["glpisearchcount2"][$itemtype] > 0 || !empty($HAVING) || in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `{$itemtable}`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `{$itemtable}`.`id`"; } } } // Specific search for others item linked (META search) if (is_array($p['itemtype2'])) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { if (isset($p['itemtype2'][$key]) && !empty($p['itemtype2'][$key]) && isset($p['contains2'][$key]) && strlen($p['contains2'][$key]) > 0) { $LINK = ""; // For AND NOT statement need to take into account all the group by items if (strstr($p['link2'][$key], "AND NOT") || isset($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["usehaving"])) { $NOT = 0; if (strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link2'][$key]; } if (!empty($HAVING)) { $LINK = $tmplink; } $HAVING .= Search::addHaving($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1, $key); } else { // Meta Where Search $LINK = " "; $NOT = 0; // Manage Link if not first item if (is_array($p['link2']) && isset($p['link2'][$key]) && strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { if (is_array($p['link2']) && isset($p['link2'][$key])) { $tmplink = " " . $p['link2'][$key]; } else { $tmplink = " AND "; } } if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= Search::addWhere($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1); } } } } // Use a ReadOnly connection if available and configured to be used $DBread = DBConnection::getReadConnection(); // If no research limit research to display item and compute number of item using simple request $nosearch = true; for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { if (isset($p['contains'][$i]) && strlen($p['contains'][$i]) > 0) { $nosearch = false; } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { $nosearch = false; } $LIMIT = ""; $numrows = 0; //No search : count number of items using a simple count(ID) request and LIMIT search if ($nosearch) { $LIMIT = " LIMIT " . $p['start'] . ", " . $LIST_LIMIT; // Force group by for all the type -> need to count only on table ID if (!isset($searchopt[$itemtype][1]['forcegroupby'])) { $count = "count(*)"; } else { $count = "count(DISTINCT `{$itemtable}`.`id`)"; } // request currentuser for SQL supervision, not displayed $query_num = "SELECT {$count}\n FROM `{$itemtable}`" . $COMMONLEFTJOIN; $first = true; if (!empty($COMMONWHERE)) { $LINK = " AND "; if ($first) { $LINK = " WHERE "; $first = false; } $query_num .= $LINK . $COMMONWHERE; } // Union Search : if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $tmpquery = $query_num; $numrows = 0; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); $citem = new $ctype(); if ($citem->canView()) { // State case if ($itemtype == 'States') { $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $query_num .= " AND {$ctable}.`states_id` > '0' "; // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $query_num .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $query_num .= " AND `{$ctable}`.`is_template` = '0' "; } } else { // Ref table case $reftable = getTableForItemType($itemtype); $replace = "FROM `{$reftable}`\n INNER JOIN `{$ctable}`\n ON (`{$reftable}`.`items_id` =`{$ctable}`.`id`\n AND `{$reftable}`.`itemtype` = '{$ctype}')"; $query_num = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $query_num); } $query_num = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $query_num); $result_num = $DBread->query($query_num); $numrows += $DBread->result($result_num, 0, 0); } } } else { $result_num = $DBread->query($query_num); $numrows = $DBread->result($result_num, 0, 0); } } // If export_all reset LIMIT condition if ($p['export_all']) { $LIMIT = ""; } if (!empty($WHERE) || !empty($COMMONWHERE)) { if (!empty($COMMONWHERE)) { $WHERE = ' WHERE ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : ''); } else { $WHERE = ' WHERE ' . $WHERE . ' '; } $first = false; } if (!empty($HAVING)) { $HAVING = ' HAVING ' . $HAVING; } /* =========== Add for plugin Monitoring ============ */ if ($items_id_check > 0) { if ($itemtype == "PluginMonitoringNetworkport") { if ($WHERE == '') { $WHERE .= " WHERE `" . getTableForItemType($itemtype) . "`.`networkports_id`='" . $items_id_check . "' "; } else { $WHERE .= " AND `" . getTableForItemType($itemtype) . "`.`networkports_id`='" . $items_id_check . "' "; } } else { $WHERE .= " AND `" . getTableForItemType($itemtype) . "`.`id`='" . $items_id_check . "' "; } } // Create QUERY if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $first = true; $QUERY = ""; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); $citem = new $ctype(); if ($citem->canView()) { if ($first) { $first = false; } else { $QUERY .= " UNION "; } $tmpquery = ""; // State case if ($itemtype == 'States') { $tmpquery = $SELECT . ", '{$ctype}' AS TYPE " . $FROM . $WHERE; $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $tmpquery .= " AND `{$ctable}`.`states_id` > '0' "; // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $tmpquery .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $tmpquery .= " AND `{$ctable}`.`is_template` = '0' "; } } else { // Ref table case $reftable = getTableForItemType($itemtype); $tmpquery = $SELECT . ", '{$ctype}' AS TYPE,\n `{$reftable}`.`id` AS refID, " . "\n `{$ctable}`.`entities_id` AS ENTITY " . $FROM . $WHERE; $replace = "FROM `{$reftable}`" . "\n INNER JOIN `{$ctable}`" . "\n ON (`{$reftable}`.`items_id`=`{$ctable}`.`id`" . "\n AND `{$reftable}`.`itemtype` = '{$ctype}')"; $tmpquery = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); } $tmpquery = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $tmpquery); // SOFTWARE HACK if ($ctype == 'Software') { $tmpquery = str_replace("glpi_softwares.serial", "''", $tmpquery); $tmpquery = str_replace("glpi_softwares.otherserial", "''", $tmpquery); } $QUERY .= $tmpquery; } } if (empty($QUERY)) { echo Search::showError($output_type); return; } $QUERY .= str_replace($CFG_GLPI["union_search_type"][$itemtype] . ".", "", $ORDER) . $LIMIT; } else { $QUERY = $SELECT . $FROM . $WHERE . $GROUPBY . $HAVING . $ORDER . $LIMIT; } $DBread->query("SET SESSION group_concat_max_len = 4096;"); $result = $DBread->query($QUERY); /// Check group concat limit : if warning : increase limit if ($result2 = $DBread->query('SHOW WARNINGS')) { if ($DBread->numrows($result2) > 0) { $data = $DBread->fetch_assoc($result2); if ($data['Code'] == 1260) { $DBread->query("SET SESSION group_concat_max_len = 4194304;"); $result = $DBread->query($QUERY); } } } // Get it from database and DISPLAY if ($result) { return $result; } else { return false; } }
function plugin_databases_giveItem($type, $ID, $data, $num) { global $DB; $searchopt =& Search::getOptions($type); $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; switch ($table . '.' . $field) { case "glpi_plugin_databases_databases_items.items_id": $query_device = "SELECT DISTINCT `itemtype`\n FROM `glpi_plugin_databases_databases_items`\n WHERE `plugin_databases_databases_id` = '" . $data['id'] . "'\n ORDER BY `itemtype`"; $result_device = $DB->query($query_device); $number_device = $DB->numrows($result_device); $y = 0; $out = ''; $databases = $data['id']; if ($number_device > 0) { for ($i = 0; $i < $number_device; $i++) { $column = "name"; $itemtype = $DB->result($result_device, $i, "itemtype"); if (!class_exists($itemtype)) { continue; } $item = new $itemtype(); if ($item->canView()) { $table_item = getTableForItemType($itemtype); $query = "SELECT `" . $table_item . "`.*, `glpi_plugin_databases_databases_items`.`id` AS items_id, `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_databases_databases_items`, `" . $table_item . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $table_item . "`.`entities_id`) " . " WHERE `" . $table_item . "`.`id` = `glpi_plugin_databases_databases_items`.`items_id`\n AND `glpi_plugin_databases_databases_items`.`itemtype` = '{$itemtype}'\n AND `glpi_plugin_databases_databases_items`.`plugin_databases_databases_id` = '" . $databases . "' " . getEntitiesRestrictRequest(" AND ", $table_item, '', '', $item->maybeRecursive()); if ($item->maybeTemplate()) { $query .= " AND `" . $table_item . "`.`is_template` = '0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $table_item . "`.`{$column}`"; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { $item = new $itemtype(); while ($data = $DB->fetch_assoc($result_linked)) { if ($item->getFromDB($data['id'])) { $out .= $item::getTypeName(1) . " - " . $item->getLink() . "<br>"; } } } else { $out .= ' '; } } } else { $out .= ' '; } } } return $out; break; case 'glpi_plugin_databases_databases.name': if ($type == 'Ticket') { $databases_id = array(); if ($data['raw']["ITEM_{$num}"] != '') { $databases_id = explode('$$$$', $data['raw']["ITEM_{$num}"]); } else { $databases_id = explode('$$$$', $data['raw']["ITEM_" . $num . "_2"]); } $ret = array(); $paDatabase = new PluginDatabasesDatabase(); foreach ($databases_id as $ap_id) { $paDatabase->getFromDB($ap_id); $ret[] = $paDatabase->getLink(); } return implode('<br>', $ret); } break; } return ""; }
/** * Print the HTML array for Items linked to a problem * * @param $problem Problem object * * @return Nothing (display) **/ static function showForProblem(Problem $problem) { global $DB, $CFG_GLPI; $instID = $problem->fields['id']; if (!$problem->can($instID, READ)) { return false; } $canedit = $problem->canEdit($instID); $rand = mt_rand(); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_items_problems`\n WHERE `glpi_items_problems`.`problems_id` = '{$instID}'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='problemitem_form{$rand}' id='problemitem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>"; echo "<tr class='tab_bg_1'><td>"; $types = array(); foreach ($problem->getAllTypesForHelpdesk() as $key => $val) { $types[] = $key; } Dropdown::showSelectItemFromItemtypes(array('itemtypes' => $types, 'entity_restrict' => $problem->fields['is_recursive'] ? getSonsOf('glpi_entities', $problem->fields['entities_id']) : $problem->fields['entities_id'])); echo "</td><td class='center' width='30%'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "<input type='hidden' name='problems_id' value='{$instID}'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('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>" . __('Type') . "</th>"; $header_end .= "<th>" . __('Entity') . "</th>"; $header_end .= "<th>" . __('Name') . "</th>"; $header_end .= "<th>" . __('Serial number') . "</th>"; $header_end .= "<th>" . __('Inventory number') . "</th></tr>"; echo $header_begin . $header_top . $header_end; $totalnb = 0; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $itemtable = getTableForItemType($itemtype); $query = "SELECT `{$itemtable}`.*,\n `glpi_items_problems`.`id` AS IDD,\n `glpi_entities`.`id` AS entity\n FROM `glpi_items_problems`,\n `{$itemtable}`"; if ($itemtype != 'Entity') { $query .= " LEFT JOIN `glpi_entities`\n ON (`{$itemtable}`.`entities_id`=`glpi_entities`.`id`) "; } $query .= " WHERE `{$itemtable}`.`id` = `glpi_items_problems`.`items_id`\n AND `glpi_items_problems`.`itemtype` = '{$itemtype}'\n AND `glpi_items_problems`.`problems_id` = '{$instID}'"; if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } $query .= getEntitiesRestrictRequest(" AND", $itemtable, '', '', $item->maybeRecursive()) . "\n ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`name`"; $result_linked = $DB->query($query); $nb = $DB->numrows($result_linked); for ($prem = true; $data = $DB->fetch_assoc($result_linked); $prem = false) { $name = $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]); } $link = $itemtype::getFormURLWithID($data['id']); $namelink = "<a href=\"" . $link . "\">" . $name . "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]); echo "</td>"; } if ($prem) { $typename = $item->getTypeName($nb); echo "<td class='center top' rowspan='{$nb}'>" . ($nb > 1 ? sprintf(__('%1$s: %2$s'), $typename, $nb) : $typename) . "</td>"; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>"; echo "<td class='center" . (isset($data['is_deleted']) && $data['is_deleted'] ? " tab_bg_2_2'" : "'"); echo ">" . $namelink . "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } $totalnb += $nb; } } if ($number) { echo $header_begin . $header_bottom . $header_end; } echo "</table>"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
$one_item = $_POST['_one_id']; } if ($one_item >= 0) { $where .= " AND `glpi_netpoints`.`id` = '{$one_item}'"; } else { if (strlen($_POST['searchText']) > 0) { $where = " WHERE (`glpi_netpoints`.`name` " . Search::makeTextSearch($_POST['searchText']) . "\n OR `glpi_locations`.`completename` " . Search::makeTextSearch($_POST['searchText']) . ")"; } else { $where = " WHERE 1 "; } } if (!(isset($_POST["devtype"]) && $_POST["devtype"] != 'NetworkEquipment' && isset($_POST["locations_id"]) && $_POST["locations_id"] > 0)) { if (isset($_POST["entity_restrict"]) && $_POST["entity_restrict"] >= 0) { $where .= " AND `glpi_netpoints`.`entities_id` = '" . $_POST["entity_restrict"] . "'"; } else { $where .= getEntitiesRestrictRequest(" AND ", "glpi_locations"); } } $query = "SELECT `glpi_netpoints`.`comment` AS comment,\n `glpi_netpoints`.`id`,\n `glpi_netpoints`.`name` AS netpname,\n `glpi_locations`.`completename` AS loc\n FROM `glpi_netpoints`\n LEFT JOIN `glpi_locations` ON (`glpi_netpoints`.`locations_id` = `glpi_locations`.`id`) "; if (isset($_POST["devtype"]) && !empty($_POST["devtype"])) { $query .= "LEFT JOIN `glpi_networkportethernets`\n ON (`glpi_netpoints`.`id` = `glpi_networkportethernets`.`netpoints_id`)\n LEFT JOIN `glpi_networkports`\n ON (`glpi_networkports`.`id` = `glpi_networkportethernets`.`id`\n AND `glpi_networkports`.`instantiation_type` = 'NetworkPortEthernet'\n AND `glpi_networkports`.`itemtype`"; if ($_POST["devtype"] == 'NetworkEquipment') { $query .= " = 'NetworkEquipment' )"; } else { $query .= " != 'NetworkEquipment' )"; if (isset($_POST["locations_id"]) && $_POST["locations_id"] >= 0) { $location_restrict = true; $where .= " AND `glpi_netpoints`.`locations_id` = '" . $_POST["locations_id"] . "' "; } } $where .= " AND `glpi_networkportethernets`.`netpoints_id` IS NULL ";