model.ajax.php 71 KB

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