/**
  * @param int       $userId
  * @param string    $content
  * @param string    $course_code
  * @param int       $session_id
  *
  * @return mixed
  */
 public static function parse_content($userId, $content, $course_code, $session_id = 0)
 {
     $readerInfo = api_get_user_info($userId);
     $courseInfo = api_get_course_info($course_code);
     $teacher_list = CourseManager::get_teacher_list_from_course_code($courseInfo['code']);
     $teacher_name = '';
     if (!empty($teacher_list)) {
         foreach ($teacher_list as $teacher_data) {
             $teacher_name = api_get_person_name($teacher_data['firstname'], $teacher_data['lastname']);
             $teacher_email = $teacher_data['email'];
             break;
         }
     }
     $courseLink = api_get_course_url($course_code, $session_id);
     $data['user_name'] = $readerInfo['username'];
     $data['user_firstname'] = $readerInfo['firstname'];
     $data['user_lastname'] = $readerInfo['lastname'];
     $data['teacher_name'] = $teacher_name;
     $data['teacher_email'] = $teacher_email;
     $data['course_title'] = $courseInfo['name'];
     $data['course_link'] = Display::url($courseLink, $courseLink);
     $data['official_code'] = $readerInfo['official_code'];
     $content = str_replace(self::get_tags(), $data, $content);
     return $content;
 }
Example #2
0
            $pluginMessage = Display::return_message($plugin->get_lang('YouNeedToConfirmYourAgreementCheckYourEmail'));
            $hideForm = true;
        }
    }
}
$form->addElement('header', get_lang('CourseLegalAgreement'));
$form->addElement('label', null, $course_legal);
if ($pluginLegal && !empty($plugin)) {
    $form->addElement('label', null, $plugin->getCurrentFile($course_info['real_id'], $session_id));
}
$form->addElement('hidden', 'course_code', $course_code);
$form->addElement('hidden', 'session_id', $session_id);
$form->addElement('checkbox', 'accept_legal', null, get_lang('AcceptLegal'));
$form->addElement('style_submit_button', null, get_lang('Accept'), 'class="save"');
$variable = 'accept_legal_' . $user_id . '_' . $course_info['real_id'] . '_' . $session_id;
$url = api_get_course_url($course_code, $session_id);
if ($form->validate()) {
    $accept_legal = $form->exportValue('accept_legal');
    if ($accept_legal == 1) {
        CourseManager::save_user_legal($user_id, $course_code, $session_id);
        if (api_check_user_access_to_legal($course_info['visibility'])) {
            Session::write($variable, true);
        }
        if ($pluginLegal) {
            header('Location:' . $url);
            exit;
        }
    }
}
$user_pass_open_course = false;
if (api_check_user_access_to_legal($course_info['visibility']) && Session::read($variable)) {
Example #3
0
 /**
  * Shows the user progress (when clicking in the Progress tab)
  *
  * @param int $user_id
  * @param int $session_id
  * @param string $extra_params
  * @param bool $show_courses
  * @param bool $showAllSessions
  *
  * @return string
  */
 public static function show_user_progress($user_id, $session_id = 0, $extra_params = '', $show_courses = true, $showAllSessions = true)
 {
     $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $tbl_access_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
     $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $tbl_access_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
     $user_id = intval($user_id);
     $session_id = intval($session_id);
     if (api_is_multiple_url_enabled()) {
         $sql = "SELECT c.code, title\n                    FROM {$tbl_course_user} cu\n                    INNER JOIN {$tbl_course} c\n                    ON (cu.c_id = c.id)\n                    INNER JOIN {$tbl_access_rel_course} a\n                    ON (a.c_id = c.id)\n                    WHERE\n                        cu.user_id = {$user_id} AND\n                        relation_type<> " . COURSE_RELATION_TYPE_RRHH . " AND\n                        access_url_id = " . api_get_current_access_url_id() . "\n                    ORDER BY title";
     } else {
         $sql = "SELECT c.code, title\n                    FROM {$tbl_course_user} u\n                    INNER JOIN {$tbl_course} c ON (c_id = c.id)\n                    WHERE\n                        u.user_id= {$user_id} AND\n                        relation_type<>" . COURSE_RELATION_TYPE_RRHH . "\n                    ORDER BY title";
     }
     $rs = Database::query($sql);
     $courses = $course_in_session = $temp_course_in_session = array();
     while ($row = Database::fetch_array($rs, 'ASSOC')) {
         $courses[$row['code']] = $row['title'];
     }
     $orderBy = " ORDER BY name ";
     $extraInnerJoin = null;
     if (SessionManager::orderCourseIsEnabled() && !empty($session_id)) {
         $orderBy = " ORDER BY s.id, position ";
         $tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
         $extraInnerJoin = " INNER JOIN {$tableSessionRelCourse} src\n                                ON (cu.c_id = src.c_id AND src.session_id = {$session_id}) ";
     }
     $sessionCondition = '';
     if (!empty($session_id)) {
         $sessionCondition = " AND s.id = {$session_id}";
     }
     // Get the list of sessions where the user is subscribed as student
     if (api_is_multiple_url_enabled()) {
         $sql = "SELECT DISTINCT c.code, s.id as session_id, name\n                    FROM {$tbl_session_course_user} cu\n                    INNER JOIN {$tbl_access_rel_session} a\n                    ON (a.session_id = cu.session_id)\n                    INNER JOIN {$tbl_session} s\n                    ON (s.id = a.session_id)\n                    INNER JOIN {$tbl_course} c\n                    ON (c.id = cu.c_id)\n                    {$extraInnerJoin}\n                    WHERE\n                        cu.user_id = {$user_id} AND\n                        access_url_id = " . api_get_current_access_url_id() . "\n                        {$sessionCondition}\n                    {$orderBy} ";
     } else {
         $sql = "SELECT DISTINCT c.code, s.id as session_id, name\n                    FROM {$tbl_session_course_user} cu\n                    INNER JOIN {$tbl_session} s\n                    ON (s.id = cu.session_id)\n                    INNER JOIN {$tbl_course} c\n                    ON (c.id = cu.c_id)\n                    {$extraInnerJoin}\n                    WHERE\n                        cu.user_id = {$user_id}\n                        {$sessionCondition}\n                    {$orderBy} ";
     }
     $rs = Database::query($sql);
     $simple_session_array = array();
     while ($row = Database::fetch_array($rs)) {
         $course_info = CourseManager::get_course_information($row['code']);
         $temp_course_in_session[$row['session_id']]['course_list'][$course_info['real_id']] = $course_info;
         $temp_course_in_session[$row['session_id']]['name'] = $row['name'];
         $simple_session_array[$row['session_id']] = $row['name'];
     }
     foreach ($simple_session_array as $my_session_id => $session_name) {
         $course_list = $temp_course_in_session[$my_session_id]['course_list'];
         $my_course_data = array();
         foreach ($course_list as $course_data) {
             $my_course_data[$course_data['id']] = $course_data['title'];
         }
         if (empty($session_id)) {
             $my_course_data = ArrayClass::utf8_sort($my_course_data);
         }
         $final_course_data = array();
         foreach ($my_course_data as $course_id => $value) {
             $final_course_data[$course_id] = $course_list[$course_id];
         }
         $course_in_session[$my_session_id]['course_list'] = $final_course_data;
         $course_in_session[$my_session_id]['name'] = $session_name;
     }
     $html = '';
     // Course list
     if ($show_courses) {
         if (!empty($courses)) {
             $html .= Display::page_subheader(Display::return_icon('course.png', get_lang('MyCourses'), array(), ICON_SIZE_SMALL) . ' ' . get_lang('MyCourses'));
             $html .= '<table class="data_table" width="100%">';
             $html .= '<tr>
                       ' . Display::tag('th', get_lang('Course'), array('width' => '300px')) . '
                       ' . Display::tag('th', get_lang('TimeSpentInTheCourse'), array('class' => 'head')) . '
                       ' . Display::tag('th', get_lang('Progress'), array('class' => 'head')) . '
                       ' . Display::tag('th', get_lang('Score') . Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), array('class' => 'head')) . '
                       ' . Display::tag('th', get_lang('LastConnexion'), array('class' => 'head')) . '
                       ' . Display::tag('th', get_lang('Details'), array('class' => 'head')) . '
                     </tr>';
             foreach ($courses as $course_code => $course_title) {
                 $courseInfo = api_get_course_info($course_code);
                 $courseId = $courseInfo['real_id'];
                 $total_time_login = Tracking::get_time_spent_on_the_course($user_id, $courseId);
                 $time = api_time_to_hms($total_time_login);
                 $progress = Tracking::get_avg_student_progress($user_id, $course_code);
                 $percentage_score = Tracking::get_avg_student_score($user_id, $course_code, array());
                 $last_connection = Tracking::get_last_connection_date_on_the_course($user_id, $courseInfo);
                 if (is_null($progress)) {
                     $progress = '0%';
                 } else {
                     $progress = $progress . '%';
                 }
                 if (isset($_GET['course']) && $course_code == $_GET['course'] && empty($_GET['session_id'])) {
                     $html .= '<tr class="row_odd" style="background-color:#FBF09D">';
                 } else {
                     $html .= '<tr class="row_even">';
                 }
                 $url = api_get_course_url($course_code, $session_id);
                 $course_url = Display::url($course_title, $url, array('target' => SESSION_LINK_TARGET));
                 $html .= '<td>' . $course_url . '</td>';
                 $html .= '<td align="center">' . $time . '</td>';
                 $html .= '<td align="center">' . $progress . '</td>';
                 $html .= '<td align="center">';
                 if (is_numeric($percentage_score)) {
                     $html .= $percentage_score . '%';
                 } else {
                     $html .= '0%';
                 }
                 $html .= '</td>';
                 $html .= '<td align="center">' . $last_connection . '</td>';
                 $html .= '<td align="center">';
                 if (isset($_GET['course']) && $course_code == $_GET['course'] && empty($_GET['session_id'])) {
                     $html .= '<a href="#">';
                     $html .= Display::return_icon('2rightarrow_na.png', get_lang('Details'));
                 } else {
                     $html .= '<a href="' . api_get_self() . '?course=' . $course_code . $extra_params . '">';
                     $html .= Display::return_icon('2rightarrow.png', get_lang('Details'));
                 }
                 $html .= '</a>';
                 $html .= '</td></tr>';
             }
             $html .= '</table>';
         }
     }
     // Session list
     if (!empty($course_in_session)) {
         $main_session_graph = '';
         //Load graphics only when calling to an specific session
         $session_graph = array();
         $all_exercise_graph_name_list = array();
         $my_results = array();
         $all_exercise_graph_list = array();
         $all_exercise_start_time = array();
         foreach ($course_in_session as $my_session_id => $session_data) {
             $course_list = $session_data['course_list'];
             $session_name = $session_data['name'];
             $user_count = count(SessionManager::get_users_by_session($my_session_id));
             $exercise_graph_name_list = array();
             //$user_results = array();
             $exercise_graph_list = array();
             foreach ($course_list as $course_data) {
                 $exercise_list = ExerciseLib::get_all_exercises($course_data, $my_session_id, false, null, false, 1);
                 foreach ($exercise_list as $exercise_data) {
                     $exercise_obj = new Exercise($course_data['id']);
                     $exercise_obj->read($exercise_data['id']);
                     //Exercise is not necessary to be visible to show results check the result_disable configuration instead
                     //$visible_return = $exercise_obj->is_visible();
                     if ($exercise_data['results_disabled'] == 0 || $exercise_data['results_disabled'] == 2) {
                         $best_average = intval(ExerciseLib::get_best_average_score_by_exercise($exercise_data['id'], $course_data['id'], $my_session_id, $user_count));
                         $exercise_graph_list[] = $best_average;
                         $all_exercise_graph_list[] = $best_average;
                         $user_result_data = ExerciseLib::get_best_attempt_by_user(api_get_user_id(), $exercise_data['id'], $course_data['real_id'], $my_session_id);
                         $score = 0;
                         if (!empty($user_result_data['exe_weighting']) && intval($user_result_data['exe_weighting']) != 0) {
                             $score = intval($user_result_data['exe_result'] / $user_result_data['exe_weighting'] * 100);
                         }
                         $time = api_strtotime($exercise_data['start_time']) ? api_strtotime($exercise_data['start_time'], 'UTC') : 0;
                         $all_exercise_start_time[] = $time;
                         $my_results[] = $score;
                         if (count($exercise_list) <= 10) {
                             $title = cut($course_data['title'], 30) . " \n " . cut($exercise_data['title'], 30);
                             $exercise_graph_name_list[] = $title;
                             $all_exercise_graph_name_list[] = $title;
                         } else {
                             // if there are more than 10 results, space becomes difficult to find, so only show the title of the exercise, not the tool
                             $title = cut($exercise_data['title'], 30);
                             $exercise_graph_name_list[] = $title;
                             $all_exercise_graph_name_list[] = $title;
                         }
                     }
                 }
             }
         }
         // Complete graph
         if (!empty($my_results) && !empty($all_exercise_graph_list)) {
             asort($all_exercise_start_time);
             //Fix exams order
             $final_all_exercise_graph_name_list = array();
             $my_results_final = array();
             $final_all_exercise_graph_list = array();
             foreach ($all_exercise_start_time as $key => $time) {
                 $label_time = '';
                 if (!empty($time)) {
                     $label_time = date('d-m-y', $time);
                 }
                 $final_all_exercise_graph_name_list[] = $all_exercise_graph_name_list[$key] . ' ' . $label_time;
                 $my_results_final[] = $my_results[$key];
                 $final_all_exercise_graph_list[] = $all_exercise_graph_list[$key];
             }
             $main_session_graph = self::generate_session_exercise_graph($final_all_exercise_graph_name_list, $my_results_final, $final_all_exercise_graph_list);
         }
         $html .= Display::page_subheader(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_SMALL) . ' ' . get_lang('Sessions'));
         $html .= '<table class="data_table" width="100%">';
         $html .= '<tr>
               ' . Display::tag('th', get_lang('Session'), array('width' => '300px')) . '
               ' . Display::tag('th', get_lang('PublishedExercises'), array('width' => '300px')) . '
               ' . Display::tag('th', get_lang('NewExercises'), array('class' => 'head')) . '
               ' . Display::tag('th', get_lang('AverageExerciseResult'), array('class' => 'head')) . '
               ' . Display::tag('th', get_lang('Details'), array('class' => 'head')) . '
               </tr>';
         foreach ($course_in_session as $my_session_id => $session_data) {
             $course_list = $session_data['course_list'];
             $session_name = $session_data['name'];
             if ($showAllSessions == false) {
                 if (isset($session_id) && !empty($session_id)) {
                     if ($session_id != $my_session_id) {
                         continue;
                     }
                 }
             }
             $all_exercises = 0;
             $all_unanswered_exercises_by_user = 0;
             $all_average = 0;
             $stats_array = array();
             foreach ($course_list as $course_data) {
                 //All exercises in the course @todo change for a real count
                 $exercises = ExerciseLib::get_all_exercises($course_data, $my_session_id);
                 $count_exercises = 0;
                 if (is_array($exercises) && !empty($exercises)) {
                     $count_exercises = count($exercises);
                 }
                 // Count of user results
                 $done_exercises = null;
                 $courseInfo = api_get_course_info($course_data['code']);
                 $answered_exercises = 0;
                 if (!empty($exercises)) {
                     foreach ($exercises as $exercise_item) {
                         $attempts = Event::count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $courseInfo['real_id'], $my_session_id);
                         if ($attempts > 1) {
                             $answered_exercises++;
                         }
                     }
                 }
                 // Average
                 $average = ExerciseLib::get_average_score_by_course($courseInfo['real_id'], $my_session_id);
                 $all_exercises += $count_exercises;
                 $all_unanswered_exercises_by_user += $count_exercises - $answered_exercises;
                 $all_average += $average;
             }
             $all_average = $all_average / count($course_list);
             if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) {
                 $html .= '<tr style="background-color:#FBF09D">';
             } else {
                 $html .= '<tr>';
             }
             $url = api_get_path(WEB_CODE_PATH) . "session/index.php?session_id={$my_session_id}";
             $html .= Display::tag('td', Display::url($session_name, $url, array('target' => SESSION_LINK_TARGET)));
             $html .= Display::tag('td', $all_exercises);
             $html .= Display::tag('td', $all_unanswered_exercises_by_user);
             //$html .= Display::tag('td', $all_done_exercise);
             $html .= Display::tag('td', ExerciseLib::convert_to_percentage($all_average));
             if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) {
                 $icon = Display::url(Display::return_icon('2rightarrow_na.png', get_lang('Details')), '?session_id=' . $my_session_id);
             } else {
                 $icon = Display::url(Display::return_icon('2rightarrow.png', get_lang('Details')), '?session_id=' . $my_session_id);
             }
             $html .= Display::tag('td', $icon);
             $html .= '</tr>';
         }
         $html .= '</table><br />';
         $html .= Display::div($main_session_graph, array('id' => 'session_graph', 'class' => 'chart-session', 'style' => 'position:relative; text-align: center;'));
         // Checking selected session.
         if (isset($_GET['session_id'])) {
             $session_id_from_get = intval($_GET['session_id']);
             $session_data = $course_in_session[$session_id_from_get];
             $course_list = $session_data['course_list'];
             $html .= Display::tag('h3', $session_data['name'] . ' - ' . get_lang('CourseList'));
             $html .= '<table class="data_table" width="100%">';
             //'.Display::tag('th', get_lang('DoneExercises'),         array('class'=>'head')).'
             $html .= '
                 <tr>
                   <th width="300px">' . get_lang('Course') . '</th>
                   ' . Display::tag('th', get_lang('PublishedExercises'), array('class' => 'head')) . '
                   ' . Display::tag('th', get_lang('NewExercises'), array('class' => 'head')) . '
                   ' . Display::tag('th', get_lang('MyAverage'), array('class' => 'head')) . '
                   ' . Display::tag('th', get_lang('AverageExerciseResult'), array('class' => 'head')) . '
                   ' . Display::tag('th', get_lang('TimeSpentInTheCourse'), array('class' => 'head')) . '
                   ' . Display::tag('th', get_lang('LPProgress'), array('class' => 'head')) . '
                   ' . Display::tag('th', get_lang('Score') . Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), array('class' => 'head')) . '
                   ' . Display::tag('th', get_lang('LastConnexion'), array('class' => 'head')) . '
                   ' . Display::tag('th', get_lang('Details'), array('class' => 'head')) . '
                 </tr>';
             foreach ($course_list as $course_data) {
                 $course_code = $course_data['code'];
                 $course_title = $course_data['title'];
                 $courseInfo = api_get_course_info($course_code);
                 $courseId = $courseInfo['real_id'];
                 // All exercises in the course @todo change for a real count
                 $exercises = ExerciseLib::get_all_exercises($course_data, $session_id_from_get);
                 $count_exercises = 0;
                 if (!empty($exercises)) {
                     $count_exercises = count($exercises);
                 }
                 $answered_exercises = 0;
                 foreach ($exercises as $exercise_item) {
                     $attempts = Event::count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $courseId, $session_id_from_get);
                     if ($attempts > 1) {
                         $answered_exercises++;
                     }
                 }
                 $unanswered_exercises = $count_exercises - $answered_exercises;
                 // Average
                 $average = ExerciseLib::get_average_score_by_course($courseId, $session_id_from_get);
                 $my_average = ExerciseLib::get_average_score_by_course_by_user(api_get_user_id(), $courseId, $session_id_from_get);
                 $stats_array[$course_code] = array('exercises' => $count_exercises, 'unanswered_exercises_by_user' => $unanswered_exercises, 'done_exercises' => $done_exercises, 'average' => $average, 'my_average' => $my_average);
                 $weighting = 0;
                 $last_connection = Tracking::get_last_connection_date_on_the_course($user_id, $courseInfo, $session_id_from_get);
                 $progress = Tracking::get_avg_student_progress($user_id, $course_code, array(), $session_id_from_get);
                 $total_time_login = Tracking::get_time_spent_on_the_course($user_id, $courseId, $session_id_from_get);
                 $time = api_time_to_hms($total_time_login);
                 $percentage_score = Tracking::get_avg_student_score($user_id, $course_code, array(), $session_id_from_get);
                 $courseCodeFromGet = isset($_GET['course']) ? $_GET['course'] : null;
                 if ($course_code == $courseCodeFromGet && $_GET['session_id'] == $session_id_from_get) {
                     $html .= '<tr class="row_odd" style="background-color:#FBF09D" >';
                 } else {
                     $html .= '<tr class="row_even">';
                 }
                 $url = api_get_course_url($course_code, $session_id_from_get);
                 $course_url = Display::url($course_title, $url, array('target' => SESSION_LINK_TARGET));
                 $html .= Display::tag('td', $course_url);
                 $html .= Display::tag('td', $stats_array[$course_code]['exercises']);
                 $html .= Display::tag('td', $stats_array[$course_code]['unanswered_exercises_by_user']);
                 //$html .= Display::tag('td', $stats_array[$course_code]['done_exercises']);
                 $html .= Display::tag('td', ExerciseLib::convert_to_percentage($stats_array[$course_code]['my_average']));
                 $html .= Display::tag('td', $stats_array[$course_code]['average'] == 0 ? '-' : '(' . ExerciseLib::convert_to_percentage($stats_array[$course_code]['average']) . ')');
                 $html .= Display::tag('td', $time, array('align' => 'center'));
                 if (is_numeric($progress)) {
                     $progress = $progress . '%';
                 } else {
                     $progress = '0%';
                 }
                 //Progress
                 $html .= Display::tag('td', $progress, array('align' => 'center'));
                 if (is_numeric($percentage_score)) {
                     $percentage_score = $percentage_score . '%';
                 } else {
                     $percentage_score = '0%';
                 }
                 //Score
                 $html .= Display::tag('td', $percentage_score, array('align' => 'center'));
                 $html .= Display::tag('td', $last_connection, array('align' => 'center'));
                 if ($course_code == $courseCodeFromGet && $_GET['session_id'] == $session_id_from_get) {
                     $details = '<a href="#">';
                     $details .= Display::return_icon('2rightarrow_na.png', get_lang('Details'));
                 } else {
                     $details = '<a href="' . api_get_self() . '?course=' . $course_code . '&session_id=' . $session_id_from_get . $extra_params . '">';
                     $details .= Display::return_icon('2rightarrow.png', get_lang('Details'));
                 }
                 $details .= '</a>';
                 $html .= Display::tag('td', $details, array('align' => 'center'));
                 $html .= '</tr>';
             }
             $html .= '</table>';
         }
     }
     return $html;
 }
/**
 * Display the goto course button of a course in the course catalog
 * @param $course
 */
function return_goto_button($course)
{
    $html = ' <a class="btn btn-default btn-sm" title="' . get_lang('GoToCourse') . '" href="' . api_get_course_url($course['code']) . '">' . Display::returnFontAwesomeIcon('share') . '</a>';
    return $html;
}
Example #5
0
 /**
  * Subscribe the user to a given course
  * @param string Course code
  * @return string  Message about results
  */
 public function subscribe_user($course_code)
 {
     $user_id = api_get_user_id();
     $all_course_information = CourseManager::get_course_information($course_code);
     if ($all_course_information['registration_code'] == '' || $_POST['course_registration_code'] == $all_course_information['registration_code']) {
         if (api_is_platform_admin()) {
             $status_user_in_new_course = COURSEMANAGER;
         } else {
             $status_user_in_new_course = null;
         }
         if (CourseManager::add_user_to_course($user_id, $course_code, $status_user_in_new_course)) {
             $send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $course_code);
             if ($send == 1) {
                 CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = false);
             } else {
                 if ($send == 2) {
                     CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = true);
                 }
             }
             $url = Display::url($all_course_information['title'], api_get_course_url($course_code));
             $message = sprintf(get_lang('EnrollToCourseXSuccessful'), $url);
         } else {
             $message = get_lang('ErrorContactPlatformAdmin');
         }
         return array('message' => $message);
     } else {
         if (isset($_POST['course_registration_code']) && $_POST['course_registration_code'] != $all_course_information['registration_code']) {
             return false;
         }
         $message = get_lang('CourseRequiresPassword') . '<br />';
         $message .= $all_course_information['title'] . ' (' . $all_course_information['visual_code'] . ') ';
         $action = api_get_path(WEB_CODE_PATH) . "auth/courses.php?action=subscribe_user_with_password&sec_token=" . $_SESSION['sec_token'];
         $form = new FormValidator('subscribe_user_with_password', 'post', $action);
         $form->addElement('hidden', 'sec_token', $_SESSION['sec_token']);
         $form->addElement('hidden', 'subscribe_user_with_password', $all_course_information['code']);
         $form->addElement('text', 'course_registration_code');
         $form->addButton(get_lang('SubmitRegistrationCode'));
         $content = $form->returnForm();
         return array('message' => $message, 'content' => $content);
     }
 }
/**
 * Display the goto course button of a course in the course catalog
 * @param $course
 */
function return_goto_button($course)
{
    $html = ' <a class="btn btn-primary" href="' . api_get_course_url($course['code']) . '">' . get_lang('GoToCourse') . '</a>';
    return $html;
}
        if ($count == 0) {
            $upIcon = 'up_na.png';
            $urlUp = '#';
        }
        $orderButtons = Display::url(Display::return_icon($upIcon, get_lang('MoveUp')), $urlUp);
        $downIcon = 'down.png';
        $downUrl = api_get_self() . '?id_session=' . $sessionId . '&course_id=' . $course->getId() . '&action=move_down';
        if ($count + 1 == count($courses)) {
            $downIcon = 'down_na.png';
            $downUrl = '#';
        }
        $orderButtons .= Display::url(Display::return_icon($downIcon, get_lang('MoveDown')), $downUrl);
        if (!SessionManager::orderCourseIsEnabled()) {
            $orderButtons = '';
        }
        $courseUrl = api_get_course_url($course->getCode(), $sessionId);
        // hide_course_breadcrumb the parameter has been added to hide the name
        // of the course, that appeared in the default $interbreadcrumb
        $courseItem .= '
		<tr>
			<td class="title">' . Display::url($course->getTitle() . ' (' . $course->getVisualCode() . ')', $courseUrl) . '</td>
			<td>' . $coach . '</td>
			<td>' . $numberOfUsers . '</td>
			<td>
                <a href="' . $courseUrl . '">' . Display::return_icon('course_home.gif', get_lang('Course')) . '</a>
                ' . $orderButtons . '
                <a href="session_course_user_list.php?id_session=' . $sessionId . '&course_code=' . $course->getCode() . '">' . Display::return_icon('user.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>
                <a href="' . api_get_path(WEB_CODE_PATH) . '/user/user_import.php?action=import&cidReq=' . $course->getCode() . '&id_session=' . $sessionId . '">' . Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'), null, ICON_SIZE_SMALL) . '</a>
				<a href="../tracking/courseLog.php?id_session=' . $sessionId . '&cidReq=' . $course->getCode() . $orig_param . '&hide_course_breadcrumb=1">' . Display::return_icon('statistics.gif', get_lang('Tracking')) . '</a>&nbsp;
				<a href="session_course_edit.php?id_session=' . $sessionId . '&page=resume_session.php&course_code=' . $course->getCode() . '' . $orig_param . '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>
				<a href="' . api_get_self() . '?id_session=' . $sessionId . '&action=delete&idChecked[]=' . $course->getCode() . '" onclick="javascript:if(!confirm(\'' . get_lang('ConfirmYourChoice') . '\')) return false;">' . Display::return_icon('delete.png', get_lang('Delete')) . '</a>
Example #8
0
                        api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$sessionId
                    );
                    $_SESSION['bc_message'] = 'EnrollToSessionXSuccessful';
                    $_SESSION['bc_url'] = $url;
                    $_SESSION['bc_success'] = true;
                } else {
                    $course_code = $_SESSION['bc_codetext'];
                    $all_course_information = CourseManager::get_course_information($course_code);
                    if (CourseManager::subscribe_user($user_id, $course_code)) {
                        $send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $course_code);
                        if ($send == 1) {
                            CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = false);
                        } else if ($send == 2) {
                            CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = true);
                        }
                        $url = Display::url($all_course_information['title'], api_get_course_url($course_code));
                        $_SESSION['bc_message'] = 'EnrollToCourseXSuccessful';
                        $_SESSION['bc_url'] = $url;
                        $_SESSION['bc_success'] = true;
                    } else {
                        $_SESSION['bc_message'] = 'ErrorContactPlatformAdmin';
                        $_SESSION['bc_success'] = false;
                    }
                }

                // Activate the use
                $TABLE_USER = Database::get_main_table(TABLE_MAIN_USER);
                $sql = "UPDATE " . $TABLE_USER . "	SET active='1' WHERE user_id='" . $_SESSION['bc_user_id'] . "'";
                Database::query($sql);

                $user_table = Database::get_main_table(TABLE_MAIN_USER);
 echo '</div>';
 echo '<div class="col-md-8">';
 $teachers = CourseManager::get_teacher_list_from_course_code_to_string($course['real_id']);
 $teachers = '<h5>' . $teachers . '</h5>';
 echo '<div class="categories-course-description"><h3>' . Text::cut($title, 60) . '</h3>' . $teachers . $rating . '</div>';
 echo '<p>';
 // we display the icon to subscribe or the text already subscribed
 echo '<div class="btn-toolbar">';
 if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
     echo '<a class="ajax btn btn-default" href="' . api_get_path(WEB_CODE_PATH) . 'inc/ajax/course_home.ajax.php?a=show_course_information&amp;code=' . $course['code'] . '" class="thickbox">' . get_lang('Description') . '</a>';
 }
 // Get access type for course button ("enter" or/and "register")
 $access_type = CourseManager::get_access_link_by_user(api_get_user_id(), $course);
 // Go To Course button (only if admin, if course public or if student already subscribed)
 if ($access_type && in_array('enter', $access_type)) {
     echo ' <a class="btn btn-primary" href="' . api_get_course_url($course['code']) . '">' . get_lang('GoToCourse') . '</a>';
 }
 // Register button
 if ($access_type && in_array('register', $access_type)) {
     echo ' <a class="btn btn-primary" href="' . api_get_self() . '?action=subscribe_course&amp;sec_token=' . $stok . '&amp;subscribe_course=' . $course['code'] . '&amp;search_term=' . $search_term . '&amp;category_code=' . $code . '">' . get_lang('Subscribe') . '</a>';
 }
 // If user is already subscribed to the course
 if (!api_is_anonymous() && in_array($course['code'], $user_coursecodes)) {
     if ($course['unsubscribe'] == UNSUBSCRIBE_ALLOWED) {
         echo ' <a class="btn btn-primary" href="' . api_get_self() . '?action=unsubscribe&amp;sec_token=' . $stok . '&amp;unsubscribe=' . $course['code'] . '&amp;search_term=' . $search_term . '&amp;category_code=' . $code . '">' . get_lang('Unsubscribe') . '</a>';
     }
     echo '<br />';
     echo '<br />';
     echo Display::label(get_lang("AlreadyRegisteredToCourse"), "info");
 }
 echo '</div>';
 * Security check
 */
if (empty($course_id)) {
    api_not_allowed();
}
/**
 * Code
 */
$course_info = api_get_course_info_by_id($course_id);
$tpl = new Template(null);
// Build the form
$form = new FormValidator('set_temp_password', 'POST', api_get_self() . '?course_id=' . $course_id . '&session_id=' . $session_id);
$form->addElement('header', get_lang('CourseRequiresPassword'));
$form->addElement('hidden', 'course_id', $course_id);
$form->addElement('hidden', 'session_id', $session_id);
$form->addElement('password', 'course_password', null, get_lang('Password'));
$form->addButtonSave(get_lang('Accept'));
if ($form->validate()) {
    $form_values = $form->exportValues();
    if ($form_values['course_password'] === $course_info['registration_code']) {
        Session::write('course_password_' . $course_info['real_id'], true);
        header('Location: ' . api_get_course_url($course_info['code'], $session_id));
        exit;
    } else {
        $tpl->assign('error_message', Display::display_error_message(get_lang('CourseRegistrationCodeIncorrect'), true, true));
    }
}
$tpl->assign('form', $form->toHtml());
$content = $tpl->get_template('auth/set_temp_password.tpl');
$tpl->assign('content', $tpl->fetch($content));
$tpl->display_one_col_template();
Example #11
0
// Display the header
Display::display_header(get_lang('CopyCourse'));
echo Display::page_header(get_lang('CopyCourse'));
/*	MAIN CODE */
// If a CourseSelectForm is posted or we should copy all resources, then copy them
if (isset($_POST['action']) && $_POST['action'] == 'course_select_form' || isset($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy') {
    if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
        $course = CourseSelectForm::get_posted_course('copy_course');
    } else {
        $cb = new CourseBuilder();
        $course = $cb->build();
    }
    $cr = new CourseRestorer($course);
    $cr->set_file_option($_POST['same_file_name_option']);
    $cr->restore($_POST['destination_course']);
    Display::display_normal_message(get_lang('CopyFinished') . ': <a href="' . api_get_course_url($_POST['destination_course']) . '">' . $_POST['destination_course'] . '</a>', false);
} elseif (isset($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
    $cb = new CourseBuilder();
    $course = $cb->build();
    $hidden_fields = array();
    $hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
    $hidden_fields['destination_course'] = $_POST['destination_course'];
    CourseSelectForm::display_form($course, $hidden_fields, true);
} else {
    $table_c = Database::get_main_table(TABLE_MAIN_COURSE);
    $table_cu = Database::get_main_table(TABLE_MAIN_COURSE_USER);
    $user_info = api_get_user_info();
    $course_info = api_get_course_info();
    $sql = 'SELECT * FROM ' . $table_c . ' c, ' . $table_cu . ' cu WHERE cu.c_id = c.id';
    if (!api_is_platform_admin()) {
        $sql .= ' AND cu.status=1 ';
Example #12
0
                            $course['exercises'][$exercise_item['id']]['data']['exercise_data'] =  $exercise;
                            $course['exercises'][$exercise_item['id']]['data']['results']       =  $user_results;
                        }
                    }
                    $final_array[$my_session_id]['data'][$my_course['code']] = $course;
                }
            }
        }
        $my_session_list[] =  $my_session_id;
    }
}*/
$new_course_list = array();
if (!empty($course_list)) {
    foreach ($course_list as $course_data) {
        if (in_array($course_data['code'], $user_course_list) || api_is_anonymous()) {
            $course_data['title'] = Display::url($course_data['title'], api_get_course_url($course_data['code'], $session_id));
        } else {
            continue;
        }
        $list = new LearnpathList(api_get_user_id(), $course_data['code'], $session_id, 'publicated_on ASC', true);
        $lp_list = $list->get_flat_list();
        $lp_count = 0;
        if (!empty($lp_list)) {
            foreach ($lp_list as $valLp) {
                if ($valLp['lp_visibility']) {
                    $lp_count++;
                }
            }
        }
        $course_info = api_get_course_info($course_data['code']);
        $exercise_count = count(ExerciseLib::get_all_exercises($course_info, $session_id, true, null, false, 1));
/**
 * Display the goto course button of a course in the course catalog
 * @param $course
 */
function display_goto_button($course)
{
    echo ' <a class="btn btn-primary" href="'.api_get_course_url($course['code']).'">'.get_lang('GoToCourse').'</a>';
}
Example #14
0
                    }
                    $final_array[$my_session_id]['data'][$my_course['code']] = $course;
                }
            }
        }
        $my_session_list[] =  $my_session_id;
    }
}
$new_course_list = array();

if (!empty($course_list)) {
    foreach ($course_list as $course_data) {
        if (in_array($course_data['code'], $user_course_list)) {
            $course_data['title'] = Display::url(
                $course_data['title'],
                api_get_course_url($course_data['code'], $session_id)
            );
        } else {
            continue;
        }

        $list = new LearnpathList(
            api_get_user_id(),
            $course_data['code'],
            $session_id,
            'publicated_on ASC',
            true
        );
        $lp_list = $list->get_flat_list();

        $lp_count = 0;
    }
}
$total_score = 0;
if (!empty($exercise_stat_info)) {
    $total_score = $exercise_stat_info['exe_result'];
}
$max_score = $objExercise->get_max_score();
Display::display_normal_message(get_lang('Saved') . '<br />', false);
// Display and save questions
ExerciseLib::display_question_list_by_attempt($objExercise, $exe_id, true);
//Unset session for clock time
ExerciseLib::exercise_time_control_delete($objExercise->id, $learnpath_id, $learnpath_item_id);
ExerciseLib::delete_chat_exercise_session($exe_id);
if ($origin != 'learnpath') {
    echo '<hr>';
    echo Display::url(get_lang('ReturnToCourseHomepage'), api_get_course_url(), array('class' => 'btn btn-primary'));
    if (api_is_allowed_to_session_edit()) {
        Session::erase('objExercise');
        Session::erase('exe_id');
    }
    Display::display_footer();
} else {
    $lp_mode = Session::read('lp_mode');
    $url = '../newscorm/lp_controller.php?cidReq=' . api_get_course_id() . '&action=view&lp_id=' . $learnpath_id . '&lp_item_id=' . $learnpath_item_id . '&exeId=' . $exercise_stat_info['exe_id'] . '&fb_type=' . $objExercise->feedback_type;
    $href = $lp_mode == 'fullscreen' ? ' window.opener.location.href="' . $url . '" ' : ' top.location.href="' . $url . '"';
    if (api_is_allowed_to_session_edit()) {
        Session::erase('objExercise');
        Session::erase('exe_id');
    }
    // Record the results in the learning path, using the SCORM interface (API)
    echo "<script>window.parent.API.void_save_asset('{$total_score}', '{$max_score}', 0, 'completed');</script>";
Example #16
0
 /**
  * Assign coaches of a session(s) as teachers to a given course (or courses)
  * @param array A list of session IDs
  * @param array A list of course IDs
  * @return string
  */
 public static function copyCoachesFromSessionToCourse($sessions, $courses)
 {
     $coachesPerSession = array();
     foreach ($sessions as $sessionId) {
         $coaches = self::getCoachesBySession($sessionId);
         $coachesPerSession[$sessionId] = $coaches;
     }
     $result = array();
     if (!empty($courses)) {
         foreach ($courses as $courseId) {
             $courseInfo = api_get_course_info_by_id($courseId);
             foreach ($coachesPerSession as $sessionId => $coachList) {
                 CourseManager::updateTeachers($courseInfo['real_id'], $coachList, false, false, false);
                 $result[$courseInfo['code']][$sessionId] = $coachList;
             }
         }
     }
     $sessionUrl = api_get_path(WEB_CODE_PATH) . 'admin/resume_session.php?id_session=';
     $htmlResult = null;
     if (!empty($result)) {
         foreach ($result as $courseCode => $data) {
             $url = api_get_course_url($courseCode);
             $htmlResult .= sprintf(get_lang('CoachesSubscribedAsATeacherInCourseX'), Display::url($courseCode, $url, array('target' => '_blank')));
             foreach ($data as $sessionId => $coachList) {
                 $sessionInfo = self::fetch($sessionId);
                 $htmlResult .= '<br />';
                 $htmlResult .= Display::url(get_lang('Session') . ': ' . $sessionInfo['name'] . ' <br />', $sessionUrl . $sessionId, array('target' => '_blank'));
                 $teacherList = array();
                 foreach ($coachList as $coachId) {
                     $userInfo = api_get_user_info($coachId);
                     $teacherList[] = $userInfo['complete_name'];
                 }
                 if (!empty($teacherList)) {
                     $htmlResult .= implode(', ', $teacherList);
                 } else {
                     $htmlResult .= get_lang('NothingToAdd');
                 }
             }
             $htmlResult .= '<br />';
         }
         $htmlResult = Display::return_message($htmlResult, 'normal', false);
     }
     return $htmlResult;
 }
 /**
  * @param int    $courseId
  * @param int    $sessionId
  * @param string $filePath
  */
 public function warnUsersByEmail($courseId, $sessionId, $filePath = null)
 {
     $courseInfo = api_get_course_info_by_id($courseId);
     $courseCode = $courseInfo['code'];
     if (empty($sessionId)) {
         $students = CourseManager::get_student_list_from_course_code($courseCode, false);
     } else {
         $students = CourseManager::get_student_list_from_course_code($courseCode, true, $sessionId);
     }
     $url = api_get_course_url($courseCode, $sessionId);
     $url = Display::url($url, $url);
     $subject = $this->get_lang("AgreementUpdated");
     $message = sprintf($this->get_lang("AgreementWasUpdatedClickHere"), $url);
     $dataFile = array();
     if (!empty($filePath)) {
         $dataFile = array('path' => $filePath, 'filename' => basename($filePath));
         $message = sprintf($this->get_lang("AgreementWasUpdatedClickHere"), $url) . " \n";
         $message .= $this->get_lang("TheAgreementIsAttachedInThisEmail");
     }
     if (!empty($students)) {
         foreach ($students as $student) {
             $userInfo = api_get_user_info($student['user_id']);
             api_mail_html($userInfo['complete_name'], $userInfo['email'], $subject, $message, null, null, null, $dataFile);
             //MessageManager::send_message_simple($student['user_id'], $subject, $message);
         }
     }
 }
 /**
  * Returns a HTML link when the exercise ends (exercise result page)
  * @return string
  */
 public function returnEndButtonHTML()
 {
     $endButtonSetting = $this->selectEndButton();
     $html = '';
     switch ($endButtonSetting) {
         case '0':
             $html = Display::url(get_lang('ReturnToCourseHomepage'), api_get_course_url(), array('class' => 'btn btn-large'));
             break;
         case '1':
             $html = Display::url(get_lang('ReturnToExerciseList'), api_get_path(WEB_CODE_PATH) . 'exercice/exercice.php?' . api_get_cidreq(), array('class' => 'btn btn-large'));
             break;
         case '2':
             global $app;
             $url = $app['url_generator']->generate('logout');
             $html = Display::url(get_lang('Logout'), $url, array('class' => 'btn btn-large'));
             break;
     }
     return $html;
 }