model.ajax.php 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. //@todo this could be integrated in the inc/lib/model.lib.php + try to clean this file
  4. $language_file = array('admin', 'exercice', 'gradebook', 'tracking');
  5. require_once '../global.inc.php';
  6. $libpath = api_get_path(LIBRARY_PATH);
  7. // 1. Setting variables needed by jqgrid
  8. $action = $_GET['a'];
  9. $page = intval($_REQUEST['page']); //page
  10. $limit = intval($_REQUEST['rows']); //quantity of rows
  11. $sidx = $_REQUEST['sidx']; //index (field) to filter
  12. $sord = $_REQUEST['sord']; //asc or desc
  13. if (strpos(strtolower($sidx), 'asc') !== false) {
  14. $sidx = str_replace(array('asc', ','), '', $sidx);
  15. $sord = 'asc';
  16. }
  17. if (strpos(strtolower($sidx), 'desc') !== false) {
  18. $sidx = str_replace(array('desc', ','), '', $sidx);
  19. $sord = 'desc';
  20. }
  21. if (!in_array($sord, array('asc','desc'))) {
  22. $sord = 'desc';
  23. }
  24. // Actions allowed to other roles.
  25. if (!in_array(
  26. $action,
  27. array(
  28. 'get_exercise_results',
  29. 'get_work_student_list_overview',
  30. 'get_hotpotatoes_exercise_results',
  31. 'get_work_teacher',
  32. 'get_work_student',
  33. 'get_work_user_list',
  34. 'get_work_user_list_others',
  35. 'get_work_user_list_all',
  36. 'get_timelines',
  37. 'get_user_skill_ranking',
  38. 'get_usergroups_teacher',
  39. 'get_user_course_report_resumed',
  40. 'get_user_course_report',
  41. 'get_sessions_tracking',
  42. 'get_course_announcements'
  43. )
  44. ) && !isset($_REQUEST['from_course_session'])) {
  45. api_protect_admin_script(true);
  46. } elseif (isset($_REQUEST['from_course_session']) &&
  47. $_REQUEST['from_course_session'] == 1
  48. ) {
  49. api_protect_teacher_script(true);
  50. }
  51. // Search features
  52. //@todo move this in the display_class or somewhere else
  53. function getWhereClause($col, $oper, $val)
  54. {
  55. $ops = array(
  56. 'eq' => '=', //equal
  57. 'ne' => '<>', //not equal
  58. 'lt' => '<', //less than
  59. 'le' => '<=', //less than or equal
  60. 'gt' => '>', //greater than
  61. 'ge' => '>=', //greater than or equal
  62. 'bw' => 'LIKE', //begins with
  63. 'bn' => 'NOT LIKE', //doesn't begin with
  64. 'in' => 'LIKE', //is in
  65. 'ni' => 'NOT LIKE', //is not in
  66. 'ew' => 'LIKE', //ends with
  67. 'en' => 'NOT LIKE', //doesn't end with
  68. 'cn' => 'LIKE', //contains
  69. 'nc' => 'NOT LIKE' //doesn't contain
  70. );
  71. if (empty($col)) {
  72. return '';
  73. }
  74. if ($oper == 'bw' || $oper == 'bn') {
  75. $val .= '%';
  76. }
  77. if ($oper == 'ew' || $oper == 'en') {
  78. $val = '%'.$val;
  79. }
  80. if ($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') {
  81. $val = '%'.$val.'%';
  82. }
  83. $val = Database::escape_string($val);
  84. return " $col {$ops[$oper]} '$val' ";
  85. }
  86. // If there is no search request sent by jqgrid, $where should be empty
  87. $whereCondition = null;
  88. $operation = isset($_REQUEST['oper']) ? $_REQUEST['oper'] : false;
  89. $exportFormat = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : 'csv';
  90. $searchField = isset($_REQUEST['searchField']) ? $_REQUEST['searchField'] : false;
  91. $searchOperator = isset($_REQUEST['searchOper']) ? $_REQUEST['searchOper'] : false;
  92. $searchString = isset($_REQUEST['searchString']) ? $_REQUEST['searchString'] : false;
  93. $search = isset($_REQUEST['_search']) ? $_REQUEST['_search'] : false;
  94. $forceSearch = isset($_REQUEST['_force_search']) ? $_REQUEST['_force_search'] : false;
  95. if ($search || $forceSearch) {
  96. $whereConditionInForm = getWhereClause($searchField, $searchOperator, $searchString);
  97. if (!empty($whereConditionInForm)) {
  98. $whereCondition .= ' AND '.$whereConditionInForm;
  99. }
  100. $filters = isset($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;
  101. if (!empty($filters) && !empty($filters->rules)) {
  102. $whereCondition .= ' AND ( ';
  103. $counter = 0;
  104. foreach ($filters->rules as $key => $rule) {
  105. $whereCondition .= getWhereClause($rule->field, $rule->op, $rule->data);
  106. if ($counter < count($filters->rules) -1) {
  107. $whereCondition .= $filters->groupOp;
  108. }
  109. $counter++;
  110. }
  111. $whereCondition .= ' ) ';
  112. }
  113. }
  114. // get index row - i.e. user click to sort $sord = $_GET['sord'];
  115. // get the direction
  116. if (!$sidx) {
  117. $sidx = 1;
  118. }
  119. //2. Selecting the count FIRST
  120. //@todo rework this
  121. switch ($action) {
  122. case 'get_course_announcements':
  123. $count = AnnouncementManager::getAnnouncements(null, null, true);
  124. break;
  125. case 'get_user_course_report':
  126. case 'get_user_course_report_resumed':
  127. if (!(api_is_platform_admin(false, true))) {
  128. //exit;
  129. }
  130. $courseCodeList = array();
  131. $userIdList = array();
  132. if (api_is_drh()) {
  133. if (api_drh_can_access_all_session_content()) {
  134. $userList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  135. 'drh_all',
  136. api_get_user_id()
  137. );
  138. if (!empty($userList)) {
  139. foreach ($userList as $user) {
  140. $userIdList[] = $user['user_id'];
  141. }
  142. }
  143. $courseList = SessionManager::getAllCoursesFollowedByUser(
  144. api_get_user_id(),
  145. null
  146. );
  147. if (!empty($courseList)) {
  148. foreach ($courseList as $course) {
  149. $courseCodeList[] = $course['code'];
  150. }
  151. }
  152. } else {
  153. $userList = UserManager::get_users_followed_by_drh(api_get_user_id());
  154. if (!empty($userList)) {
  155. $userIdList = array_keys($userList);
  156. }
  157. $courseList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  158. if (!empty($courseList)) {
  159. $courseCodeList = array_keys($courseList);
  160. }
  161. }
  162. if (empty($userIdList) || empty($courseCodeList)) {
  163. exit;
  164. }
  165. }
  166. if ($action == 'get_user_course_report') {
  167. $count = CourseManager::get_count_user_list_from_course_code(false, null, $courseCodeList, $userIdList);
  168. } else {
  169. $count = CourseManager::get_count_user_list_from_course_code(
  170. true,
  171. array('ruc'),
  172. $courseCodeList,
  173. $userIdList
  174. );
  175. }
  176. break;
  177. case 'get_course_exercise_medias':
  178. $course_id = api_get_course_int_id();
  179. $count = Question::get_count_course_medias($course_id);
  180. break;
  181. case 'get_user_skill_ranking':
  182. $skill = new Skill();
  183. $count = $skill->get_user_list_skill_ranking_count();
  184. break;
  185. case 'get_work_teacher':
  186. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  187. $count = getWorkListTeacher(0, $limit, $sidx, $sord, $whereCondition, true);
  188. break;
  189. case 'get_work_student':
  190. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  191. $count = getWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true);
  192. break;
  193. case 'get_work_user_list_all':
  194. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  195. $work_id = $_REQUEST['work_id'];
  196. $count = get_count_work($work_id);
  197. break;
  198. case 'get_work_user_list_others':
  199. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  200. $work_id = $_REQUEST['work_id'];
  201. $count = get_count_work($work_id, api_get_user_id());
  202. break;
  203. case 'get_work_user_list':
  204. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  205. $work_id = $_REQUEST['work_id'];
  206. $courseInfo = api_get_course_info();
  207. $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
  208. if (empty($documents)) {
  209. $whereCondition .= " AND u.user_id = ".api_get_user_id();
  210. $count = get_work_user_list(
  211. 0,
  212. $limit,
  213. $sidx,
  214. $sord,
  215. $work_id,
  216. $whereCondition,
  217. null,
  218. true
  219. );
  220. } else {
  221. $count = get_work_user_list_from_documents(
  222. 0,
  223. $limit,
  224. $sidx,
  225. $sord,
  226. $work_id,
  227. api_get_user_id(),
  228. $whereCondition,
  229. true
  230. );
  231. }
  232. break;
  233. case 'get_work_student_list_overview':
  234. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  235. return 0;
  236. }
  237. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  238. $workId = isset($_GET['work_id']) ? $_GET['work_id'] : null;
  239. $count = getWorkUserListData(
  240. $workId,
  241. api_get_course_id(),
  242. api_get_session_id(),
  243. api_get_group_id(),
  244. 0,
  245. $limit,
  246. null,
  247. null,
  248. true
  249. );
  250. break;
  251. case 'get_exercise_results':
  252. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  253. $exercise_id = $_REQUEST['exerciseId'];
  254. if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) {
  255. $filter_user = intval($_GET['filter_by_user']);
  256. $whereCondition .= " AND te.exe_user_id = '$filter_user'";
  257. }
  258. $count = get_count_exam_results($exercise_id, $whereCondition);
  259. break;
  260. case 'get_hotpotatoes_exercise_results':
  261. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  262. $hotpot_path = $_REQUEST['path'];
  263. $count = get_count_exam_hotpotatoes_results($hotpot_path);
  264. break;
  265. case 'get_sessions_tracking':
  266. $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
  267. $description = '';
  268. $setting = api_get_configuration_value('show_session_description');
  269. if ($setting) {
  270. $description = $keyword;
  271. }
  272. if (api_is_drh()) {
  273. $count = SessionManager::get_sessions_followed_by_drh(
  274. api_get_user_id(),
  275. null,
  276. null,
  277. true,
  278. false,
  279. false,
  280. null,
  281. $keyword,
  282. $description
  283. );
  284. } else {
  285. // Sessions for the coach
  286. $count = Tracking::get_sessions_coached_by_user(
  287. api_get_user_id(),
  288. null,
  289. null,
  290. true,
  291. $keyword,
  292. $description
  293. );
  294. }
  295. break;
  296. case 'get_sessions':
  297. $courseId = isset($_GET['course_id']) && !empty($_GET['course_id']) ? intval($_GET['course_id']) : null;
  298. $whereCondition = str_replace('category_name', 'sc.name', $whereCondition);
  299. if (!empty($courseId)) {
  300. $whereCondition .= " AND c.id = $courseId";
  301. }
  302. $count = SessionManager::get_count_admin($whereCondition);
  303. break;
  304. case 'get_session_lp_progress':
  305. case 'get_session_progress':
  306. //@TODO replace this for a more efficient function (not retrieving the whole data)
  307. $course = api_get_course_info_by_id($_GET['course_id']);
  308. $users = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id'], $_GET['date_from'], $_GET['date_to']);
  309. $count = count($users);
  310. break;
  311. case 'get_exercise_progress':
  312. //@TODO replace this for a more efficient function (not retrieving the whole data)
  313. $records = Tracking::get_exercise_progress($_GET['session_id'], $_GET['course_id'], $_GET['exercise_id'], $_GET['date_from'], $_GET['date_to']);
  314. $count = count($records);
  315. break;
  316. case 'get_session_access_overview':
  317. //@TODO replace this for a more efficient function (not retrieving the whole data)
  318. $records = SessionManager::get_user_data_access_tracking_overview($_GET['session_id'], $_GET['course_id'], $_GET['student_id'], $_GET['profile'], $_GET['date_from'], $_GET['date_to'], $options);
  319. $count = count($records);
  320. break;
  321. case 'get_survey_overview':
  322. //@TODO replace this for a more efficient function (not retrieving the whole data)
  323. $records = SessionManager::get_survey_overview($_GET['session_id'], $_GET['course_id'], $_GET['survey_id'], $_GET['date_from'], $_GET['date_to'], $options);
  324. $count = count($records);
  325. break;
  326. case 'get_exercise_grade':
  327. //@TODO replace this for a more efficient function (not retrieving the whole data)
  328. $course = api_get_course_info_by_id($_GET['course_id']);
  329. $users = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id']);
  330. $count = count($users);
  331. break;
  332. case 'get_extra_fields':
  333. $type = $_REQUEST['type'];
  334. $obj = new ExtraField($type);
  335. $count = $obj->get_count();
  336. break;
  337. case 'get_extra_field_options':
  338. $type = $_REQUEST['type'];
  339. $field_id = $_REQUEST['field_id'];
  340. $obj = new ExtraFieldOption($type);
  341. $count = $obj->get_count_by_field_id($field_id);
  342. break;
  343. case 'get_timelines':
  344. require_once $libpath.'timeline.lib.php';
  345. $obj = new Timeline();
  346. $count = $obj->get_count();
  347. break;
  348. case 'get_gradebooks':
  349. require_once $libpath.'gradebook.lib.php';
  350. $obj = new Gradebook();
  351. $count = $obj->get_count();
  352. break;
  353. case 'get_event_email_template':
  354. $obj = new EventEmailTemplate();
  355. $count = $obj->get_count();
  356. break;
  357. case 'get_careers':
  358. $obj = new Career();
  359. $count = $obj->get_count();
  360. break;
  361. case 'get_promotions':
  362. $obj = new Promotion();
  363. $count = $obj->get_count();
  364. break;
  365. case 'get_grade_models':
  366. $obj = new GradeModel();
  367. $count = $obj->get_count();
  368. break;
  369. case 'get_usergroups':
  370. $obj = new UserGroup();
  371. $count = $obj->get_count();
  372. break;
  373. case 'get_usergroups_teacher':
  374. $obj = new UserGroup();
  375. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
  376. $course_id = api_get_course_int_id();
  377. if ($type == 'registered') {
  378. $count = $obj->get_usergroup_by_course_with_data_count($course_id);
  379. } else {
  380. $count = $obj->get_count();
  381. }
  382. break;
  383. default:
  384. exit;
  385. }
  386. //3. Calculating first, end, etc
  387. $total_pages = 0;
  388. if ($count > 0) {
  389. if (!empty($limit)) {
  390. $total_pages = ceil((float)$count/(float)$limit);
  391. }
  392. }
  393. if ($page > $total_pages) {
  394. $page = $total_pages;
  395. }
  396. $start = $limit * $page - $limit;
  397. if ($start < 0) {
  398. $start = 0;
  399. }
  400. //4. Deleting an element if the user wants to
  401. if (isset($_REQUEST['oper']) && $_REQUEST['oper'] == 'del') {
  402. $obj->delete($_REQUEST['id']);
  403. }
  404. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh();
  405. //5. Querying the DB for the elements
  406. $columns = array();
  407. switch ($action) {
  408. case 'get_course_exercise_medias':
  409. $columns = array('question');
  410. $result = Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $whereCondition);
  411. break;
  412. case 'get_user_course_report_resumed':
  413. $columns = array(
  414. 'extra_ruc',
  415. 'training_hours',
  416. 'count_users',
  417. 'count_users_registered',
  418. 'average_hours_per_user',
  419. 'count_certificates'
  420. );
  421. $column_names = array(
  422. get_lang('Company'),
  423. get_lang('TrainingHoursAccumulated'),
  424. get_lang('CountOfSubscriptions'),
  425. get_lang('CountOfUsers'),
  426. get_lang('AverageHoursPerStudent'),
  427. get_lang('CountCertificates')
  428. );
  429. $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
  430. if (!empty($extra_fields)) {
  431. foreach ($extra_fields as $extra) {
  432. if ($extra['1'] == 'ruc') {
  433. continue;
  434. }
  435. $columns[] = $extra['1'];
  436. $column_names[] = $extra['3'];
  437. }
  438. }
  439. if (!in_array($sidx, array('training_hours'))) {
  440. //$sidx = 'training_hours';
  441. }
  442. $result = CourseManager::get_user_list_from_course_code(
  443. null,
  444. null,
  445. "LIMIT $start, $limit",
  446. null, //" $sidx $sord",
  447. null,
  448. null,
  449. true,
  450. true,
  451. array('ruc'),
  452. $courseCodeList,
  453. $userIdList
  454. );
  455. $new_result = array();
  456. if (!empty($result)) {
  457. foreach ($result as $row) {
  458. $row['training_hours'] = api_time_to_hms($row['training_hours']);
  459. $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']);
  460. $new_result[] = $row;
  461. }
  462. $result = $new_result;
  463. }
  464. break;
  465. case 'get_user_course_report':
  466. $columns = array('course', 'user', 'time', 'certificate', 'progress_100', 'progress');
  467. $column_names = array(
  468. get_lang('Course'),
  469. get_lang('User'),
  470. get_lang('ManHours'),
  471. get_lang('CertificateGenerated'),
  472. get_lang('Approved'),
  473. get_lang('CourseAdvance')
  474. );
  475. $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
  476. if (!empty($extra_fields)) {
  477. foreach ($extra_fields as $extra) {
  478. $columns[] = $extra['1'];
  479. $column_names[] = $extra['3'];
  480. }
  481. }
  482. if (!in_array($sidx, array('title'))) {
  483. $sidx = 'title';
  484. }
  485. $result = CourseManager::get_user_list_from_course_code(
  486. null,
  487. null,
  488. "LIMIT $start, $limit",
  489. " $sidx $sord",
  490. null,
  491. null,
  492. true,
  493. false,
  494. null,
  495. $courseCodeList,
  496. $userIdList
  497. );
  498. break;
  499. case 'get_user_skill_ranking':
  500. $columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank');
  501. $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $whereCondition);
  502. $result = msort($result, 'skills_acquired', 'asc');
  503. $skills_in_course = array();
  504. if (!empty($result)) {
  505. foreach ($result as &$item) {
  506. $user_info = api_get_user_info($item['user_id']);
  507. $personal_course_list = UserManager::get_personal_session_course_list($item['user_id']);
  508. $count_skill_by_course = array();
  509. foreach ($personal_course_list as $course_item) {
  510. if (!isset($skills_in_course[$course_item['code']])) {
  511. $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']);
  512. $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
  513. } else {
  514. $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
  515. }
  516. }
  517. $item['photo'] = Display::img($user_info['avatar_small']);
  518. $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
  519. }
  520. }
  521. break;
  522. case 'get_course_announcements':
  523. $columns = array(
  524. 'title',
  525. 'username',
  526. 'insert_date',
  527. 'actions'
  528. );
  529. $titleToSearch = isset($_REQUEST['title_to_search']) ? $_REQUEST['title_to_search'] : '';
  530. $userIdToSearch = isset($_REQUEST['user_id_to_search']) ? $_REQUEST['user_id_to_search'] : 0;
  531. $result = AnnouncementManager::getAnnouncements(
  532. null,
  533. null,
  534. false,
  535. $start,
  536. $limit,
  537. $sidx,
  538. $sord,
  539. $titleToSearch,
  540. $userIdToSearch
  541. );
  542. break;
  543. case 'get_work_teacher':
  544. $columns = array(
  545. 'type',
  546. 'title',
  547. 'sent_date',
  548. 'expires_on',
  549. 'amount',
  550. 'actions'
  551. );
  552. $result = getWorkListTeacher($start, $limit, $sidx, $sord, $whereCondition);
  553. break;
  554. case 'get_work_student':
  555. $columns = array('type', 'title', 'expires_on', 'others');
  556. if (ALLOW_USER_COMMENTS) {
  557. $columns = array(
  558. 'type',
  559. 'title',
  560. 'expires_on',
  561. 'feedback',
  562. 'last_upload',
  563. 'others'
  564. );
  565. }
  566. $result = getWorkListStudent($start, $limit, $sidx, $sord, $whereCondition);
  567. break;
  568. case 'get_work_user_list_all':
  569. if (isset($_GET['type']) && $_GET['type'] == 'simple') {
  570. $columns = array(
  571. 'type',
  572. 'firstname',
  573. 'lastname',
  574. 'title',
  575. 'qualification',
  576. 'sent_date',
  577. 'qualificator_id',
  578. 'actions'
  579. );
  580. } else {
  581. $columns = array(
  582. 'type',
  583. 'firstname',
  584. 'lastname',
  585. 'title',
  586. 'sent_date',
  587. 'actions'
  588. );
  589. if (ALLOW_USER_COMMENTS) {
  590. $columns = array(
  591. 'type',
  592. 'firstname',
  593. 'lastname',
  594. 'title',
  595. 'qualification',
  596. 'sent_date',
  597. 'actions'
  598. );
  599. }
  600. }
  601. $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
  602. break;
  603. case 'get_work_user_list_others':
  604. if (isset($_GET['type']) && $_GET['type'] == 'simple') {
  605. $columns = array(
  606. 'type', 'firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'
  607. );
  608. } else {
  609. $columns = array('type', 'firstname', 'lastname', 'title', 'sent_date', 'actions');
  610. }
  611. $whereCondition .= " AND u.user_id <> ".api_get_user_id();
  612. $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
  613. break;
  614. case 'get_work_user_list':
  615. if (isset($_GET['type']) && $_GET['type'] == 'simple') {
  616. $columns = array(
  617. 'type', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'
  618. );
  619. } else {
  620. $columns = array('type', 'title', 'sent_date', 'actions');
  621. if (ALLOW_USER_COMMENTS) {
  622. $columns = array('type', 'title', 'qualification', 'sent_date', 'actions');
  623. }
  624. }
  625. $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
  626. if (empty($documents)) {
  627. $whereCondition .= " AND u.user_id = ".api_get_user_id();
  628. $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
  629. } else {
  630. $result = get_work_user_list_from_documents(
  631. $start,
  632. $limit,
  633. $sidx,
  634. $sord,
  635. $work_id,
  636. api_get_user_id(),
  637. $whereCondition
  638. );
  639. }
  640. break;
  641. case 'get_exercise_results':
  642. $course = api_get_course_info();
  643. // Used inside get_exam_results_data()
  644. $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
  645. if ($is_allowedToEdit) {
  646. $columns = array(
  647. 'firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions'
  648. );
  649. $officialCodeInList = api_get_configuration_value('show_official_code_exercise_result_list');
  650. if ($officialCodeInList == true) {
  651. $columns = array_merge(array('official_code'), $columns);
  652. }
  653. }
  654. $result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $whereCondition);
  655. break;
  656. case 'get_hotpotatoes_exercise_results':
  657. $course = api_get_course_info();
  658. $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
  659. if (api_is_allowed_to_edit()) {
  660. $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
  661. } else {
  662. $columns = array('exe_date', 'score', 'actions');
  663. }
  664. $result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $whereCondition);
  665. break;
  666. case 'get_work_student_list_overview':
  667. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  668. return array();
  669. }
  670. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  671. $columns = array(
  672. 'student', 'works'
  673. );
  674. $result = getWorkUserListData(
  675. $workId,
  676. api_get_course_id(),
  677. api_get_session_id(),
  678. api_get_group_id(),
  679. $start,
  680. $limit,
  681. $sidx,
  682. $sord
  683. );
  684. break;
  685. case 'get_hotpotatoes_exercise_results':
  686. $course = api_get_course_info();
  687. $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
  688. if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
  689. $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
  690. } else {
  691. $columns = array('exe_date', 'score', 'actions');
  692. }
  693. $result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $whereCondition);
  694. break;
  695. case 'get_sessions_tracking':
  696. if (api_is_drh()) {
  697. $sessions = SessionManager::get_sessions_followed_by_drh(
  698. api_get_user_id(),
  699. $start,
  700. $limit,
  701. false,
  702. false,
  703. false,
  704. null,
  705. $keyword,
  706. $description
  707. );
  708. } else {
  709. // Sessions for the coach
  710. $sessions = Tracking::get_sessions_coached_by_user(
  711. api_get_user_id(),
  712. $start,
  713. $limit,
  714. false,
  715. $keyword,
  716. $description
  717. );
  718. }
  719. $columns = array(
  720. 'name',
  721. 'date',
  722. 'course_per_session',
  723. 'student_per_session',
  724. 'details'
  725. );
  726. $result = array();
  727. if (!empty($sessions)) {
  728. foreach ($sessions as $session) {
  729. if (api_drh_can_access_all_session_content()) {
  730. $count_courses_in_session = count(SessionManager::get_course_list_by_session_id($session['id']));
  731. } else {
  732. $count_courses_in_session = count(Tracking::get_courses_followed_by_coach($user_id, $session['id']));
  733. }
  734. $count_users_in_session = count(SessionManager::get_users_by_session($session['id'], 0));
  735. $session_date = array();
  736. if (!empty($session['date_start']) && $session['date_start'] != '0000-00-00') {
  737. $session_date[] = get_lang('From').' '.api_format_date($session['date_start'], DATE_FORMAT_SHORT);
  738. }
  739. if (!empty($session['date_end']) && $session['date_end'] != '0000-00-00') {
  740. $session_date[] = get_lang('Until').' '.api_format_date($session['date_end'], DATE_FORMAT_SHORT);
  741. }
  742. if (empty($session_date)) {
  743. $session_date_string = '-';
  744. } else {
  745. $session_date_string = implode(' ', $session_date);
  746. }
  747. $sessionUrl = api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id'];
  748. $result[] = array(
  749. 'name' => $session['name'],
  750. 'date' => $session_date_string,
  751. 'course_per_session' => $count_courses_in_session,
  752. 'student_per_session' => $count_users_in_session,
  753. 'details' => Display::url(Display::return_icon('2rightarrow.gif'), $sessionUrl)
  754. );
  755. }
  756. }
  757. break;
  758. case 'get_sessions':
  759. $columns = array(
  760. 'name',
  761. 'nbr_courses',
  762. 'nbr_users',
  763. 'category_name',
  764. 'date_start',
  765. 'date_end',
  766. 'coach_name',
  767. 'session_active',
  768. 'visibility'
  769. );
  770. // Rename Category_name
  771. $whereCondition = str_replace('category_name', 'sc.name', $whereCondition);
  772. $result = SessionManager::get_sessions_admin(
  773. array(
  774. 'where' => $whereCondition,
  775. 'order' => "$sidx $sord",
  776. 'limit'=> "$start , $limit"
  777. )
  778. );
  779. break;
  780. case 'get_exercise_progress':
  781. $sessionId = intval($_GET['session_id']);
  782. $courseId = intval($_GET['course_id']);
  783. $exerciseId = intval($_GET['exercise_id']);
  784. $date_from = $_GET['date_from'];
  785. $date_to = $_GET['date_to'];
  786. $columns = array(
  787. 'session',
  788. 'exercise_id',
  789. 'quiz_title',
  790. 'username',
  791. 'lastname',
  792. 'firstname',
  793. 'time',
  794. 'question_id',
  795. 'question',
  796. 'description',
  797. 'answer',
  798. 'correct',
  799. );
  800. $result = Tracking::get_exercise_progress(
  801. $sessionId,
  802. $courseId,
  803. $exerciseId,
  804. $date_from,
  805. $date_to,
  806. array(
  807. 'where' => $whereCondition,
  808. 'order' => "$sidx $sord",
  809. 'limit'=> "$start , $limit"
  810. )
  811. );
  812. break;
  813. case 'get_session_lp_progress':
  814. $sessionId = 0;
  815. if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) {
  816. $sessionId = intval($_GET['session_id']);
  817. $courseId = intval($_GET['course_id']);
  818. $course = api_get_course_info_by_id($courseId);
  819. }
  820. /**
  821. * Add lessons of course
  822. *
  823. */
  824. $columns = array(
  825. 'username',
  826. 'firstname',
  827. 'lastname',
  828. );
  829. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  830. $lessons = LearnpathList::get_course_lessons($course['code'], $sessionId);
  831. foreach ($lessons as $lesson_id => $lesson) {
  832. $columns[] = $lesson_id;
  833. }
  834. $columns[] = 'total';
  835. $result = SessionManager::get_session_lp_progress($sessionId, $courseId, $date_from, $date_to,
  836. array(
  837. 'where' => $whereCondition,
  838. 'order' => "$sidx $sord",
  839. 'limit'=> "$start , $limit"
  840. )
  841. );
  842. break;
  843. case 'get_survey_overview':
  844. $sessionId = 0;
  845. if (!empty($_GET['session_id']) &&
  846. !empty($_GET['course_id']) &&
  847. !empty($_GET['survey_id'])
  848. ) {
  849. $sessionId = intval($_GET['session_id']);
  850. $courseId = intval($_GET['course_id']);
  851. $surveyId = intval($_GET['survey_id']);
  852. $date_from = $_GET['date_from'];
  853. $date_to = $_GET['date_to'];
  854. //$course = api_get_course_info_by_id($courseId);
  855. }
  856. /**
  857. * Add lessons of course
  858. */
  859. $columns = array(
  860. 'username',
  861. 'firstname',
  862. 'lastname',
  863. );
  864. $questions = survey_manager::get_questions($surveyId, $courseId);
  865. foreach ($questions as $question_id => $question)
  866. {
  867. $columns[] = $question_id;
  868. }
  869. $result = SessionManager::get_survey_overview($sessionId, $courseId, $surveyId, $date_from, $date_to,
  870. array(
  871. 'where' => $whereCondition,
  872. 'order' => "$sidx $sord",
  873. 'limit'=> "$start , $limit"
  874. )
  875. );
  876. break;
  877. case 'get_session_progress':
  878. $columns = array(
  879. 'lastname',
  880. 'firstname',
  881. 'username',
  882. #'profile',
  883. 'total',
  884. 'courses',
  885. 'lessons',
  886. 'exercises',
  887. 'forums',
  888. 'homeworks',
  889. 'wikis',
  890. 'surveys',
  891. //exercises
  892. 'lessons_total' ,
  893. 'lessons_done' ,
  894. 'lessons_left' ,
  895. 'lessons_progress',
  896. //exercises
  897. 'exercises_total' ,
  898. 'exercises_done' ,
  899. 'exercises_left' ,
  900. 'exercises_progress' ,
  901. //forums
  902. 'forums_total' ,
  903. 'forums_done' ,
  904. 'forums_left' ,
  905. 'forums_progress' ,
  906. //assignments
  907. 'assignments_total' ,
  908. 'assignments_done' ,
  909. 'assignments_left' ,
  910. 'assignments_progress' ,
  911. //Wiki
  912. 'wiki_total',
  913. 'wiki_revisions',
  914. 'wiki_read',
  915. 'wiki_unread',
  916. 'wiki_progress',
  917. //surveys
  918. 'surveys_total' ,
  919. 'surveys_done' ,
  920. 'surveys_left' ,
  921. 'surveys_progress' ,
  922. );
  923. $sessionId = 0;
  924. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  925. $sessionId = intval($_GET['session_id']);
  926. $courseId = intval($_GET['course_id']);
  927. }
  928. $result = SessionManager::get_session_progress($sessionId, $courseId,
  929. array(
  930. 'where' => $whereCondition,
  931. 'order' => "$sidx $sord",
  932. 'limit'=> "$start , $limit"
  933. )
  934. );
  935. break;
  936. case 'get_session_access_overview':
  937. $columns = array(
  938. 'logindate',
  939. 'username',
  940. 'lastname',
  941. 'firstname',
  942. 'clicks',
  943. 'ip',
  944. 'timeLoggedIn',
  945. 'session'
  946. );
  947. $sessionId = 0;
  948. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  949. $sessionId = intval($_GET['session_id']);
  950. $courseId = intval($_GET['course_id']);
  951. $studentId = intval($_GET['student_id']);
  952. $profile = intval($_GET['profile']);
  953. $date_from = intval($_GET['date_from']);
  954. $date_to = intval($_GET['date_to']);
  955. }
  956. $result = SessionManager::get_user_data_access_tracking_overview(
  957. $sessionId,
  958. $courseId,
  959. $studentId,
  960. $profile,
  961. $date_to,
  962. $date_from,
  963. array(
  964. 'where' => $whereCondition,
  965. 'order' => "$sidx $sord",
  966. 'limit'=> "$start , $limit"
  967. )
  968. );
  969. break;
  970. case 'get_timelines':
  971. $columns = array('headline', 'actions');
  972. if (!in_array($sidx, $columns)) {
  973. $sidx = 'headline';
  974. }
  975. $course_id = api_get_course_int_id();
  976. $result = Database::select(
  977. '*',
  978. $obj->table,
  979. array(
  980. 'where' => array(
  981. 'parent_id = ? AND c_id = ?' => array('0', $course_id)
  982. ),
  983. 'order'=>"$sidx $sord",
  984. 'LIMIT'=> "$start , $limit"
  985. )
  986. );
  987. $new_result = array();
  988. foreach ($result as $item) {
  989. if (!$item['status']) {
  990. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  991. }
  992. $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH).'timeline/view.php?id='.$item['id']);
  993. $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']);
  994. $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH).'timeline/?action=edit&id='.$item['id']);
  995. $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH).'timeline/?action=delete&id='.$item['id']);
  996. $new_result[] = $item;
  997. }
  998. $result = $new_result;
  999. break;
  1000. case 'get_gradebooks':
  1001. $columns = array('name', 'certificates','skills', 'actions', 'has_certificates');
  1002. if (!in_array($sidx, $columns)) {
  1003. $sidx = 'name';
  1004. }
  1005. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1006. $new_result = array();
  1007. foreach ($result as $item) {
  1008. if ($item['parent_id'] != 0) {
  1009. continue;
  1010. }
  1011. $skills = $obj->get_skills_by_gradebook($item['id']);
  1012. //Fixes bug when gradebook doesn't have names
  1013. if (empty($item['name'])) {
  1014. $item['name'] = $item['course_code'];
  1015. }
  1016. $item['name'] = Display::url($item['name'], api_get_path(WEB_CODE_PATH).'gradebook/index.php?id_session=0&cidReq='.$item['course_code']);
  1017. if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
  1018. $item['certificates'] = Display::return_icon('accept.png', get_lang('WithCertificate'), array(), ICON_SIZE_SMALL);
  1019. $item['has_certificates'] = '1';
  1020. } else {
  1021. $item['certificates'] = Display::return_icon('warning.png', get_lang('NoCertificate'), array(), ICON_SIZE_SMALL);
  1022. $item['has_certificates'] = '0';
  1023. }
  1024. if (!empty($skills)) {
  1025. foreach($skills as $skill) {
  1026. $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));
  1027. }
  1028. }
  1029. $new_result[] = $item;
  1030. }
  1031. $result = $new_result;
  1032. break;
  1033. case 'get_event_email_template':
  1034. $columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions');
  1035. if (!in_array($sidx, $columns)) {
  1036. $sidx = 'subject';
  1037. }
  1038. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1039. $new_result = array();
  1040. foreach ($result as $item) {
  1041. $language_info = api_get_language_info($item['language_id']);
  1042. $item['language_id'] = $language_info['english_name'];
  1043. $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']);
  1044. $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']);
  1045. $new_result[] = $item;
  1046. }
  1047. $result = $new_result;
  1048. break;
  1049. case 'get_careers':
  1050. $columns = array('name', 'description', 'actions');
  1051. if (!in_array($sidx, $columns)) {
  1052. $sidx = 'name';
  1053. }
  1054. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1055. $new_result = array();
  1056. foreach ($result as $item) {
  1057. if (!$item['status']) {
  1058. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1059. }
  1060. $new_result[] = $item;
  1061. }
  1062. $result = $new_result;
  1063. break;
  1064. case 'get_promotions':
  1065. $columns = array('name', 'career', 'description', 'actions');
  1066. if (!in_array($sidx, $columns)) {
  1067. $sidx = 'name';
  1068. }
  1069. $result = Database::select(
  1070. 'p.id,p.name, p.description, c.name as career, p.status',
  1071. "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ",
  1072. array('order' => "$sidx $sord", 'LIMIT'=> "$start , $limit")
  1073. );
  1074. $new_result = array();
  1075. foreach ($result as $item) {
  1076. if (!$item['status']) {
  1077. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1078. }
  1079. $new_result[] = $item;
  1080. }
  1081. $result = $new_result;
  1082. break;
  1083. case 'get_grade_models':
  1084. $columns = array('name', 'description', 'actions');
  1085. if (!in_array($sidx, $columns)) {
  1086. $sidx = 'name';
  1087. }
  1088. $result = Database::select('*', "$obj->table ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1089. $new_result = array();
  1090. foreach ($result as $item) {
  1091. $new_result[] = $item;
  1092. }
  1093. $result = $new_result;
  1094. break;
  1095. case 'get_usergroups':
  1096. $columns = array('id', 'name', 'users', 'courses','sessions','actions');
  1097. $result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
  1098. break;
  1099. case 'get_extra_fields':
  1100. $obj = new ExtraField($type);
  1101. $columns = array('field_display_text', 'field_variable', 'field_type', 'field_changeable', 'field_visible', 'field_filter', 'field_order');
  1102. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1103. $new_result = array();
  1104. if (!empty($result)) {
  1105. foreach ($result as $item) {
  1106. $item['field_type'] = $obj->get_field_type_by_id($item['field_type']);
  1107. $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
  1108. $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
  1109. $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
  1110. $new_result[] = $item;
  1111. }
  1112. $result = $new_result;
  1113. }
  1114. break;
  1115. case 'get_exercise_grade':
  1116. $objExercise = new Exercise();
  1117. $exercises = $objExercise->getExercisesByCouseSession($_GET['course_id'], $_GET['session_id']);
  1118. $cntExer = 4;
  1119. if (!empty($exercises)) {
  1120. $cntExer += count($exercises);
  1121. }
  1122. $columns = array();
  1123. //Get dynamic column names
  1124. $i = 1;
  1125. $column_names = array();
  1126. foreach (range(1, $cntExer) as $cnt) {
  1127. switch ($cnt) {
  1128. case 1:
  1129. $columns[] = 'session';
  1130. $column_names[] = get_lang('Section');
  1131. break;
  1132. case 2:
  1133. $columns[] = 'username';
  1134. $column_names[] = get_lang('Username');
  1135. break;
  1136. case 3:
  1137. $columns[] = 'name';
  1138. $column_names[] = get_lang('Name');
  1139. break;
  1140. case $cntExer:
  1141. $columns[] = 'finalScore';
  1142. $column_names[] = get_lang('FinalScore');
  1143. break;
  1144. default:
  1145. $title = "";
  1146. if (!empty($exercises[$cnt - 4]['title'])) {
  1147. $title = ucwords(strtolower(trim($exercises[$cnt - 4]['title'])));
  1148. }
  1149. $columns[] = 'exer' . $i;
  1150. $column_names[] = $title;
  1151. $i++;
  1152. break;
  1153. }
  1154. }
  1155. $quizIds = array();
  1156. if (!empty($exercises)) {
  1157. foreach($exercises as $exercise) {
  1158. $quizIds[] = $exercise['id'];
  1159. }
  1160. }
  1161. $course = api_get_course_info_by_id($_GET['course_id']);
  1162. $listUserSess = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id']);
  1163. $usersId = array_keys($listUserSess);
  1164. $users = UserManager::get_user_list_by_ids($usersId, null, "lastname, firstname", "$start , $limit");
  1165. $exeResults = $objExercise->getExerciseAndResult($_GET['course_id'], $_GET['session_id'], $quizIds);
  1166. $arrGrade = array();
  1167. foreach ($exeResults as $exeResult) {
  1168. $arrGrade[$exeResult['exe_user_id']][$exeResult['exe_exo_id']] = $exeResult['exe_result'];
  1169. }
  1170. $result = array();
  1171. $i = 0;
  1172. foreach ($users as $user) {
  1173. $sessionInfo = SessionManager::fetch($listUserSess[$user['user_id']]['id_session']);
  1174. $result[$i]['session'] = $sessionInfo['name'];
  1175. $result[$i]['username'] = $user['username'];
  1176. $result[$i]['name'] = $user['lastname'] . " " . $user['firstname'];
  1177. $j = 1;
  1178. $finalScore = 0;
  1179. foreach ($quizIds as $quizID) {
  1180. $grade = "";
  1181. if (!empty($arrGrade [$user['user_id']][$quizID]) || $arrGrade [$user['user_id']][$quizID] == 0) {
  1182. $finalScore += $grade = $arrGrade [$user['user_id']][$quizID];
  1183. }
  1184. $result[$i]['exer' . $j] = $grade;
  1185. $j++;
  1186. }
  1187. if ($finalScore > 20) {
  1188. $finalScore = 20;
  1189. }
  1190. $result[$i]['finalScore'] = number_format($finalScore, 2);
  1191. $i++;
  1192. }
  1193. break;
  1194. case 'get_extra_field_options':
  1195. $obj = new ExtraFieldOption($type);
  1196. $columns = array('option_display_text', 'option_value', 'option_order');
  1197. $result = Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id),'order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1198. break;
  1199. case 'get_usergroups_teacher':
  1200. $columns = array('name', 'users', 'actions');
  1201. $options = array('order'=>"name $sord", 'LIMIT'=> "$start , $limit");
  1202. $options['course_id'] = $course_id;
  1203. switch ($type) {
  1204. case 'not_registered':
  1205. $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
  1206. $result = $obj->get_usergroup_not_in_course($options);
  1207. break;
  1208. case 'registered':
  1209. $options['where'] = array(" usergroup.course_id = ? " => $course_id);
  1210. $result = $obj->get_usergroup_in_course($options);
  1211. break;
  1212. }
  1213. $new_result = array();
  1214. if (!empty($result)) {
  1215. foreach ($result as $group) {
  1216. $group['users'] = count($obj->get_users_by_usergroup($group['id']));
  1217. if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
  1218. $url = 'class.php?action=remove_class_from_course&id='.$group['id'];
  1219. $icon = Display::return_icon('delete.png', get_lang('Remove'));
  1220. } else {
  1221. $url = 'class.php?action=add_class_to_course&id='.$group['id'];
  1222. $icon = Display::return_icon('add.png', get_lang('Add'));
  1223. }
  1224. $group['actions'] = Display::url($icon, $url);
  1225. $new_result[] = $group;
  1226. }
  1227. $result = $new_result;
  1228. }
  1229. if (!in_array($sidx, $columns)) {
  1230. $sidx = 'name';
  1231. }
  1232. //Multidimensional sort
  1233. $result = msort($result, $sidx, $sord);
  1234. break;
  1235. default:
  1236. exit;
  1237. }
  1238. $allowed_actions = array(
  1239. 'get_careers',
  1240. 'get_promotions',
  1241. 'get_usergroups',
  1242. 'get_usergroups_teacher',
  1243. 'get_gradebooks',
  1244. 'get_sessions',
  1245. 'get_session_access_overview',
  1246. 'get_sessions_tracking',
  1247. 'get_session_lp_progress',
  1248. 'get_survey_overview',
  1249. 'get_session_progress',
  1250. 'get_exercise_progress',
  1251. 'get_exercise_results',
  1252. 'get_work_student_list_overview',
  1253. 'get_hotpotatoes_exercise_results',
  1254. 'get_work_teacher',
  1255. 'get_work_student',
  1256. 'get_work_user_list',
  1257. 'get_work_user_list_others',
  1258. 'get_work_user_list_all',
  1259. 'get_timelines',
  1260. 'get_grade_models',
  1261. 'get_event_email_template',
  1262. 'get_user_skill_ranking',
  1263. 'get_extra_fields',
  1264. 'get_extra_field_options',
  1265. //'get_course_exercise_medias',
  1266. 'get_user_course_report',
  1267. 'get_user_course_report_resumed',
  1268. 'get_exercise_grade',
  1269. 'get_course_announcements'
  1270. );
  1271. //5. Creating an obj to return a json
  1272. if (in_array($action, $allowed_actions)) {
  1273. $response = new stdClass();
  1274. $response->page = $page;
  1275. $response->total = $total_pages;
  1276. $response->records = $count;
  1277. if ($operation && $operation == 'excel') {
  1278. $j = 1;
  1279. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  1280. $array = array();
  1281. if (empty($column_names)) {
  1282. $column_names = $columns;
  1283. }
  1284. //Headers
  1285. foreach ($column_names as $col) {
  1286. $array[0][] = $col;
  1287. }
  1288. foreach ($result as $row) {
  1289. foreach ($columns as $col) {
  1290. $array[$j][] = strip_tags($row[$col]);
  1291. }
  1292. $j++;
  1293. }
  1294. switch ($exportFormat) {
  1295. case 'xls':
  1296. //TODO add date if exists
  1297. $file_name = (!empty($action)) ? $action : 'company_report';
  1298. require_once api_get_path(LIBRARY_PATH).'browser/Browser.php';
  1299. $browser = new Browser();
  1300. if ($browser->getPlatform() == Browser::PLATFORM_WINDOWS) {
  1301. Export::export_table_xls_html($array, $file_name, 'ISO-8859-15');
  1302. } else {
  1303. Export::export_table_xls_html($array, $file_name);
  1304. }
  1305. break;
  1306. case 'csv':
  1307. default:
  1308. //TODO add date if exists
  1309. $file_name = (!empty($action)) ? $action : 'company_report';
  1310. Export::export_table_csv($array, $file_name);
  1311. break;
  1312. }
  1313. exit;
  1314. }
  1315. $i = 0;
  1316. if (!empty($result)) {
  1317. foreach ($result as $row) {
  1318. // if results tab give not id, set id to $i otherwise id="null" for all <tr> of the jqgrid - ref #4235
  1319. if (!isset($row['id']) || isset($row['id']) && $row['id'] == '') {
  1320. $response->rows[$i]['id'] = $i;
  1321. } else {
  1322. $response->rows[$i]['id'] = $row['id'];
  1323. }
  1324. $array = array();
  1325. foreach ($columns as $col) {
  1326. $array[] = isset($row[$col]) ? Security::remove_XSS($row[$col]) : null;
  1327. }
  1328. $response->rows[$i]['cell'] = $array;
  1329. $i++;
  1330. }
  1331. }
  1332. header('Content-Type: application/json;charset=utf-8');
  1333. echo json_encode($response);
  1334. }
  1335. exit;