protected function actionSave($params) { if (empty($params['number']) || empty($params['remind_date']) || empty($params['remind_time'])) { throw new \Exception('Not all parameters are given'); } $scheduleCall = new \GO\Tasks\Model\Task(); $scheduleCall->setAttributes($params); // Check if the contact_id is really an ID or if it is a name. (The is_contact is true when it is an ID) if (!empty($params['contact_id'])) { $contact = \GO\Addressbook\Model\Contact::model()->findByPk($params['contact_id']); if (!empty($params['number']) && !empty($params['save_as'])) { $contact->{$params['save_as']} = $params['number']; $contact->save(); } $name = $contact->name; } else { $name = $params['contact_name']; } $scheduleCall->name = str_replace(array('{name}', '{number}'), array($name, $params['number']), \GO::t('scheduleCallTaskName', 'tasks')); $scheduleCall->reminder = \GO\Base\Util\Date::to_unixtime($params['remind_date'] . ' ' . $params['remind_time']); $scheduleCall->save(); if (isset($contact)) { $scheduleCall->link($contact); } echo $this->renderSubmit($scheduleCall); }
protected function afterSubmit(&$response, &$model, &$params, $modifiedAttributes) { $modelTypeModel = \GO\Base\Model\ModelType::model()->findSingleByAttribute('id', $model->model_type_id); if ($modelTypeModel->model_name == 'GO\\Addressbook\\Model\\Contact') { $modelWithComment = \GO::getModel($modelTypeModel->model_name)->findByPk($model->model_id); $modelWithComment->setAttribute('action_date', \GO\Base\Util\Date::to_unixtime($params['action_date'])); $modelWithComment->save(); } return parent::afterSubmit($response, $model, $params, $modifiedAttributes); }
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(); }
public function __construct() { if (!empty($_REQUEST['startdate'])) { $this->startDate = \GO\Base\Util\Date::to_unixtime($_REQUEST['startdate']); } if (!empty($_REQUEST['enddate'])) { $this->endDate = \GO\Base\Util\Date::date_add(\GO\Base\Util\Date::to_unixtime($_REQUEST['enddate']), 1); } if ($this->supportsStatusFilter()) { if (\GO\Base\Util\Http::isPostRequest()) { $this->statuses = !empty($_POST['status_id']) ? $_POST['status_id'] : array(); \GO::config()->save_setting(get_class($this), json_encode($this->statuses), \GO::user()->id); } else { $statuses = \GO::config()->get_setting(get_class($this), \GO::user()->id); if ($statuses) { $this->statuses = json_decode($statuses); } } } }
protected function actionMoveOld($params) { $this->checkRequiredParameters(array('mailbox', 'target_mailbox'), $params); if ($params['mailbox'] == $params['target_mailbox']) { throw new \Exception(GO::t("sourceAndTargetSame", "email")); } $account = Account::model()->findByPk($params['account_id']); $imap = $account->openImapConnection($params['mailbox']); $before_timestamp = \GO\Base\Util\Date::to_unixtime($params['until_date']); if (empty($before_timestamp)) { throw new \Exception(GO::t('untilDateError', 'email') . ': ' . $params['until_date']); } $date_string = date('d-M-Y', $before_timestamp); $uids = $imap->sort_mailbox('ARRIVAL', false, 'BEFORE "' . $date_string . '"'); $response['total'] = count($uids); //$response['success'] = $imap->delete($uids); $response['success'] = true; if ($response['total']) { $chunks = array_chunk($uids, 1000); while ($uids = array_shift($chunks)) { if (!$imap->move($uids, $params['target_mailbox'])) { throw new \Exception("Could not move mails! " . $imap->last_error()); } } } return $response; }
/** * 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; } }
protected function beforeSubmit(&$response, &$model, &$params) { if (isset($params['freq'])) { if (!empty($params['freq'])) { $rRule = new \GO\Base\Util\Icalendar\Rrule(); $rRule->readJsonArray($params); $model->rrule = $rRule->createRrule(); } else { $model->rrule = ''; } } if (!empty($params['remind'])) { // Check for a setted reminder $model->reminder = \GO\Base\Util\Date::to_unixtime($params['remind_date'] . ' ' . $params['remind_time']); } else { $model->reminder = 0; } if ($model->isNew && empty($params['remind']) && !isset($params['priority'])) { //This checks if it is called from the quickadd bar $model->reminder = $model->getDefaultReminder(\GO\Base\Util\Date::to_unixtime($params['start_time'])); } return parent::beforeSubmit($response, $model, $params); }
public function actionFreeBusyInfo($params) { $event_id = empty($params['event_id']) ? 0 : $params['event_id']; $date = getdate(\GO\Base\Util\Date::to_unixtime($params['date'])); $daystart = mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']); $dayend = mktime(0, 0, 0, $date['mon'], $date['mday'] + 1, $date['year']); $response['results'] = array(); $response['success'] = true; $merged_free_busy_participants = array(); for ($i = 0; $i < 1440; $i += 15) { $merged_free_busy_participants[$i] = 0; } $merged_free_busy_all = array(); for ($i = 0; $i < 1440; $i += 15) { $merged_free_busy_all[$i] = 0; } // Create Participants header row $row['name'] = '<b>' . \GO::t('participants', 'calendar') . '</b>'; $row['email'] = ''; $row['freebusy'] = array(); for ($min = 0; $min < 1440; $min += 15) { $row['freebusy'][] = array('time' => date(\GO::user()->time_format, mktime(0, $min)), 'busy' => false); } $response['results'][] = $row; // Create a participant row for every participant if (!empty($params['participantData'])) { $participants = json_decode($params['participantData'], true); foreach ($participants as $row) { $row['freebusy'] = array(); if (!empty($row['user_id'])) { $user = \GO\Base\Model\User::model()->findByPk($row['user_id']); if ($user) { $participant = new \GO\Calendar\Model\Participant(); $participant->user_id = $user->id; $participant->name = $user->name; $participant->email = $user->email; $participant->event_id = $event_id; if ($participant->hasFreeBusyAccess()) { $freebusy = $participant->getFreeBusyInfo($daystart, $dayend); foreach ($freebusy as $min => $busy) { if ($busy == 1) { $merged_free_busy_participants[$min] = 1; $merged_free_busy_all[$min] = 1; } $row['freebusy'][] = array('time' => date('G:i', mktime(0, $min)), 'busy' => $busy); } } } } $response['results'][] = $row; } } // Create the together row $row['name'] = \GO::t('allTogetherForParticipants', 'calendar'); $row['email'] = ''; $row['freebusy'] = array(); foreach ($merged_free_busy_participants as $min => $busy) { $row['freebusy'][] = array('time' => date(\GO::user()->time_format, mktime(0, $min)), 'busy' => $busy); } $response['results'][] = $row; // And now for the resources... $resource['name'] = '<b>' . \GO::t('resources', 'calendar') . '</b>'; $resource['email'] = ''; $resource['freebusy'] = array(); for ($min = 0; $min < 1440; $min += 15) { $resource['freebusy'][] = array('time' => date(\GO::user()->time_format, mktime(0, $min)), 'busy' => false); } $response['results'][] = $resource; $merged_free_busy_resources = array(); for ($i = 0; $i < 1440; $i += 15) { $merged_free_busy_resources[$i] = 0; } $resourceIds = json_decode($params['resourceIds']); if (empty($resourceIds)) { $resourceIds = array('-1'); } $calendarsStmt = \GO\Calendar\Model\Calendar::model()->find(\GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addInCondition('id', $resourceIds))->order('name', 'ASC')); foreach ($calendarsStmt as $resourceCalModel) { $resource['name'] = $resourceCalModel->name; $resource['email'] = $resourceCalModel->user->email; $resource['freebusy'] = array(); $freebusy = $resourceCalModel->getFreeBusyInfo($daystart); foreach ($freebusy as $min => $busy) { if ($busy == 1) { $merged_free_busy_resources[$min] = 1; $merged_free_busy_all[$min] = 1; } $resource['freebusy'][] = array('time' => date('G:i', mktime(0, $min)), 'busy' => $busy); } $response['results'][] = $resource; } $resource['name'] = \GO::t('allTogetherForResources', 'calendar'); $resource['email'] = ''; $resource['freebusy'] = array(); foreach ($merged_free_busy_resources as $min => $busy) { $resource['freebusy'][] = array('time' => date(\GO::user()->time_format, mktime(0, $min)), 'busy' => $busy); } $response['results'][] = $resource; $business['name'] = '<b>' . \GO::t('allTogether', 'calendar') . '</b>'; $business['email'] = ''; $business['freebusy'] = array(); foreach ($merged_free_busy_all as $min => $busy) { $business['freebusy'][] = array('time' => date(\GO::user()->time_format, mktime(0, $min)), 'busy' => $busy); } $response['results'][] = $business; return $response; }
/** * Save the outofoffice message when it's data is posted. * * @param SieveModule $this * @param array $response * @param Account $model * @param array $params * @param array $modifiedAttributes */ public static function saveOutOfOfficeMessage(&$this, &$response, &$model, &$params, $modifiedAttributes) { // Check if the ooo_ fields are posted if (isset($params['ooo_message'])) { \GO::debug('PROCESS OUT OF OFFICE SIEVE'); // if(!isset($params['ooo_subject'])){ // $params['ooo_subject'] = \GO::t('standardvacationsubject','sieve'); // } if (!isset($params['ooo_days'])) { $params['ooo_days'] = 3; } // Check the aliasses $alias = $model->getDefaultAlias(); if (!empty($alias)) { if (empty($params['ooo_aliasses'])) { // Add the default account email address $params['ooo_aliasses'] = array($alias->email); } else { if (!is_array($params['ooo_aliasses'])) { // Replace new lines from the aliasses and replace them with a comma. $params['ooo_aliasses'] = preg_replace('#\\s+#', ',', trim($params['ooo_aliasses'])); // Make an array of the aliasses $params['ooo_aliasses'] = explode(',', $params['ooo_aliasses']); } // Remove any empty values from the array $params['ooo_aliasses'] = array_filter($params['ooo_aliasses']); // Check if the default account email address is present. // If not then add it to the list if (in_array($alias->email, $params['ooo_aliasses'])) { // Email is found } else { // Email is not found, add it as first of the list. array_unshift($params['ooo_aliasses'], $alias->email); } } } $sieve = new \GO\Sieve\Util\Sieve(); $connected = $sieve->connect($model->username, $model->decryptPassword(), $model->host, $model->sieve_port, null, !empty($model->sieve_usetls), array(), true); if (empty($connected)) { \GO::debug('DO NOT PROCESS OOO_SIEVE'); return; throw new \Exception('Sorry, manage sieve filtering not supported on ' . $model->host . ' using port ' . $model->sieve_port); } \GO::debug('PROCESSING OOO_SIEVE'); $sieveScriptName = $sieve->get_active($model->id); $sieve->load($sieveScriptName); // $params['ooo_activate'] 30-06-2015 // $params['ooo_script_active'] false // $params['ooo_aliasses'] admin@intermesh.dev // $params['ooo_deactivate'] 07-07-2015 // $params['ooo_script_index'] 0 // $params['ooo_message'] I am on vacation // $params['ooo_rule_name'] Out of office // $params['ooo_script_name'] default // $params['ooo_days'] 3 $activateDate = date('Y-m-d', \GO\Base\Util\Date::to_unixtime($params['ooo_activate'])); $deactivateDate = date('Y-m-d', \GO\Base\Util\Date::to_unixtime($params['ooo_deactivate'])); // Convert posted data to the correct rule object $rule = array("type" => "if", "tests" => array(0 => array("test" => "currentdate", "not" => false, "arg" => $activateDate, "part" => "date", "type" => "value-ge"), 1 => array("test" => "currentdate", "not" => false, "arg" => $deactivateDate, "part" => "date", "type" => "value-le")), "actions" => array(0 => array("type" => "vacation", "reason" => $params['ooo_message'], "days" => $params['ooo_days'], "addresses" => $params['ooo_aliasses'])), "join" => true, "disabled" => !$params['ooo_script_active'], "name" => $params['ooo_rule_name']); if (!empty(\GO::config()->sieve_vacation_subject)) { $rule['actions'][0]['subject'] = \GO::config()->sieve_vacation_subject; } $response['sieve_after'] = $rule; // Search for the correct index of the Out of office script again. if (!empty($sieve->script->content)) { $index = 0; foreach ($sieve->script->content as $item) { // Get the "Out of office" script because it need to be loaded here if (isset($item['name']) && $item['name'] == 'Out of office') { break; // will leave the foreach loop and also "break" the if statement } $index++; } \GO::debug('*****SIEVE OOO GET INDEX FOR OOO: ' . $index); if ($index > -1 && isset($sieve->script->content[$index])) { \GO::debug('*****SIEVE OOO ADD OOO RULE (INDEX:' . $index . '):' . var_export($rule, true)); $sieve->script->update_rule($index, $rule); } else { \GO::debug('*****SIEVE OOO ADD OOO RULE:' . var_export($rule, true)); $sieve->script->add_rule($rule); } } else { \GO::debug('*****SIEVE OOO ADD OOO RULE:' . var_export($rule, true)); $sieve->script->add_rule($rule); } \GO::debug(var_export($sieve->script->content, true)); // Het script opslaan if ($sieve->save()) { $response['success'] = true; } else { $response['feedback'] = "Could not save filtering rules. Please check your input.<br />" . $sieve->error(); $response['success'] = false; } } }