Esempio n. 1
0
 /**
  * Get the data for the grid that shows all the tasks from the selected tasklists.
  * 
  * @param Array $params
  * @return Array The array with the data for the grid. 
  */
 protected function actionBirthdays($params)
 {
     $today = mktime(0, 0, 0);
     $next_month = \GO\Base\Util\Date::date_add(mktime(0, 0, 0), 30);
     //\GO::debug($yesterday);
     $start = date('Y-m-d', $today);
     $end = date('Y-m-d', $next_month);
     //\GO::debug($start);
     $select = "t.id, birthday, first_name, middle_name, last_name, addressbook_id, photo, " . "IF (STR_TO_DATE(CONCAT(YEAR('{$start}'),'/',MONTH(birthday),'/',DAY(birthday)),'%Y/%c/%e') >= '{$start}', " . "STR_TO_DATE(CONCAT(YEAR('{$start}'),'/',MONTH(birthday),'/',DAY(birthday)),'%Y/%c/%e') , " . "STR_TO_DATE(CONCAT(YEAR('{$start}')+1,'/',MONTH(birthday),'/',DAY(birthday)),'%Y/%c/%e')) " . "as upcoming ";
     $findCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('birthday', '0000-00-00', '!=')->addRawCondition('birthday', 'NULL', 'IS NOT');
     $settings = \GO\Addressbook\Model\BirthdaysPortletSetting::model()->findByAttribute('user_id', \GO::user()->id);
     if (count($settings)) {
         $abooks = array_map(function ($value) {
             return $value->addressbook_id;
         }, $settings->fetchAll());
         $findCriteria->addInCondition('addressbook_id', $abooks);
     }
     $having = "upcoming BETWEEN '{$start}' AND '{$end}'";
     $findParams = \GO\Base\Db\FindParams::newInstance()->distinct()->select($select)->criteria($findCriteria)->having($having)->order('upcoming');
     //$response['data']['original_photo_url']=$model->photoURL;
     $columnModel = new \GO\Base\Data\ColumnModel('GO\\Addressbook\\Model\\Contact');
     $columnModel->formatColumn('addressbook_id', '$model->addressbook->name');
     $columnModel->formatColumn('photo_url', '$model->getPhotoThumbURL()');
     $columnModel->formatColumn('age', '($model->upcoming != date("Y-m-d")) ? $model->age+1 : $model->age');
     $store = new \GO\Base\Data\DbStore('GO\\Addressbook\\Model\\Contact', $columnModel, $_POST, $findParams);
     return $store->getData();
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 protected function init()
 {
     $this->columns['content']['required'] = true;
     //		$this->addDefaultTag('contact:salutation', \GO::t('default_salutation_unknown'));
     $this->addDefaultTag('salutation', \GO::t('default_salutation_unknown'));
     $this->addDefaultTag('date', \GO\Base\Util\Date::get_timestamp(time(), false));
     return parent::init();
 }
Esempio n. 4
0
 /**
  * Format the datetime to the format given
  * If there is no format specified the default user specified format will be used
  * @todo fix timezone issue
  * @param string $format the format the date should be returned
  * @return string formatted date
  */
 public function format($format = null)
 {
     if ($format === null) {
         //$format = \GO::user() ? \GO::user()->date_format . " " . \GO::user()->time_format : \GO::config()->default_date_format . " " . \GO::config()->default_time_format;
         return \GO\Base\Util\Date::get_timestamp($this->getTimestamp());
     }
     return parent::format($format);
 }
Esempio n. 5
0
 protected function afterLoad(&$response, &$model, &$params)
 {
     $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);
         $actionDate = $modelWithComment->getAttribute('action_date');
         $response['data']['action_date'] = \GO\Base\Util\Date::get_timestamp($actionDate, false);
     }
     return parent::afterLoad($response, $model, $params);
 }
Esempio n. 6
0
 public static function koningsdag($year)
 {
     $defaultDay = '27';
     $defaultMonth = '4';
     $theDate = mktime(0, 0, 0, $defaultMonth, $defaultDay, $year);
     if (date('w', $theDate) == 0) {
         $theDate = \GO\Base\Util\Date::date_add($theDate, -1);
     }
     return date('Y-m-d', $theDate);
 }
Esempio n. 7
0
 /**
  * Renders a page in the PDF with the given day parmeter
  * @param integer $day unixtimestamp of day you like to render
  */
 public function render($day)
 {
     $this->day = \GO\Base\Util\Date::clear_time($day);
     $this->currentDay = $this->day;
     //$this->events = $this->orderEvents($events);
     $this->AddPage();
     $this->calculateOverlap();
     $this->drawEventsBackground();
     $this->drawEvents();
     $this->drawTasks();
     $this->drawNotes();
 }
Esempio n. 8
0
 /**
  * Creates a new component.
  *
  * By default this object will iterate over its own children, but this can 
  * be overridden with the iterator argument
  * 
  * @param string $name 
  * @param Sabre\VObject\ElementList $iterator
  */
 public function __construct()
 {
     parent::__construct();
     $tz = new \DateTimeZone(\GO::user() ? \GO::user()->timezone : date_default_timezone_get());
     //$tz = new \DateTimeZone("Europe/Amsterdam");
     $transitions = $tz->getTransitions();
     $start_of_year = mktime(0, 0, 0, 1, 1);
     $to = \GO\Base\Util\Date::get_timezone_offset(time());
     if ($to < 0) {
         if (strlen($to) == 2) {
             $to = '-0' . $to * -1;
         }
     } else {
         if (strlen($to) == 1) {
             $to = '0' . $to;
         }
         $to = '+' . $to;
     }
     $STANDARD_TZOFFSETFROM = $STANDARD_TZOFFSETTO = $DAYLIGHT_TZOFFSETFROM = $DAYLIGHT_TZOFFSETTO = $to;
     $STANDARD_RRULE = '';
     $DAYLIGHT_RRULE = '';
     for ($i = 0, $max = count($transitions); $i < $max; $i++) {
         if ($transitions[$i]['ts'] > $start_of_year) {
             $weekday1 = $this->_getDay($transitions[$i]['time']);
             $weekday2 = $this->_getDay($transitions[$i + 1]['time']);
             if ($transitions[$i]['isdst']) {
                 $dst_start = $transitions[$i];
                 $dst_end = $transitions[$i + 1];
             } else {
                 $dst_end = $transitions[$i];
                 $dst_start = $transitions[$i + 1];
             }
             $STANDARD_TZOFFSETFROM = $this->_formatVtimezoneTransitionHour($dst_start['offset'] / 3600);
             $STANDARD_TZOFFSETTO = $this->_formatVtimezoneTransitionHour($dst_end['offset'] / 3600);
             $DAYLIGHT_TZOFFSETFROM = $this->_formatVtimezoneTransitionHour($dst_end['offset'] / 3600);
             $DAYLIGHT_TZOFFSETTO = $this->_formatVtimezoneTransitionHour($dst_start['offset'] / 3600);
             $DAYLIGHT_RRULE = "FREQ=YEARLY;BYDAY={$weekday1};BYMONTH=" . date('n', $dst_start['ts']);
             $STANDARD_RRULE = "FREQ=YEARLY;BYDAY={$weekday2};BYMONTH=" . date('n', $dst_end['ts']);
             break;
         }
     }
     $this->tzid = $tz->getName();
     //	$this->add("last-modified", "19870101T000000Z");
     $rrule = new \Sabre\VObject\Recur\RRuleIterator($STANDARD_RRULE, new \DateTime('1970-01-01 ' . substr($STANDARD_TZOFFSETFROM, 1) . ':00'));
     $rrule->next();
     $rrule->next();
     $this->add($this->createComponent("standard", array('dtstart' => $rrule->current()->format('Ymd\\THis'), 'rrule' => $STANDARD_RRULE, 'tzoffsetfrom' => $STANDARD_TZOFFSETFROM . "00", 'tzoffsetto' => $STANDARD_TZOFFSETTO . "00")));
     $rrule = new \Sabre\VObject\Recur\RRuleIterator($DAYLIGHT_RRULE, new \DateTime('1970-01-01 ' . substr($DAYLIGHT_TZOFFSETFROM, 1) . ':00'));
     $rrule->next();
     $rrule->next();
     $this->add($this->createComponent("daylight", array('dtstart' => $rrule->current()->format('Ymd\\THis'), 'rrule' => $DAYLIGHT_RRULE, 'tzoffsetfrom' => $DAYLIGHT_TZOFFSETFROM . "00", 'tzoffsetto' => $DAYLIGHT_TZOFFSETTO . "00")));
 }
Esempio n. 9
0
 public function __construct($prefixString = '')
 {
     if (!\GO::modules()->isInstalled('files')) {
         throw new \Exception('The current action requires the files module to be activated for the current user.');
     }
     // Make sure the current user's folder exists.
     $userFolderModel = \GO\Files\Model\Folder::model()->findHomeFolder(\GO::user());
     if (empty($userFolderModel)) {
         $userFolder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'users/' . \GO::user()->username);
         $userFolder->create();
         $userFolderModel = new \GO\Files\Model\Folder();
         $userFolderModel->findByPath('users/' . \GO::user()->username, true);
     }
     parent::__construct(\GO::config()->file_storage_path . $userFolderModel->path . '/' . $prefixString . \GO\Base\Util\Date::get_timestamp(time(), true) . '.log');
 }
Esempio n. 10
0
 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);
             }
         }
     }
 }
Esempio n. 11
0
 public function actionDay($date, $calendars)
 {
     $calendarIds = json_decode($calendars);
     $date = \GO\Base\Util\Date::clear_time($date);
     $start = $date - 1;
     $end = $date + 24 * 3600;
     $report = new \GO\Calendar\Reports\Day();
     foreach ($calendarIds as $id) {
         $calendar = \GO\Calendar\Model\Calendar::model()->findByPk($id);
         $events = $calendar->getEventsForPeriod($start, $end);
         if (!empty($calendar->tasklist)) {
             $tasklistId = $calendar->tasklist->id;
             $report->tasks = \GO\Tasks\Model\Task::model()->findByDate($date, $tasklistId)->fetchAll();
         }
         $report->setEvents($events);
         $report->render($date);
         $report->calendarName = $calendar->name;
     }
     $report->Output('day.pdf');
 }
Esempio n. 12
0
 protected function actionRotate($params)
 {
     $this->requireCli();
     $findParams = \GO\Base\Db\FindParams::newInstance();
     $findParams->getCriteria()->addCondition('ctime', \GO\Base\Util\Date::date_add(time(), -\GO::config()->log_max_days), '<');
     $stmt = \GO\Log\Model\Log::model()->find($findParams);
     $count = $stmt->rowCount();
     echo "Dumping " . $count . " records to CSV file\n";
     if ($count) {
         $logPath = '/var/log/groupoffice/' . \GO::config()->id . '.csv';
         $csvLogFile = new \GO\Base\Fs\CsvFile($logPath);
         $csvLogFile->parent()->create();
         while ($log = $stmt->fetch()) {
             if (!$csvLogFile->putRecord(array_values($log->getAttributes('formatted')))) {
                 throw new \Exception("Could not write to CSV log file: " . $csvLogFile->path());
             }
             $log->delete();
         }
     }
     echo "Done\n";
 }
Esempio n. 13
0
 public function formatReminderRecord($record, $model, $store)
 {
     $record['iconCls'] = 'go-icon-reminders';
     $record['type'] = \GO::t('other');
     $record['model_name'] = '';
     if (!empty($record['model_type_id'])) {
         $modelType = \GO\Base\Model\ModelType::model()->findByPk($record['model_type_id']);
         if ($modelType && \GO::getModel($modelType->model_name)) {
             $record['iconCls'] = 'go-model-icon-' . $modelType->model_name;
             $record['type'] = \GO::getModel($modelType->model_name)->localizedName;
             $record['model_name'] = $modelType->model_name;
         }
     }
     $now = \GO\Base\Util\Date::clear_time(time());
     $time = $model->vtime ? $model->vtime : $model->time;
     if (\GO\Base\Util\Date::clear_time($time) != $now) {
         $record['local_time'] = date(\GO::user()->completeDateFormat, $time);
     } else {
         $record['local_time'] = date(\GO::user()->time_format, $time);
     }
     $record['text'] = htmlspecialchars_decode($record['text']);
     return $record;
 }
Esempio n. 14
0
 public function getNextDate($startDate, $workingHours, &$leftOverHours = 0)
 {
     $hoursForDay = $this->getHoursForDay($startDate);
     //		\GO::debug('getNextDate('.date('Ymd',$startDate).', '.$workingHours.')');
     //		\GO::debug("Left: ".$this->_leftOverHours);
     //		\GO::debug("Hours for day: ".$hoursForDay);
     //		$workingHours+=$this->_leftOverHours;
     $workingHours -= $hoursForDay;
     //		\GO::debug($workingHours);
     if ($workingHours >= 0) {
         for ($i = 0; $i < 7; $i++) {
             $startDate = \GO\Base\Util\Date::date_add($startDate, 1);
             $hoursForDay = $this->getHoursForDay($startDate);
             $workingHours -= $hoursForDay;
             if ($workingHours < 0) {
                 break;
             }
         }
     }
     //		$this->_leftOverHours=$hoursForDay - $workingHours*-1;
     $leftOverHours = $hoursForDay - $workingHours * -1;
     return $startDate;
 }
Esempio n. 15
0
 private function _addProjectInfo()
 {
     $html = '<table cellpadding="2">';
     $html .= '<tr><td width="150px">' . \GO::t('strName') . ':</td><td>' . $this->project->path . '</td></tr>';
     if (!empty($this->project->reference_no)) {
         $html .= '<tr><td width="150px">' . \GO::t('referenceNo', 'projects2') . ':</td><td>' . $this->project->reference_no . '</td></tr>';
     }
     $html .= '<tr><td>' . \GO::t('status', 'projects2') . ':</td><td>' . $this->project->status->name . '</td></tr>';
     if (!empty($this->project->start_time)) {
         $html .= '<tr><td>' . \GO::t('startTime', 'projects2') . ':</td><td>' . $this->project->getAttribute('start_time', 'formatted') . '</td></tr>';
     }
     if (!empty($this->project->due_time)) {
         $html .= '<tr><td>' . \GO::t('projectDue_time', 'projects2') . ':</td><td>' . $this->project->getAttribute('due_time', 'formatted') . '</td></tr>';
     }
     $html .= '<tr><td>' . \GO::t('lag', 'projects2') . ':</td><td>' . \GO\Base\Util\Date::minutesToTimeString($this->project->getLag()) . '</td></tr>';
     if (!empty($this->project->description)) {
         $html .= '<tr><td>' . \GO::t('strDescription') . ':</td><td>' . $this->project->description . '</td></tr>';
     }
     if (!empty($this->project->income_type)) {
         switch ($this->project->income_type) {
             case \GO\Projects2\Model\Project::INCOME_CONTRACT_PRICE:
                 $html .= '<tr><td>' . \GO::t('incomeType', 'projects2') . ':</td><td>' . \GO::t('contractPrice', 'projects2') . '</td></tr>';
                 break;
             case \GO\Projects2\Model\Project::INCOME_POST_CALCULATION:
                 $html .= '<tr><td>' . \GO::t('incomeType', 'projects2') . ':</td><td>' . \GO::t('postCalculation', 'projects2') . '</td></tr>';
                 break;
             case \GO\Projects2\Model\Project::INCOME_NOT_BILLABLE:
                 $html .= '<tr><td>' . \GO::t('incomeType', 'projects2') . ':</td><td>' . \GO::t('notBillable', 'projects2') . '</td></tr>';
                 break;
             default:
                 break;
         }
     }
     $html .= '</table>';
     $this->_pdf->writeHTML($html, true, false, false, true);
     $this->_pdf->Ln(10);
 }
Esempio n. 16
0
 /**
  * Get the data for the grid that shows all the tasks from the selected tasklists.
  * 
  * @param Array $params
  * @return Array The array with the data for the grid. 
  */
 protected function actionPortletGrid($params)
 {
     $now = \GO\Base\Util\Date::date_add(mktime(0, 0, 0), 1);
     if (isset($params['completed_task_id'])) {
         $updateTask = \GO\Tasks\Model\Task::model()->findByPk($params['completed_task_id']);
         if (isset($params['checked'])) {
             $updateTask->setCompleted($params['checked'] == "true");
         }
     }
     // Find out the sort for the grid
     $sort = !empty($params['sort']) ? $params['sort'] : 'due_time';
     $dir = !empty($params['dir']) ? $params['dir'] : 'ASC';
     $store = \GO\Base\Data\Store::newInstance(\GO\Tasks\Model\Task::model());
     $findCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('start_time', $now, '<')->addCondition('status', \GO\Tasks\Model\Task::STATUS_COMPLETED, '<>', 't');
     $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', \GO::user()->id, '=', 'pt')->addCondition('tasklist_id', 'pt.tasklist_id', '=', 't', true, true);
     $tasklistJoinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('tasklist_id', 'tl.id', '=', 't', true, true);
     $findParams = $store->getDefaultParams($params)->select('t.*, tl.name AS tasklist_name')->criteria($findCriteria)->order(array('tasklist_name', $sort), $dir)->ignoreAcl()->join(\GO\Tasks\Model\PortletTasklist::model()->tableName(), $joinCriteria, 'pt')->join(\GO\Tasks\Model\Tasklist::model()->tableName(), $tasklistJoinCriteria, 'tl');
     $stmt = \GO\Tasks\Model\Task::model()->find($findParams);
     $store->setStatement($stmt);
     $store->getColumnModel()->formatColumn('tasklist_name', '$model->tasklist_name');
     $store->getColumnModel()->formatColumn('late', '$model->isLate();');
     $store->getColumnModel()->formatColumn('is_active', '$model->isActive()');
     return $store->getData();
 }
Esempio n. 17
0
 public function drawEventCalendar()
 {
     $w = $this->right - 7;
     $h = $this->getPageHeight() - $this->headerHeight - 16;
     $this->SetY(36);
     $this->SetFont(null, '', 7.5);
     $this->Cell(7);
     for ($d = 0; $d < 7; $d++) {
         $this->Cell($w / 7, 6, $this->days_long[$d], $d != 0, 0, 'C');
     }
     $this->Ln();
     $day = '';
     $weeks = $this->getWeeksInMonth();
     $dateh = 5;
     $rowh = $h / $weeks;
     $colw = $w / 7;
     $date = $this->getStartTime();
     $month = date('M', $date);
     for ($r = 0; $r < $weeks; $r++) {
         // 5 weeks TODO fix find weeks in month
         //Draw vertical dates
         $this->StartTransform();
         $this->Rotate(90);
         $this->Translate(-($rowh - 9), 0);
         $this->Cell(7, 7, $this->getWeekLabel($date), 0, 0, 'C');
         $this->Rotate(-90);
         $this->StopTransform();
         $this->setCellPaddings(1, 1, 0, 0);
         for ($c = 0; $c < 7; $c++) {
             //toggle weekday
             $coord = array($this->GetX(), $this->GetY());
             $this->SetFont(null, 'B', $this->fSizeMedium - 2);
             $this->Cell($colw, 5, date('j ', $date) . $month, 1, 0, 'L', false, '', 0, false, 'T', 'T');
             $month = '';
             $more = false;
             $this->SetFont(null, '', $this->fSizeSmall);
             if (date('M', $date) != date('M', Date::date_add($date, 1))) {
                 $month = date('M', Date::date_add($date, 1));
             }
             $events = '';
             if (date('M', $this->day) == date('M', $date)) {
                 $amount = 0;
                 if (isset($this->events[$date]['fd'])) {
                     foreach ($this->events[$date]['fd'] as $i => $event) {
                         //full day
                         $events .= '<br><font color="blue">' . substr($event->name, 0, 25) . '</font>';
                         $amount++;
                     }
                 }
                 $eventsMerge = $this->allEvents($date);
                 if (!empty($eventsMerge)) {
                     foreach ($eventsMerge as $i => $event) {
                         //part day
                         if ($i + $amount > 5) {
                             $more = true;
                             break;
                         }
                         $events .= "<br>" . date('G:i', $event->start_time) . '-' . date('G:i', $event->end_time) . ' ' . substr($event->name, 0, 25);
                     }
                 }
                 $this->SetFillColor(255);
             } else {
                 $this->SetFillColor(240);
             }
             //$this->SetXY($coord[0], $coord[1]+$dateh);
             //\GO::debug($events);
             //$this->MultiCell($colw,$rowh-$dateh,$events, 1,'L',true,0,'','',true,0,true,true,$rowh-$dateh,'T',true);
             //$this->writeHTMLCell($colw,$rowh-$dateh,$this->GetX(),$this->GetY(),  mb_convert_encoding($events,'UTF-8', 'UTF-8'), 1,0,true);
             $this->DayCell($events, $colw, $rowh - $dateh, $coord[0], $coord[1] + $dateh, $more);
             $this->SetXY($coord[0] + $colw, $coord[1]);
             $date = Date::date_add($date, 1);
         }
         $this->SetXY($this->leftMargin, $this->GetY() + $rowh);
     }
     $this->SetXY(10, 36);
     $this->Cell($colw + 7, $rowh * $weeks + 6, '', 1);
 }
Esempio n. 18
0
 /**
  * This action will generate multiple Email Download link and return a JSON
  * response with the generated links in the email subject
  * @param array $params
  * - string ids: json encode file ids to mail
  * - timestamp expire_time: chosen email link expire time 
  * - int template_id: id of used template
  * - int alias_id: id of alias to mail from
  * - string content_type : html | plain  
  * @return string Json response
  */
 protected function actionEmailDownloadLink($params)
 {
     $files = \GO\Files\Model\File::model()->findByAttribute('id', json_decode($params['ids']));
     $html = $params['content_type'] == 'html';
     $bodyindex = $html ? 'htmlbody' : 'plainbody';
     $lb = $html ? '<br />' : "\n";
     $text = $html ? \GO::t('clickHereToDownload', "files") : \GO::t('copyPasteToDownload', "files");
     $linktext = $html ? "<ul>" : $lb;
     foreach ($files as $file) {
         $url = $file->getEmailDownloadURL($html, \GO\Base\Util\Date::date_add($params['expire_time'], 1), $params['delete_when_expired']);
         $linktext .= $html ? '<li><a href="' . $url . '">' . $file->name . '</a></li>' . $lb : $url . $lb;
     }
     $linktext .= $html ? "</ul>" : "\n";
     $text .= ' (' . \GO::t('possibleUntil', 'files') . ' ' . \GO\Base\Util\Date::get_timestamp(\GO\Base\Util\Date::date_add($file->expire_time, -1), false) . ')' . $lb;
     $text .= $linktext;
     if ($params['template_id'] && ($template = \GO\Addressbook\Model\Template::model()->findByPk($params['template_id']))) {
         $message = \GO\Email\Model\SavedMessage::model()->createFromMimeData($template->content);
         $response['data'] = $message->toOutputArray($html, true);
         if (strpos($response['data'][$bodyindex], '{body}')) {
             $response['data'][$bodyindex] = \GO\Addressbook\Model\Template::model()->replaceUserTags($response['data'][$bodyindex], true);
             \GO\Addressbook\Model\Template::model()->htmlSpecialChars = false;
             $response['data'][$bodyindex] = \GO\Addressbook\Model\Template::model()->replaceCustomTags($response['data'][$bodyindex], array('body' => $text));
         } else {
             $response['data'][$bodyindex] = \GO\Addressbook\Model\Template::model()->replaceUserTags($response['data'][$bodyindex], false);
             $response['data'][$bodyindex] = $text . $response['data'][$bodyindex];
         }
     } else {
         $response['data'][$bodyindex] = $text;
     }
     $response['data']['subject'] = \GO::t('downloadLink', 'files');
     //.' '.$file->name;
     $response['success'] = true;
     return $response;
 }
Esempio n. 19
0
 function send_command($command, $piped = false)
 {
     if ($piped) {
         $final_command = '';
         foreach ($command as $v) {
             $final_command .= 'A' . $this->command_number() . ' ' . $v;
         }
         $command = $final_command;
     } else {
         $command = 'A' . $this->command_number() . ' ' . $command;
     }
     if (!is_resource($this->handle)) {
         throw new \Exception("Lost connection to " . $this->server);
     }
     $this->lastCommand = $command;
     if (!fputs($this->handle, $command)) {
         throw new \Exception("Lost connection to " . $this->server);
         //				eturn false;
     }
     if (!empty(\GO::session()->values['debugSql'])) {
         \GO::debug("S: " . $command);
     }
     $this->commands[trim($command)] = \GO\Base\Util\Date::getmicrotime();
 }
Esempio n. 20
0
 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;
 }
Esempio n. 21
0
 function _makeHeader()
 {
     $this->SetFont($this->font, '', 10);
     //		if (count($this->supplier)) {
     //			$this->_orderAttr = $billing->replace_contact_with_supplier($this->_orderAttr, $this->supplier);
     //		}
     $this->setXY($this->_template['left_col_left'], $this->_template['left_col_top']);
     $width = $this->_template['right_col_left'] - $this->_template['left_col_left'];
     $this->SetFont($this->font, 'B', 16);
     $this->Cell($width, 16, $this->_template['title'], 0, 18);
     $this->SetFont($this->font, '', 10);
     $this->MultiCell($width, 12, nl2br($this->_replaceFields($this->_template['left_col'])), 0, 'J', 0, 1, '', '', true, 0, true);
     $left_col_bottom = $this->GetY();
     $this->setXY($this->_template['right_col_left'], $this->_template['right_col_top']);
     $width = $this->getPageWidth() - $this->_template['right_col_left'] - $this->_template['margin_right'];
     $this->MultiCell($width, 12, nl2br($this->_replaceFields($this->_template['right_col'])), 0, 'J', 0, 1, '', '', true, 0, true);
     $right_col_bottom = $this->getY();
     $this->setXY($this->lMargin, $left_col_bottom);
     $keep_old = false;
     if (strpos($this->_template['left_col'], '%order_data%') === false && strpos($this->_template['right_col'], '%order_data%') === false && strpos($this->_template['right_col'], '%order_id%') === false && strpos($this->_template['left_col'], '%order_id%') === false) {
         $keep_old = true;
     }
     if ($keep_old) {
         $this->ln(20);
         if (!empty($this->_template['show_reference']) && !empty($this->_orderAttr['reference'])) {
             $this->SetFont($this->font, 'B', 10);
             $this->cell(120, 12, $this->_template['reference_name'] . ':');
             $this->SetFont($this->font, '', 10);
             $this->cell(120, 12, $this->_orderAttr['reference']);
             $this->ln();
         }
         if (GO::modules()->isInstalled("webshop") && ($linkedOrder = $this->_order->getFirstLinkedOrder())) {
             $this->SetFont($this->font, 'B', 10);
             $this->cell(120, 12, 'Order no.:');
             $this->SetFont($this->font, '', 10);
             $this->cell(120, 12, $linkedOrder->order_id);
             $this->ln();
         }
         $this->SetFont($this->font, 'B', 10);
         $this->cell(120, 12, $this->_template['number_name'] . ':');
         $this->SetFont($this->font, '', 10);
         $this->cell(120, 12, $this->_orderAttr['order_id']);
         $this->ln();
         $this->SetFont($this->font, 'B', 10);
         $this->cell(120, 12, $this->_template['date_name'] . ':');
         $this->SetFont($this->font, '', 10);
         $this->cell(120, 12, $this->_orderAttr['btime']);
         $this->ln();
         $date_sent = \GO\Base\Util\Date::get_timestamp(time(), false);
         if ($this->_template['show_date_sent']) {
             $this->SetFont($this->font, 'B', 10);
             $this->cell(120, 12, \GO::t('date_sent', 'billing') . ':');
             $this->SetFont($this->font, '', 10);
             $this->cell(120, 12, $date_sent);
             $this->ln();
         }
         $left_col_bottom = $this->GetY();
     }
     if ($right_col_bottom > $left_col_bottom) {
         $this->setY($right_col_bottom);
     }
     $this->Ln(20);
 }
Esempio n. 22
0
 public function formatDisplay($key, &$attributes, \GO\Customfields\Model\AbstractCustomFieldsRecord $model)
 {
     return \GO\Base\Util\Date::get_timestamp(strtotime($attributes[$key]), true);
 }
Esempio n. 23
0
 /**
  * Get the Vobject of this calendar
  * 
  * @return string
  */
 public function toVObject()
 {
     //$stmt = $this->events(\GO\Base\Db\FindParams::newInstance()->select("t.*"));
     $findParams = \GO\Base\Db\FindParams::newInstance()->select("t.*");
     $findParams->getCriteria()->addCondition("calendar_id", $this->id);
     $stmt = Event::model()->findForPeriod($findParams, \GO\Base\Util\Date::date_add(time(), 0, -1));
     $string = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Intermesh//NONSGML " . \GO::config()->product_name . " " . \GO::config()->version . "//EN\r\n";
     $t = new \GO\Base\VObject\VTimezone();
     $string .= $t->serialize();
     while ($event = $stmt->fetch()) {
         $v = $event->toVObject();
         $string .= $v->serialize();
     }
     $string .= "END:VCALENDAR\r\n";
     return $string;
 }
Esempio n. 24
0
 public function getDefaultReminder($startTime)
 {
     $settings = Settings::model()->getDefault(\GO::user());
     $tmp = \GO\Base\Util\Date::date_add($startTime, -$settings->reminder_days);
     // Set default to 8:00 when reminder_time is not set.
     $rtime = empty($settings->reminder_time) ? "08:00" : $settings->reminder_time;
     $dateString = date('Y-m-d', $tmp) . ' ' . $rtime;
     $time = strtotime($dateString);
     return $time;
 }
Esempio n. 25
0
 public function getAsText()
 {
     $this->shiftDays(false);
     $days = array();
     $fulldays = \GO::t('full_days');
     foreach ($this->_byday as $icalDay) {
         $index = array_search($icalDay, $this->_days);
         $days[] = $fulldays[$index];
     }
     if (count($days) == 1) {
         $daysStr = $days[0];
     } else {
         $daysStr = ' ' . \GO::t('and') . ' ' . array_pop($days);
         $daysStr = implode(', ', $days) . $daysStr;
     }
     $this->shiftDays(true);
     $html = "";
     switch ($this->_freq) {
         case 'WEEKLY':
             if ($this->_interval > 1) {
                 $html .= sprintf(\GO::t('repeats_at_not_every'), $this->_interval, \GO::t('weeks'), $daysStr);
             } else {
                 $html .= sprintf(\GO::t('repeats_at'), \GO::t('week'), $daysStr);
             }
             break;
         case 'DAILY':
             if ($this->_interval > 1) {
                 $html .= sprintf(\GO::t('repeats_at_not_every'), $this->_interval, \GO::t('days'));
             } else {
                 $html .= sprintf(\GO::t('repeats'), \GO::t('day'));
             }
             break;
         case 'MONTHLY':
             if (!$this->_byday) {
                 if ($this->_interval > 1) {
                     $html .= sprintf(\GO::t('repeats_at_not_every'), $this->_interval, \GO::t('months'));
                 } else {
                     $html .= sprintf(\GO::t('repeats'), \GO::t('month'));
                 }
             } else {
                 $bySetPositions = \GO::t('month_times');
                 if (count($days) == 1) {
                     $daysStr = $bySetPositions[$this->_bysetpos] . ' ' . $days[0];
                 } else {
                     $daysStr = ' ' . \GO::t('and') . ' ' . array_pop($days);
                     $daysStr = $bySetPositions[$this->_bysetpos] . ' ' . implode(', ', $days) . $daysStr;
                 }
                 if ($this->_interval > 1) {
                     $html .= sprintf(\GO::t('repeats_at_not_every'), $this->_interval, \GO::t('months'), $daysStr);
                 } else {
                     $html .= sprintf(\GO::t('repeats_at'), \GO::t('month'), $daysStr);
                 }
             }
             break;
         case 'YEARLY':
             if ($this->_interval > 1) {
                 $html .= sprintf(\GO::t('repeats_at_not_every'), $this->_interval, \GO::t('years'));
             } else {
                 $html .= sprintf(\GO::t('repeats'), \GO::t('year'));
             }
             break;
     }
     if ($this->until) {
         $html .= ' ' . \GO::t('until') . ' ' . \GO\Base\Util\Date::get_timestamp($this->until, false);
     }
     return $html;
 }
Esempio n. 26
0
 private function _processEventsDisplay($model, $response)
 {
     $startOfDay = \GO\Base\Util\Date::clear_time(time());
     $findParams = \GO\Base\Db\FindParams::newInstance()->order('start_time', 'DESC');
     $findParams->getCriteria()->addCondition('start_time', $startOfDay, '>=');
     $stmt = \GO\Calendar\Model\Event::model()->findLinks($model, $findParams);
     $store = \GO\Base\Data\Store::newInstance(\GO\Calendar\Model\Event::model());
     $store->setStatement($stmt);
     $columnModel = $store->getColumnModel();
     $columnModel->formatColumn('calendar_name', '$model->calendar->name');
     $columnModel->formatColumn('link_count', '$model->countLinks()');
     $columnModel->formatColumn('link_description', '$model->link_description');
     $data = $store->getData();
     $response['data']['events'] = $data['results'];
     return $response;
 }
Esempio n. 27
0
 public function formatAttribute($attributeName, $value, $html = false)
 {
     if (!isset($this->columns[$attributeName]['gotype'])) {
         if ($this->customfieldsModel() && substr($attributeName, 0, 4) == 'col_') {
             //if it's a custom field then we create a dummy customfields model.
             $cfModel = $this->_createCustomFieldsRecordFromAttributes();
             //	debug_print_backtrace();
             return $cfModel->formatAttribute($attributeName, $value, $html);
         } else {
             return $value;
         }
     }
     switch ($this->columns[$attributeName]['gotype']) {
         case 'unixdate':
             return \GO\Base\Util\Date::get_timestamp($value, false);
             break;
         case 'unixtimestamp':
             return \GO\Base\Util\Date::get_timestamp($value);
             break;
         case 'textarea':
             if ($html) {
                 return \GO\Base\Util\String::text_to_html($value);
             } else {
                 return $value;
             }
             break;
         case 'date':
             //strtotime hangs a while on parsing 0000-00-00 from the database. There shouldn't be such a date in it but
             //the old system stored dates like this.
             if ($value == "0000-00-00" || empty($value)) {
                 return "";
             }
             $date = new \DateTime($value);
             return $date->format(GO::user() ? GO::user()->completeDateFormat : GO::config()->getCompleteDateFormat());
             //return $value != '0000-00-00' ? \GO\Base\Util\Date::get_timestamp(strtotime($value),false) : '';
             break;
         case 'number':
             $decimals = isset($this->columns[$attributeName]['decimals']) ? $this->columns[$attributeName]['decimals'] : 2;
             return \GO\Base\Util\Number::localize($value, $decimals);
             break;
         case 'boolean':
             //				Formatting as yes no breaks many functions
             //				if($html)
             //					return !empty($value) ? GO::t('yes') : GO::t('no');
             //				else
             return !empty($value);
             break;
         case 'html':
             return $value;
             break;
         case 'phone':
             if ($html) {
                 if (!preg_match('/[a-z]+/i', $value)) {
                     if (preg_match('/^(\\+\\d{2})(\\d{2})(\\d{3})(\\d{4})$/', $value, $matches)) {
                         return $matches[1] . ' ' . $matches[2] . ' ' . $matches[3] . ' ' . $matches[4];
                     } elseif (preg_match('/^(\\d*)(\\d{3})(\\d{4})$/', $value, $matches)) {
                         return '(' . $matches[1] . ') ' . $matches[2] . ' ' . $matches[3];
                     }
                 }
             }
             return $value;
             break;
         default:
             if (substr($this->columns[$attributeName]['dbtype'], -3) == 'int') {
                 return $value;
             } else {
                 return $html ? htmlspecialchars($value, ENT_COMPAT, 'UTF-8') : $value;
             }
             break;
     }
 }
Esempio n. 28
0
 private function _sendmail($message, $model, $mailer, $mailing)
 {
     $typestring = $model instanceof \GO\Addressbook\Model\Company ? 'company' : 'contact';
     if ($typestring == 'contact') {
         $email = $model->firstEmail;
     } else {
         $email = $model->email;
     }
     echo '[' . \GO\Base\Util\Date::get_timestamp(time()) . "] Sending to " . $typestring . " id: " . $model->id . " email: " . $email . "\n";
     if ($typestring == 'contact') {
         $sentMailModel = \GO\Addressbook\Model\SentMailingContact::model()->findSingleByAttributes(array('sent_mailing_id' => $mailing->id, 'contact_id' => $model->id));
     } else {
         $sentMailModel = \GO\Addressbook\Model\SentMailingCompany::model()->findSingleByAttributes(array('sent_mailing_id' => $mailing->id, 'company_id' => $model->id));
     }
     $mailing = \GO\Addressbook\Model\SentMailing::model()->findByPk($mailing->id, array(), true, true);
     if ($mailing->status == \GO\Addressbook\Model\SentMailing::STATUS_PAUSED) {
         echo "Mailing paused by user. Exiting.";
         exit;
     }
     try {
         if (in_array($email, $this->_sentEmails)) {
             echo "Skipping because this e-mail address already got an e-mail\n";
         } elseif ($this->dry) {
             echo "Not sending because dry is true\n";
         } else {
             $this->fireEvent('beforeMessageSend', array(&$message, $model, $mailing));
             $this->_sentEmails[] = $email;
             $mailer->send($message);
         }
     } catch (\Exception $e) {
         $status = $e->getMessage();
     }
     if (!empty($status)) {
         $errorMsg = "---------\n" . "Failed at " . \GO\Base\Util\Date::get_timestamp(time()) . "\n" . $status . "\n" . "---------\n";
         echo $errorMsg;
         //			$mailing->errors++;
         $sentMailModel->has_error = true;
         $sentMailModel->error_description = $errorMsg;
         $this->smtpFailCount++;
         if ($this->smtpFailCount == 3) {
             echo "Pausing mailing because there were 3 send errors in a row\n";
             $mailing->status = \GO\Addressbook\Model\SentMailing::STATUS_PAUSED;
             $mailing->save();
             exit;
         }
         unset($status);
     } else {
         $sentMailModel->sent = true;
         //			$mailing->sent++;
         $this->smtpFailCount = 0;
     }
     $sentMailModel->save();
     //		$mailing->save();
     //		if ($typestring == 'contact') {
     //			$mailing->removeManyMany('contacts', $model->id);
     //		} else {
     //			$mailing->removeManyMany('companies', $model->id);
     //		}
 }
Esempio n. 29
0
 protected function actionCreateEvents($params)
 {
     $now = \GO\Base\Util\Date::clear_time(time());
     for ($i = 0; $i < 30; $i++) {
         $time = \GO\Base\Util\Date::date_add($now, -$i);
         for ($n = 0; $n < 10; $n++) {
             $event = new \GO\Calendar\Model\Event();
             $event->name = 'test ' . $n;
             $event->description = str_repeat('All work and no play, makes Jack a dull boy. ', 100);
             $event->start_time = \GO\Base\Util\Date::date_add($time, 0, 0, 0, $n + 7);
             $event->end_time = \GO\Base\Util\Date::date_add($time, 0, 0, 0, $n + 8);
             $event->save();
         }
     }
 }
Esempio n. 30
0
 /**
  * Creates a Rrule response which can be merged with a normal JSON response.
  * 
  * @return array Rrule 
  */
 public function createJSONOutput()
 {
     $this->shiftDays(false);
     $days = $this->_byday;
     $response = array();
     if (isset($this->_freq)) {
         if (!empty($this->_until)) {
             $response['until'] = \GO\Base\Util\Date::get_timestamp($this->_until, false);
             $response['repeat_forever'] = 0;
         } else {
             $response['repeat_forever'] = 1;
         }
         $response['interval'] = $this->_interval;
         $response['freq'] = $this->_freq;
         switch ($this->_freq) {
             case 'WEEKLY':
                 foreach ($days as $day) {
                     $response[$day] = 1;
                 }
                 break;
             case 'MONTHLY':
                 $response['bysetpos'] = $this->bysetpos;
                 if (!empty($days)) {
                     foreach ($days as $day) {
                         $response[$day] = 1;
                     }
                 }
                 if ($this->bysetpos == 0) {
                     $response['freq'] = 'MONTHLY_DATE';
                 }
                 break;
         }
     }
     return $response;
 }