model.ajax.php 77 KB

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