/**
  *
  * Displat all fields present in DB for an itemtype
  * @param $id the itemtype's id
  */
 public static function showObjectFieldsForm($id)
 {
     global $DB, $GO_BLACKLIST_FIELDS, $GO_READONLY_FIELDS, $GO_FIELDS, $CFG_GLPI;
     $url = Toolbox::getItemTypeFormURL(__CLASS__);
     $object_type = new PluginGenericobjectType();
     $object_type->getFromDB($id);
     $itemtype = $object_type->fields['itemtype'];
     $fields_in_db = PluginGenericobjectSingletonObjectField::getInstance($itemtype);
     $used_fields = array();
     //Reset fields definition only to keep the itemtype ones
     $GO_FIELDS = array();
     plugin_genericobject_includeCommonFields(true);
     //ToolBox::logDebug(PluginGenericobjectSingletonObjectField::$_dbfields);
     PluginGenericobjectType::includeConstants($object_type->fields['name'], true);
     self::addReadOnlyFields($object_type);
     foreach ($GO_BLACKLIST_FIELDS as $autofield) {
         if (!in_array($autofield, $used_fields)) {
             $used_fields[$autofield] = $autofield;
         }
     }
     echo "<div class='center'>";
     echo "<form name='fieldslist' method='POST' action='{$url}'>";
     echo "<table class='tab_cadre_fixe' >";
     echo "<input type='hidden' name='id' value='{$id}'>";
     echo "<tr class='tab_bg_1'><th colspan='7'>";
     echo __("Fields associated with the object", "genericobject") . " : ";
     echo $itemtype::getTypeName();
     echo "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='10'></th>";
     echo "<th>" . __("Label", "genericobject") . "</th>";
     echo "<th>" . __("Name in DB", "genericobject") . "</th>";
     echo "<th width='10'></th>";
     echo "<th width='10'></th>";
     echo "</tr>";
     $total = count($fields_in_db);
     $global_index = $index = 1;
     foreach ($fields_in_db as $field => $value) {
         self::displayFieldDefinition($url, $itemtype, $field, $index, $global_index == $total);
         //All backlisted fields cannot be moved, and are listed first
         if (!in_array($field, $GO_READONLY_FIELDS)) {
             $index++;
         }
         $table = getTableNameForForeignKeyField($field);
         $used_fields[$field] = $field;
         $global_index++;
     }
     echo "</table>";
     Html::openArrowMassives('fieldslist', true);
     Html::closeArrowMassives(array('delete' => __("Delete permanently")));
     echo "<table class='tab_cadre genericobject_fields add_new'>";
     echo "<tr class='tab_bg_1'>";
     echo "<td class='label'>" . __("Add new field", "genericobject") . "</td>";
     echo "<td align='left' class='dropdown'>";
     self::dropdownFields("new_field", $itemtype, $used_fields);
     echo "</td>";
     echo "<td>";
     echo "<input type='submit' name='add_field' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }
Example #2
0
 function showForm($id, $options = array(), $previsualisation = false)
 {
     global $DB;
     if ($previsualisation) {
         $canedit = true;
         $this->getEmpty();
     } else {
         if ($id > 0) {
             $this->check($id, 'r');
         } else {
             // Create item
             $this->check(-1, 'w');
             $this->getEmpty();
         }
         $this->showTabs($options);
         $canedit = $this->can($id, 'w');
     }
     if (isset($options['withtemplate']) && $options['withtemplate'] == 2) {
         $template = "newcomp";
         $date = sprintf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"]));
     } else {
         if (isset($options['withtemplate']) && $options['withtemplate'] == 1) {
             $template = "newtemplate";
             $date = sprintf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"]));
         } else {
             $date = sprintf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
             $template = false;
         }
     }
     $this->fields['id'] = $id;
     $this->showFormHeader($options);
     if ($previsualisation) {
         echo "<tr><th colspan='4'>" . __("Object preview", "genericobject") . ":&nbsp;";
         $itemtype = $this->objecttype->fields['itemtype'];
         echo $itemtype::getTypeName();
         echo "</th></tr>";
     }
     //Reset fields definition only to keep the itemtype ones
     $GO_FIELDS = array();
     plugin_genericobject_includeCommonFields(true);
     PluginGenericobjectType::includeConstants($this->getObjectTypeName(), true);
     foreach (PluginGenericobjectSingletonObjectField::getInstance($this->objecttype->fields['itemtype']) as $field => $description) {
         $this->displayField($canedit, $field, $this->fields[$field], $template, $description);
     }
     $this->closeColumn();
     if (!$this->isNewID($id)) {
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2' class='center'>" . $date;
         if (!$template && !empty($this->fields['template_name'])) {
             echo "<span class='small_space'>(" . __("Template name") . "&nbsp;: " . $this->fields['template_name'] . ")</span>";
         }
         echo "</td></tr>";
     }
     if (!$previsualisation) {
         $this->showFormButtons($options);
         echo "<div id='tabcontent'></div>";
         echo "<script type='text/javascript'>loadDefaultTab();</script>";
     } else {
         echo "</table></div>";
         Html::closeForm();
     }
 }
Example #3
0
 /**
  *
  * Displat all fields present in DB for an itemtype
  * @param $id the itemtype's id
  */
 public static function showObjectFieldsForm($id)
 {
     global $DB, $GO_BLACKLIST_FIELDS, $GO_READONLY_FIELDS, $GO_FIELDS, $CFG_GLPI;
     $url = Toolbox::getItemTypeFormURL(__CLASS__);
     $object_type = new PluginGenericobjectType();
     $object_type->getFromDB($id);
     $itemtype = $object_type->fields['itemtype'];
     $fields_in_db = PluginGenericobjectSingletonObjectField::getInstance($itemtype);
     $used_fields = array();
     //Reset fields definition only to keep the itemtype ones
     $GO_FIELDS = array();
     plugin_genericobject_includeCommonFields(true);
     $file = GLPI_ROOT . "/plugins/genericobject/fields/constants/" . $object_type->fields['name'] . ".constant.php";
     if (file_exists($file)) {
         include $file;
     }
     PluginGenericobjectType::includeConstants($itemtype, true);
     foreach ($GO_BLACKLIST_FIELDS as $autofield) {
         if (!in_array($autofield, $used_fields)) {
             $used_fields[$autofield] = $autofield;
         }
     }
     echo "<div class='center'>";
     echo "<form name='fieldslist' method='POST' action='{$url}'>";
     echo "<table class='tab_cadre_fixe' >";
     echo "<input type='hidden' name='id' value='{$id}'>";
     echo "<tr class='tab_bg_1'><th colspan='7'>";
     echo __("Fields associated with the object", "genericobject") . " : ";
     echo $itemtype::getTypeName();
     echo "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='10'></th>";
     echo "<th>" . __("Label", "genericobject") . "</th>";
     echo "<th>" . __("Name in DB", "genericobject") . "</th>";
     echo "<th width='10'></th>";
     echo "<th width='10'></th>";
     echo "</tr>";
     $total = count($fields_in_db);
     $global_index = $index = 1;
     foreach ($fields_in_db as $field => $value) {
         self::displayFieldDefinition($url, $itemtype, $field, $index, $global_index == $total);
         //All backlisted fields cannot be moved, and are listed first
         if (!in_array($field, $GO_READONLY_FIELDS)) {
             $index++;
         }
         //If it's a plugin dropdowns, get it's real name
         //(it may not be the one from the DB, in case it's a global field)
         $table = getTableNameForForeignKeyField($field);
         /*if ($table != '' && isPluginItemType(getItemTypeForTable($table))) {
              $classname = getItemTypeForTable($table);
              $class     = new $classname();
              $used_fields[$class->getFieldName()] = $class->getFieldName();
           } else {*/
         $used_fields[$field] = $field;
         //}
         $global_index++;
     }
     echo "</table>";
     Html::openArrowMassives('fieldslist', true);
     Html::closeArrowMassives(array('delete' => __("Delete permanently")));
     echo "<table class='tab_cadre'>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __("Add new field", "genericobject") . "</td>";
     echo "<td align='left'>";
     self::dropdownFields("new_field", $itemtype, $used_fields);
     echo "</td>";
     echo "<td>";
     echo "<input type='submit' name='add_field' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }