コード例 #1
0
ファイル: setup.php プロジェクト: publik1974/fields
function plugin_fields_checkFiles()
{
    $plugin = new Plugin();
    if (isset($_SESSION['glpiactiveentities']) && $plugin->isInstalled('fields') && $plugin->isActivated('fields')) {
        Plugin::registerClass('PluginFieldsContainer');
        Plugin::registerClass('PluginFieldsDropdown');
        Plugin::registerClass('PluginFieldsField');
        if (TableExists("glpi_plugin_fields_containers")) {
            $container_obj = new PluginFieldsContainer();
            $containers = $container_obj->find();
            foreach ($containers as $container) {
                $classname = "PluginFields" . ucfirst($container['itemtype'] . preg_replace('/s$/', '', $container['name']));
                if (!class_exists($classname)) {
                    PluginFieldsContainer::generateTemplate($container);
                }
            }
        }
        if (TableExists("glpi_plugin_fields_fields")) {
            $fields_obj = new PluginFieldsField();
            $fields = $fields_obj->find("`type` = 'dropdown'");
            foreach ($fields as $field) {
                PluginFieldsDropdown::create($field);
            }
        }
    }
}
コード例 #2
0
ファイル: profile.class.php プロジェクト: publik1974/fields
 static function addNewProfile(Profile $profile)
 {
     $containers = new PluginFieldsContainer();
     $found_containers = $containers->find();
     $fields_profile = new self();
     foreach ($found_containers as $container) {
         $fields_profile->add(array('profiles_id' => $profile->fields['id'], 'plugin_fields_containers_id' => $container['id']));
     }
     return true;
 }
コード例 #3
0
<?php

include "../../../inc/includes.php";
PluginFieldsContainer::showFormItemtype($_REQUEST);
コード例 #4
0
ファイル: container.form.php プロジェクト: publik1974/fields
<?php

include "../../../inc/includes.php";
if (empty($_GET["id"])) {
    $_GET["id"] = "";
}
$container = new PluginFieldsContainer();
if (isset($_POST["add"])) {
    $container->check(-1, CREATE, $_POST);
    $newID = $container->add($_POST);
    Html::redirect($CFG_GLPI["root_doc"] . "/plugins/fields/front/container.form.php?id={$newID}");
} elseif (isset($_POST["delete"])) {
    $container->check($_POST['id'], DELETE);
    $ok = $container->delete($_POST);
    Html::redirect($CFG_GLPI["root_doc"] . "/plugins/fields/front/container.php");
} elseif (isset($_REQUEST["purge"])) {
    $container->check($_REQUEST['id'], PURGE);
    $container->delete($_REQUEST, 1);
    Html::redirect($CFG_GLPI["root_doc"] . "/plugins/fields/front/container.php");
} elseif (isset($_POST["update"])) {
    $container->check($_POST['id'], UPDATE);
    $container->update($_POST);
    Html::back();
} elseif (isset($_POST["update_fields_values"])) {
    $container->updateFieldsValues($_REQUEST);
    Html::back();
} else {
    Html::header(__("Additionnal fields", "fields"), $_SERVER['PHP_SELF'], "config", "pluginfieldsmenu", "fieldscontainer");
    $container->display(array('id' => $_GET["id"]));
    Html::footer();
}
コード例 #5
0
ファイル: container.php プロジェクト: publik1974/fields
<?php

include "../../../inc/includes.php";
Html::header(__("Additionnal fields", "fields"), $_SERVER['PHP_SELF'], "config", "pluginfieldsmenu", "fieldscontainer");
Session::checkRight('entity', READ);
PluginFieldsContainer::titleList();
Search::show("PluginFieldsContainer");
Html::footer();
コード例 #6
0
ファイル: field.class.php プロジェクト: publik1974/fields
 static function prepareHtmlFields($fields, $items_id, $canedit = true, $show_table = true, $massiveaction = false)
 {
     if (empty($fields)) {
         return false;
     }
     //get object associated with this fields
     $tmp = $fields;
     $first_field = array_shift($tmp);
     $container_obj = new PluginFieldsContainer();
     $container_obj->getFromDB($first_field['plugin_fields_containers_id']);
     $items_itemtype = ucfirst($container_obj->fields['itemtype']);
     $classname = "PluginFields" . $items_itemtype . preg_replace('/s$/', '', $container_obj->fields['name']);
     $obj = new $classname();
     //find row for this object with the items_id
     $found_values = $obj->find("plugin_fields_containers_id = " . $first_field['plugin_fields_containers_id'] . " AND items_id = " . $items_id);
     $found_v = array_shift($found_values);
     // find profiles (to check if current profile can edit fields)
     $fprofile = new PluginFieldsProfile();
     $found_p = $fprofile->find("`profiles_id` = '" . $_SESSION['glpiactiveprofile']['id'] . "'\n                                  AND `plugin_fields_containers_id` = '" . $first_field['plugin_fields_containers_id'] . "'");
     $first_found_p = array_shift($found_p);
     // test status for "CommonITILObject" objects
     if (is_subclass_of($items_itemtype, "CommonITILObject")) {
         $items_obj = new $items_itemtype();
         $items_obj->getFromDB($items_id);
         if (in_array($items_obj->fields['status'], $items_obj->getClosedStatusArray()) || in_array($items_obj->fields['status'], $items_obj->getSolvedStatusArray()) || $first_found_p['right'] != CREATE) {
             $canedit = false;
         }
     }
     //show all fields
     $html = "";
     $odd = 0;
     foreach ($fields as $field) {
         if ($field['type'] === 'header') {
             $html .= "<tr class='tab_bg_2'>";
             $html .= "<th colspan='4'>" . $field['label'] . "</td>";
             $html .= "</tr>";
             $odd = 0;
         } else {
             //get value
             $value = "";
             if (is_array($found_v)) {
                 if ($field['type'] == "dropdown") {
                     $value = $found_v["plugin_fields_" . $field['name'] . "dropdowns_id"];
                 } else {
                     $value = $found_v[$field['name']];
                 }
             }
             if (isset($_SESSION['plugin']['fields']['values_sent'])) {
                 if ($field['type'] == "dropdown") {
                     $value = $_SESSION['plugin']['fields']['values_sent']["plugin_fields_" . $field['name'] . "dropdowns_id"];
                 } else {
                     $value = $_SESSION['plugin']['fields']['values_sent'][$field['name']];
                 }
             }
             //get default value
             if (empty($value) && !empty($field['default_value'])) {
                 $value = $field['default_value'];
             }
             //show field
             if ($show_table) {
                 if ($odd % 2 == 0) {
                     $html .= "<tr class='tab_bg_2'>";
                 }
                 $required = $field['mandatory'] == 1 ? "<span class='red'>*</span>" : '';
                 if ($container_obj->fields['itemtype'] == 'Ticket' && $container_obj->fields['type'] == 'dom' && strpos($_SERVER['HTTP_REFERER'], ".injector.php") === false && strpos($_SERVER['HTTP_REFERER'], ".public.php") === false) {
                     $html .= "<th width='13%'>" . $field['label'] . " : {$required}</th>";
                 } else {
                     $html .= "<td>" . $field['label'] . " : {$required}</td>";
                 }
                 $html .= "<td>";
             }
             $readonly = $field['is_readonly'];
             switch ($field['type']) {
                 case 'number':
                 case 'text':
                     $value = Html::cleanInputText($value);
                     if ($canedit && !$readonly) {
                         $html .= "<input type='text' name='" . $field['name'] . "' value=\"{$value}\" />";
                     } else {
                         $html .= $value;
                     }
                     break;
                 case 'textarea':
                     if ($massiveaction) {
                         continue;
                     }
                     if ($canedit && !$readonly) {
                         $html .= "<textarea cols='45' rows='4' name='" . $field['name'] . "'>" . "{$value}</textarea>";
                     } else {
                         $html .= nl2br($value);
                     }
                     break;
                 case 'dropdown':
                     if ($canedit && !$readonly) {
                         //find entity on current object
                         $obj = new $container_obj->fields['itemtype']();
                         $obj->getFromDB($items_id);
                         ob_start();
                         if (strpos($field['name'], "dropdowns_id") !== false) {
                             $dropdown_itemtype = getItemTypeForTable(getTableNameForForeignKeyField($field['name']));
                         } else {
                             $dropdown_itemtype = PluginFieldsDropdown::getClassname($field['name']);
                         }
                         Dropdown::show($dropdown_itemtype, array('value' => $value, 'entity' => $obj->getEntityID()));
                         $html .= ob_get_contents();
                         ob_end_clean();
                     } else {
                         $dropdown_table = "glpi_plugin_fields_" . $field['name'] . "dropdowns";
                         $html .= Dropdown::getDropdownName($dropdown_table, $value);
                     }
                     break;
                 case 'yesno':
                     //in massive action, we must skip display for yesno (possible bug in framework)
                     //otherwise double display of field
                     if ($massiveaction) {
                         continue;
                     }
                     if ($canedit && !$readonly) {
                         ob_start();
                         Dropdown::showYesNo($field['name'], $value);
                         $html .= ob_get_contents();
                         ob_end_clean();
                     } else {
                         $html .= Dropdown::getYesNo($value);
                     }
                     break;
                 case 'date':
                     if ($massiveaction) {
                         continue;
                     }
                     if ($canedit && !$readonly) {
                         ob_start();
                         Html::showDateFormItem($field['name'], $value);
                         $html .= ob_get_contents();
                         ob_end_clean();
                     } else {
                         $html .= Html::convDate($value);
                     }
                     break;
                 case 'datetime':
                     if ($massiveaction) {
                         continue;
                     }
                     if ($canedit && !$readonly) {
                         ob_start();
                         Html::showDateTimeFormItem($field['name'], $value);
                         $html .= ob_get_contents();
                         ob_end_clean();
                     } else {
                         $html .= Html::convDateTime($value);
                     }
                 case 'dropdownuser':
                     if ($massiveaction) {
                         continue;
                     }
                     if ($canedit && !$readonly) {
                         ob_start();
                         User::dropdown(array('name' => $field['name'], 'value' => $value, 'entity' => -1, 'right' => 'all', 'condition' => 'is_active=1 && is_deleted=0'));
                         $html .= ob_get_contents();
                         ob_end_clean();
                     } else {
                         $showuserlink = 0;
                         if (Session::haveRight('user', 'r')) {
                             $showuserlink = 1;
                         }
                         $html .= getUserName($value, $showuserlink);
                     }
             }
             if ($show_table) {
                 $html .= "</td>";
                 if ($odd % 2 == 1) {
                     $html .= "</tr>";
                 }
                 $odd++;
             }
         }
     }
     if ($show_table && $odd % 2 == 1) {
         $html .= "</tr>";
     }
     unset($_SESSION['plugin']['fields']['values_sent']);
     return $html;
 }
コード例 #7
0
ファイル: hook.php プロジェクト: publik1974/fields
/**
 * Load Fields classes in datainjection.
 * Called by Setup.php:44 if Datainjection is installed and active
**/
function plugin_datainjection_populate_fields()
{
    global $INJECTABLE_TYPES;
    $container = new PluginFieldsContainer('is_active = 1');
    $found = $container->find();
    foreach ($found as $id => $values) {
        $classname = "PluginFields" . ucfirst($values['itemtype'] . preg_replace('/s$/', '', $values['name'])) . 'Injection';
        $INJECTABLE_TYPES[$classname] = 'fields';
        $INJECTABLE_TYPES[$classname . 'Injection'] = 'fields';
    }
}
コード例 #8
0
<?php

include "../../../inc/includes.php";
PluginFieldsContainer::showFormSubtype($_REQUEST);
コード例 #9
0
ファイル: container.class.php プロジェクト: publik1974/fields
 static function findContainer($itemtype, $items_id, $type = 'tab', $subtype = '')
 {
     if ($type === 'tab' || $type === 'dom') {
         $sql_type = "`type` = '{$type}'";
     } else {
         $sql_type = "1=1";
     }
     $entity = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : 0;
     $sql_entity = getEntitiesRestrictRequest("AND", "", "", $entity, true, true);
     $sql_subtype = '';
     if ($subtype != '') {
         if ($subtype == $itemtype . '$main') {
             $sql_subtype = " AND type = 'dom' ";
         } else {
             $sql_subtype = " AND type != 'dom' AND subtype = '{$subtype}' ";
         }
     }
     $container = new PluginFieldsContainer();
     $found_c = $container->find($sql_type . " AND `itemtype` = '{$itemtype}' AND is_active = 1 " . $sql_entity . $sql_subtype);
     if (empty($found_c)) {
         return false;
     }
     if ($type == "dom") {
         $tmp = array_shift($found_c);
         $id = $tmp['id'];
     } else {
         $id = array_keys($found_c);
         if (count($id) == 1) {
             $id = array_shift($id);
         }
     }
     //profiles restriction
     if (isset($_SESSION['glpiactiveprofile']['id'])) {
         $profile = new PluginFieldsProfile();
         if (is_array($id)) {
             $condition = "`plugin_fields_containers_id` IN (" . implode(", ", $id) . ")";
         } else {
             $condition = "`plugin_fields_containers_id` = '{$id}'";
         }
         $found = $profile->find("`profiles_id` = '" . $_SESSION['glpiactiveprofile']['id'] . "'\n                                 AND {$condition}");
         $first_found = array_shift($found);
         if ($first_found['right'] == NULL) {
             return false;
         }
     }
     return $id;
 }
コード例 #10
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;
 }