function plugin_init_fields() { global $PLUGIN_HOOKS; $PLUGIN_HOOKS['csrf_compliant']['fields'] = true; $plugin = new Plugin(); if ($plugin->isInstalled('fields') && $plugin->isActivated('fields') && Session::getLoginUserID()) { // complete rule engine $PLUGIN_HOOKS['use_rules']['fields'] = array('PluginFusioninventoryTaskpostactionRule'); $PLUGIN_HOOKS['rule_matched']['fields'] = 'plugin_fields_rule_matched'; if (isset($_SESSION['glpiactiveentities'])) { $PLUGIN_HOOKS['config_page']['fields'] = 'front/container.php'; // add entry to configuration menu $PLUGIN_HOOKS["menu_toadd"]['fields'] = array('config' => 'PluginFieldsMenu'); // add tabs to itemtypes Plugin::registerClass('PluginFieldsContainer', array('addtabon' => PluginFieldsContainer::getEntries())); //include js and css $PLUGIN_HOOKS['add_css']['fields'][] = 'fields.css'; $PLUGIN_HOOKS['add_javascript']['fields'][] = 'fields.js.php'; // Add/delete profiles to automaticaly to container $PLUGIN_HOOKS['item_add']['fields']['Profile'] = array("PluginFieldsProfile", "addNewProfile"); $PLUGIN_HOOKS['pre_item_purge']['fields']['Profile'] = array("PluginFieldsProfile", "deleteProfile"); //load drag and drop javascript library on Package Interface $PLUGIN_HOOKS['add_javascript']['fields'][] = "scripts/redips-drag-min.js"; $PLUGIN_HOOKS['add_javascript']['fields'][] = "scripts/drag-field-row.js"; } // Add Fields to Datainjection if ($plugin->isInstalled('datainjection') && $plugin->isActivated('datainjection')) { $PLUGIN_HOOKS['plugin_datainjection_populate']['fields'] = "plugin_datainjection_populate_fields"; } //Retrieve dom container $itemtypes = PluginFieldsContainer::getUsedItemtypes(); if ($itemtypes !== false) { foreach ($itemtypes as $itemtype) { $PLUGIN_HOOKS['pre_item_update']['fields'][$itemtype] = array("PluginFieldsContainer", "preItemUpdate"); $PLUGIN_HOOKS['pre_item_purge']['fields'][$itemtype] = array("PluginFieldsContainer", "preItemPurge"); $PLUGIN_HOOKS['item_add']['fields'][$itemtype] = array("PluginFieldsContainer", "preItemUpdate"); } } } }
static function showForDomtabContainer() { //parse http_referer to get current url (this code is loaded by javacript) $current_url = $_SERVER['HTTP_REFERER']; if (strpos($current_url, ".form.php") === false && strpos($current_url, ".injector.php") === false && strpos($current_url, ".public.php") === false) { return false; } $expl_url = explode("?", $current_url); //get current id if (isset($expl_url[1])) { parse_str($expl_url[1], $params); if (isset($params['id'])) { $items_id = $params['id']; } else { $items_id = 0; } } else { $items_id = 0; } //get itemtype $tmp = explode("/", $expl_url[0]); $script_name = array_pop($tmp); if (in_array($script_name, array("helpdesk.public.php", "tracking.injector.php"))) { $current_itemtype = "Ticket"; } else { $current_itemtype = ucfirst(str_replace(".form.php", "", $script_name)); } //Retrieve dom container $itemtypes = PluginFieldsContainer::getUsedItemtypes('domtab', true); //if no dom containers defined for this itemtype, do nothing if (!in_array($current_itemtype, $itemtypes)) { return false; } $rand = mt_rand(); echo "jQuery(document ).ready(function(\$) {\n var dom_inserted = false;\n\n var insert_dom_tab{$rand} = function(jqui_tab, current_glpi_tab) {\n\n // escape \$ in tab name\n //current_glpi_tab = current_glpi_tab.replace('\$', '\\\\\$');\n \n setTimeout(function() {\n // tabs with form\n var selector = '#'+jqui_tab+' form:first-child input[name=update]';\n selector+= ', #'+jqui_tab+' form:first-child input[name=add]';\n selector+= ', #'+jqui_tab+' #mainformtable > tbody > tr:last-child';\n var found = insert_html{$rand}(selector, current_glpi_tab);\n \n //tabs without form\n if (!found) {\n insert_html{$rand}('#'+jqui_tab+' a.vsubmit:first-child', current_glpi_tab);\n }\n }, 500)\n };\n\n var insert_html{$rand} = function(selector, current_glpi_tab) {\n if (dom_inserted) return true;\n\n var found = false;\n jQuery(selector).each(function(index, el) {\n if (!found) {\n element = jQuery(this);\n rand = Math.round(Math.random() * 1000000);\n \n var pos_to_insert = element.closest('tr');\n if (el.tagName === 'TR') pos_to_insert = element;\n pos_to_insert.before(\n '<tr><td style=\"padding:0\" colspan=\"6\"><div id=\"tabdom_container'+rand+'\">.</div></td></tr>');\n \n jQuery('#tabdom_container'+rand).load(\n '../plugins/fields/ajax/load_dom_fields.php',\n {\n itemtype: '{$current_itemtype}',\n items_id: '{$items_id}',\n type: 'domtab', \n subtype: current_glpi_tab\n }\n );\n \n dom_inserted = true;\n found = true;\n }\n });\n\n return found;\n };\n\n findtab_and_insert = function () {\n //get active tab index\n var jqui_tab = 'ui-tabs-'+(\$('div.ui-tabs').tabs( 'option', 'active' ) + 1);\n //get active tab glpi type\n var current_glpi_tab = \$('div.ui-tabs li.ui-tabs-active a')\n .attr('href')\n .match(/&_glpi_tab=(.*)&id=/)[1];\n\n // add html in dom \n insert_dom_tab{$rand}(jqui_tab, current_glpi_tab);\n }\n\n jQuery('div.ui-tabs').tabs({\n load: function( event, ui ) {\n findtab_and_insert(); \n }\n });\n\n //trigger one time if above event not launched\n findtab_and_insert();\n });\n"; }
/** * Init hooks of the plugin. * REQUIRED * * @return void */ function plugin_init_fields() { global $PLUGIN_HOOKS; $PLUGIN_HOOKS['csrf_compliant']['fields'] = true; include_once PLUGINFIELDS_DIR . "/inc/autoload.php"; $options = array(PLUGINFIELDS_CLASS_PATH); $pluginfields_autoloader = new PluginFieldsAutoloader($options); $pluginfields_autoloader->register(); $plugin = new Plugin(); if ($plugin->isInstalled('fields') && $plugin->isActivated('fields') && Session::getLoginUserID()) { // Init hook about itemtype(s) for plugin fields $PLUGIN_HOOKS['plugin_fields'] = array(); // When a Category is changed during ticket creation if (isset($_POST) && !empty($_POST) && isset($_POST['_plugin_fields_type'])) { if ($_SERVER['REQUEST_URI'] == Ticket::getFormURL()) { //$_SESSION['plugin_fields']['Ticket'] = $_POST; foreach ($_POST as $key => $value) { if (!is_array($value)) { $_SESSION['plugin']['fields']['values_sent'][$key] = stripcslashes($value); } } } } // complete rule engine $PLUGIN_HOOKS['use_rules']['fields'] = array('PluginFusioninventoryTaskpostactionRule'); $PLUGIN_HOOKS['rule_matched']['fields'] = 'plugin_fields_rule_matched'; if (isset($_SESSION['glpiactiveentities'])) { $PLUGIN_HOOKS['config_page']['fields'] = 'front/container.php'; // add entry to configuration menu $PLUGIN_HOOKS["menu_toadd"]['fields'] = array('config' => 'PluginFieldsMenu'); // add tabs to itemtypes Plugin::registerClass('PluginFieldsContainer', array('addtabon' => array_unique(PluginFieldsContainer::getEntries()))); //include js and css if (file_exists(__DIR__ . '/css/fields.min.css')) { $PLUGIN_HOOKS['add_css']['fields'][] = 'css/fields.min.css'; } else { $PLUGIN_HOOKS['add_css']['fields'][] = 'css/fields.css'; } $PLUGIN_HOOKS['add_javascript']['fields'][] = 'fields.js.php'; // Add/delete profiles to automaticaly to container $PLUGIN_HOOKS['item_add']['fields']['Profile'] = array("PluginFieldsProfile", "addNewProfile"); $PLUGIN_HOOKS['pre_item_purge']['fields']['Profile'] = array("PluginFieldsProfile", "deleteProfile"); //load drag and drop javascript library on Package Interface $PLUGIN_HOOKS['add_javascript']['fields'][] = "js/redips-drag-min.js"; if (file_exists(__DIR__ . '/js/drag-field-row.min.js')) { $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.min.js'; } else { $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.js'; } } // Add Fields to Datainjection if ($plugin->isActivated('datainjection')) { $PLUGIN_HOOKS['plugin_datainjection_populate']['fields'] = "plugin_datainjection_populate_fields"; } //Retrieve dom container $itemtypes = PluginFieldsContainer::getUsedItemtypes(); if ($itemtypes !== false) { foreach ($itemtypes as $itemtype) { $PLUGIN_HOOKS['pre_item_update']['fields'][$itemtype] = ["PluginFieldsContainer", "preItemUpdate"]; $PLUGIN_HOOKS['pre_item_add']['fields'][$itemtype] = ["PluginFieldsContainer", "preItem"]; $PLUGIN_HOOKS['item_add']['fields'][$itemtype] = ["PluginFieldsContainer", "postItemAdd"]; $PLUGIN_HOOKS['pre_item_purge']['fields'][$itemtype] = ["PluginFieldsContainer", "preItemPurge"]; } } } }
static function showForDomtabContainer() { global $CFG_GLPI; //parse http_referer to get current url (this code is loaded by javacript) $current_url = $_SERVER['HTTP_REFERER']; if (strpos($current_url, ".form.php") === false && strpos($current_url, ".injector.php") === false && strpos($current_url, ".public.php") === false) { return false; } $expl_url = explode("?", $current_url); //get current id if (isset($expl_url[1])) { parse_str($expl_url[1], $params); if (isset($params['id'])) { $items_id = $params['id']; } else { $items_id = 0; } } else { $items_id = 0; } //get itemtype $tmp = explode("/", $expl_url[0]); $script_name = array_pop($tmp); if (in_array($script_name, array("helpdesk.public.php", "tracking.injector.php"))) { $current_itemtype = "Ticket"; } else { $current_itemtype = ucfirst(str_replace(".form.php", "", $script_name)); } //Retrieve dom container $itemtypes = PluginFieldsContainer::getUsedItemtypes('domtab', true); //if no dom containers defined for this itemtype, do nothing if (!in_array($current_itemtype, $itemtypes)) { return false; } $rand = mt_rand(); $url_ajax = $CFG_GLPI["root_doc"] . "/plugins/fields/ajax/load_dom_fields.php"; $JS = <<<JAVASCRIPT jQuery(document).ready(function(\$) { var dom_inserted = false; var insert_dom_tab{$rand} = function(jqui_tab, current_glpi_tab) { // escape \$ in tab name //current_glpi_tab = current_glpi_tab.replace('\$', '\\\\\$'); setTimeout(function() { // tabs with form var selector = '#'+jqui_tab+' form:first-child input[name=update]'; selector+= ', #'+jqui_tab+' form:first-child input[name=add]'; selector+= ', #'+jqui_tab+' #mainformtable > tbody > tr:last-child'; var found = insert_html{$rand}(selector, current_glpi_tab); //tabs without form if (!found) { insert_html{$rand}('#'+jqui_tab+' a.vsubmit:first-child', current_glpi_tab); } }, 500) }; var insert_html{$rand} = function(selector, current_glpi_tab) { if (dom_inserted) return true; var found = false; jQuery(selector).each(function(index, el) { if (!found) { element = jQuery(this); rand = Math.round(Math.random() * 1000000); var pos_to_insert = element.closest('tr'); if (el.tagName === 'TR') pos_to_insert = element; pos_to_insert.before( '<tr><td style=\\"padding:0\\" colspan=\\"6\\"><div id=\\"tabdom_container'+rand+'\\">.</div></td></tr>'); jQuery('#tabdom_container'+rand) .load('{$url_ajax}', { itemtype: '{$current_itemtype}', items_id: '{$items_id}', type: 'domtab', subtype: current_glpi_tab } ); dom_inserted = true; found = true; } }); return found; }; var findtab_and_insert = function () { //get active tab index var jqui_tab = 'ui-tabs-'+(\$('div.ui-tabs').tabs( 'option', 'active' ) + 1); //get active tab glpi type var current_glpi_tab = \$('div.ui-tabs li.ui-tabs-active a') .attr('href') .match(/&_glpi_tab=(.*)&id=/)[1]; // add html in dom insert_dom_tab{$rand}(jqui_tab, current_glpi_tab); }; \$('.ui-tabs-panel:visible').ready(function() { findtab_and_insert(); }) \$('#tabspanel + div.ui-tabs').on('tabsload', function() { setTimeout(function() { findtab_and_insert(); }, 300); }); }); JAVASCRIPT; echo $JS; }