static function uninstall() { global $DB; $obj = new self(); $DB->query("DROP TABLE IF EXISTS `" . $obj->getTable() . "`"); return true; }
/** * if profile cloned * * @param $prof Profile object **/ static function cloneProfile(Profile $prof) { global $DB; $plugprof = new self(); $crit = array('profiles_id' => $prof->input['_old_id']); foreach ($DB->request($plugprof->getTable(), $crit) as $data) { $input = ToolBox::addslashes_deep($data); unset($input['id']); $input['profiles_id'] = $prof->getID(); $plugprof->add($input); } }
/** * If host not exist add it * * */ static function addHost($item) { global $DB; $pmHost = new self(); $query = "SELECT * FROM `" . $pmHost->getTable() . "`\n WHERE `itemtype`='" . $item->fields['itemtype'] . "'\n AND `items_id`='" . $item->fields['items_id'] . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $input = array(); $input['itemtype'] = $item->fields['itemtype']; $input['items_id'] = $item->fields['items_id']; $pmHost->add($input); } }
static function transfer($ID, $entity) { global $DB; $temp = new self(); if ($ID <= 0 || !$temp->getFromDB($ID)) { return 0; } $query = "SELECT `id`\n FROM `" . $temp->getTable() . "`\n WHERE `entities_id` = '" . $entity . "'\n AND `name` = '" . addslashes($temp->fields['name']) . "'"; foreach ($DB->request($query) as $data) { return $data['id']; } $input = $temp->fields; $input['entities_id'] = $entity; unset($input['id']); return $temp->add($input); }
static function uninstall() { global $DB; //uninstall container table and class $obj = new self(); $containers = $obj->find(); foreach ($containers as $containers_id => $container) { $obj->delete(array('id' => $containers_id)); } //drop global container table $obj = new self(); $DB->query("DROP TABLE IF EXISTS `" . $obj->getTable() . "`"); //delete display preferences for this item $DB->query("DELETE FROM glpi_displaypreferences WHERE `itemtype` = '" . __CLASS__ . "'"); return true; }
/** * Update IPNetwork's dependency * * @param $network IPNetwork object **/ static function linkIPAddressFromIPNetwork(IPNetwork $network) { global $DB; $linkObject = new self(); $linkTable = $linkObject->getTable(); $ipnetworks_id = $network->getID(); // First, remove all links of the current Network $query = "SELECT `id`\n FROM `{$linkTable}`\n WHERE `ipnetworks_id` = '{$ipnetworks_id}'"; foreach ($DB->request($query) as $link) { $linkObject->delete(array('id' => $link['id'])); } // Then, look each IP address contained inside current Network $query = "SELECT '" . $ipnetworks_id . "' AS ipnetworks_id,\n `id` AS ipaddresses_id\n FROM `glpi_ipaddresses`\n WHERE " . $network->getWHEREForMatchingElement('glpi_ipaddresses', 'binary', 'version') . "\n GROUP BY `id`"; foreach ($DB->request($query) as $link) { $linkObject->add($link); } }
static function transfer($ID, $entity) { global $DB; $simcardSize = new self(); if ($ID > 0) { // Not already transfer // Search init item $query = "SELECT *\n FROM `" . $simcardSize->getTable() . "`\n WHERE `id` = '{$ID}'"; if ($result = $DB->query($query)) { if ($DB->numrows($result)) { $data = $DB->fetch_assoc($result); $data = Toolbox::addslashes_deep($data); $input['name'] = $data['name']; $input['entities_id'] = $entity; $newID = $simcardSize->getID($input); if ($newID < 0) { $newID = $simcardSize->import($input); } return $newID; } } } return 0; }
/** * Show the aliases contained by the alias * * @param $item the FQDN owning the aliases * @param $withtemplate integer withtemplate param **/ static function showForFQDN(CommonGLPI $item, $withtemplate) { global $DB; $alias = new self(); $address = new NetworkName(); $item->check($item->getID(), 'r'); $canedit = $item->can($item->getID(), 'w'); if (isset($_POST["start"])) { $start = $_POST["start"]; } else { $start = 0; } if (!empty($_POST["order"])) { $order = $_POST["order"]; } else { $order = "alias"; } $number = countElementsInTable($alias->getTable(), "`fqdns_id`='" . $item->getID() . "'"); echo "<br><div class='center'>"; if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . self::getTypeName(1) . "</th><th>" . __('No item found') . "</th></tr>"; echo "</table>\n"; } else { Html::printAjaxPager(self::getTypeName($number), $start, $number); echo "<table class='tab_cadre_fixe'><tr>"; echo "<th><a href='javascript:reloadTab(\"order=alias\");'>" . self::getTypeName(1) . "</a></th>"; // Alias echo "<th><a href='javascript:reloadTab(\"order=realname\");'>" . __("Computer's name") . "</a></th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>\n"; Session::initNavigateListItems($item->getType(), sprintf(__('%1$s = %2$s'), self::getTypeName(1), $item->fields['name'])); $query = "SELECT `glpi_networkaliases`.`id` AS alias_id,\n `glpi_networkaliases`.`name` AS alias,\n `glpi_networknames`.`id` AS address_id,\n `glpi_networkaliases`.`comment` AS comment\n FROM `glpi_networkaliases`, `glpi_networknames`\n WHERE `glpi_networkaliases`.`fqdns_id` = '" . $item->getID() . "'\n AND `glpi_networknames`.`id` = `glpi_networkaliases`.`networknames_id`\n ORDER BY `{$order}`\n LIMIT " . $_SESSION['glpilist_limit'] . "\n OFFSET {$start}"; foreach ($DB->request($query) as $data) { Session::addToNavigateListItems($alias->getType(), $data["alias_id"]); if ($address->getFromDB($data["address_id"])) { echo "<tr class='tab_bg_1'>"; echo "<td><a href='" . $alias->getFormURL() . '?id=' . $data['alias_id'] . "'>" . $data['alias'] . "</a></td>"; echo "<td><a href='" . $address->getLinkURL() . "'>" . $address->getInternetName() . "</a></td>"; echo "<td>" . $data['comment'] . "</td>"; echo "</tr>\n"; } } echo "</table>\n"; Html::printAjaxPager(self::getTypeName($number), $start, $number); } echo "</div>\n"; }
/** * Database table uninstallation for the item type * * @return boolean True on success */ public static function uninstall() { $obj = new self(); $GLOBALS['DB']->query('DROP TABLE IF EXISTS `' . $obj->getTable() . '`'); // Delete logs of the plugin $GLOBALS['DB']->query('DELETE FROM `glpi_logs` WHERE itemtype = "' . __CLASS__ . '"'); return true; }
/** * @param $networkPortID **/ static function showFormForNetworkPort($networkPortID) { global $DB, $CFG_GLPI; $name = new self(); $number_names = 0; if ($networkPortID > 0) { $query = "SELECT `id`\n FROM `" . $name->getTable() . "`\n WHERE `itemtype` = 'NetworkPort'\n AND `items_id` = '{$networkPortID}'\n AND `is_deleted` = '0'"; $result = $DB->query($query); if ($DB->numrows($result) > 1) { echo "<tr class='tab_bg_1'><th colspan='4'>" . __("Several network names available! Go to the tab 'Network Name' to manage them.") . "</th></tr>\n"; return; } switch ($DB->numrows($result)) { case 1: $nameID = $DB->fetch_assoc($result); $name->getFromDB($nameID['id']); break; case 0: $name->getEmpty(); break; } } else { $name->getEmpty(); } echo "<tr class='tab_bg_1'><th colspan='4'>"; // If the networkname is defined, we must be able to edit it. So we make a link if ($name->getID() > 0) { echo "<a href='" . $name->getLinkURL() . "'>" . self::getTypeName(1) . "</a>"; echo "<input type='hidden' name='NetworkName_id' value='" . $name->getID() . "'> \n"; Html::showSimpleForm($name->getFormURL(), 'unaffect', _sx('button', 'Dissociate'), array('id' => $name->getID()), $CFG_GLPI["root_doc"] . '/pics/sub_dropdown.png'); } else { echo self::getTypeName(1); } echo "</th>\n"; echo "</tr><tr class='tab_bg_1'>"; echo "<td>" . self::getTypeName(1) . "</td><td>\n"; Html::autocompletionTextField($name, "name", array('name' => 'NetworkName_name')); echo "</td>\n"; echo "<td>" . FQDN::getTypeName(1) . "</td><td>"; Dropdown::show(getItemTypeForTable(getTableNameForForeignKeyField("fqdns_id")), array('value' => $name->fields["fqdns_id"], 'name' => 'NetworkName_fqdns_id', 'entity' => $name->getEntityID(), 'displaywith' => array('view'))); echo "</td>\n"; echo "</tr><tr class='tab_bg_1'>\n"; echo "<td>" . IPAddress::getTypeName(Session::getPluralNumber()); IPAddress::showAddChildButtonForItemForm($name, 'NetworkName__ipaddresses'); echo "</td>"; echo "<td>"; IPAddress::showChildsForItemForm($name, 'NetworkName__ipaddresses'); echo "</td>"; // MoYo : really need to display it here ? // make confure because not updatable // echo "<td>".IPNetwork::getTypeName(Session::getPluralNumber())." "; // Html::showToolTip(__('IP network is not included in the database. However, you can see current available networks.')); // echo "</td><td>"; // IPNetwork::showIPNetworkProperties($name->getEntityID()); // echo "</td>\n"; echo "<td colspan='2'> </td>"; echo "</tr>\n"; }
static function showMinimalList($params = array()) { global $DB, $CFG_GLPI; $item = new self(); $itemtype = $item->getType(); $itemtable = $item->getTable(); // Default values of parameters $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['id'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; $p['withtemplate'] = 0; foreach ($params as $key => $val) { $p[$key] = $val; } $PluginResourcesResource = new PluginResourcesResource(); $PluginResourcesResource->getFromDB($p['id']); $canedit = $PluginResourcesResource->can($p['id'], 'w'); if (isset($_POST["start"])) { $p['start'] = $_POST["start"]; } else { $p['start'] = 0; } if (isset($_POST["sort"])) { $p['sort'] = $_POST["sort"]; } else { $p['sort'] = 1; } if (isset($_POST["order"]) && $_POST["order"] == "DESC") { $p['order'] = "DESC"; } else { $p['order'] = "ASC"; } // Manage defautll seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } $target = Toolbox::getItemTypeSearchURL($itemtype); $limitsearchopt = Search::getCleanedOptions($itemtype); $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == Search::GLOBAL_SEARCH) { $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT; } } $entity_restrict = $item->isEntityAssign(); // Get the items to display $toview = Search::addDefaultToView($itemtype); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($toview, $val); } } // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } $toview_count = count($toview); //// 1 - SELECT $query = "SELECT " . Search::addDefaultSelect($itemtype); // Add select for all toview item foreach ($toview as $key => $val) { $query .= Search::addSelect($itemtype, $val, $key, 0); } $query .= "`" . $itemtable . "`.`id` AS id "; //// 2 - FROM AND LEFT JOIN // Set reference table $query .= " FROM `" . $itemtable . "`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables); $query .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt[$itemtype] =& Search::getOptions($itemtype); // Add all table for toview items foreach ($toview as $key => $val) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]); } // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]); } } } $query .= " WHERE `" . $itemtable . "`.`plugin_resources_resources_id` = '" . $p['id'] . "'"; $query .= " AND `" . $itemtable . "`.`is_deleted` = '" . $p['is_deleted'] . "' "; //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if (in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`"; } } } $query .= $GROUPBY; //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } $query .= $ORDER; // Get it from database if ($result = $DB->query($query)) { $numrows = $DB->numrows($result); $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']); $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; if ($output_type == Search::GLOBAL_SEARCH) { if (class_exists($itemtype)) { echo "<div class='center'><h2>" . $item->getTypeName(); // More items if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } if ($p['start'] < $numrows) { if ($output_type == Search::HTML_OUTPUT && !$p['withtemplate']) { echo "<div align='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.php?contains%5B0%5D=" . $p['id'] . "&field%5B0%5D=13&sort=1&is_deleted=0&start=0'>" . _x('button', 'Search') . "</a><br>"; echo "</div>"; } // Pager if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $search_config = ""; if ($item->canCreate() && $canedit) { $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&itemtype=" . $itemtype . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' ); w.focus();\""; $search_config = "<img alt='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']); } // Pager if ($output_type == Search::HTML_OUTPUT) { Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows, $search_config); echo "<br>"; } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } //massive action $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { Html::openMassiveActionsForm('massform' . $itemtype); $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => true, 'is_deleted' => $p['is_deleted']); Html::showMassiveActions($itemtype, $massiveactionparams); } // Add toview elements $nbcols = $toview_count; if ($output_type == Search::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Display List Header echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols, 1); $header_num = 1; // Display column Headers for toview items $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; echo Search::showNewLine($output_type); if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) { // HTML display - massive modif $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); } // Display column Headers for toview items foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) { $linkto = "javascript:reloadTab('sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto . "')"; } $headers_line .= Search::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); } // End Line for column headers $headers_line .= Search::showEndLine($output_type); $headers_line_top .= $headers_line; $headers_line_bottom .= $headers_line; echo $headers_line_top; $DB->data_seek($result, $p['start']); // Define begin and end var for loop // Search case $i = $begin_display; // Init list of items displayed if ($output_type == Search::HTML_OUTPUT) { Session::initNavigateListItems($itemtype, PluginResourcesResource::getTypeName(2) . " = " . (empty($PluginResourcesResource->fields['name']) ? "(" . $p['id'] . ")" : $PluginResourcesResource->fields['name'])); } // Num of the row (1=header_line) $row_num = 1; // Display Loop while ($i < $numrows && $i < $end_display) { $item_num = 1; $data = $DB->fetch_array($result); $i++; $row_num++; echo Search::showNewLine($output_type, $i % 2); Session::addToNavigateListItems($itemtype, $data['id']); $tmpcheck = ""; if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $sel = ""; $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>"; } echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'"); foreach ($toview as $key => $val) { echo Search::showItem($output_type, Search::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, Search::displayConfigItem($itemtype, $val, $data, $key)); } echo Search::showEndLine($output_type); } // Close Table $title = ""; // Create title if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) { $title .= __('Tasks list', 'resources'); } // Display footer echo Search::showFooter($output_type, $title); //massive action if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($itemtype, $massiveactionparams); Html::closeForm(); } else { echo "</table></div>"; } // Pager if ($output_type == Search::HTML_OUTPUT) { echo "<br>"; Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows); } } else { echo Search::showError($output_type); } } }
/** * Launch the need cron tasks * * @param $mode (internal/external, <0 to force) * @param $max number of task to launch (default 1) * @param $name of task to run (default '') * * @return the name of last task launched **/ public static function launch($mode, $max = 1, $name = '') { global $CFG_GLPI; // No cron in maintenance mode if (isset($CFG_GLPI['maintenance_mode']) && $CFG_GLPI['maintenance_mode']) { return false; } $crontask = new self(); $taskname = ''; if (abs($mode) == self::MODE_EXTERNAL) { // If cron is launched in command line, and if memory is insufficient, // display a warning in the logs if (Toolbox::checkMemoryLimit() == 2) { Toolbox::logInFile('cron', __('A minimum of 64 Mio is commonly required for GLPI.') . "\n"); } // If no task in CLI mode, call cron.php from command line is not really usefull ;) if (!countElementsInTable($crontask->getTable(), ['mode' => abs($mode)])) { Toolbox::logInFile('cron', __('No task with Run mode = CLI, fix your tasks configuration') . "\n"); } } if (self::get_lock()) { for ($i = 1; $i <= $max; $i++) { $prefix = abs($mode) == self::MODE_EXTERNAL ? __('External') : __('Internal'); if ($crontask->getNeedToRun($mode, $name)) { $_SESSION["glpicronuserrunning"] = "cron_" . $crontask->fields['name']; if ($plug = isPluginItemType($crontask->fields['itemtype'])) { Plugin::load($plug['plugin'], true); } $fonction = array($crontask->fields['itemtype'], 'cron' . $crontask->fields['name']); if (is_callable($fonction)) { if ($crontask->start()) { // Lock in DB + log start $taskname = $crontask->fields['name']; //TRANS: %1$s is mode (external or internal), %2$s is an order number, $msgcron = sprintf(__('%1$s #%2$s'), $prefix, $i); $msgcron = sprintf(__('%1$s: %2$s'), $msgcron, sprintf(__('%1$s %2$s') . "\n", __('Launch'), $crontask->fields['name'])); Toolbox::logInFile('cron', $msgcron); $retcode = call_user_func($fonction, $crontask); $crontask->end($retcode); // Unlock in DB + log end } else { $msgcron = sprintf(__('%1$s #%2$s'), $prefix, $i); $msgcron = sprintf(__('%1$s: %2$s'), $msgcron, sprintf(__('%1$s %2$s') . "\n", __("Can't start"), $crontask->fields['name'])); Toolbox::logInFile('cron', $msgcron); } } else { if (is_array($fonction)) { $fonction = implode('::', $fonction); } Toolbox::logInFile('php-errors', sprintf(__('Undefined function %s (for cron)') . "\n", $fonction)); $msgcron = sprintf(__('%1$s #%2$s'), $prefix, $i); $msgcron = sprintf(__('%1$s: %2$s'), $msgcron, sprintf(__('%1$s %2$s') . "\n", __("Can't start"), $crontask->fields['name'])); Toolbox::logInFile('cron', $msgcron . "\n" . sprintf(__('Undefined function %s (for cron)') . "\n", $fonction)); } } else { if ($i == 1) { $msgcron = sprintf(__('%1$s #%2$s'), $prefix, $i); $msgcron = sprintf(__('%1$s: %2$s'), $msgcron, __('Nothing to launch')); Toolbox::logInFile('cron', $msgcron . "\n"); } } } // end for $_SESSION["glpicronuserrunning"] = ''; self::release_lock(); } else { Toolbox::logInFile('cron', __("Can't get DB lock") . "\n"); } return $taskname; }
/** * If host does not exist add it * */ static function addHost($item) { global $DB; $pmHost = new self(); $query = "SELECT * FROM `".$pmHost->getTable()."` WHERE `itemtype`='".$item->fields['itemtype']."' AND `items_id`='".$item->fields['items_id']."' LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $input = array(); $input['itemtype'] = $item->fields['itemtype']; $input['items_id'] = $item->fields['items_id']; $item2 = new $item->fields['itemtype']; $item2->getFromDB($item->fields['items_id']); // Try to fix entities_id = 0 $input['entities_id'] = $item2->fields['entities_id']; $pmHost->add($input); } }
static function isThisItemCheckRuleNetworkport($parm) { global $DB; $pmComponentscatalog_rule = new self(); $pmService = new PluginMonitoringService(); $pmSearch = new PluginMonitoringSearch(); $a_networkports_id = array(); if (get_class($parm) == 'PluginMonitoringNetworkport') { $a_networkports_id[$parm->fields['networkports_id']] = $parm->fields['items_id']; } else { if (get_class($parm) == 'NetworkEquipment') { $query = "SELECT * FROM `glpi_plugin_monitoring_networkports`\n WHERE `items_id`='" . $parm->fields['id'] . "'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $a_networkports_id[$data['networkports_id']] = $parm->fields['id']; } } } foreach ($a_networkports_id as $networkports_id => $networkequipments_id) { $a_find = array(); $query = "SELECT * FROM `" . $pmComponentscatalog_rule->getTable() . "`\n WHERE `itemtype`='PluginMonitoringNetworkport'"; $result = $DB->query($query); $get_tmp = array(); if (isset($_GET)) { $get_tmp = $_GET; } while ($data = $DB->fetch_array($result)) { if (isset($_SESSION["glpisearchcount"][$data['itemtype']])) { unset($_SESSION["glpisearchcount"][$data['itemtype']]); } if (isset($_SESSION["glpisearchcount2"][$data['itemtype']])) { unset($_SESSION["glpisearchcount2"][$data['itemtype']]); } $_GET = importArrayFromDB($data['condition']); $_GET["glpisearchcount"] = count($_GET['field']); if (isset($_GET['field2'])) { $_GET["glpisearchcount2"] = count($_GET['field2']); } if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = $parm->fields['entities_id']; } Search::manageGetValues($data['itemtype']); $resultr = $pmSearch->constructSQL("PluginMonitoringNetworkport", $_GET, $networkports_id); if ($DB->numrows($resultr) > 0) { $a_find[$data['plugin_monitoring_componentscalalog_id']][$networkports_id] = 1; } else { if (!isset($a_find[$data['plugin_monitoring_componentscalalog_id']][$networkports_id])) { $a_find[$data['plugin_monitoring_componentscalalog_id']][$networkports_id] = 0; } } } if (count($get_tmp) > 0) { $_GET = $get_tmp; } $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); foreach ($a_find as $componentscalalog_id => $datan) { foreach ($datan as $networkports_id => $is_present) { // Get all networports in this rule if ($is_present == '0') { // * Remove from dynamic if present $query = "SELECT `glpi_plugin_monitoring_services`.`id`,\n `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` as hid\n FROM `glpi_plugin_monitoring_services`\n LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts` ON\n `plugin_monitoring_componentscatalogs_hosts_id` = `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n AND `itemtype`='NetworkEquipment'\n AND `items_id`='" . $networkequipments_id . "'\n AND `is_static`='0'\n AND `networkports_id`='" . $networkports_id . "'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $pmComponentscatalog_Host->getFromDB($data['hid']); $_SESSION['plugin_monitoring_hosts'] = $pmComponentscatalog_Host->fields; $pmService->delete(array('id' => $data['id'])); } } else { // add if not present // * Add componentscatalogs_hosts if not exist $componentscatalogs_hosts_id = 0; $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n AND `itemtype`='NetworkEquipment'\n AND `items_id`='" . $networkequipments_id . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $componentscalalog_id; $input['is_static'] = '0'; $input['itemtype'] = "NetworkEquipment"; $input['items_id'] = $networkequipments_id; $componentscatalogs_hosts_id = $pmComponentscatalog_Host->add($input); } else { $a_componentscatalogs_hosts = $DB->fetch_assoc($result); $componentscatalogs_hosts_id = $a_componentscatalogs_hosts['id']; } // * Add service if not exist $pmComponentscatalog_Host->linkComponentsToItem($componentscalalog_id, $componentscatalogs_hosts_id, $networkports_id); } } } } }
static function selectGroupOnAdd($item) { global $CFG_GLPI, $DB; if (isset($item->input['_auto_import']) || isset($item->input['bypassgrouponadd'])) { return; } $peGroup_group = new self(); if ($_SESSION['glpiactiveprofile']['interface'] == 'central') { $peConfig = new PluginEscalationConfig(); if ($peConfig->getValue('workflow', $item->fields['entities_id']) == '1') { if (isset($_POST['_groups_id_assign']) && $_POST['_groups_id_assign'] > 0) { if (isset($_SESSION['plugin_escalation_files'])) { $_FILES = $_SESSION['plugin_escalation_files']; } return; } else { $group = new Group(); Html::header(__('Administration'), '', "maintain", "ticket"); if (isset($_POST['dropdown__groups_id_requester']) && $_POST['dropdown__groups_id_requester'] > 0) { $_SESSION['plugin_escalation_groups_id_requester'] = $_POST['dropdown__groups_id_requester']; } if (isset($_FILES)) { foreach ($_FILES['filename']['tmp_name'] as $numfile => $datafile) { if ($datafile != '') { $split = explode("/", $datafile); Document::renameForce($datafile, GLPI_DOC_DIR . "/_tmp/" . end($split)); $_FILES['filename']['tmp_name'][$numfile] = GLPI_DOC_DIR . "/_tmp/" . end($split); } } $_SESSION['plugin_escalation_files'] = $_FILES; } echo '<form action="' . $CFG_GLPI['root_doc'] . '/front/ticket.form.php" enctype="multipart/form-data" name="form_ticket" method="post">'; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='2'>Sélection du groupe de techniciens</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>"; echo __('Group in charge of the ticket') . " :"; echo "</td>"; echo "<td>"; $a_groups = array(); foreach ($_SESSION['glpigroups'] as $groups_id) { $group->getFromDB($groups_id); $a_groups[$groups_id] = $group->getName(); $queryg = "SELECT * FROM `" . $peGroup_group->getTable() . "`\n WHERE `groups_id_source` = '" . $groups_id . "' "; $resultg = $DB->query($queryg); while ($datag = $DB->fetch_array($resultg)) { $group->getFromDB($datag['groups_id_destination']); $a_groups[$groups_id . "_" . $datag['groups_id_destination']] = " > " . $group->getName(); } } $rand = Dropdown::showFromArray("_groups_id_assign_escalation", $a_groups); $params = array('groups_id' => '__VALUE__', 'entity' => $_POST['entities_id'], 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown__groups_id_assign" . $rand, "show_assignuser{$rand}", $CFG_GLPI["root_doc"] . "/plugins/escalation/ajax/dropdownUserassign.php", $params); echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'>"; foreach ($_POST as $key => $value) { if (is_array($value)) { foreach ($value as $keyy => $valuee) { echo '<input type="hidden" name="' . $key . '[' . $keyy . ']" value="' . $valuee . '" />'; } } else { if ($key == 'content') { $value = Html::cleanPostForTextArea(Toolbox::clean_cross_side_scripting_deep($value)); echo '<textarea name="' . $key . '" style="display:none;">' . $value . '</textarea>'; } else { if ($key == 'dropdown__groups_id_requester') { echo '<input type="hidden" name="_groups_id_requester" value="' . $value . '" />'; } else { $value = Html::cleanInputText(Toolbox::clean_cross_side_scripting_deep(stripslashes($value))); echo '<input type="hidden" name="' . $key . '" value="' . $value . '" />'; } } } } if (!isset($_POST['_users_id_assign']) or $_POST['_users_id_assign'] == '0') { echo "<span id='show_assignuser{$rand}'></span>"; } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' align='center'>"; echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); Html::footer(); exit; } } } }
/** * Prepare input datas for adding the section * Check fields values and get the order for the new section * * @param $input datas used to add the item * * @return the modified $input array **/ public function prepareInputForAdd($input) { // Control fields values : // - name is required if (empty($input['name'])) { Session::addMessageAfterRedirect(__('The title is required', 'formcreato'), false, ERROR); return array(); } // Get next order $obj = new self(); $query = "SELECT MAX(`order`) AS `order`\n FROM `{$obj->getTable()}`\n WHERE `plugin_formcreator_forms_id` = {$input['plugin_formcreator_forms_id']}"; $result = $GLOBALS['DB']->query($query); $line = $GLOBALS['DB']->fetch_array($result); $input['order'] = $line['order'] + 1; return $input; }
/** * Get Structure of the current table * * @param bool $withGuarded * @param bool $asKey * @return array * @throws \Exception */ public static function getStructure($withoutGuarded = false, $asKey = false) { $t = new self(); # if structure is defined => return structure if (isset(static::$_structure)) { return static::$_structure; } $table = $t->getTable(); $columns = array(); switch (DB::connection()->getConfig('driver')) { case 'pgsql': $query = "SELECT column_name FROM information_schema.columns WHERE table_name = '" . $table . "'"; $column_name = 'column_name'; $reverse = true; break; case 'mysql': $query = 'SHOW COLUMNS FROM ' . $table; $column_name = 'Field'; $reverse = false; break; case 'sqlsrv': $parts = explode('.', $table); $num = count($parts) - 1; $table = $parts[$num]; $query = "SELECT column_name FROM " . DB::connection()->getConfig('database') . ".INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'" . $table . "'"; $column_name = 'column_name'; $reverse = false; break; default: # Try to guess structure with first Element $table = self::where('id', '!=', 'x')->first(); if ($table) { $columns = array_keys($table->getAttributes()); } else { $error = 'Database driver not supported: you must define a static _structure variable ' . DB::connection()->getConfig('driver'); throw new \Exception($error); } break; } if (!$columns) { $columns = array(); foreach (DB::select($query) as $column) { $columns[] = $column->{$column_name}; } if ($reverse) { $columns = array_reverse($columns); } } if ($withoutGuarded) { $kColumns = array_flip($columns); foreach ($t->guarded as $key) { if (isset($kColumns[$key])) { unset($columns[$kColumns[$key]]); } } # remove timestamp $updated_at = array_search('updated_at', $columns); if ($updated_at !== false) { unset($columns['updated_at']); } $created_at = array_search('created_at', $columns); if ($created_at !== false) { unset($columns['created_at']); } } # Switch keys if we want column name as key if ($asKey) { $columns = array_flip($columns); } return $columns; }
/** * Clean all model which match some criteria * * @param $crit array of criteria (ex array('itemtype'=>'PluginAppliancesAppliance')) * **/ static function clean($crit = array()) { global $DB; $model = new self(); if (is_array($crit) && count($crit) > 0) { $crit['FIELDS'] = 'id'; foreach ($DB->request($model->getTable(), $crit) as $row) { $model->delete($row); } } }
public static function showGlobalNotation($suppliers_id) { global $DB; $config = PluginOrderConfig::getConfig(); if (!$config->canUseSupplierSatisfaction()) { return; } $survey = new self(); $survey_table = $survey->getTable(); $restrict = getEntitiesRestrictRequest(" AND ", "orders", "entities_id", '', true); $query = "SELECT orders.`id`, orders.`entities_id`, orders.`name`, survey.`comment`\n FROM `glpi_plugin_order_orders` orders, `{$survey_table}` survey\n WHERE survey.`suppliers_id` = orders.`suppliers_id`\n AND survey.`plugin_order_orders_id` = orders.`id`\n AND orders.`suppliers_id` = '{$suppliers_id}'\n {$restrict}"; $query .= "GROUP BY `survey`.id"; $result = $DB->query($query); $nb = $DB->numrows($result); $total = 0; $nb_order = 0; echo "<br>"; echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th colspan='4'>" . __("Supplier quality", "order") . "</th>"; echo "</tr>"; echo "<tr>"; echo "<th>" . __("Entity") . "</th>"; echo "<th>" . __("Order name", "order") . "</th>"; echo "<th>" . __("Note", "order") . "</th>"; echo "<th>" . __("Comment on survey", "order") . "</th>"; echo "</tr>"; if ($nb) { for ($i = 0; $i < $nb; $i++) { $name = $DB->result($result, $i, "name"); $ID = $DB->result($result, $i, "id"); $comment = $DB->result($result, $i, "comment"); $entities_id = $DB->result($result, $i, "entities_id"); $note = $survey->getTotalNotation($ID); echo "<tr class='tab_bg_1'>"; echo "<td>"; echo Dropdown::getDropdownName("glpi_entities", $entities_id); echo "</td>"; $link = Toolbox::getItemTypeFormURL('PluginOrderOrder'); echo "<td><a href=\"" . $link . "?id=" . $ID . "\">" . $name . "</a></td>"; echo "<td>" . $note . " / 10</td>"; echo "<td>" . nl2br($comment) . "</td>"; echo "</tr>"; $total += $survey->getTotalNotation($ID); $nb_order++; } echo "<tr>"; echo "<th colspan='4'> </th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'></td>"; echo "<td><div align='left'>" . __("Administrative followup quality (contracts, bills, mail, etc.)", "order") . "</div></td>"; echo "<td><div align='left'>" . Html::formatNumber($survey->getNotation($suppliers_id, "answer1")) . " / 10</div></td>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'></td>"; echo "<td><div align='left'>" . __("Commercial followup quality, visits, responseness", "order") . "</div></td>"; echo "<td><div align='left'>" . Html::formatNumber($survey->getNotation($suppliers_id, "answer2")) . " / 10</div></td>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'></td>"; echo "<td><div align='left'>" . __("Contacts availability", "order") . "</div></td>"; echo "<td><div align='left'>" . Html::formatNumber($survey->getNotation($suppliers_id, "answer3")) . " / 10</div></td>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'></td>"; echo "<td><div align='left'>" . __("Quality of supplier intervention", "order") . "</div></td>"; echo "<td><div align='left'>" . Html::formatNumber($survey->getNotation($suppliers_id, "answer4")) . " / 10</div></td>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'></td>"; echo "<td><div align='left'>" . __("Reliability about annouced delays", "order") . "</div></td>"; echo "<td><div align='left'>" . Html::formatNumber($survey->getNotation($suppliers_id, "answer5")) . " / 10</div></td>"; echo "<tr>"; echo "<th colspan='4'> </th>"; echo "</tr>"; echo "<tr class='tab_bg_1 b'>"; echo "<td colspan='2'></td>"; echo "<td><div align='left'>" . __("Final supplier note", "order") . "</div></td>"; echo "<td><div align='left'>" . Html::formatNumber($total / $nb_order) . " / 10</div></td>"; echo "</tr>"; } echo "</table>"; echo "</div>"; }