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. }
  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. $lessons = LearnpathList::get_course_lessons($course['code'], $sessionId);
  796. foreach ($lessons as $lesson_id => $lesson) {
  797. $columns[] = $lesson_id;
  798. }
  799. $columns[] = 'total';
  800. $result = SessionManager::get_session_lp_progress($sessionId, $courseId, $date_from, $date_to,
  801. array(
  802. 'where' => $whereCondition,
  803. 'order' => "$sidx $sord",
  804. 'limit'=> "$start , $limit"
  805. )
  806. );
  807. break;
  808. case 'get_survey_overview':
  809. $sessionId = 0;
  810. if (!empty($_GET['session_id']) &&
  811. !empty($_GET['course_id']) &&
  812. !empty($_GET['survey_id'])
  813. ) {
  814. $sessionId = intval($_GET['session_id']);
  815. $courseId = intval($_GET['course_id']);
  816. $surveyId = intval($_GET['survey_id']);
  817. $date_from = $_GET['date_from'];
  818. $date_to = $_GET['date_to'];
  819. //$course = api_get_course_info_by_id($courseId);
  820. }
  821. /**
  822. * Add lessons of course
  823. */
  824. $columns = array(
  825. 'username',
  826. 'firstname',
  827. 'lastname',
  828. );
  829. $questions = survey_manager::get_questions($surveyId, $courseId);
  830. foreach ($questions as $question_id => $question)
  831. {
  832. $columns[] = $question_id;
  833. }
  834. $result = SessionManager::get_survey_overview($sessionId, $courseId, $surveyId, $date_from, $date_to,
  835. array(
  836. 'where' => $whereCondition,
  837. 'order' => "$sidx $sord",
  838. 'limit'=> "$start , $limit"
  839. )
  840. );
  841. break;
  842. case 'get_session_progress':
  843. $columns = array(
  844. 'lastname',
  845. 'firstname',
  846. 'username',
  847. #'profile',
  848. 'total',
  849. 'courses',
  850. 'lessons',
  851. 'exercises',
  852. 'forums',
  853. 'homeworks',
  854. 'wikis',
  855. 'surveys',
  856. //exercises
  857. 'lessons_total' ,
  858. 'lessons_done' ,
  859. 'lessons_left' ,
  860. 'lessons_progress',
  861. //exercises
  862. 'exercises_total' ,
  863. 'exercises_done' ,
  864. 'exercises_left' ,
  865. 'exercises_progress' ,
  866. //forums
  867. 'forums_total' ,
  868. 'forums_done' ,
  869. 'forums_left' ,
  870. 'forums_progress' ,
  871. //assignments
  872. 'assignments_total' ,
  873. 'assignments_done' ,
  874. 'assignments_left' ,
  875. 'assignments_progress' ,
  876. //Wiki
  877. 'wiki_total',
  878. 'wiki_revisions',
  879. 'wiki_read',
  880. 'wiki_unread',
  881. 'wiki_progress',
  882. //surveys
  883. 'surveys_total' ,
  884. 'surveys_done' ,
  885. 'surveys_left' ,
  886. 'surveys_progress' ,
  887. );
  888. $sessionId = 0;
  889. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  890. $sessionId = intval($_GET['session_id']);
  891. $courseId = intval($_GET['course_id']);
  892. }
  893. $result = SessionManager::get_session_progress($sessionId, $courseId,
  894. array(
  895. 'where' => $whereCondition,
  896. 'order' => "$sidx $sord",
  897. 'limit'=> "$start , $limit"
  898. )
  899. );
  900. break;
  901. case 'get_session_access_overview':
  902. $columns = array(
  903. 'logindate',
  904. 'username',
  905. 'lastname',
  906. 'firstname',
  907. 'clicks',
  908. 'ip',
  909. 'timeLoggedIn',
  910. 'session'
  911. );
  912. $sessionId = 0;
  913. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  914. $sessionId = intval($_GET['session_id']);
  915. $courseId = intval($_GET['course_id']);
  916. $studentId = intval($_GET['student_id']);
  917. $profile = intval($_GET['profile']);
  918. $date_from = intval($_GET['date_from']);
  919. $date_to = intval($_GET['date_to']);
  920. }
  921. $result = SessionManager::get_user_data_access_tracking_overview(
  922. $sessionId,
  923. $courseId,
  924. $studentId,
  925. $profile,
  926. $date_to,
  927. $date_from,
  928. array(
  929. 'where' => $whereCondition,
  930. 'order' => "$sidx $sord",
  931. 'limit'=> "$start , $limit"
  932. )
  933. );
  934. break;
  935. case 'get_timelines':
  936. $columns = array('headline', 'actions');
  937. if (!in_array($sidx, $columns)) {
  938. $sidx = 'headline';
  939. }
  940. $course_id = api_get_course_int_id();
  941. $result = Database::select(
  942. '*',
  943. $obj->table,
  944. array(
  945. 'where' => array(
  946. 'parent_id = ? AND c_id = ?' => array('0', $course_id)
  947. ),
  948. 'order'=>"$sidx $sord",
  949. 'LIMIT'=> "$start , $limit"
  950. )
  951. );
  952. $new_result = array();
  953. foreach ($result as $item) {
  954. if (!$item['status']) {
  955. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  956. }
  957. $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH).'timeline/view.php?id='.$item['id']);
  958. $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']);
  959. $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH).'timeline/?action=edit&id='.$item['id']);
  960. $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH).'timeline/?action=delete&id='.$item['id']);
  961. $new_result[] = $item;
  962. }
  963. $result = $new_result;
  964. break;
  965. case 'get_gradebooks':
  966. $columns = array('name', 'certificates','skills', 'actions', 'has_certificates');
  967. if (!in_array($sidx, $columns)) {
  968. $sidx = 'name';
  969. }
  970. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  971. $new_result = array();
  972. foreach ($result as $item) {
  973. if ($item['parent_id'] != 0) {
  974. continue;
  975. }
  976. $skills = $obj->get_skills_by_gradebook($item['id']);
  977. //Fixes bug when gradebook doesn't have names
  978. if (empty($item['name'])) {
  979. $item['name'] = $item['course_code'];
  980. }
  981. $item['name'] = Display::url($item['name'], api_get_path(WEB_CODE_PATH).'gradebook/index.php?id_session=0&cidReq='.$item['course_code']);
  982. if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
  983. $item['certificates'] = Display::return_icon('accept.png', get_lang('WithCertificate'), array(), ICON_SIZE_SMALL);
  984. $item['has_certificates'] = '1';
  985. } else {
  986. $item['certificates'] = Display::return_icon('warning.png', get_lang('NoCertificate'), array(), ICON_SIZE_SMALL);
  987. $item['has_certificates'] = '0';
  988. }
  989. if (!empty($skills)) {
  990. foreach($skills as $skill) {
  991. $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));
  992. }
  993. }
  994. $new_result[] = $item;
  995. }
  996. $result = $new_result;
  997. break;
  998. case 'get_event_email_template':
  999. $columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions');
  1000. if (!in_array($sidx, $columns)) {
  1001. $sidx = 'subject';
  1002. }
  1003. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1004. $new_result = array();
  1005. foreach ($result as $item) {
  1006. $language_info = api_get_language_info($item['language_id']);
  1007. $item['language_id'] = $language_info['english_name'];
  1008. $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']);
  1009. $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']);
  1010. $new_result[] = $item;
  1011. }
  1012. $result = $new_result;
  1013. break;
  1014. case 'get_careers':
  1015. $columns = array('name', 'description', 'actions');
  1016. if (!in_array($sidx, $columns)) {
  1017. $sidx = 'name';
  1018. }
  1019. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1020. $new_result = array();
  1021. foreach ($result as $item) {
  1022. if (!$item['status']) {
  1023. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1024. }
  1025. $new_result[] = $item;
  1026. }
  1027. $result = $new_result;
  1028. break;
  1029. case 'get_promotions':
  1030. $columns = array('name', 'career', 'description', 'actions');
  1031. if (!in_array($sidx, $columns)) {
  1032. $sidx = 'name';
  1033. }
  1034. $result = Database::select(
  1035. 'p.id,p.name, p.description, c.name as career, p.status',
  1036. "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ",
  1037. array('order' => "$sidx $sord", 'LIMIT'=> "$start , $limit")
  1038. );
  1039. $new_result = array();
  1040. foreach ($result as $item) {
  1041. if (!$item['status']) {
  1042. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1043. }
  1044. $new_result[] = $item;
  1045. }
  1046. $result = $new_result;
  1047. break;
  1048. case 'get_grade_models':
  1049. $columns = array('name', 'description', 'actions');
  1050. if (!in_array($sidx, $columns)) {
  1051. $sidx = 'name';
  1052. }
  1053. $result = Database::select('*', "$obj->table ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1054. $new_result = array();
  1055. foreach ($result as $item) {
  1056. $new_result[] = $item;
  1057. }
  1058. $result = $new_result;
  1059. break;
  1060. case 'get_usergroups':
  1061. $columns = array('id', 'name', 'users', 'courses','sessions','actions');
  1062. $result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
  1063. break;
  1064. case 'get_extra_fields':
  1065. $obj = new ExtraField($type);
  1066. $columns = array('field_display_text', 'field_variable', 'field_type', 'field_changeable', 'field_visible', 'field_filter', 'field_order');
  1067. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1068. $new_result = array();
  1069. if (!empty($result)) {
  1070. foreach ($result as $item) {
  1071. $item['field_type'] = $obj->get_field_type_by_id($item['field_type']);
  1072. $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
  1073. $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
  1074. $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
  1075. $new_result[] = $item;
  1076. }
  1077. $result = $new_result;
  1078. }
  1079. break;
  1080. case 'get_exercise_grade':
  1081. $objExercise = new Exercise();
  1082. $exercises = $objExercise->getExercisesByCouseSession($_GET['course_id'], $_GET['session_id']);
  1083. $cntExer = 4;
  1084. if (!empty($exercises)) {
  1085. $cntExer += count($exercises);
  1086. }
  1087. $columns = array();
  1088. //Get dynamic column names
  1089. $i = 1;
  1090. $column_names = array();
  1091. foreach (range(1, $cntExer) as $cnt) {
  1092. switch ($cnt) {
  1093. case 1:
  1094. $columns[] = 'session';
  1095. $column_names[] = get_lang('Section');
  1096. break;
  1097. case 2:
  1098. $columns[] = 'username';
  1099. $column_names[] = get_lang('Username');
  1100. break;
  1101. case 3:
  1102. $columns[] = 'name';
  1103. $column_names[] = get_lang('Name');
  1104. break;
  1105. case $cntExer:
  1106. $columns[] = 'finalScore';
  1107. $column_names[] = get_lang('FinalScore');
  1108. break;
  1109. default:
  1110. $title = "";
  1111. if (!empty($exercises[$cnt - 4]['title'])) {
  1112. $title = ucwords(strtolower(trim($exercises[$cnt - 4]['title'])));
  1113. }
  1114. $columns[] = 'exer' . $i;
  1115. $column_names[] = $title;
  1116. $i++;
  1117. break;
  1118. }
  1119. }
  1120. $quizIds = array();
  1121. if (!empty($exercises)) {
  1122. foreach($exercises as $exercise) {
  1123. $quizIds[] = $exercise['id'];
  1124. }
  1125. }
  1126. $course = api_get_course_info_by_id($_GET['course_id']);
  1127. $listUserSess = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id']);
  1128. $usersId = array_keys($listUserSess);
  1129. $users = UserManager::get_user_list_by_ids($usersId, null, "lastname, firstname", "$start , $limit");
  1130. $exeResults = $objExercise->getExerciseAndResult($_GET['course_id'], $_GET['session_id'], $quizIds);
  1131. $arrGrade = array();
  1132. foreach ($exeResults as $exeResult) {
  1133. $arrGrade[$exeResult['exe_user_id']][$exeResult['exe_exo_id']] = $exeResult['exe_result'];
  1134. }
  1135. $result = array();
  1136. $i = 0;
  1137. foreach ($users as $user) {
  1138. $sessionInfo = SessionManager::fetch($listUserSess[$user['user_id']]['id_session']);
  1139. $result[$i]['session'] = $sessionInfo['name'];
  1140. $result[$i]['username'] = $user['username'];
  1141. $result[$i]['name'] = $user['lastname'] . " " . $user['firstname'];
  1142. $j = 1;
  1143. $finalScore = 0;
  1144. foreach ($quizIds as $quizID) {
  1145. $grade = "";
  1146. if (!empty($arrGrade [$user['user_id']][$quizID]) || $arrGrade [$user['user_id']][$quizID] == 0) {
  1147. $finalScore += $grade = $arrGrade [$user['user_id']][$quizID];
  1148. }
  1149. $result[$i]['exer' . $j] = $grade;
  1150. $j++;
  1151. }
  1152. if ($finalScore > 20) {
  1153. $finalScore = 20;
  1154. }
  1155. $result[$i]['finalScore'] = number_format($finalScore, 2);
  1156. $i++;
  1157. }
  1158. break;
  1159. case 'get_extra_field_options':
  1160. $obj = new ExtraFieldOption($type);
  1161. $columns = array('option_display_text', 'option_value', 'option_order');
  1162. $result = Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id),'order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1163. break;
  1164. case 'get_usergroups_teacher':
  1165. $columns = array('name', 'users', 'actions');
  1166. $options = array('order'=>"name $sord", 'LIMIT'=> "$start , $limit");
  1167. $options['course_id'] = $course_id;
  1168. switch ($type) {
  1169. case 'not_registered':
  1170. $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
  1171. $result = $obj->get_usergroup_not_in_course($options);
  1172. break;
  1173. case 'registered':
  1174. $options['where'] = array(" usergroup.course_id = ? " => $course_id);
  1175. $result = $obj->get_usergroup_in_course($options);
  1176. break;
  1177. }
  1178. $new_result = array();
  1179. if (!empty($result)) {
  1180. foreach ($result as $group) {
  1181. $group['users'] = count($obj->get_users_by_usergroup($group['id']));
  1182. if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
  1183. $url = 'class.php?action=remove_class_from_course&id='.$group['id'];
  1184. $icon = Display::return_icon('delete.png', get_lang('Remove'));
  1185. } else {
  1186. $url = 'class.php?action=add_class_to_course&id='.$group['id'];
  1187. $icon = Display::return_icon('add.png', get_lang('Add'));
  1188. }
  1189. $group['actions'] = Display::url($icon, $url);
  1190. $new_result[] = $group;
  1191. }
  1192. $result = $new_result;
  1193. }
  1194. if (!in_array($sidx, $columns)) {
  1195. $sidx = 'name';
  1196. }
  1197. //Multidimensional sort
  1198. $result = msort($result, $sidx, $sord);
  1199. break;
  1200. default:
  1201. exit;
  1202. }
  1203. $allowed_actions = array(
  1204. 'get_careers',
  1205. 'get_promotions',
  1206. 'get_usergroups',
  1207. 'get_usergroups_teacher',
  1208. 'get_gradebooks',
  1209. 'get_sessions',
  1210. 'get_session_access_overview',
  1211. 'get_sessions_tracking',
  1212. 'get_session_lp_progress',
  1213. 'get_survey_overview',
  1214. 'get_session_progress',
  1215. 'get_exercise_progress',
  1216. 'get_exercise_results',
  1217. 'get_work_student_list_overview',
  1218. 'get_hotpotatoes_exercise_results',
  1219. 'get_work_teacher',
  1220. 'get_work_student',
  1221. 'get_work_user_list',
  1222. 'get_work_user_list_others',
  1223. 'get_work_user_list_all',
  1224. 'get_timelines',
  1225. 'get_grade_models',
  1226. 'get_event_email_template',
  1227. 'get_user_skill_ranking',
  1228. 'get_extra_fields',
  1229. 'get_extra_field_options',
  1230. //'get_course_exercise_medias',
  1231. 'get_user_course_report',
  1232. 'get_user_course_report_resumed',
  1233. 'get_exercise_grade'
  1234. );
  1235. //5. Creating an obj to return a json
  1236. if (in_array($action, $allowed_actions)) {
  1237. $response = new stdClass();
  1238. $response->page = $page;
  1239. $response->total = $total_pages;
  1240. $response->records = $count;
  1241. if ($operation && $operation == 'excel') {
  1242. $j = 1;
  1243. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  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. require_once api_get_path(LIBRARY_PATH).'browser/Browser.php';
  1263. $browser = new Browser();
  1264. if ($browser->getPlatform() == Browser::PLATFORM_WINDOWS) {
  1265. Export::export_table_xls_html($array, $file_name, 'ISO-8859-15');
  1266. } else {
  1267. Export::export_table_xls_html($array, $file_name);
  1268. }
  1269. break;
  1270. case 'csv':
  1271. default:
  1272. //TODO add date if exists
  1273. $file_name = (!empty($action)) ? $action : 'company_report';
  1274. Export::export_table_csv($array, $file_name);
  1275. break;
  1276. }
  1277. exit;
  1278. }
  1279. $i = 0;
  1280. if (!empty($result)) {
  1281. foreach ($result as $row) {
  1282. // if results tab give not id, set id to $i otherwise id="null" for all <tr> of the jqgrid - ref #4235
  1283. if (!isset($row['id']) || isset($row['id']) && $row['id'] == '') {
  1284. $response->rows[$i]['id']= $i;
  1285. } else {
  1286. $response->rows[$i]['id']= $row['id'];
  1287. }
  1288. $array = array();
  1289. foreach ($columns as $col) {
  1290. $array[] = isset($row[$col]) ? $row[$col] : null;
  1291. }
  1292. $response->rows[$i]['cell']=$array;
  1293. $i++;
  1294. }
  1295. }
  1296. echo json_encode($response);
  1297. }
  1298. exit;