model.ajax.php 77 KB

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