diff --git a/main/auth/courses.php b/main/auth/courses.php index 3d066f8b3e..fc86c791fb 100755 --- a/main/auth/courses.php +++ b/main/auth/courses.php @@ -15,7 +15,6 @@ $cidReset = true; // Flag forcing the 'current course' reset // including files require_once '../inc/global.inc.php'; - require_once api_get_path(LIBRARY_PATH).'auth.lib.php'; require_once api_get_path(LIBRARY_PATH).'app_view.php'; require_once 'courses_controller.php'; @@ -50,7 +49,7 @@ if (!(api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_crea } // filter actions -$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'unsubscribe', 'display_courses'); +$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'unsubscribe', 'display_courses','display_random_courses'); $action = 'subscribe'; $nameTools = get_lang('SortMyCourses'); @@ -147,17 +146,18 @@ if (isset($_GET['subscribe_course'])) { } switch ($action) { - case 'createcoursecategory' : + case 'createcoursecategory': $courses_controller->categories_list($action); break; - case 'deletecoursecategory' : - case 'sortmycourses' : + case 'deletecoursecategory': + case 'sortmycourses': $courses_controller->courses_list($action); break; - case 'subscribe' : + case 'subscribe': + case 'display_random_courses': $courses_controller->courses_categories($action); break; - case 'display_courses' : + case 'display_courses': $courses_controller->courses_categories($action, $_GET['category_code']); break; } diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php index 0533335964..ee189ec4ff 100755 --- a/main/auth/courses_controller.php +++ b/main/auth/courses_controller.php @@ -65,11 +65,8 @@ class CoursesController { // extends Controller { * @param string error message(optional) */ public function categories_list($action, $message='', $error='') { - - $data = array(); - + $data = array(); $data['user_course_categories'] = $this->model->get_user_course_categories(); - $data['action'] = $action; $data['message'] = $message; $data['error'] = $error; @@ -79,7 +76,6 @@ class CoursesController { // extends Controller { $this->view->set_layout('layout'); $this->view->set_template('categories_list'); $this->view->render(); - } /** @@ -91,32 +87,33 @@ class CoursesController { // extends Controller { public function courses_categories($action, $category_code = null, $message = '', $error = '') { $data = array(); $browse_course_categories = $this->model->browse_course_categories(); - - if (!isset($category_code)) { - $category_code = $browse_course_categories[0][1]['code']; // by default first category + + if ($action == 'display_random_courses') { + $data['browse_courses_in_category'] = $this->model->browse_courses_in_category(null, 20); + } else { + if (!isset($category_code)) { + $category_code = $browse_course_categories[0][1]['code']; // by default first category + } + $data['browse_courses_in_category'] = $this->model->browse_courses_in_category($category_code); } - $data['browse_courses_in_category'] = $this->model->browse_courses_in_category($category_code); $data['browse_course_categories'] = $browse_course_categories; $data['code'] = Security::remove_XSS($category_code); // getting all the courses to which the user is subscribed to $curr_user_id = api_get_user_id(); - $user_courses = $this->model->get_courses_of_user($curr_user_id); + $user_courses = $this->model->get_courses_of_user($curr_user_id); $user_coursecodes = array(); // we need only the course codes as these will be used to match against the courses of the category if ($user_courses != '') { - foreach ($user_courses as $key => $value) { - $user_coursecodes[] = $value['code']; + foreach($user_courses as $key => $value) { + $user_coursecodes[] = $value['code']; } } - $data['user_coursecodes'] = $user_coursecodes; - - - $data['action'] = $action; - $data['message'] = $message; - $data['error'] = $error; + $data['action'] = $action; + $data['message'] = $message; + $data['error'] = $error; // render to the view $this->view->set_data($data); @@ -283,7 +280,4 @@ class CoursesController { // extends Controller { $action = 'sortmycourses'; $this->courses_list($action, $message); } - - -} -?> +} \ No newline at end of file diff --git a/main/css/fix_chamilo.css b/main/css/fix_chamilo.css index 830f6dc43c..27530d8b46 100644 --- a/main/css/fix_chamilo.css +++ b/main/css/fix_chamilo.css @@ -75,3 +75,10 @@ div.admin_section { padding-right:10px; } +body { + font-family: Arial, Helvetica, sans-serif; +} + +a:link { + font-family: Arial, Helvetica, sans-serif; +} \ No newline at end of file diff --git a/main/inc/lib/auth.lib.php b/main/inc/lib/auth.lib.php index 2171709b4a..69248f6078 100755 --- a/main/inc/lib/auth.lib.php +++ b/main/inc/lib/auth.lib.php @@ -19,24 +19,24 @@ class Auth * Constructor */ public function __construct() {} - + /** * retrieves all the courses that the user has already subscribed to * @param int User id * @return array an array containing all the information of the courses of the given user */ public function get_courses_of_user($user_id) { - $TABLECOURS = Database::get_main_table(TABLE_MAIN_COURSE); - $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER); - $TABLE_COURSE_FIELD = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD); - $TABLE_COURSE_FIELD_VALUE = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES); + $TABLECOURS = Database::get_main_table(TABLE_MAIN_COURSE); + $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER); + $TABLE_COURSE_FIELD = Database::get_main_table(TABLE_MAIN_COURSE_FIELD); + $TABLE_COURSE_FIELD_VALUE = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES); // get course list auto-register $sql = "SELECT course_code FROM $TABLE_COURSE_FIELD_VALUE tcfv INNER JOIN $TABLE_COURSE_FIELD tcf ON " . - " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 "; + " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 "; $special_course_result = Database::query($sql); - if(Database::num_rows($special_course_result)>0) { + if (Database::num_rows($special_course_result)>0) { $special_course_list = array(); while ($result_row = Database::fetch_array($special_course_result)) { $special_course_list[] = '"'.$result_row['course_code'].'"'; @@ -49,23 +49,19 @@ class Auth // Secondly we select the courses that are in a category (user_course_cat<>0) and sort these according to the sort of the category $user_id = intval($user_id); - - $sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr, - course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status, - course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat - FROM $TABLECOURS course, - $TABLECOURSUSER course_rel_user - WHERE course.code = course_rel_user.course_code - AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." - AND course_rel_user.user_id = '".$user_id."' $without_special_courses - ORDER BY course_rel_user.sort ASC"; + course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status, + course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat + FROM $TABLECOURS course, $TABLECOURSUSER course_rel_user + WHERE course.code = course_rel_user.course_code + AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." + AND course_rel_user.user_id = '".$user_id."' $without_special_courses + ORDER BY course_rel_user.sort ASC"; $result = Database::query($sql_select_courses); while ($row = Database::fetch_array($result)) { - // we only need the database name of the course - $courses[] = array('db' => $row['db'], 'code' => $row['k'], 'visual_code' => $row['vc'], 'title' => $row['i'], 'directory' => $row['dir'], 'status' => $row['status'], 'tutor' => $row['t'], 'subscribe' => $row['subscr'], 'unsubscribe' => $row['unsubscr'], 'sort' => $row['sort'], 'user_course_category' => $row['user_course_cat']); + //we only need the database name of the course + $courses[] = array('db' => $row['db'], 'code' => $row['k'], 'visual_code' => $row['vc'], 'title' => $row['i'], 'directory' => $row['dir'], 'status' => $row['status'], 'tutor' => $row['t'], 'subscribe' => $row['subscr'], 'unsubscribe' => $row['unsubscr'], 'sort' => $row['sort'], 'user_course_category' => $row['user_course_cat']); } - return $courses; } @@ -74,15 +70,15 @@ class Auth * @return array containing all the IDs of the user defined courses categories, sorted by the "sort" field */ public function get_user_course_categories() { - $user_id = api_get_user_id(); - $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); - $sql = "SELECT * FROM ".$table_category." WHERE user_id=$user_id ORDER BY sort ASC"; - $result = Database::query($sql); - $output = array(); - while ($row = Database::fetch_array($result)) { - $output[] = $row; - } - return $output; + $user_id = api_get_user_id(); + $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + $sql = "SELECT * FROM ".$table_category." WHERE user_id=$user_id ORDER BY sort ASC"; + $result = Database::query($sql); + $output = array(); + while ($row = Database::fetch_array($result)) { + $output[] = $row; + } + return $output; } /** @@ -420,17 +416,15 @@ class Auth } } return $categories; - } + } /** * Display all the courses in the given course category. I could have used a parameter here * @param string Category code * @return array Courses data */ - public function browse_courses_in_category($category_code) { - - global $_configuration; - + public function browse_courses_in_category($category_code, $random_value = null) { + global $_configuration; $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $TABLE_COURSE_FIELD = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD); $TABLE_COURSE_FIELD_VALUE = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES); @@ -440,7 +434,7 @@ class Auth " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 "; $special_course_result = Database::query($sql); - if(Database::num_rows($special_course_result)>0) { + if (Database::num_rows($special_course_result)>0) { $special_course_list = array(); while ($result_row = Database::fetch_array($special_course_result)) { $special_course_list[] = '"'.$result_row['course_code'].'"'; @@ -450,12 +444,18 @@ class Auth if (!empty($special_course_list)) { $without_special_courses = ' AND course.code NOT IN ('.implode(',',$special_course_list).')'; } - - $category_code = Database::escape_string($category_code); - - $my_category = (empty($category) ? " IS NULL" : "='".$category."'"); - - $sql = "SELECT * FROM $tbl_course WHERE category_code='$category_code' $without_special_courses ORDER BY title, visual_code"; + + if (!empty($random_value)) { + $random_value = intval($random_value); + $sql = "SELECT * FROM $tbl_course WHERE 1 $without_special_courses ORDER BY RAND() LIMIT $random_value"; + /*SELECT * FROM $tbl_course, (SELECT CEIL(MAX($tbl_course.id) * RAND()) AS randId FROM $tbl_course) AS someRandId + WHERE $tbl_course.id >= someRandId.randId LIMIT 10 + */ + } else { + $category_code = Database::escape_string($category_code); + //$my_category = (empty($category) ? " IS NULL" : "='".$category."'"); + $sql = "SELECT * FROM $tbl_course WHERE category_code='$category_code' $without_special_courses ORDER BY title, visual_code"; + } //showing only the courses of the current Dokeos access_url_id if ($_configuration['multiple_access_urls']) { @@ -479,17 +479,17 @@ class Auth $row['tutor_name'] = get_lang('NoManager'); } $courses[] = array( - 'code' => $row['code'], - 'directory' => $row['directory'], - 'db' => $row['db_name'], - 'visual_code' => $row['visual_code'], - 'title' => $row['title'], - 'tutor' => $row['tutor_name'], - 'subscribe' => $row['subscribe'], - 'unsubscribe' => $row['unsubscribe'], + 'code' => $row['code'], + 'directory' => $row['directory'], + 'db' => $row['db_name'], + 'visual_code' => $row['visual_code'], + 'title' => $row['title'], + 'tutor' => $row['tutor_name'], + 'subscribe' => $row['subscribe'], + 'unsubscribe' => $row['unsubscribe'], 'registration_code' => $registration_code, - 'creation_date' => $row['creation_date'], - 'count_users' => $count_users, + 'creation_date' => $row['creation_date'], + 'count_users' => $count_users, 'count_connections' => $count_connections_last_month ); } diff --git a/main/template/default/auth/courses_categories.php b/main/template/default/auth/courses_categories.php index 470bf0c0fe..3fe110bfb8 100755 --- a/main/template/default/auth/courses_categories.php +++ b/main/template/default/auth/courses_categories.php @@ -49,7 +49,12 @@ $stok = Security::get_token();
'.get_lang('RandomPick').''; + $code = ''; + } else { + echo ''.get_lang('RandomPick').''; + } // level 1 foreach ($browse_course_categories[0] as $category) { $category_name = $category['name']; @@ -62,10 +67,9 @@ $stok = Security::get_token(); if (!empty($count_courses_lv1)) { $category_link = ''.$category_name.' ('.$count_courses_lv1.')'; } else { - $category_link = ''.$category_name.' ('.$count_courses_lv1.')'; + $category_link = ''.$category_name.' ('.$count_courses_lv1.')'; } - } - + } echo '
'.$category_link.'
'; // level 2 if (!empty($browse_course_categories[$category_code])) {