https://github.com/pluginsGLPI/fields
-------------------------------------------------------------------------

LICENSE

This file is part of Fields.

Fields is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Fields is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Fields. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
$translation = new PluginFieldsLabelTranslation();
if (isset($_POST['add'])) {
    $translation->add($_POST);
} else {
    if (isset($_POST['update'])) {
        $translation->update($_POST);
    }
}
Html::back();
Example #2
0
function plugin_fields_getDropdown()
{
    $dropdowns = array();
    $field_obj = new PluginFieldsField();
    $fields = $field_obj->find("`type` = 'dropdown'");
    foreach ($fields as $field) {
        $field['itemtype'] = PluginFieldsField::getType();
        $label = PluginFieldsLabelTranslation::getLabelFor($field);
        $dropdowns["PluginFields" . ucfirst($field['name']) . "Dropdown"] = $label;
    }
    asort($dropdowns);
    return $dropdowns;
}
Example #3
0
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../../../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
if (!isset($_POST['itemtype']) || !isset($_POST['items_id']) || !isset($_POST['id'])) {
    exit;
}
$translation = new PluginFieldsLabelTranslation();
$canedit = $translation->can($translation->getID(), CREATE);
if ($canedit) {
    $translation->showForm($_POST['itemtype'], $_POST['items_id'], $_POST['id']);
} else {
    _e('Access denied');
}
Html::ajaxFooter();
 static function createForItem(CommonDBTM $item)
 {
     $translation = new PluginFieldsLabelTranslation();
     $translation->add(['plugin_fields_itemtype' => $item::getType(), 'plugin_fields_items_id' => $item->getID(), 'language' => $_SESSION['glpilanguage'], 'label' => $item->fields['label']]);
     return true;
 }
Example #5
0
 function post_addItem()
 {
     //Create label translation
     PluginFieldsLabelTranslation::createForItem($this);
 }
Example #6
0
 static function getAddSearchOptions($itemtype, $containers_id = false)
 {
     global $DB;
     $opt = array();
     $i = 76665;
     $query = "SELECT fields.name, fields.label, fields.type, fields.is_readonly,\n            containers.name as container_name, containers.label as container_label,\n            containers.itemtypes, containers.id as container_id, fields.id as field_id\n         FROM glpi_plugin_fields_containers containers\n         INNER JOIN glpi_plugin_fields_fields fields\n            ON containers.id = fields.plugin_fields_containers_id\n            AND containers.is_active = 1\n         WHERE containers.itemtypes LIKE '%{$itemtype}%'\n            AND fields.type != 'header'\n            ORDER BY fields.id ASC";
     $res = $DB->query($query);
     while ($data = $DB->fetch_assoc($res)) {
         if ($containers_id !== false) {
             // Filter by container (don't filter by SQL for have $i value with few containers for a itemtype)
             if ($data['container_id'] != $containers_id) {
                 $i++;
                 continue;
             }
         }
         $tablename = "glpi_plugin_fields_" . strtolower($itemtype . getPlural(preg_replace('/s$/', '', $data['container_name'])));
         //get translations
         $container = ['itemtype' => PluginFieldsContainer::getType(), 'id' => $data['container_id'], 'label' => $data['container_label']];
         $data['container_label'] = PluginFieldsLabelTranslation::getLabelFor($container);
         $field = ['itemtype' => PluginFieldsField::getType(), 'id' => $data['field_id'], 'label' => $data['label']];
         $data['label'] = PluginFieldsLabelTranslation::getLabelFor($field);
         $opt[$i]['table'] = $tablename;
         $opt[$i]['field'] = $data['name'];
         $opt[$i]['name'] = $data['container_label'] . " - " . $data['label'];
         $opt[$i]['linkfield'] = $data['name'];
         $opt[$i]['joinparams']['jointype'] = "itemtype_item";
         $opt[$i]['pfields_type'] = $data['type'];
         if ($data['is_readonly']) {
             $opt[$i]['massiveaction'] = false;
         }
         if ($data['type'] === "dropdown") {
             $opt[$i]['table'] = 'glpi_plugin_fields_' . $data['name'] . 'dropdowns';
             $opt[$i]['field'] = 'completename';
             $opt[$i]['linkfield'] = "plugin_fields_" . $data['name'] . "dropdowns_id";
             $opt[$i]['forcegroupby'] = true;
             $opt[$i]['joinparams']['jointype'] = "";
             $opt[$i]['joinparams']['beforejoin']['table'] = $tablename;
             $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item";
         }
         if ($data['type'] === "dropdownuser") {
             $opt[$i]['table'] = 'glpi_users';
             $opt[$i]['field'] = 'name';
             $opt[$i]['linkfield'] = $data['name'];
             $opt[$i]['right'] = 'all';
             $opt[$i]['forcegroupby'] = true;
             $opt[$i]['joinparams']['jointype'] = "";
             $opt[$i]['joinparams']['beforejoin']['table'] = $tablename;
             $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item";
         }
         switch ($data['type']) {
             case 'dropdown':
             case 'dropdownuser':
                 $opt[$i]['datatype'] = "dropdown";
                 break;
             case 'yesno':
                 $opt[$i]['datatype'] = "bool";
                 break;
             case 'textarea':
                 $opt[$i]['datatype'] = "text";
                 break;
             case 'number':
                 $opt[$i]['datatype'] = "number";
                 break;
             case 'date':
             case 'datetime':
                 $opt[$i]['datatype'] = $data['type'];
                 break;
             default:
                 $opt[$i]['datatype'] = "string";
         }
         $i++;
     }
     return $opt;
 }