Esempio n. 1
0
 /**
  * methods that returns the differents fields of of the model
  * @param string $field  the name of the column of the field
  * @return html returns an html string for the form
  */
 public function getFormFromField($field, $contextField)
 {
     //if the field is in the the database and is available for form , we can include it in the response
     if (in_array($field, array_keys($this->arrayFields)) && ($this->arrayFields[$field]["isVisibleInForm"] == "true" && $contextField == "ficheContext") || $this->arrayFields[$field]["isFilterVisible"] == "true" && $contextField == "filterContext") {
         $preValue;
         //variable that contains the current saved value if it exists
         if ($this->arrayFields[$field]["key"] != "MUL") {
             if ($this->arrayFields[$field]["isPictureField"] == "false" && $this->arrayFields[$field]["isFileField"] == "false") {
                 //if it is a small or medium text
                 if (preg_match("#varchar#", $this->arrayFields[$field]["type"])) {
                     if ($this->superReplace(array("varchar" => "", "(" => "", ")" => ""), $this->arrayFields[$field]["type"]) <= 150) {
                         if ($this->arrayFields[$field]["isColorPickerField"] == "true") {
                             return "<label>" . $this->arrayFields[$field]["formLabel"] . "</label>  <input class=\"formField colorPickerClass " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\" type=\"text\" value=\"" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "\"/>";
                         } else {
                             return "<label>" . $this->arrayFields[$field]["formLabel"] . "</label>  <input class=\"formField " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\" type=\"text\" value=\"" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "\"/>";
                         }
                     } else {
                         return "<label>" . $this->arrayFields[$field]["formLabel"] . "</label> <textarea class=\"formField " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\">" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "</textarea>";
                     }
                 }
                 //if it is a text
                 if (preg_match("#text#", $this->arrayFields[$field]["type"])) {
                     if ($this->arrayFields[$field]["isRichTextEditorField"] == "true") {
                         return "<label>" . $this->arrayFields[$field]["formLabel"] . "</label> <textarea class=\"formField " . $contextField . " rteClass\" id=\"" . $field . "_s_" . $contextField . "\">" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "</textarea>";
                     } else {
                         return "<label>" . $this->arrayFields[$field]["formLabel"] . "</label> <textarea class=\"formField " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\">" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "</textarea>";
                     }
                 }
                 //if it is a number
                 if (preg_match("#int#", $this->arrayFields[$field]["type"])) {
                     if ($this->arrayFields[$field]["isBooleanField"] == "true") {
                         return "<br/><br/><label class=\"cbLabel\">" . $this->arrayFields[$field]["formLabel"] . "</label> <br/> <select class=\"formField " . $contextField . " boolField\" id=\"" . $field . "_s_" . $contextField . "\"><option value=\"0\" " . ($this->isSavedElement && $this->arrayFields[$field]["currentValue"] == 0 ? "selected=\"selected\"" : "") . ">" . $this->arrayFields[$field]["false_label"] . "</option><option value=\"1\" " . ($this->isSavedElement && $this->arrayFields[$field]["currentValue"] == 1 ? "selected=\"selected\"" : "") . ">" . $this->arrayFields[$field]["true_label"] . "</option></select><br/><br/>";
                     }
                     if ($this->arrayFields[$field]["isDateField"] == "true") {
                         return "<label>" . $this->arrayFields[$field]["formLabel"] . "</label>  <input class=\"formField " . $contextField . " pickerClass\" id=\"" . $field . "_s_" . $contextField . "\" type=\"text\" value=\"" . ($this->isSavedElement ? myTools::getDateFromTimeAndCustomFormat($this->arrayFields[$field]["currentValue"], $this->gInfos->getGlobalInfoForNodeAndTable("global_date_format", $this->tableName)) : "") . "\"/>";
                     }
                     return "<label>" . $this->arrayFields[$field]["formLabel"] . "</label>  <input class=\"formField " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\" type=\"text\" value=\"" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "\"/>";
                 }
                 if (preg_match("#decimal#", $this->arrayFields[$field]["type"])) {
                     return "<label>" . $this->arrayFields[$field]["formLabel"] . "</label>  <input class=\"formField " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\" type=\"text\" value=\"" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "\"/>";
                 }
                 if (preg_match("#double#", $this->arrayFields[$field]["type"])) {
                     return "<label>" . $this->arrayFields[$field]["formLabel"] . "</label>  <input class=\"formField " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\" type=\"text\" value=\"" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "\"/>";
                 }
             } else {
                 if ($this->arrayFields[$field]["isPictureField"] == "true") {
                     return "<div id=\"browse" . $field . "\" class=\"uploadField pictureField\">" . $this->arrayFields[$field]["formLabel"] . " <img src=\"medias/images/dl_small.png\"/> <input class=\"formField " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\" type=\"hidden\" value=\"" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "\"/></div> ";
                 } else {
                     return "<div id=\"browse" . $field . "\" class=\"uploadField fileField\">" . $this->arrayFields[$field]["formLabel"] . "  <img src=\"medias/images/dl_small.png\"/> <input class=\"formField " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\" type=\"hidden\" value=\"" . ($this->isSavedElement ? $this->arrayFields[$field]["currentValue"] : "") . "\"/></div> ";
                 }
             }
         } else {
             //we extract the informations in the relation table
             $sqlChoicesQuery = "SELECT * FROM " . $this->arrayRelations[$field]["assoc_table"] . "";
             if ($this->xml->{"" . $field . ""}->displayColumn != "" && $this->xml->{"" . $field . ""}->displayColumn["sortColumn"] != "") {
                 $sqlChoicesQuery .= " ORDER BY " . $this->xml->{"" . $field . ""}->displayColumn["sortColumn"];
             }
             $resultChoices = $this->dbh->query($sqlChoicesQuery);
             $resultChoices->setFetchMode(PDO::FETCH_ASSOC);
             $resultChoices = $resultChoices->fetchAll();
             //and we do a select list
             $select = "<label>" . $this->arrayFields[$field]["formLabel"] . "</label>  <select class=\"formField " . $contextField . "\" id=\"" . $field . "_s_" . $contextField . "\">";
             $select .= "<option value=''>Aucun</option>";
             foreach ($resultChoices as $choice) {
                 $selected = "";
                 //we select the selected value if it is ever saved
                 if ($this->isSavedElement && $this->arrayFields[$field]["currentValue"] == $choice[$this->arrayRelations[$field]["assoc_col"]]) {
                     $selected = "selected=\"selected\"";
                 }
                 //we choose the good value to display , if we have a columns info for the display, it is perfect, else we display the first relation field
                 if (isset($this->arrayFields[$field]["displayColumn"])) {
                     if (count(explode("|", (string) $this->arrayFields[$field]["displayColumn"])) > 1) {
                         $concatDisplay = "";
                         foreach (explode("|", (string) $this->arrayFields[$field]["displayColumn"]) as $columnConcat) {
                             $concatDisplay .= $choice[$columnConcat] . " ";
                         }
                         $select .= "<option " . $selected . " value=\"" . $choice[$this->arrayRelations[$field]["assoc_col"]] . "\">" . $concatDisplay . "</option>";
                     } else {
                         $select .= "<option " . $selected . " value=\"" . $choice[$this->arrayRelations[$field]["assoc_col"]] . "\">" . $choice[(string) $this->arrayFields[$field]["displayColumn"]] . "</option>";
                     }
                 } else {
                     $select .= "<option " . $selected . " value=\"" . $choice[$this->arrayRelations[$field]["assoc_col"]] . "\">" . $choice[$this->arrayRelations[$field]["assoc_col"]] . "</option>";
                 }
             }
             $select .= "</select>";
             return $select;
         }
     }
 }
Esempio n. 2
0
         if (count(explode("|", (string) $xml->{"" . $columnName . ""}->displayColumn)) > 1) {
             $concatDisplay = "";
             foreach (explode("|", (string) $xml->{"" . $columnName . ""}->displayColumn) as $columnConcat) {
                 $concatDisplay .= $resultChoices[0][$columnConcat] . " ";
             }
             $xmlRetour->text($concatDisplay);
         } else {
             if (array_key_exists((string) $xml->{"" . $columnName . ""}->displayColumn, $picturesThumnailColumn)) {
                 $xmlRetour->writeCData("<img src='" . $picturesThumnailColumn[(string) $xml->{"" . $columnName . ""}->displayColumn] . $resultChoices[0][(string) $xml->{"" . $columnName . ""}->displayColumn] . "'/>");
             } else {
                 $xmlRetour->text($resultChoices[0][(string) $xml->{"" . $columnName . ""}->displayColumn]);
             }
         }
     } else {
         if ((string) $xml->{"" . $columnName . ""}->dateField['enabled'] == "true") {
             $xmlRetour->text(myTools::getDateFromTimeAndCustomFormat($columnValue, $gb->getGlobalInfoForNodeAndTable("global_date_format", $table)));
         } else {
             if ((string) $xml->{"" . $columnName . ""}->booleanField['enabled'] == "true") {
                 if ($columnValue == 0) {
                     $xmlRetour->text((string) $xml->{"" . $columnName . ""}->booleanField->boolean_false_label);
                 }
                 if ($columnValue == 1) {
                     $xmlRetour->text((string) $xml->{"" . $columnName . ""}->booleanField->boolean_true_label);
                 }
             } else {
                 //we return the value
                 $xmlRetour->text($columnValue);
             }
         }
     }
 }