summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2015-08-12 23:44:39 +0200
committerPhilip Häusler <msquare@notrademark.de>2015-08-12 23:44:39 +0200
commit803c0a552f2bf3eaab1a88efa3785a985a258277 (patch)
tree6d759a47170cf2e0fe51f9de5b35d2ce85845b3c /includes
parent681d52fe0f8a124904f97e7966ed2ee1b73124d2 (diff)
make multiple vouchers possible
Diffstat (limited to 'includes')
-rw-r--r--includes/controller/users_controller.php47
-rw-r--r--includes/model/User_model.php4
-rw-r--r--includes/view/User_view.php25
3 files changed, 51 insertions, 25 deletions
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index 7810ce77..067fc4aa 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -22,8 +22,8 @@ function users_controller() {
return user_edit_controller();
case 'delete':
return user_delete_controller();
- case 'got_voucher':
- return user_got_voucher_controller();
+ case 'edit_vouchers':
+ return user_edit_vouchers_controller();
}
}
@@ -35,7 +35,7 @@ function user_link($user) {
return page_link_to('users') . '&action=view&user_id=' . $user['UID'];
}
-function user_got_voucher_controller() {
+function user_edit_vouchers_controller() {
global $privileges, $user;
if (isset($_REQUEST['user_id'])) {
@@ -43,24 +43,37 @@ function user_got_voucher_controller() {
} else
$user_source = $user;
- $admin_user_privilege = in_array('admin_user', $privileges);
-
if (! in_array('admin_user', $privileges))
redirect(page_link_to(''));
- if (! isset($_REQUEST['got_voucher']))
- redirect(page_link_to(''));
-
- $user_source['got_voucher'] = $_REQUEST['got_voucher'] == 'true';
-
- $result = User_update($user_source);
- if ($result === false)
- engelsystem_error('Unable to update user.');
-
- success($user_source['got_voucher'] ? _('User got vouchers.') : _('User didnt got vouchers.'));
- engelsystem_log(User_Nick_render($user_source) . ($user_source['got_voucher'] ? ' got vouchers' : ' didnt got vouchers'));
+ if (isset($_REQUEST['submit'])) {
+ $ok = true;
+
+ if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0)
+ $vouchers = trim($_REQUEST['vouchers']);
+ else {
+ $ok = false;
+ error(_("Please enter a valid number of vouchers."));
+ }
+
+ if ($ok) {
+ $user_source['got_voucher'] = $vouchers;
+
+ $result = User_update($user_source);
+ if ($result === false)
+ engelsystem_error('Unable to update user.');
+
+ success(_("Saved the number of vouchers."));
+ engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf("Got %s vouchers", $user_source['got_voucher']));
+
+ redirect(user_link($user_source));
+ }
+ }
- redirect(user_link($user_source));
+ return array(
+ sprintf(_("%s's vouchers"), $user_source['Nick']),
+ User_edit_vouchers_view($user_source)
+ );
}
function user_controller() {
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index f1c3d34b..bd3ec31f 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -29,7 +29,7 @@ function User_update($user) {
`color`='" . sql_escape($user['color']) . "',
`Sprache`='" . sql_escape($user['Sprache']) . "',
`Hometown`='" . sql_escape($user['Hometown']) . "',
- `got_voucher`=" . sql_bool($user['got_voucher']) . ",
+ `got_voucher`='" . sql_escape($user['got_voucher']) . "',
`arrival_date`='" . sql_escape($user['arrival_date']) . "',
`planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "'
WHERE `UID`='" . sql_escape($user['UID']) . "'");
@@ -47,7 +47,7 @@ function User_active_count() {
}
function User_got_voucher_count() {
- return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `got_voucher` = TRUE");
+ return sql_select_single_cell("SELECT SUM(`got_voucher`) FROM `User`");
}
function User_arrived_count() {
diff --git a/includes/view/User_view.php b/includes/view/User_view.php
index 0125f4af..b3b33950 100644
--- a/includes/view/User_view.php
+++ b/includes/view/User_view.php
@@ -19,6 +19,22 @@ $tshirt_sizes = array(
'XL-G' => "XL Girl"
);
+/**
+ * View for editing the number of given vouchers
+ */
+function User_edit_vouchers_view($user) {
+ return page_with_title(sprintf(_("%s's vouchers"), User_Nick_render($user)), [
+ msg(),
+ buttons([
+ button(user_link($user), glyph('chevron-left') . _("back"))
+ ]),
+ form([
+ form_spinner('vouchers', _("Number of vouchers"), $user['got_voucher']),
+ form_submit('submit', _("Save"))
+ ], page_link_to('users') . '&action=edit_vouchers&user_id=' . $user['UID'])
+ ]);
+}
+
function Users_view($users, $order_by, $arrived_count, $active_count, $force_active_count, $freeloads_count, $tshirts_count, $voucher_count) {
foreach ($users as &$user) {
$user['Nick'] = User_Nick_render($user);
@@ -171,10 +187,8 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
'<h4>' . _("User state") . '</h4>',
($admin_user_privilege && $freeloader) ? '<span class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> ' . _("Freeloader") . '</span><br />' : '',
$user_source['Gekommen'] ? User_shift_state_render($user_source) . '<br />' : '',
- $admin_user_privilege || $its_me
- ? ($user_source['Gekommen'] ? '<span class="text-success"><span class="glyphicon glyphicon-home"></span> ' . sprintf(_("Arrived at %s"), date('Y-m-d', $user_source['arrival_date'])) . '</span>' : '<span class="text-danger">' . sprintf(_("Not arrived (Planned: %s)"), date('Y-m-d', $user_source['planned_arrival_date'])) . '</span>')
- : ($user_source['Gekommen'] ? '<span class="text-success"><span class="glyphicon glyphicon-home"></span> ' . _("Arrived") . '</span>' : '<span class="text-danger">' . _("Not arrived") . '</span>'),
- $admin_user_privilege ? ($user_source['got_voucher'] ? '<br /><span class="text-success">' . glyph('cutlery') . _("Got vouchers") . '</span>' : '<br /><span class="text-danger">' . _("Got no vouchers") . '</span>') : '',
+ $admin_user_privilege || $its_me ? ($user_source['Gekommen'] ? '<span class="text-success"><span class="glyphicon glyphicon-home"></span> ' . sprintf(_("Arrived at %s"), date('Y-m-d', $user_source['arrival_date'])) . '</span>' : '<span class="text-danger">' . sprintf(_("Not arrived (Planned: %s)"), date('Y-m-d', $user_source['planned_arrival_date'])) . '</span>') : ($user_source['Gekommen'] ? '<span class="text-success"><span class="glyphicon glyphicon-home"></span> ' . _("Arrived") . '</span>' : '<span class="text-danger">' . _("Not arrived") . '</span>'),
+ $admin_user_privilege ? ($user_source['got_voucher'] > 0 ? '<br /><span class="text-success">' . glyph('cutlery') . sprintf(ngettext("Got %s voucher", "Got %s vouchers", $user_source['got_voucher']), $user_source['got_voucher']) . '</span>' : '<br /><span class="text-danger">' . _("Got no vouchers") . '</span>') : '',
($user_source['Gekommen'] && $admin_user_privilege && $user_source['Aktiv']) ? ' <span class="text-success">' . _("Active") . '</span>' : '',
($user_source['Gekommen'] && $admin_user_privilege && $user_source['Tshirt']) ? ' <span class="text-success">' . _("T-Shirt") . '</span>' : ''
)),
@@ -192,8 +206,7 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
buttons(array(
$admin_user_privilege ? button(page_link_to('admin_user') . '&id=' . $user_source['UID'], glyph("edit") . _("edit")) : '',
($admin_user_privilege && ! $user_source['Gekommen']) ? button(page_link_to('admin_arrive') . '&arrived=' . $user_source['UID'], _("arrived")) : '',
- ($admin_user_privilege && ! $user_source['got_voucher']) ? button(page_link_to('users') . '&action=got_voucher&user_id=' . $user_source['UID'] . '&got_voucher=true', _('Got vouchers')) : '',
- ($admin_user_privilege && $user_source['got_voucher']) ? button(page_link_to('users') . '&action=got_voucher&user_id=' . $user_source['UID'] . '&got_voucher=', _('Remove vouchers')) : '',
+ $admin_user_privilege ? button(page_link_to('users') . '&action=edit_vouchers&user_id=' . $user_source['UID'], glyph('cutlery') . _('Edit vouchers')) : '',
$its_me ? button(page_link_to('user_settings'), glyph('list-alt') . _("Settings")) : '',
$its_me ? button(page_link_to('ical') . '&key=' . $user_source['api_key'], glyph('calendar') . _("iCal Export")) : '',
$its_me ? button(page_link_to('shifts_json_export') . '&key=' . $user_source['api_key'], glyph('export') . _("JSON Export")) : '',