From ed4db6cd5880535e20d461425e37978977063b32 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 14 Jun 2011 14:21:10 +0200 Subject: [PATCH] Avoiding warning messages, fixing minor PHP errors, commenting todo code --- main/admin/add_many_session_to_category.php | 8 +- main/admin/resume_session.php | 4 +- main/admin/session_category_list.php | 2 +- main/admin/session_list.php | 10 +- main/admin/user_list.php | 433 +++++++++--------- main/inc/lib/display.lib.php | 1 + main/inc/lib/sessionmanager.lib.php | 3 +- .../send_message_to_userfriend.inc.php | 6 +- user_portal.php | 14 +- 9 files changed, 241 insertions(+), 240 deletions(-) diff --git a/main/admin/add_many_session_to_category.php b/main/admin/add_many_session_to_category.php index 5667f4e2e8..c51b592519 100755 --- a/main/admin/add_many_session_to_category.php +++ b/main/admin/add_many_session_to_category.php @@ -8,7 +8,7 @@ // name of the language file that needs to be included $language_file='admin'; // resetting the course id -$cidReset=true; +$cidReset = true; require_once '../inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'add_many_session_to_category_functions.lib.php'; @@ -125,7 +125,6 @@ if(isset($_GET['msg']) && $_GET['msg']=='ok'){ // display the dokeos header Display::display_header($tool_name); - echo '
'.$tool_name.'

'; $where =''; @@ -139,6 +138,11 @@ if((isset($_POST['CategorySessionId']) && $_POST['formSent'] == 0) || isset($_GE } $rows_session_category = SessionManager::get_all_session_category(); +if (empty($rows_session_category)) { + Display::display_warning_message(get_lang('YouNeedToAddASessionCategoryFirst')); + Display::display_footer(); + exit; +} $sql = "SELECT id, name FROM $tbl_session $where ORDER BY name"; $result=Database::query($sql); diff --git a/main/admin/resume_session.php b/main/admin/resume_session.php index 6bb2d1ce8a..aafa85cf5e 100755 --- a/main/admin/resume_session.php +++ b/main/admin/resume_session.php @@ -170,8 +170,8 @@ echo Display::tag('h3', $tool_name); '; echo get_lang('URL'); echo ''; diff --git a/main/admin/session_category_list.php b/main/admin/session_category_list.php index b596fea2a1..b5af86add8 100755 --- a/main/admin/session_category_list.php +++ b/main/admin/session_category_list.php @@ -40,7 +40,7 @@ if ($action == 'delete_on_session' || $action == 'delete_off_session') { exit(); } -$interbreadcrumb[]=array("url" => "index.php","name" => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array("url" => "index.php","name" => get_lang('PlatformAdmin')); if (isset ($_GET['search']) && $_GET['search'] == 'advanced') { $interbreadcrumb[] = array ("url" => 'session_category_list.php', "name" => get_lang('ListSessionCategory')); diff --git a/main/admin/session_list.php b/main/admin/session_list.php index d3ecb4e245..f80ba17438 100755 --- a/main/admin/session_list.php +++ b/main/admin/session_list.php @@ -52,6 +52,8 @@ if ($action == 'delete') { $interbreadcrumb[]=array("url" => "index.php","name" => get_lang('PlatformAdmin')); +$keyword_name = isset($_GET['keyword_name']) ? Security::remove_XSS($_GET['keyword_name']) : null; + //table for the search if (isset ($_GET['search']) && $_GET['search'] == 'advanced') { @@ -207,13 +209,15 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') { echo '
'; if (!isset($_GET['id_category'])) { echo ''.Display::return_icon('new_session.png',get_lang('AddSession'),'','32').''; - } - echo ''.Display::return_icon('session_to_category.png',get_lang('AddSessionsInCategories'),'','32').''; + } + echo ''.Display::return_icon('session_to_category.png',get_lang('AddSessionsInCategories'),'','32').''; + + echo ''.Display::return_icon('folder.png',get_lang('ListSessionCategory'),'','32').''; echo '
'; ?>
- +
diff --git a/main/admin/user_list.php b/main/admin/user_list.php index 9c5e0bf912..01249bb2d9 100755 --- a/main/admin/user_list.php +++ b/main/admin/user_list.php @@ -119,14 +119,14 @@ $htmlHeadXtra[] = ''; + // xajax $xajax = new xajax(); $xajax->registerFunction('courses_of_user'); //$xajax->registerFunction('empty_courses_of_user'); $xajax->processRequests(); - /** * Get a formatted list of courses for given user * @param int User ID @@ -214,9 +214,9 @@ function login_user($user_id) { //Load $_user to be sure we clean it before logging in global $uidReset, $loginFailed, $_configuration, $_user; - $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); - $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN); - $track_e_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); + $main_user_table = Database::get_main_table(TABLE_MAIN_USER); + $main_admin_table = Database::get_main_table(TABLE_MAIN_ADMIN); + $track_e_login_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); //logic @@ -317,14 +317,12 @@ function login_user($user_id) { * Get the total number of users on the platform * @see SortableTable#get_total_number_of_items() */ -function get_number_of_users() -{ +function get_number_of_users() { $user_table = Database :: get_main_table(TABLE_MAIN_USER); $sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u"; // adding the filter to see the user's only of the current access_url - global $_configuration; - if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls'] && api_get_current_access_url_id()!=-1) { + if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) { $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)"; } @@ -384,7 +382,7 @@ function get_number_of_users() } // adding the filter to see the user's only of the current access_url - if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls'] && api_get_current_access_url_id()!=-1) { + if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) { $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id(); } @@ -402,7 +400,7 @@ function get_number_of_users() */ function get_user_data($from, $number_of_items, $column, $direction) { - global $_configuration,$origin; + global $origin; $user_table = Database :: get_main_table(TABLE_MAIN_USER); $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN); @@ -423,7 +421,7 @@ function get_user_data($from, $number_of_items, $column, $direction) " FROM $user_table u "; // adding the filter to see the user's only of the current access_url - if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls'] && api_get_current_access_url_id()!=-1) { + if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) { $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)"; } @@ -484,7 +482,7 @@ function get_user_data($from, $number_of_items, $column, $direction) } // adding the filter to see the user's only of the current access_url - if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls'] && api_get_current_access_url_id()!=-1) { + if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) { $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id(); } @@ -560,6 +558,7 @@ function modify_filter($user_id,$url_params,$row) { if ($row['7'] == $statusname[ANONYMOUS]) { $user_is_anonymous =true; } + $result = ''; if (!$user_is_anonymous) { $result .= ' '.get_lang('Courses').' @@ -662,14 +661,14 @@ function active_filter($active, $url_params, $row) { $image='wrong'; } - + $result = ''; if ($action=='edit') { $result = Display::return_icon($image.'.gif', get_lang('AccountExpired')); } elseif ($row['0']<>$_user['user_id']) { // you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore. //$result = ''.Display::return_icon($image.'.gif', get_lang(ucfirst($action))).''; //$result = ''; - $result .=Display::return_icon($image.'.gif', get_lang(ucfirst($action)), array('onclick'=>'active_user(this);', 'id'=>'img_'.$row['0'])).''; + $result = Display::return_icon($image.'.gif', get_lang(ucfirst($action)), array('onclick'=>'active_user(this);', 'id'=>'img_'.$row['0'])).''; //$result .= '
'; } return $result; @@ -734,10 +733,6 @@ if ($_GET['action'] == "login_as" && isset ($login_as_user_id)) { login_user($login_as_user_id); } -//if (isset ($_GET['search']) && $_GET['search'] == 'advanced') -//{} -//else -//{ if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) { $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin')); $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList')); @@ -748,245 +743,239 @@ if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) { } - Display :: display_header($tool_name, ""); - - //api_display_tool_title($tool_name); - if (isset ($_GET['action'])) { - $check = Security::check_token('get'); - if($check) { - switch ($_GET['action']) { - case 'show_message' : - if (!empty($_GET['warn'])) { - // to prevent too long messages - if ($_GET['warn'] == 'session_message'){ - $_GET['warn'] = $_SESSION['session_message_import_users']; - } - Display::display_warning_message(urldecode($_GET['warn']),false); - } - if (!empty($_GET['message'])) { - Display :: display_confirmation_message(stripslashes($_GET['message'])); - } - break; - case 'delete_user' : - if (api_is_platform_admin()) { - if ($delete_user_available) { - if ($user_id != $_user['user_id'] && UserManager :: delete_user($_GET['user_id'])) { - Display :: display_confirmation_message(get_lang('UserDeleted')); - } else { - Display :: display_error_message(get_lang('CannotDeleteUserBecauseOwnsCourse')); - } +Display :: display_header($tool_name, ""); + +//api_display_tool_title($tool_name); +if (isset ($_GET['action'])) { + $check = Security::check_token('get'); + if ($check) { + switch ($_GET['action']) { + case 'show_message' : + if (!empty($_GET['warn'])) { + // to prevent too long messages + if ($_GET['warn'] == 'session_message'){ + $_GET['warn'] = $_SESSION['session_message_import_users']; + } + Display::display_warning_message(urldecode($_GET['warn']),false); + } + if (!empty($_GET['message'])) { + Display :: display_confirmation_message(stripslashes($_GET['message'])); + } + break; + case 'delete_user' : + if (api_is_platform_admin()) { + if ($delete_user_available) { + if ($user_id != $_user['user_id'] && UserManager :: delete_user($_GET['user_id'])) { + Display :: display_confirmation_message(get_lang('UserDeleted')); } else { - Display :: display_error_message(get_lang('CannotDeleteUser')); + Display :: display_error_message(get_lang('CannotDeleteUserBecauseOwnsCourse')); } + } else { + Display :: display_error_message(get_lang('CannotDeleteUser')); } - break; - case 'lock' : - $message=lock_unlock_user('lock',$_GET['user_id']); - Display :: display_normal_message($message); - break; - case 'unlock'; - $message=lock_unlock_user('unlock',$_GET['user_id']); - Display :: display_normal_message($message); - break; + } + break; + case 'lock' : + $message=lock_unlock_user('lock',$_GET['user_id']); + Display :: display_normal_message($message); + break; + case 'unlock'; + $message=lock_unlock_user('unlock',$_GET['user_id']); + Display :: display_normal_message($message); + break; - } - Security::clear_token(); } + Security::clear_token(); } - if (isset ($_POST['action'])) - { - $check = Security::check_token('get'); - if($check) - { - switch ($_POST['action']) - { - case 'delete' : - if (api_is_platform_admin()) { - $number_of_selected_users = count($_POST['id']); - $number_of_deleted_users = 0; - if (is_array($_POST['id'])) { - foreach ($_POST['id'] as $index => $user_id) +} + +if (isset ($_POST['action'])) { + $check = Security::check_token('get'); + if ($check) { + switch ($_POST['action']) { + case 'delete' : + if (api_is_platform_admin()) { + $number_of_selected_users = count($_POST['id']); + $number_of_deleted_users = 0; + if (is_array($_POST['id'])) { + foreach ($_POST['id'] as $index => $user_id) + { + if($user_id != $_user['user_id']) { - if($user_id != $_user['user_id']) + if(UserManager :: delete_user($user_id)) { - if(UserManager :: delete_user($user_id)) - { - $number_of_deleted_users++; - } + $number_of_deleted_users++; } } } - if($number_of_selected_users == $number_of_deleted_users) - { - Display :: display_confirmation_message(get_lang('SelectedUsersDeleted')); - } - else - { - Display :: display_error_message(get_lang('SomeUsersNotDeleted')); - } } - break; - } - Security::clear_token(); + if($number_of_selected_users == $number_of_deleted_users) + { + Display :: display_confirmation_message(get_lang('SelectedUsersDeleted')); + } + else + { + Display :: display_error_message(get_lang('SomeUsersNotDeleted')); + } + } + break; } + Security::clear_token(); } - // Create a search-box - $form = new FormValidator('search_simple','get','','',null,false); - $renderer =& $form->defaultRenderer(); - $renderer->setElementTemplate('{element} '); - $form->addElement('text','keyword',get_lang('keyword')); - $form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"'); - //$form->addElement('static','search_advanced_link',null,''.get_lang('AdvancedSearch').''); +} - $form->addElement('static','search_advanced_link',null,' '.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedSearch').''); +// Create a search-box +$form = new FormValidator('search_simple','get','','',null,false); +$renderer =& $form->defaultRenderer(); +$renderer->setElementTemplate('{element} '); +$form->addElement('text','keyword',get_lang('keyword')); +$form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"'); +//$form->addElement('static','search_advanced_link',null,''.get_lang('AdvancedSearch').''); + + $form->addElement('static','search_advanced_link',null,' '.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedSearch').''); + +echo '
'; +if (api_is_platform_admin()) { + echo ''. + ''.Display::return_icon('new_user.png',get_lang('AddUsers'),'','32').''. + ''; +} +$form->display(); +echo '
'; +if (isset ($_GET['keyword'])) { + $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword'])); +} elseif (isset ($_GET['keyword_firstname'])) { + $parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']); + $parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']); + $parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']); + $parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']); + $parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']); + $parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']); + $parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']); +} +// Create a sortable table with user-data +$parameters['sec_token'] = Security::get_token(); + +// get the list of all admins to mark them in the users list +$admin_table = Database::get_main_table(TABLE_MAIN_ADMIN); +$sql_admin = "SELECT user_id FROM $admin_table"; +$res_admin = Database::query($sql_admin); +$_admins_list = array(); +while ($row_admin = Database::fetch_row($res_admin)) { + $_admins_list[] = $row_admin[0]; +} - echo '
'; - if (api_is_platform_admin()) { - echo ''. - ''.Display::return_icon('new_user.png',get_lang('AddUsers'),'','32').''. - ''; - } - $form->display(); - echo '
'; - if (isset ($_GET['keyword'])) { - $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword'])); - } elseif (isset ($_GET['keyword_firstname'])) { - $parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']); - $parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']); - $parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']); - $parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']); - $parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']); - $parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']); - $parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']); - } - // Create a sortable table with user-data - $parameters['sec_token'] = Security::get_token(); - - // get the list of all admins to mark them in the users list - $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN); - $sql_admin = "SELECT user_id FROM $admin_table"; - $res_admin = Database::query($sql_admin); - $_admins_list = array(); - while ($row_admin = Database::fetch_row($res_admin)) { - $_admins_list[] = $row_admin[0]; - } +// display advaced search form +$form = new FormValidator('advanced_search','get'); - $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true); - $user_profile = UserManager::get_picture_user($user_id, $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" '); - if (!api_is_anonymous()) { - $photo = '
'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'
'; - } else { - $photo = '
'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'
'; - } +$form->addElement('html',''); +$table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2); +$table->set_additional_parameters($parameters); +$table->set_header(0, '', false, 'width="18px"'); +$table->set_header(1, get_lang('Photo'), false); +$table->set_header(2, get_lang('OfficialCode')); +if (api_is_western_name_order()) { + $table->set_header(3, get_lang('FirstName')); + $table->set_header(4, get_lang('LastName')); +} else { + $table->set_header(3, get_lang('LastName')); + $table->set_header(4, get_lang('FirstName')); +} +$table->set_header(5, get_lang('LoginName')); +$table->set_header(6, get_lang('Email')); +$table->set_header(7, get_lang('Profile')); +$table->set_header(8, get_lang('Active'),true, 'width="15px"'); +$table->set_header(9, get_lang('Action'), false,'width="220px"'); +$table->set_column_filter(3, 'user_filter'); +$table->set_column_filter(4, 'user_filter'); - $form->display(); +$table->set_column_filter(6, 'email_filter'); +$table->set_column_filter(7, 'status_filter'); +$table->set_column_filter(8, 'active_filter'); +$table->set_column_filter(9, 'modify_filter'); - $table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2); - $table->set_additional_parameters($parameters); - $table->set_header(0, '', false, 'width="18px"'); - $table->set_header(1, get_lang('Photo'), false); - $table->set_header(2, get_lang('OfficialCode')); - if (api_is_western_name_order()) { - $table->set_header(3, get_lang('FirstName')); - $table->set_header(4, get_lang('LastName')); - } else { - $table->set_header(3, get_lang('LastName')); - $table->set_header(4, get_lang('FirstName')); - } - $table->set_header(5, get_lang('LoginName')); - $table->set_header(6, get_lang('Email')); - $table->set_header(7, get_lang('Profile')); - $table->set_header(8, get_lang('Active'),true, 'width="15px"'); - $table->set_header(9, get_lang('Action'), false,'width="220px"'); - - $table->set_column_filter(3, 'user_filter'); - $table->set_column_filter(4, 'user_filter'); - - $table->set_column_filter(6, 'email_filter'); - $table->set_column_filter(7, 'status_filter'); - $table->set_column_filter(8, 'active_filter'); - $table->set_column_filter(9, 'modify_filter'); - if (api_is_platform_admin()) - $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform'))); - $table->display(); -//} -Display :: display_footer(); +if (api_is_platform_admin()) + $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform'))); +$table->display(); + +Display :: display_footer(); \ No newline at end of file diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 460c3f918f..2c9488d86c 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -464,6 +464,7 @@ class Display { $hmail .= '&#'.ord($email { $i }).';'; } + $hclickable_text = null; // Encrypt clickable text if @ is present if (strpos($clickable_text, '@')) { for ($i = 0; $i < strlen($clickable_text); $i ++) { diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index d131bb8e36..c142a5698a 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -1100,8 +1100,7 @@ class SessionManager { * Get all session categories (filter by access_url_id) * @return mixed false if the session category does not exist, array if the session category exists */ - public static function get_all_session_category() { - $id = intval($id); + public static function get_all_session_category() { $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $id = api_get_current_access_url_id(); $sql = 'SELECT * FROM '.$tbl_session_category.' WHERE access_url_id ="'.$id.'" ORDER BY name ASC'; diff --git a/main/messages/send_message_to_userfriend.inc.php b/main/messages/send_message_to_userfriend.inc.php index 22eec8f223..8c4c278f00 100755 --- a/main/messages/send_message_to_userfriend.inc.php +++ b/main/messages/send_message_to_userfriend.inc.php @@ -33,10 +33,10 @@ if (api_get_setting('allow_message_tool')=='true') { if ($panel == 1) { //normal message $user_info=api_get_user_info($userfriend_id); ?> -
- :     +
+ :  
-
* :
+
* :


:
diff --git a/user_portal.php b/user_portal.php index 6ccb8bf672..341dcbd0dd 100755 --- a/user_portal.php +++ b/user_portal.php @@ -376,16 +376,20 @@ if (is_array($courses_tree)) { // Courses inside the current session. $date_session_start = $session['details']['date_start']; $days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600; + $session_now = time(); $html_courses_session = ''; $count_courses_session = 0; foreach ($session['courses'] as $course) { $is_coach_course = api_is_coach($session['details']['id'], $course['code']); - if ($is_coach_course) { - $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning; - } else { - $allowed_time = api_strtotime($date_session_start); - } + $allowed_time = 0; + if ($date_session_start != '0000-00-00') { + if ($is_coach_course) { + $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning; + } else { + $allowed_time = api_strtotime($date_session_start); + } + } if ($session_now > $allowed_time) { //read only and accesible if (api_get_setting('hide_courses_in_sessions') == 'false') { $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',true);