course_home.ajax.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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 ($course_info['visibility'] != COURSE_VISIBILITY_OPEN_WORLD) {
  66. if (api_is_anonymous()) {
  67. exit;
  68. }
  69. }
  70. //echo Display::tag('h2', $course_info['name']);
  71. //echo '<br />';
  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($item['title'],api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id,array('target'=>SESSION_LINK_TARGET));
  248. foreach ($flat_list as $lp_id => $lp_item) {
  249. $temp[$count]['id']= $lp_id;
  250. $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';
  251. $last_date = Tracking::get_last_connection_date_on_the_course(
  252. api_get_user_id(),
  253. $item,
  254. $session_id,
  255. false
  256. );
  257. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  258. $lp_date = api_get_local_time($lp_item['created_on']);
  259. $image = 'new.gif';
  260. $label = get_lang('LearnpathAdded');
  261. } else {
  262. $lp_date = api_get_local_time($lp_item['modified_on']);
  263. $image = 'moderator_star.png';
  264. $label = get_lang('LearnpathUpdated');
  265. }
  266. if (strtotime($last_date) < strtotime($lp_date)) {
  267. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  268. }
  269. if (!empty($lp_item['publicated_on'])) {
  270. $date = substr($lp_item['publicated_on'], 0, 10);
  271. } else {
  272. $date = '-';
  273. }
  274. //Checking LP publicated and expired_on dates
  275. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  276. $week_data = date('Y', api_strtotime($lp_item['publicated_on'], 'UTC')).' - '.get_week_from_day($lp_item['publicated_on']);
  277. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  278. continue;
  279. }
  280. } else {
  281. $week_data = '';
  282. }
  283. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  284. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  285. continue;
  286. }
  287. }
  288. $temp[$count]['cell'] = array($week_data, $date, $item['title'], Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET)));
  289. $temp[$count]['course'] = strip_tags($item['title']);
  290. $temp[$count]['lp'] = $lp_item['lp_name'];
  291. $count++;
  292. }
  293. }
  294. if (!empty($sidx)) {
  295. $temp = msort($temp, $sidx, $sord);
  296. }
  297. $response = new stdClass();
  298. $i =0;
  299. foreach($temp as $key=>$row) {
  300. $row = $row['cell'];
  301. if (!empty($row)) {
  302. if ($key >= $start && $key < ($start + $limit)) {
  303. $response->rows[$i]['id']= $key;
  304. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2],$row[3]);
  305. $i++;
  306. }
  307. }
  308. }
  309. if ($count > 0 && $limit > 0) {
  310. $total_pages = ceil($count/$limit);
  311. } else {
  312. $total_pages = 0;
  313. }
  314. $response->total = $total_pages;
  315. if ($page > $total_pages) {
  316. $response->page = $total_pages;
  317. } else {
  318. $response->page = $page;
  319. }
  320. $response->records = $count;
  321. echo json_encode($response);
  322. break;
  323. case 'session_courses_lp_by_course':
  324. require_once '../global.inc.php';
  325. $now = time();
  326. $page = intval($_REQUEST['page']); //page
  327. $limit = intval($_REQUEST['rows']); // quantity of rows
  328. $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id';
  329. $sidx = str_replace(array('course asc,', ' '), '', $sidx);
  330. $sord = $_REQUEST['sord']; //asc or desc
  331. if (!in_array($sord, array('asc','desc'))) {
  332. $sord = 'desc';
  333. }
  334. $session_id = intval($_REQUEST['session_id']);
  335. $course_id = intval($_REQUEST['course_id']);
  336. //Filter users that does not belong to the session
  337. if (!api_is_platform_admin()) {
  338. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  339. $my_session_list = array();
  340. foreach($new_session_list as $item) {
  341. if (!empty($item['id_session']))
  342. $my_session_list[] = $item['id_session'];
  343. }
  344. if (!in_array($session_id, $my_session_list)) {
  345. break;
  346. }
  347. }
  348. $start = $limit*$page - $limit;
  349. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  350. $count = 0;
  351. foreach ($course_list as $item) {
  352. if (isset($course_id) && !empty($course_id)) {
  353. if ($course_id != $item['id']) {
  354. continue;
  355. }
  356. }
  357. $list = new LearnpathList(api_get_user_id(),$item['code'],$session_id);
  358. $flat_list = $list->get_flat_list();
  359. $lps[$item['code']] = $flat_list;
  360. $item['title'] = Display::url(
  361. $item['title'],
  362. api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id, array('target'=>SESSION_LINK_TARGET)
  363. );
  364. foreach($flat_list as $lp_id => $lp_item) {
  365. $temp[$count]['id']= $lp_id;
  366. $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';
  367. $last_date = Tracking::get_last_connection_date_on_the_course(
  368. api_get_user_id(),
  369. $item,
  370. $session_id,
  371. false
  372. );
  373. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  374. $lp_date = api_get_local_time($lp_item['created_on']);
  375. $image = 'new.gif';
  376. $label = get_lang('LearnpathAdded');
  377. } else {
  378. $lp_date = api_get_local_time($lp_item['modified_on']);
  379. $image = 'moderator_star.png';
  380. $label = get_lang('LearnpathUpdated');
  381. }
  382. $icons = '';
  383. if (strtotime($last_date) < strtotime($lp_date)) {
  384. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  385. }
  386. if (!empty($lp_item['publicated_on'])) {
  387. $date = substr($lp_item['publicated_on'], 0, 10);
  388. } else {
  389. $date = '-';
  390. }
  391. //Checking LP publicated and expired_on dates
  392. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  393. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  394. continue;
  395. }
  396. }
  397. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  398. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  399. continue;
  400. }
  401. }
  402. $temp[$count]['cell'] = array(
  403. $date,
  404. $item['title'],
  405. Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET))
  406. );
  407. $temp[$count]['course'] = strip_tags($item['title']);
  408. $temp[$count]['lp'] = $lp_item['lp_name'];
  409. $temp[$count]['date'] = $lp_item['publicated_on'];
  410. $count++;
  411. }
  412. }
  413. $temp = msort($temp, $sidx, $sord);
  414. $response = new stdClass();
  415. $i =0;
  416. foreach ($temp as $key=>$row) {
  417. $row = $row['cell'];
  418. if (!empty($row)) {
  419. if ($key >= $start && $key < ($start + $limit)) {
  420. $response->rows[$i]['id']= $key;
  421. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2]);
  422. $i++;
  423. }
  424. }
  425. }
  426. if ($count > 0 && $limit > 0) {
  427. $total_pages = ceil($count / $limit);
  428. } else {
  429. $total_pages = 0;
  430. }
  431. $response->total = $total_pages;
  432. if ($page > $total_pages) {
  433. $response->page = $total_pages;
  434. } else {
  435. $response->page = $page;
  436. }
  437. $response->records = $count;
  438. echo json_encode($response);
  439. break;
  440. default:
  441. echo '';
  442. }
  443. exit;