示例#1
0
 public function Send(IEmailMessage $emailMessage)
 {
     $this->phpMailer->ClearAllRecipients();
     $this->phpMailer->ClearReplyTos();
     $this->phpMailer->CharSet = $emailMessage->Charset();
     $this->phpMailer->Subject = $emailMessage->Subject();
     $this->phpMailer->Body = $emailMessage->Body();
     $from = $emailMessage->From();
     $defaultFrom = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_ADDRESS);
     $defaultName = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_NAME);
     $address = empty($defaultFrom) ? $from->Address() : $defaultFrom;
     $name = empty($defaultName) ? $from->Name() : $defaultName;
     $this->phpMailer->SetFrom($address, $name);
     $replyTo = $emailMessage->ReplyTo();
     $this->phpMailer->AddReplyTo($replyTo->Address(), $replyTo->Name());
     $to = $this->ensureArray($emailMessage->To());
     $toAddresses = new StringBuilder();
     foreach ($to as $address) {
         $toAddresses->Append($address->Address());
         $this->phpMailer->AddAddress($address->Address(), $address->Name());
     }
     $cc = $this->ensureArray($emailMessage->CC());
     foreach ($cc as $address) {
         $this->phpMailer->AddCC($address->Address(), $address->Name());
     }
     $bcc = $this->ensureArray($emailMessage->BCC());
     foreach ($bcc as $address) {
         $this->phpMailer->AddBCC($address->Address(), $address->Name());
     }
     if ($emailMessage->HasStringAttachment()) {
         Log::Debug('Adding email attachment %s', $emailMessage->AttachmentFileName());
         $this->phpMailer->AddStringAttachment($emailMessage->AttachmentContents(), $emailMessage->AttachmentFileName());
     }
     Log::Debug('Sending %s email to: %s from: %s', get_class($emailMessage), $toAddresses->ToString(), $from->Address());
     $success = false;
     try {
         $success = $this->phpMailer->Send();
     } catch (Exception $ex) {
         Log::Error('Failed sending email. Exception: %s', $ex);
     }
     Log::Debug('Email send success: %d. %s', $success, $this->phpMailer->ErrorInfo);
 }
 /**
  * @param ConfigSetting $configSetting
  */
 public function AddSectionSetting(ConfigSetting $configSetting)
 {
     $this->sectionSettings[$configSetting->Section][] = $configSetting;
     $this->settingNames->Append($configSetting->Name . ',');
 }
示例#3
0
 /**
  * @param ReservationItemView $reservation
  * @param string $format
  * @return string
  */
 public function Format(ReservationItemView $reservation, $format = null)
 {
     $shouldHideUser = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, new BooleanConverter());
     $shouldHideDetails = ReservationDetailsFilter::HideReservationDetails($reservation->StartDate, $reservation->EndDate);
     if (($shouldHideUser || $shouldHideDetails) && (is_null($this->user) || $this->user->UserId != $reservation->UserId && !$this->user->IsAdminForGroup($reservation->OwnerGroupIds()))) {
         return '';
     }
     if (empty($format)) {
         $format = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_RESERVATION_LABEL);
     }
     if ($format == 'none' || empty($format)) {
         return '';
     }
     $name = $this->GetFullName($reservation);
     $timezone = 'UTC';
     $dateFormat = Resources::GetInstance()->GetDateFormat('res_popup');
     if (!is_null($this->user)) {
         $timezone = $this->user->Timezone;
     }
     $label = $format;
     $label = str_replace('{name}', $name, $label);
     $label = str_replace('{title}', $reservation->Title, $label);
     $label = str_replace('{description}', $reservation->Description, $label);
     $label = str_replace('{email}', $reservation->OwnerEmailAddress, $label);
     $label = str_replace('{organization}', $reservation->OwnerOrganization, $label);
     $label = str_replace('{phone}', $reservation->OwnerPhone, $label);
     $label = str_replace('{position}', $reservation->OwnerPosition, $label);
     $label = str_replace('{startdate}', $reservation->StartDate->ToTimezone($timezone)->Format($dateFormat), $label);
     $label = str_replace('{enddate}', $reservation->EndDate->ToTimezone($timezone)->Format($dateFormat), $label);
     $label = str_replace('{resourcename}', $reservation->ResourceName, $label);
     $label = str_replace('{participants}', trim(implode(', ', $reservation->ParticipantNames)), $label);
     $label = str_replace('{invitees}', trim(implode(', ', $reservation->InviteeNames)), $label);
     $matches = array();
     preg_match_all('/\\{(att\\d+?)\\}/', $format, $matches);
     $matches = $matches[0];
     if (count($matches) > 0) {
         for ($m = 0; $m < count($matches); $m++) {
             $id = filter_var($matches[$m], FILTER_SANITIZE_NUMBER_INT);
             $value = $reservation->GetAttributeValue($id);
             $label = str_replace($matches[$m], $value, $label);
         }
     }
     if (BookedStringHelper::Contains($label, '{reservationAttributes}')) {
         $attributesLabel = new StringBuilder();
         $attributes = $this->attributeRepository->GetByCategory(CustomAttributeCategory::RESERVATION);
         foreach ($attributes as $attribute) {
             $attributesLabel->Append($attribute->Label() . ': ' . $reservation->GetAttributeValue($attribute->Id()) . ', ');
         }
         $label = str_replace('{reservationAttributes}', rtrim($attributesLabel->ToString(), ', '), $label);
     }
     return $label;
 }
 /**
  * @param array|IReservedItemView[] $conflicts
  * @return string
  */
 protected function GetErrorString($conflicts)
 {
     $errorString = new StringBuilder();
     $errorString->Append(Resources::GetInstance()->GetString('ConflictingReservationDates'));
     $errorString->Append("\n");
     $format = Resources::GetInstance()->GetDateFormat(ResourceKeys::DATE_GENERAL);
     $dates = array();
     /** @var IReservedItemView $conflict */
     foreach ($conflicts as $conflict) {
         $dates[] = sprintf('%s - %s', $conflict->GetStartDate()->ToTimezone($this->timezone)->Format($format), $conflict->GetResourceName());
     }
     $uniqueDates = array_unique($dates);
     sort($uniqueDates);
     foreach ($uniqueDates as $date) {
         $errorString->Append($date);
         $errorString->Append("\n");
     }
     return $errorString->ToString();
 }
 /**
  * @param array $conflicts
  * @return string
  */
 protected function GetErrorString($conflicts)
 {
     $errorString = new StringBuilder();
     $errorString->Append(Resources::GetInstance()->GetString('ConflictingAccessoryDates'));
     $errorString->AppendLine();
     $format = Resources::GetInstance()->GetDateFormat(ResourceKeys::DATE_GENERAL);
     foreach ($conflicts as $conflict) {
         $errorString->Append(sprintf('(%s) %s', $conflict['date']->ToTimezone($this->timezone)->Format($format), $conflict['name']));
         $errorString->AppendLine();
     }
     return $errorString->ToString();
 }
示例#6
-1
 public function CreatePagination($params, &$smarty)
 {
     /** @var PageInfo $pageInfo */
     $pageInfo = $params['pageInfo'];
     if (empty($pageInfo->Total)) {
         return '';
     }
     $sb = new StringBuilder();
     $viewAllText = $this->Resources->GetString('ViewAll');
     $sb->Append('<p><br/>');
     $sb->Append($this->Resources->GetString('Rows'));
     $sb->Append(": {$pageInfo->ResultsStart} - {$pageInfo->ResultsEnd} ({$pageInfo->Total})");
     $sb->Append('<span>&nbsp;</span>');
     if ($pageInfo->TotalPages != 1) {
         $sb->Append($this->CreatePageLink(array('page' => 1, 'size' => '-1', 'text' => $viewAllText), $smarty));
     }
     $sb->Append('</p><p>');
     $sb->Append($this->Resources->GetString('Page'));
     $sb->Append(': ');
     $size = $pageInfo->PageSize;
     $currentPage = $pageInfo->CurrentPage;
     for ($i = 1; $i <= $pageInfo->TotalPages; $i++) {
         $isCurrent = $i == $currentPage;
         $sb->Append($this->CreatePageLink(array('page' => $i, 'size' => $size, 'iscurrent' => $isCurrent), $smarty));
         $sb->Append(" ");
     }
     $sb->Append('</p>');
     return $sb->ToString();
 }