model.ajax.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  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. } else if(api_is_student_boss()) {
  162. $users = UserManager::getUsersFollowedByStudentBoss(api_get_user_id());
  163. $userIdList = array_keys($users);
  164. }
  165. if ($action == 'get_user_course_report') {
  166. $count = CourseManager::get_count_user_list_from_course_code(false, null, $courseCodeList, $userIdList);
  167. } else {
  168. $count = CourseManager::get_count_user_list_from_course_code(
  169. true,
  170. array('ruc'),
  171. $courseCodeList,
  172. $userIdList
  173. );
  174. }
  175. break;
  176. case 'get_course_exercise_medias':
  177. $course_id = api_get_course_int_id();
  178. $count = Question::get_count_course_medias($course_id);
  179. break;
  180. case 'get_user_skill_ranking':
  181. $skill = new Skill();
  182. $count = $skill->get_user_list_skill_ranking_count();
  183. break;
  184. case 'get_work_teacher':
  185. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  186. $count = getWorkListTeacher(0, $limit, $sidx, $sord, $whereCondition, true);
  187. break;
  188. case 'get_work_student':
  189. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  190. $count = getWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true);
  191. break;
  192. case 'get_work_user_list_all':
  193. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  194. $work_id = $_REQUEST['work_id'];
  195. $count = get_count_work($work_id);
  196. break;
  197. case 'get_work_user_list_others':
  198. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  199. $work_id = $_REQUEST['work_id'];
  200. $count = get_count_work($work_id, api_get_user_id());
  201. break;
  202. case 'get_work_user_list':
  203. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  204. $work_id = $_REQUEST['work_id'];
  205. $courseInfo = api_get_course_info();
  206. $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
  207. if (empty($documents)) {
  208. $whereCondition .= " AND u.user_id = ".api_get_user_id();
  209. $count = get_work_user_list(
  210. 0,
  211. $limit,
  212. $sidx,
  213. $sord,
  214. $work_id,
  215. $whereCondition,
  216. null,
  217. true
  218. );
  219. } else {
  220. $count = get_work_user_list_from_documents(
  221. 0,
  222. $limit,
  223. $sidx,
  224. $sord,
  225. $work_id,
  226. api_get_user_id(),
  227. $whereCondition,
  228. true
  229. );
  230. }
  231. break;
  232. case 'get_work_student_list_overview':
  233. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  234. return 0;
  235. }
  236. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  237. $workId = isset($_GET['work_id']) ? $_GET['work_id'] : null;
  238. $count = getWorkUserListData(
  239. $workId,
  240. api_get_course_id(),
  241. api_get_session_id(),
  242. api_get_group_id(),
  243. 0,
  244. $limit,
  245. null,
  246. null,
  247. true
  248. );
  249. break;
  250. case 'get_exercise_results':
  251. $exercise_id = $_REQUEST['exerciseId'];
  252. if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) {
  253. $filter_user = intval($_GET['filter_by_user']);
  254. $whereCondition .= " AND te.exe_user_id = '$filter_user'";
  255. }
  256. $count = ExerciseLib::get_count_exam_results($exercise_id, $whereCondition);
  257. break;
  258. case 'get_hotpotatoes_exercise_results':
  259. $hotpot_path = $_REQUEST['path'];
  260. $count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
  261. break;
  262. case 'get_sessions_tracking':
  263. $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : null;
  264. if (api_is_drh()) {
  265. $count = SessionManager::get_sessions_followed_by_drh(
  266. api_get_user_id(),
  267. null,
  268. null,
  269. true,
  270. false,
  271. false,
  272. null,
  273. $keyword
  274. );
  275. } else {
  276. // Sessions for the coach
  277. $count = Tracking::get_sessions_coached_by_user(
  278. api_get_user_id(),
  279. null,
  280. null,
  281. true,
  282. $keyword
  283. );
  284. }
  285. break;
  286. case 'get_sessions':
  287. $courseId = isset($_GET['course_id']) && !empty($_GET['course_id']) ? intval($_GET['course_id']) : null;
  288. $whereCondition = str_replace('category_name', 'sc.name', $whereCondition);
  289. if (!empty($courseId)) {
  290. $whereCondition .= " AND c.id = $courseId";
  291. }
  292. $count = SessionManager::get_count_admin($whereCondition);
  293. break;
  294. case 'get_session_lp_progress':
  295. case 'get_session_progress':
  296. //@TODO replace this for a more efficient function (not retrieving the whole data)
  297. $course = api_get_course_info_by_id($_GET['course_id']);
  298. $users = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id'], $_GET['date_from'], $_GET['date_to']);
  299. $count = count($users);
  300. break;
  301. case 'get_exercise_progress':
  302. //@TODO replace this for a more efficient function (not retrieving the whole data)
  303. $records = Tracking::get_exercise_progress($_GET['session_id'], $_GET['course_id'], $_GET['exercise_id'], $_GET['date_from'], $_GET['date_to']);
  304. $count = count($records);
  305. break;
  306. case 'get_session_access_overview':
  307. //@TODO replace this for a more efficient function (not retrieving the whole data)
  308. $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);
  309. $count = count($records);
  310. break;
  311. case 'get_survey_overview':
  312. //@TODO replace this for a more efficient function (not retrieving the whole data)
  313. $records = SessionManager::get_survey_overview($_GET['session_id'], $_GET['course_id'], $_GET['survey_id'], $_GET['date_from'], $_GET['date_to'], $options);
  314. $count = count($records);
  315. break;
  316. case 'get_exercise_grade':
  317. //@TODO replace this for a more efficient function (not retrieving the whole data)
  318. $course = api_get_course_info_by_id($_GET['course_id']);
  319. $users = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id']);
  320. $count = count($users);
  321. break;
  322. case 'get_extra_fields':
  323. $type = $_REQUEST['type'];
  324. $obj = new ExtraField($type);
  325. $count = $obj->get_count();
  326. break;
  327. case 'get_extra_field_options':
  328. $type = $_REQUEST['type'];
  329. $field_id = $_REQUEST['field_id'];
  330. $obj = new ExtraFieldOption($type);
  331. $count = $obj->get_count_by_field_id($field_id);
  332. break;
  333. case 'get_timelines':
  334. require_once $libpath.'timeline.lib.php';
  335. $obj = new Timeline();
  336. $count = $obj->get_count();
  337. break;
  338. case 'get_gradebooks':
  339. require_once $libpath.'gradebook.lib.php';
  340. $obj = new Gradebook();
  341. $count = $obj->get_count();
  342. break;
  343. case 'get_event_email_template':
  344. $obj = new EventEmailTemplate();
  345. $count = $obj->get_count();
  346. break;
  347. case 'get_careers':
  348. $obj = new Career();
  349. $count = $obj->get_count();
  350. break;
  351. case 'get_promotions':
  352. $obj = new Promotion();
  353. $count = $obj->get_count();
  354. break;
  355. case 'get_grade_models':
  356. $obj = new GradeModel();
  357. $count = $obj->get_count();
  358. break;
  359. case 'get_usergroups':
  360. $obj = new UserGroup();
  361. $count = $obj->get_count();
  362. break;
  363. case 'get_usergroups_teacher':
  364. $obj = new UserGroup();
  365. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
  366. $course_id = api_get_course_int_id();
  367. if ($type == 'registered') {
  368. $count = $obj->get_usergroup_by_course_with_data_count($course_id);
  369. } else {
  370. $count = $obj->get_count();
  371. }
  372. break;
  373. default:
  374. exit;
  375. }
  376. //3. Calculating first, end, etc
  377. $total_pages = 0;
  378. if ($count > 0) {
  379. if (!empty($limit)) {
  380. $total_pages = ceil((float)$count/(float)$limit);
  381. }
  382. }
  383. if ($page > $total_pages) {
  384. $page = $total_pages;
  385. }
  386. $start = $limit * $page - $limit;
  387. if ($start < 0) {
  388. $start = 0;
  389. }
  390. //4. Deleting an element if the user wants to
  391. if (isset($_REQUEST['oper']) && $_REQUEST['oper'] == 'del') {
  392. $obj->delete($_REQUEST['id']);
  393. }
  394. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh();
  395. //5. Querying the DB for the elements
  396. $columns = array();
  397. switch ($action) {
  398. case 'get_course_exercise_medias':
  399. $columns = array('question');
  400. $result = Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $whereCondition);
  401. break;
  402. case 'get_user_course_report_resumed':
  403. $columns = array(
  404. 'extra_ruc',
  405. 'training_hours',
  406. 'count_users',
  407. 'count_users_registered',
  408. 'average_hours_per_user',
  409. 'count_certificates'
  410. );
  411. $column_names = array(
  412. get_lang('Company'),
  413. get_lang('TrainingHoursAccumulated'),
  414. get_lang('CountOfSubscriptions'),
  415. get_lang('CountOfUsers'),
  416. get_lang('AverageHoursPerStudent'),
  417. get_lang('CountCertificates')
  418. );
  419. $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
  420. if (!empty($extra_fields)) {
  421. foreach ($extra_fields as $extra) {
  422. if ($extra['1'] == 'ruc') {
  423. continue;
  424. }
  425. $columns[] = $extra['1'];
  426. $column_names[] = $extra['3'];
  427. }
  428. }
  429. if (!in_array($sidx, array('training_hours'))) {
  430. //$sidx = 'training_hours';
  431. }
  432. $result = CourseManager::get_user_list_from_course_code(
  433. null,
  434. null,
  435. "LIMIT $start, $limit",
  436. null, //" $sidx $sord",
  437. null,
  438. null,
  439. true,
  440. true,
  441. array('ruc'),
  442. $courseCodeList,
  443. $userIdList
  444. );
  445. $new_result = array();
  446. if (!empty($result)) {
  447. foreach ($result as $row) {
  448. $row['training_hours'] = api_time_to_hms($row['training_hours']);
  449. $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']);
  450. $new_result[] = $row;
  451. }
  452. $result = $new_result;
  453. }
  454. break;
  455. case 'get_user_course_report':
  456. $columns = array('course', 'user', 'time', 'certificate', 'progress_100', 'progress');
  457. $column_names = array(
  458. get_lang('Course'),
  459. get_lang('User'),
  460. get_lang('ManHours'),
  461. get_lang('CertificateGenerated'),
  462. get_lang('Approved'),
  463. get_lang('CourseAdvance')
  464. );
  465. $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
  466. if (!empty($extra_fields)) {
  467. foreach ($extra_fields as $extra) {
  468. $columns[] = $extra['1'];
  469. $column_names[] = $extra['3'];
  470. }
  471. }
  472. if (!in_array($sidx, array('title'))) {
  473. $sidx = 'title';
  474. }
  475. $result = CourseManager::get_user_list_from_course_code(
  476. null,
  477. null,
  478. "LIMIT $start, $limit",
  479. " $sidx $sord",
  480. null,
  481. null,
  482. true,
  483. false,
  484. null,
  485. $courseCodeList,
  486. $userIdList
  487. );
  488. break;
  489. case 'get_user_skill_ranking':
  490. $columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank');
  491. $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $whereCondition);
  492. $result = msort($result, 'skills_acquired', 'asc');
  493. $skills_in_course = array();
  494. if (!empty($result)) {
  495. foreach ($result as &$item) {
  496. $user_info = api_get_user_info($item['user_id']);
  497. $personal_course_list = UserManager::get_personal_session_course_list($item['user_id']);
  498. $count_skill_by_course = array();
  499. foreach ($personal_course_list as $course_item) {
  500. if (!isset($skills_in_course[$course_item['code']])) {
  501. $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']);
  502. $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
  503. } else {
  504. $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
  505. }
  506. }
  507. $item['photo'] = Display::img($user_info['avatar_small']);
  508. $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
  509. }
  510. }
  511. break;
  512. case 'get_work_teacher':
  513. $columns = array(
  514. 'type',
  515. 'title',
  516. 'sent_date',
  517. 'expires_on',
  518. 'amount',
  519. 'actions'
  520. );
  521. $result = getWorkListTeacher($start, $limit, $sidx, $sord, $whereCondition);
  522. break;
  523. case 'get_work_student':
  524. $columns = array('type', 'title', 'expires_on', 'others');
  525. if (ALLOW_USER_COMMENTS) {
  526. $columns = array(
  527. 'type',
  528. 'title',
  529. 'expires_on',
  530. 'feedback',
  531. 'last_upload',
  532. 'others'
  533. );
  534. }
  535. $result = getWorkListStudent($start, $limit, $sidx, $sord, $whereCondition);
  536. break;
  537. case 'get_work_user_list_all':
  538. if (isset($_GET['type']) && $_GET['type'] == 'simple') {
  539. $columns = array(
  540. 'type',
  541. 'firstname',
  542. 'lastname',
  543. 'title',
  544. 'qualification',
  545. 'sent_date',
  546. 'qualificator_id',
  547. 'actions'
  548. );
  549. } else {
  550. $columns = array(
  551. 'type',
  552. 'firstname',
  553. 'lastname',
  554. 'title',
  555. 'sent_date',
  556. 'actions'
  557. );
  558. if (ALLOW_USER_COMMENTS) {
  559. $columns = array(
  560. 'type',
  561. 'firstname',
  562. 'lastname',
  563. 'title',
  564. 'qualification',
  565. 'sent_date',
  566. 'actions'
  567. );
  568. }
  569. }
  570. $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
  571. break;
  572. case 'get_work_user_list_others':
  573. if (isset($_GET['type']) && $_GET['type'] == 'simple') {
  574. $columns = array(
  575. 'type', 'firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'
  576. );
  577. } else {
  578. $columns = array('type', 'firstname', 'lastname', 'title', 'sent_date', 'actions');
  579. }
  580. $whereCondition .= " AND u.user_id <> ".api_get_user_id();
  581. $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
  582. break;
  583. case 'get_work_user_list':
  584. if (isset($_GET['type']) && $_GET['type'] == 'simple') {
  585. $columns = array(
  586. 'type', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'
  587. );
  588. } else {
  589. $columns = array('type', 'title', 'sent_date', 'actions');
  590. if (ALLOW_USER_COMMENTS) {
  591. $columns = array('type', 'title', 'qualification', 'sent_date', 'actions');
  592. }
  593. }
  594. $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
  595. if (empty($documents)) {
  596. $whereCondition .= " AND u.user_id = ".api_get_user_id();
  597. $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
  598. } else {
  599. $result = get_work_user_list_from_documents(
  600. $start,
  601. $limit,
  602. $sidx,
  603. $sord,
  604. $work_id,
  605. api_get_user_id(),
  606. $whereCondition
  607. );
  608. }
  609. break;
  610. case 'get_exercise_results':
  611. $course = api_get_course_info();
  612. // Used inside ExerciseLib::get_exam_results_data()
  613. $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
  614. if ($is_allowedToEdit || api_is_student_boss()) {
  615. $columns = array(
  616. 'firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'user_ip', 'status', 'lp', 'actions'
  617. );
  618. $officialCodeInList = api_get_configuration_value('show_official_code_exercise_result_list');
  619. if ($officialCodeInList == true) {
  620. $columns = array_merge(array('official_code'), $columns);
  621. }
  622. }
  623. $result = ExerciseLib::get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $whereCondition);
  624. break;
  625. case 'get_hotpotatoes_exercise_results':
  626. $course = api_get_course_info();
  627. $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
  628. if (api_is_allowed_to_edit()) {
  629. $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
  630. } else {
  631. $columns = array('exe_date', 'score', 'actions');
  632. }
  633. $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $whereCondition);
  634. break;
  635. case 'get_work_student_list_overview':
  636. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  637. return array();
  638. }
  639. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  640. $columns = array(
  641. 'student', 'works'
  642. );
  643. $result = getWorkUserListData(
  644. $workId,
  645. api_get_course_id(),
  646. api_get_session_id(),
  647. api_get_group_id(),
  648. $start,
  649. $limit,
  650. $sidx,
  651. $sord
  652. );
  653. break;
  654. case 'get_hotpotatoes_exercise_results':
  655. $course = api_get_course_info();
  656. $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
  657. if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
  658. $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
  659. } else {
  660. $columns = array('exe_date', 'score', 'actions');
  661. }
  662. $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $whereCondition);
  663. break;
  664. case 'get_sessions_tracking':
  665. if (api_is_drh()) {
  666. $sessions = SessionManager::get_sessions_followed_by_drh(
  667. api_get_user_id(),
  668. $start,
  669. $limit,
  670. false,
  671. false,
  672. false,
  673. null,
  674. $keyword
  675. );
  676. } else {
  677. // Sessions for the coach
  678. $sessions = Tracking::get_sessions_coached_by_user(
  679. api_get_user_id(),
  680. $start,
  681. $limit,
  682. false,
  683. $keyword
  684. );
  685. }
  686. $columns = array(
  687. 'name',
  688. 'date',
  689. 'course_per_session',
  690. 'student_per_session',
  691. 'details'
  692. );
  693. $result = array();
  694. if (!empty($sessions)) {
  695. foreach ($sessions as $session) {
  696. if (api_drh_can_access_all_session_content()) {
  697. $count_courses_in_session = count(SessionManager::get_course_list_by_session_id($session['id']));
  698. } else {
  699. $count_courses_in_session = count(Tracking::get_courses_followed_by_coach($user_id, $session['id']));
  700. }
  701. $count_users_in_session = count(SessionManager::get_users_by_session($session['id'], 0));
  702. $session_date = array();
  703. if (!empty($session['date_start']) && $session['date_start'] != '0000-00-00') {
  704. $session_date[] = get_lang('From').' '.api_format_date($session['date_start'], DATE_FORMAT_SHORT);
  705. }
  706. if (!empty($session['date_end']) && $session['date_end'] != '0000-00-00') {
  707. $session_date[] = get_lang('Until').' '.api_format_date($session['date_end'], DATE_FORMAT_SHORT);
  708. }
  709. if (empty($session_date)) {
  710. $session_date_string = '-';
  711. } else {
  712. $session_date_string = implode(' ', $session_date);
  713. }
  714. $sessionUrl = api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id'];
  715. $result[] = array(
  716. 'name' => $session['name'],
  717. 'date' => $session_date_string,
  718. 'course_per_session' => $count_courses_in_session,
  719. 'student_per_session' => $count_users_in_session,
  720. 'details' => Display::url(Display::return_icon('2rightarrow.gif'), $sessionUrl)
  721. );
  722. }
  723. }
  724. break;
  725. case 'get_sessions':
  726. $columns = array(
  727. 'name',
  728. 'nbr_courses',
  729. 'nbr_users',
  730. 'category_name',
  731. 'date_start',
  732. 'date_end',
  733. 'coach_name',
  734. 'session_active',
  735. 'visibility'
  736. );
  737. // Rename Category_name
  738. $whereCondition = str_replace('category_name', 'sc.name', $whereCondition);
  739. $result = SessionManager::get_sessions_admin(
  740. array(
  741. 'where' => $whereCondition,
  742. 'order' => "$sidx $sord",
  743. 'limit'=> "$start , $limit"
  744. )
  745. );
  746. break;
  747. case 'get_exercise_progress':
  748. $sessionId = intval($_GET['session_id']);
  749. $courseId = intval($_GET['course_id']);
  750. $exerciseId = intval($_GET['exercise_id']);
  751. $date_from = $_GET['date_from'];
  752. $date_to = $_GET['date_to'];
  753. $columns = array(
  754. 'session',
  755. 'exercise_id',
  756. 'quiz_title',
  757. 'username',
  758. 'lastname',
  759. 'firstname',
  760. 'time',
  761. 'question_id',
  762. 'question',
  763. 'description',
  764. 'answer',
  765. 'correct',
  766. );
  767. $result = Tracking::get_exercise_progress(
  768. $sessionId,
  769. $courseId,
  770. $exerciseId,
  771. $date_from,
  772. $date_to,
  773. array(
  774. 'where' => $whereCondition,
  775. 'order' => "$sidx $sord",
  776. 'limit'=> "$start , $limit"
  777. )
  778. );
  779. break;
  780. case 'get_session_lp_progress':
  781. $sessionId = 0;
  782. if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) {
  783. $sessionId = intval($_GET['session_id']);
  784. $courseId = intval($_GET['course_id']);
  785. $course = api_get_course_info_by_id($courseId);
  786. }
  787. /**
  788. * Add lessons of course
  789. *
  790. */
  791. $columns = array(
  792. 'username',
  793. 'firstname',
  794. 'lastname',
  795. );
  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. $array = array();
  1245. if (empty($column_names)) {
  1246. $column_names = $columns;
  1247. }
  1248. //Headers
  1249. foreach ($column_names as $col) {
  1250. $array[0][] = $col;
  1251. }
  1252. foreach ($result as $row) {
  1253. foreach ($columns as $col) {
  1254. $array[$j][] = strip_tags($row[$col]);
  1255. }
  1256. $j++;
  1257. }
  1258. switch ($exportFormat) {
  1259. case 'xls':
  1260. //TODO add date if exists
  1261. $file_name = (!empty($action)) ? $action : 'company_report';
  1262. $browser = new Browser();
  1263. if ($browser->getPlatform() == Browser::PLATFORM_WINDOWS) {
  1264. Export::export_table_xls_html($array, $file_name, 'ISO-8859-15');
  1265. } else {
  1266. Export::export_table_xls_html($array, $file_name);
  1267. }
  1268. break;
  1269. case 'csv':
  1270. default:
  1271. //TODO add date if exists
  1272. $file_name = (!empty($action)) ? $action : 'company_report';
  1273. Export::export_table_csv($array, $file_name);
  1274. break;
  1275. }
  1276. exit;
  1277. }
  1278. $i = 0;
  1279. if (!empty($result)) {
  1280. foreach ($result as $row) {
  1281. // if results tab give not id, set id to $i otherwise id="null" for all <tr> of the jqgrid - ref #4235
  1282. if (!isset($row['id']) || isset($row['id']) && $row['id'] == '') {
  1283. $response->rows[$i]['id']= $i;
  1284. } else {
  1285. $response->rows[$i]['id']= $row['id'];
  1286. }
  1287. $array = array();
  1288. foreach ($columns as $col) {
  1289. $array[] = isset($row[$col]) ? $row[$col] : null;
  1290. }
  1291. $response->rows[$i]['cell']=$array;
  1292. $i++;
  1293. }
  1294. }
  1295. echo json_encode($response);
  1296. }
  1297. exit;