You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
engelsystem/includes/controller/user_driver_licenses_contro...

140 lines
4.4 KiB
PHTML

<?php
/**
8 years ago
* Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license
* information provided.
*/
8 years ago
function user_driver_license_required_hint()
{
global $user;
8 years ago
8 years ago
$angeltypes = User_angeltypes($user);
$user_driver_license = UserDriverLicense($user['UID']);
8 years ago
// User has already entered data, no hint needed.
if ($user_driver_license != null) {
return null;
}
8 years ago
foreach ($angeltypes as $angeltype) {
if ($angeltype['requires_driver_license']) {
8 years ago
return 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>'
);
8 years ago
}
}
8 years ago
8 years ago
return null;
}
/**
* Route user driver licenses actions.
*/
8 years ago
function user_driver_licenses_controller()
{
global $user;
8 years ago
if (!isset($user)) {
8 years ago
redirect(page_link_to(''));
}
8 years ago
8 years ago
$action = strip_request_item('action', 'edit');
8 years ago
8 years ago
switch ($action) {
8 years ago
default:
case 'edit':
return user_driver_license_edit_controller();
}
}
/**
* Link to user driver license edit page for given user.
*
8 years ago
* @param User $user
*/
8 years ago
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'];
}
/**
* Loads the user for the driver license.
*/
8 years ago
function user_driver_license_load_user()
{
global $user;
8 years ago
8 years ago
$user_source = $user;
8 years ago
8 years ago
if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']);
if ($user_source == null) {
redirect(user_driver_license_edit_link());
}
}
8 years ago
8 years ago
return $user_source;
}
/**
* Edit a users driver license information.
*/
8 years ago
function user_driver_license_edit_controller()
{
global $privileges, $user;
8 years ago
8 years ago
$user_source = user_driver_license_load_user();
8 years ago
// 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());
}
8 years ago
$user_driver_license = UserDriverLicense($user_source['UID']);
if ($user_driver_license == null) {
$wants_to_drive = false;
$user_driver_license = UserDriverLicense_new();
} else {
$wants_to_drive = true;
}
8 years ago
8 years ago
if (isset($_REQUEST['submit'])) {
$wants_to_drive = isset($_REQUEST['wants_to_drive']);
if ($wants_to_drive) {
$user_driver_license['has_car'] = isset($_REQUEST['has_car']);
$user_driver_license['has_license_car'] = isset($_REQUEST['has_license_car']);
$user_driver_license['has_license_3_5t_transporter'] = isset($_REQUEST['has_license_3_5t_transporter']);
$user_driver_license['has_license_7_5t_truck'] = isset($_REQUEST['has_license_7_5t_truck']);
$user_driver_license['has_license_12_5t_truck'] = isset($_REQUEST['has_license_12_5t_truck']);
$user_driver_license['has_license_forklift'] = isset($_REQUEST['has_license_forklift']);
8 years ago
8 years ago
if (UserDriverLicense_valid($user_driver_license)) {
if ($user_driver_license['user_id'] == null) {
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user);
} else {
UserDriverLicenses_update($user_driver_license);
}
engelsystem_log("Driver license information updated.");
success(_("Your driver license information has been saved."));
redirect(user_link($user_source));
} else {
error(_("Please select at least one driving license."));
}
} elseif ($user_driver_license['id'] != null) {
UserDriverLicenses_delete($user_source['UID']);
engelsystem_log("Driver license information removed.");
success(_("Your driver license information has been removed."));
redirect(user_link($user_source));
}
}
8 years ago
8 years ago
return [
8 years ago
sprintf(_("Edit %s driving license information"), $user_source['Nick']),
UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
];
}