123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- <?php
- /* For licensing terms, see /license.txt */
- // @todo refactor this script, create a class that manage the jqgrid requests
- /**
- * Responses to AJAX calls
- */
- $action = $_GET['a'];
- switch ($action) {
- case 'set_visibility':
- require_once '../global.inc.php';
- $course_id = api_get_course_int_id();
- if (api_is_allowed_to_edit(null, true)) {
- $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
- $tool_info = api_get_tool_information($_GET['id']);
- $tool_visibility = $tool_info['visibility'];
- $tool_image = $tool_info['image'];
- if (api_get_setting('homepage_view') != 'activity_big') {
- $tool_image = Display::return_icon($tool_image, null, null, null, null, true);
- $na_image = str_replace('.gif', '_na.gif', $tool_image);
- } else {
- // Display::return_icon() also checks in the main/css/{theme}/icons folder
- $tool_image = (substr($tool_info['image'], 0, strpos($tool_info['image'], '.'))).'.png';
- $tool_image = Display::return_icon(
- $tool_image,
- get_lang(ucfirst($too_info['name'])),
- null,
- ICON_SIZE_BIG,
- null,
- true
- );
- $na_image = str_replace('.png', '_na.png', $tool_image);
- }
- $requested_image = ($tool_visibility == 0 ) ? $tool_image : $na_image;
- $requested_class = ($tool_visibility == 0 ) ? 'visible' : 'invisible';
- $requested_message = ($tool_visibility == 0 ) ? 'is_active' : 'is_inactive';
- $requested_view = ($tool_visibility == 0 ) ? 'visible.png' : 'invisible.png';
- $requested_visible = ($tool_visibility == 0 ) ? 1 : 0;
- $requested_view = ($tool_visibility == 0 ) ? 'visible.png' : 'invisible.png';
- $requested_visible = ($tool_visibility == 0 ) ? 1 : 0;
- //HIDE AND REACTIVATE TOOL
- if ($_GET["id"] == strval(intval($_GET["id"]))) {
- /* -- session condition for visibility
- if (!empty($session_id)) {
- $sql = "select session_id FROM $tool_table WHERE id='".$_GET["id"]."' AND session_id = '$session_id'";
- $rs = Database::query($sql);
- if (Database::num_rows($rs) > 0) {
- $sql="UPDATE $tool_table SET visibility=$requested_visible WHERE id='".$_GET["id"]."' AND session_id = '$session_id'";
- } else {
- $sql_select = "select * FROM $tool_table WHERE id='".$_GET["id"]."'";
- $res_select = Database::query($sql_select);
- $row_select = Database::fetch_array($res_select);
- $sql = "INSERT INTO $tool_table(name,link,image,visibility,admin,address,added_tool,target,category,session_id)
- 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')";
- }
- } else $sql="UPDATE $tool_table SET visibility=$requested_visible WHERE id='".$_GET["id"]."'";
- */
- $sql = "UPDATE $tool_table SET visibility=$requested_visible WHERE c_id = $course_id AND id='" . intval($_GET['id']) . "'";
- Database::query($sql);
- }
- $response_data = array(
- 'image' => $requested_image,
- 'tclass' => $requested_class,
- 'message' => $requested_message,
- 'view' => $requested_view
- );
- echo json_encode($response_data);
- }
- break;
- case 'show_course_information' :
- $language_file = array('course_description');
- require_once '../global.inc.php';
- // Get the name of the database course.
- $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
- $course_info = api_get_course_info($_GET['code']);
- if ($course_info['visibility'] != COURSE_VISIBILITY_OPEN_WORLD) {
- if (api_is_anonymous()) {
- exit;
- }
- }
- echo Display::tag('h2', $course_info['name']);
- echo '<br />';
- $sql = "SELECT * FROM $tbl_course_description
- WHERE c_id = ".$course_info['real_id']." AND session_id = 0
- ORDER BY id";
- $result = Database::query($sql);
- if (Database::num_rows($result) > 0 ) {
- while ($description = Database::fetch_object($result)) {
- $descriptions[$description->id] = $description;
- }
- // Function that displays the details of the course description in html.
- echo CourseManager::get_details_course_description_html(
- $descriptions,
- api_get_system_encoding(),
- false
- );
- } else {
- echo get_lang('NoDescription');
- }
- break;
- case 'session_courses_lp_default':
- /**
- * @todo this functions need to belong to a class or a special
- * wrapper to process the AJAX petitions from the jqgrid
- */
- require_once '../global.inc.php';
- require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
- $now = time();
- $page = intval($_REQUEST['page']); //page
- $limit = intval($_REQUEST['rows']); // quantity of rows
- //index to filter
- $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id';
- $sord = $_REQUEST['sord']; //asc or desc
- if (!in_array($sord, array('asc','desc'))) {
- $sord = 'desc';
- }
- $session_id = intval($_REQUEST['session_id']);
- $course_id = intval($_REQUEST['course_id']);
- //Filter users that does not belong to the session
- if (!api_is_platform_admin()) {
- $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
- $my_session_list = array();
- foreach($new_session_list as $item) {
- if (!empty($item['id_session']))
- $my_session_list[] = $item['id_session'];
- }
- if (!in_array($session_id, $my_session_list)) {
- break;
- }
- }
- $start = $limit*$page - $limit;
- $course_list = SessionManager::get_course_list_by_session_id($session_id);
- $count = 0;
- $temp = array();
- foreach ($course_list as $item) {
- $list = new LearnpathList(api_get_user_id(), $item['code'], $session_id);
- $flat_list = $list->get_flat_list();
- $lps[$item['code']] = $flat_list;
- $course_url = api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id;
- $item['title'] = Display::url($item['title'], $course_url, array('target' => SESSION_LINK_TARGET));
- foreach ($flat_list as $lp_id => $lp_item) {
- $lp = new learnpath($item['code'], $lp_id, api_get_user_id());
- if ($lp->progress_db == 100) {
- continue;
- }
- $temp[$count]['id']= $lp_id;
- $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';
- $last_date = Tracking::get_last_connection_date_on_the_course(
- api_get_user_id(),
- $item['code'],
- $session_id,
- false
- );
- if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
- $lp_date = api_get_local_time($lp_item['created_on']);
- $image = 'new.gif';
- $label = get_lang('LearnpathAdded');
- } else {
- $lp_date = api_get_local_time($lp_item['modified_on']);
- $image = 'moderator_star.png';
- $label = get_lang('LearnpathUpdated');
- }
- if (strtotime($last_date) < strtotime($lp_date)) {
- $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
- }
- if (!empty($lp_item['publicated_on'])) {
- $date = substr($lp_item['publicated_on'], 0, 10);
- } else {
- $date = '-';
- }
- // Checking LP publicated and expired_on dates
- if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
- if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
- continue;
- }
- }
- if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
- if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
- continue;
- }
- }
- $temp[$count]['cell'] = array(
- $date,
- $item['title'],
- Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET))
- );
- $temp[$count]['course'] = strip_tags($item['title']);
- $temp[$count]['lp'] = $lp_item['lp_name'];
- $temp[$count]['date'] = $lp_item['publicated_on'];
- $count++;
- }
- }
- $temp = msort($temp, $sidx, $sord);
- $i =0;
- $response = new stdClass();
- foreach($temp as $key=>$row) {
- $row = $row['cell'];
- if (!empty($row)) {
- if ($key >= $start && $key < ($start + $limit)) {
- $response->rows[$i]['id']= $key;
- $response->rows[$i]['cell']=array($row[0], $row[1], $row[2]);
- $i++;
- }
- }
- }
- if($count > 0 && $limit > 0) {
- $total_pages = ceil($count/$limit);
- } else {
- $total_pages = 0;
- }
- $response->total = $total_pages;
- if ($page > $total_pages) {
- $response->page= $total_pages;
- } else {
- $response->page = $page;
- }
- $response->records = $count;
- echo json_encode($response);
- break;
- case 'session_courses_lp_by_week':
- require_once '../global.inc.php';
- require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
- $now = time();
- $page = intval($_REQUEST['page']); //page
- $limit = intval($_REQUEST['rows']); // quantity of rows
- $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'course';
- $sidx = str_replace(array('week desc,', ' '), '', $sidx);
- $sord = $_REQUEST['sord']; //asc or desc
- if (!in_array($sord, array('asc','desc'))) {
- $sord = 'desc';
- }
- $session_id = intval($_REQUEST['session_id']);
- $course_id = intval($_REQUEST['course_id']);
- //Filter users that does not belong to the session
- if (!api_is_platform_admin()) {
- $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
- $my_session_list = array();
- foreach($new_session_list as $item) {
- if (!empty($item['id_session']))
- $my_session_list[] = $item['id_session'];
- }
- if (!in_array($session_id, $my_session_list)) {
- break;
- }
- }
- $start = $limit*$page - $limit;
- $course_list = SessionManager::get_course_list_by_session_id($session_id);
- $count = 0;
- $temp = array();
- foreach ($course_list as $item) {
- if (isset($course_id) && !empty($course_id)) {
- if ($course_id != $item['id']) {
- continue;
- }
- }
- $list = new LearnpathList(api_get_user_id(),$item['code'], $session_id, 'publicated_on DESC');
- $flat_list = $list->get_flat_list();
- $lps[$item['code']] = $flat_list;
- $item['title'] = Display::url($item['title'],api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id,array('target'=>SESSION_LINK_TARGET));
- foreach ($flat_list as $lp_id => $lp_item) {
- $temp[$count]['id']= $lp_id;
- $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';
- $last_date = Tracking::get_last_connection_date_on_the_course(api_get_user_id(),$item['code'], $session_id, false);
- if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
- $lp_date = api_get_local_time($lp_item['created_on']);
- $image = 'new.gif';
- $label = get_lang('LearnpathAdded');
- } else {
- $lp_date = api_get_local_time($lp_item['modified_on']);
- $image = 'moderator_star.png';
- $label = get_lang('LearnpathUpdated');
- }
- if (strtotime($last_date) < strtotime($lp_date)) {
- $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
- }
- if (!empty($lp_item['publicated_on'])) {
- $date = substr($lp_item['publicated_on'], 0, 10);
- } else {
- $date = '-';
- }
- //Checking LP publicated and expired_on dates
- if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
- $week_data = date('Y', api_strtotime($lp_item['publicated_on'], 'UTC')).' - '.get_week_from_day($lp_item['publicated_on']);
- if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
- continue;
- }
- } else {
- $week_data = '';
- }
- if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
- if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
- continue;
- }
- }
- $temp[$count]['cell'] = array($week_data, $date, $item['title'], Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET)));
- $temp[$count]['course'] = strip_tags($item['title']);
- $temp[$count]['lp'] = $lp_item['lp_name'];
- $count++;
- }
- }
- if (!empty($sidx)) {
- $temp = msort($temp, $sidx, $sord);
- }
- $response = new stdClass();
- $i =0;
- foreach($temp as $key=>$row) {
- $row = $row['cell'];
- if (!empty($row)) {
- if ($key >= $start && $key < ($start + $limit)) {
- $response->rows[$i]['id']= $key;
- $response->rows[$i]['cell']=array($row[0], $row[1], $row[2],$row[3]);
- $i++;
- }
- }
- }
- if ($count > 0 && $limit > 0) {
- $total_pages = ceil($count/$limit);
- } else {
- $total_pages = 0;
- }
- $response->total = $total_pages;
- if ($page > $total_pages) {
- $response->page = $total_pages;
- } else {
- $response->page = $page;
- }
- $response->records = $count;
- echo json_encode($response);
- break;
- case 'session_courses_lp_by_course':
- require_once '../global.inc.php';
- require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
- $now = time();
- $page = intval($_REQUEST['page']); //page
- $limit = intval($_REQUEST['rows']); // quantity of rows
- $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id';
- $sidx = str_replace(array('course asc,', ' '), '', $sidx);
- $sord = $_REQUEST['sord']; //asc or desc
- if (!in_array($sord, array('asc','desc'))) {
- $sord = 'desc';
- }
- $session_id = intval($_REQUEST['session_id']);
- $course_id = intval($_REQUEST['course_id']);
- //Filter users that does not belong to the session
- if (!api_is_platform_admin()) {
- $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
- $my_session_list = array();
- foreach($new_session_list as $item) {
- if (!empty($item['id_session']))
- $my_session_list[] = $item['id_session'];
- }
- if (!in_array($session_id, $my_session_list)) {
- break;
- }
- }
- $start = $limit*$page - $limit;
- $course_list = SessionManager::get_course_list_by_session_id($session_id);
- $count = 0;
- foreach ($course_list as $item) {
- if (isset($course_id) && !empty($course_id)) {
- if ($course_id != $item['id']) {
- continue;
- }
- }
- $list = new LearnpathList(api_get_user_id(),$item['code'],$session_id);
- $flat_list = $list->get_flat_list();
- $lps[$item['code']] = $flat_list;
- $item['title'] = Display::url(
- $item['title'],
- api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id, array('target'=>SESSION_LINK_TARGET)
- );
- foreach($flat_list as $lp_id => $lp_item) {
- $temp[$count]['id']= $lp_id;
- $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';
- $last_date = Tracking::get_last_connection_date_on_the_course(api_get_user_id(),$item['code'], $session_id, false);
- if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) {
- $lp_date = api_get_local_time($lp_item['created_on']);
- $image = 'new.gif';
- $label = get_lang('LearnpathAdded');
- } else {
- $lp_date = api_get_local_time($lp_item['modified_on']);
- $image = 'moderator_star.png';
- $label = get_lang('LearnpathUpdated');
- }
- if (strtotime($last_date) < strtotime($lp_date)) {
- $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date);
- }
- if (!empty($lp_item['publicated_on'])) {
- $date = substr($lp_item['publicated_on'], 0, 10);
- } else {
- $date = '-';
- }
- //Checking LP publicated and expired_on dates
- if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') {
- if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) {
- continue;
- }
- }
- if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') {
- if ($now > api_strtotime($lp_item['expired_on'], 'UTC')) {
- continue;
- }
- }
- $temp[$count]['cell'] = array(
- $date,
- $item['title'],
- Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET))
- );
- $temp[$count]['course'] = strip_tags($item['title']);
- $temp[$count]['lp'] = $lp_item['lp_name'];
- $temp[$count]['date'] = $lp_item['publicated_on'];
- $count++;
- }
- }
- $temp = msort($temp, $sidx, $sord);
- $response = new stdClass();
- $i =0;
- foreach ($temp as $key=>$row) {
- $row = $row['cell'];
- if (!empty($row)) {
- if ($key >= $start && $key < ($start + $limit)) {
- $response->rows[$i]['id']= $key;
- $response->rows[$i]['cell']=array($row[0], $row[1], $row[2]);
- $i++;
- }
- }
- }
- if ($count > 0 && $limit > 0) {
- $total_pages = ceil($count / $limit);
- } else {
- $total_pages = 0;
- }
- $response->total = $total_pages;
- if ($page > $total_pages) {
- $response->page = $total_pages;
- } else {
- $response->page = $page;
- }
- $response->records = $count;
- echo json_encode($response);
- break;
- default:
- echo '';
- }
- exit;
|