model.ajax.php 58 KB

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