From f1145b8a5e8630e0180d35ff1ced2e934b872f01 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Tue, 13 May 2014 15:51:45 +0200 Subject: implemented team/angeltype coordinators --- README | 6 +- db/install.sql | 73 ++------ db/update.sql | 6 +- includes/controller/angeltypes_controller.php | 12 +- includes/controller/user_angeltypes_controller.php | 200 ++++++++++++++++----- includes/model/AngelType_model.php | 3 +- includes/model/UserAngelTypes_model.php | 37 +++- includes/model/User_model.php | 26 ++- includes/view/AngelTypes_view.php | 52 +++++- includes/view/UserAngelTypes_view.php | 30 +++- 10 files changed, 318 insertions(+), 127 deletions(-) diff --git a/README b/README index cf60f29a..625f2d40 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ = Installation eines frischen Engelsystems = Mindestvorrausetzungen (bzw. getestet unter): - * PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cgi-fcgi) + * PHP 5.4.x with Suhosin-Patch (cgi-fcgi) * mysqld Ver 5.1.49-3 for debian-linux-gnu on x86_64 ((Debian)) * Webserver mit PHP-Anbindung, z.B. lighttpd, nginx oder Apache @@ -13,10 +13,10 @@ Vorgehen: * Es muss eine MySQL-Datenbank angelegt werden und ein User existieren, der alle Rechte auf dieser Datenbank besitzt. * Es muss die db/install.sql importiert/ausgeführt werden. * Erstelle bei Bedarf eine config/config.php, die die Werte (z.B. DB-Zugang) aus der config/config.default.php überschreibt. - * Engelsystem im Browser aufrufen, Anmeldung mit admin:admin vornehmen und Admin-Passwort ändern. + * Engelsystem im Browser aufrufen, Anmeldung mit admin:asdfasdf vornehmen und Admin-Passwort ändern. Das Engelsystem ist jetzt einsatzbereit. Fehler bitte an bugs@engelsystem.de melden. -Trac: https://vcs.wybt.net/engelsystem/trac/ +Bugtracker: https://vcs.wybt.net/engelsystem/trac/ diff --git a/db/install.sql b/db/install.sql index 7f9fe8f1..1fc4b939 100644 --- a/db/install.sql +++ b/db/install.sql @@ -3,7 +3,7 @@ -- http://www.phpmyadmin.net -- -- Host: localhost --- Erstellungszeit: 09. Mrz 2014 um 13:11 +-- Erstellungszeit: 13. Mai 2014 um 15:50 -- Server Version: 5.6.12 -- PHP-Version: 5.5.3 @@ -14,8 +14,6 @@ SET time_zone = "+00:00"; -- -- Datenbank: `engelsystem` -- -CREATE DATABASE IF NOT EXISTS `engelsystem` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; -USE `engelsystem`; -- -------------------------------------------------------- @@ -23,7 +21,6 @@ USE `engelsystem`; -- Tabellenstruktur für Tabelle `AngelTypes` -- -DROP TABLE IF EXISTS `AngelTypes`; CREATE TABLE IF NOT EXISTS `AngelTypes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(25) NOT NULL DEFAULT '', @@ -31,7 +28,7 @@ CREATE TABLE IF NOT EXISTS `AngelTypes` ( `description` text NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `Name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; -- -- Daten für Tabelle `AngelTypes` @@ -46,35 +43,18 @@ INSERT INTO `AngelTypes` (`id`, `name`, `restricted`, `description`) VALUES -- Tabellenstruktur für Tabelle `Counter` -- -DROP TABLE IF EXISTS `Counter`; CREATE TABLE IF NOT EXISTS `Counter` ( `URL` varchar(255) NOT NULL DEFAULT '', `Anz` bigint(20) NOT NULL DEFAULT '0', PRIMARY KEY (`URL`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Counter der Seiten'; --- --- Daten für Tabelle `Counter` --- - -INSERT INTO `Counter` (`URL`, `Anz`) VALUES -('admin_user', 2), -('angeltypes', 33), -('login', 11), -('news', 6), -('register', 1), -('user_angeltypes', 2), -('user_meetings', 1), -('user_myshifts', 2), -('user_settings', 7); - -- -------------------------------------------------------- -- -- Tabellenstruktur für Tabelle `GroupPrivileges` -- -DROP TABLE IF EXISTS `GroupPrivileges`; CREATE TABLE IF NOT EXISTS `GroupPrivileges` ( `id` int(11) NOT NULL AUTO_INCREMENT, `group_id` int(11) NOT NULL, @@ -138,7 +118,6 @@ INSERT INTO `GroupPrivileges` (`id`, `group_id`, `privilege_id`) VALUES -- Tabellenstruktur für Tabelle `Groups` -- -DROP TABLE IF EXISTS `Groups`; CREATE TABLE IF NOT EXISTS `Groups` ( `Name` varchar(35) NOT NULL, `UID` int(11) NOT NULL, @@ -163,7 +142,6 @@ INSERT INTO `Groups` (`Name`, `UID`) VALUES -- Tabellenstruktur für Tabelle `LogEntries` -- -DROP TABLE IF EXISTS `LogEntries`; CREATE TABLE IF NOT EXISTS `LogEntries` ( `id` int(11) NOT NULL AUTO_INCREMENT, `timestamp` int(11) NOT NULL, @@ -171,19 +149,7 @@ CREATE TABLE IF NOT EXISTS `LogEntries` ( `message` text NOT NULL, PRIMARY KEY (`id`), KEY `timestamp` (`timestamp`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ; - --- --- Daten für Tabelle `LogEntries` --- - -INSERT INTO `LogEntries` (`id`, `timestamp`, `nick`, `message`) VALUES -(1, 1390991375, 'admin', 'Created angeltype: testengel, restricted: 0'), -(2, 1390991407, 'admin', 'User admin joined testengel.'), -(3, 1390991407, 'admin', 'User admin confirmed as testengel.'), -(4, 1394366820, 'admin', 'Updated angeltype: testengel, restricted: 0'), -(5, 1394366908, 'admin', 'Updated angeltype: testengel, restricted: 0'), -(6, 1394367023, 'admin', 'Own angel types set to: testengel'); +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; -- -------------------------------------------------------- @@ -191,7 +157,6 @@ INSERT INTO `LogEntries` (`id`, `timestamp`, `nick`, `message`) VALUES -- Tabellenstruktur für Tabelle `Messages` -- -DROP TABLE IF EXISTS `Messages`; CREATE TABLE IF NOT EXISTS `Messages` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Datum` int(11) NOT NULL, @@ -211,7 +176,6 @@ CREATE TABLE IF NOT EXISTS `Messages` ( -- Tabellenstruktur für Tabelle `NeededAngelTypes` -- -DROP TABLE IF EXISTS `NeededAngelTypes`; CREATE TABLE IF NOT EXISTS `NeededAngelTypes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `room_id` int(11) DEFAULT NULL, @@ -230,7 +194,6 @@ CREATE TABLE IF NOT EXISTS `NeededAngelTypes` ( -- Tabellenstruktur für Tabelle `News` -- -DROP TABLE IF EXISTS `News`; CREATE TABLE IF NOT EXISTS `News` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Datum` int(11) NOT NULL, @@ -240,7 +203,7 @@ CREATE TABLE IF NOT EXISTS `News` ( `Treffen` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), KEY `UID` (`UID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; -- -------------------------------------------------------- @@ -248,7 +211,6 @@ CREATE TABLE IF NOT EXISTS `News` ( -- Tabellenstruktur für Tabelle `NewsComments` -- -DROP TABLE IF EXISTS `NewsComments`; CREATE TABLE IF NOT EXISTS `NewsComments` ( `ID` bigint(11) NOT NULL AUTO_INCREMENT, `Refid` int(11) NOT NULL DEFAULT '0', @@ -266,7 +228,6 @@ CREATE TABLE IF NOT EXISTS `NewsComments` ( -- Tabellenstruktur für Tabelle `Privileges` -- -DROP TABLE IF EXISTS `Privileges`; CREATE TABLE IF NOT EXISTS `Privileges` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL, @@ -323,7 +284,6 @@ INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES -- Tabellenstruktur für Tabelle `Questions` -- -DROP TABLE IF EXISTS `Questions`; CREATE TABLE IF NOT EXISTS `Questions` ( `QID` bigint(20) NOT NULL AUTO_INCREMENT, `UID` int(11) NOT NULL DEFAULT '0', @@ -341,7 +301,6 @@ CREATE TABLE IF NOT EXISTS `Questions` ( -- Tabellenstruktur für Tabelle `Room` -- -DROP TABLE IF EXISTS `Room`; CREATE TABLE IF NOT EXISTS `Room` ( `RID` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(35) NOT NULL DEFAULT '', @@ -359,7 +318,6 @@ CREATE TABLE IF NOT EXISTS `Room` ( -- Tabellenstruktur für Tabelle `ShiftEntry` -- -DROP TABLE IF EXISTS `ShiftEntry`; CREATE TABLE IF NOT EXISTS `ShiftEntry` ( `id` int(11) NOT NULL AUTO_INCREMENT, `SID` int(11) NOT NULL DEFAULT '0', @@ -381,7 +339,6 @@ CREATE TABLE IF NOT EXISTS `ShiftEntry` ( -- Tabellenstruktur für Tabelle `Shifts` -- -DROP TABLE IF EXISTS `Shifts`; CREATE TABLE IF NOT EXISTS `Shifts` ( `SID` int(11) NOT NULL AUTO_INCREMENT, `start` int(11) NOT NULL, @@ -401,7 +358,6 @@ CREATE TABLE IF NOT EXISTS `Shifts` ( -- Tabellenstruktur für Tabelle `User` -- -DROP TABLE IF EXISTS `User`; CREATE TABLE IF NOT EXISTS `User` ( `UID` int(11) NOT NULL AUTO_INCREMENT, `Nick` varchar(23) NOT NULL DEFAULT '', @@ -436,14 +392,14 @@ CREATE TABLE IF NOT EXISTS `User` ( KEY `api_key` (`api_key`), KEY `password_recovery_token` (`password_recovery_token`), KEY `force_active` (`force_active`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ; -- -- Daten für Tabelle `User` -- INSERT INTO `User` (`UID`, `Nick`, `Name`, `Vorname`, `Alter`, `Telefon`, `DECT`, `Handy`, `email`, `ICQ`, `jabber`, `Size`, `Passwort`, `password_recovery_token`, `Gekommen`, `Aktiv`, `force_active`, `Tshirt`, `color`, `Sprache`, `Avatar`, `Menu`, `lastLogIn`, `CreateDate`, `Art`, `kommentar`, `Hometown`, `api_key`) VALUES -(1, 'admin', 'Gates', 'Bill', 42, '', '-', '', 'admin@example.com', '', '', 'XL', '$6$rounds=5000$hjXbIhoRTH3vKiRa$Wl2P2iI5T9iRR.HHu/YFHswBW0WVn0yxCfCiX0Keco9OdIoDK6bIAADswP6KvMCJSwTGdV8PgA8g8Xfw5l8BD1', NULL, 1, 0, 1, 0, 1, 'de_DE.UTF-8', 115, 'L', 1394367023, '0000-00-00 00:00:00', '', '', '', '038850abdd1feb264406be3ffa746235'); +(1, 'admin', 'Gates', 'Bill', 42, '', '-', '', 'admin@example.com', '', '', 'XL', '$6$rounds=5000$hjXbIhoRTH3vKiRa$Wl2P2iI5T9iRR.HHu/YFHswBW0WVn0yxCfCiX0Keco9OdIoDK6bIAADswP6KvMCJSwTGdV8PgA8g8Xfw5l8BD1', NULL, 1, 0, 1, 0, 1, 'de_DE.UTF-8', 115, 'L', 1399988887, '0000-00-00 00:00:00', '', '', '', '038850abdd1feb264406be3ffa746235'); -- -------------------------------------------------------- @@ -451,24 +407,18 @@ INSERT INTO `User` (`UID`, `Nick`, `Name`, `Vorname`, `Alter`, `Telefon`, `DECT` -- Tabellenstruktur für Tabelle `UserAngelTypes` -- -DROP TABLE IF EXISTS `UserAngelTypes`; CREATE TABLE IF NOT EXISTS `UserAngelTypes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `angeltype_id` int(11) NOT NULL, `confirm_user_id` int(11) DEFAULT NULL, + `coordinator` tinyint(1) NOT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`,`angeltype_id`,`confirm_user_id`), KEY `angeltype_id` (`angeltype_id`), - KEY `confirm_user_id` (`confirm_user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; - --- --- Daten für Tabelle `UserAngelTypes` --- - -INSERT INTO `UserAngelTypes` (`id`, `user_id`, `angeltype_id`, `confirm_user_id`) VALUES -(1, 1, 1, 1); + KEY `confirm_user_id` (`confirm_user_id`), + KEY `coordinator` (`coordinator`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ; -- -------------------------------------------------------- @@ -476,7 +426,6 @@ INSERT INTO `UserAngelTypes` (`id`, `user_id`, `angeltype_id`, `confirm_user_id` -- Tabellenstruktur für Tabelle `UserGroups` -- -DROP TABLE IF EXISTS `UserGroups`; CREATE TABLE IF NOT EXISTS `UserGroups` ( `id` int(11) NOT NULL AUTO_INCREMENT, `uid` int(11) NOT NULL, @@ -484,7 +433,7 @@ CREATE TABLE IF NOT EXISTS `UserGroups` ( PRIMARY KEY (`id`), KEY `uid` (`uid`,`group_id`), KEY `group_id` (`group_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=17 ; -- -- Daten für Tabelle `UserGroups` diff --git a/db/update.sql b/db/update.sql index 0d706835..9457559a 100644 --- a/db/update.sql +++ b/db/update.sql @@ -1,5 +1,9 @@ +/* teamcoordinators */ +ALTER TABLE `UserAngelTypes` ADD `coordinator` BOOLEAN NOT NULL; +ALTER TABLE `UserAngelTypes` ADD INDEX ( `coordinator` ); + /* angeltype view */ -INSERT INTO `engelsystem`.`Privileges` (`id`, `name`, `desc`) VALUES (NULL , 'angeltypes', 'View angeltypes'); +INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (NULL , 'angeltypes', 'View angeltypes'); /* force active */ ALTER TABLE `User` ADD `force_active` BOOLEAN NOT NULL AFTER `Aktiv`, ADD INDEX ( `force_active` ); diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index bcd7696e..6b94545b 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -174,7 +174,7 @@ function angeltype_controller() { return array( sprintf(_("Team %s"), $angeltype['name']), - AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges), in_array('admin_angel_types', $privileges)) + AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges)) ); } @@ -201,18 +201,10 @@ function angeltypes_list_controller() { $actions[] = '' . _("delete") . ''; } - $angeltype['membership'] = ""; + $angeltype['membership'] = AngelType_render_membership($angeltype); if ($angeltype['user_angeltype_id'] != null) { - if ($angeltype['restricted']) { - if ($angeltype['confirm_user_id'] == null) - $angeltype['membership'] = '' . _( ' . _("Unconfirmed"); - else - $angeltype['membership'] = '' . _( ' . _("Member"); - } else - $angeltype['membership'] = '' . _( ' . _("Member"); $actions[] = '' . _("leave") . ''; } else { - $angeltype['membership'] = ''; $actions[] = '' . _("join") . ''; } diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index b955fe6d..095b35f5 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -6,11 +6,6 @@ function user_angeltypes_delete_all_controller() { global $user, $privileges; - if (! in_array('admin_user_angeltypes', $privileges)) { - error(_("You are not allowed to delete all users for this angeltype.")); - redirect(page_link_to('angeltypes')); - } - if (! isset($_REQUEST['angeltype_id'])) { error(_("Angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); @@ -24,6 +19,11 @@ function user_angeltypes_delete_all_controller() { redirect(page_link_to('angeltypes')); } + if (! User_is_AngelType_coordinator($user, $angeltype)) { + error(_("You are not allowed to delete all users for this angeltype.")); + redirect(page_link_to('angeltypes')); + } + if (isset($_REQUEST['confirmed'])) { $result = UserAngelTypes_delete_all($angeltype['id']); if ($result === false) @@ -46,11 +46,6 @@ function user_angeltypes_delete_all_controller() { function user_angeltypes_confirm_all_controller() { global $user, $privileges; - if (! in_array('admin_user_angeltypes', $privileges)) { - error(_("You are not allowed to confirm all users for this angeltype.")); - redirect(page_link_to('angeltypes')); - } - if (! isset($_REQUEST['angeltype_id'])) { error(_("Angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); @@ -64,6 +59,19 @@ function user_angeltypes_confirm_all_controller() { redirect(page_link_to('angeltypes')); } + $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); + if ($user_angeltype === false) + engelsystem_error("Unable to load user angeltype."); + if ($user_angeltype == null) { + error(_("User angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } + + if (! in_array('admin_user_angeltypes', $privileges) && ! $user_angeltype['coordinator']) { + error(_("You are not allowed to confirm all users for this angeltype.")); + redirect(page_link_to('angeltypes')); + } + if (isset($_REQUEST['confirmed'])) { $result = UserAngelTypes_confirm_all($angeltype['id'], $user); if ($result === false) @@ -86,11 +94,6 @@ function user_angeltypes_confirm_all_controller() { function user_angeltype_confirm_controller() { global $user, $privileges; - if (! in_array('admin_user_angeltypes', $privileges)) { - error(_("You are not allowed to confirm this users angeltype.")); - redirect(page_link_to('angeltypes')); - } - if (! isset($_REQUEST['user_angeltype_id'])) { error(_("User angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); @@ -112,6 +115,11 @@ function user_angeltype_confirm_controller() { redirect(page_link_to('angeltypes')); } + if (! User_is_AngelType_coordinator($user, $angeltype)) { + error(_("You are not allowed to confirm this users angeltype.")); + redirect(page_link_to('angeltypes')); + } + $user_source = User($user_angeltype['user_id']); if ($user_source === false) engelsystem_error("Unable to load user."); @@ -171,7 +179,7 @@ function user_angeltype_delete_controller() { redirect(page_link_to('angeltypes')); } - if ($user['UID'] != $user_angeltype['user_id'] && ! in_array('admin_user_angeltypes', $privileges)) { + if ($user['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_coordinator($user, $angeltype)) { error(_("You are not allowed to delete this users angeltype.")); redirect(page_link_to('angeltypes')); } @@ -198,7 +206,65 @@ function user_angeltype_delete_controller() { * Update an UserAngelType. */ function user_angeltype_update_controller() { - + global $user, $privileges; + + if (! in_array('admin_angel_types', $privileges)) { + error(_("You are not allowed to set coordinator rights.")); + redirect(page_link_to('angeltypes')); + } + + if (! isset($_REQUEST['user_angeltype_id'])) { + error(_("User angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } + + if (isset($_REQUEST['coordinator']) && preg_match("/^[01]$/", $_REQUEST['coordinator'])) + $coordinator = $_REQUEST['coordinator'] == "1"; + else { + error(_("No coordinator update given.")); + redirect(page_link_to('angeltypes')); + } + + $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); + if ($user_angeltype === false) + engelsystem_error("Unable to load user angeltype."); + if ($user_angeltype == null) { + error(_("User angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } + + $angeltype = AngelType($user_angeltype['angeltype_id']); + if ($angeltype === false) + engelsystem_error("Unable to load angeltype."); + if ($angeltype == null) { + error(_("Angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } + + $user_source = User($user_angeltype['user_id']); + if ($user_source === false) + engelsystem_error("Unable to load user."); + if ($user_source == null) { + error(_("User doesn't exist.")); + redirect(page_link_to('angeltypes')); + } + + if (isset($_REQUEST['confirmed'])) { + $result = UserAngelType_update($user_angeltype['id'], $coordinator); + if ($result === false) + engelsystem_error("Unable to update coordinator rights."); + + $success_message = sprintf($coordinator ? _("Added coordinator rights for %s to %s.") : _("Removed coordinator rights for %s from %s."), $angeltype['name'], User_Nick_render($user_source)); + engelsystem_log($success_message); + success($success_message); + + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + } + + return array( + $coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"), + UserAngelType_update_view($user_angeltype, $user, $angeltype, $coordinator) + ); } /** @@ -220,38 +286,84 @@ function user_angeltype_add_controller() { redirect(page_link_to('angeltypes')); } - $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); - if ($user_angeltype === false) - engelsystem_error("Unable to load user angeltype."); - if ($user_angeltype != null) { - error(sprintf(_("User is already an %s."), $angeltype['name'])); - redirect(page_link_to('angeltypes')); - } - - if (isset($_REQUEST['confirmed'])) { - $user_angeltype_id = UserAngelType_create($user, $angeltype); - if ($user_angeltype_id === false) - engelsystem_error("Unable to create user angeltype."); + if (User_is_AngelType_coordinator($user, $angeltype)) { + // Allow to add any user + $user_id = $user['UID']; - $success_message = sprintf(_("User %s joined %s."), User_Nick_render($user), $angeltype['name']); - engelsystem_log($success_message); - success($success_message); + $users_source = Users_by_angeltype_inverted($angeltype); + if ($users_source === false) + engelsystem_error("Unable to load users."); - if (in_array('admin_user_angeltypes', $privileges)) { - $result = UserAngelType_confirm($user_angeltype_id, $user); - if ($result === false) - engelsystem_error("Unable to confirm user angeltype."); - $success_message = sprintf(_("User %s confirmed as %s."), User_Nick_render($user), $angeltype['name']); - engelsystem_log($success_message); + if (isset($_REQUEST['submit'])) { + $ok = true; + + if (isset($_REQUEST['user_id']) && in_array($_REQUEST['user_id'], array_map(function ($user) { + return $user['UID']; + }, $users_source))) + $user_id = $_REQUEST['user_id']; + else { + $ok = false; + error(_("Please select a user.")); + } + + if ($ok) { + foreach ($users_source as $user_source) + if ($user_source['UID'] == $user_id) { + $user_angeltype_id = UserAngelType_create($user_source, $angeltype); + if ($user_angeltype_id === false) + engelsystem_error("Unable to create user angeltype."); + + engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), $angeltype['name'])); + success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), $angeltype['name'])); + + $result = UserAngelType_confirm($user_angeltype_id, $user_source); + if ($result === false) + engelsystem_error("Unable to confirm user angeltype."); + engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), $angeltype['name'])); + + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + } + } } - redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + return array( + _("Add user to angeltype"), + UserAngelType_add_view($angeltype, $users_source, $user_id) + ); + } else { + // Allow only me + $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); + if ($user_angeltype === false) + engelsystem_error("Unable to load user angeltype."); + if ($user_angeltype != null) { + error(sprintf(_("You are already a %s."), $angeltype['name'])); + redirect(page_link_to('angeltypes')); + } + + if (isset($_REQUEST['confirmed'])) { + $user_angeltype_id = UserAngelType_create($user, $angeltype); + if ($user_angeltype_id === false) + engelsystem_error("Unable to create user angeltype."); + + $success_message = sprintf(_("You joined %s."), $angeltype['name']); + engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), $angeltype['name'])); + success($success_message); + + if (in_array('admin_user_angeltypes', $privileges)) { + $result = UserAngelType_confirm($user_angeltype_id, $user); + if ($result === false) + engelsystem_error("Unable to confirm user angeltype."); + engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), $angeltype['name'])); + } + + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + } + + return array( + sprintf(_("Become a %s"), $angeltype['name']), + UserAngelType_join_view($user, $angeltype) + ); } - - return array( - _("Add user to angeltype"), - UserAngelType_add_view($user, $angeltype) - ); } /** diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 832a3236..df5e6ae1 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -92,7 +92,8 @@ function AngelTypes_with_user($user) { return sql_select(" SELECT `AngelTypes`.*, `UserAngelTypes`.`id` as `user_angeltype_id`, - `UserAngelTypes`.`confirm_user_id` + `UserAngelTypes`.`confirm_user_id`, + `UserAngelTypes`.`coordinator` FROM `AngelTypes` LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id` AND `UserAngelTypes`.`user_id`=" . $user['UID'] . " diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index 4987eddd..b9b44032 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -1,9 +1,42 @@ 0) || in_array('admin_user_angeltypes', privileges_for_user($user['UID'])); +} + +/** + * Add or remove coordinator rights. + * + * @param int $user_angeltype_id + * @param bool $coordinator + */ +function UserAngelType_update($user_angeltype_id, $coordinator) { + return sql_query(" + UPDATE `UserAngelTypes` + SET `coordinator`=" . ($coordinator ? 'TRUE' : 'FALSE') . " + WHERE `id`=" . sql_escape($user_angeltype_id) . " + LIMIT 1"); +} /** * Delete all unconfirmed UserAngelTypes for given Angeltype. - * - * @param int $angeltype_id + * + * @param int $angeltype_id */ function UserAngelTypes_delete_all($angeltype_id) { return sql_query(" diff --git a/includes/model/User_model.php b/includes/model/User_model.php index d369ea3e..c8c48e6c 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -1,12 +1,34 @@ ' . _("Unconfirmed"); + elseif ($user_angeltype['coordinator']) + $membership = '' . _( ' . _("Coordinator"); + else + $membership = '' . _( ' . _("Member"); + } elseif ($user_angeltype['coordinator']) + $membership = '' . _( ' . _("Coordinator"); + else + $membership = '' . _( ' . _("Member"); + } else { + $membership = ''; + } + return $membership; +} function AngelType_delete_view($angeltype) { return page(array( @@ -56,7 +86,7 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel // Team-Coordinators list missing - $page[] = '

' . _("Members") . '

'; + $coordinators = array(); $members_confirmed = array(); $members_unconfirmed = array(); foreach ($members as $member) { @@ -67,14 +97,34 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel '' . _("deny") . '' )); $members_unconfirmed[] = $member; + } elseif ($member['coordinator']) { + if ($admin_angeltypes) + $member['actions'] = '' . _("Remove coordinator rights") . ''; + else + $member['actions'] = ''; + $coordinators[] = $member; } else { if ($admin_user_angeltypes) $member['actions'] = join(" ", array( + $admin_angeltypes ? '' . _("Add coordinator rights") . '' : '', '' . _("remove") . '' )); $members_confirmed[] = $member; } } + if (count($coordinators) > 0) { + $page[] = '

' . _("Coordinators") . '

'; + $page[] = table(array( + 'Nick' => _("Nick"), + 'DECT' => _("DECT"), + 'actions' => "" + ), $coordinators); + } + $page[] = '

' . _("Members") . '

'; + if ($admin_user_angeltypes) + $page[] = buttons(array( + button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("Add"), 'add') + )); $page[] = table(array( 'Nick' => _("Nick"), 'DECT' => _("DECT"), diff --git a/includes/view/UserAngelTypes_view.php b/includes/view/UserAngelTypes_view.php index ed825c04..68bb1ec9 100644 --- a/includes/view/UserAngelTypes_view.php +++ b/includes/view/UserAngelTypes_view.php @@ -1,4 +1,14 @@