From bdecae88edcad686379e1426fd1e0de9639d7be0 Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 15 Sep 2015 13:37:26 +0200 Subject: [PATCH 1/9] Added "is_visible" to dropdowns in fields plugin Added "is_visible" to dropdowns in fields plugin SVN r403 2014-02-04 --- inc/container.class.php | 221 ++++++++++++++--------------------- inc/dropdownbase.class.php | 42 +++++++ inc/field.class.php | 134 ++++++++++----------- templates/dropdown.class.tpl | 1 + 4 files changed, 192 insertions(+), 206 deletions(-) create mode 100644 inc/dropdownbase.class.php diff --git a/inc/container.class.php b/inc/container.class.php index 4f2777ff..1b9169ac 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -158,7 +158,6 @@ function post_addItem() { "/plugins/fields/templates/container.class.tpl"); $template_class = str_replace("%%CLASSNAME%%", $classname, $template_class); $template_class = str_replace("%%ITEMTYPE%%", $this->fields['itemtype'], $template_class); - $template_class = str_replace("%%CONTAINER%%", $this->fields['id'], $template_class); $class_filename = strtolower($this->fields['itemtype']. preg_replace('/s$/', '', $this->fields['name']).".class.php"); if (file_put_contents(GLPI_ROOT."/plugins/fields/inc/$class_filename", @@ -378,159 +377,93 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtempl function updateFieldsValues($datas) { global $DB; - if (self::validateValues($datas) === false) return false; - //insert datas in new table $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. + $classname = "PluginFields".ucfirst($container_obj->fields['itemtype']. preg_replace('/s$/', '', $container_obj->fields['name'])); $obj = new $classname; //check if datas already inserted - $found = $obj->find("items_id = $items_id"); + $found = $obj->find("items_id = ".$datas['items_id']); if (empty($found)) { $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; - } + //insert datas in vanilla table + $c_id = $datas['plugin_fields_containers_id']; + $items_id = $datas['items_id']; - /** - * Add log in "itemtype" object on fields values update - * @param int $containers_id : - * @param int $items_id : - * @param string $itemtype : - * @param array $datas : values send by update form - * @param array $old_values : old values, if empty -> values add - * @return nothing - */ - static function constructHistory($containers_id, $items_id, $itemtype, $datas, - $old_values = array()) { - //get searchoptions - $searchoptions = self::getAddSearchOptions($itemtype, $containers_id); - - //define non-datas keys - $blacklist_k = array('plugin_fields_containers_id' => 0, 'items_id' => 0, - 'update_fields_values' => 0); - - //remove non-datas keys - $datas = array_diff_key($datas, $blacklist_k); - - //add/update values condition - if (empty($old_values)) { - // -- add new item -- - - foreach ($datas as $key => $value) { - //log only not empty values - if (!empty($value)) { - //prepare log - $changes = array(0, "", $value); - - //find searchoption - foreach ($searchoptions as $id_search_option => $searchoption) { - if ($searchoption['linkfield'] == $key) { - $changes[0] = $id_search_option; - - //manage dropdown values - if ($searchoption['datatype'] === 'dropdown') { - $changes = array($id_search_option, "", - Dropdown::getDropdownName($searchoption['table'],$value)); - } - break; - } - } + //get itemtype + $container = new self; + $container->getFromDB($c_id); + $itemtype = $container->fields['itemtype']; + + //unset unused datas + unset( + $datas['plugin_fields_containers_id'], + $datas['items_id'], + $datas['update_fields_values'] + ); - //add log - Log::history($items_id, $itemtype, $changes); - } + $field_obj = new PluginFieldsField; + $field_value_obj = new PluginFieldsValue; + foreach($datas as $field => $value) { + //parse name for dropdown + if (strpos($field, "dropdown") !== false) { + $field = str_replace("plugin_fields_", "", $field); + $field = str_replace("dropdowns_id", "", $field); } - } else { - // -- update existing item -- - - //find changes - $updates = array(); - foreach ($old_values as $key => $old_value) { - if (!isset($datas[$key]) - || empty($old_value) && empty($datas[$key]) - || $old_value !== '' && $datas[$key] == 'NULL' - ) { - continue; - } - if ($datas[$key] !== $old_value) { - $updates[$key] = array(0, $old_value, $datas[$key]); - } + //find field + $found_f = $field_obj->find( + "`plugin_fields_containers_id` = $c_id AND `name` = '".$field."'"); + if (count($found_f) == 0) { + continue; } + $tmp_f = array_shift($found_f); + $fields_id = $tmp_f['id']; - //for all change find searchoption - foreach ($updates as $key => $changes) { - foreach ($searchoptions as $id_search_option => $searchoption) { - if ($searchoption['linkfield'] == $key) { - $changes[0] = $id_search_option; - - //manage dropdown values - if ($searchoption['datatype'] === 'dropdown') { - $changes[1] = Dropdown::getDropdownName($searchoption['table'],$changes[1]); - $changes[2] = Dropdown::getDropdownName($searchoption['table'],$changes[2]); - } - break; - } - } + //find existing values + $found_v = $field_value_obj->find( + "`plugin_fields_fields_id` = $fields_id AND `items_id` = '".$items_id."'"); - //add log - Log::history($items_id, $itemtype, $changes); + $value_field = 'value_varchar'; + switch ($tmp_f['type']) { + case 'dropdown': + $value_field = 'value_int'; + break; + case 'yesno': + $value_field = 'value_int'; + break; + case 'textarea': + $value_field = 'value_text'; } - } - } - - /** - * check datas inserted (only nuber for the moment) - * display a message when not ok - * @param array $datas : datas send by form - * @return boolean - */ - static function validateValues($datas) { - global $LANG; - - $field_obj = new PluginFieldsField; - $fields = $field_obj->find("plugin_fields_containers_id = ". - $datas['plugin_fields_containers_id']." AND type = 'number'"); - unset($datas['plugin_fields_containers_id']); - unset($datas['items_id']); - unset($datas['update_fields_values']); - $datas_keys = array_keys($datas); - - $fields_error = array(); - foreach ($fields as $fields_id => $field) { - if (empty($datas[$field['name']])) continue; - if (!preg_match("/[-+]?[0-9]*\.?[0-9]+/", $datas[$field['name']])) { - $fields_error[] = $field['label']; + if (count($found_v) > 0) { + //update + $tmp_v = array_shift($found_v); + $values_id = $tmp_v['id']; + $field_value_obj->update(array( + 'id' => $values_id, + $value_field => $value + )); + } else { + // add + $field_value_obj->add(array( + 'items_id' => $items_id, + 'itemtype' => $itemtype, + $value_field => $value, + 'plugin_fields_containers_id' => $c_id, + 'plugin_fields_fields_id' => $fields_id + )); } } - if (!empty($fields_error)) { - Session::AddMessageAfterRedirect($LANG['fields']['error']['no_numeric_value']. - " : (".implode(", ", $fields_error).")"); - $_SESSION['plugin']['fields']['values_sent'] = $datas; - return false; - } else return true; + return true; } @@ -594,16 +527,34 @@ static function preItemUpdate(CommonDBTM $item) { $container = new self; return $container->updateFieldsValues($datas); } - - static function getAddSearchOptions($itemtype, $containers_id = false) { + + static function preItemPurge(CommonDBTM $item) { global $DB; - $opt = array(); + $values = new PluginFieldsValue; + + //get all value associated to this item + $query = "SELECT glpi_plugin_fields_values.id as values_id + FROM glpi_plugin_fields_containers + INNER JOIN glpi_plugin_fields_values + ON glpi_plugin_fields_values.plugin_fields_containers_id = glpi_plugin_fields_containers.id + WHERE glpi_plugin_fields_containers.itemtype = '".get_Class($item)."' + AND glpi_plugin_fields_values.items_id = ".$item->fields['id']; + $res = $DB->query($query); + while ($data = $DB->fetch_assoc($res)) { + $values_id = $data['values_id']; - $where = ""; - if ($containers_id !== false) { - $where = "AND containers.id = $containers_id"; + //remove associated values + $values->delete(array( + 'id' => $values_id + ), 1); } + } + + static function getAddSearchOptions($itemtype) { + global $DB; + + $opt = array(); $i = 76665; $query = "SELECT fields.name, fields.label, fields.type, @@ -615,7 +566,6 @@ static function getAddSearchOptions($itemtype, $containers_id = false) { AND containers.is_active = 1 WHERE containers.itemtype = '$itemtype' AND fields.type != 'header' - $where ORDER BY fields.id ASC"; $res = $DB->query($query); while ($datas = $DB->fetch_assoc($res)) { @@ -635,6 +585,7 @@ static function getAddSearchOptions($itemtype, $containers_id = false) { $opt[$i]['field'] = 'name'; $opt[$i]['linkfield'] = "plugin_fields_".$datas['name']."dropdowns_id"; $opt[$i]['searchtype'] = 'equals'; + $opt[$i]['condition'] = "is_visible=1" ; $opt[$i]['joinparams']['jointype'] = ""; $opt[$i]['joinparams']['beforejoin']['table'] = $tablename; $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item"; diff --git a/inc/dropdownbase.class.php b/inc/dropdownbase.class.php new file mode 100644 index 00000000..4a826be4 --- /dev/null +++ b/inc/dropdownbase.class.php @@ -0,0 +1,42 @@ +fields['id'])) { + // $this->getEmpty(); + // } + // return array_key_exists('is_visible', $this->fields); + //} + + function getAdditionalFields() { + global $LANG; + + $val = parent::getAdditionalFields() ; + //if( $this->mayBeVisible( ) ) { + $val[] = array('name' => 'is_visible', + 'label' => $LANG['group'][0], + 'type' => 'bool', + 'list' => false) ; + //} + + return $val; + } + + function getSearchOptions() { + global $LANG; + + $val = parent::getSearchOptions( ) ; + + //if( $this->mayBeVisible( ) ) { + $val[] = array( 'table' => $this->getTable(), + 'field' => 'is_visible', + 'name' => $LANG['group'][0], + 'datatype' => 'bool') ; + //} + + return $val ; + } + +} \ No newline at end of file diff --git a/inc/field.class.php b/inc/field.class.php index 3af138eb..11abe35e 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -104,6 +104,15 @@ function prepareInputForUpdate($input) { //parse name $input['name'] = $this->prepareName($input); + //rename field in container table + if ($this->fields['type'] !== "header") { + $container_obj = new PluginFieldsContainer; + $container_obj->getFromDB($input['plugin_fields_containers_id']); + $classname = "PluginFields".ucfirst(strtolower($container_obj->fields['itemtype']. + preg_replace('/s$/', '', $container_obj->fields['name']))); + $classname::renameField($this->fields['name'], $input['name'], $this->fields['type']); + } + return $input; } @@ -127,6 +136,12 @@ function pre_deleteItem() { $classname::removeField($this->fields['name']); } + //delete values + if (!isset($_SESSION['uninstall_fields']) ) { + $DB->query("DELETE FROM glpi_plugin_fields_values WHERE plugin_fields_fields_id = ". + $this->fields['id']); + } + if (isset($oldname)) $this->fields['name'] = $oldname; if ($this->fields['type'] === "dropdown") { @@ -365,34 +380,20 @@ static function showForDomContainer() { //parse http_referer to get current url (this code is loaded by javacript) $current_url = $_SERVER['HTTP_REFERER']; - if (strpos($current_url, ".form.php") === false - && strpos($current_url, ".injector.php") === false - && strpos($current_url, ".public.php") === false) { - return false; - } + if (strpos($current_url, ".form.php") === false) return false; $expl_url = explode("?", $current_url); + //if add item form, do nothing + if (!isset($expl_url[1]) || strpos($expl_url[1], "id=") === false) return false; + //get current id - if(isset($expl_url[1])) { - parse_str($expl_url[1], $params); - if(isset($params['id'])) { - $items_id = $params['id']; - } else { - $items_id = 0; - } - } else { - $items_id = 0; - } + parse_str($expl_url[1], $params); + $items_id = $params['id']; //get itemtype $tmp = explode("/", $expl_url[0]); $script_name = array_pop($tmp); - - if(in_array($script_name, array("helpdesk.public.php","tracking.injector.php"))) { - $current_itemtype = "Ticket"; - } else { - $current_itemtype = ucfirst(str_replace(".form.php", "", $script_name)); - } + $current_itemtype = ucfirst(str_replace(".form.php", "", $script_name)); //Retrieve dom container $itemtypes = PluginFieldsContainer::getEntries('dom', true); @@ -403,8 +404,7 @@ static function showForDomContainer() { echo "Ext.onReady(function() {\n Ext.select('#page form tr:last').each(function(el){ - el.insertHtml('beforeBegin', - ''); + el.insertHtml('beforeBegin', ''); Ext.get('dom_container').load({ url: '../plugins/fields/ajax/load_dom_fields.php', params: { @@ -413,7 +413,11 @@ static function showForDomContainer() { } }); }); - });\n"; + + + "; + + echo "});\n"; } static function AjaxForDomContainer($itemtype, $items_id) { @@ -428,27 +432,20 @@ static function AjaxForDomContainer($itemtype, $items_id) { echo ""; } + //static function maybeVisible($type) { + + // $loc = new $type ; + // if (!isset($loc->fields['id'])) { + // $loc->getEmpty(); + // } + // return array_key_exists('is_visible', $loc->fields); + //} static function prepareHtmlFields($fields, $items_id, $canedit = true, $show_table = true, $massiveaction = 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']); - $classname = "PluginFields".ucfirst($container_obj->fields['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); - - //show all fields $html = ""; + $field_value_obj = new PluginFieldsValue; $odd = 0; foreach($fields as $field) { @@ -460,21 +457,26 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } 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']]; + $found_v = $field_value_obj->find( + "`plugin_fields_fields_id` = ".$field['id']." AND `items_id` = '".$items_id."'"); + if (count($found_v) > 0) { + $tmp_v = array_shift($found_v); + switch ($field['type']) { + case 'number': + case 'text': + case 'date': + case 'datetime': + $value = $tmp_v['value_varchar']; + break; + case 'textarea': + $value = $tmp_v['value_text']; + break; + case 'dropdown': + case 'yesno': + $value = $tmp_v['value_int']; + break; + default: + $value = NULL; } } @@ -486,14 +488,7 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, //show field if ($show_table) { if ($odd%2 == 0) $html.= ""; - 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.= "".$field['label']." : "; - } else { - $html.= "".$field['label']." : "; - } + $html.= "".$field['label']." : "; $html.= ""; } switch ($field['type']) { @@ -507,8 +502,8 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } break; case 'textarea': - if ($massiveaction) continue; if ($canedit) { + echo $value; $html.= ""; } else { @@ -524,7 +519,10 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } else { $dropdown_itemtype = PluginFieldsDropdown::getClassname($field['name']); } - Dropdown::show($dropdown_itemtype, array('value' => $value)); + //if( self::mayBeVisible( $dropdown_itemtype ) ) + Dropdown::show($dropdown_itemtype, array('value' => $value, 'condition' => 'is_visible=1')); + //else + // Dropdown::show($dropdown_itemtype, array('value' => $value )); $html.= ob_get_contents(); ob_end_clean(); } else { @@ -547,7 +545,6 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } break; case 'date': - if ($massiveaction) continue; if ($canedit) { ob_start(); Html::showDateFormItem($field['name'], $value); @@ -558,7 +555,6 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } break; case 'datetime': - if ($massiveaction) continue; if ($canedit) { ob_start(); Html::showDateTimeFormItem($field['name'], $value); @@ -576,9 +572,6 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } } if ($show_table && $odd%2 == 1) $html.= ""; - - unset($_SESSION['plugin']['fields']['values_sent']); - return $html; } @@ -613,7 +606,6 @@ static function showSingle($itemtype, $searchOption, $massiveaction = false) { $fields = array(array( 'id' => 0, 'type' => $searchOption['pfields_type'], - 'plugin_fields_containers_id' => $c_id, 'name' => $cleaned_linkfield )); diff --git a/templates/dropdown.class.tpl b/templates/dropdown.class.tpl index 5530ac25..7995c65c 100644 --- a/templates/dropdown.class.tpl +++ b/templates/dropdown.class.tpl @@ -21,6 +21,7 @@ class %%CLASSNAME%% extends CommonTreeDropdown { `sons_cache` TEXT DEFAULT NULL, `entities_id` INT(11) NOT NULL DEFAULT '0', `is_recursive` TINYINT(1) NOT NULL DEFAULT '0', + `is_visible` TINYINT(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `entities_id` (`entities_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; From 65707be09ad657e71cadb14fad79d74ed2f94506 Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 15 Sep 2015 13:41:45 +0200 Subject: [PATCH 2/9] Updated sources with release from TecLib Updated sources with release from TecLib SVN r409 2014-02-05 --- inc/container.class.php | 220 +++++++++++++++++++++-------------- inc/field.class.php | 88 +++++++------- templates/dropdown.class.tpl | 4 +- 3 files changed, 176 insertions(+), 136 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index 1b9169ac..abe7095a 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -158,6 +158,7 @@ function post_addItem() { "/plugins/fields/templates/container.class.tpl"); $template_class = str_replace("%%CLASSNAME%%", $classname, $template_class); $template_class = str_replace("%%ITEMTYPE%%", $this->fields['itemtype'], $template_class); + $template_class = str_replace("%%CONTAINER%%", $this->fields['id'], $template_class); $class_filename = strtolower($this->fields['itemtype']. preg_replace('/s$/', '', $this->fields['name']).".class.php"); if (file_put_contents(GLPI_ROOT."/plugins/fields/inc/$class_filename", @@ -377,93 +378,159 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtempl function updateFieldsValues($datas) { global $DB; + if (self::validateValues($datas) === false) return false; + //insert datas in new table $container_obj = new PluginFieldsContainer; $container_obj->getFromDB($datas['plugin_fields_containers_id']); - $classname = "PluginFields".ucfirst($container_obj->fields['itemtype']. + + $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 = ".$datas['items_id']); + $found = $obj->find("items_id = $items_id"); if (empty($found)) { $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); } - //insert datas in vanilla table - $c_id = $datas['plugin_fields_containers_id']; - $items_id = $datas['items_id']; + return true; + } - //get itemtype - $container = new self; - $container->getFromDB($c_id); - $itemtype = $container->fields['itemtype']; - - //unset unused datas - unset( - $datas['plugin_fields_containers_id'], - $datas['items_id'], - $datas['update_fields_values'] - ); + /** + * Add log in "itemtype" object on fields values update + * @param int $containers_id : + * @param int $items_id : + * @param string $itemtype : + * @param array $datas : values send by update form + * @param array $old_values : old values, if empty -> values add + * @return nothing + */ + static function constructHistory($containers_id, $items_id, $itemtype, $datas, + $old_values = array()) { + //get searchoptions + $searchoptions = self::getAddSearchOptions($itemtype, $containers_id); + + //define non-datas keys + $blacklist_k = array('plugin_fields_containers_id' => 0, 'items_id' => 0, + 'update_fields_values' => 0); + + //remove non-datas keys + $datas = array_diff_key($datas, $blacklist_k); + + //add/update values condition + if (empty($old_values)) { + // -- add new item -- + + foreach ($datas as $key => $value) { + //log only not empty values + if (!empty($value)) { + //prepare log + $changes = array(0, "", $value); + + //find searchoption + foreach ($searchoptions as $id_search_option => $searchoption) { + if ($searchoption['linkfield'] == $key) { + $changes[0] = $id_search_option; + + //manage dropdown values + if ($searchoption['datatype'] === 'dropdown') { + $changes = array($id_search_option, "", + Dropdown::getDropdownName($searchoption['table'],$value)); + } + break; + } + } - $field_obj = new PluginFieldsField; - $field_value_obj = new PluginFieldsValue; - foreach($datas as $field => $value) { - //parse name for dropdown - if (strpos($field, "dropdown") !== false) { - $field = str_replace("plugin_fields_", "", $field); - $field = str_replace("dropdowns_id", "", $field); + //add log + Log::history($items_id, $itemtype, $changes); + } } + } else { + // -- update existing item -- + + //find changes + $updates = array(); + foreach ($old_values as $key => $old_value) { + if (!isset($datas[$key]) + || empty($old_value) && empty($datas[$key]) + || $old_value !== '' && $datas[$key] == 'NULL' + ) { + continue; + } - //find field - $found_f = $field_obj->find( - "`plugin_fields_containers_id` = $c_id AND `name` = '".$field."'"); - if (count($found_f) == 0) { - continue; + if ($datas[$key] !== $old_value) { + $updates[$key] = array(0, $old_value, $datas[$key]); + } } - $tmp_f = array_shift($found_f); - $fields_id = $tmp_f['id']; - //find existing values - $found_v = $field_value_obj->find( - "`plugin_fields_fields_id` = $fields_id AND `items_id` = '".$items_id."'"); + //for all change find searchoption + foreach ($updates as $key => $changes) { + foreach ($searchoptions as $id_search_option => $searchoption) { + if ($searchoption['linkfield'] == $key) { + $changes[0] = $id_search_option; + + //manage dropdown values + if ($searchoption['datatype'] === 'dropdown') { + $changes[1] = Dropdown::getDropdownName($searchoption['table'],$changes[1]); + $changes[2] = Dropdown::getDropdownName($searchoption['table'],$changes[2]); + } + break; + } + } - $value_field = 'value_varchar'; - switch ($tmp_f['type']) { - case 'dropdown': - $value_field = 'value_int'; - break; - case 'yesno': - $value_field = 'value_int'; - break; - case 'textarea': - $value_field = 'value_text'; + //add log + Log::history($items_id, $itemtype, $changes); } + } + } - if (count($found_v) > 0) { - //update - $tmp_v = array_shift($found_v); - $values_id = $tmp_v['id']; - $field_value_obj->update(array( - 'id' => $values_id, - $value_field => $value - )); - } else { - // add - $field_value_obj->add(array( - 'items_id' => $items_id, - 'itemtype' => $itemtype, - $value_field => $value, - 'plugin_fields_containers_id' => $c_id, - 'plugin_fields_fields_id' => $fields_id - )); + /** + * check datas inserted (only nuber for the moment) + * display a message when not ok + * @param array $datas : datas send by form + * @return boolean + */ + static function validateValues($datas) { + global $LANG; + + $field_obj = new PluginFieldsField; + $fields = $field_obj->find("plugin_fields_containers_id = ". + $datas['plugin_fields_containers_id']." AND type = 'number'"); + + unset($datas['plugin_fields_containers_id']); + unset($datas['items_id']); + unset($datas['update_fields_values']); + $datas_keys = array_keys($datas); + + $fields_error = array(); + foreach ($fields as $fields_id => $field) { + if (empty($datas[$field['name']])) continue; + if (!preg_match("/[-+]?[0-9]*\.?[0-9]+/", $datas[$field['name']])) { + $fields_error[] = $field['label']; } } - return true; + if (!empty($fields_error)) { + Session::AddMessageAfterRedirect($LANG['fields']['error']['no_numeric_value']. + " : (".implode(", ", $fields_error).")"); + $_SESSION['plugin']['fields']['values_sent'] = $datas; + return false; + } else return true; } @@ -527,35 +594,17 @@ static function preItemUpdate(CommonDBTM $item) { $container = new self; return $container->updateFieldsValues($datas); } - - static function preItemPurge(CommonDBTM $item) { - global $DB; - - $values = new PluginFieldsValue; - - //get all value associated to this item - $query = "SELECT glpi_plugin_fields_values.id as values_id - FROM glpi_plugin_fields_containers - INNER JOIN glpi_plugin_fields_values - ON glpi_plugin_fields_values.plugin_fields_containers_id = glpi_plugin_fields_containers.id - WHERE glpi_plugin_fields_containers.itemtype = '".get_Class($item)."' - AND glpi_plugin_fields_values.items_id = ".$item->fields['id']; - $res = $DB->query($query); - while ($data = $DB->fetch_assoc($res)) { - $values_id = $data['values_id']; - - //remove associated values - $values->delete(array( - 'id' => $values_id - ), 1); - } - } - static function getAddSearchOptions($itemtype) { + static function getAddSearchOptions($itemtype, $containers_id = false) { global $DB; $opt = array(); + $where = ""; + if ($containers_id !== false) { + $where = "AND containers.id = $containers_id"; + } + $i = 76665; $query = "SELECT fields.name, fields.label, fields.type, containers.name as container_name, containers.label as container_label, @@ -566,6 +615,7 @@ static function getAddSearchOptions($itemtype) { AND containers.is_active = 1 WHERE containers.itemtype = '$itemtype' AND fields.type != 'header' + $where ORDER BY fields.id ASC"; $res = $DB->query($query); while ($datas = $DB->fetch_assoc($res)) { diff --git a/inc/field.class.php b/inc/field.class.php index 11abe35e..51a927ff 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -104,15 +104,6 @@ function prepareInputForUpdate($input) { //parse name $input['name'] = $this->prepareName($input); - //rename field in container table - if ($this->fields['type'] !== "header") { - $container_obj = new PluginFieldsContainer; - $container_obj->getFromDB($input['plugin_fields_containers_id']); - $classname = "PluginFields".ucfirst(strtolower($container_obj->fields['itemtype']. - preg_replace('/s$/', '', $container_obj->fields['name']))); - $classname::renameField($this->fields['name'], $input['name'], $this->fields['type']); - } - return $input; } @@ -136,12 +127,6 @@ function pre_deleteItem() { $classname::removeField($this->fields['name']); } - //delete values - if (!isset($_SESSION['uninstall_fields']) ) { - $DB->query("DELETE FROM glpi_plugin_fields_values WHERE plugin_fields_fields_id = ". - $this->fields['id']); - } - if (isset($oldname)) $this->fields['name'] = $oldname; if ($this->fields['type'] === "dropdown") { @@ -432,20 +417,27 @@ static function AjaxForDomContainer($itemtype, $items_id) { echo ""; } - //static function maybeVisible($type) { - - // $loc = new $type ; - // if (!isset($loc->fields['id'])) { - // $loc->getEmpty(); - // } - // return array_key_exists('is_visible', $loc->fields); - //} static function prepareHtmlFields($fields, $items_id, $canedit = true, $show_table = true, $massiveaction = 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']); + $classname = "PluginFields".ucfirst($container_obj->fields['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); + + //show all fields $html = ""; - $field_value_obj = new PluginFieldsValue; $odd = 0; foreach($fields as $field) { @@ -457,26 +449,21 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } else { //get value $value = ""; - $found_v = $field_value_obj->find( - "`plugin_fields_fields_id` = ".$field['id']." AND `items_id` = '".$items_id."'"); - if (count($found_v) > 0) { - $tmp_v = array_shift($found_v); - switch ($field['type']) { - case 'number': - case 'text': - case 'date': - case 'datetime': - $value = $tmp_v['value_varchar']; - break; - case 'textarea': - $value = $tmp_v['value_text']; - break; - case 'dropdown': - case 'yesno': - $value = $tmp_v['value_int']; - break; - default: - $value = NULL; + 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']]; } } @@ -502,8 +489,8 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } break; case 'textarea': + if ($massiveaction) continue; if ($canedit) { - echo $value; $html.= ""; } else { @@ -519,10 +506,7 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } else { $dropdown_itemtype = PluginFieldsDropdown::getClassname($field['name']); } - //if( self::mayBeVisible( $dropdown_itemtype ) ) - Dropdown::show($dropdown_itemtype, array('value' => $value, 'condition' => 'is_visible=1')); - //else - // Dropdown::show($dropdown_itemtype, array('value' => $value )); + Dropdown::show($dropdown_itemtype, array('value' => $value, 'condition' => 'is_visible=1' )); $html.= ob_get_contents(); ob_end_clean(); } else { @@ -545,6 +529,7 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } break; case 'date': + if ($massiveaction) continue; if ($canedit) { ob_start(); Html::showDateFormItem($field['name'], $value); @@ -555,6 +540,7 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } break; case 'datetime': + if ($massiveaction) continue; if ($canedit) { ob_start(); Html::showDateTimeFormItem($field['name'], $value); @@ -572,6 +558,9 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } } if ($show_table && $odd%2 == 1) $html.= ""; + + unset($_SESSION['plugin']['fields']['values_sent']); + return $html; } @@ -606,6 +595,7 @@ static function showSingle($itemtype, $searchOption, $massiveaction = false) { $fields = array(array( 'id' => 0, 'type' => $searchOption['pfields_type'], + 'plugin_fields_containers_id' => $c_id, 'name' => $cleaned_linkfield )); diff --git a/templates/dropdown.class.tpl b/templates/dropdown.class.tpl index 7995c65c..205ec243 100644 --- a/templates/dropdown.class.tpl +++ b/templates/dropdown.class.tpl @@ -1,6 +1,6 @@ Date: Tue, 15 Sep 2015 13:43:11 +0200 Subject: [PATCH 3/9] added invisible item in search (=commented out the line $opt[$i]['condition']="is_visible=1";) added invisible item in search (=commented out the line $opt[$i]['condition']="is_visible=1";) SVN r410 2014-02-06 --- inc/container.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/container.class.php b/inc/container.class.php index abe7095a..fb661d71 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -635,7 +635,7 @@ static function getAddSearchOptions($itemtype, $containers_id = false) { $opt[$i]['field'] = 'name'; $opt[$i]['linkfield'] = "plugin_fields_".$datas['name']."dropdowns_id"; $opt[$i]['searchtype'] = 'equals'; - $opt[$i]['condition'] = "is_visible=1" ; + //$opt[$i]['condition'] = "is_visible=1" ; $opt[$i]['joinparams']['jointype'] = ""; $opt[$i]['joinparams']['beforejoin']['table'] = $tablename; $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item"; From cb6493726e491c355fdf37dd5feb2c9e3039f376 Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 15 Sep 2015 13:46:49 +0200 Subject: [PATCH 4/9] Added a test on current user logged in: to be sure there is a human Added a test on current user logged in: to be sure there is a human SVN r493 2014-10-07 --- setup.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/setup.php b/setup.php index c79ac4c8..adfdab11 100644 --- a/setup.php +++ b/setup.php @@ -6,7 +6,8 @@ function plugin_init_fields() { $plugin = new Plugin(); if (isset($_SESSION['glpiactiveentities']) && $plugin->isInstalled('fields') - && $plugin->isActivated('fields')) { + && $plugin->isActivated('fields') + && Session::getLoginUserID() ) { Plugin::registerClass('PluginFieldsContainer', array('addtabon' => PluginFieldsContainer::getEntries())); @@ -42,8 +43,6 @@ function plugin_init_fields() { "preItemUpdate"); $PLUGIN_HOOKS['pre_item_purge'] ['fields'][$itemtype] = array("PluginFieldsContainer", "preItemPurge"); - $PLUGIN_HOOKS['item_add']['fields'][$itemtype] = array("PluginFieldsContainer", - "preItemUpdate"); } } } From 2f9e95fcc62d79d22a11b6bdcf9dc344d7e6ed5f Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 15 Sep 2015 13:48:29 +0200 Subject: [PATCH 5/9] Added a filter on $_SESSION['glpiactiveprofile']['id'] to prevent errors when this glpiactiveprofile key is not existing Added a filter on $_SESSION['glpiactiveprofile']['id'] to prevent errors when this glpiactiveprofile key is not existing SVN r494 2014-10-07 --- inc/container.class.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index fb661d71..fa5e9492 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -329,10 +329,14 @@ static function getEntries($type = 'tab', $full = false) { } //profiles restriction - $found = $profile->find("`profiles_id` = '".$_SESSION['glpiactiveprofile']['id']."' - AND `plugin_fields_containers_id` = '".$item['id']."'"); - $first_found = array_shift($found); - if ($first_found['right'] == NULL) continue; + if( isset($_SESSION['glpiactiveprofile']['id'])) { + $found = $profile->find("`profiles_id` = '".$_SESSION['glpiactiveprofile']['id']."' + AND `plugin_fields_containers_id` = '".$item['id']."'"); + $first_found = array_shift($found); + if ($first_found['right'] == NULL) continue; + } else + continue ; + //show more info or not if ($full) { From 7ec83d1236d057ed60eefdb56a78351d0643e67e Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 15 Sep 2015 13:50:02 +0200 Subject: [PATCH 6/9] Added a filter on HTTP_REFERER Added a filter on HTTP_REFERER SVN r495 2014-10-07 --- inc/field.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/field.class.php b/inc/field.class.php index 51a927ff..73741b83 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -364,7 +364,10 @@ static function showForTabContainer($c_id, $items_id) { static function showForDomContainer() { //parse http_referer to get current url (this code is loaded by javacript) - $current_url = $_SERVER['HTTP_REFERER']; + if( isset( $_SERVER['HTTP_REFERER'] ) ) + $current_url = $_SERVER['HTTP_REFERER']; + else return false ; + if (strpos($current_url, ".form.php") === false) return false; $expl_url = explode("?", $current_url); From 87624769cb222b2ec4706c62cb6b547a80f854d9 Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 15 Sep 2015 13:50:58 +0200 Subject: [PATCH 7/9] Added a 'forcegroupby' to be sure that the ordernumber.name field will belong to an aggregate function, otherwise sometimes (randomly) mySQL Added a 'forcegroupby' to be sure that the ordernumber.name field will belong to an aggregate function, otherwise sometimes (randomly) mySQL will output NULL values. SVN r545 2014-12-01 --- inc/container.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/container.class.php b/inc/container.class.php index fa5e9492..a4bda5bf 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -639,6 +639,7 @@ static function getAddSearchOptions($itemtype, $containers_id = false) { $opt[$i]['field'] = 'name'; $opt[$i]['linkfield'] = "plugin_fields_".$datas['name']."dropdowns_id"; $opt[$i]['searchtype'] = 'equals'; + $opt[$i]['forcegroupby'] = true ; // to fix a bug in mySQL: see http://bugs.mysql.com/bug.php?id=69268 and http://bugs.mysql.com/bug.php?id=68897 fixed in mySQL 5.6.13 //$opt[$i]['condition'] = "is_visible=1" ; $opt[$i]['joinparams']['jointype'] = ""; $opt[$i]['joinparams']['beforejoin']['table'] = $tablename; From 041ea4eddf4b121a7b4c8cf8466032549393285c Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 15 Sep 2015 13:55:18 +0200 Subject: [PATCH 8/9] Added read-only feature and new 'dropdown user' field type Added to fields plugin possibilities: 1) to set a field as read-only 2) to use 'dropdown user' as field type SVN r685 2015-06-02 --- inc/container.class.php | 24 +++++++++++++---- inc/field.class.php | 60 ++++++++++++++++++++++++++++++++--------- inc/migration.class.php | 3 ++- locales/en_GB.php | 4 +++ locales/fr_FR.php | 4 +++ setup.php | 4 +-- 6 files changed, 78 insertions(+), 21 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index a4bda5bf..814fb297 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -610,7 +610,7 @@ static function getAddSearchOptions($itemtype, $containers_id = false) { } $i = 76665; - $query = "SELECT fields.name, fields.label, fields.type, + $query = "SELECT fields.name, fields.label, fields.type, fields.is_readonly, containers.name as container_name, containers.label as container_label, containers.itemtype FROM glpi_plugin_fields_containers containers @@ -630,7 +630,10 @@ static function getAddSearchOptions($itemtype, $containers_id = false) { $opt[$i]['name'] = $datas['container_label']." - ".$datas['label']; $opt[$i]['linkfield'] = $datas['name']; //$opt[$i]['condition'] = "glpi_plugin_fields_fields.name = '".$datas['name']."'"; - //$opt[$i]['massiveaction'] = false; + + if( $datas['is_readonly'] ) + $opt[$i]['massiveaction'] = false; + $opt[$i]['joinparams']['jointype'] = "itemtype_item"; $opt[$i]['pfields_type'] = $datas['type']; @@ -644,11 +647,22 @@ static function getAddSearchOptions($itemtype, $containers_id = false) { $opt[$i]['joinparams']['jointype'] = ""; $opt[$i]['joinparams']['beforejoin']['table'] = $tablename; $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item"; - } + } elseif ($datas['type'] === "dropdownuser") { + $opt[$i]['table'] = 'glpi_users'; + $opt[$i]['field'] = 'name'; + $opt[$i]['linkfield'] = $datas['name']; + //$opt[$i]['searchtype'] = 'equals'; + $opt[$i]['forcegroupby'] = true ; // to fix a bug in mySQL: see http://bugs.mysql.com/bug.php?id=69268 and http://bugs.mysql.com/bug.php?id=68897 fixed in mySQL 5.6.13 + //$opt[$i]['condition'] = "is_visible=1" ; + $opt[$i]['joinparams']['jointype'] = ""; + $opt[$i]['joinparams']['beforejoin']['table'] = $tablename; + $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item"; + } switch ($datas['type']) { - case 'dropdown': - $opt[$i]['datatype'] = "dropdown"; + case 'dropdown': + case 'dropdownuser': + $opt[$i]['datatype'] = "dropdown"; break; case 'yesno': $opt[$i]['datatype'] = "bool"; diff --git a/inc/field.class.php b/inc/field.class.php index 73741b83..b55ee497 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -23,6 +23,10 @@ static function install(Migration $migration) { KEY `plugin_fields_containers_id` (`plugin_fields_containers_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die ($DB->error()); + } else { //table exists, but we may add fields + + $migration->addField( $table, 'is_readonly', 'bool', array('default' => false)) ; + $migration->executeMigration(); } return true; @@ -148,7 +152,7 @@ function prepareName($input) { } //for dropdown, if already exist, link to it - if ($input['type'] === "dropdown") { + if (isset( $input['type'] ) && $input['type'] === "dropdown") { $found = $this->find("name = '".$input['name']."'"); if (!empty($found)) return $input['name']; } @@ -247,6 +251,7 @@ function showSummary($container) { echo "" . $LANG['mailing'][139] . ""; echo "" . $LANG['common'][17] . ""; echo "" . $LANG['common'][44] . ""; + echo "" . $LANG['fields']['field']['label']['readonly'] . ""; echo "\n"; $fields_type = self::getTypes(); @@ -269,7 +274,10 @@ function showSummary($container) { echo "\n"; echo $this->fields['label'].""; echo "".$fields_type[$this->fields['type']].""; - echo "".$this->fields['default_value'].""; + echo "".$this->fields['default_value'].""; + echo ""; + Dropdown::showYesNo("is_readonly",$this->fields["is_readonly"],-1,array('readonly' => true)); + echo ""; echo "\n"; } } @@ -294,6 +302,7 @@ function showForm($ID, $options=array()) { $this->check(-1,'w',$input); } + $options['colspan'] = 3 ; $this->showFormHeader($options); echo ""; @@ -318,8 +327,12 @@ function showForm($ID, $options=array()) { Html::autocompletionTextField($this, 'default_value', array('value' => $this->fields["default_value"])); echo ""; + echo "".$LANG['fields']['field']['label']['readonly'].":"; + echo ""; + Dropdown::showYesNo("is_readonly",$this->fields["is_readonly"]); + echo ""; echo ""; - + $this->showFormButtons($options); } @@ -481,11 +494,12 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, $html.= "".$field['label']." : "; $html.= ""; } + $readonly = $field['is_readonly']; switch ($field['type']) { case 'number': case 'text': $value = Html::cleanInputText($value); - if ($canedit) { + if ($canedit && !$readonly) { $html.= ""; } else { $html.= $value; @@ -493,7 +507,7 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, break; case 'textarea': if ($massiveaction) continue; - if ($canedit) { + if ($canedit && !$readonly) { $html.= ""; } else { @@ -501,7 +515,7 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } break; case 'dropdown': - if ($canedit) { + if ($canedit && !$readonly) { ob_start(); if (strpos($field['name'], "dropdowns_id") !== false) { $dropdown_itemtype = getItemTypeForTable( @@ -522,7 +536,7 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, //otherwise double display of field if ($massiveaction) continue; - if ($canedit) { + if ($canedit && !$readonly) { ob_start(); Dropdown::showYesNo($field['name'], $value); $html.= ob_get_contents(); @@ -533,7 +547,7 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, break; case 'date': if ($massiveaction) continue; - if ($canedit) { + if ($canedit && !$readonly) { ob_start(); Html::showDateFormItem($field['name'], $value); $html.= ob_get_contents(); @@ -544,7 +558,7 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, break; case 'datetime': if ($massiveaction) continue; - if ($canedit) { + if ($canedit && !$readonly) { ob_start(); Html::showDateTimeFormItem($field['name'], $value); $html.= ob_get_contents(); @@ -552,6 +566,24 @@ static function prepareHtmlFields($fields, $items_id, $canedit = true, } 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.= ""; @@ -578,7 +610,7 @@ static function showSingle($itemtype, $searchOption, $massiveaction = false) { $searchOption['linkfield']); //find field - $query_f = "SELECT fields.plugin_fields_containers_id + $query_f = "SELECT fields.plugin_fields_containers_id, fields.is_readonly FROM glpi_plugin_fields_fields fields LEFT JOIN glpi_plugin_fields_containers containers ON containers.id = fields.plugin_fields_containers_id @@ -594,12 +626,13 @@ static function showSingle($itemtype, $searchOption, $massiveaction = false) { //display an hidden post field to store container id echo ""; - //preapre arary for function prepareHtmlFields + //prepare array for function prepareHtmlFields $fields = array(array( 'id' => 0, 'type' => $searchOption['pfields_type'], 'plugin_fields_containers_id' => $c_id, - 'name' => $cleaned_linkfield + 'name' => $cleaned_linkfield, + 'is_readonly' => $row_f['is_readonly'] )); //show field @@ -618,7 +651,8 @@ static function getTypes() { 'dropdown' => $LANG['fields']['field']['type']['dropdown'], 'yesno' => $LANG['fields']['field']['type']['yesno'], 'date' => $LANG['fields']['field']['type']['date'], - 'datetime' => $LANG['fields']['field']['type']['datetime'] + 'datetime' => $LANG['fields']['field']['type']['datetime'], + 'dropdownuser' => $LANG['fields']['field']['type']['dropdownuser'] ); } diff --git a/inc/migration.class.php b/inc/migration.class.php index 35e551cc..252b9863 100644 --- a/inc/migration.class.php +++ b/inc/migration.class.php @@ -47,7 +47,8 @@ static function getSQLType($field_type) { 'dropdown' => 'INT(11) NOT NULL DEFAULT 0', 'yesno' => 'INT(11) NOT NULL DEFAULT 0', 'date' => 'VARCHAR(255) DEFAULT NULL', - 'datetime' => 'VARCHAR(255) DEFAULT NULL' + 'datetime' => 'VARCHAR(255) DEFAULT NULL', + 'dropdownuser' => 'INT(11) NOT NULL DEFAULT 0' ); return $types[$field_type]; diff --git a/locales/en_GB.php b/locales/en_GB.php index a68f0748..2d1e5402 100644 --- a/locales/en_GB.php +++ b/locales/en_GB.php @@ -31,6 +31,10 @@ $LANG['fields']['field']['type']['yesno'] = "Yes/No"; $LANG['fields']['field']['type']['date'] = "Date"; $LANG['fields']['field']['type']['datetime'] = "Date & time"; +$LANG['fields']['field']['type']['dropdownuser'] = "User Dropdown"; + $LANG['fields']['field']['label']['add'] = "Add a new field"; $LANG['fields']['field']['label']['no_fields'] = "No field for this bloc"; + +$LANG['fields']['field']['label']['readonly'] = "Read only"; diff --git a/locales/fr_FR.php b/locales/fr_FR.php index d938982c..99b04617 100644 --- a/locales/fr_FR.php +++ b/locales/fr_FR.php @@ -31,6 +31,10 @@ $LANG['fields']['field']['type']['yesno'] = "Oui/Non"; $LANG['fields']['field']['type']['date'] = "Date"; $LANG['fields']['field']['type']['datetime'] = "Date & heure"; +$LANG['fields']['field']['type']['dropdownuser'] = "Liste Utilisateurs"; + $LANG['fields']['field']['label']['add'] = "Ajouter un nouveau champ"; $LANG['fields']['field']['label']['no_fields'] = "Pas de champs pour ce bloc"; + +$LANG['fields']['field']['label']['readonly'] = "Lecture seule"; diff --git a/setup.php b/setup.php index adfdab11..d3ddf6cb 100644 --- a/setup.php +++ b/setup.php @@ -52,8 +52,8 @@ function plugin_init_fields() { function plugin_version_fields() { global $LANG; return array ('name' => $LANG["fields"]["title"][1], - 'version' => '2.0', - 'author' => 'Alexandre Delaunay & Walid Nouh', + 'version' => '2.1.0', + 'author' => 'Alexandre Delaunay & Walid Nouh & Olivier Moron', 'homepage' => 'teclib.com', 'license' => 'restricted', 'minGlpiVersion' => '0.83.3'); From 37ecb5a18f7ce6a482dd4de9359650e8343880fd Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 15 Sep 2015 13:56:30 +0200 Subject: [PATCH 9/9] Added a test to prevent error when id is missing Added a test to prevent error when id is missing SVN r762 2015-08-13 --- inc/field.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inc/field.class.php b/inc/field.class.php index b55ee497..92a53eeb 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -389,6 +389,9 @@ static function showForDomContainer() { //get current id parse_str($expl_url[1], $params); + if( !isset($params['id'])) { + return false ; + } $items_id = $params['id']; //get itemtype