From 0a8495e3b54f34510188404e6cf1bb21cd0bbf19 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 1 Sep 2015 15:48:35 +0200 Subject: [PATCH] Remove gid unset, use api_get_group_id, api_get_course_id --- main/document/create_document.php | 2 +- main/forum/index.php | 6 --- main/forum/viewforumcategory.php | 7 --- ...ss_url_edit_users_to_url_functions.lib.php | 2 +- main/inc/lib/hook/README.md | 4 +- main/inc/lib/jpegcam/webcam_receiver.php | 2 +- main/inc/lib/search/search_widget.php | 47 ++++++++----------- .../svg-edit/extensions/imagelib/groups.php | 47 +++++++++++-------- main/permissions/group_permissions.inc.php | 5 +- main/user/subscribe_class.php | 13 +++-- main/user/subscribe_user.php | 14 +++++- 11 files changed, 78 insertions(+), 71 deletions(-) diff --git a/main/document/create_document.php b/main/document/create_document.php index 4be5f44e85..11e1d3b5a5 100755 --- a/main/document/create_document.php +++ b/main/document/create_document.php @@ -274,7 +274,7 @@ if ($is_certificate_mode) { } // Show read-only box only in groups -if (!empty($_SESSION['_gid'])) { +if (!empty($groupId)) { $group[]= $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly')); } $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required'); diff --git a/main/forum/index.php b/main/forum/index.php index ac59935b13..cae84da8ce 100755 --- a/main/forum/index.php +++ b/main/forum/index.php @@ -174,12 +174,6 @@ if (!api_is_anonymous()) { } } -/* CLEAN GROUP ID FOR AJAXFILEMANAGER */ - -if (isset($_SESSION['_gid'])) { - unset($_SESSION['_gid']); -} - /* ACTION LINKS */ echo '
'; diff --git a/main/forum/viewforumcategory.php b/main/forum/viewforumcategory.php index 9a95ebac75..96bedc9066 100755 --- a/main/forum/viewforumcategory.php +++ b/main/forum/viewforumcategory.php @@ -168,14 +168,7 @@ if ($action_forums != 'add') { } } - /* CLEAN GROUP ID FOR AJAXFILEMANAGER */ - - if (isset($_SESSION['_gid'])) { - unset($_SESSION['_gid']); - } - /* Display Forum Categories and the Forums in it */ - $html = ''; $html .= '
'; diff --git a/main/inc/lib/access_url_edit_users_to_url_functions.lib.php b/main/inc/lib/access_url_edit_users_to_url_functions.lib.php index 8786f01d26..e2799fcea2 100755 --- a/main/inc/lib/access_url_edit_users_to_url_functions.lib.php +++ b/main/inc/lib/access_url_edit_users_to_url_functions.lib.php @@ -28,7 +28,7 @@ class Accessurledituserstourl */ function search_users($needle, $id) { - global $tbl_user, $tbl_access_url_rel_user; + global $tbl_user; $xajax_response = new xajaxResponse(); $return = ''; diff --git a/main/inc/lib/hook/README.md b/main/inc/lib/hook/README.md index 7a8be9c8be..2085809070 100644 --- a/main/inc/lib/hook/README.md +++ b/main/inc/lib/hook/README.md @@ -18,8 +18,8 @@ From version 1.10.x, the following Hooks (or more) exist: |Number| Directory | EventClass | ObserverInterface | Reference | |------|-----------------------------------|----------------|---------------------------------|---------------------------| -| 1| /main/inc/lib/usermanager.lib.php | HookCreateUser | HookCreateUserObserverInterface | Usermanager::createUser() | -| 2| /main/inc/lib/usermanager.lib.php | HookUpdateUser | HookUpdateUserObserverInterface | Usermanager::updateUser() | +| 1| /main/inc/lib/usermanager.lib.php | HookCreateUser | HookCreateUserObserverInterface | UserManager::createUser() | +| 2| /main/inc/lib/usermanager.lib.php | HookUpdateUser | HookUpdateUserObserverInterface | UserManager::updateUser() | | 3| /main/admin/index.php | HookAdminBlock | HookAdminBlockObserverInterface | ADMIN BLOCK | # What do I need to use Hooks? diff --git a/main/inc/lib/jpegcam/webcam_receiver.php b/main/inc/lib/jpegcam/webcam_receiver.php index 9f10f3da12..1352b2a789 100755 --- a/main/inc/lib/jpegcam/webcam_receiver.php +++ b/main/inc/lib/jpegcam/webcam_receiver.php @@ -48,7 +48,7 @@ if($ext!= 'jpg'){ $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; $saveDir=$dirBaseDocuments.$webcamdir; $current_session_id = api_get_session_id(); -$groupId=$_SESSION['_gid']; +$groupId = api_get_group_id(); //avoid duplicates $webcamname_to_save=$webcamname; diff --git a/main/inc/lib/search/search_widget.php b/main/inc/lib/search/search_widget.php index 4b4bebe997..aa49c0f0ec 100755 --- a/main/inc/lib/search/search_widget.php +++ b/main/inc/lib/search/search_widget.php @@ -19,7 +19,7 @@ require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php'; * @param array $htmlHeadXtra A reference to the doc $htmlHeadXtra */ function search_widget_prepare(&$htmlHeadXtra) { - $htmlHeadXtra[] = ' + $htmlHeadXtra[] = ' @@ -31,7 +31,7 @@ function search_widget_prepare(&$htmlHeadXtra) { */ function format_one_specific_field_select($prefix, $sf_term_array, $op, $extra_select_attr='size="7" class="sf-select-multiple"') { global $charset; - $multiple_select .= ''; $all_selected = ''; if (!empty($_REQUEST['sf_'. $prefix]) ) { @@ -123,7 +123,7 @@ function search_widget_normal_form($action, $show_thesaurus, $sf_terms, $op) { $action='index.php'; } $navigator_info = api_get_navigator(); - + if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') { $submit_button1 = ''; $submit_button2 = ''; @@ -142,8 +142,8 @@ function search_widget_normal_form($action, $show_thesaurus, $sf_terms, $op) { '.$submit_button1.'

'; $list = get_specific_field_list(); - - if(!empty($list)) { + + if(!empty($list)) { $form .= ''. $advanced_options .' 
'. $help .'
@@ -200,7 +200,7 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op, if (isset($_GET['action']) && strcmp(trim($_GET['action']),'search')===0) { $action='index.php'; } - + $form = '
'; - } + } $form .= '
'; - + return $form; } @@ -276,7 +276,7 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op, */ function display_search_form($action, $show_thesaurus, $sf_terms, $op) { $type = (!empty($_REQUEST['type'])? htmlentities($_REQUEST['type']): 'normal'); - + switch ($type) { case 'prefilter': $prefilter_prefix = api_get_setting('search_prefilter_prefix'); @@ -302,17 +302,17 @@ function display_search_form($action, $show_thesaurus, $sf_terms, $op) { * @param string $action Just in case your action is not * index.php */ -function search_widget_show($action='index.php') { - global $charset; +function search_widget_show($action='index.php') +{ require_once api_get_path(LIBRARY_PATH).'search/ChamiloQuery.php'; // TODO: load images dinamically when they're avalaible from specific field ui to add - $icons_for_search_terms = array(); + $groupId = api_get_group_id(); $sf_terms = array(); $specific_fields = get_specific_field_list(); $url_params = array(); - if ( ($cid=api_get_course_id()) != -1 ) { // with cid + if (($cid = api_get_course_id()) != -1) { // with cid // get search engine terms $course_filter = chamilo_get_boolean_query(XAPIAN_PREFIX_COURSEID . $cid); @@ -330,31 +330,25 @@ function search_widget_show($action='index.php') { $url_params[] = 'sf_'.$specific_field['code']; unset($temp); } - } else { // without cid - // prepare specific fields names (and also get possible URL param names) foreach ($specific_fields as $specific_field) { //get Xapian terms for a specific term prefix, in ISO, apparently $sf_terms[$specific_field['code']] = xapian_get_all_terms(1000, $specific_field['code']); $url_params[] = 'sf_'.$specific_field['code']; } - } - echo '

'.get_lang('Search').'

'; - // Tool introduction // TODO: Settings for the online editor to be checked (insert an image for example). Probably this is a special case here. if (api_get_course_id() !== -1) - if (!empty($_SESSION['_gid'])) { - Display::display_introduction_section(TOOL_SEARCH.$_SESSION['_gid']); + if (!empty($groupId)) { + Display::display_introduction_section(TOOL_SEARCH.$groupId); } else { Display::display_introduction_section(TOOL_SEARCH); } - $op = 'or'; if (!empty($_REQUEST['operator']) && in_array($op,array('or','and'))) { $op = $_REQUEST['operator']; @@ -379,5 +373,4 @@ function search_widget_show($action='index.php') { // create the form // TODO: use FormValidator display_search_form($action, $show_thesaurus, $sf_terms, $op); - } diff --git a/main/inc/lib/svg-edit/extensions/imagelib/groups.php b/main/inc/lib/svg-edit/extensions/imagelib/groups.php index a7d1ea9c8d..b128fe6cc6 100755 --- a/main/inc/lib/svg-edit/extensions/imagelib/groups.php +++ b/main/inc/lib/svg-edit/extensions/imagelib/groups.php @@ -13,15 +13,22 @@ api_block_anonymous_users(); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $course_info = api_get_course_info(); +$groupId = api_get_group_id(); - -$group_properties = GroupManager::get_group_properties(api_get_group_id()); -$groupdirpath = $group_properties['directory']; -$group_disk_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/'; -$group_web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/'; +$group_properties = GroupManager::get_group_properties($groupId); +$groupdirpath = $group_properties['directory']; +$group_disk_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/'; +$group_web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/'; //get all group files and folders -$docs_and_folders = DocumentManager::get_all_document_data($course_info, $groupdirpath, api_get_group_id(), null, $is_allowed_to_edit, false); +$docs_and_folders = DocumentManager::get_all_document_data( + $course_info, + $groupdirpath, + api_get_group_id(), + null, + $is_allowed_to_edit, + false +); //get all group filenames $array_to_search = is_array($docs_and_folders) ? $docs_and_folders : array(); @@ -36,13 +43,13 @@ if (count($array_to_search) > 0) { $accepted_extensions = array('.svg', '.png'); if (is_array($all_files) && count($all_files) > 0) { - foreach ($all_files as & $file) { - $slideshow_extension = strrchr($file, '.'); - $slideshow_extension = strtolower($slideshow_extension); - if (in_array($slideshow_extension, $accepted_extensions)) { - $png_svg_files[] =$file; - } - } + foreach ($all_files as & $file) { + $slideshow_extension = strrchr($file, '.'); + $slideshow_extension = strtolower($slideshow_extension); + if (in_array($slideshow_extension, $accepted_extensions)) { + $png_svg_files[] =$file; + } + } } $style = ''; '.get_lang('GroupSingle').': '.$group_properties['name'].''; -if (($group_properties['doc_state'] == 2 && ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid']))) || $group_properties['doc_state'] == 1){ +if (( + $group_properties['doc_state'] == 2 && + ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $groupId))) || $group_properties['doc_state'] == 1 +){ if (!empty($png_svg_files)) { echo '

'.get_lang('SelectSVGEditImage').'

'; @@ -69,13 +79,12 @@ if (($group_properties['doc_state'] == 2 && ($is_allowed_to_edit || GroupManager if (strpos($filename, "svg")){ $new_sizes['width'] = 60; $new_sizes['height'] = 60; - } - else { + } else { $new_sizes = api_resize_image($image, 60, 60); } - echo '
  • '; - echo ''; - echo '
  • '; + echo '
  • '; + echo ''; + echo '
  • '; } echo ''; } diff --git a/main/permissions/group_permissions.inc.php b/main/permissions/group_permissions.inc.php index 92d72e978f..4597581fa2 100755 --- a/main/permissions/group_permissions.inc.php +++ b/main/permissions/group_permissions.inc.php @@ -2,12 +2,13 @@ /** * @package chamilo.permissions */ -/** +/** * Code */ include_once('permissions_functions.inc.php'); include_once('all_permissions.inc.php'); -$group_id=$_SESSION['_gid']; +$group_id = api_get_group_id(); + echo $group_id; // --------------------------------------------------- // ACTIONS diff --git a/main/user/subscribe_class.php b/main/user/subscribe_class.php index 2dcf6ccb8f..66bfc0b0a4 100755 --- a/main/user/subscribe_class.php +++ b/main/user/subscribe_class.php @@ -44,10 +44,14 @@ if (isset($_POST['action'])) { /** * * Get the number of classes to display on the current page. */ -function get_number_of_classes() { +function get_number_of_classes() +{ $class_table = Database :: get_main_table(TABLE_MAIN_CLASS); $course_class_table = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS); - $sql = "SELECT * FROM $course_class_table WHERE course_code = '" . $_SESSION['_course']['id'] . "'"; + $courseCode = api_get_course_id(); + + $sql = "SELECT * FROM $course_class_table + WHERE course_code = '" . $courseCode. "'"; $res = Database::query($sql); $subscribed_classes = array(); while ($obj = Database::fetch_object($res)) { @@ -63,6 +67,7 @@ function get_number_of_classes() { } $res = Database::query($sql); $result = Database::num_rows($res); + return $result; } @@ -73,7 +78,9 @@ function get_class_data($from, $number_of_items, $column, $direction) { $class_table = Database :: get_main_table(TABLE_MAIN_CLASS); $course_class_table = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS); $class_user_table = Database :: get_main_table(TABLE_MAIN_CLASS_USER); - $sql = "SELECT * FROM $course_class_table WHERE course_code = '" . $_SESSION['_course']['id'] . "'"; + $courseCode = api_get_course_id(); + + $sql = "SELECT * FROM $course_class_table WHERE course_code = '" . $courseCode . "'"; $res = Database::query($sql); $subscribed_classes = array(); while ($obj = Database::fetch_object($res)) { diff --git a/main/user/subscribe_user.php b/main/user/subscribe_user.php index 1606cc7826..3aba74fb81 100755 --- a/main/user/subscribe_user.php +++ b/main/user/subscribe_user.php @@ -282,6 +282,9 @@ function get_number_of_users() $tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); + $courseCode = api_get_course_id(); + $sessionId = api_get_session_id(); + if (isset($_REQUEST['type']) && $_REQUEST['type']=='teacher') { if (api_get_session_id() != 0) { @@ -429,9 +432,15 @@ function get_number_of_users() // getting all the users of the course (to make sure that we do not display users that are already in the course) if (!empty($_SESSION["id_session"])) { - $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], $_SESSION['id_session']); + $a_course_users = CourseManager:: get_user_list_from_course_code( + $courseCode, + $sessionId + ); } else { - $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], 0); + $a_course_users = CourseManager:: get_user_list_from_course_code( + $courseCode, + 0 + ); } foreach ($a_course_users as $user_id=>$course_user) { $users_of_course[] = $course_user['user_id']; @@ -445,6 +454,7 @@ function get_number_of_users() $row = Database::fetch_row($res); $count_user = $row[0]; } + return $count_user; } /**