diff --git a/public/main/inc/ajax/model.ajax.php b/public/main/inc/ajax/model.ajax.php index 992a44f6ca..f9e23010e8 100644 --- a/public/main/inc/ajax/model.ajax.php +++ b/public/main/inc/ajax/model.ajax.php @@ -48,6 +48,7 @@ if (!in_array( 'get_work_student_list_overview', 'get_work_teacher', 'get_work_student', + 'get_all_work_student', 'get_work_user_list', 'get_work_user_list_others', 'get_work_user_list_all', @@ -159,8 +160,20 @@ if (($search || $forceSearch) && ('false' !== $search)) { } if (!empty($filters)) { - if (in_array($action, ['get_questions', 'get_sessions', 'get_sessions_tracking'])) { + if (in_array($action, + [ + 'get_user_course_report_resumed', + 'get_user_course_report', + 'get_questions', + 'get_sessions', + 'get_sessions_tracking', + ] + )) { switch ($action) { + case 'get_user_course_report_resumed': + case 'get_user_course_report': + $type = 'user'; + break; case 'get_questions': $type = 'question'; break; @@ -174,22 +187,29 @@ if (($search || $forceSearch) && ('false' !== $search)) { // Extra field. $extraField = new ExtraField($type); - foreach ($filters->rules as $key => $data) { - if (empty($data)) { - continue; - } - if ('extra_access_start_date' === $data->field) { - $accessStartDate = $data->data; - } - - if ('extra_access_end_date' === $data->field) { - $accessEndDate = $data->data; - } - - if (in_array($data->field, $toRemove)) { - unset($filters->rules[$key]); + if (is_object($filters) + && property_exists($filters, 'rules') + && is_array($filters->rules) + && !empty($filters->rules) + ) { + foreach ($filters->rules as $key => $data) { + if (empty($data)) { + continue; + } + if ('extra_access_start_date' === $data->field) { + $accessStartDate = $data->data; + } + + if ('extra_access_end_date' === $data->field) { + $accessEndDate = $data->data; + } + + if (in_array($data->field, $toRemove)) { + unset($filters->rules[$key]); + } } } + $result = $extraField->getExtraFieldRules($filters, 'extra_'); $extra_fields = $result['extra_fields']; @@ -432,7 +452,6 @@ switch ($action) { if (-1 == $sessionId) { $sessionList = SessionManager::get_sessions_list(); $sessionIdList = array_column($sessionList, 'id'); - $courseCodeList = []; foreach ($sessionList as $session) { $courses = SessionManager::get_course_list_by_session_id( @@ -527,6 +546,11 @@ switch ($action) { require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; $count = getWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true); break; + case 'get_all_work_student': + require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; + $withResults = isset($_REQUEST['with_results']) ? (int) $_REQUEST['with_results'] : 0; + $count = getAllWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true, $withResults); + break; case 'get_work_user_list_all': require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; $work_id = $_REQUEST['work_id']; @@ -675,6 +699,20 @@ switch ($action) { $description, ['where' => $whereCondition, 'extra' => $extra_fields] ); + } elseif (api_is_session_admin()) { + $count = SessionManager::getSessionsFollowedByUser( + api_get_user_id(), + SESSIONADMIN, + null, + null, + true, + false, + false, + null, + $keyword, + $description, + ['where' => $whereCondition, 'extra' => $extra_fields] + ); } else { // Sessions for the coach $count = Tracking::get_sessions_coached_by_user( @@ -691,16 +729,31 @@ switch ($action) { } break; case 'get_sessions': - $list_type = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : 'simple'; - if ('simple' === $list_type) { + $listType = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : SessionManager::getDefaultSessionTab(); + + if ('custom' === $listType && api_get_configuration_value('allow_session_status')) { + $whereCondition .= ' AND (s.status IN ("'.SessionManager::STATUS_PLANNED.'", "'.SessionManager::STATUS_PROGRESS.'") ) '; + } + + switch ($listType) { + case 'complete': + $count = SessionManager::get_count_admin_complete( + ['where' => $whereCondition, 'extra' => $extra_fields] + ); + break; + case 'custom': + case 'active': + case 'close': + case 'all': + default: $count = SessionManager::formatSessionsAdminForGrid( ['where' => $whereCondition, 'extra' => $extra_fields], - true - ); - } else { - $count = SessionManager::get_count_admin_complete( - ['where' => $whereCondition, 'extra' => $extra_fields] + true, + [], + [], + $listType ); + break; } break; case 'get_session_lp_progress': @@ -801,7 +854,7 @@ switch ($action) { case 'get_usergroups': $obj = new UserGroup(); $obj->protectScript(); - $count = $obj->get_count(); + $count = $obj->get_count($whereCondition); break; case 'get_usergroups_teacher': $obj = new UserGroup(); @@ -982,7 +1035,7 @@ switch ($action) { get_lang('Certificates count'), ]; - $extra_fields = UserManager::get_extra_fields( + $userExtraFields = UserManager::get_extra_fields( 0, 100, null, @@ -991,9 +1044,9 @@ switch ($action) { true ); - if (!empty($extra_fields)) { - foreach ($extra_fields as $extra) { - if ('ruc' == $extra['1']) { + if (!empty($userExtraFields)) { + foreach ($userExtraFields as $extra) { + if ($extra['1'] == 'ruc') { continue; } $columns[] = $extra['1']; @@ -1001,10 +1054,6 @@ switch ($action) { } } - if (!in_array($sidx, ['training_hours'])) { - //$sidx = 'training_hours'; - } - if (api_is_student_boss() && empty($userIdList)) { $result = []; break; @@ -1023,7 +1072,9 @@ switch ($action) { $courseCodeList, $userIdList, null, - $sessionIdList + $sessionIdList, + null, + ['where' => $whereCondition, 'extra' => $extra_fields] ); $new_result = []; @@ -1056,7 +1107,7 @@ switch ($action) { get_lang('Course progress'), ]; - $extra_fields = UserManager::get_extra_fields( + $userExtraFields = UserManager::get_extra_fields( 0, 100, null, @@ -1064,8 +1115,8 @@ switch ($action) { true, true ); - if (!empty($extra_fields)) { - foreach ($extra_fields as $extra) { + if (!empty($userExtraFields)) { + foreach ($userExtraFields as $extra) { $columns[] = $extra['1']; $column_names[] = $extra['3']; } @@ -1086,9 +1137,9 @@ switch ($action) { } //get sessions - $arrSessions = []; + $sessions = []; if (count($sessionIdList) > 0) { - $arrSessions = CourseManager::get_user_list_from_course_code( + $sessions = CourseManager::get_user_list_from_course_code( null, null, "LIMIT $start, $limit", @@ -1101,12 +1152,14 @@ switch ($action) { $courseCodeList, $userIdList, null, - $sessionIdList + $sessionIdList, + null, + ['where' => $whereCondition, 'extra' => $extra_fields] ); } //get courses - $arrCourses = CourseManager::get_user_list_from_course_code( + $courses = CourseManager::get_user_list_from_course_code( null, null, "LIMIT $start, $limit", @@ -1118,11 +1171,14 @@ switch ($action) { null, [], $userIdList, - null + null, + null, + null, + ['where' => $whereCondition, 'extra' => $extra_fields] ); //merge courses and sessions - $result = array_merge($arrSessions, $arrCourses); + $result = array_merge($sessions, $courses); if (api_is_student_boss()) { $userGroup = new UserGroup(); @@ -1234,6 +1290,27 @@ switch ($action) { $whereCondition ); break; + case 'get_all_work_student': + $columns = [ + 'type', + 'title', + 'expires_on', + ]; + + if ($withResults) { + $columns[] = 'feedback'; + $columns[] = 'last_upload'; + } + $result = getAllWorkListStudent( + $start, + $limit, + $sidx, + $sord, + $whereCondition, + false, + $withResults + ); + break; case 'get_work_user_list_all': $plagiarismColumns = []; if (api_get_configuration_value('allow_compilatio_tool')) { @@ -1501,7 +1578,7 @@ switch ($action) { ); break; case 'get_sessions_tracking': - if (api_is_drh() || api_is_session_admin()) { + if (api_is_drh()) { $orderByName = Database::escape_string($sidx); $orderByName = in_array($orderByName, ['name', 'access_start_date']) ? $orderByName : 'name'; $orderBy = " ORDER BY $orderByName $sord"; @@ -1517,6 +1594,23 @@ switch ($action) { $description, ['where' => $whereCondition, 'extra' => $extra_fields] ); + } elseif (api_is_session_admin()) { + $orderByName = Database::escape_string($sidx); + $orderByName = in_array($orderByName, ['name', 'access_start_date']) ? $orderByName : 'name'; + $orderBy = " ORDER BY $orderByName $sord"; + $sessions = SessionManager::getSessionsFollowedByUser( + api_get_user_id(), + SESSIONADMIN, + $start, + $limit, + false, + false, + false, + $orderBy, + $keyword, + $description, + ['where' => $whereCondition, 'extra' => $extra_fields] + ); } else { // Sessions for the coach $sessions = Tracking::get_sessions_coached_by_user( @@ -1532,8 +1626,8 @@ switch ($action) { ); } - $session_columns = SessionManager::getGridColumns('my_space'); - $columns = $session_columns['simple_column_name']; + $sessionColumns = SessionManager::getGridColumns('my_space'); + $columns = $sessionColumns['simple_column_name']; $result = []; if (!empty($sessions)) { @@ -1598,29 +1692,37 @@ switch ($action) { } break; case 'get_sessions': - $session_columns = SessionManager::getGridColumns($list_type); - $columns = $session_columns['simple_column_name']; + $sessionColumns = SessionManager::getGridColumns($listType); + $columns = $sessionColumns['simple_column_name']; - if ('simple' == $list_type) { - $result = SessionManager::formatSessionsAdminForGrid( + switch ($listType) { + case 'complete': + $result = SessionManager::get_sessions_admin_complete( [ 'where' => $whereCondition, 'order' => "$sidx $sord, s.name", 'extra' => $extra_fields, 'limit' => "$start , $limit", - ], - false, - $session_columns + ] ); - } else { - $result = SessionManager::get_sessions_admin_complete( + break; + case 'active': + case 'close': + case 'custom': + case 'all': + $result = SessionManager::formatSessionsAdminForGrid( [ 'where' => $whereCondition, 'order' => "$sidx $sord, s.name", 'extra' => $extra_fields, 'limit' => "$start , $limit", - ] + ], + false, + $sessionColumns, + [], + $listType ); + break; } break; case 'get_exercise_progress': @@ -2253,6 +2355,7 @@ $allowed_actions = [ 'get_work_student_list_overview', 'get_work_teacher', 'get_work_student', + 'get_all_work_student', 'get_work_user_list', 'get_work_user_list_others', 'get_work_user_list_all', diff --git a/public/main/inc/ajax/myspace.ajax.php b/public/main/inc/ajax/myspace.ajax.php index 1ac50d95bd..c4aaf4366b 100644 --- a/public/main/inc/ajax/myspace.ajax.php +++ b/public/main/inc/ajax/myspace.ajax.php @@ -1,10 +1,12 @@ 'data_table']); + $row = 0; + $col = 0; + foreach ($sessionCategoryList as $category) { + $sessionList = $category['sessions']; + foreach ($sessionList as $session) { + $courses = $session['courses']; + $sessionId = $session['session_id']; + $session['session_name']; + $totalCourse = 0; + $totalSessionAverage = 0; + foreach ($courses as &$course) { + $average = Tracking::get_avg_student_progress($userId, $course['course_code'], [], $sessionId); + $totalSessionAverage += $average; + $totalCourse++; + if (false !== $average) { + $average = $average.' %'; + } + $course['average'] = $average; + } + + $total++; + $totalSessionAverage = round($totalSessionAverage / count($courses), 2); + $totalAverage += $totalSessionAverage; + + $row++; + $table->setCellContents($row, 0, $session['session_name']); + $table->setCellContents($row, 1, $totalSessionAverage.' %'); + $table->setCellContents($row, 2, ''); + $row++; + foreach ($courses as &$course) { + $table->setCellContents($row, 0, $session['session_name']); + $table->setCellContents($row, 1, $course['title']); + $table->setCellContents($row, 2, $course['average']); + $row++; + } + } + } + + $table->setCellContents(0, 0, get_lang('Global')); + $table->setCellContents(0, 1, round($totalAverage / $total, 2).' %'); + $result = $table->toHtml(); + + if ($cacheAvailable) { + apcu_store($variable, $result, 60); + } + + echo $result; + + break; case 'access_detail': - $user_id = intval($_REQUEST['student']); + // At this date : 23/02/2017, a minor review can't determine where is used this case 'access_detail'. + $user_id = (int) $_REQUEST['student']; $course_code = Security::remove_XSS($_REQUEST['course']); $type = Security::remove_XSS($_REQUEST['type']); $range = Security::remove_XSS($_REQUEST['range']); @@ -42,12 +117,14 @@ switch ($action) { $sessionId ); } - $foo_print = grapher($sql_result, $start_date, $end_date, $type); + $foo_print = MySpace::grapher($sql_result, $start_date, $end_date, $type); echo $foo_print; break; case 'access_detail_by_date': - $db = ['is_empty' => true]; + $export = isset($_REQUEST['export']) ? $_REQUEST['export'] : false; + + $result = ['is_empty' => true]; $start_date = isset($_REQUEST['startDate']) ? $_REQUEST['startDate'] : ''; $end_date = isset($_REQUEST['endDate']) ? $_REQUEST['endDate'] : ''; $user_id = isset($_REQUEST['student']) ? $_REQUEST['student'] : ''; @@ -56,45 +133,73 @@ switch ($action) { $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : 0; $courseInfo = api_get_course_info($course_code); - $sql_result = MySpace::get_connections_to_course_by_date( + $connections = MySpace::get_connections_to_course_by_date( $user_id, $courseInfo, $sessionId, $start_date, - $end_date + $end_date, + true ); - if (is_array($sql_result) && count($sql_result) > 0) { - $db['is_empty'] = false; - $db['result'] = convert_to_string($sql_result); - $rst = get_stats( + if (is_array($connections) && count($connections) > 0) { + $result['is_empty'] = false; + $tableData = []; + foreach ($connections as $data) { + $item = [ + api_get_local_time($data['login']), + api_time_to_hms(api_strtotime($data['logout']) - api_strtotime($data['login'])), + $data['user_ip'], + ]; + $tableData[] = $item; + } + + $table = new SortableTableFromArray( + $tableData, + 0, + 500, + 'stat_table', + null, + 'stat_table' + ); + $table->set_header(1, get_lang('LoginDate'), false); + $table->set_header(2, get_lang('Duration'), false); + $table->set_header(3, get_lang('IP'), false); + $result['result'] = $table->return_table(); + + if ($export) { + Export::arrayToXls($table->toArray()); + exit; + } + + $rst = MySpace::getStats( $user_id, $courseInfo, $sessionId, $start_date, $end_date ); - $foo_stats = ''.get_lang('Total').': '.$rst['total'].'
'; - $foo_stats .= ''.get_lang('Average').': '.$rst['avg'].'
'; - $foo_stats .= ''.get_lang('Quantity').' : '.$rst['times'].'
'; - $db['stats'] = $foo_stats; - $db['graph_result'] = grapher($sql_result, $start_date, $end_date, $type); + $stats = ''.get_lang('Total').': '.$rst['total'].'
'; + $stats .= ''.get_lang('Average').': '.$rst['avg'].'
'; + $stats .= ''.get_lang('Quantity').' : '.$rst['times'].'
'; + $result['stats'] = $stats; + $result['graph_result'] = MySpace::grapher($connections, $start_date, $end_date, $type); } else { - $db['result'] = Display::return_message( - get_lang('No data available'), + $result['result'] = Display::return_message( + get_lang('NoDataAvailable'), 'warning' ); - $db['graph_result'] = Display::return_message( - get_lang('No data available'), + $result['graph_result'] = Display::return_message( + get_lang('NoDataAvailable'), 'warning' ); - $db['stats'] = Display::return_message( - get_lang('No data available'), + $result['stats'] = Display::return_message( + get_lang('NoDataAvailable'), 'warning' ); } header('Cache-Control: no-cache'); - echo json_encode($db); + echo json_encode($result); break; } exit; diff --git a/public/main/inc/ajax/session.ajax.php b/public/main/inc/ajax/session.ajax.php index b85bfe818b..3bbd09cb9c 100644 --- a/public/main/inc/ajax/session.ajax.php +++ b/public/main/inc/ajax/session.ajax.php @@ -435,6 +435,39 @@ switch ($action) { echo true; break; + case 'search_template_session': + SessionManager::protectSession(null, false); + + api_protect_limit_for_session_admin(); + + if (empty($_GET['q'])) { + break; + } + + $q = strtolower(trim($_GET['q'])); + + $list = array_map( + function ($session) { + return [ + 'id' => $session['id'], + 'text' => strip_tags($session['name']), + ]; + }, + SessionManager::formatSessionsAdminForGrid() + ); + + $list = array_filter( + $list, + function ($session) use ($q) { + $name = strtolower($session['text']); + + return strpos($name, $q) !== false; + } + ); + + header('Content-Type: application/json'); + echo json_encode(['items' => array_values($list)]); + break; default: echo ''; } diff --git a/public/main/inc/ajax/statistics.ajax.php b/public/main/inc/ajax/statistics.ajax.php index a96be59e02..2f5f82afbd 100644 --- a/public/main/inc/ajax/statistics.ajax.php +++ b/public/main/inc/ajax/statistics.ajax.php @@ -15,6 +15,7 @@ $sessionDuration = isset($_GET['session_duration']) ? (int) $_GET['session_durat $exportFormat = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : 'csv'; $operation = isset($_REQUEST['oper']) ? $_REQUEST['oper'] : false; $order = isset($_REQUEST['sord']) && in_array($_REQUEST['sord'], ['asc', 'desc']) ? $_REQUEST['sord'] : 'asc'; +$table = ''; switch ($action) { case 'add_student_to_boss': @@ -22,7 +23,7 @@ switch ($action) { $bossId = isset($_GET['boss_id']) ? (int) $_GET['boss_id'] : 0; if ($studentId && $bossId) { - UserManager::subscribeBossToUsers($bossId, [$studentId], false); + UserManager::subscribeUserToBossList($studentId, [$bossId], true); } echo Statistics::getBossTable($bossId); @@ -77,14 +78,18 @@ switch ($action) { $courseListInString = implode(', ', $courseTitleList); $table = Database::get_main_table(TABLE_MAIN_SESSION_USER); + $urlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $sql = "SELECT - count(DISTINCT user_id) count - FROM $table + count(DISTINCT su.user_id) count + FROM $table su + INNER JOIN $urlTable au + ON (su.user_id = au.user_id) WHERE - relation_type = 0 AND - registered_at >= '$start' AND - registered_at <= '$end' AND - session_id = '$sessionId' "; + access_url_id = $urlId AND + su.relation_type = 0 AND + su.registered_at >= '$start' AND + su.registered_at <= '$end' AND + su.session_id = '$sessionId' "; $result = Database::query($sql); $result = Database::fetch_array($result); @@ -119,7 +124,7 @@ switch ($action) { // for global recent logins header('Content-type: application/json'); $list = []; - $all = Statistics::getRecentLoginStats(false, $sessionDuration); + $all = Statistics::getRecentLoginStats(false, $sessionDuration, [31]); foreach ($all as $tick => $tock) { $list['labels'][] = $tick; } @@ -279,22 +284,47 @@ switch ($action) { break; case 'status': - $statusList = api_get_status_langvars(); - unset($statusList[ANONYMOUS]); + $extraFieldValueUser = new ExtraField('user'); + $extraField = $extraFieldValueUser->get_handler_field_info_by_field_variable('statusocial'); - foreach ($statusList as $status => $name) { - $conditions = ['status' => $status]; - $count = UserManager::getUserListExtraConditions( - $conditions, + $users = UserManager::getUserListExtraConditions( + [], [], false, false, null, $extraConditions, - true + false ); - $all[$name] = $count; + + $userIdList = array_column($users, 'user_id'); + $userIdListToString = implode("', '", $userIdList); + + $all = []; + $total = count($users); + $usersFound = 0; + $extraFieldOption = new ExtraFieldOption('user'); + foreach ($extraField['options'] as $item) { + $value = Database::escape_string($item['option_value']); + $count = 0; + $sql = "SELECT count(id) count + FROM $extraFieldValueUser->table_field_values + WHERE + value = '$value' AND + item_id IN ('$userIdListToString') AND + field_id = ".$extraField['id']; + $query = Database::query($sql); + $result = Database::fetch_array($query); + + $count = $result['count']; + $usersFound += $count; + + $option = $extraFieldOption->get($item['id'], true); + $item['display_text'] = $option['display_text']; + $all[$item['display_text']] = $count; } + $all[get_lang('N/A')] = $total - $usersFound; + break; case 'language': $languages = api_get_languages(); @@ -302,12 +332,13 @@ switch ($action) { foreach ($languages['folder'] as $language) { $conditions = ['language' => $language]; $key = $language; - if ('2' === substr($language, -1)) { + if (substr($language, -1) === '2') { $key = str_replace(2, '', $language); } if (!isset($all[$key])) { $all[$key] = 0; } + $key = get_lang($key); $all[$key] += UserManager::getUserListExtraConditions( $conditions, [], @@ -352,13 +383,69 @@ switch ($action) { $query = Database::query($sql); $result = Database::fetch_array($query); $count = $result['count']; - //$item['display_text'] = str_replace('2', '', $item['display_text']); $usersFound += $count; + $item['display_text'] = get_lang(str_replace('2', '', $item['display_text'])); $all[$item['display_text']] = $count; } $all[get_lang('N/A')] = $total - $usersFound; break; + case 'age': + $extraFieldValueUser = new ExtraField('user'); + $extraField = $extraFieldValueUser->get_handler_field_info_by_field_variable('terms_datedenaissance'); + + $users = UserManager::getUserListExtraConditions( + [], + [], + false, + false, + null, + $extraConditions, + false + ); + + $userIdList = array_column($users, 'user_id'); + $userIdListToString = implode("', '", $userIdList); + + $all = []; + $total = count($users); + + $sql = "SELECT value + FROM $extraFieldValueUser->table_field_values + WHERE + item_id IN ('$userIdListToString') AND + field_id = ".$extraField['id']; + $query = Database::query($sql); + $usersFound = 0; + $now = new DateTime(); + $all = [ + //get_lang('N/A') => 0, + '16-17' => 0, + '18-25' => 0, + '26-30' => 0, + ]; + + while ($row = Database::fetch_array($query)) { + $usersFound++; + if (!empty($row['value'])) { + $date1 = new DateTime($row['value']); + $interval = $now->diff($date1); + $years = (int) $interval->y; + + if ($years >= 16 && $years <= 17) { + $all['16-17']++; + } + if ($years >= 18 && $years <= 25) { + $all['18-25']++; + } + if ($years >= 26 && $years <= 30) { + $all['26-30']++; + } + } + } + + break; + case 'career': $extraFieldValueUser = new ExtraField('user'); $extraField = $extraFieldValueUser->get_handler_field_info_by_field_variable('filiere_user'); @@ -492,11 +579,6 @@ switch ($action) { $startDate = Database::escape_string($_REQUEST['date_start']); $endDate = Database::escape_string($_REQUEST['date_end']); $statusId = (int) $_REQUEST['status']; - - /*$extraConditions = ''; - if (!empty($startDate) && !empty($endDate)) { - $extraConditions .= " AND registration_date BETWEEN '$startDate' AND '$endDate' "; - }*/ $table = Database::get_main_table(TABLE_MAIN_SESSION); $statusCondition = ''; @@ -524,6 +606,9 @@ switch ($action) { } $all[$label] = $row['count']; } + + $table = Statistics::buildJsChartData($all, ''); + $table = $table['table']; break; case 'status': $sessionStatusAllowed = api_get_configuration_value('allow_session_status'); @@ -546,6 +631,8 @@ switch ($action) { $row['status'] = SessionManager::getStatusLabel($row['status']); $all[$row['status']] = $row['count']; } + $table = Statistics::buildJsChartData($all, ''); + $table = $table['table']; break; case 'language': @@ -565,7 +652,7 @@ switch ($action) { $courseId = $courses[0]; $courseInfo = api_get_course_info_by_id($courseId); $language = $courseInfo['language']; - $language = str_replace('2', '', $language); + $language = get_lang(ucfirst(str_replace(2, '', $language))); } if (!isset($all[$language])) { @@ -573,6 +660,43 @@ switch ($action) { } $all[$language]++; } + $table = Statistics::buildJsChartData($all, ''); + $table = $table['table']; + break; + case 'course_in_session': + $sql = "SELECT id FROM $table + WHERE + (display_start_date BETWEEN '$startDate' AND '$endDate' OR + display_end_date BETWEEN '$startDate' AND '$endDate') + $statusCondition + "; + + $result = Database::query($sql); + + $all = []; + $courseSessions = []; + $total = 0; + while ($row = Database::fetch_array($result)) { + $courseList = SessionManager::getCoursesInSession($row['id']); + foreach ($courseList as $courseId) { + if (!isset($courseSessions[$courseId])) { + $courseSessions[$courseId] = 0; + } + $courseSessions[$courseId]++; + $total++; + } + } + + if (!empty($courseSessions)) { + arsort($courseSessions); + foreach ($courseSessions as $courseId => $count) { + $courseInfo = api_get_course_info_by_id($courseId); + $all[$courseInfo['name']] = $count; + } + } + $table = Statistics::buildJsChartData($all, ''); + $table = $table['table']; + break; } @@ -591,6 +715,8 @@ switch ($action) { $i++; } + $list['table'] = $table; + header('Content-type: application/json'); echo json_encode($list); break; diff --git a/public/main/inc/ajax/survey.ajax.php b/public/main/inc/ajax/survey.ajax.php index 7717f2b492..19fe3bb848 100644 --- a/public/main/inc/ajax/survey.ajax.php +++ b/public/main/inc/ajax/survey.ajax.php @@ -3,43 +3,26 @@ require_once __DIR__.'/../global.inc.php'; -$action = isset($_GET['a']) ? $_GET['a'] : null; - $current_user_id = api_get_user_id(); $courseId = api_get_course_int_id(); -$surveyId = isset($_REQUEST['survey_id']) ? $_REQUEST['survey_id'] : null; -$questionId = isset($_REQUEST['question_id']) ? $_REQUEST['question_id'] : null; +$action = isset($_GET['a']) ? $_GET['a'] : null; +$surveyId = isset($_REQUEST['survey_id']) ? $_REQUEST['survey_id'] : 0; +$questionId = isset($_REQUEST['question_id']) ? $_REQUEST['question_id'] : 0; switch ($action) { case 'load_question_options': - if (!api_is_allowed_to_edit()) { + if (!api_is_allowed_to_edit(false, true)) { exit; } - $question = SurveyManager::get_question($questionId); - if (!empty($question)) { - foreach ($question['answers'] as $index => $answer) { - echo Display::input( - 'radio', - 'option['.$questionId.']', - $question['answersid'][$index], - ['class' => 'question_option'] - ); - echo $answer; - echo '
'; + if (!empty($question) && !empty($question['answer_data'])) { + $optionList = []; + foreach ($question['answer_data'] as $answer) { + $optionList[$answer['iid']] = strip_tags($answer['data']); } + echo json_encode($optionList); } - - echo ' - - '; break; case 'save_question': if (api_is_anonymous()) { diff --git a/public/main/inc/ajax/usergroup.ajax.php b/public/main/inc/ajax/usergroup.ajax.php index d841801279..3f16c14b90 100644 --- a/public/main/inc/ajax/usergroup.ajax.php +++ b/public/main/inc/ajax/usergroup.ajax.php @@ -1,5 +1,7 @@ ['name like ?' => "%$keyword%"], 'order' => 'name ']; + $items = []; + $list = $userGroup->get_all($where); + foreach ($list as $class) { + $items[] = [ + 'id' => $class['id'], + 'text' => $class['name'], + ]; + } + echo json_encode(['items' => $items]); + } + break; case 'delete_user_in_usergroup': if ($isAllowedToEdit) { $userGroup = new UserGroup(); diff --git a/public/main/inc/ajax/work.ajax.php b/public/main/inc/ajax/work.ajax.php index 66813ce6b1..3bc1f0fd08 100644 --- a/public/main/inc/ajax/work.ajax.php +++ b/public/main/inc/ajax/work.ajax.php @@ -45,8 +45,13 @@ switch ($action) { case 'delete_student_work': api_protect_course_script(true); if ($isAllowedToEdit) { - $itemId = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0; - deleteWorkItem($itemId, $courseInfo); + if (empty($_REQUEST['id'])) { + return false; + } + $itemList = explode(',', $_REQUEST['id']); + foreach ($itemList as $itemId) { + deleteWorkItem($itemId, $courseInfo); + } echo '1'; exit; } diff --git a/public/main/inc/lib/Compilatio.php b/public/main/inc/lib/Compilatio.php index 0222f21c3d..5d202459ab 100644 --- a/public/main/inc/lib/Compilatio.php +++ b/public/main/inc/lib/Compilatio.php @@ -1,4 +1,5 @@ soapcli)) { return "Error in constructor compilatio() $this->soapcli"; } + return $this->soapcli->__call( 'addDocumentBase64', [ @@ -272,7 +274,6 @@ class Compilatio base64_encode($content), ] ); - } catch (SoapFault $fault) { return "Erreur sendDoc()".$fault->faultcode." ".$fault->faultstring; } @@ -409,7 +410,6 @@ class Compilatio $loading = Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin'); $loading .= ' '; //$refreshReturn = Display::url('javascript:window.location.reload(false);', $loading); - switch ($status) { case 'ANALYSE_IN_QUEUE': $content = $loading.$text['analysisinqueue']; diff --git a/public/main/inc/lib/NotificationEvent.php b/public/main/inc/lib/NotificationEvent.php index 095417d897..9bd964d05b 100644 --- a/public/main/inc/lib/NotificationEvent.php +++ b/public/main/inc/lib/NotificationEvent.php @@ -57,6 +57,7 @@ class NotificationEvent extends Model $list = array_column($list, 'name', 'id'); $form->addSelect('event_id', get_lang('JustificationType'), $list); $form->freeze('event_id'); + break; default: break; diff --git a/public/main/inc/lib/ScheduledAnnouncement.php b/public/main/inc/lib/ScheduledAnnouncement.php index aee00ed2c0..6094df0632 100644 --- a/public/main/inc/lib/ScheduledAnnouncement.php +++ b/public/main/inc/lib/ScheduledAnnouncement.php @@ -1,4 +1,5 @@ $pathId.$name]; } - - return false; } + + return false; } /** @@ -9051,10 +9051,10 @@ function api_number_format($number, $decimals = 0, $decimalSeparator = '.', $tho /** * Set location url with a exit break by default. * - * @param $url + * @param string $url * @param bool $exit */ -function location($url, $exit = true) +function api_location($url, $exit = true) { header('Location: '.$url);