fix different bugs with shift types

main
Philip Häusler 10 years ago
parent 702047de53
commit 2d587478a1

@ -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";

@ -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) {

@ -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>';
$import_file = '../import/import_' . $user['UID'] . '.xml';
switch ($step) {
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.");
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':
$ok = false;
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(
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(
$html .= form([
div('row', [
div('col-sm-6', [
'<h3>' . _("Rooms to create") . '</h3>',
table(_("Name"), $rooms_new),
table(_("Name"), $rooms_new)
]),
div('col-sm-6', [
'<h3>' . _("Rooms to delete") . '</h3>',
table(_("Name"), $rooms_deleted),
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']]
);

@ -10,6 +10,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)) {
if (isset($_REQUEST['entry_id']) && test_request_int('entry_id'))
@ -57,12 +63,6 @@ function user_shifts() {
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`");
$angel_types = array();
@ -179,15 +179,11 @@ 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
if (isset($_REQUEST['delete'])) {
@ -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`

@ -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>', '');

Loading…
Cancel
Save