Example #1
0
 function Save()
 {
     if ($this->_GetFileHandle()) {
         $data = array();
         $this->_FlattenPost();
         $rules = Config::GetInstance()->GetConfig('rules');
         foreach ($rules as $field => $rule) {
             if (!isset($this->post[$field])) {
                 // it could still be an uploaded file
                 $notfound = true;
                 foreach (FormPage::GetInstance()->uploads as $up) {
                     if ($up['fieldname'] == $field) {
                         $data[] = $up['storedname'];
                         $notfound = false;
                         break;
                     }
                 }
                 if ($notfound) {
                     $data[] = '';
                 }
             } else {
                 if ($rule->fieldtype == 'date' && !empty($this->post[$field])) {
                     $data[] = date(Config::GetInstance()->GetDateFormatByFieldname($field), $this->post[$field]);
                 } else {
                     if ($field == '_submitted_') {
                         $data[] = Config::ApplyUserTimezone($this->post[$field]);
                     } else {
                         $data[] = $this->post[$field];
                     }
                 }
             }
         }
         foreach (Config::GetInstance()->GetReservedFields() as $name) {
             if (isset($this->post[$name]) && $name == '_submitted_') {
                 $data[] = Config::GetInstance()->ApplyUserTimezone($this->post[$name]);
             } else {
                 if (isset($this->post[$name])) {
                     $data[] = $this->post[$name];
                 } else {
                     $data[] = '';
                 }
             }
         }
         fputcsv($this->fp, $data);
         fclose($this->fp);
     } else {
         $this->errors[] = array('err' => _T('Failed to record the data because the server is too busy or doesn\'t have write permission.'));
     }
 }