2015-12-19 23:31:08 +01:00
|
|
|
<?php
|
|
|
|
|
2016-11-17 14:35:04 +01:00
|
|
|
/**
|
|
|
|
* Returns a new empty UserDriverLicense
|
|
|
|
* FIXME entity object needed
|
|
|
|
*/
|
2016-11-17 14:40:21 +01:00
|
|
|
function UserDriverLicense_new() {
|
2016-11-17 14:35:04 +01:00
|
|
|
return [
|
2016-11-17 14:40:21 +01:00
|
|
|
'user_id' => null,
|
2016-11-17 14:35:04 +01:00
|
|
|
'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
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is it valid?
|
|
|
|
*
|
|
|
|
* @param UserDriverLicense $user_driver_license
|
|
|
|
* The UserDriverLicense to check
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function UserDriverLicense_valid($user_driver_license) {
|
|
|
|
return $user_driver_license['has_car'] || $user_driver_license['has_license_car'] || $user_driver_license['has_license_3_5t_transporter'] || $user_driver_license['has_license_7_5t_truck'] || $user_driver_license['has_license_12_5t_truck'] || $user_driver_license['has_license_forklift'];
|
|
|
|
}
|
|
|
|
|
2015-12-19 23:31:08 +01:00
|
|
|
/**
|
|
|
|
* Get a users driver license information
|
2016-11-17 14:35:04 +01:00
|
|
|
*
|
|
|
|
* @param int $user_id
|
|
|
|
* The users id
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
|
|
|
function UserDriverLicense($user_id) {
|
|
|
|
$user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
|
2016-09-29 11:18:17 +02:00
|
|
|
if ($user_driver_license === false) {
|
2016-11-10 13:55:16 +01:00
|
|
|
engelsystem_error('Unable to load user driver license.');
|
2015-12-19 23:31:08 +01:00
|
|
|
return false;
|
2016-09-29 11:18:17 +02:00
|
|
|
}
|
|
|
|
if (count($user_driver_license) > 0) {
|
2015-12-19 23:31:08 +01:00
|
|
|
return $user_driver_license[0];
|
2016-09-29 11:18:17 +02:00
|
|
|
}
|
2015-12-19 23:31:08 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a user's driver license entry
|
|
|
|
*
|
2016-11-17 14:35:04 +01:00
|
|
|
* @param UserDriverLicense $user_driver_license
|
|
|
|
* The UserDriverLicense to create
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
2016-11-17 14:40:21 +01:00
|
|
|
function UserDriverLicenses_create($user_driver_license, $user) {
|
|
|
|
$user_driver_license['user_id'] = $user['UID'];
|
2016-11-10 13:55:16 +01:00
|
|
|
$result = sql_query("
|
2015-12-19 23:31:08 +01:00
|
|
|
INSERT INTO `UserDriverLicenses` SET
|
2016-11-17 14:35:04 +01:00
|
|
|
`user_id`=" . sql_escape($user_driver_license['user_id']) . ",
|
|
|
|
`has_car`=" . sql_bool($user_driver_license['has_car']) . ",
|
|
|
|
`has_license_car`=" . sql_bool($user_driver_license['has_license_car']) . ",
|
|
|
|
`has_license_3_5t_transporter`=" . sql_bool($user_driver_license['has_license_3_5t_transporter']) . ",
|
|
|
|
`has_license_7_5t_truck`=" . sql_bool($user_driver_license['has_license_7_5t_truck']) . ",
|
|
|
|
`has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
|
|
|
|
`has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']));
|
2016-11-10 13:55:16 +01:00
|
|
|
if ($result === false) {
|
|
|
|
engelsystem_error('Unable to create user driver license');
|
|
|
|
}
|
2016-11-17 14:40:21 +01:00
|
|
|
return $user_driver_license;
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a user's driver license entry
|
|
|
|
*
|
2016-11-17 14:35:04 +01:00
|
|
|
* @param UserDriverLicense $user_driver_license
|
|
|
|
* The UserDriverLicense to update
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
2016-11-17 14:35:04 +01:00
|
|
|
function UserDriverLicenses_update($user_driver_license) {
|
2016-11-10 13:55:16 +01:00
|
|
|
$result = sql_query("UPDATE `UserDriverLicenses` SET
|
2016-11-17 14:35:04 +01:00
|
|
|
`has_car`=" . sql_bool($user_driver_license['has_car']) . ",
|
|
|
|
`has_license_car`=" . sql_bool($user_driver_license['has_license_car']) . ",
|
|
|
|
`has_license_3_5t_transporter`=" . sql_bool($user_driver_license['has_license_3_5t_transporter']) . ",
|
|
|
|
`has_license_7_5t_truck`=" . sql_bool($user_driver_license['has_license_7_5t_truck']) . ",
|
|
|
|
`has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
|
|
|
|
`has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']) . "
|
|
|
|
WHERE `user_id`='" . sql_escape($user_driver_license['user_id']) . "'");
|
2016-11-10 13:55:16 +01:00
|
|
|
if ($result === false) {
|
|
|
|
engelsystem_error("Unable to update user driver license information");
|
|
|
|
}
|
|
|
|
return $result;
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a user's driver license entry
|
|
|
|
*
|
|
|
|
* @param int $user_id
|
|
|
|
*/
|
|
|
|
function UserDriverLicenses_delete($user_id) {
|
2016-11-10 13:55:16 +01:00
|
|
|
$result = sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id));
|
|
|
|
if ($result === false) {
|
|
|
|
engelsystem_error("Unable to remove user driver license information");
|
|
|
|
}
|
|
|
|
return $result;
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|
|
|
|
?>
|