model.ajax.php 59 KB

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