course_home.ajax.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // @todo refactor this script, create a class that manage the jqgrid requests
  4. /**
  5. * Responses to AJAX calls
  6. */
  7. $action = $_GET['a'];
  8. switch ($action) {
  9. case 'set_visibility':
  10. require_once '../global.inc.php';
  11. $course_id = api_get_course_int_id();
  12. if (api_is_allowed_to_edit(null, true)) {
  13. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  14. $tool_info = api_get_tool_information($_GET['id']);
  15. $tool_visibility = $tool_info['visibility'];
  16. $tool_image = $tool_info['image'];
  17. if (api_get_setting('homepage_view') != 'activity_big') {
  18. $tool_image = Display::return_icon($tool_image, null, null, null, null, true);
  19. $na_image = str_replace('.gif', '_na.gif', $tool_image);
  20. } else {
  21. // Display::return_icon() also checks in the app/Resources/public/css/themes/{theme}/icons folder
  22. $tool_image = (substr($tool_image, 0, strpos($tool_image, '.'))).'.png';
  23. $tool_image = Display::return_icon(
  24. $tool_image,
  25. get_lang(ucfirst($tool_info['name'])),
  26. null,
  27. ICON_SIZE_BIG,
  28. null,
  29. true
  30. );
  31. $na_image = str_replace('.png', '_na.png', $tool_image);
  32. }
  33. if (isset($tool_info['custom_icon']) && !empty($tool_info['custom_icon'])) {
  34. $tool_image = CourseHome::getCustomWebIconPath().$tool_info['custom_icon'];
  35. $na_image = CourseHome::getCustomWebIconPath().CourseHome::getDisableIcon($tool_info['custom_icon']);
  36. }
  37. $requested_image = ($tool_visibility == 0 ) ? $tool_image : $na_image;
  38. $requested_class = ($tool_visibility == 0 ) ? 'visible' : 'invisible';
  39. $requested_message = ($tool_visibility == 0 ) ? 'is_active' : 'is_inactive';
  40. $requested_view = ($tool_visibility == 0 ) ? 'visible.png' : 'invisible.png';
  41. $requested_visible = ($tool_visibility == 0 ) ? 1 : 0;
  42. $requested_view = ($tool_visibility == 0 ) ? 'visible.png' : 'invisible.png';
  43. $requested_visible = ($tool_visibility == 0 ) ? 1 : 0;
  44. // HIDE AND REACTIVATE TOOL
  45. if ($_GET["id"] == strval(intval($_GET["id"]))) {
  46. $sql = "UPDATE $tool_table SET
  47. visibility = $requested_visible
  48. WHERE c_id = $course_id AND id='" . intval($_GET['id']) . "'";
  49. Database::query($sql);
  50. }
  51. $response_data = array(
  52. 'image' => $requested_image,
  53. 'tclass' => $requested_class,
  54. 'message' => $requested_message,
  55. 'view' => $requested_view
  56. );
  57. echo json_encode($response_data);
  58. }
  59. break;
  60. case 'show_course_information' :
  61. require_once '../global.inc.php';
  62. // Get the name of the database course.
  63. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
  64. $course_info = api_get_course_info($_GET['code']);
  65. if (
  66. api_get_setting('course_catalog_hide_private') === 'true' &&
  67. $course_info['visibility'] == COURSE_VISIBILITY_REGISTERED
  68. ) {
  69. echo get_lang('PrivateAccess');
  70. break;
  71. }
  72. $sql = "SELECT * FROM $tbl_course_description
  73. WHERE c_id = ".$course_info['real_id']." AND session_id = 0
  74. ORDER BY id";
  75. $result = Database::query($sql);
  76. if (Database::num_rows($result) > 0 ) {
  77. while ($description = Database::fetch_object($result)) {
  78. $descriptions[$description->id] = $description;
  79. }
  80. // Function that displays the details of the course description in html.
  81. echo CourseManager::get_details_course_description_html(
  82. $descriptions,
  83. api_get_system_encoding(),
  84. false
  85. );
  86. } else {
  87. echo get_lang('NoDescription');
  88. }
  89. break;
  90. case 'session_courses_lp_default':
  91. /**
  92. * @todo this functions need to belong to a class or a special
  93. * wrapper to process the AJAX petitions from the jqgrid
  94. */
  95. require_once '../global.inc.php';
  96. $now = time();
  97. $page = intval($_REQUEST['page']); //page
  98. $limit = intval($_REQUEST['rows']); // quantity of rows
  99. //index to filter
  100. $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id';
  101. $sord = $_REQUEST['sord']; //asc or desc
  102. if (!in_array($sord, array('asc','desc'))) {
  103. $sord = 'desc';
  104. }
  105. $session_id = intval($_REQUEST['session_id']);
  106. $course_id = intval($_REQUEST['course_id']);
  107. //Filter users that does not belong to the session
  108. if (!api_is_platform_admin()) {
  109. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  110. $my_session_list = array();
  111. foreach($new_session_list as $item) {
  112. if (!empty($item['id_session']))
  113. $my_session_list[] = $item['id_session'];
  114. }
  115. if (!in_array($session_id, $my_session_list)) {
  116. break;
  117. }
  118. }
  119. $start = $limit*$page - $limit;
  120. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  121. $count = 0;
  122. $temp = array();
  123. foreach ($course_list as $item) {
  124. $list = new LearnpathList(api_get_user_id(), $item['code'], $session_id);
  125. $flat_list = $list->get_flat_list();
  126. $lps[$item['code']] = $flat_list;
  127. $course_url = api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id;
  128. $item['title'] = Display::url($item['title'], $course_url, array('target' => SESSION_LINK_TARGET));
  129. foreach ($flat_list as $lp_id => $lp_item) {
  130. $temp[$count]['id']= $lp_id;
  131. $lp = new learnpath($item['code'], $lp_id, api_get_user_id());
  132. if ($lp->progress_db == 100) {
  133. continue;
  134. }
  135. $lp_url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?cidReq='.$item['code'].'&id_session='.$session_id.'&lp_id='.$lp_id.'&action=view';
  136. $last_date = Tracking::get_last_connection_date_on_the_course(
  137. api_get_user_id(),
  138. $item,
  139. $session_id,
  140. false
  141. );
  142. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  143. $lp_date = api_get_local_time($lp_item['created_on']);
  144. $image = 'new.gif';
  145. $label = get_lang('LearnpathAdded');
  146. } else {
  147. $lp_date = api_get_local_time($lp_item['modified_on']);
  148. $image = 'moderator_star.png';
  149. $label = get_lang('LearnpathUpdated');
  150. }
  151. $icons = '';
  152. if (strtotime($last_date) < strtotime($lp_date)) {
  153. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  154. }
  155. if (!empty($lp_item['publicated_on'])) {
  156. $date = substr($lp_item['publicated_on'], 0, 10);
  157. } else {
  158. $date = '-';
  159. }
  160. // Checking LP publicated and expired_on dates
  161. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  162. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  163. continue;
  164. }
  165. }
  166. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  167. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  168. continue;
  169. }
  170. }
  171. $temp[$count]['cell'] = array(
  172. $date,
  173. $item['title'],
  174. Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET))
  175. );
  176. $temp[$count]['course'] = strip_tags($item['title']);
  177. $temp[$count]['lp'] = $lp_item['lp_name'];
  178. $temp[$count]['date'] = $lp_item['publicated_on'];
  179. $count++;
  180. }
  181. }
  182. $temp = msort($temp, $sidx, $sord);
  183. $i =0;
  184. $response = new stdClass();
  185. foreach($temp as $key=>$row) {
  186. $row = $row['cell'];
  187. if (!empty($row)) {
  188. if ($key >= $start && $key < ($start + $limit)) {
  189. $response->rows[$i]['id']= $key;
  190. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2]);
  191. $i++;
  192. }
  193. }
  194. }
  195. if($count > 0 && $limit > 0) {
  196. $total_pages = ceil($count/$limit);
  197. } else {
  198. $total_pages = 0;
  199. }
  200. $response->total = $total_pages;
  201. if ($page > $total_pages) {
  202. $response->page= $total_pages;
  203. } else {
  204. $response->page = $page;
  205. }
  206. $response->records = $count;
  207. echo json_encode($response);
  208. break;
  209. case 'session_courses_lp_by_week':
  210. require_once '../global.inc.php';
  211. $now = time();
  212. $page = intval($_REQUEST['page']); //page
  213. $limit = intval($_REQUEST['rows']); // quantity of rows
  214. $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'course';
  215. $sidx = str_replace(array('week desc,', ' '), '', $sidx);
  216. $sord = $_REQUEST['sord']; //asc or desc
  217. if (!in_array($sord, array('asc','desc'))) {
  218. $sord = 'desc';
  219. }
  220. $session_id = intval($_REQUEST['session_id']);
  221. $course_id = intval($_REQUEST['course_id']);
  222. //Filter users that does not belong to the session
  223. if (!api_is_platform_admin()) {
  224. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  225. $my_session_list = array();
  226. foreach($new_session_list as $item) {
  227. if (!empty($item['id_session']))
  228. $my_session_list[] = $item['id_session'];
  229. }
  230. if (!in_array($session_id, $my_session_list)) {
  231. break;
  232. }
  233. }
  234. $start = $limit*$page - $limit;
  235. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  236. $count = 0;
  237. $temp = array();
  238. foreach ($course_list as $item) {
  239. if (isset($course_id) && !empty($course_id)) {
  240. if ($course_id != $item['id']) {
  241. continue;
  242. }
  243. }
  244. $list = new LearnpathList(api_get_user_id(),$item['code'], $session_id, 'publicated_on DESC');
  245. $flat_list = $list->get_flat_list();
  246. $lps[$item['code']] = $flat_list;
  247. $item['title'] = Display::url(
  248. $item['title'],
  249. api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id,
  250. array('target' => SESSION_LINK_TARGET)
  251. );
  252. foreach ($flat_list as $lp_id => $lp_item) {
  253. $temp[$count]['id']= $lp_id;
  254. $lp_url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?cidReq='.$item['code'].'&id_session='.$session_id.'&lp_id='.$lp_id.'&action=view';
  255. $last_date = Tracking::get_last_connection_date_on_the_course(
  256. api_get_user_id(),
  257. $item,
  258. $session_id,
  259. false
  260. );
  261. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  262. $lp_date = api_get_local_time($lp_item['created_on']);
  263. $image = 'new.gif';
  264. $label = get_lang('LearnpathAdded');
  265. } else {
  266. $lp_date = api_get_local_time($lp_item['modified_on']);
  267. $image = 'moderator_star.png';
  268. $label = get_lang('LearnpathUpdated');
  269. }
  270. if (strtotime($last_date) < strtotime($lp_date)) {
  271. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  272. }
  273. if (!empty($lp_item['publicated_on'])) {
  274. $date = substr($lp_item['publicated_on'], 0, 10);
  275. } else {
  276. $date = '-';
  277. }
  278. // Checking LP publicated and expired_on dates
  279. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  280. $week_data = date('Y', api_strtotime($lp_item['publicated_on'], 'UTC')).' - '.get_week_from_day($lp_item['publicated_on']);
  281. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  282. continue;
  283. }
  284. } else {
  285. $week_data = '';
  286. }
  287. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  288. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  289. continue;
  290. }
  291. }
  292. $temp[$count]['cell'] = array(
  293. $week_data,
  294. $date,
  295. $item['title'],
  296. Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target' => SESSION_LINK_TARGET)),
  297. );
  298. $temp[$count]['course'] = strip_tags($item['title']);
  299. $temp[$count]['lp'] = $lp_item['lp_name'];
  300. $count++;
  301. }
  302. }
  303. if (!empty($sidx)) {
  304. $temp = msort($temp, $sidx, $sord);
  305. }
  306. $response = new stdClass();
  307. $i =0;
  308. foreach($temp as $key=>$row) {
  309. $row = $row['cell'];
  310. if (!empty($row)) {
  311. if ($key >= $start && $key < ($start + $limit)) {
  312. $response->rows[$i]['id']= $key;
  313. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2],$row[3]);
  314. $i++;
  315. }
  316. }
  317. }
  318. if ($count > 0 && $limit > 0) {
  319. $total_pages = ceil($count/$limit);
  320. } else {
  321. $total_pages = 0;
  322. }
  323. $response->total = $total_pages;
  324. if ($page > $total_pages) {
  325. $response->page = $total_pages;
  326. } else {
  327. $response->page = $page;
  328. }
  329. $response->records = $count;
  330. echo json_encode($response);
  331. break;
  332. case 'session_courses_lp_by_course':
  333. require_once '../global.inc.php';
  334. $now = time();
  335. $page = intval($_REQUEST['page']); //page
  336. $limit = intval($_REQUEST['rows']); // quantity of rows
  337. $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id';
  338. $sidx = str_replace(array('course asc,', ' '), '', $sidx);
  339. $sord = $_REQUEST['sord']; //asc or desc
  340. if (!in_array($sord, array('asc', 'desc'))) {
  341. $sord = 'desc';
  342. }
  343. $session_id = intval($_REQUEST['session_id']);
  344. $course_id = intval($_REQUEST['course_id']);
  345. //Filter users that does not belong to the session
  346. if (!api_is_platform_admin()) {
  347. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  348. $my_session_list = array();
  349. foreach($new_session_list as $item) {
  350. if (!empty($item['id_session']))
  351. $my_session_list[] = $item['id_session'];
  352. }
  353. if (!in_array($session_id, $my_session_list)) {
  354. break;
  355. }
  356. }
  357. $start = $limit*$page - $limit;
  358. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  359. $count = 0;
  360. foreach ($course_list as $item) {
  361. if (isset($course_id) && !empty($course_id)) {
  362. if ($course_id != $item['id']) {
  363. continue;
  364. }
  365. }
  366. $list = new LearnpathList(api_get_user_id(),$item['code'],$session_id);
  367. $flat_list = $list->get_flat_list();
  368. $lps[$item['code']] = $flat_list;
  369. $item['title'] = Display::url(
  370. $item['title'],
  371. api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id, array('target'=>SESSION_LINK_TARGET)
  372. );
  373. foreach($flat_list as $lp_id => $lp_item) {
  374. $temp[$count]['id']= $lp_id;
  375. $lp_url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?cidReq='.$item['code'].'&id_session='.$session_id.'&lp_id='.$lp_id.'&action=view';
  376. $last_date = Tracking::get_last_connection_date_on_the_course(
  377. api_get_user_id(),
  378. $item,
  379. $session_id,
  380. false
  381. );
  382. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  383. $lp_date = api_get_local_time($lp_item['created_on']);
  384. $image = 'new.gif';
  385. $label = get_lang('LearnpathAdded');
  386. } else {
  387. $lp_date = api_get_local_time($lp_item['modified_on']);
  388. $image = 'moderator_star.png';
  389. $label = get_lang('LearnpathUpdated');
  390. }
  391. $icons = '';
  392. if (strtotime($last_date) < strtotime($lp_date)) {
  393. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  394. }
  395. if (!empty($lp_item['publicated_on'])) {
  396. $date = substr($lp_item['publicated_on'], 0, 10);
  397. } else {
  398. $date = '-';
  399. }
  400. //Checking LP publicated and expired_on dates
  401. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  402. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  403. continue;
  404. }
  405. }
  406. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  407. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  408. continue;
  409. }
  410. }
  411. $temp[$count]['cell'] = array(
  412. $date,
  413. $item['title'],
  414. Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET))
  415. );
  416. $temp[$count]['course'] = strip_tags($item['title']);
  417. $temp[$count]['lp'] = $lp_item['lp_name'];
  418. $temp[$count]['date'] = $lp_item['publicated_on'];
  419. $count++;
  420. }
  421. }
  422. $temp = msort($temp, $sidx, $sord);
  423. $response = new stdClass();
  424. $i =0;
  425. foreach ($temp as $key=>$row) {
  426. $row = $row['cell'];
  427. if (!empty($row)) {
  428. if ($key >= $start && $key < ($start + $limit)) {
  429. $response->rows[$i]['id']= $key;
  430. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2]);
  431. $i++;
  432. }
  433. }
  434. }
  435. if ($count > 0 && $limit > 0) {
  436. $total_pages = ceil($count / $limit);
  437. } else {
  438. $total_pages = 0;
  439. }
  440. $response->total = $total_pages;
  441. if ($page > $total_pages) {
  442. $response->page = $total_pages;
  443. } else {
  444. $response->page = $page;
  445. }
  446. $response->records = $count;
  447. echo json_encode($response);
  448. break;
  449. default:
  450. echo '';
  451. }
  452. exit;