예제 #1
0
파일: hook.php 프로젝트: publik1974/fields
function plugin_fields_uninstall()
{
    global $DB;
    $_SESSION['uninstall_fields'] = true;
    $classesToUninstall = array('PluginFieldsDropdown', 'PluginFieldsContainer', 'PluginFieldsContainer_Field', 'PluginFieldsField', 'PluginFieldsValue', 'PluginFieldsProfile', 'PluginFieldsMigration');
    echo "<center>";
    echo "<table class='tab_cadre_fixe'>";
    echo "<tr><th>" . __("MySQL tables uninstallation", "fields") . "<th></tr>";
    echo "<tr class='tab_bg_1'>";
    echo "<td align='center'>";
    foreach ($classesToUninstall as $class) {
        if ($plug = isPluginItemType($class)) {
            $dir = GLPI_ROOT . "/plugins/fields/inc/";
            $item = strtolower($plug['class']);
            if (file_exists("{$dir}{$item}.class.php")) {
                include_once "{$dir}{$item}.class.php";
                if (!call_user_func(array($class, 'uninstall'))) {
                    return false;
                }
            }
        }
    }
    echo "</td>";
    echo "</tr>";
    echo "</table></center>";
    unset($_SESSION['uninstall_fields']);
    // clean display preferences
    $DB->query("DELETE FROM glpi_displaypreferences WHERE itemtype LIKE 'PluginFields%'");
    return true;
}
예제 #2
0
파일: hook.php 프로젝트: equinoxefr/order
function plugin_order_install()
{
    foreach (glob(GLPI_ROOT . '/plugins/order/inc/*.php') as $file) {
        //Do not load datainjection files (not needed and avoid missing class error message)
        if (!preg_match('/injection.class.php/', $file)) {
            include_once $file;
        }
    }
    echo "<center>";
    echo "<table class='tab_cadre_fixe'>";
    echo "<tr><th>" . __("Plugin installation or upgrade", "order") . "<th></tr>";
    echo "<tr class='tab_bg_1'>";
    echo "<td align='center'>";
    $migration = new Migration("1.5.2");
    $classes = array('PluginOrderConfig', 'PluginOrderBillState', 'PluginOrderBillType', 'PluginOrderOrderState', 'PluginOrderOrder', 'PluginOrderOrder_Item', 'PluginOrderReference', 'PluginOrderDeliveryState', 'PluginOrderNotificationTargetOrder', 'PluginOrderOrder_Supplier', 'PluginOrderBill', 'PluginOrderOrderPayment', 'PluginOrderOrderType', 'PluginOrderOther', 'PluginOrderOtherType', 'PluginOrderPreference', 'PluginOrderProfile', 'PluginOrderReference_Supplier', 'PluginOrderSurveySupplier', 'PluginOrderOrderTax', 'PluginOrderDocumentCategory');
    foreach ($classes as $class) {
        if ($plug = isPluginItemType($class)) {
            $plugname = strtolower($plug['plugin']);
            $dir = GLPI_ROOT . "/plugins/{$plugname}/inc/";
            $item = strtolower($plug['class']);
            if (file_exists("{$dir}{$item}.class.php")) {
                include_once "{$dir}{$item}.class.php";
                call_user_func(array($class, 'install'), $migration);
            }
        }
    }
    echo "</td>";
    echo "</tr>";
    echo "</table></center>";
    return true;
}
 /**
  * Get the assiociated item_device associated with this device
  * This method can be override, for instance by the plugin
  *
  * @since version 0.85
  *
  * @return array of the types of CommonDevice available
  **/
 static function getItem_DeviceType()
 {
     $devicetype = get_called_class();
     if ($plug = isPluginItemType($devicetype)) {
         return 'Plugin' . $plug['plugin'] . 'Item_' . $plug['class'];
     }
     return "Item_{$devicetype}";
 }
 function glpiautoload($classname)
 {
     global $DEBUG_AUTOLOAD, $CFG_GLPI;
     static $notfound = array();
     // empty classname or non concerted plugin
     if (empty($classname) || is_numeric($classname)) {
         return FALSE;
     }
     $dir = GLPI_ROOT . "/inc/";
     //$classname="PluginExampleProfile";
     if ($plug = isPluginItemType($classname)) {
         $plugname = strtolower($plug['plugin']);
         $dir = GLPI_ROOT . "/plugins/{$plugname}/inc/";
         $item = strtolower($plug['class']);
         // Is the plugin activate ?
         // Command line usage of GLPI : need to do a real check plugin activation
         if (isCommandLine()) {
             $plugin = new Plugin();
             if (count($plugin->find("directory='{$plugname}' AND state=" . Plugin::ACTIVATED)) == 0) {
                 // Plugin does not exists or not activated
                 return FALSE;
             }
         } else {
             // Standard use of GLPI
             if (!in_array($plugname, $_SESSION['glpi_plugins'])) {
                 // Plugin not activated
                 return FALSE;
             }
         }
     } else {
         // Is ezComponent class ?
         $matches = array();
         if (preg_match('/^ezc([A-Z][a-z]+)/', $classname, $matches)) {
             include_once GLPI_EZC_BASE;
             ezcBase::autoload($classname);
             return TRUE;
         } else {
             $item = strtolower($classname);
         }
     }
     // No errors for missing classes due to implementation
     if (!isset($CFG_GLPI['missingclasses']) or !in_array($item, $CFG_GLPI['missingclasses'])) {
         if (file_exists("{$dir}{$item}.class.php")) {
             include_once "{$dir}{$item}.class.php";
             if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
                 $DEBUG_AUTOLOAD[] = $classname;
             }
         } else {
             if (!isset($notfound["{$classname}"])) {
                 // trigger an error to get a backtrace, but only once (use prefix 'x' to handle empty case)
                 //Toolbox::logInFile('debug', "file $dir$item.class.php not founded trying to load class $classname\n");
                 trigger_error("GLPI autoload : file {$dir}{$item}.class.php not founded trying to load class '{$classname}'");
                 $notfound["{$classname}"] = TRUE;
             }
         }
     }
 }
 /**
  * Get all data needed for template processing
  *
  * @param $event
  * @param $options   array
  **/
 function getDatasForTemplate($event, $options = array())
 {
     $events = $this->getAllEvents();
     $this->datas['##crontask.action##'] = $events[$event];
     $cron = new Crontask();
     foreach ($options['items'] as $id => $crontask) {
         $tmp = array();
         $tmp['##crontask.name##'] = '';
         if ($isplug = isPluginItemType($crontask["itemtype"])) {
             $tmp['##crontask.name##'] = $isplug["plugin"] . " - ";
         }
         $tmp['##crontask.name##'] .= $crontask['name'];
         $tmp['##crontask.description##'] = $cron->getDescription($id);
         $tmp['##crontask.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "Crontask_" . $id);
         $this->datas['crontasks'][] = $tmp;
     }
     $this->getTags();
     foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
         if (!isset($this->datas[$tag])) {
             $this->datas[$tag] = $values['label'];
         }
     }
 }
 /**
  * Get all data needed for template processing
  *
  * @param $event
  * @param $options   array
  **/
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI;
     $events = $this->getAllEvents();
     $this->datas['##crontask.action##'] = $events[$event];
     $cron = new Crontask();
     foreach ($options['items'] as $id => $crontask) {
         $tmp = array();
         $tmp['##crontask.name##'] = '';
         if ($isplug = isPluginItemType($crontask["itemtype"])) {
             $tmp['##crontask.name##'] = $isplug["plugin"] . " - ";
         }
         $tmp['##crontask.name##'] .= $crontask['name'];
         $tmp['##crontask.description##'] = $cron->getDescription($id);
         $tmp['##crontask.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=crontask_" . $id);
         $this->datas['crontasks'][] = $tmp;
     }
     $this->getTags();
     foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
         if (!isset($this->datas[$tag])) {
             $this->datas[$tag] = $values['label'];
         }
     }
 }
 /**
  * Get rulecollection classname by giving his itemtype
  *
  * @param $itemtype itemtype
  * @param $check_dictionnary_type check if the itemtype is a dictionnary or not
  *
  * @return the rulecollection class or null
  */
 static function getClassByType($itemtype, $check_dictionnary_type = false)
 {
     global $CFG_GLPI;
     if ($plug = isPluginItemType($itemtype)) {
         $typeclass = 'Plugin' . $plug['plugin'] . $plug['class'] . 'Collection';
     } else {
         if (in_array($itemtype, $CFG_GLPI["dictionnary_types"])) {
             $typeclass = 'RuleDictionnary' . $itemtype . "Collection";
         } else {
             $typeclass = $itemtype . "Collection";
         }
     }
     if ($check_dictionnary_type && in_array($itemtype, $CFG_GLPI["dictionnary_types"]) || !$check_dictionnary_type) {
         if (class_exists($typeclass)) {
             return new $typeclass();
         }
         return NULL;
     }
 }
예제 #8
0
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief List of device for tracking.
* @since version 0.85
*/
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
// Security
if (!TableExists($_POST['table'])) {
    exit;
}
$itemtypeisplugin = isPluginItemType($_POST['itemtype']);
if (!($item = getItemForItemtype($_POST['itemtype']))) {
    exit;
}
if ($item->isEntityAssign()) {
    if (isset($_POST["entity_restrict"]) && $_POST["entity_restrict"] >= 0) {
        $entity = $_POST["entity_restrict"];
    } else {
        $entity = '';
    }
    // allow opening ticket on recursive object (printer, software, ...)
    $recursive = $item->maybeRecursive();
    $where = getEntitiesRestrictRequest("WHERE", $_POST['table'], '', $entity, $recursive);
} else {
    $where = "WHERE 1";
}
예제 #9
0
 /**
  * Define a new class managed by a plugin
  *
  * @param $itemtype        class name
  * @param $attrib    array of attributes, a hashtable with index in
  *                         (classname, typename, reservation_types)
  *
  * @return bool
  **/
 static function registerClass($itemtype, $attrib = array())
 {
     global $CFG_GLPI;
     $plug = isPluginItemType($itemtype);
     if (!$plug) {
         return false;
     }
     $plugin = strtolower($plug['plugin']);
     if (isset($attrib['doc_types'])) {
         $attrib['document_types'] = $attrib['doc_types'];
         unset($attrib['doc_types']);
     }
     if (isset($attrib['helpdesk_types'])) {
         $attrib['ticket_types'] = $attrib['helpdesk_types'];
         unset($attrib['helpdesk_types']);
     }
     if (isset($attrib['netport_types'])) {
         $attrib['networkport_types'] = $attrib['netport_types'];
         unset($attrib['netport_types']);
     }
     foreach (array('contract_types', 'directconnect_types', 'document_types', 'helpdesk_visible_types', 'infocom_types', 'linkgroup_tech_types', 'linkgroup_types', 'linkuser_tech_types', 'linkuser_types', 'location_types', 'networkport_instantiations', 'networkport_types', 'notificationtemplates_types', 'planning_types', 'reservation_types', 'rulecollections_types', 'systeminformations_types', 'ticket_types', 'unicity_types', 'link_types') as $att) {
         if (isset($attrib[$att]) && $attrib[$att]) {
             array_push($CFG_GLPI[$att], $itemtype);
             unset($attrib[$att]);
         }
     }
     if (isset($attrib['device_types']) && $attrib['device_types'] && method_exists($itemtype, 'getItem_DeviceType')) {
         if (class_exists($itemtype::getItem_DeviceType())) {
             array_push($CFG_GLPI['device_types'], $itemtype);
         }
         unset($attrib[$att]);
     }
     if (isset($attrib['addtabon'])) {
         if (!is_array($attrib['addtabon'])) {
             $attrib['addtabon'] = array($attrib['addtabon']);
         }
         foreach ($attrib['addtabon'] as $form) {
             CommonGLPI::registerStandardTab($form, $itemtype);
         }
     }
     //Manage entity forward from a source itemtype to this itemtype
     if (isset($attrib['forwardentityfrom'])) {
         CommonDBTM::addForwardEntity($attrib['forwardentityfrom'], $itemtype);
     }
     // Use it for plugin debug
     //       if (count($attrib)) {
     //          foreach ($attrib as $key => $val) {
     //             Toolbox::logInFile('debug',"Attribut $key used by $itemtype no more used for plugins\n");
     //          }
     //}
     return true;
 }
예제 #10
0
 /**
  * @param $target             NotificationTarget object
  * @param $user_infos   array
  * @param $event
  * @param $options      array
  *
  * @return id of the template in templates_by_languages / false if computation failed
  **/
 function getTemplateByLanguage(NotificationTarget $target, $user_infos = array(), $event, $options = array())
 {
     $lang = array();
     $language = $user_infos['language'];
     if (isset($user_infos['additionnaloption'])) {
         $additionnaloption = $user_infos['additionnaloption'];
     } else {
         $additionnaloption = array();
     }
     $tid = $language;
     $tid .= serialize($additionnaloption);
     $tid = sha1($tid);
     if (!isset($this->templates_by_languages[$tid])) {
         //Switch to the desired language
         $bak_dropdowntranslations = $_SESSION['glpi_dropdowntranslations'];
         $_SESSION['glpi_dropdowntranslations'] = DropdownTranslation::getAvailableTranslations($language);
         Session::loadLanguage($language);
         $bak_language = $_SESSION["glpilanguage"];
         $_SESSION["glpilanguage"] = $language;
         //If event is raised by a plugin, load it in order to get the language file available
         if ($plug = isPluginItemType(get_class($target->obj))) {
             Plugin::loadLang(strtolower($plug['plugin']), $language);
         }
         //Get template's language data for in this language
         $options['additionnaloption'] = $additionnaloption;
         $data =& $target->getForTemplate($event, $options);
         $footer_string = Html::entity_decode_deep(sprintf(__('Automatically generated by GLPI %s'), GLPI_VERSION));
         $add_header = Html::entity_decode_deep($target->getContentHeader());
         $add_footer = Html::entity_decode_deep($target->getContentFooter());
         //Restore default language
         $_SESSION["glpilanguage"] = $bak_language;
         Session::loadLanguage();
         $_SESSION['glpi_dropdowntranslations'] = $bak_dropdowntranslations;
         if ($plug = isPluginItemType(get_class($target->obj))) {
             Plugin::loadLang(strtolower($plug['plugin']));
         }
         if ($template_datas = $this->getByLanguage($language)) {
             //Template processing
             // Decode html chars to have clean text
             $template_datas['content_text'] = Html::entity_decode_deep($template_datas['content_text']);
             $save_data = $data;
             $data = Html::entity_decode_deep($data);
             $template_datas['subject'] = Html::entity_decode_deep($template_datas['subject']);
             $this->signature = Html::entity_decode_deep($this->signature);
             $lang['subject'] = $target->getSubjectPrefix($event) . self::process($template_datas['subject'], $data);
             $lang['content_html'] = '';
             //If no html content, then send only in text
             if (!empty($template_datas['content_html'])) {
                 // Encode in HTML all chars
                 $data_html = Html::entities_deep($data);
                 $data_html = Html::nl2br_deep($data_html);
                 // Restore HTML tags
                 if (count($target->html_tags)) {
                     foreach ($target->html_tags as $tag) {
                         if (isset($save_data[$tag])) {
                             $data_html[$tag] = $save_data[$tag];
                         }
                     }
                 }
                 $signature_html = Html::entities_deep($this->signature);
                 $signature_html = Html::nl2br_deep($signature_html);
                 $template_datas['content_html'] = self::process($template_datas['content_html'], $data_html);
                 $lang['content_html'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n                        'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>" . "<html>\n                        <head>\n                         <META http-equiv='Content-Type' content='text/html; charset=utf-8'>\n                         <title>" . Html::entities_deep($lang['subject']) . "</title>\n                         <style type='text/css'>\n                           " . $this->fields['css'] . "\n                         </style>\n                        </head>\n                        <body>\n" . (!empty($add_header) ? $add_header . "\n<br><br>" : '') . $template_datas['content_html'] . "<br><br>-- \n<br>" . $signature_html . "<br>{$footer_string}" . "<br><br>\n" . (!empty($add_footer) ? $add_footer . "\n<br><br>" : '') . "\n</body></html>";
             }
             $lang['content_text'] = (!empty($add_header) ? $add_header . "\n\n" : '') . Html::clean(self::process($template_datas['content_text'], $data) . "\n\n-- \n" . $this->signature . "\n" . Html::entity_decode_deep(sprintf(__('Automatically generated by GLPI %s'), GLPI_VERSION))) . "\n\n" . $add_footer;
             $this->templates_by_languages[$tid] = $lang;
         }
     }
     if (isset($this->templates_by_languages[$tid])) {
         return $tid;
     }
     return false;
 }
예제 #11
0
 /**
  * Check already planned user for a period
  *
  * @param $users_id        user id
  * @param $begin           begin date
  * @param $end             end date
  * @param $except    array of items which not be into account array
  *                         ('Reminder'=>array(1,2,id_of_items))
  **/
 static function checkAlreadyPlanned($users_id, $begin, $end, $except = array())
 {
     global $CFG_GLPI;
     $planned = false;
     $message = '';
     foreach ($CFG_GLPI['planning_types'] as $itemtype) {
         $data = call_user_func(array($itemtype, 'populatePlanning'), array('who' => $users_id, 'who_group' => 0, 'begin' => $begin, 'end' => $end));
         if (isPluginItemType($itemtype)) {
             if (isset($data['items'])) {
                 $data = $data['items'];
             } else {
                 $data = array();
             }
         }
         if (count($data) && method_exists($itemtype, 'getAlreadyPlannedInformation')) {
             foreach ($data as $key => $val) {
                 if (!isset($except[$itemtype]) || is_array($except[$itemtype]) && !in_array($val['id'], $except[$itemtype])) {
                     $planned = true;
                     $message .= '- ' . call_user_func(array($itemtype, 'getAlreadyPlannedInformation'), $val) . '<br>';
                 }
             }
         }
     }
     if ($planned) {
         Session::addMessageAfterRedirect(__('The user is busy at the selected timeframe.') . '<br>' . $message, false, ERROR);
     }
     return $planned;
 }
예제 #12
0
 /**
  * Get associated device to the current item_device
  *
  * @since version 0.85
  *
  * @return string containing the device
  **/
 static function getDeviceType()
 {
     $devicetype = get_called_class();
     if ($plug = isPluginItemType($devicetype)) {
         return 'Plugin' . $plug['plugin'] . str_replace('Item_', '', $plug['class']);
     }
     return str_replace('Item_', '', $devicetype);
 }
 /**
  * Get all available types to which an ITIL object can be assigned
  **/
 static function getAllTypesForHelpdesk()
 {
     global $PLUGIN_HOOKS, $CFG_GLPI;
     /// TODO ticket_types -> itil_types
     $types = array();
     $ptypes = array();
     //Types of the plugins (keep the plugin hook for right check)
     if (isset($PLUGIN_HOOKS['assign_to_ticket'])) {
         foreach ($PLUGIN_HOOKS['assign_to_ticket'] as $plugin => $value) {
             $ptypes = Plugin::doOneHook($plugin, 'AssignToTicket', $ptypes);
         }
     }
     asort($ptypes);
     //Types of the core (after the plugin for robustness)
     foreach ($CFG_GLPI["ticket_types"] as $itemtype) {
         if ($item = getItemForItemtype($itemtype)) {
             if (!isPluginItemType($itemtype) && in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) {
                 $types[$itemtype] = $item->getTypeName(1);
             }
         }
     }
     asort($types);
     // core type first... asort could be better ?
     // Drop not available plugins
     foreach ($ptypes as $itemtype => $itemtype_name) {
         if (!in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) {
             unset($ptypes[$itemtype]);
         }
     }
     $types = array_merge($types, $ptypes);
     return $types;
 }
 /**
  * Get search URL for itemtype
  *
  * @param $itemtype  string   item type
  * @param $full               path or relative one (true by default)
  *
  * return string itemtype search URL
  **/
 static function getItemTypeSearchURL($itemtype, $full = true)
 {
     global $CFG_GLPI;
     $dir = $full ? $CFG_GLPI['root_doc'] : '';
     if ($plug = isPluginItemType($itemtype)) {
         $dir .= "/plugins/" . strtolower($plug['plugin']);
         $item = strtolower($plug['class']);
     } else {
         // Standard case
         if ($itemtype == 'Cartridge') {
             $itemtype = 'CartridgeItem';
         }
         if ($itemtype == 'Consumable') {
             $itemtype = 'ConsumableItem';
         }
         $item = strtolower($itemtype);
     }
     return "{$dir}/front/{$item}.php";
 }
예제 #15
0
Html::header_nocache();
if (!($item = getItemForItemtype($_POST['itemtype']))) {
    exit;
}
$item->checkGlobal(READ);
$group = "";
$values = array();
$searchopt = Search::getCleanedOptions($_POST["itemtype"], READ, false);
echo "<table width='100%'><tr><td width='40%'>";
foreach ($searchopt as $key => $val) {
    // print groups
    $str_limit = 28;
    if (!is_array($val)) {
        $group = $val;
    } else {
        // No search on plugins
        if (!isPluginItemType($key) && !isset($val["nometa"])) {
            $values[$group][$key] = $val["name"];
        }
    }
}
$rand = Dropdown::showFromArray("metacriteria[" . $_POST["num"] . "][field]", $values, array('value' => $_POST["field"]));
$field_id = Html::cleanId("dropdown_metacriteria[" . $_POST["num"] . "][field]" . $rand);
echo "</td><td class='left'>";
echo "<span id='Search2Span" . $_POST["itemtype"] . $_POST["num"] . "'>\n";
$_POST['meta'] = 1;
include GLPI_ROOT . "/ajax/searchoption.php";
echo "</span>\n";
$params = array('field' => '__VALUE__', 'itemtype' => $_POST["itemtype"], 'num' => $_POST["num"], 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"], 'meta' => 1);
Ajax::updateItemOnSelectEvent($field_id, "Search2Span" . $_POST["itemtype"] . $_POST["num"], $CFG_GLPI["root_doc"] . "/ajax/searchoption.php", $params);
echo '</td></tr></table>';
예제 #16
0
 /**
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $CFG_GLPI;
     $action = $ma->getAction();
     switch ($action) {
         case 'delete':
             foreach ($ids as $id) {
                 if ($item->can($id, DELETE)) {
                     if ($item->delete(array("id" => $id))) {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             break;
         case 'restore':
             foreach ($ids as $id) {
                 if ($item->can($id, PURGE)) {
                     if ($item->restore(array("id" => $id))) {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             break;
         case 'purge_item_but_devices':
         case 'purge_but_item_linked':
         case 'purge':
             foreach ($ids as $id) {
                 if ($item->can($id, PURGE)) {
                     $force = 1;
                     // Only mark deletion for
                     if ($item->maybeDeleted() && $item->useDeletedToLockIfDynamic() && $item->isDynamic()) {
                         $force = 0;
                     }
                     $delete_array = array('id' => $id);
                     if ($action == 'purge_item_but_devices') {
                         $delete_array['keep_devices'] = true;
                     }
                     if ($item instanceof CommonDropdown) {
                         if ($item->haveChildren()) {
                             if ($action != 'purge_but_item_linked') {
                                 $force = 0;
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage(__("You can't delete that item by massive actions, because it has sub-items"));
                                 $ma->addMessage(__("but you can do it by the form of the item"));
                                 continue;
                             }
                         }
                         if ($item->isUsed()) {
                             if ($action != 'purge_but_item_linked') {
                                 $force = 0;
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage(__("You can't delete that item, because it is used for one or more items"));
                                 $ma->addMessage(__("but you can do it by the form of the item"));
                                 continue;
                             }
                         }
                     }
                     if ($item->delete($delete_array, $force)) {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             break;
         case 'update':
             if (!isset($ma->POST['search_options']) || !isset($ma->POST['search_options'][$item->getType()])) {
                 return false;
             }
             $index = $ma->POST['search_options'][$item->getType()];
             $searchopt = Search::getCleanedOptions($item->getType(), UPDATE);
             $input = $ma->POST;
             if (isset($searchopt[$index])) {
                 /// Infocoms case
                 if (!isPluginItemType($item->getType()) && Search::isInfocomOption($item->getType(), $index)) {
                     $ic = new Infocom();
                     $link_entity_type = -1;
                     /// Specific entity item
                     if ($searchopt[$index]["table"] == "glpi_suppliers") {
                         $ent = new Supplier();
                         if ($ent->getFromDB($input[$input["field"]])) {
                             $link_entity_type = $ent->fields["entities_id"];
                         }
                     }
                     foreach ($ids as $key) {
                         if ($item->getFromDB($key)) {
                             if ($link_entity_type < 0 || $link_entity_type == $item->getEntityID() || $ent->fields["is_recursive"] && in_array($link_entity_type, getAncestorsOf("glpi_entities", $item->getEntityID()))) {
                                 $input2["items_id"] = $key;
                                 $input2["itemtype"] = $item->getType();
                                 if ($ic->can(-1, CREATE, $input2)) {
                                     // Add infocom if not exists
                                     if (!$ic->getFromDBforDevice($item->getType(), $key)) {
                                         $input2["items_id"] = $key;
                                         $input2["itemtype"] = $item->getType();
                                         unset($ic->fields);
                                         $ic->add($input2);
                                         $ic->getFromDBforDevice($item->getType(), $key);
                                     }
                                     $id = $ic->fields["id"];
                                     unset($ic->fields);
                                     if ($ic->update(array('id' => $id, $input["field"] => $input[$input["field"]]))) {
                                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                                     } else {
                                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                         $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                                     }
                                 } else {
                                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                                 }
                             } else {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                 $ma->addMessage($item->getErrorMessage(ERROR_COMPAT));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                         }
                     }
                 } else {
                     /// Not infocoms
                     $link_entity_type = array();
                     /// Specific entity item
                     $itemtable = getTableForItemType($item->getType());
                     $itemtype2 = getItemTypeForTable($searchopt[$index]["table"]);
                     if ($item2 = getItemForItemtype($itemtype2)) {
                         if ($index != 80 && $searchopt[$index]["table"] != $itemtable && $item2->isEntityAssign() && $item->isEntityAssign()) {
                             if ($item2->getFromDB($input[$input["field"]])) {
                                 if (isset($item2->fields["entities_id"]) && $item2->fields["entities_id"] >= 0) {
                                     if (isset($item2->fields["is_recursive"]) && $item2->fields["is_recursive"]) {
                                         $link_entity_type = getSonsOf("glpi_entities", $item2->fields["entities_id"]);
                                     } else {
                                         $link_entity_type[] = $item2->fields["entities_id"];
                                     }
                                 }
                             }
                         }
                     }
                     foreach ($ids as $key) {
                         if ($item->canEdit($key) && $item->canMassiveAction($action, $input['field'], $input[$input["field"]])) {
                             if (count($link_entity_type) == 0 || in_array($item->fields["entities_id"], $link_entity_type)) {
                                 if ($item->update(array('id' => $key, $input["field"] => $input[$input["field"]]))) {
                                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                                 } else {
                                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                     $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                                 }
                             } else {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                 $ma->addMessage($item->getErrorMessage(ERROR_COMPAT));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                             $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                         }
                     }
                 }
             }
             break;
         case 'add_transfer_list':
             $itemtype = $item->getType();
             if (!isset($_SESSION['glpitransfer_list'])) {
                 $_SESSION['glpitransfer_list'] = array();
             }
             if (!isset($_SESSION['glpitransfer_list'][$itemtype])) {
                 $_SESSION['glpitransfer_list'][$itemtype] = array();
             }
             foreach ($ids as $id) {
                 $_SESSION['glpitransfer_list'][$itemtype][$id] = $id;
                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
             }
             $ma->setRedirect($CFG_GLPI['root_doc'] . '/front/transfer.action.php');
             break;
     }
 }
$submitname = _sx('button', 'Post');
if (isset($_POST['submitname']) && $_POST['submitname']) {
    $submitname = stripslashes($_POST['submitname']);
}
if (isset($_POST["itemtype"]) && isset($_POST["id_field"]) && $_POST["id_field"]) {
    $search = Search::getOptions($_POST["itemtype"]);
    if (!isset($search[$_POST["id_field"]])) {
        exit;
    }
    $search = $search[$_POST["id_field"]];
    $FIELDNAME_PRINTED = false;
    $USE_TABLE = false;
    echo "<table class='tab_glpi' width='100%'><tr><td>";
    $plugdisplay = false;
    // Specific plugin Type case
    if (($plug = isPluginItemType($_POST["itemtype"])) || ($plug = isPluginItemType(getItemTypeForTable($search['table'])))) {
        $plugdisplay = Plugin::doOneHook($plug['plugin'], 'MassiveActionsFieldsDisplay', array('itemtype' => $_POST["itemtype"], 'options' => $search));
    }
    $fieldname = '';
    if (empty($search["linkfield"]) || $search['table'] == 'glpi_infocoms') {
        $fieldname = $search["field"];
    } else {
        $fieldname = $search["linkfield"];
    }
    if (!$plugdisplay) {
        $options = array();
        $values = array();
        // For ticket template or aditional options of massive actions
        if (isset($_POST['options'])) {
            $options = $_POST['options'];
        }
 function showMethods()
 {
     global $WEBSERVICES_METHOD, $CFG_GLPI;
     echo "<div class='center'><br><table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='4'>" . __('Method list - defined and allowed by this rule', 'webservices') . "</th></tr>";
     echo "<tr><th>" . __('Method name', 'webservices') . "</th>" . "<th>" . __('Provider plugin', 'webservices') . "</th>" . "<th>" . __('Internal function name', 'webservices') . "</th>" . "<th>" . __('Function is available', 'webservices') . "</th></tr>";
     // Allow all plugins to register their methods
     $WEBSERVICES_METHOD = array();
     Plugin::doHook("webservices");
     foreach ($WEBSERVICES_METHOD as $method => $function) {
         // Display if MySQL REGEXP match
         if (countElementsInTable($this->getTable(), "ID='" . $this->fields['id'] . "' AND '" . addslashes($method) . "' REGEXP pattern") > 0) {
             $result = $function;
             if (is_array($function)) {
                 if ($tmp = isPluginItemType($function[0])) {
                     $plugin = $tmp['plugin'];
                 } else {
                     $plugin = "&nbsp;";
                 }
                 $result = implode('::', $function);
             } else {
                 if (preg_match('/^plugin_(.*)_method/', $function, $res)) {
                     $plugin = $res[1];
                 } else {
                     $plugin = "&nbsp;";
                 }
             }
             $call = is_callable($function) ? __('Yes') : __('No');
             $color = is_callable($function) ? "greenbutton" : "redbutton";
             echo "<tr class='tab_bg_1'><td class='b'>{$method}</td><td>{$plugin}</td>" . "<td>{$result}</td><td class='center'>" . "<img src=\"" . $CFG_GLPI['root_doc'] . "/pics/{$color}.png\" alt='ok'>&nbsp;{$call}</td></tr>";
         }
     }
     echo "</table></div>";
 }
예제 #19
0
 /**
  * Register new task for plugin (called by plugin during install)
  *
  * @param $itemtype        itemtype of the plugin object
  * @param $name            of the task
  * @param $frequency       of execution
  * @param $options   array of optional options
  *       (state, mode, allowmode, hourmin, hourmax, logs_lifetime, param, comment)
  *
  * @return bool for success
  **/
 public static function Register($itemtype, $name, $frequency, $options = array())
 {
     // Check that hook exists
     if (!isPluginItemType($itemtype)) {
         return false;
     }
     $temp = new self();
     // Avoid duplicate entry
     if ($temp->getFromDBbyName($itemtype, $name)) {
         return false;
     }
     $input = array('itemtype' => $itemtype, 'name' => $name, 'frequency' => $frequency);
     foreach (array('allowmode', 'comment', 'hourmax', 'hourmin', 'logs_lifetime', 'mode', 'param', 'state') as $key) {
         if (isset($options[$key])) {
             $input[$key] = $options[$key];
         }
     }
     return $temp->add($input);
 }
예제 #20
0
 /**
  * Show the rule
  *
  * @param $ID              ID of the rule
  * @param $options   array of possible options:
  *     - target filename : where to go when done.
  *     - withtemplate boolean : template or basic item
  *
  * @return nothing
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     if (!$this->isNewID($ID)) {
         $this->check($ID, READ);
     } else {
         // Create item
         $this->checkGlobal(UPDATE);
     }
     $canedit = $this->canEdit(static::$rightname);
     $rand = mt_rand();
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Name') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "name");
     echo "</td>";
     echo "<td>" . __('Description') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "description");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Logical operator') . "</td>";
     echo "<td>";
     $this->dropdownRulesMatch(array('value' => $this->fields["match"]));
     echo "</td>";
     echo "<td>" . __('Active') . "</td>";
     echo "<td>";
     Dropdown::showYesNo("is_active", $this->fields["is_active"]);
     echo "</td></tr>\n";
     if ($this->useConditions()) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Use rule for') . "</td>";
         echo "<td>";
         $this->dropdownConditions(array('value' => $this->fields["condition"]));
         echo "</td>";
         echo "<td colspan='2'>";
         echo "</td></tr>\n";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Comments') . "</td>";
     echo "<td class='middle' colspan='3'>";
     echo "<textarea cols='110' rows='3' name='comment' >" . $this->fields["comment"] . "</textarea>";
     if (!$this->isNewID($ID)) {
         if ($this->fields["date_mod"]) {
             echo "<br>";
             printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
         }
     }
     if ($canedit) {
         echo "<input type='hidden' name='ranking' value='" . $this->fields["ranking"] . "'>";
         echo "<input type='hidden' name='sub_type' value='" . get_class($this) . "'>";
     }
     echo "</td></tr>\n";
     if ($canedit) {
         if ($ID > 0) {
             if ($plugin = isPluginItemType($this->getType())) {
                 $url = $CFG_GLPI["root_doc"] . "/plugins/" . strtolower($plugin['plugin']);
             } else {
                 $url = $CFG_GLPI["root_doc"];
             }
             echo "<tr><td class='tab_bg_2 center' colspan='4'>";
             echo "<a class='vsubmit' href='#' onClick=\"" . Html::jsGetElementbyID('ruletest' . $rand) . ".dialog('open');\">" . _x('button', 'Test') . "</a>";
             Ajax::createIframeModalWindow('ruletest' . $rand, $url . "/front/rule.test.php?" . "sub_type=" . $this->getType() . "&rules_id=" . $this->fields["id"], array('title' => _x('button', 'Test')));
             echo "</td></tr>\n";
         }
     }
     $this->showFormButtons($options);
     return true;
 }
예제 #21
0
 /**
  * Register new task for plugin (called by plugin during install)
  *
  * @param $itemtype        itemtype of the plugin object
  * @param $name            of the task
  * @param $frequency       of execution
  * @param $options   array of optional options
  *       (state, mode, allowmode, hourmin, hourmax, logs_lifetime, param, comment)
  *
  * @return bool for success
  **/
 public static function Register($itemtype, $name, $frequency, $options = array())
 {
     // Check that hook exists
     if (!isPluginItemType($itemtype)) {
         return false;
     }
     $temp = new self();
     // Avoid duplicate entry
     if ($temp->getFromDBbyName($itemtype, $name)) {
         return false;
     }
     $input = array('itemtype' => $itemtype, 'name' => $name, 'allowmode' => self::MODE_INTERNAL | self::MODE_EXTERNAL, 'frequency' => $frequency);
     foreach (array('allowmode', 'comment', 'hourmax', 'hourmin', 'logs_lifetime', 'mode', 'param', 'state') as $key) {
         if (isset($options[$key])) {
             $input[$key] = $options[$key];
         }
     }
     if (defined('GLPI_SYSTEM_CRON') && $input['allowmode'] & self::MODE_EXTERNAL && !isset($input['mode'])) {
         // Downstream packages may provide a good system cron
         $input['mode'] = self::MODE_EXTERNAL;
     }
     return $temp->add($input);
 }
예제 #22
0
                // Standard datatype usage
                if (!$display && isset($searchopt['datatype'])) {
                    switch ($searchopt['datatype']) {
                        case "date":
                        case "date_delay":
                        case "datetime":
                            $options2['relative_dates'] = true;
                            break;
                    }
                }
                $out = $item->getValueToSelect($searchopt, $inputname, $_POST['value'], $options2);
                if (strlen($out)) {
                    echo $out;
                    $display = true;
                }
                //Could display be handled by a plugin ?
                if (!$display && ($plug = isPluginItemType(getItemTypeForTable($searchopt['table'])))) {
                    $function = 'plugin_' . $plug['plugin'] . '_searchOptionsValues';
                    if (function_exists($function)) {
                        $params = array('name' => $inputname, 'searchtype' => $_POST['searchtype'], 'searchoption' => $searchopt, 'value' => $_POST['value']);
                        $display = $function($params);
                    }
                }
            }
            break;
    }
    // Default case : text field
    if (!$display) {
        echo "<input type='text' size='13' name='{$inputname}' value=\"" . Html::cleanInputText($_POST['value']) . "\">";
    }
}
예제 #23
0
                switch ($params["type"]) {
                    case "comp_champ":
                        $val = Stat::getItems($_GET["itemtype"], $params["date1"], $params["date2"], $params["dropdown"]);
                        Stat::showTable($_GET["itemtype"], $params["type"], $params["date1"], $params["date2"], $params["start"], $val, $params["dropdown"]);
                        break;
                    case "device":
                        $val = Stat::getItems($_GET["itemtype"], $params["date1"], $params["date2"], $params["dropdown"]);
                        Stat::showTable($_GET["itemtype"], $params["type"], $params["date1"], $params["date2"], $params["start"], $val, $params["dropdown"]);
                        break;
                    default:
                        $val2 = isset($params['value2']) ? $params['value2'] : 0;
                        $val = Stat::getItems($_GET["itemtype"], $params["date1"], $params["date2"], $params["type"], $val2);
                        Stat::showTable($_GET["itemtype"], $params["type"], $params["date1"], $params["date2"], $params["start"], $val, $val2);
                }
            } else {
                if (isset($_GET["type"]) && $_GET["type"] == "hardwares") {
                    Stat::showItems("", $_GET["date1"], $_GET["date2"], $_GET['start']);
                }
            }
            break;
        default:
            // Plugin case
            if ($plug = isPluginItemType($_GET["item_type"])) {
                if (Plugin::doOneHook($plug['plugin'], 'dynamicReport', $_GET)) {
                    exit;
                }
            }
            $params = Search::manageParams($_GET["item_type"], $_GET);
            Search::showList($_GET["item_type"], $params);
    }
}
예제 #24
0
 /**
  * Show the rule
  *
  * @param $ID              ID of the rule
  * @param $options   array of possible options:
  *     - target filename : where to go when done.
  *     - withtemplate boolean : template or basic item
  *
  * @return nothing
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     if (!$this->isNewID($ID)) {
         $this->check($ID, 'r');
     } else {
         // Create item
         $this->checkGlobal('w');
     }
     $canedit = $this->can(static::$right, "w");
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Name') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "name");
     echo "</td>";
     echo "<td>" . __('Description') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "description");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Logical operator') . "</td>";
     echo "<td>";
     $this->dropdownRulesMatch(array('value' => $this->fields["match"]));
     echo "</td>";
     echo "<td>" . __('Active') . "</td>";
     echo "<td>";
     Dropdown::showYesNo("is_active", $this->fields["is_active"]);
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Comments') . "</td>";
     echo "<td class='middle' colspan='3'>";
     echo "<textarea cols='110' rows='3' name='comment' >" . $this->fields["comment"] . "</textarea>";
     if (!$this->isNewID($ID)) {
         if ($this->fields["date_mod"]) {
             echo "<br>";
             printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
         }
     }
     echo "</td></tr>\n";
     if ($canedit) {
         echo "<input type='hidden' name='ranking' value='" . $this->fields["ranking"] . "'>";
         echo "<input type='hidden' name='sub_type' value='" . get_class($this) . "'>";
         if ($ID > 0) {
             if ($plugin = isPluginItemType($this->getType())) {
                 $url = $CFG_GLPI["root_doc"] . "/plugins/" . strtolower($plugin['plugin']);
             } else {
                 $url = $CFG_GLPI["root_doc"];
             }
             echo "<tr><td class='tab_bg_2 center' colspan='4'>";
             echo "<a class='vsubmit' href='#' onClick=\"var w=window.open('" . $url . "/front/popup.php?popup=test_rule&amp;sub_type=" . $this->getType() . "&amp;rules_id=" . $this->fields["id"] . "' ,'glpipopup', 'height=400," . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">" . __('Test') . "</a>";
             echo "</td></tr>\n";
         }
     }
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
예제 #25
0
 /**
  * Generic Function to display Items
  *
  * @param $itemtype              item type
  * @param $ID                    ID of the SEARCH_OPTION item
  * @param $data            array containing data results
  * @param $num                   item num in the request
  * @param $meta                  is a meta item ? (default 0)
  * @param $addobjectparams array added parameters for union search
  *
  * @return string to print
  **/
 static function giveItem($itemtype, $ID, array $data, $num, $meta = 0, array $addobjectparams = array())
 {
     global $CFG_GLPI, $DB;
     $searchopt =& self::getOptions($itemtype);
     if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) {
         if (isset($searchopt[$ID]['addobjectparams']) && $searchopt[$ID]['addobjectparams']) {
             return self::giveItem($data["TYPE"], $ID, $data, $num, $meta, $searchopt[$ID]['addobjectparams']);
         }
         return self::giveItem($data["TYPE"], $ID, $data, $num, $meta);
     }
     if (count($addobjectparams)) {
         $searchopt[$ID] = array_merge($searchopt[$ID], $addobjectparams);
     }
     // Plugin can override core definition for its type
     if ($plug = isPluginItemType($itemtype)) {
         $function = 'plugin_' . $plug['plugin'] . '_giveItem';
         if (function_exists($function)) {
             $out = $function($itemtype, $ID, $data, $num);
             if (!empty($out)) {
                 return $out;
             }
         }
     }
     $NAME = "ITEM_";
     //       if ($meta) {
     //          $NAME = "META_";
     //       }
     if (isset($searchopt[$ID]["table"])) {
         $table = $searchopt[$ID]["table"];
         $field = $searchopt[$ID]["field"];
         $linkfield = $searchopt[$ID]["linkfield"];
         /// TODO try to clean all specific cases using SpecificToDisplay
         switch ($table . '.' . $field) {
             case "glpi_users.name":
                 // USER search case
                 if ($itemtype != 'User' && isset($searchopt[$ID]["forcegroupby"]) && $searchopt[$ID]["forcegroupby"]) {
                     $out = "";
                     $count_display = 0;
                     $added = array();
                     $showuserlink = 0;
                     if (Session::haveRight('user', READ)) {
                         $showuserlink = 1;
                     }
                     for ($k = 0; $k < $data[$num]['count']; $k++) {
                         if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0 || isset($data[$num][$k][2]) && $data[$num][$k][2] != '') {
                             if ($count_display) {
                                 $out .= self::LBBR;
                             }
                             if ($itemtype == 'Ticket') {
                                 if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0) {
                                     $userdata = getUserName($data[$num][$k]['name'], 2);
                                     $tooltip = "";
                                     if (Session::haveRight('user', READ)) {
                                         $tooltip = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                                     }
                                     $out .= sprintf(__('%1$s %2$s'), $userdata['name'], $tooltip);
                                     $count_display++;
                                 }
                             } else {
                                 $out .= getUserName($data[$num][$k]['name'], $showuserlink);
                                 $count_display++;
                             }
                             // Manage alternative_email for tickets_users
                             if ($itemtype == 'Ticket' && isset($data[$num][$k][2])) {
                                 $split = explode(self::LONGSEP, $data[$num][$k][2]);
                                 for ($l = 0; $l < count($split); $l++) {
                                     $split2 = explode(" ", $split[$l]);
                                     if (count($split2) == 2 && $split2[0] == 0 && !empty($split2[1])) {
                                         if ($count_display) {
                                             $out .= self::LBBR;
                                         }
                                         $count_display++;
                                         $out .= "<a href='mailto:" . $split2[1] . "'>" . $split2[1] . "</a>";
                                     }
                                 }
                             }
                         }
                     }
                     return $out;
                 }
                 if ($itemtype != 'User') {
                     $toadd = '';
                     if ($itemtype == 'Ticket' && $data[$num][0]['id'] > 0) {
                         $userdata = getUserName($data[$num][0]['id'], 2);
                         $toadd = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                     }
                     $usernameformat = formatUserName($data[$num][0]['id'], $data[$num][0]['name'], $data[$num][0]['realname'], $data[$num][0]['firstname'], 1);
                     return sprintf(__('%1$s %2$s'), $usernameformat, $toadd);
                 }
                 break;
             case "glpi_profiles.name":
                 if ($itemtype == 'User' && $ID == 20) {
                     $out = "";
                     $count_display = 0;
                     $added = array();
                     for ($k = 0; $k < $data[$num]['count']; $k++) {
                         if (strlen(trim($data[$num][$k]['name'])) > 0) {
                             $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_entities', $data[$num][$k]['entities_id']));
                             $comp = '';
                             if ($data[$num][$k]['is_recursive']) {
                                 $comp = __('R');
                                 if ($data[$num][$k]['is_dynamic']) {
                                     $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                                 }
                             }
                             if ($data[$num][$k]['is_dynamic']) {
                                 $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                             }
                             if (!empty($comp)) {
                                 $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                             }
                             if (!in_array($text, $added)) {
                                 if ($count_display) {
                                     $out .= self::LBBR;
                                 }
                                 $count_display++;
                                 $out .= $text;
                                 $added[] = $text;
                             }
                         }
                     }
                     return $out;
                 }
                 break;
             case "glpi_entities.completename":
                 if ($itemtype == 'User') {
                     $out = "";
                     $added = array();
                     $count_display = 0;
                     for ($k = 0; $k < $data[$num]['count']; $k++) {
                         if (strlen(trim($data[$num][$k]['name'])) > 0) {
                             $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_profiles', $data[$num][$k]['profiles_id']));
                             $comp = '';
                             if ($data[$num][$k]['is_recursive']) {
                                 $comp = __('R');
                                 if ($data[$num][$k]['is_dynamic']) {
                                     $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                                 }
                             }
                             if ($data[$num][$k]['is_dynamic']) {
                                 $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                             }
                             if (!empty($comp)) {
                                 $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                             }
                             if (!in_array($text, $added)) {
                                 if ($count_display) {
                                     $out .= self::LBBR;
                                 }
                                 $count_display++;
                                 $out .= $text;
                                 $added[] = $text;
                             }
                         }
                     }
                     return $out;
                 }
                 break;
             case "glpi_documenttypes.icon":
                 if (!empty($data[$num][0]['name'])) {
                     return "<img class='middle' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $data[$num][0]['name'] . "'>";
                 }
                 return "&nbsp;";
             case "glpi_documents.filename":
                 $doc = new Document();
                 if ($doc->getFromDB($data['id'])) {
                     return $doc->getDownloadLink();
                 }
                 return NOT_AVAILABLE;
             case "glpi_tickets_tickets.tickets_id_1":
                 $out = "";
                 $displayed = array();
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     $linkid = $data[$num][$k]['tickets_id_2'] == $data['id'] ? $data[$num][$k]['name'] : $data[$num][$k]['tickets_id_2'];
                     if ($linkid > 0 && !isset($displayed[$linkid])) {
                         $text = "<a ";
                         $text .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id={$linkid}\">";
                         $text .= Dropdown::getDropdownName('glpi_tickets', $linkid) . "</a>";
                         if (count($displayed)) {
                             $out .= self::LBBR;
                         }
                         $displayed[$linkid] = $linkid;
                         $out .= $text;
                     }
                 }
                 return $out;
             case "glpi_problems.id":
                 if ($searchopt[$ID]["datatype"] == 'count') {
                     if ($data[$num][0]['name'] > 0 && Session::haveRight("problem", Problem::READALL)) {
                         if ($itemtype == 'ITILCategory') {
                             $options['criteria'][0]['field'] = 7;
                             $options['criteria'][0]['searchtype'] = 'equals';
                             $options['criteria'][0]['value'] = $data['id'];
                             $options['criteria'][0]['link'] = 'AND';
                         } else {
                             $options['criteria'][0]['field'] = 12;
                             $options['criteria'][0]['searchtype'] = 'equals';
                             $options['criteria'][0]['value'] = 'all';
                             $options['criteria'][0]['link'] = 'AND';
                             $options['metacriteria'][0]['itemtype'] = $itemtype;
                             $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name');
                             $options['metacriteria'][0]['searchtype'] = 'equals';
                             $options['metacriteria'][0]['value'] = $data['id'];
                             $options['metacriteria'][0]['link'] = 'AND';
                         }
                         $options['reset'] = 'reset';
                         $out = "<a id='problem{$itemtype}" . $data['id'] . "' ";
                         $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/problem.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                         $out .= $data[$num][0]['name'] . "</a>";
                         return $out;
                     }
                 }
                 break;
             case "glpi_tickets.id":
                 if ($searchopt[$ID]["datatype"] == 'count') {
                     if ($data[$num][0]['name'] > 0 && Session::haveRight("ticket", Ticket::READALL)) {
                         if ($itemtype == 'User') {
                             // Requester
                             if ($ID == 60) {
                                 $options['criteria'][0]['field'] = 4;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = $data['id'];
                                 $options['criteria'][0]['link'] = 'AND';
                             }
                             // Writer
                             if ($ID == 61) {
                                 $options['criteria'][0]['field'] = 22;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = $data['id'];
                                 $options['criteria'][0]['link'] = 'AND';
                             }
                             // Assign
                             if ($ID == 64) {
                                 $options['criteria'][0]['field'] = 5;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = $data['id'];
                                 $options['criteria'][0]['link'] = 'AND';
                             }
                         } else {
                             if ($itemtype == 'ITILCategory') {
                                 $options['criteria'][0]['field'] = 7;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = $data['id'];
                                 $options['criteria'][0]['link'] = 'AND';
                             } else {
                                 $options['criteria'][0]['field'] = 12;
                                 $options['criteria'][0]['searchtype'] = 'equals';
                                 $options['criteria'][0]['value'] = 'all';
                                 $options['criteria'][0]['link'] = 'AND';
                                 $options['metacriteria'][0]['itemtype'] = $itemtype;
                                 $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name');
                                 $options['metacriteria'][0]['searchtype'] = 'equals';
                                 $options['metacriteria'][0]['value'] = $data['id'];
                                 $options['metacriteria'][0]['link'] = 'AND';
                             }
                         }
                         $options['reset'] = 'reset';
                         $out = "<a id='ticket{$itemtype}" . $data['id'] . "' ";
                         $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                         $out .= $data[$num][0]['name'] . "</a>";
                         return $out;
                     }
                 }
                 break;
             case "glpi_tickets.due_date":
             case "glpi_problems.due_date":
             case "glpi_changes.due_date":
                 // Due date + progress
                 if ($ID == 151) {
                     $out = Html::convDate($data[$num][0]['name']);
                     // No due date in waiting status
                     if ($data[$num][0]['status'] == CommonITILObject::WAITING) {
                         return '';
                     }
                     if (empty($data[$num][0]['name'])) {
                         return '';
                     }
                     if ($data[$num][0]['status'] == Ticket::SOLVED || $data[$num][0]['status'] == Ticket::CLOSED) {
                         return $out;
                     }
                     $itemtype = getItemTypeForTable($table);
                     $item = new $itemtype();
                     $item->getFromDB($data['id']);
                     $percentage = 0;
                     $totaltime = 0;
                     $currenttime = 0;
                     if ($item->isField('slas_id') && $item->fields['slas_id'] != 0) {
                         // Have SLA
                         $sla = new SLA();
                         $sla->getFromDB($item->fields['slas_id']);
                         $currenttime = $sla->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s'));
                         $totaltime = $sla->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']);
                     } else {
                         $calendars_id = Entity::getUsedConfig('calendars_id', $item->fields['entities_id']);
                         if ($calendars_id != 0) {
                             // Ticket entity have calendar
                             $calendar = new Calendar();
                             $calendar->getFromDB($calendars_id);
                             $currenttime = $calendar->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s'));
                             $totaltime = $calendar->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']);
                         } else {
                             // No calendar
                             $currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($item->fields['date']);
                             $totaltime = strtotime($data[$num][0]['name']) - strtotime($item->fields['date']);
                         }
                     }
                     if ($totaltime != 0) {
                         $percentage = round(100 * $currenttime / $totaltime);
                     } else {
                         // Total time is null : no active time
                         $percentage = 100;
                     }
                     if ($percentage > 100) {
                         $percentage = 100;
                     }
                     $percentage_text = $percentage;
                     if ($_SESSION['glpiduedatewarning_unit'] == '%') {
                         $less_warn_limit = $_SESSION['glpiduedatewarning_less'];
                         $less_warn = 100 - $percentage;
                     } else {
                         if ($_SESSION['glpiduedatewarning_unit'] == 'hour') {
                             $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP;
                             $less_warn = $totaltime - $currenttime;
                         } else {
                             if ($_SESSION['glpiduedatewarning_unit'] == 'day') {
                                 $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * DAY_TIMESTAMP;
                                 $less_warn = $totaltime - $currenttime;
                             }
                         }
                     }
                     if ($_SESSION['glpiduedatecritical_unit'] == '%') {
                         $less_crit_limit = $_SESSION['glpiduedatecritical_less'];
                         $less_crit = 100 - $percentage;
                     } else {
                         if ($_SESSION['glpiduedatecritical_unit'] == 'hour') {
                             $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * HOUR_TIMESTAMP;
                             $less_crit = $totaltime - $currenttime;
                         } else {
                             if ($_SESSION['glpiduedatecritical_unit'] == 'day') {
                                 $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * DAY_TIMESTAMP;
                                 $less_crit = $totaltime - $currenttime;
                             }
                         }
                     }
                     $color = $_SESSION['glpiduedateok_color'];
                     if ($less_crit < $less_crit_limit) {
                         $color = $_SESSION['glpiduedatecritical_color'];
                     } else {
                         if ($less_warn < $less_warn_limit) {
                             $color = $_SESSION['glpiduedatewarning_color'];
                         }
                     }
                     //Calculate bar progress
                     $out .= "<div class='center' style='background-color: #ffffff; width: 100%;\n                            border: 1px solid #9BA563; position: relative;' >";
                     $out .= "<div style='position:absolute;'>&nbsp;" . $percentage_text . "%</div>";
                     $out .= "<div class='center' style='background-color: " . $color . ";\n                            width: " . $percentage . "%; height: 12px' ></div>";
                     $out .= "</div>";
                     return $out;
                 }
                 break;
             case "glpi_softwarelicenses.number":
                 if ($data[$num][0]['min'] == -1) {
                     return __('Unlimited');
                 }
                 if (empty($data[$num][0]['name'])) {
                     return 0;
                 }
                 return $data[$num][0]['name'];
             case "glpi_auth_tables.name":
                 return Auth::getMethodName($data[$num][0]['name'], $data[$num][0]['auths_id'], 1, $data[$num][0]['ldapname'] . $data[$num][0]['mailname']);
             case "glpi_reservationitems.comment":
                 if (empty($data[$num][0]['name'])) {
                     return "<a title=\"" . __s('Modify the comment') . "\"\n                           href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' >" . __('None') . "</a>";
                 }
                 return "<a title=\"" . __s('Modify the comment') . "\"\n                        href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' >" . Html::resume_text($data[$num][0]['name']) . "</a>";
             case 'glpi_crontasks.description':
                 $tmp = new CronTask();
                 return $tmp->getDescription($data[$num][0]['name']);
             case 'glpi_changes.status':
                 $status = Change::getStatus($data[$num][0]['name']);
                 return "<img src=\"" . Change::getStatusIconURL($data[$num][0]['name']) . "\"\n                        alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
             case 'glpi_problems.status':
                 $status = Problem::getStatus($data[$num][0]['name']);
                 return "<img src=\"" . Problem::getStatusIconURL($data[$num][0]['name']) . "\"\n                        alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
             case 'glpi_tickets.status':
                 $status = Ticket::getStatus($data[$num][0]['name']);
                 return "<img src=\"" . Ticket::getStatusIconURL($data[$num][0]['name']) . "\"\n                        alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
             case 'glpi_projectstates.name':
                 $out = '';
                 $query = "SELECT `color`\n                         FROM `glpi_projectstates`\n                         WHERE `name` = '" . $data[$num][0]['name'] . "'";
                 foreach ($DB->request($query) as $color) {
                     $color = $color['color'];
                     $out = "<div style=\"background-color:" . $color . ";\">";
                     $name = $data[$num][0]['name'];
                     if (isset($data[$num][0]['trans'])) {
                         $name = $data[$num][0]['trans'];
                     }
                     if ($itemtype == 'ProjectState') {
                         $out .= "<a href='" . $CFG_GLPI["root_doc"] . "/front/projectstate.form.php?id=" . $data[$num][0]["id"] . "'>" . $name . "</a></div>";
                     } else {
                         $out .= $name . "</div>";
                     }
                 }
                 return $out;
             case 'glpi_items_tickets.items_id':
             case 'glpi_items_problems.items_id':
                 if (!empty($data[$num])) {
                     $items = array();
                     foreach ($data[$num] as $key => $val) {
                         if (is_numeric($key)) {
                             if (!empty($val['itemtype']) && ($item = getItemForItemtype($val['itemtype']))) {
                                 if ($item->getFromDB($val['name'])) {
                                     $items[] = $item->getLink(array('comments' => true));
                                 }
                             }
                         }
                     }
                     if (!empty($items)) {
                         return implode("<br>", $items);
                     }
                 }
                 return '&nbsp;';
             case 'glpi_items_tickets.itemtype':
             case 'glpi_items_problems.itemtype':
                 if (!empty($data[$num])) {
                     $itemtypes = array();
                     foreach ($data[$num] as $key => $val) {
                         if (is_numeric($key)) {
                             if (!empty($val['name'])) {
                                 if (substr($val['name'], 0, 6) == 'Plugin') {
                                     $plug = new $val['name']();
                                     $name = $plug->getTypeName();
                                     $itemtypes[] = __($name);
                                 } else {
                                     $itemtypes[] = __($val['name']);
                                 }
                             }
                         }
                     }
                     if (!empty($itemtypes)) {
                         return implode("<br>", $itemtypes);
                     }
                 }
                 return '&nbsp;';
             case 'glpi_tickets.name':
             case 'glpi_problems.name':
             case 'glpi_changes.name':
                 if (isset($data[$num][0]['content']) && isset($data[$num][0]['id']) && isset($data[$num][0]['status'])) {
                     $link = Toolbox::getItemTypeFormURL($itemtype);
                     $out = "<a id='{$itemtype}" . $data[$num][0]['id'] . "' href=\"" . $link;
                     $out .= strstr($link, '?') ? '&amp;' : '?';
                     $out .= 'id=' . $data[$num][0]['id'];
                     // Force solution tab if solved
                     if ($item = getItemForItemtype($itemtype)) {
                         if (in_array($data[$num][0]['status'], $item->getSolvedStatusArray())) {
                             $out .= "&amp;forcetab={$itemtype}\$2";
                         }
                     }
                     $out .= "\">";
                     $name = $data[$num][0]['name'];
                     if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][0]['name'])) {
                         $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][0]['id']);
                     }
                     $out .= $name . "</a>";
                     $hdecode = Html::entity_decode_deep($data[$num][0]['content']);
                     $content = Toolbox::unclean_cross_side_scripting_deep($hdecode);
                     $out = sprintf(__('%1$s %2$s'), $out, Html::showToolTip(nl2br(Html::Clean($content)), array('applyto' => $itemtype . $data[$num][0]['id'], 'display' => false)));
                     return $out;
                 }
             case 'glpi_ticketvalidations.status':
                 $out = '';
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if ($data[$num][$k]['name']) {
                         $status = TicketValidation::getStatus($data[$num][$k]['name']);
                         $bgcolor = TicketValidation::getStatusColor($data[$num][$k]['name']);
                         $out .= (empty($out) ? '' : self::LBBR) . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>';
                     }
                 }
                 return $out;
             case 'glpi_ticketsatisfactions.satisfaction':
                 if (self::$output_type == self::HTML_OUTPUT) {
                     return TicketSatisfaction::displaySatisfaction($data[$num][0]['name']);
                 }
                 break;
             case 'glpi_projects._virtual_planned_duration':
                 return Html::timestampToString(ProjectTask::getTotalPlannedDurationForProject($data["id"]), false);
             case 'glpi_projects._virtual_effective_duration':
                 return Html::timestampToString(ProjectTask::getTotalEffectiveDurationForProject($data["id"]), false);
             case 'glpi_cartridgeitems._virtual':
                 return Cartridge::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT);
             case 'glpi_printers._virtual':
                 return Cartridge::getCountForPrinter($data["id"], self::$output_type != self::HTML_OUTPUT);
             case 'glpi_consumableitems._virtual':
                 return Consumable::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT);
             case 'glpi_links._virtual':
                 $out = '';
                 $link = new Link();
                 if (($item = getItemForItemtype($itemtype)) && $item->getFromDB($data['id']) && $link->getfromDB($data[$num][0]['id']) && $item->fields['entities_id'] == $link->fields['entities_id']) {
                     if (count($data[$num])) {
                         $count_display = 0;
                         foreach ($data[$num] as $val) {
                             if (is_array($val)) {
                                 $links = Link::getAllLinksFor($item, $val);
                                 foreach ($links as $link) {
                                     if ($count_display) {
                                         $out .= self::LBBR;
                                     }
                                     $out .= $link;
                                     $count_display++;
                                 }
                             }
                         }
                     }
                 }
                 return $out;
             case 'glpi_reservationitems._virtual':
                 if ($data[$num][0]['is_active']) {
                     return "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . __s('See planning') . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>";
                 } else {
                     return "&nbsp;";
                 }
         }
     }
     //// Default case
     // Link with plugin tables : need to know left join structure
     if (isset($table)) {
         if (preg_match("/^glpi_plugin_([a-z0-9]+)/", $table . '.' . $field, $matches)) {
             if (count($matches) == 2) {
                 $plug = $matches[1];
                 $function = 'plugin_' . $plug . '_giveItem';
                 if (function_exists($function)) {
                     $out = $function($itemtype, $ID, $data, $num);
                     if (!empty($out)) {
                         return $out;
                     }
                 }
             }
         }
     }
     $unit = '';
     if (isset($searchopt[$ID]['unit'])) {
         $unit = $searchopt[$ID]['unit'];
     }
     // Preformat items
     if (isset($searchopt[$ID]["datatype"])) {
         switch ($searchopt[$ID]["datatype"]) {
             case "itemlink":
                 $linkitemtype = getItemTypeForTable($searchopt[$ID]["table"]);
                 $out = "";
                 $count_display = 0;
                 $separate = self::LBBR;
                 if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                     $separate = self::LBHR;
                 }
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (isset($data[$num][$k]['id'])) {
                         if ($count_display) {
                             $out .= $separate;
                         }
                         $count_display++;
                         $page = $linkitemtype::getFormUrl();
                         $page .= strpos($page, '?') ? '&id' : '?id';
                         $name = Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit);
                         if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][$k]['name'])) {
                             $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][$k]['id']);
                         }
                         $out .= "<a id='" . $linkitemtype . "_" . $data['id'] . "_" . $data[$num][$k]['id'] . "' href='{$page}=" . $data[$num][$k]['id'] . "'>" . $name . "</a>";
                     }
                 }
                 return $out;
             case "text":
                 $separate = self::LBBR;
                 if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                     $separate = self::LBHR;
                 }
                 $out = '';
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (strlen(trim($data[$num][$k]['name'])) > 0) {
                         if ($count_display) {
                             $out .= $separate;
                         }
                         $count_display++;
                         $text = "";
                         if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) {
                             $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep(nl2br($data[$num][$k]['name'])));
                         } else {
                             $text = nl2br($data[$num][$k]['name']);
                         }
                         if (self::$output_type == self::HTML_OUTPUT && Toolbox::strlen($text) > $CFG_GLPI['cut']) {
                             $rand = mt_rand();
                             $out .= sprintf(__('%1$s %2$s'), "<span id='text{$rand}'>" . Html::resume_text($text, $CFG_GLPI['cut']) . '</span>', Html::showToolTip($text, array('applyto' => "text{$rand}", 'display' => false)));
                         } else {
                             $out .= $text;
                         }
                     }
                 }
                 return $out;
             case "date":
             case "date_delay":
                 $out = '';
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) {
                         $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel'];
                     } else {
                         $out .= (empty($out) ? '' : self::LBBR) . Html::convDate($data[$num][$k]['name']);
                     }
                 }
                 return $out;
             case "datetime":
                 $out = '';
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) {
                         $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel'];
                     } else {
                         $out .= (empty($out) ? '' : self::LBBR) . Html::convDateTime($data[$num][$k]['name']);
                     }
                 }
                 return $out;
             case "timestamp":
                 $withseconds = false;
                 if (isset($searchopt[$ID]['withseconds'])) {
                     $withseconds = $searchopt[$ID]['withseconds'];
                 }
                 $withdays = true;
                 if (isset($searchopt[$ID]['withdays'])) {
                     $withdays = $searchopt[$ID]['withdays'];
                 }
                 $out = '';
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     $out .= (empty($out) ? '' : '<br>') . Html::timestampToString($data[$num][$k]['name'], $withseconds, $withdays);
                 }
                 return $out;
             case "email":
                 $out = '';
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if ($count_display) {
                         $out .= self::LBBR;
                     }
                     $count_display++;
                     if (!empty($data[$num][$k]['name'])) {
                         $out .= empty($out) ? '' : self::LBBR;
                         $out .= "<a href='mailto:" . $data[$num][$k]['name'] . "'>" . $data[$num][$k]['name'];
                         $out .= "</a>";
                     }
                 }
                 return empty($out) ? "&nbsp;" : $out;
             case "weblink":
                 $orig_link = trim($data[$num][0]['name']);
                 if (!empty($orig_link)) {
                     // strip begin of link
                     $link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link);
                     $link = preg_replace('/\\/$/', '', $link);
                     if (Toolbox::strlen($link) > $CFG_GLPI["url_maxlength"]) {
                         $link = Toolbox::substr($link, 0, $CFG_GLPI["url_maxlength"]) . "...";
                     }
                     return "<a href=\"" . formatOutputWebLink($orig_link) . "\" target='_blank'>{$link}</a>";
                 }
                 return "&nbsp;";
             case "count":
             case "number":
                 $out = "";
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (strlen(trim($data[$num][$k]['name'])) > 0) {
                         if ($count_display) {
                             $out .= self::LBBR;
                         }
                         $count_display++;
                         if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) {
                             $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']];
                         } else {
                             $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$num][$k]['name'], false, 0));
                             $out .= Dropdown::getValueWithUnit($number, $unit);
                         }
                     }
                 }
                 return $out;
             case "decimal":
                 $out = "";
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (strlen(trim($data[$num][$k]['name'])) > 0) {
                         if ($count_display) {
                             $out .= self::LBBR;
                         }
                         $count_display++;
                         if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) {
                             $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']];
                         } else {
                             $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$num][$k]['name']));
                             $out .= Dropdown::getValueWithUnit($number, $unit);
                         }
                     }
                 }
                 return $out;
             case "bool":
                 $out = "";
                 $count_display = 0;
                 for ($k = 0; $k < $data[$num]['count']; $k++) {
                     if (strlen(trim($data[$num][$k]['name'])) > 0) {
                         if ($count_display) {
                             $out .= self::LBBR;
                         }
                         $count_display++;
                         $out .= Dropdown::getValueWithUnit(Dropdown::getYesNo($data[$num][$k]['name']), $unit);
                     }
                 }
                 return $out;
             case "itemtypename":
                 if ($obj = getItemForItemtype($data[$num][0]['name'])) {
                     return $obj->getTypeName();
                 }
                 return "";
             case "language":
                 if (isset($CFG_GLPI['languages'][$data[$num][0]['name']])) {
                     return $CFG_GLPI['languages'][$data[$num][0]['name']][0];
                 }
                 return __('Default value');
         }
     }
     // Manage items with need group by / group_concat
     $out = "";
     $count_display = 0;
     $separate = self::LBBR;
     if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
         $separate = self::LBHR;
     }
     for ($k = 0; $k < $data[$num]['count']; $k++) {
         if (strlen(trim($data[$num][$k]['name'])) > 0) {
             if ($count_display) {
                 $out .= $separate;
             }
             $count_display++;
             // Get specific display if available
             $itemtype = getItemTypeForTable($table);
             if ($item = getItemForItemtype($itemtype)) {
                 $tmpdata = $data[$num][$k];
                 // Copy name to real field
                 $tmpdata[$field] = $data[$num][$k]['name'];
                 $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true, 'searchopt' => $searchopt[$ID]));
             }
             if (!empty($specific)) {
                 $out .= $specific;
             } else {
                 if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) {
                     $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']];
                 } else {
                     // Empty is 0 or empty
                     if (empty($split[0]) && isset($searchopt[$ID]['emptylabel'])) {
                         $out .= $searchopt[$ID]['emptylabel'];
                     } else {
                         // Trans field exists
                         if (isset($data[$num][$k]['trans']) && !empty($data[$num][$k]['trans'])) {
                             $out .= Dropdown::getValueWithUnit($data[$num][$k]['trans'], $unit);
                         } else {
                             $out .= Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit);
                         }
                     }
                 }
             }
         }
     }
     return $out;
     // Trans in group concat
     if (count($split) == 3 && !empty($split[1])) {
         return Dropdown::getValueWithUnit($split[1], $unit);
     }
     return Dropdown::getValueWithUnit($split[0], $unit);
 }
예제 #26
0
 /**
  * Check if it's possible to assign ticket to a type (core or plugin)
  *
  * @param $itemtype the object's type
  *
  * @return true if ticket can be assign to this type, false if not
  **/
 static function isPossibleToAssignType($itemtype)
 {
     global $PLUGIN_HOOKS;
     // Plugin case
     if (isPluginItemType($itemtype)) {
         /// TODO maybe only check plugin of itemtype ?
         //If it's not a core's type, then check plugins
         $types = array();
         if (isset($PLUGIN_HOOKS['assign_to_ticket'])) {
             foreach ($PLUGIN_HOOKS['assign_to_ticket'] as $plugin => $value) {
                 $types = doOneHook($plugin, 'AssignToTicket', $types);
             }
             if (array_key_exists($itemtype, $types)) {
                 return true;
             }
         }
         // standard case
     } else {
         if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) {
             return true;
         }
     }
     return false;
 }
예제 #27
0
/**
 * To load classes
 *
 * @param $classname : class to load
**/
function glpi_autoload($classname)
{
    global $DEBUG_AUTOLOAD, $CFG_GLPI;
    static $notfound = array('xStates' => true, 'xAllAssets' => true);
    // empty classname or non concerted plugin or classname containing dot (leaving GLPI main treee)
    if (empty($classname) || is_numeric($classname) || strpos($classname, '.') !== false) {
        die("Security die. trying to load an forbidden class name");
    }
    $dir = GLPI_ROOT . "/inc/";
    if ($plug = isPluginItemType($classname)) {
        $plugname = strtolower($plug['plugin']);
        $dir = GLPI_ROOT . "/plugins/{$plugname}/inc/";
        $item = strtolower($plug['class']);
        // Is the plugin activate ?
        // Command line usage of GLPI : need to do a real check plugin activation
        if (isCommandLine()) {
            $plugin = new Plugin();
            if (count($plugin->find("directory='{$plugname}' AND state=" . Plugin::ACTIVATED)) == 0) {
                // Plugin does not exists or not activated
                return false;
            }
        } else {
            // Standard use of GLPI
            if (!isset($_SESSION['glpi_plugins']) || !in_array($plugname, $_SESSION['glpi_plugins'])) {
                // Plugin not activated
                return false;
            }
        }
    } else {
        //TODO: clean, seems uneeded, as composer autoloader is used first
        // Do not try to load phpcas using GLPI autoload
        //if (preg_match('/^CAS_.*/', $classname)) {
        //   return false;
        //}
        // Do not try to load Zend using GLPI autoload
        //if (preg_match('/^Zend.*/', $classname)) {
        //   return false;
        //}
        // Do not try to load Simplepie using GLPI autoload
        //if (preg_match('/^SimplePie.*/', $classname)) {
        //   return false;
        //}
        $item = strtolower($classname);
    }
    if (file_exists("{$dir}{$item}.class.php")) {
        include_once "{$dir}{$item}.class.php";
        if (isset($_SESSION['glpi_use_mode']) && $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
            $DEBUG_AUTOLOAD[] = $classname;
        }
    } else {
        if (!isset($notfound["x{$classname}"])) {
            // trigger an error to get a backtrace, but only once (use prefix 'x' to handle empty case)
            // trigger_error("GLPI autoload : file $dir$item.class.php not founded trying to load class '$classname'");
            $notfound["x{$classname}"] = true;
        }
    }
}
예제 #28
0
function plugin_genericobject_uninstall()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/genericobject/inc/type.class.php";
    //For each type
    foreach (PluginGenericobjectType::getTypes(true) as $tmp => $value) {
        $itemtype = $value['itemtype'];
        if (class_exists($itemtype)) {
            $itemtype::uninstall();
        }
    }
    foreach (array('PluginGenericobjectType', 'PluginGenericobjectProfile', 'PluginGenericobjectField', 'PluginGenericobjectTypeFamily') as $itemtype) {
        if ($plug = isPluginItemType($itemtype)) {
            $plugname = strtolower($plug['plugin']);
            $dir = GLPI_ROOT . "/plugins/{$plugname}/inc/";
            $item = strtolower($plug['class']);
            if (file_exists("{$dir}{$item}.class.php")) {
                include_once "{$dir}{$item}.class.php";
                $itemtype::uninstall();
            }
        }
    }
    return true;
}
예제 #29
0
 /**
  * Generic Function to add where to a request
  *
  * @param $link link string
  * @param $nott is it a negative serach ?
  * @param $itemtype item type
  * @param $ID ID of the item to search
  * @param $searchtype searchtype used (equals or contains)
  * @param $val item num in the request
  * @param $meta is a meta search (meta=2 in search.class.php)
  *
  * @return select string
  **/
 static function addWhere($link, $nott, $itemtype, $ID, $searchtype, $val, $meta = 0)
 {
     $searchopt =& Search::getOptions($itemtype);
     $table = $searchopt[$ID]["table"];
     $field = $searchopt[$ID]["field"];
     $inittable = $table;
     $addtable = '';
     /*if ($table != getTableForItemType($itemtype)
           && $searchopt[$ID]["linkfield"] != getForeignKeyFieldForTable($table)) {
          $addtable = "_".$searchopt[$ID]["linkfield"];
          $table .= $addtable;
       }*/
     if (isset($searchopt[$ID]['joinparams'])) {
         $complexjoin = Search::computeComplexJoinID($searchopt[$ID]['joinparams']);
         if (!empty($complexjoin)) {
             $table .= "_" . $complexjoin;
         }
     }
     if ($meta && getTableForItemType($itemtype) != $table) {
         $table .= "_" . $itemtype;
     }
     // Hack to allow search by ID on every sub-table
     if (preg_match('/^\\$\\$\\$\\$([0-9]+)$/', $val, $regs)) {
         return $link . " (`{$table}`.`id` " . ($nott ? "<>" : "=") . $regs[1] . " " . ($regs[1] == 0 ? " OR `{$table}`.`id` IS NULL" : '') . ") ";
     }
     // Preparse value
     if (isset($searchopt[$ID]["datatype"])) {
         switch ($searchopt[$ID]["datatype"]) {
             case "datetime":
             case "date":
             case "date_delay":
                 $format_use = "Y-m-d";
                 if ($searchopt[$ID]["datatype"] == 'datetime') {
                     $format_use = "Y-m-d H:i:s";
                 }
                 // Parsing relative date
                 if ($val == 'NOW') {
                     $val = date($format_use);
                 }
                 if (preg_match("/^(-?)(\\d+)(\\w+)\$/", $val, $matches)) {
                     if (in_array($matches[3], array('YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR'))) {
                         $nb = intval($matches[2]);
                         if ($matches[1] == '-') {
                             $nb = -$nb;
                         }
                         // Use it to have a clean delay computation (MONTH / YEAR have not always the same duration)
                         $hour = date("H");
                         $minute = date("i");
                         $second = 0;
                         $month = date("n");
                         $day = date("j");
                         $year = date("Y");
                         switch ($matches[3]) {
                             case "YEAR":
                                 $year += $nb;
                                 break;
                             case "MONTH":
                                 $month += $nb;
                                 break;
                             case "WEEK":
                                 $day += 7 * $nb;
                                 break;
                             case "DAY":
                                 $day += $nb;
                                 break;
                             case "HOUR":
                                 $hour += $nb;
                                 break;
                         }
                         $val = date($format_use, mktime($hour, $minute, $second, $month, $day, $year));
                     }
                 }
                 break;
         }
     }
     switch ($searchtype) {
         case "contains":
             $SEARCH = Search::makeTextSearch($val, $nott);
             break;
         case "equals":
             if ($nott) {
                 $SEARCH = " <> '{$val}'";
             } else {
                 $SEARCH = " = '{$val}'";
             }
             break;
         case "notequals":
             if ($nott) {
                 $SEARCH = " = '{$val}'";
             } else {
                 $SEARCH = " <> '{$val}'";
             }
             break;
     }
     // Plugin can override core definition for its type
     if ($plug = isPluginItemType($itemtype)) {
         $function = 'plugin_' . $plug['plugin'] . '_addWhere';
         if (function_exists($function)) {
             $out = $function($link, $nott, $itemtype, $ID, $val);
             if (!empty($out)) {
                 return $out;
             }
         }
     }
     switch ($inittable . "." . $field) {
         //          case "glpi_users_validation.name" :
         case "glpi_users.name":
             if ($itemtype == 'User') {
                 // glpi_users case / not link table
                 if (in_array($searchtype, array('equals', 'notequals'))) {
                     return " {$link} `{$table}`.`id`" . $SEARCH;
                 }
                 return Search::makeTextCriteria("`{$table}`.`{$field}`", $val, $nott, $link);
             }
             if ($_SESSION["glpinames_format"] == FIRSTNAME_BEFORE) {
                 $name1 = 'firstname';
                 $name2 = 'realname';
             } else {
                 $name1 = 'realname';
                 $name2 = 'firstname';
             }
             if (in_array($searchtype, array('equals', 'notequals'))) {
                 return " {$link} (`{$table}`.`id`" . $SEARCH . ($val == 0 ? " OR `{$table}`.`id` IS NULL" : '') . ') ';
             }
             return $link . " (`{$table}`.`{$name1}` {$SEARCH}\n                            OR `{$table}`.`{$name2}` {$SEARCH}\n                            OR CONCAT(`{$table}`.`{$name1}`, ' ',\n                                      `{$table}`.`{$name2}`) {$SEARCH}" . Search::makeTextCriteria("`{$table}`.`{$field}`", $val, $nott, 'OR') . ") ";
         case "glpi_groups.name":
             $linkfield = "";
             if (in_array($searchtype, array('equals', 'notequals'))) {
                 return " {$link} (`{$table}`.`id`" . $SEARCH . ($val == 0 ? " OR `{$table}`.`id` IS NULL" : '') . ') ';
             }
             return Search::makeTextCriteria("`{$table}`.`{$field}`", $val, $nott, $link);
     }
     //// Default cases
     // Link with plugin tables
     if (preg_match("/^glpi_plugin_([a-z0-9]+)/", $inittable, $matches)) {
         if (count($matches) == 2) {
             $plug = $matches[1];
             $function = 'plugin_' . $plug . '_addWhere';
             if (function_exists($function)) {
                 $out = $function($link, $nott, $itemtype, $ID, $val);
                 if (!empty($out)) {
                     return $out;
                 }
             }
         }
     }
     $tocompute = "`{$table}`.`{$field}`";
     if (isset($searchopt[$ID]["computation"])) {
         $tocompute = $searchopt[$ID]["computation"];
         $tocompute = str_replace("TABLE", "`{$table}`", $tocompute);
     }
     // Preformat items
     if (isset($searchopt[$ID]["datatype"])) {
         switch ($searchopt[$ID]["datatype"]) {
             case "itemtypename":
                 if (in_array($searchtype, array('equals', 'notequals'))) {
                     return " {$link} (`{$table}`.`{$field}`" . $SEARCH . ') ';
                 }
             case "datetime":
             case "date":
             case "date_delay":
                 if ($searchopt[$ID]["datatype"] == 'datetime') {
                     // Specific search for datetime
                     if (in_array($searchtype, array('equals', 'notequals'))) {
                         $val = preg_replace("/:00\$/", '', $val);
                         $val = '^' . $val;
                         if ($searchtype == 'notequals') {
                             $nott = !$nott;
                         }
                         return Search::makeTextCriteria("`{$table}`.`{$field}`", $val, $nott, $link);
                     }
                 }
                 if ($searchtype == 'lessthan') {
                     $val = '<' . $val;
                 }
                 if ($searchtype == 'morethan') {
                     $val = '>' . $val;
                 }
                 if ($searchtype) {
                     $date_computation = $tocompute;
                 }
                 $search_unit = ' MONTH ';
                 if (isset($searchopt[$ID]['searchunit'])) {
                     $search_unit = $searchopt[$ID]['searchunit'];
                 }
                 if ($searchopt[$ID]["datatype"] == "date_delay") {
                     $delay_unit = ' MONTH ';
                     if (isset($searchopt[$ID]['delayunit'])) {
                         $delay_unit = $searchopt[$ID]['delayunit'];
                     }
                     $date_computation = "ADDDATE(`{$table}`." . $searchopt[$ID]["datafields"][1] . ",\n                                               INTERVAL `{$table}`." . $searchopt[$ID]["datafields"][2] . "\n                                               {$delay_unit})";
                 }
                 if (in_array($searchtype, array('equals', 'notequals'))) {
                     return " {$link} ({$date_computation} " . $SEARCH . ') ';
                 }
                 $search = array("/\\&lt;/", "/\\&gt;/");
                 $replace = array("<", ">");
                 $val = preg_replace($search, $replace, $val);
                 if (preg_match("/^\\s*([<>=]+)(.*)/", $val, $regs)) {
                     if (is_numeric($regs[2])) {
                         return $link . " {$date_computation} " . $regs[1] . "\n                            ADDDATE(NOW(), INTERVAL " . $regs[2] . " {$search_unit}) ";
                     }
                     // ELSE Reformat date if needed
                     $regs[2] = preg_replace('@(\\d{1,2})(-|/)(\\d{1,2})(-|/)(\\d{4})@', '\\5-\\3-\\1', $regs[2]);
                     if (preg_match('/[0-9]{2,4}-[0-9]{1,2}-[0-9]{1,2}/', $regs[2])) {
                         return $link . " {$date_computation} " . $regs[1] . " '" . $regs[2] . "'";
                     }
                     return "";
                 }
                 // ELSE standard search
                 // Date format modification if needed
                 $val = preg_replace('@(\\d{1,2})(-|/)(\\d{1,2})(-|/)(\\d{4})@', '\\5-\\3-\\1', $val);
                 return Search::makeTextCriteria($date_computation, $val, $nott, $link);
             case "right":
                 if ($val == 'NULL' || $val == 'null') {
                     return $link . " {$tocompute} IS " . ($nott ? 'NOT' : '') . " NULL ";
                 }
                 return $link . " {$tocompute} = '{$val}' ";
             case "bool":
                 if (!is_numeric($val)) {
                     if (strcasecmp($val, __('No')) == 0) {
                         $val = 0;
                     } else {
                         if (strcasecmp($val, __('Yes')) == 0) {
                             $val = 1;
                         }
                     }
                 }
                 // No break here : use number comparaison case
             // No break here : use number comparaison case
             case "number":
             case "decimal":
             case "timestamp":
                 $search = array("/\\&lt;/", "/\\&gt;/");
                 $replace = array("<", ">");
                 $val = preg_replace($search, $replace, $val);
                 if (preg_match("/([<>])([=]*)[[:space:]]*([0-9]+)/", $val, $regs)) {
                     if ($nott) {
                         if ($regs[1] == '<') {
                             $regs[1] = '>';
                         } else {
                             $regs[1] = '<';
                         }
                     }
                     $regs[1] .= $regs[2];
                     return $link . " ({$tocompute} " . $regs[1] . " " . $regs[3] . ") ";
                 }
                 if (is_numeric($val)) {
                     if (isset($searchopt[$ID]["width"])) {
                         $ADD = "";
                         if ($nott && $val != 'NULL' && $val != 'null') {
                             $ADD = " OR {$tocompute} IS NULL";
                         }
                         if ($nott) {
                             return $link . " ({$tocompute} < " . (intval($val) - $searchopt[$ID]["width"]) . "\n                                        OR {$tocompute} > " . (intval($val) + $searchopt[$ID]["width"]) . "\n                                        {$ADD}) ";
                         }
                         return $link . " (({$tocompute} >= " . (intval($val) - $searchopt[$ID]["width"]) . "\n                                      AND {$tocompute} <= " . (intval($val) + $searchopt[$ID]["width"]) . ")\n                                     {$ADD}) ";
                     }
                     if (!$nott) {
                         return " {$link} ({$tocompute} = " . intval($val) . ") ";
                     }
                     return " {$link} ({$tocompute} <> " . intval($val) . ") ";
                 }
                 break;
         }
     }
     // Default case
     if (in_array($searchtype, array('equals', 'notequals'))) {
         $out = " {$link} (`{$table}`.`id`" . $SEARCH;
         if ($searchtype == 'notequals') {
             $nott = !$nott;
         }
         // Add NULL if $val = 0 and not negative search
         if (!$nott && $val == 0) {
             $out .= " OR `{$table}`.`id` IS NULL";
         }
         $out .= ')';
         return $out;
     }
     return Search::makeTextCriteria($tocompute, $val, $nott, $link);
 }
예제 #30
0
 /**
  * Get a notificationtarget class by giving the object which raises the event
  *
  * @param $item            the object which raises the event
  * @param $event           the event which will be used (default '')
  * @param $options   array of options
  *
  * @return a notificationtarget class or false
  **/
 static function getInstance($item, $event = '', $options = array())
 {
     if ($plug = isPluginItemType($item->getType())) {
         $name = 'Plugin' . $plug['plugin'] . 'NotificationTarget' . $plug['class'];
     } else {
         $name = 'NotificationTarget' . $item->getType();
     }
     $entity = 0;
     if (class_exists($name)) {
         //Entity ID exists in the options array
         if (isset($options['entities_id'])) {
             $entity = $options['entities_id'];
             //Item which raises the event contains an entityID
         } else {
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
         }
         return new $name($entity, $event, $item, $options);
     }
     return false;
 }