Exemplo n.º 1
0
function regenerateFiles()
{
    $container = new PluginFieldsContainer();
    $found_container = $container->find();
    foreach ($found_container as $current_container) {
        $containers_id = $current_container['id'];
        $container->getFromDB($containers_id);
        $container->post_addItem();
    }
}
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 /**
  * Insert values submited by fields container
  * @param  array $datas datas posted
  * @return boolean
  */
 function updateFieldsValues($datas)
 {
     global $DB;
     if (self::validateValues($datas) === false) {
         return false;
     }
     $container_obj = new PluginFieldsContainer();
     $container_obj->getFromDB($datas['plugin_fields_containers_id']);
     $items_id = $datas['items_id'];
     $itemtype = $container_obj->fields['itemtype'];
     $classname = "PluginFields" . ucfirst($itemtype . preg_replace('/s$/', '', $container_obj->fields['name']));
     $obj = new $classname();
     //check if datas already inserted
     $found = $obj->find("items_id = {$items_id}");
     if (empty($found)) {
         // add fields datas
         $obj->add($datas);
         //construct history on itemtype object (Historical tab)
         self::constructHistory($datas['plugin_fields_containers_id'], $items_id, $itemtype, $datas);
     } else {
         $first_found = array_pop($found);
         $datas['id'] = $first_found['id'];
         $obj->update($datas);
         //construct history on itemtype object (Historical tab)
         self::constructHistory($datas['plugin_fields_containers_id'], $items_id, $itemtype, $datas, $first_found);
     }
     return true;
 }
Exemplo n.º 4
0
 /**
  * Pre item hook for add and update
  * Validates and store plugin data in item object
  *
  * @param CommonDBTM $item Item instance
  *
  * @return boolean
  */
 static function preItem(CommonDBTM $item)
 {
     //find container (if not exist, do nothing)
     if (isset($_REQUEST['c_id'])) {
         $c_id = $_REQUEST['c_id'];
     } else {
         $c_id = self::findContainer(get_Class($item), "dom");
         if ($c_id === false) {
             $c_id = self::findContainer(get_Class($item));
             //tries for 'tab'
             if ($c_id === false) {
                 return false;
             }
         }
     }
     //need to check if container is usable on this object entity
     $loc_c = new PluginFieldsContainer();
     $loc_c->getFromDB($c_id);
     $entities = array($loc_c->fields['entities_id']);
     if ($loc_c->fields['is_recursive']) {
         $entities = getSonsOf(getTableForItemType('Entity'), $loc_c->fields['entities_id']);
     }
     //workaround: when a ticket is created from readdonly profile,
     //it is not initialized; see https://github.com/glpi-project/glpi/issues/1438
     if (!isset($item->fields) || count($item->fields) == 0) {
         $item->fields = $item->input;
     }
     if (!in_array($item->fields['entities_id'], $entities)) {
         return false;
     }
     $data = self::populateData($c_id, $item);
     if ($data !== false) {
         if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) {
             return $item->input = [];
         }
         return $item->plugin_fields_data = $data;
     }
     return $item->input = [];
 }