summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/views/form.html.php2
-rw-r--r--modules/user/controllers/admin_groups.php87
-rw-r--r--modules/user/controllers/admin_users.php1
-rw-r--r--modules/user/helpers/group.php18
-rw-r--r--modules/user/helpers/user.php2
-rw-r--r--modules/user/helpers/user_menu.php12
-rw-r--r--modules/user/views/admin_groups.html.php21
-rw-r--r--modules/user/views/admin_users_delete.html.php5
8 files changed, 124 insertions, 24 deletions
diff --git a/core/views/form.html.php b/core/views/form.html.php
index b3a779fe..5b00adb8 100644
--- a/core/views/form.html.php
+++ b/core/views/form.html.php
@@ -7,7 +7,7 @@ if ($class) {
print "<!-- unused class in form.html.php: $class -->";
}
if ($title) {
- print "<!-- unused title in form.html.php: $title -->";
+ print $title;
}
if (!function_exists("DrawForm")) {
diff --git a/modules/user/controllers/admin_groups.php b/modules/user/controllers/admin_groups.php
new file mode 100644
index 00000000..7fdbb0dc
--- /dev/null
+++ b/modules/user/controllers/admin_groups.php
@@ -0,0 +1,87 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Admin_Groups_Controller extends Controller {
+ public function index() {
+ $view = new Admin_View("admin.html");
+ $view->content = new View("admin_groups.html");
+ $view->content->groups = ORM::factory("group")->orderby("name")->find_all();
+ print $view;
+ }
+
+ public function create() {
+ $form = group::get_add_form_admin();
+ if (request::method() =="post" ) {
+ if($form->validate()) {
+ $group = group::create($form->add_group->inputs["name"]->value);
+ $group->save();
+ message::success(sprintf(_("Created group %s"), $group->name));
+ print json_encode(array("result" => "success"));
+ } else {
+ message::error(_("Failed to create group"));
+ print json_encode(array("result" => "error",
+ "form" => $form->__toString()));
+ }
+ } else {
+ print $form;
+ }
+ }
+
+ public function delete($id) {
+ $group = ORM::factory("group", $id);
+ if (!$group->loaded) {
+ kohana::show_404();
+ }
+
+ if (request::method() == "post" ) {
+ $name = $group->name;
+ $group->delete();
+
+ log::success("group", sprintf(_("Deleted group %s"), $name));
+ message::success(sprintf(_("Deleted group %s"), $name));
+ print json_encode(array("result" => "success"));
+ } else {
+ print group::get_delete_form_admin($group);
+ }
+
+ }
+
+ public function edit($id) {
+ $group = ORM::factory("group", $id);
+ if (!$group->loaded) {
+ kohana::show_404();
+ }
+
+ $form = group::get_edit_form_admin($group);
+ if (request::method() =="post" ) {
+ if($form->validate()) {
+ $group->name = $form->edit_group->inputs["name"]->value;
+ $group->save();
+ message::success(sprintf(_("Changed group %s"), $group->name));
+ print json_encode(array("result" => "success"));
+ } else {
+ message::error(sprintf(_("Failed to change group %s"), $group->name));
+ print json_encode(array("result" => "error",
+ "form" => $form->__toString()));
+ }
+ } else {
+ print $form;
+ }
+ }
+}
diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php
index 22801c95..53769e51 100644
--- a/modules/user/controllers/admin_users.php
+++ b/modules/user/controllers/admin_users.php
@@ -22,7 +22,6 @@ class Admin_Users_Controller extends Controller {
$view = new Admin_View("admin.html");
$view->content = new View("admin_users.html");
$view->content->users = ORM::factory("user")->orderby("name")->find_all();
- $view->content->groups = ORM::factory("group")->orderby("name")->find_all();
print $view;
}
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php
index a1aea90f..9ffa9929 100644
--- a/modules/user/helpers/group.php
+++ b/modules/user/helpers/group.php
@@ -61,8 +61,8 @@ class group_Core {
return model_cache::get("group", 2);
}
- public static function get_edit_form($group, $action = NULL) {
- $form = new Forge($action);
+ public static function get_edit_form_admin($group) {
+ $form = new Forge("admin/groups/edit/$group->id");
$form_group = $form->group("edit_group")->label(_("Edit Group"));
$form_group->input("name")->label(_("Name"))->id("gName")->value($group->name);
$form_group->submit(_("Modify"));
@@ -70,8 +70,8 @@ class group_Core {
return $form;
}
- public static function get_add_form($action = NULL) {
- $form = new Forge($action);
+ public static function get_add_form_admin() {
+ $form = new Forge("admin/groups/create");
$form_group = $form->group("add_group")->label(_("Add Group"));
$form_group->input("name")->label(_("Name"))->id("gName");
$form_group->submit(_("Create"));
@@ -80,11 +80,9 @@ class group_Core {
return $form;
}
- public static function get_delete_form($group, $action = NULL) {
- $form = new Forge($action);
- $form_group = $form->group("delete_group")->label(_("Delete Group"));
- $form_group->label(sprintf(_("Are you sure you want to delete %s?"), $group->name));
- $form_group->submit(_("Delete"));
- return $form;
+ public static function get_delete_form_admin($group) {
+ $form = new Forge("admin/groups/delete/$group->id",
+ sprintf(_("Are you sure you want to delete %s"), $group->name));
+ print $form;
}
}
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index 35a7e24e..f2912a0f 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -63,7 +63,7 @@ class user_Core {
public static function get_delete_form_admin($user) {
$form = new Forge("admin/users/delete/$user->id",
sprintf(_("Are you sure you want to delete %s"), $user->name));
- return $form->render("admin_users_delete.html");
+ print $form;
}
/**
diff --git a/modules/user/helpers/user_menu.php b/modules/user/helpers/user_menu.php
index 88f30f29..713e47bb 100644
--- a/modules/user/helpers/user_menu.php
+++ b/modules/user/helpers/user_menu.php
@@ -22,15 +22,15 @@ class user_menu_Core {
$menu->get("users_groups_menu")
->append(Menu::factory("link")
->id("list_users")
- ->label(_("List Users"))
+ ->label(_("Users"))
->url(url::site("admin/users")))
->append(Menu::factory("link")
- ->id("create_user")
- ->label(_("Create new user"))
- ->url("#"))
+ ->id("list_groups")
+ ->label(_("Groups"))
+ ->url(url::site("admin/groups")))
->append(Menu::factory("link")
- ->id("edit_user")
- ->label(_("Edit user"))
+ ->id("users_groups")
+ ->label(_("Users <-> Groups"))
->url("#"));
}
}
diff --git a/modules/user/views/admin_groups.html.php b/modules/user/views/admin_groups.html.php
new file mode 100644
index 00000000..5b4b52e4
--- /dev/null
+++ b/modules/user/views/admin_groups.html.php
@@ -0,0 +1,21 @@
+<? defined("SYSPATH") or die("No direct script access."); ?>
+<div class="gBlock">
+ <h2>Group Administration</h2>
+ <div class="gBlockContent">
+ <p>These are the groups in your system</p>
+ </div>
+ <ul>
+ <? foreach ($groups as $i => $group): ?>
+ <li>
+ <?= $group->name ?>
+ <a href="groups/edit/<?= $group->id ?>" class="gDialogLink">edit</a>
+ <? if (!$group->special): ?>
+ <a href="groups/delete/<?= $group->id ?>" class="gDialogLink">delete</a>
+ <? endif ?>
+ </li>
+ <? endforeach ?>
+ <li><a href="groups/create" class="gDialogLink">Add group</a></li>
+ </ul>
+</div>
+
+
diff --git a/modules/user/views/admin_users_delete.html.php b/modules/user/views/admin_users_delete.html.php
deleted file mode 100644
index 4ee9e3d4..00000000
--- a/modules/user/views/admin_users_delete.html.php
+++ /dev/null
@@ -1,5 +0,0 @@
-<? defined("SYSPATH") or die("No direct script access."); ?>
-<?= $open ?>
-<h3><?= $title ?></h3>
-<?= $inputs['csrf']->render() ?>
-<?= $close ?>