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"; } }
You should have received a copy of the GNU General Public License along with Genericobject. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- @package genericobject @author the genericobject plugin team @copyright Copyright (c) 2010-2011 Order plugin team @license GPLv2+ http://www.gnu.org/licenses/gpl.txt @link https://forge.indepnet.net/projects/genericobject @link http://www.glpi-project.org/ @since 2009 ---------------------------------------------------------------------- */ include "../../../inc/includes.php"; if (isset($_POST["delete"])) { $type = new PluginGenericobjectType(); $type->getFromDB($_POST["id"]); $itemtype = $type->fields['itemtype']; PluginGenericobjectType::registerOneType($itemtype); foreach ($_POST["fields"] as $field => $value) { if ($type->can($_POST["id"], PURGE) && $value == 1 && PluginGenericobjectField::checkNecessaryFieldsDelete($itemtype, $field)) { PluginGenericobjectField::deleteField(getTableForItemType($itemtype), $field); Session::addMessageAfterRedirect(__("Field(s) deleted successfully", "genericobject"), true, INFO); } } } elseif (isset($_POST["add_field"])) { $type = new PluginGenericobjectType(); if ($_POST["new_field"] && $type->can($_POST["id"], UPDATE)) { $itemtype = $type->fields['itemtype']; PluginGenericobjectType::registerOneType($itemtype); PluginGenericobjectField::addNewField(getTableForItemType($itemtype), $_POST["new_field"]); Session::addMessageAfterRedirect(__("Field added successfully", "genericobject"));
@link https://forge.indepnet.net/projects/genericobject @link http://www.glpi-project.org/ @since 2009 ---------------------------------------------------------------------- */ include "../../../inc/includes.php"; if (!isset($_GET["id"])) { $_GET["id"] = ''; } $type = new PluginGenericobjectType(); $extraparams = array(); if (isset($_POST["select"]) && $_POST["select"] == "all") { $extraparams["selected"] = "checked"; } //Change fields order if (isset($_GET["action"])) { $type->getFromDB($_REQUEST["id"]); PluginGenericobjectType::registerOneType($type); PluginGenericobjectObject::changeFieldOrder($_GET["field"], $type->fields["itemtype"], $_GET["action"]); Html::back(); //Add a new itemtype } elseif (isset($_POST["add"])) { $new_id = $type->add($_POST); Html::redirect(Toolbox::getItemTypeFormURL('PluginGenericobjectType') . "?id={$new_id}"); //Update an existing itemtype } elseif (isset($_POST["update"])) { if (isset($_POST['itemtypes']) && is_array($_POST['itemtypes'])) { $_POST['linked_itemtypes'] = json_encode($_POST['itemtypes']); } $type->update($_POST); Html::back(); //Delete an itemtype
along with Genericobject. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- @package genericobject @author the genericobject plugin team @copyright Copyright (c) 2010-2011 Order plugin team @license GPLv2+ http://www.gnu.org/licenses/gpl.txt @link https://forge.indepnet.net/projects/genericobject @link http://www.glpi-project.org/ @since 2009 ---------------------------------------------------------------------- */ define('GLPI_ROOT', '../..'); include GLPI_ROOT . "/inc/includes.php"; if (isset($_GET['itemtypes_id']) && $_GET['itemtypes_id'] != '') { $type = new PluginGenericobjectType(); $type->getFromDB($_GET['itemtypes_id']); Html::redirect(Toolbox::getItemTypeSearchURL($type->fields['itemtype'])); } else { $types = PluginGenericobjectType::getTypesByFamily(); foreach ($types as $family => $typeData) { foreach ($typeData as $ID => $value) { if (!plugin_genericobject_haveRight($value['itemtype'], 'r')) { unset($types[$family][$ID]); } } } //There's only one family if (count($types) == 1) { //There's only one itemtype ? If yes, then automatically //redirect to the search engine if (key($types) == NULL) {
/** * * 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>"; }