course_home.ajax.php 20 KB

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