course_home.ajax.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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. //echo Display::tag('h2', $course_info['name']);
  73. //echo '<br />';
  74. $sql = "SELECT * FROM $tbl_course_description
  75. WHERE c_id = ".$course_info['real_id']." AND session_id = 0
  76. ORDER BY id";
  77. $result = Database::query($sql);
  78. if (Database::num_rows($result) > 0 ) {
  79. while ($description = Database::fetch_object($result)) {
  80. $descriptions[$description->id] = $description;
  81. }
  82. // Function that displays the details of the course description in html.
  83. echo CourseManager::get_details_course_description_html(
  84. $descriptions,
  85. api_get_system_encoding(),
  86. false
  87. );
  88. } else {
  89. echo get_lang('NoDescription');
  90. }
  91. break;
  92. case 'session_courses_lp_default':
  93. /**
  94. * @todo this functions need to belong to a class or a special
  95. * wrapper to process the AJAX petitions from the jqgrid
  96. */
  97. require_once '../global.inc.php';
  98. $now = time();
  99. $page = intval($_REQUEST['page']); //page
  100. $limit = intval($_REQUEST['rows']); // quantity of rows
  101. //index to filter
  102. $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id';
  103. $sord = $_REQUEST['sord']; //asc or desc
  104. if (!in_array($sord, array('asc','desc'))) {
  105. $sord = 'desc';
  106. }
  107. $session_id = intval($_REQUEST['session_id']);
  108. $course_id = intval($_REQUEST['course_id']);
  109. //Filter users that does not belong to the session
  110. if (!api_is_platform_admin()) {
  111. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  112. $my_session_list = array();
  113. foreach($new_session_list as $item) {
  114. if (!empty($item['id_session']))
  115. $my_session_list[] = $item['id_session'];
  116. }
  117. if (!in_array($session_id, $my_session_list)) {
  118. break;
  119. }
  120. }
  121. $start = $limit*$page - $limit;
  122. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  123. $count = 0;
  124. $temp = array();
  125. foreach ($course_list as $item) {
  126. $list = new LearnpathList(api_get_user_id(), $item['code'], $session_id);
  127. $flat_list = $list->get_flat_list();
  128. $lps[$item['code']] = $flat_list;
  129. $course_url = api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id;
  130. $item['title'] = Display::url($item['title'], $course_url, array('target' => SESSION_LINK_TARGET));
  131. foreach ($flat_list as $lp_id => $lp_item) {
  132. $temp[$count]['id']= $lp_id;
  133. $lp = new learnpath($item['code'], $lp_id, api_get_user_id());
  134. if ($lp->progress_db == 100) {
  135. continue;
  136. }
  137. $lp_url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?cidReq='.$item['code'].'&id_session='.$session_id.'&lp_id='.$lp_id.'&action=view';
  138. $last_date = Tracking::get_last_connection_date_on_the_course(
  139. api_get_user_id(),
  140. $item,
  141. $session_id,
  142. false
  143. );
  144. if (empty($lp_item['modified_on'])) {
  145. $lp_date = api_get_local_time($lp_item['created_on']);
  146. $image = 'new.gif';
  147. $label = get_lang('LearnpathAdded');
  148. } else {
  149. $lp_date = api_get_local_time($lp_item['modified_on']);
  150. $image = 'moderator_star.png';
  151. $label = get_lang('LearnpathUpdated');
  152. }
  153. $icons = '';
  154. if (strtotime($last_date) < strtotime($lp_date)) {
  155. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  156. }
  157. if (!empty($lp_item['publicated_on'])) {
  158. $date = substr($lp_item['publicated_on'], 0, 10);
  159. } else {
  160. $date = '-';
  161. }
  162. // Checking LP publicated and expired_on dates
  163. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  164. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  165. continue;
  166. }
  167. }
  168. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  169. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  170. continue;
  171. }
  172. }
  173. $temp[$count]['cell'] = array(
  174. $date,
  175. $item['title'],
  176. Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET))
  177. );
  178. $temp[$count]['course'] = strip_tags($item['title']);
  179. $temp[$count]['lp'] = $lp_item['lp_name'];
  180. $temp[$count]['date'] = $lp_item['publicated_on'];
  181. $count++;
  182. }
  183. }
  184. $temp = msort($temp, $sidx, $sord);
  185. $i =0;
  186. $response = new stdClass();
  187. foreach($temp as $key=>$row) {
  188. $row = $row['cell'];
  189. if (!empty($row)) {
  190. if ($key >= $start && $key < ($start + $limit)) {
  191. $response->rows[$i]['id']= $key;
  192. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2]);
  193. $i++;
  194. }
  195. }
  196. }
  197. if($count > 0 && $limit > 0) {
  198. $total_pages = ceil($count/$limit);
  199. } else {
  200. $total_pages = 0;
  201. }
  202. $response->total = $total_pages;
  203. if ($page > $total_pages) {
  204. $response->page= $total_pages;
  205. } else {
  206. $response->page = $page;
  207. }
  208. $response->records = $count;
  209. echo json_encode($response);
  210. break;
  211. case 'session_courses_lp_by_week':
  212. require_once '../global.inc.php';
  213. $now = time();
  214. $page = intval($_REQUEST['page']); //page
  215. $limit = intval($_REQUEST['rows']); // quantity of rows
  216. $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'course';
  217. $sidx = str_replace(array('week desc,', ' '), '', $sidx);
  218. $sord = $_REQUEST['sord']; //asc or desc
  219. if (!in_array($sord, array('asc','desc'))) {
  220. $sord = 'desc';
  221. }
  222. $session_id = intval($_REQUEST['session_id']);
  223. $course_id = intval($_REQUEST['course_id']);
  224. //Filter users that does not belong to the session
  225. if (!api_is_platform_admin()) {
  226. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  227. $my_session_list = array();
  228. foreach($new_session_list as $item) {
  229. if (!empty($item['id_session']))
  230. $my_session_list[] = $item['id_session'];
  231. }
  232. if (!in_array($session_id, $my_session_list)) {
  233. break;
  234. }
  235. }
  236. $start = $limit*$page - $limit;
  237. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  238. $count = 0;
  239. $temp = array();
  240. foreach ($course_list as $item) {
  241. if (isset($course_id) && !empty($course_id)) {
  242. if ($course_id != $item['id']) {
  243. continue;
  244. }
  245. }
  246. $list = new LearnpathList(api_get_user_id(),$item['code'], $session_id, 'publicated_on DESC');
  247. $flat_list = $list->get_flat_list();
  248. $lps[$item['code']] = $flat_list;
  249. $item['title'] = Display::url($item['title'],api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id,array('target'=>SESSION_LINK_TARGET));
  250. foreach ($flat_list as $lp_id => $lp_item) {
  251. $temp[$count]['id']= $lp_id;
  252. $lp_url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?cidReq='.$item['code'].'&id_session='.$session_id.'&lp_id='.$lp_id.'&action=view';
  253. $last_date = Tracking::get_last_connection_date_on_the_course(
  254. api_get_user_id(),
  255. $item,
  256. $session_id,
  257. false
  258. );
  259. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  260. $lp_date = api_get_local_time($lp_item['created_on']);
  261. $image = 'new.gif';
  262. $label = get_lang('LearnpathAdded');
  263. } else {
  264. $lp_date = api_get_local_time($lp_item['modified_on']);
  265. $image = 'moderator_star.png';
  266. $label = get_lang('LearnpathUpdated');
  267. }
  268. if (strtotime($last_date) < strtotime($lp_date)) {
  269. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  270. }
  271. if (!empty($lp_item['publicated_on'])) {
  272. $date = substr($lp_item['publicated_on'], 0, 10);
  273. } else {
  274. $date = '-';
  275. }
  276. //Checking LP publicated and expired_on dates
  277. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  278. $week_data = date('Y', api_strtotime($lp_item['publicated_on'], 'UTC')).' - '.get_week_from_day($lp_item['publicated_on']);
  279. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  280. continue;
  281. }
  282. } else {
  283. $week_data = '';
  284. }
  285. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  286. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  287. continue;
  288. }
  289. }
  290. $temp[$count]['cell'] = array($week_data, $date, $item['title'], Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET)));
  291. $temp[$count]['course'] = strip_tags($item['title']);
  292. $temp[$count]['lp'] = $lp_item['lp_name'];
  293. $count++;
  294. }
  295. }
  296. if (!empty($sidx)) {
  297. $temp = msort($temp, $sidx, $sord);
  298. }
  299. $response = new stdClass();
  300. $i =0;
  301. foreach($temp as $key=>$row) {
  302. $row = $row['cell'];
  303. if (!empty($row)) {
  304. if ($key >= $start && $key < ($start + $limit)) {
  305. $response->rows[$i]['id']= $key;
  306. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2],$row[3]);
  307. $i++;
  308. }
  309. }
  310. }
  311. if ($count > 0 && $limit > 0) {
  312. $total_pages = ceil($count/$limit);
  313. } else {
  314. $total_pages = 0;
  315. }
  316. $response->total = $total_pages;
  317. if ($page > $total_pages) {
  318. $response->page = $total_pages;
  319. } else {
  320. $response->page = $page;
  321. }
  322. $response->records = $count;
  323. echo json_encode($response);
  324. break;
  325. case 'session_courses_lp_by_course':
  326. require_once '../global.inc.php';
  327. $now = time();
  328. $page = intval($_REQUEST['page']); //page
  329. $limit = intval($_REQUEST['rows']); // quantity of rows
  330. $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id';
  331. $sidx = str_replace(array('course asc,', ' '), '', $sidx);
  332. $sord = $_REQUEST['sord']; //asc or desc
  333. if (!in_array($sord, array('asc','desc'))) {
  334. $sord = 'desc';
  335. }
  336. $session_id = intval($_REQUEST['session_id']);
  337. $course_id = intval($_REQUEST['course_id']);
  338. //Filter users that does not belong to the session
  339. if (!api_is_platform_admin()) {
  340. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  341. $my_session_list = array();
  342. foreach($new_session_list as $item) {
  343. if (!empty($item['id_session']))
  344. $my_session_list[] = $item['id_session'];
  345. }
  346. if (!in_array($session_id, $my_session_list)) {
  347. break;
  348. }
  349. }
  350. $start = $limit*$page - $limit;
  351. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  352. $count = 0;
  353. foreach ($course_list as $item) {
  354. if (isset($course_id) && !empty($course_id)) {
  355. if ($course_id != $item['id']) {
  356. continue;
  357. }
  358. }
  359. $list = new LearnpathList(api_get_user_id(),$item['code'],$session_id);
  360. $flat_list = $list->get_flat_list();
  361. $lps[$item['code']] = $flat_list;
  362. $item['title'] = Display::url(
  363. $item['title'],
  364. api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id, array('target'=>SESSION_LINK_TARGET)
  365. );
  366. foreach($flat_list as $lp_id => $lp_item) {
  367. $temp[$count]['id']= $lp_id;
  368. $lp_url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?cidReq='.$item['code'].'&id_session='.$session_id.'&lp_id='.$lp_id.'&action=view';
  369. $last_date = Tracking::get_last_connection_date_on_the_course(
  370. api_get_user_id(),
  371. $item,
  372. $session_id,
  373. false
  374. );
  375. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  376. $lp_date = api_get_local_time($lp_item['created_on']);
  377. $image = 'new.gif';
  378. $label = get_lang('LearnpathAdded');
  379. } else {
  380. $lp_date = api_get_local_time($lp_item['modified_on']);
  381. $image = 'moderator_star.png';
  382. $label = get_lang('LearnpathUpdated');
  383. }
  384. $icons = '';
  385. if (strtotime($last_date) < strtotime($lp_date)) {
  386. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  387. }
  388. if (!empty($lp_item['publicated_on'])) {
  389. $date = substr($lp_item['publicated_on'], 0, 10);
  390. } else {
  391. $date = '-';
  392. }
  393. //Checking LP publicated and expired_on dates
  394. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  395. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  396. continue;
  397. }
  398. }
  399. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  400. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  401. continue;
  402. }
  403. }
  404. $temp[$count]['cell'] = array(
  405. $date,
  406. $item['title'],
  407. Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET))
  408. );
  409. $temp[$count]['course'] = strip_tags($item['title']);
  410. $temp[$count]['lp'] = $lp_item['lp_name'];
  411. $temp[$count]['date'] = $lp_item['publicated_on'];
  412. $count++;
  413. }
  414. }
  415. $temp = msort($temp, $sidx, $sord);
  416. $response = new stdClass();
  417. $i =0;
  418. foreach ($temp as $key=>$row) {
  419. $row = $row['cell'];
  420. if (!empty($row)) {
  421. if ($key >= $start && $key < ($start + $limit)) {
  422. $response->rows[$i]['id']= $key;
  423. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2]);
  424. $i++;
  425. }
  426. }
  427. }
  428. if ($count > 0 && $limit > 0) {
  429. $total_pages = ceil($count / $limit);
  430. } else {
  431. $total_pages = 0;
  432. }
  433. $response->total = $total_pages;
  434. if ($page > $total_pages) {
  435. $response->page = $total_pages;
  436. } else {
  437. $response->page = $page;
  438. }
  439. $response->records = $count;
  440. echo json_encode($response);
  441. break;
  442. default:
  443. echo '';
  444. }
  445. exit;