model.ajax.php 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. require_once __DIR__.'/../global.inc.php';
  5. // 1. Setting variables needed by jqgrid
  6. $action = $_GET['a'];
  7. $page = (int) $_REQUEST['page']; //page
  8. $limit = (int) $_REQUEST['rows']; //quantity of rows
  9. // Makes max row persistence after refreshing the grid
  10. $savedRows = Session::read('max_rows_'.$action);
  11. if (empty($savedRows)) {
  12. Session::write('max_rows_'.$action, $limit);
  13. } else {
  14. if ($limit != $savedRows) {
  15. Session::write('max_rows_'.$action, $limit);
  16. }
  17. }
  18. $sidx = $_REQUEST['sidx']; //index (field) to filter
  19. $sord = $_REQUEST['sord']; //asc or desc
  20. $exportFilename = isset($_REQUEST['export_filename']) ? $_REQUEST['export_filename'] : '';
  21. if (strpos(strtolower($sidx), 'asc') !== false) {
  22. $sidx = str_replace(['asc', ','], '', $sidx);
  23. $sord = 'asc';
  24. }
  25. if (strpos(strtolower($sidx), 'desc') !== false) {
  26. $sidx = str_replace(['desc', ','], '', $sidx);
  27. $sord = 'desc';
  28. }
  29. if (!in_array($sord, ['asc', 'desc'])) {
  30. $sord = 'desc';
  31. }
  32. // Actions allowed to other roles.
  33. if (!in_array(
  34. $action,
  35. [
  36. 'get_exercise_results',
  37. 'get_exercise_results_report',
  38. 'get_work_student_list_overview',
  39. 'get_hotpotatoes_exercise_results',
  40. 'get_work_teacher',
  41. 'get_work_student',
  42. 'get_work_user_list',
  43. 'get_work_user_list_others',
  44. 'get_work_user_list_all',
  45. 'get_timelines',
  46. 'get_user_skill_ranking',
  47. 'get_usergroups',
  48. 'get_usergroups_teacher',
  49. 'get_user_course_report_resumed',
  50. 'get_user_course_report',
  51. 'get_sessions_tracking',
  52. 'get_sessions',
  53. 'get_course_announcements',
  54. 'course_log_events',
  55. 'get_learning_path_calendars',
  56. 'get_usergroups_users',
  57. 'get_calendar_users',
  58. 'get_exercise_categories',
  59. ]
  60. ) && !isset($_REQUEST['from_course_session'])) {
  61. api_protect_admin_script(true);
  62. } elseif (isset($_REQUEST['from_course_session']) &&
  63. $_REQUEST['from_course_session'] == 1
  64. ) {
  65. api_protect_teacher_script(true);
  66. }
  67. $toRemove = ['extra_access_start_date', 'extra_access_end_date'];
  68. // Search features
  69. //@todo move this in the display_class or somewhere else
  70. /**
  71. * @param string $col
  72. * @param string $oper
  73. * @param string $val
  74. *
  75. * @return string
  76. */
  77. function getWhereClause($col, $oper, $val)
  78. {
  79. $ops = [
  80. 'eq' => '=', //equal
  81. 'ne' => '<>', //not equal
  82. 'lt' => '<', //less than
  83. 'le' => '<=', //less than or equal
  84. 'gt' => '>', //greater than
  85. 'ge' => '>=', //greater than or equal
  86. 'bw' => 'LIKE', //begins with
  87. 'bn' => 'NOT LIKE', //doesn't begin with
  88. 'in' => 'LIKE', //is in
  89. 'ni' => 'NOT LIKE', //is not in
  90. 'ew' => 'LIKE', //ends with
  91. 'en' => 'NOT LIKE', //doesn't end with
  92. 'cn' => 'LIKE', //contains
  93. 'nc' => 'NOT LIKE', //doesn't contain
  94. ];
  95. if (empty($col)) {
  96. return '';
  97. }
  98. if ($oper == 'bw' || $oper == 'bn') {
  99. $val .= '%';
  100. }
  101. if ($oper == 'ew' || $oper == 'en') {
  102. $val = '%'.$val;
  103. }
  104. if ($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') {
  105. $val = '%'.$val.'%';
  106. }
  107. $val = Database::escape_string($val);
  108. return " $col {$ops[$oper]} '$val' ";
  109. }
  110. // If there is no search request sent by jqgrid, $where should be empty
  111. $whereCondition = '';
  112. $operation = isset($_REQUEST['oper']) ? $_REQUEST['oper'] : false;
  113. $exportFormat = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : 'csv';
  114. $searchField = isset($_REQUEST['searchField']) ? $_REQUEST['searchField'] : false;
  115. $searchOperator = isset($_REQUEST['searchOper']) ? $_REQUEST['searchOper'] : false;
  116. $searchString = isset($_REQUEST['searchString']) ? $_REQUEST['searchString'] : false;
  117. $search = isset($_REQUEST['_search']) ? $_REQUEST['_search'] : false;
  118. $forceSearch = isset($_REQUEST['_force_search']) ? $_REQUEST['_force_search'] : false;
  119. $extra_fields = [];
  120. $accessStartDate = '';
  121. $accessEndDate = '';
  122. $overwriteColumnHeaderExport = [];
  123. if (!empty($search)) {
  124. $search = 'true';
  125. }
  126. if (($search || $forceSearch) && ($search !== 'false')) {
  127. $whereCondition = ' 1 = 1 ';
  128. $whereConditionInForm = getWhereClause(
  129. $searchField,
  130. $searchOperator,
  131. $searchString
  132. );
  133. if (!empty($whereConditionInForm)) {
  134. $whereCondition .= ' AND ( ';
  135. $whereCondition .= ' ('.$whereConditionInForm.') ';
  136. }
  137. $filters = isset($_REQUEST['filters']) && !is_array($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;
  138. if (isset($_REQUEST['filters2'])) {
  139. $filters = json_decode($_REQUEST['filters2']);
  140. }
  141. if (!empty($filters)) {
  142. if (in_array($action, ['get_questions', 'get_sessions', 'get_sessions_tracking'])) {
  143. switch ($action) {
  144. case 'get_questions':
  145. $type = 'question';
  146. break;
  147. case 'get_sessions':
  148. case 'get_sessions_tracking':
  149. $type = 'session';
  150. break;
  151. }
  152. if (!empty($type)) {
  153. // Extra field.
  154. $extraField = new ExtraField($type);
  155. foreach ($filters->rules as $key => $data) {
  156. if (empty($data)) {
  157. continue;
  158. }
  159. if ($data->field === 'extra_access_start_date') {
  160. $accessStartDate = $data->data;
  161. }
  162. if ($data->field === 'extra_access_end_date') {
  163. $accessEndDate = $data->data;
  164. }
  165. if (in_array($data->field, $toRemove)) {
  166. unset($filters->rules[$key]);
  167. }
  168. }
  169. $result = $extraField->getExtraFieldRules($filters, 'extra_');
  170. $extra_fields = $result['extra_fields'];
  171. $condition_array = $result['condition_array'];
  172. $extraCondition = '';
  173. if (!empty($condition_array)) {
  174. $extraCondition = $filters->groupOp.' ( ';
  175. $extraCondition .= implode($filters->groupOp, $condition_array);
  176. $extraCondition .= ' ) ';
  177. }
  178. $whereCondition .= $extraCondition;
  179. // Question field
  180. $resultQuestion = $extraField->getExtraFieldRules(
  181. $filters,
  182. 'question_'
  183. );
  184. $questionFields = $resultQuestion['extra_fields'];
  185. $condition_array = $resultQuestion['condition_array'];
  186. $extraQuestionCondition = '';
  187. if (!empty($condition_array)) {
  188. $extraQuestionCondition = $filters->groupOp.' ( ';
  189. $extraQuestionCondition .= implode($filters->groupOp, $condition_array);
  190. $extraQuestionCondition .= ' ) ';
  191. // Remove conditions already added
  192. $extraQuestionCondition = str_replace(
  193. $extraCondition,
  194. '',
  195. $extraQuestionCondition
  196. );
  197. }
  198. $whereCondition .= $extraQuestionCondition;
  199. if (isset($filters->custom_dates)) {
  200. $whereCondition .= $filters->custom_dates;
  201. }
  202. }
  203. } elseif (!empty($filters->rules)) {
  204. $whereCondition .= ' AND ( ';
  205. $counter = 0;
  206. foreach ($filters->rules as $key => $rule) {
  207. $whereCondition .= getWhereClause(
  208. $rule->field,
  209. $rule->op,
  210. $rule->data
  211. );
  212. if ($counter < count($filters->rules) - 1) {
  213. $whereCondition .= $filters->groupOp;
  214. }
  215. $counter++;
  216. }
  217. $whereCondition .= ' ) ';
  218. }
  219. }
  220. if (!empty($whereConditionInForm)) {
  221. $whereCondition .= ' ) ';
  222. }
  223. }
  224. // get index row - i.e. user click to sort $sord = $_GET['sord'];
  225. // get the direction
  226. if (!$sidx) {
  227. $sidx = 1;
  228. }
  229. //2. Selecting the count FIRST
  230. //@todo rework this
  231. switch ($action) {
  232. case 'get_exercise_categories':
  233. $manager = new ExerciseCategoryManager();
  234. $courseId = isset($_REQUEST['c_id']) ? $_REQUEST['c_id'] : 0;
  235. $count = $manager->getCourseCount($courseId);
  236. break;
  237. case 'get_calendar_users':
  238. $calendarPlugin = LearningCalendarPlugin::create();
  239. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
  240. $count = $calendarPlugin->getUsersPerCalendarCount($id);
  241. break;
  242. case 'get_usergroups_users':
  243. $usergroup = new UserGroup();
  244. $usergroup->protectScript(null, true, true);
  245. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
  246. $count = $usergroup->getUserGroupUsers($id, true);
  247. break;
  248. case 'get_learning_path_calendars':
  249. $calendarPlugin = LearningCalendarPlugin::create();
  250. $count = $calendarPlugin->getCalendarCount();
  251. break;
  252. case 'course_log_events':
  253. $courseId = api_get_course_int_id();
  254. if (empty($courseId)) {
  255. exit;
  256. }
  257. $sessionId = api_get_session_id();
  258. if (!api_is_allowed_to_edit()) {
  259. exit;
  260. }
  261. $count = Statistics::getNumberOfActivities($courseId, $sessionId);
  262. break;
  263. case 'get_programmed_announcements':
  264. $object = new ScheduledAnnouncement();
  265. $count = $object->get_count();
  266. break;
  267. case 'get_group_reporting':
  268. $course_id = isset($_REQUEST['course_id']) ? $_REQUEST['course_id'] : null;
  269. $group_id = isset($_REQUEST['gidReq']) ? $_REQUEST['gidReq'] : null;
  270. $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : null;
  271. $count = Tracking::get_group_reporting(
  272. $course_id,
  273. $sessionId,
  274. $group_id,
  275. 'count'
  276. );
  277. break;
  278. case 'get_user_course_report':
  279. case 'get_user_course_report_resumed':
  280. $userNotAllowed = !api_is_student_boss() && !api_is_platform_admin(false, true);
  281. if ($userNotAllowed) {
  282. exit;
  283. }
  284. $userId = api_get_user_id();
  285. $sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;
  286. $courseCodeList = [];
  287. $userIdList = [];
  288. $sessionIdList = [];
  289. $searchByGroups = false;
  290. if (api_is_drh()) {
  291. if (api_drh_can_access_all_session_content()) {
  292. $userList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  293. 'drh_all',
  294. api_get_user_id()
  295. );
  296. if (!empty($userList)) {
  297. foreach ($userList as $user) {
  298. $userIdList[] = $user['user_id'];
  299. }
  300. }
  301. $courseList = SessionManager::getAllCoursesFollowedByUser(
  302. api_get_user_id(),
  303. null
  304. );
  305. if (!empty($courseList)) {
  306. foreach ($courseList as $course) {
  307. $courseCodeList[] = $course['code'];
  308. }
  309. }
  310. } else {
  311. $userList = UserManager::get_users_followed_by_drh(api_get_user_id());
  312. if (!empty($userList)) {
  313. $userIdList = array_keys($userList);
  314. }
  315. $courseList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  316. if (!empty($courseList)) {
  317. $courseCodeList = array_keys($courseList);
  318. }
  319. }
  320. if (empty($userIdList) || empty($courseCodeList)) {
  321. exit;
  322. }
  323. } elseif (api_is_student_boss()) {
  324. $supervisorStudents = UserManager::getUsersFollowedByUser(
  325. api_get_user_id(),
  326. api_is_student_boss() ? null : STUDENT,
  327. false,
  328. false,
  329. false,
  330. null,
  331. null,
  332. null,
  333. null,
  334. 1,
  335. null,
  336. api_is_student_boss() ? STUDENT_BOSS : COURSEMANAGER,
  337. null
  338. );
  339. $supervisorStudents = array_column($supervisorStudents, 'user_id');
  340. //get students with course or session
  341. $userIdList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  342. 'admin',
  343. null,
  344. false,
  345. null,
  346. null,
  347. null,
  348. 'asc',
  349. null,
  350. null,
  351. null,
  352. [],
  353. $supervisorStudents,
  354. 5
  355. );
  356. $userIdList = array_column($userIdList, 'user_id');
  357. //get students session courses
  358. if ($sessionId == -1) {
  359. $sessionList = SessionManager::get_sessions_list();
  360. $sessionIdList = array_column($sessionList, 'id');
  361. $courseCodeList = [];
  362. foreach ($sessionList as $session) {
  363. $courses = SessionManager::get_course_list_by_session_id($session['id']);
  364. $courseCodeList = array_merge($courseCodeList, array_column($courses, 'code'));
  365. }
  366. }
  367. $searchByGroups = true;
  368. } elseif (api_is_platform_admin()) {
  369. // Get students with course or session
  370. $userIdList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  371. 'admin',
  372. null,
  373. false,
  374. null,
  375. null,
  376. null,
  377. 'asc',
  378. null,
  379. null,
  380. null,
  381. [],
  382. [],
  383. 5
  384. );
  385. $userIdList = array_column($userIdList, 'user_id');
  386. //get students session courses
  387. if ($sessionId == -1) {
  388. $sessionList = SessionManager::get_sessions_list();
  389. $sessionIdList = array_column($sessionList, 'id');
  390. $courseCodeList = [];
  391. foreach ($sessionList as $session) {
  392. $courses = SessionManager::get_course_list_by_session_id(
  393. $session['id']
  394. );
  395. $courseCodeList = array_merge(
  396. $courseCodeList,
  397. array_column($courses, 'code')
  398. );
  399. }
  400. }
  401. $searchByGroups = true;
  402. }
  403. if ($searchByGroups) {
  404. $userGroup = new UserGroup();
  405. $userIdList = array_merge(
  406. $userIdList,
  407. $userGroup->getGroupUsersByUser(api_get_user_id())
  408. );
  409. }
  410. if (is_array($userIdList)) {
  411. $userIdList = array_unique($userIdList);
  412. }
  413. if (api_is_student_boss()) {
  414. $userCourses = [];
  415. foreach ($userIdList as $userId) {
  416. $userCourses = array_merge(
  417. $userCourses,
  418. CourseManager::get_courses_list_by_user_id($userId, true)
  419. );
  420. $userSessions = SessionManager::getSessionsFollowedByUser($userId);
  421. $sessionIdList = array_merge(
  422. $sessionIdList,
  423. array_column($userSessions, 'id')
  424. );
  425. }
  426. $courseCodeList = array_column($userCourses, 'code');
  427. }
  428. if (!empty($courseCodeList)) {
  429. $courseCodeList = array_unique($courseCodeList);
  430. }
  431. if (!empty($sessionIdList)) {
  432. $sessionIdList = array_unique($sessionIdList);
  433. }
  434. if (api_is_student_boss() && empty($userIdList)) {
  435. $count = 0;
  436. break;
  437. }
  438. if ($action == 'get_user_course_report') {
  439. $count = CourseManager::get_count_user_list_from_course_code(
  440. false,
  441. null,
  442. $courseCodeList,
  443. $userIdList,
  444. $sessionIdList
  445. );
  446. } else {
  447. $count = CourseManager::get_count_user_list_from_course_code(
  448. true,
  449. ['ruc'],
  450. $courseCodeList,
  451. $userIdList,
  452. $sessionIdList
  453. );
  454. }
  455. break;
  456. case 'get_course_exercise_medias':
  457. $course_id = api_get_course_int_id();
  458. $count = Question::get_count_course_medias($course_id);
  459. break;
  460. case 'get_user_skill_ranking':
  461. $skill = new Skill();
  462. $count = $skill->getUserListSkillRankingCount();
  463. break;
  464. case 'get_course_announcements':
  465. $count = AnnouncementManager::getAnnouncements(null, null, true);
  466. break;
  467. case 'get_work_teacher':
  468. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  469. $count = getWorkListTeacher(0, $limit, $sidx, $sord, $whereCondition, true);
  470. break;
  471. case 'get_work_student':
  472. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  473. $count = getWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true);
  474. break;
  475. case 'get_work_user_list_all':
  476. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  477. $work_id = $_REQUEST['work_id'];
  478. $count = get_count_work($work_id);
  479. break;
  480. case 'get_work_user_list_others':
  481. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  482. $work_id = $_REQUEST['work_id'];
  483. $count = get_count_work($work_id, api_get_user_id());
  484. break;
  485. case 'get_work_user_list':
  486. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  487. $work_id = $_REQUEST['work_id'];
  488. $courseInfo = api_get_course_info();
  489. $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
  490. if (trim($whereCondition) === '1 = 1') {
  491. $whereCondition = '';
  492. }
  493. if (empty($documents)) {
  494. $whereCondition .= " AND u.user_id = ".api_get_user_id();
  495. $count = get_work_user_list(
  496. 0,
  497. $limit,
  498. $sidx,
  499. $sord,
  500. $work_id,
  501. $whereCondition,
  502. null,
  503. true
  504. );
  505. } else {
  506. $count = get_work_user_list_from_documents(
  507. 0,
  508. $limit,
  509. $sidx,
  510. $sord,
  511. $work_id,
  512. api_get_user_id(),
  513. $whereCondition,
  514. true
  515. );
  516. }
  517. break;
  518. case 'get_work_student_list_overview':
  519. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  520. return 0;
  521. }
  522. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  523. $workId = isset($_GET['work_id']) ? $_GET['work_id'] : null;
  524. $count = getWorkUserListData(
  525. $workId,
  526. api_get_course_id(),
  527. api_get_session_id(),
  528. api_get_group_id(),
  529. 0,
  530. $limit,
  531. null,
  532. null,
  533. true
  534. );
  535. break;
  536. case 'get_exercise_results':
  537. $exercise_id = $_REQUEST['exerciseId'];
  538. if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) {
  539. $filter_user = (int) $_GET['filter_by_user'];
  540. if (empty($whereCondition)) {
  541. $whereCondition .= " te.exe_user_id = '$filter_user'";
  542. } else {
  543. $whereCondition .= " AND te.exe_user_id = '$filter_user'";
  544. }
  545. }
  546. if (isset($_GET['group_id_in_toolbar']) && !empty($_GET['group_id_in_toolbar'])) {
  547. $groupIdFromToolbar = (int) $_GET['group_id_in_toolbar'];
  548. if (!empty($groupIdFromToolbar)) {
  549. if (empty($whereCondition)) {
  550. $whereCondition .= " te.group_id = '$groupIdFromToolbar'";
  551. } else {
  552. $whereCondition .= " AND group_id = '$groupIdFromToolbar'";
  553. }
  554. }
  555. }
  556. if (!empty($whereCondition)) {
  557. $whereCondition = " AND $whereCondition";
  558. }
  559. $count = ExerciseLib::get_count_exam_results(
  560. $exercise_id,
  561. $whereCondition
  562. );
  563. break;
  564. case 'get_exercise_results_report':
  565. api_protect_admin_script();
  566. $exerciseId = isset($_REQUEST['exercise_id']) ? $_REQUEST['exercise_id'] : 0;
  567. $courseId = isset($_REQUEST['course_id']) ? $_REQUEST['course_id'] : 0;
  568. if (empty($exerciseId)) {
  569. exit;
  570. }
  571. if (!empty($courseId)) {
  572. $courseInfo = api_get_course_info_by_id($courseId);
  573. } else {
  574. $courseCode = isset($_REQUEST['cidReq']) ? $_REQUEST['cidReq'] : '';
  575. if (!empty($courseCode)) {
  576. $courseInfo = api_get_course_info($courseCode);
  577. }
  578. }
  579. if (empty($courseInfo)) {
  580. exit;
  581. }
  582. $startDate = Database::escape_string($_REQUEST['start_date']);
  583. $whereCondition .= " AND exe_date > '$startDate' AND te.status = '' ";
  584. $count = ExerciseLib::get_count_exam_results(
  585. $exerciseId,
  586. $whereCondition,
  587. $courseInfo['code'],
  588. true
  589. );
  590. break;
  591. case 'get_hotpotatoes_exercise_results':
  592. $hotpot_path = $_REQUEST['path'];
  593. $count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
  594. break;
  595. case 'get_sessions_tracking':
  596. $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
  597. $description = '';
  598. $setting = api_get_setting('show_session_description');
  599. if ($setting === 'true') {
  600. $description = $keyword;
  601. }
  602. if (api_is_drh() || api_is_session_admin()) {
  603. $count = SessionManager::get_sessions_followed_by_drh(
  604. api_get_user_id(),
  605. null,
  606. null,
  607. true,
  608. false,
  609. false,
  610. null,
  611. $keyword,
  612. $description,
  613. ['where' => $whereCondition, 'extra' => $extra_fields]
  614. );
  615. } else {
  616. // Sessions for the coach
  617. $count = Tracking::get_sessions_coached_by_user(
  618. api_get_user_id(),
  619. null,
  620. null,
  621. true,
  622. $keyword,
  623. $description,
  624. null,
  625. null,
  626. ['where' => $whereCondition, 'extra' => $extra_fields]
  627. );
  628. }
  629. break;
  630. case 'get_sessions':
  631. $list_type = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : 'simple';
  632. if ($list_type === 'simple') {
  633. $count = SessionManager::formatSessionsAdminForGrid(
  634. ['where' => $whereCondition, 'extra' => $extra_fields],
  635. true
  636. );
  637. } else {
  638. $count = SessionManager::get_count_admin_complete(
  639. ['where' => $whereCondition, 'extra' => $extra_fields]
  640. );
  641. }
  642. break;
  643. case 'get_session_lp_progress':
  644. case 'get_session_progress':
  645. //@TODO replace this for a more efficient function (not retrieving the whole data)
  646. $course = api_get_course_info_by_id($_GET['course_id']);
  647. $users = CourseManager::get_student_list_from_course_code(
  648. $course['code'],
  649. true,
  650. $_GET['session_id'],
  651. $_GET['date_from'],
  652. $_GET['date_to']
  653. );
  654. $count = count($users);
  655. break;
  656. case 'get_exercise_progress':
  657. //@TODO replace this for a more efficient function (not retrieving the whole data)
  658. $records = Tracking::get_exercise_progress(
  659. $_GET['session_id'],
  660. $_GET['course_id'],
  661. $_GET['exercise_id'],
  662. $_GET['date_from'],
  663. $_GET['date_to']
  664. );
  665. $count = count($records);
  666. break;
  667. case 'get_session_access_overview':
  668. //@TODO replace this for a more efficient function (not retrieving the whole data)
  669. $records = SessionManager::get_user_data_access_tracking_overview(
  670. $_GET['session_id'],
  671. $_GET['course_id'],
  672. $_GET['student_id'],
  673. $_GET['profile'],
  674. $_GET['date_from'],
  675. $_GET['date_to'],
  676. $options
  677. );
  678. $count = count($records);
  679. break;
  680. case 'get_survey_overview':
  681. //@TODO replace this for a more efficient function (not retrieving the whole data)
  682. $records = SessionManager::get_survey_overview(
  683. $_GET['session_id'],
  684. $_GET['course_id'],
  685. $_GET['survey_id'],
  686. $_GET['date_from'],
  687. $_GET['date_to'],
  688. $options
  689. );
  690. $count = count($records);
  691. break;
  692. case 'get_exercise_grade':
  693. //@TODO replace this for a more efficient function (not retrieving the whole data)
  694. $course = api_get_course_info_by_id($_GET['course_id']);
  695. $users = CourseManager::get_student_list_from_course_code(
  696. $course['code'],
  697. true,
  698. $_GET['session_id']
  699. );
  700. $count = count($users);
  701. break;
  702. case 'get_extra_fields':
  703. $type = $_REQUEST['type'];
  704. $obj = new ExtraField($type);
  705. $count = $obj->get_count();
  706. break;
  707. case 'get_extra_field_options':
  708. $type = $_REQUEST['type'];
  709. $field_id = $_REQUEST['field_id'];
  710. $obj = new ExtraFieldOption($type);
  711. $count = $obj->get_count_by_field_id($field_id);
  712. break;
  713. case 'get_timelines':
  714. $obj = new Timeline();
  715. $count = $obj->get_count();
  716. break;
  717. case 'get_gradebooks':
  718. $obj = new Gradebook();
  719. $count = $obj->get_count();
  720. break;
  721. case 'get_event_email_template':
  722. $obj = new EventEmailTemplate();
  723. $count = $obj->get_count();
  724. break;
  725. case 'get_careers':
  726. $obj = new Career();
  727. $count = $obj->get_count();
  728. break;
  729. case 'get_promotions':
  730. $obj = new Promotion();
  731. $count = $obj->get_count();
  732. break;
  733. case 'get_mail_template':
  734. $obj = new MailTemplateManager();
  735. $count = $obj->get_count();
  736. break;
  737. case 'get_grade_models':
  738. $obj = new GradeModel();
  739. $count = $obj->get_count();
  740. break;
  741. case 'get_usergroups':
  742. $obj = new UserGroup();
  743. $obj->protectScript();
  744. $count = $obj->get_count();
  745. break;
  746. case 'get_usergroups_teacher':
  747. $obj = new UserGroup();
  748. $obj->protectScript(null, false, true);
  749. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
  750. $groupFilter = isset($_REQUEST['group_filter']) ? (int) $_REQUEST['group_filter'] : 0;
  751. $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
  752. $course_id = api_get_course_int_id();
  753. $options = [];
  754. $options['course_id'] = $course_id;
  755. switch ($type) {
  756. case 'not_registered':
  757. $options['where'] = [' (course_id IS NULL OR course_id != ?) ' => $course_id];
  758. if (!empty($keyword)) {
  759. $options['where']['AND name like %?% '] = $keyword;
  760. }
  761. $count = $obj->getUserGroupNotInCourse($options, $groupFilter, true);
  762. break;
  763. case 'registered':
  764. $options['where'] = [' usergroup.course_id = ? ' => $course_id];
  765. $count = $obj->getUserGroupInCourse(
  766. $options,
  767. $groupFilter,
  768. true
  769. );
  770. break;
  771. }
  772. break;
  773. default:
  774. exit;
  775. }
  776. // 3. Calculating first, end, etc
  777. $total_pages = 0;
  778. if ($count > 0) {
  779. if (!empty($limit)) {
  780. $total_pages = ceil((float) $count / (float) $limit);
  781. }
  782. }
  783. if ($page > $total_pages) {
  784. $page = $total_pages;
  785. }
  786. $start = $limit * $page - $limit;
  787. if ($start < 0) {
  788. $start = 0;
  789. }
  790. //4. Deleting an element if the user wants to
  791. if (isset($_REQUEST['oper']) && $_REQUEST['oper'] == 'del') {
  792. $obj->delete($_REQUEST['id']);
  793. }
  794. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh();
  795. //5. Querying the DB for the elements
  796. $columns = [];
  797. switch ($action) {
  798. case 'get_exercise_categories':
  799. api_protect_course_script();
  800. if (!api_is_allowed_to_edit()) {
  801. api_not_allowed(true);
  802. }
  803. $columns = ['name', 'actions'];
  804. $manager = new ExerciseCategoryManager();
  805. $result = $manager->get_all([
  806. 'where' => ['c_id = ? ' => $courseId],
  807. 'order' => "$sidx $sord",
  808. 'LIMIT' => "$start , $limit",
  809. ]);
  810. break;
  811. case 'get_calendar_users':
  812. $columns = ['firstname', 'lastname', 'exam'];
  813. $result = $calendarPlugin->getUsersPerCalendar($id);
  814. break;
  815. case 'get_usergroups_users':
  816. $columns = ['name', 'actions'];
  817. if (api_get_plugin_setting('learning_calendar', 'enabled') === 'true') {
  818. $columns = [
  819. 'name',
  820. 'calendar',
  821. 'gradebook_items',
  822. 'time_spent',
  823. 'lp_day_completed',
  824. 'days_diff',
  825. 'actions',
  826. 'calendar_id',
  827. ];
  828. }
  829. $result = $usergroup->getUserGroupUsers($id);
  830. break;
  831. case 'get_learning_path_calendars':
  832. $columns = ['title', 'total_hours', 'minutes_per_day', 'actions'];
  833. $result = $calendarPlugin->getCalendars(
  834. $start,
  835. $limit,
  836. $sidx,
  837. $sord
  838. );
  839. break;
  840. case 'course_log_events':
  841. $columns = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
  842. $result = Statistics::getActivitiesData(
  843. $start,
  844. $limit,
  845. $sidx,
  846. $sord,
  847. $courseId,
  848. $sessionId
  849. );
  850. break;
  851. case 'get_programmed_announcements':
  852. $columns = ['subject', 'date', 'sent', 'actions'];
  853. $sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : 0;
  854. $result = Database::select(
  855. '*',
  856. $object->table,
  857. [
  858. 'where' => ['session_id = ? ' => $sessionId],
  859. 'order' => "$sidx $sord",
  860. 'LIMIT' => "$start , $limit", ]
  861. );
  862. if ($result) {
  863. foreach ($result as &$item) {
  864. $item['sent'] = $item['sent'] == 1 ? get_lang('Yes') : get_lang('No');
  865. $item['date'] = api_get_local_time($item['date']);
  866. }
  867. }
  868. break;
  869. case 'get_group_reporting':
  870. $columns = ['name', 'time', 'progress', 'score', 'works', 'messages', 'actions'];
  871. $result = Tracking::get_group_reporting(
  872. $course_id,
  873. $sessionId,
  874. $group_id,
  875. 'all',
  876. $start,
  877. $limit,
  878. $sidx,
  879. $sord,
  880. $whereCondition
  881. );
  882. break;
  883. case 'get_course_exercise_medias':
  884. $columns = ['question'];
  885. $result = Question::get_course_medias(
  886. $course_id,
  887. $start,
  888. $limit,
  889. $sidx,
  890. $sord,
  891. $whereCondition
  892. );
  893. break;
  894. case 'get_user_course_report_resumed':
  895. $columns = [
  896. 'extra_ruc',
  897. 'training_hours',
  898. 'count_users',
  899. 'count_users_registered',
  900. 'average_hours_per_user',
  901. 'count_certificates',
  902. ];
  903. $column_names = [
  904. get_lang('Company'),
  905. get_lang('TrainingHoursAccumulated'),
  906. get_lang('CountOfSubscriptions'),
  907. get_lang('CountOfUsers'),
  908. get_lang('AverageHoursPerStudent'),
  909. get_lang('CountCertificates'),
  910. ];
  911. $extra_fields = UserManager::get_extra_fields(
  912. 0,
  913. 100,
  914. null,
  915. null,
  916. true,
  917. true
  918. );
  919. if (!empty($extra_fields)) {
  920. foreach ($extra_fields as $extra) {
  921. if ($extra['1'] == 'ruc') {
  922. continue;
  923. }
  924. $columns[] = $extra['1'];
  925. $column_names[] = $extra['3'];
  926. }
  927. }
  928. if (!in_array($sidx, ['training_hours'])) {
  929. //$sidx = 'training_hours';
  930. }
  931. if (api_is_student_boss() && empty($userIdList)) {
  932. $result = [];
  933. break;
  934. }
  935. $result = CourseManager::get_user_list_from_course_code(
  936. null,
  937. null,
  938. "LIMIT $start, $limit",
  939. null, //" $sidx $sord",
  940. null,
  941. null,
  942. true,
  943. true,
  944. ['ruc'],
  945. $courseCodeList,
  946. $userIdList,
  947. null,
  948. $sessionIdList
  949. );
  950. $new_result = [];
  951. if (!empty($result)) {
  952. foreach ($result as $row) {
  953. $row['training_hours'] = api_time_to_hms($row['training_hours']);
  954. $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']);
  955. $new_result[] = $row;
  956. }
  957. $result = $new_result;
  958. }
  959. break;
  960. case 'get_user_course_report':
  961. $columns = [
  962. 'course',
  963. 'user',
  964. 'email',
  965. 'time',
  966. 'certificate',
  967. 'progress_100',
  968. 'progress',
  969. ];
  970. $column_names = [
  971. get_lang('Course'),
  972. get_lang('User'),
  973. get_lang('Email'),
  974. get_lang('ManHours'),
  975. get_lang('CertificateGenerated'),
  976. get_lang('Approved'),
  977. get_lang('CourseAdvance'),
  978. ];
  979. $extra_fields = UserManager::get_extra_fields(
  980. 0,
  981. 100,
  982. null,
  983. null,
  984. true,
  985. true
  986. );
  987. if (!empty($extra_fields)) {
  988. foreach ($extra_fields as $extra) {
  989. $columns[] = $extra['1'];
  990. $column_names[] = $extra['3'];
  991. }
  992. }
  993. if (api_is_student_boss()) {
  994. $columns[] = 'group';
  995. $column_names[] = get_lang('Group');
  996. }
  997. if (!in_array($sidx, ['title'])) {
  998. $sidx = 'title';
  999. }
  1000. if (api_is_student_boss() && empty($userIdList)) {
  1001. $result = [];
  1002. break;
  1003. }
  1004. //get sessions
  1005. $arrSessions = [];
  1006. if (count($sessionIdList) > 0) {
  1007. $arrSessions = CourseManager::get_user_list_from_course_code(
  1008. null,
  1009. null,
  1010. "LIMIT $start, $limit",
  1011. " $sidx $sord",
  1012. null,
  1013. null,
  1014. true,
  1015. false,
  1016. null,
  1017. $courseCodeList,
  1018. $userIdList,
  1019. null,
  1020. $sessionIdList
  1021. );
  1022. }
  1023. //get courses
  1024. $arrCourses = CourseManager::get_user_list_from_course_code(
  1025. null,
  1026. null,
  1027. "LIMIT $start, $limit",
  1028. " $sidx $sord",
  1029. null,
  1030. null,
  1031. true,
  1032. false,
  1033. null,
  1034. [],
  1035. $userIdList,
  1036. null
  1037. );
  1038. //merge courses and sessions
  1039. $result = array_merge($arrSessions, $arrCourses);
  1040. if (api_is_student_boss()) {
  1041. $userGroup = new UserGroup();
  1042. foreach ($result as &$item) {
  1043. $userGroups = $userGroup->get_groups_by_user($item['user_id']);
  1044. $item['group'] = implode(", ", array_column($userGroups, 'name'));
  1045. unset($item['user_id']);
  1046. }
  1047. }
  1048. break;
  1049. case 'get_user_skill_ranking':
  1050. $columns = [
  1051. 'photo',
  1052. 'firstname',
  1053. 'lastname',
  1054. 'skills_acquired',
  1055. 'currently_learning',
  1056. 'rank',
  1057. ];
  1058. $result = $skill->getUserListSkillRanking(
  1059. $start,
  1060. $limit,
  1061. $sidx,
  1062. $sord,
  1063. $whereCondition
  1064. );
  1065. $result = msort($result, 'skills_acquired', 'asc');
  1066. $skills_in_course = [];
  1067. if (!empty($result)) {
  1068. foreach ($result as &$item) {
  1069. $user_info = api_get_user_info($item['user_id']);
  1070. $personal_course_list = UserManager::get_personal_session_course_list(
  1071. $item['user_id']
  1072. );
  1073. $count_skill_by_course = [];
  1074. foreach ($personal_course_list as $course_item) {
  1075. if (!isset($skills_in_course[$course_item['code']])) {
  1076. $count_skill_by_course[$course_item['code']] = $skill->getCountSkillsByCourse($course_item['code']);
  1077. $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
  1078. } else {
  1079. $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
  1080. }
  1081. }
  1082. $item['photo'] = Display::img($user_info['avatar_small'], $user_info['complete_name'], [], false);
  1083. $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
  1084. }
  1085. }
  1086. break;
  1087. case 'get_course_announcements':
  1088. $columns = [
  1089. 'title',
  1090. 'username',
  1091. 'insert_date',
  1092. 'actions',
  1093. ];
  1094. $titleToSearch = isset($_REQUEST['title_to_search']) ? $_REQUEST['title_to_search'] : '';
  1095. $userIdToSearch = isset($_REQUEST['user_id_to_search']) ? $_REQUEST['user_id_to_search'] : 0;
  1096. $result = AnnouncementManager::getAnnouncements(
  1097. null,
  1098. null,
  1099. false,
  1100. $start,
  1101. $limit,
  1102. $sidx,
  1103. $sord,
  1104. $titleToSearch,
  1105. $userIdToSearch
  1106. );
  1107. break;
  1108. case 'get_work_teacher':
  1109. $columns = [
  1110. 'type',
  1111. 'title',
  1112. 'sent_date',
  1113. 'expires_on',
  1114. 'amount',
  1115. 'actions',
  1116. ];
  1117. $result = getWorkListTeacher(
  1118. $start,
  1119. $limit,
  1120. $sidx,
  1121. $sord,
  1122. $whereCondition
  1123. );
  1124. break;
  1125. case 'get_work_student':
  1126. $columns = [
  1127. 'type',
  1128. 'title',
  1129. 'expires_on',
  1130. 'feedback',
  1131. 'last_upload',
  1132. 'others',
  1133. ];
  1134. $result = getWorkListStudent(
  1135. $start,
  1136. $limit,
  1137. $sidx,
  1138. $sord,
  1139. $whereCondition
  1140. );
  1141. break;
  1142. case 'get_work_user_list_all':
  1143. $plagiarismColumns = [];
  1144. if (api_get_configuration_value('allow_compilatio_tool')) {
  1145. $plagiarismColumns = ['compilatio'];
  1146. }
  1147. if (isset($_GET['type']) && $_GET['type'] === 'simple') {
  1148. $columns = [
  1149. 'fullname',
  1150. 'title',
  1151. 'qualification',
  1152. 'sent_date',
  1153. 'qualificator_id',
  1154. 'correction',
  1155. ];
  1156. $columns = array_merge($columns, $plagiarismColumns);
  1157. $columns[] = 'actions';
  1158. } else {
  1159. $columns = [
  1160. 'fullname',
  1161. 'title',
  1162. 'qualification',
  1163. 'sent_date',
  1164. 'correction',
  1165. ];
  1166. $columns = array_merge($columns, $plagiarismColumns);
  1167. $columns[] = 'actions';
  1168. }
  1169. $whereCondition = " AND $whereCondition ";
  1170. $result = get_work_user_list(
  1171. $start,
  1172. $limit,
  1173. $sidx,
  1174. $sord,
  1175. $work_id,
  1176. $whereCondition
  1177. );
  1178. break;
  1179. case 'get_work_user_list_others':
  1180. $plagiarismColumns = [];
  1181. if (api_get_configuration_value('allow_compilatio_tool')) {
  1182. $plagiarismColumns = ['compilatio'];
  1183. }
  1184. if (isset($_GET['type']) && $_GET['type'] === 'simple') {
  1185. $columns = [
  1186. 'type', 'firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id',
  1187. ];
  1188. $columns = array_merge($columns, $plagiarismColumns);
  1189. $columns[] = 'actions';
  1190. } else {
  1191. $columns = ['type', 'firstname', 'lastname', 'title', 'sent_date'];
  1192. $columns = array_merge($columns, $plagiarismColumns);
  1193. $columns[] = 'actions';
  1194. }
  1195. if (trim($whereCondition) === '1 = 1') {
  1196. $whereCondition = '';
  1197. }
  1198. $whereCondition .= " AND u.user_id <> ".api_get_user_id();
  1199. $result = get_work_user_list(
  1200. $start,
  1201. $limit,
  1202. $sidx,
  1203. $sord,
  1204. $work_id,
  1205. $whereCondition
  1206. );
  1207. break;
  1208. case 'get_work_user_list':
  1209. $plagiarismColumns = [];
  1210. if (api_get_configuration_value('allow_compilatio_tool')) {
  1211. $plagiarismColumns = ['compilatio'];
  1212. }
  1213. if (isset($_GET['type']) && $_GET['type'] == 'simple') {
  1214. $columns = [
  1215. 'type', 'title', 'qualification', 'sent_date', 'qualificator_id',
  1216. ];
  1217. $columns = array_merge($columns, $plagiarismColumns);
  1218. $columns[] = 'actions';
  1219. } else {
  1220. $columns = ['type', 'title', 'qualification', 'sent_date'];
  1221. $columns = array_merge($columns, $plagiarismColumns);
  1222. $columns[] = 'actions';
  1223. }
  1224. $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
  1225. if (trim($whereCondition) === '1 = 1') {
  1226. $whereCondition = '';
  1227. }
  1228. if (empty($documents)) {
  1229. $whereCondition .= ' AND u.user_id = '.api_get_user_id();
  1230. $result = get_work_user_list(
  1231. $start,
  1232. $limit,
  1233. $sidx,
  1234. $sord,
  1235. $work_id,
  1236. $whereCondition
  1237. );
  1238. } else {
  1239. $result = get_work_user_list_from_documents(
  1240. $start,
  1241. $limit,
  1242. $sidx,
  1243. $sord,
  1244. $work_id,
  1245. api_get_user_id(),
  1246. $whereCondition
  1247. );
  1248. }
  1249. break;
  1250. case 'get_exercise_results':
  1251. $is_allowedToEdit = api_is_allowed_to_edit(null, true) ||
  1252. api_is_drh() ||
  1253. api_is_student_boss() ||
  1254. api_is_session_admin();
  1255. if ($is_allowedToEdit || api_is_student_boss()) {
  1256. $columns = [
  1257. 'firstname',
  1258. 'lastname',
  1259. 'username',
  1260. 'group_name',
  1261. 'exe_duration',
  1262. 'start_date',
  1263. 'exe_date',
  1264. 'score',
  1265. 'user_ip',
  1266. 'status',
  1267. 'lp',
  1268. 'actions',
  1269. ];
  1270. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  1271. if ($officialCodeInList === 'true') {
  1272. $columns = array_merge(['official_code'], $columns);
  1273. }
  1274. }
  1275. $result = ExerciseLib::get_exam_results_data(
  1276. $start,
  1277. $limit,
  1278. $sidx,
  1279. $sord,
  1280. $exercise_id,
  1281. $whereCondition
  1282. );
  1283. break;
  1284. case 'get_exercise_results_report':
  1285. $columns = [
  1286. 'firstname',
  1287. 'lastname',
  1288. 'username',
  1289. ];
  1290. $extraFieldsToAdd = [];
  1291. $extraFields = api_get_configuration_value('exercise_category_report_user_extra_fields');
  1292. $roundValues = api_get_configuration_value('exercise_category_round_score_in_export');
  1293. if (!empty($extraFields) && isset($extraFields['fields'])) {
  1294. $extraField = new ExtraField('user');
  1295. foreach ($extraFields['fields'] as $variable) {
  1296. $info = $extraField->get_handler_field_info_by_field_variable($variable);
  1297. if ($info) {
  1298. $extraFieldsToAdd[] = $variable;
  1299. }
  1300. }
  1301. }
  1302. if (!empty($extraFieldsToAdd)) {
  1303. $columns = array_merge($columns, $extraFieldsToAdd);
  1304. }
  1305. $columns[] = 'session';
  1306. $columns[] = 'session_access_start_date';
  1307. $columns[] = 'exe_date';
  1308. $columns[] = 'score';
  1309. if ($operation === 'excel') {
  1310. $columns = [
  1311. 'firstname',
  1312. 'lastname',
  1313. 'username',
  1314. ];
  1315. if (!empty($extraFieldsToAdd)) {
  1316. $columns = array_merge($columns, $extraFieldsToAdd);
  1317. }
  1318. $columns[] = 'session';
  1319. $columns[] = 'session_access_start_date';
  1320. $columns[] = 'exe_date';
  1321. $columns[] = 'score_percentage';
  1322. $columns[] = 'only_score';
  1323. $columns[] = 'total';
  1324. $overwriteColumnHeaderExport['session_access_start_date'] = get_lang('SessionStartDate');
  1325. $overwriteColumnHeaderExport['exe_date'] = get_lang('StartDate');
  1326. $overwriteColumnHeaderExport['score_percentage'] = get_lang('Score').' - '.get_lang('Percentage');
  1327. $overwriteColumnHeaderExport['only_score'] = get_lang('Score').' - '.get_lang('ScoreNote');
  1328. $overwriteColumnHeaderExport['total'] = get_lang('Score').' - '.get_lang('ScoreTest');
  1329. }
  1330. $categoryList = TestCategory::getListOfCategoriesIDForTest($exerciseId, $courseId);
  1331. if (!empty($categoryList)) {
  1332. foreach ($categoryList as $categoryInfo) {
  1333. $label = 'category_'.$categoryInfo['id'];
  1334. if ($operation == 'excel') {
  1335. $columns[] = $label.'_score_percentage';
  1336. $columns[] = $label.'_only_score';
  1337. $columns[] = $label.'_total';
  1338. $overwriteColumnHeaderExport[$label] = $categoryInfo['title'];
  1339. $overwriteColumnHeaderExport[$label.'_score_percentage'] = $categoryInfo['title'].
  1340. ' - '.get_lang('Percentage');
  1341. $overwriteColumnHeaderExport[$label.'_only_score'] = $categoryInfo['title'].
  1342. ' - '.get_lang('ScoreNote');
  1343. $overwriteColumnHeaderExport[$label.'_total'] = $categoryInfo['title'].
  1344. ' - '.get_lang('ScoreTest');
  1345. } else {
  1346. $columns[] = $label;
  1347. }
  1348. }
  1349. }
  1350. if ($operation !== 'excel') {
  1351. $columns[] = 'actions';
  1352. }
  1353. $whereCondition .= " AND te.status = '' ";
  1354. $result = ExerciseLib::get_exam_results_data(
  1355. $start,
  1356. $limit,
  1357. $sidx,
  1358. $sord,
  1359. $exerciseId,
  1360. $whereCondition,
  1361. false,
  1362. $courseInfo['code'],
  1363. true,
  1364. true,
  1365. $extraFieldsToAdd,
  1366. true,
  1367. $roundValues
  1368. );
  1369. break;
  1370. case 'get_hotpotatoes_exercise_results':
  1371. $course = api_get_course_info();
  1372. $documentPath = api_get_path(SYS_COURSE_PATH).$course['path']."/document";
  1373. if (api_is_allowed_to_edit()) {
  1374. $columns = ['firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions'];
  1375. } else {
  1376. $columns = ['exe_date', 'score', 'actions'];
  1377. }
  1378. $result = ExerciseLib::get_exam_results_hotpotatoes_data(
  1379. $start,
  1380. $limit,
  1381. $sidx,
  1382. $sord,
  1383. $hotpot_path,
  1384. $whereCondition
  1385. );
  1386. break;
  1387. case 'get_work_student_list_overview':
  1388. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  1389. return [];
  1390. }
  1391. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  1392. $columns = [
  1393. 'student', 'works',
  1394. ];
  1395. $result = getWorkUserListData(
  1396. $workId,
  1397. api_get_course_id(),
  1398. api_get_session_id(),
  1399. api_get_group_id(),
  1400. $start,
  1401. $limit,
  1402. $sidx,
  1403. $sord
  1404. );
  1405. break;
  1406. case 'get_hotpotatoes_exercise_results':
  1407. $course = api_get_course_info();
  1408. $documentPath = api_get_path(SYS_COURSE_PATH).$course['path']."/document";
  1409. if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
  1410. $columns = ['firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions'];
  1411. } else {
  1412. $columns = ['exe_date', 'score', 'actions'];
  1413. }
  1414. $result = ExerciseLib::get_exam_results_hotpotatoes_data(
  1415. $start,
  1416. $limit,
  1417. $sidx,
  1418. $sord,
  1419. $hotpot_path,
  1420. $whereCondition
  1421. );
  1422. break;
  1423. case 'get_sessions_tracking':
  1424. if (api_is_drh() || api_is_session_admin()) {
  1425. $orderByName = Database::escape_string($sidx);
  1426. $orderByName = in_array($orderByName, ['name', 'access_start_date']) ? $orderByName : 'name';
  1427. $orderBy = " ORDER BY $orderByName $sord";
  1428. $sessions = SessionManager::get_sessions_followed_by_drh(
  1429. api_get_user_id(),
  1430. $start,
  1431. $limit,
  1432. false,
  1433. false,
  1434. false,
  1435. $orderBy,
  1436. $keyword,
  1437. $description,
  1438. ['where' => $whereCondition, 'extra' => $extra_fields]
  1439. );
  1440. } else {
  1441. // Sessions for the coach
  1442. $sessions = Tracking::get_sessions_coached_by_user(
  1443. api_get_user_id(),
  1444. $start,
  1445. $limit,
  1446. false,
  1447. $keyword,
  1448. $description,
  1449. $sidx,
  1450. $sord,
  1451. ['where' => $whereCondition, 'extra' => $extra_fields]
  1452. );
  1453. }
  1454. $session_columns = SessionManager::getGridColumns('my_space');
  1455. $columns = $session_columns['simple_column_name'];
  1456. $result = [];
  1457. if (!empty($sessions)) {
  1458. foreach ($sessions as $session) {
  1459. if (api_drh_can_access_all_session_content()) {
  1460. $count_courses_in_session = SessionManager::get_course_list_by_session_id(
  1461. $session['id'],
  1462. '',
  1463. null,
  1464. true
  1465. );
  1466. } else {
  1467. $count_courses_in_session = count(
  1468. Tracking::get_courses_followed_by_coach(
  1469. $user_id,
  1470. $session['id']
  1471. )
  1472. );
  1473. }
  1474. $count_users_in_session = SessionManager::get_users_by_session(
  1475. $session['id'],
  1476. 0,
  1477. true
  1478. );
  1479. $session['display_start_date'] = '';
  1480. $session['display_end_date'] = '';
  1481. $session['coach_access_start_date'] = '';
  1482. $session['coach_access_end_date'] = '';
  1483. $dateData = SessionManager::parseSessionDates($session, true);
  1484. $dateToString = $dateData['access'];
  1485. $detailButtons = [];
  1486. $detailButtons[] = Display::url(
  1487. Display::return_icon('works.png', get_lang('WorksReport')),
  1488. api_get_path(WEB_CODE_PATH).'mySpace/works_in_session_report.php?session='.$session['id']
  1489. );
  1490. $detailButtons[] = Display::url(
  1491. Display::return_icon('2rightarrow.png'),
  1492. api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id']
  1493. );
  1494. $item = [
  1495. 'name' => Display::url(
  1496. $session['name'],
  1497. api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id']
  1498. ),
  1499. 'date' => $dateToString,
  1500. 'course_per_session' => $count_courses_in_session,
  1501. 'student_per_session' => $count_users_in_session,
  1502. 'actions' => implode(' ', $detailButtons),
  1503. ];
  1504. if (!empty($extra_fields)) {
  1505. foreach ($extra_fields as $extraField) {
  1506. $item[$extraField['field']] = $extraField['data'];
  1507. }
  1508. }
  1509. $result[] = $item;
  1510. }
  1511. }
  1512. break;
  1513. case 'get_sessions':
  1514. $session_columns = SessionManager::getGridColumns($list_type);
  1515. $columns = $session_columns['simple_column_name'];
  1516. if ($list_type == 'simple') {
  1517. $result = SessionManager::formatSessionsAdminForGrid(
  1518. [
  1519. 'where' => $whereCondition,
  1520. 'order' => "$sidx $sord, s.name",
  1521. 'extra' => $extra_fields,
  1522. 'limit' => "$start , $limit",
  1523. ],
  1524. false,
  1525. $session_columns
  1526. );
  1527. } else {
  1528. $result = SessionManager::get_sessions_admin_complete(
  1529. [
  1530. 'where' => $whereCondition,
  1531. 'order' => "$sidx $sord, s.name",
  1532. 'extra' => $extra_fields,
  1533. 'limit' => "$start , $limit",
  1534. ]
  1535. );
  1536. }
  1537. break;
  1538. case 'get_exercise_progress':
  1539. $sessionId = (int) $_GET['session_id'];
  1540. $courseId = (int) $_GET['course_id'];
  1541. $exerciseId = (int) $_GET['exercise_id'];
  1542. $date_from = $_GET['date_from'];
  1543. $date_to = $_GET['date_to'];
  1544. $columns = [
  1545. 'session',
  1546. 'exercise_id',
  1547. 'quiz_title',
  1548. 'username',
  1549. 'lastname',
  1550. 'firstname',
  1551. 'time',
  1552. 'question_id',
  1553. 'question',
  1554. 'description',
  1555. 'answer',
  1556. 'correct',
  1557. ];
  1558. $result = Tracking::get_exercise_progress(
  1559. $sessionId,
  1560. $courseId,
  1561. $exerciseId,
  1562. $date_from,
  1563. $date_to,
  1564. [
  1565. 'where' => $whereCondition,
  1566. 'order' => "$sidx $sord",
  1567. 'limit' => "$start , $limit",
  1568. ]
  1569. );
  1570. break;
  1571. case 'get_session_lp_progress':
  1572. $sessionId = 0;
  1573. if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) {
  1574. $sessionId = (int) $_GET['session_id'];
  1575. $courseId = (int) $_GET['course_id'];
  1576. $course = api_get_course_info_by_id($courseId);
  1577. }
  1578. /**
  1579. * Add lessons of course.
  1580. */
  1581. $columns = [
  1582. 'username',
  1583. 'firstname',
  1584. 'lastname',
  1585. ];
  1586. $lessons = LearnpathList::get_course_lessons(
  1587. $course['code'],
  1588. $sessionId
  1589. );
  1590. foreach ($lessons as $lesson_id => $lesson) {
  1591. $columns[] = $lesson_id;
  1592. }
  1593. $columns[] = 'total';
  1594. $result = SessionManager::get_session_lp_progress(
  1595. $sessionId,
  1596. $courseId,
  1597. $date_from,
  1598. $date_to,
  1599. [
  1600. 'where' => $whereCondition,
  1601. 'order' => "$sidx $sord",
  1602. 'limit' => "$start , $limit",
  1603. ]
  1604. );
  1605. break;
  1606. case 'get_survey_overview':
  1607. $sessionId = 0;
  1608. if (!empty($_GET['session_id']) &&
  1609. !empty($_GET['course_id']) &&
  1610. !empty($_GET['survey_id'])
  1611. ) {
  1612. $sessionId = intval($_GET['session_id']);
  1613. $courseId = intval($_GET['course_id']);
  1614. $surveyId = intval($_GET['survey_id']);
  1615. $date_from = $_GET['date_from'];
  1616. $date_to = $_GET['date_to'];
  1617. //$course = api_get_course_info_by_id($courseId);
  1618. }
  1619. /**
  1620. * Add lessons of course.
  1621. */
  1622. $columns = [
  1623. 'username',
  1624. 'firstname',
  1625. 'lastname',
  1626. ];
  1627. $questions = SurveyManager::get_questions($surveyId, $courseId);
  1628. foreach ($questions as $question_id => $question) {
  1629. $columns[] = $question_id;
  1630. }
  1631. $result = SessionManager::get_survey_overview(
  1632. $sessionId,
  1633. $courseId,
  1634. $surveyId,
  1635. $date_from,
  1636. $date_to,
  1637. [
  1638. 'where' => $whereCondition,
  1639. 'order' => "$sidx $sord",
  1640. 'limit' => "$start , $limit",
  1641. ]
  1642. );
  1643. break;
  1644. case 'get_session_progress':
  1645. $columns = [
  1646. 'lastname',
  1647. 'firstname',
  1648. 'username',
  1649. //'profile',
  1650. 'total',
  1651. 'courses',
  1652. 'lessons',
  1653. 'exercises',
  1654. 'forums',
  1655. 'homeworks',
  1656. 'wikis',
  1657. 'surveys',
  1658. //exercises
  1659. 'lessons_total',
  1660. 'lessons_done',
  1661. 'lessons_left',
  1662. 'lessons_progress',
  1663. //exercises
  1664. 'exercises_total',
  1665. 'exercises_done',
  1666. 'exercises_left',
  1667. 'exercises_progress',
  1668. //forums
  1669. 'forums_total',
  1670. 'forums_done',
  1671. 'forums_left',
  1672. 'forums_progress',
  1673. //assignments
  1674. 'assignments_total',
  1675. 'assignments_done',
  1676. 'assignments_left',
  1677. 'assignments_progress',
  1678. //Wiki
  1679. 'wiki_total',
  1680. 'wiki_revisions',
  1681. 'wiki_read',
  1682. 'wiki_unread',
  1683. 'wiki_progress',
  1684. //surveys
  1685. 'surveys_total',
  1686. 'surveys_done',
  1687. 'surveys_left',
  1688. 'surveys_progress',
  1689. ];
  1690. $sessionId = 0;
  1691. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  1692. $sessionId = intval($_GET['session_id']);
  1693. $courseId = intval($_GET['course_id']);
  1694. }
  1695. $result = SessionManager::get_session_progress(
  1696. $sessionId,
  1697. $courseId,
  1698. null,
  1699. null,
  1700. [
  1701. 'where' => $whereCondition,
  1702. 'order' => "$sidx $sord",
  1703. 'limit' => "$start , $limit",
  1704. ]
  1705. );
  1706. break;
  1707. case 'get_session_access_overview':
  1708. $columns = [
  1709. 'logindate',
  1710. 'username',
  1711. 'lastname',
  1712. 'firstname',
  1713. 'clicks',
  1714. 'ip',
  1715. 'timeLoggedIn',
  1716. 'session',
  1717. ];
  1718. $sessionId = 0;
  1719. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  1720. $sessionId = intval($_GET['session_id']);
  1721. $courseId = intval($_GET['course_id']);
  1722. $studentId = intval($_GET['student_id']);
  1723. $profile = intval($_GET['profile']);
  1724. $date_from = intval($_GET['date_from']);
  1725. $date_to = intval($_GET['date_to']);
  1726. }
  1727. $result = SessionManager::get_user_data_access_tracking_overview(
  1728. $sessionId,
  1729. $courseId,
  1730. $studentId,
  1731. $profile,
  1732. $date_to,
  1733. $date_from,
  1734. [
  1735. 'where' => $whereCondition,
  1736. 'order' => "$sidx $sord",
  1737. 'limit' => "$start , $limit",
  1738. ]
  1739. );
  1740. break;
  1741. case 'get_timelines':
  1742. $columns = ['headline', 'actions'];
  1743. if (!in_array($sidx, $columns)) {
  1744. $sidx = 'headline';
  1745. }
  1746. $course_id = api_get_course_int_id();
  1747. $result = Database::select(
  1748. '*',
  1749. $obj->table,
  1750. [
  1751. 'where' => [
  1752. 'parent_id = ? AND c_id = ?' => ['0', $course_id],
  1753. ],
  1754. 'order' => "$sidx $sord",
  1755. 'LIMIT' => "$start , $limit",
  1756. ]
  1757. );
  1758. $new_result = [];
  1759. foreach ($result as $item) {
  1760. if (!$item['status']) {
  1761. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1762. }
  1763. $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH).'timeline/view.php?id='.$item['id']);
  1764. $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']);
  1765. $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH).'timeline/?action=edit&id='.$item['id']);
  1766. $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH).'timeline/?action=delete&id='.$item['id']);
  1767. $new_result[] = $item;
  1768. }
  1769. $result = $new_result;
  1770. break;
  1771. case 'get_gradebooks':
  1772. $columns = ['name', 'certificates', 'skills', 'actions', 'has_certificates'];
  1773. if (!in_array($sidx, $columns)) {
  1774. $sidx = 'name';
  1775. }
  1776. $result = Database::select(
  1777. '*',
  1778. $obj->table,
  1779. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1780. );
  1781. $new_result = [];
  1782. foreach ($result as $item) {
  1783. if ($item['parent_id'] != 0) {
  1784. continue;
  1785. }
  1786. $skills = $obj->getSkillsByGradebook($item['id']);
  1787. //Fixes bug when gradebook doesn't have names
  1788. if (empty($item['name'])) {
  1789. $item['name'] = $item['course_code'];
  1790. }
  1791. $item['name'] = Display::url(
  1792. $item['name'],
  1793. api_get_path(WEB_CODE_PATH).'gradebook/index.php?id_session=0&cidReq='.$item['course_code']
  1794. );
  1795. if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
  1796. $item['certificates'] = Display::return_icon(
  1797. 'accept.png',
  1798. get_lang('WithCertificate'),
  1799. [],
  1800. ICON_SIZE_SMALL
  1801. );
  1802. $item['has_certificates'] = '1';
  1803. } else {
  1804. $item['certificates'] = Display::return_icon(
  1805. 'warning.png',
  1806. get_lang('NoCertificate'),
  1807. [],
  1808. ICON_SIZE_SMALL
  1809. );
  1810. $item['has_certificates'] = '0';
  1811. }
  1812. if (!empty($skills)) {
  1813. $item['skills'] = '';
  1814. foreach ($skills as $skill) {
  1815. $item['skills'] .= Display::span($skill['name'], ['class' => 'label_tag skill']);
  1816. }
  1817. }
  1818. $new_result[] = $item;
  1819. }
  1820. $result = $new_result;
  1821. break;
  1822. case 'get_event_email_template':
  1823. $columns = ['subject', 'event_type_name', 'language_id', 'activated', 'actions'];
  1824. if (!in_array($sidx, $columns)) {
  1825. $sidx = 'subject';
  1826. }
  1827. $result = Database::select(
  1828. '*',
  1829. $obj->table,
  1830. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1831. );
  1832. $new_result = [];
  1833. foreach ($result as $item) {
  1834. $language_info = api_get_language_info($item['language_id']);
  1835. $item['language_id'] = $language_info['english_name'];
  1836. $item['actions'] = Display::url(
  1837. Display::return_icon('edit.png', get_lang('Edit')),
  1838. api_get_path(WEB_CODE_PATH).'admin/event_type.php?action=edit&event_type_name='.$item['event_type_name']
  1839. );
  1840. $item['actions'] .= Display::url(
  1841. Display::return_icon('delete.png', get_lang('Delete')),
  1842. api_get_path(WEB_CODE_PATH).'admin/event_controller.php?action=delete&id='.$item['id']
  1843. );
  1844. $new_result[] = $item;
  1845. }
  1846. $result = $new_result;
  1847. break;
  1848. case 'get_careers':
  1849. $columns = ['name', 'description', 'actions'];
  1850. if (!in_array($sidx, $columns)) {
  1851. $sidx = 'name';
  1852. }
  1853. $result = Database::select(
  1854. '*',
  1855. $obj->table,
  1856. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1857. );
  1858. $new_result = [];
  1859. foreach ($result as $item) {
  1860. if (!$item['status']) {
  1861. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1862. }
  1863. $new_result[] = $item;
  1864. }
  1865. $result = $new_result;
  1866. break;
  1867. case 'get_promotions':
  1868. $columns = ['name', 'career', 'description', 'actions'];
  1869. if (!in_array($sidx, $columns)) {
  1870. $sidx = 'name';
  1871. }
  1872. $result = Database::select(
  1873. 'p.id,p.name, p.description, c.name as career, p.status',
  1874. "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ",
  1875. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1876. );
  1877. $new_result = [];
  1878. foreach ($result as $item) {
  1879. if (!$item['status']) {
  1880. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1881. }
  1882. $new_result[] = $item;
  1883. }
  1884. $result = $new_result;
  1885. break;
  1886. case 'get_mail_template':
  1887. $columns = ['name', 'type', 'default_template', 'actions'];
  1888. if (!in_array($sidx, $columns)) {
  1889. $sidx = 'name';
  1890. }
  1891. if (!in_array($sidx, $columns)) {
  1892. $sidx = 'name';
  1893. }
  1894. $result = Database::select(
  1895. '*',
  1896. $obj->table,
  1897. [
  1898. 'where' => ['url_id = ? ' => api_get_current_access_url_id()],
  1899. 'order' => "$sidx $sord",
  1900. 'LIMIT' => "$start , $limit",
  1901. ]
  1902. );
  1903. $new_result = [];
  1904. foreach ($result as $item) {
  1905. $new_result[] = $item;
  1906. }
  1907. $result = $new_result;
  1908. break;
  1909. case 'get_grade_models':
  1910. $columns = ['name', 'description', 'actions'];
  1911. if (!in_array($sidx, $columns)) {
  1912. $sidx = 'name';
  1913. }
  1914. $result = Database::select(
  1915. '*',
  1916. "$obj->table ",
  1917. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1918. );
  1919. $new_result = [];
  1920. foreach ($result as $item) {
  1921. $new_result[] = $item;
  1922. }
  1923. $result = $new_result;
  1924. break;
  1925. case 'get_usergroups':
  1926. $obj->protectScript();
  1927. $columns = ['name', 'users', 'courses', 'sessions', 'group_type', 'actions'];
  1928. $result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
  1929. break;
  1930. case 'get_extra_fields':
  1931. $obj = new ExtraField($type);
  1932. $columns = [
  1933. 'display_text',
  1934. 'variable',
  1935. 'field_type',
  1936. 'changeable',
  1937. 'visible_to_self',
  1938. 'visible_to_others',
  1939. 'filter',
  1940. 'field_order',
  1941. ];
  1942. $result = $obj->getAllGrid($sidx, $sord, $start, $limit);
  1943. $new_result = [];
  1944. if (!empty($result)) {
  1945. $checkIcon = Display::return_icon(
  1946. 'check-circle.png',
  1947. get_lang('Yes')
  1948. );
  1949. $timesIcon = Display::return_icon(
  1950. 'closed-circle.png',
  1951. get_lang('No')
  1952. );
  1953. foreach ($result as $item) {
  1954. $item['display_text'] = ExtraField::translateDisplayName(
  1955. $item['variable'],
  1956. $item['displayText']
  1957. );
  1958. $item['field_type'] = $obj->get_field_type_by_id($item['fieldType']);
  1959. $item['changeable'] = $item['changeable'] ? $checkIcon : $timesIcon;
  1960. $item['visible_to_self'] = $item['visibleToSelf'] ? $checkIcon : $timesIcon;
  1961. $item['visible_to_others'] = $item['visibleToOthers'] ? $checkIcon : $timesIcon;
  1962. $item['filter'] = $item['filter'] ? $checkIcon : $timesIcon;
  1963. $new_result[] = $item;
  1964. }
  1965. $result = $new_result;
  1966. }
  1967. break;
  1968. case 'get_exercise_grade':
  1969. $objExercise = new Exercise();
  1970. $exercises = $objExercise->getExercisesByCourseSession(
  1971. $_GET['course_id'],
  1972. $_GET['session_id']
  1973. );
  1974. $cntExer = 4;
  1975. if (!empty($exercises)) {
  1976. $cntExer += count($exercises);
  1977. }
  1978. $columns = [];
  1979. //Get dynamic column names
  1980. $i = 1;
  1981. $column_names = [];
  1982. foreach (range(1, $cntExer) as $cnt) {
  1983. switch ($cnt) {
  1984. case 1:
  1985. $columns[] = 'session';
  1986. $column_names[] = get_lang('Section');
  1987. break;
  1988. case 2:
  1989. $columns[] = 'username';
  1990. $column_names[] = get_lang('Username');
  1991. break;
  1992. case 3:
  1993. $columns[] = 'name';
  1994. $column_names[] = get_lang('Name');
  1995. break;
  1996. case $cntExer:
  1997. $columns[] = 'finalScore';
  1998. $column_names[] = get_lang('FinalScore');
  1999. break;
  2000. default:
  2001. $title = '';
  2002. if (!empty($exercises[$cnt - 4]['title'])) {
  2003. $title = ucwords(strtolower(trim($exercises[$cnt - 4]['title'])));
  2004. }
  2005. $columns[] = 'exer'.$i;
  2006. $column_names[] = $title;
  2007. $i++;
  2008. break;
  2009. }
  2010. }
  2011. $quizIds = [];
  2012. if (!empty($exercises)) {
  2013. foreach ($exercises as $exercise) {
  2014. $quizIds[] = $exercise['id'];
  2015. }
  2016. }
  2017. $course = api_get_course_info_by_id($_GET['course_id']);
  2018. $listUserSess = CourseManager::get_student_list_from_course_code(
  2019. $course['code'],
  2020. true,
  2021. $_GET['session_id']
  2022. );
  2023. $usersId = array_keys($listUserSess);
  2024. $users = UserManager::get_user_list_by_ids(
  2025. $usersId,
  2026. null,
  2027. "lastname, firstname",
  2028. "$start , $limit"
  2029. );
  2030. $exeResults = $objExercise->getExerciseAndResult(
  2031. $_GET['course_id'],
  2032. $_GET['session_id'],
  2033. $quizIds
  2034. );
  2035. $arrGrade = [];
  2036. foreach ($exeResults as $exeResult) {
  2037. $arrGrade[$exeResult['exe_user_id']][$exeResult['exe_exo_id']] = $exeResult['exe_result'];
  2038. }
  2039. $result = [];
  2040. $i = 0;
  2041. foreach ($users as $user) {
  2042. $sessionInfo = SessionManager::fetch($listUserSess[$user['user_id']]['id_session']);
  2043. $result[$i]['session'] = $sessionInfo['name'];
  2044. $result[$i]['username'] = $user['username'];
  2045. $result[$i]['name'] = $user['lastname']." ".$user['firstname'];
  2046. $j = 1;
  2047. $finalScore = 0;
  2048. foreach ($quizIds as $quizID) {
  2049. $grade = '';
  2050. if (!empty($arrGrade[$user['user_id']][$quizID]) || $arrGrade[$user['user_id']][$quizID] == 0) {
  2051. $finalScore += $grade = $arrGrade[$user['user_id']][$quizID];
  2052. }
  2053. $result[$i]['exer'.$j] = $grade;
  2054. $j++;
  2055. }
  2056. if ($finalScore > 20) {
  2057. $finalScore = 20;
  2058. }
  2059. $result[$i]['finalScore'] = number_format($finalScore, 2);
  2060. $i++;
  2061. }
  2062. break;
  2063. case 'get_extra_field_options':
  2064. $obj = new ExtraFieldOption($type);
  2065. $columns = ['display_text', 'option_value', 'option_order'];
  2066. $result = $obj->get_all([
  2067. 'where' => ['field_id = ? ' => $field_id],
  2068. 'order' => "$sidx $sord",
  2069. 'LIMIT' => "$start , $limit",
  2070. ]);
  2071. break;
  2072. case 'get_usergroups_teacher':
  2073. $columns = ['name', 'users', 'status', 'group_type', 'actions'];
  2074. $options['order'] = "name $sord";
  2075. $options['limit'] = "$start , $limit";
  2076. switch ($type) {
  2077. case 'not_registered':
  2078. $result = $obj->getUserGroupNotInCourse($options, $groupFilter);
  2079. break;
  2080. case 'registered':
  2081. $result = $obj->getUserGroupInCourse($options, $groupFilter);
  2082. break;
  2083. }
  2084. $new_result = [];
  2085. $currentUserId = api_get_user_id();
  2086. $isAllow = api_is_allowed_to_edit();
  2087. if (!empty($result)) {
  2088. $urlUserGroup = api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?'.api_get_cidreq();
  2089. foreach ($result as $group) {
  2090. $countUsers = count($obj->get_users_by_usergroup($group['id']));
  2091. $group['users'] = $countUsers;
  2092. if (!empty($countUsers)) {
  2093. $group['users'] = Display::url(
  2094. $countUsers,
  2095. $urlUserGroup.'&id='.$group['id']
  2096. );
  2097. }
  2098. if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
  2099. $url = 'class.php?action=remove_class_from_course&id='.$group['id'].'&'.api_get_cidreq();
  2100. $icon = Display::return_icon('delete.png', get_lang('Remove'));
  2101. } else {
  2102. $url = 'class.php?action=add_class_to_course&id='.$group['id'].'&'.api_get_cidreq().'&type=not_registered';
  2103. $icon = Display::return_icon('add.png', get_lang('Add'));
  2104. }
  2105. switch ($group['group_type']) {
  2106. case 0:
  2107. $group['group_type'] = Display::label(get_lang('Class'), 'primary');
  2108. break;
  2109. case 1:
  2110. $group['group_type'] = Display::label(get_lang('Social'), 'success');
  2111. break;
  2112. }
  2113. $role = $obj->getUserRoleToString(api_get_user_id(), $group['id']);
  2114. $group['status'] = $role;
  2115. $group['actions'] = '';
  2116. if ($isAllow) {
  2117. if ($obj->allowTeachers() && $group['author_id'] == $currentUserId) {
  2118. $group['actions'] .= Display::url(
  2119. Display::return_icon('statistics.png', get_lang('Stats')),
  2120. $urlUserGroup.'&id='.$group['id']
  2121. ).'&nbsp;';
  2122. }
  2123. $group['actions'] .= Display::url($icon, $url);
  2124. }
  2125. $new_result[] = $group;
  2126. }
  2127. $result = $new_result;
  2128. }
  2129. if (!in_array($sidx, $columns)) {
  2130. $sidx = 'name';
  2131. }
  2132. // Multidimensional sort
  2133. $result = msort($result, $sidx, $sord);
  2134. break;
  2135. default:
  2136. exit;
  2137. }
  2138. $allowed_actions = [
  2139. 'get_careers',
  2140. 'get_promotions',
  2141. 'get_mail_template',
  2142. 'get_usergroups',
  2143. 'get_usergroups_teacher',
  2144. 'get_gradebooks',
  2145. 'get_sessions',
  2146. 'get_session_access_overview',
  2147. 'get_sessions_tracking',
  2148. 'get_session_lp_progress',
  2149. 'get_survey_overview',
  2150. 'get_session_progress',
  2151. 'get_exercise_progress',
  2152. 'get_exercise_results',
  2153. 'get_exercise_results_report',
  2154. 'get_work_student_list_overview',
  2155. 'get_hotpotatoes_exercise_results',
  2156. 'get_work_teacher',
  2157. 'get_work_student',
  2158. 'get_work_user_list',
  2159. 'get_work_user_list_others',
  2160. 'get_work_user_list_all',
  2161. 'get_timelines',
  2162. 'get_grade_models',
  2163. 'get_event_email_template',
  2164. 'get_user_skill_ranking',
  2165. 'get_extra_fields',
  2166. 'get_extra_field_options',
  2167. //'get_course_exercise_medias',
  2168. 'get_user_course_report',
  2169. 'get_user_course_report_resumed',
  2170. 'get_exercise_grade',
  2171. 'get_group_reporting',
  2172. 'get_course_announcements',
  2173. 'get_programmed_announcements',
  2174. 'course_log_events',
  2175. 'get_learning_path_calendars',
  2176. 'get_usergroups_users',
  2177. 'get_calendar_users',
  2178. 'get_exercise_categories',
  2179. ];
  2180. // 5. Creating an obj to return a json
  2181. if (in_array($action, $allowed_actions)) {
  2182. $response = new stdClass();
  2183. $response->page = $page;
  2184. $response->total = $total_pages;
  2185. $response->records = $count;
  2186. if ($operation && $operation == 'excel') {
  2187. $j = 1;
  2188. $array = [];
  2189. if (empty($column_names)) {
  2190. $column_names = $columns;
  2191. }
  2192. // Headers
  2193. foreach ($column_names as $col) {
  2194. // Overwrite titles
  2195. if (isset($overwriteColumnHeaderExport[$col])) {
  2196. $col = $overwriteColumnHeaderExport[$col];
  2197. }
  2198. $array[0][] = $col;
  2199. }
  2200. foreach ($result as $row) {
  2201. foreach ($columns as $col) {
  2202. $array[$j][] = strip_tags($row[$col]);
  2203. }
  2204. $j++;
  2205. }
  2206. $fileName = !empty($action) ? $action : 'company_report';
  2207. if (!empty($exportFilename)) {
  2208. $fileName = $exportFilename;
  2209. }
  2210. switch ($exportFormat) {
  2211. case 'xls':
  2212. Export::arrayToXls($array, $fileName);
  2213. break;
  2214. case 'xls_html':
  2215. //TODO add date if exists
  2216. $browser = new Browser();
  2217. if ($browser->getPlatform() == Browser::PLATFORM_WINDOWS) {
  2218. Export::export_table_xls_html($array, $fileName, 'ISO-8859-15');
  2219. } else {
  2220. Export::export_table_xls_html($array, $fileName);
  2221. }
  2222. break;
  2223. case 'csv':
  2224. default:
  2225. Export::arrayToCsv($array, $fileName);
  2226. break;
  2227. }
  2228. exit;
  2229. }
  2230. $i = 0;
  2231. if (!empty($result)) {
  2232. foreach ($result as $row) {
  2233. // if results tab give not id, set id to $i otherwise id="null"
  2234. // for all <tr> of the jqgrid - ref #4235
  2235. if (!isset($row['id']) || isset($row['id']) && $row['id'] == '') {
  2236. $response->rows[$i]['id'] = $i;
  2237. } else {
  2238. $response->rows[$i]['id'] = $row['id'];
  2239. }
  2240. $array = [];
  2241. foreach ($columns as $col) {
  2242. if (in_array($col, ['correction', 'actions'])) {
  2243. $array[] = isset($row[$col]) ? $row[$col] : '';
  2244. } else {
  2245. $array[] = isset($row[$col]) ? Security::remove_XSS($row[$col]) : '';
  2246. }
  2247. }
  2248. $response->rows[$i]['cell'] = $array;
  2249. $i++;
  2250. }
  2251. }
  2252. header('Content-Type: application/json;charset=utf-8');
  2253. echo json_encode($response);
  2254. }
  2255. exit;