$all_datas = array();
 $course_code = $_course['id'];
 foreach ($a_students as $student_id => $student) {
     $student_datas = UserManager::get_user_info_by_id($student_id);
     $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
     $nb_courses_student = 0;
     $avg_time_spent = Tracking::get_time_spent_on_the_course($student_id, $course_code);
     $avg_student_score = Tracking::get_average_test_scorm_and_lp($student_id, $course_code);
     $avg_student_progress = Tracking::get_avg_student_progress($student_id, $course_code);
     $total_assignments = Tracking::count_student_assignments($student_id, $course_code);
     $total_messages = Tracking::count_student_messages($student_id, $course_code);
     $row = array();
     $row[] = $student_datas['official_code'];
     $row[] = $student_datas['lastname'];
     $row[] = $student_datas['firstname'];
     $row[] = api_time_to_hms($avg_time_spent);
     if (is_null($avg_student_score)) {
         $avg_student_score = 0;
     }
     if (is_null($avg_student_progress)) {
         $avg_student_progress = 0;
     }
     $row[] = $avg_student_progress . ' %';
     $row[] = $avg_student_score . ' %';
     $row[] = $total_assignments;
     $row[] = $total_messages;
     $row[] = Tracking::get_first_connection_date_on_the_course($student_id, $course_code);
     $row[] = Tracking::get_last_connection_date_on_the_course($student_id, $course_code);
     if ($export_csv) {
         $row[8] = strip_tags($row[8]);
         $csv_content[] = $row;
Ejemplo n.º 2
0
 /**
  * Get data for courses list in sortable with pagination
  * @return array
  */
 public static function get_course_data($from, $number_of_items, $column, $direction)
 {
     global $courses, $csv_content, $charset, $session_id;
     // definition database tables
     $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
     $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $course_data = array();
     $courses_code = array_keys($courses);
     foreach ($courses_code as &$code) {
         $code = "'{$code}'";
     }
     // get all courses with limit
     $sql = "SELECT course.code as col1, course.title as col2\n                FROM {$tbl_course} course\n                WHERE course.code IN (" . implode(',', $courses_code) . ")";
     if (!in_array($direction, array('ASC', 'DESC'))) {
         $direction = 'ASC';
     }
     $column = intval($column);
     $from = intval($from);
     $number_of_items = intval($number_of_items);
     $sql .= " ORDER BY col{$column} {$direction} ";
     $sql .= " LIMIT {$from},{$number_of_items}";
     $res = Database::query($sql);
     while ($row_course = Database::fetch_row($res)) {
         $course_code = $row_course[0];
         $courseInfo = api_get_course_info($course_code);
         $courseId = $courseInfo['real_id'];
         $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0;
         // students directly subscribed to the course
         if (empty($session_id)) {
             $sql = "SELECT user_id\n                        FROM {$tbl_course_user} as course_rel_user\n                        WHERE\n                            course_rel_user.status='5' AND\n                            course_rel_user.c_id = '{$courseId}'";
         } else {
             $sql = "SELECT user_id FROM {$tbl_session_course_user} srcu\n                        WHERE\n                            c_id = '{$courseId}' AND\n                            session_id = '{$session_id}' AND\n                            status<>2";
         }
         $rs = Database::query($sql);
         $users = array();
         while ($row = Database::fetch_array($rs)) {
             $users[] = $row['user_id'];
         }
         if (count($users) > 0) {
             $nb_students_in_course = count($users);
             $avg_assignments_in_course = Tracking::count_student_assignments($users, $course_code, $session_id);
             $avg_messages_in_course = Tracking::count_student_messages($users, $course_code, $session_id);
             $avg_progress_in_course = Tracking::get_avg_student_progress($users, $course_code, array(), $session_id);
             $avg_score_in_course = Tracking::get_avg_student_score($users, $course_code, array(), $session_id);
             $avg_score_in_exercise = Tracking::get_avg_student_exercise_score($users, $course_code, 0, $session_id);
             $avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $courseInfo['real_id'], $session_id);
             $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
             if (is_numeric($avg_score_in_course)) {
                 $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2);
             }
             $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
         } else {
             $avg_time_spent_in_course = null;
             $avg_progress_in_course = null;
             $avg_score_in_course = null;
             $avg_score_in_exercise = null;
             $avg_messages_in_course = null;
             $avg_assignments_in_course = null;
         }
         $table_row = array();
         $table_row[] = $row_course[1];
         $table_row[] = $nb_students_in_course;
         $table_row[] = $avg_time_spent_in_course;
         $table_row[] = is_null($avg_progress_in_course) ? '' : $avg_progress_in_course . '%';
         $table_row[] = is_null($avg_score_in_course) ? '' : $avg_score_in_course . '%';
         $table_row[] = is_null($avg_score_in_exercise) ? '' : $avg_score_in_exercise . '%';
         $table_row[] = $avg_messages_in_course;
         $table_row[] = $avg_assignments_in_course;
         //set the "from" value to know if I access the Reporting by the chamilo tab or the course link
         $table_row[] = '<center><a href="../../tracking/courseLog.php?cidReq=' . $course_code . '&from=myspace&id_session=' . $session_id . '">
                          <img src="' . api_get_path(WEB_IMG_PATH) . 'icons/22/2rightarrow.png" border="0" /></a>
                         </center>';
         $csv_content[] = array(api_html_entity_decode($row_course[1], ENT_QUOTES, $charset), $nb_students_in_course, $avg_time_spent_in_course, is_null($avg_progress_in_course) ? null : $avg_progress_in_course . '%', is_null($avg_score_in_course) ? null : is_numeric($avg_score_in_course) ? $avg_score_in_course . '%' : $avg_score_in_course, is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise . '%', $avg_messages_in_course, $avg_assignments_in_course);
         $course_data[] = $table_row;
     }
     return $course_data;
 }
Ejemplo n.º 3
0
             $column_names[] = $extra['3'];
         }
     }
     if (!in_array($sidx, array('training_hours'))) {
         //$sidx = 'training_hours';
     }
     if (api_is_student_boss() && empty($userIdList)) {
         $result = [];
         break;
     }
     $result = CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", null, null, null, true, true, array('ruc'), $courseCodeList, $userIdList, null, $sessionIdList);
     $new_result = array();
     if (!empty($result)) {
         foreach ($result as $row) {
             $row['training_hours'] = api_time_to_hms($row['training_hours']);
             $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']);
             $new_result[] = $row;
         }
         $result = $new_result;
     }
     break;
 case 'get_user_course_report':
     $columns = array('course', 'user', 'email', 'time', 'certificate', 'progress_100', 'progress');
     $column_names = array(get_lang('Course'), get_lang('User'), get_lang('Email'), get_lang('ManHours'), get_lang('CertificateGenerated'), get_lang('Approved'), get_lang('CourseAdvance'));
     $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
     if (!empty($extra_fields)) {
         foreach ($extra_fields as $extra) {
             $columns[] = $extra['1'];
             $column_names[] = $extra['3'];
         }
     }
Ejemplo n.º 4
0
    $headerList = array();
    foreach ($header as $item) {
        $headerList[] = $item[0];
    }
    $csvContent[] = array();
    $csvContent[] = array(get_lang('Courses'));
    $csvContent[] = $headerList;
    $data = array();
    $courseToolInformationTotal = null;
    while ($course = Database::fetch_object($res)) {
        $courseToolInformation = null;
        $tools = '<a href="course_information.php?code=' . $course->code . '">' . Display::return_icon('synthese_view.gif', get_lang('Overview')) . '</a>' . '<a href="' . api_get_path(WEB_COURSE_PATH) . $course->directory . '">' . Display::return_icon('course_home.gif', get_lang('CourseHomepage')) . '</a>' . '<a href="course_edit.php?course_code=' . $course->code . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>';
        if ($course->status == STUDENT) {
            $tools .= '<a href="user_information.php?action=unsubscribe&course_code=' . $course->code . '&user_id=' . $user['user_id'] . '">' . Display::return_icon('delete.png', get_lang('Delete')) . '</a>';
        }
        $timeSpent = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $course->code, 0));
        $totalForumMessages = CourseManager::getCountPostInForumPerUser($user['user_id'], $course->id, 0);
        $courseInfo = api_get_course_info($course->code);
        $row = array(Display::url($course->code, $courseInfo['course_public_url']), $course->title, $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'), $timeSpent, $totalForumMessages, $tools);
        $csvContent[] = array_map('strip_tags', $row);
        $data[] = $row;
        $result = TrackingUserLogCSV::getToolInformation($user['user_id'], $courseInfo, 0);
        $courseToolInformationTotal .= $result['html'];
        $csvContent = array_merge($csvContent, $result['array']);
    }
    $courseInformation = Display::page_subheader(get_lang('Courses'));
    $courseInformation .= Display::return_sortable_table($header, $data, array(), array(), array('user_id' => intval($_GET['user_id'])));
    $courseInformation .= $courseToolInformationTotal;
} else {
    $courseInformation = '<p>' . get_lang('NoCoursesForThisUser') . '</p>';
}
Ejemplo n.º 5
0
 /**
  * Return user info array of all users registered in a course
  * This only returns the users that are registered in this actual course, not linked courses.
  * @param string $course_code
  * @param int $session_id
  * @param string $limit
  * @param string $order_by the field to order the users by.
  * Valid values are 'lastname', 'firstname', 'username', 'email', 'official_code' OR a part of a SQL statement
  * that starts with ORDER BY ...
  * @param null $filter_by_status if using the session_id: 0 or 2 (student, coach),
  * if using session_id = 0 STUDENT or COURSEMANAGER
  * @param null $return_count
  * @param bool $add_reports
  * @param bool $resumed_report
  * @param array $extra_field
  * @param array $courseCodeList
  * @param array $userIdList
  * @param string $filterByActive
  * @param array $sessionIdList
  * @return array|int
  */
 public static function get_user_list_from_course_code($course_code = null, $session_id = 0, $limit = null, $order_by = null, $filter_by_status = null, $return_count = null, $add_reports = false, $resumed_report = false, $extra_field = array(), $courseCodeList = array(), $userIdList = array(), $filterByActive = null, $sessionIdList = array())
 {
     $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
     $sessionTable = Database::get_main_table(TABLE_MAIN_SESSION);
     $session_id = intval($session_id);
     $course_code = Database::escape_string($course_code);
     $courseInfo = api_get_course_info($course_code);
     $courseId = 0;
     if (!empty($courseInfo)) {
         $courseId = $courseInfo['real_id'];
     }
     $where = array();
     if (empty($order_by)) {
         $order_by = 'user.lastname, user.firstname';
         if (api_is_western_name_order()) {
             $order_by = 'user.firstname, user.lastname';
         }
     }
     // if the $order_by does not contain 'ORDER BY'
     // we have to check if it is a valid field that can be sorted on
     if (!strstr($order_by, 'ORDER BY')) {
         if (!empty($order_by)) {
             $order_by = 'ORDER BY ' . $order_by;
         } else {
             $order_by = '';
         }
     }
     $filter_by_status_condition = null;
     if (!empty($session_id) || !empty($sessionIdList)) {
         $sql = 'SELECT DISTINCT
                     user.user_id,
                     user.email,
                     session_course_user.status as status_session,
                     session_id,
                     user.*,
                     course.*,
                     session.name as session_name
                 ';
         if ($return_count) {
             $sql = " SELECT COUNT(user.user_id) as count";
         }
         $sessionCondition = " session_course_user.session_id = {$session_id}";
         if (!empty($sessionIdList)) {
             $sessionIdListTostring = implode("','", array_map('intval', $sessionIdList));
             $sessionCondition = " session_course_user.session_id IN ('{$sessionIdListTostring}') ";
         }
         $courseCondition = " course.id = {$courseId}";
         if (!empty($courseCodeList)) {
             $courseCodeListForSession = array_map(array('Database', 'escape_string'), $courseCodeList);
             $courseCodeListForSession = implode('","', $courseCodeListForSession);
             $courseCondition = ' course.code IN ("' . $courseCodeListForSession . '")  ';
         }
         $sql .= ' FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
         $sql .= " LEFT JOIN " . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . " as session_course_user\n                      ON\n                        user.user_id = session_course_user.user_id AND\n                        {$sessionCondition}\n                        INNER JOIN {$course_table} course ON session_course_user.c_id = course.id AND\n                        {$courseCondition}\n                        INNER JOIN {$sessionTable} session ON session_course_user.session_id = session.id\n                   ";
         $where[] = ' session_course_user.c_id IS NOT NULL ';
         // 2 = coach
         // 0 = student
         if (isset($filter_by_status)) {
             $filter_by_status = intval($filter_by_status);
             $filter_by_status_condition = " session_course_user.status = {$filter_by_status} AND ";
         }
     } else {
         if ($return_count) {
             $sql = " SELECT COUNT(*) as count";
             if ($resumed_report) {
                 //$sql = " SELECT count(field_id) ";
             }
         } else {
             if (empty($course_code)) {
                 $sql = 'SELECT DISTINCT
                             course.title,
                             course.code,
                             course_rel_user.status as status_rel,
                             user.user_id,
                             user.email,
                             course_rel_user.is_tutor,
                             user.*  ';
             } else {
                 $sql = 'SELECT DISTINCT
                             course_rel_user.status as status_rel,
                             user.user_id,
                             user.email,
                             course_rel_user.is_tutor,
                             user.*  ';
             }
         }
         $sql .= ' FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
         $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_COURSE_USER) . ' as course_rel_user
                     ON user.user_id = course_rel_user.user_id AND
                     course_rel_user.relation_type <> ' . COURSE_RELATION_TYPE_RRHH . '  ';
         $sql .= " INNER JOIN {$course_table} course ON course_rel_user.c_id = course.id ";
         if (!empty($course_code)) {
             $sql .= ' AND course_rel_user.c_id="' . $courseId . '"';
         }
         $where[] = ' course_rel_user.c_id IS NOT NULL ';
         if (isset($filter_by_status) && is_numeric($filter_by_status)) {
             $filter_by_status = intval($filter_by_status);
             $filter_by_status_condition = " course_rel_user.status = {$filter_by_status} AND ";
         }
     }
     $multiple_access_url = api_get_multiple_access_url();
     if ($multiple_access_url) {
         $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER) . ' au
                   ON (au.user_id = user.user_id) ';
     }
     $extraFieldWasAdded = false;
     if ($return_count && $resumed_report) {
         foreach ($extra_field as $extraField) {
             $extraFieldInfo = UserManager::get_extra_field_information_by_name($extraField);
             if (!empty($extraFieldInfo)) {
                 $fieldValuesTable = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
                 $sql .= ' LEFT JOIN ' . $fieldValuesTable . ' as ufv
                         ON (
                             user.user_id = ufv.item_id AND
                             (field_id = ' . $extraFieldInfo['id'] . ' OR field_id IS NULL)
                         )';
                 $extraFieldWasAdded = true;
             }
         }
     }
     $sql .= ' WHERE ' . $filter_by_status_condition . ' ' . implode(' OR ', $where);
     if ($multiple_access_url) {
         $current_access_url_id = api_get_current_access_url_id();
         $sql .= " AND (access_url_id =  {$current_access_url_id} ) ";
     }
     if ($return_count && $resumed_report && $extraFieldWasAdded) {
         $sql .= ' AND field_id IS NOT NULL GROUP BY value ';
     }
     if (!empty($courseCodeList)) {
         $courseCodeList = array_map(array('Database', 'escape_string'), $courseCodeList);
         $courseCodeList = implode('","', $courseCodeList);
         if (empty($sessionIdList)) {
             $sql .= ' AND course.code IN ("' . $courseCodeList . '")';
         }
     }
     if (!empty($userIdList)) {
         $userIdList = array_map('intval', $userIdList);
         $userIdList = implode('","', $userIdList);
         $sql .= ' AND user.user_id IN ("' . $userIdList . '")';
     }
     if (isset($filterByActive)) {
         $filterByActive = intval($filterByActive);
         $sql .= ' AND user.active = ' . $filterByActive;
     }
     $sql .= ' ' . $order_by . ' ' . $limit;
     $rs = Database::query($sql);
     $users = array();
     $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
     $counter = 1;
     $count_rows = Database::num_rows($rs);
     if ($return_count && $resumed_report) {
         return $count_rows;
     }
     $table_user_field_value = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
     $tableExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
     if ($count_rows) {
         while ($user = Database::fetch_array($rs)) {
             if ($return_count) {
                 return $user['count'];
             }
             $report_info = array();
             $user_info = $user;
             $user_info['status'] = $user['status'];
             if (isset($user['is_tutor'])) {
                 $user_info['is_tutor'] = $user['is_tutor'];
             }
             if (!empty($session_id)) {
                 $user_info['status_session'] = $user['status_session'];
             }
             $sessionId = isset($user['session_id']) ? $user['session_id'] : 0;
             $course_code = isset($user['code']) ? $user['code'] : null;
             if ($add_reports) {
                 if ($resumed_report) {
                     $extra = array();
                     if (!empty($extra_fields)) {
                         foreach ($extra_fields as $extra) {
                             if (in_array($extra['1'], $extra_field)) {
                                 $user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']);
                                 break;
                             }
                         }
                     }
                     $row_key = '-1';
                     $name = '-';
                     if (!empty($extra)) {
                         if (!empty($user_data[$extra['1']])) {
                             $row_key = $user_data[$extra['1']];
                             $name = $user_data[$extra['1']];
                             $users[$row_key]['extra_' . $extra['1']] = $name;
                         }
                     }
                     $users[$row_key]['training_hours'] += Tracking::get_time_spent_on_the_course($user['user_id'], $courseId, $sessionId);
                     $users[$row_key]['count_users'] += $counter;
                     $registered_users_with_extra_field = 0;
                     if (!empty($name) && $name != '-') {
                         $extraFieldType = EntityExtraField::COURSE_FIELD_TYPE;
                         $name = Database::escape_string($name);
                         $sql = "SELECT count(v.item_id) as count\n                                    FROM {$table_user_field_value} v INNER JOIN\n                                    {$tableExtraField} f\n                                    ON (f.id = v.field_id)\n                                    WHERE value = '{$name}' AND extra_field_type = {$extraFieldType}";
                         $result_count = Database::query($sql);
                         if (Database::num_rows($result_count)) {
                             $row_count = Database::fetch_array($result_count);
                             $registered_users_with_extra_field = $row_count['count'];
                         }
                     }
                     $users[$row_key]['count_users_registered'] = $registered_users_with_extra_field;
                     $users[$row_key]['average_hours_per_user'] = $users[$row_key]['training_hours'] / $users[$row_key]['count_users'];
                     $category = Category::load(null, null, $course_code, null, null, $sessionId);
                     if (!isset($users[$row_key]['count_certificates'])) {
                         $users[$row_key]['count_certificates'] = 0;
                     }
                     if (isset($category[0]) && $category[0]->is_certificate_available($user['user_id'])) {
                         $users[$row_key]['count_certificates']++;
                     }
                     foreach ($extra_fields as $extra) {
                         if ($extra['1'] == 'ruc') {
                             continue;
                         }
                         if (!isset($users[$row_key][$extra['1']])) {
                             $user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']);
                             if (!empty($user_data[$extra['1']])) {
                                 $users[$row_key][$extra['1']] = $user_data[$extra['1']];
                             }
                         }
                     }
                 } else {
                     $sessionName = !empty($sessionId) ? ' - ' . $user['session_name'] : '';
                     $report_info['course'] = $user['title'] . $sessionName;
                     $report_info['user'] = api_get_person_name($user['firstname'], $user['lastname']);
                     $report_info['email'] = $user['email'];
                     $report_info['time'] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $courseId, $sessionId));
                     $category = Category::load(null, null, $course_code, null, null, $sessionId);
                     $report_info['certificate'] = Display::label(get_lang('No'));
                     if (isset($category[0]) && $category[0]->is_certificate_available($user['user_id'])) {
                         $report_info['certificate'] = Display::label(get_lang('Yes'), 'success');
                     }
                     $progress = intval(Tracking::get_avg_student_progress($user['user_id'], $course_code, array(), $sessionId));
                     $report_info['progress_100'] = $progress == 100 ? Display::label(get_lang('Yes'), 'success') : Display::label(get_lang('No'));
                     $report_info['progress'] = $progress . "%";
                     foreach ($extra_fields as $extra) {
                         $user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']);
                         $report_info[$extra['1']] = $user_data[$extra['1']];
                     }
                     $report_info['user_id'] = $user['user_id'];
                     $users[] = $report_info;
                 }
             } else {
                 $users[$user['user_id']] = $user_info;
             }
         }
     }
     return $users;
 }
Ejemplo n.º 6
0
 /**
  * Get data for users list in sortable with pagination
  * @param $from
  * @param $number_of_items
  * @param $column
  * @param $direction
  * @param $includeInvitedUsers boolean Whether include the invited users
  * @return array
  */
 public static function get_user_data($from, $number_of_items, $column, $direction, $includeInvitedUsers = false)
 {
     global $user_ids, $course_code, $additional_user_profile_info, $export_csv, $is_western_name_order, $csv_content, $session_id;
     $course_code = Database::escape_string($course_code);
     $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
     $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
     $access_url_id = api_get_current_access_url_id();
     // get all users data from a course for sortable with limit
     if (is_array($user_ids)) {
         $user_ids = array_map('intval', $user_ids);
         $condition_user = "******" . implode(',', $user_ids) . ") ";
     } else {
         $user_ids = intval($user_ids);
         $condition_user = "******";
     }
     if (!empty($_GET['user_keyword'])) {
         $keyword = trim(Database::escape_string($_GET['user_keyword']));
         $condition_user .= " AND (\n                user.firstname LIKE '%" . $keyword . "%' OR\n                user.lastname LIKE '%" . $keyword . "%'  OR\n                user.username LIKE '%" . $keyword . "%'  OR\n                user.email LIKE '%" . $keyword . "%'\n             ) ";
     }
     $url_table = null;
     $url_condition = null;
     if (api_is_multiple_url_enabled()) {
         $url_table = ", " . $tbl_url_rel_user . "as url_users";
         $url_condition = " AND user.user_id = url_users.user_id AND access_url_id='{$access_url_id}'";
     }
     $invitedUsersCondition = '';
     if (!$includeInvitedUsers) {
         $invitedUsersCondition = " AND user.status != " . INVITEE;
     }
     $sql = "SELECT  user.user_id as user_id,\n                    user.official_code  as col0,\n                    user.lastname       as col1,\n                    user.firstname      as col2,\n                    user.username       as col3\n                FROM {$tbl_user} as user {$url_table}\n    \t        {$condition_user} {$url_condition} {$invitedUsersCondition}";
     if (!in_array($direction, array('ASC', 'DESC'))) {
         $direction = 'ASC';
     }
     $column = intval($column);
     $from = intval($from);
     $number_of_items = intval($number_of_items);
     $sql .= " ORDER BY col{$column} {$direction} ";
     $sql .= " LIMIT {$from},{$number_of_items}";
     $res = Database::query($sql);
     $users = array();
     $course_info = api_get_course_info($course_code);
     $total_surveys = 0;
     $total_exercises = ExerciseLib::get_all_exercises($course_info, $session_id, false, null, false, 3);
     if (empty($session_id)) {
         $survey_user_list = array();
         $survey_list = SurveyManager::get_surveys($course_code, $session_id);
         $total_surveys = count($survey_list);
         if (!empty($survey_list)) {
             foreach ($survey_list as $survey) {
                 $user_list = SurveyManager::get_people_who_filled_survey($survey['survey_id'], false, $course_info['real_id']);
                 foreach ($user_list as $user_id) {
                     isset($survey_user_list[$user_id]) ? $survey_user_list[$user_id]++ : ($survey_user_list[$user_id] = 1);
                 }
             }
         }
     }
     while ($user = Database::fetch_array($res, 'ASSOC')) {
         $courseInfo = api_get_course_info($course_code);
         $courseId = $courseInfo['real_id'];
         $user['official_code'] = $user['col0'];
         $user['lastname'] = $user['col1'];
         $user['firstname'] = $user['col2'];
         $user['username'] = $user['col3'];
         $user['time'] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $courseId, $session_id));
         $avg_student_score = Tracking::get_avg_student_score($user['user_id'], $course_code, array(), $session_id);
         $avg_student_progress = Tracking::get_avg_student_progress($user['user_id'], $course_code, array(), $session_id);
         if (empty($avg_student_progress)) {
             $avg_student_progress = 0;
         }
         $user['average_progress'] = $avg_student_progress . '%';
         $total_user_exercise = Tracking::get_exercise_student_progress($total_exercises, $user['user_id'], $courseId, $session_id);
         $user['exercise_progress'] = $total_user_exercise;
         $total_user_exercise = Tracking::get_exercise_student_average_best_attempt($total_exercises, $user['user_id'], $courseId, $session_id);
         $user['exercise_average_best_attempt'] = $total_user_exercise;
         if (is_numeric($avg_student_score)) {
             $user['student_score'] = $avg_student_score . '%';
         } else {
             $user['student_score'] = $avg_student_score;
         }
         $user['count_assignments'] = Tracking::count_student_assignments($user['user_id'], $course_code, $session_id);
         $user['count_messages'] = Tracking::count_student_messages($user['user_id'], $course_code, $session_id);
         $user['first_connection'] = Tracking::get_first_connection_date_on_the_course($user['user_id'], $courseId, $session_id);
         $user['last_connection'] = Tracking::get_last_connection_date_on_the_course($user['user_id'], $courseInfo, $session_id);
         // we need to display an additional profile field
         $user['additional'] = '';
         if (isset($_GET['additional_profile_field']) && is_numeric($_GET['additional_profile_field'])) {
             if (isset($additional_user_profile_info[$user['user_id']]) && is_array($additional_user_profile_info[$user['user_id']])) {
                 $user['additional'] = implode(', ', $additional_user_profile_info[$user['user_id']]);
             }
         }
         if (empty($session_id)) {
             $user['survey'] = (isset($survey_user_list[$user['user_id']]) ? $survey_user_list[$user['user_id']] : 0) . ' / ' . $total_surveys;
         }
         $user['link'] = '<center><a href="../mySpace/myStudents.php?student=' . $user['user_id'] . '&details=true&course=' . $course_code . '&origin=tracking_course&id_session=' . $session_id . '"><img src="' . api_get_path(WEB_IMG_PATH) . 'icons/22/2rightarrow.png" border="0" /></a></center>';
         // store columns in array $users
         $is_western_name_order = api_is_western_name_order();
         $user_row = array();
         $user_row[] = $user['official_code'];
         //0
         if ($is_western_name_order) {
             $user_row[] = $user['firstname'];
             $user_row[] = $user['lastname'];
         } else {
             $user_row[] = $user['lastname'];
             $user_row[] = $user['firstname'];
         }
         $user_row[] = $user['username'];
         $user_row[] = $user['time'];
         $user_row[] = $user['average_progress'];
         $user_row[] = $user['exercise_progress'];
         $user_row[] = $user['exercise_average_best_attempt'];
         $user_row[] = $user['student_score'];
         $user_row[] = $user['count_assignments'];
         $user_row[] = $user['count_messages'];
         if (empty($session_id)) {
             $user_row[] = $user['survey'];
         }
         $user_row[] = $user['first_connection'];
         $user_row[] = $user['last_connection'];
         if (isset($_GET['additional_profile_field']) && is_numeric($_GET['additional_profile_field'])) {
             $user_row[] = $user['additional'];
         }
         $user_row[] = $user['link'];
         $users[] = $user_row;
         if ($export_csv) {
             if (empty($session_id)) {
                 $user_row = array_map('strip_tags', $user_row);
                 unset($user_row[14]);
                 unset($user_row[15]);
             } else {
                 $user_row = array_map('strip_tags', $user_row);
                 unset($user_row[13]);
                 unset($user_row[14]);
             }
             $csv_content[] = $user_row;
         }
     }
     return $users;
 }
Ejemplo n.º 7
0
function get_courses($from, $limit, $column, $direction)
{
    $userId = api_get_user_id();
    $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
    $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : null;
    $follow = isset($_GET['follow']) ? true : false;
    $drhLoaded = false;
    if (api_is_drh()) {
        if (api_drh_can_access_all_session_content()) {
            $courses = SessionManager::getAllCoursesFollowedByUser($userId, $sessionId, $from, $limit, $column, $direction, false, $keyword);
            $drhLoaded = true;
        }
    }
    if ($drhLoaded == false) {
        $courses = CourseManager::getCoursesFollowedByUser($userId, COURSEMANAGER, $from, $limit, $column, $direction, false, $keyword, $sessionId, $follow);
    }
    $courseList = array();
    if (!empty($courses)) {
        foreach ($courses as $data) {
            $courseCode = $data['code'];
            $courseInfo = api_get_course_info($courseCode);
            $userList = CourseManager::get_user_list_from_course_code($data['code'], $sessionId);
            $userIdList = array();
            if (!empty($userList)) {
                foreach ($userList as $user) {
                    $userIdList[] = $user['user_id'];
                }
            }
            $messagesInCourse = 0;
            $assignmentsInCourse = 0;
            $avgTimeSpentInCourse = 0;
            $avgProgressInCourse = 0;
            if (count($userIdList) > 0) {
                $countStudents = count($userIdList);
                // tracking data
                $avgProgressInCourse = Tracking::get_avg_student_progress($userIdList, $courseCode, array(), $sessionId);
                $avgScoreInCourse = Tracking::get_avg_student_score($userIdList, $courseCode, array(), $sessionId);
                $avgTimeSpentInCourse = Tracking::get_time_spent_on_the_course($userIdList, $courseInfo['real_id'], $sessionId);
                $messagesInCourse = Tracking::count_student_messages($userIdList, $courseCode, $sessionId);
                $assignmentsInCourse = Tracking::count_student_assignments($userIdList, $courseCode, $sessionId);
                $avgTimeSpentInCourse = api_time_to_hms($avgTimeSpentInCourse / $countStudents);
                $avgProgressInCourse = round($avgProgressInCourse / $countStudents, 2);
                if (is_numeric($avgScoreInCourse)) {
                    $avgScoreInCourse = round($avgScoreInCourse / $countStudents, 2) . '%';
                }
            }
            $thematic = new Thematic();
            $tematic_advance = $thematic->get_total_average_of_thematic_advances($courseCode, $sessionId);
            $tematicAdvanceProgress = '-';
            if (!empty($tematic_advance)) {
                $tematicAdvanceProgress = '<a title="' . get_lang('GoToThematicAdvance') . '" href="' . api_get_path(WEB_CODE_PATH) . 'course_progress/index.php?cidReq=' . $courseCode . '&id_session=' . $sessionId . '">' . $tematic_advance . '%</a>';
            }
            $courseIcon = '<a href="' . api_get_path(WEB_CODE_PATH) . 'tracking/courseLog.php?cidReq=' . $courseCode . '&id_session=' . $sessionId . '">
                        ' . Display::return_icon('2rightarrow.png', get_lang('Details')) . '
                      </a>';
            $title = Display::url($data['title'], $courseInfo['course_public_url'] . '?id_session=' . $sessionId);
            $attendanceLink = Display::url(Display::return_icon('attendance_list.png', get_lang('Attendance'), array(), ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH) . 'attendance/index.php?cidReq=' . $courseCode . '&id_session=' . $sessionId . '&action=calendar_logins');
            $courseList[] = array($title, $countStudents, is_null($avgTimeSpentInCourse) ? '-' : $avgTimeSpentInCourse, $tematicAdvanceProgress, is_null($avgProgressInCourse) ? '-' : $avgProgressInCourse . '%', is_null($avgScoreInCourse) ? '-' : $avgScoreInCourse, is_null($messagesInCourse) ? '-' : $messagesInCourse, is_null($assignmentsInCourse) ? '-' : $assignmentsInCourse, $attendanceLink, $courseIcon);
        }
    }
    return $courseList;
}
Ejemplo n.º 8
0
                    if ($access_url_id != -1) {
                        $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
					FROM ' . $tbl_user . ',' . $tbl_sessions . ' as session,' . $tbl_track_login . ' , ' . $tbl_session_rel_access_url . ' as session_rel_url
					WHERE id_coach=user_id AND login_user_id=user_id  AND access_url_id = ' . $access_url_id . ' AND  session_rel_url.session_id=session.id
					GROUP BY user_id
					ORDER BY login_date ' . $tracking_direction;
                    }
                }
                $result_sessions_coach = Database::query($sql_session_coach);
                $total_no_coaches += Database::num_rows($result_sessions_coach);
                while ($coach = Database::fetch_array($result_sessions_coach)) {
                    $global_coaches[$coach['user_id']] = $coach;
                }
                $all_datas = array();
                foreach ($global_coaches as $id_coach => $coaches) {
                    $time_on_platform = api_time_to_hms(Tracking::get_time_spent_on_the_platform($coaches['user_id']));
                    $last_connection = Tracking::get_last_connection_date($coaches['user_id']);
                    $nb_students = count(Tracking::get_student_followed_by_coach($coaches['user_id']));
                    $nb_courses = count(Tracking::get_courses_followed_by_coach($coaches['user_id']));
                    $nb_sessions = count(Tracking::get_sessions_coached_by_user($coaches['user_id']));
                    $table_row = array();
                    if ($is_western_name_order) {
                        $table_row[] = $coaches['firstname'];
                        $table_row[] = $coaches['lastname'];
                    } else {
                        $table_row[] = $coaches['lastname'];
                        $table_row[] = $coaches['firstname'];
                    }
                    $table_row[] = $time_on_platform;
                    $table_row[] = $last_connection;
                    $table_row[] = $nb_students;
Ejemplo n.º 9
0
    /**
     * Get course information data
     * @return array
     */
    function get_course_information_data()
    {
        $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
        $course_data = array();
        $courses = $this->courses;

        $thematic = new Thematic();

        foreach ($courses as $row_course) {

            $course_code = $row_course['code'];
            $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0;

            // students directly subscribed to the course
            $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user
                    WHERE course_rel_user.status=" . STUDENT . " AND course_rel_user.course_code='$course_code'";
            $rs = Database::query($sql);
            $users = array();
            while ($row = Database::fetch_array($rs)) {
                $users[] = $row['user_id'];
            }
            if (count($users) > 0) {
                $nb_students_in_course = count($users);
                $avg_time_spent_in_course = api_time_to_hms(
                    Tracking::get_time_spent_on_the_course($users, $course_code ) / $nb_students_in_course);
            } else {
                $avg_time_spent_in_course = null;
            }
            $tematic_advance = $thematic->get_total_average_of_thematic_advances(
                $course_code,
                0
            );

            if (!empty($tematic_advance)) {
                $tematic_advance_progress = '<a title="' . get_lang('GoToThematicAdvance') . '" href="' . api_get_path(WEB_CODE_PATH) . 'course_progress/index.php?cidReq=' . $course_code . '&action=thematic_details">' . $tematic_advance . '%</a>';
            } else {
                $tematic_advance_progress = '0%';
            }

            $table_row = array();
            $table_row[] = $row_course['title'];
            $table_row[] = $nb_students_in_course;
            $table_row[] = $avg_time_spent_in_course;
            $table_row[] = $tematic_advance_progress;
            $course_data[] = $table_row;
        }

        return $course_data;
    }
Ejemplo n.º 10
0
 /**
  * @param Application $app
  * @return string
  */
 public function indexAction(Application $app)
 {
     $request = $app['request'];
     $language_file = array('admin', 'exercice', 'gradebook', 'tracking');
     // 1. Setting variables needed by jqgrid
     $action = $request->get('a');
     $page = $request->get('page');
     //page
     $limit = $request->get('rows');
     //quantity of rows
     $sidx = $request->get('sidx');
     //index (field) to filter
     $sord = $request->get('sord');
     //asc or desc
     if (strpos(strtolower($sidx), 'asc') !== false) {
         $sidx = str_replace(array('asc', ','), '', $sidx);
         $sord = 'asc';
     }
     if (strpos(strtolower($sidx), 'desc') !== false) {
         $sidx = str_replace(array('desc', ','), '', $sidx);
         $sord = 'desc';
     }
     if (!in_array($sord, array('asc', 'desc'))) {
         $sord = 'desc';
     }
     if (!in_array($action, array('get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_user_skill_ranking', 'get_usergroups_teacher', 'get_question_list', 'get_user_list_plugin_widescale'))) {
         api_protect_admin_script(true);
     }
     if ($action == 'get_user_list_plugin_widescale') {
         $allowed = api_is_drh() || api_is_platform_admin();
         if (!$allowed) {
             api_not_allowed();
         }
     }
     // Search features.
     // If there is no search request sent by jqgrid, $where should be empty.
     $where_condition = "";
     $operation = $request->get('oper');
     $export_format = $request->get('export_format');
     $search_field = $request->get('searchField');
     $search_oper = $request->get('searchOper');
     $search_string = $request->get('searchString');
     $isSearch = $request->get('_search');
     $filters = $request->get('filters');
     $type = $request->get('type');
     $extra_fields = array();
     $questionFields = array();
     if ($isSearch == 'true') {
         $where_condition = ' 1 = 1 ';
         $where_condition_in_form = $this->getWhereClause($search_field, $search_oper, $search_string);
         if (!empty($where_condition_in_form)) {
             $where_condition .= ' AND ' . $where_condition_in_form;
         }
         $filters = isset($filters) ? json_decode($filters) : false;
         // for now
         if (!empty($filters)) {
             switch ($action) {
                 case 'get_questions':
                     $extraFieldtype = 'question';
                     break;
                 case 'get_sessions':
                     $extraFieldtype = 'session';
                     break;
             }
             // Extra field.
             $extraField = new \ExtraField($extraFieldtype);
             $result = $extraField->getExtraFieldRules($filters, 'extra_');
             $extra_fields = $result['extra_fields'];
             $condition_array = $result['condition_array'];
             if (!empty($condition_array)) {
                 $where_condition .= ' AND ( ';
                 $where_condition .= implode($filters->groupOp, $condition_array);
                 $where_condition .= ' ) ';
             }
             // Question field.
             $resultQuestion = $extraField->getExtraFieldRules($filters, 'question_');
             $questionFields = $resultQuestion['extra_fields'];
             $condition_array = $resultQuestion['condition_array'];
             if (!empty($condition_array)) {
                 $where_condition .= ' AND ( ';
                 $where_condition .= implode($filters->groupOp, $condition_array);
                 $where_condition .= ' ) ';
             }
         }
     }
     // get index row - i.e. user click to sort $sord = $_GET['sord'];
     // get the direction
     if (!$sidx) {
         $sidx = 1;
     }
     //2. Selecting the count FIRST
     //@todo rework this
     switch ($action) {
         case 'get_questions':
             $categoryId = $request->get('categoryId');
             $exerciseId = $request->get('exerciseId');
             //$courseId = null; //$request->get('courseId');
             $courseId = $request->get('courseId');
             // Question manager can view all questions
             if (api_is_question_manager()) {
                 $courseId = null;
             }
             $count = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'extra' => $extra_fields, 'question' => $questionFields), true);
             break;
         case 'get_user_list_plugin_widescale':
             $count = \UserManager::get_user_data(null, null, null, null, true);
             break;
         case 'get_question_list':
             require_once api_get_path(SYS_CODE_PATH) . 'exercice/exercise.class.php';
             $exerciseId = $request->get('exerciseId');
             $exercise = new \Exercise(api_get_course_int_id());
             $exercise->read($exerciseId);
             $count = $exercise->selectNbrQuestions();
             break;
         case 'get_group_reporting':
             $course_id = $request->get('course_id');
             $group_id = $request->get('gidReq');
             $count = \Tracking::get_group_reporting($course_id, $group_id, 'count');
             break;
         case 'get_user_course_report_resumed':
             $count = \CourseManager::get_count_user_list_from_course_code(true, 'ruc');
             break;
         case 'get_user_course_report':
             $count = \CourseManager::get_count_user_list_from_course_code(false);
             break;
         case 'get_course_exercise_medias':
             $course_id = api_get_course_int_id();
             $count = \Question::get_count_course_medias($course_id);
             break;
         case 'get_user_skill_ranking':
             $skill = new \Skill();
             $count = $skill->get_user_list_skill_ranking_count();
             break;
         case 'get_work_user_list':
             require_once api_get_path(SYS_CODE_PATH) . 'work/work.lib.php';
             $work_id = $request->get('work_id');
             //$_REQUEST['work_id'];
             $count = get_count_work($work_id);
             break;
         case 'get_exercise_results':
             $exercise_id = $request->get('exerciseId');
             //$_REQUEST['exerciseId'];
             $filter_by_user = $request->get('filter_by_user');
             if (isset($filter_by_user) && !empty($filter_by_user)) {
                 $filter_user = intval($filter_by_user);
                 if ($where_condition == "") {
                     $where_condition .= " te.exe_user_id  = '{$filter_user}'";
                 } else {
                     $where_condition .= " AND te.exe_user_id  = '{$filter_user}'";
                 }
             }
             $count = \ExerciseLib::get_count_exam_results($exercise_id, $where_condition);
             break;
         case 'get_hotpotatoes_exercise_results':
             $hotpot_path = $request->get('path');
             //$_REQUEST['path'];
             $count = \ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
             break;
         case 'get_sessions':
             $list_type = $request->get('list_type');
             if ($list_type == 'simple' || empty($list_type)) {
                 $count = \SessionManager::get_sessions_admin(array('where' => $where_condition, 'extra' => $extra_fields), true);
             } else {
                 $count = \SessionManager::get_count_admin_complete(array('where' => $where_condition, 'extra' => $extra_fields));
             }
             break;
         case 'get_extra_fields':
             $obj = new \ExtraField($type);
             $count = $obj->get_count();
             break;
         case 'get_extra_field_options':
             $field_id = $request->get('field_id');
             $obj = new \ExtraFieldOption($type);
             $count = $obj->get_count_by_field_id($field_id);
             break;
         case 'get_timelines':
             $obj = new \Timeline();
             $count = $obj->get_count();
             break;
         case 'get_gradebooks':
             $obj = new \Gradebook();
             $count = $obj->get_count();
             break;
         case 'get_event_email_template':
             $obj = new \EventEmailTemplate();
             $count = $obj->get_count();
             break;
         case 'get_careers':
             $obj = new \Career();
             $count = $obj->get_count();
             break;
         case 'get_promotions':
             $obj = new \Promotion();
             $count = $obj->get_count();
             break;
         case 'get_grade_models':
             $obj = new \GradeModel();
             $count = $obj->get_count();
             break;
         case 'get_usergroups':
             $obj = new \UserGroup();
             $count = $obj->get_count();
             break;
         case 'get_usergroups_teacher':
             $obj = new \UserGroup();
             $course_id = api_get_course_int_id();
             if ($type == 'registered') {
                 $count = $obj->get_usergroup_by_course_with_data_count($course_id);
             } else {
                 $count = $obj->get_count();
             }
             break;
         default:
             exit;
     }
     //3. Calculating first, end, etc
     $total_pages = 0;
     if ((int) $count > 0) {
         if (!empty($limit)) {
             $total_pages = ceil($count / $limit);
         }
     }
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $start = $limit * $page - $limit;
     if ($start < 0) {
         $start = 0;
     }
     //4. Deleting an element if the user wants to
     if ($operation == 'del') {
         $obj->delete($request->get('id'));
     }
     $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh();
     //5. Querying the DB for the elements
     $columns = array();
     switch ($action) {
         case 'get_questions':
             $columns = \Question::getQuestionColumns(api_get_course_id(), $extra_fields, $questionFields, true);
             $columns = $columns['simple_column_name'];
             $result = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'question' => $questionFields, 'limit' => "{$start} , {$limit}"));
             //var_dump($result);
             break;
         case 'get_user_list_plugin_widescale':
             $columns = array('username', 'firstname', 'lastname', 'exam_password');
             $column_names = array(get_lang('Username'), get_lang('Firstname'), get_lang('Lastname'), get_lang('Password'));
             $result = \UserManager::get_user_data($start, $limit, $sidx, $sord);
             break;
         case 'get_question_list':
             if (isset($exercise) && !empty($exercise)) {
                 $columns = array('question', 'type', 'category', 'level', 'score', 'actions');
                 $result = $exercise->getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition);
             }
             break;
         case 'get_group_reporting':
             $columns = array('name', 'time', 'progress', 'score', 'works', 'messages', 'actions');
             $result = \Tracking::get_group_reporting($course_id, $group_id, 'all', $start, $limit, $sidx, $sord, $where_condition);
             break;
         case 'get_course_exercise_medias':
             $columns = array('question');
             $result = \Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $where_condition);
             if (!empty($result)) {
                 foreach ($result as &$media) {
                     $media['id'] = $media['iid'];
                 }
             }
             break;
         case 'get_user_course_report_resumed':
             $columns = array('extra_ruc', 'training_hours', 'count_users', 'count_users_registered', 'average_hours_per_user', 'count_certificates');
             $column_names = array(get_lang('Company'), get_lang('TrainingHoursAccumulated'), get_lang('CountOfSubscriptions'), get_lang('CountOfUsers'), get_lang('AverageHoursPerStudent'), get_lang('CountCertificates'));
             $result = \CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", " {$sidx} {$sord}", null, null, true, true, 'ruc');
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $row) {
                     $row['training_hours'] = api_time_to_hms($row['training_hours']);
                     $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']);
                     $new_result[] = $row;
                 }
                 $result = $new_result;
             }
             break;
         case 'get_user_course_report':
             $columns = array('course', 'user', 'time', 'certificate', 'progress_100', 'progress');
             $column_names = array(get_lang('Course'), get_lang('User'), get_lang('ManHours'), get_lang('CertificateGenerated'), get_lang('Approved'), get_lang('CourseAdvance'));
             $extra_fields = \UserManager::get_extra_fields(0, 100, null, null, true, true);
             if (!empty($extra_fields)) {
                 foreach ($extra_fields as $extra) {
                     $columns[] = $extra['1'];
                     $column_names[] = $extra['3'];
                 }
             }
             $result = \CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", " {$sidx} {$sord}", null, null, true);
             break;
         case 'get_user_skill_ranking':
             $columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank');
             $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition);
             $result = \ArrayClass::msort($result, 'skills_acquired', 'asc');
             $skills_in_course = array();
             if (!empty($result)) {
                 //$counter = 1;
                 foreach ($result as &$item) {
                     $user_info = api_get_user_info($item['user_id']);
                     $personal_course_list = \UserManager::get_personal_session_course_list($item['user_id']);
                     $count_skill_by_course = array();
                     foreach ($personal_course_list as $course_item) {
                         if (!isset($skills_in_course[$course_item['code']])) {
                             $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']);
                             $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
                         } else {
                             $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
                         }
                     }
                     $item['photo'] = \Display::img($user_info['avatar_small']);
                     $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
                 }
             }
             break;
         case 'get_work_user_list':
             if (isset($type) && $type == 'simple') {
                 $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions');
             } else {
                 $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'sent_date', 'actions');
             }
             $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
             break;
         case 'get_exercise_results':
             $course = api_get_course_info();
             //used inside get_exam_results_data()
             $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
             if ($is_allowedToEdit) {
                 $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions');
             } else {
                 //$columns = array('exe_duration', 'start_date', 'exe_date', 'score', 'status', 'actions');
             }
             $result = \ExerciseLib::get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
             break;
         case 'get_hotpotatoes_exercise_results':
             $course = api_get_course_info();
             //used inside get_exam_results_data()
             $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
             $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
             $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition);
             //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
             break;
         case 'get_sessions':
             $session_columns = \SessionManager::get_session_columns($list_type);
             $columns = $session_columns['simple_column_name'];
             if ($list_type == 'simple') {
                 $result = SessionManager::get_sessions_admin(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}"), false);
             } else {
                 $result = SessionManager::get_sessions_admin_complete(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}"));
             }
             break;
         case 'get_timelines':
             $columns = array('headline', 'actions');
             //$columns = array('headline', 'type', 'start_date', 'end_date', 'text', 'media', 'media_credit', 'media_caption', 'title_slide', 'parent_id');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'headline';
             }
             $course_id = api_get_course_int_id();
             $result = Database::select('*', $obj->table, array('where' => array('parent_id = ? AND c_id = ?' => array('0', $course_id)), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if (!$item['status']) {
                     $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>';
                 }
                 $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH) . 'timeline/view.php?id=' . $item['id']);
                 $item['actions'] = Display::url(Display::return_icon('add.png', get_lang('AddItems')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=add_item&parent_id=' . $item['id']);
                 $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=edit&id=' . $item['id']);
                 $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=delete&id=' . $item['id']);
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_gradebooks':
             $columns = array('name', 'certificates', 'skills', 'actions', 'has_certificates');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if ($item['parent_id'] != 0) {
                     continue;
                 }
                 $skills = $obj->get_skills_by_gradebook($item['id']);
                 //Fixes bug when gradebook doesn't have names
                 if (empty($item['name'])) {
                     $item['name'] = $item['course_code'];
                 } else {
                     //$item['name'] =  $item['name'].' ['.$item['course_code'].']';
                 }
                 $item['name'] = Display::url($item['name'], api_get_path(WEB_CODE_PATH) . 'gradebook/index.php?id_session=0&cidReq=' . $item['course_code']);
                 if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
                     $item['certificates'] = Display::return_icon('accept.png', get_lang('WithCertificate'), array(), ICON_SIZE_SMALL);
                     $item['has_certificates'] = '1';
                 } else {
                     $item['certificates'] = Display::return_icon('warning.png', get_lang('NoCertificate'), array(), ICON_SIZE_SMALL);
                     $item['has_certificates'] = '0';
                 }
                 if (!empty($skills)) {
                     foreach ($skills as $skill) {
                         $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));
                     }
                 }
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_event_email_template':
             $columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'subject';
             }
             $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 $language_info = api_get_language_info($item['language_id']);
                 $item['language_id'] = $language_info['english_name'];
                 $item['actions'] = Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'admin/event_type.php?action=edit&event_type_name=' . $item['event_type_name']);
                 $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'admin/event_controller.php?action=delete&id=' . $item['id']);
                 /*if (!$item['status']) {
                       $item['name'] = '<font style="color:#AAA">'.$item['subject'].'</font>';
                   }*/
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_careers':
             $columns = array('name', 'description', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if (!$item['status']) {
                     $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>';
                 }
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_promotions':
             $columns = array('name', 'career', 'description', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('p.id,p.name, p.description, c.name as career, p.status', "{$obj->table} p LEFT JOIN " . Database::get_main_table(TABLE_CAREER) . " c  ON c.id = p.career_id ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if (!$item['status']) {
                     $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>';
                 }
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_grade_models':
             $columns = array('name', 'description', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('*', "{$obj->table} ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_usergroups':
             $columns = array('name', 'users', 'courses', 'sessions', 'group_type', 'actions');
             $result = Database::select('*', $obj->table, array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $group) {
                     $group['sessions'] = count($obj->get_sessions_by_usergroup($group['id']));
                     $group['courses'] = count($obj->get_courses_by_usergroup($group['id']));
                     $group['users'] = count($obj->get_users_by_usergroup($group['id']));
                     switch ($group['group_type']) {
                         case '0':
                             $group['group_type'] = Display::label(get_lang('Class'), 'info');
                             break;
                         case '1':
                             $group['group_type'] = Display::label(get_lang('Social'), 'success');
                             break;
                     }
                     $new_result[] = $group;
                 }
                 $result = $new_result;
             }
             $columns = array('name', 'users', 'courses', 'sessions', 'group_type');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             //Multidimensional sort
             ArrayClass::msort($result, $sidx);
             break;
         case 'get_extra_fields':
             $obj = new \ExtraField($type);
             $columns = array('field_display_text', 'field_variable', 'field_type', 'field_changeable', 'field_visible', 'field_filter', 'field_order');
             $result = \Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $item) {
                     $item['field_type'] = $obj->get_field_type_by_id($item['field_type']);
                     $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                     $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                     $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                     $new_result[] = $item;
                 }
                 $result = $new_result;
             }
             break;
         case 'get_extra_field_options':
             $obj = new \ExtraFieldOption($type);
             $columns = array('option_display_text', 'option_value', 'option_order');
             $result = \Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             /*$new_result = array();
               if (!empty($result)) {
                   foreach ($result as $item) {
                       $item['field_type']         = $obj->get_field_type_by_id($item['field_type']);
                       $item['field_changeable']   = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                       $item['field_visible']      = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                       $item['field_filter']       = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                       $new_result[]        = $item;
                   }
                   $result = $new_result;
               }*/
             break;
         case 'get_usergroups_teacher':
             $columns = array('name', 'users', 'actions');
             $options = array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}");
             $options['course_id'] = $course_id;
             switch ($type) {
                 case 'not_registered':
                     $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
                     $result = $obj->get_usergroup_not_in_course($options);
                     break;
                 case 'registered':
                     $options['where'] = array(" usergroup.course_id = ? " => $course_id);
                     $result = $obj->get_usergroup_in_course($options);
                     break;
             }
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $group) {
                     $group['users'] = count($obj->get_users_by_usergroup($group['id']));
                     if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
                         $url = 'class.php?action=remove_class_from_course&id=' . $group['id'];
                         $icon = Display::return_icon('delete.png', get_lang('Remove'));
                     } else {
                         $url = 'class.php?action=add_class_to_course&id=' . $group['id'];
                         $icon = Display::return_icon('add.png', get_lang('Add'));
                     }
                     $group['actions'] = Display::url($icon, $url);
                     $new_result[] = $group;
                 }
                 $result = $new_result;
             }
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             //Multidimensional sort
             \ArrayClass::msort($result, $sidx);
             break;
         default:
             exit;
     }
     $allowed_actions = array('get_careers', 'get_promotions', 'get_usergroups', 'get_usergroups_teacher', 'get_gradebooks', 'get_sessions', 'get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_grade_models', 'get_event_email_template', 'get_user_skill_ranking', 'get_extra_fields', 'get_extra_field_options', 'get_course_exercise_medias', 'get_user_course_report', 'get_user_course_report_resumed', 'get_group_reporting', 'get_question_list', 'get_user_list_plugin_widescale', 'get_questions');
     //5. Creating an obj to return a json
     if (in_array($action, $allowed_actions)) {
         $response = new \stdClass();
         $response->page = $page;
         $response->total = $total_pages;
         $response->records = $count;
         if ($operation && $operation == 'excel') {
             $j = 1;
             $array = array();
             if (empty($column_names)) {
                 $column_names = $columns;
             }
             //Headers
             foreach ($column_names as $col) {
                 $array[0][] = $col;
             }
             foreach ($result as $row) {
                 foreach ($columns as $col) {
                     $array[$j][] = strip_tags($row[$col]);
                 }
                 $j++;
             }
             switch ($export_format) {
                 case 'xls':
                     Export::export_table_xls($array, 'company_report');
                     break;
                 case 'csv':
                 default:
                     Export::export_table_csv($array, 'company_report');
                     break;
             }
             exit;
         }
         $i = 0;
         if (!empty($result)) {
             foreach ($result as $row) {
                 //print_r($row);
                 // if results tab give not id, set id to $i otherwise id="null" for all <tr> of the jqgrid - ref #4235
                 if (!isset($row['id']) || isset($row['id']) && $row['id'] == "") {
                     $response->rows[$i]['id'] = $i;
                 } else {
                     $response->rows[$i]['id'] = $row['id'];
                 }
                 $array = array();
                 foreach ($columns as $col) {
                     $array[] = isset($row[$col]) ? $row[$col] : null;
                 }
                 $response->rows[$i]['cell'] = $array;
                 $i++;
             }
         }
         return json_encode($response);
     }
 }
<?php 
        if (!api_is_platform_admin(true) && $_user['status'] != DRH) {
            // courses followed by user where we are coach
            if (!isset($_GET['id_coach'])) {
                $a_courses = Tracking::get_courses_followed_by_coach($_user['user_id']);
            } else {
                $a_courses = Tracking::get_courses_followed_by_coach(Security::remove_XSS($_GET['id_coach']));
            }
        }
        if (count($a_courses) > 0) {
            $csv_content[] = array();
            $csv_content[] = array(get_lang('Course'), get_lang('Time'), get_lang('Progress'), get_lang('Score'));
            foreach ($a_courses as $course_code) {
                if (CourseManager::is_user_subscribed_in_course($student_id, $course_code, true)) {
                    $course_infos = CourseManager::get_course_information($course_code);
                    $time_spent_on_course = api_time_to_hms(Tracking::get_time_spent_on_the_course($a_infosUser['user_id'], $course_code));
                    $progress = Tracking::get_avg_student_progress($a_infosUser['user_id'], $course_code) . ' %';
                    $score = Tracking::get_avg_student_score($a_infosUser['user_id'], $course_code) . ' %';
                    $csv_content[] = array($course_infos['title'], $time_spent_on_course, $progress, $score);
                    echo '
					<tr>				
						<td align="right">
							' . $course_infos['title'] . '
						</td>
						<td align="right">
							' . $time_spent_on_course . '
						</td>
						<td align="right">
							' . $progress . '
						</td>
						<td align="right">
Ejemplo n.º 12
0
                } else {
                    echo '<tr><th>' . get_lang('LastName') . '</th><th>' . get_lang('FirstName') . '</th><th>' . get_lang('Email') . '</th><th>' . get_lang('AdminCourses') . '</th><th>' . get_lang('Students') . '</th></tr>';
                }
            }
        } else {
            $css_class = "row_even";
        }
        $i++;
        if ($is_western_name_order) {
            $data[$user_id]["firstname"] = $firstname;
            $data[$user_id]["lastname"] = $lastname;
        } else {
            $data[$user_id]["lastname"] = $lastname;
            $data[$user_id]["firstname"] = $firstname;
        }
        $time_on_platform = api_time_to_hms(Tracking::get_time_spent_on_the_platform($user_id, $time_filter, $start_date, $end_date));
        $data[$user_id]["timespentlastweek"] = $time_on_platform;
        $data[$user_id]["email"] = $email;
        if ($is_western_name_order) {
            echo '<tr class="' . $css_class . '"><td>' . $firstname . '</td><td>' . $lastname . '</td><td align="right">' . $time_on_platform . '</td><td align="right"><a href="mailto:' . $email . '">' . $email . '</a></td><td align="right"><a href="course.php?user_id=' . $user_id . '"><img src="' . api_get_path(WEB_IMG_PATH) . '2rightarrow.gif" border="0" /></a></td><td align="right"><a href="student.php?user_id=' . $user_id . '&amp;display=yourstudents"><img src="' . api_get_path(WEB_IMG_PATH) . '2rightarrow.gif" border="0" /></a></td></tr>';
        } else {
            echo '<tr class="' . $css_class . '"><td>' . $lastname . '</td><td>' . $firstname . '</td><td align="right">' . $time_on_platform . '</td><td align="right"><a href="mailto:' . $email . '">' . $email . '</a></td><td align="right"><a href="course.php?user_id=' . $user_id . '"><img src="' . api_get_path(WEB_IMG_PATH) . '2rightarrow.gif" border="0" /></a></td><td align="right"><a href="student.php?user_id=' . $user_id . '&amp;display=yourstudents"><img src="' . api_get_path(WEB_IMG_PATH) . '2rightarrow.gif" border="0" /></a></td></tr>';
        }
    }
} else {
    // No results
    echo '<tr><td colspan="6">' . get_lang("NoResults") . '</td></tr>';
}
echo '</table>';
if (isset($_POST['export']) || api_is_drh() && isset($_GET['export'])) {
    MySpace::export_csv($header, $data, 'teachers.csv');
Ejemplo n.º 13
0
/**
 * Creates a small table in the last column of the table with the user overview
 *
 * @param integer $user_id the id of the user
 * @param array $url_params additonal url parameters
 * @param array $row the row information (the other columns)
 * @return html code
 * 
 * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium
 * @version Dokeos 1.8.6
 * @since October 2008
 */
function course_info_tracking_filter($user_id, $url_params, $row)
{
    // the table header
    $return .= '<table class="data_table" style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
    /*$return .= '	<tr>';
    	$return .= '		<th>'.get_lang('Course').'</th>';
    	$return .= '		<th>'.get_lang('AvgTimeSpentInTheCourse').'</th>';
    	$return .= '		<th>'.get_lang('AvgStudentsProgress').'</th>';
    	$return .= '		<th>'.get_lang('AvgCourseScore').'</th>';
    	$return .= '		<th>'.get_lang('AvgExercisesScore').'</th>';
    	$return .= '		<th>'.get_lang('AvgMessages').'</th>';
    	$return .= '		<th>'.get_lang('AvgAssignments').'</th>';
    	$return .= '		<th>'.get_lang('TotalExercisesScoreObtained').'</th>';
    	$return .= '		<th>'.get_lang('TotalExercisesScorePossible').'</th>';
    	$return .= '		<th>'.get_lang('TotalExercisesAnswered').'</th>';
    	$return .= '		<th>'.get_lang('TotalExercisesScorePercentage').'</th>';
    	$return .= '		<th>'.get_lang('FirstLogin').'</th>';
    	$return .= '		<th>'.get_lang('LatestLogin').'</th>';
    	$return .= '	</tr>';*/
    // database table definition
    $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
    // getting all the courses of the user
    $sql = "SELECT * FROM {$tbl_course_user} WHERE user_id = '" . Database::escape_string($user_id) . "'";
    $result = api_sql_query($sql, __FILE__, __LINE__);
    while ($row = Database::fetch_row($result)) {
        $return .= '<tr>';
        // course code
        $return .= '	<td width="157px" >' . cut($row[0], 20, true) . '</td>';
        // time spent in the course
        $return .= '	<td><div>' . api_time_to_hms(Tracking::get_time_spent_on_the_course($user_id, $row[0])) . '</div></td>';
        // student progress in course
        $return .= '	<td><div>' . round(Tracking::get_avg_student_progress($user_id, $row[0]), 2) . '</div></td>';
        // student score
        $return .= '	<td><div>' . round(Tracking::get_avg_student_score($user_id, $row[0]), 2) . '</div></td>';
        // student tes score
        //$return .= '	<td><div style="width:40px">'.round(Tracking :: get_avg_student_exercise_score ($user_id, $row[0]),2).'%</div></td>';
        // student messages
        $return .= '	<td><div>' . Tracking::count_student_messages($user_id, $row[0]) . '</div></td>';
        // student assignments
        $return .= '	<td><div>' . Tracking::count_student_assignments($user_id, $row[0]) . '</div></td>';
        // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
        $exercises_results = exercises_results($user_id, $row[0]);
        $return .= '	<td width="105px"><div>' . $exercises_results['score_obtained'] . '/' . $exercises_results['score_possible'] . '(' . $exercises_results['percentage'] . '%)</div></td>';
        //$return .= '	<td><div>'.$exercises_results['score_possible'].'</div></td>';
        $return .= '	<td><div>' . $exercises_results['questions_answered'] . '</div></td>';
        //$return .= '	<td><div>'.$exercises_results['percentage'].'% </div></td>';
        // first connection
        //$return .= '	<td width="60px">'.Tracking :: get_first_connection_date_on_the_course ($user_id, $row[0]).'</td>';
        // last connection
        $return .= '	<td><div>' . Tracking::get_last_connection_date_on_the_course($user_id, $row[0]) . '</div></td>';
        $return .= '<tr>';
    }
    $return .= '</table>';
    return $return;
}
Ejemplo n.º 14
0
    public function get_teachers_content_html_for_drh()
    {
        $teachers = $this->teachers;
        //$content = '<div style="margin:10px;">';
        $content = '<h4>' . get_lang('YourTeachers') . '</h4>';
        $teachers_table = null;
        if (count($teachers) > 0) {
            $a_last_week = get_last_week();
            $last_week = date('Y-m-d', $a_last_week[0]) . ' ' . get_lang('To') . ' ' . date('Y-m-d', $a_last_week[6]);
            $teachers_table .= '<table class="data_table" width:"95%">';
            $teachers_table .= '
								<tr>
									<th>' . get_lang('User') . '</th>
									<th>' . get_lang('TimeSpentLastWeek') . '<br />' . $last_week . '</th>
								</tr>
							';
            $i = 1;
            foreach ($teachers as $teacher) {
                $teacher_id = $teacher['user_id'];
                $firstname = $teacher['firstname'];
                $lastname = $teacher['lastname'];
                $username = $teacher['username'];
                $time_on_platform = api_time_to_hms(Tracking::get_time_spent_on_the_platform($teacher_id, true));
                if ($i % 2 == 0) {
                    $class_tr = 'row_odd';
                } else {
                    $class_tr = 'row_even';
                }
                $teachers_table .= '<tr class="' . $class_tr . '">
										<td>' . api_get_person_name($firstname, $lastname) . ' (' . $username . ')</td>
										<td align="right">' . $time_on_platform . '</td>
									</tr>';
                $i++;
            }
            $teachers_table .= '</table>';
        } else {
            $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
        }
        $content .= $teachers_table;
        if (count($teachers) > 0) {
            $content .= '<div style="text-align:right;margin-top:10px;"><a href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/teachers.php">' . get_lang('SeeMore') . '</a></div>';
        }
        //$content .= '</div>';
        return $content;
    }
Ejemplo n.º 15
0
 /**
  * Return user info array of all users registered in the specified course
  * This only returns the users that are registered in this actual course, not linked courses.
  *
  * @param string    $course_code the code of the course
  * @param boolean   $with_session determines if the course is used in a session or not
  * @param integer   $session_id the id of the session
  * @param string    $limit the LIMIT statement of the sql statement
  * @param string    $order_by the field to order the users by. Valid values are 'lastname', 'firstname', 'username', 'email', 'official_code' OR a part of a SQL statement that starts with ORDER BY ...
  * @param int       if using the session_id: 0 or 2 (student, coach), if using session_id = 0 STUDENT or COURSEMANAGER
  * @return array
  */
 public static function get_user_list_from_course_code($course_code = null, $session_id = 0, $limit = null, $order_by = null, $filter_by_status = null, $return_count = null, $add_reports = false, $resumed_report = false, $extra_field = null)
 {
     // variable initialisation
     $session_id = intval($session_id);
     $course_code = Database::escape_string($course_code);
     $where = array();
     // if the $order_by does not contain 'ORDER BY' we have to check if it is a valid field that can be sorted on
     if (!strstr($order_by, 'ORDER BY')) {
         //if (!empty($order_by) AND in_array($order_by, array('lastname', 'firstname', 'username', 'email', 'official_code'))) {
         if (!empty($order_by)) {
             $order_by = 'ORDER BY ' . $order_by;
         } else {
             $order_by = '';
         }
     }
     $courseInfo = api_get_course_info($course_code);
     $courseId = null;
     if ($courseInfo) {
         $courseId = $courseInfo['real_id'];
     }
     $filter_by_status_condition = null;
     if (!empty($session_id) && !empty($courseId)) {
         $sql = 'SELECT DISTINCT user.user_id, session_course_user.status as status_session, user.*  ';
         $sql .= ' FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
         $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . ' as session_course_user
                   ON user.user_id = session_course_user.id_user
                   AND session_course_user.c_id="' . $courseId . '"
                   AND session_course_user.id_session = ' . $session_id;
         $where[] = ' session_course_user.c_id IS NOT NULL ';
         // 2 = coach
         // 0 = student
         if (isset($filter_by_status)) {
             $filter_by_status = intval($filter_by_status);
             $filter_by_status_condition = " session_course_user.status = {$filter_by_status} AND ";
         }
     } else {
         if ($return_count) {
             $sql = " SELECT COUNT(*) as count";
             if ($resumed_report) {
                 //$sql = " SELECT count(field_id) ";
             }
         } else {
             if (empty($course_code)) {
                 $sql = 'SELECT DISTINCT course.title, course.code, course_rel_user.status as status_rel, user.user_id, course_rel_user.role, course_rel_user.tutor_id, user.*  ';
             } else {
                 $sql = 'SELECT DISTINCT course_rel_user.status as status_rel, user.user_id, course_rel_user.role, course_rel_user.tutor_id, user.*  ';
             }
         }
         $sql .= ' FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
         $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_COURSE_USER) . ' as course_rel_user
                     ON user.user_id = course_rel_user.user_id AND
                     course_rel_user.relation_type <> ' . COURSE_RELATION_TYPE_RRHH;
         if (!empty($courseInfo)) {
             $sql .= " AND course_rel_user.c_id = " . $courseId;
         } else {
             $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
             $sql .= " INNER JOIN {$course_table} course ON course_rel_user.c_id = course.id";
         }
         $where[] = ' course_rel_user.c_id IS NOT NULL ';
         if (isset($filter_by_status) && $filter_by_status != '') {
             $filter_by_status = intval($filter_by_status);
             $filter_by_status_condition = " course_rel_user.status = {$filter_by_status} AND ";
         }
     }
     $multiple_access_url = api_get_multiple_access_url();
     if ($multiple_access_url) {
         $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER) . '  au ON (au.user_id = user.user_id) ';
     }
     if ($return_count && $resumed_report) {
         $extra_field_info = UserManager::get_extra_field_information_by_name($extra_field);
         $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES) . ' as ufv ON (user.user_id = ufv.user_id AND (field_id = ' . $extra_field_info['id'] . ' OR field_id IS NULL ) )';
     }
     $sql .= ' WHERE ' . $filter_by_status_condition . ' ' . implode(' OR ', $where);
     if ($multiple_access_url) {
         $current_access_url_id = api_get_current_access_url_id();
         $sql .= " AND (access_url_id =  {$current_access_url_id} ) ";
     }
     if ($return_count && $resumed_report) {
         $sql .= ' AND field_id IS NOT NULL  GROUP BY field_value ';
     }
     $sql .= ' ' . $order_by . ' ' . $limit;
     $rs = Database::query($sql);
     $users = array();
     if ($add_reports) {
         $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
     }
     $counter = 1;
     $count_rows = Database::num_rows($rs);
     if ($return_count && $resumed_report) {
         return $count_rows;
     }
     $table_user_field_value = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
     if ($count_rows) {
         while ($user = Database::fetch_array($rs)) {
             $report_info = array();
             if ($return_count) {
                 return $user['count'];
             }
             $user_info = $user;
             $user_info['status'] = $user['status'];
             if (isset($user['role'])) {
                 $user_info['role'] = $user['role'];
             }
             if (isset($user['tutor_id'])) {
                 $user_info['tutor_id'] = $user['tutor_id'];
             }
             if (!empty($session_id)) {
                 $user_info['status_session'] = $user['status_session'];
             }
             $user_info['complete_name'] = api_get_person_name($user_info['firstname'], $user_info['lastname']);
             if ($add_reports) {
                 $course_code = $user['code'];
                 if ($resumed_report) {
                     foreach ($extra_fields as $extra) {
                         if ($extra['1'] == $extra_field) {
                             $user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']);
                             break;
                         }
                     }
                     if (empty($user_data[$extra['1']])) {
                         $row_key = '-1';
                         $name = '-';
                     } else {
                         $row_key = $user_data[$extra['1']];
                         $name = $user_data[$extra['1']];
                     }
                     $users[$row_key]['extra_' . $extra['1']] = $name;
                     $users[$row_key]['training_hours'] += Tracking::get_time_spent_on_the_course($user['user_id'], $courseId, 0);
                     $users[$row_key]['count_users'] += $counter;
                     $registered_users_with_extra_field = 0;
                     if (!empty($name) && $name != '-') {
                         $name = Database::escape_string($name);
                         $sql = "SELECT count(user_id) as count FROM {$table_user_field_value} WHERE field_value = '{$name}'";
                         $result_count = Database::query($sql);
                         if (Database::num_rows($result_count)) {
                             $row_count = Database::fetch_array($result_count);
                             $registered_users_with_extra_field = $row_count['count'];
                         }
                     }
                     $users[$row_key]['count_users_registered'] = $registered_users_with_extra_field;
                     $users[$row_key]['average_hours_per_user'] = $users[$row_key]['training_hours'] / $users[$row_key]['count_users'];
                     $category = Category::load(null, null, $course_code);
                     if (!isset($users[$row_key]['count_certificates'])) {
                         $users[$row_key]['count_certificates'] = 0;
                     }
                     if (isset($category[0]) && $category[0]->is_certificate_available($user['user_id'])) {
                         $users[$row_key]['count_certificates']++;
                     }
                 } else {
                     $report_info['course'] = $user['title'];
                     $report_info['user'] = api_get_person_name($user['firstname'], $user['lastname']);
                     $report_info['time'] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $courseId, 0));
                     $category = Category::load(null, null, $course_code);
                     $report_info['certificate'] = Display::label(get_lang('No'));
                     if (isset($category[0]) && $category[0]->is_certificate_available($user['user_id'])) {
                         $report_info['certificate'] = Display::label(get_lang('Yes'), 'success');
                     }
                     //$report_info['score'] = Tracking::get_avg_student_score($user['user_id'], $courseId, array(), 0);
                     $progress = intval(Tracking::get_avg_student_progress($user['user_id'], $courseId, array(), 0));
                     $report_info['progress_100'] = $progress == 100 ? Display::label(get_lang('Yes'), 'success') : Display::label(get_lang('No'));
                     $report_info['progress'] = $progress . "%";
                     foreach ($extra_fields as $extra) {
                         $user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']);
                         $report_info[$extra['1']] = $user_data[$extra['1']];
                     }
                     $users[] = $report_info;
                 }
             } else {
                 $users[$user['user_id']] = $user_info;
             }
         }
         $counter++;
     }
     return $users;
 }
Ejemplo n.º 16
0
    api_not_allowed(true);
}
$lpTable = Database::get_course_table(TABLE_LP_MAIN);
$lpId = isset($_GET['lp_id']) ? boolval($_GET['lp_id']) : false;
$sessionId = api_get_session_id();
$courseId = api_get_course_int_id();
$courseCode = api_get_course_id();
$sessionUsers = SessionManager::get_users_by_session($sessionId, 0);
$userList = [];
$lpInfo = Database::select('*', $lpTable, array('where' => array('c_id = ? AND ' => $courseId, 'id = ?' => $lpId)), 'first');
foreach ($sessionUsers as $user) {
    $lpTime = Tracking::get_time_spent_in_lp($user['user_id'], $courseCode, array($lpId), $sessionId);
    $lpScore = Tracking::get_avg_student_score($user['user_id'], $courseCode, array($lpId), $sessionId);
    $lpPogress = Tracking::get_avg_student_progress($user['user_id'], $courseCode, array($lpId), $sessionId);
    $lpLastConnection = Tracking::get_last_connection_time_in_lp($user['user_id'], $courseCode, array($lpId), $sessionId);
    $lpLastConnection = empty($lpLastConnection) ? '-' : api_convert_and_format_date($lpLastConnection, DATE_TIME_FORMAT_LONG);
    $userList[] = ['id' => $user['user_id'], 'first_name' => $user['firstname'], 'last_name' => $user['lastname'], 'lp_time' => api_time_to_hms($lpTime), 'lp_score' => is_numeric($lpScore) ? "{$lpScore}%" : $lpScore, 'lp_progress' => "{$lpPogress}%", 'lp_last_connection' => $lpLastConnection];
}
// View
$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH) . 'newscorm/lp_controller.php', 'name' => get_lang('LearningPaths')];
$actions = Display::url(Display::return_icon('back.png', get_lang('Back'), array(), ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH) . 'newscorm/lp_controller.php?' . api_get_cidreq());
$template = new Template(get_lang('StudentScore'));
$template->assign('user_list', $userList);
$template->assign('session_id', api_get_session_id());
$template->assign('course_code', api_get_course_id());
$template->assign('lp_id', $lpId);
$layout = $template->get_template('learnpath/report.tpl');
$template->assign('header', $lpInfo['name']);
$template->assign('actions', $actions);
$template->assign('content', $template->fetch($layout));
$template->display_one_col_template();
Ejemplo n.º 17
0
 $form = Tracking::setUserSearchForm($form);
 $form->display();
 // html part
 echo '<div class="report_section">
         <table class="table table-bordered table-striped">
             <tr>
                 <td>' . get_lang('AverageCoursePerStudent') . '</td>
                 <td align="right">' . (is_null($avg_courses_per_student) ? '' : round($avg_courses_per_student, 2)) . '</td>
             </tr>
             <tr>
                 <td>' . get_lang('InactivesStudents') . '</td>
                 <td align="right">' . $nb_inactive_students . '</td>
             </tr>
             <tr>
                 <td>' . get_lang('AverageTimeSpentOnThePlatform') . '</td>
                 <td align="right">' . (is_null($avg_time_spent) ? '' : api_time_to_hms($avg_time_spent)) . '</td>
             </tr>
             <tr>
                 <td>' . get_lang('AverageProgressInLearnpath') . '</td>
                 <td align="right">' . (is_null($avg_total_progress) ? '' : round($avg_total_progress, 2) . '%') . '</td>
             </tr>
             <tr>
                 <td>' . get_lang('AvgCourseScore') . '</td>
                 <td align="right">' . (is_null($avg_results_to_exercises) ? '' : round($avg_results_to_exercises, 2) . '%') . '</td>
             </tr>
             <tr>
                 <td>' . get_lang('AveragePostsInForum') . '</td>
                 <td align="right">' . (is_null($nb_posts) ? '' : round($nb_posts, 2)) . '</td>
             </tr>
             <tr>
                 <td>' . get_lang('AverageAssignments') . '</td>
Ejemplo n.º 18
0
     $sql = "SELECT id_user as user_id FROM {$tbl_session_course_user} srcu\n\t\t\t        WHERE  srcu.c_id='{$courseId}' AND id_session = '{$id_session}' AND srcu.status<>2";
 }
 $rs = Database::query($sql);
 $users = array();
 while ($row = Database::fetch_array($rs)) {
     $users[] = $row['user_id'];
 }
 if (count($users) > 0) {
     $nb_students_in_course = count($users);
     // tracking datas
     $avg_progress_in_course = Tracking::get_avg_student_progress($users, $courseId, array(), $id_session);
     $avg_score_in_course = Tracking::get_avg_student_score($users, $courseId, array(), $id_session);
     $avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $courseId, $id_session);
     $messages_in_course = Tracking::count_student_messages($users, $courseId, $id_session);
     $assignments_in_course = Tracking::count_student_assignments($users, $courseId, $id_session);
     $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
     $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
     if (is_numeric($avg_score_in_course)) {
         $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2) . '%';
     }
 } else {
     $avg_time_spent_in_course = null;
     $avg_progress_in_course = null;
     $avg_score_in_course = null;
     $messages_in_course = null;
     $assignments_in_course = null;
 }
 $tematic_advance_progress = 0;
 $thematic = new Thematic($course);
 $tematic_advance = $thematic->get_total_average_of_thematic_advances($course_code, $id_session);
 if (!empty($tematic_advance)) {
Ejemplo n.º 19
0
                while ($row_news = Database::fetch_array($res_news)) {
                    $array[$i]['total_announcements'] = $row_news[0];
                }
                //@todo don't know what means this value
                $count_students_complete_all_activities_at_50 = 0;
                if (!empty($student_count)) {
                    $array[$i]['count_students_accessing'] = $count_students_accessing;
                    $array[$i]['count_students_accessing_percentage'] = round($count_students_accessing / $student_count * 100, 0);
                    $array[$i]['count_students_complete_all_activities_at_50'] = $count_students_complete_all_activities;
                    $array[$i]['count_students_complete_all_activities'] = round($count_students_complete_all_activities / $student_count * 100, 0);
                    $array[$i]['average_percentage_activities_completed_per_student'] = round($count_students_complete_all_activities / $student_count * 100, 2);
                    $array[$i]['total_time_spent'] = 0;
                    $array[$i]['average_time_spent_per_student'] = 0;
                    if (!empty($total_time_spent)) {
                        $array[$i]['total_time_spent'] = api_time_to_hms($total_time_spent);
                        $array[$i]['average_time_spent_per_student'] = api_time_to_hms($total_time_spent / $student_count);
                    }
                    //$array[$i]['tools_used'] = $total_tools;
                }
                $i++;
            }
        }
    }
}
$headers = array(get_lang('LearningPath'), get_lang('Teachers'), get_lang('Courses'), get_lang('NumberOfStudents'), get_lang('NumberStudentsAccessingCourse'), get_lang('PercentageStudentsAccessingCourse'), get_lang('NumberStudentsCompleteAllActivities'), get_lang('PercentageStudentsCompleteAllActivities'), get_lang('AverageOfActivitiesCompletedPerStudent'), get_lang('TotalTimeSpentInTheCourse'), get_lang('AverageTimePerStudentInCourse'), get_lang('NumberOfDocumentsInLearnpath'), get_lang('NumberOfExercisesInLearnpath'), get_lang('NumberOfLinksInLearnpath'), get_lang('NumberOfForumsInLearnpath'), get_lang('NumberOfAssignmentsInLearnpath'), get_lang('NumberOfAnnouncementsInCourse'));
if (isset($_GET['export'])) {
    global $charset;
    $spreadsheet = new PHPExcel();
    $spreadsheet->setActiveSheetIndex(0);
    $worksheet = $spreadsheet->getActiveSheet();
    $line = 0;
Ejemplo n.º 20
0
            $firstname = $coachs["firstname"];
        }
        $sql_connection_time = "SELECT login_date, logout_date FROM {$tbl_track_login} WHERE login_user_id ='{$id_coach}' AND logout_date <> 'null'";
        $result_connection_time = Database::query($sql_connection_time);
        $nb_seconds = 0;
        while ($connections = Database::fetch_array($result_connection_time)) {
            $login_date = $connections["login_date"];
            $logout_date = $connections["logout_date"];
            $timestamp_login_date = strtotime($login_date);
            $timestamp_logout_date = strtotime($logout_date);
            $nb_seconds += $timestamp_logout_date - $timestamp_login_date;
        }
        if ($nb_seconds == 0) {
            $s_connection_time = '';
        } else {
            $s_connection_time = api_time_to_hms($nb_seconds);
        }
        if ($i % 2 == 0) {
            $css_class = "row_odd";
            if ($i % 20 == 0 && $i != 0) {
                if (api_is_western_name_order()) {
                    echo '<tr>
					    <th>' . get_lang('FirstName') . '</th>
                        <th>' . get_lang('LastName') . '</th>
                        <th>' . get_lang('ConnectionTime') . '</th>
                        <th>' . get_lang('AdminCourses') . '</th>
                        <th>' . get_lang('Students') . '</th>
					</tr>';
                } else {
                    echo '<tr>
					    <th>' . get_lang('LastName') . '</th>
    public function get_teachers_content_html_for_drh()
    {
        $content = '<div style="margin:10px;">';
        $content .= '<h3><font color="#000">' . get_lang('YourTeachers') . '</font></h3>';
        if (count($this->teachers) > 0) {
            $a_last_week = Text::get_last_week();
            $last_week = api_convert_and_format_date($a_last_week[0], DATE_FORMAT_SHORT) . ' ' . get_lang('Until') . '<br />' . api_convert_and_format_date($a_last_week[6], DATE_FORMAT_SHORT);
            $teachers_table = '<table class="data_table">';
            $teachers_table .= '<tr>
									<th>' . get_lang('User') . '</th>
									<th>' . get_lang('TimeSpentLastWeek') . '<br />' . $last_week . '</th>
								</tr>';
            $i = 1;
            foreach ($this->teachers as $teacher) {
                $teacher_id = $teacher['user_id'];
                $firstname = $teacher['firstname'];
                $lastname = $teacher['lastname'];
                $username = $teacher['username'];
                $time_on_platform = api_time_to_hms(Tracking::get_time_spent_on_the_platform($teacher_id, 'custom', api_get_utc_datetime($a_last_week[0]), api_get_utc_datetime($a_last_week[6])));
                if ($i % 2 == 0) {
                    $class_tr = 'row_odd';
                } else {
                    $class_tr = 'row_even';
                }
                $teachers_table .= '<tr class="' . $class_tr . '">
										<td>' . api_get_person_name($firstname, $lastname) . ' (' . $username . ')</td>
										<td align="right">' . $time_on_platform . '</td>
									</tr>';
                $i++;
            }
            $teachers_table .= '</table>';
        } else {
            $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
        }
        $content .= $teachers_table;
        if (count($this->teachers) > 0) {
            $content .= '<div style="text-align:right;margin-top:10px;"><a href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/teachers.php">' . get_lang('SeeMore') . '</a></div>';
        }
        $content .= '</div>';
        return $content;
    }
Ejemplo n.º 22
0
        $headerList[] = $item[0];
    }
    $csvContent[] = array();
    $csvContent[] = array(get_lang('Courses'));
    $csvContent[] = $headerList;
    $data = array();
    $courseToolInformationTotal = null;
    while ($course = Database::fetch_object($res)) {
        $courseInfo = api_get_course_info_by_id($course->c_id);
        $courseCode = $courseInfo['code'];
        $courseToolInformation = null;
        $tools = '<a href="course_information.php?code=' . $courseCode . '">' . Display::return_icon('synthese_view.gif', get_lang('Overview')) . '</a>' . '<a href="' . $courseInfo['course_public_url'] . '">' . Display::return_icon('course_home.gif', get_lang('CourseHomepage')) . '</a>' . '<a href="course_edit.php?course_code=' . $courseCode . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>';
        if ($course->status == STUDENT) {
            $tools .= '<a href="user_information.php?action=unsubscribe&course_code=' . $courseCode . '&user_id=' . $user['user_id'] . '">' . Display::return_icon('delete.png', get_lang('Delete')) . '</a>';
        }
        $timeSpent = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $courseInfo['real_id'], 0));
        $totalForumMessages = CourseManager::getCountPostInForumPerUser($user['user_id'], $course->id, 0);
        $row = array(Display::url($courseCode, $courseInfo['course_public_url']), $course->title, $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'), $timeSpent, $totalForumMessages, $tools);
        $csvContent[] = array_map('strip_tags', $row);
        $data[] = $row;
        $result = TrackingUserLogCSV::getToolInformation($user['user_id'], $courseInfo, 0);
        $courseToolInformationTotal .= $result['html'];
        $csvContent = array_merge($csvContent, $result['array']);
    }
    $courseInformation = Display::page_subheader(get_lang('Courses'));
    $courseInformation .= Display::return_sortable_table($header, $data, array(), array(), array('user_id' => intval($_GET['user_id'])));
    $courseInformation .= $courseToolInformationTotal;
} else {
    $courseInformation = '<p>' . get_lang('NoCoursesForThisUser') . '</p>';
}
/**
Ejemplo n.º 23
0
 }
 // Quiz in lp
 $score = Tracking::get_avg_student_score($student_id, $course_code, array($lp_id), $sessionId);
 // Latest exercise results in a LP
 $score_latest = Tracking::get_avg_student_score($student_id, $course_code, array($lp_id), $sessionId, false, true);
 if ($i % 2 == 0) {
     $css_class = "row_even";
 } else {
     $css_class = "row_odd";
 }
 $i++;
 // csv export content
 $csv_content[] = array(api_html_entity_decode(stripslashes($lp_name), ENT_QUOTES, $charset), api_time_to_hms($total_time), $score . '%', $score_latest . '%', $progress . '%', $start_time);
 echo '<tr class="' . $css_class . '">';
 echo Display::tag('td', stripslashes($lp_name));
 echo Display::tag('td', api_time_to_hms($total_time));
 if (!is_null($score)) {
     if (is_numeric($score)) {
         $score = $score . '%';
     }
 }
 echo Display::tag('td', $score);
 if (!is_null($score_latest)) {
     if (is_numeric($score_latest)) {
         $score_latest = $score_latest . '%';
     }
 }
 echo Display::tag('td', $score_latest);
 if (is_numeric($progress)) {
     $progress = $progress . '%';
 } else {
    /**
     * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
     * @return string  content html
     */
    public function get_students_content_html_for_platform_admin()
    {
        $students = $this->students;
        $content = '<div style="margin:10px;">';
        $content .= '<h3><font color="#000">' . get_lang('YourStudents') . '</font></h3>';
        $students_table = null;
        if (count($students) > 0) {
            $students_table .= '<table class="data_table">';
            $students_table .= '<tr>
									<th width="10%" rowspan="2">' . get_lang('FirstName') . '</th>
									<th width="10%" rowspan="2">' . get_lang('LastName') . '</th>
									<th width="30%" colspan="2">' . get_lang('CourseInformation') . '</th>
								</tr>
								<tr>
									<th width="10%">' . get_lang('Courses') . '</th>
									<th width="10%">' . get_lang('Time') . '</th>
								</tr>';
            $i = 1;
            foreach ($students as $student) {
                $courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true);
                $count_courses = count($courses_by_user);
                $rowspan = $count_courses ? $count_courses + 1 : 2;
                if ($i % 2 == 0) {
                    $style = ' style="background-color:#F2F2F2" ';
                } else {
                    $style = ' style="background-color:#FFF" ';
                }
                $students_table .= '<tr ' . $style . '>
										<td rowspan="' . $rowspan . '">' . $student['firstname'] . '</td>
										<td rowspan="' . $rowspan . '">' . $student['lastname'] . '</td>
									</tr>';
                // courses information about the student
                if (!empty($courses_by_user)) {
                    foreach ($courses_by_user as $course) {
                        $course_code = $course['code'];
                        $course_title = $course['title'];
                        $time = api_time_to_hms(Tracking::get_time_spent_on_the_course($student['user_id'], $course['real_id']));
                        $students_table .= '<tr ' . $style . '>
											<td align="right">' . $course_title . '</td>
											<td align="right">' . $time . '</td>
											</tr>';
                    }
                } else {
                    $students_table .= '<tr ' . $style . '>
											<td align="center" colspan="2"><i>' . get_lang('Empty') . '</i></td>
										</tr>';
                }
                $i++;
            }
            $students_table .= '</table>';
        } else {
            $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
        }
        $content .= $students_table;
        if (count($students) > 0) {
            $content .= '<div style="text-align:right;margin-top:10px;"><a href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/index.php?view=admin&display=useroverview">' . get_lang('SeeMore') . '</a></div>';
        }
        $content .= '</div>';
        return $content;
    }
Ejemplo n.º 25
0
/**
* fire a cron URL using CURL.
*
*
*/
function fire_vhost_cron($vhost)
{
    global $VCRON, $DB;
    if ($VCRON->TRACE_ENABLE) {
        $CRONTRACE = fopen($VCRON->TRACE, 'a');
    }
    $ch = curl_init($vhost->root_web . '/main/cron/run.php');
    $http_proxy_host = api_get_setting('vchamilo_httpproxyhost', 'vchamilo');
    $http_proxy_port = api_get_setting('vchamilo_httpproxyport', 'vchamilo');
    $http_proxy_bypass = api_get_setting('vchamilo_httpproxybypass', 'vchamilo');
    $http_proxy_user = api_get_setting('vchamilo_httpproxyuser', 'vchamilo');
    $http_proxy_password = api_get_setting('vchamilo_httpproxypassword', 'vchamilo');
    curl_setopt($ch, CURLOPT_TIMEOUT, $VCRON->TIMEOUT);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Chamilo');
    curl_setopt($ch, CURLOPT_POSTFIELDS, '');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml charset=UTF-8"));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    // Check for proxy.
    if (!empty($http_proxy_host) and !is_proxybypass($uri)) {
        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
        if (empty($http_proxy_port)) {
            echo "Using proxy {$http_proxy_host}\n";
            curl_setopt($ch, CURLOPT_PROXY, $http_proxy_host);
        } else {
            echo "Using proxy {$http_proxy_host}:{$http_proxy_port}\n";
            curl_setopt($ch, CURLOPT_PROXY, $http_proxy_host . ':' . $http_proxy_port);
        }
        if (!empty($http_proxy_user) and !empty($http_proxy_password)) {
            curl_setopt($ch, CURLOPT_PROXYUSERPWD, $http_proxy_user . ':' . $http_proxy_password);
            if (defined('CURLOPT_PROXYAUTH')) {
                // any proxy authentication if PHP 5.1
                curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM);
            }
        }
    }
    $timestamp_send = time();
    $rawresponse = curl_exec($ch);
    $timestamp_receive = time();
    if ($rawresponse === false) {
        $error = curl_errno($ch) . ':' . curl_error($ch);
        if ($VCRON->TRACE_ENABLE) {
            if ($CRONTRACE) {
                fputs($CRONTRACE, "VCron start on {$vhost->root_web} : " . api_time_to_hms($timestamp_send) . "\n");
                fputs($CRONTRACE, "VCron Error : {$error} \n");
                fputs($CRONTRACE, "VCron stop on {$vhost->root_web} : {$timestamp_receive}\n#################\n\n");
                fclose($CRONTRACE);
            }
        }
        echo "VCron started on {$vhost->root_web} : " . api_time_to_hms($timestamp_send) . "\n";
        echo "VCron Error : {$error} \n";
        echo "VCron stop on {$vhost->root_web} : " . api_time_to_hms($timestamp_receive) . "\n#################\n\n";
        return false;
    }
    if ($VCRON->TRACE_ENABLE) {
        if ($CRONTRACE) {
            fputs($CRONTRACE, "VCron start on {$vhost->vhostname} : " . api_time_to_hms($timestamp_send) . "\n");
            fputs($CRONTRACE, $rawresponse . "\n");
            fputs($CRONTRACE, "VCron stop on {$vhost->vhostname} : " . api_time_to_hms($timestamp_receive) . "\n#################\n\n");
            fclose($CRONTRACE);
        }
    }
    echo "VCron start on {$vhost->root_web} : " . api_time_to_hms($timestamp_send) . "\n";
    echo $rawresponse . "\n";
    echo "VCron stop on {$vhost->root_web} : " . api_time_to_hms($timestamp_receive) . "\n#################\n\n";
    $vhost->lastcrongap = time() - $vhost->lastcron;
    $vhost->lastcron = $timestamp_send;
    $vhost->croncount++;
    $vhostid = $vhost->id;
    unset($vhost->id);
    Database::update('vchamilo', (array) $vhost, array('id = ?' => $vhostid));
}