Ejemplo n.º 1
0
 /**
  * Check succession rules for user
  *
  * This function checks the user's eligibility for the course lessons,
  * based on the course rules and the user's completed lessons, as well as
  * the dates that each lesson is available on.
  * <br/>Eaample:
  * <code>
  * $course = new EfrontCourse(23);
  * $eligibility = $course -> checkRules('jdoe');
  * </code>
  * In the above example, let's suppose that the course 23 has 3 lessons, with ids 1,2 and 3. Let's suppose that in order to access
  * lesson 2, the user must have completed lesson 1, and for accessing lesson 3, the user must have completed both lessons 1 and 2.
  * Then, if the user has completed lesson 1, the above example will return:
  * <code>array(2 => 1, 3 => 0);</code>
  * where if he has completed both 2 and 3 it will return:
  * <code>array(2 => 1, 3 => 1);</code>
  *
  * @param mixed $user A user login or an EfrontUser object
  * @return array The eligibility array, holding lessons ids as keys and true/false (or 0/1) as values
  * @since 3.5.0
  * @access public
  */
 public function checkRules($user, $courseLessons = false)
 {
     if ($courseLessons == false) {
         if (!$user instanceof EfrontUser) {
             $user = EfrontUserFactory::factory($user);
         }
         $courseLessons = $user->getUserStatusInCourseLessons($this);
     }
     $user = EfrontUser::convertArgumentToUserLogin($user);
     $roles = EfrontLessonUser::getLessonsRoles();
     $courseLessons = EfrontCourse::convertLessonObjectsToArrays($courseLessons);
     if (!empty($courseLessons)) {
         $allowed = array_combine(array_keys($courseLessons), array_fill(0, sizeof($courseLessons), 1));
         //By default, all lessons are accessible
     } else {
         $allowed = array();
     }
     if ($this->course['depends_on']) {
         try {
             $dependsOn = new EfrontCourse($this->course['depends_on']);
             if ($dependsOn->course['active'] && !$dependsOn->course['archive']) {
                 $result = eF_getTableData("users_to_courses", "completed, user_type", "users_LOGIN='******' and courses_ID=" . $dependsOn->course['id']);
                 if (!$result[0]['completed'] && $roles[$result[0]['user_type']] == 'student') {
                     foreach ($allowed as $key => $value) {
                         $allowed[$key] = 0;
                     }
                     return $allowed;
                 }
             }
         } catch (Exception $e) {
         }
     }
     $completedLessons = array();
     foreach ($courseLessons as $key => $value) {
         !isset($value['start_date']) or $dates[$key]['from_timestamp'] = $value['start_date'];
         !isset($value['end_date']) or $dates[$key]['to_timestamp'] = $value['end_date'];
         if (isset($value['start_period']) && isset($value['end_period'])) {
             //$dates[$key]['from_timestamp'] 	= $this -> course['start_date'] + 24 * 60 * 60 * $value['start_period'];
             //$dates[$key]['to_timestamp'] 	= $dates[$key]['from_timestamp'] + 24 * 60 * 60 * $value['end_period'];
             $dates[$key]['from_timestamp'] = $value['active_in_lesson'] + 24 * 60 * 60 * $value['start_period'];
             $dates[$key]['to_timestamp'] = $dates[$key]['from_timestamp'] + 24 * 60 * 60 * $value['end_period'];
         } elseif (isset($value['start_date']) && isset($value['end_date'])) {
             $dates[$key]['from_timestamp'] = $value['start_date'];
             $dates[$key]['to_timestamp'] = $value['end_date'];
         }
         if ($roles[$value['user_type']] == 'student') {
             $completedLessons[$key] = $value['completed'];
         }
     }
     foreach ($this->rules as $lessonId => $lessonRules) {
         if (eF_checkParameter($lessonId, 'id')) {
             $evalString = '';
             for ($i = 1; $i < sizeof($lessonRules['lesson']); $i++) {
                 $evalString .= $completedLessons[$lessonRules['lesson'][$i]] . ' ' . ($lessonRules['condition'][$i + 1] == 'and' ? '&' : '|');
             }
             $evalString = $evalString . ' ' . $completedLessons[$lessonRules['lesson'][$i]];
             if (!empty($completedLessons) && isset($completedLessons[$lessonRules['lesson'][$i]])) {
                 if (trim($evalString) == '') {
                     $evalString = 'false';
                 }
                 eval("\$allowed[{$lessonId}] = {$evalString};");
             }
         }
     }
     foreach ($allowed as $id => $allow) {
         if (isset($dates[$id]['from_timestamp']) && $dates[$id]['from_timestamp'] > time()) {
             $allowed[$id] = 0;
         }
         if (isset($dates[$id]['to_timestamp']) && $dates[$id]['to_timestamp'] < time()) {
             $allowed[$id] = 0;
         }
     }
     return $allowed;
 }
Ejemplo n.º 2
0
                     }
                 }
             }
         }
     } catch (Exception $e) {
         handleAjaxExceptions($e);
     }
     $days_after_enrollment = array();
     for ($k = 0; $k <= 360; $k++) {
         $days_after_enrollment[$k] = $k;
         if ($k >= 100) {
             $k += 5;
         }
     }
     $smarty->assign("T_DAYS_AFTER_ENROLLMENT", $days_after_enrollment);
     $smarty->assign("T_COURSE_LESSONS", EfrontCourse::convertLessonObjectsToArrays($courseLessons));
     //pr($courseLessons);
 } else {
     if ($_GET['op'] == 'export_course') {
         if (isset($currentUser->coreAccess['content']) && $currentUser->coreAccess['content'] != 'change') {
             eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=control_panel&message=" . urlencode(_UNAUTHORIZEDACCESS) . "&message_type=failure");
         }
         /* Export part */
         $form = new HTML_QuickForm("export_course_form", "post", basename($_SERVER['PHP_SELF']) . '?' . $baseUrl . '&op=export_course', "", null, true);
         $form->addElement('submit', 'submit_export_course', _EXPORT, 'class = "flatButton"');
         try {
             $currentExportedFile = new EfrontFile($currentUser->user['directory'] . '/temp/' . EfrontFile::encode($currentCourse->course['name']) . '.zip');
             $smarty->assign("T_EXPORTED_FILE", $currentExportedFile);
         } catch (Exception $e) {
         }
         if ($form->isSubmitted() && $form->validate()) {
Ejemplo n.º 3
0
             echo "<status>error</status>";
             echo "<message>Incomplete arguments</message>";
             echo "</xml>";
         }
     } else {
         echo "<xml>";
         echo "<status>error</status>";
         echo "<message>Invalid token</message>";
         echo "</xml>";
     }
     break;
 case 'course_lessons':
     if (isset($_GET['token']) && checkToken($_GET['token'])) {
         if (isset($_GET['course'])) {
             $course = new EfrontCourse($_GET['course']);
             $lessons = EfrontCourse::convertLessonObjectsToArrays($course->getCourseLessons());
             echo "<xml>";
             echo "\n\t";
             echo "<lessons>";
             echo "\n\t\t";
             foreach ($lessons as $key => $values) {
                 echo "<lesson>";
                 echo "\n\t\t\t";
                 echo "<id>" . $lessons[$key]['id'] . "</id>";
                 echo "\n\t\t\t";
                 echo "<name>" . $lessons[$key]['name'] . "</name>";
                 echo "\n\t\t\t";
                 echo "<previous_lessons_ID>" . $lessons[$key]['previous_lessons_ID'] . "</previous_lessons_ID>";
                 echo "\n\t\t";
                 echo "</lesson>";
             }