model.ajax.php 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427
  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();
  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 (!empty($whereCondition)) {
  547. $whereCondition = " AND $whereCondition";
  548. }
  549. $count = ExerciseLib::get_count_exam_results(
  550. $exercise_id,
  551. $whereCondition
  552. );
  553. break;
  554. case 'get_exercise_results_report':
  555. api_protect_admin_script();
  556. $exerciseId = isset($_REQUEST['exercise_id']) ? $_REQUEST['exercise_id'] : 0;
  557. $courseId = isset($_REQUEST['course_id']) ? $_REQUEST['course_id'] : 0;
  558. if (empty($exerciseId)) {
  559. exit;
  560. }
  561. if (!empty($courseId)) {
  562. $courseInfo = api_get_course_info_by_id($courseId);
  563. } else {
  564. $courseCode = isset($_REQUEST['cidReq']) ? $_REQUEST['cidReq'] : '';
  565. if (!empty($courseCode)) {
  566. $courseInfo = api_get_course_info($courseCode);
  567. }
  568. }
  569. if (empty($courseInfo)) {
  570. exit;
  571. }
  572. $startDate = Database::escape_string($_REQUEST['start_date']);
  573. $whereCondition .= " AND exe_date > '$startDate' AND te.status = '' ";
  574. $count = ExerciseLib::get_count_exam_results(
  575. $exerciseId,
  576. $whereCondition,
  577. $courseInfo['code'],
  578. true
  579. );
  580. break;
  581. case 'get_hotpotatoes_exercise_results':
  582. $hotpot_path = $_REQUEST['path'];
  583. $count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
  584. break;
  585. case 'get_sessions_tracking':
  586. $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
  587. $description = '';
  588. $setting = api_get_setting('show_session_description');
  589. if ($setting === 'true') {
  590. $description = $keyword;
  591. }
  592. if (api_is_drh() || api_is_session_admin()) {
  593. $count = SessionManager::get_sessions_followed_by_drh(
  594. api_get_user_id(),
  595. null,
  596. null,
  597. true,
  598. false,
  599. false,
  600. null,
  601. $keyword,
  602. $description,
  603. ['where' => $whereCondition, 'extra' => $extra_fields]
  604. );
  605. } else {
  606. // Sessions for the coach
  607. $count = Tracking::get_sessions_coached_by_user(
  608. api_get_user_id(),
  609. null,
  610. null,
  611. true,
  612. $keyword,
  613. $description,
  614. null,
  615. null,
  616. ['where' => $whereCondition, 'extra' => $extra_fields]
  617. );
  618. }
  619. break;
  620. case 'get_sessions':
  621. $list_type = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : 'simple';
  622. $language = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : '';
  623. $session_columns = SessionManager::getGridColumns($list_type);
  624. $columns = $session_columns['simple_column_name'];
  625. $loadExtraFields = isset($_REQUEST['load_extra_field']) ? $_REQUEST['load_extra_field'] : '';
  626. $extraFieldsToLoad = [];
  627. if (!empty($loadExtraFields)) {
  628. $loadExtraFields = explode(',', $loadExtraFields);
  629. foreach ($loadExtraFields as $fieldId) {
  630. $extraField = new ExtraField('session');
  631. $fieldData = $extraField->get($fieldId);
  632. $extraFieldsToLoad[] = $fieldData;
  633. }
  634. }
  635. if ($list_type === 'simple') {
  636. $count = SessionManager::get_sessions_admin(
  637. ['where' => $whereCondition, 'extra' => $extra_fields],
  638. true,
  639. [],
  640. $extraFieldsToLoad,
  641. $language
  642. //$accessStartDate,
  643. //$accessEndDate
  644. );
  645. } else {
  646. $count = SessionManager::get_count_admin_complete(
  647. ['where' => $whereCondition, 'extra' => $extra_fields]
  648. );
  649. }
  650. break;
  651. case 'get_session_lp_progress':
  652. case 'get_session_progress':
  653. //@TODO replace this for a more efficient function (not retrieving the whole data)
  654. $course = api_get_course_info_by_id($_GET['course_id']);
  655. $users = CourseManager::get_student_list_from_course_code(
  656. $course['code'],
  657. true,
  658. $_GET['session_id'],
  659. $_GET['date_from'],
  660. $_GET['date_to']
  661. );
  662. $count = count($users);
  663. break;
  664. case 'get_exercise_progress':
  665. //@TODO replace this for a more efficient function (not retrieving the whole data)
  666. $records = Tracking::get_exercise_progress(
  667. $_GET['session_id'],
  668. $_GET['course_id'],
  669. $_GET['exercise_id'],
  670. $_GET['date_from'],
  671. $_GET['date_to']
  672. );
  673. $count = count($records);
  674. break;
  675. case 'get_session_access_overview':
  676. //@TODO replace this for a more efficient function (not retrieving the whole data)
  677. $records = SessionManager::get_user_data_access_tracking_overview(
  678. $_GET['session_id'],
  679. $_GET['course_id'],
  680. $_GET['student_id'],
  681. $_GET['profile'],
  682. $_GET['date_from'],
  683. $_GET['date_to'],
  684. $options
  685. );
  686. $count = count($records);
  687. break;
  688. case 'get_survey_overview':
  689. //@TODO replace this for a more efficient function (not retrieving the whole data)
  690. $records = SessionManager::get_survey_overview(
  691. $_GET['session_id'],
  692. $_GET['course_id'],
  693. $_GET['survey_id'],
  694. $_GET['date_from'],
  695. $_GET['date_to'],
  696. $options
  697. );
  698. $count = count($records);
  699. break;
  700. case 'get_exercise_grade':
  701. //@TODO replace this for a more efficient function (not retrieving the whole data)
  702. $course = api_get_course_info_by_id($_GET['course_id']);
  703. $users = CourseManager::get_student_list_from_course_code(
  704. $course['code'],
  705. true,
  706. $_GET['session_id']
  707. );
  708. $count = count($users);
  709. break;
  710. case 'get_extra_fields':
  711. $type = $_REQUEST['type'];
  712. $obj = new ExtraField($type);
  713. $count = $obj->get_count();
  714. break;
  715. case 'get_extra_field_options':
  716. $type = $_REQUEST['type'];
  717. $field_id = $_REQUEST['field_id'];
  718. $obj = new ExtraFieldOption($type);
  719. $count = $obj->get_count_by_field_id($field_id);
  720. break;
  721. case 'get_timelines':
  722. $obj = new Timeline();
  723. $count = $obj->get_count();
  724. break;
  725. case 'get_gradebooks':
  726. $obj = new Gradebook();
  727. $count = $obj->get_count();
  728. break;
  729. case 'get_event_email_template':
  730. $obj = new EventEmailTemplate();
  731. $count = $obj->get_count();
  732. break;
  733. case 'get_careers':
  734. $obj = new Career();
  735. $count = $obj->get_count();
  736. break;
  737. case 'get_promotions':
  738. $obj = new Promotion();
  739. $count = $obj->get_count();
  740. break;
  741. case 'get_mail_template':
  742. $obj = new MailTemplateManager();
  743. $count = $obj->get_count();
  744. break;
  745. case 'get_grade_models':
  746. $obj = new GradeModel();
  747. $count = $obj->get_count();
  748. break;
  749. case 'get_usergroups':
  750. $obj = new UserGroup();
  751. $obj->protectScript();
  752. $count = $obj->get_count();
  753. break;
  754. case 'get_usergroups_teacher':
  755. $obj = new UserGroup();
  756. $obj->protectScript();
  757. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
  758. $groupFilter = isset($_REQUEST['group_filter']) ? (int) $_REQUEST['group_filter'] : 0;
  759. $course_id = api_get_course_int_id();
  760. if ($type === 'registered') {
  761. $count = $obj->getUserGroupByCourseWithDataCount(
  762. $course_id,
  763. $groupFilter
  764. );
  765. } else {
  766. $count = $obj->get_count($groupFilter);
  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('TrainingHoursAccumulated'),
  902. get_lang('CountOfSubscriptions'),
  903. get_lang('CountOfUsers'),
  904. get_lang('AverageHoursPerStudent'),
  905. get_lang('CountCertificates'),
  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('Email'),
  970. get_lang('ManHours'),
  971. get_lang('CertificateGenerated'),
  972. get_lang('Approved'),
  973. get_lang('CourseAdvance'),
  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. $course = api_get_course_info();
  1248. // Used inside ExerciseLib::get_exam_results_data()
  1249. $documentPath = api_get_path(SYS_COURSE_PATH).$course['path']."/document";
  1250. $is_allowedToEdit = api_is_allowed_to_edit(null, true) ||
  1251. api_is_drh() ||
  1252. api_is_student_boss() ||
  1253. api_is_session_admin();
  1254. if ($is_allowedToEdit || api_is_student_boss()) {
  1255. $columns = [
  1256. 'firstname',
  1257. 'lastname',
  1258. 'username',
  1259. 'group_name',
  1260. 'exe_duration',
  1261. 'start_date',
  1262. 'exe_date',
  1263. 'score',
  1264. 'user_ip',
  1265. 'status',
  1266. 'lp',
  1267. 'actions',
  1268. ];
  1269. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  1270. if ($officialCodeInList === 'true') {
  1271. $columns = array_merge(['official_code'], $columns);
  1272. }
  1273. }
  1274. $result = ExerciseLib::get_exam_results_data(
  1275. $start,
  1276. $limit,
  1277. $sidx,
  1278. $sord,
  1279. $exercise_id,
  1280. $whereCondition
  1281. );
  1282. break;
  1283. case 'get_exercise_results_report':
  1284. // Used inside ExerciseLib::get_exam_results_data()
  1285. $documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
  1286. $sessionId = api_get_session_id();
  1287. $columns = [
  1288. 'firstname',
  1289. 'lastname',
  1290. 'username',
  1291. ];
  1292. $extraFieldsToAdd = [];
  1293. $extraFields = api_get_configuration_value('exercise_category_report_user_extra_fields');
  1294. $roundValues = api_get_configuration_value('exercise_category_round_score_in_export');
  1295. if (!empty($extraFields) && isset($extraFields['fields'])) {
  1296. $extraField = new ExtraField('user');
  1297. foreach ($extraFields['fields'] as $variable) {
  1298. $info = $extraField->get_handler_field_info_by_field_variable($variable);
  1299. if ($info) {
  1300. $extraFieldsToAdd[] = $variable;
  1301. }
  1302. }
  1303. }
  1304. if (!empty($extraFieldsToAdd)) {
  1305. $columns = array_merge($columns, $extraFieldsToAdd);
  1306. }
  1307. $columns[] = 'session';
  1308. $columns[] = 'session_access_start_date';
  1309. $columns[] = 'exe_date';
  1310. $columns[] = 'score';
  1311. if ($operation === 'excel') {
  1312. $columns = [
  1313. 'firstname',
  1314. 'lastname',
  1315. 'username',
  1316. ];
  1317. if (!empty($extraFieldsToAdd)) {
  1318. $columns = array_merge($columns, $extraFieldsToAdd);
  1319. }
  1320. $columns[] = 'session';
  1321. $columns[] = 'session_access_start_date';
  1322. $columns[] = 'exe_date';
  1323. $columns[] = 'score_percentage';
  1324. $columns[] = 'only_score';
  1325. $columns[] = 'total';
  1326. $overwriteColumnHeaderExport['session_access_start_date'] = get_lang('SessionStartDate');
  1327. $overwriteColumnHeaderExport['exe_date'] = get_lang('StartDate');
  1328. $overwriteColumnHeaderExport['score_percentage'] = get_lang('Score').' - '.get_lang('Percentage');
  1329. $overwriteColumnHeaderExport['only_score'] = get_lang('Score').' - '.get_lang('ScoreNote');
  1330. $overwriteColumnHeaderExport['total'] = get_lang('Score').' - '.get_lang('ScoreTest');
  1331. }
  1332. $categoryList = TestCategory::getListOfCategoriesIDForTest($exerciseId, $courseId);
  1333. if (!empty($categoryList)) {
  1334. foreach ($categoryList as $categoryInfo) {
  1335. $label = 'category_'.$categoryInfo['id'];
  1336. if ($operation == 'excel') {
  1337. $columns[] = $label.'_score_percentage';
  1338. $columns[] = $label.'_only_score';
  1339. $columns[] = $label.'_total';
  1340. $overwriteColumnHeaderExport[$label] = $categoryInfo['title'];
  1341. $overwriteColumnHeaderExport[$label.'_score_percentage'] = $categoryInfo['title'].
  1342. ' - '.get_lang('Percentage');
  1343. $overwriteColumnHeaderExport[$label.'_only_score'] = $categoryInfo['title'].
  1344. ' - '.get_lang('ScoreNote');
  1345. $overwriteColumnHeaderExport[$label.'_total'] = $categoryInfo['title'].
  1346. ' - '.get_lang('ScoreTest');
  1347. } else {
  1348. $columns[] = $label;
  1349. }
  1350. }
  1351. }
  1352. if ($operation !== 'excel') {
  1353. $columns[] = 'actions';
  1354. }
  1355. $whereCondition .= " AND te.status = '' ";
  1356. $result = ExerciseLib::get_exam_results_data(
  1357. $start,
  1358. $limit,
  1359. $sidx,
  1360. $sord,
  1361. $exerciseId,
  1362. $whereCondition,
  1363. false,
  1364. $courseInfo['code'],
  1365. true,
  1366. true,
  1367. $extraFieldsToAdd,
  1368. true,
  1369. $roundValues
  1370. );
  1371. break;
  1372. case 'get_hotpotatoes_exercise_results':
  1373. $course = api_get_course_info();
  1374. $documentPath = api_get_path(SYS_COURSE_PATH).$course['path']."/document";
  1375. if (api_is_allowed_to_edit()) {
  1376. $columns = ['firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions'];
  1377. } else {
  1378. $columns = ['exe_date', 'score', 'actions'];
  1379. }
  1380. $result = ExerciseLib::get_exam_results_hotpotatoes_data(
  1381. $start,
  1382. $limit,
  1383. $sidx,
  1384. $sord,
  1385. $hotpot_path,
  1386. $whereCondition
  1387. );
  1388. break;
  1389. case 'get_work_student_list_overview':
  1390. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  1391. return [];
  1392. }
  1393. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  1394. $columns = [
  1395. 'student', 'works',
  1396. ];
  1397. $result = getWorkUserListData(
  1398. $workId,
  1399. api_get_course_id(),
  1400. api_get_session_id(),
  1401. api_get_group_id(),
  1402. $start,
  1403. $limit,
  1404. $sidx,
  1405. $sord
  1406. );
  1407. break;
  1408. case 'get_hotpotatoes_exercise_results':
  1409. $course = api_get_course_info();
  1410. $documentPath = api_get_path(SYS_COURSE_PATH).$course['path']."/document";
  1411. if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
  1412. $columns = ['firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions'];
  1413. } else {
  1414. $columns = ['exe_date', 'score', 'actions'];
  1415. }
  1416. $result = ExerciseLib::get_exam_results_hotpotatoes_data(
  1417. $start,
  1418. $limit,
  1419. $sidx,
  1420. $sord,
  1421. $hotpot_path,
  1422. $whereCondition
  1423. );
  1424. break;
  1425. case 'get_sessions_tracking':
  1426. if (api_is_drh() || api_is_session_admin()) {
  1427. $orderByName = Database::escape_string($sidx);
  1428. $orderByName = in_array($orderByName, ['name', 'access_start_date']) ? $orderByName : 'name';
  1429. $orderBy = " ORDER BY $orderByName $sord";
  1430. $sessions = SessionManager::get_sessions_followed_by_drh(
  1431. api_get_user_id(),
  1432. $start,
  1433. $limit,
  1434. false,
  1435. false,
  1436. false,
  1437. $orderBy,
  1438. $keyword,
  1439. $description
  1440. );
  1441. } else {
  1442. // Sessions for the coach
  1443. $sessions = Tracking::get_sessions_coached_by_user(
  1444. api_get_user_id(),
  1445. $start,
  1446. $limit,
  1447. false,
  1448. $keyword,
  1449. $description,
  1450. $sidx,
  1451. $sord
  1452. );
  1453. }
  1454. $columns = [
  1455. 'name',
  1456. 'date',
  1457. 'course_per_session',
  1458. 'student_per_session',
  1459. 'details',
  1460. ];
  1461. $result = [];
  1462. if (!empty($sessions)) {
  1463. foreach ($sessions as $session) {
  1464. if (api_drh_can_access_all_session_content()) {
  1465. $count_courses_in_session = SessionManager::get_course_list_by_session_id(
  1466. $session['id'],
  1467. '',
  1468. null,
  1469. true
  1470. );
  1471. } else {
  1472. $count_courses_in_session = count(
  1473. Tracking::get_courses_followed_by_coach(
  1474. $user_id,
  1475. $session['id']
  1476. )
  1477. );
  1478. }
  1479. $count_users_in_session = SessionManager::get_users_by_session(
  1480. $session['id'],
  1481. 0,
  1482. true
  1483. );
  1484. $session['display_start_date'] = '';
  1485. $session['display_end_date'] = '';
  1486. $session['coach_access_start_date'] = '';
  1487. $session['coach_access_end_date'] = '';
  1488. $dateData = SessionManager::parseSessionDates($session, true);
  1489. $dateToString = $dateData['access'];
  1490. $detailButtons = [];
  1491. $detailButtons[] = Display::url(
  1492. Display::return_icon('works.png', get_lang('WorksReport')),
  1493. api_get_path(WEB_CODE_PATH).'mySpace/works_in_session_report.php?session='.$session['id']
  1494. );
  1495. $detailButtons[] = Display::url(
  1496. Display::return_icon('2rightarrow.png'),
  1497. api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id']
  1498. );
  1499. $result[] = [
  1500. 'name' => Display::url(
  1501. $session['name'],
  1502. api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id']
  1503. ),
  1504. 'date' => $dateToString,
  1505. 'course_per_session' => $count_courses_in_session,
  1506. 'student_per_session' => $count_users_in_session,
  1507. 'details' => implode(' ', $detailButtons),
  1508. ];
  1509. }
  1510. }
  1511. break;
  1512. case 'get_sessions':
  1513. $session_columns = SessionManager::getGridColumns($list_type);
  1514. $columns = $session_columns['simple_column_name'];
  1515. if ($list_type == 'simple') {
  1516. $result = SessionManager::get_sessions_admin(
  1517. [
  1518. 'where' => $whereCondition,
  1519. 'order' => "$sidx $sord, s.name",
  1520. 'extra' => $extra_fields,
  1521. 'limit' => "$start , $limit",
  1522. ],
  1523. false,
  1524. $session_columns,
  1525. $extraFieldsToLoad,
  1526. $language
  1527. //$accessStartDate,
  1528. //$accessEndDate
  1529. );
  1530. } else {
  1531. $result = SessionManager::get_sessions_admin_complete(
  1532. [
  1533. 'where' => $whereCondition,
  1534. 'order' => "$sidx $sord, s.name",
  1535. 'extra' => $extra_fields,
  1536. 'limit' => "$start , $limit",
  1537. ]
  1538. );
  1539. }
  1540. break;
  1541. case 'get_exercise_progress':
  1542. $sessionId = (int) $_GET['session_id'];
  1543. $courseId = (int) $_GET['course_id'];
  1544. $exerciseId = (int) $_GET['exercise_id'];
  1545. $date_from = $_GET['date_from'];
  1546. $date_to = $_GET['date_to'];
  1547. $columns = [
  1548. 'session',
  1549. 'exercise_id',
  1550. 'quiz_title',
  1551. 'username',
  1552. 'lastname',
  1553. 'firstname',
  1554. 'time',
  1555. 'question_id',
  1556. 'question',
  1557. 'description',
  1558. 'answer',
  1559. 'correct',
  1560. ];
  1561. $result = Tracking::get_exercise_progress(
  1562. $sessionId,
  1563. $courseId,
  1564. $exerciseId,
  1565. $date_from,
  1566. $date_to,
  1567. [
  1568. 'where' => $whereCondition,
  1569. 'order' => "$sidx $sord",
  1570. 'limit' => "$start , $limit",
  1571. ]
  1572. );
  1573. break;
  1574. case 'get_session_lp_progress':
  1575. $sessionId = 0;
  1576. if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) {
  1577. $sessionId = (int) $_GET['session_id'];
  1578. $courseId = (int) $_GET['course_id'];
  1579. $course = api_get_course_info_by_id($courseId);
  1580. }
  1581. /**
  1582. * Add lessons of course.
  1583. */
  1584. $columns = [
  1585. 'username',
  1586. 'firstname',
  1587. 'lastname',
  1588. ];
  1589. $lessons = LearnpathList::get_course_lessons(
  1590. $course['code'],
  1591. $sessionId
  1592. );
  1593. foreach ($lessons as $lesson_id => $lesson) {
  1594. $columns[] = $lesson_id;
  1595. }
  1596. $columns[] = 'total';
  1597. $result = SessionManager::get_session_lp_progress(
  1598. $sessionId,
  1599. $courseId,
  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_survey_overview':
  1610. $sessionId = 0;
  1611. if (!empty($_GET['session_id']) &&
  1612. !empty($_GET['course_id']) &&
  1613. !empty($_GET['survey_id'])
  1614. ) {
  1615. $sessionId = intval($_GET['session_id']);
  1616. $courseId = intval($_GET['course_id']);
  1617. $surveyId = intval($_GET['survey_id']);
  1618. $date_from = $_GET['date_from'];
  1619. $date_to = $_GET['date_to'];
  1620. //$course = api_get_course_info_by_id($courseId);
  1621. }
  1622. /**
  1623. * Add lessons of course.
  1624. */
  1625. $columns = [
  1626. 'username',
  1627. 'firstname',
  1628. 'lastname',
  1629. ];
  1630. $questions = SurveyManager::get_questions($surveyId, $courseId);
  1631. foreach ($questions as $question_id => $question) {
  1632. $columns[] = $question_id;
  1633. }
  1634. $result = SessionManager::get_survey_overview(
  1635. $sessionId,
  1636. $courseId,
  1637. $surveyId,
  1638. $date_from,
  1639. $date_to,
  1640. [
  1641. 'where' => $whereCondition,
  1642. 'order' => "$sidx $sord",
  1643. 'limit' => "$start , $limit",
  1644. ]
  1645. );
  1646. break;
  1647. case 'get_session_progress':
  1648. $columns = [
  1649. 'lastname',
  1650. 'firstname',
  1651. 'username',
  1652. //'profile',
  1653. 'total',
  1654. 'courses',
  1655. 'lessons',
  1656. 'exercises',
  1657. 'forums',
  1658. 'homeworks',
  1659. 'wikis',
  1660. 'surveys',
  1661. //exercises
  1662. 'lessons_total',
  1663. 'lessons_done',
  1664. 'lessons_left',
  1665. 'lessons_progress',
  1666. //exercises
  1667. 'exercises_total',
  1668. 'exercises_done',
  1669. 'exercises_left',
  1670. 'exercises_progress',
  1671. //forums
  1672. 'forums_total',
  1673. 'forums_done',
  1674. 'forums_left',
  1675. 'forums_progress',
  1676. //assignments
  1677. 'assignments_total',
  1678. 'assignments_done',
  1679. 'assignments_left',
  1680. 'assignments_progress',
  1681. //Wiki
  1682. 'wiki_total',
  1683. 'wiki_revisions',
  1684. 'wiki_read',
  1685. 'wiki_unread',
  1686. 'wiki_progress',
  1687. //surveys
  1688. 'surveys_total',
  1689. 'surveys_done',
  1690. 'surveys_left',
  1691. 'surveys_progress',
  1692. ];
  1693. $sessionId = 0;
  1694. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  1695. $sessionId = intval($_GET['session_id']);
  1696. $courseId = intval($_GET['course_id']);
  1697. }
  1698. $result = SessionManager::get_session_progress(
  1699. $sessionId,
  1700. $courseId,
  1701. null,
  1702. null,
  1703. [
  1704. 'where' => $whereCondition,
  1705. 'order' => "$sidx $sord",
  1706. 'limit' => "$start , $limit",
  1707. ]
  1708. );
  1709. break;
  1710. case 'get_session_access_overview':
  1711. $columns = [
  1712. 'logindate',
  1713. 'username',
  1714. 'lastname',
  1715. 'firstname',
  1716. 'clicks',
  1717. 'ip',
  1718. 'timeLoggedIn',
  1719. 'session',
  1720. ];
  1721. $sessionId = 0;
  1722. if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
  1723. $sessionId = intval($_GET['session_id']);
  1724. $courseId = intval($_GET['course_id']);
  1725. $studentId = intval($_GET['student_id']);
  1726. $profile = intval($_GET['profile']);
  1727. $date_from = intval($_GET['date_from']);
  1728. $date_to = intval($_GET['date_to']);
  1729. }
  1730. $result = SessionManager::get_user_data_access_tracking_overview(
  1731. $sessionId,
  1732. $courseId,
  1733. $studentId,
  1734. $profile,
  1735. $date_to,
  1736. $date_from,
  1737. [
  1738. 'where' => $whereCondition,
  1739. 'order' => "$sidx $sord",
  1740. 'limit' => "$start , $limit",
  1741. ]
  1742. );
  1743. break;
  1744. case 'get_timelines':
  1745. $columns = ['headline', 'actions'];
  1746. if (!in_array($sidx, $columns)) {
  1747. $sidx = 'headline';
  1748. }
  1749. $course_id = api_get_course_int_id();
  1750. $result = Database::select(
  1751. '*',
  1752. $obj->table,
  1753. [
  1754. 'where' => [
  1755. 'parent_id = ? AND c_id = ?' => ['0', $course_id],
  1756. ],
  1757. 'order' => "$sidx $sord",
  1758. 'LIMIT' => "$start , $limit",
  1759. ]
  1760. );
  1761. $new_result = [];
  1762. foreach ($result as $item) {
  1763. if (!$item['status']) {
  1764. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1765. }
  1766. $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH).'timeline/view.php?id='.$item['id']);
  1767. $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']);
  1768. $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH).'timeline/?action=edit&id='.$item['id']);
  1769. $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH).'timeline/?action=delete&id='.$item['id']);
  1770. $new_result[] = $item;
  1771. }
  1772. $result = $new_result;
  1773. break;
  1774. case 'get_gradebooks':
  1775. $columns = ['name', 'certificates', 'skills', 'actions', 'has_certificates'];
  1776. if (!in_array($sidx, $columns)) {
  1777. $sidx = 'name';
  1778. }
  1779. $result = Database::select(
  1780. '*',
  1781. $obj->table,
  1782. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1783. );
  1784. $new_result = [];
  1785. foreach ($result as $item) {
  1786. if ($item['parent_id'] != 0) {
  1787. continue;
  1788. }
  1789. $skills = $obj->getSkillsByGradebook($item['id']);
  1790. //Fixes bug when gradebook doesn't have names
  1791. if (empty($item['name'])) {
  1792. $item['name'] = $item['course_code'];
  1793. }
  1794. $item['name'] = Display::url(
  1795. $item['name'],
  1796. api_get_path(WEB_CODE_PATH).'gradebook/index.php?id_session=0&cidReq='.$item['course_code']
  1797. );
  1798. if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
  1799. $item['certificates'] = Display::return_icon(
  1800. 'accept.png',
  1801. get_lang('WithCertificate'),
  1802. [],
  1803. ICON_SIZE_SMALL
  1804. );
  1805. $item['has_certificates'] = '1';
  1806. } else {
  1807. $item['certificates'] = Display::return_icon(
  1808. 'warning.png',
  1809. get_lang('NoCertificate'),
  1810. [],
  1811. ICON_SIZE_SMALL
  1812. );
  1813. $item['has_certificates'] = '0';
  1814. }
  1815. if (!empty($skills)) {
  1816. $item['skills'] = '';
  1817. foreach ($skills as $skill) {
  1818. $item['skills'] .= Display::span($skill['name'], ['class' => 'label_tag skill']);
  1819. }
  1820. }
  1821. $new_result[] = $item;
  1822. }
  1823. $result = $new_result;
  1824. break;
  1825. case 'get_event_email_template':
  1826. $columns = ['subject', 'event_type_name', 'language_id', 'activated', 'actions'];
  1827. if (!in_array($sidx, $columns)) {
  1828. $sidx = 'subject';
  1829. }
  1830. $result = Database::select(
  1831. '*',
  1832. $obj->table,
  1833. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1834. );
  1835. $new_result = [];
  1836. foreach ($result as $item) {
  1837. $language_info = api_get_language_info($item['language_id']);
  1838. $item['language_id'] = $language_info['english_name'];
  1839. $item['actions'] = Display::url(
  1840. Display::return_icon('edit.png', get_lang('Edit')),
  1841. api_get_path(WEB_CODE_PATH).'admin/event_type.php?action=edit&event_type_name='.$item['event_type_name']
  1842. );
  1843. $item['actions'] .= Display::url(
  1844. Display::return_icon('delete.png', get_lang('Delete')),
  1845. api_get_path(WEB_CODE_PATH).'admin/event_controller.php?action=delete&id='.$item['id']
  1846. );
  1847. $new_result[] = $item;
  1848. }
  1849. $result = $new_result;
  1850. break;
  1851. case 'get_careers':
  1852. $columns = ['name', 'description', 'actions'];
  1853. if (!in_array($sidx, $columns)) {
  1854. $sidx = 'name';
  1855. }
  1856. $result = Database::select(
  1857. '*',
  1858. $obj->table,
  1859. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1860. );
  1861. $new_result = [];
  1862. foreach ($result as $item) {
  1863. if (!$item['status']) {
  1864. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1865. }
  1866. $new_result[] = $item;
  1867. }
  1868. $result = $new_result;
  1869. break;
  1870. case 'get_promotions':
  1871. $columns = ['name', 'career', 'description', 'actions'];
  1872. if (!in_array($sidx, $columns)) {
  1873. $sidx = 'name';
  1874. }
  1875. $result = Database::select(
  1876. 'p.id,p.name, p.description, c.name as career, p.status',
  1877. "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ",
  1878. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1879. );
  1880. $new_result = [];
  1881. foreach ($result as $item) {
  1882. if (!$item['status']) {
  1883. $item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
  1884. }
  1885. $new_result[] = $item;
  1886. }
  1887. $result = $new_result;
  1888. break;
  1889. case 'get_mail_template':
  1890. $columns = ['name', 'type', 'default_template', 'actions'];
  1891. if (!in_array($sidx, $columns)) {
  1892. $sidx = 'name';
  1893. }
  1894. if (!in_array($sidx, $columns)) {
  1895. $sidx = 'name';
  1896. }
  1897. $result = Database::select(
  1898. '*',
  1899. $obj->table,
  1900. [
  1901. 'where' => ['url_id = ? ' => api_get_current_access_url_id()],
  1902. 'order' => "$sidx $sord",
  1903. 'LIMIT' => "$start , $limit",
  1904. ]
  1905. );
  1906. $new_result = [];
  1907. foreach ($result as $item) {
  1908. $new_result[] = $item;
  1909. }
  1910. $result = $new_result;
  1911. break;
  1912. case 'get_grade_models':
  1913. $columns = ['name', 'description', 'actions'];
  1914. if (!in_array($sidx, $columns)) {
  1915. $sidx = 'name';
  1916. }
  1917. $result = Database::select(
  1918. '*',
  1919. "$obj->table ",
  1920. ['order' => "$sidx $sord", 'LIMIT' => "$start , $limit"]
  1921. );
  1922. $new_result = [];
  1923. foreach ($result as $item) {
  1924. $new_result[] = $item;
  1925. }
  1926. $result = $new_result;
  1927. break;
  1928. case 'get_usergroups':
  1929. $obj->protectScript();
  1930. $columns = ['name', 'users', 'courses', 'sessions', 'group_type', 'actions'];
  1931. $result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
  1932. break;
  1933. case 'get_extra_fields':
  1934. $obj = new ExtraField($type);
  1935. $columns = [
  1936. 'display_text',
  1937. 'variable',
  1938. 'field_type',
  1939. 'changeable',
  1940. 'visible_to_self',
  1941. 'visible_to_others',
  1942. 'filter',
  1943. 'field_order',
  1944. ];
  1945. $result = $obj->getAllGrid($sidx, $sord, $start, $limit);
  1946. $new_result = [];
  1947. if (!empty($result)) {
  1948. $checkIcon = Display::return_icon(
  1949. 'check-circle.png',
  1950. get_lang('Yes')
  1951. );
  1952. $timesIcon = Display::return_icon(
  1953. 'closed-circle.png',
  1954. get_lang('No')
  1955. );
  1956. foreach ($result as $item) {
  1957. $item['display_text'] = ExtraField::translateDisplayName(
  1958. $item['variable'],
  1959. $item['displayText']
  1960. );
  1961. $item['field_type'] = $obj->get_field_type_by_id($item['fieldType']);
  1962. $item['changeable'] = $item['changeable'] ? $checkIcon : $timesIcon;
  1963. $item['visible_to_self'] = $item['visibleToSelf'] ? $checkIcon : $timesIcon;
  1964. $item['visible_to_others'] = $item['visibleToOthers'] ? $checkIcon : $timesIcon;
  1965. $item['filter'] = $item['filter'] ? $checkIcon : $timesIcon;
  1966. $new_result[] = $item;
  1967. }
  1968. $result = $new_result;
  1969. }
  1970. break;
  1971. case 'get_exercise_grade':
  1972. $objExercise = new Exercise();
  1973. $exercises = $objExercise->getExercisesByCourseSession(
  1974. $_GET['course_id'],
  1975. $_GET['session_id']
  1976. );
  1977. $cntExer = 4;
  1978. if (!empty($exercises)) {
  1979. $cntExer += count($exercises);
  1980. }
  1981. $columns = [];
  1982. //Get dynamic column names
  1983. $i = 1;
  1984. $column_names = [];
  1985. foreach (range(1, $cntExer) as $cnt) {
  1986. switch ($cnt) {
  1987. case 1:
  1988. $columns[] = 'session';
  1989. $column_names[] = get_lang('Section');
  1990. break;
  1991. case 2:
  1992. $columns[] = 'username';
  1993. $column_names[] = get_lang('Username');
  1994. break;
  1995. case 3:
  1996. $columns[] = 'name';
  1997. $column_names[] = get_lang('Name');
  1998. break;
  1999. case $cntExer:
  2000. $columns[] = 'finalScore';
  2001. $column_names[] = get_lang('FinalScore');
  2002. break;
  2003. default:
  2004. $title = '';
  2005. if (!empty($exercises[$cnt - 4]['title'])) {
  2006. $title = ucwords(strtolower(trim($exercises[$cnt - 4]['title'])));
  2007. }
  2008. $columns[] = 'exer'.$i;
  2009. $column_names[] = $title;
  2010. $i++;
  2011. break;
  2012. }
  2013. }
  2014. $quizIds = [];
  2015. if (!empty($exercises)) {
  2016. foreach ($exercises as $exercise) {
  2017. $quizIds[] = $exercise['id'];
  2018. }
  2019. }
  2020. $course = api_get_course_info_by_id($_GET['course_id']);
  2021. $listUserSess = CourseManager::get_student_list_from_course_code(
  2022. $course['code'],
  2023. true,
  2024. $_GET['session_id']
  2025. );
  2026. $usersId = array_keys($listUserSess);
  2027. $users = UserManager::get_user_list_by_ids(
  2028. $usersId,
  2029. null,
  2030. "lastname, firstname",
  2031. "$start , $limit"
  2032. );
  2033. $exeResults = $objExercise->getExerciseAndResult(
  2034. $_GET['course_id'],
  2035. $_GET['session_id'],
  2036. $quizIds
  2037. );
  2038. $arrGrade = [];
  2039. foreach ($exeResults as $exeResult) {
  2040. $arrGrade[$exeResult['exe_user_id']][$exeResult['exe_exo_id']] = $exeResult['exe_result'];
  2041. }
  2042. $result = [];
  2043. $i = 0;
  2044. foreach ($users as $user) {
  2045. $sessionInfo = SessionManager::fetch($listUserSess[$user['user_id']]['id_session']);
  2046. $result[$i]['session'] = $sessionInfo['name'];
  2047. $result[$i]['username'] = $user['username'];
  2048. $result[$i]['name'] = $user['lastname']." ".$user['firstname'];
  2049. $j = 1;
  2050. $finalScore = 0;
  2051. foreach ($quizIds as $quizID) {
  2052. $grade = '';
  2053. if (!empty($arrGrade[$user['user_id']][$quizID]) || $arrGrade[$user['user_id']][$quizID] == 0) {
  2054. $finalScore += $grade = $arrGrade[$user['user_id']][$quizID];
  2055. }
  2056. $result[$i]['exer'.$j] = $grade;
  2057. $j++;
  2058. }
  2059. if ($finalScore > 20) {
  2060. $finalScore = 20;
  2061. }
  2062. $result[$i]['finalScore'] = number_format($finalScore, 2);
  2063. $i++;
  2064. }
  2065. break;
  2066. case 'get_extra_field_options':
  2067. $obj = new ExtraFieldOption($type);
  2068. $columns = ['display_text', 'option_value', 'option_order'];
  2069. $result = $obj->get_all([
  2070. 'where' => ["field_id = ? " => $field_id],
  2071. 'order' => "$sidx $sord",
  2072. 'LIMIT' => "$start , $limit",
  2073. ]);
  2074. break;
  2075. case 'get_usergroups_teacher':
  2076. $columns = ['name', 'users', 'status', 'group_type', 'actions'];
  2077. $options = ['order' => "name $sord", 'LIMIT' => "$start , $limit"];
  2078. $options['course_id'] = $course_id;
  2079. switch ($type) {
  2080. case 'not_registered':
  2081. $options['where'] = [' (course_id IS NULL OR course_id != ?) ' => $course_id];
  2082. $result = $obj->getUserGroupNotInCourse($options, $groupFilter);
  2083. break;
  2084. case 'registered':
  2085. $options['where'] = [' usergroup.course_id = ? ' => $course_id];
  2086. $result = $obj->getUserGroupInCourse($options, $groupFilter);
  2087. break;
  2088. }
  2089. $new_result = [];
  2090. if (!empty($result)) {
  2091. $urlUserGroup = api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?'.api_get_cidreq();
  2092. foreach ($result as $group) {
  2093. $count = count($obj->get_users_by_usergroup($group['id']));
  2094. $group['users'] = $count;
  2095. if ($obj->allowTeachers()) {
  2096. $group['users'] = Display::url(
  2097. $count,
  2098. $urlUserGroup.'&id='.$group['id']
  2099. );
  2100. }
  2101. if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
  2102. $url = 'class.php?action=remove_class_from_course&id='.$group['id'].'&'.api_get_cidreq();
  2103. $icon = Display::return_icon('delete.png', get_lang('Remove'));
  2104. } else {
  2105. $url = 'class.php?action=add_class_to_course&id='.$group['id'].'&'.api_get_cidreq().'&type=not_registered';
  2106. $icon = Display::return_icon('add.png', get_lang('Add'));
  2107. }
  2108. switch ($group['group_type']) {
  2109. case 0:
  2110. $group['group_type'] = Display::label(get_lang('Class'), 'primary');
  2111. break;
  2112. case 1:
  2113. $group['group_type'] = Display::label(get_lang('Social'), 'success');
  2114. break;
  2115. }
  2116. $role = $obj->getUserRoleToString(api_get_user_id(), $group['id']);
  2117. $group['status'] = $role;
  2118. $group['actions'] = '';
  2119. if ($obj->allowTeachers()) {
  2120. $group['actions'] .= Display::url(
  2121. Display::return_icon('statistics.png'),
  2122. $urlUserGroup.'&id='.$group['id']
  2123. ).'&nbsp;';
  2124. }
  2125. $group['actions'] .= Display::url($icon, $url);
  2126. $new_result[] = $group;
  2127. }
  2128. $result = $new_result;
  2129. }
  2130. if (!in_array($sidx, $columns)) {
  2131. $sidx = 'name';
  2132. }
  2133. // Multidimensional sort
  2134. $result = msort($result, $sidx, $sord);
  2135. break;
  2136. default:
  2137. exit;
  2138. }
  2139. $allowed_actions = [
  2140. 'get_careers',
  2141. 'get_promotions',
  2142. 'get_mail_template',
  2143. 'get_usergroups',
  2144. 'get_usergroups_teacher',
  2145. 'get_gradebooks',
  2146. 'get_sessions',
  2147. 'get_session_access_overview',
  2148. 'get_sessions_tracking',
  2149. 'get_session_lp_progress',
  2150. 'get_survey_overview',
  2151. 'get_session_progress',
  2152. 'get_exercise_progress',
  2153. 'get_exercise_results',
  2154. 'get_exercise_results_report',
  2155. 'get_work_student_list_overview',
  2156. 'get_hotpotatoes_exercise_results',
  2157. 'get_work_teacher',
  2158. 'get_work_student',
  2159. 'get_work_user_list',
  2160. 'get_work_user_list_others',
  2161. 'get_work_user_list_all',
  2162. 'get_timelines',
  2163. 'get_grade_models',
  2164. 'get_event_email_template',
  2165. 'get_user_skill_ranking',
  2166. 'get_extra_fields',
  2167. 'get_extra_field_options',
  2168. //'get_course_exercise_medias',
  2169. 'get_user_course_report',
  2170. 'get_user_course_report_resumed',
  2171. 'get_exercise_grade',
  2172. 'get_group_reporting',
  2173. 'get_course_announcements',
  2174. 'get_programmed_announcements',
  2175. 'course_log_events',
  2176. 'get_learning_path_calendars',
  2177. 'get_usergroups_users',
  2178. 'get_calendar_users',
  2179. 'get_exercise_categories',
  2180. ];
  2181. // 5. Creating an obj to return a json
  2182. if (in_array($action, $allowed_actions)) {
  2183. $response = new stdClass();
  2184. $response->page = $page;
  2185. $response->total = $total_pages;
  2186. $response->records = $count;
  2187. if ($operation && $operation == 'excel') {
  2188. $j = 1;
  2189. $array = [];
  2190. if (empty($column_names)) {
  2191. $column_names = $columns;
  2192. }
  2193. // Headers
  2194. foreach ($column_names as $col) {
  2195. // Overwrite titles
  2196. if (isset($overwriteColumnHeaderExport[$col])) {
  2197. $col = $overwriteColumnHeaderExport[$col];
  2198. }
  2199. $array[0][] = $col;
  2200. }
  2201. foreach ($result as $row) {
  2202. foreach ($columns as $col) {
  2203. $array[$j][] = strip_tags($row[$col]);
  2204. }
  2205. $j++;
  2206. }
  2207. $fileName = !empty($action) ? $action : 'company_report';
  2208. if (!empty($exportFilename)) {
  2209. $fileName = $exportFilename;
  2210. }
  2211. switch ($exportFormat) {
  2212. case 'xls':
  2213. Export::arrayToXls($array, $fileName);
  2214. break;
  2215. case 'xls_html':
  2216. //TODO add date if exists
  2217. $browser = new Browser();
  2218. if ($browser->getPlatform() == Browser::PLATFORM_WINDOWS) {
  2219. Export::export_table_xls_html($array, $fileName, 'ISO-8859-15');
  2220. } else {
  2221. Export::export_table_xls_html($array, $fileName);
  2222. }
  2223. break;
  2224. case 'csv':
  2225. default:
  2226. Export::arrayToCsv($array, $fileName);
  2227. break;
  2228. }
  2229. exit;
  2230. }
  2231. $i = 0;
  2232. if (!empty($result)) {
  2233. foreach ($result as $row) {
  2234. // if results tab give not id, set id to $i otherwise id="null"
  2235. // for all <tr> of the jqgrid - ref #4235
  2236. if (!isset($row['id']) || isset($row['id']) && $row['id'] == '') {
  2237. $response->rows[$i]['id'] = $i;
  2238. } else {
  2239. $response->rows[$i]['id'] = $row['id'];
  2240. }
  2241. $array = [];
  2242. foreach ($columns as $col) {
  2243. if (in_array($col, ['correction', 'actions'])) {
  2244. $array[] = isset($row[$col]) ? $row[$col] : '';
  2245. } else {
  2246. $array[] = isset($row[$col]) ? Security::remove_XSS($row[$col]) : '';
  2247. }
  2248. }
  2249. $response->rows[$i]['cell'] = $array;
  2250. $i++;
  2251. }
  2252. }
  2253. header('Content-Type: application/json;charset=utf-8');
  2254. echo json_encode($response);
  2255. }
  2256. exit;