course_home.ajax.php 21 KB

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