summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2014-12-22 20:06:37 +0100
committerPhilip Häusler <msquare@notrademark.de>2014-12-22 20:06:37 +0100
commit2d587478a1094969fbb44bde29b34b034868db70 (patch)
treededbfa93c2ac88170e91306b4907f4a7d14ee221 /includes
parent702047de5391b968137966077103cbb6d0a24dd8 (diff)
fix different bugs with shift types
Diffstat (limited to 'includes')
-rw-r--r--includes/mailer/shifts_mailer.php11
-rw-r--r--includes/model/Shifts_model.php5
-rw-r--r--includes/pages/admin_import.php160
-rw-r--r--includes/pages/user_shifts.php46
-rw-r--r--includes/sys_template.php11
5 files changed, 153 insertions, 80 deletions
diff --git a/includes/mailer/shifts_mailer.php b/includes/mailer/shifts_mailer.php
index 16b0db65..fb234aab 100644
--- a/includes/mailer/shifts_mailer.php
+++ b/includes/mailer/shifts_mailer.php
@@ -11,7 +11,12 @@ function mail_shift_change($old_shift, $new_shift) {
$message .= "\n";
if ($old_shift["name"] != $new_shift["name"]) {
- $message .= sprintf(_("* Shift Name changed from %s to %s"), $old_shift["name"], $new_shift["name"]) . "\n";
+ $message .= sprintf(_("* Shift type changed from %s to %s"), $old_shift["name"], $new_shift["name"]) . "\n";
+ $noticable_changes = true;
+ }
+
+ if ($old_shift["title"] != $new_shift["title"]) {
+ $message .= sprintf(_("* Shift title changed from %s to %s"), $old_shift["title"], $new_shift["title"]) . "\n";
$noticable_changes = true;
}
@@ -39,6 +44,7 @@ function mail_shift_change($old_shift, $new_shift) {
$message .= _("The updated Shift:") . "\n";
$message .= $new_shift["name"] . "\n";
+ $message .= $new_shift["title"] . "\n";
$message .= date("y-m-d H:i", $new_shift["start"]) . " - " . date("H:i", $new_shift["end"]) . "\n";
$message .= $new_room["Name"] . "\n";
@@ -54,6 +60,7 @@ function mail_shift_delete($shift) {
$message = _("A Shift you are registered on was deleted:") . "\n";
$message .= $shift["name"] . "\n";
+ $message .= $new_shift["title"] . "\n";
$message .= date("y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
$message .= $room["Name"] . "\n";
@@ -68,6 +75,7 @@ function mail_shift_assign($user, $shift) {
$message = _("You have been assigned to a Shift:") . "\n";
$message .= $shift["name"] . "\n";
+ $message .= $shift["title"] . "\n";
$message .= date("y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
$message .= $room["Name"] . "\n";
@@ -81,6 +89,7 @@ function mail_shift_removed($user, $shift) {
$message = _("You have been removed from a Shift:") . "\n";
$message .= $shift["name"] . "\n";
+ $message .= $shift["title"] . "\n";
$message .= date("y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
$message .= $room["Name"] . "\n";
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index eca0d141..ee9c3773 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -20,7 +20,7 @@ function Shift_delete($shift_id) {
* Update a shift.
*/
function Shift_update($shift) {
- $old_shift = Shift($shift['SID']);
+ $shift['name'] = ShiftType($shift['shifttype_id'])['name'];
mail_shift_change(Shift($shift['SID']), $shift);
return sql_query("UPDATE `Shifts` SET
@@ -43,7 +43,7 @@ function Shift_update_by_psid($shift) {
return false;
if (count($shift_source) == 0)
return null;
- $shift['SID'] = $shift_source['SID'];
+ $shift['SID'] = $shift_source[0]['SID'];
return Shift_update($shift);
}
@@ -146,6 +146,7 @@ function Shift($id) {
$result = $shifts_source[0];
$result['ShiftEntry'] = $shiftsEntry_source;
+ $result['NeedAngels'] = [];
$temp = NeededAngelTypes_by_shift($id);
foreach ($temp as $e) {
diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php
index 120ab91b..ad0b2b1e 100644
--- a/includes/pages/admin_import.php
+++ b/includes/pages/admin_import.php
@@ -10,104 +10,154 @@ function admin_import() {
$html = "";
$step = "input";
- if (isset($_REQUEST['step']))
+ if (isset($_REQUEST['step']) && in_array($step, [
+ 'input',
+ 'check',
+ 'import'
+ ]))
$step = $_REQUEST['step'];
- $html .= '<p>';
- $html .= $step == "input" ? '<b>1. Input</b>' : '1. Input';
- $html .= ' &raquo; ';
- $html .= $step == "check" ? '<b>2. Validate</b>' : '2. Validate';
- $html .= ' &raquo; ';
- $html .= $step == "import" ? '<b>3. Import</b>' : '3. Import';
- $html .= '</p>';
+ if ($test_handle = fopen('../import/tmp', 'w')) {
+ fclose($test_handle);
+ unlink('../import/tmp');
+ } else {
+ error(_('Webserver has no write-permission on import directory.'));
+ }
$import_file = '../import/import_' . $user['UID'] . '.xml';
+ $shifttype_id = null;
+
+ $shifttypes_source = ShiftTypes();
+ if ($shifttypes_source === false)
+ engelsystem_error('Unable to load shifttypes.');
+ $shifttypes = [];
+ foreach ($shifttypes_source as $shifttype)
+ $shifttypes[$shifttype['id']] = $shifttype['name'];
switch ($step) {
- case "input":
+ case 'input':
$ok = false;
- if ($test_handle = fopen('../import/tmp', 'w')) {
- fclose($test_handle);
- unlink('../import/tmp');
- } else {
- error("Webserver has no write-permission on import directory.");
- }
if (isset($_REQUEST['submit'])) {
$ok = true;
+
+ if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']]))
+ $shifttype_id = $_REQUEST['shifttype_id'];
+ else {
+ $ok = false;
+ error(_('Please select a shift type.'));
+ }
+
if (isset($_FILES['xcal_file']) && ($_FILES['xcal_file']['error'] == 0)) {
if (move_uploaded_file($_FILES['xcal_file']['tmp_name'], $import_file)) {
libxml_use_internal_errors(true);
if (simplexml_load_file($import_file) === false) {
$ok = false;
- error("No valid xml/xcal file provided.");
+ error(_('No valid xml/xcal file provided.'));
unlink($import_file);
}
} else {
$ok = false;
- error("File upload went wrong.");
+ error(_('File upload went wrong.'));
}
} else {
$ok = false;
- error("Please provide some data.");
+ error(_('Please provide some data.'));
}
}
- if ($ok)
- redirect(page_link_to('admin_import') . "&step=check");
- else {
- $html .= form(array(
- form_info('', _("This import will create/update/delete rooms and shifts by given FRAB-export file. The needed file format is xcal.")),
- form_file('xcal_file', _("xcal-File (.xcal)")),
- form_submit('submit', _("Import"))
- ));
+ if ($ok) {
+ redirect(page_link_to('admin_import') . "&step=check&shifttype_id=" . $shifttype_id);
+ } else {
+ $html .= div('well well-sm text-center', [
+ _('File Upload') . mute(glyph('arrow-right')) . mute(_('Validation')) . mute(glyph('arrow-right')) . mute(_('Import'))
+ ]) . div('row', [
+ div('col-md-offset-3 col-md-6', [
+ form(array(
+ form_info('', _("This import will create/update/delete rooms and shifts by given FRAB-export file. The needed file format is xcal.")),
+ form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
+ form_file('xcal_file', _("xcal-File (.xcal)")),
+ form_submit('submit', _("Import"))
+ ))
+ ])
+ ]);
}
break;
- case "check":
- if (! file_exists($import_file))
+ case 'check':
+ if (! file_exists($import_file)) {
+ error(_('Missing import file.'));
redirect(page_link_to('admin_import'));
+ }
+
+ if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']]))
+ $shifttype_id = $_REQUEST['shifttype_id'];
+ else {
+ error(_('Please select a shift type.'));
+ redirect(page_link_to('admin_import'));
+ }
list($rooms_new, $rooms_deleted) = prepare_rooms($import_file);
- list($events_new, $events_updated, $events_deleted) = prepare_events($import_file);
+ list($events_new, $events_updated, $events_deleted) = prepare_events($import_file, $shifttype_id);
- $html .= form(array(
- '<h3>' . _("Rooms to create") . '</h3>',
- table(_("Name"), $rooms_new),
- '<h3>' . _("Rooms to delete") . '</h3>',
- table(_("Name"), $rooms_deleted),
+ $html .= form([
+ div('row', [
+ div('col-sm-6', [
+ '<h3>' . _("Rooms to create") . '</h3>',
+ table(_("Name"), $rooms_new)
+ ]),
+ div('col-sm-6', [
+ '<h3>' . _("Rooms to delete") . '</h3>',
+ table(_("Name"), $rooms_deleted)
+ ])
+ ]),
'<h3>' . _("Shifts to create") . '</h3>',
table(array(
'day' => _("Day"),
'start' => _("Start"),
'end' => _("End"),
- 'name' => _("Name"),
+ 'shifttype' => _('Shift type'),
+ 'title' => _("Title"),
'room' => _("Room")
- ), shifts_printable($events_new)),
+ ), shifts_printable($events_new, $shifttypes)),
'<h3>' . _("Shifts to update") . '</h3>',
table(array(
'day' => _("Day"),
'start' => _("Start"),
'end' => _("End"),
- 'name' => _("Name"),
+ 'shifttype' => _('Shift type'),
+ 'title' => _("Title"),
'room' => _("Room")
- ), shifts_printable($events_updated)),
+ ), shifts_printable($events_updated, $shifttypes)),
'<h3>' . _("Shifts to delete") . '</h3>',
table(array(
'day' => _("Day"),
'start' => _("Start"),
'end' => _("End"),
- 'name' => _("Name"),
+ 'shifttype' => _('Shift type'),
+ 'title' => _("Title"),
'room' => _("Room")
- ), shifts_printable($events_deleted)),
+ ), shifts_printable($events_deleted, $shifttypes)),
form_submit('submit', _("Import"))
- ), page_link_to('admin_import') . '&step=import');
+ ], page_link_to('admin_import') . '&step=import&shifttype_id=' . $shifttype_id);
break;
- case "import":
+ case 'import':
+ if (! file_exists($import_file)) {
+ error(_('Missing import file.'));
+ redirect(page_link_to('admin_import'));
+ }
+
if (! file_exists($import_file))
redirect(page_link_to('admin_import'));
+ if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']]))
+ $shifttype_id = $_REQUEST['shifttype_id'];
+ else {
+ error(_('Please select a shift type.'));
+ redirect(page_link_to('admin_import'));
+ }
+
list($rooms_new, $rooms_deleted) = prepare_rooms($import_file);
foreach ($rooms_new as $room) {
sql_query("INSERT INTO `Room` SET `Name`='" . sql_escape($room) . "', `FromPentabarf`='Y', `Show`='Y'");
@@ -116,7 +166,7 @@ function admin_import() {
foreach ($rooms_deleted as $room)
sql_query("DELETE FROM `Room` WHERE `Name`='" . sql_escape($room) . "' LIMIT 1");
- list($events_new, $events_updated, $events_deleted) = prepare_events($import_file);
+ list($events_new, $events_updated, $events_deleted) = prepare_events($import_file, $shifttype_id);
foreach ($events_new as $event) {
$result = Shift_create($event);
if ($result === false)
@@ -145,7 +195,10 @@ function admin_import() {
redirect(page_link_to('admin_import'));
}
- return $html;
+ return page_with_title(admin_import_title(), [
+ msg(),
+ $html
+ ]);
}
function prepare_rooms($file) {
@@ -179,7 +232,7 @@ function prepare_rooms($file) {
);
}
-function prepare_events($file) {
+function prepare_events($file, $shifttype_id) {
global $rooms_import;
$data = read_xml($file);
@@ -195,10 +248,11 @@ function prepare_events($file) {
$event_id = trim($event_pb->{
'event-id' });
$shifts_pb[$event_id] = array(
+ 'shifttype_id' => $shifttype_id,
'start' => DateTime::createFromFormat("Ymd\THis", $event->dtstart)->getTimestamp(),
'end' => DateTime::createFromFormat("Ymd\THis", $event->dtend)->getTimestamp(),
'RID' => $rooms_import[trim($event->location)],
- 'name' => trim($event->summary),
+ 'title' => trim($event->summary),
'URL' => trim($event->url),
'PSID' => $event_id
);
@@ -209,14 +263,14 @@ function prepare_events($file) {
foreach ($shifts as $shift)
$shifts_db[$shift['PSID']] = $shift;
- $shifts_new = array();
- $shifts_updated = array();
+ $shifts_new = [];
+ $shifts_updated = [];
foreach ($shifts_pb as $shift)
if (! isset($shifts_db[$shift['PSID']]))
$shifts_new[] = $shift;
else {
$tmp = $shifts_db[$shift['PSID']];
- if ($shift['name'] != $tmp['name'] || $shift['start'] != $tmp['start'] || $shift['end'] != $tmp['end'] || $shift['RID'] != $tmp['RID'] || $shift['URL'] != $tmp['URL'])
+ if ($shift['shifttype_id'] != $tmp['shifttype_id'] || $shift['title'] != $tmp['title'] || $shift['start'] != $tmp['start'] || $shift['end'] != $tmp['end'] || $shift['RID'] != $tmp['RID'] || $shift['URL'] != $tmp['URL'])
$shifts_updated[] = $shift;
}
@@ -239,7 +293,7 @@ function read_xml($file) {
return $xml_import;
}
-function shifts_printable($shifts) {
+function shifts_printable($shifts, $shifttypes) {
global $rooms_import;
$rooms = array_flip($rooms_import);
@@ -250,7 +304,11 @@ function shifts_printable($shifts) {
$shifts_printable[] = array(
'day' => date("l, Y-m-d", $shift['start']),
'start' => date("H:i", $shift['start']),
- 'name' => shorten($shift['name']),
+ 'shifttype' => ShiftType_name_render([
+ 'id' => $shift['shifttype_id'],
+ 'name' => $shifttypes[$shift['shifttype_id']]
+ ]),
+ 'title' => shorten($shift['title']),
'end' => date("H:i", $shift['end']),
'room' => $rooms[$shift['RID']]
);
diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php
index 9ec79438..a727bbcb 100644
--- a/includes/pages/user_shifts.php
+++ b/includes/pages/user_shifts.php
@@ -9,6 +9,12 @@ function user_shifts() {
if (User_is_freeloader($user))
redirect(page_link_to('user_myshifts'));
+
+ // Locations laden
+ $rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
+ $room_array = array();
+ foreach ($rooms as $room)
+ $room_array[$room['RID']] = $room['Name'];
// Löschen einzelner Schicht-Einträge (Also Belegung einer Schicht von Engeln) durch Admins
if (isset($_REQUEST['entry_id']) && in_array('user_shifts_admin', $privileges)) {
@@ -56,12 +62,6 @@ function user_shifts() {
if (count($shift) == 0)
redirect(page_link_to('user_shifts'));
$shift = $shift[0];
-
- // Locations laden
- $rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
- $room_array = array();
- foreach ($rooms as $room)
- $room_array[$room['RID']] = $room['Name'];
// Engeltypen laden
$types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
@@ -179,17 +179,13 @@ function user_shifts() {
else
redirect(page_link_to('user_shifts'));
- $shift = sql_select("
- SELECT `Shifts`.*, `ShiftTypes`.`name`, `Room`.*
- FROM `Shifts`
- JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
- JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
- WHERE `SID`=" . sql_escape($shift_id));
- if (count($shift) == 0)
+ $shift = Shift($shift_id);
+ if ($shift === false)
+ engelsystem_error('Unable to load shift.');
+ if ($shift == null)
redirect(page_link_to('user_shifts'));
- $shift = $shift[0];
-
- // Schicht löschen bestätigt
+
+ // Schicht löschen bestätigt
if (isset($_REQUEST['delete'])) {
$result = Shift_delete($shift_id);
if ($result === false)
@@ -210,15 +206,13 @@ function user_shifts() {
else
redirect(page_link_to('user_shifts'));
- $shift = sql_select("
- SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.*
- FROM `Shifts`
- JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
- JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
- WHERE `SID`=" . sql_escape($shift_id));
- if (count($shift) == 0)
+ $shift = Shift($shift_id);
+ $room;
+ $shift['Name'] = $room_array[$shift['RID']];
+ if ($shift === false)
+ engelsystem_error('Unable to load shift.');
+ if ($shift == null)
redirect(page_link_to('user_shifts'));
- $shift = $shift[0];
if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id']))
$type_id = $_REQUEST['type_id'];
@@ -434,7 +428,7 @@ function view_user_shifts() {
0
);
- $SQL = "SELECT DISTINCT `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name` as `room_name`, nat2.`special_needs` > 0 AS 'has_special_needs'
+ $SQL = "SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`, nat2.`special_needs` > 0 AS 'has_special_needs'
FROM `Shifts`
INNER JOIN `Room` USING (`RID`)
INNER JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
@@ -454,7 +448,9 @@ function view_user_shifts() {
}
$SQL .= "
ORDER BY `start`";
+
$shifts = sql_select($SQL);
+
$ownshifts_source = sql_select("
SELECT `ShiftTypes`.`name`, `Shifts`.*
FROM `Shifts`
diff --git a/includes/sys_template.php b/includes/sys_template.php
index 56751e16..7ffe1529 100644
--- a/includes/sys_template.php
+++ b/includes/sys_template.php
@@ -9,6 +9,15 @@ $themes = array(
"2" => "Engelsystem 31c3"
);
+/**
+ * Display muted (grey) text.
+ *
+ * @param string $text
+ */
+function mute($text) {
+ return '<span class="text-muted">' . $text . '</span>';
+}
+
function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '') {
return '<div class="progress"><div class="progress-bar ' . $class . '" role="progressbar" aria-valuenow="' . $valuenow . '" aria-valuemin="' . $valuemin . '" aria-valuemax="' . $valuemax . '" style="width: ' . (($valuenow - $valuemin) * 100 / ($valuemax - $valuemin)) . '%">' . $content . '</div></div>';
}
@@ -195,7 +204,7 @@ function form_radio($name, $label, $selected, $value) {
*/
function form_info($label, $text = "") {
if ($label == "")
- return '<span class="help-block">' . $text . '</span>';
+ return '<span class="help-block">' . glyph('info-sign') . $text . '</span>';
if ($text == "")
return '<h4>' . $label . '</h4>';
return form_element($label, '<p class="form-control-static">' . $text . '</p>', '');