diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/controller/angeltypes_controller.php | 2 | ||||
-rw-r--r-- | includes/controller/users_controller.php | 41 | ||||
-rw-r--r-- | includes/model/User_model.php | 10 | ||||
-rw-r--r-- | includes/pages/admin_user.php | 88 | ||||
-rw-r--r-- | includes/sys_template.php | 24 | ||||
-rw-r--r-- | includes/view/User_view.php | 47 |
6 files changed, 125 insertions, 87 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 93c0e6bf..79ffcfb4 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -225,7 +225,7 @@ function angeltypes_list_controller() { $angeltype['restricted'] = $angeltype['restricted'] ? '<img src="pic/icons/lock.png" alt="' . _("Restricted") . '" title="' . _("Restricted") . '">' : ''; $angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>'; - $angeltype['actions'] = buttons($actions); + $angeltype['actions'] = table_buttons($actions); } return array( diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 1f3b3677..b1692e21 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -55,7 +55,46 @@ function user_controller() { } function users_list_controller() { - redirect(page_link_to('admin_user')); + global $privileges; + + if (! in_array('admin_user', $privileges)) + 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' + ))) + $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"); + + return array( + _('All users'), + Users_view($users, $order_by, $arrived_count, $active_count, $force_active_count, $freeloads_count, $tshirts_count) + ); } /** diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 7d2809f7..af4c4a97 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -1,9 +1,19 @@ <?php + /** * User model */ /** + * Get all users, ordered by Nick by default or by given param. + * + * @param string $order_by + */ +function Users($order_by = 'Nick') { + return sql_select("SELECT * FROM `User` ORDER BY `" . sql_escape($order_by) . "` ASC"); +} + +/** * Returns true if user is freeloader * * @param User $user diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index 9bce56c8..26bf18b5 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -12,7 +12,6 @@ function admin_user() { if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['id']) && sql_num_query("SELECT * FROM `User` WHERE `UID`=" . sql_escape($_REQUEST['id'])) > 0) { $id = $_REQUEST['id']; if (! isset($_REQUEST['action'])) { - $html .= '<h1>' . _('Edit user') . '</h1>'; $html .= "Hallo,<br />" . "hier kannst du den Eintrag ändern. Unter dem Punkt 'Gekommen' " . "wird der Engel als anwesend markiert, ein Ja bei Aktiv bedeutet, " . "dass der Engel aktiv war und damit ein Anspruch auf ein T-Shirt hat. " . "Wenn T-Shirt ein 'Ja' enthält, bedeutet dies, dass der Engel " . "bereits sein T-Shirt erhalten hat.<br /><br />\n"; $html .= "<form action=\"" . page_link_to("admin_user") . "&action=save&id=$id\" method=\"post\">\n"; @@ -265,90 +264,11 @@ function admin_user() { } } } else { - // Userliste, keine UID uebergeben... - $html .= '<h1>' . _('All users') . '</h1>'; - - $html .= "<a href=\"" . page_link_to("register") . "\">Neuen Engel eintragen »</a><br /><br />\n"; - - if (! isset($_GET["OrderBy"])) - $_GET["OrderBy"] = "Nick"; - $SQL = "SELECT * FROM `User` ORDER BY `" . sql_escape($_GET["OrderBy"]) . "` ASC"; - $angels = sql_select($SQL); - - function prepare_angel_table($angel) { - global $privileges; - $groups = sql_select_single_col("SELECT `Name` FROM `UserGroups` JOIN `Groups` ON (`Groups`.`UID` = `UserGroups`.`group_id`) WHERE `UserGroups`.`uid`=" . sql_escape($angel["UID"]) . " ORDER BY `Groups`.`Name`"); - $angeltypes = sql_select_single_col(" - SELECT `AngelTypes`.`name` - FROM `UserAngelTypes` - JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id`) - WHERE `user_id`=" . sql_escape($angel['UID'])); - $popup = '<div class="hidden">'; - $popup .= _("Angeltypes") . ': ' . implode(', ', $angeltypes); - $popup .= '<br />' . _("Groups") . ': ' . implode(', ', $groups); - if (strlen($angel["Telefon"]) > 0) - $popup .= "<br>Tel: " . $angel["Telefon"]; - if (strlen($angel["Handy"]) > 0) - $popup .= "<br>Handy: " . $angel["Handy"]; - if (strlen($angel["DECT"]) > 0) - $popup .= "<br>DECT: " . $angel["DECT"]; - if (strlen($angel["Hometown"]) > 0) - $popup .= "<br>Hometown: " . $angel["Hometown"]; - if (strlen($angel["CreateDate"]) > 0) - $popup .= "<br>Registered: " . $angel["CreateDate"]; - if (strlen($angel["Art"]) > 0) - $popup .= "<br>Type: " . $angel["Art"]; - if (strlen($angel["ICQ"]) > 0) - $popup .= "<br>ICQ: " . $angel["ICQ"]; - if (strlen($angel["jabber"]) > 0) - $popup .= "<br>Jabber: " . $angel["jabber"]; - return array( - 'Nick' => User_Nick_render($angel), - 'Name' => htmlspecialchars($angel['Vorname'] . ' ' . $angel['Name']) . $popup, - 'DECT' => htmlspecialchars($angel['DECT']), - 'Gekommen' => '<img src="pic/icons/' . ($angel['Gekommen'] == 1 ? 'tick' : 'cross') . '.png" alt="' . $angel['Gekommen'] . '">', - 'freeloads' => sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1 AND `UID` = " . sql_escape($angel['UID'])), - 'Aktiv' => '<img src="pic/icons/' . ($angel['Aktiv'] == 1 ? 'tick' : 'cross') . '.png" alt="' . $angel['Aktiv'] . '">', - 'force_active' => '<img src="pic/icons/' . ($angel['force_active'] == 1 ? 'tick' : 'cross') . '.png" alt="' . $angel['force_active'] . '">', - 'Tshirt' => '<img src="pic/icons/' . ($angel['Tshirt'] == 1 ? 'tick' : 'cross') . '.png" alt="' . $angel['Tshirt'] . '">', - 'Size' => $angel['Size'], - 'lastLogIn' => date('d.m.&\n\b\s\p;H:i', $angel['lastLogIn']), - 'edit' => img_button(page_link_to('admin_user') . '&id=' . $angel['UID'], 'pencil', _("edit")) - ); - } - $angels = array_map('prepare_angel_table', $angels); - $Gekommen = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1"); - $Active = 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"); - $Tshirt = sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1"); - $angels[] = array( - 'Nick' => '<strong>Summe</strong>', - 'Gekommen' => $Gekommen, - 'Aktiv' => $Active, - 'force_active' => $force_active_count, - 'freeloads' => $freeloads_count, - 'Tshirt' => $Tshirt , - 'edit' => '<strong>' . count($angels) . '</strong>' - ); - $html .= table(array( - 'Nick' => '<a href="' . page_link_to("admin_user") . '&OrderBy=Nick">Nick</a>', - 'Name' => '<a href="' . page_link_to("admin_user") . '&OrderBy=Vorname">Vorname</a> <a href="' . page_link_to("admin_user") . '&OrderBy=Name">Name</a>', - 'DECT' => '<a href="' . page_link_to("admin_user") . '&OrderBy=DECT">DECT</a>', - 'Gekommen' => '<div class="rotate"><a href="' . page_link_to("admin_user") . '&OrderBy=Gekommen">Gekommen</a></div>', - 'freeloads' => '<div class="rotate">' . _("Freeloads") . '</div>', - 'Aktiv' => '<div class="rotate"><a href="' . page_link_to("admin_user") . '&OrderBy=Aktiv">Aktiv</a></div>', - 'force_active' => '<div class="rotate"><a href="' . page_link_to("admin_user") . '&OrderBy=force_active">' . _("Forced") . '</a></div>', - 'Tshirt' => '<div class="rotate"><a href="' . page_link_to("admin_user") . '&OrderBy=Tshirt">T-Shirt</a></div>', - 'Size' => '<div class="rotate"><a href="' . page_link_to("admin_user") . '&OrderBy=Size">Größe</a></div>', - 'lastLogIn' => '<a href="' . page_link_to("admin_user") . '&OrderBy=lastLogIn">Last login</a>', - 'edit' => '' - ), $angels); + redirect(page_link_to('users')); } - return page(array( - '<div class="col-md-12">', - $html, - '</div>' + + return page_with_title(_('Edit user'), array( + $html )); } ?> diff --git a/includes/sys_template.php b/includes/sys_template.php index aaa79993..bf0e81fc 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -8,6 +8,24 @@ $themes = array( "1" => "Engelsystem dark" ); +/** + * Render glyphicon + * + * @param string $glyph_name + */ +function glyph($glyph_name) { + return ' <span class="glyphicon glyphicon-' . $glyph_name . '"></span> '; +} + +/** + * Renders a tick or a cross by given boolean + * + * @param boolean $boolean + */ +function glyph_bool($boolean) { + return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>'; +} + function div($class, $content = array(), $id = "") { $id = $id != '' ? ' id="' . $id . '"' : ''; return '<div' . $id . ' class="' . $class . '">' . join("\n", $content) . '</div>'; @@ -292,7 +310,11 @@ function button($href, $label, $class = "") { * Rendert eine Toolbar mit Knöpfen */ function buttons($buttons = array ()) { - return '<div class="form-group"><div class="btn-group">' . join(' ', $buttons) . '</div></div>'; + return '<div class="form-group">' . table_buttons($buttons) . '</div>'; +} + +function table_buttons($buttons = array()) { + return '<div class="btn-group">' . join(' ', $buttons) . '</div>'; } // Load and render template diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 4c783644..a866439d 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -19,6 +19,53 @@ $tshirt_sizes = array( 'XL-G' => "XL Girl" ); +function Users_view($users, $order_by, $arrived_count, $active_count, $force_active_count, $freeloads_count, $tshirts_count) { + foreach ($users as &$user) { + $user['Gekommen'] = glyph_bool($user['Gekommen']); + $user['Aktiv'] = glyph_bool($user['Aktiv']); + $user['force_active'] = glyph_bool($user['force_active']); + $user['Tshirt'] = glyph_bool($user['Tshirt']); + $user['lastLogIn'] = date(_('m/d/Y h:i a'), $user['lastLogIn']); + $user['actions'] = table_buttons(array( + button(page_link_to('admin_user') . '&id=' . $user['UID'], _('edit'), 'btn-xs') + )); + } + $users[] = array( + 'Nick' => '<strong>' . _('Sum') . '</strong>', + 'Gekommen' => $arrived_count, + 'Aktiv' => $active_count, + 'force_active' => $force_active_count, + 'freeloads' => $freeloads_count, + 'Tshirt' => $tshirts_count, + 'actions' => '<strong>' . count($users) . '</strong>' + ); + + return page_with_title(_('All users'), array( + msg(), + buttons(array( + button(page_link_to('register'), glyph('plus') . _('New user')) + )), + table(array( + 'Nick' => Users_table_header_link('Nick', _('Nick'), $order_by), + 'Vorname' => Users_table_header_link('Vorname', _('Prename'), $order_by), + 'Name' => Users_table_header_link('Name', _('Name'), $order_by), + 'DECT' => Users_table_header_link('DECT', _('DECT'), $order_by), + 'Gekommen' => Users_table_header_link('Gekommen', _('Arrived'), $order_by), + 'freeloads' => _('Freeloads'), + 'Aktiv' => Users_table_header_link('Aktiv', _('Active'), $order_by), + 'force_active' => Users_table_header_link('force_active', _('Forced'), $order_by), + 'Tshirt' => Users_table_header_link('Tshirt', _('T-Shirt'), $order_by), + 'Size' => Users_table_header_link('Size', _('Size'), $order_by), + 'lastLogIn' => Users_table_header_link('lastLogIn', _('Last login'), $order_by), + 'actions' => '' + ), $users) + )); +} + +function Users_table_header_link($column, $label, $order_by) { + return '<a href="' . page_link_to('users') . '&OrderBy=' . $column . '">' . $label . ($order_by == $column ? ' <span class="caret"></span>' : '') . '</a>'; +} + function User_shift_state_render($user) { $upcoming_shifts = ShiftEntries_upcoming_for_user($user); if ($upcoming_shifts === false) |