Exemple #1
0
 private function _setEventAttributes($model, $params)
 {
     //Grid sends move request
     if (isset($params['offset'])) {
         $model->start_time = \GO\Base\Util\Date::roundQuarters($model->start_time + $params['offset']);
         $model->end_time = \GO\Base\Util\Date::roundQuarters($model->end_time + $params['offset']);
     }
     if (isset($params['offset_days'])) {
         $model->start_time = \GO\Base\Util\Date::date_add($model->start_time, $params['offset_days']);
         $model->end_time = \GO\Base\Util\Date::date_add($model->end_time, $params['offset_days']);
     }
     //when a user resizes an event
     if (isset($params['duration_end_time'])) {
         //only use time for the update
         $old_end_date = getdate($model->end_time);
         $new_end_time = getdate($params['duration_end_time']);
         $model->end_time = mktime($new_end_time['hours'], $new_end_time['minutes'], 0, $old_end_date['mon'], $old_end_date['mday'], $old_end_date['year']);
     }
     if (!empty($params['freq'])) {
         $rRule = new \GO\Base\Util\Icalendar\Rrule();
         $rRule->readJsonArray($params);
         $model->rrule = $rRule->createRrule();
     } elseif (isset($params['freq'])) {
         $model->rrule = "";
     }
     if (isset($params['reminder_value']) && isset($params['reminder_multiplier'])) {
         $model->reminder = \GO\Base\Util\Number::unlocalize($params['reminder_value']) * $params['reminder_multiplier'];
     }
     //		else
     //			$model->reminder = 0;
     $model->setAttributes($params);
 }
Exemple #2
0
 public function formatFormInput($key, &$attributes, \GO\Customfields\Model\AbstractCustomFieldsRecord $model)
 {
     if (empty($attributes[$key]) && $attributes[$key] != 0) {
         return null;
     } else {
         return \GO\Base\Util\Number::unlocalize($attributes[$key]);
     }
 }
Exemple #3
0
 protected function beforeSubmit(&$response, &$model, &$params)
 {
     if (!\GO::user()) {
         if (empty($params['serverclient_token']) || $params['serverclient_token'] != \GO::config()->serverclient_token) {
             throw new \GO\Base\Exception\AccessDenied();
         } else {
             \GO::session()->runAsRoot();
         }
     }
     if (isset($params['domain_id'])) {
         $domainModel = \GO\Postfixadmin\Model\Domain::model()->findByPk($params['domain_id']);
     } else {
         $domainModel = \GO\Postfixadmin\Model\Domain::model()->findSingleByAttribute("domain", $params['domain']);
         //serverclient module doesn't know the domain_id. It sends the domain name as string.
         if (!$domainModel) {
             //todo create new domain
             $domainModel = new \GO\Postfixadmin\Model\Domain();
             $domainModel->domain = $params['domain'];
             $domainModel->user_id = \GO::user()->id;
             $domainModel->save();
         }
         $params['domain_id'] = $domainModel->id;
         $model->quota = $domainModel->default_quota;
     }
     if (isset($params['quota'])) {
         $model->quota = \GO\Base\Util\Number::unlocalize($params['quota']) * 1024;
         unset($params['quota']);
     }
     if ($params['password'] != $params['password2']) {
         throw new \Exception(\GO::t('passwordMatchError'));
     }
     if (empty($params['password'])) {
         unset($params['password']);
     }
     if (isset($params['username'])) {
         $params['username'] .= '@' . $domainModel->domain;
     }
     if ($model->isNew) {
         //			$aliasModel = \GO\Postfixadmin\Model\Alias::model()->findSingleByAttribute('address', $params['username']);
         //			if (empty($aliasModel)) {
         //				$aliasModel = new \GO\Postfixadmin\Model\Alias();
         //			}
         //			$aliasModel->domain_id = $params['domain_id'];
         //			$aliasModel->address = $params['username'];
         //			$aliasModel->goto = $params['username'];
         //			$aliasModel->save();
         if (!empty($params['alias']) && $params['alias'] != $params['username']) {
             $aliasModel = \GO\Postfixadmin\Model\Alias::model()->findSingleByAttribute('address', $params['alias']);
             if (empty($aliasModel)) {
                 $aliasModel = new \GO\Postfixadmin\Model\Alias();
             }
             $aliasModel->domain_id = $params['domain_id'];
             $aliasModel->address = $params['alias'];
             $aliasModel->goto = $params['username'];
             $aliasModel->save();
         }
     }
 }
Exemple #4
0
 protected function beforeSubmit(&$response, &$model, &$params)
 {
     if (isset($params['total_quota'])) {
         $model->total_quota = \GO\Base\Util\Number::unlocalize($params['total_quota']) * 1024;
         unset($params['total_quota']);
     }
     if (isset($params['default_quota'])) {
         $model->default_quota = \GO\Base\Util\Number::unlocalize($params['default_quota']) * 1024;
         unset($params['default_quota']);
     }
     return parent::beforeSubmit($response, $model, $params);
 }
Exemple #5
0
 public function readJsonArray($json)
 {
     $parameters = array();
     $parameters['interval'] = \GO\Base\Util\Number::unlocalize($json['interval']);
     $parameters['freq'] = strtoupper($json['freq']);
     if ($parameters['freq'] == 'MONTHLY_DATE') {
         $parameters['freq'] = 'MONTHLY';
     }
     $parameters['eventstarttime'] = isset($json['eventstarttime']) ? \GO\Base\Util\Date::to_unixtime($json['eventstarttime']) : \GO\Base\Util\Date::to_unixtime($json['start_time']);
     $parameters['until'] = empty($json['repeat_forever']) && isset($json['until']) ? \GO\Base\Util\Date::to_unixtime($json['until'] . ' 23:59') : 0;
     //date('G', $parameters['eventstarttime']).':'.date('i', $parameters['eventstarttime'])) : 0;
     $parameters['bymonth'] = isset($json['bymonth']) ? $json['bymonth'] : '';
     $parameters['bymonthday'] = isset($json['bymonthday']) ? $json['bymonthday'] : '';
     //bysetpos is not understood by old lib
     $parameters['bysetpos'] = isset($json['bysetpos']) ? $json['bysetpos'] : 1;
     $parameters['byday'] = array();
     foreach ($this->_days as $day) {
         if (isset($json[$day])) {
             $day = $day;
             //				if(!empty($json['bysetpos']))
             //					$day = $json['bysetpos'].$day;
             $parameters['byday'][] = $day;
         }
     }
     // Weekly recurrence _must_ have BYDAY set.
     if (strtolower($parameters['freq']) == 'weekly' && count($parameters['byday']) < 1) {
         $dayInt = date('w', $parameters['eventstarttime']);
         $parameters['byday'][] = $this->_days[$dayInt];
     } else {
         if (strtolower($parameters['freq']) == 'monthly' && isset($json['bysetpos'])) {
             if (count($parameters['byday']) < 1) {
                 throw new \Exception(\GO::t('selectMonthlyDay'));
             } else {
                 if (empty($json['bysetpos'])) {
                     throw new \Exception(\GO::t('selectWeekOfMonth'));
                 }
             }
         }
     }
     $this->setParams($parameters);
     $this->shiftDays();
 }
Exemple #6
0
 public function formatFormInput($key, &$attributes, \GO\Customfields\Model\AbstractCustomFieldsRecord $model)
 {
     $result_string = '';
     if (!empty($this->field->function)) {
         $f = $this->field->function;
         foreach ($attributes as $key => $value) {
             $f = str_replace('{' . $key . '}', floatval(\GO\Base\Util\Number::unlocalize($value)), $f);
         }
         $f = preg_replace('/\\{[^}]*\\}/', '0', $f);
         $old = ini_set("display_errors", "on");
         //if we don't set display_errors to on the next eval will send a http 500 status. Wierd but this works.
         @eval("\$result_string=" . $f . ";");
         if ($old !== false) {
             ini_set("display_errors", $old);
         }
         if ($result_string == "") {
             $result_string = null;
         }
     }
     $attributes[$key] = $result_string;
     return $attributes[$key];
 }
Exemple #7
0
 /**
  * Formats user input for the database.
  *
  * @param string $column
  * @param mixed $value
  * @return array
  */
 public function formatInput($column, $value)
 {
     if (!isset($this->columns[$column]['gotype'])) {
         //don't process unknown columns. But keep them for flexibility.
         return $value;
     }
     switch ($this->columns[$column]['gotype']) {
         case 'unixdate':
         case 'unixtimestamp':
             if ($this->columns[$column]['null'] && ($value == "" || $value == null)) {
                 return null;
             } else {
                 return \GO\Base\Util\Date::to_unixtime($value);
             }
             break;
         case 'number':
             $value = \GO\Base\Util\Number::unlocalize($value);
             if ($value === null && !$this->columns[$column]['null']) {
                 $value = 0;
             }
             return $value;
             break;
         case 'phone':
             //if it contains alpha chars then leave it alone.
             if (preg_match('/[a-z]+/i', $value)) {
                 return $value;
             } else {
                 return trim(preg_replace('/[\\s-_\\(\\)]+/', '', $value));
             }
             break;
         case 'boolean':
             $ret = empty($value) || $value === "false" ? 0 : 1;
             return $ret;
             break;
         case 'date':
             return \GO\Base\Util\Date::to_db_date($value);
             break;
         case 'textfield':
             return (string) $value;
             break;
         default:
             if ($this->columns[$column]['type'] == PDO::PARAM_INT) {
                 if ($this->columns[$column]['null'] && $value == "") {
                     $value = null;
                 } else {
                     $value = intval($value);
                 }
             }
             return $value;
             break;
     }
 }
Exemple #8
0
 protected function increaseTotals($record)
 {
     foreach ($this->totalizeColumns as $column) {
         if (isset($record[$column])) {
             $this->totals[$column] += \GO\Base\Util\Number::unlocalize($record[$column]);
         }
     }
 }