improve code style
This commit is contained in:
parent
6dfefc3bb9
commit
d5d2acc7d8
|
@ -48,10 +48,10 @@ $shift_sum_formula = "SUM(
|
|||
)";
|
||||
|
||||
// voucher calculation
|
||||
$voucher_settings = array(
|
||||
$voucher_settings = [
|
||||
"initial_vouchers" => 2,
|
||||
"shifts_per_voucher" => 1
|
||||
);
|
||||
];
|
||||
|
||||
// weigh every shift the same
|
||||
// $shift_sum_formula = "SUM(`end` - `start`)";
|
||||
|
@ -60,10 +60,10 @@ $voucher_settings = array(
|
|||
$api_key = "";
|
||||
|
||||
// MySQL-Connection Settings
|
||||
$config = array(
|
||||
$config = [
|
||||
'host' => "localhost",
|
||||
'user' => "root",
|
||||
'pw' => "",
|
||||
'db' => "engelsystem"
|
||||
);
|
||||
];
|
||||
?>
|
||||
|
|
|
@ -137,12 +137,12 @@ function shifts_json_export_all_controller() {
|
|||
function shifts_json_export_controller() {
|
||||
global $ical_shifts, $user;
|
||||
|
||||
if (isset($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
|
||||
$key = $_REQUEST['key'];
|
||||
} else {
|
||||
if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
|
||||
engelsystem_error("Missing key.");
|
||||
}
|
||||
|
||||
$key = $_REQUEST['key'];
|
||||
|
||||
$user = User_by_api_key($key);
|
||||
if ($user === false) {
|
||||
engelsystem_error("Unable to find user.");
|
||||
|
|
|
@ -69,6 +69,8 @@ function user_driver_license_edit_link($user = null) {
|
|||
function user_driver_license_edit_controller() {
|
||||
global $privileges, $user;
|
||||
|
||||
$user_source = $user;
|
||||
|
||||
if (isset($_REQUEST['user_id'])) {
|
||||
$user_source = User($_REQUEST['user_id']);
|
||||
if ($user_source === false) {
|
||||
|
@ -82,8 +84,6 @@ function user_driver_license_edit_controller() {
|
|||
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;
|
||||
|
|
|
@ -61,8 +61,9 @@ function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_
|
|||
// you canot join if shift is full
|
||||
foreach ($needed_angeltypes as $needed_angeltype) {
|
||||
if ($needed_angeltype['angel_type_id'] == $angeltype['id']) {
|
||||
if ($needed_angeltype['taken'] >= $needed_angeltype['count'])
|
||||
if ($needed_angeltype['taken'] >= $needed_angeltype['count']) {
|
||||
$user_may_join_shift = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,9 @@ function sql_transaction_rollback() {
|
|||
|
||||
if (-- $sql_nested_transaction_level == 0) {
|
||||
return sql_query("ROLLBACK");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,14 +81,14 @@ function sql_error($message) {
|
|||
* Username
|
||||
* @param string $pass
|
||||
* Password
|
||||
* @param string $db
|
||||
* @param string $db_name
|
||||
* DB to select
|
||||
* @return mysqli The connection handler
|
||||
*/
|
||||
function sql_connect($host, $user, $pass, $db) {
|
||||
function sql_connect($host, $user, $pass, $db_name) {
|
||||
global $sql_connection;
|
||||
|
||||
$sql_connection = new mysqli($host, $user, $pass, $db);
|
||||
$sql_connection = new mysqli($host, $user, $pass, $db_name);
|
||||
if ($sql_connection->connect_errno) {
|
||||
error("Unable to connect to MySQL: " . $sql_connection->connect_error);
|
||||
return sql_error("Unable to connect to MySQL: " . $sql_connection->connect_error);
|
||||
|
|
|
@ -385,7 +385,7 @@ function shifts_printable($shifts, $shifttypes) {
|
|||
return $shifts_printable;
|
||||
}
|
||||
|
||||
function shift_sort($a, $b) {
|
||||
return ($a['start'] < $b['start']) ? - 1 : 1;
|
||||
function shift_sort($shift_a, $shift_b) {
|
||||
return ($shift_a['start'] < $shift_b['start']) ? - 1 : 1;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -62,9 +62,10 @@ function admin_news() {
|
|||
redirect(page_link_to("news"));
|
||||
break;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
return error("No News found.", true);
|
||||
}
|
||||
}
|
||||
return $html . '</div>';
|
||||
}
|
||||
?>
|
|
@ -82,8 +82,9 @@ function user_myshifts() {
|
|||
}
|
||||
|
||||
return ShiftEntry_edit_view(User_Nick_render($shifts_user), date("Y-m-d H:i", $shift['start']) . ', ' . shift_length($shift), $shift['Name'], $shift['name'], $shift['angel_type'], $shift['Comment'], $shift['freeloaded'], $shift['freeload_comment'], in_array("user_shifts_admin", $privileges));
|
||||
} else
|
||||
} else {
|
||||
redirect(page_link_to('user_myshifts'));
|
||||
}
|
||||
} elseif (isset($_REQUEST['cancel']) && preg_match("/^[0-9]*$/", $_REQUEST['cancel'])) {
|
||||
$user_id = $_REQUEST['cancel'];
|
||||
$shift = sql_select("
|
||||
|
|
|
@ -679,8 +679,9 @@ function view_user_shifts() {
|
|||
$user_may_join_shift &= isset($angeltype['user_id']);
|
||||
|
||||
// you cannot join if you are not confirmed
|
||||
if ($angeltype['restricted'] == 1 && isset($angeltype['user_id']))
|
||||
if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) {
|
||||
$user_may_join_shift &= isset($angeltype['confirm_user_id']);
|
||||
}
|
||||
|
||||
// you can only join if the shift is in future or running
|
||||
$user_may_join_shift &= time() < $shift['start'];
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
/**
|
||||
* Leitet den Browser an die übergebene URL weiter und hält das Script an.
|
||||
*/
|
||||
function redirect($to) {
|
||||
header("Location: " . $to, true, 302);
|
||||
function redirect($url) {
|
||||
header("Location: " . $url, true, 302);
|
||||
raw_output("");
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ function glyph_bool($boolean) {
|
|||
return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>';
|
||||
}
|
||||
|
||||
function div($class, $content = array(), $dom_id = "") {
|
||||
function div($class, $content = [], $dom_id = "") {
|
||||
$dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : '';
|
||||
return '<div' . $dom_id . ' class="' . $class . '">' . join("\n", $content) . '</div>';
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
|
|||
'actions' => ''
|
||||
];
|
||||
|
||||
if ($angeltype['requires_driver_license'] && ($coordinator || $admin_angeltypes))
|
||||
if ($angeltype['requires_driver_license'] && ($coordinator || $admin_angeltypes)) {
|
||||
$table_headers = [
|
||||
'Nick' => _("Nick"),
|
||||
'DECT' => _("DECT"),
|
||||
|
@ -166,6 +166,7 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
|
|||
'has_license_forklift' => _("Forklift"),
|
||||
'actions' => ''
|
||||
];
|
||||
}
|
||||
|
||||
if (count($coordinators) > 0) {
|
||||
$page[] = '<h3>' . _("Coordinators") . '</h3>';
|
||||
|
|
|
@ -152,17 +152,15 @@ function User_shift_state_render($user) {
|
|||
if ($upcoming_shifts[0]['start'] > time()) {
|
||||
if ($upcoming_shifts[0]['start'] - time() > 3600) {
|
||||
return '<span class="text-success moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>';
|
||||
} else {
|
||||
return '<span class="text-warning moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>';
|
||||
}
|
||||
return '<span class="text-warning moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>';
|
||||
}
|
||||
$halfway = ($upcoming_shifts[0]['start'] + $upcoming_shifts[0]['end']) / 2;
|
||||
|
||||
if (time() < $halfway) {
|
||||
return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Shift starts %c") . '</span>';
|
||||
} else {
|
||||
return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['end'] . '">' . _("Shift ends %c") . '</span>';
|
||||
}
|
||||
return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['end'] . '">' . _("Shift ends %c") . '</span>';
|
||||
}
|
||||
|
||||
function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me) {
|
||||
|
@ -340,7 +338,7 @@ function User_angeltypes_render($user_angeltypes) {
|
|||
}
|
||||
|
||||
function User_groups_render($user_groups) {
|
||||
$output = array();
|
||||
$output = [];
|
||||
foreach ($user_groups as $group) {
|
||||
$output[] = substr($group['Name'], 2);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue