static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item) { global $DB; $ID = $item->getField('id'); if (!Session::haveRight('knowbase', 'r') || !Session::haveRight('faq', 'r')) { return false; } $knowbaseitemcategories_id = $item->getField('knowbaseitemcategories_id'); $fullcategoryname = Html::clean(getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id)); $question = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('name'), ENT_QUOTES, "UTF-8"))); $answer = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('answer'), ENT_QUOTES, "UTF-8"))); $pdf->setColumnsSize(100); if (Toolbox::strlen($fullcategoryname) > 0) { $pdf->displayTitle('<b>' . __('Category name') . '</b>'); $pdf->displayLine($fullcategoryname); } if (Toolbox::strlen($question) > 0) { $pdf->displayTitle('<b>' . __('Subject') . '</b>'); $pdf->displayText('', $question, 5); } else { $pdf->displayTitle('<b>' . __('No question found', 'pdf') . '</b>'); } if (Toolbox::strlen($answer) > 0) { $pdf->displayTitle('<b>' . __('Content') . '</b>'); $pdf->displayText('', $answer, 5); } else { $pdf->displayTitle('<b>' . __('No answer found') . '</b>'); } $pdf->setColumnsSize(50, 15, 15, 10, 10); $pdf->displayTitle(__('Writer'), __('Creation date'), __('Last update'), __('FAQ'), _n('View', 'Views', 2)); $pdf->displayLine(getUserName($item->fields["users_id"]), Html::convDateTime($item->fields["date"]), Html::convDateTime($item->fields["date_mod"]), Dropdown::getYesNo($item->fields["is_faq"]), $item->fields["view"]); $pdf->displaySpace(); }
/** * Report if a dropdown have Child * Used to (dis)allow delete action **/ function haveChildren() { if (parent::haveChildren()) { return true; } $kb = new KnowbaseItem(); $fk = $this->getForeignKeyField(); $id = $this->fields['id']; return countElementsInTable($kb->getTable(), "`{$fk}`='{$id}'") > 0; }
/** * Get a KB/FAQ article * for an authenticated user (or anonymous if allowed from config) * * @param $params array of options * @param $protocol the commonication protocol used **/ static function methodGetKnowBaseItem($params, $protocol) { global $DB, $CFG_GLPI; if (isset($params['help'])) { return array('id' => 'integer,mandatory', 'help' => 'bool,optional'); } $kb = new KnowbaseItem(); if (!isset($params['id'])) { return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'id'); } if (!is_numeric($params['id'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'id'); } if (!$kb->can($params['id'], 'r')) { return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND); } $answer = Toolbox::unclean_cross_side_scripting_deep($kb->getField('answer')); $resp = $kb->fields; $resp['answer'] = $answer; $resp['answer_text'] = html_entity_decode(Html::clean($answer), 0, 'UTF-8'); $resp['documents'] = self::getDocForItem($kb); $kb->updateCounter(); return $resp; }
/** * Show items links to a webapplication * * @since version 0.84 * * @param $PluginWebapplicationsWebapplication PluginWebapplicationsWebapplication object * * @return nothing (HTML display) **/ static function showForWebapplication(PluginWebapplicationsWebapplication $webapplication) { global $DB, $CFG_GLPI; $instID = $webapplication->fields['id']; if (!$webapplication->can($instID, READ)) { return false; } $canedit = $webapplication->can($instID, UPDATE); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_plugin_webapplications_webapplications_items`\n WHERE `plugin_webapplications_webapplications_id` = '{$instID}'\n ORDER BY `itemtype` "; $result = $DB->query($query); $number = $DB->numrows($result); $rand = mt_rand(); if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='webapplicationitem_form{$rand}' id='webapplicationitem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL("PluginWebapplicationsWebapplication") . "'>"; 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 class='right'>"; Dropdown::showAllItems("items_id", 0, 0, $webapplication->fields['is_recursive'] ? -1 : $webapplication->fields['entities_id'], PluginWebapplicationsWebapplication::getTypes(), false, true); echo "</td><td class='center'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "<input type='hidden' name='plugin_webapplications_webapplications_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(); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $column = "name"; if ($itemtype == 'Ticket') { $column = "id"; } $itemtable = getTableForItemType($itemtype); $query = "SELECT `{$itemtable}`.*,\n `glpi_plugin_webapplications_webapplications_items`.`id` AS IDD, "; if ($itemtype == 'KnowbaseItem') { $query .= "-1 AS entity\n FROM `glpi_plugin_webapplications_webapplications_items`, `{$itemtable}`\n " . KnowbaseItem::addVisibilityJoins() . "\n WHERE `{$itemtable}`.`id` = `glpi_plugin_webapplications_webapplications_items`.`items_id`\n AND "; } else { $query .= "`glpi_entities`.`id` AS entity\n FROM `glpi_plugin_webapplications_webapplications_items`, `{$itemtable}` "; if ($itemtype != 'Entity') { $query .= "LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`) "; } $query .= "WHERE `{$itemtable}`.`id` = `glpi_plugin_webapplications_webapplications_items`.`items_id`\n AND "; } $query .= "`glpi_plugin_webapplications_webapplications_items`.`itemtype` = '{$itemtype}'\n AND `glpi_plugin_webapplications_webapplications_items`.`plugin_webapplications_webapplications_id` = '{$instID}' "; if ($itemtype == 'KnowbaseItem') { if (Session::getLoginUserID()) { $where = "AND " . KnowbaseItem::addVisibilityRestrict(); } else { // Anonymous access if (Session::isMultiEntitiesMode()) { $where = " AND (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')"; } } } else { $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive()); } if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } if ($itemtype == 'KnowbaseItem') { $query .= " ORDER BY `{$itemtable}`.`{$column}`"; } else { $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`"; } if ($itemtype == 'SoftwareLicense') { $soft = new Software(); } if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { while ($data = $DB->fetch_assoc($result_linked)) { if ($itemtype == 'Ticket') { $data["name"] = sprintf(__('%1$s: %2$s'), __('Ticket'), $data["id"]); } if ($itemtype == 'SoftwareLicense') { $soft->getFromDB($data['softwares_id']); $data["name"] = sprintf(__('%1$s - %2$s'), $data["name"], $soft->fields['name']); } $linkname = $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]); } $link = Toolbox::getItemTypeFormURL($itemtype); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $linkname . "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]); echo "</td>"; } echo "<td class='center'>" . $item->getTypeName(1) . "</td>"; echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']); echo "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } } } echo "</table>"; if ($canedit && $number) { $paramsma['ontop'] = false; Html::showMassiveActions($paramsma); Html::closeForm(); } echo "</div>"; }
echo "<tr class='noHover'><td class='top'>"; Reminder::showListForCentral(false); echo "</td></tr>"; } if (Session::haveRight("rssfeed_public", READ)) { echo "<tr class='noHover'><td class='top'>"; RSSFeed::showListForCentral(false); echo "</td></tr>"; } echo "</table></td>"; echo "<td class='top' width='50%'><br>"; echo "<table class='central'>"; // Show KB items if (Session::haveRight('knowbase', KnowbaseItem::READFAQ)) { echo "<tr class='noHover'><td class='top'>"; KnowbaseItem::showRecentPopular("popular"); echo "</td></tr>"; echo "<tr class='noHover'><td class='top'><br>"; KnowbaseItem::showRecentPopular("recent"); echo "</td></tr>"; echo "<tr class='noHover'><td class='top'><br>"; KnowbaseItem::showRecentPopular("lastupdate"); echo "</td></tr>"; } else { echo "<tr><td> </td></tr>"; } echo "</table>"; echo "</td>"; echo "</tr></table>"; } Html::helpFooter();
along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkCentralAccess(); if (isset($_GET["item_type"]) && isset($_GET["display_type"])) { if ($_GET["display_type"] < 0) { $_GET["display_type"] = -$_GET["display_type"]; $_GET["export_all"] = 1; } switch ($_GET["item_type"]) { case 'KnowbaseItem': KnowbaseItem::showList($_GET, $_GET["is_faq"]); break; case 'Stat': if (isset($_GET["item_type_param"])) { $params = Toolbox::decodeArrayFromInput($_GET["item_type_param"]); switch ($params["type"]) { case "comp_champ": $val = Stat::getItems($_GET["itemtype"], $params["date1"], $params["date2"], $params["dropdown"]); Stat::showTable($_GET["itemtype"], $params["type"], $params["date1"], $params["date2"], $params["start"], $val, $params["dropdown"]); break; case "device": $val = Stat::getItems($_GET["itemtype"], $params["date1"], $params["date2"], $params["dropdown"]); Stat::showTable($_GET["itemtype"], $params["type"], $params["date1"], $params["date2"], $params["start"], $val, $params["dropdown"]); break; default: $val2 = isset($params['value2']) ? $params['value2'] : 0;
$_GET["action"] = "edit"; include "bookmark.php"; break; case "edit_user_notification": popHeader($LANG['Menu'][40], $_SERVER['PHP_SELF']); include "ticket_user.form.php"; break; case "add_ldapuser": popHeader($LANG['ldap'][35], $_SERVER['PHP_SELF']); include "ldap.import.php"; break; case "add_ruleparameter": popHeader($LANG['ldap'][35], $_SERVER['PHP_SELF']); include strtolower($_GET['sub_type'] . "Parameter.php"); break; case "list_notificationtags": popHeader($LANG['mailing'][138], $_SERVER['PHP_SELF']); include "notification.tags.php"; break; case "show_kb": popHeader($LANG['title'][5], $_SERVER['PHP_SELF']); $kb = new KnowbaseItem(); $kb->check($_GET["id"], 'r'); $kb->showFull(true); popHeader($LANG['mailing'][138], $_SERVER['PHP_SELF']); break; } echo "<div class='center'><br><a href='javascript:window.close()'>" . $LANG['buttons'][60] . "</a>"; echo "</div>"; popFooter(); }
/** Generate bigdump : generate items for an entity * * @param $ID_entity entity ID **/ function generate_entity($ID_entity) { global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK, $DOCUMENTS, $NET_PORT, $NET_LOC; regenerateTreeCompleteName("glpi_entities"); $current_year = date("Y"); // DOMAIN $items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine"); $dp = new Domain(); $FIRST["domain"] = getMaxItem("glpi_domains")+1; for ($i=0 ; $i<$MAX['domain'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "domain $ID_entity '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); } $LAST["domain"] = getMaxItem("glpi_domains"); // STATUS $items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'"); $dp = new State(); $FIRST["state"] = getMaxItem("glpi_states")+1; for ($i=0 ; $i<$MAX['state'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "State $ID_entity '$i"; } $state_id = $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); // generate sub status for ($j=0 ; $j<$MAX['state'] ; $j++) { $val2 = "Sub $val $j"; $dp->add(toolbox::addslashes_deep(array('name' => $val2, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'states_id' => $state_id, 'comment' => "comment $val"))); } } $LAST["state"] = getMaxItem("glpi_states"); // glpi_groups $FIRST["groups"] = getMaxItem("glpi_groups")+1; $group = new Group(); for ($i=0 ; $i<$MAX['groups'] ; $i++) { $gID = $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "group d'$i", 'comment' => "comment group d'$i", 'is_assign' => 0))); // Generate sub group for ($j=0 ; $j<$MAX['groups'] ; $j++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "subgroup d'$j", 'comment' => "comment subgroup d'$j of group $i", 'groups_id' => $gID, 'is_assign' => 0))); } } $LAST["groups"] = getMaxItem("glpi_groups"); $FIRST["techgroups"] = $LAST["groups"]+1; for ($i=0 ; $i<$MAX['groups'] ; $i++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "tech group d'$i", 'comment' => "comment tech group d'$i"))); } $LAST["techgroups"] = getMaxItem("glpi_groups"); regenerateTreeCompleteName("glpi_groups"); // glpi_users $FIRST["users_sadmin"] = getMaxItem("glpi_users")+1; $user = new User(); $gu = new Group_User(); for ($i=0 ; $i<$MAX['users_sadmin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "sadmin$i-$ID_entity", 'password' => "sadmin'$i", 'password2' => "sadmin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "sadmin '$i name", 'firstname' => "sadmin '$i firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 4, '_entities_id' => $ID_entity, '_is_recursive' => 1 ))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_sadmin"] = getMaxItem("glpi_users"); $FIRST["users_admin"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_admin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "admin$i-$ID_entity", 'password' => "admin'$i", 'password2' => "admin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "admin$i 'name", 'firstname' => "admin$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 3, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']), 'is_manager' => 1, 'is_delegate' => 1)); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'is_manager' => 1, 'is_delegate' => 1)); } $LAST["users_admin"] = getMaxItem("glpi_users"); $FIRST["users_normal"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_normal'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "normal$i-$ID_entity", 'password' => "normal'$i", 'password2' => "normal'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "normal$i 'name", 'firstname' => "normal$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 2, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_normal"] = getMaxItem("glpi_users"); $FIRST["users_postonly"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_postonly'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "postonly$i-$ID_entity", 'password' => "postonly'$i", 'password2' => "postonly'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "postonly$i 'name", 'firstname' => "postonly$i 'firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 1, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); } $LAST["users_postonly"] = getMaxItem("glpi_users"); $FIRST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories")+1; $kbc = new KnowbaseItemCategory(); for ($i=0 ; $i<max(1,pow($MAX['kbcategories'],1/3)) ; $i++) { $newID = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ' categorie $i", 'comment' => "comment ' categorie $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $j++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity s-categorie '$j", 'comment' => "comment s-categorie '$j", 'knowbaseitemcategories_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $k++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ss-categorie' $k", 'comment' => "comment ss-categorie' $k", 'knowbaseitemcategories_id' => $newID2))); } } } $query = "OPTIMIZE TABLE `glpi_knowbaseitemcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_knowbaseitemcategories"); $LAST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories"); // LOCATIONS $added = 0; $FIRST["locations"] = getMaxItem("glpi_locations")+1; $loc = new Location(); for ($i=0 ; $i<pow($MAX['locations'],1/5)&&$added<$MAX['locations'] ; $i++) { $added++; $newID = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "location' $i", 'comment' => "comment 'location $i", 'building' => "building $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $added++; $newID2 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "s-location '$j", 'comment' => "comment s-location '$j", 'building' => "building $i", 'room' => "stage '$j", 'locations_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $k++) { $added++; $newID3 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ss-location '$k", 'comment' => "comment ss-location' $k", 'building' => "building $i", 'room' => "part' $k", 'locations_id' => $newID2))); for ($l=0 ; $l<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $l++) { $added++; $newID4 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "sss-location' $l", 'comment' => "comment sss-location' $l", 'building' => "building $i", 'room' => "room' $l", 'locations_id' => $newID3))); for ($m=0 ; $m<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $m++) { $added++; $newID5 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ssss-location' $m", 'comment' => "comment ssss-location' $m", 'building' => "building $i", 'room' => "room' $l-$m", 'locations_id' => $newID4))); } } } } } $query = "OPTIMIZE TABLE `glpi_locations`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_locations"); $LAST["locations"]=getMaxItem("glpi_locations"); // Task categories $added = 0; $FIRST["taskcategory"] = getMaxItem("glpi_taskcategories")+1; $tc = new TaskCategory(); for ($i=0 ; $i<pow($MAX['taskcategory'],1/5)&&$added<$MAX['taskcategory'] ; $i++) { $added++; $newID = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $newID2 = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i", 'taskcategories_id' => $newID))); $added++; } } $query = "OPTIMIZE TABLE `glpi_taskcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_taskcategories"); $LAST["taskcategory"] = getMaxItem("glpi_taskcategories"); $ic = new ItilCategory(); // Specific ticket categories $newID = $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "category for entity' $ID_entity", 'comment' => "comment category for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'],$LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'],$LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1))); for ($i=0 ; $i<max(1,pow($MAX['tracking_category'],1/3)) ; $i++) { $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "scategory for entity' $ID_entity", 'comment' => "comment scategory for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1, 'itilcategories_id' => $newID))); } regenerateTreeCompleteName("glpi_itilcategories"); $FIRST["solutiontypes"] = getMaxItem("glpi_solutiontypes")+1; $items = array("d'après KB"); $st = new SolutionType(); for ($i=0 ; $i<$MAX['solutiontypes'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de solution ' $i"; } $st->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val", 'entities_id' => $ID_entity, 'is_recursive' => 1))); } $LAST["solutiontypes"] = getMaxItem("glpi_solutiontypes"); $FIRST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates")+1; $nb_items = mt_rand(0,$MAX['solutiontemplates']); $st = new SolutionTemplate(); for ($i=0 ; $i<$nb_items ; $i++) { $st-> add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "solution' $i-$ID_entity", 'content' => "content solution' $i-$ID_entity", 'solutiontypes_id' => mt_rand(0,$MAX['solutiontypes']), 'comment' => "comment solution' $i-$ID_entity"))); } $LAST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates"); // Add Specific questions $k = 0; $FIRST["kbitems"] = getMaxItem("glpi_knowbaseitems")+1; $ki = new KnowbaseItem(); $eki = new Entity_KnowbaseItem(); for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 0)); } } // Add global questions for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Recursive Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 1)); } } $LAST["kbitems"] = getMaxItem("glpi_knowbaseitems"); // Ajout documents specific $FIRST["document"] = getMaxItem("glpi_documents")+1; $doc = new Document(); for ($i=0 ; $i<$MAX['document'] ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "commen't $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-0"; } // Global ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "comment' $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-1"; } $LAST["document"] = getMaxItem("glpi_documents"); // Ajout budgets specific $FIRST["budget"] = getMaxItem("glpi_budgets")+1; $b = new Budget(); for ($i=0 ; $i<$MAX['budget'] ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 0, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["budget"] = getMaxItem("glpi_budgets"); // GLobal ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "Recursive budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 1, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["document"] = getMaxItem("glpi_documents"); // glpi_suppliers $items = array("DELL", "IBM", "ACER", "Microsoft", "Epson", "Xerox", "Hewlett Packard", "Nikon", "Targus", "LG", "Samsung", "Lexmark"); $FIRST["enterprises"] = getMaxItem("glpi_suppliers")+1; $ent = new Supplier(); // Global ones for ($i=0 ; $i<$MAX['enterprises']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive' $val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes enterprises' $i"))); addDocuments('Supplier', $entID); } // Specific ones for ($i=0 ; $i<$MAX['enterprises'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "'$val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes supplier' $i", 'comment' => "comment supplier' $i"))); addDocuments('Supplier', $entID); } $LAST["enterprises"] = getMaxItem("glpi_suppliers"); // Ajout contracts $FIRST["contract"] = getMaxItem("glpi_contracts")+1; $c = new Contract(); $cs = new Contract_Supplier(); $cc = new ContractCost(); // Specific for ($i=0 ; $i<$MAX['contract'] ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "contract' $i-$ID_entity", 'num' => "num' $i", 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); // Add a cost $cc->add(toolbox::addslashes_deep( array('contracts_id' => $contractID, 'cost' => mt_rand(100,10000), 'name' => "Initial 'cost", 'begin_date' => $date, 'budgets_id' => mt_rand($FIRST['budget'], $LAST['budget'])))); } for ($i=0 ; $i<$MAX['contract']/2 ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive contract' $i-$ID_entity", 'num' => "num' $i", 'cost' => mt_rand(100,10000), 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); } $LAST["contract"] = getMaxItem("glpi_contracts"); // Ajout contacts $prenoms = array("Jean", "John", "Louis", "Pierre", "Auguste", "Albert", "Julien", "Guillaume", "Bruno", "Maurice", "Francois", "Laurent", "Richard", "Henri", "Clement", "d'avy"); $noms = array("Dupont", "Smith", "Durand", "Martin", "Dubois", "Dufour", "Dupin", "Duval", "Petit", "Grange", "Bernard", "Bonnet", "Richard", "Leroy", "Dumont", "Fontaine", "d'orleans"); $FIRST["contacts"] = getMaxItem("glpi_contacts")+1; $c = new Contact(); $cs = new Contact_Supplier(); for ($i=0 ; $i<$MAX['contacts'] ; $i++) { if (isset($noms[$i])) { $val = $noms[$i]; } else { $val = "name $i"; } if (isset($prenoms[$i])) { $val2 = $prenoms[$i]; } else { $val2 = "firstname $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val-$ID_entity", 'firstname' => $val2, 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } for ($i=0 ; $i<$MAX['contacts']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive contact $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val'-$ID_entity", 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } $LAST["contacts"] = getMaxItem("glpi_contacts"); // TYPE DE CONSOMMABLES $FIRST["type_of_consumables"] = getMaxItem("glpi_consumableitems")+1; $ci = new Consumableitem(); for ($i=0 ; $i<$MAX['type_of_consumables'] ; $i++) { $consID = $ci->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "consumable type' $i", 'ref' => "ref d' $i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'consumableitemtypes_id' => mt_rand(0,$MAX['consumable_type']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment' $i", 'notepad' => "notes consumableitem' $i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('ConsumableItem', $consID); // AJOUT INFOCOMS addInfocoms('ConsumableItem', $consID, $ID_entity); // Ajout consommable en stock $c = new Consumable(); for ($j=0 ; $j<mt_rand(0,$MAX['consumables_stock']) ; $j++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } // Ajout consommable donne for ($j=0 ; $j<mt_rand(0,$MAX['consumables_given']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date, 'date_out' => date("Y-m-d"))); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } } $LAST["type_of_consumables"] = getMaxItem("glpi_consumableitems"); // TYPE DE CARTOUCHES $FIRST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems")+1; $ct = new CartridgeItem(); for ($i=0 ; $i<$MAX['type_of_cartridges'] ; $i++) { $cartID = $ct->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "cartridge ' type $i", 'ref' => "ref '$i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment '$i", 'notepad' => "notes cartridgeitem '$i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('CartridgeItem', $cartID); // AJOUT INFOCOMS addInfocoms('CartridgeItem', $cartID, $ID_entity); $c = new Cartridge(); $cipm = new CartridgeItem_PrinterModel(); // Ajout cartouche en stock for ($j=0 ; $j<mt_rand(0,$MAX['cartridges_stock']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $cartID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Cartridge', $ID, $ID_entity); } // Assoc printer type to cartridge type $cipm->add(array('cartridgeitems_id' => $cartID, 'printermodels_id' => mt_rand(1,$MAX['type_printers']), )); } $LAST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems"); // Networking $NET_LOC = array(); $FIRST["networking"] = getMaxItem("glpi_networkequipments")+1; $FIRST["printers"] = getMaxItem("glpi_printers")+1; $ne = new NetworkEquipment(); $p = new Printer(); $np = new Netpoint(); $c = new Cartridge(); foreach ($DB->request('glpi_locations') as $data) { $i = $data["id"]; $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $infoIP = getNextIP(); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); // insert networking $netwID = $ne->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "networking '$i-$ID_entity", 'ram' => mt_rand(32,256), 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num '$i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment '$i", 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'networkequipmenttypes_id' => mt_rand(1,$MAX['type_networking']), 'networkequipmentmodels_id' => mt_rand(1,$MAX['model_networking']), 'networkequipmentfirmwares_id' => mt_rand(1,$MAX['firmware']), 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'mac' => getNextMAC(), 'ip' => $infoIP["ip"], 'notepad' => "notes networking '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); $NET_LOC[$data['id']] = $netwID; addDocuments('NetworkEquipment', $netwID); addContracts('NetworkEquipment', $netwID); // AJOUT INFOCOMS addInfocoms('NetworkEquipment', $netwID, $ID_entity); // Link with father addNetworkEthernetPort('NetworkEquipment', $netwID, $ID_entity, $i); // Ajout imprimantes reseaux : 1 par loc + connexion d un matos reseau + ajout de cartouches // Add trackings addTracking('NetworkEquipment', $netwID, $ID_entity); $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $recur = mt_rand(0,1); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recur, 'name' => "printer of loc '$i", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'is_global' => 1, 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity, $recur); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result2 = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result2)>0) { $ctypeID = $DB->result($result2,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = abs(round(($date2-$date1)/$oldnb)); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => $date, 'date_use' => date("Y-m-d",$date2))); } $iface = mt_rand(1,$MAX['iface']); // Add networking ports addNetworkEthernetPort('Printer', $printID, $ID_entity, $i); } unset($NET_LOC); $LAST["networking"] = getMaxItem("glpi_networkequipments"); //////////// INVENTORY // glpi_computers $FIRST["computers"] = getMaxItem("glpi_computers")+1; $FIRST["monitors"] = getMaxItem("glpi_monitors")+1; $FIRST["phones"] = getMaxItem("glpi_phones")+1; $FIRST["peripherals"] = getMaxItem("glpi_peripherals")+1; $c = new Computer(); $mon = new Monitor(); $cdevmb = new Item_DeviceMotherBoard(); $cdevproc = new Item_DeviceProcessor(); $cdevmem = new Item_DeviceMemory(); $cdevhd = new Item_DeviceHardDrive(); $cdevnc = new Item_DeviceNetworkCard(); $cdevdr = new Item_DeviceDrive(); $cdevcon = new Item_DeviceControl(); $cdevgc = new Item_DeviceGraphicCard(); $cdevsc = new Item_DeviceSoundCard(); $cdevpci = new Item_DevicePci(); $cdevcase = new Item_DeviceCase(); $cdevps = new Item_DevicePowerSupply(); $cdisk = new ComputerDisk(); $np = new Netpoint(); $ci = new Computer_Item(); $phone = new Phone(); $print = new Printer(); $periph = new Peripheral(); $cart = new Cartridge(); for ($i=0 ; $i<$MAX['computers'] ; $i++) { $loc = mt_rand($FIRST["locations"],$LAST['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $userID = mt_rand($FIRST['users_normal'],$LAST['users_postonly']); $groupID = mt_rand($FIRST["groups"],$LAST["groups"]); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); $compID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "computer ' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'operatingsystems_id' => mt_rand(1,$MAX['os']), 'operatingsystemversions_id' => mt_rand(1,$MAX['os_version']), 'operatingsystemservicepacks_id' => mt_rand(1,$MAX['os_sp']), 'os_license_number' => "os sn $i", 'os_licenseid' => "os id $i", 'autoupdatesystems_id' => mt_rand(1,$MAX['os_sp']), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'computertypes_id' => mt_rand(1,$MAX['type_computers']), 'computermodels_id' => mt_rand(1,$MAX['model']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes computer '$i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'uuid' => Toolbox::getRandomString(30) ))); addDocuments('Computer', $compID); addContracts('Computer', $compID); $NET_PORT['Computer'][$compID] = 0; // Add trackings addTracking('Computer', $compID, $ID_entity); // Add reservation addReservation('Computer', $compID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Computer', $compID, $ID_entity); // ADD DEVICE $cdevmb->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevproc->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevmem->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevhd->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $cdevnc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15), 'mac' => getNextMAC())); $cdevdr->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevcon->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevgc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevsc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); for($nb = 0; $nb<$max; $nb++) { $cdevpci->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); } $cdevcase->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial'=> Toolbox::getRandomString(15))); $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevps->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } // insert disk $nb_disk = mt_rand(1,$MAX_DISK); for ($j=1 ; $j<=$nb_disk ; $j++) { $totalsize = mt_rand(10000,1000000); $freesize = mt_rand(0,$totalsize); $cdisk->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'computers_id' => $compID, 'name' => "disk '$j", 'device' => "/dev/disk$j", 'mountpoint' => "/mnt/disk$j", 'filesystems_id' => mt_rand(1,10), 'totalsize' => $totalsize, 'freesize' => $freesize))); } // Add networking ports addNetworkEthernetPort('Computer', $compID, $ID_entity, $loc); // Ajout d'un ecran sur l'ordi $monID = $mon->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "monitor' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'size' => mt_rand(14,22), 'have_micro' => mt_rand(0,1), 'have_speaker' => mt_rand(0,1), 'have_subd' => mt_rand(0,1), 'have_bnc' => mt_rand(0,1), 'have_dvi' => mt_rand(0,1), 'have_pivot' => mt_rand(0,1), 'have_hdmi' => mt_rand(0,1), 'have_displayport' => mt_rand(0,1), 'locations_id' => $loc, 'monitortypes_id' => mt_rand(1,$MAX['type_monitors']), 'monitormodels_id' => mt_rand(1,$MAX['model_monitors']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes monitor' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Monitor', $monID); addContracts('Monitor', $monID); // Add trackings addTracking('Monitor', $monID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Monitor', $monID, $ID_entity); $ci->add(array('itemtype' => 'Monitor', 'items_id' => $monID, 'computers_id' => $compID, )); // Ajout d'un telephhone avec l'ordi $telID = $phone->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "phone' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'firmware' => Toolbox::getRandomString(10), 'brand' => "brand' $i", 'phonepowersupplies_id' => mt_rand(0,$MAX['phone_power']), 'number_line' => Toolbox::getRandomString(10), 'have_headset' => mt_rand(0,1), 'have_hp' => mt_rand(0,1), 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_phones']), 'phonemodels_id' => mt_rand(1,$MAX['model_phones']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes phone' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Phone', $telID); addContracts('Phone', $telID); // Add trackings addTracking('Phone', $telID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Phone', $telID, $ID_entity); $ci->add(array('itemtype' => 'Phone', 'items_id' => $telID, 'computers_id' => $compID)); // Ajout des periphs externes en connection directe while (mt_rand(0,100)<$percent['peripherals']) { $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes peripheral' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => $compID)); } // Ajout d'une imprimante connection directe pour X% des computers + ajout de cartouches if (mt_rand(0,100)<=$percent['printer']) { // Add printer $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "printer of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_postonly'], $LAST['users_postonly']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Printer', 'items_id' => $printID, 'computers_id' => $compID)); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result)>0) { $ctypeID = $DB->result($result,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = round(($date2-$date1)/$oldnb); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date2))); } } } $LAST["computers"] = getMaxItem("glpi_computers"); $LAST["monitors"] = getMaxItem("glpi_monitors"); $LAST["phones"] = getMaxItem("glpi_phones"); // Add global peripherals $periph = new Peripheral(); $ci = new Computer_Item(); for ($i=0 ; $i<$MAX['global_peripherals'] ; $i++) { $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph '$i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes peripheral' $i", 'users_id' => mt_rand($FIRST['users_normal'], $LAST['users_normal']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add reservation addReservation('Peripheral', $periphID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Peripheral', $periphID, $ID_entity); // Add connections $val = mt_rand(1,$MAX['connect_for_peripherals']); for ($j=1 ; $j<$val ; $j++) { $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => mt_rand($FIRST["computers"],$LAST['computers']))); } } $LAST["peripherals"] = getMaxItem("glpi_peripherals"); $FIRST["software"] = getMaxItem("glpi_softwares")+1; // Ajout logiciels + licences associees a divers PCs $items = array(array("Open'Office", "1.1.4", "2.0", "2.0.1"), array("Microsoft Office", "95", "97", "XP", "2000", "2003", "2007"), array("Acrobat Reader", "6.0", "7.0", "7.04"), array("Gimp", "2.0", "2.2"), array("InkScape", "0.4")); $soft = new Software(); $softvers = new SoftwareVersion(); $softlic = new SoftwareLicense(); $csv = new Computer_SoftwareVersion(); $csl = new Computer_SoftwareLicense(); for ($i=0 ; $i<$MAX['software'] ; $i++) { if (isset($items[$i])) { $name = $items[$i][0]; } else { $name = "software '$i"; } $loc = mt_rand(1,$MAX['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $recursive = mt_rand(0,1); $softID = $soft->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'name' => $name, 'comment' => "comment '$i", 'locations_id' => $loc, 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes software '$i", 'users_id' => mt_rand($FIRST['users_admin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'is_helpdesk_visible' => 1, 'softwarecategories_id' => mt_rand(1,$MAX['softwarecategory']) ))); addDocuments('Software', $softID); addContracts('Software', $softID); // Add trackings addTracking('Software', $softID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Software', $softID, $ID_entity); // Add versions $FIRST["version"] = getMaxItem("glpi_softwareversions")+1; if (isset($items[$i])) { $val2 = count($items[$i]); } else { $val2 = mt_rand(1,$MAX['softwareversions']+1); } for ($j=1 ; $j<=$val2 ; $j++) { if (isset($items[$i])) { $version = $items[$i][mt_rand(1,count($items[$i])-1)]; } else { $version = "$j.0"; } $os = mt_rand(1,$MAX['os']); $versID = $softvers->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'name' => $version, 'comment' => "comment '$version", 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'operatingsystems_id' => $os))); $val3 = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$val3 ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csv->add(array('computers_id' => $comp_id, 'softwareversions_id' => $versID)); } } $LAST["version"] = getMaxItem("glpi_softwareversions"); // Add licenses $val2 = mt_rand(1,$MAX['softwarelicenses']); for ($j=0 ; $j<$val2 ; $j++) { $softwareversions_id_buy = mt_rand($FIRST["version"],$LAST["version"]); $softwareversions_id_use = mt_rand($softwareversions_id_buy,$LAST["version"]); $nbused = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $licID = $softlic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'number' => $nbused, 'softwarelicensetypes_id' => mt_rand(1,$MAX['licensetype']), 'name' => "license '$j", 'serial' => "serial $j", 'otherserial' => "otherserial $j", 'comment' => "comment license '$j", 'softwareversions_id_buy' => $softwareversions_id_buy, 'softwareversions_id_use' => $softwareversions_id_use))); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$nbused ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csl->add(array('computers_id' => $comp_id, 'softwarelicenses_id' => $licID)); } } } $LAST["software"] = getMaxItem("glpi_softwares"); }
/** * Get a translation for a value * * @param $item item to translate * @param $field field to return (default 'name') * * @return the field translated if a translation is available, or the original field if not **/ static function getTranslatedValue(KnowbaseItem $item, $field = "name") { global $DB; $obj = new self(); $found = $obj->find("`knowbaseitems_id` = '" . $item->getID() . "' AND `language` = '" . $_SESSION['glpilanguage'] . "'"); if (count($found) > 0 && in_array($field, array('name', 'answer'))) { $first = array_shift($found); return $first[$field]; } return $item->fields[$field]; }
/** * * Note : can separe code of view list * @param PluginTagTag $tag * @return boolean */ static function showForTag(PluginTagTag $tag) { global $DB; $instID = $tag->fields['id']; if (!$tag->can($instID, READ)) { return false; } $canedit = $tag->can($instID, UPDATE); $table = getTableForItemType(__CLASS__); $result = $DB->query("SELECT DISTINCT `itemtype`\n FROM `{$table}`\n WHERE `plugin_tag_tags_id` = '{$instID}'"); $result2 = $DB->query("SELECT `itemtype`, items_id\n FROM `{$table}`\n WHERE `plugin_tag_tags_id` = '{$instID}'"); $number = $DB->numrows($result); $rand = mt_rand(); if ($canedit) { echo "<div class='firstbloc'>"; //can use standart GLPI function $target = Toolbox::getItemTypeFormURL('PluginTagTag'); echo "<form name='tagitem_form{$rand}' id='tagitem_form{$rand}' method='post' action='" . $target . "'>"; 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 class='right'>"; //Note : this function is deprecated (and replace by an other) $itemtypes_to_show = self::getItemtypes($tag->fields['type_menu']); Dropdown::showAllItems("items_id", 0, 0, $tag->fields['is_recursive'] ? -1 : $tag->fields['entities_id'], $itemtypes_to_show, false, true); echo "<style>.select2-container { text-align: left; } </style>"; //minor echo "</td><td class='center'>"; echo "<input type='hidden' name='plugin_tag_tags_id' value='{$instID}'>"; //Note : can use standart GLPI method 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); Html::showMassiveActions(); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } $item_id = $DB->result($result2, $i, "items_id"); if ($item->canView()) { $column = strtolower(substr($itemtype, 0, 6)) == "device" ? "designation" : "name"; // For rules itemtypes (example : ruledictionnaryphonemodel) if (strtolower(substr($itemtype, 0, 4)) == 'rule' || $itemtype == "PluginResourcesRulechecklist") { $itemtable = getTableForItemType('Rule'); } else { $itemtable = getTableForItemType($itemtype); } $obj = new $itemtype(); $obj->getFromDB($item_id); $query = "SELECT `{$itemtable}`.*, `glpi_plugin_tag_tagitems`.`id` AS IDD, "; switch ($itemtype) { case 'KnowbaseItem': $query .= "-1 AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n " . KnowbaseItem::addVisibilityJoins() . "\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; break; case 'Profile': case 'RSSFeed': case 'Reminder': case 'Entity': //Possible to add (in code) condition to visibility : $query .= "-1 AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; break; default: if (isset($obj->fields['entities_id'])) { $query .= "`glpi_entities`.`id` AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`)\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; } else { $query .= "-1 AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; } break; } $query .= "`glpi_plugin_tag_tagitems`.`itemtype` = '{$itemtype}'\n AND `glpi_plugin_tag_tagitems`.`plugin_tag_tags_id` = '{$instID}' "; $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive()); if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } switch ($itemtype) { case 'KnowbaseItem': case 'Profile': case 'RSSFeed': case 'Reminder': case 'Entity': $query .= " ORDER BY `{$itemtable}`.`{$column}`"; break; default: if (isset($obj->fields['entities_id'])) { $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`"; } else { $query .= " ORDER BY `{$itemtable}`.`{$column}`"; } break; } if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { while ($data = $DB->fetch_assoc($result_linked)) { if ($itemtype == 'Softwarelicense') { $soft = new Software(); $soft->getFromDB($data['softwares_id']); $data["name"] .= ' - ' . $soft->getName(); //This add name of software } elseif ($itemtype == "PluginResourcesResource") { $data["name"] = formatUserName($data["id"], "", $data["name"], $data["firstname"]); } $linkname = $data[$column]; if ($_SESSION["glpiis_ids_visible"] || empty($data[$column])) { $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]); } $name = "<a href=\"" . Toolbox::getItemTypeFormURL($itemtype) . "?id=" . $data["id"] . "\">" . $linkname . "</a>"; if ($itemtype == 'PluginProjetProjet' || $itemtype == 'PluginResourcesResource') { $pieces = preg_split('/(?=[A-Z])/', $itemtype); $plugin_name = $pieces[2]; $datas = array("entities_id" => $data["entity"], "ITEM_0" => $data["name"], "ITEM_0_2" => $data["id"], "id" => $data["id"], "META_0" => $data["name"]); //for PluginResourcesResource if (isset($data["is_recursive"])) { $datas["is_recursive"] = $data["is_recursive"]; } Plugin::load(strtolower($plugin_name), true); $function_giveitem = 'plugin_' . strtolower($plugin_name) . '_giveItem'; if (function_exists($function_giveitem)) { // For security $name = call_user_func($function_giveitem, $itemtype, 1, $datas, 0); } } echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; if ($item->canUpdate()) { Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]); } echo "</td>"; } echo "<td class='center'>"; // Show plugin name (is to delete remove any ambiguity) : $pieces = preg_split('/(?=[A-Z])/', $itemtype); if ($pieces[1] == 'Plugin') { $plugin_name = $pieces[2]; if (function_exists("plugin_version_" . $plugin_name)) { // For security $tab = call_user_func("plugin_version_" . $plugin_name); echo $tab["name"] . " : "; } } echo $item->getTypeName(1) . "</td>"; echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; echo "<td class='center'>"; $entity = $data['entity']; //for Plugins : if ($data["entity"] == -1) { $item->getFromDB($data['id']); if (isset($item->fields["entities_id"])) { $entity = $item->fields["entities_id"]; } } echo Dropdown::getDropdownName("glpi_entities", $entity); echo "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } } } echo "</table>"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show KB categories * * @param $options $_GET * * @return nothing (display the form) **/ static function showFirstLevel($options) { global $DB, $CFG_GLPI; $faq = !Session::haveRight("knowbase", "r"); // Default values of parameters $params["knowbaseitemcategories_id"] = "0"; $params["target"] = $_SERVER['PHP_SELF']; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } $faq_limit = ''; $parameters = ''; // Manage search solution if (isset($options['item_itemtype']) && isset($options['item_items_id'])) { $parameters = "&item_items_id=" . $options['item_items_id'] . "&item_itemtype=" . $options['item_itemtype']; } if ($faq) { if (!$CFG_GLPI["use_public_faq"] && !Session::haveRight("faq", "r")) { return false; } if (Session::getLoginUserID()) { $faq_limit = getEntitiesRestrictRequest("AND", "glpi_knowbaseitemcategories", "", "", true); } else { // Anonymous access if (Session::isMultiEntitiesMode()) { $faq_limit = " AND (`glpi_knowbaseitemcategories`.`entities_id` = '0'\n AND `glpi_knowbaseitemcategories`.`is_recursive` = '1')"; } } // Get All FAQ categories if (!isset($_SESSION['glpi_faqcategories'])) { $_SESSION['glpi_faqcategories'] = '(0)'; $tmp = array(); $query = "SELECT DISTINCT `glpi_knowbaseitems`.`knowbaseitemcategories_id`\n FROM `glpi_knowbaseitems`\n " . KnowbaseItem::addVisibilityJoins() . "\n LEFT JOIN `glpi_knowbaseitemcategories`\n ON (`glpi_knowbaseitemcategories`.`id`\n = `glpi_knowbaseitems`.`knowbaseitemcategories_id`)\n WHERE `glpi_knowbaseitems`.`is_faq` = '1'\n AND " . KnowbaseItem::addVisibilityRestrict() . "\n {$faq_limit}"; if ($result = $DB->query($query)) { if ($DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { if (!in_array($data['knowbaseitemcategories_id'], $tmp)) { $tmp[] = $data['knowbaseitemcategories_id']; $tmp = array_merge($tmp, getAncestorsOf('glpi_knowbaseitemcategories', $data['knowbaseitemcategories_id'])); } } } if (count($tmp)) { $_SESSION['glpi_faqcategories'] = "('" . implode("','", $tmp) . "')"; } } } $query = "SELECT DISTINCT `glpi_knowbaseitemcategories`.*\n FROM `glpi_knowbaseitemcategories`\n WHERE `glpi_knowbaseitemcategories`.`id` IN " . $_SESSION['glpi_faqcategories'] . "\n AND (`glpi_knowbaseitemcategories`.`knowbaseitemcategories_id`\n = '" . $params["knowbaseitemcategories_id"] . "')\n {$faq_limit}\n ORDER BY `name` ASC"; } else { if (!Session::haveRight("knowbase", "r")) { return false; } $faq_limit = getEntitiesRestrictRequest("AND", "glpi_knowbaseitemcategories", "entities_id", $_SESSION['glpiactiveentities'], true); $query = "SELECT *\n FROM `glpi_knowbaseitemcategories`\n WHERE `glpi_knowbaseitemcategories`.`knowbaseitemcategories_id`\n = '" . $params["knowbaseitemcategories_id"] . "'\n {$faq_limit}\n ORDER BY `name` ASC"; } // Show category if ($result = $DB->query($query)) { echo "<table class='tab_cadre_central'>"; echo "<tr><td colspan='3'><a href='" . $params['target'] . "?knowbaseitemcategories_id=0{$parameters}'>"; echo "<img alt='' src='" . $CFG_GLPI["root_doc"] . "/pics/folder-open.png' class='bottom'></a>"; // Display Category if ($params["knowbaseitemcategories_id"] != 0) { $tmpID = $params["knowbaseitemcategories_id"]; $todisplay = ""; while ($tmpID != 0) { $query2 = "SELECT *\n FROM `glpi_knowbaseitemcategories`\n WHERE `glpi_knowbaseitemcategories`.`id` = '{$tmpID}'\n {$faq_limit}"; $result2 = $DB->query($query2); if ($DB->numrows($result2) == 1) { $data = $DB->fetch_assoc($result2); $tmpID = $data["knowbaseitemcategories_id"]; $todisplay = "<a href='" . $params['target'] . "?knowbaseitemcategories_id=" . $data["id"] . "{$parameters}'>" . $data["name"] . "</a>" . (empty($todisplay) ? "" : " > ") . $todisplay; } else { $tmpID = 0; } } echo " > " . $todisplay; } if ($DB->numrows($result) > 0) { $i = 0; while ($row = $DB->fetch_assoc($result)) { // on affiche les résultats sur trois colonnes if ($i % 3 == 0) { echo "<tr>"; } $ID = $row["id"]; echo "<td class='tdkb_result'>"; echo "<img alt='' src='" . $CFG_GLPI["root_doc"] . "/pics/folder.png' hspace='5'>"; echo "<span class='b'>" . "<a href='" . $params['target'] . "?knowbaseitemcategories_id=" . $row["id"] . "{$parameters}'>" . $row["name"] . "</a></span>"; echo "<div class='kb_resume'>" . Html::resume_text($row['comment'], 60) . "</div>"; if ($i % 3 == 2) { echo "</tr>"; } $i++; } } echo "<tr><td colspan='3'> </td></tr></table><br>"; } }
if (!isset($_GET["tickets_id"])) { $_GET["tickets_id"] = ""; } if (!isset($_GET["modify"])) { $_GET["modify"] = ""; } if (!isset($_GET["delete"])) { $_GET["delete"] = ""; } if (!isset($_GET["addtofaq"])) { $_GET["addtofaq"] = ""; } if (!isset($_GET["removefromfaq"])) { $_GET["removefromfaq"] = ""; } $kb = new KnowbaseItem(); if ($_GET["id"] == "new") { // on affiche le formulaire de saisie de l'item $kb->check(-1, 'w'); commonHeader($LANG['title'][5], $_SERVER['PHP_SELF'], "utils", "knowbase"); $available_options = array('tickets_id'); $options = array(); foreach ($available_options as $key) { if (isset($_GET[$key])) { $options[$key] = $_GET[$key]; } } $kb->showForm("", $options); commonFooter(); } else { if (isset($_POST["add"])) {
// ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; checkSeveralRightsOr(array('knowbase' => 'r', 'faq' => 'r')); if (isset($_GET["id"])) { glpi_header($CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=" . $_GET["id"]); } commonHeader($LANG['title'][5], $_SERVER['PHP_SELF'], "utils", "knowbase"); // Search a solution if (!isset($_GET["contains"]) && isset($_GET["tickets_id"])) { $ticket = new Ticket(); if ($ticket->getFromDB($_GET["tickets_id"])) { $_GET["contains"] = $ticket->getField('name'); } } if (!isset($_GET["contains"])) { $_GET["contains"] = ""; } if (!isset($_GET["knowbaseitemcategories_id"])) { $_GET["knowbaseitemcategories_id"] = "0"; } $faq = !haveRight("knowbase", "r"); KnowbaseItem::searchForm($_GET, $faq); if (!isset($_GET["tickets_id"])) { KnowbaseItemCategory::showFirstLevel($_GET, $faq); } KnowbaseItem::showList($_GET, $faq); if (!$_GET["knowbaseitemcategories_id"] && strlen($_GET["contains"]) == 0) { KnowbaseItem::showViewGlobal($CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php", $faq); } commonFooter();
// Purpose of file: // ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); header_nocache(); if (!isset($_POST["id"])) { exit; } if (!isset($_REQUEST['glpi_tab'])) { exit; } if (empty($_POST["id"])) { $_POST["id"] = -1; } $kb = new KnowbaseItem(); if ($_POST['id'] > 0 && $kb->can($_POST['id'], 'r')) { switch ($_REQUEST['glpi_tab']) { case -1: $kb->showMenu(); Document::showAssociated($kb); Plugin::displayAction($kb, $_REQUEST['glpi_tab']); break; default: if (!Plugin::displayAction($kb, $_REQUEST['glpi_tab'])) { $kb->showMenu(); Document::showAssociated($kb); } } } ajaxFooter();
break; case 'Entity': $item = new Entity_KnowbaseItem(); break; } if (!is_null($item)) { $item->add($_POST); Event::log($_POST["knowbaseitems_id"], "knowbaseitem", 4, "tools", sprintf(__('%s adds a target'), $_SESSION["glpiname"])); } } Html::back(); } else { if (isset($_GET["id"])) { if (isset($_GET["_in_modal"])) { Html::popHeader(__('Knowledge base'), $_SERVER['PHP_SELF']); $kb = new KnowbaseItem(); if ($_GET['id']) { $kb->check($_GET["id"], READ); $kb->showFull(); } else { // New item $kb->showForm($_GET["id"], $_GET); } Html::popFooter(); } else { // modifier un item dans la base de connaissance $kb->check($_GET["id"], READ); if (Session::getLoginUserID()) { if ($_SESSION["glpiactiveprofile"]["interface"] == "central") { Html::header(KnowbaseItem::getTypeName(1), $_SERVER['PHP_SELF'], "tools", "knowbaseitem"); } else {
/** * Check is the curent user is allowed to see the file * * @param $options array of options (only 'tickets_id' used) * * @return boolean **/ function canViewFile($options) { global $DB, $CFG_GLPI; if (isset($_SESSION["glpiactiveprofile"]["interface"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central") { // My doc Check and Common doc right access if ($this->can($this->fields["id"], READ) || $this->fields["users_id"] === Session::getLoginUserID()) { return true; } // Reminder Case $query = "SELECT *\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_reminders`\n ON (`glpi_reminders`.`id` = `glpi_documents_items`.`items_id`\n AND `glpi_documents_items`.`itemtype` = 'Reminder')\n " . Reminder::addVisibilityJoins() . "\n WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n AND " . Reminder::addVisibilityRestrict(); $result = $DB->query($query); if ($DB->numrows($result) > 0) { return true; } // Knowbase Case if (Session::haveRight("knowbase", READ)) { $query = "SELECT *\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_knowbaseitems`\n ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`\n AND `glpi_documents_items`.`itemtype` = 'KnowbaseItem')\n " . KnowbaseItem::addVisibilityJoins() . "\n WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n AND " . KnowbaseItem::addVisibilityRestrict(); $result = $DB->query($query); if ($DB->numrows($result) > 0) { return true; } } if (Session::haveRight('knowbase', KnowbaseItem::READFAQ)) { $query = "SELECT *\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_knowbaseitems`\n ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`\n AND `glpi_documents_items`.`itemtype` = 'KnowbaseItem')\n " . KnowbaseItem::addVisibilityJoins() . "\n WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n AND `glpi_knowbaseitems`.`is_faq` = '1'\n AND " . KnowbaseItem::addVisibilityRestrict(); $result = $DB->query($query); if ($DB->numrows($result) > 0) { return true; } } // Tracking Case if (isset($options["tickets_id"])) { $job = new Ticket(); if ($job->can($options["tickets_id"], READ)) { $query = "SELECT *\n FROM `glpi_documents_items`\n WHERE `glpi_documents_items`.`items_id` = '" . $options["tickets_id"] . "'\n AND `glpi_documents_items`.`itemtype` = 'Ticket'\n AND `documents_id`='" . $this->fields["id"] . "'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { return true; } } } } else { if (Session::getLoginUserID()) { // ! central // Check if it is my doc if ($this->fields["users_id"] === Session::getLoginUserID()) { return true; } // Reminder Case $query = "SELECT *\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_reminders`\n ON (`glpi_reminders`.`id` = `glpi_documents_items`.`items_id`\n AND `glpi_documents_items`.`itemtype` = 'Reminder')\n " . Reminder::addVisibilityJoins() . "\n WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n AND " . Reminder::addVisibilityRestrict(); $result = $DB->query($query); if ($DB->numrows($result) > 0) { return true; } if (Session::haveRight('knowbase', KnowbaseItem::READFAQ)) { // Check if it is a FAQ document $query = "SELECT *\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_knowbaseitems`\n ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n " . KnowbaseItem::addVisibilityJoins() . "\n WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n AND `glpi_knowbaseitems`.`is_faq` = '1'\n AND " . KnowbaseItem::addVisibilityRestrict(); $result = $DB->query($query); if ($DB->numrows($result) > 0) { return true; } } // Tracking Case if (isset($options["tickets_id"])) { $job = new Ticket(); if ($job->can($options["tickets_id"], READ)) { $query = "SELECT *\n FROM `glpi_documents_items`\n WHERE `glpi_documents_items`.`items_id` = '" . $options["tickets_id"] . "'\n AND `glpi_documents_items`.`itemtype` = 'Ticket'\n AND `documents_id` = '" . $this->fields["id"] . "'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { return true; } } } } } // Public FAQ for not connected user if ($CFG_GLPI["use_public_faq"]) { $query = "SELECT *\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_knowbaseitems`\n ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n LEFT JOIN `glpi_entities_knowbaseitems`\n ON (`glpi_knowbaseitems`.`id` = `glpi_entities_knowbaseitems`.`knowbaseitems_id`)\n WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n AND `glpi_knowbaseitems`.`is_faq` = '1'\n AND `glpi_entities_knowbaseitems`.`entities_id` = '0'\n AND `glpi_entities_knowbaseitems`.`is_recursive` = '1'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { return true; } } return false; }
/** * Show items links to a document * * @since version 0.84 * * @param $doc Document object * * @return nothing (HTML display) **/ static function showForDocument(Document $doc) { global $DB, $CFG_GLPI; $instID = $doc->fields['id']; if (!$doc->can($instID, READ)) { return false; } $canedit = $doc->can($instID, UPDATE); // for a document, // don't show here others documents associated to this one, // it's done for both directions in self::showAssociated $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_documents_items`\n WHERE `glpi_documents_items`.`documents_id` = '{$instID}'\n AND `glpi_documents_items`.`itemtype` != 'Document'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); $rand = mt_rand(); if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='documentitem_form{$rand}' id='documentitem_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 class='right'>"; Dropdown::showSelectItemFromItemtypes(array('itemtypes' => Document::getItemtypesThatCanHave(), 'entity_restrict' => $doc->fields['is_recursive'] ? getSonsOf('glpi_entities', $doc->fields['entities_id']) : $doc->fields['entities_id'], 'checkright' => true)); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "<input type='hidden' name='documents_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>" . __('Name') . "</th>"; $header_end .= "<th>" . __('Entity') . "</th>"; $header_end .= "<th>" . __('Serial number') . "</th>"; $header_end .= "<th>" . __('Inventory number') . "</th>"; $header_end .= "</tr>"; echo $header_begin . $header_top . $header_end; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { if ($item instanceof CommonDevice) { $column = "designation"; } else { if ($item instanceof Item_Devices) { $column = "itemtype"; } else { $column = "name"; } } if ($itemtype == 'Ticket') { $column = "id"; } $itemtable = getTableForItemType($itemtype); $query = "SELECT `{$itemtable}`.*,\n `glpi_documents_items`.`id` AS IDD, "; if ($itemtype == 'KnowbaseItem') { $query .= "-1 AS entity\n FROM `glpi_documents_items`, `{$itemtable}`\n " . KnowbaseItem::addVisibilityJoins() . "\n WHERE `{$itemtable}`.`id` = `glpi_documents_items`.`items_id`\n AND "; } else { $query .= "`glpi_entities`.`id` AS entity\n FROM `glpi_documents_items`, `{$itemtable}`"; if ($itemtype != 'Entity') { $query .= " LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`)"; } $query .= " WHERE `{$itemtable}`.`id` = `glpi_documents_items`.`items_id`\n AND "; } $query .= "`glpi_documents_items`.`itemtype` = '{$itemtype}'\n AND `glpi_documents_items`.`documents_id` = '{$instID}' "; if ($itemtype == 'KnowbaseItem') { if (Session::getLoginUserID()) { $where = "AND " . KnowbaseItem::addVisibilityRestrict(); } else { // Anonymous access if (Session::isMultiEntitiesMode()) { $where = " AND (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')"; } } } else { $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive()); } if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } if ($itemtype == 'KnowbaseItem') { $query .= " ORDER BY `{$itemtable}`.`{$column}`"; } else { $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`"; } if ($itemtype == 'SoftwareLicense') { $soft = new Software(); } if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { while ($data = $DB->fetch_assoc($result_linked)) { if ($itemtype == 'Ticket') { $data["name"] = sprintf(__('%1$s: %2$s'), __('Ticket'), $data["id"]); } if ($itemtype == 'SoftwareLicense') { $soft->getFromDB($data['softwares_id']); $data["name"] = sprintf(__('%1$s - %2$s'), $data["name"], $soft->fields['name']); } if ($item instanceof CommonDevice) { $linkname = $data["designation"]; } else { if ($item instanceof Item_Devices) { $linkname = $data["itemtype"]; } else { $linkname = $data["name"]; } } if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]); } if ($item instanceof Item_Devices) { $tmpitem = new $item::$itemtype_2(); if ($tmpitem->getFromDB($data[$item::$items_id_2])) { $linkname = $tmpitem->getLink(); } } $link = Toolbox::getItemTypeFormURL($itemtype); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $linkname . "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]); echo "</td>"; } echo "<td class='center'>" . $item->getTypeName(1) . "</td>"; echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']); echo "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } } } if ($number) { echo $header_begin . $header_bottom . $header_end; } echo "</table>"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Form to add a solution to a ticket * * @param $knowbase_id_toload integer load a kb article as solution (0 = no load) **/ function showSolutionForm($knowbase_id_toload = 0) { global $LANG, $CFG_GLPI; $this->check($this->getField('id'), 'r'); $canedit = $this->canSolve(); $options = array(); if ($knowbase_id_toload > 0) { $kb = new KnowbaseItem(); if ($kb->getFromDB($knowbase_id_toload)) { $this->fields['solution'] = $kb->getField('answer'); } } $this->showFormHeader($options); $show_template = $canedit; // && $this->getField('ticketsolutiontypes_id') == 0 // && empty($this->fields['solution']); $rand_template = mt_rand(); $rand_text = $rand_type = 0; if ($canedit) { $rand_text = mt_rand(); $rand_type = mt_rand(); } if ($show_template) { echo "<tr class='tab_bg_2'>"; echo "<td>" . $LANG['jobresolution'][6] . " : </td><td>"; Dropdown::show('TicketSolutionTemplate', array('value' => 0, 'entity' => $this->getEntityID(), 'rand' => $rand_template, 'toupdate' => array('value_fieldname' => 'value', 'to_update' => 'solution' . $rand_text, 'url' => $CFG_GLPI["root_doc"] . "/ajax/solution.php", 'moreparams' => array('type_id' => 'dropdown_ticketsolutiontypes_id' . $rand_type)))); echo "</td><td colspan='2'>"; echo "<a title\"" . $LANG['job'][23] . "\"\n href='" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.php?tickets_id=" . $this->getField('id') . "'>" . $LANG['job'][23] . "</a>"; echo "</td></tr>"; } echo "<tr class='tab_bg_2'>"; echo "<td>" . $LANG['job'][48] . " : </td><td>"; $current = $this->fields['status']; // Settings a solution will set status to solved if ($canedit) { Dropdown::show('TicketSolutionType', array('value' => $this->getField('ticketsolutiontypes_id'), 'rand' => $rand_type)); } else { echo Dropdown::getDropdownName('glpi_ticketsolutiontypes', $this->getField('ticketsolutiontypes_id')); } echo "</td><td>" . $LANG['job'][25] . "</td><td>"; Dropdown::showYesNo('_sol_to_kb', false); echo "</td></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . $LANG['joblist'][6] . " : </td><td colspan='3'>"; if ($canedit) { initEditorSystem("solution"); echo "<div id='solution{$rand_text}'>"; echo "<textarea id='solution' name='solution' rows='12' cols='80'>"; echo $this->getField('solution'); echo "</textarea></div>"; } else { echo unclean_cross_side_scripting_deep($this->getField('solution')); } echo "</td></tr>"; $options['candel'] = false; $options['canedit'] = $canedit; $this->showFormButtons($options); }
// Affichage Module FAQ //****************** $name = ""; checkFaqAccess(); if (getLoginUserID()) { helpHeader($LANG['Menu'][20], $_SERVER['PHP_SELF'], $_SESSION["glpiname"]); } else { $_SESSION["glpilanguage"] = $CFG_GLPI['language']; // Anonymous FAQ simpleHeader($LANG['Menu'][20], array($LANG['Menu'][20] => $_SERVER['PHP_SELF'])); } if (!isset($_GET["contains"])) { $_GET["contains"] = ""; } if (!isset($_GET["knowbaseitemcategories_id"])) { $_GET["knowbaseitemcategories_id"] = 0; } if (isset($_GET["id"])) { $kb = new KnowbaseItem(); if ($kb->getFromDB($_GET["id"])) { $kb->showFull(false); } } else { KnowbaseItem::searchForm($_GET, 1); KnowbaseItemCategory::showFirstLevel($_GET, 1); KnowbaseItem::showList($_GET, 1); if (!$_GET["knowbaseitemcategories_id"] && strlen($_GET["contains"]) == 0) { KnowbaseItem::showViewGlobal($_SERVER['PHP_SELF'], 1); } } helpFooter();
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkSeveralRightsOr(array('knowbase' => 'r', 'faq' => 'r')); if (isset($_GET["id"])) { Html::redirect($CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=" . $_GET["id"]); } Html::header(KnowbaseItem::getTypeName(1), $_SERVER['PHP_SELF'], "utils", "knowbase"); // Search a solution if (!isset($_GET["contains"]) && isset($_GET["item_itemtype"]) && isset($_GET["item_items_id"])) { if ($item = getItemForItemtype($_GET["item_itemtype"])) { if ($item->getFromDB($_GET["item_items_id"])) { $_GET["contains"] = addslashes($item->getField('name')); } } } // Manage forcetab : non standard system (file name <> class name) if (isset($_GET['forcetab'])) { Session::setActiveTab('Knowbase', $_GET['forcetab']); unset($_GET['forcetab']); } $kb = new Knowbase(); $kb->show($_GET);
/** * Show the knowbase Manage view **/ static function showManageView() { if (isset($_GET["unpublished"])) { $_SESSION['kbunpublished'] = $_GET["unpublished"]; } else { if (isset($_SESSION['kbunpublished'])) { $_GET["unpublished"] = $_SESSION['kbunpublished']; } } if (!isset($_GET["unpublished"])) { $_GET["unpublished"] = 'myunpublished'; } $ki = new KnowbaseItem(); $ki->showManageForm($_GET); KnowbaseItem::showList($_GET, $_GET["unpublished"]); }
/** * Form to add a solution to an ITIL object * * @param $knowbase_id_toload integer load a kb article as solution (0 = no load by default) * (default 0) **/ function showSolutionForm($knowbase_id_toload = 0) { global $CFG_GLPI; $this->check($this->getField('id'), READ); $canedit = $this->canSolve(); $options = array(); if ($knowbase_id_toload > 0) { $kb = new KnowbaseItem(); if ($kb->getFromDB($knowbase_id_toload)) { $this->fields['solution'] = $kb->getField('answer'); } } // Alert if validation waiting $validationtype = $this->getType() . 'Validation'; if (method_exists($validationtype, 'alertValidation')) { $validationtype::alertValidation($this, 'solution'); } $this->showFormHeader($options); $show_template = $canedit; // && $this->getField('solutiontypes_id') == 0 // && empty($this->fields['solution']); $rand_template = mt_rand(); $rand_text = $rand_type = 0; if ($canedit) { $rand_text = mt_rand(); $rand_type = mt_rand(); } if ($show_template) { echo "<tr class='tab_bg_2'>"; echo "<td>" . _n('Solution template', 'Solution templates', 1) . "</td><td>"; SolutionTemplate::dropdown(array('value' => 0, 'entity' => $this->getEntityID(), 'rand' => $rand_template, 'toupdate' => array('value_fieldname' => 'value', 'to_update' => 'solution' . $rand_text, 'url' => $CFG_GLPI["root_doc"] . "/ajax/solution.php", 'moreparams' => array('type_id' => 'dropdown_solutiontypes_id' . $rand_type)))); echo "</td><td colspan='2'>"; if (Session::haveRightsOr('knowbase', array(READ, KnowbaseItem::READFAQ))) { echo "<a class='vsubmit' title=\"" . __s('Search a solution') . "\"\n href='" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.php?item_itemtype=" . $this->getType() . "&item_items_id=" . $this->getField('id') . "&forcetab=Knowbase\$1'>" . __('Search a solution') . "</a>"; } echo "</td></tr>"; } echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Solution type') . "</td><td>"; $current = $this->fields['status']; // Settings a solution will set status to solved if ($canedit) { SolutionType::dropdown(array('value' => $this->getField('solutiontypes_id'), 'rand' => $rand_type, 'entity' => $this->getEntityID())); } else { echo Dropdown::getDropdownName('glpi_solutiontypes', $this->getField('solutiontypes_id')); } echo "</td><td colspan='2'> </td></tr>"; if ($canedit && Session::haveRight('knowbase', UPDATE)) { echo "<tr class='tab_bg_2'><td>" . __('Save and add to the knowledge base') . "</td><td>"; Dropdown::showYesNo('_sol_to_kb', false); echo "</td><td colspan='2'> </td></tr>"; } echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Description') . "</td><td colspan='3'>"; if ($canedit) { $rand = mt_rand(); Html::initEditorSystem("solution{$rand}"); echo "<div id='solution{$rand_text}'>"; echo "<textarea id='solution{$rand}' name='solution' rows='12' cols='80' class='form-control'>" . $this->getField('solution') . "</textarea></div>"; } else { echo Toolbox::unclean_cross_side_scripting_deep($this->getField('solution')); } echo "</td></tr>"; $options['candel'] = false; $options['canedit'] = $canedit; $this->showFormButtons($options); }
Reminder::showListForCentral($_SESSION["glpiactive_entity"]); $entities = array_reverse(getAncestorsOf("glpi_entities", $_SESSION["glpiactive_entity"])); foreach ($entities as $entity) { Reminder::showListForCentral($entity, true); } foreach ($_SESSION["glpiactiveentities"] as $entity) { if ($entity != $_SESSION["glpiactive_entity"]) { Reminder::showListForCentral($entity, false); } } echo "</td></tr>"; } echo "</table></td>"; echo "<td class='top' width='450px'><br>"; echo "<table>"; // Show KB items if (haveRight("faq", "r")) { echo "<tr><td class='top' width='450px'>"; KnowbaseItem::showRecentPopular($CFG_GLPI['root_doc'] . '/front/helpdesk.faq.php', "popular", 1); echo "</td></tr>"; echo "<tr><td class='top' width='450px'><br>"; KnowbaseItem::showRecentPopular($CFG_GLPI['root_doc'] . '/front/helpdesk.faq.php', "recent", 1); echo "</td></tr>"; } else { echo "<tr><td> </td></tr>"; } echo "</table>"; echo "</td>"; echo "</tr></table>"; } helpFooter();