summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/mailer/shifts_mailer.php74
-rw-r--r--includes/model/ShiftEntry_model.php23
-rw-r--r--includes/model/Shifts_model.php2
3 files changed, 53 insertions, 46 deletions
diff --git a/includes/mailer/shifts_mailer.php b/includes/mailer/shifts_mailer.php
index c9d20976..cd34274f 100644
--- a/includes/mailer/shifts_mailer.php
+++ b/includes/mailer/shifts_mailer.php
@@ -1,96 +1,90 @@
<?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"]);
-
+
$noticable_changes = false;
-
+
$message = _("A Shift you are registered on has changed:");
- $message .="\n";
-
- if($old_shift["name"] != $new_shift["name"]) {
+ $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";
+
+ 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";
+
+ 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"]) {
+
+ 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
+
+ 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("H:i", $new_shift["end"]) . "\n";
$message .= $new_room["Name"] . "\n";
-
- foreach ($users as $user) {
- if ($user["email_shiftinfo"]) {
- engelsystem_email_to_user($user, _("[Angelsystem] Your Shift has changed"), $message);
- }
- }
+
+ foreach ($users as $user)
+ if ($user["email_shiftinfo"])
+ engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift has changed"), $message);
}
function mail_shift_delete($shift) {
-
$users = ShiftEntries_by_shift($shift["SID"]);
$room = Room($shift["RID"]);
-
+
$message = _("A Shift you are registered on was deleted:") . "\n";
-
+
$message .= $shift["name"] . "\n";
$message .= date("y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
$message .= $room["Name"] . "\n";
-
- foreach ($users as $user) {
- if ($user["email_shiftinfo"]) {
- engelsystem_email_to_user($user, _("[Angelsystem] Your Shift was deleted"), $message);
- }
- }
+
+ foreach ($users as $user)
+ if ($user["email_shiftinfo"])
+ engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift was deleted"), $message);
}
function mail_shift_assign($user, $shift) {
if ($user["email_shiftinfo"]) {
$room = Room($shift["RID"]);
-
+
$message = _("You have been assigned to a Shift:") . "\n";
$message .= $shift["name"] . "\n";
$message .= date("y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
$message .= $room["Name"] . "\n";
-
- engelsystem_email_to_user($user, _("[Angelsystem] Assigned to Shift"), $message);
+
+ engelsystem_email_to_user($user, '[engelsystem] ' . _("Assigned to Shift"), $message);
}
}
function mail_shift_removed($user, $shift) {
if ($user["email_shiftinfo"]) {
$room = Room($shift["RID"]);
-
+
$message = _("You have been removed from a Shift:") . "\n";
$message .= $shift["name"] . "\n";
$message .= date("y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n";
$message .= $room["Name"] . "\n";
-
- engelsystem_email_to_user($user, _("[Angelsystem] Assigned to Shift"), $message);
+
+ engelsystem_email_to_user($user, '[engelsystem] ' . _("Removed from Shift"), $message);
}
}
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index 0cf5c040..e1f0cd2e 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -22,9 +22,10 @@ function ShiftEntries_by_shift($shift_id) {
/**
* Create a new shift entry.
*
- * @param ShiftEntry $shift_entry
+ * @param ShiftEntry $shift_entry
*/
function ShiftEntry_create($shift_entry) {
+ mail_shift_assign(User($shift_entry['UID']), Shift($shift_entry['SID']));
return sql_query("INSERT INTO `ShiftEntry` SET
`SID`=" . sql_escape($shift_entry['SID']) . ",
`TID`=" . sql_escape($shift_entry['TID']) . ",
@@ -46,16 +47,30 @@ function ShiftEntry_update($shift_entry) {
}
/**
+ * Get a shift entry.
+ */
+function ShiftEntry($shift_entry_id) {
+ $shift_entry = sql_select("SELECT * FROM `ShiftEntry` WHERE `id`=" . sql_escape($shift_entry_id));
+ if ($shift_entry === false)
+ return false;
+ if (count($shift_entry) == 0)
+ return null;
+ return $shift_entry[0];
+}
+
+/**
* Delete a shift entry.
*/
function ShiftEntry_delete($shift_entry_id) {
+ $shift_entry = ShiftEntry($shift_entry_id);
+ mail_shift_removed(User($shift_entry['UID']), Shift($shift_entry['SID']));
return sql_query("DELETE FROM `ShiftEntry` WHERE `id`=" . sql_escape($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,8 +86,8 @@ 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("
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 11309e11..8530a0c8 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -11,7 +11,6 @@ function Shift_delete_by_psid($shift_psid) {
* Delete a shift.
*/
function Shift_delete($shift_id) {
-
mail_shift_delete(Shift($shift_id));
return sql_query("DELETE FROM `Shifts` WHERE `SID`=" . sql_escape($shift_id));
@@ -21,7 +20,6 @@ function Shift_delete($shift_id) {
* Update a shift.
*/
function Shift_update($shift) {
-
$old_shift = Shift($shift['SID']);
mail_shift_change(Shift($shift['SID']), $shift);