course_home.ajax.php 21 KB

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