function plugin_init_genericobject() { global $PLUGIN_HOOKS, $CFG_GLPI, $GO_BLACKLIST_FIELDS, $GO_FIELDS, $GENERICOBJECT_PDF_TYPES, $GO_LINKED_TYPES, $GO_READONLY_FIELDS; $GO_READONLY_FIELDS = array("is_helpdesk_visible", "comment"); $GO_BLACKLIST_FIELDS = array("itemtype", "table", "is_deleted", "id", "entities_id", "is_recursive", "is_template", "notepad", "template_name", "date_mod", "name", "is_helpdesk_visible", "comment"); $GO_LINKED_TYPES = array('Computer', 'Phone', 'Peripheral', 'Software', 'Monitor', 'Printer', 'NetworkEquipment'); $PLUGIN_HOOKS['csrf_compliant']['genericobject'] = true; $GENERICOBJECT_PDF_TYPES = array(); $plugin = new Plugin(); if ($plugin->isInstalled("genericobject") && $plugin->isActivated("genericobject")) { plugin_genericobject_includeCommonFields(); $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1; /* load changeprofile function */ $PLUGIN_HOOKS['change_profile']['genericobject'] = array('PluginGenericobjectProfile', 'changeProfile'); // Display a menu entry ? $PLUGIN_HOOKS['menu_entry']['genericobject'] = true; //Do not display icon if not using the genericobject plugin if (isset($_GET['id']) && $_GET['id'] != '' && strpos($_SERVER['REQUEST_URI'], Toolbox::getItemTypeFormURL("PluginGenericobjectType")) !== false) { $url = '/plugins/genericobject/index.php'; $type = new PluginGenericobjectType(); $type->getFromDB($_GET['id']); if ($type->fields['is_active']) { $url .= '?itemtypes_id=' . $_GET['id']; $image = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/stats_item.png' title=\"" . __("Go to objects list", "genericobject") . "\" alt=\"" . __("Go to objects list", "genericobject") . "\">"; $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links'][$image] = $url; } } $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['add'] = Toolbox::getItemTypeFormURL('PluginGenericobjectType', false); $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['search'] = Toolbox::getItemTypeSearchURL('PluginGenericobjectType', false); // Config page if (Session::haveRight('config', 'w')) { $PLUGIN_HOOKS['submenu_entry']['genericobject']['config'] = 'front/type.php'; $PLUGIN_HOOKS['config_page']['genericobject'] = 'front/type.php'; $PLUGIN_HOOKS['submenu_entry']['genericobject']['add']['type'] = 'front/type.form.php'; $PLUGIN_HOOKS['submenu_entry']['genericobject']['search']['type'] = 'front/type.php'; } $PLUGIN_HOOKS['assign_to_ticket']['genericobject'] = true; $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1; $PLUGIN_HOOKS['post_init']['genericobject'] = 'plugin_post_init_genericobject'; $PLUGIN_HOOKS['plugin_datainjection_populate']['genericobject'] = "plugin_datainjection_populate_genericobject"; } }
function plugin_init_genericobject() { global $PLUGIN_HOOKS, $CFG_GLPI, $GO_BLACKLIST_FIELDS, $GO_FIELDS, $GENERICOBJECT_PDF_TYPES, $GO_LINKED_TYPES, $GO_READONLY_FIELDS, $LOADED_PLUGINS; include_once GLPI_ROOT . '/plugins/genericobject/inc/profile.class.php'; PluginGenericobjectProfile::reloadProfileRights(); $GO_READONLY_FIELDS = array("is_helpdesk_visible", "comment"); $GO_BLACKLIST_FIELDS = array("itemtype", "table", "is_deleted", "id", "entities_id", "is_recursive", "is_template", "notepad", "template_name", "date_mod", "name", "is_helpdesk_visible", "comment"); $GO_LINKED_TYPES = array('Computer', 'Phone', 'Peripheral', 'Software', 'Monitor', 'Printer', 'NetworkEquipment'); $PLUGIN_HOOKS['csrf_compliant']['genericobject'] = true; $GENERICOBJECT_PDF_TYPES = array(); $plugin = new Plugin(); if ($plugin->isInstalled("genericobject") && $plugin->isActivated("genericobject")) { plugin_genericobject_includeCommonFields(); $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1; // add css styles $PLUGIN_HOOKS['add_css']['genericobject'] = array("css/styles.css"); // Display a menu entry ? $PLUGIN_HOOKS['menu_toadd']['genericobject'] = array('config' => 'PluginGenericobjectType', 'assets' => 'PluginGenericobjectObject'); // Ensure GLPI does correctly load menu entries for each activated objects // TODO: it could be better to check existence of those entries before unsetting the glpimenu // session in order to trigger rebuild. unset($_SESSION['glpimenu']); // Config page /*if (Session::haveRight('config', READ)) { $PLUGIN_HOOKS['config_page']['genericobject'] = 'front/type.php'; $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['add'] = Toolbox::getItemTypeFormURL('PluginGenericobjectType', false); $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['search'] = Toolbox::getItemTypeSearchURL('PluginGenericobjectType', false); }*/ $PLUGIN_HOOKS['assign_to_ticket']['genericobject'] = true; $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1; $PLUGIN_HOOKS['post_init']['genericobject'] = 'plugin_post_init_genericobject'; $PLUGIN_HOOKS['plugin_datainjection_populate']['genericobject'] = "plugin_datainjection_populate_genericobject"; } }
function showForm($id, $options = array(), $previsualisation = false) { global $DB; if ($previsualisation) { $canedit = true; $this->getEmpty(); } else { if ($id > 0) { $this->check($id, 'r'); } else { // Create item $this->check(-1, 'w'); $this->getEmpty(); } $this->showTabs($options); $canedit = $this->can($id, 'w'); } if (isset($options['withtemplate']) && $options['withtemplate'] == 2) { $template = "newcomp"; $date = sprintf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"])); } else { if (isset($options['withtemplate']) && $options['withtemplate'] == 1) { $template = "newtemplate"; $date = sprintf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"])); } else { $date = sprintf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"])); $template = false; } } $this->fields['id'] = $id; $this->showFormHeader($options); if ($previsualisation) { echo "<tr><th colspan='4'>" . __("Object preview", "genericobject") . ": "; $itemtype = $this->objecttype->fields['itemtype']; echo $itemtype::getTypeName(); echo "</th></tr>"; } //Reset fields definition only to keep the itemtype ones $GO_FIELDS = array(); plugin_genericobject_includeCommonFields(true); PluginGenericobjectType::includeConstants($this->getObjectTypeName(), true); foreach (PluginGenericobjectSingletonObjectField::getInstance($this->objecttype->fields['itemtype']) as $field => $description) { $this->displayField($canedit, $field, $this->fields[$field], $template, $description); } $this->closeColumn(); if (!$this->isNewID($id)) { echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' class='center'>" . $date; if (!$template && !empty($this->fields['template_name'])) { echo "<span class='small_space'>(" . __("Template name") . " : " . $this->fields['template_name'] . ")</span>"; } echo "</td></tr>"; } if (!$previsualisation) { $this->showFormButtons($options); echo "<div id='tabcontent'></div>"; echo "<script type='text/javascript'>loadDefaultTab();</script>"; } else { echo "</table></div>"; Html::closeForm(); } }
/** * * Displat all fields present in DB for an itemtype * @param $id the itemtype's id */ public static function showObjectFieldsForm($id) { global $DB, $GO_BLACKLIST_FIELDS, $GO_READONLY_FIELDS, $GO_FIELDS, $CFG_GLPI; $url = Toolbox::getItemTypeFormURL(__CLASS__); $object_type = new PluginGenericobjectType(); $object_type->getFromDB($id); $itemtype = $object_type->fields['itemtype']; $fields_in_db = PluginGenericobjectSingletonObjectField::getInstance($itemtype); $used_fields = array(); //Reset fields definition only to keep the itemtype ones $GO_FIELDS = array(); plugin_genericobject_includeCommonFields(true); //ToolBox::logDebug(PluginGenericobjectSingletonObjectField::$_dbfields); PluginGenericobjectType::includeConstants($object_type->fields['name'], true); self::addReadOnlyFields($object_type); foreach ($GO_BLACKLIST_FIELDS as $autofield) { if (!in_array($autofield, $used_fields)) { $used_fields[$autofield] = $autofield; } } echo "<div class='center'>"; echo "<form name='fieldslist' method='POST' action='{$url}'>"; echo "<table class='tab_cadre_fixe' >"; echo "<input type='hidden' name='id' value='{$id}'>"; echo "<tr class='tab_bg_1'><th colspan='7'>"; echo __("Fields associated with the object", "genericobject") . " : "; echo $itemtype::getTypeName(); echo "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th width='10'></th>"; echo "<th>" . __("Label", "genericobject") . "</th>"; echo "<th>" . __("Name in DB", "genericobject") . "</th>"; echo "<th width='10'></th>"; echo "<th width='10'></th>"; echo "</tr>"; $total = count($fields_in_db); $global_index = $index = 1; foreach ($fields_in_db as $field => $value) { self::displayFieldDefinition($url, $itemtype, $field, $index, $global_index == $total); //All backlisted fields cannot be moved, and are listed first if (!in_array($field, $GO_READONLY_FIELDS)) { $index++; } $table = getTableNameForForeignKeyField($field); $used_fields[$field] = $field; $global_index++; } echo "</table>"; Html::openArrowMassives('fieldslist', true); Html::closeArrowMassives(array('delete' => __("Delete permanently"))); echo "<table class='tab_cadre genericobject_fields add_new'>"; echo "<tr class='tab_bg_1'>"; echo "<td class='label'>" . __("Add new field", "genericobject") . "</td>"; echo "<td align='left' class='dropdown'>"; self::dropdownFields("new_field", $itemtype, $used_fields); echo "</td>"; echo "<td>"; echo "<input type='submit' name='add_field' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; }
/** * * Displat all fields present in DB for an itemtype * @param $id the itemtype's id */ public static function showObjectFieldsForm($id) { global $DB, $GO_BLACKLIST_FIELDS, $GO_READONLY_FIELDS, $GO_FIELDS, $CFG_GLPI; $url = Toolbox::getItemTypeFormURL(__CLASS__); $object_type = new PluginGenericobjectType(); $object_type->getFromDB($id); $itemtype = $object_type->fields['itemtype']; $fields_in_db = PluginGenericobjectSingletonObjectField::getInstance($itemtype); $used_fields = array(); //Reset fields definition only to keep the itemtype ones $GO_FIELDS = array(); plugin_genericobject_includeCommonFields(true); $file = GLPI_ROOT . "/plugins/genericobject/fields/constants/" . $object_type->fields['name'] . ".constant.php"; if (file_exists($file)) { include $file; } PluginGenericobjectType::includeConstants($itemtype, true); foreach ($GO_BLACKLIST_FIELDS as $autofield) { if (!in_array($autofield, $used_fields)) { $used_fields[$autofield] = $autofield; } } echo "<div class='center'>"; echo "<form name='fieldslist' method='POST' action='{$url}'>"; echo "<table class='tab_cadre_fixe' >"; echo "<input type='hidden' name='id' value='{$id}'>"; echo "<tr class='tab_bg_1'><th colspan='7'>"; echo __("Fields associated with the object", "genericobject") . " : "; echo $itemtype::getTypeName(); echo "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th width='10'></th>"; echo "<th>" . __("Label", "genericobject") . "</th>"; echo "<th>" . __("Name in DB", "genericobject") . "</th>"; echo "<th width='10'></th>"; echo "<th width='10'></th>"; echo "</tr>"; $total = count($fields_in_db); $global_index = $index = 1; foreach ($fields_in_db as $field => $value) { self::displayFieldDefinition($url, $itemtype, $field, $index, $global_index == $total); //All backlisted fields cannot be moved, and are listed first if (!in_array($field, $GO_READONLY_FIELDS)) { $index++; } //If it's a plugin dropdowns, get it's real name //(it may not be the one from the DB, in case it's a global field) $table = getTableNameForForeignKeyField($field); /*if ($table != '' && isPluginItemType(getItemTypeForTable($table))) { $classname = getItemTypeForTable($table); $class = new $classname(); $used_fields[$class->getFieldName()] = $class->getFieldName(); } else {*/ $used_fields[$field] = $field; //} $global_index++; } echo "</table>"; Html::openArrowMassives('fieldslist', true); Html::closeArrowMassives(array('delete' => __("Delete permanently"))); echo "<table class='tab_cadre'>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __("Add new field", "genericobject") . "</td>"; echo "<td align='left'>"; self::dropdownFields("new_field", $itemtype, $used_fields); echo "</td>"; echo "<td>"; echo "<input type='submit' name='add_field' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; }
function plugin_init_genericobject() { global $PLUGIN_HOOKS, $CFG_GLPI, $GO_BLACKLIST_FIELDS, $GO_FIELDS, $GENERICOBJECT_PDF_TYPES, $GO_LINKED_TYPES, $GO_READONLY_FIELDS, $LOADED_PLUGINS; $GO_READONLY_FIELDS = array("is_helpdesk_visible", "comment"); $GO_BLACKLIST_FIELDS = array("itemtype", "table", "is_deleted", "id", "entities_id", "is_recursive", "is_template", "notepad", "template_name", "date_mod", "name", "is_helpdesk_visible", "comment", "date_creation"); $GO_LINKED_TYPES = array('Computer', 'Phone', 'Peripheral', 'Software', 'Monitor', 'Printer', 'NetworkEquipment'); $PLUGIN_HOOKS['csrf_compliant']['genericobject'] = true; $GENERICOBJECT_PDF_TYPES = array(); $plugin = new Plugin(); if ($plugin->isInstalled("genericobject") && $plugin->isActivated("genericobject") && isset($_SESSION['glpiactiveprofile'])) { $PLUGIN_HOOKS['change_profile']['genericobject'] = array('PluginGenericobjectProfile', 'changeProfile'); plugin_genericobject_includeCommonFields(); $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1; // add css styles $PLUGIN_HOOKS['add_css']['genericobject'] = array("css/styles.css"); // Display a menu entry ? $PLUGIN_HOOKS['menu_toadd']['genericobject'] = array('config' => 'PluginGenericobjectType', 'assets' => 'PluginGenericobjectObject'); // Config page if (Session::haveRight('config', READ)) { $PLUGIN_HOOKS['config_page']['genericobject'] = 'front/type.php'; } $PLUGIN_HOOKS['assign_to_ticket']['genericobject'] = true; $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1; $PLUGIN_HOOKS['post_init']['genericobject'] = 'plugin_post_init_genericobject'; $PLUGIN_HOOKS['plugin_datainjection_populate']['genericobject'] = "plugin_datainjection_populate_genericobject"; } }
function plugin_init_genericobject() { global $PLUGIN_HOOKS, $CFG_GLPI, $GO_BLACKLIST_FIELDS, $GO_FIELDS, $GENERICOBJECT_PDF_TYPES, $GO_LINKED_TYPES, $GO_READONLY_FIELDS, $LOADED_PLUGINS; include_once(GLPI_ROOT.'/plugins/genericobject/inc/profile.class.php'); PluginGenericobjectProfile::reloadProfileRights(); $GO_READONLY_FIELDS = array ("is_helpdesk_visible", "comment"); $GO_BLACKLIST_FIELDS = array ("itemtype", "table", "is_deleted", "id", "entities_id", "is_recursive", "is_template", "notepad", "template_name", "date_mod", "name", "is_helpdesk_visible", "comment"); $GO_LINKED_TYPES = array ('Computer', 'Phone', 'Peripheral', 'Software', 'Monitor', 'Printer', 'NetworkEquipment'); $PLUGIN_HOOKS['csrf_compliant']['genericobject'] = true; $GENERICOBJECT_PDF_TYPES = array (); $plugin = new Plugin(); if ($plugin->isInstalled("genericobject") && $plugin->isActivated("genericobject")) { plugin_genericobject_includeCommonFields(); $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1; // add css styles $PLUGIN_HOOKS['add_css']['genericobject'] = array( "css/styles.css" ); // Display a menu entry ? $PLUGIN_HOOKS['menu_toadd']['genericobject'] = array( 'config' => 'PluginGenericobjectType', 'assets' => 'PluginGenericobjectObject' ); // Ensure GLPI does correctly load menu entries for each activated objects // TODO: it could be better to check existence of those entries before unsetting the glpimenu // session in order to trigger rebuild. unset($_SESSION['glpimenu']); //Do not display icon if not using the genericobject plugin // if (isset($_GET['id']) && $_GET['id'] != '' // && strpos($_SERVER['REQUEST_URI'], // Toolbox::getItemTypeFormURL("PluginGenericobjectType")) !== false) { // $url = '/plugins/genericobject/index.php'; // $type = new PluginGenericobjectType(); // $type->getFromDB($_GET['id']); // if ($type->fields['is_active']) { // $url.= '?itemtypes_id='.$_GET['id']; // $image = "<img src='".$CFG_GLPI["root_doc"]."/pics/stats_item.png' title=\"". // __("Go to objects list", "genericobject"). // "\" alt=\"".__("Go to objects list", "genericobject")."\">"; // $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links'][$image] // = $url; // } // } $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['add'] = Toolbox::getItemTypeFormURL('PluginGenericobjectType', false); $PLUGIN_HOOKS['submenu_entry']['genericobject']['options']['type']['links']['search'] = Toolbox::getItemTypeSearchURL('PluginGenericobjectType', false); // Config page if (Session::haveRight('config', READ)) { $PLUGIN_HOOKS['config_page']['genericobject'] = 'front/type.php'; } $PLUGIN_HOOKS['assign_to_ticket']['genericobject'] = true; $PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1; $PLUGIN_HOOKS['post_init']['genericobject'] = 'plugin_post_init_genericobject'; $PLUGIN_HOOKS['plugin_datainjection_populate']['genericobject'] = "plugin_datainjection_populate_genericobject"; } }