diff options
-rw-r--r-- | includes/controller/users_controller.php | 31 | ||||
-rw-r--r-- | includes/model/ShiftEntry_model.php | 7 | ||||
-rw-r--r-- | includes/model/User_model.php | 41 | ||||
-rw-r--r-- | includes/pages/user_myshifts.php | 3 | ||||
-rw-r--r-- | includes/view/User_view.php | 1 |
5 files changed, 57 insertions, 26 deletions
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index b1692e21..b24a7fdf 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -54,6 +54,9 @@ function user_controller() { ); } +/** + * List all users. + */ function users_list_controller() { global $privileges; @@ -61,39 +64,19 @@ function users_list_controller() { redirect(page_link_to('')); $order_by = 'Nick'; - if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], array( - 'Nick', - 'Name', - 'Vorname', - 'Alter', - 'DECT', - 'email', - 'Size', - 'Gekommen', - 'Aktiv', - 'force_active', - 'Tshirt', - 'lastLogIn' - ))) + if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns())) $order_by = $_REQUEST['OrderBy']; $users = Users($order_by); if ($users === false) engelsystem_error('Unable to load users.'); - foreach ($users as &$user) { - $user['freeloads'] = sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1 AND `UID` = " . sql_escape($user['UID'])); - } - - $arrived_count = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1"); - $active_count = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1"); - $force_active_count = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `force_active` = 1"); - $freeloads_count = sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1"); - $tshirts_count = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1"); + foreach ($users as &$user) + $user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user)); return array( _('All users'), - Users_view($users, $order_by, $arrived_count, $active_count, $force_active_count, $freeloads_count, $tshirts_count) + Users_view($users, $order_by, User_arrived_count(), User_active_count(), User_force_active_count(), ShiftEntries_freeleaded_count(), User_tshirts_count()) ); } diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index 332620f6..c7895f17 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -1,6 +1,13 @@ <?php /** + * Counts all freeloaded shifts. + */ +function ShiftEntries_freeleaded_count() { + return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1"); +} + +/** * Returns next (or current) shifts of given user. * @param User $user */ diff --git a/includes/model/User_model.php b/includes/model/User_model.php index af4c4a97..45ed2700 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -5,8 +5,47 @@ */ /** + * Counts all forced active users. + */ +function User_force_active_count() { + return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `force_active` = 1"); +} + +function User_active_count() { + return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1"); +} + +function User_arrived_count() { + return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1"); +} + +function User_tshirts_count() { + return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1"); +} + +/** + * Returns all column names for sorting in an array. + */ +function User_sortable_columns() { + return array( + 'Nick', + 'Name', + 'Vorname', + 'Alter', + 'DECT', + 'email', + 'Size', + 'Gekommen', + 'Aktiv', + 'force_active', + 'Tshirt', + 'lastLogIn' + ); +} + +/** * Get all users, ordered by Nick by default or by given param. - * + * * @param string $order_by */ function Users($order_by = 'Nick') { diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 3a3f6712..35aa8f54 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -1,4 +1,5 @@ <?php + function myshifts_title() { return _("My shifts"); } @@ -64,7 +65,7 @@ function user_myshifts() { LIMIT 1"); engelsystem_log("Updated " . User_Nick_render($user_source) . "'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); success(_("Shift saved.")); - redirect(page_link_to('user_myshifts')); + redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']); } return ShiftEntry_edit_view(User_Nick_render($shifts_user), date("Y-m-d H:i", $shift['start']) . ', ' . shift_length($shift), $shift['Name'], $shift['name'], $shift['angel_type'], $shift['Comment'], $shift['freeloaded'], $shift['freeload_comment'], in_array("user_shifts_admin", $privileges)); diff --git a/includes/view/User_view.php b/includes/view/User_view.php index a866439d..912579e7 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -21,6 +21,7 @@ $tshirt_sizes = array( function Users_view($users, $order_by, $arrived_count, $active_count, $force_active_count, $freeloads_count, $tshirts_count) { foreach ($users as &$user) { + $user['Nick'] = User_Nick_render($user); $user['Gekommen'] = glyph_bool($user['Gekommen']); $user['Aktiv'] = glyph_bool($user['Aktiv']); $user['force_active'] = glyph_bool($user['force_active']); |