Now ties into the various edit/add User dialogs.
This commit is contained in:
parent
ba99a5a96d
commit
73d8940cfa
@ -1,70 +0,0 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
|
||||
class Admin_User_Homes_Controller extends Controller
|
||||
{
|
||||
/**
|
||||
* the index page of the user homes admin
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$view = new Admin_View("admin.html");
|
||||
$view->content = new View("admin_user_homes.html");
|
||||
$view->content->users = ORM::factory("user")->orderby("name")->find_all();
|
||||
$root = ORM::factory("item", 1);
|
||||
$view->content->album_tree = $this->tree($root, "");
|
||||
|
||||
print $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* recursive function to build drop down list of all galleries
|
||||
*/
|
||||
function tree($parent, $dashes)
|
||||
{
|
||||
|
||||
$albums = ORM::factory("item")
|
||||
->where(array("parent_id" => $parent->id, "type" => "album"))
|
||||
->orderby(array("title" => "ASC"))
|
||||
->find_all();
|
||||
|
||||
|
||||
$view = new View("album_list.html");
|
||||
$view->id = $parent->id;
|
||||
if ($parent->id == "1")
|
||||
{
|
||||
$view->name = "root";
|
||||
}
|
||||
else
|
||||
{
|
||||
$view->name = "$dashes $parent->name";
|
||||
}
|
||||
|
||||
$view->children = "";
|
||||
foreach ($albums as $album)
|
||||
{
|
||||
$view->children .= $this->tree($album, "-$dashes");
|
||||
}
|
||||
return $view->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called when the user home is changed
|
||||
*/
|
||||
public function change_home($user_id, $home)
|
||||
{
|
||||
$user = ORM::factory("user", $user_id);
|
||||
if ($user->loaded)
|
||||
{
|
||||
if ($home==0)
|
||||
{
|
||||
$user->home = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$user->home = $home;
|
||||
}
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -9,11 +9,15 @@ class user_homes_event_Core
|
||||
*/
|
||||
static function user_login($user)
|
||||
{
|
||||
if ($user->home)
|
||||
$home = ORM::factory("user_home")
|
||||
->where("id", $user->id)->find();
|
||||
if ($home)
|
||||
{
|
||||
if ($home->home!=0)
|
||||
{
|
||||
|
||||
$session = Session::instance();
|
||||
$session->set("redirect_home",$user->home);
|
||||
$session->set("redirect_home",$home->home);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -37,4 +41,147 @@ class user_homes_event_Core
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* called just before a user is deleted. This will remove the user from
|
||||
* the user_homes directory.
|
||||
*/
|
||||
static function user_before_delete($user)
|
||||
{
|
||||
ORM::factory("user_home")
|
||||
->where("id", $user->id)
|
||||
->delete_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* called when admin is adding a user
|
||||
*/
|
||||
static function user_add_form_admin($user, $form)
|
||||
{
|
||||
$form->add_user->dropdown("user_home")
|
||||
->label(t("Home Gallery"))
|
||||
->options(self::createGalleryArray())
|
||||
->selected(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* called after a user has been added
|
||||
*/
|
||||
static function user_add_form_admin_completed($user, $form)
|
||||
{
|
||||
$home = ORM::factory("user_home")
|
||||
->where("id", $user->id)->find();
|
||||
$home->id=$user->id;
|
||||
$home->home=$form->add_user->user_home->value;
|
||||
$home->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* called when admin is editing a user
|
||||
*/
|
||||
static function user_edit_form_admin($user, $form)
|
||||
{
|
||||
$home = ORM::factory("user_home")
|
||||
->where("id", $user->id)->find();
|
||||
|
||||
if ($home)
|
||||
{
|
||||
$selected = $home->home;
|
||||
}
|
||||
else
|
||||
{
|
||||
$selected = 0;
|
||||
}
|
||||
$form->edit_user->dropdown("user_home")
|
||||
->label(t("Home Gallery"))
|
||||
->options(self::createGalleryArray())
|
||||
->selected($selected);
|
||||
}
|
||||
/**
|
||||
* called after a user had been edited by the admin
|
||||
*/
|
||||
static function user_edit_form_admin_completed($user, $form)
|
||||
{
|
||||
$home = ORM::factory("user_home")
|
||||
->where("id", $user->id)->find();
|
||||
$home->id=$user->id;
|
||||
$home->home=$form->edit_user->user_home->value;
|
||||
$home->save();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* called when user is editing their own form
|
||||
*/
|
||||
static function user_edit_form($user, $form)
|
||||
{
|
||||
$home = ORM::factory("user_home")
|
||||
->where("id", $user->id)->find();
|
||||
|
||||
if ($home)
|
||||
{
|
||||
$selected = $home->home;
|
||||
}
|
||||
else
|
||||
{
|
||||
$selected = 0;
|
||||
}
|
||||
$form->edit_user->dropdown("user_home")
|
||||
->label(t("Home Gallery"))
|
||||
->options(self::createGalleryArray())
|
||||
->selected($selected);
|
||||
}
|
||||
|
||||
/**
|
||||
* called after a user had been edited by the user
|
||||
*/
|
||||
static function user_edit_form_completed($user, $form)
|
||||
{
|
||||
$home = ORM::factory("user_home")
|
||||
->where("id", $user->id)->find();
|
||||
$home->id=$user->id;
|
||||
$home->home=$form->edit_user->user_home->value;
|
||||
$home->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* creates an array of galleries
|
||||
*/
|
||||
static function createGalleryArray()
|
||||
{
|
||||
$array[0] = "none";
|
||||
$root = ORM::factory("item", 1);
|
||||
self::tree($root, "", $array);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* recursive function to build array for drop down list
|
||||
*/
|
||||
static function tree($parent, $dashes, &$array)
|
||||
{
|
||||
if ($parent->id == "1")
|
||||
{
|
||||
$array[$parent->id] = "home";
|
||||
}
|
||||
else
|
||||
{
|
||||
$array[$parent->id] = "$dashes $parent->name";
|
||||
}
|
||||
|
||||
$albums = ORM::factory("item")
|
||||
->where(array("parent_id" => $parent->id, "type" => "album"))
|
||||
->orderby(array("title" => "ASC"))
|
||||
->find_all();
|
||||
foreach ($albums as $album)
|
||||
{
|
||||
self::tree($album, "-$dashes", $array);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,23 +8,28 @@ class user_homes_installer
|
||||
}
|
||||
|
||||
/**
|
||||
* installs the extra collumn on the users table when the
|
||||
* installs the the table of user homes when the
|
||||
* module is installed
|
||||
*/
|
||||
|
||||
static function activate()
|
||||
{
|
||||
$db = Database::instance();
|
||||
$db->query("ALTER TABLE {users} ADD home int(9) default NULL;");
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {user_homes} (
|
||||
`id` int(9) NOT NULL,
|
||||
`home` int(9) default NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY(`id`))
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
}
|
||||
|
||||
/**
|
||||
* uninstalls the extra collumn on the users table when the
|
||||
* drops the table of user homes when the
|
||||
* module is uninstalled
|
||||
*/
|
||||
static function deactivate()
|
||||
{
|
||||
$db = Database::instance();
|
||||
$db->query("ALTER TABLE {users} DROP COLUMN home;");
|
||||
$db->query("DROP TABLE IF EXISTS {user_homes};");
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
class user_homes_menu_Core
|
||||
{
|
||||
/**
|
||||
* adds the users home admin to the menu screen
|
||||
*/
|
||||
static function admin($menu, $theme)
|
||||
{
|
||||
$menu->add_after("users_groups",
|
||||
Menu::factory("link")
|
||||
->id("user_homes")
|
||||
->label(t("User Homes"))
|
||||
->url(url::site("admin/user_homes")));
|
||||
}
|
||||
}
|
5
modules/user_homes/models/user_home.php
Normal file
5
modules/user_homes/models/user_home.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
class User_home_Model extends ORM
|
||||
{
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<div class="gBlock">
|
||||
<h2>
|
||||
<?= t("User Homes") ?>
|
||||
</h2>
|
||||
|
||||
<div class="gBlockContent">
|
||||
<table id="gUserAdminList">
|
||||
<tr>
|
||||
<th><?= t("Username") ?></th>
|
||||
<th><?= t("Full name") ?></th>
|
||||
<th><?= t("Home") ?></th>
|
||||
</tr>
|
||||
<? foreach ($users as $i => $user): ?>
|
||||
<tr id="gUser-<?= $user->id ?>" class="<?= text::alternate("gOddRow", "gEvenRow") ?> <?= $user->admin ? "admin" : "" ?>">
|
||||
<td id="user-<?= $user->id ?>" class="core-info ">
|
||||
<?= p::clean($user->name) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= p::clean($user->full_name) ?>
|
||||
</td>
|
||||
<td>
|
||||
<select id="s_<?=$user->id ?>">
|
||||
<option value='0'>None</option>
|
||||
<?= $album_tree ?>
|
||||
</select>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function()
|
||||
{
|
||||
var select=$("#s_<?=$user->id ?>");
|
||||
<? if ($user->home): ?>
|
||||
select.val(<?=$user->home?>);
|
||||
<? endif; ?>
|
||||
var churl = "<?= url::site("admin/user_homes/change_home/$user->id/__ALBUM_ID__") ?>";
|
||||
select.change(function()
|
||||
{
|
||||
var album_id=select.val();
|
||||
$.get(churl.replace("__ALBUM_ID__", album_id));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</td>
|
||||
</tr>
|
||||
<? endforeach ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
@ -1,3 +0,0 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<option value="<?=$id?>"><?=$name?></option>
|
||||
<?= $children ?>
|
Reference in New Issue
Block a user