Moving some code from local to a CourseManager function in order to avoid a bug when $_course was not loaded even if we have a correct course code

skala
Julio Montoya 13 years ago
parent 8988067794
commit 1082ace12c
  1. 1
      main/course_home/activity.php
  2. 53
      main/course_home/course_home.php
  3. 46
      main/inc/lib/course.lib.php
  4. 7
      main/inc/lib/events.lib.inc.php
  5. 25
      main/inc/lib/social.lib.php
  6. 85
      main/inc/local.inc.php

@ -73,7 +73,6 @@ if (api_is_allowed_to_edit(null, true) && !api_is_coach()) {
</table>
</div>';
}
$my_list = CourseHome::get_tools_category(TOOL_AUTHORING);
$items = CourseHome::show_tools_category($my_list);
$content .= return_block(get_lang('Authoring'), $items);

@ -47,7 +47,7 @@ require dirname(__FILE__).'/../inc/global.inc.php';
//unset($_SESSION['oLP']);
//unset($_SESSION['lpobject']);
$htmlHeadXtra[] ='<script type="text/javascript">
$htmlHeadXtra[] ='<script>
$(document).ready(function() {
$(".make_visible_and_invisible").attr("href", "javascript:void(0);");
$(".make_visible_and_invisible > img").click(function () {
@ -111,19 +111,6 @@ $(function() {
</script>';
if (!isset($cidReq)) {
$cidReq = api_get_course_id(); // To provide compatibility with previous systems.
global $error_msg,$error_no;
$classError = 'init';
$error_no[$classError][] = '2';
$error_level[$classError][] = 'info';
$error_msg[$classError][] = "[".__FILE__."][".__LINE__."] cidReq was missing $cidReq take $dbname;";
}
if (isset($_SESSION['_gid'])) {
unset($_SESSION['_gid']);
}
// The section for the tabs
$this_section = SECTION_COURSES;
@ -139,26 +126,15 @@ define('TOOL_COURSE_PLUGIN', 'toolcourseplugin'); //all plugins that
define('TOOL_ADMIN', 'tooladmin');
define('TOOL_ADMIN_PLATFORM', 'tooladminplatform');
//define('TOOL_ADMIN_PLATFORM_VISIBLE', 'tooladminplatformvisible');
//define('TOOL_ADMIN_PLATFORM_INVISIBLE', 'tooladminplatforminvisible');
//define('TOOL_ADMIN_COURS_INVISIBLE', 'tooladmincoursinvisible');
define('TOOL_STUDENT_VIEW', 'toolstudentview');
define('TOOL_ADMIN_VISIBLE', 'tooladminvisible');
/* Virtual course support code */
$user_id = api_get_user_id();
$course_code = $_course['sysCode'];
$course_info = Database::get_course_info($course_code);
$return_result = CourseManager::determine_course_title_from_course_info($_user['user_id'], $course_info);
$course_title = $return_result['title'];
$course_code = $return_result['code'];
$_course['name'] = $course_title;
$_course['official_code'] = $course_code;
$course_code = api_get_course_id();
//Deleting group session
Session::erase('toolgroup');
Session::erase('_gid');
$is_speacialcourse = CourseManager::is_special_course($course_code);
@ -168,33 +144,28 @@ if ($is_speacialcourse) {
CourseManager::subscribe_user($user_id, $course_code, $status = STUDENT);
}
}
/* Is the user allowed here? */
if (!$is_allowed_in_course) {
api_not_allowed(true);
}
/* Header */
/* STATISTICS */
if (!isset($coursesAlreadyVisited[$_cid])) {
if (!isset($coursesAlreadyVisited[$course_code])) {
event_access_course();
$coursesAlreadyVisited[$_cid] = 1;
$coursesAlreadyVisited[$course_code] = 1;
Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
}
/*Auto lunch code */
/*Auto launch code */
$show_autolunch_lp_warning = false;
$auto_lunch = api_get_course_setting('enable_lp_auto_launch');
if (!empty($auto_lunch)) {
$auto_launch = api_get_course_setting('enable_lp_auto_launch');
if (!empty($auto_launch)) {
$session_id = api_get_session_id();
if ($auto_lunch == 2) { //LP list
if ($auto_launch == 2) { //LP list
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
$show_autolunch_lp_warning = true;
} else {
$session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
if (!isset($_SESSION[$session_key])) {
//redirecting to the LP
@ -244,15 +215,11 @@ if (!empty($auto_lunch)) {
}
$tool_table = Database::get_course_table(TABLE_TOOL_LIST);
$temps = time();
$reqdate = "&reqdate=$temps";
/* MAIN CODE */
//display course title for course home page (similar to toolname for tool pages)
//echo '<h3>'.api_display_tool_title($nameTools) . '</h3>';
/* Introduction section (editable by course admins) */
$content = Display::return_introduction_section(TOOL_COURSE_HOMEPAGE, array(

@ -42,7 +42,6 @@
CourseManager::get_target_of_linked_course($virtual_course_code)
TITLE AND CODE FUNCTIONS
CourseManager::determine_course_title_from_course_info($user_id, $course_info)
CourseManager::create_combined_name($user_is_registered_in_real_course, $real_course_name, $virtual_course_list)
CourseManager::create_combined_code($user_is_registered_in_real_course, $real_course_code, $virtual_course_list)
@ -804,6 +803,7 @@ class CourseManager {
* @return an array with indices
* $return_result['title'] - the course title of the combined courses
* $return_result['code'] - the course code of the combined courses
* @deprecated use api_get_course_info()
*/
public static function determine_course_title_from_course_info($user_id, $course_info) {
@ -3778,4 +3778,48 @@ class CourseManager {
return $row[0];
}
/*
* This code was originaly in local.inc.php
*/
static function get_course_info_with_category($course_code) {
global $_configuration;
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
$course_code = Database::escape_string($course_code);
$sql = "SELECT course.*, course_category.code faCode, course_category.name faName FROM $course_table
LEFT JOIN $course_cat_table
ON course.category_code = course_category.code
WHERE course.code = '$course_code'";
$result = Database::query($sql);
$_course = array();
if (Database::num_rows($result) > 0) {
$course_data = Database::fetch_array($result);
//@TODO real_cid should be cid, for working with numeric course id
$_course['real_id'] = $course_data['id'];
$_course['id'] = $course_data['code']; //auto-assigned integer
$_course['code'] = $course_data['code'];
$_course['name'] = $course_data['title'];
$_course['title'] = $course_data['title'];
$_course['official_code'] = $course_data['visual_code']; // use in echo
$_course['sysCode'] = $course_data['code']; // use as key in db
$_course['path'] = $course_data['directory']; // use as key in path
$_course['dbName'] = $course_data['db_name']; // use as key in db list
$_course['db_name'] = $course_data['db_name']; // not needed in Chamilo 1.9
$_course['dbNameGlu'] = $_configuration['table_prefix'] . $course_data['db_name'] . $_configuration['db_glue']; // use in all queries //not needed in Chamilo 1.9
$_course['titular'] = $course_data['tutor_name'];// this should be deprecated and use the table course_rel_user
$_course['language'] = $course_data['course_language'];
$_course['extLink']['url' ] = $course_data['department_url'];
$_course['extLink']['name'] = $course_data['department_name'];
$_course['categoryCode'] = $course_data['faCode'];
$_course['categoryName'] = $course_data['faName'];
$_course['visibility'] = $course_data['visibility'];
$_course['subscribe_allowed'] = $course_data['subscribe'];
$_course['unubscribe_allowed'] = $course_data['unsubscribe'];
$_course['activate_legal'] = $course_data['activate_legal'];
$_course['show_score'] = $course_data['show_score']; //used in the work tool
}
return $_course;
}
} //end class CourseManager

@ -104,14 +104,15 @@ function event_login() {
* @desc Record information for access event for courses
*/
function event_access_course() {
global $_user, $TABLETRACK_ACCESS, $TABLETRACK_LASTACCESS;
global $TABLETRACK_ACCESS, $TABLETRACK_LASTACCESS;
$id_session = api_get_session_id();
$now = api_get_utc_datetime();
$_cid = api_get_course_id();
$user_id = api_get_user_id();
if ($_user['user_id']) {
$user_id = "'".$_user['user_id']."'";
if ($user_id) {
$user_id = "'".$user_id."'";
} else {
$user_id = "0"; // no one
}

@ -417,29 +417,6 @@ class SocialManager extends UserManager {
return; //do not display this course entry
}
}
$has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_code, api_get_user_id());
if ($has_virtual_courses) {
$return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
$course_display_title = $return_result['title'];
$course_display_code = $return_result['code'];
} else {
$course_display_title = $course_title;
$course_display_code = $course_visual_code;
}
/*
$s_course_status=$my_course['s'];
$s_htlm_status_icon="";
if ($s_course_status==1) {
$s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px'));
}
if ($s_course_status==2) {
$s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('coachs.gif', get_lang('Status').': '.get_lang('GeneralCoach'),array('style'=>'width:11px; height:11px'));
}
if ($s_course_status==5) {
$s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'),array('style'=>'width:11px; height:11px'));
}*/
$s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course'));
@ -452,7 +429,7 @@ class SocialManager extends UserManager {
if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
$result .= '<a href="javascript:void(0)" id="ln_'.$count.'" onclick=toogle_course(this,\''.$course_id.'\');>&nbsp;'.$course_title.'</a>';
} else {
$result .= $course_display_title." "." ".get_lang('CourseClosed')."";
$result .= $course_title." "." ".get_lang('CourseClosed')."";
}
$result .= '</h3>';
//$current_course_settings = CourseManager :: get_access_settings($my_course['k']);

@ -56,23 +56,7 @@
* boolean $is_allowedCreateCourse
*
* COURSE VARIABLES
*
* string $_cid (the course id)
*
* int $_course['id' ] - auto-assigned integer
* string $_course['name' ] - the title of the course
* string $_course['official_code'] - the visual / fake / official code
* string $_course['sysCode' ]
* string $_course['path' ]
* string $_course['dbName' ]
* string $_course['dbNameGlu' ]
* string $_course['titular' ]
* string $_course['language' ]
* string $_course['extLink' ]['url' ]
* string $_course['extLink' ]['name']
* string $_course['categoryCode']
* string $_course['categoryName']
* see the function get_course_info_with_category
* boolean $is_courseMember
* boolean $is_courseTutor
* boolean $is_courseAdmin
@ -157,7 +141,6 @@ $gidReq = isset($_GET["gidReq"]) ? Database::escape_string($_GET["gidReq"]) : ''
$cidReq = isset($cidReq) ? Database::escape_string($cidReq) : '';
// $cidReq can be set in URL-parameter
$cidReq = isset($_GET["cidReq"]) ? Database::escape_string($_GET["cidReq"]) : $cidReq;
$cidReset = isset($cidReset) ? Database::escape_string($cidReset) : '';
// $cidReset can be set in URL-parameter
@ -673,51 +656,17 @@ if (isset($uidReset) && $uidReset) { // session data refresh requested
if (isset($cidReset) && $cidReset) {
// Course session data refresh requested or empty data
if ($cidReq) {
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
$sql = "SELECT course.*, course_category.code faCode, course_category.name faName
FROM $course_table
LEFT JOIN $course_cat_table
ON course.category_code = course_category.code
WHERE course.code = '$cidReq'";
$result = Database::query($sql);
$_course = CourseManager::get_course_info_with_category($cidReq);
if (Database::num_rows($result) > 0) {
$course_data = Database::fetch_array($result);
//@TODO real_cid should be cid, for working with numeric course id
$_real_cid = $course_data['id'];
$_cid = $course_data['code'];
$_course = array();
$_course['real_id'] = $course_data['id'];
$_course['id'] = $course_data['code']; //auto-assigned integer
$_course['code'] = $course_data['code'];
$_course['name'] = $course_data['title'];
$_course['title'] = $course_data['title'];
$_course['official_code'] = $course_data['visual_code']; // use in echo
$_course['sysCode'] = $course_data['code']; // use as key in db
$_course['path'] = $course_data['directory']; // use as key in path
$_course['dbName'] = $course_data['db_name']; // use as key in db list
$_course['db_name'] = $course_data['db_name']; // not needed in Chamilo 1.9
$_course['dbNameGlu'] = $_configuration['table_prefix'] . $course_data['db_name'] . $_configuration['db_glue']; // use in all queries //not needed in Chamilo 1.9
$_course['titular'] = $course_data['tutor_name'];// this should be deprecated and use the table course_rel_user
$_course['language'] = $course_data['course_language'];
$_course['extLink']['url' ] = $course_data['department_url'];
$_course['extLink']['name'] = $course_data['department_name'];
$_course['categoryCode'] = $course_data['faCode'];
$_course['categoryName'] = $course_data['faName'];
$_course['visibility'] = $course_data['visibility'];
$_course['subscribe_allowed'] = $course_data['subscribe'];
$_course['unubscribe_allowed'] = $course_data['unsubscribe'];
$_course['activate_legal'] = $course_data['activate_legal'];
$_course['show_score'] = $course_data['show_score']; //used in the work tool
//error_log('Course set: '.$_cid);
Session::write('_cid', $_cid);
Session::write('_course',$_course);
if (!empty($_course)) {
//@TODO real_cid should be cid, for working with numeric course id
$_real_cid = $_course['real_id'];
$_cid = $_course['code'];
Session::write('_real_cid', $_real_cid);
Session::write('_cid', $_cid);
Session::write('_course', $_course);
// if a session id has been given in url, we store the session
if (api_get_setting('use_session_mode') == 'true') {
@ -740,7 +689,7 @@ if (isset($cidReset) && $cidReset) {
if (!isset($_SESSION['login_as'])) {
//Course login
if (isset($_user['user_id'])) {
event_course_login($_course['sysCode'], $_user['user_id'], api_get_session_id());
event_course_login($_course['code'], $_user['user_id'], api_get_session_id());
}
}
} else {
@ -770,7 +719,22 @@ if (isset($cidReset) && $cidReset) {
}
}
} else {
// Continue with the previous values
if (empty($_SESSION['_course']) && !empty($_SESSION['_cid'])) {
//Just in case $_course is empty we try to load if the c_id still exists
$_course = CourseManager::get_course_info_with_category($_SESSION['_cid']);
if (!empty($_course)) {
$_real_cid = $_course['real_id'];
$_cid = $_course['code'];
Session::write('_real_cid', $_real_cid);
Session::write('_cid', $_cid);
Session::write('_course', $_course);
}
}
if (empty($_SESSION['_course']) OR empty($_SESSION['_cid'])) { //no previous values...
$_cid = -1; //set default values that will be caracteristic of being unset
$_course = -1;
@ -1053,7 +1017,6 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) {
Session::write('is_courseTutor', $is_courseTutor);
Session::write('is_courseCoach', $is_courseCoach);
Session::write('is_allowed_in_course', $is_allowed_in_course);
Session::write('is_sessionAdmin', $is_sessionAdmin);
} else { // continue with the previous values

Loading…
Cancel
Save