Exemplo n.º 1
0
function plugin_pre_item_update_tag($parm)
{
    global $DB;
    if (isset($_REQUEST['plugin_tag_tag_id']) && isset($_REQUEST['plugin_tag_tag_itemtype'])) {
        $already_present = array();
        $itemtype = PluginTagTag::getItemtype($_REQUEST['plugin_tag_tag_itemtype'], $_REQUEST['plugin_tag_tag_id']);
        $query_part = "`items_id`=" . $_REQUEST['plugin_tag_tag_id'] . " \n                     AND `itemtype` = '" . $itemtype . "'";
        $item = new PluginTagTagItem();
        foreach ($item->find($query_part) as $indb) {
            if (isset($_REQUEST["_plugin_tag_tag_values"]) && in_array($indb["plugin_tag_tags_id"], $_REQUEST["_plugin_tag_tag_values"])) {
                $already_present[] = $indb["plugin_tag_tags_id"];
            } else {
                $item->delete(array("id" => $indb['id']));
            }
        }
        if (isset($_REQUEST["_plugin_tag_tag_values"])) {
            foreach ($_REQUEST["_plugin_tag_tag_values"] as $tag_id) {
                if (!in_array($tag_id, $already_present)) {
                    $item->add(array('plugin_tag_tags_id' => $tag_id, 'items_id' => $_REQUEST['plugin_tag_tag_id'], 'itemtype' => ucfirst($itemtype)));
                }
            }
        }
    }
    return $parm;
}
Exemplo n.º 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);
     }
 }
Exemplo n.º 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";
 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();\">";
     }
 }