public function appendNewNotification($event_types, $replace_notification = false, $create_negative = true, $delete_negative = false)
 {
     if ($create_negative) {
         // Get all (positive and negative) notifications stored for this event (more than one are possible for each event)
         $event_notifications = eF_getTableData("event_notifications", "*", "active = 1 AND (event_type = '" . $this->event['type'] . "' OR event_type = '" . -1 * $this->event['type'] . "')");
     } else {
         // Get all notifications stored for exactly this event (only positive or negative though more than one are possible for each event)
         $event_notifications = eF_getTableData("event_notifications", "*", "active = 1 AND (event_type = '" . $this->event['type'] . "')");
     }
     if (sizeof($event_notifications)) {
         // Form each one and append it to the notifications queue
         $notifications_to_send = array();
         foreach ($event_notifications as $event_notification) {
             // Check whether the triggered event satisfies the conditions to be sent as an announcement
             $conditions = unserialize($event_notification['send_conditions']);
             $conditions_passed = true;
             foreach ($conditions as $field => $value) {
                 // A value of 0 means any* (any lesson, test, content etc)
                 if ($value != 0) {
                     if ($this->event['lessons_ID'] != $value && $this->event['entity_ID'] != $value && $this->event['courses_ID'] != $value) {
                         $conditions_passed = false;
                         break;
                     }
                 }
                 $conditions_passed = true;
             }
             // If all conditions are satisfied (or no conditions exist)
             if ($conditions_passed) {
                 // Set type - entity field: denoting the type of the event ."_". the ID of the involved entity (lesson, test, forum etc)
                 if ($this->event['type'] == EfrontEvent::COURSE_PROGRAMMED_START || $this->event['type'] == EfrontEvent::COURSE_PROGRAMMED_EXPIRY) {
                     $event_notification['id_type_entity'] = $event_notification['id'] . "_" . $event_notification['event_type'] . "_" . $this->event['lessons_ID'];
                     $negativeTypeEntity = "_" . -1 * $event_notification['event_type'] . "_" . $this->event['lessons_ID'];
                 } else {
                     if ($this->event['entity_ID']) {
                         $event_notification['id_type_entity'] = $event_notification['id'] . "_" . $event_notification['event_type'] . "_" . $this->event['entity_ID'];
                         $negativeTypeEntity = "_" . -1 * $event_notification['event_type'] . "_" . $this->event['entity_ID'];
                     } else {
                         if ($this->event['lessons_ID']) {
                             $event_notification['id_type_entity'] = $event_notification['id'] . "_" . $event_notification['event_type'] . "_" . $this->event['lessons_ID'];
                             $negativeTypeEntity = "_" . -1 * $event_notification['event_type'] . "_" . $this->event['lessons_ID'];
                         } else {
                             if ($this->event['courses_ID']) {
                                 $event_notification['id_type_entity'] = $event_notification['id'] . "_" . $event_notification['event_type'] . "_" . $this->event['courses_ID'];
                                 $negativeTypeEntity = "_" . -1 * $event_notification['event_type'] . "_" . $this->event['courses_ID'];
                             } else {
                                 $event_notification['id_type_entity'] = $event_notification['id'] . "_" . $event_notification['event_type'] . "_";
                                 $negativeTypeEntity = "_" . -1 * $event_notification['event_type'] . "_";
                             }
                         }
                     }
                 }
                 // Check whether this is of a NOT-event
                 if ($event_notification['event_type'] < 0 || $replace_notification) {
                     $event_notification['event_type'] = -1 * $event_notification['event_type'];
                     // in that case delete the corresponding record in the table (if such exists)
                     eF_deleteTableData("notifications", "id_type_entity= '" . $event_notification['id_type_entity'] . "' AND recipient = '" . $this->event['users_LOGIN'] . "'");
                     if ($this->event['type'] == -1 * EfrontEvent::COURSE_COMPLETION && $event_notification['event_type'] < 0 || $this->event['type'] == EfrontEvent::COURSE_COMPLETION && $event_notification['event_type'] > 0 || $this->event['type'] == -1 * EfrontEvent::LESSON_COMPLETION && $event_notification['event_type'] < 0 || $this->event['type'] == EfrontEvent::LESSON_COMPLETION && $event_notification['event_type'] > 0) {
                         //for these 2 notifications, we don't want them to be re-scheduled
                         continue;
                     }
                 }
                 if ($delete_negative) {
                     eF_deleteTableData("notifications", "id_type_entity like '%" . $negativeTypeEntity . "' AND recipient = '" . $this->event['users_LOGIN'] . "'");
                 }
                 // Set event notification recipients
                 if ($event_notification['send_recipients'] == EfrontNotification::TRIGGERINGUSER) {
                     $event_notification['send_conditions'] = "";
                     $event_notification['recipient'] = $this->event['users_LOGIN'];
                 } else {
                     if ($event_notification['send_recipients'] == EfrontNotification::ALLSYSTEMUSERS) {
                         $event_notification['send_conditions'] = "N;";
                         $event_notification['recipient'] = "";
                     } else {
                         if ($event_notification['send_recipients'] == EfrontNotification::SYSTEMADMINISTRATOR) {
                             $event_notification['send_conditions'] = serialize(array("user_type" => "administrator"));
                             $event_notification['recipient'] = "";
                         } else {
                             if ($event_notification['send_recipients'] == EfrontNotification::ALLLESSONUSERS) {
                                 $event_notification['send_conditions'] = serialize(array("lessons_ID" => $this->event['lessons_ID']));
                                 $event_notification['recipient'] = "";
                             } else {
                                 if ($event_notification['send_recipients'] == EfrontNotification::LESSONPROFESSORS) {
                                     $event_notification['send_conditions'] = serialize(array("lessons_ID" => $this->event['lessons_ID'], "user_type" => "professor"));
                                     $event_notification['recipient'] = "";
                                 } else {
                                     if ($event_notification['send_recipients'] == EfrontNotification::COURSEPROFESSORS) {
                                         $event_notification['send_conditions'] = serialize(array("courses_ID" => $this->event['lessons_ID'], "user_type" => "professor"));
                                         $event_notification['recipient'] = "";
                                     } else {
                                         if ($event_notification['send_recipients'] == EfrontNotification::ALLCOURSEUSERS) {
                                             $event_notification['send_conditions'] = serialize(array("courses_ID" => $this->event['lessons_ID']));
                                             $event_notification['recipient'] = "";
                                         } else {
                                             if ($event_notification['send_recipients'] == EfrontNotification::LESSONUSERSNOTCOMPLETED) {
                                                 $event_notification['send_conditions'] = serialize(array("lessons_ID" => $this->event['lessons_ID'], "completed" => "0"));
                                                 $event_notification['recipient'] = "";
                                             } else {
                                                 if ($event_notification['send_recipients'] == EfrontNotification::EXPLICITLYSEL) {
                                                     if (isset($this->event['explicitly_selected'])) {
                                                         // General case - set field "explicitly_selected" in the triggerEvent fields
                                                         if (!is_array($this->event['explicitly_selected'])) {
                                                             $this->event['explicitly_selected'] = array($this->event['explicitly_selected']);
                                                         }
                                                         $event_notification['send_conditions'] = serialize(array("users_login" => $this->event['explicitly_selected']));
                                                         $event_notification['recipient'] = "";
                                                     } else {
                                                         // This special treatment is used for surveys - so that all members of the survey will get the notification when the time of dispatch comes
                                                         $event_notification['send_conditions'] = serialize(array("entity_ID" => $this->event['entity_ID'], "entity_category" => $event_types[$event_notification['event_type']]['category']));
                                                         $event_notification['recipient'] = "";
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (G_VERSIONTYPE == 'enterprise') {
                     #cpp#ifdef ENTERPRISE
                     if ($event_notification['send_recipients'] == EfrontNotification::USERSUPERVISORS) {
                         $cond = array("users_login" => $this->event['users_LOGIN'], "supervisor" => 1);
                         if (in_array('courses_ID', array_keys($conditions))) {
                             $cond['courses_ID'] = $this->event['lessons_ID'];
                         }
                         $event_notification['send_conditions'] = serialize($cond);
                         $event_notification['recipient'] = "";
                     } elseif ($event_notification['send_recipients'] == EfrontNotification::USERIMMEDIATESUPERVISORS) {
                         $cond = array("users_login" => $this->event['users_LOGIN'], "immediate_supervisor" => 1);
                         if (in_array('courses_ID', array_keys($conditions))) {
                             $cond['courses_ID'] = $this->event['lessons_ID'];
                         }
                         $event_notification['send_conditions'] = serialize($cond);
                         $event_notification['recipient'] = "";
                     } else {
                         if ($event_notification['send_recipients'] == EfrontNotification::ALLSUPERVISORS) {
                             $event_notification['send_conditions'] = 'supervisors';
                             $event_notification['recipient'] = "";
                         }
                     }
                 }
                 #cpp#endif
                 /*
                 	    			// Special treatment due to explicity recipient selection
                 	    			if ($this -> event['type'] == EfrontEvent::NEW_SURVEY) {
                 	    				$event_notification['send_conditions'] = serialize(array("surveys_ID" => $this -> event['entity_ID']));
                 	    				$event_notification['recipient'] = "";
                 	    			}
                 */
                 //@TODO unite with upper
                 // Format the message on the first layer: replacing event specific information now
                 // Note: Recipient's specific information will be first replaced in layer 2 (before sending)
                 $template_formulations = $this->createSubstitutionsArray($event_types, $event_notification['send_recipients']);
                 $subject = eF_formulateTemplateMessage($event_notification['subject'], $template_formulations);
                 $message = eF_formulateTemplateMessage($event_notification['message'], $template_formulations);
                 $html_message = $event_notification['html_message'];
                 // Create a single array to implode it and insert it at once in the notifications queue table
                 //Added != XXXX_EXPIRY because notification was not sent in expiry date but immediately
                 if ($event_notification['send_immediately'] && ($this->event['type'] != EfrontEvent::PROJECT_EXPIRY && $this->event['type'] != EfrontEvent::LESSON_PROGRAMMED_EXPIRY && $this->event['type'] != EfrontEvent::COURSE_PROGRAMMED_EXPIRY && $this->event['type'] != EfrontEvent::COURSE_CERTIFICATE_EXPIRY)) {
                     $timestamp = 0;
                     $_SESSION['send_next_notifications_now'] = 1;
                 } else {
                     $timestamp = $this->event['timestamp'] + ($event_notification['after_time'] ? $event_notification['after_time'] : 0);
                 }
                 $notifications_to_send[] = array('timestamp' => $timestamp, 'id_type_entity' => $event_notification['id_type_entity'], 'send_interval' => 0, 'send_conditions' => $event_notification['send_conditions'], 'recipient' => $this->event['users_LOGIN'], 'subject' => $subject, 'message' => $message, 'html_message' => $html_message);
                 //$notifications_to_send[] = $timestamp. "','". $event_notification['id_type_entity'] ."','" .$event_notification['after_time']. "', '" .$event_notification['send_conditions']."','". $event_notification['recipient']. "', '".$subject. "', '".$message. "', '".$html_message;
             }
         }
         if (sizeof($notifications_to_send)) {
             //eF_execute("INSERT INTO notifications (timestamp, id_type_entity, send_interval, send_conditions, recipient, subject, message, html_message) VALUES ('". implode("'),('", $notifications_to_send) . "')");
             eF_insertTableDataMultiple("notifications", $notifications_to_send);
         }
     }
 }
 public function sendTo($recipient)
 {
     if (is_array($recipient)) {
         if (isset($recipient['login'])) {
             if (!(isset($recipient['email']) && isset($recipient['name']) && isset($recipient['surname']) && isset($recipient['user_type']))) {
                 $recipient = $recipient['login'];
             } else {
                 $defined = 1;
             }
         } else {
             throw new EfrontNotificationException(_UNKNOWNRECIPIENT, EfrontNotificationException::NORECIPIENTLOGIN_DEFINED);
         }
     }
     if (!$defined) {
         $recipient = eF_getTableData("users", "*", "login = '******'");
         if (!empty($recipient)) {
             $recipient = $recipient[0];
         } else {
             throw new EfrontNotificationException(_UNKNOWNRECIPIENT, EfrontNotificationException::NORECIPIENTLOGIN_DEFINED);
         }
     }
     // create the array of substitutions for this particular user and replace them in the subject/message texts
     $hostname = G_SERVERNAME;
     if ($hostname[strlen($hostname) - 1] == "/") {
         $hostname = substr($hostname, 0, strlen($hostname) - 1);
     }
     $language = eF_getTableData("languages", "translation", "name = '" . $recipient['languages_NAME'] . "'");
     if (!empty($language)) {
         $language = $language[0]['translation'];
     }
     $template_formulations = array("users_name" => $recipient['name'], "users_surname" => $recipient['surname'], "users_login" => $recipient['login'], "users_email" => $recipient['email'], "users_comments" => $recipient['comments'], "users_language" => $language, "date" => formatTimestamp(time()), "date_time" => formatTimestamp(time(), 'time'), "timestamp" => time(), "user_type" => $recipient['user_type'], "host_name" => $hostname, "site_name" => $GLOBALS['configuration']['site_name'], "site_motto" => $GLOBALS['configuration']['site_motto']);
     $header = array('From' => $GLOBALS['configuration']['system_email'], 'To' => $recipient['email'], 'Subject' => eF_formulateTemplateMessage($this->notification['subject'], $template_formulations), 'Content-Transfer-Encoding' => '7bit', 'Date' => date("r"));
     if ($this->notification['html_message'] == 1) {
         $header['Content-type'] = 'text/html;charset="UTF-8"';
         // if content-type is text/html, the message cannot be received by mail clients for Registration content
     } else {
         $header['Content-type'] = 'text/plain;charset="UTF-8"';
     }
     $smtp = Mail::factory('smtp', array('auth' => $GLOBALS['configuration']['smtp_auth'] ? true : false, 'host' => $GLOBALS['configuration']['smtp_host'], 'password' => $GLOBALS['configuration']['smtp_pass'], 'port' => $GLOBALS['configuration']['smtp_port'], 'username' => $GLOBALS['configuration']['smtp_user'], 'timeout' => $GLOBALS['configuration']['smtp_timeout']));
     // force url change for html messages
     $message = eF_getCorrectLanguageMessage($this->notification['message'], $recipient['languages_NAME']);
     // Local paths names should become urls
     if ($this->notification['html_message'] == 1) {
         $message = str_replace('="content', '="###host_name###/content', $message);
         /*
          * //Commented-out Feb 2013 (periklis) because it's no longer needed (probably)        	
         			if ($configuration['math_images']) {
         				$message = "<html><body><script type = \"text/javascript\" src = \"###host_name###/js/ASCIIMath2Tex.js\"> </script>".$message."</body></html>";
         			} else {
         				$message = "<html><body><script type = \"text/javascript\" src = \"###host_name###/js/ASCIIMathML.js\"> </script>".$message."</body></html>";
         			}
         */
     } else {
         $message = str_replace("<br />", "\r\n", $message);
         $message = str_replace("<br>", "\r\n", $message);
         $message = str_replace("<p>", "\r\n", $message);
         $message = str_replace("</p>", "\r\n", $message);
         $message = str_replace("&amp;", "&", $message);
         $message = strip_tags($message);
     }
     $message = eF_formulateTemplateMessage($message, $template_formulations);
     $message = eF_replaceMD5($message);
     if ($GLOBALS['configuration']['notifications_send_mode'] == 0) {
         //email only
         if (!empty($recipient['email'])) {
             $result = $smtp->send($recipient['email'], $header, $message);
         }
     } else {
         if ($GLOBALS['configuration']['notifications_send_mode'] == 1) {
             //pm only
             $pm = new eF_PersonalMessage($recipient['login'], $recipient['login'], $header['Subject'], $message);
             $result = $pm->send();
         } else {
             if ($GLOBALS['configuration']['notifications_send_mode'] == 2) {
                 //email and pm
                 $pm = new eF_PersonalMessage($recipient['login'], $recipient['login'], $header['Subject'], $message);
                 $pm->send();
                 if (!empty($recipient['email'])) {
                     $result = $smtp->send($recipient['email'], $header, $message);
                 }
             }
         }
     }
     if (PEAR::isError($result)) {
         $admin = EfrontSystem::getAdministrator();
         eF_mail($GLOBALS['configuration']['system_email'], $admin->user['email'], _AUTOMATEDEMAILSENTFROM . $admin->user['email'], $result->getMessage());
         throw new EfrontNotificationException($result->getMessage(), EfrontNotificationException::GENERAL_ERROR);
     }
     if ($result === true) {
         // put into sent_notifications table
         eF_insertTableData("sent_notifications", array("timestamp" => time(), "recipient" => $recipient['email'] . " (" . $recipient['name'] . " " . $recipient['surname'] . ")", "subject" => $header['Subject'], "body" => $message, "html_message" => $this->notification['html_message']));
         return true;
     } else {
         return false;
     }
 }
Example #3
0
                             $condition = $form->exportValue('available_lessons');
                             $condition = array("lessons_ID" => $condition);
                         } else {
                             $condition = array();
                         }
                     }
                 }
             }
         }
     }
     if (isset($_GET['add_notification'])) {
         //Added because course not completion notification for already assigned users (rows added while creating notification) has not replaced formulations
         //only users assigned to course after creating the notification was correct (since it is created via triggerEvent) (#5918)
         $template_formulations = EfrontNotification::createSubstitutionsArrayForDateNotifications($condition);
         $subject = eF_formulateTemplateMessage($subject, $template_formulations);
         $message = eF_formulateTemplateMessage($message, $template_formulations);
         EfrontNotification::addEventNotification($events_type, $subject, $message, $condition, $_POST['event_recipients'], $html_message, $after_time, $send_immediately);
     } else {
         // if we changed from simple notification event -> on/after event notification
         if (!isset($_GET['event'])) {
             eF_deleteTableData("notifications", "id = '" . $_GET['edit_notification'] . "'");
             //$notification = array ("event_type"        => $events_type, "send_conditions" => serialize($condition),"send_recipients" => $_POST['event_recipients'], "message"          => $message,"subject"       => $subject);
             EfrontNotification::addEventNotification($events_type, $subject, $message, $condition, $_POST['event_recipients'], $html_message, $after_time, $send_immediately);
         } else {
             EfrontNotification::editEventNotification($_GET['edit_notification'], $events_type, $subject, $message, $condition, $_POST['event_recipients'], $html_message, $after_time, $send_immediately);
         }
     }
     $message = _NOTIFICATIONSETUPSUCCESSFULLY;
     $message_type = 'success';
 }
 eF_redirect(basename($_SERVER['PHP_SELF']) . "?ctg=digests&message=" . urlencode($message) . "&message_type=" . $message_type);