Beispiel #1
0
 /**
  * Actually carry out the action.
  *
  * @return boolean  True on success.
  * @throws Ulaform_Exception
  */
 public function doAction($form_params, $form_data, $fields)
 {
     /* Check if table exists. */
     if (!in_array($form_params['table'], $this->_db->tables())) {
         try {
             $this->_createDataTable($form_params, $fields);
         } catch (Horde_Db_Exception $e) {
             throw new Ulaform_Exception($e->getMessage());
         }
     }
     /* Submit data to database. */
     $columns = array();
     $values = array();
     foreach ($fields as $field) {
         switch ($field['field_type']) {
             case 'file':
             case 'image':
                 if (count($form_data[$field['field_name']])) {
                     $data = file_get_contents($form_data[$field['field_name']]['file']);
                     if (Horde_String::lower($this->_db->adapterName()) == 'pgsql') {
                         $data = bin2hex($data);
                     }
                     $columns[] = $field['field_name'];
                     $values[] = $data;
                 }
                 break;
             case 'set':
                 $columns[] = $field['field_name'];
                 $values[] = implode(', ', $form_data[$field['field_name']]);
                 break;
             default:
                 $data = $form_data[$field['field_name']];
                 $columns[] = $field['field_name'];
                 $values[] = Horde_String::convertCharset($data, 'UTF-8', $this->_charset);
                 break;
         }
     }
     $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $form_params['table'], implode(', ', $columns), str_repeat('?, ', count($values) - 1) . '?');
     try {
         $this->_db->insert($sql, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Ulaform_Exception($e->getMessage());
     }
     return true;
 }