Ejemplo n.º 1
0
 /**
  * Creates user folders
  * @since 3.6.4
  * @access private
  */
 private function createUserFolders()
 {
     $user_dir = G_UPLOADPATH . $this->user['login'] . '/';
     mkdir($user_dir, 0755);
     mkdir($user_dir . 'message_attachments/', 0755);
     mkdir($user_dir . 'message_attachments/Incoming/', 0755);
     mkdir($user_dir . 'message_attachments/Sent/', 0755);
     mkdir($user_dir . 'message_attachments/Drafts/', 0755);
     mkdir($user_dir . 'avatars/', 0755);
     try {
         //Create database representations for personal messages folders (it has nothing to do with filsystem database representation)
         eF_insertTableDataMultiple("f_folders", array(array('name' => 'Incoming', 'users_LOGIN' => $this->user['login']), array('name' => 'Sent', 'users_LOGIN' => $this->user['login']), array('name' => 'Drafts', 'users_LOGIN' => $this->user['login'])));
     } catch (Exception $e) {
     }
 }
Ejemplo n.º 2
0
 public static function switchLessonReportingMode($mode)
 {
     if ($GLOBALS['configuration']['time_reports'] != $mode && $mode == 1) {
         //step one: Read all times from the user_times table, per user,lesson and unit
         $data = $totals = array();
         $result = eF_getTableData("user_times", "users_LOGIN, entity_ID, lessons_ID, time", "entity = 'unit'");
         foreach ($result as $value) {
             if (isset($totals[$value['users_LOGIN']][$value['lessons_ID']][$value['entity_ID']])) {
                 $totals[$value['users_LOGIN']][$value['lessons_ID']][$value['entity_ID']] += $value['time'];
             } else {
                 $totals[$value['users_LOGIN']][$value['lessons_ID']][$value['entity_ID']] = $value['time'];
             }
         }
         //step 2: read all current time entries in the users_to_content table
         $result = eF_getTableData("users_to_content", "users_LOGIN, content_ID, lessons_ID, total_time");
         foreach ($result as $value) {
             $existing[$value['users_LOGIN']][$value['lessons_ID']][$value['content_ID']] = $value['total_time'];
         }
         //step 3: Populate the users_to_content table with the data from the user_times table, or update if a value already exist (overwriting it).
         foreach ($totals as $user => $lesson) {
             foreach ($lesson as $lessonId => $content) {
                 foreach ($content as $contentId => $seconds) {
                     if (isset($existing[$user][$lessonId][$contentId])) {
                         eF_updateTableData("users_to_content", array("total_time" => $seconds), "users_LOGIN='******' and content_ID={$contentId} and lessons_ID={$lessonId}");
                     } else {
                         $data[] = array("users_LOGIN" => $user, "content_ID" => $contentId, "lessons_ID" => $lessonId, "total_time" => $seconds);
                     }
                 }
             }
         }
         eF_insertTableDataMultiple("users_to_content", $data);
         //step 4: Read the lesson (but not unit) times from the user_times table
         $data = $totals = array();
         $result = eF_getTableData("user_times", "users_LOGIN, entity_ID, time", "entity = 'lesson'");
         foreach ($result as $value) {
             if (isset($totals[$value['users_LOGIN']][$value['entity_ID']])) {
                 $totals[$value['users_LOGIN']][$value['entity_ID']] += $value['time'];
             } else {
                 $totals[$value['users_LOGIN']][$value['entity_ID']] = $value['time'];
             }
         }
         //step 5: Populate the users_to_content table with the plain lesson times, using null as a contentId
         foreach ($totals as $user => $lesson) {
             foreach ($lesson as $lessonId => $seconds) {
                 $data[] = array("users_LOGIN" => $user, "content_ID" => null, "lessons_ID" => $lessonId, "total_time" => $seconds);
             }
         }
         eF_deleteTableData("users_to_content", "content_ID is null or content_ID=0");
         //empty previous entries
         eF_insertTableDataMultiple("users_to_content", $data);
     }
 }
Ejemplo n.º 3
0
 /**
  * Add users to course
  *
  * This function is used to register one or more users to the current course. A single login
  * or an array of logins may be specified
  * <br/>Example:
  * <code>
  * $course -> addUsers('joe', 'professor');         //Add the user with login 'joe' as a professor to this course
  * $users = array('joe', 'mary', 'mike');
  * $types = array('student', 'student', 'professor');
  * $course -> addUsers($users, $types);             //Add the users in the array $users with roles $types
  * </code>
  *
  * @param mixed $login The user login name
  * @param mixed $role The user role for this course, defaults to 'student'
  * @param boolean $confirmed If false, then the registration is set to 'pending' mode and the administration must confirm it
  * @since 3.5.0
  * @access public
  * @todo deprecated
  */
 public function addUsers($users, $userRoles = 'student', $confirmed = true)
 {
     if ($this->course['supervisor_LOGIN']) {
         $confirmed = false;
     }
     $roles = EfrontUser::getRoles();
     $users = EfrontUser::verifyUsersList($users);
     $userRoles = EfrontUser::verifyRolesList($userRoles, sizeof($users));
     foreach ($userRoles as $key => $value) {
         if (!EfrontUser::isStudentRole($value) && !EfrontUser::isProfessorRole($value)) {
             unset($userRoles[$key]);
             unset($users[$key]);
         }
     }
     if (empty($users)) {
         return false;
     }
     //For a single user, don't retrieve the full list of course users; that can be indefinitely big
     if (sizeof($users) == 1) {
         $result = eF_getTableData("users_to_courses uc, users u", "uc.users_LOGIN, uc.archive, uc.user_type, uc.to_timestamp, u.archive as user_archive, uc.completed", "u.login = '******' and u.login=uc.users_LOGIN and uc.courses_ID=" . $this->course['id']);
     } else {
         $result = eF_getTableData("users_to_courses uc, users u", "uc.users_LOGIN, uc.archive, uc.user_type, uc.to_timestamp, u.archive as user_archive, uc.completed", "u.login=uc.users_LOGIN and uc.courses_ID=" . $this->course['id']);
     }
     $courseUsers = array();
     $courseRoles = $this->getPossibleCourseRoles();
     $courseStudents = 0;
     foreach ($result as $value) {
         $courseUsers[$value['users_LOGIN']] = $value;
         if (!$value['user_archive'] && !$value['archive'] && EfrontUser::isStudentRole($value['user_type'])) {
             $courseStudents++;
         }
     }
     /*This query returns an array like:
     +------------+------------+-------------+-----------+----------------+---------+
     | courses_ID | lessons_ID | users_login | user_type | from_timestamp | archive |
     +------------+------------+-------------+-----------+----------------+---------+
     |          1 |          3 | professor   | professor |     1233140503 |       0 |
     |          1 |          3 | elpapath    | professor |     1233140503 |       0 |
     |          1 |         19 | periklis3   | student   |     1280488977 |       0 |
     |          1 |         20 | NULL        | NULL      |           NULL |    NULL |
     +------------+------------+-------------+-----------+----------------+---------+
     		So that it contains all the course's lessons and NULL for any lesson that does not have a user assigned
     		*/
     $result = eF_getTableData("lessons_to_courses lc left outer join users_to_lessons ul on lc.lessons_ID=ul.lessons_ID", "lc.lessons_ID, ul.users_LOGIN, ul.user_type, ul.from_timestamp, ul.archive, ul.to_timestamp, ul.completed", "courses_ID = " . $this->course['id']);
     $courseLessonsToUsers = array();
     foreach ($result as $value) {
         if (!is_null($value['users_LOGIN'])) {
             $courseLessonsToUsers[$value['lessons_ID']][$value['users_LOGIN']] = $value;
         } else {
             $courseLessonsToUsers[$value['lessons_ID']] = array();
         }
     }
     $courseLessons = array_unique(array_keys($courseLessonsToUsers));
     $result = eF_getTableData("projects", "id, lessons_ID", "auto_assign=1 and deadline >= " . time() . " and lessons_ID in (select lessons_ID from lessons_to_courses where courses_ID=" . $this->course['id'] . ")");
     $newProjectAssignments = $courseLessonsAutoAssignProjects = $assignedProjectsToUsers = array();
     foreach ($result as $value) {
         $courseLessonsAutoAssignProjects[$value['lessons_ID']][] = $value['id'];
     }
     $result = eF_getTableData("users_to_projects up, projects p", "up.users_LOGIN, up.projects_ID", "up.projects_ID=p.id and p.auto_assign=1 and p.deadline >= " . time() . " and p.lessons_ID in (select lessons_ID from lessons_to_courses where courses_ID=" . $this->course['id'] . ")");
     foreach ($result as $value) {
         $assignedProjectsToUsers[$value['users_LOGIN']][$value['projects_ID']] = $value['projects_ID'];
     }
     $newUsers = array();
     $existingUsers = array();
     foreach ($users as $key => $user) {
         $roleInCourse = $userRoles[$key];
         $roles[$roleInCourse] == 'student' ? $isStudentRoleInCourse = true : ($isStudentRoleInCourse = false);
         if ($this->course['max_users'] && $isStudentRoleInCourse && $this->course['max_users'] <= $courseStudents++) {
             throw new EfrontCourseException(str_replace(array("%x", "%y", "%z"), array($this->course['name'], $this->course['max_users'], $GLOBALS['configuration']['system_email']), _MAXSEATSDEPLEATED), EfrontCourseException::MAX_USERS_LIMIT);
         }
         if (!isset($courseUsers[$user])) {
             $newUsers[] = array('users_LOGIN' => $user, 'courses_ID' => $this->course['id'], 'active' => 1, 'archive' => 0, 'from_timestamp' => $confirmed ? time() : 0, 'user_type' => $roleInCourse, 'completed' => 0, 'score' => 0, 'issued_certificate' => '', 'comments' => '', 'to_timestamp' => 0);
         } elseif ($roleInCourse != $courseUsers[$user]['user_type'] || $courseUsers[$user]['archive']) {
             //update from_timestamp value when user reassigned to a course (only if it is not completed)
             if ($courseUsers[$user]['completed']) {
                 $fields = array('archive' => 0, 'user_type' => $roleInCourse);
             } else {
                 $fields = array('archive' => 0, 'user_type' => $roleInCourse, 'from_timestamp' => time());
             }
             //!$courseUsers[$user]['archive'] OR $fields['to_timestamp'] = 0;
             $confirmed or $fields['from_timestamp'] = 0;
             $where = "users_LOGIN='******' and courses_ID=" . $this->course['id'];
             self::persistCourseUsers($fields, $where, $this->course['id'], $user);
             $existingUsers[] = $courseUsers[$user];
         }
         foreach ($courseLessons as $id) {
             if (!isset($courseLessonsToUsers[$id][$user])) {
                 $usersToAddToCourseLesson[$id][$user] = array('login' => $user, 'role' => $roleInCourse, 'confirmed' => $confirmed);
                 $newLessonUsers[] = array('users_LOGIN' => $user, 'lessons_ID' => $id, 'active' => 1, 'archive' => 0, 'from_timestamp' => $confirmed ? time() : 0, 'user_type' => $roleInCourse, 'positions' => '', 'done_content' => '', 'current_unit' => 0, 'completed' => 0, 'score' => 0, 'comments' => '', 'to_timestamp' => 0);
                 if (EfrontUser::isStudentRole($roleInCourse)) {
                     foreach ($courseLessonsAutoAssignProjects[$id] as $projectId) {
                         if (!isset($assignedProjectsToUsers[$user][$projectId])) {
                             $newProjectAssignments[] = array('users_LOGIN' => $user, 'projects_ID' => $projectId);
                         }
                     }
                 }
             } elseif ($roleInCourse != $courseLessonsToUsers[$id][$user]['user_type'] || $courseLessonsToUsers[$id][$user]['archive']) {
                 //update also lesson from_timestamp value when user reassigned to a course (only if it is not completed)
                 if ($courseLessonsToUsers[$id][$user]['completed']) {
                     $fields = array('archive' => 0, 'user_type' => $roleInCourse);
                 } else {
                     $fields = array('archive' => 0, 'user_type' => $roleInCourse, 'from_timestamp' => time());
                 }
                 $fields['access_counter'] = 0;
                 //!$courseLessonsToUsers[$id][$user]['archive'] OR $fields['to_timestamp'] = 0;
                 $confirmed or $fields['from_timestamp'] = 0;
                 eF_updateTableData("users_to_lessons", $fields, "users_LOGIN='******' and lessons_ID=" . $id);
                 if (EfrontUser::isStudentRole($roleInCourse)) {
                     foreach ($courseLessonsAutoAssignProjects[$id] as $projectId) {
                         if (!isset($assignedProjectsToUsers[$user][$projectId])) {
                             $newProjectAssignments[] = array('users_LOGIN' => $user, 'projects_ID' => $projectId);
                         }
                     }
                 }
             }
         }
     }
     if (!empty($newUsers)) {
         eF_insertTableDataMultiple("users_to_courses", $newUsers);
     }
     if (!empty($newLessonUsers)) {
         eF_insertTableDataMultiple("users_to_lessons", $newLessonUsers);
     }
     if (!empty($newProjectAssignments)) {
         eF_insertTableDataMultiple("users_to_projects", $newProjectAssignments);
     }
     !isset($newUsers) ? $newUsers = array() : null;
     !isset($existingUsers) ? $existingUsers = array() : null;
     $eventArray = array_merge($newUsers, $existingUsers);
     if (!defined(_DISABLE_EVENTS) || _DISABLE_EVENTS !== true) {
         foreach ($eventArray as $value) {
             $event = array("type" => EfrontUser::isStudentRole($value['user_type']) ? EfrontEvent::COURSE_ACQUISITION_AS_STUDENT : EfrontEvent::COURSE_ACQUISITION_AS_PROFESSOR, "users_LOGIN" => $value['users_LOGIN'], "lessons_ID" => $this->course['id'], "lessons_name" => $this->course['name']);
             EfrontEvent::triggerEvent($event);
             if (EfrontUser::isStudentRole($value['user_type'])) {
                 $event = array("type" => -1 * EfrontEvent::COURSE_COMPLETION, "users_LOGIN" => $value['users_LOGIN'], "lessons_ID" => $this->course['id'], "lessons_name" => $this->course['name'], "replace" => true, "create_negative" => false);
                 EfrontEvent::triggerEvent($event);
             }
         }
     }
     $modules = eF_loadAllModules();
     foreach ($modules as $module) {
         $module->onAddUsersToCourse($this->course['id'], $eventArray, $newLessonUsers);
     }
     $this->users = false;
     //Reset users cache
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
0
 /**
  * Add the user in the lesson having the specified role
  *
  * @param string $user The user's login
  * @param mixed $roleInLesson the user's role in the lesson
  * @since 3.6.1
  * @access protected
  */
 private function addUsersToLesson($usersData)
 {
     $autoAssignedProjects = $this->getAutoAssignProjects();
     $archivedLessonUsers = $this->getArchivedUsers();
     $newUsers = array();
     $options = unserialize($this->lesson['options']);
     $positions = $options['default_positions'];
     foreach ($usersData as $value) {
         if (in_array($value['login'], $archivedLessonUsers)) {
             //Update only fields not related to progress
             $updateFields = array('active' => 1, 'archive' => 0, 'from_timestamp' => $value['confirmed'] ? time() : 0, 'user_type' => $value['role'], 'access_counter' => 0);
             eF_updateTableData("users_to_lessons", $updateFields, "users_LOGIN='******'login'] . "' and lessons_ID=" . $this->lesson['id']);
         } else {
             $newUsers[] = $value['login'];
             $fields[] = array('users_LOGIN' => $value['login'], 'lessons_ID' => $this->lesson['id'], 'active' => 1, 'archive' => 0, 'from_timestamp' => $value['confirmed'] ? time() : 0, 'user_type' => $value['role'], 'positions' => '', 'done_content' => '', 'current_unit' => 0, 'completed' => 0, 'score' => 0, 'comments' => '', 'positions' => $positions, 'to_timestamp' => 0);
         }
     }
     if (!empty($newUsers)) {
         eF_insertTableDataMultiple("users_to_lessons", $fields);
         foreach ($autoAssignedProjects as $project) {
             $project->addUsers($newUsers);
         }
     }
     if (!defined(_DISABLE_EVENTS) || _DISABLE_EVENTS !== true) {
         foreach ($usersData as $value) {
             $event = array("type" => EfrontUser::isStudentRole($value['role']) ? EfrontEvent::LESSON_ACQUISITION_AS_STUDENT : EfrontEvent::LESSON_ACQUISITION_AS_PROFESSOR, "users_LOGIN" => $value['login'], "lessons_ID" => $this->lesson['id'], "lessons_name" => $this->lesson['name']);
             EfrontEvent::triggerEvent($event);
             if (EfrontUser::isStudentRole($value['role'])) {
                 $event = array("type" => -1 * EfrontEvent::LESSON_COMPLETION, "users_LOGIN" => $value['login'], "lessons_ID" => $this->lesson['id'], "lessons_name" => $this->lesson['name'], "replace" => true, "create_negative" => false);
                 EfrontEvent::triggerEvent($event);
             }
         }
     }
 }
Ejemplo n.º 6
0
     //We asked to copy the surveys
 } else {
     if (isset($_GET['entity']) && $_GET['entity'] == 'surveys') {
         try {
             $result = eF_getTableData("surveys", "*", "lessons_ID = " . $_GET['from']);
             foreach ($result as $key => $value) {
                 $result[$key]['lessons_ID'] = $currentLesson->lesson['id'];
                 $result_questions = eF_getTableData("questions_to_surveys", "*", "surveys_ID=" . $result[$key]['id']);
                 unset($result[$key]['id']);
                 $new_id = eF_insertTableData("surveys", $result[$key]);
                 foreach ($result_questions as $index => $question) {
                     unset($question['id']);
                     $question['surveys_ID'] = $new_id;
                     $result_questions[$index] = $question;
                 }
                 eF_insertTableDataMultiple("questions_to_surveys", $result_questions);
             }
         } catch (Exception $e) {
             header("HTTP/1.0 500 ");
             echo $e->getMessage() . ' (' . $e->getCode() . ')';
         }
         exit;
         //We asked to copy content
     } else {
         $currentContent = new EfrontContentTree($currentLesson, true);
         $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST));
         if (sizeof($currentContent->tree) == 0) {
             $smarty->assign("T_CONTENT_TREE", $currentContent->toHTML($iterator, 'dhtmlTargetTree', array('noclick' => true, 'drag' => false, 'tree_root' => true)));
         } else {
             $smarty->assign("T_CONTENT_TREE", $currentContent->toHTML($iterator, 'dhtmlTargetTree', array('noclick' => true, 'drag' => false, 'expand' => true, 'truncateNames' => EfrontUnit::MAXIMUM_NAME_LENGTH)));
         }
Ejemplo n.º 7
0
 /**
  * Function insertText()
  *
  * This function registers a new keyword to the search table. Input arguments are:
  * - The keyword to be commited
  * - The id of the database entry in the keyword original table
  * - This table's name.
  * - Whether the keyword lies on the title or the body of the containing text
  *
  * @param string $text The search keyword
  * @param int $foreignID The keyword's original entry id
  * @param string $tableName The keyword's original table name
  * @param string $position The keyword's original text position, either 'title' or 'data'.
  * @since 3.5.0
  * @access public
  */
 public static function insertText($text, $foreignID, $tableName, $position)
 {
     $fields['foreign_ID'] = $foreignID;
     $fields['table_name'] = EfrontSearch::$tableAssoc[$tableName];
     //from 3.6 there is a corespondence between tables and numbers
     $position == "title" ? $fields['position'] = 0 : ($fields['position'] = 1);
     //from 3.6  1 means 'data' and 0 means 'title'
     //todo : remove also some special chars like [ ] & * etc
     if ($text == "") {
         return true;
     }
     $replace = array("&nbsp;", "(", "{", "}", ")", "]", "[", "@", "#", "\$", "%", "^", "&", "*", ".", ",", "'", "\"", "/", "\\");
     $querywords = mb_strtolower(strip_tags(str_replace($replace, " ", $text)));
     $eachword = explode(" ", $querywords);
     $eachword = array_unique($eachword);
     //Remove duplicate values from search table
     $terms = array();
     foreach ($eachword as $key => $value) {
         $len = mb_strlen($value);
         if ($len > 3 and $len < 100) {
             //Only words with length more than 3 and less than 100 characters long.
             $terms[] = $value;
         } else {
         }
     }
     //Querying for all values may be very slow; this is why we added this 20 values limit
     if (sizeof($terms) > 20) {
         $result = eF_getTableDataFlat("search_invertedindex", "id,keyword");
     } else {
         $terms = array_map(create_function('$x', 'return htmlspecialchars($x, ENT_QUOTES, "utf-8");'), $terms);
         $result = eF_getTableDataFlat("search_invertedindex", "*", "keyword IN ('" . implode("','", $terms) . "')");
     }
     isset($result["keyword"]) && $result["keyword"] ? $allTerms = $result["keyword"] : ($allTerms = array());
     if (!empty($terms)) {
         foreach ($terms as $key => $value) {
             $position = array_search($value, $allTerms);
             //array_search may also return null!
             if ($position === false && !is_null($position)) {
                 $newId = eF_insertTableData("search_invertedindex", array("keyword" => $value));
                 //$fields['keyword'] = $newId;
                 $allFields[] = $fields + array('keyword' => $newId);
                 //$rows[] = "('".implode("','",$fields)."')";
             } else {
                 //$fields['keyword'] = $result["id"][$position];
                 $allFields[] = $fields + array('keyword' => $result["id"][$position]);
                 //$rows[] = "('".implode("','",$fields)."')";
             }
         }
         $allFields = array_map('unserialize', array_unique(array_map('serialize', $allFields)));
         //$res = eF_executeNew("insert into search_keywords (".implode(",", array_keys($fields)).") values ".implode(",",$rows)."");
         eF_insertTableDataMultiple("search_keywords", $allFields);
     }
     return true;
 }
Ejemplo n.º 8
0
 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);
         }
     }
 }
Ejemplo n.º 9
0
        $uploadedFile = $filesystem->uploadFile('import_file');
        if ($uploadedFile['extension'] != 'csv') {
            $message = _YOUHAVETOUSEACSVFILE;
            eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=glossary&message=" . urlencode($message) . "&message_type=failure");
        } else {
            if (($handle = fopen($uploadedFile['path'], "r")) !== FALSE) {
                while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
                    $terms[] = $data;
                }
                fclose($handle);
            }
            $entries = array();
            foreach ($terms as $value) {
                $entries[] = array("name" => $value[0], "info" => $value[1], "lessons_ID" => $_SESSION['s_lessons_ID'], "type" => 'general');
            }
            eF_insertTableDataMultiple("glossary", $entries);
        }
    } catch (Exception $e) {
        $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
        $message = $e->getMessage() . ' (' . $e->getCode() . ') &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);
$importForm->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
$importForm->setRequiredNote(_REQUIREDNOTE);
$importForm->accept($renderer);
$smarty->assign('T_IMPORT_FORM', $renderer->toArray());
$load_editor = true;
$entityName = 'glossary';
if (EfrontUser::isOptionVisible('shared_glossary')) {
Ejemplo n.º 10
0
        } else {
            $newTest = EfrontTest::createTest(false, $testFields);
        }
        // If the new test comes from an existing one we should also copy its questions...
        if ($_GET['edit_test']) {
            $testQuestions = $currentTest->getQuestions();
            $newTest->addQuestions($testQuestions);
            // ... and its users if it is a skillgap test
            if ($skillgap_tests) {
                $testUsers = eF_getTableDataFlat("users_to_skillgap_tests", "users_LOGIN", "tests_ID = '" . $_GET['edit_test'] . "'");
                $fields = array();
                foreach ($testUsers as $entry) {
                    $fields[] = array('tests_ID' => $newTest->test['id'], 'users_LOGIN' => $entry['useres_LOGIN']);
                }
                if (sizeof($fields) > 0) {
                    eF_insertTableDataMultiple("users_to_skillgap_tests", $fields);
                    //$insertString = "('" . $newTest->test['id'] . "', '" . implode("'),('" . $newTest -> test['id'] . "', '", $testUsers['users_LOGIN']) . "')";
                    //eF_execute("INSERT INTO users_to_skillgap_tests (tests_ID,users_LOGIN) VALUES $insertString");
                }
            }
        }
        if ($_GET['ctg'] != 'feedback') {
            $messageString = _SUCCESFULLYMODIFIEDTEST;
        } else {
            $messageString = _SUCCESFULLYMODIFIEDFEEDBACK;
        }
        EfrontCache::getInstance()->deleteCache("content_tree:{$_SESSION['s_lessons_ID']}");
        eF_redirect("" . ltrim(basename($_SERVER['PHP_SELF']), "/") . "?ctg=" . $_GET['ctg'] . "&edit_test=" . $newTest->test['id'] . "&from_unit=" . $_GET['from_unit'] . "&tab=questions&&message=" . urlencode($messageString) . "&message_type=success");
    }
}
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
 /**
  * The main functionality
  *
  * (non-PHPdoc)
  * @see libraries/EfrontModule#getModule()
  */
 public function getModule()
 {
     $currentLesson = $this->getCurrentLesson();
     $smarty = $this->getSmartyVar();
     $smarty->assign("T_MODULE_BASEDIR", $this->moduleBaseDir);
     $smarty->assign("T_MODULE_BASELINK", $this->moduleBaseLink);
     $smarty->assign("T_MODULE_BASEURL", $this->moduleBaseUrl);
     if ($currentLesson && !$currentLesson->options['digital_library']) {
         $result = eF_getTableDataFlat("module_shared_files", "path", "lessons_ID=" . $currentLesson->lesson['id']);
         $lessonSharedFiles = $result['path'];
         $basedir = new EfrontDirectory($currentLesson->getDirectory());
         if ($_GET['other']) {
             $directory = new EfrontDirectory($_GET['other']);
             if (strpos($directory['path'], $basedir['path']) !== false && strcmp($directory['path'], $basedir['path'])) {
                 $basedir = $directory;
                 $smarty->assign("T_PARENT_DIR", dirname($basedir['path']));
             }
         }
         $smarty->assign("T_CURRENT_DIR", str_replace($currentLesson->getDirectory(), "", $basedir['path']));
         $filesystem = new FileSystemTree($basedir, true);
         $files = $directories = array();
         foreach ($filesystem->tree as $key => $value) {
             $value['image'] = $value->getTypeImage();
             if (strpos($value['mime_type'], "image") !== false || strpos($value['mime_type'], "text") !== false || strpos($value['mime_type'], "pdf") !== false || strpos($value['mime_type'], "html") !== false || strpos($value['mime_type'], "flash") !== false) {
                 $value['preview'] = true;
             }
             if (in_array($key, $lessonSharedFiles)) {
                 $value['module_shared_files_status'] = true;
             }
             if ($value instanceof EfrontFile) {
                 $files[$key] = (array) $value;
             } elseif ($value instanceof EfrontDirectory) {
                 $value['size'] = 0;
                 $directories[$key] = (array) $value;
             }
         }
         $tableName = "sharedFilesTable";
         $dataSource = array_merge($directories, $files);
         list($tableSize, $dataSource) = filterSortPage($dataSource);
         $smarty->assign("T_TABLE_SIZE", $tableSize);
         if (!empty($dataSource)) {
             $smarty->assign("T_DATA_SOURCE", $dataSource);
         }
         try {
             if (isset($_GET['ajax']) && isset($_GET['share_file'])) {
                 try {
                     $entity = new EfrontFile(urldecode($_GET['share_file']));
                 } catch (Exception $e) {
                     $entity = new EfrontDirectory(urldecode($_GET['share_file']));
                 }
                 if (in_array($entity['path'], $lessonSharedFiles)) {
                     eF_deleteTableData("module_shared_files", "path='" . $entity['path'] . "' and lessons_ID=" . $currentLesson->lesson['id']);
                     $added = false;
                     if ($entity instanceof EfrontDirectory) {
                         $subTree = new FileSystemTree($entity, true);
                         $insertValues = array();
                         foreach ($subTree->tree as $value) {
                             eF_deleteTableData("module_shared_files", "path='" . $value['path'] . "' and lessons_ID=" . $currentLesson->lesson['id']);
                         }
                     }
                 } else {
                     eF_insertTableData("module_shared_files", array("path" => $entity['path'], 'lessons_ID' => $currentLesson->lesson['id']));
                     $added = true;
                     if ($entity instanceof EfrontDirectory) {
                         $subTree = new FileSystemTree($entity, true);
                         $insertValues = array();
                         foreach ($subTree->tree as $value) {
                             $insertValues[] = array("path" => $value['path'], 'lessons_ID' => $currentLesson->lesson['id']);
                         }
                         if (!empty($insertValues)) {
                             eF_insertTableDataMultiple("module_shared_files", $insertValues);
                         }
                     }
                 }
                 echo json_encode(array('status' => 1, 'added' => $added));
                 exit;
             }
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         return true;
     } else {
         if ($currentLesson) {
             $currentLesson->options['digital_library'] = 0;
             $currentLesson->persist();
             eF_redirect($this->moduleBaseUrl . '&message=' . urlencode(_MODULE_SHARED_FILES_SHAREDFILESENABLED));
             //$this->setMessageVar(_MODULE_SHARED_FILES_SHAREDFILESENABLED);
             //$smarty -> assign("T_SHARED_FILES_ENABLED", true);
         }
     }
 }
Ejemplo n.º 12
0
 /**
  *
  * @param $table
  * @param $newTable
  * @param $oldDB
  * @param $newDB
  * @return unknown_type
  */
 public static function updateDBTable($table, $newTable, $oldDB = false, $newDB = false)
 {
     if ($oldDB && $newDB) {
         $GLOBALS['db']->NConnect($oldDB['db_host'], $oldDB['db_user'], $oldDB['db_password'], $oldDB['db_name']);
         $GLOBALS['db']->Execute("SET NAMES 'UTF8'");
     }
     try {
         $data = eF_getTableData($table, "count(*)");
     } catch (Exception $e) {
         $limit = 0;
     }
     $unfold = 2000;
     $limit = ceil($data[0]['count(*)'] / $unfold);
     if ($table != $newTable) {
         try {
             $GLOBALS['db']->Execute("truncate table {$newTable}");
         } catch (Exception $e) {
         }
     }
     if ($table == 'f_folders') {
         //because of  UNIQUE(name, users_LOGIN) added there, we have to remove possible duplicates
         $dbVersion = $GLOBALS['db']->getCol("select value from configuration where name = 'database_version'");
         if (!empty($dbVersion)) {
             $dbVersion = $dbVersion[0];
         } else {
             $dbVersion = '3.5';
         }
         if (version_compare($dbVersion, '3.6.4') == -1) {
             $upgrade_f_folders = eF_getTableData("f_folders", "*");
             foreach ($upgrade_f_folders as $key => $value) {
                 $usersToFolders[$value['users_LOGIN']][$value['name']][] = $value['id'];
             }
             foreach ($usersToFolders as $login => $folder) {
                 foreach ($folder as $name => $arrayId) {
                     if (sizeof($arrayId) > 1) {
                         $maxId = max(array_values($arrayId));
                         $arrayCut = array_diff($arrayId, array($maxId));
                         eF_deleteTableData("f_folders", "id IN (" . implode(",", $arrayCut) . ")");
                         eF_updateTableData("f_personal_messages", array('f_folders_ID' => $maxId), "f_folders_ID IN (" . implode(",", $arrayCut) . ")");
                     }
                 }
             }
         }
     }
     for ($i = 0; $i < $limit; $i++) {
         if ($oldDB && $newDB) {
             $GLOBALS['db']->NConnect($oldDB['db_host'], $oldDB['db_user'], $oldDB['db_password'], $oldDB['db_name']);
             $GLOBALS['db']->Execute("SET NAMES 'UTF8'");
         }
         $data = eF_getTableData($table, "*", "", "'' limit {$unfold} offset " . $i * $unfold);
         //Special handling for glossary table that changed name
         if ($table == 'glossary_words') {
             if ($newTable != $table) {
                 $newTable = 'install_glossary';
             } else {
                 $newTable = 'glossary';
             }
             $table = 'glossary';
         }
         //Get the old database descriptions, it is used in updateDBData(), which however must be called after any connection to the new DB
         //so this line MUST be called before the new connection
         $table_fields = $GLOBALS['db']->GetCol("describe {$table}");
         if ($oldDB && $newDB) {
             $GLOBALS['db']->NConnect($newDB['db_host'], $newDB['db_user'], $newDB['db_password'], $newDB['db_name']);
             $GLOBALS['db']->Execute("SET NAMES 'UTF8'");
             $result = $GLOBALS['db']->getAll("describe {$table}");
         } else {
             $result = $GLOBALS['db']->getAll("describe install_{$table}");
         }
         //$result contains the new database descriptions. So both result and this code must be executed AFTER the new DB connection
         $fieldTypes = array();
         foreach ($result as $key => $value) {
             $fieldTypes[$value['Field']] = $value['Type'];
         }
         $data = self::updateDBData($table, $data, $table_fields, $fieldTypes);
         if (sizeof($data) > 0) {
             $data = array_values($data);
             //Reindex array, in case some values where removed
         }
         eF_insertTableDataMultiple($newTable, $data, false);
     }
     $GLOBALS['db']->Execute("drop table if exists glossary_words");
     $GLOBALS['db']->Execute("drop table if exists install_glossary_words");
 }