model.ajax.php 49 KB

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