model.ajax.php 57 KB

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