Example #1
0
 /**
  * Constructor.
  *
  * @param array $params Array with parameters.
  *
  * @return void
  */
 public function __construct($params)
 {
     parent::__construct($params[self::PARAMS_CHARSET]);
     $this->_bodyMode = $params[self::PARAMS_BODYMODE];
 }
Example #2
0
 /**
  * Sends a mail containing the Minutes protocol.
  *
  * A pdf can be also attached to the mail.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b> id of the minute to send.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - array <b>options</b> If contain 'pdf', a pdf is attached to the mail.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success' or 'error'.
  *  - message => Success or error message.
  *  - code    => 0 for success, -1 for error.
  *  - id      => id of the minute.
  * </pre>
  *
  * @throws Phprojekt_PublishedException On error in the send action or wrong id.
  *
  * @return void
  */
 public function jsonSendMailAction()
 {
     $errors = array();
     $params = $this->getRequest()->getParams();
     $this->setCurrentProjectId();
     // Sanity check
     if (empty($params['id']) || !is_numeric($params['id'])) {
         throw new Phprojekt_PublishedException(self::ID_REQUIRED_TEXT);
     }
     $minutesId = (int) $params['id'];
     $minutes = $this->getModelObject()->find($minutesId);
     // Was the id provided a valid one?
     if (!$minutes instanceof Phprojekt_Model_Interface || !$minutes->id) {
         // Invalid ID
         throw new Phprojekt_PublishedException(self::ID_REQUIRED_TEXT);
     }
     // Security check: is the current user owner of this minutes entry?
     if ($minutes->ownerId != PHprojekt_Auth::getUserId()) {
         throw new Phprojekt_PublishedException(self::USER_IS_NOT_OWNER);
     }
     $mail = new Phprojekt_Mail();
     /* @var $mail Zend_Mail */
     $smtpTransport = $mail->setTransport();
     $validator = new Zend_Validate_EmailAddress();
     $emailsListed = $this->getRequest()->getParam('recipients', array());
     $emailsListed = $this->_getMailFromUserIds($emailsListed, $validator);
     $emailsWritten = $this->getRequest()->getParam('additional', '');
     $emailsWritten = $this->_getMailFromCsvString($emailsWritten, $validator);
     $userMails = array_merge($emailsListed, $emailsWritten);
     $errors = $this->_addRecipients($mail, $userMails, $errors);
     // Sanity check
     if (array() === $mail->getRecipients()) {
         $errors[] = array('message' => self::MISSING_MAIL_RECIPIENTS, 'value' => null);
     }
     if (!count($errors)) {
         // Handle PDF attachment if needed
         if (!empty($params['options']) && is_array($params['options'])) {
             if (in_array('pdf', $params['options'])) {
                 $pdf = (string) Minutes_Helpers_Pdf::getPdf($minutes);
                 $mail->createAttachment($pdf, 'application/x-pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_8BIT, 'minutes_' . $minutesId . '.pdf');
             }
         }
         // Set sender address
         $ownerModel = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User');
         $ownerModel->find($minutes->ownerId);
         $ownerEmail = $ownerModel->getSetting('email');
         $display = $ownerModel->getDisplay();
         $mail->setFrom($ownerEmail, $ownerModel->applyDisplay($display, $ownerModel));
         // Set subject
         $subject = sprintf('%s "%s", %s', Phprojekt::getInstance()->translate('Meeting minutes for'), $minutes->title, $minutes->meetingDatetime);
         $mail->setSubject($subject);
         // Set mail content
         $mail->setBodyText($subject, 'utf-8');
         $mail->setBodyHtml($this->_getHtmlList($minutes), 'utf-8');
         // Keep send() commented out until test phase is over
         $mail->send($smtpTransport);
         $return = array('type' => 'success', 'message' => Phprojekt::getInstance()->translate(self::MAIL_SUCCESS_TEXT), 'code' => 0, 'id' => $minutesId);
     } else {
         $message = Phprojekt::getInstance()->translate(self::MAIL_FAIL_TEXT);
         foreach ($errors as $error) {
             $message .= "\n";
             $message .= sprintf("%s %s", Phprojekt::getInstance()->translate($error['message']), $error['value']);
         }
         $return = array('type' => 'error', 'message' => nl2br($message), 'code' => -1, 'id' => $minutesId);
     }
     Phprojekt_Converter_Json::echoConvert($return);
 }