model.ajax.php 78 KB

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