course_home.ajax.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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 = Display::return_icon(str_replace('.gif','_na.gif',$tool_image), null, null, null, null, true);
  20. $tool_image = Display::return_icon($tool_image, null, null, null, null, true);
  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. $page = intval($_REQUEST['page']); //page
  95. $limit = intval($_REQUEST['rows']); // quantity of rows
  96. $sidx = $_REQUEST['sidx']; //index to filter
  97. $sord = $_REQUEST['sord']; //asc or desc
  98. if (!in_array($sord, array('asc','desc'))) {
  99. $sord = 'desc';
  100. }
  101. $session_id = intval($_REQUEST['session_id']);
  102. $course_id = intval($_REQUEST['course_id']);
  103. //Filter users that does not belong to the session
  104. if (!api_is_platform_admin()) {
  105. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  106. $my_session_list = array();
  107. foreach($new_session_list as $item) {
  108. if (!empty($item['id_session']))
  109. $my_session_list[] = $item['id_session'];
  110. }
  111. if (!in_array($session_id, $my_session_list)) {
  112. break;
  113. }
  114. }
  115. if(!$sidx) $sidx = 1;
  116. $start = $limit*$page - $limit;
  117. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  118. $count = 0;
  119. foreach ($course_list as $item) {
  120. if (isset($course_id) && !empty($course_id)) {
  121. if ($course_id != $item['id']) {
  122. continue;
  123. }
  124. }
  125. $list = new LearnpathList(api_get_user_id(), $item['code'], $session_id);
  126. $flat_list = $list->get_flat_list();
  127. $lps[$item['code']] = $flat_list;
  128. $course_url = api_get_path(WEB_COURSE_PATH).$item['directory'].'/index.php?id_session='.$session_id;
  129. $item['title'] = Display::url($item['title'], $course_url, array('target'=>SESSION_LINK_TARGET));
  130. foreach($flat_list as $lp_id => $lp_item) {
  131. $temp[$count]['id']= $lp_id;
  132. $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';
  133. $last_date = Tracking::get_last_connection_date_on_the_course(api_get_user_id(), $item['id'], $session_id, false);
  134. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  135. $lp_date = api_get_local_time($lp_item['created_on']);
  136. $image = 'new.gif';
  137. $label = get_lang('LearnpathAdded');
  138. } else {
  139. $lp_date = api_get_local_time($lp_item['modified_on']);
  140. $image = 'moderator_star.png';
  141. $label = get_lang('LearnpathUpdated');
  142. }
  143. if (strtotime($last_date) < strtotime($lp_date)) {
  144. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  145. }
  146. if (!empty($lp_item['publicated_on'])) {
  147. $date = substr($lp_item['publicated_on'], 0, 10);
  148. } else {
  149. $date = '-';
  150. }
  151. //Checking LP publicated and expired_on dates
  152. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  153. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  154. continue;
  155. }
  156. }
  157. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  158. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  159. continue;
  160. }
  161. }
  162. $temp[$count]['cell']=array($date, $item['title'], Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET)));
  163. $temp[$count]['course'] = strip_tags($item['title']);
  164. $temp[$count]['lp'] = $lp_item['lp_name'];
  165. $temp[$count]['date'] = $lp_item['publicated_on'];
  166. $count++;
  167. }
  168. }
  169. $temp = ArrayClass::msort($temp, $sidx, $sord);
  170. $i =0;
  171. $response = new stdClass();
  172. foreach($temp as $key=>$row) {
  173. $row = $row['cell'];
  174. if (!empty($row)) {
  175. if ($key >= $start && $key < ($start + $limit)) {
  176. $response->rows[$i]['id']= $key;
  177. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2]);
  178. $i++;
  179. }
  180. }
  181. }
  182. if($count > 0 && $limit > 0) {
  183. $total_pages = ceil($count/$limit);
  184. } else {
  185. $total_pages = 0;
  186. }
  187. $response->total = $total_pages;
  188. if ($page > $total_pages) {
  189. $response->page= $total_pages;
  190. } else {
  191. $response->page = $page;
  192. }
  193. $response->records = $count;
  194. echo json_encode($response);
  195. break;
  196. case 'session_courses_lp_by_week':
  197. require_once '../global.inc.php';
  198. $page = intval($_REQUEST['page']); //page
  199. $limit = intval($_REQUEST['rows']); // quantity of rows
  200. $sidx = $_REQUEST['sidx']; //index to filter
  201. if (empty($sidx)) $sidx = 'course';
  202. $sord = $_REQUEST['sord']; //asc or desc
  203. if (!in_array($sord, array('asc','desc'))) {
  204. $sord = 'desc';
  205. }
  206. $session_id = intval($_REQUEST['session_id']);
  207. $course_id = intval($_REQUEST['course_id']);
  208. //Filter users that does not belong to the session
  209. if (!api_is_platform_admin()) {
  210. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  211. $my_session_list = array();
  212. foreach($new_session_list as $item) {
  213. if (!empty($item['id_session']))
  214. $my_session_list[] = $item['id_session'];
  215. }
  216. if (!in_array($session_id, $my_session_list)) {
  217. break;
  218. }
  219. }
  220. $start = $limit*$page - $limit;
  221. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  222. $count = 0;
  223. $temp = array();
  224. foreach ($course_list as $item) {
  225. if (isset($course_id) && !empty($course_id)) {
  226. if ($course_id != $item['id']) {
  227. continue;
  228. }
  229. }
  230. $list = new LearnpathList(api_get_user_id(),$item['code'], $session_id, 'publicated_on DESC');
  231. $flat_list = $list->get_flat_list();
  232. $lps[$item['code']] = $flat_list;
  233. $item['title'] = Display::url($item['title'],api_get_path(WEB_COURSE_PATH).$item['directory'].'/index.php?id_session='.$session_id,array('target'=>SESSION_LINK_TARGET));
  234. foreach($flat_list as $lp_id => $lp_item) {
  235. $temp[$count]['id']= $lp_id;
  236. $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';
  237. $last_date = Tracking::get_last_connection_date_on_the_course(api_get_user_id(),$item['id'], $session_id, false);
  238. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  239. $lp_date = api_get_local_time($lp_item['created_on']);
  240. $image = 'new.gif';
  241. $label = get_lang('LearnpathAdded');
  242. } else {
  243. $lp_date = api_get_local_time($lp_item['modified_on']);
  244. $image = 'moderator_star.png';
  245. $label = get_lang('LearnpathUpdated');
  246. }
  247. if (strtotime($last_date) < strtotime($lp_date)) {
  248. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  249. }
  250. if (!empty($lp_item['publicated_on'])) {
  251. $date = substr($lp_item['publicated_on'], 0, 10);
  252. } else {
  253. $date = '-';
  254. }
  255. //Checking LP publicated and expired_on dates
  256. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  257. $week_data = date('Y', api_strtotime($lp_item['publicated_on'], 'UTC')).' - '.get_week_from_day($lp_item['publicated_on']);
  258. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  259. continue;
  260. }
  261. } else {
  262. $week_data = '';
  263. }
  264. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  265. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  266. continue;
  267. }
  268. }
  269. $temp[$count]['cell'] = array($week_data, $date, $item['title'], Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET)));
  270. $temp[$count]['course'] = strip_tags($item['title']);
  271. $temp[$count]['lp'] = $lp_item['lp_name'];
  272. $count++;
  273. }
  274. }
  275. $temp = ArrayClass::msort($temp, $sidx, $sord);
  276. $response = new stdClass();
  277. $i =0;
  278. foreach($temp as $key=>$row) {
  279. $row = $row['cell'];
  280. if (!empty($row)) {
  281. if ($key >= $start && $key < ($start + $limit)) {
  282. $response->rows[$i]['id']= $key;
  283. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2],$row[3]);
  284. $i++;
  285. }
  286. }
  287. }
  288. if($count > 0 && $limit > 0) {
  289. $total_pages = ceil($count/$limit);
  290. } else {
  291. $total_pages = 0;
  292. }
  293. $response->total = $total_pages;
  294. if ($page > $total_pages) {
  295. $response->page = $total_pages;
  296. } else {
  297. $response->page = $page;
  298. }
  299. $response->records = $count;
  300. echo json_encode($response);
  301. break;
  302. case 'session_courses_lp_by_course':
  303. require_once '../global.inc.php';
  304. $page = intval($_REQUEST['page']); //page
  305. $limit = intval($_REQUEST['rows']); // quantity of rows
  306. $sidx = $_REQUEST['sidx']; //index to filter
  307. $sord = $_REQUEST['sord']; //asc or desc
  308. if (!in_array($sord, array('asc','desc'))) {
  309. $sord = 'desc';
  310. }
  311. $session_id = intval($_REQUEST['session_id']);
  312. $course_id = intval($_REQUEST['course_id']);
  313. //Filter users that does not belong to the session
  314. if (!api_is_platform_admin()) {
  315. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  316. $my_session_list = array();
  317. foreach($new_session_list as $item) {
  318. if (!empty($item['id_session']))
  319. $my_session_list[] = $item['id_session'];
  320. }
  321. if (!in_array($session_id, $my_session_list)) {
  322. break;
  323. }
  324. }
  325. if(!$sidx) $sidx =1;
  326. $start = $limit*$page - $limit;
  327. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  328. $count = 0;
  329. foreach ($course_list as $item) {
  330. if (isset($course_id) && !empty($course_id)) {
  331. if ($course_id != $item['id']) {
  332. continue;
  333. }
  334. }
  335. $list = new LearnpathList(api_get_user_id(),$item['code'],$session_id);
  336. $flat_list = $list->get_flat_list();
  337. $lps[$item['code']] = $flat_list;
  338. $item['title'] = Display::url($item['title'],api_get_path(WEB_COURSE_PATH).$item['directory'].'/index.php?id_session='.$session_id, array('target'=>SESSION_LINK_TARGET));
  339. foreach($flat_list as $lp_id => $lp_item) {
  340. $temp[$count]['id']= $lp_id;
  341. $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';
  342. $last_date = Tracking::get_last_connection_date_on_the_course(api_get_user_id(),$item['id'], $session_id, false);
  343. if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
  344. $lp_date = api_get_local_time($lp_item['created_on']);
  345. $image = 'new.gif';
  346. $label = get_lang('LearnpathAdded');
  347. } else {
  348. $lp_date = api_get_local_time($lp_item['modified_on']);
  349. $image = 'moderator_star.png';
  350. $label = get_lang('LearnpathUpdated');
  351. }
  352. if (strtotime($last_date) < strtotime($lp_date)) {
  353. $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
  354. }
  355. if (!empty($lp_item['publicated_on'])) {
  356. $date = substr($lp_item['publicated_on'], 0, 10);
  357. } else {
  358. $date = '-';
  359. }
  360. //Checking LP publicated and expired_on dates
  361. if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
  362. if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
  363. continue;
  364. }
  365. }
  366. if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
  367. if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
  368. continue;
  369. }
  370. }
  371. $temp[$count]['cell'] = array($date, $item['title'], Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET)));
  372. $temp[$count]['course'] = strip_tags($item['title']);
  373. $temp[$count]['lp'] = $lp_item['lp_name'];
  374. $temp[$count]['date'] = $lp_item['publicated_on'];
  375. $count++;
  376. }
  377. }
  378. $temp = ArrayClass::msort($temp, $sidx, $sord);
  379. $response = new stdClass();
  380. $i =0;
  381. foreach($temp as $key=>$row) {
  382. $row = $row['cell'];
  383. if (!empty($row)) {
  384. if ($key >= $start && $key < ($start + $limit)) {
  385. $response->rows[$i]['id']= $key;
  386. $response->rows[$i]['cell']=array($row[0], $row[1], $row[2],$row[3]);
  387. $i++;
  388. }
  389. }
  390. }
  391. if($count > 0 && $limit > 0) {
  392. $total_pages = ceil($count/$limit);
  393. } else {
  394. $total_pages = 0;
  395. }
  396. $response->total = $total_pages;
  397. if ($page > $total_pages) {
  398. $response->page= $total_pages;
  399. } else {
  400. $response->page = $page;
  401. }
  402. $response->records = $count;
  403. echo json_encode($response);
  404. break;
  405. default:
  406. echo '';
  407. }
  408. exit;