diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-10-09 21:47:31 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2018-10-31 13:43:23 +0100 |
commit | 89e62c95a7ffd71a8e860f59378ecd13d6cbb196 (patch) | |
tree | a26965030177112a0d54a232c81ffd21d48529de /includes/pages | |
parent | b069a938c6721ab5adddcbec4cff858ded6f0e1e (diff) |
Changed more functions :tada:
Diffstat (limited to 'includes/pages')
-rw-r--r-- | includes/pages/admin_active.php | 17 | ||||
-rw-r--r-- | includes/pages/admin_arrive.php | 13 | ||||
-rw-r--r-- | includes/pages/admin_news.php | 3 | ||||
-rw-r--r-- | includes/pages/admin_questions.php | 5 | ||||
-rw-r--r-- | includes/pages/admin_user.php | 57 | ||||
-rw-r--r-- | includes/pages/guest_login.php | 15 | ||||
-rw-r--r-- | includes/pages/user_messages.php | 19 | ||||
-rw-r--r-- | includes/pages/user_myshifts.php | 13 | ||||
-rw-r--r-- | includes/pages/user_news.php | 7 | ||||
-rw-r--r-- | includes/pages/user_questions.php | 3 | ||||
-rw-r--r-- | includes/pages/user_shifts.php | 2 |
11 files changed, 75 insertions, 79 deletions
diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index 3a9ba8c4..33c7459d 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -1,6 +1,7 @@ <?php use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -100,8 +101,8 @@ function admin_active() if ($request->has('active') && preg_match('/^\d+$/', $request->input('active'))) { $user_id = $request->input('active'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if ($user_source) { DB::update('UPDATE `User` SET `Aktiv`=1 WHERE `UID`=? LIMIT 1', [$user_id]); engelsystem_log('User ' . User_Nick_render($user_source) . ' is active now.'); $msg = success(__('Angel has been marked as active.'), true); @@ -110,8 +111,8 @@ function admin_active() } } elseif ($request->has('not_active') && preg_match('/^\d+$/', $request->input('not_active'))) { $user_id = $request->input('not_active'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if (!$user_source) { DB::update('UPDATE `User` SET `Aktiv`=0 WHERE `UID`=? LIMIT 1', [$user_id]); engelsystem_log('User ' . User_Nick_render($user_source) . ' is NOT active now.'); $msg = success(__('Angel has been marked as not active.'), true); @@ -120,8 +121,8 @@ function admin_active() } } elseif ($request->has('tshirt') && preg_match('/^\d+$/', $request->input('tshirt'))) { $user_id = $request->input('tshirt'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if (!$user_source) { DB::update('UPDATE `User` SET `Tshirt`=1 WHERE `UID`=? LIMIT 1', [$user_id]); engelsystem_log('User ' . User_Nick_render($user_source) . ' has tshirt now.'); $msg = success(__('Angel has got a t-shirt.'), true); @@ -130,8 +131,8 @@ function admin_active() } } elseif ($request->has('not_tshirt') && preg_match('/^\d+$/', $request->input('not_tshirt'))) { $user_id = $request->input('not_tshirt'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if (!$user_source) { DB::update('UPDATE `User` SET `Tshirt`=0 WHERE `UID`=? LIMIT 1', [$user_id]); engelsystem_log('User ' . User_Nick_render($user_source) . ' has NO tshirt.'); $msg = success(__('Angel has got no t-shirt.'), true); diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index 4f29b85d..62d74290 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -1,6 +1,7 @@ <?php use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -26,8 +27,8 @@ function admin_arrive() if ($request->has('reset') && preg_match('/^\d+$/', $request->input('reset'))) { $user_id = $request->input('reset'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if ($user_source) { DB::update(' UPDATE `User` SET `Gekommen`=0, `arrival_date` = NULL @@ -36,14 +37,14 @@ function admin_arrive() ', [$user_id]); engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source)); success(__('Reset done. Angel has not arrived.')); - redirect(user_link($user_source['UID'])); + redirect(user_link($user_source->id)); } else { $msg = error(__('Angel not found.'), true); } } elseif ($request->has('arrived') && preg_match('/^\d+$/', $request->input('arrived'))) { $user_id = $request->input('arrived'); - $user_source = User($user_id); - if (!empty($user_source)) { + $user_source = User::find($user_id); + if ($user_source) { DB::update(' UPDATE `User` SET `Gekommen`=1, `arrival_date`=? @@ -52,7 +53,7 @@ function admin_arrive() ', [time(), $user_id]); engelsystem_log('User set has arrived: ' . User_Nick_render($user_source)); success(__('Angel has been marked as arrived.')); - redirect(user_link($user_source['UID'])); + redirect(user_link($user_source->id)); } else { $msg = error(__('Angel not found.'), true); } diff --git a/includes/pages/admin_news.php b/includes/pages/admin_news.php index d387e06b..2e951dde 100644 --- a/includes/pages/admin_news.php +++ b/includes/pages/admin_news.php @@ -1,6 +1,7 @@ <?php use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -29,7 +30,7 @@ function admin_news() switch ($request->input('action')) { case 'edit': - $user_source = User($news['UID']); + $user_source = User::find($news['UID']); if ( !in_array('admin_news_html', $privileges) && strip_tags($news['Text']) != $news['Text'] diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php index fc84ff9e..02f53d93 100644 --- a/includes/pages/admin_questions.php +++ b/includes/pages/admin_questions.php @@ -1,6 +1,7 @@ <?php use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -46,7 +47,7 @@ function admin_questions() $unanswered_questions_table = []; $questions = DB::select('SELECT * FROM `Questions` WHERE `AID` IS NULL'); foreach ($questions as $question) { - $user_source = User($question['UID']); + $user_source = User::find($question['UID']); $unanswered_questions_table[] = [ 'from' => User_Nick_render($user_source), @@ -66,7 +67,7 @@ function admin_questions() $answered_questions_table = []; $questions = DB::select('SELECT * FROM `Questions` WHERE NOT `AID` IS NULL'); foreach ($questions as $question) { - $user_source = User($question['UID']); + $user_source = User::find($question['UID']); $answer_user_source = User($question['AID']); $answered_questions_table[] = [ 'from' => User_Nick_render($user_source), diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index b4dd9c1b..961d59a2 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -1,6 +1,7 @@ <?php use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -27,8 +28,8 @@ function admin_user() $user_id = $request->input('id'); if (!$request->has('action')) { - $user_source = User($user_id); - if (empty($user_source)) { + $user_source = User::find($user_id); + if (!$user_source) { error(__('This user does not exist.')); redirect(users_link()); } @@ -47,22 +48,20 @@ function admin_user() $html .= '<input type="hidden" name="Type" value="Normal">' . "\n"; $html .= '<tr><td>' . "\n"; $html .= '<table>' . "\n"; - $html .= ' <tr><td>Nick</td><td>' . '<input size="40" name="eNick" value="' . $user_source['Nick'] . '" class="form-control"></td></tr>' . "\n"; + $html .= ' <tr><td>Nick</td><td>' . '<input size="40" name="eNick" value="' . $user_source->name . '" class="form-control"></td></tr>' . "\n"; $html .= ' <tr><td>Last login</td><td><p class="help-block">' - . date('Y-m-d H:i', $user_source['lastLogIn']) + . $user_source->last_login_at->format('Y-m-d H:i') . '</p></td></tr>' . "\n"; - $html .= ' <tr><td>Name</td><td>' . '<input size="40" name="eName" value="' . $user_source['Name'] . '" class="form-control"></td></tr>' . "\n"; - $html .= ' <tr><td>Vorname</td><td>' . '<input size="40" name="eVorname" value="' . $user_source['Vorname'] . '" class="form-control"></td></tr>' . "\n"; - $html .= ' <tr><td>Alter</td><td>' . '<input size="5" name="eAlter" value="' . $user_source['Alter'] . '" class="form-control"></td></tr>' . "\n"; - $html .= ' <tr><td>Telefon</td><td>' . '<input type="tel" size="40" name="eTelefon" value="' . $user_source['Telefon'] . '" class="form-control"></td></tr>' . "\n"; - $html .= ' <tr><td>Handy</td><td>' . '<input type= "tel" size="40" name="eHandy" value="' . $user_source['Handy'] . '" class="form-control"></td></tr>' . "\n"; - $html .= ' <tr><td>DECT</td><td>' . '<input size="4" name="eDECT" value="' . $user_source['DECT'] . '" class="form-control"></td></tr>' . "\n"; - if ($user_source['email_by_human_allowed']) { - $html .= " <tr><td>email</td><td>" . '<input type="email" size="40" name="eemail" value="' . $user_source['email'] . '" class="form-control"></td></tr>' . "\n"; + $html .= ' <tr><td>Name</td><td>' . '<input size="40" name="eName" value="' . $user_source->personalData->last_name . '" class="form-control"></td></tr>' . "\n"; + $html .= ' <tr><td>Vorname</td><td>' . '<input size="40" name="eVorname" value="' . $user_source->personalData->first_name . '" class="form-control"></td></tr>' . "\n"; + $html .= ' <tr><td>Handy</td><td>' . '<input type= "tel" size="40" name="eHandy" value="' . $user_source->contact->mobile . '" class="form-control"></td></tr>' . "\n"; + $html .= ' <tr><td>DECT</td><td>' . '<input size="4" name="eDECT" value="' . $user_source->contact->dect . '" class="form-control"></td></tr>' . "\n"; + if ($user_source->settings->email_human) { + $html .= " <tr><td>email</td><td>" . '<input type="email" size="40" name="eemail" value="' . $user_source->email . '" class="form-control"></td></tr>' . "\n"; } - $html .= " <tr><td>jabber</td><td>" . '<input type="email" size="40" name="ejabber" value="' . $user_source['jabber'] . '" class="form-control"></td></tr>' . "\n"; $html .= ' <tr><td>Size</td><td>' - . html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size'], __('Please select...')) . '</td></tr>' . "\n"; + . html_select_key('size', 'eSize', $tshirt_sizes, $user_source->personalData->shirt_size, + __('Please select...')) . '</td></tr>' . "\n"; $options = [ '1' => __('Yes'), @@ -71,23 +70,21 @@ function admin_user() // Gekommen? $html .= ' <tr><td>Gekommen</td><td>' . "\n"; - $html .= html_options('eGekommen', $options, $user_source['Gekommen']) . '</td></tr>' . "\n"; + $html .= html_options('eGekommen', $options, $user_source->state->arrived) . '</td></tr>' . "\n"; // Aktiv? $html .= ' <tr><td>Aktiv</td><td>' . "\n"; - $html .= html_options('eAktiv', $options, $user_source['Aktiv']) . '</td></tr>' . "\n"; + $html .= html_options('eAktiv', $options, $user_source->state->active) . '</td></tr>' . "\n"; // Aktiv erzwingen if (in_array('admin_active', $privileges)) { $html .= ' <tr><td>' . __('Force active') . '</td><td>' . "\n"; - $html .= html_options('force_active', $options, $user_source['force_active']) . '</td></tr>' . "\n"; + $html .= html_options('force_active', $options, $user_source->state->force_active) . '</td></tr>' . "\n"; } // T-Shirt bekommen? $html .= ' <tr><td>T-Shirt</td><td>' . "\n"; - $html .= html_options('eTshirt', $options, $user_source['Tshirt']) . '</td></tr>' . "\n"; - - $html .= ' <tr><td>Hometown</td><td>' . '<input size="40" name="Hometown" value="' . $user_source['Hometown'] . '" class="form-control"></td></tr>' . "\n"; + $html .= html_options('eTshirt', $options, $user_source->personalData->shirt_size) . '</td></tr>' . "\n"; $html .= '</table>' . "\n" . '</td><td valign="top"></td></tr>'; @@ -165,7 +162,7 @@ function admin_user() } $html .= buttons([ - button(user_delete_link($user_source['UID']), glyph('lock') . __('delete'), 'btn-danger') + button(user_delete_link($user_source->id), glyph('lock') . __('delete'), 'btn-danger') ]); $html .= "<hr />"; @@ -227,7 +224,7 @@ function admin_user() $user_groups_info[] = $groups[$group]['Name']; } } - $user_source = User($user_id); + $user_source = User::find($user_id); engelsystem_log( 'Set groups of ' . User_Nick_render($user_source) . ' to: ' . join(', ', $user_groups_info) @@ -243,7 +240,7 @@ function admin_user() case 'save': $force_active = $user->state->force_active; - $user_source = User($user_id); + $user_source = User::find($user_id); if (in_array('admin_active', $privileges)) { $force_active = $request->input('force_active'); } @@ -252,37 +249,29 @@ function admin_user() `Nick` = ?, `Name` = ?, `Vorname` = ?, - `Telefon` = ?, `Handy` = ?, - `Alter` =?, `DECT` = ?, - ' . ($user_source['email_by_human_allowed'] + ' . ($user_source->settings->email_human ? '`email` = ' . DB::getPdo()->quote($request->postData('eemail')) . ',' : '') . ' - `jabber` = ?, `Size` = ?, `Gekommen`= ?, `Aktiv`= ?, `force_active`= ?, - `Tshirt` = ?, - `Hometown` = ? + `Tshirt` = ? WHERE `UID` = ? LIMIT 1'; DB::update($sql, [ User_validate_Nick($request->postData('eNick')), $request->postData('eName'), $request->postData('eVorname'), - $request->postData('eTelefon'), $request->postData('eHandy'), - $request->postData('eAlter'), $request->postData('eDECT'), - $request->postData('ejabber'), $request->postData('eSize'), $request->postData('eGekommen'), $request->postData('eAktiv'), $force_active, $request->postData('eTshirt'), - $request->postData('Hometown'), $user_id, ]); engelsystem_log( @@ -300,7 +289,7 @@ function admin_user() && $request->postData('new_pw') == $request->postData('new_pw2') ) { set_password($user_id, $request->postData('new_pw')); - $user_source = User($user_id); + $user_source = User::find($user_id); engelsystem_log('Set new password for ' . User_Nick_render($user_source)); $html .= success('Passwort neu gesetzt.', true); } else { diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 1bb39d01..32532c6f 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -2,6 +2,7 @@ use Carbon\Carbon; use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -264,7 +265,7 @@ function guest_register() } engelsystem_log( - 'User ' . User_Nick_render(User($user_id)) + 'User ' . User_Nick_render(User::find($user_id)) . ' signed up as: ' . join(', ', $user_angel_types_info) ); success(__('Angel registration successful!')); @@ -430,10 +431,10 @@ function guest_login() if ($request->has('submit')) { if ($request->has('nick') && strlen(User_validate_Nick($request->input('nick'))) > 0) { $nick = User_validate_Nick($request->input('nick')); - $login_user = DB::selectOne('SELECT * FROM `User` WHERE `Nick`=?', [$nick]); - if (!empty($login_user)) { + $login_user = User::whereName($nick); + if ($login_user) { if ($request->has('password')) { - if (!verify_password($request->postData('password'), $login_user['Passwort'], $login_user['UID'])) { + if (!verify_password($request->postData('password'), $login_user->password, $login_user->id)) { $valid = false; error(__('Your password is incorrect. Please try it again.')); } @@ -450,9 +451,9 @@ function guest_login() error(__('Please enter a nickname.')); } - if ($valid && !empty($login_user)) { - $session->set('uid', $login_user['UID']); - $session->set('locale', $login_user['Sprache']); + if ($valid && $login_user) { + $session->set('uid', $login_user->id); + $session->set('locale', $login_user->settings->language); redirect(page_link_to('news')); } diff --git a/includes/pages/user_messages.php b/includes/pages/user_messages.php index d2034dc0..4431133e 100644 --- a/includes/pages/user_messages.php +++ b/includes/pages/user_messages.php @@ -1,6 +1,7 @@ <?php use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -34,13 +35,13 @@ function user_unread_messages() */ function user_messages() { - global $user; + $user = auth()->user(); $request = request(); if (!$request->has('action')) { $users = DB::select( 'SELECT `UID`, `Nick` FROM `User` WHERE NOT `UID`=? ORDER BY `Nick`', - [$user['UID']] + [$user->id] ); $to_select_data = [ @@ -61,8 +62,8 @@ function user_messages() ORDER BY `isRead`,`Datum` DESC ', [ - $user['UID'], - $user['UID'], + $user->id, + $user->id, ] ); @@ -78,8 +79,8 @@ function user_messages() ]; foreach ($messages as $message) { - $sender_user_source = User($message['SUID']); - $receiver_user_source = User($message['RUID']); + $sender_user_source = User::find($message['SUID']); + $receiver_user_source = User::find($message['RUID']); $messages_table_entry = [ 'new' => $message['isRead'] == 'N' ? '<span class="glyphicon glyphicon-envelope"></span>' : '', @@ -89,7 +90,7 @@ function user_messages() 'text' => str_replace("\n", '<br />', $message['Text']) ]; - if ($message['RUID'] == $user['UID']) { + if ($message['RUID'] == $user->id) { if ($message['isRead'] == 'N') { $messages_table_entry['actions'] = button( page_link_to('user_messages', ['action' => 'read', 'id' => $message['id']]), @@ -134,7 +135,7 @@ function user_messages() 'SELECT `RUID` FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id] ); - if (!empty($message) && $message['RUID'] == $user['UID']) { + if (!empty($message) && $message['RUID'] == $user->id) { DB::update( 'UPDATE `Messages` SET `isRead`=\'Y\' WHERE `id`=? LIMIT 1', [$message_id] @@ -156,7 +157,7 @@ function user_messages() 'SELECT `SUID` FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id] ); - if (!empty($message) && $message['SUID'] == $user['UID']) { + if (!empty($message) && $message['SUID'] == $user->id) { DB::delete('DELETE FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]); redirect(page_link_to('user_messages')); } else { diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 2a8a5d5a..ab4b00b6 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -1,6 +1,7 @@ <?php use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -31,12 +32,12 @@ function user_myshifts() $shift_entry_id = $user['UID']; } - $shifts_user = DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$shift_entry_id]); + $shifts_user = User::find($shift_entry_id); if ($request->has('reset')) { if ($request->input('reset') == 'ack') { User_reset_api_key($user); success(__('Key changed.')); - redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']])); + redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user->id])); } return page_with_title(__('Reset API key'), [ error( @@ -68,7 +69,7 @@ function user_myshifts() ', [ $shift_entry_id, - $shifts_user['UID'], + $shifts_user->id, ] ); if (!empty($shift)) { @@ -87,7 +88,7 @@ function user_myshifts() } $comment = strip_request_item_nl('comment'); - $user_source = User($shift['UID']); + $user_source = User::find($shift['UID']); if ($valid) { ShiftEntry_update([ @@ -105,7 +106,7 @@ function user_myshifts() . '. Freeloaded: ' . ($freeloaded ? 'YES Comment: ' . $freeload_comment : 'NO') ); success(__('Shift saved.')); - redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']])); + redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user->id])); } } @@ -125,6 +126,6 @@ function user_myshifts() } } - redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']])); + redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user->id])); return ''; } diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index ac1f8b80..266018a0 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -1,6 +1,7 @@ <?php use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -111,9 +112,7 @@ function display_news($news) } $html .= '<span class="glyphicon glyphicon-time"></span> ' . date('Y-m-d H:i', $news['Datum']) . ' '; - $user_source = User($news['UID']); - - $html .= User_Nick_render($user_source); + $html .= User_Nick_render(User::find($news['UID'])); if ($page != 'news_comments') { $html .= ' <a href="' . page_link_to('news_comments', ['nid' => $news['ID']]) . '">' . '<span class="glyphicon glyphicon-comment"></span> ' @@ -171,7 +170,7 @@ function user_news_comments() [$nid] ); foreach ($comments as $comment) { - $user_source = User($comment['UID']); + $user_source = User::find($comment['UID']); $html .= '<div class="panel panel-default">'; $html .= '<div class="panel-body">' . nl2br(htmlspecialchars($comment['Text'])) . '</div>'; diff --git a/includes/pages/user_questions.php b/includes/pages/user_questions.php index 94922141..c269dbb1 100644 --- a/includes/pages/user_questions.php +++ b/includes/pages/user_questions.php @@ -1,6 +1,7 @@ <?php use Engelsystem\Database\DB; +use Engelsystem\Models\User\User; /** * @return string @@ -29,7 +30,7 @@ function user_questions() [$user->id] ); foreach ($answered_questions as &$question) { - $answer_user_source = User($question['AID']); + $answer_user_source = User::find($question['AID']); $question['answer_user'] = User_Nick_render($answer_user_source); } diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index dc33d078..350394be 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -217,7 +217,7 @@ function view_user_shifts() } $ownTypes = []; - foreach (UserAngelTypes_by_User($user) as $type) { + foreach (UserAngelTypes_by_User($user['UID']) as $type) { $ownTypes[] = (int)$type['angeltype_id']; } |