summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/controller/shifts_controller.php36
-rw-r--r--includes/engelsystem.php2
-rw-r--r--includes/helper/graph_helper.php2
-rw-r--r--includes/model/Shifts_model.php2
-rw-r--r--includes/model/Stats.php10
-rw-r--r--includes/model/User_model.php34
-rw-r--r--includes/pages/admin_active.php2
-rw-r--r--includes/pages/admin_arrive.php1
-rw-r--r--includes/pages/admin_user.php10
-rw-r--r--includes/pages/user_myshifts.php2
-rw-r--r--includes/pages/user_shifts.php4
-rw-r--r--includes/sys_form.php20
-rw-r--r--includes/sys_template.php65
-rw-r--r--includes/view/UserDriverLicenses_view.php14
-rw-r--r--includes/view/User_view.php9
15 files changed, 121 insertions, 92 deletions
diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php
index d2a37f3c..63d2d4c7 100644
--- a/includes/controller/shifts_controller.php
+++ b/includes/controller/shifts_controller.php
@@ -277,6 +277,10 @@ function shift_controller()
$shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
foreach ($angeltypes as &$angeltype) {
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
+ if(empty($needed_angeltype)) {
+ continue;
+ }
+
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
$angeltype_signup_state = Shift_signup_allowed(
@@ -288,11 +292,7 @@ function shift_controller()
$needed_angeltype,
$shift_entries
);
- if (empty($shift_signup_state)) {
- $shift_signup_state = $angeltype_signup_state;
- } else {
- $shift_signup_state->combineWith($angeltype_signup_state);
- }
+ $shift_signup_state->combineWith($angeltype_signup_state);
$angeltype['shift_signup_state'] = $angeltype_signup_state;
}
@@ -346,32 +346,6 @@ function shift_next_controller()
}
/**
- * Export all shifts using api-key.
- */
-function shifts_json_export_all_controller()
-{
- $api_key = config('api_key');
- $request = request();
-
- if (empty($api_key)) {
- engelsystem_error('Config contains empty apikey.');
- }
-
- if (!$request->has('api_key')) {
- engelsystem_error('Missing parameter api_key.');
- }
-
- if ($request->input('api_key') != $api_key) {
- engelsystem_error('Invalid api_key.');
- }
-
- $shifts_source = Shifts();
-
- header('Content-Type: application/json; charset=utf-8');
- raw_output(json_encode($shifts_source));
-}
-
-/**
* Export filtered shifts via JSON.
* (Like iCal Export or shifts view)
*/
diff --git a/includes/engelsystem.php b/includes/engelsystem.php
index 4c096b43..a5dee186 100644
--- a/includes/engelsystem.php
+++ b/includes/engelsystem.php
@@ -16,7 +16,7 @@ require __DIR__ . '/includes.php';
* Check for maintenance
*/
if ($app->get('config')->get('maintenance')) {
- echo file_get_contents(__DIR__ . '/../templates/layouts/maintenance.html');
+ echo file_get_contents(__DIR__ . '/../resources/views/layouts/maintenance.html');
die();
}
diff --git a/includes/helper/graph_helper.php b/includes/helper/graph_helper.php
index 12c7df6c..f49ab635 100644
--- a/includes/helper/graph_helper.php
+++ b/includes/helper/graph_helper.php
@@ -33,7 +33,7 @@ function bargraph($dom_id, $key, $row_names, $colors, $data)
return '<canvas id="' . $dom_id . '" style="width: 100%; height: 300px;"></canvas>
<script type="text/javascript">
$(function(){
- var ctx = $("#' . $dom_id . '").get(0).getContext("2d");
+ var ctx = $(\'#' . $dom_id . '\').get(0).getContext(\'2d\');
var chart = new Chart(ctx).Bar(' . json_encode([
'labels' => $labels,
'datasets' => $datasets
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index cf6f5609..74facc0a 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -182,7 +182,7 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
/**
* @param array $shift
* @param array $angeltype
- * @return array
+ * @return array|null
*/
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
{
diff --git a/includes/model/Stats.php b/includes/model/Stats.php
index 20376ac6..c8342d82 100644
--- a/includes/model/Stats.php
+++ b/includes/model/Stats.php
@@ -128,17 +128,21 @@ function stats_angels_needed_three_hours()
}
/**
- * Returns the number of needed angels for nightshifts (between 2 and 8)
+ * Returns the number of needed angels for nightshifts (see config)
*
* @return int|string
*/
function stats_angels_needed_for_nightshifts()
{
+ $nightShiftsConfig = config('night_shifts');
+ $nightStartTime = $nightShiftsConfig['start'];
+ $nightEndTime = $nightShiftsConfig['end'];
+
$night_start = parse_date(
'Y-m-d H:i',
- date('Y-m-d', time() + 12 * 60 * 60) . ' 02:00'
+ date('Y-m-d', time() + 12 * 60 * 60) . ' ' . $nightStartTime . ':00'
);
- $night_end = $night_start + 6 * 60 * 60;
+ $night_end = $night_start + ($nightEndTime - $nightStartTime) * 60 * 60;
$result = Db::selectOne("
SELECT SUM(`count`) AS `count` FROM (
SELECT
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index cbdb5efe..092ddf27 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -26,8 +26,7 @@ function User_delete($user_id)
*/
function User_tshirt_score($user)
{
- $shift_sum_formula = config('shift_sum_formula');
-
+ $shift_sum_formula = User_get_shifts_sum_query();
$result_shifts = DB::selectOne('
SELECT ROUND((' . $shift_sum_formula . ') / 3600, 2) AS `tshirt_score`
FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
@@ -530,3 +529,34 @@ function User_get_eligable_voucher_count(&$user)
return $eligable_vouchers;
}
+
+/**
+ * Generates the query to sum night shifts
+ *
+ * @return string
+ */
+function User_get_shifts_sum_query()
+{
+ $nightShifts = config('night_shifts');
+ if (!$nightShifts['enabled']) {
+ return 'SUM(`end` - `start`)';
+ }
+
+ return sprintf('
+ SUM(
+ (1 +
+ (
+ (HOUR(FROM_UNIXTIME(`Shifts`.`end`)) > %1$d AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) < %2$d)
+ OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) > %1$d AND HOUR(FROM_UNIXTIME(`Shifts`.`start`)) < %2$d)
+ OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) <= %1$d AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) >= %2$d)
+ )
+ )
+ * (`Shifts`.`end` - `Shifts`.`start`)
+ * (1 - (%3$d + 1) * `ShiftEntry`.`freeloaded`)
+ )
+ ',
+ $nightShifts['start'],
+ $nightShifts['end'],
+ $nightShifts['multiplier']
+ );
+}
diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php
index 7aeb249f..3a9ba8c4 100644
--- a/includes/pages/admin_active.php
+++ b/includes/pages/admin_active.php
@@ -16,7 +16,7 @@ function admin_active_title()
function admin_active()
{
$tshirt_sizes = config('tshirt_sizes');
- $shift_sum_formula = config('shift_sum_formula');
+ $shift_sum_formula = User_get_shifts_sum_query();
$request = request();
$msg = '';
diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php
index c6b3eccd..cb03437f 100644
--- a/includes/pages/admin_arrive.php
+++ b/includes/pages/admin_arrive.php
@@ -21,6 +21,7 @@ function admin_arrive()
if ($request->has('search')) {
$search = strip_request_item('search');
+ $search = trim($search);
}
if ($request->has('reset') && preg_match('/^\d+$/', $request->input('reset'))) {
diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php
index 1eb1f08f..a0125604 100644
--- a/includes/pages/admin_user.php
+++ b/includes/pages/admin_user.php
@@ -52,14 +52,14 @@ function admin_user()
. '</p></td></tr>' . "\n";
$html .= ' <tr><td>Name</td><td>' . '<input size="40" name="eName" value="' . $user_source['Name'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Vorname</td><td>' . '<input size="40" name="eVorname" value="' . $user_source['Vorname'] . '" class="form-control"></td></tr>' . "\n";
- $html .= ' <tr><td>Alter</td><td>' . '<input size="5" name="eAlter" value="' . $user_source['Alter'] . '" class="form-control"></td></tr>' . "\n";
- $html .= ' <tr><td>Telefon</td><td>' . '<input size="40" name="eTelefon" value="' . $user_source['Telefon'] . '" class="form-control"></td></tr>' . "\n";
- $html .= ' <tr><td>Handy</td><td>' . '<input size="40" name="eHandy" value="' . $user_source['Handy'] . '" class="form-control"></td></tr>' . "\n";
+ $html .= ' <tr><td>Alter</td><td>' . '<input type="value" size="5" name="eAlter" value="' . $user_source['Alter'] . '" class="form-control"></td></tr>' . "\n";
+ $html .= ' <tr><td>Telefon</td><td>' . '<input type="tel" size="40" name="eTelefon" value="' . $user_source['Telefon'] . '" class="form-control"></td></tr>' . "\n";
+ $html .= ' <tr><td>Handy</td><td>' . '<input type= "tel" size="40" name="eHandy" value="' . $user_source['Handy'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>DECT</td><td>' . '<input size="4" name="eDECT" value="' . $user_source['DECT'] . '" class="form-control"></td></tr>' . "\n";
if ($user_source['email_by_human_allowed']) {
- $html .= " <tr><td>email</td><td>" . '<input size="40" name="eemail" value="' . $user_source['email'] . '" class="form-control"></td></tr>' . "\n";
+ $html .= " <tr><td>email</td><td>" . '<input type="email" size="40" name="eemail" value="' . $user_source['email'] . '" class="form-control"></td></tr>' . "\n";
}
- $html .= " <tr><td>jabber</td><td>" . '<input size="40" name="ejabber" value="' . $user_source['jabber'] . '" class="form-control"></td></tr>' . "\n";
+ $html .= " <tr><td>jabber</td><td>" . '<input type="email" size="40" name="ejabber" value="' . $user_source['jabber'] . '" class="form-control"></td></tr>' . "\n";
$html .= ' <tr><td>Size</td><td>'
. html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size'], __('Please select...')) . '</td></tr>' . "\n";
diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php
index e679d788..2a8a5d5a 100644
--- a/includes/pages/user_myshifts.php
+++ b/includes/pages/user_myshifts.php
@@ -71,7 +71,7 @@ function user_myshifts()
$shifts_user['UID'],
]
);
- if (count($shift) > 0) {
+ if (!empty($shift)) {
$freeloaded = $shift['freeloaded'];
$freeload_comment = $shift['freeload_comment'];
diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php
index 3c1ed6fa..6754292e 100644
--- a/includes/pages/user_shifts.php
+++ b/includes/pages/user_shifts.php
@@ -224,7 +224,7 @@ function view_user_shifts()
return page([
div('col-md-12', [
msg(),
- view(__DIR__ . '/../../templates/pages/user-shifts.html', [
+ view(__DIR__ . '/../../resources/views/pages/user-shifts.html', [
'title' => shifts_title(),
'room_select' => make_select($rooms, $shiftsFilter->getRooms(), 'rooms', __('Rooms')),
'start_select' => html_select_key(
@@ -333,7 +333,7 @@ function make_select($items, $selected, $name, $title = null, $additionalButtons
. (in_array($i['id'], $selected) ? ' checked="checked"' : '')
. ' > ' . $i['name'] . '</label>'
. (!isset($i['enabled']) || $i['enabled'] ? '' : glyph('lock'))
- . '</div><br />';
+ . '</div>';
}
$html .= '<div id="selection_' . $name . '" class="selection ' . $name . '">' . "\n";
$html .= implode("\n", $htmlItems);
diff --git a/includes/sys_form.php b/includes/sys_form.php
index b75c7316..edf9542a 100644
--- a/includes/sys_form.php
+++ b/includes/sys_form.php
@@ -38,12 +38,12 @@ function form_spinner($name, $label, $value)
</div>
</div>
<script type="text/javascript">
- $("#spinner-' . $name . '-down").click(function() {
- var spinner = $("#spinner-' . $name . '");
+ $(\'#spinner-' . $name . '-down\').click(function() {
+ var spinner = $(\'#spinner-' . $name . '\');
spinner.val(parseInt(spinner.val()) - 1);
});
- $("#spinner-' . $name . '-up").click(function() {
- var spinner = $("#spinner-' . $name . '");
+ $(\'#spinner-' . $name . '-up\').click(function() {
+ var spinner = $(\'#spinner-' . $name . '\');
spinner.val(parseInt(spinner.val()) + 1);
});
</script>
@@ -71,7 +71,7 @@ function form_date($name, $label, $value, $start_date = '', $end_date = '')
return form_element($label, '
<div class="input-group date" id="' . $dom_id . '">
- <input name="' . $name . '" class="form-control" value="' . htmlspecialchars($value) . '">'
+ <input type="date" name="' . $name . '" class="form-control" value="' . htmlspecialchars($value) . '">'
. '<span class="input-group-addon">' . glyph('th') . '</span>
</div>
<script type="text/javascript">
@@ -157,17 +157,17 @@ function form_multi_checkboxes($names, $label, $items, $selected, $disabled = []
* @param string $label
* @param string $selected
* @param string $value
- * @param string $id
+ * @param string $html_id
* @return string
*/
-function form_checkbox($name, $label, $selected, $value = 'checked', $id = null)
+function form_checkbox($name, $label, $selected, $value = 'checked', $html_id = null)
{
- if (is_null($id)) {
- $id = $name;
+ if (is_null($html_id)) {
+ $html_id = $name;
}
return '<div class="checkbox"><label>'
- . '<input type="checkbox" id="' . $id . '" name="' . $name . '" value="' . htmlspecialchars($value) . '" '
+ . '<input type="checkbox" id="' . $html_id . '" name="' . $name . '" value="' . htmlspecialchars($value) . '" '
. ($selected ? ' checked="checked"' : '') . ' /> '
. $label
. '</label></div>';
diff --git a/includes/sys_template.php b/includes/sys_template.php
index 52578f18..dc87e94e 100644
--- a/includes/sys_template.php
+++ b/includes/sys_template.php
@@ -1,5 +1,7 @@
<?php
+use Engelsystem\Renderer\Twig\Extensions\Assets;
+
/**
* Render a stat for dashborad (big number with label).
* If no style given, style is danger if number > 0, and success if number == 0.
@@ -219,12 +221,12 @@ function toolbar_popover($glyphicon, $label, $content, $class = '')
. ' <span class="caret"></span></a>
<script type="text/javascript">
$(function(){
- $("#' . $dom_id . '").popover({
- trigger: "focus",
+ $(\'#' . $dom_id . '\').popover({
+ trigger: \'focus\',
html: true,
- content: "' . addslashes(join('', $content)) . '",
- placement: "bottom",
- container: "#navbar-collapse-1"
+ content: \'' . addslashes(join('', $content)) . '\',
+ placement: \'bottom\',
+ container: \'#navbar-collapse-1\'
})
});
</script></li>';
@@ -438,26 +440,39 @@ function table_body($array)
*/
function ReplaceSmilies($msg)
{
- $msg = str_replace(';o))', '<img src="pic/smiles/icon_redface.gif">', $msg);
- $msg = str_replace(':-))', '<img src="pic/smiles/icon_redface.gif">', $msg);
- $msg = str_replace(';o)', '<img src="pic/smiles/icon_wind.gif">', $msg);
- $msg = str_replace(':)', '<img src="pic/smiles/icon_smile.gif">', $msg);
- $msg = str_replace(':-)', '<img src="pic/smiles/icon_smile.gif">', $msg);
- $msg = str_replace(':(', '<img src="pic/smiles/icon_sad.gif">', $msg);
- $msg = str_replace(':-(', '<img src="pic/smiles/icon_sad.gif">', $msg);
- $msg = str_replace(':o(', '<img src="pic/smiles/icon_sad.gif">', $msg);
- $msg = str_replace(':o)', '<img src="pic/smiles/icon_lol.gif">', $msg);
- $msg = str_replace(';o(', '<img src="pic/smiles/icon_cry.gif">', $msg);
- $msg = str_replace(';(', '<img src="pic/smiles/icon_cry.gif">', $msg);
- $msg = str_replace(';-(', '<img src="pic/smiles/icon_cry.gif">', $msg);
- $msg = str_replace('8)', '<img src="pic/smiles/icon_rolleyes.gif">', $msg);
- $msg = str_replace('8o)', '<img src="pic/smiles/icon_rolleyes.gif">', $msg);
- $msg = str_replace(':P', '<img src="pic/smiles/icon_evil.gif">', $msg);
- $msg = str_replace(':-P', '<img src="pic/smiles/icon_evil.gif">', $msg);
- $msg = str_replace(':oP', '<img src="pic/smiles/icon_evil.gif">', $msg);
- $msg = str_replace(';P', '<img src="pic/smiles/icon_mad.gif">', $msg);
- $msg = str_replace(';oP', '<img src="pic/smiles/icon_mad.gif">', $msg);
- $msg = str_replace('?)', '<img src="pic/smiles/icon_question.gif">', $msg);
+ /** @var Assets $assets */
+ $assets = app('twig.extension.assets');
+
+ foreach (
+ [
+ ';o))' => 'redface',
+ ':-))' => 'redface',
+ ';o)' => 'wind',
+ ':)' => 'smile',
+ ':-)' => 'smile',
+ ':(' => 'sad',
+ ':-(' => 'sad',
+ ':o(' => 'sad',
+ ':o)' => 'lol',
+ ':D' => 'lol',
+ ';o(' => 'cry',
+ ';(' => 'cry',
+ ';-(' => 'cry',
+ '8)' => 'rolleyes',
+ '8o)' => 'rolleyes',
+ ':P' => 'evil',
+ ':-P' => 'evil',
+ ':oP' => 'evil',
+ ';P' => 'mad',
+ ';oP' => 'mad',
+ '?)' => 'question',
+ ] as $search => $replace
+ ) {
+ $msg = str_ireplace($search, sprintf(
+ '<img src="%s">',
+ sprintf($assets->getAsset('assets/emojis/%s.gif'), $replace)
+ ), $msg);
+ }
return $msg;
}
diff --git a/includes/view/UserDriverLicenses_view.php b/includes/view/UserDriverLicenses_view.php
index 0c46b567..317910b6 100644
--- a/includes/view/UserDriverLicenses_view.php
+++ b/includes/view/UserDriverLicenses_view.php
@@ -53,18 +53,18 @@ function UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver
]),
'<script type="text/javascript">
$(function() {
- var checkbox = $("#wants_to_drive");
- if(checkbox.is(":checked"))
- $("#driving_license").show();
+ var checkbox = $(\'#wants_to_drive\');
+ if(checkbox.is(\':checked\'))
+ $(\'#driving_license\').show();
else
- $("#driving_license").hide();
+ $(\'#driving_license\').hide();
checkbox.click(
function() {
- if($("#wants_to_drive").is(":checked"))
- $("#driving_license").show();
+ if($(\'#wants_to_drive\').is(\':checked\'))
+ $(\'#driving_license\').show();
else
- $("#driving_license").hide();
+ $(\'#driving_license\').hide();
}
);
});
diff --git a/includes/view/User_view.php b/includes/view/User_view.php
index 40e7bfe1..3d5cfd69 100644
--- a/includes/view/User_view.php
+++ b/includes/view/User_view.php
@@ -532,6 +532,7 @@ function User_view(
$admin_user_worklog_privilege,
$user_worklogs
) {
+ $nightShiftsConfig = config('night_shifts');
$user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']);
$myshifts_table = '';
if ($its_me || $admin_user_privilege) {
@@ -619,8 +620,12 @@ function User_view(
]),
($its_me || $admin_user_privilege) ? '<h2>' . __('Shifts') . '</h2>' : '',
$myshifts_table,
- $its_me ? info(
- glyph('info-sign') . __('Your night shifts between 2 and 8 am count twice.'),
+ ($its_me && $nightShiftsConfig['enabled']) ? info(
+ glyph('info-sign') . sprintf(
+ __('Your night shifts between %d and %d am count twice.'),
+ $nightShiftsConfig['start'],
+ $nightShiftsConfig['end']
+ ),
true
) : '',
$its_me && count($shifts) == 0