model.ajax.php 76 KB

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