/**
  * Fügt dem Feld eine Array von Werten hinzu
  * @param $values Array von Werten
  * @access protected
  */
 function addValues($values)
 {
     rex_valid_type($values, 'array', __FILE__, __LINE__);
     $value = array_shift($values);
     $mode = '';
     $group = false;
     if (isset($value[0]) && isset($value[1])) {
         $mode = 'Numeric';
         if (isset($value[2]) && isset($value[3])) {
             $group = true;
         }
     } elseif (isset($value['label']) && isset($value['value'])) {
         $mode = 'Assoc';
         if (isset($value['id']) && isset($value['re_id'])) {
             $group = true;
         }
     } elseif (is_scalar($value)) {
         $mode = 'Scalar';
     } else {
         rexForm::triggerError('Unexpected Array-Structure for Array $values. Expected Keys are "0" and "1" or "label" and "value"!');
     }
     if ($mode == 'Numeric') {
         // Add first Option
         if ($group) {
             $this->addValue($value[0], $value[1], $value[2], $value[3]);
         } else {
             $this->addValue($value[0], $value[1]);
         }
         // Add remaing Options
         foreach ($values as $value) {
             if ($group) {
                 $this->addValue($value[0], $value[1], $value[2], $value[3]);
             } else {
                 $this->addValue($value[0], $value[1]);
             }
         }
     } elseif ($mode == 'Assoc') {
         // Add first Option
         if ($group) {
             $this->addValue($value['label'], $value['value'], $value['id'], $value['re_id']);
         } else {
             $this->addValue($value['label'], $value['value']);
         }
         // Add remaing Options
         foreach ($values as $value) {
             if ($group) {
                 $this->addValue($value['label'], $value['value'], $value['id'], $value['re_id']);
             } else {
                 $this->addValue($value['label'], $value['value']);
             }
         }
     } elseif ($mode == 'Scalar') {
         // Add first Option
         $this->addValue($value, $value);
         // Add remaing Options
         foreach ($values as $value) {
             $this->addValue($value, $value);
         }
     }
 }
 /**
  * Fügt dem Feld neue Werte via SQL-Query hinzu.
  * Dieser Query muss ein 2 Spaltiges Resultset beschreiben.
  * 
  * @param $query SQL-Query
  * @access protected
  */
 function addSqlValues($query)
 {
     $sql = new sql();
     //      $sql->debugsql = true;
     $result = $sql->get_array($query, MYSQL_NUM);
     if (is_array($result) && count($result) >= 1) {
         $value = array_shift($result);
         if (count($value) > 2) {
             rexForm::triggerError('Query "' . $query . '" affects more than 2 columns!');
         }
         if (count($value) == 2) {
             // Add first Option
             $this->addValue($value[0], $value[1]);
             foreach ($result as $value) {
                 // Add remaing Options
                 $this->addValue($value[0], $value[1]);
             }
         } elseif (count($value) == 1) {
             // Add first Option
             $this->addValue($value[0], $value[0]);
             foreach ($result as $value) {
                 // Add remaing Options
                 $this->addValue($value[0], $value[0]);
             }
         }
     }
 }
 function addSection(&$section)
 {
     if (!rexFormSection::isValid($section)) {
         rexForm::triggerError('Unexpected type "' . gettype($section) . '" for $section! Expecting type string or rexFormSection-Object!');
     }
     $section->rexform =& $this;
     $this->section =& $section;
     $this->sections[] =& $section;
 }
 function save()
 {
     $form =& $this->getForm();
     $sql =& $form->sql;
     $mode = $this->_getMode();
     $qry = '';
     switch ($mode) {
         case CONTROLLER_INSERT_MODE:
             $qry = 'INSERT INTO ';
             break;
         case CONTROLLER_UPDATE_MODE:
             $qry = 'UPDATE ';
             break;
         default:
             rexForm::triggerError('Unexpected value "' . $mode . '"for $mode !');
             return;
     }
     $qry .= $this->getTableName() . ' SET';
     // Set values
     $first = true;
     $fields =& $this->getFields();
     for ($i = 0; $i < $this->numFields(); $i++) {
         $field_value = $fields[$i]->getInsertValue();
         // NULL Werte nicht speichern
         if ($field_value === null) {
             continue;
         }
         if ($first) {
             $first = false;
         } else {
             $qry .= ',';
         }
         $qry .= ' ' . $fields[$i]->getName() . '=' . $this->_prepareValue($field_value);
     }
     if ($mode == CONTROLLER_UPDATE_MODE) {
         $where = $this->_getWhereString();
         $qry .= ' WHERE ' . $where . ' LIMIT 1';
     }
     $sql->setQuery($qry);
     return $sql->getError();
 }