#198 fixed: driving license feature completed - integrated into angeltypes

This commit is contained in:
Philip Häusler 2015-12-20 11:36:12 +01:00
parent 2cb44fe517
commit 0ac05d251c
8 changed files with 115 additions and 40 deletions

View File

@ -11,3 +11,5 @@ CREATE TABLE IF NOT EXISTS `UserDriverLicenses` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `UserDriverLicenses` ALTER TABLE `UserDriverLicenses`
ADD CONSTRAINT `userdriverlicenses_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE; ADD CONSTRAINT `userdriverlicenses_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `AngelTypes` ADD `requires_driver_license` BOOLEAN NOT NULL;

View File

@ -97,6 +97,7 @@ function angeltype_edit_controller() {
$name = ""; $name = "";
$restricted = false; $restricted = false;
$description = ""; $description = "";
$requires_driver_license = false;
if (isset($_REQUEST['angeltype_id'])) { if (isset($_REQUEST['angeltype_id'])) {
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
@ -108,6 +109,7 @@ function angeltype_edit_controller() {
$name = $angeltype['name']; $name = $angeltype['name'];
$restricted = $angeltype['restricted']; $restricted = $angeltype['restricted'];
$description = $angeltype['description']; $description = $angeltype['description'];
$requires_driver_license = $angeltype['requires_driver_license'];
if (! User_is_AngelType_coordinator($user, $angeltype)) if (! User_is_AngelType_coordinator($user, $angeltype))
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
@ -132,6 +134,7 @@ function angeltype_edit_controller() {
} }
$restricted = isset($_REQUEST['restricted']); $restricted = isset($_REQUEST['restricted']);
$requires_driver_license = isset($_REQUEST['requires_driver_license']);
} }
if (isset($_REQUEST['description'])) if (isset($_REQUEST['description']))
@ -140,26 +143,26 @@ function angeltype_edit_controller() {
if ($ok) { if ($ok) {
$restricted = $restricted ? 1 : 0; $restricted = $restricted ? 1 : 0;
if (isset($angeltype)) { if (isset($angeltype)) {
$result = AngelType_update($angeltype['id'], $name, $restricted, $description); $result = AngelType_update($angeltype['id'], $name, $restricted, $description, $requires_driver_license);
if ($result === false) if ($result === false)
engelsystem_error("Unable to update angeltype."); engelsystem_error("Unable to update angeltype.");
engelsystem_log("Updated angeltype: " . $name . ", restricted: " . $restricted); engelsystem_log("Updated angeltype: " . $name . ($restricted ? ", restricted" : "") . ($requires_driver_license ? ", requires driver license" : ""));
$angeltype_id = $angeltype['id']; $angeltype_id = $angeltype['id'];
} else { } else {
$angeltype_id = AngelType_create($name, $restricted, $description); $angeltype_id = AngelType_create($name, $restricted, $description, $requires_driver_license);
if ($angeltype_id === false) if ($angeltype_id === false)
engelsystem_error("Unable to create angeltype."); engelsystem_error("Unable to create angeltype.");
engelsystem_log("Created angeltype: " . $name . ", restricted: " . $restricted); engelsystem_log("Created angeltype: " . $name . ($restricted ? ", restricted" : "") . ($requires_driver_license ? ", requires driver license" : ""));
} }
success("Angel type saved."); success("Angel type saved.");
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id); redirect(angeltype_link($angeltype_id));
} }
} }
return array( return array(
sprintf(_("Edit %s"), $name), sprintf(_("Edit %s"), $name),
AngelType_edit_view($name, $restricted, $description, $coordinator_mode) AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license)
); );
} }
@ -185,13 +188,17 @@ function angeltype_controller() {
if ($user_angeltype === false) if ($user_angeltype === false)
engelsystem_error("Unable to load user angeltype."); engelsystem_error("Unable to load user angeltype.");
$user_driver_license = UserDriverLicense($user['UID']);
if ($user_driver_license === false)
engelsystem_error("Unable to load user driver license.");
$members = Users_by_angeltype($angeltype); $members = Users_by_angeltype($angeltype);
if ($members === false) if ($members === false)
engelsystem_error("Unable to load members."); engelsystem_error("Unable to load members.");
return array( return array(
sprintf(_("Team %s"), $angeltype['name']), sprintf(_("Team %s"), $angeltype['name']),
AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges), $user_angeltype['coordinator']) AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges), $user_angeltype['coordinator'], $user_driver_license, $user)
); );
} }

View File

@ -1,5 +1,31 @@
<?php <?php
/**
* Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license information provided.
*/
function user_driver_license_required_hint() {
global $user;
$angeltypes = User_angeltypes($user);
if ($angeltypes === false)
engelsystem_error("Unable to load user angeltypes.");
$user_driver_license = UserDriverLicense($user['UID']);
if ($user_driver_license === false)
engelsystem_error("Unable to load user driver license.");
$driving_license_information_required = false;
foreach ($angeltypes as $angeltype)
if ($angeltype['requires_driver_license']) {
$driving_license_information_required = true;
break;
}
if ($driving_license_information_required && $user_driver_license == null)
return info(sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '<a href="' . user_driver_license_edit_link() . '">' . _("driving license information") . '</a>'), true);
return '';
}
/** /**
* Route user driver licenses actions. * Route user driver licenses actions.
*/ */

View File

@ -17,15 +17,17 @@ function AngelType_delete($angeltype) {
* *
* @param int $angeltype_id * @param int $angeltype_id
* @param string $name * @param string $name
* @param boolean $restricted * @param bool $restricted
* @param string $description * @param string $description
* @param bool $requires_driver_license
*/ */
function AngelType_update($angeltype_id, $name, $restricted, $description) { function AngelType_update($angeltype_id, $name, $restricted, $description, $requires_driver_license) {
return sql_query(" return sql_query("
UPDATE `AngelTypes` SET UPDATE `AngelTypes` SET
`name`='" . sql_escape($name) . "', `name`='" . sql_escape($name) . "',
`restricted`='" . sql_escape($restricted ? 1 : 0) . "', `restricted`=" . sql_bool($restricted) . ",
`description`='" . sql_escape($description) . "' `description`='" . sql_escape($description) . "',
`requires_driver_license`=" . sql_bool($requires_driver_license) . "
WHERE `id`='" . sql_escape($angeltype_id) . "' WHERE `id`='" . sql_escape($angeltype_id) . "'
LIMIT 1"); LIMIT 1");
} }
@ -38,12 +40,13 @@ function AngelType_update($angeltype_id, $name, $restricted, $description) {
* @param string $description * @param string $description
* @return New Angeltype id * @return New Angeltype id
*/ */
function AngelType_create($name, $restricted, $description) { function AngelType_create($name, $restricted, $description, $requires_driver_license) {
$result = sql_query(" $result = sql_query("
INSERT INTO `AngelTypes` SET INSERT INTO `AngelTypes` SET
`name`='" . sql_escape($name) . "', `name`='" . sql_escape($name) . "',
`restricted`='" . sql_escape($restricted ? 1 : 0) . "', `restricted`=" . sql_bool($restricted) . ",
`description`='" . sql_escape($description) . "'"); `description`='" . sql_escape($description) . "',
`requires_driver_license`=" . sql_bool($requires_driver_license));
if ($result === false) if ($result === false)
return false; return false;
return sql_id(); return sql_id();

View File

@ -1,8 +1,14 @@
<?php <?php
/** /**
* User angeltypes model * User angeltypes model
*/ */
/**
* List users angeltypes.
*
* @param User $user
*/
function User_angeltypes($user) { function User_angeltypes($user) {
return sql_select(" return sql_select("
SELECT `AngelTypes`.*, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`coordinator` SELECT `AngelTypes`.*, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`coordinator`

View File

@ -123,9 +123,11 @@ function Users_by_angeltype($angeltype) {
`User`.*, `User`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`, `UserAngelTypes`.`id` as `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`confirm_user_id`,
`UserAngelTypes`.`coordinator` `UserAngelTypes`.`coordinator`,
`UserDriverLicenses`.*
FROM `User` FROM `User`
JOIN `UserAngelTypes` ON `User`.`UID`=`UserAngelTypes`.`user_id` JOIN `UserAngelTypes` ON `User`.`UID`=`UserAngelTypes`.`user_id`
LEFT JOIN `UserDriverLicenses` ON `User`.`UID`=`UserDriverLicenses`.`user_id`
WHERE `UserAngelTypes`.`angeltype_id`='" . sql_escape($angeltype['id']) . "' WHERE `UserAngelTypes`.`angeltype_id`='" . sql_escape($angeltype['id']) . "'
ORDER BY `Nick`"); ORDER BY `Nick`");
} }

View File

@ -48,6 +48,10 @@ function header_toolbar() {
if (! isset($user['planned_departure_date']) || $user['planned_departure_date'] == null) if (! isset($user['planned_departure_date']) || $user['planned_departure_date'] == null)
$hints[] = info(_("Please enter your planned date of departure on your settings page to give us a feeling for teardown capacities."), true); $hints[] = info(_("Please enter your planned date of departure on your settings page to give us a feeling for teardown capacities."), true);
$driver_license_required = user_driver_license_required_hint();
if ($driver_license_required != '')
$hints[] = $driver_license_required;
if (User_is_freeloader($user)) { if (User_is_freeloader($user)) {
$hints[] = error(sprintf(_("You freeloaded at least %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again."), $max_freeloadable_shifts), true); $hints[] = error(sprintf(_("You freeloaded at least %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again."), $max_freeloadable_shifts), true);
$hint_class = 'danger'; $hint_class = 'danger';

View File

@ -50,7 +50,7 @@ function AngelType_delete_view($angeltype) {
)); ));
} }
function AngelType_edit_view($name, $restricted, $description, $coordinator_mode) { function AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license) {
return page_with_title(sprintf(_("Edit %s"), $name), array( return page_with_title(sprintf(_("Edit %s"), $name), array(
buttons(array( buttons(array(
button(page_link_to('angeltypes'), _("Angeltypes"), 'back') button(page_link_to('angeltypes'), _("Angeltypes"), 'back')
@ -59,6 +59,7 @@ function AngelType_edit_view($name, $restricted, $description, $coordinator_mode
form(array( form(array(
$coordinator_mode ? form_info(_("Name"), $name) : form_text('name', _("Name"), $name), $coordinator_mode ? form_info(_("Name"), $name) : form_text('name', _("Name"), $name),
$coordinator_mode ? form_info(_("Restricted"), $restricted ? _("Yes") : _("No")) : form_checkbox('restricted', _("Restricted"), $restricted), $coordinator_mode ? form_info(_("Restricted"), $restricted ? _("Yes") : _("No")) : form_checkbox('restricted', _("Restricted"), $restricted),
$coordinator_mode ? form_info(_("Requires driver license"), $requires_driver_license ? _("Yes") : _("No")) : form_checkbox('requires_driver_license', _("Requires driver license"), $requires_driver_license),
form_info("", _("Restricted angel types can only be used by an angel if enabled by an archangel (double opt-in).")), form_info("", _("Restricted angel types can only be used by an angel if enabled by an archangel (double opt-in).")),
form_textarea('description', _("Description"), $description), form_textarea('description', _("Description"), $description),
form_info("", _("Please use markdown for the description.")), form_info("", _("Please use markdown for the description.")),
@ -67,14 +68,20 @@ function AngelType_edit_view($name, $restricted, $description, $coordinator_mode
)); ));
} }
function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angeltypes, $admin_angeltypes, $coordinator) { function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angeltypes, $admin_angeltypes, $coordinator, $user_driver_license, $user) {
$buttons = array( $buttons = [
button(page_link_to('angeltypes'), _("Angeltypes"), 'back') button(page_link_to('angeltypes'), _("Angeltypes"), 'back')
); ];
if ($angeltype['requires_driver_license'])
$buttons[] = button(user_driver_license_edit_link($user), glyph("road") . _("my driving license"));
if ($user_angeltype == null) if ($user_angeltype == null)
$buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add'); $buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add');
else { else {
if ($angeltype['requires_driver_license'] && $user_driver_license == null)
error(_("This angeltype requires a driver license. Please enter your driver license information!"));
if ($angeltype['restricted'] && $user_angeltype['confirm_user_id'] == null) if ($angeltype['restricted'] && $user_angeltype['confirm_user_id'] == null)
error(sprintf(_("You are unconfirmed for this angeltype. Please go to the introduction for %s to get confirmed."), $angeltype['name'])); error(sprintf(_("You are unconfirmed for this angeltype. Please go to the introduction for %s to get confirmed."), $angeltype['name']));
$buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $user_angeltype['id'], _("leave"), 'cancel'); $buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $user_angeltype['id'], _("leave"), 'cancel');
@ -95,13 +102,22 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
if ($angeltype['description'] != "") if ($angeltype['description'] != "")
$page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>'; $page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
// Team-Coordinators list missing
$coordinators = array(); $coordinators = array();
$members_confirmed = array(); $members_confirmed = array();
$members_unconfirmed = array(); $members_unconfirmed = array();
foreach ($members as $member) { foreach ($members as $member) {
$member['Nick'] = User_Nick_render($member); $member['Nick'] = User_Nick_render($member);
if ($angeltype['requires_driver_license']) {
$member['wants_to_drive'] = glyph_bool($member['user_id']);
$member['has_car'] = glyph_bool($member['has_car']);
$member['has_license_car'] = glyph_bool($member['has_license_car']);
$member['has_license_3_5t_transporter'] = glyph_bool($member['has_license_3_5t_transporter']);
$member['has_license_7_5t_truck'] = glyph_bool($member['has_license_7_5t_truck']);
$member['has_license_12_5t_truck'] = glyph_bool($member['has_license_12_5t_truck']);
$member['has_license_forklift'] = glyph_bool($member['has_license_forklift']);
}
if ($angeltype['restricted'] && $member['confirm_user_id'] == null) { if ($angeltype['restricted'] && $member['confirm_user_id'] == null) {
$member['actions'] = table_buttons([ $member['actions'] = table_buttons([
button(page_link_to('user_angeltypes') . '&action=confirm&user_angeltype_id=' . $member['user_angeltype_id'], _("confirm"), 'btn-xs'), button(page_link_to('user_angeltypes') . '&action=confirm&user_angeltype_id=' . $member['user_angeltype_id'], _("confirm"), 'btn-xs'),
@ -125,13 +141,30 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
$members_confirmed[] = $member; $members_confirmed[] = $member;
} }
} }
if (count($coordinators) > 0) {
$page[] = '<h3>' . _("Coordinators") . '</h3>'; $table_headers = [
$page[] = table(array( 'Nick' => _("Nick"),
'DECT' => _("DECT"),
'actions' => ''
];
if ($angeltype['requires_driver_license'] && ($coordinator || $admin_angeltypes))
$table_headers = [
'Nick' => _("Nick"), 'Nick' => _("Nick"),
'DECT' => _("DECT"), 'DECT' => _("DECT"),
'actions' => "" 'wants_to_drive' => _("Driver"),
), $coordinators); 'has_car' => _("Has car"),
'has_license_car' => _("Car"),
'has_license_3_5t_transporter' => _("3,5t Transporter"),
'has_license_7_5t_truck' => _("7,5t Truck"),
'has_license_12_5t_truck' => _("12,5t Truck"),
'has_license_forklift' => _("Forklift"),
'actions' => ''
];
if (count($coordinators) > 0) {
$page[] = '<h3>' . _("Coordinators") . '</h3>';
$page[] = table($table_headers, $coordinators);
} }
if (count($members_confirmed) > 0) if (count($members_confirmed) > 0)
@ -150,26 +183,18 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
$page[] = '<h3>' . _("Members") . '</h3>'; $page[] = '<h3>' . _("Members") . '</h3>';
if ($admin_user_angeltypes) if ($admin_user_angeltypes)
$page[] = buttons(array( $page[] = buttons([
button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("Add"), 'add') button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("Add"), 'add')
)); ]);
$page[] = table(array( $page[] = table($table_headers, $members_confirmed);
'Nick' => _("Nick"),
'DECT' => _("DECT"),
'actions' => ""
), $members_confirmed);
if ($admin_user_angeltypes && $angeltype['restricted'] && count($members_unconfirmed) > 0) { if ($admin_user_angeltypes && $angeltype['restricted'] && count($members_unconfirmed) > 0) {
$page[] = '<h3>' . _("Unconfirmed") . '</h3>'; $page[] = '<h3>' . _("Unconfirmed") . '</h3>';
$page[] = buttons(array( $page[] = buttons([
button(page_link_to('user_angeltypes') . '&action=confirm_all&angeltype_id=' . $angeltype['id'], _("confirm all"), 'ok'), button(page_link_to('user_angeltypes') . '&action=confirm_all&angeltype_id=' . $angeltype['id'], _("confirm all"), 'ok'),
button(page_link_to('user_angeltypes') . '&action=delete_all&angeltype_id=' . $angeltype['id'], _("deny all"), 'cancel') button(page_link_to('user_angeltypes') . '&action=delete_all&angeltype_id=' . $angeltype['id'], _("deny all"), 'cancel')
)); ]);
$page[] = table(array( $page[] = table($table_headers, $members_unconfirmed);
'Nick' => _("Nick"),
'DECT' => _("DECT"),
'actions' => ""
), $members_unconfirmed);
} }
return page_with_title(sprintf(_("Team %s"), $angeltype['name']), $page); return page_with_title(sprintf(_("Team %s"), $angeltype['name']), $page);