model.ajax.php 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
  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. require_once __DIR__.'/../global.inc.php';
  5. $libpath = api_get_path(LIBRARY_PATH);
  6. // 1. Setting variables needed by jqgrid
  7. $action = $_GET['a'];
  8. $page = intval($_REQUEST['page']); //page
  9. $limit = intval($_REQUEST['rows']); //quantity of rows
  10. $sidx = $_REQUEST['sidx']; //index (field) to filter
  11. $sord = $_REQUEST['sord']; //asc or desc
  12. if (strpos(strtolower($sidx), 'asc') !== false) {
  13. $sidx = str_replace(array('asc', ','), '', $sidx);
  14. $sord = 'asc';
  15. }
  16. if (strpos(strtolower($sidx), 'desc') !== false) {
  17. $sidx = str_replace(array('desc', ','), '', $sidx);
  18. $sord = 'desc';
  19. }
  20. if (!in_array($sord, array('asc','desc'))) {
  21. $sord = 'desc';
  22. }
  23. // Actions allowed to other roles.
  24. if (!in_array(
  25. $action,
  26. array(
  27. 'get_exercise_results',
  28. 'get_work_student_list_overview',
  29. 'get_hotpotatoes_exercise_results',
  30. 'get_work_teacher',
  31. 'get_work_student',
  32. 'get_work_user_list',
  33. 'get_work_user_list_others',
  34. 'get_work_user_list_all',
  35. 'get_timelines',
  36. 'get_user_skill_ranking',
  37. 'get_usergroups_teacher',
  38. 'get_user_course_report_resumed',
  39. 'get_user_course_report',
  40. 'get_sessions_tracking',
  41. 'get_sessions',
  42. 'get_course_announcements'
  43. )
  44. ) && !isset($_REQUEST['from_course_session'])) {
  45. api_protect_admin_script(true);
  46. } elseif (isset($_REQUEST['from_course_session']) &&
  47. $_REQUEST['from_course_session'] == 1
  48. ) {
  49. api_protect_teacher_script(true);
  50. }
  51. // Search features
  52. //@todo move this in the display_class or somewhere else
  53. function getWhereClause($col, $oper, $val)
  54. {
  55. $ops = array(
  56. 'eq' => '=', //equal
  57. 'ne' => '<>', //not equal
  58. 'lt' => '<', //less than
  59. 'le' => '<=', //less than or equal
  60. 'gt' => '>', //greater than
  61. 'ge' => '>=', //greater than or equal
  62. 'bw' => 'LIKE', //begins with
  63. 'bn' => 'NOT LIKE', //doesn't begin with
  64. 'in' => 'LIKE', //is in
  65. 'ni' => 'NOT LIKE', //is not in
  66. 'ew' => 'LIKE', //ends with
  67. 'en' => 'NOT LIKE', //doesn't end with
  68. 'cn' => 'LIKE', //contains
  69. 'nc' => 'NOT LIKE' //doesn't contain
  70. );
  71. if (empty($col)) {
  72. return '';
  73. }
  74. if ($oper == 'bw' || $oper == 'bn') {
  75. $val .= '%';
  76. }
  77. if ($oper == 'ew' || $oper == 'en') {
  78. $val = '%'.$val;
  79. }
  80. if ($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') {
  81. $val = '%'.$val.'%';
  82. }
  83. $val = Database::escape_string($val);
  84. return " $col {$ops[$oper]} '$val' ";
  85. }
  86. // If there is no search request sent by jqgrid, $where should be empty
  87. $whereCondition = '';
  88. $operation = isset($_REQUEST['oper']) ? $_REQUEST['oper'] : false;
  89. $exportFormat = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : 'csv';
  90. $searchField = isset($_REQUEST['searchField']) ? $_REQUEST['searchField'] : false;
  91. $searchOperator = isset($_REQUEST['searchOper']) ? $_REQUEST['searchOper'] : false;
  92. $searchString = isset($_REQUEST['searchString']) ? $_REQUEST['searchString'] : false;
  93. $search = isset($_REQUEST['_search']) ? $_REQUEST['_search'] : false;
  94. $forceSearch = isset($_REQUEST['_force_search']) ? $_REQUEST['_force_search'] : false;
  95. $extra_fields = array();
  96. if (!empty($searchString)) {
  97. $search = 'true';
  98. }
  99. if (($search || $forceSearch) && ($search !== 'false')) {
  100. $whereCondition = ' 1 = 1 ';
  101. $whereConditionInForm = getWhereClause($searchField, $searchOperator, $searchString);
  102. if (!empty($whereConditionInForm)) {
  103. $whereCondition .= ' AND '.$whereConditionInForm;
  104. }
  105. $filters = isset($_REQUEST['filters']) && !is_array($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;
  106. if (!empty($filters)) {
  107. if (in_array($action, ['get_questions', 'get_sessions'])) {
  108. switch ($action) {
  109. case 'get_questions':
  110. $type = 'question';
  111. break;
  112. case 'get_sessions':
  113. $type = 'session';
  114. break;
  115. }
  116. if (!empty($type)) {
  117. // Extra field.
  118. $extraField = new ExtraField($type);
  119. $result = $extraField->getExtraFieldRules($filters, 'extra_');
  120. $extra_fields = $result['extra_fields'];
  121. $condition_array = $result['condition_array'];
  122. $extraCondition = '';
  123. if (!empty($condition_array)) {
  124. $extraCondition = ' AND ( ';
  125. $extraCondition .= implode($filters->groupOp, $condition_array);
  126. $extraCondition .= ' ) ';
  127. }
  128. $whereCondition .= $extraCondition;
  129. // Question field
  130. $resultQuestion = $extraField->getExtraFieldRules($filters, 'question_');
  131. $questionFields = $resultQuestion['extra_fields'];
  132. $condition_array = $resultQuestion['condition_array'];
  133. if (!empty($condition_array)) {
  134. $extraQuestionCondition = ' AND ( ';
  135. $extraQuestionCondition .= implode($filters->groupOp, $condition_array);
  136. $extraQuestionCondition .= ' ) ';
  137. // Remove conditions already added
  138. $extraQuestionCondition = str_replace($extraCondition, '', $extraQuestionCondition);
  139. }
  140. $whereCondition .= $extraQuestionCondition;
  141. }
  142. } elseif (!empty($filters->rules)) {
  143. $whereCondition .= ' AND ( ';
  144. $counter = 0;
  145. foreach ($filters->rules as $key => $rule) {
  146. $whereCondition .= getWhereClause($rule->field, $rule->op, $rule->data);
  147. if ($counter < count($filters->rules) -1) {
  148. $whereCondition .= $filters->groupOp;
  149. }
  150. $counter++;
  151. }
  152. $whereCondition .= ' ) ';
  153. }
  154. }
  155. }
  156. // get index row - i.e. user click to sort $sord = $_GET['sord'];
  157. // get the direction
  158. if (!$sidx) {
  159. $sidx = 1;
  160. }
  161. //2. Selecting the count FIRST
  162. //@todo rework this
  163. switch ($action) {
  164. case 'get_group_reporting':
  165. $course_id = isset($_REQUEST['course_id']) ? $_REQUEST['course_id'] : null;
  166. $group_id = isset($_REQUEST['gidReq']) ? $_REQUEST['gidReq'] : null;
  167. $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : null;
  168. $count = Tracking::get_group_reporting($course_id, $sessionId, $group_id, 'count');
  169. break;
  170. case 'get_user_course_report':
  171. case 'get_user_course_report_resumed':
  172. $userId = api_get_user_id();
  173. $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  174. $courseCodeList = array();
  175. $userIdList = array();
  176. $sessionIdList = [];
  177. $searchByGroups = false;
  178. if (api_is_drh()) {
  179. if (api_drh_can_access_all_session_content()) {
  180. $userList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  181. 'drh_all',
  182. api_get_user_id()
  183. );
  184. if (!empty($userList)) {
  185. foreach ($userList as $user) {
  186. $userIdList[] = $user['user_id'];
  187. }
  188. }
  189. $courseList = SessionManager::getAllCoursesFollowedByUser(
  190. api_get_user_id(),
  191. null
  192. );
  193. if (!empty($courseList)) {
  194. foreach ($courseList as $course) {
  195. $courseCodeList[] = $course['code'];
  196. }
  197. }
  198. } else {
  199. $userList = UserManager::get_users_followed_by_drh(api_get_user_id());
  200. if (!empty($userList)) {
  201. $userIdList = array_keys($userList);
  202. }
  203. $courseList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  204. if (!empty($courseList)) {
  205. $courseCodeList = array_keys($courseList);
  206. }
  207. }
  208. if (empty($userIdList) || empty($courseCodeList)) {
  209. exit;
  210. }
  211. } elseif (api_is_student_boss()) {
  212. $supervisorStudents = UserManager::getUsersFollowedByUser(
  213. api_get_user_id(),
  214. api_is_student_boss() ? null : STUDENT,
  215. false,
  216. false,
  217. false,
  218. 0,
  219. null,
  220. 0,
  221. 'ASC',
  222. 1,
  223. null,
  224. api_is_student_boss() ? STUDENT_BOSS : COURSEMANAGER,
  225. null
  226. );
  227. $supervisorStudents = array_column($supervisorStudents, 'user_id');
  228. //get students with course or session
  229. $userIdList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  230. 'admin',
  231. null,
  232. false,
  233. null,
  234. null,
  235. 1,
  236. 'asc',
  237. null,
  238. null,
  239. null,
  240. array(),
  241. $supervisorStudents,
  242. 5
  243. );
  244. $userIdList = array_column($userIdList, 'user_id');
  245. //get students session courses
  246. if ($sessionId == -1) {
  247. $sessionList = SessionManager::get_sessions_list();
  248. $sessionIdList = array_column($sessionList, 'id');
  249. $courseCodeList = array();
  250. foreach ($sessionList as $session) {
  251. $courses = SessionManager::get_course_list_by_session_id($session['id']);
  252. $courseCodeList = array_merge($courseCodeList, array_column($courses, 'code'));
  253. }
  254. }
  255. $searchByGroups = true;
  256. } elseif (api_is_platform_admin()) {
  257. //get students with course or session
  258. $userIdList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  259. 'admin',
  260. null,
  261. false,
  262. null,
  263. null,
  264. 1,
  265. 'asc',
  266. null,
  267. null,
  268. null,
  269. array(),
  270. array(),
  271. 5
  272. );
  273. $userIdList = array_column($userIdList, 'user_id');
  274. //get students session courses
  275. if ($sessionId == -1) {
  276. $sessionList = SessionManager::get_sessions_list();
  277. $sessionIdList = array_column($sessionList, 'id');
  278. $courseCodeList = array();
  279. foreach ($sessionList as $session) {
  280. $courses = SessionManager::get_course_list_by_session_id($session['id']);
  281. $courseCodeList = array_merge($courseCodeList, array_column($courses, 'code'));
  282. }
  283. }
  284. $searchByGroups = true;
  285. }
  286. if ($searchByGroups) {
  287. $userGroup = new UserGroup();
  288. $userIdList = array_merge(
  289. $userIdList,
  290. $userGroup->getGroupUsersByUser(api_get_user_id())
  291. );
  292. }
  293. if (is_array($userIdList)) {
  294. $userIdList = array_unique($userIdList);
  295. }
  296. if (api_is_student_boss()) {
  297. $userCourses = [];
  298. foreach ($userIdList as $userId) {
  299. $userCourses = array_merge(
  300. $userCourses,
  301. CourseManager::get_courses_list_by_user_id($userId, true)
  302. );
  303. $userSessions = SessionManager::getSessionsFollowedByUser($userId);
  304. $sessionIdList = array_merge(
  305. $sessionIdList,
  306. array_column($userSessions, 'id')
  307. );
  308. }
  309. $courseCodeList = array_column($userCourses, 'code');
  310. }
  311. if (!empty($courseCodeList)) {
  312. $courseCodeList = array_unique($courseCodeList);
  313. }
  314. if (!empty($sessionIdList)) {
  315. $sessionIdList = array_unique($sessionIdList);
  316. }
  317. if (api_is_student_boss() && empty($userIdList)) {
  318. $count = 0;
  319. break;
  320. }
  321. if ($action == 'get_user_course_report') {
  322. $count = CourseManager::get_count_user_list_from_course_code(
  323. false,
  324. null,
  325. $courseCodeList,
  326. $userIdList,
  327. $sessionIdList
  328. );
  329. } else {
  330. $count = CourseManager::get_count_user_list_from_course_code(
  331. true,
  332. array('ruc'),
  333. $courseCodeList,
  334. $userIdList,
  335. $sessionIdList
  336. );
  337. }
  338. break;
  339. case 'get_course_exercise_medias':
  340. $course_id = api_get_course_int_id();
  341. $count = Question::get_count_course_medias($course_id);
  342. break;
  343. case 'get_user_skill_ranking':
  344. $skill = new Skill();
  345. $count = $skill->get_user_list_skill_ranking_count();
  346. break;
  347. case 'get_course_announcements':
  348. $count = AnnouncementManager::getAnnouncements(null, null, true);
  349. break;
  350. case 'get_work_teacher':
  351. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  352. $count = getWorkListTeacher(0, $limit, $sidx, $sord, $whereCondition, true);
  353. break;
  354. case 'get_work_student':
  355. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  356. $count = getWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true);
  357. break;
  358. case 'get_work_user_list_all':
  359. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  360. $work_id = $_REQUEST['work_id'];
  361. $count = get_count_work($work_id);
  362. break;
  363. case 'get_work_user_list_others':
  364. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  365. $work_id = $_REQUEST['work_id'];
  366. $count = get_count_work($work_id, api_get_user_id());
  367. break;
  368. case 'get_work_user_list':
  369. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  370. $work_id = $_REQUEST['work_id'];
  371. $courseInfo = api_get_course_info();
  372. $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
  373. if (empty($documents)) {
  374. $whereCondition .= " AND u.user_id = ".api_get_user_id();
  375. $count = get_work_user_list(
  376. 0,
  377. $limit,
  378. $sidx,
  379. $sord,
  380. $work_id,
  381. $whereCondition,
  382. null,
  383. true
  384. );
  385. } else {
  386. $count = get_work_user_list_from_documents(
  387. 0,
  388. $limit,
  389. $sidx,
  390. $sord,
  391. $work_id,
  392. api_get_user_id(),
  393. $whereCondition,
  394. true
  395. );
  396. }
  397. break;
  398. case 'get_work_student_list_overview':
  399. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  400. return 0;
  401. }
  402. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  403. $workId = isset($_GET['work_id']) ? $_GET['work_id'] : null;
  404. $count = getWorkUserListData(
  405. $workId,
  406. api_get_course_id(),
  407. api_get_session_id(),
  408. api_get_group_id(),
  409. 0,
  410. $limit,
  411. null,
  412. null,
  413. true
  414. );
  415. break;
  416. case 'get_exercise_results':
  417. $exercise_id = $_REQUEST['exerciseId'];
  418. if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) {
  419. $filter_user = (int) $_GET['filter_by_user'];
  420. if (empty($whereCondition)) {
  421. $whereCondition .= " te.exe_user_id = '$filter_user'";
  422. } else {
  423. $whereCondition .= " AND te.exe_user_id = '$filter_user'";
  424. }
  425. }
  426. if (!empty($whereCondition)) {
  427. $whereCondition = " AND $whereCondition";
  428. }
  429. $count = ExerciseLib::get_count_exam_results($exercise_id, $whereCondition);
  430. break;
  431. case 'get_hotpotatoes_exercise_results':
  432. $hotpot_path = $_REQUEST['path'];
  433. $count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
  434. break;
  435. case 'get_sessions_tracking':
  436. $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
  437. $description = '';
  438. $setting = api_get_setting('show_session_description');
  439. if ($setting === 'true') {
  440. $description = $keyword;
  441. }
  442. if (api_is_drh() || api_is_session_admin()) {
  443. $count = SessionManager::get_sessions_followed_by_drh(
  444. api_get_user_id(),
  445. null,
  446. null,
  447. true,
  448. false,
  449. false,
  450. null,
  451. $keyword,
  452. $description
  453. );
  454. } else {
  455. // Sessions for the coach
  456. $count = Tracking::get_sessions_coached_by_user(
  457. api_get_user_id(),
  458. null,
  459. null,
  460. true,
  461. $keyword,
  462. $description
  463. );
  464. }
  465. break;
  466. case 'get_sessions':
  467. $list_type = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : 'simple';
  468. if ($list_type === 'simple') {
  469. $count = SessionManager::get_sessions_admin(
  470. array('where' => $whereCondition, 'extra' => $extra_fields),
  471. true
  472. );
  473. } else {
  474. $count = SessionManager::get_count_admin_complete(
  475. array('where' => $whereCondition, 'extra' => $extra_fields)
  476. );
  477. }
  478. break;
  479. case 'get_session_lp_progress':
  480. case 'get_session_progress':
  481. //@TODO replace this for a more efficient function (not retrieving the whole data)
  482. $course = api_get_course_info_by_id($_GET['course_id']);
  483. $users = CourseManager::get_student_list_from_course_code(
  484. $course['code'],
  485. true,
  486. $_GET['session_id'],
  487. $_GET['date_from'],
  488. $_GET['date_to']
  489. );
  490. $count = count($users);
  491. break;
  492. case 'get_exercise_progress':
  493. //@TODO replace this for a more efficient function (not retrieving the whole data)
  494. $records = Tracking::get_exercise_progress(
  495. $_GET['session_id'],
  496. $_GET['course_id'],
  497. $_GET['exercise_id'],
  498. $_GET['date_from'],
  499. $_GET['date_to']
  500. );
  501. $count = count($records);
  502. break;
  503. case 'get_session_access_overview':
  504. //@TODO replace this for a more efficient function (not retrieving the whole data)
  505. $records = SessionManager::get_user_data_access_tracking_overview(
  506. $_GET['session_id'],
  507. $_GET['course_id'],
  508. $_GET['student_id'],
  509. $_GET['profile'],
  510. $_GET['date_from'],
  511. $_GET['date_to'],
  512. $options
  513. );
  514. $count = count($records);
  515. break;
  516. case 'get_survey_overview':
  517. //@TODO replace this for a more efficient function (not retrieving the whole data)
  518. $records = SessionManager::get_survey_overview(
  519. $_GET['session_id'],
  520. $_GET['course_id'],
  521. $_GET['survey_id'],
  522. $_GET['date_from'],
  523. $_GET['date_to'],
  524. $options
  525. );
  526. $count = count($records);
  527. break;
  528. case 'get_exercise_grade':
  529. //@TODO replace this for a more efficient function (not retrieving the whole data)
  530. $course = api_get_course_info_by_id($_GET['course_id']);
  531. $users = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id']);
  532. $count = count($users);
  533. break;
  534. case 'get_extra_fields':
  535. $type = $_REQUEST['type'];
  536. $obj = new ExtraField($type);
  537. $count = $obj->get_count();
  538. break;
  539. case 'get_extra_field_options':
  540. $type = $_REQUEST['type'];
  541. $field_id = $_REQUEST['field_id'];
  542. $obj = new ExtraFieldOption($type);
  543. $count = $obj->get_count_by_field_id($field_id);
  544. break;
  545. case 'get_timelines':
  546. require_once $libpath.'timeline.lib.php';
  547. $obj = new Timeline();
  548. $count = $obj->get_count();
  549. break;
  550. case 'get_gradebooks':
  551. require_once $libpath.'gradebook.lib.php';
  552. $obj = new Gradebook();
  553. $count = $obj->get_count();
  554. break;
  555. case 'get_event_email_template':
  556. $obj = new EventEmailTemplate();
  557. $count = $obj->get_count();
  558. break;
  559. case 'get_careers':
  560. $obj = new Career();
  561. $count = $obj->get_count();
  562. break;
  563. case 'get_promotions':
  564. $obj = new Promotion();
  565. $count = $obj->get_count();
  566. break;
  567. case 'get_grade_models':
  568. $obj = new GradeModel();
  569. $count = $obj->get_count();
  570. break;
  571. case 'get_usergroups':
  572. $obj = new UserGroup();
  573. $count = $obj->get_count();
  574. break;
  575. case 'get_usergroups_teacher':
  576. $obj = new UserGroup();
  577. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
  578. $groupFilter = isset($_REQUEST['group_filter']) ? intval($_REQUEST['group_filter']) : 0;
  579. $course_id = api_get_course_int_id();
  580. if ($type == 'registered') {
  581. $count = $obj->getUserGroupByCourseWithDataCount($course_id, $groupFilter);
  582. } else {
  583. $count = $obj->get_count($groupFilter);
  584. }
  585. break;
  586. default:
  587. exit;
  588. }
  589. //3. Calculating first, end, etc
  590. $total_pages = 0;
  591. if ($count > 0) {
  592. if (!empty($limit)) {
  593. $total_pages = ceil((float)$count/(float)$limit);
  594. }
  595. }
  596. if ($page > $total_pages) {
  597. $page = $total_pages;
  598. }
  599. $start = $limit * $page - $limit;
  600. if ($start < 0) {
  601. $start = 0;
  602. }
  603. //4. Deleting an element if the user wants to
  604. if (isset($_REQUEST['oper']) && $_REQUEST['oper'] == 'del') {
  605. $obj->delete($_REQUEST['id']);
  606. }
  607. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh();
  608. //5. Querying the DB for the elements
  609. $columns = array();
  610. switch ($action) {
  611. case 'get_group_reporting':
  612. $columns = array('name', 'time', 'progress', 'score', 'works', 'messages', 'actions');
  613. $result = Tracking::get_group_reporting(
  614. $course_id,
  615. $sessionId,
  616. $group_id,
  617. 'all',
  618. $start,
  619. $limit,
  620. $sidx,
  621. $sord,
  622. $whereCondition
  623. );
  624. break;
  625. case 'get_course_exercise_medias':
  626. $columns = array('question');
  627. $result = Question::get_course_medias(
  628. $course_id,
  629. $start,
  630. $limit,
  631. $sidx,
  632. $sord,
  633. $whereCondition
  634. );
  635. break;
  636. case 'get_user_course_report_resumed':
  637. $columns = array(
  638. 'extra_ruc',
  639. 'training_hours',
  640. 'count_users',
  641. 'count_users_registered',
  642. 'average_hours_per_user',
  643. 'count_certificates'
  644. );
  645. $column_names = array(
  646. get_lang('Company'),
  647. get_lang('TrainingHoursAccumulated'),
  648. get_lang('CountOfSubscriptions'),
  649. get_lang('CountOfUsers'),
  650. get_lang('AverageHoursPerStudent'),
  651. get_lang('CountCertificates')
  652. );
  653. $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
  654. if (!empty($extra_fields)) {
  655. foreach ($extra_fields as $extra) {
  656. if ($extra['1'] == 'ruc') {
  657. continue;
  658. }
  659. $columns[] = $extra['1'];
  660. $column_names[] = $extra['3'];
  661. }
  662. }
  663. if (!in_array($sidx, array('training_hours'))) {
  664. //$sidx = 'training_hours';
  665. }
  666. if (api_is_student_boss() && empty($userIdList)) {
  667. $result = [];
  668. break;
  669. }
  670. $result = CourseManager::get_user_list_from_course_code(
  671. null,
  672. null,
  673. "LIMIT $start, $limit",
  674. null, //" $sidx $sord",
  675. null,
  676. null,
  677. true,
  678. true,
  679. array('ruc'),
  680. $courseCodeList,
  681. $userIdList,
  682. null,
  683. $sessionIdList
  684. );
  685. $new_result = array();
  686. if (!empty($result)) {
  687. foreach ($result as $row) {
  688. $row['training_hours'] = api_time_to_hms($row['training_hours']);
  689. $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']);
  690. $new_result[] = $row;
  691. }
  692. $result = $new_result;
  693. }
  694. break;
  695. case 'get_user_course_report':
  696. $columns = array(
  697. 'course',
  698. 'user',
  699. 'email',
  700. 'time',
  701. 'certificate',
  702. 'progress_100',
  703. 'progress',
  704. );
  705. $column_names = array(
  706. get_lang('Course'),
  707. get_lang('User'),
  708. get_lang('Email'),
  709. get_lang('ManHours'),
  710. get_lang('CertificateGenerated'),
  711. get_lang('Approved'),
  712. get_lang('CourseAdvance')
  713. );
  714. $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
  715. if (!empty($extra_fields)) {
  716. foreach ($extra_fields as $extra) {
  717. $columns[] = $extra['1'];
  718. $column_names[] = $extra['3'];
  719. }
  720. }
  721. if (api_is_student_boss()) {
  722. $columns[] = 'group';
  723. $column_names[] = get_lang('Group');
  724. }
  725. if (!in_array($sidx, array('title'))) {
  726. $sidx = 'title';
  727. }
  728. if (api_is_student_boss() && empty($userIdList)) {
  729. $result = [];
  730. break;
  731. }
  732. //get sessions
  733. $arrSessions = array();
  734. if(count($sessionIdList) > 0) {
  735. $arrSessions = CourseManager::get_user_list_from_course_code(
  736. null,
  737. null,
  738. "LIMIT $start, $limit",
  739. " $sidx $sord",
  740. null,
  741. null,
  742. true,
  743. false,
  744. null,
  745. $courseCodeList,
  746. $userIdList,
  747. null,
  748. $sessionIdList
  749. );
  750. }
  751. //get courses
  752. $arrCourses = CourseManager::get_user_list_from_course_code(
  753. null,
  754. null,
  755. "LIMIT $start, $limit",
  756. " $sidx $sord",
  757. null,
  758. null,
  759. true,
  760. false,
  761. null,
  762. [],
  763. $userIdList,
  764. null
  765. );
  766. //merge courses and sessions
  767. $result = array_merge($arrSessions, $arrCourses);
  768. if (api_is_student_boss()) {
  769. $userGroup = new UserGroup();
  770. foreach ($result as &$item) {
  771. $userGroups = $userGroup->get_groups_by_user($item['user_id']);
  772. $item['group'] = implode(", ", array_column($userGroups, 'name'));
  773. unset($item['user_id']);
  774. }
  775. }
  776. break;
  777. case 'get_user_skill_ranking':
  778. $columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank');
  779. $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $whereCondition);
  780. $result = msort($result, 'skills_acquired', 'asc');
  781. $skills_in_course = array();
  782. if (!empty($result)) {
  783. foreach ($result as &$item) {
  784. $user_info = api_get_user_info($item['user_id']);
  785. $personal_course_list = UserManager::get_personal_session_course_list($item['user_id']);
  786. $count_skill_by_course = array();
  787. foreach ($personal_course_list as $course_item) {
  788. if (!isset($skills_in_course[$course_item['code']])) {
  789. $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']);
  790. $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
  791. } else {
  792. $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
  793. }
  794. }
  795. $item['photo'] = Display::img($user_info['avatar_small'], $user_info['complete_name'], [], false);
  796. $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
  797. }
  798. }
  799. break;
  800. case 'get_course_announcements':
  801. $columns = array(
  802. 'title',
  803. 'username',
  804. 'insert_date',
  805. 'actions'
  806. );
  807. $titleToSearch = isset($_REQUEST['title_to_search']) ? $_REQUEST['title_to_search'] : '';
  808. $userIdToSearch = isset($_REQUEST['user_id_to_search']) ? $_REQUEST['user_id_to_search'] : 0;
  809. $result = AnnouncementManager::getAnnouncements(
  810. null,
  811. null,
  812. false,
  813. $start,
  814. $limit,
  815. $sidx,
  816. $sord,
  817. $titleToSearch,
  818. $userIdToSearch
  819. );
  820. break;
  821. case 'get_work_teacher':
  822. $columns = array(
  823. 'type',
  824. 'title',
  825. 'sent_date',
  826. 'expires_on',
  827. 'amount',
  828. 'actions'
  829. );
  830. $result = getWorkListTeacher($start, $limit, $sidx, $sord, $whereCondition);
  831. break;
  832. case 'get_work_student':
  833. $columns = array(
  834. 'type',
  835. 'title',
  836. 'expires_on',
  837. 'feedback',
  838. 'last_upload',
  839. 'others'
  840. );
  841. $result = getWorkListStudent($start, $limit, $sidx, $sord, $whereCondition);
  842. break;
  843. case 'get_work_user_list_all':
  844. if (isset($_GET['type']) && $_GET['type'] === 'simple') {
  845. $columns = array(
  846. 'fullname',
  847. 'title',
  848. 'qualification',
  849. 'sent_date',
  850. 'qualificator_id',
  851. 'correction',
  852. 'actions'
  853. );
  854. } else {
  855. $columns = array(
  856. 'fullname',
  857. 'title',
  858. 'qualification',
  859. 'sent_date',
  860. //'status',
  861. //'has_correction',
  862. 'correction',
  863. 'actions'
  864. );
  865. }
  866. $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
  867. break;
  868. case 'get_work_user_list_others':
  869. if (isset($_GET['type']) && $_GET['type'] === 'simple') {
  870. $columns = array(
  871. 'type', 'firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'
  872. );
  873. } else {
  874. $columns = array('type', 'firstname', 'lastname', 'title', 'sent_date', 'actions');
  875. }
  876. $whereCondition .= " AND u.user_id <> ".api_get_user_id();
  877. $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
  878. break;
  879. case 'get_work_user_list':
  880. if (isset($_GET['type']) && $_GET['type'] == 'simple') {
  881. $columns = array(
  882. 'type', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'
  883. );
  884. } else {
  885. $columns = array('type', 'title', 'qualification', 'sent_date', 'actions');
  886. }
  887. $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
  888. if (empty($documents)) {
  889. $whereCondition .= " AND u.user_id = ".api_get_user_id();
  890. $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
  891. } else {
  892. $result = get_work_user_list_from_documents(
  893. $start,
  894. $limit,
  895. $sidx,
  896. $sord,
  897. $work_id,
  898. api_get_user_id(),
  899. $whereCondition
  900. );
  901. }
  902. break;
  903. case 'get_exercise_results':
  904. $course = api_get_course_info();
  905. // Used inside ExerciseLib::get_exam_results_data()
  906. $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
  907. if ($is_allowedToEdit || api_is_student_boss()) {
  908. $columns = array(
  909. 'firstname',
  910. 'lastname',
  911. 'username',
  912. 'group_name',
  913. 'exe_duration',
  914. 'start_date',
  915. 'exe_date',
  916. 'score',
  917. 'user_ip',
  918. 'status',
  919. 'lp',
  920. 'actions',
  921. );
  922. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  923. if ($officialCodeInList === 'true') {
  924. $columns = array_merge(array('official_code'), $columns);
  925. }
  926. }
  927. $result = ExerciseLib::get_exam_results_data(
  928. $start,
  929. $limit,
  930. $sidx,
  931. $sord,
  932. $exercise_id,
  933. $whereCondition
  934. );
  935. break;
  936. case 'get_hotpotatoes_exercise_results':
  937. $course = api_get_course_info();
  938. $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
  939. if (api_is_allowed_to_edit()) {
  940. $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
  941. } else {
  942. $columns = array('exe_date', 'score', 'actions');
  943. }
  944. $result = ExerciseLib::get_exam_results_hotpotatoes_data(
  945. $start,
  946. $limit,
  947. $sidx,
  948. $sord,
  949. $hotpot_path,
  950. $whereCondition
  951. );
  952. break;
  953. case 'get_work_student_list_overview':
  954. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  955. return array();
  956. }
  957. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  958. $columns = array(
  959. 'student', 'works'
  960. );
  961. $result = getWorkUserListData(
  962. $workId,
  963. api_get_course_id(),
  964. api_get_session_id(),
  965. api_get_group_id(),
  966. $start,
  967. $limit,
  968. $sidx,
  969. $sord
  970. );
  971. break;
  972. case 'get_hotpotatoes_exercise_results':
  973. $course = api_get_course_info();
  974. $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
  975. if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
  976. $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
  977. } else {
  978. $columns = array('exe_date', 'score', 'actions');
  979. }
  980. $result = ExerciseLib::get_exam_results_hotpotatoes_data(
  981. $start,
  982. $limit,
  983. $sidx,
  984. $sord,
  985. $hotpot_path,
  986. $whereCondition
  987. );
  988. break;
  989. case 'get_sessions_tracking':
  990. if (api_is_drh() || api_is_session_admin()) {
  991. $sessions = SessionManager::get_sessions_followed_by_drh(
  992. api_get_user_id(),
  993. $start,
  994. $limit,
  995. false,
  996. false,
  997. false,
  998. null,
  999. $keyword,
  1000. $description
  1001. );
  1002. } else {
  1003. // Sessions for the coach
  1004. $sessions = Tracking::get_sessions_coached_by_user(
  1005. api_get_user_id(),
  1006. $start,
  1007. $limit,
  1008. false,
  1009. $keyword,
  1010. $description
  1011. );
  1012. }
  1013. $columns = array(
  1014. 'name',
  1015. 'date',
  1016. 'course_per_session',
  1017. 'student_per_session',
  1018. 'details'
  1019. );
  1020. $result = array();
  1021. if (!empty($sessions)) {
  1022. foreach ($sessions as $session) {
  1023. if (api_drh_can_access_all_session_content()) {
  1024. $count_courses_in_session = SessionManager::get_course_list_by_session_id($session['id'], '', null, true);
  1025. } else {
  1026. $count_courses_in_session = count(Tracking::get_courses_followed_by_coach($user_id, $session['id']));
  1027. }
  1028. $count_users_in_session = SessionManager::get_users_by_session($session['id'], 0, true);
  1029. $session_date = array();
  1030. if (!empty($session['access_start_date'])) {
  1031. $session_date[] = get_lang('From').' '.api_format_date($session['access_start_date'], DATE_FORMAT_SHORT);
  1032. }
  1033. if (!empty($session['access_end_date'])) {
  1034. $session_date[] = get_lang('Until').' '.api_format_date($session['access_end_date'], DATE_FORMAT_SHORT);
  1035. }
  1036. if (empty($session_date)) {
  1037. $session_date_string = '-';
  1038. } else {
  1039. $session_date_string = implode(' ', $session_date);
  1040. }
  1041. $detailButtons = [];
  1042. $detailButtons[] = Display::url(
  1043. Display::return_icon('works.png', get_lang('WorksReport')),
  1044. api_get_path(WEB_CODE_PATH) . 'mySpace/works_in_session_report.php?session=' . $session['id']
  1045. );
  1046. $detailButtons[] = Display::url(
  1047. Display::return_icon('2rightarrow.png'),
  1048. api_get_path(WEB_CODE_PATH) . 'mySpace/course.php?session_id=' . $session['id']
  1049. );
  1050. $result[] = array(
  1051. 'name' => Display::url(
  1052. $session['name'],
  1053. api_get_path(WEB_CODE_PATH) . 'mySpace/course.php?session_id=' . $session['id']
  1054. ),
  1055. 'date' => $session_date_string,
  1056. 'course_per_session' => $count_courses_in_session,
  1057. 'student_per_session' => $count_users_in_session,
  1058. 'details' => implode(' ', $detailButtons)
  1059. );
  1060. }
  1061. }
  1062. break;
  1063. case 'get_sessions':
  1064. $session_columns = SessionManager::getGridColumns($list_type);
  1065. $columns = $session_columns['simple_column_name'];
  1066. if ($list_type == 'simple') {
  1067. $result = SessionManager::get_sessions_admin(
  1068. array(
  1069. 'where' => $whereCondition,
  1070. 'order' => "$sidx $sord",
  1071. 'extra' => $extra_fields,
  1072. 'limit' => "$start , $limit",
  1073. ),
  1074. false
  1075. );
  1076. } else {
  1077. $result = SessionManager::get_sessions_admin_complete(
  1078. array(
  1079. 'where' => $whereCondition,
  1080. 'order' => "$sidx $sord",
  1081. 'extra' => $extra_fields,
  1082. 'limit' => "$start , $limit",
  1083. )
  1084. );
  1085. }
  1086. break;
  1087. /*
  1088. $columns = array(
  1089. 'name',
  1090. 'nbr_courses',
  1091. 'nbr_users',
  1092. 'category_name',
  1093. 'access_start_date',
  1094. 'access_end_date',
  1095. 'coach_name',
  1096. 'session_active',
  1097. 'visibility'
  1098. );
  1099. if (SessionManager::allowToManageSessions()) {
  1100. if (SessionManager::allowOnlyMySessions()) {
  1101. $whereCondition .= ' AND s.id_coach = '.api_get_user_id();
  1102. }
  1103. // Rename Category_name
  1104. $whereCondition = str_replace(
  1105. 'category_name',
  1106. 'sc.name',
  1107. $whereCondition
  1108. );
  1109. $result = SessionManager::get_sessions_admin(
  1110. array(
  1111. 'where' => $whereCondition,
  1112. 'order' => "$sidx $sord",
  1113. 'limit' => "$start , $limit"
  1114. )
  1115. );
  1116. }
  1117. */
  1118. break;
  1119. case 'get_exercise_progress':
  1120. $sessionId = intval($_GET['session_id']);
  1121. $courseId = intval($_GET['course_id']);
  1122. $exerciseId = intval($_GET['exercise_id']);
  1123. $date_from = $_GET['date_from'];
  1124. $date_to = $_GET['date_to'];
  1125. $columns = array(
  1126. 'session',
  1127. 'exercise_id',
  1128. 'quiz_title',
  1129. 'username',
  1130. 'lastname',
  1131. 'firstname',
  1132. 'time',
  1133. 'question_id',
  1134. 'question',
  1135. 'description',
  1136. 'answer',
  1137. 'correct',
  1138. );
  1139. $result = Tracking::get_exercise_progress(
  1140. $sessionId,
  1141. $courseId,
  1142. $exerciseId,
  1143. $date_from,
  1144. $date_to,
  1145. array(
  1146. 'where' => $whereCondition,
  1147. 'order' => "$sidx $sord",
  1148. 'limit'=> "$start , $limit"
  1149. )
  1150. );
  1151. break;
  1152. case 'get_session_lp_progress':
  1153. $sessionId = 0;
  1154. if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) {
  1155. $sessionId = intval($_GET['session_id']);
  1156. $courseId = intval($_GET['course_id']);
  1157. $course = api_get_course_info_by_id($courseId);
  1158. }
  1159. /**
  1160. * Add lessons of course
  1161. *
  1162. */
  1163. $columns = array(
  1164. 'username',
  1165. 'firstname',
  1166. 'lastname',
  1167. );
  1168. $lessons = LearnpathList::get_course_lessons($course['code'], $sessionId);
  1169. foreach ($lessons as $lesson_id => $lesson) {
  1170. $columns[] = $lesson_id;
  1171. }
  1172. $columns[] = 'total';
  1173. $result = SessionManager::get_session_lp_progress(
  1174. $sessionId,
  1175. $courseId,
  1176. $date_from,
  1177. $date_to,
  1178. array(
  1179. 'where' => $whereCondition,
  1180. 'order' => "$sidx $sord",
  1181. 'limit' => "$start , $limit",
  1182. )
  1183. );
  1184. break;
  1185. case 'get_survey_overview':
  1186. $sessionId = 0;
  1187. if (!empty($_GET['session_id']) &&
  1188. !empty($_GET['course_id']) &&
  1189. !empty($_GET['survey_id'])
  1190. ) {
  1191. $sessionId = intval($_GET['session_id']);
  1192. $courseId = intval($_GET['course_id']);
  1193. $surveyId = intval($_GET['survey_id']);
  1194. $date_from = $_GET['date_from'];
  1195. $date_to = $_GET['date_to'];
  1196. //$course = api_get_course_info_by_id($courseId);
  1197. }
  1198. /**
  1199. * Add lessons of course
  1200. */
  1201. $columns = array(
  1202. 'username',
  1203. 'firstname',
  1204. 'lastname',
  1205. );
  1206. $questions = SurveyManager::get_questions($surveyId, $courseId);
  1207. foreach ($questions as $question_id => $question) {
  1208. $columns[] = $question_id;
  1209. }
  1210. $result = SessionManager::get_survey_overview(
  1211. $sessionId,
  1212. $courseId,
  1213. $surveyId,
  1214. $date_from,
  1215. $date_to,
  1216. array(
  1217. 'where' => $whereCondition,
  1218. 'order' => "$sidx $sord",
  1219. 'limit' => "$start , $limit",
  1220. )
  1221. );
  1222. break;
  1223. case 'get_session_progress':
  1224. $columns = array(
  1225. 'lastname',
  1226. 'firstname',
  1227. 'username',
  1228. #'profile',
  1229. 'total',
  1230. 'courses',
  1231. 'lessons',
  1232. 'exercises',
  1233. 'forums',
  1234. 'homeworks',
  1235. 'wikis',
  1236. 'surveys',
  1237. //exercises
  1238. 'lessons_total',
  1239. 'lessons_done',
  1240. 'lessons_left',
  1241. 'lessons_progress',
  1242. //exercises
  1243. 'exercises_total',
  1244. 'exercises_done',
  1245. 'exercises_left',
  1246. 'exercises_progress',
  1247. //forums
  1248. 'forums_total',
  1249. 'forums_done',
  1250. 'forums_left',
  1251. 'forums_progress',
  1252. //assignments
  1253. 'assignments_total',
  1254. 'assignments_done',
  1255. 'assignments_left',
  1256. 'assignments_progress',
  1257. //Wiki
  1258. 'wiki_total',
  1259. 'wiki_revisions',
  1260. 'wiki_read',
  1261. 'wiki_unread',
  1262. 'wiki_progress',
  1263. //surveys
  1264. 'surveys_total',
  1265. 'surveys_done',
  1266. 'surveys_left',
  1267. 'surveys_progress',
  1268. );
  1269. $sessionId = 0;
  1270. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  1271. $sessionId = intval($_GET['session_id']);
  1272. $courseId = intval($_GET['course_id']);
  1273. }
  1274. $result = SessionManager::get_session_progress(
  1275. $sessionId,
  1276. $courseId,
  1277. null,
  1278. null,
  1279. array(
  1280. 'where' => $whereCondition,
  1281. 'order' => "$sidx $sord",
  1282. 'limit'=> "$start , $limit"
  1283. )
  1284. );
  1285. break;
  1286. case 'get_session_access_overview':
  1287. $columns = array(
  1288. 'logindate',
  1289. 'username',
  1290. 'lastname',
  1291. 'firstname',
  1292. 'clicks',
  1293. 'ip',
  1294. 'timeLoggedIn',
  1295. 'session'
  1296. );
  1297. $sessionId = 0;
  1298. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  1299. $sessionId = intval($_GET['session_id']);
  1300. $courseId = intval($_GET['course_id']);
  1301. $studentId = intval($_GET['student_id']);
  1302. $profile = intval($_GET['profile']);
  1303. $date_from = intval($_GET['date_from']);
  1304. $date_to = intval($_GET['date_to']);
  1305. }
  1306. $result = SessionManager::get_user_data_access_tracking_overview(
  1307. $sessionId,
  1308. $courseId,
  1309. $studentId,
  1310. $profile,
  1311. $date_to,
  1312. $date_from,
  1313. array(
  1314. 'where' => $whereCondition,
  1315. 'order' => "$sidx $sord",
  1316. 'limit'=> "$start , $limit"
  1317. )
  1318. );
  1319. break;
  1320. case 'get_timelines':
  1321. $columns = array('headline', 'actions');
  1322. if (!in_array($sidx, $columns)) {
  1323. $sidx = 'headline';
  1324. }
  1325. $course_id = api_get_course_int_id();
  1326. $result = Database::select(
  1327. '*',
  1328. $obj->table,
  1329. array(
  1330. 'where' => array(
  1331. 'parent_id = ? AND c_id = ?' => array('0', $course_id)
  1332. ),
  1333. 'order'=>"$sidx $sord",
  1334. 'LIMIT'=> "$start , $limit"
  1335. )
  1336. );
  1337. $new_result = array();
  1338. foreach ($result as $item) {
  1339. if (!$item['status']) {
  1340. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1341. }
  1342. $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH).'timeline/view.php?id='.$item['id']);
  1343. $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']);
  1344. $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH).'timeline/?action=edit&id='.$item['id']);
  1345. $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH).'timeline/?action=delete&id='.$item['id']);
  1346. $new_result[] = $item;
  1347. }
  1348. $result = $new_result;
  1349. break;
  1350. case 'get_gradebooks':
  1351. $columns = array('name', 'certificates','skills', 'actions', 'has_certificates');
  1352. if (!in_array($sidx, $columns)) {
  1353. $sidx = 'name';
  1354. }
  1355. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1356. $new_result = array();
  1357. foreach ($result as $item) {
  1358. if ($item['parent_id'] != 0) {
  1359. continue;
  1360. }
  1361. $skills = $obj->get_skills_by_gradebook($item['id']);
  1362. //Fixes bug when gradebook doesn't have names
  1363. if (empty($item['name'])) {
  1364. $item['name'] = $item['course_code'];
  1365. }
  1366. $item['name'] = Display::url($item['name'], api_get_path(WEB_CODE_PATH).'gradebook/index.php?id_session=0&cidReq='.$item['course_code']);
  1367. if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
  1368. $item['certificates'] = Display::return_icon('accept.png', get_lang('WithCertificate'), array(), ICON_SIZE_SMALL);
  1369. $item['has_certificates'] = '1';
  1370. } else {
  1371. $item['certificates'] = Display::return_icon('warning.png', get_lang('NoCertificate'), array(), ICON_SIZE_SMALL);
  1372. $item['has_certificates'] = '0';
  1373. }
  1374. if (!empty($skills)) {
  1375. $item['skills'] = '';
  1376. foreach ($skills as $skill) {
  1377. $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));
  1378. }
  1379. }
  1380. $new_result[] = $item;
  1381. }
  1382. $result = $new_result;
  1383. break;
  1384. case 'get_event_email_template':
  1385. $columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions');
  1386. if (!in_array($sidx, $columns)) {
  1387. $sidx = 'subject';
  1388. }
  1389. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1390. $new_result = array();
  1391. foreach ($result as $item) {
  1392. $language_info = api_get_language_info($item['language_id']);
  1393. $item['language_id'] = $language_info['english_name'];
  1394. $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']);
  1395. $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']);
  1396. $new_result[] = $item;
  1397. }
  1398. $result = $new_result;
  1399. break;
  1400. case 'get_careers':
  1401. $columns = array('name', 'description', 'actions');
  1402. if (!in_array($sidx, $columns)) {
  1403. $sidx = 'name';
  1404. }
  1405. $result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
  1406. $new_result = array();
  1407. foreach ($result as $item) {
  1408. if (!$item['status']) {
  1409. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1410. }
  1411. $new_result[] = $item;
  1412. }
  1413. $result = $new_result;
  1414. break;
  1415. case 'get_promotions':
  1416. $columns = array('name', 'career', 'description', 'actions');
  1417. if (!in_array($sidx, $columns)) {
  1418. $sidx = 'name';
  1419. }
  1420. $result = Database::select(
  1421. 'p.id,p.name, p.description, c.name as career, p.status',
  1422. "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ",
  1423. array('order' => "$sidx $sord", 'LIMIT'=> "$start , $limit")
  1424. );
  1425. $new_result = array();
  1426. foreach ($result as $item) {
  1427. if (!$item['status']) {
  1428. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1429. }
  1430. $new_result[] = $item;
  1431. }
  1432. $result = $new_result;
  1433. break;
  1434. case 'get_grade_models':
  1435. $columns = array('name', 'description', 'actions');
  1436. if (!in_array($sidx, $columns)) {
  1437. $sidx = 'name';
  1438. }
  1439. $result = Database::select('*', "$obj->table ", array('order' => "$sidx $sord", 'LIMIT' => "$start , $limit"));
  1440. $new_result = array();
  1441. foreach ($result as $item) {
  1442. $new_result[] = $item;
  1443. }
  1444. $result = $new_result;
  1445. break;
  1446. case 'get_usergroups':
  1447. $columns = array('name', 'users', 'courses', 'sessions', 'group_type', 'actions');
  1448. $result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
  1449. break;
  1450. case 'get_extra_fields':
  1451. $obj = new ExtraField($type);
  1452. $columns = array(
  1453. 'display_text',
  1454. 'variable',
  1455. 'field_type',
  1456. 'changeable',
  1457. 'visible_to_self',
  1458. 'visible_to_others',
  1459. 'filter',
  1460. 'field_order',
  1461. );
  1462. $result = $obj->getAllGrid($sidx, $sord, $start, $limit);
  1463. $new_result = array();
  1464. if (!empty($result)) {
  1465. $checkIcon = Display::return_icon('check-circle.png', get_lang('Yes'));
  1466. $timesIcon = Display::return_icon('closed-circle.png', get_lang('No'));
  1467. foreach ($result as $item) {
  1468. $item['display_text'] = ExtraField::translateDisplayName($item['variable'], $item['displayText']);
  1469. $item['field_type'] = $obj->get_field_type_by_id($item['fieldType']);
  1470. $item['changeable'] = $item['changeable'] ? $checkIcon : $timesIcon;
  1471. $item['visible_to_self'] = $item['visibleToSelf'] ? $checkIcon : $timesIcon;
  1472. $item['visible_to_others'] = $item['visibleToOthers'] ? $checkIcon : $timesIcon;
  1473. $item['filter'] = $item['filter'] ? $checkIcon : $timesIcon;
  1474. $new_result[] = $item;
  1475. }
  1476. $result = $new_result;
  1477. }
  1478. break;
  1479. case 'get_exercise_grade':
  1480. $objExercise = new Exercise();
  1481. $exercises = $objExercise->getExercisesByCourseSession(
  1482. $_GET['course_id'],
  1483. $_GET['session_id']
  1484. );
  1485. $cntExer = 4;
  1486. if (!empty($exercises)) {
  1487. $cntExer += count($exercises);
  1488. }
  1489. $columns = array();
  1490. //Get dynamic column names
  1491. $i = 1;
  1492. $column_names = array();
  1493. foreach (range(1, $cntExer) as $cnt) {
  1494. switch ($cnt) {
  1495. case 1:
  1496. $columns[] = 'session';
  1497. $column_names[] = get_lang('Section');
  1498. break;
  1499. case 2:
  1500. $columns[] = 'username';
  1501. $column_names[] = get_lang('Username');
  1502. break;
  1503. case 3:
  1504. $columns[] = 'name';
  1505. $column_names[] = get_lang('Name');
  1506. break;
  1507. case $cntExer:
  1508. $columns[] = 'finalScore';
  1509. $column_names[] = get_lang('FinalScore');
  1510. break;
  1511. default:
  1512. $title = "";
  1513. if (!empty($exercises[$cnt - 4]['title'])) {
  1514. $title = ucwords(strtolower(trim($exercises[$cnt - 4]['title'])));
  1515. }
  1516. $columns[] = 'exer' . $i;
  1517. $column_names[] = $title;
  1518. $i++;
  1519. break;
  1520. }
  1521. }
  1522. $quizIds = array();
  1523. if (!empty($exercises)) {
  1524. foreach ($exercises as $exercise) {
  1525. $quizIds[] = $exercise['id'];
  1526. }
  1527. }
  1528. $course = api_get_course_info_by_id($_GET['course_id']);
  1529. $listUserSess = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id']);
  1530. $usersId = array_keys($listUserSess);
  1531. $users = UserManager::get_user_list_by_ids($usersId, null, "lastname, firstname", "$start , $limit");
  1532. $exeResults = $objExercise->getExerciseAndResult($_GET['course_id'], $_GET['session_id'], $quizIds);
  1533. $arrGrade = array();
  1534. foreach ($exeResults as $exeResult) {
  1535. $arrGrade[$exeResult['exe_user_id']][$exeResult['exe_exo_id']] = $exeResult['exe_result'];
  1536. }
  1537. $result = array();
  1538. $i = 0;
  1539. foreach ($users as $user) {
  1540. $sessionInfo = SessionManager::fetch($listUserSess[$user['user_id']]['id_session']);
  1541. $result[$i]['session'] = $sessionInfo['name'];
  1542. $result[$i]['username'] = $user['username'];
  1543. $result[$i]['name'] = $user['lastname'] . " " . $user['firstname'];
  1544. $j = 1;
  1545. $finalScore = 0;
  1546. foreach ($quizIds as $quizID) {
  1547. $grade = '';
  1548. if (!empty($arrGrade [$user['user_id']][$quizID]) || $arrGrade [$user['user_id']][$quizID] == 0) {
  1549. $finalScore += $grade = $arrGrade [$user['user_id']][$quizID];
  1550. }
  1551. $result[$i]['exer' . $j] = $grade;
  1552. $j++;
  1553. }
  1554. if ($finalScore > 20) {
  1555. $finalScore = 20;
  1556. }
  1557. $result[$i]['finalScore'] = number_format($finalScore, 2);
  1558. $i++;
  1559. }
  1560. break;
  1561. case 'get_extra_field_options':
  1562. $obj = new ExtraFieldOption($type);
  1563. $columns = array('display_text', 'option_value', 'option_order');
  1564. $result = $obj->get_all([
  1565. 'where' => array("field_id = ? " => $field_id),
  1566. 'order' => "$sidx $sord",
  1567. 'LIMIT' => "$start , $limit"
  1568. ]);
  1569. break;
  1570. case 'get_usergroups_teacher':
  1571. $columns = array('name', 'users', 'status', 'group_type', 'actions');
  1572. $options = array('order'=>"name $sord", 'LIMIT'=> "$start , $limit");
  1573. $options['course_id'] = $course_id;
  1574. switch ($type) {
  1575. case 'not_registered':
  1576. $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
  1577. $result = $obj->getUserGroupNotInCourse($options, $groupFilter);
  1578. break;
  1579. case 'registered':
  1580. $options['where'] = array(" usergroup.course_id = ? " => $course_id);
  1581. $result = $obj->getUserGroupInCourse($options, $groupFilter);
  1582. break;
  1583. }
  1584. $new_result = array();
  1585. if (!empty($result)) {
  1586. foreach ($result as $group) {
  1587. $group['users'] = count($obj->get_users_by_usergroup($group['id']));
  1588. if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
  1589. $url = 'class.php?action=remove_class_from_course&id='.$group['id'].'&'.api_get_cidreq();
  1590. $icon = Display::return_icon('delete.png', get_lang('Remove'));
  1591. //$class = 'btn btn-danger';
  1592. //$text = get_lang('Remove');
  1593. } else {
  1594. $url = 'class.php?action=add_class_to_course&id='.$group['id'].'&'.api_get_cidreq().'&type=not_registered';
  1595. //$class = 'btn btn-primary';
  1596. $icon = Display::return_icon('add.png', get_lang('Add'));
  1597. //$text = get_lang('Add');
  1598. }
  1599. switch ($group['group_type']) {
  1600. case 0:
  1601. $group['group_type'] = Display::label(get_lang('Class'), 'primary');
  1602. break;
  1603. case 1:
  1604. $group['group_type'] = Display::label(get_lang('Social'), 'success');
  1605. break;
  1606. }
  1607. $role = $obj->getUserRoleToString(api_get_user_id(), $group['id']);
  1608. $group['status'] = $role;
  1609. $group['actions'] = Display::url($icon, $url);
  1610. $new_result[] = $group;
  1611. }
  1612. $result = $new_result;
  1613. }
  1614. if (!in_array($sidx, $columns)) {
  1615. $sidx = 'name';
  1616. }
  1617. // Multidimensional sort
  1618. $result = msort($result, $sidx, $sord);
  1619. break;
  1620. default:
  1621. exit;
  1622. }
  1623. $allowed_actions = array(
  1624. 'get_careers',
  1625. 'get_promotions',
  1626. 'get_usergroups',
  1627. 'get_usergroups_teacher',
  1628. 'get_gradebooks',
  1629. 'get_sessions',
  1630. 'get_session_access_overview',
  1631. 'get_sessions_tracking',
  1632. 'get_session_lp_progress',
  1633. 'get_survey_overview',
  1634. 'get_session_progress',
  1635. 'get_exercise_progress',
  1636. 'get_exercise_results',
  1637. 'get_work_student_list_overview',
  1638. 'get_hotpotatoes_exercise_results',
  1639. 'get_work_teacher',
  1640. 'get_work_student',
  1641. 'get_work_user_list',
  1642. 'get_work_user_list_others',
  1643. 'get_work_user_list_all',
  1644. 'get_timelines',
  1645. 'get_grade_models',
  1646. 'get_event_email_template',
  1647. 'get_user_skill_ranking',
  1648. 'get_extra_fields',
  1649. 'get_extra_field_options',
  1650. //'get_course_exercise_medias',
  1651. 'get_user_course_report',
  1652. 'get_user_course_report_resumed',
  1653. 'get_exercise_grade',
  1654. 'get_group_reporting',
  1655. 'get_course_announcements'
  1656. );
  1657. //5. Creating an obj to return a json
  1658. if (in_array($action, $allowed_actions)) {
  1659. $response = new stdClass();
  1660. $response->page = $page;
  1661. $response->total = $total_pages;
  1662. $response->records = $count;
  1663. if ($operation && $operation == 'excel') {
  1664. $j = 1;
  1665. $array = array();
  1666. if (empty($column_names)) {
  1667. $column_names = $columns;
  1668. }
  1669. //Headers
  1670. foreach ($column_names as $col) {
  1671. $array[0][] = $col;
  1672. }
  1673. foreach ($result as $row) {
  1674. foreach ($columns as $col) {
  1675. $array[$j][] = strip_tags($row[$col]);
  1676. }
  1677. $j++;
  1678. }
  1679. switch ($exportFormat) {
  1680. case 'xls':
  1681. //TODO add date if exists
  1682. $file_name = (!empty($action)) ? $action : 'company_report';
  1683. $browser = new Browser();
  1684. if ($browser->getPlatform() == Browser::PLATFORM_WINDOWS) {
  1685. Export::export_table_xls_html($array, $file_name, 'ISO-8859-15');
  1686. } else {
  1687. Export::export_table_xls_html($array, $file_name);
  1688. }
  1689. break;
  1690. case 'csv':
  1691. default:
  1692. //TODO add date if exists
  1693. $file_name = (!empty($action)) ? $action : 'company_report';
  1694. Export::arrayToCsv($array, $file_name);
  1695. break;
  1696. }
  1697. exit;
  1698. }
  1699. $i = 0;
  1700. if (!empty($result)) {
  1701. foreach ($result as $row) {
  1702. // if results tab give not id, set id to $i otherwise id="null" for all <tr> of the jqgrid - ref #4235
  1703. if (!isset($row['id']) || isset($row['id']) && $row['id'] == '') {
  1704. $response->rows[$i]['id']= $i;
  1705. } else {
  1706. $response->rows[$i]['id']= $row['id'];
  1707. }
  1708. $array = array();
  1709. foreach ($columns as $col) {
  1710. if (in_array($col, ['correction', 'actions'])) {
  1711. $array[] = isset($row[$col]) ? $row[$col] : '';
  1712. } else {
  1713. $array[] = isset($row[$col]) ? Security::remove_XSS($row[$col]) : '';
  1714. }
  1715. }
  1716. $response->rows[$i]['cell']=$array;
  1717. $i++;
  1718. }
  1719. }
  1720. header('Content-Type: application/json;charset=utf-8');
  1721. echo json_encode($response);
  1722. }
  1723. exit;