summaryrefslogtreecommitdiff
path: root/includes/model/User_model.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/model/User_model.php')
-rw-r--r--includes/model/User_model.php104
1 files changed, 100 insertions, 4 deletions
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index 576bb3f5..6d38a224 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -29,6 +29,7 @@ function User_update($user) {
`Handy`='" . sql_escape($user['Handy']) . "',
`email`='" . sql_escape($user['email']) . "',
`email_shiftinfo`=" . sql_bool($user['email_shiftinfo']) . ",
+ `email_by_human_allowed`=" . sql_bool($user['email_by_human_allowed']) . ",
`jabber`='" . sql_escape($user['jabber']) . "',
`Size`='" . sql_escape($user['Size']) . "',
`Gekommen`='" . sql_escape($user['Gekommen']) . "',
@@ -40,7 +41,8 @@ function User_update($user) {
`Hometown`='" . sql_escape($user['Hometown']) . "',
`got_voucher`='" . sql_escape($user['got_voucher']) . "',
`arrival_date`='" . sql_escape($user['arrival_date']) . "',
- `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "'
+ `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "',
+ `planned_departure_date`='" . sql_escape($user['planned_departure_date']) . "'
WHERE `UID`='" . sql_escape($user['UID']) . "'");
}
@@ -113,12 +115,16 @@ function User_is_freeloader($user) {
* @param Angeltype $angeltype
*/
function Users_by_angeltype_inverted($angeltype) {
- return sql_select("
+ $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;
}
/**
@@ -132,7 +138,7 @@ function Users_by_angeltype($angeltype) {
`User`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`,
- `UserAngelTypes`.`coordinator`,
+ `UserAngelTypes`.`supporter`,
`UserDriverLicenses`.*
FROM `User`
JOIN `UserAngelTypes` ON `User`.`UID`=`UserAngelTypes`.`user_id`
@@ -158,6 +164,96 @@ function User_validate_Nick($nick) {
}
/**
+ * Validate user email address.
+ *
+ * @param string $mail
+ * The email address to validate
+ * @return ValidationResult
+ */
+function User_validate_mail($mail) {
+ $mail = strip_item($mail);
+ return new ValidationResult(check_email($mail), $mail);
+}
+
+/**
+ * Validate user jabber address
+ *
+ * @param string $jabber
+ * Jabber-ID to validate
+ * @return ValidationResult
+ */
+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);
+}
+
+/**
+ * Validate the planned arrival date
+ *
+ * @param int $planned_arrival_date
+ * Unix timestamp
+ * @return ValidationResult
+ */
+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
+ 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
+ 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
+ return new ValidationResult(false, $event_config['teardown_end_date']);
+ }
+ return new ValidationResult(true, $planned_arrival_date);
+}
+
+/**
+ * Validate the planned departure date
+ *
+ * @param int $planned_arrival_date
+ * Unix timestamp
+ * @param int $planned_departure_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
+ return new ValidationResult(true, null);
+ }
+ 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
+ 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
+ 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
+ return new ValidationResult(false, $event_config['teardown_end_date']);
+ }
+ return new ValidationResult(true, $planned_departure_date);
+}
+
+/**
* Returns user by id.
*
* @param $user_id UID
@@ -165,7 +261,7 @@ function User_validate_Nick($nick) {
function User($user_id) {
$user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
if ($user_source === false) {
- return false;
+ engelsystem_error("Unable to load user.");
}
if (count($user_source) > 0) {
return $user_source[0];