function plugin_pre_item_purge_tag($object)
{
    if (isset($object->input["plugin_tag_tag_itemtype"])) {
        // Example : TicketTask no have tag
        $tagitem = new PluginTagTagItem();
        $result = $tagitem->deleteByCriteria(array("items_id" => $object->fields["id"], "itemtype" => ucfirst($object->input["plugin_tag_tag_itemtype"])));
    }
}
Beispiel #2
0
 static function tagDropdownMultiple($options = array())
 {
     $itemtype = self::getItemtype($_REQUEST['itemtype'], $_REQUEST['id']);
     $obj = new $itemtype();
     // Object must be an instance of CommonDBTM (or inherint of this)
     if (!$obj instanceof CommonDBTM) {
         return;
     }
     $obj->getFromDB($_REQUEST['id']);
     $sel_attr = $obj->canUpdateItem() ? '' : ' disabled ';
     echo "<select data-placeholder='" . __('Choose tags...', 'tag') . self::MNBSP . "' name='_plugin_tag_tag_values[]'\n          id='tag_select' multiple class='chosen-select-no-results' " . $sel_attr . " style='width:80%;' >";
     $selected_id = array();
     $tag_item = new PluginTagTagItem();
     foreach ($tag_item->find('items_id=' . $_REQUEST['id'] . ' 
                             AND itemtype="' . $itemtype . '"') as $found_item) {
         $selected_id[] = $found_item['plugin_tag_tags_id'];
     }
     // Restrict tag by entity if current object has entity
     $where = "1 ";
     if (isset($obj->fields['entities_id'])) {
         $field = $obj->getType() == 'Entity' ? 'id' : 'entities_id';
         $where .= getEntitiesRestrictRequest("AND", '', '', $obj->fields[$field], true);
     }
     $tag = new self();
     $items = $tag->find($where, 'name');
     foreach ($items as $item) {
         $param = in_array($item['id'], $selected_id) ? ' selected ' : '';
         $param .= 'data-color-option="' . $item['color'] . '"';
         if (!empty($item['type_menu'])) {
             // Allowed types
             foreach (json_decode($item['type_menu'], true) as $subtype) {
                 if (strtolower($subtype) == $itemtype) {
                     echo '<option value="' . $item['id'] . '" ' . $param . '>' . $item['name'] . '</option>';
                     break;
                 }
             }
         } else {
             echo '<option value="' . $item['id'] . '" ' . $param . '>' . $item['name'] . '</option>';
         }
     }
     echo "</select>";
     if (self::canCreate()) {
         $rand = mt_rand();
         /*
         echo "<script type='text/javascript'>\n
            window.updateTagSelectResults_".$rand." = function () {
               
            }
         </script>";
         */
         // Show '+' button :
         self::showMoreButton($rand);
     }
 }
Beispiel #3
0
<?php

include '../../../inc/includes.php';
Session::checkRight("config", UPDATE);
Plugin::load('tag', true);
$plugin = new Plugin();
if (!$plugin->isInstalled("tag") || !$plugin->isActivated("tag")) {
    Html::displayNotFoundError();
}
if (isset($_POST['add']) || isset($_REQUEST['update'])) {
    if (isset($_POST['add'])) {
        $item = new PluginTagTagItem();
        // Check unicity :
        if (isset($_REQUEST['plugin_tag_tags_id'])) {
            $found = $item->find('plugin_tag_tags_id = ' . $_REQUEST['plugin_tag_tags_id'] . '
                               AND items_id = ' . $_REQUEST['items_id'] . '
                               AND itemtype = "' . $_REQUEST['itemtype'] . '"');
            if (count($found) == 0) {
                $item->add($_REQUEST);
            }
        } else {
            $item->add($_REQUEST);
        }
    }
}
$dropdown = new PluginTagTag();
include GLPI_ROOT . "/front/dropdown.common.form.php";
Beispiel #4
0
     // check if itemtype can display tag control
     if (in_array(strtolower($_POST['itemtype']), array_map('strtolower', getBlacklistItemtype()))) {
         return '';
     }
     $class = $_POST['itemtype'] == 'ticket' ? "tab_bg_1" : '';
     echo "<tr class='{$class} tab_bg_1'>";
     echo "<th>" . _n('Tag', 'Tags', 2, 'tag') . "</th>";
     echo "<td colspan='3'>";
     PluginTagTag::tagDropdownMultiple();
     echo "</td>";
     echo "</tr>";
     break;
 case 'add_subtypes':
     // Sub type add
     $itemtypes = array();
     foreach (PluginTagTagItem::getItemtypes($_POST['type_menu']) as $itemtype) {
         $item = getItemForItemtype($itemtype);
         $itemtypes[$itemtype] = $item->getTypeName();
     }
     Dropdown::showFromArray("add_subtypes", $itemtypes, array('multiple' => true, 'rand' => $_POST['rand'], 'width' => '50%'));
     // Add subtypes button
     echo " <a class=\"vsubmit\" onclick=\"pluginTagAddSubType('dropdown_subtypes" . $_POST['rand'] . "', 'dropdown_add_subtypes" . $_POST['rand'] . "', '" . $CFG_GLPI['root_doc'] . "/plugins/tag/ajax/tag.php');\">" . __('Add type', 'tag') . "</a>";
     break;
 case 'list_subtypes':
     // Sub type list
     $itemtypes = array();
     if (!empty($_POST['subtypes'])) {
         foreach ($_POST['subtypes'] as $key => $itemtype) {
             $item = getItemForItemtype($itemtype);
             $itemtypes[$key]['value'] = $itemtype;
             $itemtypes[$key]['text'] = $item->getTypeName();
 static function tagDropdownMultiple($options = array())
 {
     global $CFG_GLPI;
     //default options
     $params['name'] = '_plugin_tag_tag_values';
     $params['rand'] = mt_rand();
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     // multiple select : add [] to name
     $params['name'] .= "[]";
     $itemtype = self::getItemtype($_REQUEST['itemtype'], $_REQUEST['id']);
     $obj = new $itemtype();
     // Object must be an instance of CommonDBTM (or inherint of this)
     if (!$obj instanceof CommonDBTM) {
         return;
     }
     $selected_id = array();
     $tag_item = new PluginTagTagItem();
     foreach ($tag_item->find('items_id=' . $_REQUEST['id'] . ' 
                                   AND itemtype="' . $itemtype . '"') as $found_item) {
         $selected_id[] = $found_item['plugin_tag_tags_id'];
     }
     $obj->getFromDB($_REQUEST['id']);
     $sel_attr = $obj->canUpdateItem() ? '' : ' disabled ';
     $tag = new self();
     $where = "";
     // restrict tag by entity if current object has entity
     if (isset($obj->fields['entities_id'])) {
         if ($itemtype == 'entity') {
             $field = 'id';
         } else {
             $field = 'entities_id';
         }
         $where = getEntitiesRestrictRequest(" ", '', '', $obj->fields[$field], true);
     }
     $found = $tag->find($where);
     echo "<span style='width:80%'>";
     echo "<select data-placeholder='" . __('Choose tags...', 'tag') . self::MNBSP . "' name='" . $params['name'] . "'\n                id='tag_select' multiple class='chosen-select-no-results' {$sel_attr} style='width:80%;' >";
     usort($found, array(__CLASS__, "cmp_Tag"));
     foreach ($found as $label) {
         $param = in_array($label['id'], $selected_id) ? ' selected ' : '';
         if (is_null($label['color'])) {
             $label['color'] = "";
         }
         $param .= 'data-color-option="' . $label['color'] . '"';
         echo '<option value="' . $label['id'] . '" ' . $param . '>' . $label['name'] . '</option>';
     }
     echo "</select>";
     echo "</span>";
     echo "<script type='text/javascript'>\n\n         window.updateTagSelectResults_" . $params['rand'] . " = function () {\n            \n         }\n      </script>";
     if (self::canCreate()) {
         // Show '+' button :
         echo "&nbsp;<img title=\"" . __s('Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer;margin-left:2px;'\n              onClick=\"var w = window.open('" . $CFG_GLPI['root_doc'] . "/plugins/tag/front/tag.form.php?popup=1&amp;rand=" . $params['rand'] . "', " . "'glpipopup', 'height=400, width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">";
     }
 }