Example #1
0
 /**
  * Class Constructor
  *
  * Creates a Form Class with all the information to use the Form functions
  *
  * @param $data An Array of all the values for the fields
  * @param $required An Array of all the required keys for the form
  * @param $labels An Array of all the custom labels for the form
  * @param $examples An Array of all the exmples for each form element
  * @return bool
  */
 public function __construct($data, $required = array(), $labels = array(), $examples = array())
 {
     // Loop through all the data
     foreach ($data as $key => $data) {
         // Set all the field info
         $tmpField = new Field();
         $tmpField->Set('name', $key);
         $tmpField->Set('value', $data);
         $tmpField->Set('required', $required[$key]);
         $tmpField->Set('label', $labels[$key]);
         $tmpField->Set('example', $examples[$key]);
         $tmpField->Set('display', count($this->fields) + 1);
         // Add the field to the list
         $this->fields[$key] = $tmpField;
     }
     // Set the local display
     $this->display = $this->GetFields();
 }
Example #2
0
 /**
  * Parse the table information into an array format
  *
  * @return boolean
  */
 private function ParseTable()
 {
     global $db;
     // Query for one record
     $result = $db->Query('SELECT * FROM `' . $this->table . '` LIMIT 1', $this->database, false);
     // Loop through all the fields
     while ($field = $db->FetchField($result)) {
         // Set all the field info
         $field_count = count($this->fields);
         $tmpField = new Field();
         $tmpField->Set('name', $field->name);
         $tmpField->Set('type', $field->type);
         $tmpField->Set('length', $db->FieldLength($result, $field_count));
         $tmpField->Set('validate', $this->ValidType($field));
         $tmpField->Set('primary', $field->primary_key);
         $tmpField->Set('display', $field_count + 1);
         // Set the primary if it is
         if ($field->primary_key == 1) {
             $this->primary = $field->name;
         }
         // Add the field to the list
         $this->fields[$field->name] = $tmpField;
     }
     if (USE_ENUM == true) {
         // Query for the ENUM information
         $result2 = $db->Query('DESCRIBE ' . $this->table, $this->database, false);
         // Loop through all the fields
         while ($info = $db->FetchArray($result2)) {
             $options = array();
             // Split up the type
             preg_match_all('/\'(.*?)\'/', $info['Type'], $field);
             if (is_array($field[1]) && count($field[1]) > 0) {
                 foreach ($field[1] as $key => $value) {
                     $options[$value] = $value;
                 }
                 $this->SetOption($info['Field'], $options);
             }
         }
     }
     return true;
 }