From 2dcb7cc2de448c664bbc9a7112f9cb13dc15c516 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 8 Oct 2018 21:15:56 +0200 Subject: Replaced some global `$user` variables --- includes/pages/admin_import.php | 5 +++-- includes/pages/admin_news.php | 5 +++-- includes/pages/admin_questions.php | 4 ++-- includes/pages/admin_user.php | 15 ++++++++------- includes/pages/guest_login.php | 7 ++++--- includes/pages/user_messages.php | 6 +++--- includes/pages/user_news.php | 10 +++++----- includes/pages/user_questions.php | 10 +++++----- includes/pages/user_shifts.php | 10 +++++----- 9 files changed, 38 insertions(+), 34 deletions(-) (limited to 'includes/pages') diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php index 29aa719b..f6889320 100644 --- a/includes/pages/admin_import.php +++ b/includes/pages/admin_import.php @@ -13,7 +13,8 @@ function admin_import_title() */ function admin_import() { - global $rooms_import, $user; + global $rooms_import; + $user = Auth()->user(); $html = ''; $import_dir = __DIR__ . '/../../import'; $request = request(); @@ -38,7 +39,7 @@ function admin_import() error(__('Webserver has no write-permission on import directory.')); } - $import_file = $import_dir . '/import_' . $user['UID'] . '.xml'; + $import_file = $import_dir . '/import_' . $user->id . '.xml'; $shifttype_id = null; $add_minutes_start = 15; $add_minutes_end = 15; diff --git a/includes/pages/admin_news.php b/includes/pages/admin_news.php index 8a3fe9c2..d387e06b 100644 --- a/includes/pages/admin_news.php +++ b/includes/pages/admin_news.php @@ -7,7 +7,8 @@ use Engelsystem\Database\DB; */ function admin_news() { - global $user, $privileges; + global $privileges; + $user = Auth()->user(); $request = request(); if (!$request->has('action')) { @@ -77,7 +78,7 @@ function admin_news() time(), strip_tags($request->postData('eBetreff')), $text, - $user['UID'], + $user->id, $request->has('eTreffen') ? 1 : 0, $news_id ] diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php index b4a956d5..fc84ff9e 100644 --- a/includes/pages/admin_questions.php +++ b/includes/pages/admin_questions.php @@ -39,7 +39,7 @@ function admin_new_questions() */ function admin_questions() { - global $user; + $user = Auth()->user(); $request = request(); if (!$request->has('action')) { @@ -126,7 +126,7 @@ function admin_questions() LIMIT 1 ', [ - $user['UID'], + $user->id, $answer, $question_id, ] diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index a0125604..2ef48eb7 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -15,7 +15,8 @@ function admin_user_title() */ function admin_user() { - global $user, $privileges; + global $privileges; + $user = Auth()->user(); $tshirt_sizes = config('tshirt_sizes'); $request = request(); $html = ''; @@ -52,7 +53,7 @@ function admin_user() . '

' . "\n"; $html .= ' Name' . '' . "\n"; $html .= ' Vorname' . '' . "\n"; - $html .= ' Alter' . '' . "\n"; + $html .= ' Alter' . '' . "\n"; $html .= ' Telefon' . '' . "\n"; $html .= ' Handy' . '' . "\n"; $html .= ' DECT' . '' . "\n"; @@ -114,7 +115,7 @@ function admin_user() $my_highest_group = DB::selectOne( 'SELECT group_id FROM `UserGroups` WHERE `uid`=? ORDER BY `group_id` LIMIT 1', - [$user['UID']] + [$user->id] ); if (!empty($my_highest_group)) { $my_highest_group = $my_highest_group['group_id']; @@ -128,7 +129,7 @@ function admin_user() $his_highest_group = $his_highest_group['group_id']; } - if ($user_id != $user['UID'] && $my_highest_group <= $his_highest_group) { + if ($user_id != $user->id && $my_highest_group <= $his_highest_group) { $html .= 'Hier kannst Du die Benutzergruppen des Engels festlegen:
' . "\n"; @@ -171,10 +172,10 @@ function admin_user() } else { switch ($request->input('action')) { case 'save_groups': - if ($user_id != $user['UID']) { + if ($user_id != $user->id) { $my_highest_group = DB::selectOne( 'SELECT * FROM `UserGroups` WHERE `uid`=? ORDER BY `group_id`', - [$user['UID']] + [$user->id] ); $his_highest_group = DB::selectOne( 'SELECT * FROM `UserGroups` WHERE `uid`=? ORDER BY `group_id`', @@ -241,7 +242,7 @@ function admin_user() break; case 'save': - $force_active = $user['force_active']; + $force_active = $user->state->force_active; $user_source = User($user_id); if (in_array('admin_active', $privileges)) { $force_active = $request->input('force_active'); diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 95e63bbc..1bb39d01 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -34,7 +34,8 @@ function logout_title() */ function guest_register() { - global $user, $privileges; + global $privileges; + $user = Auth()->user(); $tshirt_sizes = config('tshirt_sizes'); $enable_tshirt_size = config('enable_tshirt_size'); $min_password_length = config('min_password_length'); @@ -70,7 +71,7 @@ function guest_register() } } - if (!in_array('register', $privileges) || (!isset($user) && !config('registration_enabled'))) { + if (!in_array('register', $privileges) || (!$user && !config('registration_enabled'))) { error(__('Registration is disabled.')); return page_with_title(register_title(), [ @@ -269,7 +270,7 @@ function guest_register() success(__('Angel registration successful!')); // User is already logged in - that means a supporter has registered an angel. Return to register page. - if (isset($user)) { + if ($user) { redirect(page_link_to('register')); } diff --git a/includes/pages/user_messages.php b/includes/pages/user_messages.php index 0738f433..d2034dc0 100644 --- a/includes/pages/user_messages.php +++ b/includes/pages/user_messages.php @@ -15,12 +15,12 @@ function messages_title() */ function user_unread_messages() { - global $user; + $user = Auth()->user(); - if (isset($user)) { + if ($user) { $new_messages = count(DB::select( 'SELECT `id` FROM `Messages` WHERE isRead=\'N\' AND `RUID`=?', - [$user['UID']] + [$user->id] )); if ($new_messages > 0) { return ' ' . $new_messages . ''; diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index f95b6ae8..ac1f8b80 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -132,8 +132,7 @@ function display_news($news) */ function user_news_comments() { - global $user; - + $user = Auth()->user(); $request = request(); $html = '

' . user_news_comments_title() . '

'; @@ -158,7 +157,7 @@ function user_news_comments() $nid, date('Y-m-d H:i:s'), $text, - $user["UID"], + $user->id, ] ); engelsystem_log('Created news_comment: ' . $text); @@ -200,7 +199,8 @@ function user_news_comments() */ function user_news() { - global $privileges, $user; + global $privileges; + $user = Auth()->user(); $display_news = config('display_news'); $request = request(); @@ -225,7 +225,7 @@ function user_news() time(), strip_tags($request->postData('betreff')), $text, - $user['UID'], + $user->id, $isMeeting, ] ); diff --git a/includes/pages/user_questions.php b/includes/pages/user_questions.php index ea255a3d..94922141 100644 --- a/includes/pages/user_questions.php +++ b/includes/pages/user_questions.php @@ -15,18 +15,18 @@ function questions_title() */ function user_questions() { - global $user; + $user = Auth()->user(); $request = request(); if (!$request->has('action')) { $open_questions = DB::select( 'SELECT * FROM `Questions` WHERE `AID` IS NULL AND `UID`=?', - [$user['UID']] + [$user->id] ); $answered_questions = DB::select( 'SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`=?', - [$user['UID']] + [$user->id] ); foreach ($answered_questions as &$question) { $answer_user_source = User($question['AID']); @@ -47,7 +47,7 @@ function user_questions() INSERT INTO `Questions` (`UID`, `Question`) VALUES (?, ?) ', - [$user['UID'], $question] + [$user->id, $question] ); success(__('You question was saved.')); @@ -69,7 +69,7 @@ function user_questions() 'SELECT `UID` FROM `Questions` WHERE `QID`=? LIMIT 1', [$question_id] ); - if (!empty($question) && $question['UID'] == $user['UID']) { + if (!empty($question) && $question['UID'] == $user->id) { DB::delete( 'DELETE FROM `Questions` WHERE `QID`=? LIMIT 1', [$question_id] diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 6754292e..dc33d078 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -129,7 +129,7 @@ function load_days() */ function load_types() { - global $user; + $user = Auth()->user(); if (!count(DB::select('SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0'))) { error(__('The administration has not configured any angeltypes yet - or you are not subscribed to any angeltype.')); @@ -155,7 +155,7 @@ function load_types() ORDER BY `AngelTypes`.`name` ', [ - $user['UID'], + $user->id, ] ); if (empty($types)) { @@ -284,13 +284,13 @@ function view_user_shifts() */ function ical_hint() { - global $user; + $user = Auth()->user(); return heading(__('iCal export'), 2) . '

' . sprintf( __('Export your own shifts. iCal format or JSON format available (please keep secret, otherwise reset the api key).'), - page_link_to('ical', ['key' => $user['api_key']]), - page_link_to('shifts_json_export', ['key' => $user['api_key']]), + page_link_to('ical', ['key' => $user->api_key]), + page_link_to('shifts_json_export', ['key' => $user->api_key]), page_link_to('user_myshifts', ['reset' => 1]) ) . '

'; } -- cgit v1.2.3-70-g09d2