model.ajax.php 66 KB

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