diff --git a/config/config.default.php b/config/config.default.php index 26217c39..fd4ff5a6 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -31,9 +31,9 @@ return [ // Contact email address, linked on every page 'Contact' => env('CONTACT_EMAIL', 'mailto:ticket@c3heaven.de'), ], - + // Link to documentation/help - 'documentation_url' => 'https://engelsystem.de/doc/', + 'documentation_url' => 'https://engelsystem.de/doc/', // Email config 'email' => [ diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index ad62416a..6c64cb27 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -62,7 +62,7 @@ function user_angeltypes_delete_all_controller() if ($request->hasPostData('deny_all')) { UserAngelTypes_delete_all($angeltype['id']); - engelsystem_log(sprintf('Denied all users for angeltype %s', AngelType_name_render($angeltype))); + engelsystem_log(sprintf('Denied all users for angeltype %s', AngelType_name_render($angeltype, true))); success(sprintf(__('Denied all users for angeltype %s.'), AngelType_name_render($angeltype))); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); } @@ -102,7 +102,7 @@ function user_angeltypes_confirm_all_controller() if ($request->hasPostData('confirm_all')) { UserAngelTypes_confirm_all($angeltype['id'], $user->id); - engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype))); + engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype, true))); success(sprintf(__('Confirmed all users for angeltype %s.'), AngelType_name_render($angeltype))); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); } @@ -156,8 +156,8 @@ function user_angeltype_confirm_controller() engelsystem_log(sprintf( '%s confirmed for angeltype %s', - User_Nick_render($user_source), - AngelType_name_render($angeltype) + User_Nick_render($user_source, true), + AngelType_name_render($angeltype, true) )); success(sprintf( __('%s confirmed for angeltype %s.'), @@ -214,9 +214,8 @@ function user_angeltype_delete_controller() if ($request->hasPostData('delete')) { UserAngelType_delete($user_angeltype); - $success_message = sprintf(__('User %s removed from %s.'), User_Nick_render($user_source), $angeltype['name']); - engelsystem_log($success_message); - success($success_message); + engelsystem_log(sprintf('User %s removed from %s.', User_Nick_render($user_source, true), $angeltype['name'])); + success(sprintf(__('User %s removed from %s.'), User_Nick_render($user_source), $angeltype['name'])); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); } @@ -275,15 +274,19 @@ function user_angeltype_update_controller() if ($request->hasPostData('submit')) { UserAngelType_update($user_angeltype['id'], $supporter); - $success_message = sprintf( - $supporter - ? __('Added supporter rights for %s to %s.') - : __('Removed supporter rights for %s from %s.'), + $msg = $supporter + ? __('Added supporter rights for %s to %s.') + : __('Removed supporter rights for %s from %s.'); + engelsystem_log(sprintf( + $msg, + AngelType_name_render($angeltype, true), + User_Nick_render($user_source, true) + )); + success(sprintf( + $msg, AngelType_name_render($angeltype), User_Nick_render($user_source) - ); - engelsystem_log($success_message); - success($success_message); + )); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); } @@ -324,8 +327,8 @@ function user_angeltype_add_controller() engelsystem_log(sprintf( 'User %s added to %s.', - User_Nick_render($user_source), - AngelType_name_render($angeltype) + User_Nick_render($user_source, true), + AngelType_name_render($angeltype, true) )); success(sprintf( __('User %s added to %s.'), @@ -336,8 +339,8 @@ function user_angeltype_add_controller() UserAngelType_confirm($user_angeltype_id, $user_source->id); engelsystem_log(sprintf( 'User %s confirmed as %s.', - User_Nick_render($user_source), - AngelType_name_render($angeltype) + User_Nick_render($user_source, true), + AngelType_name_render($angeltype, true) )); redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); @@ -372,8 +375,8 @@ function user_angeltype_join_controller($angeltype) $success_message = sprintf(__('You joined %s.'), $angeltype['name']); engelsystem_log(sprintf( 'User %s joined %s.', - User_Nick_render($user), - AngelType_name_render($angeltype) + User_Nick_render($user, true), + AngelType_name_render($angeltype, true) )); success($success_message); @@ -381,8 +384,8 @@ function user_angeltype_join_controller($angeltype) UserAngelType_confirm($user_angeltype_id, $user->id); engelsystem_log(sprintf( 'User %s confirmed as %s.', - User_Nick_render($user), - AngelType_name_render($angeltype) + User_Nick_render($user, true), + AngelType_name_render($angeltype, true) )); } diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index dea27645..7c6bde02 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -85,7 +85,7 @@ function user_delete_controller() mail_user_delete($user_source); success(__('User deleted.')); - engelsystem_log(sprintf('Deleted %s', User_Nick_render($user_source))); + engelsystem_log(sprintf('Deleted %s', User_Nick_render($user_source, true))); redirect(users_link()); } @@ -170,7 +170,7 @@ function user_edit_vouchers_controller() $user_source->state->save(); success(__('Saved the number of vouchers.')); - engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf('Got %s vouchers', + engelsystem_log(User_Nick_render($user_source, true) . ': ' . sprintf('Got %s vouchers', $user_source->state->got_voucher)); redirect(user_link($user_source->id)); diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 9b35f2b8..713d0f74 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -48,7 +48,7 @@ function AngelType_delete($angeltype) WHERE `id`=? LIMIT 1 ', [$angeltype['id']]); - engelsystem_log('Deleted angeltype: ' . AngelType_name_render($angeltype)); + engelsystem_log('Deleted angeltype: ' . AngelType_name_render($angeltype, true)); } /** diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index 54837bac..a017a32c 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -94,7 +94,7 @@ function ShiftEntry_create($shift_entry) ] ); engelsystem_log( - 'User ' . User_Nick_render($user) + 'User ' . User_Nick_render($user, true) . ' signed up for shift ' . $shift['name'] . ' from ' . date('Y-m-d H:i', $shift['start']) . ' to ' . date('Y-m-d H:i', $shift['end']) @@ -156,7 +156,7 @@ function ShiftEntry_delete($shiftEntry) $angeltype = AngelType($shiftEntry['TID']); engelsystem_log( - 'Shift signout: ' . User_Nick_render($signout_user) . ' from shift ' . $shifttype['name'] + 'Shift signout: ' . User_Nick_render($signout_user, true) . ' from shift ' . $shifttype['name'] . ' at ' . $room['Name'] . ' from ' . date('Y-m-d H:i', $shift['start']) . ' to ' . date('Y-m-d H:i', $shift['end']) diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index 3b679cda..7b766c5e 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -47,7 +47,7 @@ function UserWorkLog_delete($userWorkLog) engelsystem_log(sprintf( 'Delete work log for %s, %s hours, %s', - User_Nick_render($user_source), + User_Nick_render($user_source, true), $userWorkLog['work_hours'], $userWorkLog['comment'] )); @@ -78,7 +78,7 @@ function UserWorkLog_update($userWorkLog) engelsystem_log(sprintf( 'Updated work log for %s, %s hours, %s', - User_Nick_render($user_source), + User_Nick_render($user_source, true), $userWorkLog['work_hours'], $userWorkLog['comment']) ); @@ -115,7 +115,7 @@ function UserWorkLog_create($userWorkLog) time() ]); - engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s', User_Nick_render($user_source), + engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s', User_Nick_render($user_source, true), $userWorkLog['work_hours'], $userWorkLog['comment'])); return $result; diff --git a/includes/model/User_model.php b/includes/model/User_model.php index a928d895..1994bc47 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -5,6 +5,7 @@ use Engelsystem\Database\DB; use Engelsystem\Models\User\PasswordReset; use Engelsystem\Models\User\User; use Engelsystem\ValidationResult; +use Illuminate\Database\Query\JoinClause; /** * User model @@ -117,14 +118,14 @@ function Users_by_angeltype($angeltype) function User_validate_Nick($nick) { $nick = trim($nick); - - if(strlen($nick) == 0 || strlen($nick) > 23) { + + if (strlen($nick) == 0 || strlen($nick) > 23) { return new ValidationResult(false, $nick); } - if(preg_match('/([^\p{L}\p{N}\-_. ]+)/ui', $nick)) { + if (preg_match('/([^\p{L}\p{N}\-_. ]+)/ui', $nick)) { return new ValidationResult(false, $nick); } - + return new ValidationResult(true, $nick); } @@ -222,7 +223,7 @@ function User_reset_api_key($user, $log = true) $user->save(); if ($log) { - engelsystem_log(sprintf('API key resetted (%s).', User_Nick_render($user))); + engelsystem_log(sprintf('API key resetted (%s).', User_Nick_render($user, true))); } } @@ -239,7 +240,7 @@ function User_generate_password_recovery_token($user) $reset->token = md5($user->name . time() . rand()); $reset->save(); - engelsystem_log('Password recovery for ' . User_Nick_render($user) . ' started.'); + engelsystem_log('Password recovery for ' . User_Nick_render($user, true) . ' started.'); return $reset->token; } diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index c2f36693..508f3d81 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -86,7 +86,7 @@ function admin_active() foreach ($users as $usr) { $usr->state->active = true; $usr->state->save(); - $user_nicks[] = User_Nick_render($usr); + $user_nicks[] = User_Nick_render($usr, true); } State::whereForceActive(true)->update(['active' => true]); @@ -108,7 +108,7 @@ function admin_active() if ($user_source) { $user_source->state->active = true; $user_source->state->save(); - engelsystem_log('User ' . User_Nick_render($user_source) . ' is active now.'); + engelsystem_log('User ' . User_Nick_render($user_source, true) . ' is active now.'); $msg = success(__('Angel has been marked as active.'), true); } else { $msg = error(__('Angel not found.'), true); @@ -119,7 +119,7 @@ function admin_active() if ($user_source) { $user_source->state->active = false; $user_source->state->save(); - engelsystem_log('User ' . User_Nick_render($user_source) . ' is NOT active now.'); + engelsystem_log('User ' . User_Nick_render($user_source, true) . ' is NOT active now.'); $msg = success(__('Angel has been marked as not active.'), true); } else { $msg = error(__('Angel not found.'), true); @@ -130,7 +130,7 @@ function admin_active() if ($user_source) { $user_source->state->got_shirt = true; $user_source->state->save(); - engelsystem_log('User ' . User_Nick_render($user_source) . ' has tshirt now.'); + engelsystem_log('User ' . User_Nick_render($user_source, true) . ' has tshirt now.'); $msg = success(__('Angel has got a t-shirt.'), true); } else { $msg = error('Angel not found.', true); @@ -141,7 +141,7 @@ function admin_active() if ($user_source) { $user_source->state->got_shirt = false; $user_source->state->save(); - engelsystem_log('User ' . User_Nick_render($user_source) . ' has NO tshirt.'); + engelsystem_log('User ' . User_Nick_render($user_source, true) . ' has NO tshirt.'); $msg = success(__('Angel has got no t-shirt.'), true); } else { $msg = error(__('Angel not found.'), true); diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index aedb0803..f05b42cf 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -37,7 +37,7 @@ function admin_arrive() $user_source->state->arrival_date = null; $user_source->state->save(); - engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source)); + engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source, true)); success(__('Reset done. Angel has not arrived.')); redirect(user_link($user_source->id)); } else { @@ -55,7 +55,7 @@ function admin_arrive() $user_source->state->arrival_date = new Carbon\Carbon(); $user_source->state->save(); - engelsystem_log('User set has arrived: ' . User_Nick_render($user_source)); + engelsystem_log('User set has arrived: ' . User_Nick_render($user_source, true)); success(__('Angel has been marked as arrived.')); redirect(user_link($user_source->id)); } else { diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php index 7b6ce2ab..0e41390f 100644 --- a/includes/pages/admin_questions.php +++ b/includes/pages/admin_questions.php @@ -130,9 +130,9 @@ function admin_questions() ); engelsystem_log( 'Question ' - . htmlspecialchars($question['Question']) + . $question['Question'] . ' answered: ' - . htmlspecialchars($answer) + . $answer ); redirect(page_link_to('admin_questions')); } else { @@ -159,7 +159,7 @@ function admin_questions() ); if (!empty($question)) { DB::delete('DELETE FROM `Questions` WHERE `QID`=? LIMIT 1', [$question_id]); - engelsystem_log('Question deleted: ' . htmlspecialchars($question['Question'])); + engelsystem_log('Question deleted: ' . $question['Question']); redirect(page_link_to('admin_questions')); } else { return error('No question found.', true); diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index e59c5baa..e6f94180 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -240,7 +240,7 @@ function admin_user() } $user_source = User::find($user_id); engelsystem_log( - 'Set groups of ' . User_Nick_render($user_source) . ' to: ' + 'Set groups of ' . User_Nick_render($user_source, true) . ' to: ' . join(', ', $user_groups_info) ); $html .= success('Benutzergruppen gespeichert.', true); @@ -293,7 +293,7 @@ function admin_user() ) { set_password($user_id, $request->postData('new_pw')); $user_source = User::find($user_id); - engelsystem_log('Set new password for ' . User_Nick_render($user_source)); + engelsystem_log('Set new password for ' . User_Nick_render($user_source, true)); $html .= success('Passwort neu gesetzt.', true); } else { $html .= error( diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index a0aa92a5..b079b9fe 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -86,10 +86,11 @@ function guest_register() if ($request->has('nick')) { $nickValidation = User_validate_Nick($request->input('nick')); $nick = $nickValidation->getValue(); - - if(!$nickValidation->isValid()) { + + if (!$nickValidation->isValid()) { $valid = false; - $msg .= error(sprintf(__('Please enter a valid nick.') . ' ' . __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.'), $nick), true); + $msg .= error(sprintf(__('Please enter a valid nick.') . ' ' . __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.'), + $nick), true); } if (User::whereName($nick)->count() > 0) { $valid = false; @@ -246,7 +247,7 @@ function guest_register() } engelsystem_log( - 'User ' . User_Nick_render($user) + 'User ' . User_Nick_render($user, true) . ' signed up as: ' . join(', ', $user_angel_types_info) ); success(__('Angel registration successful!')); @@ -287,7 +288,8 @@ function guest_register() div('row', [ div('col-sm-4', [ form_text('nick', __('Nick') . ' ' . entry_required(), $nick), - form_info('', __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.')) + form_info('', + __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.')) ]), div('col-sm-8', [ form_email('mail', __('E-Mail') . ' ' . entry_required(), $mail), diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 11bbc9f4..9ab86f2a 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -99,7 +99,7 @@ function user_myshifts() ]); engelsystem_log( - 'Updated ' . User_Nick_render($user_source) . '\'s shift ' . $shift['name'] + 'Updated ' . User_Nick_render($user_source, true) . '\'s shift ' . $shift['name'] . ' from ' . date('Y-m-d H:i', $shift['start']) . ' to ' . date('Y-m-d H:i', $shift['end']) . ' with comment ' . $comment diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index 29aff5ca..39ce24a5 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -156,7 +156,7 @@ function user_news_comments() ] ); - engelsystem_log('Created news_comment: ' . htmlspecialchars($text)); + engelsystem_log('Created news_comment: ' . $text); $html .= success(__('Entry saved.'), true); } diff --git a/includes/sys_log.php b/includes/sys_log.php index 9ac17dc0..d3214290 100644 --- a/includes/sys_log.php +++ b/includes/sys_log.php @@ -18,7 +18,7 @@ function engelsystem_log($message, $level = LogLevel::INFO) $user = auth()->user(); if ($user) { - $nick = User_Nick_render($user); + $nick = User_Nick_render($user, true); } $logger->log($level, '{nick}: {message}', ['nick' => $nick, 'message' => $message]); diff --git a/includes/sys_template.php b/includes/sys_template.php index e40530d5..fad207a9 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -380,7 +380,7 @@ function button_glyph($href, $glyph, $class = '') /** * Rendert einen Knopf, der zur Hilfe eines bestimmten Themas führt. - * + * * @param string $topic documentation resource (like user/), is appended to documentation url. * @return string */ diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php index f4e83758..f5434e8f 100644 --- a/includes/view/AngelTypes_view.php +++ b/includes/view/AngelTypes_view.php @@ -12,10 +12,15 @@ use Engelsystem\ShiftsFilterRenderer; * Renders the angeltypes name as link. * * @param array $angeltype + * @param bool $plain * @return string */ -function AngelType_name_render($angeltype) +function AngelType_name_render($angeltype, $plain = false) { + if ($plain) { + return sprintf('%s (%u)', $angeltype['name'], $angeltype['id']); + } + return '' . ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name'] . ''; diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 85e6920c..59f611bc 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -36,7 +36,10 @@ function User_settings_view( form_info('', __('Here you can change your user details.')), form_info(entry_required() . ' = ' . __('Entry required!')), form_text('nick', __('Nick'), $user_source->name, true), - form_info('', __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.')), + form_info( + '', + __('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.') + ), form_text('lastname', __('Last name'), $personalData->last_name), form_text('prename', __('First name'), $personalData->first_name), $enable_planned_arrival ? form_date( @@ -856,14 +859,19 @@ function User_groups_render($user_groups) * Render a user nickname. * * @param array|User $user + * @param bool $plain * @return string */ -function User_Nick_render($user) +function User_Nick_render($user, $plain = false) { if (is_array($user)) { $user = (new User())->forceFill($user); } + if ($plain) { + return sprintf('%s (%u)', $user->name, $user->id); + } + return render_profile_link( ' ' . htmlspecialchars($user->name) . '', $user->id,