Enabled Search, Improved Navbar, Fixed Application Authorisation and some other minor fixes
This commit is contained in:
@@ -172,7 +172,7 @@ class Config extends Kohana_Config {
|
||||
|
||||
public static function theme() {
|
||||
// If we are using user admin pages (and login), we'll choose the admin theme.
|
||||
if (! empty(URL::$method_directory[strtolower(Request::current()->directory())]) OR in_array(strtolower(Request::current()->controller()),array('login')))
|
||||
if (Request::current() AND (! empty(URL::$method_directory[strtolower(Request::current()->directory())]) OR in_array(strtolower(Request::current()->controller()),array('login'))))
|
||||
return 'theme/'.Kohana::$config->load('config')->theme_admin;
|
||||
else
|
||||
return 'theme/'.Kohana::$config->load('config')->theme;
|
||||
|
14
application/classes/Controller/Search.php
Normal file
14
application/classes/Controller/Search.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides system search capabilities
|
||||
*
|
||||
* @package OSB
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Search extends Controller_TemplateDefault {
|
||||
}
|
||||
?>
|
37
application/classes/Controller/User/Search.php
Normal file
37
application/classes/Controller/User/Search.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides System Search capabilities
|
||||
*
|
||||
* @package OSB
|
||||
* @category Controllers/User
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_User_Search extends Controller_Search {
|
||||
protected $secure_actions = array(
|
||||
'ajaxlist'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Used by AJAX calls to find accounts, invoices, services and payments
|
||||
*/
|
||||
public function action_ajaxlist() {
|
||||
$result = array();
|
||||
|
||||
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
|
||||
$result = array_merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'url','id',array('ACC %s: %s'=>array('id','name(TRUE)')),array(),array('urlprefix'=>'a/service/list/')));
|
||||
$result = array_merge($result,ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'url','id',array('INV %s: %s'=>array('id','account->name(TRUE)')),array(),array('urlprefix'=>'u/invoice/view/')));
|
||||
$result = array_merge($result,ORM::factory('Service')->list_autocomplete($_REQUEST['term'],'url','id',array('SVC %s: %s'=>array('id','service_name()')),array(),array('urlprefix'=>'u/service/view/')));
|
||||
|
||||
foreach (array('Service_Plugin_Adsl','Service_Plugin_Domain','Service_Plugin_Host') as $o)
|
||||
$result = array_merge($result,ORM::factory($o)->list_autocomplete($_REQUEST['term'],'url','service_id',array('SVC %s: %s'=>array('service_id','service_name()')),array(),array('urlprefix'=>'u/service/view/')));
|
||||
}
|
||||
|
||||
$this->auto_render = FALSE;
|
||||
$this->response->headers('Content-Type','application/json');
|
||||
$this->response->body(json_encode(array_values($result)));
|
||||
}
|
||||
}
|
||||
?>
|
@@ -22,8 +22,12 @@ class Kohana_Exception extends Kohana_Kohana_Exception {
|
||||
$eo = ORM::factory('Log_Error');
|
||||
$eo->message = Kohana_Exception::text($e);
|
||||
$eo->account_id = Auth::instance()->get_user()->id;
|
||||
$eo->module = (Request::current()->directory() ? Request::current()->directory().'_' : '').Request::current()->controller();
|
||||
$eo->method = Request::current()->action();
|
||||
|
||||
if (Request::current()) {
|
||||
$eo->module = (Request::current()->directory() ? Request::current()->directory().'_' : '').Request::current()->controller();
|
||||
$eo->method = Request::current()->action();
|
||||
}
|
||||
|
||||
$eo->save();
|
||||
|
||||
} catch (Exception $x) {
|
||||
|
@@ -166,13 +166,11 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
/**
|
||||
* Search for accounts matching a term
|
||||
*/
|
||||
public function list_autocomplete($term,$index='id',array $limit=array()) {
|
||||
$result = array();
|
||||
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
|
||||
$ao = Auth::instance()->get_user();
|
||||
|
||||
$this->clear();
|
||||
$this->where_active();
|
||||
$value = 'name(TRUE)';
|
||||
|
||||
// Build our where clause
|
||||
// First Name, Last name
|
||||
@@ -190,7 +188,6 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
|
||||
} elseif (preg_match('/\@/',$term)) {
|
||||
$this->where('email','like','%'.$term.'%');
|
||||
$value = 'email';
|
||||
|
||||
} else {
|
||||
$this->where_open()
|
||||
@@ -201,22 +198,10 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
->where_close();
|
||||
}
|
||||
|
||||
foreach ($limit as $w) {
|
||||
list($k,$s,$v) = $w;
|
||||
|
||||
$this->and_where($k,$s,$v);
|
||||
}
|
||||
|
||||
// Restrict results to authorised accounts
|
||||
$this->and_where('id','IN',$ao->RTM->customers($ao->RTM));
|
||||
array_push($limit,array('id','IN',$ao->RTM->customers($ao->RTM)));
|
||||
|
||||
foreach ($this->find_all() as $o)
|
||||
$result[$o->$index] = array(
|
||||
'value'=>$o->$index,
|
||||
'label'=>sprintf('ACC %s: %s',$o->id,Table::resolve($o,$value)),
|
||||
);
|
||||
|
||||
return $result;
|
||||
return parent::list_autocomplete($term,$index,$value,$label,$limit,$options);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -20,6 +20,10 @@ class Model_RTM extends ORM_OSB {
|
||||
);
|
||||
|
||||
public function customers(Model_RTM $rtmo) {
|
||||
// If our RTM is NULL, then we are our only customer.
|
||||
if (is_null($rtmo->id))
|
||||
return (array(Auth::Instance()->get_user()));
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($rtmo->agents_direct() as $artmo)
|
||||
|
@@ -33,6 +33,13 @@ abstract class ORM extends Kohana_ORM {
|
||||
$this->_formated = TRUE;
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
$this->_formated = FALSE;
|
||||
$this->_object_formated = array();
|
||||
|
||||
return parent::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a formated columns, as per the model definition
|
||||
*/
|
||||
@@ -111,6 +118,62 @@ abstract class ORM extends Kohana_ORM {
|
||||
return $this->_where_active()->find_all();
|
||||
}
|
||||
|
||||
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
|
||||
$result = array();
|
||||
|
||||
$query = empty($options['object']) ? $this : $options['object'];
|
||||
|
||||
foreach ($limit as $w) {
|
||||
list($k,$s,$v) = $w;
|
||||
|
||||
$query->and_where($k,$s,$v);
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
foreach ((empty($options['object']) ? $query->find_all() : $query->execute()) as $o) {
|
||||
// If we got here via a DB query, we need to reload our ORM object from the result.
|
||||
if (! is_object($o)) {
|
||||
if (empty($options['key']))
|
||||
throw new Kohana_Exception('Missing key for non object');
|
||||
|
||||
$o = $this->clear()->where($options['key'],'=',$o[$options['key']])->find();
|
||||
}
|
||||
|
||||
switch ($index) {
|
||||
case 'url':
|
||||
if (empty($options['urlprefix']))
|
||||
throw new Kohana_Exception('Missing URL Prefix');
|
||||
|
||||
$v = $options['urlprefix'].$o->resolve($value);
|
||||
|
||||
break;
|
||||
|
||||
default: $v = $o->resolve($value);
|
||||
}
|
||||
|
||||
$k = '';
|
||||
foreach ($label as $k => $details)
|
||||
foreach ($details as $lvalue)
|
||||
$k = preg_replace('/%s/',$o->resolve($lvalue),$k,1);
|
||||
|
||||
$result[$c++] = array(
|
||||
'value'=>$v,
|
||||
'label'=>$k,
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used so that methods can be called via variables
|
||||
*/
|
||||
public function resolve($key) {
|
||||
eval("\$x = \$this->$key;");
|
||||
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function help to find records that are active
|
||||
*/
|
||||
|
@@ -104,7 +104,6 @@ abstract class ORM_OSB extends ORM {
|
||||
$this->_object[$column] = $this->_blob($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
echo Debug::vars($e);die();
|
||||
// @todo Log this exception
|
||||
echo Kohana_Exception::text($e), "\n";
|
||||
echo debug_print_backtrace();
|
||||
|
@@ -14,8 +14,8 @@ class URL extends Kohana_URL {
|
||||
public static $method_directory = array(
|
||||
'admin'=>'a',
|
||||
'reseller'=>'r',
|
||||
'task'=>'task',
|
||||
'user'=>'u',
|
||||
'task'=>'task',
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -49,5 +49,26 @@ class URL extends Kohana_URL {
|
||||
// If we get here, we didnt have anything.
|
||||
return $dir;
|
||||
}
|
||||
|
||||
public static function navbar() {
|
||||
$result = array();
|
||||
|
||||
foreach (array_reverse(static::$method_directory) as $k=>$v)
|
||||
switch ($k) {
|
||||
case 'admin': $result[$k] = array('name'=>'Administrator','icon'=>'icon-globe');
|
||||
break;
|
||||
|
||||
case 'affiliate':
|
||||
case 'reseller': $result[$k] = array('name'=>'Reseller','icon'=>'icon-th-list');
|
||||
break;
|
||||
|
||||
case 'user': $result[$k] = array('name'=>Auth::instance()->get_user()->name(),'icon'=>'icon-user');
|
||||
break;
|
||||
|
||||
default: $result[$k] = array('name'=>$k,'icon'=>'icon-question-sign');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user