Exemplo n.º 1
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();
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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');
 }
Exemplo n.º 5
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;
     }
 }
Exemplo n.º 6
0
 public function getAttributes($formatted = false)
 {
     if (!$formatted) {
         return $this->attributes;
     }
     $attributes = $this->attributes;
     $from = $this->from->getAddress();
     $attributes['from'] = $from["personal"];
     $attributes['sender'] = $from["email"];
     $attributes['to'] = (string) $this->to;
     $attributes['cc'] = (string) $this->cc;
     $attributes['bcc'] = (string) $this->bcc;
     $attributes['reply_to'] = (string) $this->reply_to;
     //		$dayStart = mktime(0,0,0);
     //$dayEnd = mktime(0,0,0,date('m'),date('d')+1);
     //		if($this->udate<$dayStart)
     $attributes["date"] = \GO\Base\Util\Date::get_timestamp($this->udate, false);
     //		else
     $attributes["date_time"] = date(\GO::user()->time_format, $this->udate);
     //		if($this->internal_udate<$dayStart)
     $attributes["arrival"] = \GO\Base\Util\Date::get_timestamp($this->internal_udate, false);
     //		else
     $attributes["arrival_time"] = date(\GO::user()->time_format, $this->internal_udate);
     return $attributes;
 }
Exemplo n.º 7
0
 /**
  * Import an event from a VObject 
  * 
  * @param Sabre\VObject\Component $vobject
  * @param array $attributes Extra attributes to apply to the event. Raw values should be past. No input formatting is applied.
  * @param boolean $dontSave. Don't save the event. WARNING. Event can't be fully imported this way because participants and exceptions need an ID. This option is useful if you want to display info about an ICS file.
  * @param boolean $importExternal This should be switched on if importing happens from external ICS calendar.
  * @return Event 
  */
 public function importVObject(Sabre\VObject\Component $vobject, $attributes = array(), $dontSave = false, $makeSureUserParticipantExists = false, $importExternal = false)
 {
     $uid = (string) $vobject->uid;
     if (!empty($uid)) {
         $this->uuid = $uid;
     }
     $this->name = (string) $vobject->summary;
     if (empty($this->name)) {
         $this->name = \GO::t('unnamed');
     }
     $dtstart = $vobject->dtstart ? $vobject->dtstart->getDateTime() : new \DateTime();
     $dtend = $vobject->dtend ? $vobject->dtend->getDateTime() : new \DateTime();
     $substractOnEnd = 0;
     //funambol sends this special parameter
     //		if((string) $vobject->{"X-FUNAMBOL-ALLDAY"}=="1"){
     //			$this->all_day_event=1;
     //		}else
     //		{
     $this->all_day_event = isset($vobject->dtstart['VALUE']) && $vobject->dtstart['VALUE'] == 'DATE' ? 1 : 0;
     //ios sends start and end date at 00:00 hour
     //DTEND;TZID=Europe/Amsterdam:20140121T000000
     //DTSTART;TZID=Europe/Amsterdam:20140120T000000
     if ($dtstart->format('Hi') == "0000" && $dtend->format('Hi') == "0000") {
         $this->all_day_event = true;
         $substractOnEnd = 60;
     }
     //		}
     if ($this->all_day_event) {
         if ($dtstart->getTimezone()->getName() == 'UTC') {
             $this->_utcToLocal($dtstart);
         }
         if ($dtend->getTimezone()->getName() == 'UTC') {
             $this->_utcToLocal($dtend);
         }
     }
     $this->start_time = intval($dtstart->format('U'));
     $this->end_time = intval($dtend->format('U')) - $substractOnEnd;
     if ($vobject->duration) {
         $duration = \GO\Base\VObject\Reader::parseDuration($vobject->duration);
         $this->end_time = $this->start_time + $duration;
     }
     if ($this->end_time <= $this->start_time) {
         $this->end_time = $this->start_time + 3600;
     }
     if ($vobject->description) {
         $this->description = (string) $vobject->description;
     }
     if ((string) $vobject->rrule != "") {
         $rrule = new \GO\Base\Util\Icalendar\Rrule();
         $rrule->readIcalendarRruleString($this->start_time, (string) $vobject->rrule);
         $rrule->shiftDays(true);
         $this->rrule = $rrule->createRrule();
         $this->repeat_end_time = $rrule->until;
     } else {
         $this->rrule = "";
         $this->repeat_end_time = 0;
     }
     if ($vobject->{"last-modified"}) {
         $this->mtime = intval($vobject->{"last-modified"}->getDateTime()->format('U'));
     }
     if ($vobject->location) {
         $this->location = (string) $vobject->location;
     }
     //var_dump($vobject->status);
     if ($vobject->status) {
         $status = (string) $vobject->status;
         if ($this->isValidStatus($status)) {
             $this->status = $status;
         }
     }
     if (isset($vobject->class)) {
         $this->private = strtoupper($vobject->class) != 'PUBLIC';
     }
     $this->reminder = 0;
     //		if($vobject->valarm && $vobject->valarm->trigger){
     //
     //			$type = (string) $vobject->valarm->trigger["value"];
     //
     //
     //			if($type == "DURATION") {
     //				$duration = \GO\Base\VObject\Reader::parseDuration($vobject->valarm->trigger);
     //				if($duration>0){
     //					$this->reminder = $duration*-1;
     //				}
     //			}else
     //			{
     //				\GO::debug("WARNING: Ignoring unsupported reminder value of type: ".$type);
     //			}
     //
     if ($vobject->valarm && $vobject->valarm->trigger) {
         $date = $vobject->valarm->getEffectiveTriggerTime();
         if ($date) {
             if ($this->all_day_event) {
                 $this->_utcToLocal($date);
             }
             $this->reminder = $this->start_time - $date->format('U');
         }
     } elseif ($vobject->aalarm) {
         //funambol sends old vcalendar 1.0 format
         $aalarm = explode(';', (string) $vobject->aalarm);
         if (!empty($aalarm[0])) {
             $p = Sabre\VObject\DateTimeParser::parse($aalarm[0]);
             $this->reminder = $this->start_time - $p->format('U');
         }
     }
     $this->setAttributes($attributes, false);
     $recurrenceIds = $vobject->select('recurrence-id');
     if (count($recurrenceIds)) {
         //this is a single instance of a recurring series.
         //attempt to find the exception of the recurring series event by uuid
         //and recurrence time so we can set the relation cal_exceptions.exception_event_id=cal_events.id
         $firstMatch = array_shift($recurrenceIds);
         $recurrenceTime = $firstMatch->getDateTime()->format('U');
         $whereCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('calendar_id', $this->calendar_id, '=', 'ev')->addCondition('uuid', $this->uuid, '=', 'ev')->addCondition('time', $recurrenceTime, '=', 't');
         $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('event_id', 'ev.id', '=', 't', true, true);
         $findParams = \GO\Base\Db\FindParams::newInstance()->single()->criteria($whereCriteria)->join(Event::model()->tableName(), $joinCriteria, 'ev');
         $exception = Exception::model()->find($findParams);
         if ($exception) {
             $this->exception_for_event_id = $exception->event_id;
             if (empty($this->name) || $this->name == \GO::t('unnamed')) {
                 $this->name = $exception->mainevent->name;
             }
         } else {
             //exception was not found for this recurrence. Find the recurring series and add the exception.
             $recurringEvent = Event::model()->findByUuid($this->uuid, 0, $this->calendar_id);
             if ($recurringEvent) {
                 \GO::debug("Creating MISSING exception for " . date('c', $recurrenceTime));
                 //aftersave will create Exception
                 $this->exception_for_event_id = $recurringEvent->id;
                 //will be saved later
                 $exception = new Exception();
                 $exception->time = $recurrenceTime;
                 $exception->event_id = $recurringEvent->id;
                 if (empty($this->name) || $this->name == \GO::t('unnamed')) {
                     $this->name = $exception->mainevent->name;
                 }
             } else {
                 //ignore this because the invited participant might not be invited to the series
                 //throw new \Exception("Could not find master event!");
                 //hack to make it be seen as an exception
                 $this->exception_for_event_id = -1;
             }
         }
     }
     if ($vobject->valarm && $vobject->valarm->trigger) {
         $reminderTime = $vobject->valarm->getEffectiveTriggerTime();
         //echo $reminderTime->format('c');
         if ($this->all_day_event) {
             $this->_utcToLocal($reminderTime);
         }
         $seconds = $reminderTime->format('U');
         $this->reminder = $this->start_time - $seconds;
         if ($this->reminder < 0) {
             $this->reminder = 0;
         }
     }
     $cats = (string) $vobject->categories;
     if (!empty($cats)) {
         //Group-Office only supports a single category.
         $cats = explode(',', $cats);
         $categoryName = array_shift($cats);
         $category = Category::model()->findByName($this->calendar_id, $categoryName);
         if (!$category && !$dontSave && $this->calendar_id) {
             $category = new Category();
             $category->name = $categoryName;
             $category->calendar_id = $this->calendar_id;
             $category->save(true);
         }
         if ($category) {
             $this->category_id = $category->id;
             $this->background = $category->color;
         }
     }
     //set is_organizer flag
     if ($vobject->organizer && $this->calendar) {
         $organizerEmail = str_replace('mailto:', '', strtolower((string) $vobject->organizer));
         $this->is_organizer = $organizerEmail == $this->calendar->user->email;
     }
     if (!$dontSave) {
         $this->cutAttributeLengths();
         //			try {
         $this->_isImport = true;
         if (!$importExternal) {
             $this->setValidationRule('uuid', 'unique', array('calendar_id', 'start_time', 'exception_for_event_id'));
         }
         //				//make sure no duplicates are imported
         //				if(!is_array($previouslyImportedEventsArray)){
         //					// We do not take events from previous import iterations into account, and we will do a validation check.
         //					$this->setValidationRule('uuid', 'unique', array('calendar_id','start_time'));
         //				}else
         //				{
         //
         //					// We take into account the history if imported items to better handle recurring events, exceptions and rescheduled events.
         //
         //					if (!empty($this->rrule)) {
         //
         //						\GO::debug('=== ['.\GO\Base\Util\Date::get_timestamp($this->start_time).'] '.$this->name.' (with rrule)');
         //
         //						// Handle imported recurring event.
         //
         //						$existingEventModel = Event::model()->find(
         //							\GO\Base\Db\FindParams::newInstance()
         //								->single()
         //								->criteria(\GO\Base\Db\FindCriteria::newInstance()
         //									->addCondition('calendar_id',$this->calendar_id)
         //									->addCondition('uuid',$this->uuid)
         //									->addCondition('rrule','','!=')
         //								)
         //						);
         //
         //						if (!empty($existingEventModel)) {
         //							// Update the existing recurring event in the calendar.
         //							$this->id = $existingEventModel->id;
         //							$this->setIsNew(false);
         //						}
         //
         //					} else {
         //
         //						\GO::debug('=== ['.\GO\Base\Util\Date::get_timestamp($this->start_time).'] '.$this->name);
         //
         //						// Handle imported non-recurring event or exception event.
         //
         //						$existingEventsStmt = Event::model()->find(
         //							\GO\Base\Db\FindParams::newInstance()
         //								->criteria(\GO\Base\Db\FindCriteria::newInstance()
         //									->addCondition('calendar_id',$this->calendar_id)
         //									->addCondition('uuid',$this->uuid)
         //									->addCondition('rrule','','=')
         //								)
         //						);
         //
         //						foreach ($existingEventsStmt as $existingEventModel) {
         //							if ($existingEventModel && !self::eventIsFromCurrentImport($existingEventModel,$previouslyImportedEventsArray)) {
         //								// The existing event model in the database was previously imported during the current import process.
         //
         //								// We rightfully assume here that the latest version of this event will be saved in Group-Office as a new event later in this function.
         //								$existingEventModel->delete();
         //							}
         //						}
         //
         //					}
         //				}
         if (!$this->save()) {
             if ($importExternal) {
                 $installationName = !empty(\GO::config()->title) ? \GO::config()->title : 'Group-Office';
                 $validationErrStr = implode("\n", $this->getValidationErrors()) . "\n";
                 $mailSubject = str_replace(array('%cal', '%event'), array($this->calendar->name, $this->name), \GO::t('eventNotSavedSubject', 'calendar'));
                 $body = \GO::t('eventNotSavedBody', 'calendar');
                 $body = str_replace(array('%goname', '%event', '%starttime', '%cal', '%errormessage'), array($installationName, $this->name, \GO\Base\Util\Date::get_timestamp($this->start_time), $this->calendar->name, $validationErrStr), $body);
                 $message = \GO\Base\Mail\Message::newInstance($mailSubject)->setFrom(\GO::config()->webmaster_email, \GO::config()->title)->addTo($this->calendar->user->email);
                 $message->setHtmlAlternateBody(nl2br($body));
                 if (\GO\Base\Mail\Mailer::newGoInstance()->send($message)) {
                     throw new \GO\Base\Exception\Validation('DUE TO ERROR, CRON SENT MAIL TO: ' . $this->calendar->user->email . '. THIS IS THE EMAIL MESSAGE:' . "\r\n" . $body);
                 } else {
                     throw new \GO\Base\Exception\Validation('CRON COULD NOT SEND EMAIL WITH ERROR MESSAGE TO: ' . $this->calendar->user->email . '. THIS IS THE EMAIL MESSAGE:' . "\r\n" . $body);
                 }
             } else {
                 throw new \GO\Base\Exception\Validation(implode("\n", $this->getValidationErrors()) . "\n");
             }
         }
         $this->_isImport = false;
         //			} catch (\Exception $e) {
         //				throw new \Exception($this->name.' ['.\GO\Base\Util\Date::get_timestamp($this->start_time).' - '.\GO\Base\Util\Date::get_timestamp($this->end_time).'] '.$e->getMessage());
         //			}
         if (!empty($exception)) {
             //save the exception we found by recurrence-id
             $exception->exception_event_id = $this->id;
             $exception->save();
             \GO::debug("saved exception");
         }
         //			$test = (bool) $vobject->organizer;
         //			var_dump($test);
         //			exit();
         //
         if ($vobject->organizer) {
             $p = $this->importVObjectAttendee($this, $vobject->organizer, true);
         } else {
             $p = false;
         }
         $calendarParticipantFound = !empty($p) && $p->user_id == $this->calendar->user_id;
         $attendees = $vobject->select('attendee');
         foreach ($attendees as $attendee) {
             $p = $this->importVObjectAttendee($this, $attendee, false);
             if ($p->user_id == $this->calendar->user_id) {
                 $calendarParticipantFound = true;
             }
         }
         //if the calendar owner is not in the participants then we should chnage the is_organizer flag because otherwise the event can't be opened or accepted.
         if (!$calendarParticipantFound) {
             if ($makeSureUserParticipantExists) {
                 $participant = \GO\Calendar\Model\Participant::model()->findSingleByAttributes(array('event_id' => $this->id, 'email' => $this->calendar->user->email));
                 if (!$participant) {
                     //this is a bad situation. The import thould have detected a user for one of the participants.
                     //It uses the E-mail account aliases to determine a user. See GO_Calendar_Model_Event::importVObject
                     $participant = new \GO\Calendar\Model\Participant();
                     $participant->event_id = $this->id;
                     $participant->user_id = $this->calendar->user_id;
                     $participant->email = $this->calendar->user->email;
                 } else {
                     $participant->user_id = $this->calendar->user_id;
                 }
                 $participant->save();
             } else {
                 $this->is_organizer = true;
                 $this->save();
             }
         }
         //Add exception dates to Event
         foreach ($vobject->select('EXDATE') as $i => $exdate) {
             try {
                 $dts = $exdate->getDateTimes();
                 if ($dts === null) {
                     continue;
                 }
                 foreach ($dts as $dt) {
                     $this->addException($dt->format('U'));
                 }
             } catch (Exception $e) {
                 trigger_error($e->getMessage(), E_USER_NOTICE);
             }
         }
         if ($importExternal && $this->isRecurring()) {
             $exceptionEventsStmt = Event::model()->find(\GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('calendar_id', $this->calendar_id)->addCondition('uuid', $this->uuid)->addCondition('rrule', '', '=')));
             foreach ($exceptionEventsStmt as $exceptionEventModel) {
                 $exceptionEventModel->exception_for_event_id = $this->id;
                 $exceptionEventModel->save();
                 //TODO: This method only works when an exception takes place on the same day as the original occurence.
                 //We should store the RECURRENCE-ID value so we can find it later.
                 $this->addException($exceptionEventModel->start_time, $exceptionEventModel->id);
                 //					\GO::debug('=== EXCEPTION EVENT === ['.\GO\Base\Util\Date::get_timestamp($exceptionEventModel->start_time).'] '.$exceptionEventModel->name.' (\Exception for event: '.$exceptionEventModel->exception_for_event_id.')');
             }
         }
     }
     return $this;
 }
Exemplo n.º 8
0
 /**
  * get a pdf of a count of all categories
  * 
  * @param array $params
  * @return PDF file 
  */
 public function actionPrintCategoryCount($params)
 {
     \GO::session()->closeWriting();
     // If a year is posted then determine the correct start and end date and set them here
     if (isset($params['fullYear'])) {
         $params['startDate'] = '';
         // TODO: Find this
         $params['endDate'] = '';
         // TODO: Find this
     }
     if (isset($params['startDate'])) {
         $startDate = $params['startDate'];
     } else {
         $startDate = \GO\Base\Util\Date::date_add(time(), -14);
         // - (2 * 7 * 24 * 60 * 60); // -2weken
         $startDate = \GO\Base\Util\Date::get_timestamp($startDate, false);
     }
     if (isset($params['endDate'])) {
         $endDate = $params['endDate'];
     } else {
         $endDate = time();
         $endDate = \GO\Base\Util\Date::get_timestamp($endDate, false);
     }
     $categoryCountModel = new \GO\Calendar\Model\PrintCategoryCount($startDate, $endDate);
     //		//Set the PDF filename
     $filename = \GO::t('eventsPerCategoryCount', 'calendar') . '.pdf';
     //
     //		// Start building the PDF file
     $pdf = new \GO\Calendar\Reports\PrintCategoryCount($orientation = 'L');
     $pdf->setTitle(\GO::t('eventsPerCategoryCount', 'calendar'));
     //$pdf->setSubTitle($startDate.' '.\GO::t('till','calendar').' '.$endDate);
     $pdf->render($categoryCountModel);
     return $pdf->Output($filename, 'D');
 }
Exemplo n.º 9
0
 protected function actionSource($params)
 {
     $account = Account::model()->findByPk($params['account_id']);
     $imap = $account->openImapConnection($params['mailbox']);
     //$filename = empty($params['download']) ? "message.txt" :"message.eml";
     $message = \GO\Email\Model\ImapMessage::model()->findByUid($account, $params['mailbox'], $params['uid']);
     $filename = GO\Base\Fs\File::stripInvalidChars($message->subject . ' - ' . \GO\Base\Util\Date::get_timestamp($message->udate));
     $filename .= empty($params['download']) ? ".txt" : ".eml";
     \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\Fs\File($filename), empty($params['download']));
     /*
      * Somehow fetching a message with an empty message part which should fetch it
      * all doesn't work. (http://tools.ietf.org/html/rfc3501#section-6.4.5)
      *
      * That's why I first fetch the header and then the text.
      */
     $header = $imap->get_message_part($params['uid'], 'HEADER', true) . "\r\n\r\n";
     $size = $imap->get_message_part_start($params['uid'], 'TEXT', true);
     header('Content-Length: ' . (strlen($header) + $size));
     echo $header;
     while ($line = $imap->get_message_part_line()) {
         echo $line;
     }
 }
Exemplo n.º 10
0
 public function formatDisplay($key, &$attributes, \GO\Customfields\Model\AbstractCustomFieldsRecord $model)
 {
     return \GO\Base\Util\Date::get_timestamp(strtotime($attributes[$key]), true);
 }
Exemplo n.º 11
0
 protected function actionExportEventAsIcs($event_id)
 {
     $eventModel = \GO\Calendar\Model\Event::model()->findByPk($event_id);
     if (!$eventModel) {
         throw new Exception('Could not find event with ID #' . $event_id . '.');
     }
     if ($eventModel->exception_for_event_id > 0) {
         $eventModel = \GO\Calendar\Model\Event::model()->findByPk($eventModel->exception_for_event_id);
     }
     if (!$eventModel) {
         throw new Exception('Could not find main recurring event of event #' . $event_id . '.');
     }
     \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\FS\File($eventModel->calendar->name . ' - ' . \GO\Base\Util\Date::get_timestamp($eventModel->start_time) . ' ' . $eventModel->name . '.ics'));
     echo "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();
     echo $t->serialize();
     $v = $eventModel->toVObject();
     echo $v->serialize();
     $exceptionsStmt = \GO\Calendar\Model\Event::model()->findByAttributes(array('calendar_id' => $eventModel->calendar_id, 'exception_for_event_id' => $eventModel->id));
     foreach ($exceptionsStmt as $exceptionEventModel) {
         $vexc = $exceptionEventModel->toVObject();
         echo $vexc->serialize();
     }
     echo "END:VCALENDAR\r\n";
 }
Exemplo n.º 12
0
 public function getResponseData()
 {
     $dayString = \GO::t('full_days');
     $response = $this->_event->getAttributes('html');
     if ($this->isAllDay()) {
         $response['time'] = $this->getFormattedTime();
     } else {
         if (date(\GO::user()->date_format, $this->getAlternateStartTime()) != date(\GO::user()->date_format, $this->getAlternateEndTime())) {
             $response['time'] = $this->getFormattedTime();
         } else {
             $response['time'] = $this->getFormattedTime();
         }
     }
     //		$response['time_of_day'] = $this->getTimeOfDay();
     $response['status'] = $this->_event->status;
     $response['username'] = $this->_event->user ? $this->_event->user->getName() : \GO::t('unknown') . ' ' . \GO::t('user');
     $response['musername'] = !empty($this->_event->mUser) ? $this->_event->mUser->getName() : '';
     //		if($this->_event->status==Event::STATUS_CANCELLED){
     //			$response['name'] .= ' ('.$this->_event->localizedStatus.')';
     //		}
     //
     if ($this->_isMerged) {
         $response['name'] = $response['name'] . ' (' . implode(',', $this->_initials) . ')';
         $response['calendar_name'] = implode('; ', $this->_calendarNames);
         unset($response['status']);
         // unset this, it is not relevant to show this in merge view
         unset($response['username']);
         // unset this, it is not relevant to show this in merge view.
     } else {
         $response['calendar_name'] = $this->_calendarNames[0];
     }
     $response['id'] = $this->_event->id . ':' . $this->getAlternateStartTime();
     // a unique id for the data store. Is not really used.
     $response['background'] = $this->_backgroundColor;
     $response['start_time'] = date('Y-m-d H:i', $this->getAlternateStartTime());
     $response['end_time'] = date('Y-m-d H:i', $this->getAlternateEndTime());
     $response['ctime'] = date('Y-m-d H:i', $this->_event->ctime);
     $response['mtime'] = date('Y-m-d H:i', $this->_event->mtime);
     $response['event_id'] = $this->_event->id;
     $response['description'] = nl2br(htmlspecialchars(\GO\Base\Util\String::cut_string($this->_event->description, 800), ENT_COMPAT, 'UTF-8'));
     $response['private'] = $this->isPrivate();
     $response['private_enabled'] = $this->_event->private;
     $response['resources'] = array();
     if ($response['private']) {
         $response['name'] = \GO::t('private', 'calendar');
         $response['description'] = "";
         $response['location'] = "";
         $response['repeats'] = false;
         $response['has_reminder'] = false;
         $response['link_count'] = false;
         $response['status_color'] = false;
         $response['status'] = false;
     } else {
         $response['repeats'] = $this->isRepeating();
         $response['has_reminder'] = $response['reminder'] > 0 ? 1 : 0;
         $response['link_count'] = $this->getLinkCount();
         $response['status_color'] = $this->_event->getStatusColor();
         if ($this->_event->resources) {
             foreach ($this->_event->resources as $resourceModel) {
                 $response['resources'][$resourceModel->id] = $resourceModel->calendar->name;
             }
         }
     }
     $response['permission_level'] = $this->_event->permissionLevel;
     $response['all_day_event'] = $this->isAllDay();
     $response['day'] = $dayString[date('w', $this->getAlternateStartTime())] . ' ' . \GO\Base\Util\Date::get_timestamp($this->getAlternateStartTime(), false);
     // date(implode(\GO::user()->date_separator,str_split(\GO::user()->date_format,1)), ($eventModel->start_time));
     $response['read_only'] = $this->isReadOnly();
     $response['model_name'] = $this->_event->className();
     $response['partstatus'] = "none";
     if (isset($response['status']) && $response['status'] == Event::STATUS_CANCELLED) {
         //hack to make it transparent on cancelled status too in the view.
         $response['partstatus'] = Participant::STATUS_DECLINED;
     } else {
         if ($participant = $this->_event->getParticipantOfCalendar()) {
             $response['partstatus'] = $participant->status;
         }
     }
     $duration = $this->getDurationInMinutes();
     if ($duration >= 60) {
         $durationHours = floor($duration / 60);
         $durationRestMinutes = $duration % 60;
         $response['duration'] = $durationHours . ' ' . \GO::t('hours') . ', ' . $durationRestMinutes . ' ' . \GO::t('mins');
     } else {
         $response['duration'] = $duration . 'm';
     }
     return $response;
 }
Exemplo n.º 13
0
 public function actionVerify($params)
 {
     $response['success'] = true;
     $params['email'] = strtolower($params['email']);
     //if file was already stored somewhere after decryption
     if (!empty($params['cert_id'])) {
         $cert = \GO\Smime\Model\PublicCertificate::model()->findByPk($params['cert_id']);
         $certData = $cert->cert;
     } else {
         //			if (!empty($params['filepath'])) {
         //				$srcFile = new \GO\Base\Fs\File(\GO::config()->tmpdir.$params['filepath']);
         if (!empty($params['account_id'])) {
             $account = \GO\Email\Model\Account::model()->findByPk($params['account_id']);
             $imapMessage = \GO\Email\Model\ImapMessage::model()->findByUid($account, $params['mailbox'], $params['uid']);
             $srcFile = \GO\Base\Fs\File::tempFile();
             if (!$imapMessage->saveToFile($srcFile->path())) {
                 throw new \Exception("Could not fetch message from IMAP server");
             }
             $this->_decryptFile($srcFile, $account);
         }
         //			throw new \Exception($srcFile->path());
         $pubCertFile = \GO\Base\Fs\File::tempFile();
         //Command line:
         //openssl smime -verify -in msg.txt
         $valid = openssl_pkcs7_verify($srcFile->path(), null, $pubCertFile->path(), $this->_getRootCertificates());
         //Adding the PKCS7_NOVERIFY flag was used for testing some messages that could not be verified by openssl but did in Mozilla thunderbird.
         //Error msg: error:21075075:PKCS7 routines:PKCS7_verify:certificate verify error
         //
         //			$valid = openssl_pkcs7_verify($srcFile->path(), PKCS7_NOVERIFY, $pubCertFile->path(), $this->_getRootCertificates());
         //			throw new \Exception($srcFile->path());
         $srcFile->delete();
         if ($valid) {
             if ($pubCertFile->exists()) {
                 $certData = $pubCertFile->getContents();
                 $arr = openssl_x509_parse($certData);
                 $senderEmailStr = !empty($arr['extensions']['subjectAltName']) ? $arr['extensions']['subjectAltName'] : $arr['subject']['emailAddress'];
                 $senderEmails = explode(',', $senderEmailStr);
                 $emails = array();
                 foreach ($senderEmails as $emailRaw) {
                     $email = strtolower(\GO\Base\Util\String::get_email_from_string($emailRaw));
                     if ($email) {
                         $emails[] = $email;
                     }
                 }
                 $pubCertFile->delete();
                 $this->_savePublicCertificate($certData, $emails);
             } else {
                 throw new \Exception('Certificate appears to be valid but could not get certificate from signature. SSL Error: ' . openssl_error_string());
             }
             if (empty($certData)) {
                 throw new \Exception('Certificate appears to be valid but could not get certificate from signature.');
             }
         }
     }
     if (!isset($arr) && isset($certData)) {
         $arr = openssl_x509_parse($certData);
         $senderEmailStr = !empty($arr['extensions']['subjectAltName']) ? $arr['extensions']['subjectAltName'] : $arr['subject']['emailAddress'];
         $emails = array();
         foreach ($senderEmails as $emailRaw) {
             $email = strtolower(\GO\Base\Util\String::get_email_from_string($emailRaw));
             if ($email) {
                 $emails[] = $email;
             }
         }
     } else {
         if (empty($emails)) {
             $emails = array('unknown');
         }
     }
     $response['html'] = '';
     $response['cls'] = '';
     $response['text'] = '';
     if (isset($params['account_id'])) {
         if (!$valid) {
             $response['cls'] = 'smi-invalid';
             $response['text'] = \GO::t('invalidCert', 'smime');
             $response['html'] .= '<h1 class="smi-invalid">' . \GO::t('invalidCert', 'smime') . '</h1>';
             $response['html'] .= '<p>';
             while ($msg = openssl_error_string()) {
                 $response['html'] .= $msg . "<br />\n";
             }
             $response['html'] .= '</p>';
         } else {
             if (!in_array($params['email'], $emails)) {
                 $response['cls'] = 'smi-certemailmismatch';
                 $response['text'] = \GO::t('certEmailMismatch', 'smime');
                 $response['html'] .= $response['short_html'] = '<h1 class="smi-certemailmismatch">' . \GO::t('certEmailMismatch', 'smime') . '</h1>';
             } else {
                 $response['cls'] = 'smi-valid';
                 $response['text'] = \GO::t('validCert', 'smime');
                 $response['html'] .= $response['short_html'] = '<h1 class="smi-valid">' . \GO::t('validCert', 'smime') . '</h1>';
             }
         }
     }
     if (!isset($params['account_id']) || $valid) {
         $response['html'] .= '<table>';
         $response['html'] .= '<tr><td width="100">' . \GO::t('name') . ':</td><td>' . $arr['name'] . '</td></tr>';
         $response['html'] .= '<tr><td width="100">' . \GO::t('email', 'smime') . ':</td><td>' . implode(', ', $emails) . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('hash', 'smime') . ':</td><td>' . $arr['hash'] . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('serial_number', 'smime') . ':</td><td>' . $arr['serialNumber'] . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('version', 'smime') . ':</td><td>' . $arr['version'] . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('issuer', 'smime') . ':</td><td>';
         foreach ($arr['issuer'] as $skey => $svalue) {
             if (is_array($svalue)) {
                 foreach ($svalue as $sv) {
                     $response['html'] .= $skey . ':' . $sv . '; ';
                 }
             } else {
                 $response['html'] .= $skey . ':' . $svalue . '; ';
             }
         }
         $response['html'] .= '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('valid_from', 'smime') . ':</td><td>' . \GO\Base\Util\Date::get_timestamp($arr['validFrom_time_t']) . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('valid_to', 'smime') . ':</td><td>' . \GO\Base\Util\Date::get_timestamp($arr['validTo_time_t']) . '</td></tr>';
         $response['html'] .= '</table>';
     }
     return $response;
 }
Exemplo n.º 14
0
 public function getActionDate()
 {
     return \GO\Base\Util\Date::get_timestamp($this->action_date, false);
 }
Exemplo n.º 15
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;
 }
Exemplo n.º 16
0
 public function getJson()
 {
     $dayString = \GO::t('full_days');
     return array('name' => htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8'), 'description' => '', 'time' => date(\GO::user()->time_format, strtotime($this->date)), 'all_day_event' => 1, 'start_time' => $this->date . ' 00:00', 'end_time' => $this->date . ' 23:59', 'background' => 'f1f1f1', 'model_name' => '', 'day' => $dayString[date('w', strtotime($this->date))] . ' ' . \GO\Base\Util\Date::get_timestamp(strtotime($this->date), false), 'read_only' => true, 'is_virtual' => true);
 }
Exemplo n.º 17
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);
     //		}
 }
Exemplo n.º 18
0
 /**
  * Returns MIME fields contained in this class's instance as an associative
  * array.
  *
  * @param boolean $html Whether or not to return the HTML body. The alternative is
  * plain text. Defaults to true.
  *
  * @return Array
  */
 public function toOutputArray($html = true, $recipientsAsString = false, $noMaxBodySize = false, $useHtmlSpecialChars = true)
 {
     $from = $this->from->getAddresses();
     $response['notification'] = $this->disposition_notification_to;
     //seen is expensive because it can't be recovered from cache.
     // We'll use the grid to check if a message was seen or not.
     //$response['seen']=$this->seen;
     $from = $this->from->getAddress();
     $response['seen'] = $this->seen;
     $response['forwarded'] = $this->forwarded;
     $response['flagged'] = $this->flagged;
     $response['answered'] = $this->answered;
     $response['from'] = $from['personal'];
     $response['sender'] = $from['email'];
     $response['to'] = $recipientsAsString ? (string) $this->to : $this->_convertRecipientArray($this->to->getAddresses());
     $response['cc'] = $recipientsAsString ? (string) $this->cc : $this->_convertRecipientArray($this->cc->getAddresses());
     $response['bcc'] = $recipientsAsString ? (string) $this->bcc : $this->_convertRecipientArray($this->bcc->getAddresses());
     $response['reply_to'] = (string) $this->reply_to;
     $response['message_id'] = $this->message_id;
     $response['date'] = $this->date;
     $response['to_string'] = (string) $this->to;
     if (!$recipientsAsString && empty($response['to'])) {
         $response['to'][] = array('email' => '', 'personal' => \GO::t('no_recipients', 'email'));
     }
     $response['full_from'] = (string) $this->from;
     $response['priority'] = intval($this->x_priority);
     $response['udate'] = $this->udate;
     $response['date'] = \GO\Base\Util\Date::get_timestamp($this->udate);
     $response['size'] = $this->size;
     $labels = array();
     if (property_exists($this, 'account')) {
         $labels = \GO\Email\Model\Label::model()->getAccountLabels($this->account->id);
     }
     $response['labels'] = array();
     if (!empty($this->labels)) {
         foreach ($this->labels as $label) {
             if (isset($labels[$label])) {
                 $response['labels'][] = array('name' => $labels[$label]->name, 'color' => $labels[$label]->color);
             }
         }
     }
     $response['attachments'] = array();
     $response['zip_of_attachments_url'] = $this->getZipOfAttachmentsUrl();
     $response['inlineAttachments'] = array();
     if ($html) {
         $response['htmlbody'] = $this->getHtmlBody(false, $noMaxBodySize);
     } else {
         $response['plainbody'] = $this->getPlainBody(false, $noMaxBodySize);
     }
     if ($useHtmlSpecialChars) {
         $response['subject'] = htmlspecialchars($this->subject, ENT_COMPAT, 'UTF-8');
     } else {
         $response['subject'] = $this->subject;
     }
     $response['body_truncated'] = $this->bodyIsTruncated();
     $response['smime_signed'] = isset($this->content_type_attributes['smime-type']) && $this->content_type_attributes['smime-type'] == 'signed-data';
     $attachments = $this->getAttachments();
     foreach ($attachments as $att) {
         if ($html && $att->disposition != 'attachment') {
             if ($att->mime == 'text/html') {
                 $htmlPartStr = $att->getData();
                 $htmlPartStr = \GO\Base\Util\String::convertLinks($htmlPartStr);
                 $htmlPartStr = \GO\Base\Util\String::sanitizeHtml($htmlPartStr);
                 $response['htmlbody'] .= '<hr />' . $htmlPartStr;
                 continue;
             } else {
                 if ($att->mime == 'text/plain') {
                     $htmlPartStr = $att->getData();
                     $htmlPartStr = \GO\Base\Util\String::text_to_html($htmlPartStr);
                     $response['htmlbody'] .= '<hr />' . $htmlPartStr;
                     continue;
                 }
             }
         }
         $replaceCount = 0;
         $a = $att->getAttributes();
         //add unique token for detecting precense of inline attachment when we submit the message in handleFormInput
         $a['token'] = md5($a['tmp_file']);
         $a['url'] .= '&amp;token=' . $a['token'];
         if ($html && !empty($a['content_id'])) {
             $response['htmlbody'] = str_replace('cid:' . $a['content_id'], $a['url'], $response['htmlbody'], $replaceCount);
         }
         if ($a['name'] == 'smime.p7s') {
             $response['smime_signed'] = true;
             continue;
         }
         if (!$replaceCount) {
             $response['attachments'][] = $a;
         } else {
             $response['inlineAttachments'][] = $a;
         }
     }
     $response['contact_name'] = "";
     $response['contact_thumb_url'] = GO::config()->host . 'modules/addressbook/themes/Default/images/unknown-person.png';
     $response['blocked_images'] = 0;
     $response['xssDetected'] = false;
     $this->fireEvent('tooutputarray', array(&$response, $this));
     return $response;
 }
Exemplo n.º 19
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;
 }
Exemplo n.º 20
0
 public function getJsonData()
 {
     $data = array('id' => $this->model_id, 'name' => $this->path, 'ctime' => \GO\Base\Util\Date::get_timestamp($this->ctime), 'mtime' => \GO\Base\Util\Date::get_timestamp($this->mtime), 'extension' => $this->extension, 'size' => $this->size, 'user_id' => $this->user_id, 'type' => $this->type, 'folder_id' => $this->folder_id, 'type_id' => 'f:' . $this->id, 'path' => $this->path, 'locked' => $this->isLocked(), 'locked_user_id' => $this->locked_user_id, 'unlock_allowed' => $this->unlockAllowed(), 'expire_time' => $this->expire_time > 0 ? \GO\Base\Util\Date::get_timestamp($this->expire_time, false) : '', 'thumbs' => 0, 'thumb_url' => $this->getThumbURL());
     if ($this->customfieldsRecord) {
         $data = array_merge($data, $this->customfieldsRecord->getAttributes('html'));
     }
     return $data;
 }
Exemplo 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);
 }
Exemplo n.º 22
0
 protected function afterDisplay(&$response, &$model, &$params)
 {
     $response['data']['name'] = $model->name;
     $response['data']['photo_url'] = $model->photoThumbURL;
     $response['data']['original_photo_url'] = $model->photoURL;
     $response['data']['addressbook_name'] = $model->addressbook->name;
     $company = $model->company();
     if ($company) {
         $response['data']['company_name'] = $company->name;
         $response['data']['company_name2'] = $company->name2;
         $response['data']['company_formatted_address'] = nl2br($company->getFormattedAddress());
         $response['data']['company_google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($company->address, $company->address_no, $company->city, $company->country);
         $response['data']['company_formatted_post_address'] = nl2br($company->getFormattedPostAddress());
         $response['data']['company_google_maps_post_link'] = \GO\Base\Util\Common::googleMapsLink($company->post_address, $company->post_address_no, $company->post_city, $company->post_country);
         $response['data']['company_email'] = $company->email;
         $response['data']['company_phone'] = $company->phone;
     } else {
         $response['data']['company_name'] = '';
         $response['data']['company_name2'] = '';
         $response['data']['company_formatted_address'] = '';
         $response['data']['company_google_maps_link'] = '';
         $response['data']['company_formatted_post_address'] = '';
         $response['data']['company_google_maps_post_link'] = '';
         $response['data']['company_email'] = '';
         $response['data']['company_phone'] = '';
     }
     $response['data']['google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($model->address, $model->address_no, $model->city, $model->country);
     $response['data']['formatted_address'] = nl2br($model->getFormattedAddress());
     $response['data']['action_date'] = \GO\Base\Util\Date::get_timestamp($model->action_date, false);
     if (\GO::modules()->customfields && isset($response['data']['customfields']) && \GO\Customfields\Model\DisableCategories::isEnabled("GO\\Addressbook\\Model\\Contact", $model->addressbook_id)) {
         $ids = \GO\Customfields\Model\EnabledCategory::model()->getEnabledIds("GO\\Addressbook\\Model\\Contact", $model->addressbook_id);
         $enabled = array();
         foreach ($response['data']['customfields'] as $cat) {
             if (in_array($cat['id'], $ids)) {
                 $enabled[] = $cat;
             }
         }
         $response['data']['customfields'] = $enabled;
     }
     if (\GO::modules()->isInstalled('customfields')) {
         $response['data']['items_under_blocks'] = array();
         $enabledBlocksStmt = \GO\Customfields\Model\EnabledBlock::getEnabledBlocks($model->addressbook_id, 'GO\\Addressbook\\Model\\Addressbook', $model->className());
         foreach ($enabledBlocksStmt as $i => $enabledBlockModel) {
             $items = $enabledBlockModel->block->getItemNames($model->id, $model->name);
             if (!empty($items)) {
                 $blockedItemsEl = array('id' => $i, 'block_name' => $enabledBlockModel->block->name, 'items' => $items);
                 $blockedItemsEl['model_name'] = !empty($items[0]) ? $items[0]['model_name'] : '';
                 $modelNameArr = explode('_', $blockedItemsEl['model_name']);
                 $blockedItemsEl['type'] = !empty($modelNameArr[3]) ? $modelNameArr[3] : '';
                 $response['data']['items_under_blocks'][] = $blockedItemsEl;
             }
         }
     }
     return parent::afterDisplay($response, $model, $params);
 }
Exemplo n.º 23
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;
 }
Exemplo n.º 24
0
 /**
  * The default action for displaying a model in a DisplayPanel.
  */
 protected function actionDisplay($params)
 {
     $response = array('data' => array(), 'success' => true);
     $modelName = $this->model;
     $model = \GO::getModel($modelName)->findByPk($this->getPrimaryKeyFromParams($params));
     if (!$model) {
         throw new \GO\Base\Exception\NotFound();
     }
     $response = $this->beforeDisplay($response, $model, $params);
     //todo build in new style. Now it's necessary for old library functions
     //require_once(\GO::config()->root_path.'Group-Office.php');
     $response['data'] = array_merge($response['data'], $model->getAttributes('html'));
     $response['data']['model'] = $model->className();
     $response['data']['permission_level'] = $model->getPermissionLevel();
     $response['data']['write_permission'] = \GO\Base\Model\Acl::hasPermission($response['data']['permission_level'], \GO\Base\Model\Acl::WRITE_PERMISSION);
     if (!empty($model->ctime)) {
         $response['data']['ctime'] = \GO\Base\Util\Date::get_timestamp($model->ctime);
     }
     if (!empty($model->mtime)) {
         $response['data']['mtime'] = \GO\Base\Util\Date::get_timestamp($model->mtime);
     }
     if (!empty($model->user)) {
         $response['data']['username'] = $model->user->name;
     }
     if (!empty($model->mUser)) {
         $response['data']['musername'] = $model->mUser->name;
     }
     $response['data']['customfields'] = array();
     if (!isset($response['data']['workflow']) && \GO::modules()->workflow) {
         $response = $this->_processWorkflowDisplay($model, $response);
     }
     if ($model->customfieldsRecord) {
         $response = $this->_processCustomFieldsDisplay($model, $response);
     }
     if ($model->hasLinks()) {
         $response = $this->_processLinksDisplay($model, $response, isset($params['links_limit']) ? $params['links_limit'] : 15);
         if (!isset($response['data']['events']) && \GO::modules()->calendar) {
             $response = $this->_processEventsDisplay($model, $response);
         }
         if (!isset($response['data']['tasks']) && \GO::modules()->tasks) {
             $response = $this->_processTasksDisplay($model, $response);
         }
     }
     if (!isset($response['data']['files'])) {
         $response = $this->_processFilesDisplay($model, $response);
     }
     if (\GO::modules()->comments) {
         $response = $this->_processCommentsDisplay($model, $response);
     }
     if (\GO::modules()->lists) {
         $response = \GO\Lists\ListsModule::displayResponse($model, $response);
     }
     $response = $this->afterDisplay($response, $model, $params);
     $this->fireEvent('display', array(&$this, &$response, &$model));
     return $response;
 }