diff --git a/fields/field.constant.php b/fields/field.constant.php index 4b9a9c6..0abb5f5 100644 --- a/fields/field.constant.php +++ b/fields/field.constant.php @@ -51,6 +51,7 @@ $GO_FIELDS['comment']['name'] = __("Comments"); $GO_FIELDS['comment']['field'] = 'comment'; $GO_FIELDS['comment']['input_type'] = 'multitext'; +$GO_FIELDS['comment']['colums'] = '3'; //[CRI] : colums - Add colspan on formulary $GO_FIELDS['other']['name'] = __("Others"); $GO_FIELDS['other']['input_type'] = 'text'; @@ -75,8 +76,6 @@ $GO_FIELDS['types_id']['name'] = __("Type"); $GO_FIELDS['types_id']['linkfield'] = 'type'; $GO_FIELDS['types_id']['input_type'] = 'dropdown'; -// The 'isolated' dropdown type will create a isolated table for each type that will be assigned -// with this field. $GO_FIELDS['types_id']['dropdown_type'] = 'isolated'; $GO_FIELDS['models_id']['name'] = __("Model"); @@ -147,3 +146,14 @@ $GO_FIELDS['groups_id_tech']['name'] = __("Group in charge of the hardware"); $GO_FIELDS['groups_id_tech']['input_type'] = 'dropdown'; $GO_FIELDS['groups_id_tech']['condition'] = ['is_assign' => 1]; + +//*****// +// INICIO [CRI] : section - Add section on formulary +//*****// +$GO_FIELDS['section']['name'] = __("Example secction"); +$GO_FIELDS['section']['field'] = 'sectionRow'; +$GO_FIELDS['section']['input_type'] = 'sectionRow'; +$GO_FIELDS['section']['colums'] = '4'; +//*****// +// FINAL [CRI] : section - Add section on formulary +//*****// \ No newline at end of file diff --git a/inc/field.class.php b/inc/field.class.php index f95eb79..f279831 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -393,6 +393,15 @@ public static function addNewField($table, $field, $after = false) { case 'decimal' : $query .= "DECIMAL(20,4) NOT NULL DEFAULT '0.0000'"; break; + //*****// + // INICIO [CRI] : section - Add section on formulary + //*****// + case 'sectionRow' : + $query .= "VARCHAR(45) NULL DEFAULT 'Section'"; + break; + //*****// + // FINAL [CRI] : section - Add section on formulary + //*****// } if ($after) { $query.=" AFTER `$after`"; diff --git a/inc/object.class.php b/inc/object.class.php index 9bd3a2b..440d368 100644 --- a/inc/object.class.php +++ b/inc/object.class.php @@ -591,145 +591,218 @@ function displayField($canedit, $name, $value, $template, $description = []) { $searchoption = PluginGenericobjectField::getFieldOptions($name, get_called_class()); + $this->countColumns($searchoption); // [CRI] : section - Add section on formulary + if (!empty($searchoption) && !in_array($name, self::getFieldsToHide())) { - if (isset($searchoption['input_type']) && 'emptyspace' === $searchoption['input_type']) { - $searchoption['name'] = " "; - $description['Type'] = 'emptyspace'; - } + //*****// + // INICIO [CRI] : section - Add section on formulary + //*****// + + if ($this->colums["field"]=="sectionRow") { - $this->startColumn(); - echo $searchoption['name']; - if (isset($searchoption['autoname']) && $searchoption['autoname'] && $template) { - echo "* "; - } - $this->endColumn(); - $this->startColumn(); + $this->startColumn(); + echo $searchoption['name']; + $this->endColumn(); - // Keep only main column type by removing anything that is preceded by a space (e.g. " unsigned") - // or a parenthesis (e.g. "(255)"). - $column_type = preg_replace('/[ (].+$/', '', $description['Type']); - switch ($column_type) { - case "int": - $fk_table = getTableNameForForeignKeyField($name); - if ($fk_table != '') { - $itemtype = getItemTypeForTable($fk_table); - $dropdown = new $itemtype(); - $parameters = ['name' => $name, 'value' => $value, 'comments' => true]; - if ($dropdown->isEntityAssign()) { - $parameters["entity"] = $this->fields['entities_id']; - } - if ($dropdown->maybeRecursive()) { - $parameters['entity_sons'] = true; - } - if (isset($searchoption['condition'])) { - $parameters['condition'] = $searchoption['condition']; - } - if ($dropdown instanceof User) { - $parameters['entity'] = $this->fields["entities_id"]; - $parameters['right'] = 'all'; - User::dropdown($parameters); - } else { - Dropdown::show($itemtype, $parameters); - } - } else { - $min = $max = $step = 0; - if (isset($searchoption['min'])) { - $min = $searchoption['min']; - } else { - $min = 0; - } - if (isset($searchoption['max'])) { - $max = $searchoption['max']; - } else { - $max = 100; - } - if (isset($searchoption['step'])) { - $step = $searchoption['step']; - } else { - $step = 1; - } - Dropdown::showNumber( - $name, [ - 'value' => $value, - 'min' => $min, - 'max' => $max, - 'step' => $step - ] - ); - } - break; - - case "tinyint": - Dropdown::showYesNo($name, $value); - break; + } else { + + //*****// + // FINAL [CRI] : section - Add section on formulary + //*****// + + if (isset($searchoption['input_type']) && 'emptyspace' === $searchoption['input_type']) { + $searchoption['name'] = " "; + $description['Type'] = 'emptyspace'; + } - case "varchar": - if (isset($searchoption['autoname']) && $searchoption['autoname']) { - $objectName = autoName($this->fields[$name], $name, ($template === "newcomp"), - $this->getType(), $this->fields["entities_id"]); - } else { - $objectName = $this->fields[$name]; - } - echo Html::input( - $name, - [ - 'value' => $objectName, - ] - ); - break; + $this->colums["field"] = ""; //[CRI] : colums - Add colspan on formulary - case "longtext": - case "text": - echo ""; - break; + $this->startColumn(); + echo $searchoption['name']; + if (isset($searchoption['autoname']) && $searchoption['autoname'] && $template) { + echo "* "; + } + $this->endColumn(); + $this->colums["field"] = $searchoption['name']; //[CRI] : colums - Add colspan on formulary + $this->startColumn(); + + // Keep only main column type by removing anything that is preceded by a space (e.g. " unsigned") + // or a parenthesis (e.g. "(255)"). + $column_type = preg_replace('/[ (].+$/', '', $description['Type']); + switch ($column_type) { + case "int": + $fk_table = getTableNameForForeignKeyField($name); + if ($fk_table != '') { + $itemtype = getItemTypeForTable($fk_table); + $dropdown = new $itemtype(); + //$parameters = ['name' => $name, 'value' => $value, 'comments' => true]; + $parameters = ['name' => $name, 'value' => $value, 'comments' => true, 'width' => "88%"]; //[CRI] : colums - Add colspan on formulary + if ($dropdown->isEntityAssign()) { + $parameters["entity"] = $this->fields['entities_id']; + } + if ($dropdown->maybeRecursive()) { + $parameters['entity_sons'] = true; + } + if (isset($searchoption['condition'])) { + $parameters['condition'] = $searchoption['condition']; + } + if ($dropdown instanceof User) { + $parameters['entity'] = $this->fields["entities_id"]; + $parameters['right'] = 'all'; + User::dropdown($parameters); + } else { + Dropdown::show($itemtype, $parameters); + } + } else { + $min = $max = $step = 0; + if (isset($searchoption['min'])) { + $min = $searchoption['min']; + } else { + $min = 0; + } + if (isset($searchoption['max'])) { + $max = $searchoption['max']; + } else { + $max = 100; + } + if (isset($searchoption['step'])) { + $step = $searchoption['step']; + } else { + $step = 1; + } + Dropdown::showNumber( + $name, [ + 'value' => $value, + 'min' => $min, + 'max' => $max, + 'step' => $step + ] + ); + } + break; - case "emptyspace": - echo ' '; - break; + case "tinyint": + Dropdown::showYesNo($name, $value); + break; - case "date": - Html::showDateField( - $name, [ - 'value' => $value, - 'maybeempty' => true, - 'canedit' => true + case "varchar": + if (isset($searchoption['autoname']) && $searchoption['autoname']) { + $objectName = autoName($this->fields[$name], $name, ($template === "newcomp"), + $this->getType(), $this->fields["entities_id"]); + } else { + $objectName = $this->fields[$name]; + } + echo Html::input( + $name, + [ + 'value' => $objectName, + 'option' => 'style="width:95%"', //[CRI] : colums - Add colspan on formulary ] ); break; - case "datetime": - case "timestamp": - Html::showDateTimeField( - $name, [ - 'value' => $value, - 'timestep' => true, - 'maybeempty' => true - ] - ); + case "longtext": + case "text": + /* + echo ""; + */ + echo ""; //[CRI] : colums - Add colspan on formulary break; - case "float": - case 'decimal': - echo ""; - break; + case "emptyspace": + echo ' '; + break; - default: - echo ""; + case "date": + Html::showDateField( + $name, [ + 'value' => $value, + 'maybeempty' => true, + 'canedit' => true + ] + ); + break; + + case "datetime": + case "timestamp": + Html::showDateTimeField( + $name, [ + 'value' => $value, + 'timestep' => true, + 'maybeempty' => true + ] + ); + break; + + case "float": + case 'decimal': + echo ""; break; + default: + echo ""; + break; + + } + $this->endColumn(); } - $this->endColumn(); + } } - + /** + * INICIO [CRI] : Column number of the field, Check that the colum's number is not over 4 + **/ + function countColumns($searchoption) { + + if (isset($searchoption["input_type"])) { + $this->colums["input_type"] = $searchoption["input_type"]; + } else { + $this->colums["input_type"] = ""; + } + + if (isset($searchoption["field"])) { + $this->colums["field"] = $searchoption["field"]; + } else { + $this->colums["field"] = ""; + } + + if ((isset($searchoption["field"])) and ($searchoption["field"]=="sectionRow")) { + if (isset($searchoption["colums"])) { + if ($searchoption["colums"]>4) { + $this->colums["number"]=4; + } else { + $this->colums["number"]=$searchoption["colums"]; + } + } else { + $this->colums["number"]=4; + } + } else { + + if (isset($searchoption["colums"])) { + if ($searchoption["colums"]>3){ + $this->colums["number"]=3; + } else { + $this->colums["number"]=$searchoption["colums"]; + } + } else { + $this->colums["number"]=1; + } + } + //echo $this->colums["number"]." ".$this->colums["field"]." ".$this->colums["input_type"]."
"; + } + + /** + * FINAL [CRI] : Column number of the field, Check that the colum's number is not over 4 + **/ /** * Add a new column - **/ + **//* function startColumn() { if ($this->cpt == 0) { echo ""; @@ -738,12 +811,68 @@ function startColumn() { echo ""; $this->cpt++; } +*/ + + //*****// + // INICIO [CRI] : Add a new column + //*****// + + function startColumn() { + + $field=$this->colums["field"]; + if (empty($field)){ + $colums=1; + $top=4-($this->cpt + $this->colums["number"] + 1); + if ($top<0){ + $top=$this->cpt-4; + } + } else { + $colums=$this->colums["number"]; + $top=4-($this->cpt + $colums); + } + + if ($field=="sectionRow") { + $label="th"; $style="style='border-top: 5px solid white; border-bottom: 5px solid white;'"; + } else { + $label="td"; $style=""; + } + + if ($colums>1){ + if ($this->colums["input_type"]=="dropdown") { $colums=1; } + $colspan=" colspan = '".$colums."'"; + } else { + $colspan=""; + } + + if ($top<0) { + echo ""; + //echo "ff4 - (".$this->cpt." + ".$this->colums["number"]." + 1) =".$top." colums ".$colums; + $this->cpt=4; + $this->endColumn(); + $this->startColumn(); + } else { + + if ($this->cpt == 0) { + echo ""; + } + + echo "<$label $style $colspan>"; + if ((empty($field)) and ($colums>1)){} else { + $this->cpt=$this->cpt+$colums; + } + + } + } + + //*****// + // FINAL [CRI] : Add a new column + //*****// /** * End a column - **/ + **//* function endColumn() { echo ""; @@ -753,8 +882,37 @@ function endColumn() { } } +*/ + //*****// + // INICIO [CRI] : End a column + //*****// + function endColumn() { + + $input_type=$this->colums["input_type"]; + $field=$this->colums["field"]; + $colums=$this->colums["number"]; + + if ($field=="sectionRow") { $label="th"; } else { $label="td"; } + + if ((!empty($field)) and ($input_type=="dropdown") and ($colums>1)) { + echo "<$label colspan = '2'>"; + $this->cpt=4; + } + + echo ""; + + if ($this->cpt == 4) { + echo ""; + $this->cpt = 0; + } + + } + + //*****// + // FINAL [CRI] : End a column + //*****// /** * Close a column