Initial Leenooks Module for Kohana
This commit is contained in:
89
classes/lnApp/Controller/Default.php
Normal file
89
classes/lnApp/Controller/Default.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides the default controller for rendering pages.
|
||||
*
|
||||
* @package lnApp
|
||||
* @category lnApp/Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Controller_Default extends Controller {
|
||||
/**
|
||||
* The variable that our output is stored in
|
||||
*/
|
||||
protected $output = NULL;
|
||||
/**
|
||||
* @var string page media route as per [Route]
|
||||
*/
|
||||
protected $mediaroute = 'default/media';
|
||||
/**
|
||||
* Controls access to this controller.
|
||||
* Can be set to a string or an array, for example 'login' or array('login', 'admin')
|
||||
* Note that in second(array) example, user must have both 'login' AND 'admin' roles set in database
|
||||
*
|
||||
* @var boolean is authenticate required with this controller
|
||||
*/
|
||||
protected $auth_required = FALSE;
|
||||
/**
|
||||
* If redirecting to a login page, which page to redirect to
|
||||
*/
|
||||
protected $noauth_redirect = 'login';
|
||||
/**
|
||||
* Controls access for separate actions, eg:
|
||||
* 'adminpanel' => 'admin' will only allow users with the role admin to access action_adminpanel
|
||||
* 'moderatorpanel' => array('login', 'moderator') will only allow users with the roles login and moderator to access action_moderatorpanel
|
||||
*
|
||||
* @var array actions that require a valid user
|
||||
*/
|
||||
protected $secure_actions = array();
|
||||
|
||||
/**
|
||||
* Check and see if this controller needs authentication
|
||||
*
|
||||
* if $this->auth_required is TRUE, then the user must be logged in only.
|
||||
* if $this->auth_required is FALSE, AND $this->secure_actions has an array of
|
||||
* methods set to TRUE, then the user must be logged in AND a member of the
|
||||
* role.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _auth_required() {
|
||||
// If our global configurable is disabled, then continue
|
||||
if (! Kohana::$config->load('config')->method_security)
|
||||
return FALSE;
|
||||
|
||||
return (($this->auth_required !== FALSE && Auth::instance()->logged_in() === FALSE) ||
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action(),$this->secure_actions) &&
|
||||
Auth::instance()->logged_in($this->secure_actions[$this->request->action()]) === FALSE));
|
||||
}
|
||||
|
||||
public function before() {
|
||||
parent::before();
|
||||
|
||||
// Check user auth and role
|
||||
if ($this->_auth_required()) {
|
||||
// For AJAX/JSON requests, authorisation is controlled in the method.
|
||||
if (Request::current()->is_ajax() && $this->request->action() === 'json') {
|
||||
// Nothing required.
|
||||
|
||||
// For no AJAX/JSON requests, display an access page
|
||||
} elseif (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__)) {
|
||||
HTTP::redirect('login/noaccess');
|
||||
|
||||
} else {
|
||||
Session::instance()->set('afterlogin',Request::detect_uri());
|
||||
HTTP::redirect($this->noauth_redirect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function after() {
|
||||
parent::after();
|
||||
|
||||
// Generate and check the ETag for this file
|
||||
$this->check_cache(sha1($this->response->body()));
|
||||
}
|
||||
}
|
||||
?>
|
73
classes/lnApp/Controller/Login.php
Normal file
73
classes/lnApp/Controller/Login.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides login capability
|
||||
*
|
||||
* @package lnApp
|
||||
* @category lnApp/Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
* @also [logout]
|
||||
*/
|
||||
class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
protected $auth_required = FALSE;
|
||||
|
||||
public function action_index() {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in() != 0) {
|
||||
// Redirect to the user account
|
||||
HTTP::redirect(URL::link('user','welcome/index'));
|
||||
}
|
||||
|
||||
// If there is a post and $_POST is not empty
|
||||
if ($_POST) {
|
||||
// Store our details in a session key
|
||||
Session::instance()->set(Kohana::$config->load('auth')->session_key,$_POST['username']);
|
||||
Session::instance()->set('password',$_POST['password']);
|
||||
|
||||
// If the post data validates using the rules setup in the user model
|
||||
if (Auth::instance()->login($_POST['username'],$_POST['password'])) {
|
||||
// Redirect to the user account
|
||||
if ($redir = Session::instance()->get('afterlogin')) {
|
||||
Session::instance()->delete('afterlogin');
|
||||
HTTP::redirect($redir);
|
||||
|
||||
} else
|
||||
HTTP::redirect(URL::link('user','welcome/index'));
|
||||
|
||||
} else {
|
||||
// We are not successful logging in, so delete our session data
|
||||
Session::instance()->delete(Kohana::$config->load('auth')->session_key);
|
||||
Session::instance()->delete('password');
|
||||
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Invalid username or password'),
|
||||
'type'=>'error',
|
||||
'body'=>_('The username or password was invalid.')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Login to server'),
|
||||
'body'=>View::factory('login'),
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("#ajxbody").click(function() {$("#ajBODY").load("'.$this->request->uri().'/"); return false;});
|
||||
});'
|
||||
));
|
||||
}
|
||||
|
||||
public function action_noaccess() {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('No access to requested resource'),
|
||||
'type'=>'error',
|
||||
'body'=>_('You do not have access to the requested resource, please contact your administrator.')
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
30
classes/lnApp/Controller/Logout.php
Normal file
30
classes/lnApp/Controller/Logout.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides logout capability
|
||||
*
|
||||
* @package lnApp
|
||||
* @category lnApp/Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
* @also [login]
|
||||
*/
|
||||
class lnApp_Controller_Logout extends Controller {
|
||||
public function action_index() {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in() != 0) {
|
||||
$ao = Auth::instance()->get_user();
|
||||
|
||||
if (method_exists($ao,'log'))
|
||||
$ao->log('Logged Out');
|
||||
|
||||
Auth::instance()->logout();
|
||||
|
||||
HTTP::redirect('login');
|
||||
}
|
||||
|
||||
HTTP::redirect('welcome/index');
|
||||
}
|
||||
}
|
||||
?>
|
63
classes/lnApp/Controller/Media.php
Normal file
63
classes/lnApp/Controller/Media.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides access to rendering media items (javascript, images and css).
|
||||
*
|
||||
* @package lnApp
|
||||
* @category lnApp/Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Controller_Media extends Controller {
|
||||
/**
|
||||
* This action will render all the media related files for a page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function action_get() {
|
||||
// Get the file path from the request
|
||||
$file = $this->request->param('file');
|
||||
|
||||
// Find the file extension
|
||||
$ext = pathinfo($file,PATHINFO_EXTENSION);
|
||||
|
||||
// Remove the extension from the filename
|
||||
$file = substr($file,0,-(strlen($ext)+1));
|
||||
$f = '';
|
||||
|
||||
// If our file is pathed with session, our file is in our session.
|
||||
if ($fd = Session::instance()->get_once($this->request->param('file'))) {
|
||||
$this->response->body($fd);
|
||||
|
||||
// First try and find media files for the theme-site_id
|
||||
} elseif ($f = Kohana::find_file($x=sprintf('media/site/%s/theme/%s',Config::siteid(),Config::theme()),$file,$ext)) {
|
||||
// Send the file content as the response
|
||||
$this->response->body(file_get_contents($f));
|
||||
|
||||
// Try and find media files for the site_id
|
||||
} elseif ($f = Kohana::find_file(sprintf('media/site/%s',Config::siteid()),$file,$ext)) {
|
||||
// Send the file content as the response
|
||||
$this->response->body(file_get_contents($f));
|
||||
|
||||
// If not found try a default media file
|
||||
} elseif ($f = Kohana::find_file('media',$file,$ext)) {
|
||||
// Send the file content as the response
|
||||
$this->response->body(file_get_contents($f));
|
||||
|
||||
} else {
|
||||
// Return a 404 status
|
||||
$this->response->status(404);
|
||||
}
|
||||
|
||||
// Generate and check the ETag for this file
|
||||
if (Kohana::$environment === Kohana::PRODUCTION OR Kohana::$config->load('debug')->etag)
|
||||
$this->check_cache(sha1($this->response->body()));
|
||||
|
||||
// Set the proper headers to allow caching
|
||||
$this->response->headers('Content-Type',File::mime_by_ext($ext));
|
||||
$this->response->headers('Content-Length',(string)$this->response->content_length());
|
||||
$this->response->headers('Last-Modified',date('r',$f ? filemtime($f) : time()));
|
||||
}
|
||||
}
|
||||
?>
|
20
classes/lnApp/Controller/Task.php
Normal file
20
classes/lnApp/Controller/Task.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides the default controller for tasks.
|
||||
*
|
||||
* @package lnApp
|
||||
* @category lnApp/Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Controller_Task extends Controller {
|
||||
public function before() {
|
||||
if (! Kohana::$is_cli)
|
||||
throw new Kohana_Exception('Cant run :method, it must be run by the CLI',array(':method'=>$this->request->action()));
|
||||
|
||||
parent::before();
|
||||
}
|
||||
}
|
||||
?>
|
260
classes/lnApp/Controller/TemplateDefault.php
Normal file
260
classes/lnApp/Controller/TemplateDefault.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides the default template controller for rendering pages.
|
||||
*
|
||||
* @package lnApp
|
||||
* @category lnApp/Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
|
||||
/**
|
||||
* @var string page template
|
||||
*/
|
||||
public $template = 'theme/bootstrap/default';
|
||||
/**
|
||||
* @var object meta object information as per [meta]
|
||||
*/
|
||||
protected $meta;
|
||||
/**
|
||||
* Controls access to this controller.
|
||||
* Can be set to a string or an array, for example 'login' or array('login', 'admin')
|
||||
* Note that in second(array) example, user must have both 'login' AND 'admin' roles set in database
|
||||
*
|
||||
* @var boolean is authenticate required with this controller
|
||||
*/
|
||||
protected $auth_required = FALSE;
|
||||
/**
|
||||
* If redirecting to a login page, which page to redirect to
|
||||
*/
|
||||
protected $noauth_redirect = 'login';
|
||||
/**
|
||||
* Controls access for separate actions, eg:
|
||||
* 'adminpanel' => 'admin' will only allow users with the role admin to access action_adminpanel
|
||||
* 'moderatorpanel' => array('login', 'moderator') will only allow users with the roles login and moderator to access action_moderatorpanel
|
||||
*
|
||||
* @var array actions that require a valid user
|
||||
*/
|
||||
protected $secure_actions = array();
|
||||
|
||||
/**
|
||||
* Check and see if this controller needs authentication
|
||||
*
|
||||
* if $this->auth_required is TRUE, then the user must be logged in only.
|
||||
* if $this->auth_required is FALSE, AND $this->secure_actions has an array of
|
||||
* methods set to TRUE, then the user must be logged in AND a member of the
|
||||
* role.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _auth_required() {
|
||||
// If our global configurable is disabled, then continue
|
||||
if (! Kohana::$config->load('config')->method_security)
|
||||
return FALSE;
|
||||
|
||||
return (($this->auth_required !== FALSE && Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__) === FALSE) ||
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action(),$this->secure_actions) &&
|
||||
Auth::instance()->logged_in($this->secure_actions[$this->request->action()],get_class($this).'|'.__METHOD__) === FALSE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the template [View] object.
|
||||
*
|
||||
* Page information is provided by [meta].
|
||||
* @uses meta
|
||||
*/
|
||||
public function before() {
|
||||
// Do not template media files
|
||||
if ($this->request->action() === 'media') {
|
||||
$this->auto_render = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
// Actions that start with ajax, should only be ajax
|
||||
if (! Kohana::$config->load('debug')->ajax AND preg_match('/^ajax/',Request::current()->action()) AND ! Request::current()->is_ajax())
|
||||
die();
|
||||
|
||||
parent::before();
|
||||
|
||||
// Check user auth and role
|
||||
if ($this->_auth_required()) {
|
||||
if (Kohana::$is_cli)
|
||||
throw new Kohana_Exception('Cant run :method, authentication not possible',array(':method'=>$this->request->action()));
|
||||
|
||||
// If auth is required and the user is logged in, then they dont have access.
|
||||
// (We have already checked authorisation.)
|
||||
if (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__)) {
|
||||
if (Config::sitemode() == Kohana::DEVELOPMENT)
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Insufficient Access'),
|
||||
'type'=>'debug',
|
||||
'body'=>Debug::vars(array('required'=>$this->auth_required,'action'=>$this->request->action(),'user'=>Auth::instance()->get_user()->username)),
|
||||
));
|
||||
|
||||
// @todo Login No Access redirects are not handled in JS?
|
||||
if ($this->request->is_ajax()) {
|
||||
echo _('You dont have enough permissions.');
|
||||
die();
|
||||
} else
|
||||
HTTP::redirect('login/noaccess');
|
||||
|
||||
} else {
|
||||
Session::instance()->set('afterlogin',Request::detect_uri());
|
||||
HTTP::redirect($this->noauth_redirect);
|
||||
}
|
||||
}
|
||||
|
||||
// For AJAX calls, we dont need to render the complete page.
|
||||
if ($this->request->is_ajax()) {
|
||||
$this->auto_render = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind our template meta variable
|
||||
$this->meta = new Meta;
|
||||
View::bind_global('meta',$this->meta);
|
||||
|
||||
// Add our logo
|
||||
/*
|
||||
Style::add(array(
|
||||
'type'=>'stdin',
|
||||
'data'=>'h1 span{background:url('.Config::logo_uri().') no-repeat;}',
|
||||
));
|
||||
*/
|
||||
|
||||
// Our default script(s)
|
||||
/*
|
||||
foreach (array('file'=>array_reverse(array(
|
||||
'js/jquery-1.6.4.min.js',
|
||||
'js/jquery.jstree-1.0rc3.js',
|
||||
'js/jquery.cookie.js',
|
||||
))) as $type => $datas) {
|
||||
|
||||
foreach ($datas as $data) {
|
||||
Script::add(array(
|
||||
'type'=>$type,
|
||||
'data'=>$data,
|
||||
),TRUE);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Initialise our content
|
||||
$this->template->left = '';
|
||||
$this->template->content = '';
|
||||
$this->template->right = '';
|
||||
}
|
||||
|
||||
public function after() {
|
||||
if (! is_string($this->template) AND empty($this->template->content))
|
||||
$this->template->content = Block::factory();
|
||||
|
||||
if ($this->auto_render) {
|
||||
// Application Title
|
||||
if (class_exists('Model_Module') AND $mo=ORM::factory('Module',array('name'=>Request::current()->controller())) AND $mo->loaded())
|
||||
$this->meta->title = sprintf('%s: %s',Kohana::$config->load('config')->appname,$mo->display('name'));
|
||||
else
|
||||
$this->meta->title = Config::sitename();
|
||||
|
||||
$this->template->title = '';
|
||||
|
||||
// Language
|
||||
$this->meta->language = Config::language();
|
||||
|
||||
// Description
|
||||
$this->meta->description = sprintf('%s::%s',$this->request->controller(),$this->request->action());
|
||||
|
||||
// Link images on the header line
|
||||
$this->template->headimages = $this->_headimages();
|
||||
|
||||
// System Messages line
|
||||
$this->template->sysmsg = $this->_sysmsg();
|
||||
|
||||
// Left Item
|
||||
$this->template->left = '';
|
||||
|
||||
// Right Item
|
||||
$this->template->right = '';
|
||||
|
||||
// Footer
|
||||
$this->template->footer = $this->_footer();
|
||||
|
||||
// For any ajax rendered actions, we'll need to capture the content and put it in the response
|
||||
} elseif ($this->request->is_ajax() && isset($this->template->content) && ! $this->response->body()) {
|
||||
// @todo move this formatting to a view?
|
||||
if ($s = $this->_sysmsg() AND (string)$s)
|
||||
$this->response->body(sprintf('<table class="sysmsg"><tr><td>%s</td></tr></table>',$s));
|
||||
|
||||
// In case there any style sheets for this render.
|
||||
$this->response->bodyadd(Style::factory());
|
||||
|
||||
// Since we are ajax, we should re-render the breadcrumb
|
||||
Session::instance()->set('breadcrumb',(string)BreadCrumb::factory());
|
||||
$this->response->bodyadd(Script::add(array('type'=>'stdin','data'=>'$().ready($("#ajCONTROL").load("'.URL::site('welcome/breadcrumb').'",null,function(x,s,r) {}));')));
|
||||
|
||||
// In case there any javascript for this render.
|
||||
$this->response->bodyadd(Script::factory());
|
||||
|
||||
// Get the response body
|
||||
$this->response->bodyadd(sprintf('<table class="content"><tr><td>%s</td></tr></table>',$this->template->content));
|
||||
}
|
||||
|
||||
parent::after();
|
||||
|
||||
// Generate and check the ETag for this file
|
||||
$this->check_cache(sha1($this->response->body()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Method to call from the tree menu
|
||||
*/
|
||||
public function action_menu() {
|
||||
$this->template->content = _('Please choose from the menu on the left - you may need to expand the items by pressing on the plus.');
|
||||
}
|
||||
|
||||
protected function _headimages() {
|
||||
HeadImages::add(array(
|
||||
'url'=>'http://dev.leenooks.net',
|
||||
'img'=>'img/forum-big.png',
|
||||
'attrs'=>array('onclick'=>"target='_blank';",'title'=>'Link')
|
||||
));
|
||||
|
||||
return HeadImages::factory();
|
||||
}
|
||||
|
||||
protected function _sysmsg() {
|
||||
return SystemMessage::factory();
|
||||
}
|
||||
|
||||
public function _footer() {
|
||||
return sprintf('© %s',Config::sitename());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a view path to help View::factory() calls
|
||||
*
|
||||
* The purpose of this method is to ensure that we have a consistant
|
||||
* layout for our view files, including those that are needed by
|
||||
* plugins
|
||||
*
|
||||
* @param string Plugin Name (optional)
|
||||
*/
|
||||
public function viewpath($plugin='') {
|
||||
$request = Request::current();
|
||||
|
||||
$path = $request->controller();
|
||||
|
||||
if ($request->directory())
|
||||
$path .= ($path ? '/' : '').$request->directory();
|
||||
|
||||
if ($plugin)
|
||||
$path .= ($path ? '/' : '').$plugin;
|
||||
|
||||
$path .= ($path ? '/' : '').$request->action();
|
||||
|
||||
return strtolower($path);
|
||||
}
|
||||
}
|
||||
?>
|
116
classes/lnApp/Controller/Tree.php
Normal file
116
classes/lnApp/Controller/Tree.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class extends renders OSB menu tree.
|
||||
*
|
||||
* @package lnApp
|
||||
* @category lnApp/Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class lnApp_Controller_Tree extends Controller_Default {
|
||||
/**
|
||||
* @var string page media route as per [Route]
|
||||
*/
|
||||
protected static $jsmediaroute = 'default/media';
|
||||
|
||||
public function after() {
|
||||
$this->response->headers('Content-Type','application/json');
|
||||
$this->response->body(json_encode($this->output));
|
||||
|
||||
parent::after();
|
||||
}
|
||||
|
||||
public static function js() {
|
||||
$mediapath = Route::get(static::$jsmediaroute);
|
||||
|
||||
return '
|
||||
<div id="tree" class=""></div>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
$(function () {
|
||||
var use_ajax = false;
|
||||
|
||||
$("#tree").jstree({
|
||||
themes : {
|
||||
"theme" : "classic",
|
||||
},
|
||||
ui : {
|
||||
"select_limit" : 1,
|
||||
"select_node" : false,
|
||||
},
|
||||
cookies : {
|
||||
"save_selected" : false,
|
||||
"cookie_options" : { path : "'.URL::site().'" }
|
||||
},
|
||||
json_data : {
|
||||
"correct_state" : "true",
|
||||
"progressive_render" : "true",
|
||||
"ajax" : {
|
||||
"url" : "'.URL::site('tree/json').'",
|
||||
"data" : function (n) {
|
||||
return { id : n.attr ? n.attr("id") : "N_"+0 };
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins : [ "themes", "json_data", "ui", "cookies" ],
|
||||
});
|
||||
|
||||
// On selection
|
||||
$("#tree").bind("select_node.jstree", function (e, data) {
|
||||
if (a = data.rslt.obj.attr(\'id\').indexOf(\'_\')) {
|
||||
id = data.rslt.obj.attr(\'id\').substr(a+1);
|
||||
|
||||
if (href = $("#N_"+id).attr("href")) {
|
||||
if (! use_ajax) {
|
||||
window.location = href;
|
||||
return;
|
||||
}
|
||||
|
||||
$("#ajBODY").empty().html("<img src=\"'.URL::site('media/img/ajax-progress.gif').'\" alt=\"Loading...\" />");
|
||||
$("#ajBODY").load(href, function(r,s,x) {
|
||||
if (s == "error") {
|
||||
var msg = "Sorry but there was an error: ";
|
||||
$("#ajBODY").html(msg + x.status + " " + x.statusText + r);
|
||||
}
|
||||
});
|
||||
} else
|
||||
alert("Unknown: "+id+" HREF:"+href);
|
||||
}
|
||||
});
|
||||
});
|
||||
// -->
|
||||
</script>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the Tree Menu
|
||||
*
|
||||
* The incoming ID is either a Branch B_x or a Node N_x
|
||||
* Where X is actually the module.
|
||||
*
|
||||
* @param array $data Tree data passed in by inherited methods
|
||||
*/
|
||||
public function action_json(array $data=array()) {
|
||||
if ($this->_auth_required() AND ! Auth::instance()->logged_in()) {
|
||||
$this->output = array('attr'=>array('id'=>'a_login'),
|
||||
'data'=>array('title'=>_('Please Login').'...','attr'=>array('id'=>'N_login','href'=>URL::site('login'))));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->output = array();
|
||||
|
||||
foreach ($data as $branch) {
|
||||
array_push($this->output,array(
|
||||
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
|
||||
'state'=>$branch['state'],
|
||||
'data'=>array('title'=>$branch['name']),
|
||||
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::link('user',$branch['name'].'/menu',TRUE) : $branch['attr_href']),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user