diff options
Diffstat (limited to 'includes/model')
-rw-r--r-- | includes/model/LogEntries_model.php | 9 | ||||
-rw-r--r-- | includes/model/Room_model.php | 34 | ||||
-rw-r--r-- | includes/model/ShiftTypes_model.php | 2 | ||||
-rw-r--r-- | includes/model/Shifts_model.php | 10 | ||||
-rw-r--r-- | includes/model/UserAngelTypes_model.php | 14 | ||||
-rw-r--r-- | includes/model/User_model.php | 10 |
6 files changed, 59 insertions, 20 deletions
diff --git a/includes/model/LogEntries_model.php b/includes/model/LogEntries_model.php index d13c3692..8b7f65a0 100644 --- a/includes/model/LogEntries_model.php +++ b/includes/model/LogEntries_model.php @@ -12,7 +12,7 @@ function LogEntry_create($nick, $message) { } /** - * Returns log entries of the last 24 hours with maximum count of 1000. + * Returns log entries with maximum count of 10000. */ function LogEntries() { return sql_select("SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000"); @@ -25,4 +25,11 @@ function LogEntries_filter($keyword) { 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`"); +} + ?> diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php index 523436c6..2868916e 100644 --- a/includes/model/Room_model.php +++ b/includes/model/Room_model.php @@ -1,15 +1,33 @@ <?php /** - * Returns room id array + * Delete a room + * @param int $room_id */ -function Room_ids() { - $room_source = sql_select("SELECT `RID` FROM `Room` WHERE `show` = 'Y'"); - if ($room_source === false) +function Room_delete($room_id) { + return sql_query("DELETE FROM `Room` WHERE `RID`=" . sql_escape($room_id)); +} + +/** + * Create a new room + * + * @param string $name + * Name of the room + * @param boolean $from_frab + * Is this a frab imported room? + * @param boolean $public + * Is the room visible for angels? + */ +function Room_create($name, $from_frab, $public) { + $result = sql_query(" + INSERT INTO `Room` SET + `Name`='" . sql_escape($name) . "', + `FromPentabarf`='" . sql_escape($from_frab ? 'Y' : 'N') . "', + `show`='" . sql_escape($public ? 'Y' : 'N') . "', + `Number`=0"); + if ($result === false) return false; - if (count($room_source) > 0) - return $room_source; - return null; + return sql_id(); } /** @@ -18,7 +36,7 @@ function Room_ids() { * @param $id RID */ function Room($id) { - $room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($id) . "' AND `show` = 'Y' LIMIT 1"); + $room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($id) . "' AND `show` = 'Y'"); if ($room_source === false) return false; diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php index 907ad076..7f057da8 100644 --- a/includes/model/ShiftTypes_model.php +++ b/includes/model/ShiftTypes_model.php @@ -35,7 +35,7 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) { function ShiftType_create($name, $angeltype_id, $description) { $result = sql_query("INSERT INTO `ShiftTypes` SET `name`='" . sql_escape($name) . "', - `angeltype_id`='" . sql_null($angeltype_id) . "', + `angeltype_id`=" . sql_null($angeltype_id) . ", `description`='" . sql_escape($description) . "'"); if ($result === false) return false; diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index c12d3e01..d32de0cb 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -101,6 +101,7 @@ function Shift_delete($shift_id) { * Update a shift. */ function Shift_update($shift) { + global $user; $shift['name'] = ShiftType($shift['shifttype_id'])['name']; mail_shift_change(Shift($shift['SID']), $shift); @@ -111,7 +112,9 @@ function Shift_update($shift) { `RID`='" . sql_escape($shift['RID']) . "', `title`=" . sql_null($shift['title']) . ", `URL`=" . sql_null($shift['URL']) . ", - `PSID`=" . sql_null($shift['PSID']) . " + `PSID`=" . sql_null($shift['PSID']) . ", + `edited_by_user_id`='" . sql_escape($user['UID']) . "', + `edited_at_timestamp`=" . time() . " WHERE `SID`='" . sql_escape($shift['SID']) . "'"); } @@ -134,6 +137,7 @@ 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 `shifttype_id`='" . sql_escape($shift['shifttype_id']) . "', `start`='" . sql_escape($shift['start']) . "', @@ -141,7 +145,9 @@ function Shift_create($shift) { `RID`='" . sql_escape($shift['RID']) . "', `title`=" . sql_null($shift['title']) . ", `URL`=" . sql_null($shift['URL']) . ", - `PSID`=" . sql_null($shift['PSID'])); + `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(); diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index 19686480..b2ebd9fe 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -19,13 +19,19 @@ function User_angeltypes($user) { */ function User_unconfirmed_AngelTypes($user) { return sql_select(" - SELECT `UnconfirmedMembers`.*, `AngelTypes`.`name` FROM `UserAngelTypes` + SELECT + `UserAngelTypes`.*, + `AngelTypes`.`name`, + count(`UnconfirmedMembers`.`user_id`) as `count` + FROM `UserAngelTypes` JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` JOIN `UserAngelTypes` as `UnconfirmedMembers` ON `UserAngelTypes`.`angeltype_id`=`UnconfirmedMembers`.`angeltype_id` WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "' - AND `UserAngelTypes`.`coordinator`=TRUE - AND `AngelTypes`.`restricted`=TRUE - AND `UnconfirmedMembers`.`confirm_user_id` IS NULL"); + AND `UserAngelTypes`.`coordinator`=TRUE + AND `AngelTypes`.`restricted`=TRUE + AND `UnconfirmedMembers`.`confirm_user_id` IS NULL + GROUP BY `UserAngelTypes`.`angeltype_id` + ORDER BY `AngelTypes`.`name`"); } /** diff --git a/includes/model/User_model.php b/includes/model/User_model.php index c6f8e3bf..bd3ec31f 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -29,8 +29,10 @@ function User_update($user) { `color`='" . sql_escape($user['color']) . "', `Sprache`='" . sql_escape($user['Sprache']) . "', `Hometown`='" . sql_escape($user['Hometown']) . "', - `got_voucher`=" . sql_bool($user['got_voucher']) . " - WHERE `UID`='" . sql_escape($user['UID']). "'"); + `got_voucher`='" . sql_escape($user['got_voucher']) . "', + `arrival_date`='" . sql_escape($user['arrival_date']) . "', + `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "' + WHERE `UID`='" . sql_escape($user['UID']) . "'"); } /** @@ -45,7 +47,7 @@ function User_active_count() { } function User_got_voucher_count() { - return sql_select_single_cell("SELECT COUNT(*) FROM `User` WHERE `got_voucher` = TRUE"); + return sql_select_single_cell("SELECT SUM(`got_voucher`) FROM `User`"); } function User_arrived_count() { @@ -165,7 +167,7 @@ function User($id) { * @param $id UID */ function mUser_Limit($id) { - $user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `jabber`, `Avatar` FROM `User` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1"); + $user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `jabber` FROM `User` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1"); if ($user_source === false) return false; if (count($user_source) > 0) |