2009-07-24 23:11:02 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
2009-08-03 03:36:03 +00:00
|
|
|
/**
|
2009-08-02 07:17:36 +00:00
|
|
|
* Gallery - a web based photo album viewer and editor
|
|
|
|
* Copyright (C) 2000-2009 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 user_homes_event_Core {
|
|
|
|
/**
|
2009-08-03 03:36:03 +00:00
|
|
|
* Called when a user logs in. This will setup the session with the
|
2009-08-02 07:17:36 +00:00
|
|
|
* 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) {
|
2009-12-23 05:31:03 +00:00
|
|
|
$home = ORM::factory("user_home")->where("id", "=", $user->id)->find();
|
|
|
|
if ($home->loaded() && $home->home != 0) {
|
2009-08-03 03:36:03 +00:00
|
|
|
Session::instance()->set("redirect_home", $home->home);
|
2009-08-02 07:17:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2009-08-03 03:36:03 +00:00
|
|
|
// Remove from session to ensure redirect does not occur again
|
2009-08-02 07:17:36 +00:00
|
|
|
$session->set("redirect_home",null);
|
|
|
|
url::redirect("albums/$home");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 03:36:03 +00:00
|
|
|
* Called just before a user is deleted. This will remove the user from
|
2009-08-02 07:17:36 +00:00
|
|
|
* the user_homes directory.
|
|
|
|
*/
|
|
|
|
static function user_before_delete($user) {
|
|
|
|
ORM::factory("user_home")
|
2009-12-23 05:31:03 +00:00
|
|
|
->where("id", "=", $user->id)
|
2009-08-03 03:36:03 +00:00
|
|
|
->delete_all();
|
2009-08-02 07:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 03:36:03 +00:00
|
|
|
* Called when admin is adding a user
|
2009-08-02 07:17:36 +00:00
|
|
|
*/
|
|
|
|
static function user_add_form_admin($user, $form) {
|
|
|
|
$form->add_user->dropdown("user_home")
|
2009-08-03 03:36:03 +00:00
|
|
|
->label(t("Home Gallery"))
|
|
|
|
->options(self::createGalleryArray())
|
|
|
|
->selected(0);
|
2009-08-02 07:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 03:36:03 +00:00
|
|
|
* Called after a user has been added
|
2009-08-02 07:17:36 +00:00
|
|
|
*/
|
|
|
|
static function user_add_form_admin_completed($user, $form) {
|
2009-12-23 05:31:03 +00:00
|
|
|
$home = ORM::factory("user_home")->where("id", "=", $user->id)->find();
|
2009-08-03 03:36:03 +00:00
|
|
|
$home->id = $user->id;
|
|
|
|
$home->home = $form->add_user->user_home->value;
|
2009-08-02 07:17:36 +00:00
|
|
|
$home->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 03:36:03 +00:00
|
|
|
* Called when admin is editing a user
|
2009-08-02 07:17:36 +00:00
|
|
|
*/
|
|
|
|
static function user_edit_form_admin($user, $form) {
|
2009-12-23 05:31:03 +00:00
|
|
|
$home = ORM::factory("user_home")->where("id", "=", $user->id)->find();
|
|
|
|
if ($home->loaded()) {
|
2009-08-02 07:17:36 +00:00
|
|
|
$selected = $home->home;
|
|
|
|
} else {
|
|
|
|
$selected = 0;
|
|
|
|
}
|
|
|
|
$form->edit_user->dropdown("user_home")
|
2009-08-03 03:36:03 +00:00
|
|
|
->label(t("Home Gallery"))
|
|
|
|
->options(self::createGalleryArray())
|
|
|
|
->selected($selected);
|
2009-08-02 07:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 03:36:03 +00:00
|
|
|
* Called after a user had been edited by the admin
|
2009-08-02 07:17:36 +00:00
|
|
|
*/
|
|
|
|
static function user_edit_form_admin_completed($user, $form) {
|
2009-12-23 05:31:03 +00:00
|
|
|
$home = ORM::factory("user_home")->where("id", "=", $user->id)->find();
|
2009-08-03 03:36:03 +00:00
|
|
|
$home->id = $user->id;
|
|
|
|
$home->home = $form->edit_user->user_home->value;
|
2009-08-02 07:17:36 +00:00
|
|
|
$home->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-08-03 03:36:03 +00:00
|
|
|
* Called when user is editing their own form
|
2009-08-02 07:17:36 +00:00
|
|
|
*/
|
|
|
|
static function user_edit_form($user, $form) {
|
2009-12-23 05:31:03 +00:00
|
|
|
$home = ORM::factory("user_home")->where("id", "=", $user->id)->find();
|
2009-08-02 07:17:36 +00:00
|
|
|
|
2009-12-23 05:31:03 +00:00
|
|
|
if ($home->loaded()) {
|
2009-08-02 07:17:36 +00:00
|
|
|
$selected = $home->home;
|
|
|
|
} else {
|
|
|
|
$selected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$form->edit_user->dropdown("user_home")
|
2009-08-03 03:36:03 +00:00
|
|
|
->label(t("Home Gallery"))
|
|
|
|
->options(self::createGalleryArray())
|
|
|
|
->selected($selected);
|
2009-08-02 07:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 03:36:03 +00:00
|
|
|
* Called after a user had been edited by the user
|
2009-08-02 07:17:36 +00:00
|
|
|
*/
|
|
|
|
static function user_edit_form_completed($user, $form) {
|
2009-12-23 05:31:03 +00:00
|
|
|
$home = ORM::factory("user_home")->where("id", "=", $user->id)->find();
|
2009-08-03 03:36:03 +00:00
|
|
|
$home->id = $user->id;
|
|
|
|
$home->home = $form->edit_user->user_home->value;
|
2009-08-02 07:17:36 +00:00
|
|
|
$home->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 03:36:03 +00:00
|
|
|
* Creates an array of galleries
|
2009-08-02 07:17:36 +00:00
|
|
|
*/
|
|
|
|
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") {
|
2009-08-03 03:37:37 +00:00
|
|
|
$array[$parent->id] = ORM::factory("item", 1)->title;
|
2009-08-02 07:17:36 +00:00
|
|
|
} else {
|
|
|
|
$array[$parent->id] = "$dashes $parent->name";
|
|
|
|
}
|
|
|
|
|
|
|
|
$albums = ORM::factory("item")
|
2009-12-23 05:31:03 +00:00
|
|
|
->where("parent_id", "=", $parent->id)
|
|
|
|
->where("type", "=", "album")
|
|
|
|
->order_by("title", "ASC")
|
2009-08-03 03:36:03 +00:00
|
|
|
->find_all();
|
2009-08-02 07:17:36 +00:00
|
|
|
foreach ($albums as $album) {
|
|
|
|
self::tree($album, "-$dashes", $array);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-01-25 04:43:02 +00:00
|
|
|
|
|
|
|
static function show_user_profile($data) {
|
|
|
|
$home = ORM::factory("user_home")->where("id", "=", $data->user->id)->find();
|
|
|
|
|
|
|
|
if ($home->loaded()) {
|
|
|
|
$view = new View("user_profile_home.html");
|
|
|
|
$item = ORM::factory("item")->where("id", "=", $home->home)->find();
|
|
|
|
if ($item->loaded()) {
|
|
|
|
$view->item = $item;
|
|
|
|
$data->content[] = (object)array("title" => t("Home album"), "view" => $view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 23:11:02 +00:00
|
|
|
}
|