model.ajax.php 60 KB

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