#198 add basic driver license information

main
Philip Häusler 9 years ago
parent dc4eb98caf
commit facc32f133

@ -0,0 +1,13 @@
-- drivers license information
CREATE TABLE IF NOT EXISTS `UserDriverLicenses` (
`user_id` int(11) NOT NULL,
`has_car` tinyint(1) NOT NULL,
`has_license_car` tinyint(1) NOT NULL,
`has_license_3_5t_transporter` tinyint(1) NOT NULL,
`has_license_7_5t_truck` tinyint(1) NOT NULL,
`has_license_12_5t_truck` tinyint(1) NOT NULL,
`has_license_forklift` tinyint(1) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `UserDriverLicenses`
ADD CONSTRAINT `userdriverlicenses_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE;

@ -202,24 +202,18 @@ function angeltypes_list_controller() {
foreach ($angeltypes as &$angeltype) {
$actions = array(
button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'],_("view"),"btn-xs")
//'<a class="view btn btn-default" href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . _("view") . '</a>'
);
if (in_array('admin_angel_types', $privileges)) {
$actions[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), "btn-xs");
$actions[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), "btn-xs");
//$actions[] = '<a class="edit" href="' . page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'] . '">' . _("edit") . '</a>';
//$actions[] = '<a class="delete" href="' . page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'] . '">' . _("delete") . '</a>';
}
$angeltype['membership'] = AngelType_render_membership($angeltype);
if ($angeltype['user_angeltype_id'] != null) {
//$actions[] = '<a class="cancel" href="' . page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'] . '">' . _("leave") . '</a>';
$actions[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), "btn-xs");
} else {
$actions[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), "btn-xs");
//$actions[] = '<a class="add" href="' . page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'] . '">' . _("join") . '</a>';
}
$angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : '';

@ -0,0 +1,118 @@
<?php
/**
* Route user driver licenses actions.
*/
function user_driver_licenses_controller() {
global $privileges, $user;
if (! isset($user))
redirect(page_link_to(''));
if (! isset($_REQUEST['action']))
$_REQUEST['action'] = 'edit';
switch ($_REQUEST['action']) {
default:
case 'edit':
return user_driver_license_edit_controller();
}
}
/**
* Link to user driver license edit page for given user.
*
* @param User $user
*/
function user_driver_license_edit_link($user = null) {
if ($user == null)
return page_link_to('user_driver_licenses');
return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID'];
}
/**
* Edit a users driver license information.
*/
function user_driver_license_edit_controller() {
global $privileges, $user;
if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']);
if ($user_source === false)
engelsystem_error('Unable to load angeltype.');
if ($user_source == null)
redirect(user_driver_license_edit_link());
// only privilege admin_user can edit other users driver license information
if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges))
redirect(user_driver_license_edit_link());
} else {
$user_source = $user;
}
$wants_to_drive = false;
$has_car = false;
$has_license_car = false;
$has_license_3_5t_transporter = false;
$has_license_7_5t_truck = false;
$has_license_12_5t_truck = false;
$has_license_forklift = false;
$user_driver_license = UserDriverLicense($user_source['UID']);
if ($user_driver_license === false)
engelsystem_error('Unable to load user driver license.');
if ($user_driver_license != null) {
$wants_to_drive = true;
$has_car = $user_driver_license['has_car'];
$has_license_car = $user_driver_license['has_license_car'];
$has_license_3_5t_transporter = $user_driver_license['has_license_3_5t_transporter'];
$has_license_7_5t_truck = $user_driver_license['has_license_7_5t_truck'];
$has_license_12_5t_truck = $user_driver_license['has_license_12_5t_truck'];
$has_license_forklift = $user_driver_license['has_license_forklift'];
}
if (isset($_REQUEST['submit'])) {
$ok = true;
$wants_to_drive = isset($_REQUEST['wants_to_drive']);
$has_car = isset($_REQUEST['has_car']);
$has_license_car = isset($_REQUEST['has_license_car']);
$has_license_3_5t_transporter = isset($_REQUEST['has_license_3_5t_transporter']);
$has_license_7_5t_truck = isset($_REQUEST['has_license_7_5t_truck']);
$has_license_12_5t_truck = isset($_REQUEST['has_license_12_5t_truck']);
$has_license_forklift = isset($_REQUEST['has_license_forklift']);
if ($wants_to_drive && ! $has_license_car && ! $has_license_3_5t_transporter && ! $has_license_7_5t_truck && ! $has_license_12_5t_truck && ! $has_license_forklift) {
$ok = false;
error(_("Please select at least one driving license."));
}
if ($ok) {
if (! $wants_to_drive && $user_driver_license != null) {
$result = UserDriverLicenses_delete($user_source['UID']);
if ($result === false)
engelsystem_error('Unable to remove user driver license information');
success(_("Your driver license information has been removed."));
} else {
if ($wants_to_drive) {
if ($user_driver_license == null)
$result = UserDriverLicenses_create($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift);
else
$result = UserDriverLicenses_update($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift);
if ($result === false)
engelsystem_error('Unable to save user driver license information.');
}
success(_("Your driver license information has been saved."));
}
redirect(user_link($user_source));
}
}
return [
sprintf(_("Edit %s driving license information"), $user_source['Nick']),
UserDriverLicense_edit_view($user_source, $wants_to_drive, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift)
];
}
?>

@ -19,6 +19,7 @@ require_once realpath(__DIR__ . '/../includes/model/ShiftEntry_model.php');
require_once realpath(__DIR__ . '/../includes/model/Shifts_model.php');
require_once realpath(__DIR__ . '/../includes/model/ShiftTypes_model.php');
require_once realpath(__DIR__ . '/../includes/model/UserAngelTypes_model.php');
require_once realpath(__DIR__ . '/../includes/model/UserDriverLicenses_model.php');
require_once realpath(__DIR__ . '/../includes/model/UserGroups_model.php');
require_once realpath(__DIR__ . '/../includes/model/User_model.php');
@ -29,6 +30,7 @@ require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php');
require_once realpath(__DIR__ . '/../includes/view/UserAngelTypes_view.php');
require_once realpath(__DIR__ . '/../includes/view/UserDriverLicenses_view.php');
require_once realpath(__DIR__ . '/../includes/view/User_view.php');
require_once realpath(__DIR__ . '/../includes/controller/angeltypes_controller.php');
@ -37,6 +39,7 @@ require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php')
require_once realpath(__DIR__ . '/../includes/controller/shifttypes_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/users_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/user_angeltypes_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/user_driver_licenses_controller.php');
require_once realpath(__DIR__ . '/../includes/helper/graph_helper.php');
require_once realpath(__DIR__ . '/../includes/helper/internationalization_helper.php');

@ -0,0 +1,69 @@
<?php
/**
* Get a users driver license information
* @param int $user_id The users id
*/
function UserDriverLicense($user_id) {
$user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
if ($user_driver_license === false)
return false;
if (count($user_driver_license) > 0)
return $user_driver_license[0];
return null;
}
/**
* Create a user's driver license entry
*
* @param bool $user_id
* @param bool $has_car
* @param bool $has_license_car
* @param bool $has_license_3_5t_transporter
* @param bool $has_license_7_5t_truck
* @param bool $has_license_12_5t_truck
* @param bool $has_license_forklift
*/
function UserDriverLicenses_create($user_id, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) {
return sql_query("
INSERT INTO `UserDriverLicenses` SET
`user_id`=" . sql_escape($user_id) . ",
`has_car`=" . sql_bool($has_car) . ",
`has_license_car`=" . sql_bool($has_license_car) . ",
`has_license_3_5t_transporter`=" . sql_bool($has_license_3_5t_transporter) . ",
`has_license_7_5t_truck`=" . sql_bool($has_license_7_5t_truck) . ",
`has_license_12_5t_truck`=" . sql_bool($has_license_12_5t_truck) . ",
`has_license_forklift`=" . sql_bool($has_license_forklift));
}
/**
* Update a user's driver license entry
*
* @param bool $user_id
* @param bool $has_car
* @param bool $has_license_car
* @param bool $has_license_3_5t_transporter
* @param bool $has_license_7_5t_truck
* @param bool $has_license_12_5t_truck
* @param bool $has_license_forklift
*/
function UserDriverLicenses_update($user_id, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) {
return sql_query("UPDATE `UserDriverLicenses` SET
`has_car`=" . sql_bool($has_car) . ",
`has_license_car`=" . sql_bool($has_license_car) . ",
`has_license_3_5t_transporter`=" . sql_bool($has_license_3_5t_transporter) . ",
`has_license_7_5t_truck`=" . sql_bool($has_license_7_5t_truck) . ",
`has_license_12_5t_truck`=" . sql_bool($has_license_12_5t_truck) . ",
`has_license_forklift`=" . sql_bool($has_license_forklift) . "
WHERE `user_id`='" . sql_escape($user_id) . "'");
}
/**
* Delete a user's driver license entry
*
* @param int $user_id
*/
function UserDriverLicenses_delete($user_id) {
return sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id));
}
?>

@ -0,0 +1,56 @@
<?php
/**
* Edit a user's driving license information.
* @param User $user_source
* @param bool $wants_to_drive
* @param bool $has_car
* @param bool $has_license_car
* @param bool $has_license_3_5t_transporter
* @param bool $has_license_7_5t_truck
* @param bool $has_license_12_5t_truck
* @param bool $has_license_forklift
*/
function UserDriverLicense_edit_view($user_source, $wants_to_drive, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) {
return page_with_title(sprintf(_("Edit %s driving license information"), User_Nick_render($user_source)), [
buttons([
button(user_link($user_source), _("Back to profile"), 'back')
]),
msg(),
form([
form_info(_("Privacy"), _("Your driving license information is only visible for coordinators and admins.")),
form_checkbox('wants_to_drive', _("I am willing to operate cars for the PL"), $wants_to_drive),
div('panel panel-default', [
div('panel-body', [
form_checkbox('has_car', _("I have my own car with me and am willing to use it for the PL (You'll get reimbursed for fuel)"), $has_car),
heading(_("Driver license"), 3),
form_checkbox('has_license_car', _("Car"), $has_license_car),
form_checkbox('has_license_3_5t_transporter', _("Transporter 3,5t"), $has_license_3_5t_transporter),
form_checkbox('has_license_7_5t_truck', _("Truck 7,5t"), $has_license_7_5t_truck),
form_checkbox('has_license_12_5t_truck', _("Truck 12,5t"), $has_license_12_5t_truck),
form_checkbox('has_license_forklift', _("Forklift"), $has_license_forklift)
])
], 'driving_license'),
form_submit('submit', _("Save"))
]) ,
'<script type="text/javascript">
$(function() {
if($("#wants_to_drive").is(":checked"))
$("#driving_license").show();
else
$("#driving_license").hide();
$("#wants_to_drive").click(
function(e) {
if($("#wants_to_drive").is(":checked"))
$("#driving_license").show();
else
$("#driving_license").hide();
}
);
});
</script>'
]);
}
?>

@ -205,6 +205,7 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel
div('col-md-12', array(
buttons(array(
$admin_user_privilege ? button(page_link_to('admin_user') . '&id=' . $user_source['UID'], glyph("edit") . _("edit")) : '',
$admin_user_privilege ? button(user_driver_license_edit_link($user_source), glyph("road") . _("driving license")) : '',
($admin_user_privilege && ! $user_source['Gekommen']) ? button(page_link_to('admin_arrive') . '&arrived=' . $user_source['UID'], _("arrived")) : '',
$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")) : '',

@ -9,6 +9,7 @@ $free_pages = array(
'credits',
'angeltypes',
'users',
'user_driver_licenses',
'ical',
'shifts_json_export',
'shifts',
@ -58,6 +59,8 @@ if (isset($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && (i
list($title, $content) = users_controller();
} elseif ($p == "user_angeltypes") {
list($title, $content) = user_angeltypes_controller();
} elseif ($p == "user_driver_licenses") {
list($title, $content) = user_driver_licenses_controller();
} elseif ($p == "shifttypes") {
list($title, $content) = shifttypes_controller();
} elseif ($p == "news") {

Loading…
Cancel
Save