summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
authorBot <bot@myigel.name>2017-01-02 03:57:23 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2017-01-02 03:57:23 +0100
commit7313e15ce8236e19331fb6639a3a5b97c8f06ecd (patch)
tree399e5eaa403d6dd5993ca8fb6f2162319d2ed2e1 /includes/model
parentb839e401062b294292fdcbd7e30b79bc149fab6f (diff)
PSR-2 formatting
Diffstat (limited to 'includes/model')
-rw-r--r--includes/model/AngelType_model.php193
-rw-r--r--includes/model/EventConfig_model.php45
-rw-r--r--includes/model/LogEntries_model.php28
-rw-r--r--includes/model/Message_model.php45
-rw-r--r--includes/model/NeededAngelTypes_model.php72
-rw-r--r--includes/model/Room_model.php48
-rw-r--r--includes/model/ShiftEntry_model.php97
-rw-r--r--includes/model/ShiftSignupState.php53
-rw-r--r--includes/model/ShiftTypes_model.php65
-rw-r--r--includes/model/ShiftsFilter.php134
-rw-r--r--includes/model/Shifts_model.php369
-rw-r--r--includes/model/UserAngelTypes_model.php187
-rw-r--r--includes/model/UserDriverLicenses_model.php77
-rw-r--r--includes/model/UserGroups_model.php7
-rw-r--r--includes/model/User_model.php335
-rw-r--r--includes/model/ValidationResult.php26
16 files changed, 942 insertions, 839 deletions
diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php
index 8d6a89b3..022462c0 100644
--- a/includes/model/AngelType_model.php
+++ b/includes/model/AngelType_model.php
@@ -5,8 +5,9 @@ use Engelsystem\ValidationResult;
* Returns an array containing the basic attributes of angeltypes.
* FIXME! This is the big sign for needing entity objects
*/
-function AngelType_new() {
- return [
+function AngelType_new()
+{
+ return [
'id' => null,
'name' => "",
'restricted' => false,
@@ -16,7 +17,7 @@ function AngelType_new() {
'contact_user_id' => null,
'contact_name' => null,
'contact_dect' => null,
- 'contact_email' => null
+ 'contact_email' => null
];
}
@@ -27,17 +28,18 @@ function AngelType_new() {
* The angeltype
* @return ValidationResult
*/
-function AngelType_validate_contact_user_id($angeltype) {
- if (! isset($angeltype['contact_user_id'])) {
- return new ValidationResult(true, null);
- }
- if (isset($angeltype['contact_name']) || isset($angeltype['contact_dect']) || isset($angeltype['contact_email'])) {
- return new ValidationResult(false, $angeltype['contact_user_id']);
- }
- if (User($angeltype['contact_user_id']) == null) {
- return new ValidationResult(false, $angeltype['contact_user_id']);
- }
- return new ValidationResult(true, $angeltype['contact_user_id']);
+function AngelType_validate_contact_user_id($angeltype)
+{
+ if (! isset($angeltype['contact_user_id'])) {
+ return new ValidationResult(true, null);
+ }
+ if (isset($angeltype['contact_name']) || isset($angeltype['contact_dect']) || isset($angeltype['contact_email'])) {
+ return new ValidationResult(false, $angeltype['contact_user_id']);
+ }
+ if (User($angeltype['contact_user_id']) == null) {
+ return new ValidationResult(false, $angeltype['contact_user_id']);
+ }
+ return new ValidationResult(true, $angeltype['contact_user_id']);
}
/**
@@ -46,43 +48,45 @@ function AngelType_validate_contact_user_id($angeltype) {
* @param Angeltype $angeltype
* The angeltype
*/
-function AngelType_contact_info($angeltype) {
- if (isset($angeltype['contact_user_id'])) {
- $contact_user = User($angeltype['contact_user_id']);
- $contact_data = [
+function AngelType_contact_info($angeltype)
+{
+ if (isset($angeltype['contact_user_id'])) {
+ $contact_user = User($angeltype['contact_user_id']);
+ $contact_data = [
'contact_name' => $contact_user['Nick'],
- 'contact_dect' => $contact_user['DECT']
+ 'contact_dect' => $contact_user['DECT']
];
- if ($contact_user['email_by_human_allowed']) {
- $contact_data['contact_email'] = $contact_user['email'];
+ if ($contact_user['email_by_human_allowed']) {
+ $contact_data['contact_email'] = $contact_user['email'];
+ }
+ return $contact_data;
}
- return $contact_data;
- }
- if (isset($angeltype['contact_name'])) {
- return [
+ if (isset($angeltype['contact_name'])) {
+ return [
'contact_name' => $angeltype['contact_name'],
'contact_dect' => $angeltype['contact_dect'],
- 'contact_email' => $angeltype['contact_email']
+ 'contact_email' => $angeltype['contact_email']
];
- }
- return null;
+ }
+ return null;
}
/**
* Delete an Angeltype.
*
- * @param Angeltype $angeltype
+ * @param Angeltype $angeltype
*/
-function AngelType_delete($angeltype) {
- $result = sql_query("
+function AngelType_delete($angeltype)
+{
+ $result = sql_query("
DELETE FROM `AngelTypes`
WHERE `id`='" . sql_escape($angeltype['id']) . "'
LIMIT 1");
- if ($result === false) {
- engelsystem_error("Unable to delete angeltype.");
- }
- engelsystem_log("Deleted angeltype: " . AngelType_name_render($angeltype));
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to delete angeltype.");
+ }
+ engelsystem_log("Deleted angeltype: " . AngelType_name_render($angeltype));
+ return $result;
}
/**
@@ -91,8 +95,9 @@ function AngelType_delete($angeltype) {
* @param Angeltype $angeltype
* The angeltype
*/
-function AngelType_update($angeltype) {
- $result = sql_query("
+function AngelType_update($angeltype)
+{
+ $result = sql_query("
UPDATE `AngelTypes` SET
`name`='" . sql_escape($angeltype['name']) . "',
`restricted`=" . sql_bool($angeltype['restricted']) . ",
@@ -104,11 +109,11 @@ function AngelType_update($angeltype) {
`contact_dect`=" . sql_null($angeltype['contact_dect']) . ",
`contact_email`=" . sql_null($angeltype['contact_email']) . "
WHERE `id`='" . sql_escape($angeltype['id']) . "'");
- if ($result === false) {
- engelsystem_error("Unable to update angeltype.");
- }
- engelsystem_log("Updated angeltype: " . $angeltype['name'] . ($angeltype['restricted'] ? ", restricted" : "") . ($angeltype['no_self_signup'] ? ", no_self_signup" : "") . ($angeltype['requires_driver_license'] ? ", requires driver license" : ""));
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to update angeltype.");
+ }
+ engelsystem_log("Updated angeltype: " . $angeltype['name'] . ($angeltype['restricted'] ? ", restricted" : "") . ($angeltype['no_self_signup'] ? ", no_self_signup" : "") . ($angeltype['requires_driver_license'] ? ", requires driver license" : ""));
+ return $result;
}
/**
@@ -118,8 +123,9 @@ function AngelType_update($angeltype) {
* The angeltype
* @return the created angeltype
*/
-function AngelType_create($angeltype) {
- $result = sql_query("
+function AngelType_create($angeltype)
+{
+ $result = sql_query("
INSERT INTO `AngelTypes` SET
`name`='" . sql_escape($angeltype['name']) . "',
`restricted`=" . sql_bool($angeltype['restricted']) . ",
@@ -130,12 +136,12 @@ function AngelType_create($angeltype) {
`contact_name`=" . sql_null($angeltype['contact_name']) . ",
`contact_dect`=" . sql_null($angeltype['contact_dect']) . ",
`contact_email`=" . sql_null($angeltype['contact_email']));
- if ($result === false) {
- engelsystem_error("Unable to create angeltype.");
- }
- $angeltype['id'] = sql_id();
- engelsystem_log("Created angeltype: " . $angeltype['name'] . ($angeltype['restricted'] ? ", restricted" : "") . ($angeltype['requires_driver_license'] ? ", requires driver license" : ""));
- return $angeltype;
+ if ($result === false) {
+ engelsystem_error("Unable to create angeltype.");
+ }
+ $angeltype['id'] = sql_id();
+ engelsystem_log("Created angeltype: " . $angeltype['name'] . ($angeltype['restricted'] ? ", restricted" : "") . ($angeltype['requires_driver_license'] ? ", requires driver license" : ""));
+ return $angeltype;
}
/**
@@ -148,35 +154,37 @@ function AngelType_create($angeltype) {
* The angeltype the name is for
* @return ValidationResult result and validated name
*/
-function AngelType_validate_name($name, $angeltype) {
- $name = strip_item($name);
- if ($name == "") {
- return new ValidationResult(false, "");
- }
- if ($angeltype != null && isset($angeltype['id'])) {
- $valid = sql_num_query("
+function AngelType_validate_name($name, $angeltype)
+{
+ $name = strip_item($name);
+ if ($name == "") {
+ return new ValidationResult(false, "");
+ }
+ if ($angeltype != null && isset($angeltype['id'])) {
+ $valid = sql_num_query("
SELECT *
FROM `AngelTypes`
WHERE `name`='" . sql_escape($name) . "'
AND NOT `id`='" . sql_escape($angeltype['id']) . "'
LIMIT 1") == 0;
- return new ValidationResult($valid, $name);
- }
- $valid = sql_num_query("
+ return new ValidationResult($valid, $name);
+ }
+ $valid = sql_num_query("
SELECT `id`
FROM `AngelTypes`
WHERE `name`='" . sql_escape($name) . "'
LIMIT 1") == 0;
- return new ValidationResult($valid, $name);
+ return new ValidationResult($valid, $name);
}
/**
* Returns all angeltypes and subscription state to each of them for given user.
*
- * @param User $user
+ * @param User $user
*/
-function AngelTypes_with_user($user) {
- $result = sql_select("
+function AngelTypes_with_user($user)
+{
+ $result = sql_select("
SELECT `AngelTypes`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`,
@@ -185,35 +193,37 @@ function AngelTypes_with_user($user) {
LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id`
AND `UserAngelTypes`.`user_id`=" . $user['UID'] . "
ORDER BY `name`");
- if ($result === false) {
- engelsystem_error("Unable to load angeltypes.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to load angeltypes.");
+ }
+ return $result;
}
/**
* Returns all angeltypes.
*/
-function AngelTypes() {
- $result = sql_select("
+function AngelTypes()
+{
+ $result = sql_select("
SELECT *
FROM `AngelTypes`
ORDER BY `name`");
- if ($result === false) {
- engelsystem_error("Unable to load angeltypes.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to load angeltypes.");
+ }
+ return $result;
}
/**
* Returns AngelType id array
*/
-function AngelType_ids() {
- $result = sql_select("SELECT `id` FROM `AngelTypes`");
- if ($result === false) {
- engelsystem_error("Unable to load angeltypes.");
- }
- return select_array($result, 'id', 'id');
+function AngelType_ids()
+{
+ $result = sql_select("SELECT `id` FROM `AngelTypes`");
+ if ($result === false) {
+ engelsystem_error("Unable to load angeltypes.");
+ }
+ return select_array($result, 'id', 'id');
}
/**
@@ -222,15 +232,14 @@ function AngelType_ids() {
* @param $angeltype_id angelType
* ID
*/
-function AngelType($angeltype_id) {
- $angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "'");
- if ($angelType_source === false) {
- engelsystem_error("Unable to load angeltype.");
- }
- if (count($angelType_source) > 0) {
- return $angelType_source[0];
- }
- return null;
+function AngelType($angeltype_id)
+{
+ $angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "'");
+ if ($angelType_source === false) {
+ engelsystem_error("Unable to load angeltype.");
+ }
+ if (count($angelType_source) > 0) {
+ return $angelType_source[0];
+ }
+ return null;
}
-
-?>
diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php
index de5073d0..b4fdb728 100644
--- a/includes/model/EventConfig_model.php
+++ b/includes/model/EventConfig_model.php
@@ -3,39 +3,41 @@
/**
* Get event config.
*/
-function EventConfig() {
- $event_config = sql_select("SELECT * FROM `EventConfig` LIMIT 1");
- if ($event_config === false) {
- engelsystem_error("Unable to load event config.");
- return false;
- }
- if (count($event_config) > 0) {
- return $event_config[0];
- }
- return null;
+function EventConfig()
+{
+ $event_config = sql_select("SELECT * FROM `EventConfig` LIMIT 1");
+ if ($event_config === false) {
+ engelsystem_error("Unable to load event config.");
+ return false;
+ }
+ if (count($event_config) > 0) {
+ return $event_config[0];
+ }
+ return null;
}
/**
* Update event config.
*
- * @param string $event_name
- * @param int $buildup_start_date
- * @param int $event_start_date
- * @param int $event_end_date
- * @param int $teardown_end_date
- * @param string $event_welcome_msg
+ * @param string $event_name
+ * @param int $buildup_start_date
+ * @param int $event_start_date
+ * @param int $event_end_date
+ * @param int $teardown_end_date
+ * @param string $event_welcome_msg
*/
-function EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg) {
- if (EventConfig() == null) {
- return sql_query("INSERT INTO `EventConfig` SET
+function EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg)
+{
+ if (EventConfig() == null) {
+ return sql_query("INSERT INTO `EventConfig` SET
`event_name`=" . sql_null($event_name) . ",
`buildup_start_date`=" . sql_null($buildup_start_date) . ",
`event_start_date`=" . sql_null($event_start_date) . ",
`event_end_date`=" . sql_null($event_end_date) . ",
`teardown_end_date`=" . sql_null($teardown_end_date) . ",
`event_welcome_msg`=" . sql_null($event_welcome_msg));
- }
- return sql_query("UPDATE `EventConfig` SET
+ }
+ return sql_query("UPDATE `EventConfig` SET
`event_name`=" . sql_null($event_name) . ",
`buildup_start_date`=" . sql_null($buildup_start_date) . ",
`event_start_date`=" . sql_null($event_start_date) . ",
@@ -43,4 +45,3 @@ function EventConfig_update($event_name, $buildup_start_date, $event_start_date,
`teardown_end_date`=" . sql_null($teardown_end_date) . ",
`event_welcome_msg`=" . sql_null($event_welcome_msg));
}
-?>
diff --git a/includes/model/LogEntries_model.php b/includes/model/LogEntries_model.php
index 09bd03dc..2a3a1d6e 100644
--- a/includes/model/LogEntries_model.php
+++ b/includes/model/LogEntries_model.php
@@ -7,32 +7,34 @@
* @param $message Log
* Message
*/
-function LogEntry_create($nick, $message) {
- return sql_query("INSERT INTO `LogEntries` SET `timestamp`='" . sql_escape(time()) . "', `nick`='" . sql_escape($nick) . "', `message`='" . sql_escape($message) . "'");
+function LogEntry_create($nick, $message)
+{
+ return sql_query("INSERT INTO `LogEntries` SET `timestamp`='" . sql_escape(time()) . "', `nick`='" . sql_escape($nick) . "', `message`='" . sql_escape($message) . "'");
}
/**
* Returns log entries with maximum count of 10000.
*/
-function LogEntries() {
- return sql_select("SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000");
+function LogEntries()
+{
+ return sql_select("SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000");
}
/**
* Returns log entries filtered by a keyword
*/
-function LogEntries_filter($keyword) {
- if ($keyword == "") {
- return LogEntries();
- }
- return sql_select("SELECT * FROM `LogEntries` WHERE `nick` LIKE '%" . sql_escape($keyword) . "%' OR `message` LIKE '%" . sql_escape($keyword) . "%' ORDER BY `timestamp` DESC");
+function LogEntries_filter($keyword)
+{
+ if ($keyword == "") {
+ return LogEntries();
+ }
+ return sql_select("SELECT * FROM `LogEntries` WHERE `nick` LIKE '%" . sql_escape($keyword) . "%' OR `message` LIKE '%" . sql_escape($keyword) . "%' ORDER BY `timestamp` DESC");
}
/**
* Delete all log entries.
*/
-function LogEntries_clear_all() {
- return sql_query("TRUNCATE `LogEntries`");
+function LogEntries_clear_all()
+{
+ return sql_query("TRUNCATE `LogEntries`");
}
-
-?>
diff --git a/includes/model/Message_model.php b/includes/model/Message_model.php
index 652b60ea..6ee19792 100644
--- a/includes/model/Message_model.php
+++ b/includes/model/Message_model.php
@@ -3,8 +3,9 @@
/**
* Returns Message id array
*/
-function Message_ids() {
- return sql_select("SELECT `id` FROM `Messages`");
+function Message_ids()
+{
+ return sql_select("SELECT `id` FROM `Messages`");
}
/**
@@ -13,15 +14,16 @@ function Message_ids() {
* @param $message_id message
* ID
*/
-function Message($message_id) {
- $message_source = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
- if ($message_source === false) {
- return false;
- }
- if (count($message_source) > 0) {
- return $message_source[0];
- }
- return null;
+function Message($message_id)
+{
+ $message_source = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
+ if ($message_source === false) {
+ return false;
+ }
+ if (count($message_source) > 0) {
+ return $message_source[0];
+ }
+ return null;
}
/**
@@ -34,18 +36,17 @@ function Message($message_id) {
* @param $text Text
* of Message
*/
-function Message_send($receiver_user_id, $text) {
- global $user;
+function Message_send($receiver_user_id, $text)
+{
+ global $user;
- $text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($text));
- $receiver_user_id = preg_replace("/([^0-9]{1,})/ui", '', strip_tags($receiver_user_id));
+ $text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($text));
+ $receiver_user_id = preg_replace("/([^0-9]{1,})/ui", '', strip_tags($receiver_user_id));
- if (($text != "" && is_numeric($receiver_user_id)) && (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($receiver_user_id) . "' AND NOT `UID`='" . sql_escape($user['UID']) . "' LIMIT 1") > 0)) {
- sql_query("INSERT INTO `Messages` SET `Datum`='" . sql_escape(time()) . "', `SUID`='" . sql_escape($user['UID']) . "', `RUID`='" . sql_escape($receiver_user_id) . "', `Text`='" . sql_escape($text) . "'");
- return true;
- }
+ if (($text != "" && is_numeric($receiver_user_id)) && (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($receiver_user_id) . "' AND NOT `UID`='" . sql_escape($user['UID']) . "' LIMIT 1") > 0)) {
+ sql_query("INSERT INTO `Messages` SET `Datum`='" . sql_escape(time()) . "', `SUID`='" . sql_escape($user['UID']) . "', `RUID`='" . sql_escape($receiver_user_id) . "', `Text`='" . sql_escape($text) . "'");
+ return true;
+ }
- return false;
+ return false;
}
-
-?> \ No newline at end of file
diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php
index 3bd3660f..e2661b9a 100644
--- a/includes/model/NeededAngelTypes_model.php
+++ b/includes/model/NeededAngelTypes_model.php
@@ -16,17 +16,18 @@
* @param int $count
* How many angels are needed?
*/
-function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count) {
- $result = sql_query("
+function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count)
+{
+ $result = sql_query("
INSERT INTO `NeededAngelTypes` SET
`shift_id`=" . sql_null($shift_id) . ",
`angel_type_id`='" . sql_escape($angeltype_id) . "',
`room_id`=" . sql_null($room_id) . ",
`count`='" . sql_escape($count) . "'");
- if ($result === false) {
- return false;
- }
- return sql_id();
+ if ($result === false) {
+ return false;
+ }
+ return sql_id();
}
/**
@@ -35,8 +36,9 @@ function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count) {
* @param int $shift_id
* id of the shift
*/
-function NeededAngelTypes_delete_by_shift($shift_id) {
- return sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`='" . sql_escape($shift_id) . "'");
+function NeededAngelTypes_delete_by_shift($shift_id)
+{
+ return sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`='" . sql_escape($shift_id) . "'");
}
/**
@@ -45,8 +47,9 @@ function NeededAngelTypes_delete_by_shift($shift_id) {
* @param int $room_id
* id of the room
*/
-function NeededAngelTypes_delete_by_room($room_id) {
- return sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
+function NeededAngelTypes_delete_by_room($room_id)
+{
+ return sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
}
/**
@@ -55,8 +58,9 @@ function NeededAngelTypes_delete_by_room($room_id) {
* @param int $shiftID
* id of shift
*/
-function NeededAngelTypes_by_shift($shiftId) {
- $needed_angeltypes_source = sql_select("
+function NeededAngelTypes_by_shift($shiftId)
+{
+ $needed_angeltypes_source = sql_select("
SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
FROM `NeededAngelTypes`
JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id`
@@ -64,13 +68,13 @@ function NeededAngelTypes_by_shift($shiftId) {
AND `count` > 0
ORDER BY `room_id` DESC
");
- if ($needed_angeltypes_source === false) {
- engelsystem_error("Unable to load needed angeltypes.");
- }
+ if ($needed_angeltypes_source === false) {
+ engelsystem_error("Unable to load needed angeltypes.");
+ }
// Use settings from room
if (count($needed_angeltypes_source) == 0) {
- $needed_angeltypes_source = sql_select("
+ $needed_angeltypes_source = sql_select("
SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted`
FROM `NeededAngelTypes`
JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id`
@@ -79,27 +83,25 @@ function NeededAngelTypes_by_shift($shiftId) {
AND `count` > 0
ORDER BY `room_id` DESC
");
- if ($needed_angeltypes_source === false) {
- engelsystem_error("Unable to load needed angeltypes.");
- }
+ if ($needed_angeltypes_source === false) {
+ engelsystem_error("Unable to load needed angeltypes.");
+ }
}
- $shift_entries = ShiftEntries_by_shift($shiftId);
- $needed_angeltypes = [];
- foreach ($needed_angeltypes_source as $angeltype) {
- $angeltype['shift_entries'] = [];
- $angeltype['taken'] = 0;
- foreach ($shift_entries as $shift_entry) {
- if ($shift_entry['TID'] == $angeltype['angel_type_id'] && $shift_entry['freeloaded'] == 0) {
- $angeltype['taken'] ++;
- $angeltype['shift_entries'][] = $shift_entry;
- }
- }
+ $shift_entries = ShiftEntries_by_shift($shiftId);
+ $needed_angeltypes = [];
+ foreach ($needed_angeltypes_source as $angeltype) {
+ $angeltype['shift_entries'] = [];
+ $angeltype['taken'] = 0;
+ foreach ($shift_entries as $shift_entry) {
+ if ($shift_entry['TID'] == $angeltype['angel_type_id'] && $shift_entry['freeloaded'] == 0) {
+ $angeltype['taken'] ++;
+ $angeltype['shift_entries'][] = $shift_entry;
+ }
+ }
- $needed_angeltypes[] = $angeltype;
- }
+ $needed_angeltypes[] = $angeltype;
+ }
- return $needed_angeltypes;
+ return $needed_angeltypes;
}
-
-?> \ No newline at end of file
diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php
index 6b6e269e..d7031d84 100644
--- a/includes/model/Room_model.php
+++ b/includes/model/Room_model.php
@@ -4,17 +4,19 @@
* returns a list of rooms.
* @param boolean $show_all returns also hidden rooms when true
*/
-function Rooms($show_all = false) {
- return sql_select("SELECT * FROM `Room`" . ($show_all ? "" : " WHERE `show`='Y'") . " ORDER BY `Name`");
+function Rooms($show_all = false)
+{
+ return sql_select("SELECT * FROM `Room`" . ($show_all ? "" : " WHERE `show`='Y'") . " ORDER BY `Name`");
}
/**
* Delete a room
*
- * @param int $room_id
+ * @param int $room_id
*/
-function Room_delete($room_id) {
- return sql_query("DELETE FROM `Room` WHERE `RID`=" . sql_escape($room_id));
+function Room_delete($room_id)
+{
+ return sql_query("DELETE FROM `Room` WHERE `RID`=" . sql_escape($room_id));
}
/**
@@ -27,34 +29,34 @@ function Room_delete($room_id) {
* @param boolean $public
* Is the room visible for angels?
*/
-function Room_create($name, $from_frab, $public) {
- $result = sql_query("
+function Room_create($name, $from_frab, $public)
+{
+ $result = sql_query("
INSERT INTO `Room` SET
`Name`='" . sql_escape($name) . "',
`FromPentabarf`='" . sql_escape($from_frab ? 'Y' : '') . "',
`show`='" . sql_escape($public ? 'Y' : '') . "',
`Number`=0");
- if ($result === false) {
- return false;
- }
- return sql_id();
+ if ($result === false) {
+ return false;
+ }
+ return sql_id();
}
/**
* Returns room by id.
*
- * @param $room_id RID
+ * @param $room_id RID
*/
-function Room($room_id) {
- $room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($room_id) . "' AND `show` = 'Y'");
+function Room($room_id)
+{
+ $room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($room_id) . "' AND `show` = 'Y'");
- if ($room_source === false) {
- return false;
- }
- if (count($room_source) > 0) {
- return $room_source[0];
- }
- return null;
+ if ($room_source === false) {
+ return false;
+ }
+ if (count($room_source) > 0) {
+ return $room_source[0];
+ }
+ return null;
}
-
-?>
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index 9f4faf9e..c25938e3 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -4,30 +4,33 @@
* Returns an array with the attributes of shift entries.
* FIXME! Needs entity object.
*/
-function ShiftEntry_new() {
- return [
+function ShiftEntry_new()
+{
+ return [
'id' => null,
'SID' => null,
'TID' => null,
'UID' => null,
'Comment' => null,
'freeloaded_comment' => null,
- 'freeloaded' => false
+ 'freeloaded' => false
];
}
/**
* Counts all freeloaded shifts.
*/
-function ShiftEntries_freeleaded_count() {
- return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
+function ShiftEntries_freeleaded_count()
+{
+ return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
}
/**
* List users subsribed to a given shift.
*/
-function ShiftEntries_by_shift($shift_id) {
- return sql_select("
+function ShiftEntries_by_shift($shift_id)
+{
+ return sql_select("
SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
FROM `ShiftEntry`
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
@@ -38,11 +41,12 @@ 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
+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']) . "',
`UID`='" . sql_escape($shift_entry['UID']) . "',
@@ -54,8 +58,9 @@ function ShiftEntry_create($shift_entry) {
/**
* Update a shift entry.
*/
-function ShiftEntry_update($shift_entry) {
- return sql_query("UPDATE `ShiftEntry` SET
+function ShiftEntry_update($shift_entry)
+{
+ return sql_query("UPDATE `ShiftEntry` SET
`Comment`='" . sql_escape($shift_entry['Comment']) . "',
`freeload_comment`='" . sql_escape($shift_entry['freeload_comment']) . "',
`freeloaded`=" . sql_bool($shift_entry['freeloaded']) . "
@@ -65,33 +70,36 @@ 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];
+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) . "'");
+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("
+function ShiftEntries_upcoming_for_user($user)
+{
+ return sql_select("
SELECT *
FROM `ShiftEntry`
JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`)
@@ -105,10 +113,11 @@ function ShiftEntries_upcoming_for_user($user) {
/**
* Returns shifts completed by the given user.
*
- * @param User $user
+ * @param User $user
*/
-function ShiftEntries_finished_by_user($user) {
- return sql_select("
+function ShiftEntries_finished_by_user($user)
+{
+ return sql_select("
SELECT *
FROM `ShiftEntry`
JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`)
@@ -123,30 +132,30 @@ function ShiftEntries_finished_by_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) {
- $result = sql_select("
+function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id)
+{
+ $result = sql_select("
SELECT *
FROM `ShiftEntry`
WHERE `SID`=" . sql_escape($shift_id) . "
AND `TID`=" . sql_escape($angeltype_id) . "
");
- if ($result === false) {
- engelsystem_error("Unable to load shift entries.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to load shift entries.");
+ }
+ return $result;
}
/**
* Returns all freeloaded shifts for given user.
*/
-function ShiftEntries_freeloaded_by_user($user) {
- return sql_select("SELECT *
+function ShiftEntries_freeloaded_by_user($user)
+{
+ return sql_select("SELECT *
FROM `ShiftEntry`
WHERE `freeloaded` = 1
AND `UID`=" . sql_escape($user['UID']));
}
-
-?>
diff --git a/includes/model/ShiftSignupState.php b/includes/model/ShiftSignupState.php
index 393023ee..9c20a575 100644
--- a/includes/model/ShiftSignupState.php
+++ b/includes/model/ShiftSignupState.php
@@ -6,7 +6,8 @@ namespace Engelsystem;
* BO to represent if there are free slots on a shift for a given angeltype
* and if signup for a given user is possible (or not, because of collisions, etc.)
*/
-class ShiftSignupState {
+class ShiftSignupState
+{
/**
* Shift has free places
@@ -43,14 +44,15 @@ class ShiftSignupState {
*/
const SIGNED_UP = 'SIGNED_UP';
- private $state;
+ private $state;
- private $freeEntries;
+ private $freeEntries;
- public function __construct($state, $free_entries) {
- $this->state = $state;
- $this->freeEntries = $free_entries;
- }
+ public function __construct($state, $free_entries)
+ {
+ $this->state = $state;
+ $this->freeEntries = $free_entries;
+ }
/**
* Combine this state with another state from the same shift.
@@ -58,16 +60,18 @@ class ShiftSignupState {
* @param ShiftSignupState $shiftSignupState
* The other state to combine
*/
- public function combineWith(ShiftSignupState $shiftSignupState) {
- $this->freeEntries += $shiftSignupState->getFreeEntries();
+ public function combineWith(ShiftSignupState $shiftSignupState)
+ {
+ $this->freeEntries += $shiftSignupState->getFreeEntries();
- if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) {
- $this->state = $shiftSignupState->state;
- }
+ if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) {
+ $this->state = $shiftSignupState->state;
+ }
}
- private function valueForState($state) {
- switch ($state) {
+ private function valueForState($state)
+ {
+ switch ($state) {
case ShiftSignupState::SHIFT_ENDED:
return 100;
@@ -85,33 +89,34 @@ class ShiftSignupState {
case ShiftSignupState::ADMIN:
return 60;
}
- }
+ }
/**
* Returns true, if signup is allowed
*/
- public function isSignupAllowed() {
- switch ($this->state) {
+ public function isSignupAllowed()
+ {
+ switch ($this->state) {
case ShiftSignupState::FREE:
case ShiftSignupState::ADMIN:
return true;
}
- return false;
+ return false;
}
/**
* Return the shift signup state
*/
- public function getState() {
- return $this->state;
+ public function getState()
+ {
+ return $this->state;
}
/**
* How many places are free in this shift for the angeltype?
*/
- public function getFreeEntries() {
- return $this->freeEntries;
+ public function getFreeEntries()
+ {
+ return $this->freeEntries;
}
}
-
-?> \ No newline at end of file
diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php
index 89704a65..fb361db9 100644
--- a/includes/model/ShiftTypes_model.php
+++ b/includes/model/ShiftTypes_model.php
@@ -4,20 +4,22 @@
* Delete a shift type.
* @param int $shifttype_id
*/
-function ShiftType_delete($shifttype_id) {
- return sql_query("DELETE FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
+function ShiftType_delete($shifttype_id)
+{
+ return sql_query("DELETE FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
}
/**
* Update a shift type.
*
- * @param int $shifttype_id
- * @param string $name
- * @param int $angeltype_id
- * @param string $description
+ * @param int $shifttype_id
+ * @param string $name
+ * @param int $angeltype_id
+ * @param string $description
*/
-function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) {
- return sql_query("UPDATE `ShiftTypes` SET
+function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
+{
+ return sql_query("UPDATE `ShiftTypes` SET
`name`='" . sql_escape($name) . "',
`angeltype_id`=" . sql_null($angeltype_id) . ",
`description`='" . sql_escape($description) . "'
@@ -27,43 +29,44 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) {
/**
* Create a shift type.
*
- * @param string $name
- * @param int $angeltype_id
- * @param string $description
+ * @param string $name
+ * @param int $angeltype_id
+ * @param string $description
* @return new shifttype id
*/
-function ShiftType_create($name, $angeltype_id, $description) {
- $result = sql_query("INSERT INTO `ShiftTypes` SET
+function ShiftType_create($name, $angeltype_id, $description)
+{
+ $result = sql_query("INSERT INTO `ShiftTypes` SET
`name`='" . sql_escape($name) . "',
`angeltype_id`=" . sql_null($angeltype_id) . ",
`description`='" . sql_escape($description) . "'");
- if ($result === false) {
- return false;
- }
- return sql_id();
+ if ($result === false) {
+ return false;
+ }
+ return sql_id();
}
/**
* Get a shift type by id.
*
- * @param int $shifttype_id
+ * @param int $shifttype_id
*/
-function ShiftType($shifttype_id) {
- $shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
- if ($shifttype === false) {
- engelsystem_error('Unable to load shift type.');
- }
- if ($shifttype == null) {
- return null;
- }
- return $shifttype[0];
+function ShiftType($shifttype_id)
+{
+ $shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
+ if ($shifttype === false) {
+ engelsystem_error('Unable to load shift type.');
+ }
+ if ($shifttype == null) {
+ return null;
+ }
+ return $shifttype[0];
}
/**
* Get all shift types.
*/
-function ShiftTypes() {
- return sql_select("SELECT * FROM `ShiftTypes` ORDER BY `name`");
+function ShiftTypes()
+{
+ return sql_select("SELECT * FROM `ShiftTypes` ORDER BY `name`");
}
-
-?> \ No newline at end of file
diff --git a/includes/model/ShiftsFilter.php b/includes/model/ShiftsFilter.php
index ff1f5d40..cba6fee7 100644
--- a/includes/model/ShiftsFilter.php
+++ b/includes/model/ShiftsFilter.php
@@ -7,7 +7,8 @@ namespace Engelsystem;
*
* @author msquare
*/
-class ShiftsFilter {
+class ShiftsFilter
+{
/**
* How long can the time interval be?
@@ -32,90 +33,101 @@ class ShiftsFilter {
*/
private $userShiftsAdmin;
- private $filled = [];
+ private $filled = [];
- private $rooms = [];
+ private $rooms = [];
- private $types = [];
+ private $types = [];
- private $startTime = null;
+ private $startTime = null;
- private $endTime = null;
+ private $endTime = null;
- public function __construct($user_shifts_admin, $rooms, $types) {
- $this->user_shifts_admin = $user_shifts_admin;
- $this->rooms = $rooms;
- $this->types = $types;
+ public function __construct($user_shifts_admin, $rooms, $types)
+ {
+ $this->user_shifts_admin = $user_shifts_admin;
+ $this->rooms = $rooms;
+ $this->types = $types;
- $this->filled = [
- ShiftsFilter::FILLED_FREE
+ $this->filled = [
+ ShiftsFilter::FILLED_FREE
];
- if ($user_shifts_admin) {
- $this->filled[] = ShiftsFilter::FILLED_FILLED;
+ if ($user_shifts_admin) {
+ $this->filled[] = ShiftsFilter::FILLED_FILLED;
+ }
}
- }
- public function getStartTime() {
- return $this->startTime;
- }
+ public function getStartTime()
+ {
+ return $this->startTime;
+ }
- public function setStartTime($startTime) {
- $this->startTime = $startTime;
- }
+ public function setStartTime($startTime)
+ {
+ $this->startTime = $startTime;
+ }
- public function getEndTime() {
- return $this->endTime;
- }
+ public function getEndTime()
+ {
+ return $this->endTime;
+ }
- public function setEndTime($endTime) {
- if ($endTime - $this->startTime > ShiftsFilter::MAX_DURATION) {
- $endTime = $this->startTime + ShiftsFilter::MAX_DURATION;
+ public function setEndTime($endTime)
+ {
+ if ($endTime - $this->startTime > ShiftsFilter::MAX_DURATION) {
+ $endTime = $this->startTime + ShiftsFilter::MAX_DURATION;
+ }
+ $this->endTime = $endTime;
}
- $this->endTime = $endTime;
- }
- public function getTypes() {
- if (count($this->types) == 0) {
- return [
- 0
+ public function getTypes()
+ {
+ if (count($this->types) == 0) {
+ return [
+ 0
];
+ }
+ return $this->types;
}
- return $this->types;
- }
- public function setTypes($types) {
- $this->types = $types;
- }
+ public function setTypes($types)
+ {
+ $this->types = $types;
+ }
- public function getRooms() {
- if (count($this->rooms) == 0) {
- return [
- 0
+ public function getRooms()
+ {
+ if (count($this->rooms) == 0) {
+ return [
+ 0
];
+ }
+ return $this->rooms;
}
- return $this->rooms;
- }
- public function setRooms($rooms) {
- $this->rooms = $rooms;
- }
+ public function setRooms($rooms)
+ {
+ $this->rooms = $rooms;
+ }
- public function isUserShiftsAdmin() {
- return $this->userShiftsAdmin;
- }
+ public function isUserShiftsAdmin()
+ {
+ return $this->userShiftsAdmin;
+ }
- public function setUserShiftsAdmin($userShiftsAdmin) {
- $this->userShiftsAdmin = $userShiftsAdmin;
- }
+ public function setUserShiftsAdmin($userShiftsAdmin)
+ {
+ $this->userShiftsAdmin = $userShiftsAdmin;
+ }
- public function getFilled() {
- return $this->filled;
- }
+ public function getFilled()
+ {
+ return $this->filled;
+ }
- public function setFilled($filled) {
- $this->filled = $filled;
- }
+ public function setFilled($filled)
+ {
+ $this->filled = $filled;
+ }
}
-
-?> \ No newline at end of file
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 29156423..0d49f5da 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -2,16 +2,18 @@
use Engelsystem\ShiftsFilter;
use Engelsystem\ShiftSignupState;
-function Shifts_by_room($room) {
- $result = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($room['RID']) . " ORDER BY `start`");
- if ($result === false) {
- engelsystem_error("Unable to load shifts.");
- }
- return $result;
+function Shifts_by_room($room)
+{
+ $result = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($room['RID']) . " ORDER BY `start`");
+ if ($result === false) {
+ engelsystem_error("Unable to load shifts.");
+ }
+ return $result;
}
-function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
- $SQL = "SELECT * FROM (
+function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
+{
+ $SQL = "SELECT * FROM (
SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
FROM `Shifts`
JOIN `Room` USING (`RID`)
@@ -37,15 +39,16 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
AND NOT `Shifts`.`PSID` IS NULL) as tmp_shifts
ORDER BY `start`";
- $result = sql_select($SQL);
- if ($result === false) {
- engelsystem_error("Unable to load shifts by filter.");
- }
- return $result;
+ $result = sql_select($SQL);
+ if ($result === false) {
+ engelsystem_error("Unable to load shifts by filter.");
+ }
+ return $result;
}
-function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
- $SQL = "SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
+function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
+{
+ $SQL = "SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
FROM `Shifts`
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
@@ -62,15 +65,16 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
AND NOT `Shifts`.`PSID` IS NULL";
- $result = sql_select($SQL);
- if ($result === false) {
- engelsystem_error("Unable to load needed angeltypes by filter.");
- }
- return $result;
+ $result = sql_select($SQL);
+ if ($result === false) {
+ engelsystem_error("Unable to load needed angeltypes by filter.");
+ }
+ return $result;
}
-function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) {
- $result = sql_select("SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
+function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype)
+{
+ $result = sql_select("SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
FROM `Shifts`
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
@@ -87,58 +91,61 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) {
WHERE `Shifts`.`SID`=" . sql_escape($shift['SID']) . "
AND `AngelTypes`.`id`=" . sql_escape($angeltype['id']) . "
AND NOT `Shifts`.`PSID` IS NULL");
- if ($result === false) {
- engelsystem_error("Unable to load needed angeltypes by filter.");
- }
- if (count($result) == 0) {
- return null;
- }
- return $result[0];
+ if ($result === false) {
+ engelsystem_error("Unable to load needed angeltypes by filter.");
+ }
+ if (count($result) == 0) {
+ return null;
+ }
+ return $result[0];
}
-function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
- $SQL = "SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
+function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
+{
+ $SQL = "SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
FROM `Shifts`
JOIN `ShiftEntry` ON `ShiftEntry`.`SID`=`Shifts`.`SID`
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
ORDER BY `Shifts`.`start`";
- $result = sql_select($SQL);
- if ($result === false) {
- engelsystem_error("Unable to load shift entries by filter.");
- }
- return $result;
+ $result = sql_select($SQL);
+ if ($result === false) {
+ engelsystem_error("Unable to load shift entries by filter.");
+ }
+ return $result;
}
/**
* Check if a shift collides with other shifts (in time).
*
- * @param Shift $shift
- * @param array<Shift> $shifts
+ * @param Shift $shift
+ * @param array<Shift> $shifts
*/
-function Shift_collides($shift, $shifts) {
- foreach ($shifts as $other_shift) {
- if ($shift['SID'] != $other_shift['SID']) {
- if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) {
- return true;
- }
+function Shift_collides($shift, $shifts)
+{
+ foreach ($shifts as $other_shift) {
+ if ($shift['SID'] != $other_shift['SID']) {
+ if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) {
+ return true;
+ }
+ }
}
- }
- return false;
+ return false;
}
/**
* Returns the number of needed angels/free shift entries for an angeltype.
*/
-function Shift_free_entries($needed_angeltype, $shift_entries) {
- $taken = 0;
- foreach ($shift_entries as $shift_entry) {
- if ($shift_entry['freeloaded'] == 0) {
- $taken ++;
+function Shift_free_entries($needed_angeltype, $shift_entries)
+{
+ $taken = 0;
+ foreach ($shift_entries as $shift_entry) {
+ if ($shift_entry['freeloaded'] == 0) {
+ $taken ++;
+ }
}
- }
- return max(0, $needed_angeltype['count'] - $taken);
+ return max(0, $needed_angeltype['count'] - $taken);
}
/**
@@ -153,55 +160,56 @@ function Shift_free_entries($needed_angeltype, $shift_entries) {
* @param boolean $angeltype_supporter
* True, if the user has angeltype supporter rights for the angeltype, which enables him to sign somebody up for the shift.
*/
-function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries) {
- $free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
+function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries)
+{
+ $free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
- if ($user['Gekommen'] == 0) {
- return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
- }
+ if ($user['Gekommen'] == 0) {
+ return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
+ }
- if ($user_shifts == null) {
- $user_shifts = Shifts_by_user($user);
- }
+ if ($user_shifts == null) {
+ $user_shifts = Shifts_by_user($user);
+ }
- $signed_up = false;
- foreach ($user_shifts as $user_shift) {
- if ($user_shift['SID'] == $shift['SID']) {
- $signed_up = true;
- break;
+ $signed_up = false;
+ foreach ($user_shifts as $user_shift) {
+ if ($user_shift['SID'] == $shift['SID']) {
+ $signed_up = true;
+ break;
+ }
}
- }
- if ($signed_up) {
- // you cannot join if you already singed up for this shift
+ if ($signed_up) {
+ // you cannot join if you already singed up for this shift
return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries);
- }
+ }
- if (time() > $shift['start']) {
- // you can only join if the shift is in future
+ if (time() > $shift['start']) {
+ // you can only join if the shift is in future
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
- }
- if ($free_entries == 0) {
- // you cannot join if shift is full
+ }
+ if ($free_entries == 0) {
+ // you cannot join if shift is full
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
- }
+ }
- if ($user_angeltype == null) {
- $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- }
+ if ($user_angeltype == null) {
+ $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
+ }
- if ($user_angeltype == null || ($angeltype['no_self_signup'] == 1 && $user_angeltype != null) || ($angeltype['restricted'] == 1 && $user_angeltype != null && ! isset($user_angeltype['confirm_user_id']))) {
- // you cannot join if user is not of this angel type
+ if ($user_angeltype == null || ($angeltype['no_self_signup'] == 1 && $user_angeltype != null) || ($angeltype['restricted'] == 1 && $user_angeltype != null && ! isset($user_angeltype['confirm_user_id']))) {
+ // you cannot join if user is not of this angel type
// you cannot join if you are not confirmed
// you cannot join if angeltype has no self signup
return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries);
- }
+ }
- if (Shift_collides($shift, $user_shifts)) {
- // you cannot join if user alread joined a parallel or this shift
+ if (Shift_collides($shift, $user_shifts)) {
+ // you cannot join if user alread joined a parallel or this shift
return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries);
- }
+ }
// Hooray, shift is free for you!
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
@@ -210,13 +218,14 @@ function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype,
/**
* Check if an angeltype supporter can sign up a user to a shift.
*/
-function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries) {
- $free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
- if ($free_entries == 0) {
- return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
- }
+function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries)
+{
+ $free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
+ if ($free_entries == 0) {
+ return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
+ }
- return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
+ return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
}
/**
@@ -227,15 +236,16 @@ function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype,
* @param AngelType $angeltype
* The angeltype to which the user wants to sign up
*/
-function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries) {
- $free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
+function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries)
+{
+ $free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
- if ($free_entries == 0) {
- // User shift admins may join anybody in every shift
+ if ($free_entries == 0) {
+ // User shift admins may join anybody in every shift
return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries);
- }
+ }
- return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
+ return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
}
/**
@@ -248,49 +258,53 @@ function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entrie
* @param array<Shift> $user_shifts
* List of the users shifts
*/
-function Shift_signup_allowed($signup_user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null, $needed_angeltype, $shift_entries) {
- global $user, $privileges;
+function Shift_signup_allowed($signup_user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null, $needed_angeltype, $shift_entries)
+{
+ global $user, $privileges;
- if (in_array('user_shifts_admin', $privileges)) {
- return Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries);
- }
+ if (in_array('user_shifts_admin', $privileges)) {
+ return Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries);
+ }
- if (in_array('shiftentry_edit_angeltype_supporter', $privileges) && User_is_AngelType_supporter($user, $angeltype)) {
- return Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries);
- }
+ if (in_array('shiftentry_edit_angeltype_supporter', $privileges) && User_is_AngelType_supporter($user, $angeltype)) {
+ return Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries);
+ }
- return Shift_signup_allowed_angel($signup_user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries);
+ return Shift_signup_allowed_angel($signup_user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries);
}
/**
* Delete a shift by its external id.
*/
-function Shift_delete_by_psid($shift_psid) {
- return sql_query("DELETE FROM `Shifts` WHERE `PSID`='" . sql_escape($shift_psid) . "'");
+function Shift_delete_by_psid($shift_psid)
+{
+ return sql_query("DELETE FROM `Shifts` WHERE `PSID`='" . sql_escape($shift_psid) . "'");
}
/**
* Delete a shift.
*/
-function Shift_delete($shift_id) {
- mail_shift_delete(Shift($shift_id));
+function Shift_delete($shift_id)
+{
+ mail_shift_delete(Shift($shift_id));
- $result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
- if ($result === false) {
- engelsystem_error('Unable to delete shift.');
- }
- return $result;
+ $result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
+ if ($result === false) {
+ engelsystem_error('Unable to delete shift.');
+ }
+ return $result;
}
/**
* Update a shift.
*/
-function Shift_update($shift) {
- global $user;
- $shift['name'] = ShiftType($shift['shifttype_id'])['name'];
- mail_shift_change(Shift($shift['SID']), $shift);
+function Shift_update($shift)
+{
+ global $user;
+ $shift['name'] = ShiftType($shift['shifttype_id'])['name'];
+ mail_shift_change(Shift($shift['SID']), $shift);
- return sql_query("UPDATE `Shifts` SET
+ return sql_query("UPDATE `Shifts` SET
`shifttype_id`='" . sql_escape($shift['shifttype_id']) . "',
`start`='" . sql_escape($shift['start']) . "',
`end`='" . sql_escape($shift['end']) . "',
@@ -306,16 +320,17 @@ function Shift_update($shift) {
/**
* Update a shift by its external id.
*/
-function Shift_update_by_psid($shift) {
- $shift_source = sql_select("SELECT `SID` FROM `Shifts` WHERE `PSID`=" . $shift['PSID']);
- if ($shift_source === false) {
- return false;
- }
- if (count($shift_source) == 0) {
- return null;
- }
- $shift['SID'] = $shift_source[0]['SID'];
- return Shift_update($shift);
+function Shift_update_by_psid($shift)
+{
+ $shift_source = sql_select("SELECT `SID` FROM `Shifts` WHERE `PSID`=" . $shift['PSID']);
+ if ($shift_source === false) {
+ return false;
+ }
+ if (count($shift_source) == 0) {
+ return null;
+ }
+ $shift['SID'] = $shift_source[0]['SID'];
+ return Shift_update($shift);
}
/**
@@ -323,9 +338,10 @@ function Shift_update_by_psid($shift) {
*
* @return new shift id or false
*/
-function Shift_create($shift) {
- global $user;
- $result = sql_query("INSERT INTO `Shifts` SET
+function Shift_create($shift)
+{
+ global $user;
+ $result = sql_query("INSERT INTO `Shifts` SET
`shifttype_id`='" . sql_escape($shift['shifttype_id']) . "',
`start`='" . sql_escape($shift['start']) . "',
`end`='" . sql_escape($shift['end']) . "',
@@ -335,17 +351,18 @@ function Shift_create($shift) {
`PSID`=" . sql_null($shift['PSID']) . ",
`created_by_user_id`='" . sql_escape($user['UID']) . "',
`created_at_timestamp`=" . time());
- if ($result === false) {
- return false;
- }
- return sql_id();
+ if ($result === false) {
+ return false;
+ }
+ return sql_id();
}
/**
* Return users shifts.
*/
-function Shifts_by_user($user, $include_freeload_comments = false) {
- $result = sql_select("
+function Shifts_by_user($user, $include_freeload_comments = false)
+{
+ $result = sql_select("
SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`,
`ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`,
" . ($include_freeload_comments ? "`ShiftEntry`.`freeload_comment`, " : "") . "
@@ -357,10 +374,10 @@ function Shifts_by_user($user, $include_freeload_comments = false) {
WHERE `UID`='" . sql_escape($user['UID']) . "'
ORDER BY `start`
");
- if ($result === false) {
- engelsystem_error('Unable to load users shifts.');
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error('Unable to load users shifts.');
+ }
+ return $result;
}
/**
@@ -369,64 +386,64 @@ function Shifts_by_user($user, $include_freeload_comments = false) {
* @param $shift_id Shift
* ID
*/
-function Shift($shift_id) {
- $shifts_source = sql_select("
+function Shift($shift_id)
+{
+ $shifts_source = sql_select("
SELECT `Shifts`.*, `ShiftTypes`.`name`
FROM `Shifts`
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
WHERE `SID`='" . sql_escape($shift_id) . "'");
- $shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'");
+ $shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'");
- if ($shifts_source === false) {
- engelsystem_error('Unable to load shift.');
- }
+ if ($shifts_source === false) {
+ engelsystem_error('Unable to load shift.');
+ }
- if (empty($shifts_source)) {
- return null;
- }
+ if (empty($shifts_source)) {
+ return null;
+ }
- $result = $shifts_source[0];
+ $result = $shifts_source[0];
- $result['ShiftEntry'] = $shiftsEntry_source;
- $result['NeedAngels'] = [];
+ $result['ShiftEntry'] = $shiftsEntry_source;
+ $result['NeedAngels'] = [];
- $temp = NeededAngelTypes_by_shift($shift_id);
- foreach ($temp as $e) {
- $result['NeedAngels'][] = [
+ $temp = NeededAngelTypes_by_shift($shift_id);
+ foreach ($temp as $e) {
+ $result['NeedAngels'][] = [
'TID' => $e['angel_type_id'],
'count' => $e['count'],
'restricted' => $e['restricted'],
- 'taken' => $e['taken']
+ 'taken' => $e['taken']
];
- }
+ }
- return $result;
+ return $result;
}
/**
* Returns all shifts with needed angeltypes and count of subscribed jobs.
*/
-function Shifts() {
- $shifts_source = sql_select("
+function Shifts()
+{
+ $shifts_source = sql_select("
SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.`RID`, `Room`.`Name` as `room_name`
FROM `Shifts`
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID`
");
- if ($shifts_source === false) {
- return false;
- }
-
- foreach ($shifts_source as &$shift) {
- $needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
- if ($needed_angeltypes === false) {
- return false;
+ if ($shifts_source === false) {
+ return false;
}
+
+ foreach ($shifts_source as &$shift) {
+ $needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
+ if ($needed_angeltypes === false) {
+ return false;
+ }
- $shift['angeltypes'] = $needed_angeltypes;
- }
+ $shift['angeltypes'] = $needed_angeltypes;
+ }
- return $shifts_source;
+ return $shifts_source;
}
-
-?>
diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php
index 11366cdf..ea7a454c 100644
--- a/includes/model/UserAngelTypes_model.php
+++ b/includes/model/UserAngelTypes_model.php
@@ -13,8 +13,9 @@
* The angeltype to be checked
* @return boolean
*/
-function UserAngelType_exists($user, $angeltype) {
- return sql_num_query("
+function UserAngelType_exists($user, $angeltype)
+{
+ return sql_num_query("
SELECT `id`
FROM `UserAngelTypes`
WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "'
@@ -25,29 +26,31 @@ function UserAngelType_exists($user, $angeltype) {
/**
* List users angeltypes.
*
- * @param User $user
+ * @param User $user
*/
-function User_angeltypes($user) {
- $result = sql_select("
+function User_angeltypes($user)
+{
+ $result = sql_select("
SELECT `AngelTypes`.*, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter`
FROM `UserAngelTypes`
JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`
WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "'
");
- if ($result === false) {
- engelsystem_error("Unable to load user angeltypes.");
- return false;
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to load user angeltypes.");
+ return false;
+ }
+ return $result;
}
/**
* Gets unconfirmed user angeltypes for angeltypes of which the given user is a supporter.
*
- * @param User $user
+ * @param User $user
*/
-function User_unconfirmed_AngelTypes($user) {
- $result = sql_select("
+function User_unconfirmed_AngelTypes($user)
+{
+ $result = sql_select("
SELECT
`UserAngelTypes`.*,
`AngelTypes`.`name`,
@@ -61,23 +64,24 @@ function User_unconfirmed_AngelTypes($user) {
AND `UnconfirmedMembers`.`confirm_user_id` IS NULL
GROUP BY `UserAngelTypes`.`angeltype_id`
ORDER BY `AngelTypes`.`name`");
- if ($result === false) {
- engelsystem_error("Unable to load user angeltypes.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to load user angeltypes.");
+ }
+ return $result;
}
/**
* Returns true if user is angeltype supporter or has privilege admin_user_angeltypes.
*
- * @param User $user
- * @param AngelType $angeltype
+ * @param User $user
+ * @param AngelType $angeltype
*/
-function User_is_AngelType_supporter(&$user, $angeltype) {
- if(!isset($user['privileges'])) {
- $user['privileges'] = privileges_for_user($user['UID']);
- }
- return (sql_num_query("
+function User_is_AngelType_supporter(&$user, $angeltype)
+{
+ if (!isset($user['privileges'])) {
+ $user['privileges'] = privileges_for_user($user['UID']);
+ }
+ return (sql_num_query("
SELECT `id`
FROM `UserAngelTypes`
WHERE `user_id`='" . sql_escape($user['UID']) . "'
@@ -89,80 +93,85 @@ function User_is_AngelType_supporter(&$user, $angeltype) {
/**
* Add or remove supporter rights.
*
- * @param int $user_angeltype_id
- * @param bool $supporter
+ * @param int $user_angeltype_id
+ * @param bool $supporter
*/
-function UserAngelType_update($user_angeltype_id, $supporter) {
- $result = sql_query("
+function UserAngelType_update($user_angeltype_id, $supporter)
+{
+ $result = sql_query("
UPDATE `UserAngelTypes`
SET `supporter`=" . sql_bool($supporter) . "
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1");
- if ($result === false) {
- engelsystem_error("Unable to update supporter rights.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to update supporter rights.");
+ }
+ return $result;
}
/**
* Delete all unconfirmed UserAngelTypes for given Angeltype.
*
- * @param int $angeltype_id
+ * @param int $angeltype_id
*/
-function UserAngelTypes_delete_all($angeltype_id) {
- $result = sql_query("
+function UserAngelTypes_delete_all($angeltype_id)
+{
+ $result = sql_query("
DELETE FROM `UserAngelTypes`
WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "'
AND `confirm_user_id` IS NULL");
- if ($result === false) {
- engelsystem_error("Unable to delete all unconfirmed users.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to delete all unconfirmed users.");
+ }
+ return $result;
}
/**
* Confirm all unconfirmed UserAngelTypes for given Angeltype.
*
- * @param int $angeltype_id
- * @param User $confirm_user
+ * @param int $angeltype_id
+ * @param User $confirm_user
*/
-function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) {
- $result = sql_query("
+function UserAngelTypes_confirm_all($angeltype_id, $confirm_user)
+{
+ $result = sql_query("
UPDATE `UserAngelTypes`
SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "'
WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "'
AND `confirm_user_id` IS NULL");
- if ($result === false) {
- engelsystem_error("Unable to confirm all users.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to confirm all users.");
+ }
+ return $result;
}
/**
* Confirm an UserAngelType with confirming user.
*
- * @param int $user_angeltype_id
- * @param User $confirm_user
+ * @param int $user_angeltype_id
+ * @param User $confirm_user
*/
-function UserAngelType_confirm($user_angeltype_id, $confirm_user) {
- $result = sql_query("
+function UserAngelType_confirm($user_angeltype_id, $confirm_user)
+{
+ $result = sql_query("
UPDATE `UserAngelTypes`
SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "'
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1");
- if ($result === false) {
- engelsystem_error("Unable to confirm user angeltype.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to confirm user angeltype.");
+ }
+ return $result;
}
/**
* Delete an UserAngelType.
*
- * @param UserAngelType $user_angeltype
+ * @param UserAngelType $user_angeltype
*/
-function UserAngelType_delete($user_angeltype) {
- return sql_query("
+function UserAngelType_delete($user_angeltype)
+{
+ return sql_query("
DELETE FROM `UserAngelTypes`
WHERE `id`='" . sql_escape($user_angeltype['id']) . "'
LIMIT 1");
@@ -171,59 +180,61 @@ function UserAngelType_delete($user_angeltype) {
/**
* Create an UserAngelType.
*
- * @param User $user
- * @param Angeltype $angeltype
+ * @param User $user
+ * @param Angeltype $angeltype
*/
-function UserAngelType_create($user, $angeltype) {
- $result = sql_query("
+function UserAngelType_create($user, $angeltype)
+{
+ $result = sql_query("
INSERT INTO `UserAngelTypes` SET
`user_id`='" . sql_escape($user['UID']) . "',
`angeltype_id`='" . sql_escape($angeltype['id']) . "'");
- if ($result === false) {
- engelsystem_error("Unable to create user angeltype.");
- }
- return sql_id();
+ if ($result === false) {
+ engelsystem_error("Unable to create user angeltype.");
+ }
+ return sql_id();
}
/**
* Get an UserAngelType by its id.
*
- * @param int $user_angeltype_id
+ * @param int $user_angeltype_id
*/
-function UserAngelType($user_angeltype_id) {
- $angeltype = sql_select("
+function UserAngelType($user_angeltype_id)
+{
+ $angeltype = sql_select("
SELECT *
FROM `UserAngelTypes`
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1");
- if ($angeltype === false) {
- engelsystem_error("Unable to load user angeltype.");
- }
- if (count($angeltype) == 0) {
- return null;
- }
- return $angeltype[0];
+ if ($angeltype === false) {
+ engelsystem_error("Unable to load user angeltype.");
+ }
+ if (count($angeltype) == 0) {
+ return null;
+ }
+ return $angeltype[0];
}
/**
* Get an UserAngelType by user and angeltype.
*
- * @param User $user
- * @param Angeltype $angeltype
+ * @param User $user
+ * @param Angeltype $angeltype
*/
-function UserAngelType_by_User_and_AngelType($user, $angeltype) {
- $angeltype = sql_select("
+function UserAngelType_by_User_and_AngelType($user, $angeltype)
+{
+ $angeltype = sql_select("
SELECT *
FROM `UserAngelTypes`
WHERE `user_id`='" . sql_escape($user['UID']) . "'
AND `angeltype_id`='" . sql_escape($angeltype['id']) . "'
LIMIT 1");
- if ($angeltype === false) {
- engelsystem_error("Unable to load user angeltype.");
- }
- if (count($angeltype) == 0) {
- return null;
- }
- return $angeltype[0];
+ if ($angeltype === false) {
+ engelsystem_error("Unable to load user angeltype.");
+ }
+ if (count($angeltype) == 0) {
+ return null;
+ }
+ return $angeltype[0];
}
-?> \ No newline at end of file
diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php
index 6caa3589..7d1be528 100644
--- a/includes/model/UserDriverLicenses_model.php
+++ b/includes/model/UserDriverLicenses_model.php
@@ -4,15 +4,16 @@
* Returns a new empty UserDriverLicense
* FIXME entity object needed
*/
-function UserDriverLicense_new() {
- return [
+function UserDriverLicense_new()
+{
+ return [
'user_id' => null,
'has_car' => false,
'has_license_car' => false,
'has_license_3_5t_transporter' => false,
'has_license_7_5t_truck' => false,
'has_license_12_5t_truck' => false,
- 'has_license_forklift' => false
+ 'has_license_forklift' => false
];
}
@@ -23,8 +24,9 @@ function UserDriverLicense_new() {
* The UserDriverLicense to check
* @return boolean
*/
-function UserDriverLicense_valid($user_driver_license) {
- return $user_driver_license['has_car'] || $user_driver_license['has_license_car'] || $user_driver_license['has_license_3_5t_transporter'] || $user_driver_license['has_license_7_5t_truck'] || $user_driver_license['has_license_12_5t_truck'] || $user_driver_license['has_license_forklift'];
+function UserDriverLicense_valid($user_driver_license)
+{
+ return $user_driver_license['has_car'] || $user_driver_license['has_license_car'] || $user_driver_license['has_license_3_5t_transporter'] || $user_driver_license['has_license_7_5t_truck'] || $user_driver_license['has_license_12_5t_truck'] || $user_driver_license['has_license_forklift'];
}
/**
@@ -33,16 +35,17 @@ function UserDriverLicense_valid($user_driver_license) {
* @param int $user_id
* The users id
*/
-function UserDriverLicense($user_id) {
- $user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
- if ($user_driver_license === false) {
- engelsystem_error('Unable to load user driver license.');
- return false;
- }
- if (count($user_driver_license) > 0) {
- return $user_driver_license[0];
- }
- return null;
+function UserDriverLicense($user_id)
+{
+ $user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
+ if ($user_driver_license === false) {
+ engelsystem_error('Unable to load user driver license.');
+ return false;
+ }
+ if (count($user_driver_license) > 0) {
+ return $user_driver_license[0];
+ }
+ return null;
}
/**
@@ -51,9 +54,10 @@ function UserDriverLicense($user_id) {
* @param UserDriverLicense $user_driver_license
* The UserDriverLicense to create
*/
-function UserDriverLicenses_create($user_driver_license, $user) {
- $user_driver_license['user_id'] = $user['UID'];
- $result = sql_query("
+function UserDriverLicenses_create($user_driver_license, $user)
+{
+ $user_driver_license['user_id'] = $user['UID'];
+ $result = sql_query("
INSERT INTO `UserDriverLicenses` SET
`user_id`=" . sql_escape($user_driver_license['user_id']) . ",
`has_car`=" . sql_bool($user_driver_license['has_car']) . ",
@@ -62,10 +66,10 @@ function UserDriverLicenses_create($user_driver_license, $user) {
`has_license_7_5t_truck`=" . sql_bool($user_driver_license['has_license_7_5t_truck']) . ",
`has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
`has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']));
- if ($result === false) {
- engelsystem_error('Unable to create user driver license');
- }
- return $user_driver_license;
+ if ($result === false) {
+ engelsystem_error('Unable to create user driver license');
+ }
+ return $user_driver_license;
}
/**
@@ -74,8 +78,9 @@ function UserDriverLicenses_create($user_driver_license, $user) {
* @param UserDriverLicense $user_driver_license
* The UserDriverLicense to update
*/
-function UserDriverLicenses_update($user_driver_license) {
- $result = sql_query("UPDATE `UserDriverLicenses` SET
+function UserDriverLicenses_update($user_driver_license)
+{
+ $result = sql_query("UPDATE `UserDriverLicenses` SET
`has_car`=" . sql_bool($user_driver_license['has_car']) . ",
`has_license_car`=" . sql_bool($user_driver_license['has_license_car']) . ",
`has_license_3_5t_transporter`=" . sql_bool($user_driver_license['has_license_3_5t_transporter']) . ",
@@ -83,22 +88,22 @@ function UserDriverLicenses_update($user_driver_license) {
`has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
`has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']) . "
WHERE `user_id`='" . sql_escape($user_driver_license['user_id']) . "'");
- if ($result === false) {
- engelsystem_error("Unable to update user driver license information");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to update user driver license information");
+ }
+ return $result;
}
/**
* Delete a user's driver license entry
*
- * @param int $user_id
+ * @param int $user_id
*/
-function UserDriverLicenses_delete($user_id) {
- $result = sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id));
- if ($result === false) {
- engelsystem_error("Unable to remove user driver license information");
- }
- return $result;
+function UserDriverLicenses_delete($user_id)
+{
+ $result = sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id));
+ if ($result === false) {
+ engelsystem_error("Unable to remove user driver license information");
+ }
+ return $result;
}
-?> \ No newline at end of file
diff --git a/includes/model/UserGroups_model.php b/includes/model/UserGroups_model.php
index 766f402f..61fd074a 100644
--- a/includes/model/UserGroups_model.php
+++ b/includes/model/UserGroups_model.php
@@ -4,8 +4,9 @@
* Returns users groups
* @param User $user
*/
-function User_groups($user) {
- return sql_select("
+function User_groups($user)
+{
+ return sql_select("
SELECT `Groups`.*
FROM `UserGroups`
JOIN `Groups` ON `Groups`.`UID`=`UserGroups`.`group_id`
@@ -13,5 +14,3 @@ function User_groups($user) {
ORDER BY `UserGroups`.`group_id`
");
}
-
-?> \ No newline at end of file
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index 3ebd3bf9..9324bf53 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -8,19 +8,21 @@ use Engelsystem\ValidationResult;
/**
* Delete a user
*
- * @param int $user_id
+ * @param int $user_id
*/
-function User_delete($user_id) {
- return sql_query("DELETE FROM `User` WHERE `UID`='" . sql_escape($user_id) . "'");
+function User_delete($user_id)
+{
+ return sql_query("DELETE FROM `User` WHERE `UID`='" . sql_escape($user_id) . "'");
}
/**
* Update user.
*
- * @param User $user
+ * @param User $user
*/
-function User_update($user) {
- return sql_query("UPDATE `User` SET
+function User_update($user)
+{
+ return sql_query("UPDATE `User` SET
`Nick`='" . sql_escape($user['Nick']) . "',
`Name`='" . sql_escape($user['Name']) . "',
`Vorname`='" . sql_escape($user['Vorname']) . "',
@@ -50,31 +52,37 @@ function User_update($user) {
/**
* Counts all forced active users.
*/
-function User_force_active_count() {
- return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `force_active` = 1");
+function User_force_active_count()
+{
+ return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `force_active` = 1");
}
-function User_active_count() {
- return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1");
+function User_active_count()
+{
+ return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Aktiv` = 1");
}
-function User_got_voucher_count() {
- return sql_select_single_cell("SELECT SUM(`got_voucher`) FROM `User`");
+function User_got_voucher_count()
+{
+ return sql_select_single_cell("SELECT SUM(`got_voucher`) FROM `User`");
}
-function User_arrived_count() {
- return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1");
+function User_arrived_count()
+{
+ return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Gekommen` = 1");
}
-function User_tshirts_count() {
- return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1");
+function User_tshirts_count()
+{
+ return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `Tshirt` = 1");
}
/**
* Returns all column names for sorting in an array.
*/
-function User_sortable_columns() {
- return [
+function User_sortable_columns()
+{
+ return [
'Nick',
'Name',
'Vorname',
@@ -86,55 +94,59 @@ function User_sortable_columns() {
'Aktiv',
'force_active',
'Tshirt',
- 'lastLogIn'
+ 'lastLogIn'
];
}
/**
* Get all users, ordered by Nick by default or by given param.
*
- * @param string $order_by
+ * @param string $order_by
*/
-function Users($order_by = 'Nick') {
- return sql_select("SELECT * FROM `User` ORDER BY `" . sql_escape($order_by) . "` ASC");
+function Users($order_by = 'Nick')
+{
+ return sql_select("SELECT * FROM `User` ORDER BY `" . sql_escape($order_by) . "` ASC");
}
/**
* Returns true if user is freeloader
*
- * @param User $user
+ * @param User $user
*/
-function User_is_freeloader($user) {
- global $max_freeloadable_shifts, $user;
+function User_is_freeloader($user)
+{
+ global $max_freeloadable_shifts, $user;
- return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts;
+ return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts;
}
/**
* Returns all users that are not member of given angeltype.
*
- * @param Angeltype $angeltype
+ * @param Angeltype $angeltype
*/
-function Users_by_angeltype_inverted($angeltype) {
- $result = sql_select("
+function Users_by_angeltype_inverted($angeltype)
+{
+ $result = sql_select("
SELECT `User`.*
FROM `User`
LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`='" . sql_escape($angeltype['id']) . "')
WHERE `UserAngelTypes`.`id` IS NULL
ORDER BY `Nick`");
- if ($result === false) {
- engelsystem_error("Unable to load users.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to load users.");
+ }
+ return $result;
}
/**
* Returns all members of given angeltype.
*
- * @param Angeltype $angeltype
+ * @param Angeltype $angeltype
*/
-function Users_by_angeltype($angeltype) {
- $result = sql_select("
+function Users_by_angeltype($angeltype)
+{
+ $result = sql_select("
SELECT
`User`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`,
@@ -146,26 +158,28 @@ function Users_by_angeltype($angeltype) {
LEFT JOIN `UserDriverLicenses` ON `User`.`UID`=`UserDriverLicenses`.`user_id`
WHERE `UserAngelTypes`.`angeltype_id`='" . sql_escape($angeltype['id']) . "'
ORDER BY `Nick`");
- if ($result === false) {
- engelsystem_error("Unable to load members.");
- }
- return $result;
+ if ($result === false) {
+ engelsystem_error("Unable to load members.");
+ }
+ return $result;
}
/**
* Returns User id array
*/
-function User_ids() {
- return sql_select("SELECT `UID` FROM `User`");
+function User_ids()
+{
+ return sql_select("SELECT `UID` FROM `User`");
}
/**
* Strip unwanted characters from a users nick.
*
- * @param string $nick
+ * @param string $nick
*/
-function User_validate_Nick($nick) {
- return preg_replace("/([^a-z0-9üöäß. _+*-]{1,})/ui", '', $nick);
+function User_validate_Nick($nick)
+{
+ return preg_replace("/([^a-z0-9üöäß. _+*-]{1,})/ui", '', $nick);
}
/**
@@ -175,9 +189,10 @@ function User_validate_Nick($nick) {
* The email address to validate
* @return ValidationResult
*/
-function User_validate_mail($mail) {
- $mail = strip_item($mail);
- return new ValidationResult(check_email($mail), $mail);
+function User_validate_mail($mail)
+{
+ $mail = strip_item($mail);
+ return new ValidationResult(check_email($mail), $mail);
}
/**
@@ -187,13 +202,14 @@ function User_validate_mail($mail) {
* Jabber-ID to validate
* @return ValidationResult
*/
-function User_validate_jabber($jabber) {
- $jabber = strip_item($jabber);
- if ($jabber == '') {
- // Empty is ok
+function User_validate_jabber($jabber)
+{
+ $jabber = strip_item($jabber);
+ if ($jabber == '') {
+ // Empty is ok
return new ValidationResult(true, '');
- }
- return new ValidationResult(check_email($jabber), $jabber);
+ }
+ return new ValidationResult(check_email($jabber), $jabber);
}
/**
@@ -203,25 +219,26 @@ function User_validate_jabber($jabber) {
* Unix timestamp
* @return ValidationResult
*/
-function User_validate_planned_arrival_date($planned_arrival_date) {
- if ($planned_arrival_date == null) {
- // null is not okay
+function User_validate_planned_arrival_date($planned_arrival_date)
+{
+ if ($planned_arrival_date == null) {
+ // null is not okay
return new ValidationResult(false, time());
- }
- $event_config = EventConfig();
- if ($event_config == null) {
- // Nothing to validate against
+ }
+ $event_config = EventConfig();
+ if ($event_config == null) {
+ // Nothing to validate against
return new ValidationResult(true, $planned_arrival_date);
- }
- if (isset($event_config['buildup_start_date']) && $planned_arrival_date < $event_config['buildup_start_date']) {
- // Planned arrival can not be before buildup start date
+ }
+ if (isset($event_config['buildup_start_date']) && $planned_arrival_date < $event_config['buildup_start_date']) {
+ // Planned arrival can not be before buildup start date
return new ValidationResult(false, $event_config['buildup_start_date']);
- }
- if (isset($event_config['teardown_end_date']) && $planned_arrival_date > $event_config['teardown_end_date']) {
- // Planned arrival can not be after teardown end date
+ }
+ if (isset($event_config['teardown_end_date']) && $planned_arrival_date > $event_config['teardown_end_date']) {
+ // Planned arrival can not be after teardown end date
return new ValidationResult(false, $event_config['teardown_end_date']);
- }
- return new ValidationResult(true, $planned_arrival_date);
+ }
+ return new ValidationResult(true, $planned_arrival_date);
}
/**
@@ -233,45 +250,47 @@ function User_validate_planned_arrival_date($planned_arrival_date) {
* Unix timestamp
* @return ValidationResult
*/
-function User_validate_planned_departure_date($planned_arrival_date, $planned_departure_date) {
- if ($planned_departure_date == null) {
- // null is okay
+function User_validate_planned_departure_date($planned_arrival_date, $planned_departure_date)
+{
+ if ($planned_departure_date == null) {
+ // null is okay
return new ValidationResult(true, null);
- }
- if ($planned_arrival_date > $planned_departure_date) {
- // departure cannot be before arrival
+ }
+ if ($planned_arrival_date > $planned_departure_date) {
+ // departure cannot be before arrival
return new ValidationResult(false, $planned_arrival_date);
- }
- $event_config = EventConfig();
- if ($event_config == null) {
- // Nothing to validate against
+ }
+ $event_config = EventConfig();
+ if ($event_config == null) {
+ // Nothing to validate against
return new ValidationResult(true, $planned_departure_date);
- }
- if (isset($event_config['buildup_start_date']) && $planned_departure_date < $event_config['buildup_start_date']) {
- // Planned arrival can not be before buildup start date
+ }
+ if (isset($event_config['buildup_start_date']) && $planned_departure_date < $event_config['buildup_start_date']) {
+ // Planned arrival can not be before buildup start date
return new ValidationResult(false, $event_config['buildup_start_date']);
- }
- if (isset($event_config['teardown_end_date']) && $planned_departure_date > $event_config['teardown_end_date']) {
- // Planned arrival can not be after teardown end date
+ }
+ if (isset($event_config['teardown_end_date']) && $planned_departure_date > $event_config['teardown_end_date']) {
+ // Planned arrival can not be after teardown end date
return new ValidationResult(false, $event_config['teardown_end_date']);
- }
- return new ValidationResult(true, $planned_departure_date);
+ }
+ return new ValidationResult(true, $planned_departure_date);
}
/**
* Returns user by id.
*
- * @param $user_id UID
+ * @param $user_id UID
*/
-function User($user_id) {
- $user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
- if ($user_source === false) {
- engelsystem_error("Unable to load user.");
- }
- if (count($user_source) > 0) {
- return $user_source[0];
- }
- return null;
+function User($user_id)
+{
+ $user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
+ if ($user_source === false) {
+ engelsystem_error("Unable to load user.");
+ }
+ if (count($user_source) > 0) {
+ return $user_source[0];
+ }
+ return null;
}
/**
@@ -281,94 +300,98 @@ function User($user_id) {
* User api key
* @return Matching user, null or false on error
*/
-function User_by_api_key($api_key) {
- $user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1");
- if ($user === false) {
- engelsystem_error("Unable to find user by api key.");
- }
- if (count($user) == 0) {
- return null;
- }
- return $user[0];
+function User_by_api_key($api_key)
+{
+ $user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1");
+ if ($user === false) {
+ engelsystem_error("Unable to find user by api key.");
+ }
+ if (count($user) == 0) {
+ return null;
+ }
+ return $user[0];
}
/**
* Returns User by email.
*
- * @param string $email
+ * @param string $email
* @return Matching user, null or false on error
*/
-function User_by_email($email) {
- $user = sql_select("SELECT * FROM `User` WHERE `email`='" . sql_escape($email) . "' LIMIT 1");
- if ($user === false) {
- engelsystem_error("Unable to load user.");
- }
- if (count($user) == 0) {
- return null;
- }
- return $user[0];
+function User_by_email($email)
+{
+ $user = sql_select("SELECT * FROM `User` WHERE `email`='" . sql_escape($email) . "' LIMIT 1");
+ if ($user === false) {
+ engelsystem_error("Unable to load user.");
+ }
+ if (count($user) == 0) {
+ return null;
+ }
+ return $user[0];
}
/**
* Returns User by password token.
*
- * @param string $token
+ * @param string $token
* @return Matching user, null or false on error
*/
-function User_by_password_recovery_token($token) {
- $user = sql_select("SELECT * FROM `User` WHERE `password_recovery_token`='" . sql_escape($token) . "' LIMIT 1");
- if ($user === false) {
- engelsystem_error("Unable to load user.");
- }
- if (count($user) == 0) {
- return null;
- }
- return $user[0];
+function User_by_password_recovery_token($token)
+{
+ $user = sql_select("SELECT * FROM `User` WHERE `password_recovery_token`='" . sql_escape($token) . "' LIMIT 1");
+ if ($user === false) {
+ engelsystem_error("Unable to load user.");
+ }
+ if (count($user) == 0) {
+ return null;
+ }
+ return $user[0];
}
/**
* Generates a new api key for given user.
*
- * @param User $user
+ * @param User $user
*/
-function User_reset_api_key(&$user, $log = true) {
- $user['api_key'] = md5($user['Nick'] . time() . rand());
- $result = sql_query("UPDATE `User` SET `api_key`='" . sql_escape($user['api_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
- if ($result === false) {
- return false;
- }
- if ($log) {
- engelsystem_log(sprintf("API key resetted (%s).", User_Nick_render($user)));
- }
+function User_reset_api_key(&$user, $log = true)
+{
+ $user['api_key'] = md5($user['Nick'] . time() . rand());
+ $result = sql_query("UPDATE `User` SET `api_key`='" . sql_escape($user['api_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
+ if ($result === false) {
+ return false;
+ }
+ if ($log) {
+ engelsystem_log(sprintf("API key resetted (%s).", User_Nick_render($user)));
+ }
}
/**
* Generates a new password recovery token for given user.
*
- * @param User $user
+ * @param User $user
*/
-function User_generate_password_recovery_token(&$user) {
- $user['password_recovery_token'] = md5($user['Nick'] . time() . rand());
- $result = sql_query("UPDATE `User` SET `password_recovery_token`='" . sql_escape($user['password_recovery_token']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
- if ($result === false) {
- engelsystem_error("Unable to generate password recovery token.");
- }
- engelsystem_log("Password recovery for " . User_Nick_render($user) . " started.");
- return $user['password_recovery_token'];
+function User_generate_password_recovery_token(&$user)
+{
+ $user['password_recovery_token'] = md5($user['Nick'] . time() . rand());
+ $result = sql_query("UPDATE `User` SET `password_recovery_token`='" . sql_escape($user['password_recovery_token']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
+ if ($result === false) {
+ engelsystem_error("Unable to generate password recovery token.");
+ }
+ engelsystem_log("Password recovery for " . User_Nick_render($user) . " started.");
+ return $user['password_recovery_token'];
}
-function User_get_eligable_voucher_count(&$user) {
- global $voucher_settings;
+function User_get_eligable_voucher_count(&$user)
+{
+ global $voucher_settings;
- $shifts_done = count(ShiftEntries_finished_by_user($user));
+ $shifts_done = count(ShiftEntries_finished_by_user($user));
- $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers'];
- $elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
- if ($elegible_vouchers < 0) {
- return 0;
- }
+ $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers'];
+ $elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
+ if ($elegible_vouchers < 0) {
+ return 0;
+ }
- return $elegible_vouchers;
+ return $elegible_vouchers;
}
-
-?>
diff --git a/includes/model/ValidationResult.php b/includes/model/ValidationResult.php
index 0fc24161..7dfcb5ba 100644
--- a/includes/model/ValidationResult.php
+++ b/includes/model/ValidationResult.php
@@ -6,11 +6,11 @@ namespace Engelsystem;
* BO that represents the result of an entity attribute validation.
* It contains the validated value and a bool for validation success.
*/
-class ValidationResult {
+class ValidationResult
+{
+ private $valid;
- private $valid;
-
- private $value;
+ private $value;
/**
* Constructor.
@@ -20,23 +20,25 @@ class ValidationResult {
* @param * $value
* The validated value
*/
- public function __construct($valid, $value) {
- $this->valid = $valid;
- $this->value = $value;
+ public function __construct($valid, $value)
+ {
+ $this->valid = $valid;
+ $this->value = $value;
}
/**
* Is the value valid?
*/
- public function isValid() {
- return $this->valid;
+ public function isValid()
+ {
+ return $this->valid;
}
/**
* The parsed/validated value.
*/
- public function getValue() {
- return $this->value;
+ public function getValue()
+ {
+ return $this->value;
}
}
-?> \ No newline at end of file