Example #1
0
 public function useCoupon($user, $payment, $productsList)
 {
     if (!$user instanceof EfrontUser) {
         $user = Efront::factory($user);
     }
     if (!$payment instanceof payments) {
         $payment = new payments($payment);
     }
     $fields = array('users_ID' => $user->user['id'], 'coupons_ID' => $this->{$this->entity}['id'], 'payments_ID' => $payment->{$payment->entity}['id'], 'products_list' => serialize($productsList), 'timestamp' => time());
     eF_insertTableData("users_to_coupons", $fields);
     EfrontEvent::triggerEvent(array("type" => EfrontEvent::COUPON_USAGE, "users_LOGIN" => $user->user['login'], "users_name" => $user->user['name'], "users_surname" => $user->user['surname'], "entity_name" => $this->{$this->entity}['code'], "entity_ID" => $this->{$this->entity}['id']));
 }
Example #2
0
 /**
  * Create news
  *
  * This function is used to create news
  * <br>Example:
  * <code>
  * $fields = array("title"       => $form -> exportValue('title'),
  *       "data"        => $form -> exportValue('data'),
  *       "timestamp"   => $from_timestamp,
  *		 "expire"      => $to_timestamp,
  *       "lessons_ID"  => isset($_SESSION['s_lessons_ID']) && $_SESSION['s_lessons_ID'] ? $_SESSION['s_lessons_ID'] : 0,
  *       "users_LOGIN" => $_SESSION['s_login']);
  *
  * $news = news :: create($fields, 0));
  *
  * </code>
  *
  * @param $fields An array of data
  * @param $sendEmail Whether to send the announcement as an email as well
  * @return news The new object
  * @since 3.6.0
  * @access public
  * @static
  */
 public static function create($fields = array(), $sendEmail = false)
 {
     $fields = array('title' => $fields['title'], 'data' => $fields['data'], 'timestamp' => $fields['timestamp'] ? $fields['timestamp'] : time(), 'expire' => $fields['expire'] ? $fields['expire'] : null, 'lessons_ID' => $fields['lessons_ID'], 'users_LOGIN' => $fields['users_LOGIN']);
     $newId = eF_insertTableData("news", $fields);
     $result = eF_getTableData("news", "*", "id=" . $newId);
     //We perform an extra step/query for retrieving data, sinve this way we make sure that the array fields will be in correct order (forst id, then name, etc)
     $news = new news($result[0]['id']);
     if ($news->news['lessons_ID']) {
         //EfrontEvent::triggerEvent(array("type" => EfrontEvent::NEW_LESSON_ANNOUNCEMENT, "users_LOGIN" => $fields['users_LOGIN'], "users_name" => $currentUser -> user['name'], "users_surname" => $currentUser -> user['surname'], "lessons_ID" => $fields['lessons_ID'], "entity_ID" => $id, "entity_name" => $news_content['title']), isset($_POST['email']));
         EfrontEvent::triggerEvent(array("type" => EfrontEvent::NEW_LESSON_ANNOUNCEMENT, "users_LOGIN" => $GLOBALS['currentUser']->user['login'], "users_name" => $GLOBALS['currentUser']->user['name'], "users_surname" => $GLOBALS['currentUser']->user['surname'], "lessons_ID" => $GLOBALS['currentLesson']->lesson['id'], "lessons_name" => $GLOBALS['currentLesson']->lesson['name'], "entity_name" => $fields['title'], "entity_ID" => $newId), $sendEmail);
     } else {
         //EfrontEvent::triggerEvent(array("type" => EfrontEvent::NEW_SYSTEM_ANNOUNCEMENT, "users_LOGIN" => $fields['users_LOGIN'], "users_name" => $currentUser -> user['name'], "users_surname" => $currentUser -> user['surname'], "entity_ID" => $id, "entity_name" => $news_content['title']), isset($_POST['email']));
         EfrontEvent::triggerEvent(array("type" => EfrontEvent::NEW_SYSTEM_ANNOUNCEMENT, "users_LOGIN" => $GLOBALS['currentUser']->user['login'], "users_name" => $GLOBALS['currentUser']->user['name'], "users_surname" => $GLOBALS['currentUser']->user['surname'], "lessons_name" => $GLOBALS['currentLesson']->lesson['name'], "entity_name" => $fields['title'], "entity_ID" => $newId), $sendEmail);
     }
     EfrontSearch::insertText($news->news['title'], $news->news['id'], "news", "title");
     EfrontSearch::insertText($news->news['data'], $news->news['id'], "news", "data");
     return $news;
 }
 /**
  * Create a new unit
  *
  * This function is used to create a new unit.
  * <br/>Example:
  * <code>
  * $fields = array('name' => 'new unit', 'ctg_type' => 'theory');
  * $unit = EfrontUnit :: createUnit($fields);
  * </code>
  *
  * @param array $fields The new unit fields
  * @return EfrontUnit The newly created unit
  * @since 3.5.0
  * @access public
  */
 public static function createUnit($fields = array())
 {
     if (!isset($fields['lessons_ID'])) {
         return false;
     }
     !isset($fields['name']) ? $fields['name'] = 'Default unit' : null;
     !isset($fields['timestamp']) ? $fields['timestamp'] = time() : null;
     !isset($fields['ctg_type']) ? $fields['ctg_type'] = 'theory' : null;
     if (!isset($fields['metadata'])) {
         $defaultMetadata = array('title' => $fields['name'], 'creator' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'publisher' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'contributor' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'date' => date("Y/m/d", $fields['timestamp']), 'type' => 'content');
         $fields['metadata'] = serialize($defaultMetadata);
     }
     $newId = eF_insertTableData("content", $fields);
     EfrontCache::getInstance()->deleteCache("content_tree:{$this['lessons_ID']}");
     $result = eF_getTableData("content", "*", "id=" . $newId);
     //We perform an extra step/query for retrieving data, sinve this way we make sure that the array fields will be in correct order (forst id, then name, etc)
     $unit = new EfrontUnit($result[0]);
     EfrontSearch::insertText(htmlspecialchars($fields['name'], ENT_QUOTES), $unit['id'], "content", "title");
     EfrontEvent::triggerEvent(array("type" => EfrontEvent::CONTENT_CREATION, "lessons_ID" => $fields['lessons_ID'], "entity_ID" => $unit['id'], "entity_name" => $fields['name']));
     return $unit;
 }
Example #4
0
 /**
  * Add users to group
  *
  * This function is used to add users to the current group
  * <br>Example:
  * <code>
  * $group = new EfrontGroup(2);
  * $group -> addUsers(array('jdoe', 'doej'));
  * </code>
  *
  * @param mixed $users An array of user logins or EfrontUser objects, or a single login or EfrontUser object
  * @return boolean True if everything is ok
  * @since 3.5.2
  * @access public
  */
 public function addUsers($users, $userTypeInCourses = 'student')
 {
     if (empty($users)) {
         return true;
     }
     $users = EfrontUser::verifyUsersList($users);
     $groupUsers = eF_getTableDataFlat("users_to_groups", "users_LOGIN", "groups_ID=" . $this->group['id']);
     $errors = array();
     foreach ($users as $key => $user) {
         if (!in_array($user, $groupUsers['users_LOGIN'], true)) {
             $fields[] = array('groups_ID' => $this->group['id'], 'users_LOGIN' => $user);
         }
     }
     eF_insertTableDataMultiple("users_to_groups", $fields);
     foreach ($fields as $utg) {
         EfrontEvent::triggerEvent(array("type" => EfrontEvent::NEW_ASSIGNMENT_TO_GROUP, "users_LOGIN" => $utg['users_LOGIN'], "entity_ID" => $this->group['id'], "entity_name" => $this->group['name']));
     }
     foreach ($this->getCourses(true, true) as $course) {
         try {
             $course->addUsers($users, $userTypeInCourses, 1);
         } catch (Exception $e) {
             if ($e->getCode() == EfrontCourseException::MAX_USERS_LIMIT) {
                 $max_users_errors[] = $e->getMessage();
             } else {
                 $errors[] = $e->getMessage();
             }
         }
     }
     foreach ($this->getLessons(true, true) as $lesson) {
         try {
             $lesson->addUsers($users, $userTypeInCourses, 1);
         } catch (Exception $e) {
             if ($e->getCode() == EfrontCourseException::MAX_USERS_LIMIT) {
                 $max_users_errors[] = $e->getMessage();
             } else {
                 $errors[] = $e->getMessage();
             }
         }
     }
     if (!empty($errors)) {
         throw new EfrontGroupException(implode("<br>", $errors), EfrontGroupException::ASSIGNMENT_ERROR);
     }
     if (!empty($max_users_errors)) {
         return $max_users_errors;
     }
     return true;
 }
         }
         if ($form->exportValue('system_avatar') == "none") {
             $selectedAvatar = 'unknown_small.png';
         } else {
             if ($form->exportValue('system_avatar') != "") {
                 $selectedAvatar = $form->exportValue('system_avatar');
             }
         }
         if (isset($selectedAvatar)) {
             $selectedAvatar = $avatarsFileSystemTree->seekNode(G_SYSTEMAVATARSPATH . $selectedAvatar);
             $newList = FileSystemTree::importFiles($selectedAvatar['path']);
             //Import the file to the database, so we can access it with view_file
             $editedUser->user['avatar'] = key($newList);
         }
     }
     EfrontEvent::triggerEvent(array("type" => EfrontEvent::AVATAR_CHANGE, "users_LOGIN" => $editedUser->user['login'], "users_name" => $editedUser->user['name'], "users_surname" => $editedUser->user['surname'], "lessons_ID" => 0, "lessons_name" => "", "entity_ID" => $editedUser->user['avatar']));
 }
 $editedUser->persist();
 if (G_VERSIONTYPE == 'enterprise') {
     #cpp#ifdef ENTERPRISE
     if (isset($_GET['add_user'])) {
         $editedEmployee = EfrontHcdUser::createUser(array('users_login' => $editedUser->user['login']));
         if ($currentEmployee->isSupervisor() && !EfrontUser::isOptionVisible('show_unassigned_users_to_supervisors')) {
             //if supervisors can't see unassigned users, then attach this new user to the supervisor's firts branch and job
             $branch = new EfrontBranch(current($currentEmployee->getSupervisedBranchesRecursive()));
             $nospecific = false;
             foreach ($branch->getJobDescriptions() as $value) {
                 if ($value['description'] == _NOSPECIFICJOB) {
                     $nospecific = $value['job_description_ID'];
                 }
             }
 /**
  * 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
     }
 }
Example #7
0
 public function persist()
 {
     parent::persist();
     $sourceUnit = new EfrontUnit($this->comments['content_ID']);
     EfrontEvent::triggerEvent(array("type" => EfrontEvent::NEW_COMMENT_WRITING, "lessons_ID" => $sourceUnit['lessons_ID'], "entity_ID" => $this->comments['content_ID'], "entity_name" => $sourceUnit['name']));
 }
Example #8
0
                 if ($_GET['ldap']) {
                     $newUser->login($_SESSION['ldap_user_pwd'], $encrypted);
                     unset($_SESSION['ldap_user_pwd']);
                 } else {
                     $newUser->login($newUser->user['password'], $encrypted);
                 }
                 if ($GLOBALS['configuration']['force_change_password'] && !$newUser->isLdapUser && $newUser->user['need_pwd_change']) {
                     eF_redirect("index.php?ctg=password_change");
                 } else {
                     if ($GLOBALS['configuration']['show_license_note'] && $newUser->user['viewed_license'] == 0) {
                         eF_redirect("index.php?ctg=agreement&message=" . urlencode($message) . "&message_type=" . $message_type);
                     } else {
                         if ($_SESSION['login_mode']) {
                             eF_redirect("index.php?ctg=checkout&checkout=1&message=" . urlencode($message) . "&message_type=" . $message_type);
                         } else {
                             EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_VISITED, "users_LOGIN" => $newUser->user['login'], "users_name" => $newUser->user['name'], "users_surname" => $newUser->user['surname']));
                             loginRedirect($newUser->user['user_type'], urlencode($message), $message_type);
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
             $message = $e->getMessage() . ' &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
             $message_type = failure;
         }
     }
 }
 $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
 $renderer->setRequiredTemplate('{$html}{if $required}
         &nbsp;<span class = "formRequired">*</span>
Example #9
0
         $result = eF_getTableData("users", "login, avatar", "login IN ('" . implode("','", $all_related_users) . "')");
         $users_avatars = array();
         foreach ($result as $avatar) {
             $users_avatars[$avatar['login']] = $avatar['avatar'];
         }
     }
     $myEvents = EfrontEvent::getEvents($all_related_users, true, 1000);
 } else {
     if (isset($_GET['ajax'])) {
         $result = eF_getTableData("users", "login, avatar");
         $users_avatars = array();
         foreach ($result as $avatar) {
             $users_avatars[$avatar['login']] = $avatar['avatar'];
         }
     }
     $myEvents = EfrontEvent::getEventsForAllUsers(true, 1000);
 }
 $allModules = eF_loadAllModules();
 $eventMessages = array();
 foreach ($myEvents as $key => $event) {
     if ($myEvents[$key]->createMessage($allModules)) {
         if (strpos($myEvents[$key]->event['time'], "-") === false) {
             // Added this to prevent events that changed time in the future as project expiration
             $new_event = array("time" => $myEvents[$key]->event['time'], "message" => $myEvents[$key]->event['message']);
             if ($myEvents[$key]->event['editlink']) {
                 $new_event['editlink'] = $myEvents[$key]->event['editlink'];
             }
             if ($myEvents[$key]->event['deletelink']) {
                 $new_event['deletelink'] = $myEvents[$key]->event['deletelink'];
             }
             // Keep that for the avatar searching after the filtering
 /**
  * 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;
 }
Example #11
0
 /**
  * Handle AJAX actions
  *
  * This function is used to perform the necessary ajax actions,
  * that may be used in tests
  * <br/>Example:
  * <code>
  * $result     = eF_getTableData("completed_tests", "*", "id=".$_GET['show_solved_test']);
  * $showTest   = unserialize($result[0]['test']);
  * $status     = $showTest -> getStatus($result[0]['users_LOGIN']);
  * $testString = $showTest -> toHTMLQuickForm(new HTML_Quickform(), false, true, true);
  * $testString = $showTest -> toHTMLSolved($testString, true);
  * if (isset($_GET['ajax'])) {
  *     $showTest -> handleAjaxActions();
  * }
  * </code>
  *
  * @since 3.5.2
  * @access public
  */
 public function handleAjaxActions()
 {
     try {
         if (isset($_GET['test_score'])) {
             if (mb_strpos($_GET['test_score'], ",") !== false) {
                 $_GET['test_score'] = str_replace(",", ".", $_GET['test_score']);
             }
             if (is_numeric($_GET['test_score']) && $_GET['test_score'] <= 100 && $_GET['test_score'] >= 0) {
                 $this->completedTest['score'] = $_GET['test_score'];
                 foreach ($this->questions as $id => $question) {
                     if ($question->pending) {
                         $this->questions[$id]->pending = 0;
                         $this->questions[$id]->score = $this->completedTest['score'];
                     }
                 }
                 if ($this->test['mastery_score'] && $this->test['mastery_score'] > $this->completedTest['score']) {
                     $this->completedTest['status'] = 'failed';
                 } else {
                     if ($this->test['mastery_score'] && $this->test['mastery_score'] <= $this->completedTest['score']) {
                         $this->completedTest['status'] = 'passed';
                     }
                 }
                 $this->completedTest['pending'] = 0;
                 $this->save();
                 $result = eF_getTableData("completed_tests", "archive", "id=" . $this->completedTest['id']);
                 if (!$result[0]['archive']) {
                     $testUser = EfrontUserFactory::factory($this->completedTest['login']);
                     if ($this->completedTest['status'] == 'failed') {
                         $testUser->setSeenUnit($this->test['content_ID'], $this->test['lessons_ID'], 0);
                     } else {
                         $testUser->setSeenUnit($this->test['content_ID'], $this->test['lessons_ID'], 1);
                     }
                 }
                 echo $this->completedTest['status'];
             } else {
                 throw new EfrontTestException(_INVALIDSCORE . ': ' . $_GET['test_score'], EfrontTestException::INVALID_SCORE);
             }
             exit;
         } else {
             if (isset($_GET['test_feedback'])) {
                 $this->completedTest['feedback'] = $_GET['test_feedback'];
                 $this->save();
                 echo $_GET['test_feedback'];
                 exit;
             } else {
                 if (isset($_GET['redo_test']) && eF_checkParameter($_GET['redo_test'], 'id')) {
                     $result = eF_getTableData("completed_tests", "tests_ID, users_LOGIN", "id=" . $_GET['redo_test']);
                     $test = new EfrontTest($result[0]['tests_ID']);
                     $test->redo($result[0]['users_LOGIN']);
                     exit;
                 } else {
                     if (isset($_GET['redo_wrong_test']) && eF_checkParameter($_GET['redo_wrong_test'], 'id')) {
                         $result = eF_getTableData("completed_tests", "tests_ID, users_LOGIN", "id=" . $_GET['redo_wrong_test']);
                         $test = new EfrontTest($result[0]['tests_ID']);
                         $test->redoOnlyWrong($result[0]['users_LOGIN']);
                         exit;
                     } else {
                         if (isset($_GET['delete_done_test'])) {
                             if (isset($_GET['all'])) {
                                 $this->undo($this->completedTest['login']);
                                 //eF_deleteTableData("completed_tests", "users_LOGIN='******'login']."' and tests_ID=".$this -> completedTest['testsId']);
                             } else {
                                 $this->undo($this->completedTest['login'], $this->completedTest['id']);
                                 //eF_deleteTableData("completed_tests", "id=".$this -> completedTest['id']);
                             }
                             exit;
                         } else {
                             if (isset($_GET['question_score'])) {
                                 if (mb_strpos($_GET['question_score'], ",") !== false) {
                                     $_GET['question_score'] = str_replace(",", ".", $_GET['question_score']);
                                 }
                                 if (in_array($_GET['question'], array_keys($this->questions))) {
                                     if (is_numeric($_GET['question_score']) && $_GET['question_score'] <= 100 && $_GET['question_score'] >= 0) {
                                         $this->questions[$_GET['question']]->score = $_GET['question_score'];
                                         $this->questions[$_GET['question']]->scoreInTest = round($_GET['question_score'] * $this->getQuestionWeight($_GET['question']), 3);
                                         $this->questions[$_GET['question']]->pending = 0;
                                         $score = 0;
                                         foreach ($this->questions as $question) {
                                             $this->completedTest['scoreInTest'][$question->question['id']] = $question->scoreInTest;
                                             $score += $question->scoreInTest;
                                         }
                                         $this->completedTest['score'] = round($score, 2);
                                         $testUser = EfrontUserFactory::factory($this->completedTest['login']);
                                         if ($this->test['mastery_score'] && $this->test['mastery_score'] > $this->completedTest['score']) {
                                             if ($this->getPotentialScore() < $this->test['mastery_score']) {
                                                 $this->completedTest['status'] = 'failed';
                                                 $flag = 0;
                                                 //$testUser -> setSeenUnit($this -> test['content_ID'], $this -> test['lessons_ID'], 0);
                                             }
                                         } else {
                                             if ($this->test['mastery_score'] && $this->test['mastery_score'] <= $this->completedTest['score']) {
                                                 $this->completedTest['status'] = 'passed';
                                                 $flag = 1;
                                                 //$testUser -> setSeenUnit($this -> test['content_ID'], $this -> test['lessons_ID'], 1);
                                             }
                                         }
                                         $this->completedTest['pending'] = 0;
                                         foreach ($this->getQuestions(true) as $question) {
                                             if ($question->pending) {
                                                 $this->completedTest['pending'] = 1;
                                             }
                                         }
                                         try {
                                             $lesson = new EfrontLesson($this->test['lessons_ID']);
                                             $lesson_name = $lesson->lesson['name'];
                                         } catch (EfrontLessonException $e) {
                                             $lesson_name = _SKILLGAPTESTS;
                                         }
                                         if (!$this->completedTest['pending']) {
                                             EfrontEvent::triggerEvent(array("type" => EfrontEvent::TEST_MARKED, "users_LOGIN" => $this->completedTest['login'], "lessons_ID" => $this->test['lessons_ID'], "lessons_name" => $lesson_name, "entity_ID" => $this->test['id'], "entity_name" => $this->test['name']));
                                         }
                                         if ($this->completedTest['status'] == 'failed' && $this->completedTest['pending'] != 1) {
                                             EfrontEvent::triggerEvent(array("type" => EfrontEvent::TEST_FAILURE, "users_LOGIN" => $this->completedTest['login'], "lessons_ID" => $this->test['lessons_ID'], "lessons_name" => $lesson_name, "entity_ID" => $this->test['id'], "entity_name" => $this->test['name']));
                                         }
                                         $this->save();
                                         $testUser->setSeenUnit($this->test['content_ID'], $this->test['lessons_ID'], $flag);
                                         echo json_encode($this->completedTest);
                                     } else {
                                         throw new EfrontTestException(_INVALIDSCORE . ': ' . $_GET['test_score'], EfrontTestException::INVALID_SCORE);
                                     }
                                 } else {
                                     throw new EfrontTestException(_INVALIDID . ': ' . $_GET['question'], EfrontTestException::QUESTION_NOT_EXISTS);
                                 }
                                 exit;
                             } else {
                                 if (isset($_GET['question_feedback'])) {
                                     if (in_array($_GET['question'], array_keys($this->questions))) {
                                         $this->questions[$_GET['question']]->feedback = $_GET['question_feedback'];
                                         $this->save();
                                         echo $_GET['question_feedback'];
                                     } else {
                                         throw new EfrontTestException(_INVALIDID . ': ' . $_GET['question'], EfrontTestException::QUESTION_NOT_EXISTS);
                                     }
                                     exit;
                                 } else {
                                     if (isset($_GET['delete_file'])) {
                                         $file = new EfrontFile($_GET['delete_file']);
                                         $testDirectory = $this->getDirectory();
                                         if (strpos($file['path'], $testDirectory['path']) !== false) {
                                             $file->delete();
                                         }
                                         exit;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         handleAjaxExceptions($e);
     }
 }
 /**
  * Add event to eFront's events log
  *
  * This function enables module to provide events to the log
  * Events should be UNIQUELY defined INSIDE the module
  *
  * All data required for the appearance of the log message (provided by the getEventMessage function)
  * should be defined in the second argument array.
  *
  * <br/>Example:
  * <code>
  * $define("NEW_MODULE_ENTITY_INSERTION", 1);
  * $module -> addEvent(NEW_MODULE_ENTITY_INSERTION, array("id" => $id, "title" => $title));
  * </code>
  * The $data parameter is the information required by the getEventMessage function to display the related message
  * for this event.
  * Note:
  * Field 'timestamp' is automatically completed
  * If fields "users_LOGIN", "users_name" and "users_surname" are not defined, then the currentUser's info will be used
  * If fields "lessons_ID" and "lessons_name" are defined, then this event will also be related with that lesson
  * The array might contain any other fields. However, the exact same ones need to be used by getEventMessage
  *
  * @param integer $type The unique code of the event inside the particular module scope
  * @param array $data The information required by the getEventMessage function to display the related message
  * for this event.
  * @return EfrontEvent the result of the event insertion to the database or false if arguments are not correct
  * @since 3.6.0
  * @access public
  */
 public function addEvent($type, $data)
 {
     $fields = array();
     // All module related events have the same offset + the particular event's type
     $fields['type'] = EfrontEvent::MODULE_BASE_TYPE_CODE + (int) $type;
     // This should not exist normally, just in case
     unset($data['type']);
     // The discimination between events from different modules with the same type is made
     // by the entity_ID field, which is the className of the implicated module
     $fields['entity_ID'] = $this->className;
     // Mandatory users_LOGIN, users_surname, users_name fields
     if (isset($data['users_LOGIN'])) {
         $fields['users_LOGIN'] = $data['users_LOGIN'];
         if (isset($data['surname']) && isset($data['name'])) {
             $fields['users_surname'] = $data['surname'];
             $fields['users_name'] = $data['name'];
         } else {
             $eventsUser = EfrontUserFactory::factory($data['users_LOGIN']);
             $fields['users_surname'] = $eventsUser->user['surname'];
             $fields['users_name'] = $eventsUser->user['name'];
         }
         // We remove data fields, to serialize all remaining ones into the entity_name field
         unset($data['users_LOGIN']);
         unset($data['users_surname']);
         unset($data['users_name']);
     } else {
         $currentUser = $this->getCurrentUser();
         $fields['users_LOGIN'] = $currentUser->user['login'];
         $fields['users_surname'] = $currentUser->user['surname'];
         $fields['users_name'] = $currentUser->user['name'];
     }
     // The lessons_ID field associates an event with a specific lesson
     if (isset($data['lessons_ID'])) {
         $fields['lessons_ID'] = $data['lessons_ID'];
         if (isset($data['lessons_name'])) {
             $fields['lessons_name'] = $data['lessons_name'];
             unset($data['lessons_name']);
         } else {
             $lesson = new EfrontLesson($fields['lessons_ID']);
             $fields['lessons_name'] = $lesson->lesson['name'];
         }
         // We remove data fields, to serialize all remaining ones into the entity_name field
         unset($data['lessons_ID']);
     }
     // Serialize all remaining user provided data for this event, with the same labels as the ones given
     if (!empty($data)) {
         $fields['entity_name'] = serialize($data);
     }
     // Finally get current time
     $fields['timestamp'] = time();
     return EfrontEvent::triggerEvent($fields);
 }
Example #13
0
 /**
  * 
  * @param $fields
  * @return unknown_type
  */
 public static function create($fields = array())
 {
     $new_id = eF_insertTableData("f_poll", $fields);
     EfrontSearch::insertText($fields['title'], $new_id, "f_poll", "title");
     if (mb_strlen($fields['question']) > 3) {
         EfrontSearch::insertText(strip_tags($fields['question']), $new_id, "f_poll", "data");
     }
     $post_lesson_id = $post_lesson_name = null;
     $result = eF_getTableData("lessons l, f_forums f", "l.id,l.name", "l.id=f.lessons_ID and f.id={$fields['f_forums_ID']}");
     if (!empty($result)) {
         $post_lesson_id = $result[0]['id'];
         $post_lesson_name = $result[0]['name'];
     }
     // Timelines add event
     EfrontEvent::triggerEvent(array("type" => EfrontEvent::NEW_POLL, "users_LOGIN" => $_SESSION['s_login'], "lessons_ID" => $post_lesson_id, "lessons_name" => $post_lesson_name, "entity_ID" => $new_id, "entity_name" => $fields['title']));
 }
Example #14
0
 /**
  * Create Payment
  *
  * This function is used to create a new payment entry
  *
  * @param array $fields The payment properties
  * @return payment The created payment
  * @since 3.6.0
  * @access public
  */
 public static function create($fields = array())
 {
     $fields['lessons'] = array_filter($fields['lessons'], 'is_numeric');
     if (isset($fields['lessons']) && sizeof($fields['lessons']) > 0) {
         $lessonNames = eF_getTableDataFlat("lessons", "name", "id in (" . implode(",", $fields['lessons']) . ")");
     }
     $fields['courses'] = array_filter($fields['courses'], 'is_numeric');
     if (isset($fields['courses']) && sizeof($fields['courses']) > 0) {
         $courseNames = eF_getTableDataFlat("courses", "name", "id in (" . implode(",", $fields['courses']) . ")");
     }
     !isset($fields['charset']) or $fields['comments'] = iconv($fields['charset'], "UTF-8", $fields['comments']);
     $fields = array('timestamp' => isset($fields['timestamp']) && eF_checkParameter($fields['timestamp'], 'timestamp') ? $fields['timestamp'] : time(), 'users_LOGIN' => isset($fields['users_LOGIN']) && eF_checkParameter($fields['users_LOGIN'], 'login') ? $fields['users_LOGIN'] : $_SESSION['s_login'], 'amount' => isset($fields['amount']) && is_numeric($fields['amount']) && $fields['amount'] > 0 ? $fields['amount'] : 0, 'status' => isset($fields['status']) && $fields['status'] ? $fields['status'] : 'completed', 'txn_id' => $fields['txn_id'], 'comments' => $fields['comments'], 'method' => isset($fields['method']) && in_array($fields['method'], array_keys(self::$methods)) ? $fields['method'] : 'manual');
     $user = EfrontUserFactory::factory($fields['users_LOGIN']);
     if ($fields['method'] == 'paypal') {
         //@todo: get corresponding paypal_data id
         $eventType = EfrontEvent::NEW_PAYPAL_PAYMENT;
     } else {
         if ($fields['method'] == 'balance') {
             $eventType = EfrontEvent::NEW_BALANCE_PAYMENT;
         } else {
             if ($fields['method'] == 'manual') {
                 $eventType = EfrontEvent::NEW_MANUAL_PAYMENT;
             } else {
                 $eventType = false;
             }
         }
     }
     $newId = eF_insertTableData("payments", $fields);
     $result = eF_getTableData("payments", "*", "id=" . $newId);
     //We perform an extra step/query for retrieving data, since this way we make sure that the array fields will be in correct order (first id, then name, etc)
     $payment = new payments($result[0]['id']);
     if ($eventType) {
         $event = array("type" => $eventType, "users_LOGIN" => $user->user['login'], "users_name" => $user->user['name'], "users_surname" => $user->user['surname'], "entity_ID" => $newId);
         if (isset($lessonNames) && !empty($lessonNames)) {
             $event['lessons_name'] = _LESSONS . ': ' . implode(",", $lessonNames['name']) . '<br>';
         }
         if (isset($courseNames) && !empty($courseNames)) {
             $event['lessons_name'] .= _COURSES . ': ' . implode(",", $courseNames['name']);
         }
         if ($fields['credit']) {
             $event['lessons_name'] .= _BALANCE . ': ' . $fields['credit'];
         }
         EfrontEvent::triggerEvent($event);
     }
     return $payment;
 }
Example #15
0
        if ($fromTimestamp < $toTimestamp) {
            $currentLesson->lesson['from_timestamp'] = $fromTimestamp;
            $currentLesson->lesson['to_timestamp'] = $toTimestamp;
            //$currentLesson -> lesson['shift']          = $form -> exportValue('shift') ? 1 : 0;
            $smarty->assign("T_FROM_TIMESTAMP", $currentLesson->lesson['from_timestamp']);
            $smarty->assign("T_TO_TIMESTAMP", $currentLesson->lesson['to_timestamp']);
            // Note: the semantics of the following event triggers: these triggerings are used to create future "before event" notifications now
            // For this reason the timestamp is set to the values of the lesson
            eF_deleteTableData("notifications", "id_type_entity LIKE '%_" . -1 * EfrontEvent::LESSON_PROGRAMMED_START . "_" . $lesson->lesson['id'] . "'");
            eF_deleteTableData("notifications", "id_type_entity LIKE '%_" . -1 * EfrontEvent::LESSON_PROGRAMMED_EXPIRY . "_" . $lesson->lesson['id'] . "'");
            eF_deleteTableData("events", "lessons_ID = " . $currentLesson->lesson['id'] . " AND (type = '" . EfrontEvent::LESSON_PROGRAMMED_START . "' OR type = '" . EfrontEvent::LESSON_PROGRAMMED_EXPIRY . "')");
            $currentLesson->persist();
            if ($fromTimestamp > time()) {
                EfrontEvent::triggerEvent(array("type" => EfrontEvent::LESSON_PROGRAMMED_START, "timestamp" => $fromTimestamp, "lessons_ID" => $currentLesson->lesson['id'], "lessons_name" => $currentLesson->lesson['name']));
            }
            if ($toTimestamp > time()) {
                EfrontEvent::triggerEvent(array("type" => EfrontEvent::LESSON_PROGRAMMED_EXPIRY, "timestamp" => $toTimestamp, "lessons_ID" => $currentLesson->lesson['id'], "lessons_name" => $currentLesson->lesson['name']));
            }
            $message = _OPERATIONCOMPLETEDSUCCESSFULLY;
            $message_type = 'success';
        } else {
            $message = _ENDDATEMUSTBEBEFORESTARTDATE;
            $message_type = 'failure';
        }
    }
}
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
$form->setRequiredNote(_REQUIREDNOTE);
$form->accept($renderer);
$smarty->assign('T_ADD_PERIOD_FORM', $renderer->toArray());
Example #16
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;
                     }
 private function sendNotificationsRemoveLessonUsers($users)
 {
     foreach ($users as $user) {
         EfrontEvent::triggerEvent(array("type" => EfrontEvent::LESSON_REMOVAL, "users_LOGIN" => $user, "lessons_ID" => $this->lesson['id'], "lessons_name" => $this->lesson['name']));
     }
 }
Example #18
0
 if ($form->isSubmitted() && $form->validate() && !$currentProject->expired) {
     try {
         $projectDirectory = G_UPLOADPATH . $currentUser->user['login'] . '/projects';
         if (!is_dir($projectDirectory)) {
             EfrontDirectory::createDirectory($projectDirectory);
         }
         $projectDirectory = G_UPLOADPATH . $currentUser->user['login'] . '/projects/' . $currentProject->project['id'];
         if (!is_dir($projectDirectory)) {
             EfrontDirectory::createDirectory($projectDirectory);
         }
         $filesystem = new FileSystemTree($projectDirectory);
         $uploadedFile = $filesystem->uploadFile('filename', $projectDirectory);
         //$uploadedFile -> rename($uploadedFile['directory'].'/project_'.$currentProject -> project['id'].'.'.$uploadedFile['extension']);
         $fields_update = array("filename" => $uploadedFile['id'], "upload_timestamp" => time());
         eF_updateTableData("users_to_projects", $fields_update, "users_LOGIN='******'login'] . "' AND projects_ID=" . $_GET['view_project']);
         EfrontEvent::triggerEvent(array("type" => EfrontEvent::PROJECT_SUBMISSION, "users_LOGIN" => $currentUser->user['login'], "lessons_ID" => $currentLesson->lesson['id'], "lessons_name" => $currentLesson->lesson['name'], "entity_ID" => $currentProject->project['id'], "entity_name" => $currentProject->project['title']));
         eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=projects&view_project=" . $_GET['view_project'] . "&message=" . urlencode(_FILEUPLOADED) . "&message_type=success");
     } catch (EfrontFileException $e) {
         $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
         $message = _SOMEPROBLEMOCCURED . ': ' . $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
         $message_type = 'failure';
     }
 } elseif ($currentProject->expired) {
     $message = _PROJECTEXPIRED;
     $message_type = 'failure';
 }
 $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
 $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
 $form->setRequiredNote(_REQUIREDNOTE);
 $form->accept($renderer);
 $smarty->assign('T_UPLOAD_PROJECT_FORM', $renderer->toArray());
Example #19
0
 /**
  * Check if a course must be reset because of certificate expiry or 'before expiry' reset
  *
  * @param mixed lesson A lesson id or an EfrontLesson object
  * @since 3.6.3
  * @access public
  */
 public static function checkCertificateExpire()
 {
     $courses = eF_getTableData("courses", "id,reset_interval,reset", "certificate_expiration !=0");
     $notifications = eF_getTableData("event_notifications", "id,event_type,after_time,send_conditions", "event_type=-56 and active=1");
     $notifications_on_event = eF_getTableData("event_notifications", "id,event_type,after_time,send_conditions", "event_type=56 and active=1");
     foreach ($courses as $value) {
         $course = new EfrontCourse($value['id']);
         $constraints = array('archive' => false, 'active' => true, 'condition' => 'issued_certificate != ""');
         $users = $course->getStudentUsers(false, $constraints);
         foreach ($users as $user) {
             $login = $user['login'];
             $dateTable = unserialize($user['issued_certificate']);
             if (eF_checkParameter($dateTable['date'], 'timestamp')) {
                 //new way that issued date saves
                 $expirationArray = convertTimeToDays($course->course['certificate_expiration']);
                 $expirationTimestamp = getCertificateExpirationTimestamp($dateTable['date'], $expirationArray);
                 if ($course->course['reset_interval'] != 0) {
                     $resetArray = convertTimeToDays($value['reset_interval']);
                     $resetTimestamp = getCertificateResetTimestamp($expirationTimestamp, $resetArray);
                     if ($resetTimestamp < time()) {
                         $user = EfrontUserFactory::factory($user);
                         $user->resetProgressInCourse($course, true, true);
                     }
                 }
                 if ($course->course['reset']) {
                     //If student completed again the course with reset_interval, he has a new expire date so he will not be reset,(so it is not elseif)
                     if ($expirationTimestamp < time()) {
                         if (!$user instanceof EfrontUser) {
                             $user = EfrontUserFactory::factory($user);
                         }
                         $user->resetProgressInCourse($course, true);
                         foreach ($notifications_on_event as $notification) {
                             $send_conditions = unserialize($notification['send_conditions']);
                             $courses_ID = $send_conditions['courses_ID'];
                             if ($courses_ID == $value['id'] || $courses_ID == 0) {
                                 if ($notification['after_time'] == 0) {
                                     EfrontEvent::triggerEvent(array("type" => EfrontEvent::COURSE_CERTIFICATE_EXPIRY, "users_LOGIN" => $user->user['login'], "lessons_ID" => $course->course['id'], "lessons_name" => $course->course['name'], 'create_negative' => false));
                                 }
                             }
                         }
                     }
                 }
                 if (!$course->course['reset'] && !$course->course['reset_interval']) {
                     if ($expirationTimestamp < time()) {
                         eF_updateTableData("users_to_courses", array("issued_certificate" => ""), "users_LOGIN='******' and courses_ID = " . $course->course['id']);
                         foreach ($notifications_on_event as $notification) {
                             $send_conditions = unserialize($notification['send_conditions']);
                             $courses_ID = $send_conditions['courses_ID'];
                             if ($courses_ID == $value['id'] || $courses_ID == 0) {
                                 if ($notification['after_time'] == 0) {
                                     EfrontEvent::triggerEvent(array("type" => EfrontEvent::COURSE_CERTIFICATE_REVOKE, "users_LOGIN" => $login, "lessons_ID" => $course->course['id'], "lessons_name" => $course->course['name'], "create_negative" => false));
                                 }
                             }
                         }
                     }
                 }
                 foreach ($notifications as $notification) {
                     $send_conditions = unserialize($notification['send_conditions']);
                     $courses_ID = $send_conditions['courses_ID'];
                     if ($courses_ID == $value['id'] || $courses_ID == 0) {
                         if ($notification['after_time'] < 0) {
                             $resetArray = convertTimeToDays(abs($notification['after_time']));
                             $resetTimestamp = getCertificateResetTimestamp($expirationTimestamp, $resetArray);
                             // in order notification to be sent one (not every day after $resetTimestamp)
                             if ($GLOBALS['configuration']['last_reset_certificate'] < $resetTimestamp && $resetTimestamp < time() && $expirationTimestamp > time()) {
                                 EfrontEvent::triggerEvent(array("type" => -1 * EfrontEvent::COURSE_CERTIFICATE_EXPIRY, "users_LOGIN" => $login, "lessons_ID" => $course->course['id'], "lessons_name" => $course->course['name'], "create_negative" => false));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Create a new project
  *
  * This function is used to create a new project,
  * based on the specified values.
  * <br/>Example:
  * <code>
  * </code>
  *
  * @param array $fields The new project properties
  * @return EfrontProject The new project
  * @since 3.5.0
  * @access public
  */
 public static function createProject($fields = array())
 {
     $projectMetadata = array('title' => $fields['title'], 'creator' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'publisher' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'contributor' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'date' => date("Y/m/d", time()), 'type' => 'project');
     $fields['metadata'] = serialize($projectMetadata);
     $newId = eF_insertTableData("projects", $fields);
     $result = eF_getTableData("projects", "*", "id=" . $newId);
     //We perform an extra step/query for retrieving data, sinve this way we make sure that the array fields will be in correct order (forst id, then name, etc)
     $project = new EfrontProject($result[0]['id']);
     EfrontEvent::triggerEvent(array("type" => EfrontEvent::PROJECT_CREATION, "users_LOGIN" => $GLOBALS['currentUser']->user['login'], "users_name" => $GLOBALS['currentUser']->user['name'], "users_surname" => $GLOBALS['currentUser']->user['surname'], "lessons_ID" => $GLOBALS['currentLesson']->lesson['id'], "lessons_name" => $GLOBALS['currentLesson']->lesson['name'], "entity_name" => $fields['title'], "entity_ID" => $newId));
     return $project;
 }
 /**
  * Set seen unit
  *
  * This function is used to set the designated unit as seen or not seen,
  * according to $seen parameter. It also sets current unit to be the seen
  * unit, if we are setting a unit as seen. Otherwise, the current unit is
  * either leaved unchanged, or, if it matches the unset unit, it points
  * to another seen unit.
  * <br/>Example:
  * <code>
  * $user -> setSeenUnit(32, 2, true);						   //Set the unit with id 32 in lesson 2 as seen
  * $user -> setSeenUnit(32, 2, false);						  //Set the unit with id 32 in lesson 2 as not seen
  * </code>
  * From version 3.5.2 and above, this function also sets the lesson as completed, if the conditions are met
  *
  * @param mixed $unit The unit to set status for, can be an id or an EfrontUnit object
  * @param mixed $lesson The lesson that the unit belongs to, can be an id or an EfrontLesson object
  * @param boolean $seen Whether to set the unit as seen or not
  * @return boolean true if the lesson was completed as well
  * @since 3.5.0
  * @access public
  */
 public function setSeenUnit($unit, $lesson, $seen)
 {
     if (isset($this->coreAccess['content']) && $this->coreAccess['content'] != 'change') {
         //If user type is not plain 'student' and is not set to 'change' mode, do nothing
         return true;
     }
     if ($unit instanceof EfrontUnit) {
         //Check validity of $unit
         $unit = $unit['id'];
     } elseif (!eF_checkParameter($unit, 'id')) {
         throw new EfrontContentException(_INVALIDID . ": {$unit}", EfrontContentException::INVALID_ID);
     }
     if ($lesson instanceof EfrontLesson) {
         //Check validity of $lesson
         $lesson = $lesson->lesson['id'];
     } elseif (!eF_checkParameter($lesson, 'id')) {
         throw new EfrontLessonException(_INVALIDID . ": {$lesson}", EfrontLessonException::INVALID_ID);
     }
     $lessons = $this->getLessons();
     if (!in_array($lesson, array_keys($lessons))) {
         //Check if the user is actually registered in this lesson
         throw new EfrontUserException(_USERDOESNOTHAVETHISLESSON . ": " . $lesson, EfrontUserException::USER_NOT_HAVE_LESSON);
     }
     $result = eF_getTableData("users_to_lessons", "done_content, current_unit", "users_LOGIN='******'login'] . "' and lessons_ID=" . $lesson);
     sizeof($result) > 0 ? $doneContent = unserialize($result[0]['done_content']) : ($doneContent = array());
     $current_unit = 0;
     if ($seen) {
         $doneContent[$unit] = $unit;
         $current_unit = $unit;
     } else {
         if (isset($doneContent[$unit])) {
             //Because of Fatal error: Cannot unset string offsets error
             unset($doneContent[$unit]);
         }
         if ($unit == $result[0]['current_unit']) {
             sizeof($doneContent) ? $current_unit = end($doneContent) : ($current_unit = 0);
         }
     }
     sizeof($doneContent) ? $doneContent = serialize($doneContent) : ($doneContent = null);
     eF_updateTableData("users_to_lessons", array('done_content' => $doneContent, 'current_unit' => $current_unit), "users_LOGIN='******'login'] . "' and lessons_ID=" . $lesson);
     //		$cacheKey = "user_lesson_status:lesson:".$lesson."user:"******"type" => EfrontEvent::CONTENT_COMPLETION, "users_LOGIN" => $this->user['login'], "lessons_ID" => $lesson, "entity_ID" => $current_unit));
     }
     //Set the lesson as complete, if it can be.
     $completedLesson = false;
     $userProgress = EfrontStats::getUsersLessonStatus($lesson, $this->user['login']);
     $userProgress = $userProgress[$lesson][$this->user['login']];
     //eF_updateTableData("users_to_lessons", array('progress' => $userProgress['overall_progress']), "users_LOGIN='******'login']."' and lessons_ID=".$lesson);
     if ($seen) {
         if ($userProgress['lesson_passed'] && !$userProgress['completed']) {
             $lesson = new EfrontLesson($lesson);
             if ($lesson->options['auto_complete']) {
                 $userProgress['tests_avg_score'] ? $avgScore = $userProgress['tests_avg_score'] : ($avgScore = 100);
                 $timestamp = _AUTOCOMPLETEDAT . ': ' . date("Y/m/d, H:i:s");
                 $this->completeLesson($lesson, $avgScore, $timestamp);
                 $completedLesson = true;
             }
         }
         if (!self::$cached_modules) {
             self::$cached_modules = eF_loadAllModules();
         }
         // Trigger all necessary events. If the function has not been re-defined in the derived module class, nothing will happen
         foreach (self::$cached_modules as $module) {
             $module->onCompleteUnit($unit, $this->user['login']);
         }
     }
     return $completedLesson;
 }
Example #22
0
            $_SESSION['s_courses_ID'] = $course->course['id'];
        } else {
            unset($_SESSION['s_courses_ID']);
        }
        if (in_array($_GET['lessons_ID'], array_keys($userLessons))) {
            $newLesson = new EfrontLesson($_GET['lessons_ID']);
            if (!isset($_GET['course']) && !isset($_GET['from_course']) && $roles[$userLessons[$_GET['lessons_ID']]] == 'student' && ($newLesson->lesson['from_timestamp'] && $newLesson->lesson['from_timestamp'] > time() || $newLesson->lesson['to_timestamp'] && $newLesson->lesson['to_timestamp'] < time())) {
                eF_redirect("student.php?ctg=lessons&message=" . urlencode(_YOUCANNOTACCESSTHISLESSONORITDOESNOTEXIST));
            }
            $_SESSION['s_lessons_ID'] = $_GET['lessons_ID'];
            $_SESSION['s_type'] = $roles[$userLessons[$_GET['lessons_ID']]];
            //$justVisited = 1;   // used to trigger the event when the lesson info is available
            // The justVisited flag is set to one during the first visit to this lesson
            //if ($justVisited) {
            //Trigger onLessonVisited event
            EfrontEvent::triggerEvent(array("type" => EfrontEvent::LESSON_VISITED, "users_LOGIN" => $currentUser->user['login'], "users_name" => $currentUser->user['name'], "users_surname" => $currentUser->user['surname'], "lessons_ID" => $_SESSION['s_lessons_ID']));
            //}
            $smarty->assign("T_CHANGE_LESSON", "true");
            $smarty->assign("T_REFRESH_SIDE", "true");
        } else {
            unset($_GET['lessons_ID']);
            $message = _YOUCANNOTACCESSTHISLESSONORITDOESNOTEXIST;
            $message_type = 'failure';
            $ctg = 'personal';
        }
    } else {
        if ($_GET['lessons_ID'] == $_SESSION['s_lessons_ID']) {
            $smarty->assign("T_SHOW_LOADED_LESSON_OPTIONS", 1);
        }
    }
}
Example #23
0
         if (isset($_GET['ajax']) && $_GET['ajax'] == 'approval') {
             try {
                 $course = new EfrontCourse($_GET['course_id']);
                 $course->confirm($_GET['users_login']);
                 echo json_encode(array('status' => 1));
                 exit;
             } catch (Exception $e) {
                 handleAjaxExceptions($e);
             }
         } elseif (isset($_GET['ajax']) && $_GET['ajax'] == 'cancel') {
             try {
                 if (eF_checkParameter($_GET['course_id'], 'id')) {
                     $course = new EfrontCourse($_GET['course_id']);
                     $course->removeUsers($_GET['users_login']);
                     $event = array("type" => EfrontEvent::COURSE_USER_REFUSAL, "users_LOGIN" => $_GET['users_login'], "lessons_ID" => $course->course['id'], "lessons_name" => $course->course['name']);
                     EfrontEvent::triggerEvent($event);
                     echo json_encode(array('status' => 1));
                     exit;
                 }
             } catch (Exception $e) {
                 handleAjaxExceptions($e);
             }
         }
     }
 }
 #cpp#endif
 if ($currentUser->coreAccess['dashboard'] != 'hidden') {
     $myCoursesOptions[] = array('text' => _DASHBOARD, 'image' => "32x32/user.png", 'href' => basename($_SERVER['PHP_SELF']) . "?ctg=personal");
 }
 $constraints = array('archive' => false, 'active' => true, 'sort' => 'name');
 $userCourses = $currentUser->getUserCourses($constraints);
Example #24
0
 $smarty->assign("_change_history_", $_change_history_);
 if (eF_checkParameter($_GET['delete_event'], 'id') && $_change_history_) {
     try {
         eF_deleteTableData("events", "id = '" . $_GET['delete_event'] . "'");
     } catch (Exception $e) {
         handleAjaxExceptions($e);
     }
     exit;
 } else {
     $history = array();
     // Get history from events table - 3.6 and on
     //type>300 is the HCD events
     $history_from_events = eF_getTableData("events", "*", "users_LOGIN = '******'login'] . "' AND (type > 300 OR type=50 OR type=53)");
     $allModules = eF_loadAllModules();
     foreach ($history_from_events as $key => $event) {
         $eventObject = new EfrontEvent($event);
         $history[$key]['event_ID'] = $event['id'];
         $history[$key]['timestamp'] = $event['timestamp'];
         $history[$key]['message'] = $eventObject->createMessage($allModules);
     }
     // Get history from module_hcd_events table - for before 3.6
     $history_hcd_events = eF_getTableData("module_hcd_events", "*", "users_login = '******'login'] . "' AND event_code <10");
     foreach ($history_hcd_events as $key => $event) {
         $history[$key]['event_ID'] = $event['event_ID'];
         $history[$key]['timestamp'] = $event['timestamp'];
         $history[$key]['message'] = $event['specification'];
     }
     if (isset($_GET['ajax']) && $_GET['ajax'] == 'historyFormTable') {
         $dataSource = $history;
         $tableName = "historyFormTable";
         include "sorted_table.php";