course_home.ajax.php 20 KB

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