public static function uninstall() { // Define DB tables $table_targets = getTableForItemType('NotificationTarget'); $table_notification = getTableForItemType('Notification'); $table_translations = getTableForItemType('NotificationTemplateTranslation'); $table_templates = getTableForItemType('NotificationTemplate'); // Delete translations $query = 'DELETE FROM `' . $table_translations . '` WHERE `notificationtemplates_id` IN ( SELECT `id` FROM ' . $table_templates . ' WHERE `itemtype` = "PluginFormcreatorFormanswer")'; $GLOBALS['DB']->query($query); // Delete notification templates $query = 'DELETE FROM `' . $table_templates . '` WHERE `itemtype` = "PluginFormcreatorFormanswer"'; $GLOBALS['DB']->query($query); // Delete notification targets $query = 'DELETE FROM `' . $table_targets . '` WHERE `notifications_id` IN ( SELECT `id` FROM ' . $table_notification . ' WHERE `itemtype` = "PluginFormcreatorFormanswer")'; $GLOBALS['DB']->query($query); // Delete notifications $query = 'DELETE FROM `' . $table_notification . '` WHERE `itemtype` = "PluginFormcreatorFormanswer"'; $GLOBALS['DB']->query($query); }
function showAllItems($myname, $value_type = 0, $value = 0, $entity_restrict = -1) { global $DB, $CFG_GLPI; $types = array('Computer', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer'); $rand = mt_rand(); echo "<table border='0'><tr><td>\n"; echo "<select name='type' id='item_type{$rand}'>\n"; echo "<option value='0;0'>" . Dropdown::EMPTY_VALUE . "</option>\n"; foreach ($types as $type => $label) { $item = new $label(); echo "<option value='" . $label . ";" . getTableForItemType($label . "Type") . "'>" . $item->getTypeName() . "</option>\n"; } echo "</select>"; $params = array('typetable' => '__VALUE__', 'value' => $value, 'myname' => $myname, 'entity_restrict' => $entity_restrict); Ajax::updateItemOnSelectEvent("item_type{$rand}", "show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/archires/ajax/dropdownAllItems.php", $params); echo "</td><td>\n"; echo "<span id='show_{$myname}{$rand}'> </span>\n"; echo "</td></tr></table>\n"; if ($value > 0) { echo "<script type='text/javascript' >\n"; echo "document.getElementById('item_type{$rand}').value='" . $value_type . "';"; echo "</script>\n"; $params["typetable"] = $value_type; Ajax::updateItem("show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/archires/ajax/dropdownAllItems.php", $params); } return $rand; }
static function uninstall() { global $DB; $table = getTableForItemType(__CLASS__); $DB->query("DROP TABLE IF EXISTS`{$table}`"); return true; }
function plugin_tag_getAddSearchOptions($itemtype) { $sopt = array(); if (!Session::haveRight("itilcategory", READ)) { return array(); } if (strpos($itemtype, 'Plugin') !== false && strpos($itemtype, 'CronTask') !== false) { return array(); } if ($itemtype === 'PluginTagTag' || $itemtype === 'TicketTemplate' || strpos($itemtype, 'PluginPrintercounters') !== false) { return array(); } $rng1 = 10500; //$sopt[strtolower($itemtype)] = ''; //self::getTypeName(2); $sopt[$rng1]['table'] = getTableForItemType('PluginTagTag'); $sopt[$rng1]['field'] = 'name'; $sopt[$rng1]['name'] = _n('Tag', 'Tag', 2, 'tag'); $sopt[$rng1]['datatype'] = 'string'; $sopt[$rng1]['searchtype'] = "contains"; $sopt[$rng1]['massiveaction'] = false; $sopt[$rng1]['forcegroupby'] = true; $sopt[$rng1]['usehaving'] = true; $sopt[$rng1]['joinparams'] = array('beforejoin' => array('table' => 'glpi_plugin_tag_tagitems', 'joinparams' => array('jointype' => "itemtype_item"))); //array('jointype' => "itemtype_item"); return $sopt; }
function getSqlSubRequest($itemtype, $loc, $obj) { $table = getTableForItemType($itemtype); $models_id = getForeignKeyFieldForTable(getTableForItemType($itemtype . 'Model')); $types_id = getForeignKeyFieldForTable(getTableForItemType($itemtype . 'Type')); $fields = array('name' => 'name', 'serial' => 'serial', 'otherserial' => 'otherserial', $models_id => 'models_id', $types_id => 'types_id'); $query_where = "SELECT '{$itemtype}' AS itemtype,\n `{$table}`.`id` AS items_id,\n `{$table}`.`locations_id`"; foreach ($fields as $field => $alias) { if ($obj->isField($field)) { $query_where .= ", `{$table}`.`{$field}` AS {$alias}"; } else { $query_where .= ", '' AS {$alias}"; } } $query_where .= " FROM `{$table}` "; if ($obj->isEntityAssign()) { $query_where .= getEntitiesRestrictRequest('WHERE', "{$table}"); } else { $query_where .= 'WHERE 1'; } if ($obj->maybeTemplate()) { $query_where .= " AND `is_template`='0'"; } if ($obj->maybeDeleted()) { $query_where .= " AND `is_deleted`='0'"; } $query_where .= $loc->getSqlCriteriasRestriction(); return $query_where; }
static function uninstall() { global $DB; //Old table $DB->query("DROP TABLE IF EXISTS `glpi_dropdown_plugin_order_deliverystate`") or die($DB->error()); //New table $DB->query("DROP TABLE IF EXISTS `" . getTableForItemType(__CLASS__) . "`") or die($DB->error()); }
static function uninstall() { global $DB; $displayPreference = new DisplayPreference(); $displayPreference->deleteByCriteria(array('itemtype' => __CLASS__)); $table = getTableForItemType(__CLASS__); $DB->query("DROP TABLE IF EXISTS `{$table}`"); }
static function uninstall() { global $DB; //Old table name $DB->query("DROP TABLE IF EXISTS `glpi_dropdown_plugin_order_payment`") or die($DB->error()); //Current table name $DB->query("DROP TABLE IF EXISTS `" . getTableForItemType(__CLASS__) . "`") or die($DB->error()); }
/** * Update from 0.78 to 0.78.1 * * @return bool for success (will die for most error) */ function update078to0781() { global $DB, $migration; $updateresult = true; $migration->displayTitle(sprintf(__('Update to %s'), '0.78.1')); $migration->setVersion('0.78.1'); //TRANS: %s is 'Clean reservation entity link' $migration->displayMessage(sprintf(__('Data migration - %s'), 'Clean reservation entity link')); // Updating schema $entities = getAllDatasFromTable('glpi_entities'); $entities[0] = "Root"; $query = "SELECT DISTINCT `itemtype` FROM `glpi_reservationitems`"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_assoc($result)) { $itemtable = getTableForItemType($data['itemtype']); // ajout d'un contrôle pour voir si la table existe ( cas migration plugin non fait) if (!TableExists($itemtable)) { $migration->displayWarning("*** Skip : no table {$itemtable} ***", true); continue; } $do_recursive = false; if (FieldExists($itemtable, 'is_recursive', false)) { $do_recursive = true; } foreach ($entities as $entID => $val) { if ($do_recursive) { // Non recursive ones $query3 = "UPDATE `glpi_reservationitems`\n SET `entities_id`={$entID}, `is_recursive`=0\n WHERE `itemtype`='" . $data['itemtype'] . "'\n AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n WHERE `entities_id`={$entID} AND `is_recursive`=0)"; $DB->queryOrDie($query3, "0.78.1 update entities_id and is_recursive=0 in glpi_reservationitems for " . $data['itemtype']); // Recursive ones $query3 = "UPDATE `glpi_reservationitems`\n SET `entities_id`={$entID}, `is_recursive`=1\n WHERE `itemtype`='" . $data['itemtype'] . "'\n AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n WHERE `entities_id`={$entID} AND `is_recursive`=1)"; $DB->queryOrDie($query3, "0.78.1 update entities_id and is_recursive=1 in glpi_reservationitems for " . $data['itemtype']); } else { $query3 = "UPDATE `glpi_reservationitems`\n SET `entities_id`={$entID}\n WHERE `itemtype`='" . $data['itemtype'] . "'\n AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n WHERE `entities_id`={$entID})"; $DB->queryOrDie($query3, "0.78.1 update entities_id in glpi_reservationitems for " . $data['itemtype']); } } } } } $query = "ALTER TABLE `glpi_tickets`\n CHANGE `global_validation` `global_validation` VARCHAR(255) DEFAULT 'none'"; $DB->query($query) or die("0.78.1 change ticket global_validation default state"); $query = "UPDATE `glpi_tickets`\n SET `global_validation`='none'\n WHERE `id` NOT IN (SELECT DISTINCT `tickets_id`\n FROM `glpi_ticketvalidations`)"; $DB->query($query) or die("0.78.1 update ticket global_validation state"); if (!FieldExists('glpi_knowbaseitemcategories', 'entities_id', false)) { $query = "ALTER TABLE `glpi_knowbaseitemcategories`\n ADD `entities_id` INT NOT NULL DEFAULT '0' AFTER `id`,\n ADD `is_recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `entities_id`,\n ADD INDEX `entities_id` (`entities_id`),ADD INDEX `is_recursive` (`is_recursive`)"; $DB->queryOrDie($query, "0.78.1 add entities_id,is_recursive in glpi_knowbaseitemcategories"); // Set existing categories recursive global $query = "UPDATE `glpi_knowbaseitemcategories` SET `is_recursive` = '1'"; $DB->queryOrDie($query, "0.78.1 set value of is_recursive in glpi_knowbaseitemcategories"); $query = "ALTER TABLE `glpi_knowbaseitemcategories` DROP INDEX `unicity` ,\n ADD UNIQUE `unicity` ( `entities_id`, `knowbaseitemcategories_id` , `name` ) "; $DB->queryOrDie($query, "0.78.1 update unicity index on glpi_knowbaseitemcategories"); } // must always be at the end (only for end message) $migration->executeMigration(); return $updateresult; }
public function getAnswer() { $value = $this->getValue(); if ($this->fields['values'] == 'User') { return getUserName($value); } else { return Dropdown::getDropdownName(getTableForItemType($this->fields['values']), $value); } }
static function uninstall() { global $DB; $table = getTableForItemType(__CLASS__); if (TableExists($table)) { $query = "DROP TABLE IF EXISTS `{$table}`"; $DB->query($query) or die($DB->error()); } }
/** * Singleton to store DB fields definition * * @since 2.1.0 * @param itemtype itemtype to query * @param reload reload db fields configuration from DB * * @return an array which contains DB fields definition */ public static function getInstance($itemtype, $reload = false) { global $DB; if (!isset(self::$_dbfields[$itemtype]) || $reload) { self::$_dbfields[$itemtype] = $DB->list_fields(getTableForItemType($itemtype)); } else { } return self::$_dbfields[$itemtype]; }
/** * * Get a preference for an user * @param unknown_type preference field to get * @param unknown_type user ID * @return preference value or 0 */ static function checkPreferenceValue($field, $users_id = 0) { $data = getAllDatasFromTable(getTableForItemType(__CLASS__), "`users_id`='{$users_id}'"); if (!empty($data)) { $first = array_pop($data); return $first[$field]; } else { return 0; } }
/** * Function to update Printer * * @param array $a_inventory data fron agent inventory * @param id $items_id id of the printer * * @return nothing */ function updatePrinter($a_inventory, $items_id) { global $DB; $printer = new Printer(); $pfPrinter = new PluginFusioninventoryPrinter(); $printer->getFromDB($items_id); if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = $printer->fields['entities_id']; } if (!isset($_SESSION['glpiactiveentities'])) { $_SESSION['glpiactiveentities'] = array($printer->fields['entities_id']); } if (!isset($_SESSION['glpiactive_entity'])) { $_SESSION['glpiactive_entity'] = $printer->fields['entities_id']; } // * Printer $db_printer = $printer->fields; $a_lockable = PluginFusioninventoryLock::getLockFields('glpi_printers', $items_id); $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['Printer'], $db_printer, $a_lockable); $a_inventory['Printer'] = $a_ret[0]; $input = $a_inventory['Printer']; $input['id'] = $items_id; $printer->update($input); // * Printer fusion (ext) $db_printer = array(); $query = "SELECT *\n FROM `" . getTableForItemType("PluginFusioninventoryPrinter") . "`\n WHERE `printers_id` = '{$items_id}'"; $result = $DB->query($query); while ($data = $DB->fetch_assoc($result)) { foreach ($data as $key => $value) { $db_printer[$key] = Toolbox::addslashes_deep($value); } } if (count($db_printer) == '0') { // Add $a_inventory['PluginFusioninventoryPrinter']['printers_id'] = $items_id; $pfPrinter->add($a_inventory['PluginFusioninventoryPrinter']); } else { // Update $idtmp = $db_printer['id']; unset($db_printer['id']); unset($db_printer['printers_id']); unset($db_printer['plugin_fusioninventory_configsecurities_id']); $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['PluginFusioninventoryPrinter'], $db_printer); $a_inventory['PluginFusioninventoryPrinter'] = $a_ret[0]; $input = $a_inventory['PluginFusioninventoryPrinter']; $input['id'] = $idtmp; $pfPrinter->update($input); } // * Ports $this->importPorts($a_inventory, $items_id); // Page counters $this->importPageCounters($a_inventory['pagecounters'], $items_id); // Cartridges $this->importCartridges($a_inventory['cartridge'], $items_id); }
public static function uninstall() { $query = "DELETE FROM glpi_logs WHERE itemtype_link='" . __CLASS__ . "'"; $GLOBALS['DB']->query($query); $query = "DELETE FROM glpi_bookmarks WHERE itemtype='" . __CLASS__ . "'"; $GLOBALS['DB']->query($query); $query = "DELETE FROM glpi_displaypreferences WHERE itemtype='" . __CLASS__ . "' OR num=10500"; $GLOBALS['DB']->query($query); $query = "DROP TABLE IF EXISTS `" . getTableForItemType(__CLASS__) . "`"; return $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); }
/** * Initialize all classes and generic variables of the plugin */ function plugin_init_formcreator() { global $PLUGIN_HOOKS; // Set the plugin CSRF compliance (required since GLPI 0.84) $PLUGIN_HOOKS['csrf_compliant']['formcreator'] = true; $plugin = new Plugin(); if (isset($_SESSION['glpiID']) && $plugin->isInstalled('formcreator') && $plugin->isActivated('formcreator')) { // Massive Action definition $PLUGIN_HOOKS['use_massive_action']['formcreator'] = 1; // If user have acces to one form or more, add link $form_table = getTableForItemType('PluginFormcreatorForm'); $table_fp = getTableForItemType('PluginFormcreatorFormprofiles'); $where = getEntitiesRestrictRequest("", $form_table, "", "", true, false); $query = "SELECT COUNT({$form_table}.id)\n FROM {$form_table}\n WHERE {$form_table}.`is_active` = 1\n AND {$form_table}.`is_deleted` = 0\n AND {$form_table}.`helpdesk_home` = 1\n AND ({$form_table}.`language` = '{$_SESSION['glpilanguage']}' OR {$form_table}.`language` = '')\n AND {$where}\n AND ({$form_table}.`access_rights` != " . PluginFormcreatorForm::ACCESS_RESTRICTED . " OR {$form_table}.`id` IN (\n SELECT plugin_formcreator_forms_id\n FROM {$table_fp}\n WHERE plugin_formcreator_profiles_id = " . (int) $_SESSION['glpiactiveprofile']['id'] . "))"; $result = $GLOBALS['DB']->query($query); list($nb) = $GLOBALS['DB']->fetch_array($result); if ($nb > 0) { $PLUGIN_HOOKS['menu_toadd']['formcreator']['helpdesk'] = 'PluginFormcreatorFormlist'; } if (strpos($_SERVER['REQUEST_URI'], "plugins/formcreator") !== false || strpos($_SERVER['REQUEST_URI'], "central.php") !== false || isset($_SESSION['glpiactiveprofile']) && $_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') { // Add specific CSS $PLUGIN_HOOKS['add_css']['formcreator'][] = "css/styles.css"; $PLUGIN_HOOKS['add_css']['formcreator'][] = 'lib/pqselect/pqselect.min.css'; $PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'lib/pqselect/pqselect.min.js'; // Add specific JavaScript $PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'scripts/forms-validation.js.php'; $PLUGIN_HOOKS['add_javascript']['formcreator'][] = 'scripts/scripts.js.php'; } // Add a link in the main menu plugins for technician and admin panel $PLUGIN_HOOKS['menu_entry']['formcreator'] = 'front/formlist.php'; // Config page $plugin = new Plugin(); $links = array(); if (Session::haveRight('entity', UPDATE)) { $PLUGIN_HOOKS['config_page']['formcreator'] = 'front/form.php'; $PLUGIN_HOOKS['menu_toadd']['formcreator']['admin'] = 'PluginFormcreatorForm'; $links['config'] = '/plugins/formcreator/front/form.php'; $links['add'] = '/plugins/formcreator/front/form.form.php'; } $img = '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/check.png" title="' . __('Forms waiting for validation', 'formcreator') . '" alt="Waiting forms list" />'; $links[$img] = '/plugins/formcreator/front/formanswer.php'; // Set options for pages (title, links, buttons...) $links['search'] = '/plugins/formcreator/front/formlist.php'; $PLUGIN_HOOKS['submenu_entry']['formcreator']['options'] = array('config' => array('title' => __('Setup'), 'page' => '/plugins/formcreator/front/form.php', 'links' => $links), 'options' => array('title' => _n('Form', 'Forms', 2, 'formcreator'), 'links' => $links)); // Load field class and all its method to manage fields Plugin::registerClass('PluginFormcreatorFields'); // Notification Plugin::registerClass('PluginFormcreatorFormanswer', array('notificationtemplates_types' => true)); if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE && isset($_SESSION['glpimenu'])) { unset($_SESSION['glpimenu']); } } }
/** * Function to update NetworkEquipment * * @param array $a_inventory data fron agent inventory * @param id $items_id id of the networkequipment * * @return nothing */ function updateNetworkEquipment($a_inventory, $items_id) { global $DB; $networkEquipment = new NetworkEquipment(); $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment(); $networkEquipment->getFromDB($items_id); if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = $networkEquipment->fields['entities_id']; } if (!isset($_SESSION['glpiactiveentities'])) { $_SESSION['glpiactiveentities'] = array($networkEquipment->fields['entities_id']); } if (!isset($_SESSION['glpiactive_entity'])) { $_SESSION['glpiactive_entity'] = $networkEquipment->fields['entities_id']; } // * NetworkEquipment $db_networkequipment = $networkEquipment->fields; $a_lockable = PluginFusioninventoryLock::getLockFields('glpi_networkequipments', $items_id); $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['NetworkEquipment'], $db_networkequipment, $a_lockable); $a_inventory['NetworkEquipment'] = $a_ret[0]; $mac = $a_inventory['NetworkEquipment']['mac']; unset($a_inventory['NetworkEquipment']['mac']); $input = $a_inventory['NetworkEquipment']; $input['id'] = $items_id; $networkEquipment->update($input); $this->internalPorts($a_inventory['internalport'], $items_id, $mac, 'Internal'); // * NetworkEquipment fusion (ext) $db_networkequipment = array(); $query = "SELECT *\n FROM `" . getTableForItemType("PluginFusioninventoryNetworkEquipment") . "`\n WHERE `networkequipments_id` = '{$items_id}'"; $result = $DB->query($query); while ($data = $DB->fetch_assoc($result)) { foreach ($data as $key => $value) { $db_networkequipment[$key] = Toolbox::addslashes_deep($value); } } if (count($db_networkequipment) == '0') { // Add $a_inventory['PluginFusioninventoryNetworkEquipment']['networkequipments_id'] = $items_id; $pfNetworkEquipment->add($a_inventory['PluginFusioninventoryNetworkEquipment']); } else { // Update $idtmp = $db_networkequipment['id']; unset($db_networkequipment['id']); unset($db_networkequipment['networkequipments_id']); unset($db_networkequipment['plugin_fusioninventory_configsecurities_id']); $a_ret = PluginFusioninventoryToolbox::checkLock($a_inventory['PluginFusioninventoryNetworkEquipment'], $db_networkequipment); $a_inventory['PluginFusioninventoryNetworkEquipment'] = $a_ret[0]; $input = $a_inventory['PluginFusioninventoryNetworkEquipment']; $input['id'] = $idtmp; $pfNetworkEquipment->update($input); } // * Ports $this->importPorts($a_inventory, $items_id); }
static function uninstall() { global $DB; $displayPreference = new DisplayPreference(); $displayPreference->deleteByCriteria(array('itemtype' => __CLASS__)); // Remove dropdowns localization $dropdownTranslation = new DropdownTranslation(); $dropdownTranslation->deleteByCriteria(array("itemtype = 'PluginSimcardSimcardSize'"), 1); $table = getTableForItemType(__CLASS__); $DB->query("DROP TABLE IF EXISTS `{$table}`"); }
static function pdfDevice(PluginPdfSimplePDF $pdf, Computer $computer) { global $DB; $devtypes = Item_Devices::getDeviceTypes(); $ID = $computer->getField('id'); if (!$computer->can($ID, 'r')) { return false; } $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . Toolbox::ucfirst(_n('Component', 'Components', 2)) . '</b>'); $pdf->setColumnsSize(3, 14, 42, 41); foreach ($devtypes as $itemtype) { $devicetypes = new $itemtype(); $specificities = $devicetypes->getSpecificities(); $specif_fields = array_keys($specificities); $specif_text = implode(',', $specif_fields); if (!empty($specif_text)) { $specif_text = " ," . $specif_text . " "; } $associated_type = str_replace('Item_', '', $itemtype); $linktable = getTableForItemType($itemtype); $fk = getForeignKeyFieldForTable(getTableForItemType($associated_type)); $query = "SELECT count(*) AS NB, `id`, `" . $fk . "`" . $specif_text . "\n FROM `" . $linktable . "`\n WHERE `items_id` = '" . $ID . "'\n AND `itemtype` = 'Computer'\n GROUP BY `" . $fk . "`" . $specif_text; $device = new $associated_type(); foreach ($DB->request($query) as $data) { if ($device->getFromDB($data[$fk])) { $spec = $device->getAdditionalFields(); $col4 = ''; if (count($spec)) { $colspan = 60 / count($spec); foreach ($spec as $i => $label) { if (isset($device->fields[$label["name"]]) && !empty($device->fields[$label["name"]])) { if ($label["type"] == "dropdownValue" && $device->fields[$label["name"]] != 0) { $table = getTableNameForForeignKeyField($label["name"]); $value = Dropdown::getDropdownName($table, $device->fields[$label["name"]]); $col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', Html::clean($value) . " "); } else { $value = $device->fields[$label["name"]]; $col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $value . " "); } } else { if (isset($device->fields[$label["name"] . "_default"]) && !empty($device->fields[$label["name"] . "_default"])) { $col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $device->fields[$label["name"] . "_default"] . " "); } } } } $pdf->displayLine($data['NB'], $device->getTypeName(), $device->getName(), $col4); } } } $pdf->displaySpace(); }
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item->getType() == 'Computer') { if (Session::haveRight('computer', READ)) { $a_nb = countElementsInTable(getTableForItemType("PluginFusioninventoryInventoryComputerStorage"), "`computers_id`='" . $item->getID() . "'"); if (count($a_nb) > 0) { // return self::createTabEntry(__('Storage', 'fusioninventory')); } } } return ''; }
static function uninstall() { global $DB; foreach (array('DisplayPreference', 'Bookmark') as $itemtype) { $item = new $itemtype(); $item->deleteByCriteria(array('itemtype' => __CLASS__)); } // Remove dropdowns localization $dropdownTranslation = new DropdownTranslation(); $dropdownTranslation->deleteByCriteria(array("itemtype = 'PluginSimcardSimcardType'"), 1); $table = getTableForItemType(__CLASS__); $DB->query("DROP TABLE IF EXISTS `{$table}`"); }
/** * Database table installation for the item type * * @param Migration $migration * @return boolean True on success */ public static function install(Migration $migration) { $obj = new self(); $table = $obj->getTable(); // Create new table if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); // Create questions table $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `plugin_formcreator_forms_id` int(11) NOT NULL,\n `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `order` int(11) NOT NULL DEFAULT '0'\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } else { /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `name`\n FROM `{$table}`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `' . $table . '` SET `name` = "' . plugin_formcreator_encode($line['name']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } // Migration from previous version => Remove useless target field if (FieldExists($table, 'plugin_formcreator_targets_id', false)) { $GLOBALS['DB']->query("ALTER TABLE `{$table}` DROP `plugin_formcreator_targets_id`;"); } // Migration from previous version => Rename "position" into "order" and start order from 1 instead of 0 if (FieldExists($table, 'position', false)) { $GLOBALS['DB']->query("ALTER TABLE `{$table}` CHANGE `position` `order` INT(11) NOT NULL DEFAULT '0';"); $GLOBALS['DB']->query("UPDATE `{$table}` SET `order` = `order` + 1;"); } // Migration from previous version => Update Question table, then create a "description" question from content if (FieldExists($table, 'content', false)) { $version = plugin_version_formcreator(); $migration = new Migration($version['version']); PluginFormcreatorQuestion::install($migration); $table_questions = getTableForItemType('PluginFormcreatorQuestion'); // Increment the order of questions which are in a section with a description $query = "UPDATE `{$table_questions}`\n SET `order` = `order` + 1\n WHERE `plugin_formcreator_sections_id` IN (\n SELECT `id`\n FROM {$table}\n WHERE `content` != ''\n );"; $GLOBALS['DB']->query($query); // Create description from content $query = "INSERT INTO `{$table_questions}` (`plugin_formcreator_sections_id`, `fieldtype`, `name`, `description`, `order`)\n SELECT `id`, 'description' AS fieldtype, CONCAT('Description ', `id`) AS name, `content`, 1 AS `order`\n FROM {$table}\n WHERE `content` != ''"; $GLOBALS['DB']->query($query); // Delete content column $GLOBALS['DB']->query("ALTER TABLE `{$table}` DROP `content`;"); } return true; }
function getSearchOptions() { $computer = new Computer(); $options = $computer->getSearchOptions(); $options['6000']['name'] = __('Static group', 'fusioninventory'); $options['6000']['table'] = getTableForItemType('PluginFusioninventoryDeployGroup'); $options['6000']['massiveaction'] = FALSE; $options['6000']['field'] = 'name'; $options['6000']['forcegroupby'] = true; $options['6000']['usehaving'] = true; $options['6000']['datatype'] = 'dropdown'; $options['6000']['joinparams'] = array('beforejoin' => array('table' => 'glpi_plugin_fusioninventory_deploygroups_staticdatas', 'joinparams' => array('jointype' => 'itemtype_item', 'specific_itemtype' => 'Computer'))); return $options; }
/** * @param $values * @param $add (true by default) * @param $rights array **/ function processAfterInsertOrUpdate($values, $add = true, $rights = array()) { if (isset($values['Computer']['id'])) { $class = "Item_" . get_parent_class($this); $item = new $class(); $foreign = getForeignKeyFieldForTable(getTableForItemType(get_parent_class($this))); if (!countElementsInTable($item->getTable(), "`{$foreign}`='" . $values[get_parent_class($this)]['id'] . "'\n AND `itemtype`='Computer'\n AND `items_id`='" . $values['Computer']['id'] . "'")) { $tmp[$foreign] = $values[get_parent_class($this)]['id']; $tmp['items_id'] = $values['Computer']['id']; $tmp['itemtype'] = 'Computer'; $item->add($tmp); } } }
function getSearchOptions() { $tab = parent::getSearchOptions(); $tab[4]['name'] = __('Content'); $tab[4]['field'] = 'content'; $tab[4]['table'] = $this->getTable(); $tab[4]['datatype'] = 'text'; $tab[4]['htmltext'] = true; $tab[3]['name'] = __('Task category'); $tab[3]['field'] = 'name'; $tab[3]['table'] = getTableForItemType('TaskCategory'); $tab[3]['datatype'] = 'dropdown'; return $tab; }
function plugin_genericobject_getDropdown() { $dropdowns = array(); $plugin = new Plugin(); if ($plugin->isActivated("genericobject")) { foreach (getAllDatasFromTable(getTableForItemType('PluginGenericobjectType'), "`is_active`='1'") as $itemtype) { foreach (PluginGenericobjectType::getDropdownForItemtype($itemtype['itemtype']) as $table) { $dropdown_itemtype = getItemTypeForTable($table); $dropdowns[$dropdown_itemtype] = $dropdown_itemtype::getTypeName(); } } } return $dropdowns; }
/** * @see CommonGLPI::getTabNameForItem() **/ function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate && $item->getType() == 'PluginFusioninventoryDeployGroup' && $item->fields['type'] == PluginFusioninventoryDeployGroup::STATIC_GROUP) { $tabs[1] = _n('Criterion', 'Criteria', 2); $count = countElementsInTable(getTableForItemType(__CLASS__), "`itemtype`='Computer'\n AND `plugin_fusioninventory_deploygroups_id`='" . $item->getID() . "'"); if ($_SESSION['glpishow_count_on_tabs']) { $tabs[2] = self::createTabEntry(_n('Associated item', 'Associated items', $count), $count); } else { $tabs[2] = _n('Associated item', 'Associated items', $count); } return $tabs; } return ''; }
function dropdown_getTypeName($class, $nb = 0) { global $GO_FIELDS; $fk = getForeignKeyFieldForTable(getTableForItemType($class)); $instance = new $class(); $options = PluginGenericobjectField::getFieldOptions($fk, $instance->linked_itemtype); $dropdown_type = isset($options['dropdown_type']) ? $options['dropdown_type'] : null; $label = $options['name']; if (!is_null($dropdown_type) and $dropdown_type === 'isolated') { $linked_itemtype_object = new $instance->linked_itemtype(); $label .= " (" . __($linked_itemtype_object::getTypeName(), 'genericobject') . ")"; } if ($label != '') { return $label; } else { return $class; } }
/** * @param $report * @param $name * @param $tableortype (default '') * @param $label (default '') * @param $condition (default '') **/ function __construct($report, $name, $tableortype = '', $label = '', $condition = '') { parent::__construct($report, $name, $name, $label); $this->condition = $condition; if (empty($tableortype)) { $this->table = getTableNameForForeignKeyField($name); } else { if (preg_match("/^glpi_/", $tableortype)) { $this->table = $tableortype; } else { if ($tableortype == NOT_AVAILABLE) { $this->table = NOT_AVAILABLE; } else { $this->table = getTableForItemType($tableortype); } } } }
/** * Update from 4.2.1 to 4.2.2 * * @return bool for success (will die for most error) * */ function update421to422() { global $DB; $migration = new Migration('422'); $query = "SELECT * FROM `glpi_plugin_positions_positions`"; $result_query = $DB->query($query); while ($data = $DB->fetch_array($result_query)) { if (!($itemclass = getAllDatasFromTable(getTableForItemType($data['itemtype']), "`id` = " . $data['items_id']))) { $query = "DELETE FROM `glpi_plugin_positions_positions` WHERE `items_id` =" . $data['items_id'] . " AND `itemtype` = '" . $data['itemtype'] . "'"; $DB->queryOrDie($query); continue; } $itemclass = reset($itemclass); $query = "UPDATE `glpi_plugin_positions_positions` SET `locations_id` = " . $itemclass['locations_id'] . " WHERE `items_id` =" . $data['items_id'] . " AND `itemtype` = '" . $data['itemtype'] . "'"; $DB->queryOrDie($query, "ADD fields locations_ids for glpi_plugin_positions_positions"); } $migration->executeMigration(); return true; }