public function jsonGetSpecificUsersAction() { $ids = Cleaner::sanitize('arrayofint', $this->getRequest()->getParam('users', array())); if (empty($ids)) { $ids[] = (int) PHprojekt_Auth::getUserId(); } $db = Phprojekt::getInstance()->getDb(); $where = sprintf('status = %s AND id IN (%s)', $db->quote('A'), implode(", ", $ids)); $user = new Phprojekt_User_User(); $records = $user->fetchAll($where); $data = array(); foreach ($records as $record) { $data['data'][] = array('id' => (int) $record->id, 'display' => $record->displayName); } Phprojekt_Converter_Json::echoConvert($data, Phprojekt_ModelInformation_Default::ORDERING_LIST); }
/** * 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); }
/** * Returns the list of events where the logged user is involved, * for a specific period (like week or month). * * The function use Phprojekt_ModelInformation_Default::ORDERING_LIST for get and sort the fields. * * OPTIONAL request parameters: * <pre> * - date <b>dateStart</b> Start date for filter. * - date <b>dateEnd</b> End date for filter. * - integer <b>count</b> Use for SQL LIMIT count. * - integer <b>offset</b> Use for SQL LIMIT offset. * </pre> * * The return is in CSV format. * * @return void */ public function csvPeriodListAction() { $count = (int) $this->getRequest()->getParam('count', null); $offset = (int) $this->getRequest()->getParam('start', null); $db = Phprojekt::getInstance()->getDb(); $dateStart = $db->quote(Cleaner::sanitize('date', $this->getRequest()->getParam('dateStart', date("Y-m-d")))); $dateEnd = $db->quote(Cleaner::sanitize('date', $this->getRequest()->getParam('dateEnd', date("Y-m-d")))); $this->setCurrentProjectId(); $where = sprintf('participant_id = %d AND DATE(start_datetime) <= %s AND DATE(end_datetime) >= %s', (int) PHprojekt_Auth::getUserId(), $dateEnd, $dateStart); $records = $this->getModelObject()->fetchAll($where, "start_datetime", $count, $offset); Phprojekt_Converter_Csv::echoConvert($records, Phprojekt_ModelInformation_Default::ORDERING_FORM); }