示例#1
0
 /**
  * It is used to generate form fields from database table information
  * 
  * It fetches field information from database
  * For each field in database it generates a html form field. e.g text field, textarea etc
  * 	 
  * @param string $data_type the short table name. it is used to generate form fields
  * @param string $fields_to_hide the list of fields to hide
  * @param array $row_data the table row data
  */
 private function GetFormFields($data_type, $fields_to_hide, $row_data)
 {
     /** The application configuration is fetched */
     $configuration = $this->GetConfigurationObject();
     /** The parameters for the data object */
     $meta_information = array("configuration" => $configuration, "key_field" => "id", "data_type" => $data_type);
     /** Mysqldataobject is created */
     $data_object = new MysqlDataObject($meta_information);
     /** The field information */
     $field_information = $data_object->GetFieldInformation();
     /** The html for the form fields */
     $form_fields_html = "";
     /** Each form field is generated */
     for ($count = 0; $count < count($field_information); $count++) {
         /** The field data */
         $field_data = $field_information[$count];
         /** The field value is set */
         $field_value = isset($row_data[$field_data['Field']]) ? str_replace('"', "&quot;", $row_data[$field_data['Field']]) : "";
         /** The field name */
         $field_name = ucwords(str_replace("_", " ", $field_data['Field']));
         /** The field parameters */
         $field_parameters = array();
         /** The template name */
         $template_name = "";
         /** If the field type contains "text" and the field does not need to be hidden then it is rendered using textarea */
         if (strpos($field_data['Type'], "text") !== false && !in_array($field_data['Field'], $fields_to_hide)) {
             /** The template name */
             $template_name = "textarea";
             /** The field parameters are set */
             $field_parameters['textarea_name'] = "form[textarea_" . $field_data['Field'] . "]";
             $field_parameters['textarea_id'] = "textarea_" . $field_data['Field'];
             $field_parameters['textarea_value'] = $field_value;
             $field_parameters['textarea_cols'] = "48";
             $field_parameters['textarea_rows'] = "4";
             $field_parameters['field_label'] = $field_name;
         } else {
             $template_name = "input";
             if (strpos($field_data['Type'], "int") !== false) {
                 $input_type = "number";
             } else {
                 $input_type = "text";
             }
             /** If the given field is in the list of fields to hide then it is hidden */
             if (in_array($field_data['Field'], $fields_to_hide)) {
                 $input_type = "hidden";
             }
             /** The field parameters are set */
             $field_parameters['input_name'] = "form[input_" . $field_data['Field'] . "]";
             $field_parameters['input_id'] = "input_" . $field_data['Field'];
             $field_parameters['input_value'] = $field_value;
             $field_parameters['input_css'] = "CSStextFIELDlarge";
             $field_parameters['input_type'] = $input_type;
             $field_parameters['field_label'] = $field_name;
         }
         /** The form field is rendered */
         $form_field_html = $this->RenderFormField($template_name, $field_parameters);
         /** The final form field html is rendered */
         $form_fields_html = $form_fields_html . $form_field_html;
     }
     return $form_fields_html;
 }