model.ajax.php 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396
  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_careers':
  722. $obj = new Career();
  723. $count = $obj->get_count();
  724. break;
  725. case 'get_promotions':
  726. $obj = new Promotion();
  727. $count = $obj->get_count();
  728. break;
  729. case 'get_mail_template':
  730. $obj = new MailTemplateManager();
  731. $count = $obj->get_count();
  732. break;
  733. case 'get_grade_models':
  734. $obj = new GradeModel();
  735. $count = $obj->get_count();
  736. break;
  737. case 'get_usergroups':
  738. $obj = new UserGroup();
  739. $obj->protectScript();
  740. $count = $obj->get_count();
  741. break;
  742. case 'get_usergroups_teacher':
  743. $obj = new UserGroup();
  744. $obj->protectScript(null, false, true);
  745. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
  746. $groupFilter = isset($_REQUEST['group_filter']) ? (int) $_REQUEST['group_filter'] : 0;
  747. $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
  748. $course_id = api_get_course_int_id();
  749. $options = [];
  750. $options['course_id'] = $course_id;
  751. switch ($type) {
  752. case 'not_registered':
  753. $options['where'] = [' (course_id IS NULL OR course_id != ?) ' => $course_id];
  754. if (!empty($keyword)) {
  755. $options['where']['AND name like %?% '] = $keyword;
  756. }
  757. $count = $obj->getUserGroupNotInCourse($options, $groupFilter, true);
  758. break;
  759. case 'registered':
  760. $options['where'] = [' usergroup.course_id = ? ' => $course_id];
  761. $count = $obj->getUserGroupInCourse(
  762. $options,
  763. $groupFilter,
  764. true
  765. );
  766. break;
  767. }
  768. break;
  769. default:
  770. exit;
  771. }
  772. // 3. Calculating first, end, etc
  773. $total_pages = 0;
  774. if ($count > 0) {
  775. if (!empty($limit)) {
  776. $total_pages = ceil((float) $count / (float) $limit);
  777. }
  778. }
  779. if ($page > $total_pages) {
  780. $page = $total_pages;
  781. }
  782. $start = $limit * $page - $limit;
  783. if ($start < 0) {
  784. $start = 0;
  785. }
  786. //4. Deleting an element if the user wants to
  787. if (isset($_REQUEST['oper']) && $_REQUEST['oper'] == 'del') {
  788. $obj->delete($_REQUEST['id']);
  789. }
  790. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh();
  791. //5. Querying the DB for the elements
  792. $columns = [];
  793. switch ($action) {
  794. case 'get_exercise_categories':
  795. api_protect_course_script();
  796. if (!api_is_allowed_to_edit()) {
  797. api_not_allowed(true);
  798. }
  799. $columns = ['name', 'actions'];
  800. $manager = new ExerciseCategoryManager();
  801. $result = $manager->get_all([
  802. 'where' => ['c_id = ? ' => $courseId],
  803. 'order' => "$sidx $sord",
  804. 'LIMIT' => "$start , $limit",
  805. ]);
  806. break;
  807. case 'get_calendar_users':
  808. $columns = ['firstname', 'lastname', 'exam'];
  809. $result = $calendarPlugin->getUsersPerCalendar($id);
  810. break;
  811. case 'get_usergroups_users':
  812. $columns = ['name', 'actions'];
  813. if (api_get_plugin_setting('learning_calendar', 'enabled') === 'true') {
  814. $columns = [
  815. 'name',
  816. 'calendar',
  817. 'gradebook_items',
  818. 'time_spent',
  819. 'lp_day_completed',
  820. 'days_diff',
  821. 'actions',
  822. 'calendar_id',
  823. ];
  824. }
  825. $result = $usergroup->getUserGroupUsers($id);
  826. break;
  827. case 'get_learning_path_calendars':
  828. $columns = ['title', 'total_hours', 'minutes_per_day', 'actions'];
  829. $result = $calendarPlugin->getCalendars(
  830. $start,
  831. $limit,
  832. $sidx,
  833. $sord
  834. );
  835. break;
  836. case 'course_log_events':
  837. $columns = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
  838. $result = Statistics::getActivitiesData(
  839. $start,
  840. $limit,
  841. $sidx,
  842. $sord,
  843. $courseId,
  844. $sessionId
  845. );
  846. break;
  847. case 'get_programmed_announcements':
  848. $columns = ['subject', 'date', 'sent', 'actions'];
  849. $sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : 0;
  850. $result = Database::select(
  851. '*',
  852. $object->table,
  853. [
  854. 'where' => ['session_id = ? ' => $sessionId],
  855. 'order' => "$sidx $sord",
  856. 'LIMIT' => "$start , $limit", ]
  857. );
  858. if ($result) {
  859. foreach ($result as &$item) {
  860. $item['sent'] = $item['sent'] == 1 ? get_lang('Yes') : get_lang('No');
  861. $item['date'] = api_get_local_time($item['date']);
  862. }
  863. }
  864. break;
  865. case 'get_group_reporting':
  866. $columns = ['name', 'time', 'progress', 'score', 'works', 'messages', 'actions'];
  867. $result = Tracking::get_group_reporting(
  868. $course_id,
  869. $sessionId,
  870. $group_id,
  871. 'all',
  872. $start,
  873. $limit,
  874. $sidx,
  875. $sord,
  876. $whereCondition
  877. );
  878. break;
  879. case 'get_course_exercise_medias':
  880. $columns = ['question'];
  881. $result = Question::get_course_medias(
  882. $course_id,
  883. $start,
  884. $limit,
  885. $sidx,
  886. $sord,
  887. $whereCondition
  888. );
  889. break;
  890. case 'get_user_course_report_resumed':
  891. $columns = [
  892. 'extra_ruc',
  893. 'training_hours',
  894. 'count_users',
  895. 'count_users_registered',
  896. 'average_hours_per_user',
  897. 'count_certificates',
  898. ];
  899. $column_names = [
  900. get_lang('Company'),
  901. get_lang('Hours of accumulated training'),
  902. get_lang('Subscriptions count'),
  903. get_lang('Users count'),
  904. get_lang('Avg hours/student'),
  905. get_lang('Certificates count'),
  906. ];
  907. $extra_fields = UserManager::get_extra_fields(
  908. 0,
  909. 100,
  910. null,
  911. null,
  912. true,
  913. true
  914. );
  915. if (!empty($extra_fields)) {
  916. foreach ($extra_fields as $extra) {
  917. if ($extra['1'] == 'ruc') {
  918. continue;
  919. }
  920. $columns[] = $extra['1'];
  921. $column_names[] = $extra['3'];
  922. }
  923. }
  924. if (!in_array($sidx, ['training_hours'])) {
  925. //$sidx = 'training_hours';
  926. }
  927. if (api_is_student_boss() && empty($userIdList)) {
  928. $result = [];
  929. break;
  930. }
  931. $result = CourseManager::get_user_list_from_course_code(
  932. null,
  933. null,
  934. "LIMIT $start, $limit",
  935. null, //" $sidx $sord",
  936. null,
  937. null,
  938. true,
  939. true,
  940. ['ruc'],
  941. $courseCodeList,
  942. $userIdList,
  943. null,
  944. $sessionIdList
  945. );
  946. $new_result = [];
  947. if (!empty($result)) {
  948. foreach ($result as $row) {
  949. $row['training_hours'] = api_time_to_hms($row['training_hours']);
  950. $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']);
  951. $new_result[] = $row;
  952. }
  953. $result = $new_result;
  954. }
  955. break;
  956. case 'get_user_course_report':
  957. $columns = [
  958. 'course',
  959. 'user',
  960. 'email',
  961. 'time',
  962. 'certificate',
  963. 'progress_100',
  964. 'progress',
  965. ];
  966. $column_names = [
  967. get_lang('Course'),
  968. get_lang('User'),
  969. get_lang('e-mail'),
  970. get_lang('Man hours'),
  971. get_lang('Generated certificate'),
  972. get_lang('Approved'),
  973. get_lang('Course progress'),
  974. ];
  975. $extra_fields = UserManager::get_extra_fields(
  976. 0,
  977. 100,
  978. null,
  979. null,
  980. true,
  981. true
  982. );
  983. if (!empty($extra_fields)) {
  984. foreach ($extra_fields as $extra) {
  985. $columns[] = $extra['1'];
  986. $column_names[] = $extra['3'];
  987. }
  988. }
  989. if (api_is_student_boss()) {
  990. $columns[] = 'group';
  991. $column_names[] = get_lang('Group');
  992. }
  993. if (!in_array($sidx, ['title'])) {
  994. $sidx = 'title';
  995. }
  996. if (api_is_student_boss() && empty($userIdList)) {
  997. $result = [];
  998. break;
  999. }
  1000. //get sessions
  1001. $arrSessions = [];
  1002. if (count($sessionIdList) > 0) {
  1003. $arrSessions = CourseManager::get_user_list_from_course_code(
  1004. null,
  1005. null,
  1006. "LIMIT $start, $limit",
  1007. " $sidx $sord",
  1008. null,
  1009. null,
  1010. true,
  1011. false,
  1012. null,
  1013. $courseCodeList,
  1014. $userIdList,
  1015. null,
  1016. $sessionIdList
  1017. );
  1018. }
  1019. //get courses
  1020. $arrCourses = CourseManager::get_user_list_from_course_code(
  1021. null,
  1022. null,
  1023. "LIMIT $start, $limit",
  1024. " $sidx $sord",
  1025. null,
  1026. null,
  1027. true,
  1028. false,
  1029. null,
  1030. [],
  1031. $userIdList,
  1032. null
  1033. );
  1034. //merge courses and sessions
  1035. $result = array_merge($arrSessions, $arrCourses);
  1036. if (api_is_student_boss()) {
  1037. $userGroup = new UserGroup();
  1038. foreach ($result as &$item) {
  1039. $userGroups = $userGroup->get_groups_by_user($item['user_id']);
  1040. $item['group'] = implode(", ", array_column($userGroups, 'name'));
  1041. unset($item['user_id']);
  1042. }
  1043. }
  1044. break;
  1045. case 'get_user_skill_ranking':
  1046. $columns = [
  1047. 'photo',
  1048. 'firstname',
  1049. 'lastname',
  1050. 'skills_acquired',
  1051. 'currently_learning',
  1052. 'rank',
  1053. ];
  1054. $result = $skill->getUserListSkillRanking(
  1055. $start,
  1056. $limit,
  1057. $sidx,
  1058. $sord,
  1059. $whereCondition
  1060. );
  1061. $result = msort($result, 'skills_acquired', 'asc');
  1062. $skills_in_course = [];
  1063. if (!empty($result)) {
  1064. foreach ($result as &$item) {
  1065. $user_info = api_get_user_info($item['user_id']);
  1066. $personal_course_list = UserManager::get_personal_session_course_list(
  1067. $item['user_id']
  1068. );
  1069. $count_skill_by_course = [];
  1070. foreach ($personal_course_list as $course_item) {
  1071. if (!isset($skills_in_course[$course_item['code']])) {
  1072. $count_skill_by_course[$course_item['code']] = $skill->getCountSkillsByCourse($course_item['code']);
  1073. $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
  1074. } else {
  1075. $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
  1076. }
  1077. }
  1078. $item['photo'] = Display::img($user_info['avatar_small'], $user_info['complete_name'], [], false);
  1079. $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
  1080. }
  1081. }
  1082. break;
  1083. case 'get_course_announcements':
  1084. $columns = [
  1085. 'title',
  1086. 'username',
  1087. 'insert_date',
  1088. 'actions',
  1089. ];
  1090. $titleToSearch = isset($_REQUEST['title_to_search']) ? $_REQUEST['title_to_search'] : '';
  1091. $userIdToSearch = isset($_REQUEST['user_id_to_search']) ? $_REQUEST['user_id_to_search'] : 0;
  1092. $result = AnnouncementManager::getAnnouncements(
  1093. null,
  1094. null,
  1095. false,
  1096. $start,
  1097. $limit,
  1098. $sidx,
  1099. $sord,
  1100. $titleToSearch,
  1101. $userIdToSearch
  1102. );
  1103. break;
  1104. case 'get_work_teacher':
  1105. $columns = [
  1106. 'type',
  1107. 'title',
  1108. 'sent_date',
  1109. 'expires_on',
  1110. 'amount',
  1111. 'actions',
  1112. ];
  1113. $result = getWorkListTeacher(
  1114. $start,
  1115. $limit,
  1116. $sidx,
  1117. $sord,
  1118. $whereCondition
  1119. );
  1120. break;
  1121. case 'get_work_student':
  1122. $columns = [
  1123. 'type',
  1124. 'title',
  1125. 'expires_on',
  1126. 'feedback',
  1127. 'last_upload',
  1128. 'others',
  1129. ];
  1130. $result = getWorkListStudent(
  1131. $start,
  1132. $limit,
  1133. $sidx,
  1134. $sord,
  1135. $whereCondition
  1136. );
  1137. break;
  1138. case 'get_work_user_list_all':
  1139. $plagiarismColumns = [];
  1140. if (api_get_configuration_value('allow_compilatio_tool')) {
  1141. $plagiarismColumns = ['compilatio'];
  1142. }
  1143. if (isset($_GET['type']) && $_GET['type'] === 'simple') {
  1144. $columns = [
  1145. 'fullname',
  1146. 'title',
  1147. 'qualification',
  1148. 'sent_date',
  1149. 'qualificator_id',
  1150. 'correction',
  1151. ];
  1152. $columns = array_merge($columns, $plagiarismColumns);
  1153. $columns[] = 'actions';
  1154. } else {
  1155. $columns = [
  1156. 'fullname',
  1157. 'title',
  1158. 'qualification',
  1159. 'sent_date',
  1160. 'correction',
  1161. ];
  1162. $columns = array_merge($columns, $plagiarismColumns);
  1163. $columns[] = 'actions';
  1164. }
  1165. $whereCondition = " AND $whereCondition ";
  1166. $result = get_work_user_list(
  1167. $start,
  1168. $limit,
  1169. $sidx,
  1170. $sord,
  1171. $work_id,
  1172. $whereCondition
  1173. );
  1174. break;
  1175. case 'get_work_user_list_others':
  1176. $plagiarismColumns = [];
  1177. if (api_get_configuration_value('allow_compilatio_tool')) {
  1178. $plagiarismColumns = ['compilatio'];
  1179. }
  1180. if (isset($_GET['type']) && $_GET['type'] === 'simple') {
  1181. $columns = [
  1182. 'type', 'firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id',
  1183. ];
  1184. $columns = array_merge($columns, $plagiarismColumns);
  1185. $columns[] = 'actions';
  1186. } else {
  1187. $columns = ['type', 'firstname', 'lastname', 'title', 'sent_date'];
  1188. $columns = array_merge($columns, $plagiarismColumns);
  1189. $columns[] = 'actions';
  1190. }
  1191. if (trim($whereCondition) === '1 = 1') {
  1192. $whereCondition = '';
  1193. }
  1194. $whereCondition .= " AND u.user_id <> ".api_get_user_id();
  1195. $result = get_work_user_list(
  1196. $start,
  1197. $limit,
  1198. $sidx,
  1199. $sord,
  1200. $work_id,
  1201. $whereCondition
  1202. );
  1203. break;
  1204. case 'get_work_user_list':
  1205. $plagiarismColumns = [];
  1206. if (api_get_configuration_value('allow_compilatio_tool')) {
  1207. $plagiarismColumns = ['compilatio'];
  1208. }
  1209. if (isset($_GET['type']) && $_GET['type'] == 'simple') {
  1210. $columns = [
  1211. 'type', 'title', 'qualification', 'sent_date', 'qualificator_id',
  1212. ];
  1213. $columns = array_merge($columns, $plagiarismColumns);
  1214. $columns[] = 'actions';
  1215. } else {
  1216. $columns = ['type', 'title', 'qualification', 'sent_date'];
  1217. $columns = array_merge($columns, $plagiarismColumns);
  1218. $columns[] = 'actions';
  1219. }
  1220. $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
  1221. if (trim($whereCondition) === '1 = 1') {
  1222. $whereCondition = '';
  1223. }
  1224. if (empty($documents)) {
  1225. $whereCondition .= ' AND u.user_id = '.api_get_user_id();
  1226. $result = get_work_user_list(
  1227. $start,
  1228. $limit,
  1229. $sidx,
  1230. $sord,
  1231. $work_id,
  1232. $whereCondition
  1233. );
  1234. } else {
  1235. $result = get_work_user_list_from_documents(
  1236. $start,
  1237. $limit,
  1238. $sidx,
  1239. $sord,
  1240. $work_id,
  1241. api_get_user_id(),
  1242. $whereCondition
  1243. );
  1244. }
  1245. break;
  1246. case 'get_exercise_results':
  1247. $is_allowedToEdit = api_is_allowed_to_edit(null, true) ||
  1248. api_is_drh() ||
  1249. api_is_student_boss() ||
  1250. api_is_session_admin();
  1251. if ($is_allowedToEdit || api_is_student_boss()) {
  1252. $columns = [
  1253. 'firstname',
  1254. 'lastname',
  1255. 'username',
  1256. 'group_name',
  1257. 'exe_duration',
  1258. 'start_date',
  1259. 'exe_date',
  1260. 'score',
  1261. 'user_ip',
  1262. 'status',
  1263. 'lp',
  1264. 'actions',
  1265. ];
  1266. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  1267. if ($officialCodeInList === 'true') {
  1268. $columns = array_merge(['official_code'], $columns);
  1269. }
  1270. }
  1271. $result = ExerciseLib::get_exam_results_data(
  1272. $start,
  1273. $limit,
  1274. $sidx,
  1275. $sord,
  1276. $exercise_id,
  1277. $whereCondition
  1278. );
  1279. break;
  1280. case 'get_exercise_results_report':
  1281. $columns = [
  1282. 'firstname',
  1283. 'lastname',
  1284. 'username',
  1285. ];
  1286. $extraFieldsToAdd = [];
  1287. $extraFields = api_get_configuration_value('exercise_category_report_user_extra_fields');
  1288. $roundValues = api_get_configuration_value('exercise_category_round_score_in_export');
  1289. if (!empty($extraFields) && isset($extraFields['fields'])) {
  1290. $extraField = new ExtraField('user');
  1291. foreach ($extraFields['fields'] as $variable) {
  1292. $info = $extraField->get_handler_field_info_by_field_variable($variable);
  1293. if ($info) {
  1294. $extraFieldsToAdd[] = $variable;
  1295. }
  1296. }
  1297. }
  1298. if (!empty($extraFieldsToAdd)) {
  1299. $columns = array_merge($columns, $extraFieldsToAdd);
  1300. }
  1301. $columns[] = 'session';
  1302. $columns[] = 'session_access_start_date';
  1303. $columns[] = 'exe_date';
  1304. $columns[] = 'score';
  1305. if ($operation === 'excel') {
  1306. $columns = [
  1307. 'firstname',
  1308. 'lastname',
  1309. 'username',
  1310. ];
  1311. if (!empty($extraFieldsToAdd)) {
  1312. $columns = array_merge($columns, $extraFieldsToAdd);
  1313. }
  1314. $columns[] = 'session';
  1315. $columns[] = 'session_access_start_date';
  1316. $columns[] = 'exe_date';
  1317. $columns[] = 'score_percentage';
  1318. $columns[] = 'only_score';
  1319. $columns[] = 'total';
  1320. $overwriteColumnHeaderExport['session_access_start_date'] = get_lang('Access start date');
  1321. $overwriteColumnHeaderExport['exe_date'] = get_lang('Start Date');
  1322. $overwriteColumnHeaderExport['score_percentage'] = get_lang('Score').' - '.get_lang('Percentage');
  1323. $overwriteColumnHeaderExport['only_score'] = get_lang('Score').' - '.get_lang('Note');
  1324. $overwriteColumnHeaderExport['total'] = get_lang('Score').' - '.get_lang('Test');
  1325. }
  1326. $categoryList = TestCategory::getListOfCategoriesIDForTest($exerciseId, $courseId);
  1327. if (!empty($categoryList)) {
  1328. foreach ($categoryList as $categoryInfo) {
  1329. $label = 'category_'.$categoryInfo['id'];
  1330. if ($operation == 'excel') {
  1331. $columns[] = $label.'_score_percentage';
  1332. $columns[] = $label.'_only_score';
  1333. $columns[] = $label.'_total';
  1334. $overwriteColumnHeaderExport[$label] = $categoryInfo['title'];
  1335. $overwriteColumnHeaderExport[$label.'_score_percentage'] = $categoryInfo['title'].
  1336. ' - '.get_lang('Percentage');
  1337. $overwriteColumnHeaderExport[$label.'_only_score'] = $categoryInfo['title'].
  1338. ' - '.get_lang('Note');
  1339. $overwriteColumnHeaderExport[$label.'_total'] = $categoryInfo['title'].
  1340. ' - '.get_lang('Test');
  1341. } else {
  1342. $columns[] = $label;
  1343. }
  1344. }
  1345. }
  1346. if ($operation !== 'excel') {
  1347. $columns[] = 'actions';
  1348. }
  1349. $whereCondition .= " AND te.status = '' ";
  1350. $result = ExerciseLib::get_exam_results_data(
  1351. $start,
  1352. $limit,
  1353. $sidx,
  1354. $sord,
  1355. $exerciseId,
  1356. $whereCondition,
  1357. false,
  1358. $courseInfo['code'],
  1359. true,
  1360. true,
  1361. $extraFieldsToAdd,
  1362. true,
  1363. $roundValues
  1364. );
  1365. break;
  1366. case 'get_hotpotatoes_exercise_results':
  1367. $course = api_get_course_info();
  1368. $documentPath = api_get_path(SYS_COURSE_PATH).$course['path']."/document";
  1369. if (api_is_allowed_to_edit()) {
  1370. $columns = ['firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions'];
  1371. } else {
  1372. $columns = ['exe_date', 'score', 'actions'];
  1373. }
  1374. $result = ExerciseLib::get_exam_results_hotpotatoes_data(
  1375. $start,
  1376. $limit,
  1377. $sidx,
  1378. $sord,
  1379. $hotpot_path,
  1380. $whereCondition
  1381. );
  1382. break;
  1383. case 'get_work_student_list_overview':
  1384. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  1385. return [];
  1386. }
  1387. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  1388. $columns = [
  1389. 'student', 'works',
  1390. ];
  1391. $result = getWorkUserListData(
  1392. $workId,
  1393. api_get_course_id(),
  1394. api_get_session_id(),
  1395. api_get_group_id(),
  1396. $start,
  1397. $limit,
  1398. $sidx,
  1399. $sord
  1400. );
  1401. break;
  1402. case 'get_hotpotatoes_exercise_results':
  1403. $course = api_get_course_info();
  1404. $documentPath = api_get_path(SYS_COURSE_PATH).$course['path']."/document";
  1405. if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
  1406. $columns = ['firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions'];
  1407. } else {
  1408. $columns = ['exe_date', 'score', 'actions'];
  1409. }
  1410. $result = ExerciseLib::get_exam_results_hotpotatoes_data(
  1411. $start,
  1412. $limit,
  1413. $sidx,
  1414. $sord,
  1415. $hotpot_path,
  1416. $whereCondition
  1417. );
  1418. break;
  1419. case 'get_sessions_tracking':
  1420. if (api_is_drh() || api_is_session_admin()) {
  1421. $orderByName = Database::escape_string($sidx);
  1422. $orderByName = in_array($orderByName, ['name', 'access_start_date']) ? $orderByName : 'name';
  1423. $orderBy = " ORDER BY $orderByName $sord";
  1424. $sessions = SessionManager::get_sessions_followed_by_drh(
  1425. api_get_user_id(),
  1426. $start,
  1427. $limit,
  1428. false,
  1429. false,
  1430. false,
  1431. $orderBy,
  1432. $keyword,
  1433. $description,
  1434. ['where' => $whereCondition, 'extra' => $extra_fields]
  1435. );
  1436. } else {
  1437. // Sessions for the coach
  1438. $sessions = Tracking::get_sessions_coached_by_user(
  1439. api_get_user_id(),
  1440. $start,
  1441. $limit,
  1442. false,
  1443. $keyword,
  1444. $description,
  1445. $sidx,
  1446. $sord,
  1447. ['where' => $whereCondition, 'extra' => $extra_fields]
  1448. );
  1449. }
  1450. $session_columns = SessionManager::getGridColumns('my_space');
  1451. $columns = $session_columns['simple_column_name'];
  1452. $result = [];
  1453. if (!empty($sessions)) {
  1454. foreach ($sessions as $session) {
  1455. if (api_drh_can_access_all_session_content()) {
  1456. $count_courses_in_session = SessionManager::get_course_list_by_session_id(
  1457. $session['id'],
  1458. '',
  1459. null,
  1460. true
  1461. );
  1462. } else {
  1463. $count_courses_in_session = count(
  1464. Tracking::get_courses_followed_by_coach(
  1465. $user_id,
  1466. $session['id']
  1467. )
  1468. );
  1469. }
  1470. $count_users_in_session = SessionManager::get_users_by_session(
  1471. $session['id'],
  1472. 0,
  1473. true
  1474. );
  1475. $session['display_start_date'] = '';
  1476. $session['display_end_date'] = '';
  1477. $session['coach_access_start_date'] = '';
  1478. $session['coach_access_end_date'] = '';
  1479. $dateData = SessionManager::parseSessionDates($session, true);
  1480. $dateToString = $dateData['access'];
  1481. $detailButtons = [];
  1482. $detailButtons[] = Display::url(
  1483. Display::return_icon('works.png', get_lang('Assignments report')),
  1484. api_get_path(WEB_CODE_PATH).'mySpace/works_in_session_report.php?session='.$session['id']
  1485. );
  1486. $detailButtons[] = Display::url(
  1487. Display::return_icon('2rightarrow.png'),
  1488. api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id']
  1489. );
  1490. $item = [
  1491. 'name' => Display::url(
  1492. $session['name'],
  1493. api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id']
  1494. ),
  1495. 'date' => $dateToString,
  1496. 'course_per_session' => $count_courses_in_session,
  1497. 'student_per_session' => $count_users_in_session,
  1498. 'actions' => implode(' ', $detailButtons),
  1499. ];
  1500. if (!empty($extra_fields)) {
  1501. foreach ($extra_fields as $extraField) {
  1502. $item[$extraField['field']] = $extraField['data'];
  1503. }
  1504. }
  1505. $result[] = $item;
  1506. }
  1507. }
  1508. break;
  1509. case 'get_sessions':
  1510. $session_columns = SessionManager::getGridColumns($list_type);
  1511. $columns = $session_columns['simple_column_name'];
  1512. if ($list_type == 'simple') {
  1513. $result = SessionManager::formatSessionsAdminForGrid(
  1514. [
  1515. 'where' => $whereCondition,
  1516. 'order' => "$sidx $sord, s.name",
  1517. 'extra' => $extra_fields,
  1518. 'limit' => "$start , $limit",
  1519. ],
  1520. false,
  1521. $session_columns
  1522. );
  1523. } else {
  1524. $result = SessionManager::get_sessions_admin_complete(
  1525. [
  1526. 'where' => $whereCondition,
  1527. 'order' => "$sidx $sord, s.name",
  1528. 'extra' => $extra_fields,
  1529. 'limit' => "$start , $limit",
  1530. ]
  1531. );
  1532. }
  1533. break;
  1534. case 'get_exercise_progress':
  1535. $sessionId = (int) $_GET['session_id'];
  1536. $courseId = (int) $_GET['course_id'];
  1537. $exerciseId = (int) $_GET['exercise_id'];
  1538. $date_from = $_GET['date_from'];
  1539. $date_to = $_GET['date_to'];
  1540. $columns = [
  1541. 'session',
  1542. 'exercise_id',
  1543. 'quiz_title',
  1544. 'username',
  1545. 'lastname',
  1546. 'firstname',
  1547. 'time',
  1548. 'question_id',
  1549. 'question',
  1550. 'description',
  1551. 'answer',
  1552. 'correct',
  1553. ];
  1554. $result = Tracking::get_exercise_progress(
  1555. $sessionId,
  1556. $courseId,
  1557. $exerciseId,
  1558. $date_from,
  1559. $date_to,
  1560. [
  1561. 'where' => $whereCondition,
  1562. 'order' => "$sidx $sord",
  1563. 'limit' => "$start , $limit",
  1564. ]
  1565. );
  1566. break;
  1567. case 'get_session_lp_progress':
  1568. $sessionId = 0;
  1569. if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) {
  1570. $sessionId = (int) $_GET['session_id'];
  1571. $courseId = (int) $_GET['course_id'];
  1572. $course = api_get_course_info_by_id($courseId);
  1573. }
  1574. /**
  1575. * Add lessons of course.
  1576. */
  1577. $columns = [
  1578. 'username',
  1579. 'firstname',
  1580. 'lastname',
  1581. ];
  1582. $lessons = LearnpathList::get_course_lessons(
  1583. $course['code'],
  1584. $sessionId
  1585. );
  1586. foreach ($lessons as $lesson_id => $lesson) {
  1587. $columns[] = $lesson_id;
  1588. }
  1589. $columns[] = 'total';
  1590. $result = SessionManager::get_session_lp_progress(
  1591. $sessionId,
  1592. $courseId,
  1593. $date_from,
  1594. $date_to,
  1595. [
  1596. 'where' => $whereCondition,
  1597. 'order' => "$sidx $sord",
  1598. 'limit' => "$start , $limit",
  1599. ]
  1600. );
  1601. break;
  1602. case 'get_survey_overview':
  1603. $sessionId = 0;
  1604. if (!empty($_GET['session_id']) &&
  1605. !empty($_GET['course_id']) &&
  1606. !empty($_GET['survey_id'])
  1607. ) {
  1608. $sessionId = intval($_GET['session_id']);
  1609. $courseId = intval($_GET['course_id']);
  1610. $surveyId = intval($_GET['survey_id']);
  1611. $date_from = $_GET['date_from'];
  1612. $date_to = $_GET['date_to'];
  1613. //$course = api_get_course_info_by_id($courseId);
  1614. }
  1615. /**
  1616. * Add lessons of course.
  1617. */
  1618. $columns = [
  1619. 'username',
  1620. 'firstname',
  1621. 'lastname',
  1622. ];
  1623. $questions = SurveyManager::get_questions($surveyId, $courseId);
  1624. foreach ($questions as $question_id => $question) {
  1625. $columns[] = $question_id;
  1626. }
  1627. $result = SessionManager::get_survey_overview(
  1628. $sessionId,
  1629. $courseId,
  1630. $surveyId,
  1631. $date_from,
  1632. $date_to,
  1633. [
  1634. 'where' => $whereCondition,
  1635. 'order' => "$sidx $sord",
  1636. 'limit' => "$start , $limit",
  1637. ]
  1638. );
  1639. break;
  1640. case 'get_session_progress':
  1641. $columns = [
  1642. 'lastname',
  1643. 'firstname',
  1644. 'username',
  1645. //'profile',
  1646. 'total',
  1647. 'courses',
  1648. 'lessons',
  1649. 'exercises',
  1650. 'forums',
  1651. 'homeworks',
  1652. 'wikis',
  1653. 'surveys',
  1654. //exercises
  1655. 'lessons_total',
  1656. 'lessons_done',
  1657. 'lessons_left',
  1658. 'lessons_progress',
  1659. //exercises
  1660. 'exercises_total',
  1661. 'exercises_done',
  1662. 'exercises_left',
  1663. 'exercises_progress',
  1664. //forums
  1665. 'forums_total',
  1666. 'forums_done',
  1667. 'forums_left',
  1668. 'forums_progress',
  1669. //assignments
  1670. 'assignments_total',
  1671. 'assignments_done',
  1672. 'assignments_left',
  1673. 'assignments_progress',
  1674. //Wiki
  1675. 'wiki_total',
  1676. 'wiki_revisions',
  1677. 'wiki_read',
  1678. 'wiki_unread',
  1679. 'wiki_progress',
  1680. //surveys
  1681. 'surveys_total',
  1682. 'surveys_done',
  1683. 'surveys_left',
  1684. 'surveys_progress',
  1685. ];
  1686. $sessionId = 0;
  1687. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  1688. $sessionId = intval($_GET['session_id']);
  1689. $courseId = intval($_GET['course_id']);
  1690. }
  1691. $result = SessionManager::get_session_progress(
  1692. $sessionId,
  1693. $courseId,
  1694. null,
  1695. null,
  1696. [
  1697. 'where' => $whereCondition,
  1698. 'order' => "$sidx $sord",
  1699. 'limit' => "$start , $limit",
  1700. ]
  1701. );
  1702. break;
  1703. case 'get_session_access_overview':
  1704. $columns = [
  1705. 'logindate',
  1706. 'username',
  1707. 'lastname',
  1708. 'firstname',
  1709. 'clicks',
  1710. 'ip',
  1711. 'timeLoggedIn',
  1712. 'session',
  1713. ];
  1714. $sessionId = 0;
  1715. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  1716. $sessionId = intval($_GET['session_id']);
  1717. $courseId = intval($_GET['course_id']);
  1718. $studentId = intval($_GET['student_id']);
  1719. $profile = intval($_GET['profile']);
  1720. $date_from = intval($_GET['date_from']);
  1721. $date_to = intval($_GET['date_to']);
  1722. }
  1723. $result = SessionManager::get_user_data_access_tracking_overview(
  1724. $sessionId,
  1725. $courseId,
  1726. $studentId,
  1727. $profile,
  1728. $date_to,
  1729. $date_from,
  1730. [
  1731. 'where' => $whereCondition,
  1732. 'order' => "$sidx $sord",
  1733. 'limit' => "$start , $limit",
  1734. ]
  1735. );
  1736. break;
  1737. case 'get_timelines':
  1738. $columns = ['headline', 'actions'];
  1739. if (!in_array($sidx, $columns)) {
  1740. $sidx = 'headline';
  1741. }
  1742. $course_id = api_get_course_int_id();
  1743. $result = Database::select(
  1744. '*',
  1745. $obj->table,
  1746. [
  1747. 'where' => [
  1748. 'parent_id = ? AND c_id = ?' => ['0', $course_id],
  1749. ],
  1750. 'order' => "$sidx $sord",
  1751. 'LIMIT' => "$start , $limit",
  1752. ]
  1753. );
  1754. $new_result = [];
  1755. foreach ($result as $item) {
  1756. if (!$item['status']) {
  1757. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1758. }
  1759. $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH).'timeline/view.php?id='.$item['id']);
  1760. $item['actions'] = Display::url(Display::return_icon('add.png', get_lang('Add items')), api_get_path(WEB_CODE_PATH).'timeline/?action=add_item&parent_id='.$item['id']);
  1761. $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH).'timeline/?action=edit&id='.$item['id']);
  1762. $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH).'timeline/?action=delete&id='.$item['id']);
  1763. $new_result[] = $item;
  1764. }
  1765. $result = $new_result;
  1766. break;
  1767. case 'get_gradebooks':
  1768. $columns = ['name', 'certificates', 'skills', 'actions', 'has_certificates'];
  1769. if (!in_array($sidx, $columns)) {
  1770. $sidx = 'name';
  1771. }
  1772. $result = Database::select(
  1773. '*',
  1774. $obj->table,
  1775. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1776. );
  1777. $new_result = [];
  1778. foreach ($result as $item) {
  1779. if ($item['parent_id'] != 0) {
  1780. continue;
  1781. }
  1782. $skills = $obj->getSkillsByGradebook($item['id']);
  1783. $courseId = $item['c_id'];
  1784. $courseInfo = api_get_course_info_by_id($courseId);
  1785. //Fixes bug when gradebook doesn't have names
  1786. if (empty($item['name'])) {
  1787. $item['name'] = $courseInfo['code'];
  1788. }
  1789. $item['name'] = Display::url(
  1790. $item['name'],
  1791. api_get_path(WEB_CODE_PATH).'gradebook/index.php?id_session=0&cidReq='.$courseInfo['code']
  1792. );
  1793. if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
  1794. $item['certificates'] = Display::return_icon(
  1795. 'accept.png',
  1796. get_lang('With Certificate'),
  1797. [],
  1798. ICON_SIZE_SMALL
  1799. );
  1800. $item['has_certificates'] = '1';
  1801. } else {
  1802. $item['certificates'] = Display::return_icon(
  1803. 'warning.png',
  1804. get_lang('No certificate'),
  1805. [],
  1806. ICON_SIZE_SMALL
  1807. );
  1808. $item['has_certificates'] = '0';
  1809. }
  1810. if (!empty($skills)) {
  1811. $item['skills'] = '';
  1812. foreach ($skills as $skill) {
  1813. $item['skills'] .= Display::span($skill['name'], ['class' => 'label_tag skill']);
  1814. }
  1815. }
  1816. $new_result[] = $item;
  1817. }
  1818. $result = $new_result;
  1819. break;
  1820. case 'get_careers':
  1821. $columns = ['name', 'description', 'actions'];
  1822. if (!in_array($sidx, $columns)) {
  1823. $sidx = 'name';
  1824. }
  1825. $result = Database::select(
  1826. '*',
  1827. $obj->table,
  1828. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1829. );
  1830. $new_result = [];
  1831. foreach ($result as $item) {
  1832. if (!$item['status']) {
  1833. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1834. }
  1835. $new_result[] = $item;
  1836. }
  1837. $result = $new_result;
  1838. break;
  1839. case 'get_promotions':
  1840. $columns = ['name', 'career', 'description', 'actions'];
  1841. if (!in_array($sidx, $columns)) {
  1842. $sidx = 'name';
  1843. }
  1844. $result = Database::select(
  1845. 'p.id,p.name, p.description, c.name as career, p.status',
  1846. "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ",
  1847. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1848. );
  1849. $new_result = [];
  1850. foreach ($result as $item) {
  1851. if (!$item['status']) {
  1852. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1853. }
  1854. $new_result[] = $item;
  1855. }
  1856. $result = $new_result;
  1857. break;
  1858. case 'get_mail_template':
  1859. $columns = ['name', 'type', 'default_template', 'actions'];
  1860. if (!in_array($sidx, $columns)) {
  1861. $sidx = 'name';
  1862. }
  1863. if (!in_array($sidx, $columns)) {
  1864. $sidx = 'name';
  1865. }
  1866. $result = Database::select(
  1867. '*',
  1868. $obj->table,
  1869. [
  1870. 'where' => ['url_id = ? ' => api_get_current_access_url_id()],
  1871. 'order' => "$sidx $sord",
  1872. 'LIMIT' => "$start , $limit",
  1873. ]
  1874. );
  1875. $new_result = [];
  1876. foreach ($result as $item) {
  1877. $new_result[] = $item;
  1878. }
  1879. $result = $new_result;
  1880. break;
  1881. case 'get_grade_models':
  1882. $columns = ['name', 'description', 'actions'];
  1883. if (!in_array($sidx, $columns)) {
  1884. $sidx = 'name';
  1885. }
  1886. $result = Database::select(
  1887. '*',
  1888. "$obj->table ",
  1889. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1890. );
  1891. $new_result = [];
  1892. foreach ($result as $item) {
  1893. $new_result[] = $item;
  1894. }
  1895. $result = $new_result;
  1896. break;
  1897. case 'get_usergroups':
  1898. $obj->protectScript();
  1899. $columns = ['name', 'users', 'courses', 'sessions', 'group_type', 'actions'];
  1900. $result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
  1901. break;
  1902. case 'get_extra_fields':
  1903. $obj = new ExtraField($type);
  1904. $columns = [
  1905. 'display_text',
  1906. 'variable',
  1907. 'field_type',
  1908. 'changeable',
  1909. 'visible_to_self',
  1910. 'visible_to_others',
  1911. 'filter',
  1912. 'field_order',
  1913. ];
  1914. $result = $obj->getAllGrid($sidx, $sord, $start, $limit);
  1915. $new_result = [];
  1916. if (!empty($result)) {
  1917. $checkIcon = Display::return_icon(
  1918. 'check-circle.png',
  1919. get_lang('Yes')
  1920. );
  1921. $timesIcon = Display::return_icon(
  1922. 'closed-circle.png',
  1923. get_lang('No')
  1924. );
  1925. foreach ($result as $item) {
  1926. $item['display_text'] = ExtraField::translateDisplayName(
  1927. $item['variable'],
  1928. $item['displayText']
  1929. );
  1930. $item['field_type'] = $obj->get_field_type_by_id($item['fieldType']);
  1931. $item['changeable'] = $item['changeable'] ? $checkIcon : $timesIcon;
  1932. $item['visible_to_self'] = $item['visibleToSelf'] ? $checkIcon : $timesIcon;
  1933. $item['visible_to_others'] = $item['visibleToOthers'] ? $checkIcon : $timesIcon;
  1934. $item['filter'] = $item['filter'] ? $checkIcon : $timesIcon;
  1935. $new_result[] = $item;
  1936. }
  1937. $result = $new_result;
  1938. }
  1939. break;
  1940. case 'get_exercise_grade':
  1941. $objExercise = new Exercise();
  1942. $exercises = $objExercise->getExercisesByCourseSession(
  1943. $_GET['course_id'],
  1944. $_GET['session_id']
  1945. );
  1946. $cntExer = 4;
  1947. if (!empty($exercises)) {
  1948. $cntExer += count($exercises);
  1949. }
  1950. $columns = [];
  1951. //Get dynamic column names
  1952. $i = 1;
  1953. $column_names = [];
  1954. foreach (range(1, $cntExer) as $cnt) {
  1955. switch ($cnt) {
  1956. case 1:
  1957. $columns[] = 'session';
  1958. $column_names[] = get_lang('Section');
  1959. break;
  1960. case 2:
  1961. $columns[] = 'username';
  1962. $column_names[] = get_lang('Username');
  1963. break;
  1964. case 3:
  1965. $columns[] = 'name';
  1966. $column_names[] = get_lang('Name');
  1967. break;
  1968. case $cntExer:
  1969. $columns[] = 'finalScore';
  1970. $column_names[] = get_lang('Final score');
  1971. break;
  1972. default:
  1973. $title = '';
  1974. if (!empty($exercises[$cnt - 4]['title'])) {
  1975. $title = ucwords(strtolower(trim($exercises[$cnt - 4]['title'])));
  1976. }
  1977. $columns[] = 'exer'.$i;
  1978. $column_names[] = $title;
  1979. $i++;
  1980. break;
  1981. }
  1982. }
  1983. $quizIds = [];
  1984. if (!empty($exercises)) {
  1985. foreach ($exercises as $exercise) {
  1986. $quizIds[] = $exercise['id'];
  1987. }
  1988. }
  1989. $course = api_get_course_info_by_id($_GET['course_id']);
  1990. $listUserSess = CourseManager::get_student_list_from_course_code(
  1991. $course['code'],
  1992. true,
  1993. $_GET['session_id']
  1994. );
  1995. $usersId = array_keys($listUserSess);
  1996. $users = UserManager::get_user_list_by_ids(
  1997. $usersId,
  1998. null,
  1999. "lastname, firstname",
  2000. "$start , $limit"
  2001. );
  2002. $exeResults = $objExercise->getExerciseAndResult(
  2003. $_GET['course_id'],
  2004. $_GET['session_id'],
  2005. $quizIds
  2006. );
  2007. $arrGrade = [];
  2008. foreach ($exeResults as $exeResult) {
  2009. $arrGrade[$exeResult['exe_user_id']][$exeResult['exe_exo_id']] = $exeResult['score'];
  2010. }
  2011. $result = [];
  2012. $i = 0;
  2013. foreach ($users as $user) {
  2014. $sessionInfo = SessionManager::fetch($listUserSess[$user['user_id']]['id_session']);
  2015. $result[$i]['session'] = $sessionInfo['name'];
  2016. $result[$i]['username'] = $user['username'];
  2017. $result[$i]['name'] = $user['lastname']." ".$user['firstname'];
  2018. $j = 1;
  2019. $finalScore = 0;
  2020. foreach ($quizIds as $quizID) {
  2021. $grade = '';
  2022. if (!empty($arrGrade[$user['user_id']][$quizID]) || $arrGrade[$user['user_id']][$quizID] == 0) {
  2023. $finalScore += $grade = $arrGrade[$user['user_id']][$quizID];
  2024. }
  2025. $result[$i]['exer'.$j] = $grade;
  2026. $j++;
  2027. }
  2028. if ($finalScore > 20) {
  2029. $finalScore = 20;
  2030. }
  2031. $result[$i]['finalScore'] = number_format($finalScore, 2);
  2032. $i++;
  2033. }
  2034. break;
  2035. case 'get_extra_field_options':
  2036. $obj = new ExtraFieldOption($type);
  2037. $columns = ['display_text', 'option_value', 'option_order'];
  2038. $result = $obj->get_all([
  2039. 'where' => ['field_id = ? ' => $field_id],
  2040. 'order' => "$sidx $sord",
  2041. 'LIMIT' => "$start , $limit",
  2042. ]);
  2043. break;
  2044. case 'get_usergroups_teacher':
  2045. $columns = ['name', 'users', 'status', 'group_type', 'actions'];
  2046. $options['order'] = "name $sord";
  2047. $options['limit'] = "$start , $limit";
  2048. switch ($type) {
  2049. case 'not_registered':
  2050. $result = $obj->getUserGroupNotInCourse($options, $groupFilter);
  2051. break;
  2052. case 'registered':
  2053. $result = $obj->getUserGroupInCourse($options, $groupFilter);
  2054. break;
  2055. }
  2056. $new_result = [];
  2057. $currentUserId = api_get_user_id();
  2058. $isAllow = api_is_allowed_to_edit();
  2059. if (!empty($result)) {
  2060. $urlUserGroup = api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?'.api_get_cidreq();
  2061. foreach ($result as $group) {
  2062. $countUsers = count($obj->get_users_by_usergroup($group['id']));
  2063. $group['users'] = $countUsers;
  2064. if (!empty($countUsers)) {
  2065. $group['users'] = Display::url(
  2066. $countUsers,
  2067. $urlUserGroup.'&id='.$group['id']
  2068. );
  2069. }
  2070. if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
  2071. $url = 'class.php?action=remove_class_from_course&id='.$group['id'].'&'.api_get_cidreq();
  2072. $icon = Display::return_icon('delete.png', get_lang('Remove'));
  2073. } else {
  2074. $url = 'class.php?action=add_class_to_course&id='.$group['id'].'&'.api_get_cidreq().'&type=not_registered';
  2075. $icon = Display::return_icon('add.png', get_lang('Add'));
  2076. }
  2077. switch ($group['group_type']) {
  2078. case 0:
  2079. $group['group_type'] = Display::label(get_lang('Class'), 'primary');
  2080. break;
  2081. case 1:
  2082. $group['group_type'] = Display::label(get_lang('Social'), 'success');
  2083. break;
  2084. }
  2085. $role = $obj->getUserRoleToString(api_get_user_id(), $group['id']);
  2086. $group['status'] = $role;
  2087. $group['actions'] = '';
  2088. if ($isAllow) {
  2089. if ($obj->allowTeachers() && $group['author_id'] == $currentUserId) {
  2090. $group['actions'] .= Display::url(
  2091. Display::return_icon('statistics.png', get_lang('Statistics')),
  2092. $urlUserGroup.'&id='.$group['id']
  2093. ).'&nbsp;';
  2094. }
  2095. $group['actions'] .= Display::url($icon, $url);
  2096. }
  2097. $new_result[] = $group;
  2098. }
  2099. $result = $new_result;
  2100. }
  2101. if (!in_array($sidx, $columns)) {
  2102. $sidx = 'name';
  2103. }
  2104. // Multidimensional sort
  2105. $result = msort($result, $sidx, $sord);
  2106. break;
  2107. default:
  2108. exit;
  2109. }
  2110. $allowed_actions = [
  2111. 'get_careers',
  2112. 'get_promotions',
  2113. 'get_mail_template',
  2114. 'get_usergroups',
  2115. 'get_usergroups_teacher',
  2116. 'get_gradebooks',
  2117. 'get_sessions',
  2118. 'get_session_access_overview',
  2119. 'get_sessions_tracking',
  2120. 'get_session_lp_progress',
  2121. 'get_survey_overview',
  2122. 'get_session_progress',
  2123. 'get_exercise_progress',
  2124. 'get_exercise_results',
  2125. 'get_exercise_results_report',
  2126. 'get_work_student_list_overview',
  2127. 'get_hotpotatoes_exercise_results',
  2128. 'get_work_teacher',
  2129. 'get_work_student',
  2130. 'get_work_user_list',
  2131. 'get_work_user_list_others',
  2132. 'get_work_user_list_all',
  2133. 'get_timelines',
  2134. 'get_grade_models',
  2135. 'get_user_skill_ranking',
  2136. 'get_extra_fields',
  2137. 'get_extra_field_options',
  2138. //'get_course_exercise_medias',
  2139. 'get_user_course_report',
  2140. 'get_user_course_report_resumed',
  2141. 'get_exercise_grade',
  2142. 'get_group_reporting',
  2143. 'get_course_announcements',
  2144. 'get_programmed_announcements',
  2145. 'course_log_events',
  2146. 'get_learning_path_calendars',
  2147. 'get_usergroups_users',
  2148. 'get_calendar_users',
  2149. 'get_exercise_categories',
  2150. ];
  2151. // 5. Creating an obj to return a json
  2152. if (in_array($action, $allowed_actions)) {
  2153. $response = new stdClass();
  2154. $response->page = $page;
  2155. $response->total = $total_pages;
  2156. $response->records = $count;
  2157. if ($operation && $operation == 'excel') {
  2158. $j = 1;
  2159. $array = [];
  2160. if (empty($column_names)) {
  2161. $column_names = $columns;
  2162. }
  2163. // Headers
  2164. foreach ($column_names as $col) {
  2165. // Overwrite titles
  2166. if (isset($overwriteColumnHeaderExport[$col])) {
  2167. $col = $overwriteColumnHeaderExport[$col];
  2168. }
  2169. $array[0][] = $col;
  2170. }
  2171. foreach ($result as $row) {
  2172. foreach ($columns as $col) {
  2173. $array[$j][] = strip_tags($row[$col]);
  2174. }
  2175. $j++;
  2176. }
  2177. $fileName = !empty($action) ? $action : 'company_report';
  2178. if (!empty($exportFilename)) {
  2179. $fileName = $exportFilename;
  2180. }
  2181. switch ($exportFormat) {
  2182. case 'xls':
  2183. Export::arrayToXls($array, $fileName);
  2184. break;
  2185. case 'xls_html':
  2186. //TODO add date if exists
  2187. $browser = new Browser();
  2188. if ($browser->getPlatform() == Browser::PLATFORM_WINDOWS) {
  2189. Export::export_table_xls_html($array, $fileName, 'ISO-8859-15');
  2190. } else {
  2191. Export::export_table_xls_html($array, $fileName);
  2192. }
  2193. break;
  2194. case 'csv':
  2195. default:
  2196. Export::arrayToCsv($array, $fileName);
  2197. break;
  2198. }
  2199. exit;
  2200. }
  2201. $i = 0;
  2202. if (!empty($result)) {
  2203. foreach ($result as $row) {
  2204. // if results tab give not id, set id to $i otherwise id="null"
  2205. // for all <tr> of the jqgrid - ref #4235
  2206. if (!isset($row['id']) || isset($row['id']) && $row['id'] == '') {
  2207. $response->rows[$i]['id'] = $i;
  2208. } else {
  2209. $response->rows[$i]['id'] = $row['id'];
  2210. }
  2211. $array = [];
  2212. foreach ($columns as $col) {
  2213. if (in_array($col, ['correction', 'actions'])) {
  2214. $array[] = isset($row[$col]) ? $row[$col] : '';
  2215. } else {
  2216. $array[] = isset($row[$col]) ? Security::remove_XSS($row[$col]) : '';
  2217. }
  2218. }
  2219. $response->rows[$i]['cell'] = $array;
  2220. $i++;
  2221. }
  2222. }
  2223. header('Content-Type: application/json;charset=utf-8');
  2224. echo json_encode($response);
  2225. }
  2226. exit;