model.ajax.php 59 KB

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