/**
  * Get all (scheduled and on event) notifications
  *
  * <br/>Example:
  * <code>
  * EfrontNotification :: getAllNotifications();
  * </code>
  *
  * @return array of notifications in form []=>array([id],[send_interval],[send_conditions],[message], ([timestamp] OR [event]))
  * @since 3.6.0
  * @access public
  */
 public static function getAllNotifications()
 {
     $allNotifications = eF_getTableData("notifications", "*", "id_type_entity IS NULL");
     $event_notifications = eF_getTableData("event_notifications", "*", "", "active desc");
     $event_types = EfrontEvent::getEventTypes();
     foreach ($event_notifications as $notification) {
         if ($notification['event_type'] > 0) {
             $event_types_text = $event_types[$notification['event_type']]['text'];
         } else {
             $notification['event_type'] = -1 * $notification['event_type'];
             if ($notification['send_interval'] > 0 || $notification['after_time'] > 0) {
                 $event_types_text = $event_types[$notification['event_type']]['canBeNegated'];
                 // get the negative event text
             } else {
                 $event_types_text = $event_types[$notification['event_type']]['text'];
                 //using the updated positive now value
             }
         }
         if ($notification['send_recipients'] == EfrontNotification::TRIGGERINGUSER) {
             $event_notification_recipients = _USERTRIGGERINGTHEEVENT;
         } else {
             if ($notification['send_recipients'] == EfrontNotification::ALLSYSTEMUSERS) {
                 $event_notification_recipients = _ALLSYSTEMUSERS;
             } else {
                 if ($notification['send_recipients'] == EfrontNotification::SYSTEMADMINISTRATOR) {
                     $event_notification_recipients = _SYSTEMADMINISTRATOR;
                 } else {
                     if ($notification['send_recipients'] == EfrontNotification::ALLLESSONUSERS) {
                         $event_notification_recipients = _ALLLESSONUSERS;
                     } else {
                         if ($notification['send_recipients'] == EfrontNotification::EXPLICITLYSEL) {
                             $event_notification_recipients = _EXPLICITLYSELECTED;
                         } else {
                             if ($notification['send_recipients'] == EfrontNotification::LESSONPROFESSORS) {
                                 $event_notification_recipients = _LESSONPROFESSORS;
                             } else {
                                 if ($notification['send_recipients'] == EfrontNotification::LESSONUSERSNOTCOMPLETED) {
                                     $event_notification_recipients = _LESSONUSERSNOTCOMPLETED;
                                 } else {
                                     if ($notification['send_recipients'] == EfrontNotification::COURSEPROFESSORS) {
                                         $event_notification_recipients = _COURSEPROFESSORS;
                                     } else {
                                         if ($notification['send_recipients'] == EfrontNotification::ALLCOURSEUSERS) {
                                             $event_notification_recipients = _ALLCOURSEUSERS;
                                         } else {
                                             if ($notification['send_recipients'] == EfrontNotification::USERSUPERVISORS) {
                                                 $event_notification_recipients = _USERSUPERVISORS;
                                             } else {
                                                 if ($notification['send_recipients'] == EfrontNotification::USERIMMEDIATESUPERVISORS) {
                                                     $event_notification_recipients = _USERIMMEDIATESUPERVISORS;
                                                 } else {
                                                     if ($notification['send_recipients'] == EfrontNotification::ALLSUPERVISORS) {
                                                         $event_notification_recipients = _ALLSUPERVISORS;
                                                     } else {
                                                         $event_notification_recipients = "";
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $allNotifications[] = array("id" => $notification['id'], "active" => $notification['active'], "event_notification_recipients" => $event_notification_recipients, "event_type" => $notification['event_type'], "event" => $event_types_text, "send_interval" => $notification['after_time'], "send_conditions" => $notification['send_conditions'], "subject" => $notification['subject']);
     }
     return $allNotifications;
 }
Ejemplo n.º 2
0
     $smarty->assign("T_MESSAGE_QUEUE_SIZE", $sending_queue_size[0]['count']);
     // This is almost buggy - cannot filter according to recipients count - significant optimization however
     foreach ($sending_queue_msgs as $key => $message) {
         $notification = new EfrontNotification($message);
         if ($notification->notification['recipient'] == "") {
             $sending_queue_msgs[$key]['recipients_count'] = sizeof($notification->getRecipients());
         }
     }
     if (!empty($sending_queue_msgs)) {
         $smarty->assign("T_QUEUE_MSGS", $sending_queue_msgs);
     }
     $smarty->display('administrator.tpl');
     exit;
 }
 $notifications = EfrontNotification::getAllNotifications();
 $events_table = EfrontEvent::getEventTypes(false);
 if (sizeof($notifications) > 0) {
     try {
         foreach ($notifications as $key => $notification) {
             // when
             if (isset($notification['event'])) {
                 $notifications[$key]['is_event'] = 1;
                 if ($notification['send_interval'] > 0) {
                     $days = $notification['send_interval'] / 86400;
                     if ($days < 1.0) {
                         $hours = $days * 24;
                         // The span is used for correct sorting of the table
                         $notifications[$key]['when'] = "<span style='display:none'>{$days}</span>" . $hours . " " . _HOURSAFTEREVENT;
                     } else {
                         $notifications[$key]['when'] = "<span style='display:none'>{$days}</span>" . $days . " " . _DAYSAFTEREVENT;
                     }
Ejemplo n.º 3
0
 /**
  * Trigger an event
  *
  * Denotes the triggering of an event in the eFront system
  * All functionalities that should take place during an event triggering
  * like logging, notification sending etc, should be defined here
  * <br/>Example:
  * <code>
  * $fields = array('name' => 'new event', 'languages_NAME' => 'english');
  * $event = EfrontEvent :: triggerEvent($fields);
  * </code>
  *
  * @param array $fields The new fields
  * @param boolean $send_notification Send notification or not
  * @return EfrontEvent the new event
  * @since 3.6.0
  * @access public
  */
 public static function triggerEvent($fields, $send_notification = true)
 {
     // Check and create all necessary fields
     if (!isset($fields['type'])) {
         throw new EfrontEventException(_NOEVENTCODEDEFINED, EfrontEventException::NOEVENTCODE_DEFINED);
     }
     //These are the mandatory fields. In case one of these is absent, fill it in with a default value
     // If no user is defined the currentuser will be used as user triggering the event
     if (!isset($fields['users_LOGIN'])) {
         if (isset($GLOBALS['currentUser'])) {
             $fields['users_LOGIN'] = $GLOBALS['currentUser']->user['login'];
             $fields['users_name'] = $GLOBALS['currentUser']->user['name'];
             $fields['users_surname'] = $GLOBALS['currentUser']->user['surname'];
         } else {
             $fields['users_LOGIN'] = $_SESSION['s_login'];
         }
     }
     // If a users login is defined, but without any name/surname fields, then get them from the DB
     if (!isset($fields['users_name']) || !isset($fields['users_surname'])) {
         $users_id = eF_getTableData("users", "name, surname", "login = '******'users_LOGIN'] . "'");
         if ($users_id) {
             $fields['users_name'] = $users_id[0]['name'];
             $fields['users_surname'] = $users_id[0]['surname'];
         } else {
             $fields['users_name'] = '';
             $fields['users_surname'] = '';
         }
     }
     // Events that canBePreceded might be triggered from now for the future - these events have their timestamp field already set
     if (!isset($fields['timestamp'])) {
         $fields['timestamp'] = time();
     }
     // Get the events array and get the information for this event type
     $event_types = EfrontEvent::getEventTypes();
     $type = $event_types[abs($fields['type'])];
     // the $fields['lessons_ID'] may refer to either courses or lessons according to the type of the event
     if ($type['category'] == "courses") {
         // Allow multiple course ids for each event
         if (is_array($fields['lessons_ID'])) {
             $event_courses = eF_getTableData("courses", "id, name", "id in (" . implode(",", $fields['lessons_ID']) . ")");
             $result = true;
             //$fields['lessons'] = array();
             $fields['lessons_name'] = "";
             foreach ($event_courses as $course) {
                 //$fields['lessons'][] = array("lessons_ID" => $course['id'], 'lessons_name' => $course['name']);
                 if ($fields['lessons_name'] != "") {
                     $fields['lessons_name'] .= ", ";
                 }
                 $fields['lessons_name'] .= $course['name'];
             }
         } else {
             // if not pre-defined
             if (!isset($fields['lessons_name']) || $fields['lessons_name'] == "") {
                 $event_courses = eF_getTableData("courses", "id, name", "id = '" . $fields['lessons_ID'] . "'");
                 $fields['lessons_name'] = $event_courses[0]['name'];
             }
         }
     } else {
         // Allow multiple lesson ids for each event
         if (isset($fields['lessons_ID']) && is_array($fields['lessons_ID'])) {
             $event_lessons = eF_getTableData("lessons", "id, name", "id in (" . implode(",", $fields['lessons_ID']) . ")");
             $result = true;
             //$fields['lessons'] = array();
             $fields['lessons_name'] = "";
             foreach ($event_lessons as $lesson) {
                 //$fields['lessons'][] = array("lessons_ID" => $lesson['id'], 'lessons_name' => $lesson['name']);
                 if ($fields['lessons_name'] != "") {
                     $fields['lessons_name'] .= ", ";
                 }
                 $fields['lessons_name'] .= $lesson['name'];
             }
         } else {
             // if not pre-defined
             if (isset($fields['lessons_ID']) && (!isset($fields['lessons_name']) || $fields['lessons_name'] == "")) {
                 $event_lessons = eF_getTableData("lessons", "id, name", "id = '" . $fields['lessons_ID'] . "'");
                 $fields['lessons_name'] = $event_lessons[0]['name'];
             }
         }
     }
     if ($fields['type'] == EfrontEvent::CONTENT_COMPLETION) {
         if (isset($fields['entity_ID']) && !isset($fields['entity_name'])) {
             $unit_info = new EfrontUnit($fields['entity_ID']);
             $fields['entity_name'] = $unit_info['name'];
         }
     }
     $replace = false;
     if (isset($fields['replace']) && $fields['replace'] === true) {
         $replace = true;
         unset($fields['replace']);
     }
     $create_negative = true;
     if (isset($fields['create_negative']) && $fields['create_negative'] === false) {
         $create_negative = false;
         unset($fields['create_negative']);
     }
     $delete_negative = false;
     if (isset($fields['delete_negative']) && $fields['delete_negative'] === true) {
         $delete_negative = true;
         unset($fields['delete_negative']);
     }
     // If social eFront module is enabled then log this event
     // Negative events like not visited, not completed etc are not to be logged
     if ($fields['type'] > 0 && (!isset($event_types[$fields['type']]['notToBeLogged']) || $event_types[$fields['type']]['notToBeLogged'] == 0)) {
         if (isset($fields['explicitly_selected'])) {
             $explicitly_selected = $fields['explicitly_selected'];
             unset($fields['explicitly_selected']);
         }
         EfrontEvent::logEvent($fields);
         if (isset($explicitly_selected)) {
             $fields['explicitly_selected'] = $explicitly_selected;
         }
     }
     // By default all notifications will be sent
     if ($send_notification) {
         $event = new EfrontEvent($fields);
         // this should create an event instance for our class
         $event->appendNewNotification($event_types, $replace, $create_negative, $delete_negative);
         // append this notification to the email queue
     }
 }