summaryrefslogtreecommitdiff
path: root/includes/controller
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2014-01-05 19:30:06 +0100
committerPhilip Häusler <msquare@notrademark.de>2014-01-05 19:30:06 +0100
commit5e8453992810181facf168d6aaede9d2dcd61dba (patch)
treec6aad1564d86ed5789c25b7bab0b36047f0fbaac /includes/controller
parentd921cf903eedd98fce74114d43f7c98ed8baabdc (diff)
rewritten angeltypes and user angeltypes
Diffstat (limited to 'includes/controller')
-rw-r--r--includes/controller/angeltypes_controller.php196
-rw-r--r--includes/controller/user_angeltypes_controller.php272
2 files changed, 468 insertions, 0 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php
new file mode 100644
index 00000000..03c9651d
--- /dev/null
+++ b/includes/controller/angeltypes_controller.php
@@ -0,0 +1,196 @@
+<?php
+
+function angeltypes_title() {
+ return _("Angeltypes");
+}
+
+/**
+ * Route angeltype actions.
+ */
+function angeltypes_controller() {
+ if (! isset($_REQUEST['action']))
+ $_REQUEST['action'] = 'list';
+ switch ($_REQUEST['action']) {
+ default:
+ case 'list':
+ list($title, $content) = angeltypes_list_controller();
+ break;
+ case 'view':
+ list($title, $content) = angeltype_controller();
+ break;
+ case 'edit':
+ list($title, $content) = angeltype_edit_controller();
+ break;
+ case 'delete':
+ list($title, $content) = angeltype_delete_controller();
+ break;
+ }
+
+ return array(
+ $title,
+ $content
+ );
+}
+
+function angeltype_delete_controller() {
+ global $privileges, $user;
+
+ if (! in_array('admin_angel_types', $privileges))
+ redirect(page_link_to('angeltypes'));
+
+ $angeltype = mAngelType($_REQUEST['angeltype_id']);
+ if ($angeltype === false)
+ engelsystem_error("Unable to load angeltype.");
+ if ($angeltype == null)
+ redirect(page_link_to('angeltypes'));
+
+ if (isset($_REQUEST['confirmed'])) {
+ $result = AngelType_delete($angeltype);
+ if ($result === false)
+ engelsystem_error("Unable to delete angeltype.");
+
+ engelsystem_log("Deleted angeltype: " . $name);
+ success(sprintf(_("Angeltype %s deleted."), $name));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ return array(
+ sprintf(_("Delete angeltype %s"), $angeltype['name']),
+ AngelType_delete_view($angeltype)
+ );
+}
+
+function angeltype_edit_controller() {
+ global $privileges, $user;
+
+ if (! in_array('admin_angel_types', $privileges))
+ redirect(page_link_to('angeltypes'));
+
+ $name = "";
+ $restricted = false;
+ if (isset($_REQUEST['angeltype_id'])) {
+ $angeltype = mAngelType($_REQUEST['angeltype_id']);
+ if ($angeltype === false)
+ engelsystem_error("Unable to load angeltype.");
+ if ($angeltype == null)
+ redirect(page_link_to('angeltypes'));
+
+ $name = $angeltype['name'];
+ $restricted = $angeltype['restricted'];
+ }
+
+ if (isset($_REQUEST['submit'])) {
+ $ok = true;
+
+ if (isset($_REQUEST['name'])) {
+ list($valid, $name) = AngelType_validate_name($_REQUEST['name'], $angeltype);
+ if (! $valid) {
+ $ok = false;
+ error(_("Please check the name. Maybe it already exists."));
+ }
+ }
+
+ $restricted = isset($_REQUEST['restricted']);
+
+ if ($ok) {
+ $restricted = $restricted ? 1 : 0;
+ if (isset($angeltype)) {
+ $result = AngelType_update($angeltype['id'], $name, $restricted);
+ if ($result === false)
+ engelsystem_error("Unable to update angeltype.");
+ engelsystem_log("Updated angeltype: " . $name . ", restricted: " . $restricted);
+ $angeltype_id = $angeltype['id'];
+ } else {
+ $angeltype_id = AngelType_create($name, $restricted);
+ if ($angeltype_id === false)
+ engelsystem_error("Unable to create angeltype.");
+ engelsystem_log("Created angeltype: " . $name . ", restricted: " . $restricted);
+ }
+
+ success("Angel type saved.");
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id);
+ }
+ }
+
+ return array(
+ isset($angeltype) ? sprintf(_("Edit %s"), $name) : _("Add new angeltype"),
+ AngelType_edit_view($name, $restricted)
+ );
+}
+
+/**
+ * View details of a given angeltype.
+ */
+function angeltype_controller() {
+ global $privileges, $user;
+
+ if (! isset($_REQUEST['angeltype_id']))
+ redirect(page_link_to('angeltypes'));
+
+ $angeltype = mAngelType($_REQUEST['angeltype_id']);
+ if ($angeltype === false)
+ engelsystem_error("Unable to load angeltype.");
+ if ($angeltype == null)
+ 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.");
+
+ $members = Users_by_angeltype($angeltype);
+ if ($members === false)
+ engelsystem_error("Unable to load members.");
+
+ 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))
+ );
+}
+
+/**
+ * View a list of all angeltypes.
+ */
+function angeltypes_list_controller() {
+ global $privileges, $user;
+
+ $angeltypes = AngelTypes_with_user($user);
+ if ($angeltypes === false)
+ engelsystem_error("Unable to load angeltypes.");
+
+ foreach ($angeltypes as &$angeltype) {
+ $actions = array(
+ '<a class="view" href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . _("view") . '</a>'
+ );
+
+ if (in_array('admin_angel_types', $privileges)) {
+ $actions[] = '<a class="edit" href="' . page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'] . '">' . _("edit") . '</a>';
+ $actions[] = '<a class="delete" href="' . page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'] . '">' . _("delete") . '</a>';
+ }
+
+ $angeltype['membership'] = "";
+ if ($angeltype['user_angeltype_id'] != null) {
+ if ($angeltype['restricted']) {
+ if ($angeltype['confirm_user_id'] == null)
+ $angeltype['membership'] = '<img src="pic/icons/lock.png" alt="' . _("Unconfirmed") . '" title="' . _("Unconfirmed") . '"> ' . _("Unconfirmed");
+ else
+ $angeltype['membership'] = '<img src="pic/icons/tick.png" alt="' . _("Member") . '" title="' . _("Member") . '"> ' . _("Member");
+ } else
+ $angeltype['membership'] = '<img src="pic/icons/tick.png" alt="' . _("Member") . '" title="' . _("Member") . '"> ' . _("Member");
+ $actions[] = '<a class="cancel" href="' . page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'] . '">' . _("leave") . '</a>';
+ } else {
+ $angeltype['membership'] = '<img src="pic/icons/cross.png" alt="" title="">';
+ $actions[] = '<a class="add" href="' . page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'] . '">' . _("join") . '</a>';
+ }
+
+ $angeltype['restricted'] = $angeltype['restricted'] ? '<img src="pic/icons/lock.png" alt="' . _("Restricted") . '" title="' . _("Restricted") . '">' : '';
+ $angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>';
+
+ $angeltype['actions'] = join(" ", $actions);
+ }
+
+ return array(
+ angeltypes_title(),
+ AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges))
+ );
+}
+?> \ No newline at end of file
diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php
new file mode 100644
index 00000000..d110f7a7
--- /dev/null
+++ b/includes/controller/user_angeltypes_controller.php
@@ -0,0 +1,272 @@
+<?php
+
+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'));
+ }
+
+ $angeltype = mAngelType($_REQUEST['angeltype_id']);
+ if ($angeltype === false)
+ engelsystem_error("Unable to load angeltype.");
+ if ($angeltype == null) {
+ error(_("Angeltype doesn't exist."));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ $result = UserAngelTypes_delete_all($angeltype['id']);
+ if ($result === false)
+ engelsystem_error("Unable to confirm all users.");
+
+ engelsystem_log(sprintf("Denied all users for angeltype %s", $angeltype['name']));
+ success(sprintf(_("Denied all users for angeltype %s."), $angeltype['name']));
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return array(
+ _("Deny all users"),
+ UserAngelTypes_delete_all_view($angeltype)
+ );
+}
+
+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'));
+ }
+
+ $angeltype = mAngelType($_REQUEST['angeltype_id']);
+ if ($angeltype === false)
+ engelsystem_error("Unable to load angeltype.");
+ if ($angeltype == null) {
+ error(_("Angeltype doesn't exist."));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ $result = UserAngelTypes_confirm_all($angeltype['id'], $user);
+ if ($result === false)
+ engelsystem_error("Unable to confirm all users.");
+
+ engelsystem_log(sprintf("Confirmed all users for angeltype %s", $angeltype['name']));
+ success(sprintf(_("Confirmed all users for angeltype %s."), $angeltype['name']));
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return array(
+ _("Confirm all users"),
+ UserAngelTypes_confirm_all_view($angeltype)
+ );
+}
+
+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'));
+ }
+
+ $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 = mAngelType($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_confirm($user_angeltype['id'], $user);
+ if ($result === false)
+ engelsystem_error("Unable to confirm user angeltype.");
+
+ engelsystem_log(sprintf("%s confirmed for angeltype %s", User_Nick_render($user_source), $angeltype['name']));
+ success(sprintf(_("%s confirmed for angeltype %s."), User_Nick_render($user_source), $angeltype['name']));
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return array(
+ _("Confirm angeltype for user"),
+ UserAngelType_confirm_view($user_angeltype, $user, $angeltype)
+ );
+}
+
+function user_angeltype_delete_controller() {
+ global $user, $privileges;
+
+ if (! isset($_REQUEST['user_angeltype_id'])) {
+ error(_("User angeltype doesn't exist."));
+ 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 = mAngelType($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 ($user['UID'] != $user_angeltype['user_id'] && ! in_array('admin_user_angeltypes', $privileges)) {
+ error(_("You are not allowed to delete this users angeltype."));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ $result = UserAngelType_delete($user_angeltype);
+ if ($result === false)
+ engelsystem_error("Unable to delete user angeltype.");
+
+ $success_message = sprintf(_("User %s removed from %s."), User_Nick_render($user_source), $angeltype['name']);
+ engelsystem_log($success_message);
+ success($success_message);
+
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return array(
+ _("Remove angeltype"),
+ UserAngelType_delete_view($user_angeltype, $user, $angeltype)
+ );
+}
+
+function user_angeltype_update_controller() {
+
+}
+
+function user_angeltype_add_controller() {
+ global $user, $privileges;
+
+ if (! isset($_REQUEST['angeltype_id'])) {
+ error(_("Angeltype doesn't exist."));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $angeltype = mAngelType($_REQUEST['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_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.");
+
+ $success_message = sprintf(_("User %s joined %s."), User_Nick_render($user), $angeltype['name']);
+ engelsystem_log($success_message);
+ 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.");
+ $success_message = sprintf(_("User %s confirmed as %s."), User_Nick_render($user), $angeltype['name']);
+ engelsystem_log($success_message);
+ }
+
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return array(
+ _("Add user to angeltype"),
+ UserAngelType_add_view($user, $angeltype)
+ );
+}
+
+function user_angeltypes_controller() {
+ if (! isset($_REQUEST['action']))
+ redirect(page_link_to('angeltypes'));
+
+ switch ($_REQUEST['action']) {
+ case 'delete_all':
+ list($title, $content) = user_angeltypes_delete_all_controller();
+ break;
+ case 'confirm_all':
+ list($title, $content) = user_angeltypes_confirm_all_controller();
+ break;
+ case 'confirm':
+ list($title, $content) = user_angeltype_confirm_controller();
+ break;
+ case 'delete':
+ list($title, $content) = user_angeltype_delete_controller();
+ break;
+ case 'update':
+ list($title, $content) = user_angeltype_update_controller();
+ break;
+ case 'add':
+ list($title, $content) = user_angeltype_add_controller();
+ break;
+ default:
+ redirect(page_link_to('angeltypes'));
+ }
+
+ return array(
+ $title,
+ $content
+ );
+}
+
+?> \ No newline at end of file