Exemplo n.º 1
0
 /**
  * Sends a message from one user to another.
  * @param Int $fromuserid 				id of the user sending the message.
  * @param Int $touserid 				id of the user to send the message to.
  * @param String $subject 				A valid RFC 2047 subject. See http://www.faqs.org/rfcs/rfc2047
  * @param String $message 				body of the message to send (text/rich html).
  * @param Array $attachments 			array of $_FILES with the attachments.
  * @param String $attachmentTag		Tag that contains the attachment files in the $_FILES array.
  * @param Array $external_recipients 	A valid RFC 2822 recipients set. See http://www.faqs.org/rfcs/rfc2822
  * @return boolean 						true if successful, false otherwise
  */
 public function sendMessage($fromuserid, $touserid, $subject, $message, $attachments, $external_recipients = null, $attachmentTag)
 {
     // sanity checks
     if (empty($fromuserid) || empty($touserid)) {
         return false;
     }
     if (empty($subject)) {
         $subject = "(" . $this->lh->translationFor("no_subject") . ")";
     }
     if (empty($message)) {
         $message = "(" . $this->lh->translationFor("no_message") . ")";
     }
     // first send to external recipients (if any), because we are moving them later with the call to move_uploaded_file.
     if (!empty($external_recipients)) {
         require_once 'MailHandler.php';
         $mh = \creamy\MailHandler::getInstance();
         $result = $mh->sendMailWithAttachments($external_recipients, $subject, $message, $attachments, $attachmentTag);
     }
     // Now store the message in our database.
     // try to store the inbox message for the target user. Start transaction because we could have attachments.
     $this->dbConnector->startTransaction();
     // message data.
     $data = array("user_from" => $fromuserid, "user_to" => $touserid, "subject" => $subject, "message" => $message, "date" => $this->dbConnector->now(), "message_read" => 0, "favorite" => 0);
     // insert the new message in the inbox of the receiving user.
     $inboxmsgid = $this->dbConnector->insert(CRM_MESSAGES_INBOX_TABLE_NAME, $data);
     if (!$inboxmsgid) {
         $this->dbConnector->rollback();
         return false;
     }
     // insert the new message in the outbox of the sending user.
     $data["message_read"] = 1;
     $outboxmsgid = $this->dbConnector->insert(CRM_MESSAGES_OUTBOX_TABLE_NAME, $data);
     if (!$outboxmsgid) {
         $this->dbConnector->rollback();
         return false;
     }
     // insert attachments (if any).
     if (!$this->addAttachmentsForMessage($inboxmsgid, $outboxmsgid, $fromuserid, $touserid, $attachments, $attachmentTag)) {
         $this->dbConnector->rollback();
         return false;
     }
     // success! commit transactions.
     $this->dbConnector->commit();
     return true;
 }
Exemplo n.º 2
0
require_once dirname(dirname(dirname(__FILE__))) . '/php/DbHandler.php';
/** 
 * Checks the events for today and sends an email to users with pending events for
 * today. This behaviour can be enabled/disabled by means of the setting property
 * notification_email_events (1=yes, 0=no).
 */
// initialize vars.
if (!isset($db)) {
    $db = new \creamy\DbHandler();
}
// check if notifications for events is enabled.
$enabled = $db->getNotificationsForEventsSetting();
if (filter_var($enabled, FILTER_VALIDATE_BOOLEAN)) {
    // if email notifications for events is enabled...
    require_once dirname(dirname(dirname(__FILE__))) . '/php/MailHandler.php';
    if (!isset($mh)) {
        $mh = \creamy\MailHandler::getInstance();
    }
    $events = $db->getEventsForTodayForAllUsers(true);
    // error_log("Events: ".var_export($events, true));
    if (!empty($events)) {
        foreach ($events as $event) {
            // for every event...
            // send a new notification
            if ($mh->sendNewEventMailToUser($event)) {
                $db->setEventAsNotified($event["id"]);
                // set event as notified in DDBB.
            }
        }
    }
}