diff options
-rw-r--r-- | includes/mailer/shifts_mailer.php | 54 | ||||
-rw-r--r-- | includes/model/ShiftEntry_model.php | 18 |
2 files changed, 63 insertions, 9 deletions
diff --git a/includes/mailer/shifts_mailer.php b/includes/mailer/shifts_mailer.php index e69de29b..ffc1dea7 100644 --- a/includes/mailer/shifts_mailer.php +++ b/includes/mailer/shifts_mailer.php @@ -0,0 +1,54 @@ +<?php + +function mail_shift_change($old_shift, $new_shift) { + + $users = ShiftEntries_by_shift($old_shift["SID"]); + $old_room = Room($old_shift["RID"]); + $new_room = Room($new_shift["RID"]); + + foreach ($users as $user) { + if ($user["email_shiftinfo"]) { + + $noticable_changes = false; + + $message = _("A Shift you are registered on has changed:"); + $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"; + $noticable_changes = true; + } + + if($old_shift["start"] != $new_shift["start"]) { + $message .= sprintf(_("* Shift Start changed from %s to %s"),date("y-m-d H:i", $old_shift["start"]), date("y-m-d H:i", $new_shift["start"])) . "\n"; + $noticable_changes = true; + } + + if($old_shift["end"] != $new_shift["end"]) { + $message .= sprintf(_("* Shift End changed from %s to %s"),date("y-m-d H:i", $old_shift["end"]), date("y-m-d H:i", $new_shift["end"])) . "\n"; + $noticable_changes = true; + } + + if($old_shift["RID"] != $new_shift["RID"]) { + $message .= sprintf(_("* Shift Location changed from %s to %s"), $old_room["Name"], $new_room["Name"]) . "\n"; + $noticable_changes = true; + } + + if (!noticable_changes) { + //There are no changes worth sending an E-Mail + return; + } + + $message .= "\n"; + $message .= _("The updated Shift:") . "\n"; + + $message .= $new_shift["name"] . "\n"; + $message .= date("y-m-d H:i", $new_shift["start"]) . " - " . date("y-m-d H:i", $new_shift["end"]) . "\n"; + $message .= $new_room["Name"] . "\n"; + + engelsystem_email_to_user($user, _("[Angelsystem] Your Shift has changed"), $message); + } + } +} + +?> diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index 903bc544..0cf5c040 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -22,7 +22,7 @@ function ShiftEntries_by_shift($shift_id) { /** * Create a new shift entry. * - * @param ShiftEntry $shift_entry + * @param ShiftEntry $shift_entry */ function ShiftEntry_create($shift_entry) { return sql_query("INSERT INTO `ShiftEntry` SET @@ -55,7 +55,7 @@ function ShiftEntry_delete($shift_entry_id) { /** * Returns next (or current) shifts of given user. * - * @param User $user + * @param User $user */ function ShiftEntries_upcoming_for_user($user) { return sql_select(" @@ -71,12 +71,12 @@ function ShiftEntries_upcoming_for_user($user) { /** * Returns all shift entries in given shift for given angeltype. * - * @param int $shift_id - * @param int $angeltype_id + * @param int $shift_id + * @param int $angeltype_id */ function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) { return sql_select(" - SELECT * + SELECT * FROM `ShiftEntry` WHERE `SID`=" . sql_escape($shift_id) . " AND `TID`=" . sql_escape($angeltype_id) . " @@ -87,10 +87,10 @@ function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) { * Returns all freeloaded shifts for given user. */ function ShiftEntries_freeloaded_by_user($user) { - return sql_select("SELECT * - FROM `ShiftEntry` - WHERE `freeloaded` = 1 + return sql_select("SELECT * + FROM `ShiftEntry` + WHERE `freeloaded` = 1 AND `UID`=" . sql_escape($user['UID'])); } -?>
\ No newline at end of file +?> |