1
0

Initial Commit.

This commit is contained in:
Ben Smith 2009-07-25 11:11:02 +12:00
parent 23b0527580
commit ba99a5a96d
7 changed files with 208 additions and 0 deletions

View File

@ -0,0 +1,70 @@
<?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();
}
}
}

View File

@ -0,0 +1,40 @@
<?php defined("SYSPATH") or die("No direct script access.");
class user_homes_event_Core
{
/**
* called when a user logs in. This will setup the session with the
* user home if it exists on the database. This means when the page
* is refreshed after logging in the direction can occur.
*/
static function user_login($user)
{
if ($user->home)
{
$session = Session::instance();
$session->set("redirect_home",$user->home);
}
}
/**
* called after a log in occurs and when the first gallery is loaded.
* if the home variable exists on the session then a redirect will
* occur to that home and the variable removed from the session to
*/
static function gallery_ready()
{
$session = Session::instance();
$home = $session->get("redirect_home");
if ($home)
{
// remove from session to ensure redirect does not
// occur again
$session->set("redirect_home",null);
url::redirect("albums/$home");
}
}
}

View File

@ -0,0 +1,30 @@
<?php defined("SYSPATH") or die("No direct script access.");
class user_homes_installer
{
static function install()
{
module::set_version("user_homes", 1);
}
/**
* installs the extra collumn on the users table when the
* module is installed
*/
static function activate()
{
$db = Database::instance();
$db->query("ALTER TABLE {users} ADD home int(9) default NULL;");
}
/**
* uninstalls the extra collumn on the users table when the
* module is uninstalled
*/
static function deactivate()
{
$db = Database::instance();
$db->query("ALTER TABLE {users} DROP COLUMN home;");
}
}

View File

@ -0,0 +1,15 @@
<?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")));
}
}

View File

@ -0,0 +1,3 @@
name = "User Homes"
description = "Allows users to have home galleries that they are redirected to when logged in."
version = 1

View File

@ -0,0 +1,47 @@
<?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>

View File

@ -0,0 +1,3 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<option value="<?=$id?>"><?=$name?></option>
<?= $children ?>