From 0a74ab94a8ebc93a7624e0bef90dfd7d8024deaa Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Sun, 7 Dec 2014 17:07:19 +0100 Subject: add shift entry delete model --- includes/model/ShiftEntry_model.php | 12 +++++++++++- includes/model/Shifts_model.php | 1 + includes/pages/user_myshifts.php | 9 +++++---- includes/pages/user_shifts.php | 6 ++++-- 4 files changed, 21 insertions(+), 7 deletions(-) (limited to 'includes') diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index 20d0946f..f84b312f 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -7,9 +7,12 @@ 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(" - SELECT `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded` + SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `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` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` @@ -31,6 +34,13 @@ function ShiftEntry_create($shift_entry) { `freeloaded`=" . sql_escape($shift_entry['freeloaded'] ? 'TRUE' : 'FALSE')); } +/** + * Delete a shift entry. + */ +function ShiftEntry_delete($shift_entry_id) { + return sql_query("DELETE FROM `ShiftEntry` WHERE `id`=" . sql_escape($shift_entry_id)); +} + /** * Returns next (or current) shifts of given user. * diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 5d0ec4a2..c66cfb83 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -1,4 +1,5 @@ 0) { $shift = $shift[0]; if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) { - sql_query("DELETE FROM `ShiftEntry` WHERE `id`=" . sql_escape($id) . " LIMIT 1"); - $msg .= success(_("You have been signed off from the shift."), true); + $result = ShiftEntry_delete($id); + if ($result === false) + engelsystem_error('Unable to delete shift entry.'); + success(_("You have been signed off from the shift.")); } else - $msg .= error(_("It's too late to sign yourself off the shift. If neccessary, ask the dispatcher to do so."), true); + error(_("It's too late to sign yourself off the shift. If neccessary, ask the dispatcher to do so.")); } else redirect(page_link_to('user_myshifts')); } - msg(); redirect(page_link_to('users') . '&action=view'); } ?> diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index ee8e3b19..07f10ea2 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -20,7 +20,10 @@ function user_shifts() { $shift_entry_source = sql_select("SELECT `User`.`Nick`, `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type` FROM `ShiftEntry` JOIN `User` ON (`User`.`UID`=`ShiftEntry`.`UID`) JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `ShiftEntry`.`id`=" . sql_escape($entry_id) . " LIMIT 1"); if (count($shift_entry_source) > 0) { $shift_entry_source = $shift_entry_source[0]; - sql_query("DELETE FROM `ShiftEntry` WHERE `id`=" . sql_escape($entry_id) . " LIMIT 1"); + + $result = ShiftEntry_delete($entry_id); + if ($result === false) + engelsystem_error('Unable to delete shift entry.'); engelsystem_log("Deleted " . User_Nick_render($shift_entry_source) . "'s shift: " . $shift_entry_source['name'] . " at " . $shift_entry_source['Name'] . " from " . date("y-m-d H:i", $shift_entry_source['start']) . " to " . date("y-m-d H:i", $shift_entry_source['end']) . " as " . $shift_entry_source['angel_type']); success(_("Shift entry deleted.")); @@ -169,7 +172,6 @@ function user_shifts() { // Schicht löschen bestätigt if (isset($_REQUEST['delete'])) { - sql_query("DELETE FROM `ShiftEntry` WHERE `SID`=" . sql_escape($shift_id)); sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`=" . sql_escape($shift_id)); sql_query("DELETE FROM `Shifts` WHERE `SID`=" . sql_escape($shift_id) . " LIMIT 1"); -- cgit v1.2.3-54-g00ecf From 156db1eadd905c7ee4c7c37dc246c8c689ae2396 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Sun, 7 Dec 2014 17:13:14 +0100 Subject: add shift entry update model --- includes/model/ShiftEntry_model.php | 11 +++++++++++ includes/pages/admin_user.php | 1 - includes/pages/user_myshifts.php | 15 +++++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'includes') diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index f84b312f..903bc544 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -34,6 +34,17 @@ function ShiftEntry_create($shift_entry) { `freeloaded`=" . sql_escape($shift_entry['freeloaded'] ? 'TRUE' : 'FALSE')); } +/** + * Update a shift entry. + */ +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_escape($shift_entry['freeloaded'] ? 'TRUE' : 'FALSE') . " + WHERE `id`=" . sql_escape($shift_entry['id'])); +} + /** * Delete a shift entry. */ diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index 87190857..4e10ca1e 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -215,7 +215,6 @@ function admin_user() { $user_source = sql_select("SELECT `Nick`, `UID` FROM `User` WHERE `UID` = '" . sql_escape($id) . "' LIMIT 1"); sql_query("DELETE FROM `User` WHERE `UID`=" . sql_escape($id) . " LIMIT 1"); sql_query("DELETE FROM `UserGroups` WHERE `uid`=" . sql_escape($id)); - sql_query("UPDATE `ShiftEntry` SET `UID`=0, `Comment`=NULL WHERE `UID`=" . sql_escape($id)); engelsystem_log("Deleted user " . User_Nick_render($user_source)); $html .= success("Benutzer gelöscht!", true); } else { diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 41ea9381..d74475d2 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -57,12 +57,15 @@ function user_myshifts() { $comment = strip_request_item_nl('comment'); $user_source = User($shift['UID']); - sql_query("UPDATE `ShiftEntry` SET - `Comment`='" . sql_escape($comment) . "', - `freeloaded`=" . sql_escape($freeloaded ? 1 : 0) . ", - `freeload_comment`='" . sql_escape($freeload_comment) . "' - WHERE `id`=" . sql_escape($id) . " - LIMIT 1"); + $result = ShiftEntry_update(array( + 'id' => $id, + 'Comment' => $comment, + 'freeloaded' => $freeloaded, + 'freeload_comment' => $freeload_comment + )); + if ($result === false) + engelsystem_error('Unable to update shift entr.'); + engelsystem_log("Updated " . User_Nick_render($user_source) . "'s shift " . $shift['name'] . " from " . date("y-m-d H:i", $shift['start']) . " to " . date("y-m-d H:i", $shift['end']) . " with comment " . $comment); success(_("Shift saved.")); redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']); -- cgit v1.2.3-54-g00ecf From fa0e38ebff81a02f89bd4493627c49bbc48bc93b Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Sun, 7 Dec 2014 17:34:29 +0100 Subject: add shift create model --- includes/model/Shifts_model.php | 20 +++++++++++++++++++ includes/mysqli_provider.php | 43 ++++++++++++++++++++++++----------------- includes/pages/admin_import.php | 10 +++++++--- includes/pages/admin_shifts.php | 10 +++++++--- public/index.php | 8 ++++---- 5 files changed, 63 insertions(+), 28 deletions(-) (limited to 'includes') diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index c66cfb83..a9a9244e 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -1,5 +1,25 @@ close(); } +/** + * Return NULL if given value is null. + */ +function sql_null($value = null) { + return $value == null ? 'NULL' : ("'" . sql_escape($value) . "'"); +} + /** * Start new transaction. */ function sql_transaction_start() { global $sql_nested_transaction_level; - + if ($sql_nested_transaction_level ++ == 0) return sql_query("BEGIN"); else @@ -26,7 +33,7 @@ function sql_transaction_start() { */ function sql_transaction_commit() { global $sql_nested_transaction_level; - + if (-- $sql_nested_transaction_level == 0) return sql_query("COMMIT"); else @@ -38,7 +45,7 @@ function sql_transaction_commit() { */ function sql_transaction_rollback() { global $sql_nested_transaction_level; - + if (-- $sql_nested_transaction_level == 0) return sql_query("ROLLBACK"); else @@ -48,17 +55,17 @@ function sql_transaction_rollback() { /** * Logs an sql error. * - * @param string $message + * @param string $message * @return false */ function sql_error($message) { sql_close(); - + $message = trim($message) . "\n"; $message .= debug_string_backtrace() . "\n"; - + error_log('mysql_provider error: ' . $message); - + return false; } @@ -77,19 +84,19 @@ function sql_error($message) { */ function sql_connect($host, $user, $pass, $db) { global $sql_connection; - + $sql_connection = new mysqli($host, $user, $pass, $db); if ($sql_connection->connect_errno) return sql_error("Unable to connect to MySQL: " . $sql_connection->connect_error); - + $result = $sql_connection->query("SET CHARACTER SET utf8;"); if (! $result) return sql_error("Unable to set utf8 character set (" . $sql_connection->errno . ") " . $sql_connection->error); - + $result = $sql_connection->set_charset('utf8'); if (! $result) return sql_error("Unable to set utf8 names (" . $sql_connection->errno . ") " . $sql_connection->error); - + return $sql_connection; } @@ -110,12 +117,12 @@ function sql_select_db($db_name) { /** * MySQL SELECT query * - * @param string $query + * @param string $query * @return Result array or false on error */ function sql_select($query) { global $sql_connection; - + $result = $sql_connection->query($query); if ($result) { $data = array(); @@ -129,12 +136,12 @@ function sql_select($query) { /** * MySQL execute a query * - * @param string $query + * @param string $query * @return mysqli_result boolean resource or false on error */ function sql_query($query) { global $sql_connection; - + $result = $sql_connection->query($query); if ($result) { return $result; @@ -155,7 +162,7 @@ function sql_id() { /** * Escape a string for a sql query. * - * @param string $query + * @param string $query * @return string */ function sql_escape($query) { @@ -166,7 +173,7 @@ function sql_escape($query) { /** * Count query result lines. * - * @param string $query + * @param string $query * @return int Count of result lines */ function sql_num_query($query) { diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php index 8362391d..31b73992 100644 --- a/includes/pages/admin_import.php +++ b/includes/pages/admin_import.php @@ -1,4 +1,5 @@ $count) { diff --git a/public/index.php b/public/index.php index 0ba203b0..cd77f9f3 100644 --- a/public/index.php +++ b/public/index.php @@ -82,7 +82,7 @@ $free_pages = array( 'api', 'credits', 'angeltypes', - 'users' + 'users' ); // Gewünschte Seite/Funktion @@ -91,10 +91,10 @@ if (! isset($_REQUEST['p'])) $_REQUEST['p'] = isset($user) ? "news" : "login"; if (isset($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && (in_array($_REQUEST['p'], $free_pages) || in_array($_REQUEST['p'], $privileges))) { $p = $_REQUEST['p']; - + $title = $p; $content = ""; - + if ($p == "api") { require_once realpath(__DIR__ . '/../includes/controller/api.php'); error("Api disabled temporily."); @@ -222,7 +222,7 @@ echo template_render('../templates/layout.html', array( 'content' => msg() . $content, 'header_toolbar' => header_toolbar(), 'faq_url' => $faq_url, - 'locale' => $_SESSION['locale'] + 'locale' => $_SESSION['locale'] )); counter(); -- cgit v1.2.3-54-g00ecf From d26f8aa12cd71cd5301e6747fbedf6bfbe2ac37f Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Sun, 7 Dec 2014 17:41:40 +0100 Subject: add shift update model --- includes/model/Shifts_model.php | 28 ++++++++++++++++++++++++++++ includes/pages/admin_import.php | 7 +++++-- includes/pages/user_shifts.php | 8 +++++++- 3 files changed, 40 insertions(+), 3 deletions(-) (limited to 'includes') diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index a9a9244e..a1d7967f 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -1,7 +1,35 @@ $count) { -- cgit v1.2.3-54-g00ecf From b75700ee1bf4bc07f1da7899aac864cb561022f4 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Sun, 7 Dec 2014 17:48:35 +0100 Subject: add shift delete model --- includes/model/Shifts_model.php | 14 ++++++++++++++ includes/pages/admin_import.php | 7 +++++-- includes/pages/user_shifts.php | 5 +++-- 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'includes') diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index a1d7967f..28f84c26 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -1,5 +1,19 @@