improve code style

main
msquare 8 years ago
parent 6dfefc3bb9
commit d5d2acc7d8

@ -48,10 +48,10 @@ $shift_sum_formula = "SUM(
)"; )";
// voucher calculation // voucher calculation
$voucher_settings = array( $voucher_settings = [
"initial_vouchers" => 2, "initial_vouchers" => 2,
"shifts_per_voucher" => 1 "shifts_per_voucher" => 1
); ];
// weigh every shift the same // weigh every shift the same
// $shift_sum_formula = "SUM(`end` - `start`)"; // $shift_sum_formula = "SUM(`end` - `start`)";
@ -60,10 +60,10 @@ $voucher_settings = array(
$api_key = ""; $api_key = "";
// MySQL-Connection Settings // MySQL-Connection Settings
$config = array( $config = [
'host' => "localhost", 'host' => "localhost",
'user' => "root", 'user' => "root",
'pw' => "", 'pw' => "",
'db' => "engelsystem" 'db' => "engelsystem"
); ];
?> ?>

@ -137,12 +137,12 @@ function shifts_json_export_all_controller() {
function shifts_json_export_controller() { function shifts_json_export_controller() {
global $ical_shifts, $user; global $ical_shifts, $user;
if (isset($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
$key = $_REQUEST['key'];
} else {
engelsystem_error("Missing key."); engelsystem_error("Missing key.");
} }
$key = $_REQUEST['key'];
$user = User_by_api_key($key); $user = User_by_api_key($key);
if ($user === false) { if ($user === false) {
engelsystem_error("Unable to find user."); engelsystem_error("Unable to find user.");

@ -69,6 +69,8 @@ function user_driver_license_edit_link($user = null) {
function user_driver_license_edit_controller() { function user_driver_license_edit_controller() {
global $privileges, $user; global $privileges, $user;
$user_source = $user;
if (isset($_REQUEST['user_id'])) { if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']); $user_source = User($_REQUEST['user_id']);
if ($user_source === false) { 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)) { if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges)) {
redirect(user_driver_license_edit_link()); redirect(user_driver_license_edit_link());
} }
} else {
$user_source = $user;
} }
$wants_to_drive = false; $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 // you canot join if shift is full
foreach ($needed_angeltypes as $needed_angeltype) { foreach ($needed_angeltypes as $needed_angeltype) {
if ($needed_angeltype['angel_type_id'] == $angeltype['id']) { 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; $user_may_join_shift = false;
}
break; break;
} }
} }

@ -50,9 +50,9 @@ function sql_transaction_rollback() {
if (-- $sql_nested_transaction_level == 0) { if (-- $sql_nested_transaction_level == 0) {
return sql_query("ROLLBACK"); return sql_query("ROLLBACK");
} else {
return true;
} }
return true;
} }
/** /**
@ -81,14 +81,14 @@ function sql_error($message) {
* Username * Username
* @param string $pass * @param string $pass
* Password * Password
* @param string $db * @param string $db_name
* DB to select * DB to select
* @return mysqli The connection handler * @return mysqli The connection handler
*/ */
function sql_connect($host, $user, $pass, $db) { function sql_connect($host, $user, $pass, $db_name) {
global $sql_connection; 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) { if ($sql_connection->connect_errno) {
error("Unable to connect to MySQL: " . $sql_connection->connect_error); error("Unable to connect to MySQL: " . $sql_connection->connect_error);
return sql_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; return $shifts_printable;
} }
function shift_sort($a, $b) { function shift_sort($shift_a, $shift_b) {
return ($a['start'] < $b['start']) ? - 1 : 1; return ($shift_a['start'] < $shift_b['start']) ? - 1 : 1;
} }
?> ?>

@ -62,8 +62,9 @@ function admin_news() {
redirect(page_link_to("news")); redirect(page_link_to("news"));
break; break;
} }
} else } else {
return error("No News found.", true); return error("No News found.", true);
}
} }
return $html . '</div>'; 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)); 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')); redirect(page_link_to('user_myshifts'));
}
} elseif (isset($_REQUEST['cancel']) && preg_match("/^[0-9]*$/", $_REQUEST['cancel'])) { } elseif (isset($_REQUEST['cancel']) && preg_match("/^[0-9]*$/", $_REQUEST['cancel'])) {
$user_id = $_REQUEST['cancel']; $user_id = $_REQUEST['cancel'];
$shift = sql_select(" $shift = sql_select("

@ -679,10 +679,11 @@ function view_user_shifts() {
$user_may_join_shift &= isset($angeltype['user_id']); $user_may_join_shift &= isset($angeltype['user_id']);
// you cannot join if you are not confirmed // 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']); $user_may_join_shift &= isset($angeltype['confirm_user_id']);
}
// you can only join if the shift is in future or running
// you can only join if the shift is in future or running
$user_may_join_shift &= time() < $shift['start']; $user_may_join_shift &= time() < $shift['start'];
// User shift admins may join anybody in every shift // User shift admins may join anybody in every shift

@ -3,8 +3,8 @@
/** /**
* Leitet den Browser an die übergebene URL weiter und hält das Script an. * Leitet den Browser an die übergebene URL weiter und hält das Script an.
*/ */
function redirect($to) { function redirect($url) {
header("Location: " . $to, true, 302); header("Location: " . $url, true, 302);
raw_output(""); raw_output("");
} }

@ -41,7 +41,7 @@ function glyph_bool($boolean) {
return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>'; 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 . '"' : ''; $dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : '';
return '<div' . $dom_id . ' class="' . $class . '">' . join("\n", $content) . '</div>'; 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' => '' 'actions' => ''
]; ];
if ($angeltype['requires_driver_license'] && ($coordinator || $admin_angeltypes)) if ($angeltype['requires_driver_license'] && ($coordinator || $admin_angeltypes)) {
$table_headers = [ $table_headers = [
'Nick' => _("Nick"), 'Nick' => _("Nick"),
'DECT' => _("DECT"), 'DECT' => _("DECT"),
@ -166,6 +166,7 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel
'has_license_forklift' => _("Forklift"), 'has_license_forklift' => _("Forklift"),
'actions' => '' 'actions' => ''
]; ];
}
if (count($coordinators) > 0) { if (count($coordinators) > 0) {
$page[] = '<h3>' . _("Coordinators") . '</h3>'; $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()) {
if ($upcoming_shifts[0]['start'] - time() > 3600) { if ($upcoming_shifts[0]['start'] - time() > 3600) {
return '<span class="text-success moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Next shift %c") . '</span>'; 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; $halfway = ($upcoming_shifts[0]['start'] + $upcoming_shifts[0]['end']) / 2;
if (time() < $halfway) { if (time() < $halfway) {
return '<span class="text-danger moment-countdown" data-timestamp="' . $upcoming_shifts[0]['start'] . '">' . _("Shift starts %c") . '</span>'; 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) { 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) { function User_groups_render($user_groups) {
$output = array(); $output = [];
foreach ($user_groups as $group) { foreach ($user_groups as $group) {
$output[] = substr($group['Name'], 2); $output[] = substr($group['Name'], 2);
} }

Loading…
Cancel
Save