Exemple #1
0
 /**
  * Sets the name and email of the sender.
  *
  * @see Phprojekt_User_User()
  *
  * @param integer $from ID of the user who send the mail.
  *
  * @return void
  */
 public function setCustomFrom($from)
 {
     $phpUser = new Phprojekt_User_User();
     $phpUser->find($from);
     $email = $phpUser->getSetting('email');
     $name = trim($phpUser->firstname . ' ' . $phpUser->lastname);
     if (!empty($name)) {
         $name .= ' (' . $phpUser->username . ')';
     } else {
         $name = $phpUser->username;
     }
     $this->setFrom($email, $name);
 }
Exemple #2
0
 /**
  * Convert a UTC time to user or user to UTC and return the timestamp.
  *
  * @param string  $value Date value to convert.
  * @param integer $side  1 for utc to user, -1 for user to utc.
  *
  * @return integer Unix timestamp value.
  */
 public static function convert($value, $side)
 {
     $timeZone = Phprojekt_User_User::getSetting("timeZone", 'UTC');
     if (strstr($timeZone, "_")) {
         list($hours, $minutes) = explode("_", $timeZone);
     } else {
         $hours = (int) $timeZone;
         $minutes = 0;
     }
     $hoursComplement = $hours * $side;
     $minutesComplement = $minutes * $side;
     $u = strtotime($value);
     return mktime(date("H", $u) + $hoursComplement, date("i", $u) + $minutesComplement, date("s", $u), date("m", $u), date("d", $u), date("Y", $u));
 }
Exemple #3
0
 /**
  * Translate a string using the current module.
  *
  * @param string             $message    Message to translate.
  * @param string|Zend_Locale $locale     Locale/Language to set.
  * @param string             $moduleName Module where search the string.
  *
  * @return string Translated string.
  */
 public function translate($message, $locale = null, $moduleName = null)
 {
     $translate = Phprojekt::getInstance()->getTranslate($locale);
     if (null === $moduleName) {
         $moduleName = Zend_Controller_Front::getInstance()->getRequest()->getModuleName();
     }
     // Fix for request to the core
     if ($moduleName == 'Core') {
         $paramModule = Zend_Controller_Front::getInstance()->getRequest()->getParam('moduleName', null);
         // Use a $moduleName param if is not a system Setting or Configuration
         if (null !== $paramModule && !in_array($paramModule, array('General', 'User', 'Notification'))) {
             $moduleName = $paramModule;
         }
     }
     if (null === $locale) {
         $locale = Phprojekt_User_User::getSetting("language", $this->_config->language);
     }
     return $translate->translate($message, $moduleName, $locale);
 }
Exemple #4
0
 /**
  * Standard action.
  *
  * The function sets up the template index.phtml and renders it.
  *
  * @return void
  */
 public function indexAction()
 {
     $language = Phprojekt_User_User::getSetting("language", Phprojekt::getInstance()->getConfig()->language);
     $this->view->webpath = Phprojekt::getInstance()->getConfig()->webpath;
     $this->view->language = $language;
     $this->view->compressedDojo = (bool) Phprojekt::getInstance()->getConfig()->compressedDojo;
     $this->view->frontendMsg = (bool) Phprojekt::getInstance()->getConfig()->frontendMessages;
     // Since the time for re-starting a poll to the server is in milliseconds, a multiple of 1000 is needed here.
     $this->view->pollingLoop = Phprojekt::getInstance()->getConfig()->pollingLoop * 1000;
     $this->render('index');
 }
 /**
  * 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.
  *  - id      => id of the minute.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception 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 Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400);
     }
     $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 Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400);
     }
     // Security check: is the current user owner of this minutes entry?
     if ($minutes->ownerId != PHprojekt_Auth::getUserId()) {
         throw new Zend_Controller_Action_Exception(self::USER_IS_NOT_OWNER, 403);
     }
     $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 = new Phprojekt_User_User();
         $ownerModel->find($minutes->ownerId);
         $ownerEmail = $ownerModel->getSetting('email');
         $mail->setFrom($ownerEmail, $ownerModel->displayName);
         // 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), '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), 'id' => $minutesId);
     }
     Phprojekt_Converter_Json::echoConvert($return);
 }