forked from extern/egroupware
Various optimizations to the API. This also does a little internal caching of some of the account data, but, only for a single page session.
This commit is contained in:
parent
5044e863f4
commit
6da089837d
@ -243,7 +243,7 @@
|
||||
global $phpgw, $phpgw_info;
|
||||
static $name_list;
|
||||
|
||||
if($name_list[$account_lid])
|
||||
if(@isset($name_list[$account_lid]))
|
||||
{
|
||||
return $name_list[$account_lid];
|
||||
}
|
||||
@ -252,13 +252,13 @@
|
||||
if($this->db->num_rows())
|
||||
{
|
||||
$this->db->next_record();
|
||||
$name_list[$account_lid] = $this->db->f('account_id');
|
||||
return intval($this->db->f('account_id'));
|
||||
$name_list[$account_lid] = intval($this->db->f('account_id'));
|
||||
}
|
||||
else
|
||||
{
|
||||
return False;
|
||||
$name_list[$account_lid] = False;
|
||||
}
|
||||
return $name_list[$account_lid];
|
||||
}
|
||||
|
||||
function id2name($account_id)
|
||||
@ -266,7 +266,7 @@
|
||||
global $phpgw, $phpgw_info;
|
||||
static $id_list;
|
||||
|
||||
if($id_list[$account_id])
|
||||
if(isset($id_list[$account_id]))
|
||||
{
|
||||
return $id_list[$account_id];
|
||||
}
|
||||
@ -276,29 +276,35 @@
|
||||
{
|
||||
$this->db->next_record();
|
||||
$id_list[$account_id] = $this->db->f('account_lid');
|
||||
return $this->db->f('account_lid');
|
||||
}
|
||||
else
|
||||
{
|
||||
return False;
|
||||
$id_list[$account_id] = False;
|
||||
}
|
||||
return $id_list[$account_id];
|
||||
}
|
||||
|
||||
function get_type($accountid = '')
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
static $account_type;
|
||||
|
||||
$account_id = get_account_id($accountid);
|
||||
if(@isset($account_type[$account_id]))
|
||||
{
|
||||
return $account_type[$account_id];
|
||||
}
|
||||
$this->db->query("SELECT account_type FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
|
||||
if ($this->db->num_rows())
|
||||
{
|
||||
$this->db->next_record();
|
||||
return $this->db->f('account_type');
|
||||
$account_type[$account_id] = $this->db->f('account_type');
|
||||
}
|
||||
else
|
||||
{
|
||||
return False;
|
||||
$account_type[$account_id] = False;
|
||||
}
|
||||
return $account_type[$account_id];
|
||||
}
|
||||
|
||||
/*
|
||||
@ -308,16 +314,28 @@
|
||||
function exists($account)
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
/* This sets up internal caching variables for this functon */
|
||||
static $by_id, $by_lid;
|
||||
|
||||
if(gettype($account) == 'integer')
|
||||
{
|
||||
$sql_name = 'account_id';
|
||||
$ldap_name = 'uidnumber';
|
||||
/* If data is cached, use it. */
|
||||
if(@isset($by_id[$account]))
|
||||
{
|
||||
return $by_id[$account];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql_name = 'account_lid';
|
||||
$ldap_name = 'uid';
|
||||
/* If data is cached, use it. */
|
||||
if(@isset($by_lid[$account]))
|
||||
{
|
||||
return $by_lid[$account];
|
||||
}
|
||||
}
|
||||
$this->db->query("SELECT count(*) FROM phpgw_accounts WHERE $sql_name='$account'",__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
@ -335,6 +353,18 @@
|
||||
$in += 2;
|
||||
}
|
||||
/* echo "<p>class_accounts_ldap->exists('$account') == $in</p>"; */
|
||||
|
||||
/* This sets up internal caching for this functon */
|
||||
if($sql_name == 'account_id')
|
||||
{
|
||||
$by_id[$account] = $in;
|
||||
$by_lid[$this->id2name($account)] = $in;
|
||||
}
|
||||
else
|
||||
{
|
||||
$by_lid[$account] = $in;
|
||||
$by_id[$this->name2id($account)] = $in;
|
||||
}
|
||||
|
||||
return $in;
|
||||
}
|
||||
|
@ -172,13 +172,13 @@
|
||||
if($this->db->num_rows())
|
||||
{
|
||||
$this->db->next_record();
|
||||
$name_list[$account_lid] = $this->db->f('account_id');
|
||||
return $this->db->f('account_id');
|
||||
$name_list[$account_lid] = intval($this->db->f('account_id'));
|
||||
}
|
||||
else
|
||||
{
|
||||
return False;
|
||||
$name_list[$account_lid] = False;
|
||||
}
|
||||
return $name_list[$account_lid];
|
||||
}
|
||||
|
||||
function id2name($account_id)
|
||||
@ -196,43 +196,73 @@
|
||||
{
|
||||
$this->db->next_record();
|
||||
$id_list[$account_id] = $this->db->f('account_lid');
|
||||
return $this->db->f('account_lid');
|
||||
}
|
||||
else
|
||||
{
|
||||
return False;
|
||||
$id_list[$account_id] = False;
|
||||
}
|
||||
return $id_list[$account_id];
|
||||
}
|
||||
|
||||
function get_type($accountid)
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
static $account_type;
|
||||
|
||||
$account_id = get_account_id($accountid);
|
||||
if(@isset($account_type[$account_id]))
|
||||
{
|
||||
return $account_type[$account_id];
|
||||
}
|
||||
$this->db->query("SELECT account_type FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
|
||||
if ($this->db->num_rows())
|
||||
{
|
||||
$this->db->next_record();
|
||||
return $this->db->f('account_type');
|
||||
$account_type[$account_id] = $this->db->f('account_type');
|
||||
}
|
||||
else
|
||||
{
|
||||
return False;
|
||||
$account_type[$account_id] = False;
|
||||
}
|
||||
return $account_type[$account_id];
|
||||
}
|
||||
|
||||
function exists($account_lid)
|
||||
{
|
||||
static $by_id, $by_lid;
|
||||
|
||||
$sql = "SELECT count(account_id) FROM phpgw_accounts WHERE ";
|
||||
if(gettype($account_lid) == 'integer')
|
||||
{
|
||||
$account_id = $account_lid;
|
||||
settype($account_lid,'string');
|
||||
$account_lid = $this->id2name($account_id);
|
||||
if(@isset($by_id[$account_lid]))
|
||||
{
|
||||
return $by_id[$account_lid];
|
||||
}
|
||||
$sql .= "account_id = ".$account_lid;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(@isset($by_lid[$account_lid]))
|
||||
{
|
||||
return $by_lid[$account_lid];
|
||||
}
|
||||
$sql .= "account_lid = '".$account_lid."'";
|
||||
}
|
||||
|
||||
$this->db->query("SELECT count(*) FROM phpgw_accounts WHERE account_lid='".$account_lid."'",__LINE__,__FILE__);
|
||||
$this->db->query($sql,__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
return $this->db->f(0) > 0;
|
||||
$ret_val = $this->db->f(0) > 0;
|
||||
if(gettype($account_lid) == 'integer')
|
||||
{
|
||||
$by_id[$account_lid] = $ret_val;
|
||||
$by_lid[$this->id2name($account_lid)] = $ret_val;
|
||||
}
|
||||
else
|
||||
{
|
||||
$by_lid[$account_lid] = $ret_val;
|
||||
$by_id[$this->name2id($account_lid)] = $ret_val;
|
||||
}
|
||||
return $ret_val;
|
||||
}
|
||||
|
||||
function create($account_info)
|
||||
|
@ -254,14 +254,17 @@
|
||||
|
||||
function exists($account_lid)
|
||||
{
|
||||
$sql = "SELECT count(account_id) FROM phpgw_accounts WHERE ";
|
||||
if(gettype($account_lid) == 'integer')
|
||||
{
|
||||
$account_id = $account_lid;
|
||||
settype($account_lid,'string');
|
||||
$account_lid = $this->id2name($account_id);
|
||||
$sql .= "account_id = ".$account_lid;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql .= "account_lid = '".$account_lid."'";
|
||||
}
|
||||
|
||||
$this->db->query("SELECT count(*) FROM phpgw_accounts WHERE account_lid='".$account_lid."'",__LINE__,__FILE__);
|
||||
$this->db->query($sql,__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
return $this->db->f(0) > 0;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@
|
||||
default: return False;
|
||||
|
||||
}
|
||||
$this->db->query("select count(*) from phpgw_categories $w",__LINE__,__FILE__);
|
||||
$this->db->query("select count(cat_id) from phpgw_categories $w",__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
|
||||
return $this->db->f(0);
|
||||
@ -475,7 +475,7 @@
|
||||
$cat_exists = " cat_name='" . addslashes($cat_name) . "' AND cat_id != '$cat_id' ";
|
||||
}
|
||||
|
||||
$this->db->query("select count(*) from phpgw_categories where $cat_exists $filter",__LINE__,__FILE__);
|
||||
$this->db->query("select count(cat_id) from phpgw_categories where $cat_exists $filter",__LINE__,__FILE__);
|
||||
|
||||
$this->db->next_record();
|
||||
|
||||
|
@ -243,13 +243,13 @@
|
||||
{
|
||||
return (isset($GLOBALS['phpgw_info']['user']['account_id'])?$GLOBALS['phpgw_info']['user']['account_id']:0);
|
||||
}
|
||||
elseif (gettype($default_id) == 'string')
|
||||
elseif (is_string($default_id))
|
||||
{
|
||||
return $GLOBALS['phpgw']->accounts->name2id($default_id);
|
||||
}
|
||||
return intval($default_id);
|
||||
}
|
||||
elseif (gettype($account_id) == 'string')
|
||||
elseif (is_string($account_id))
|
||||
{
|
||||
if($GLOBALS['phpgw']->accounts->exists(intval($account_id)) == True)
|
||||
{
|
||||
@ -412,7 +412,7 @@
|
||||
}
|
||||
|
||||
$GLOBALS['phpgw']->db->Halt_On_Error = 'no';
|
||||
@$GLOBALS['phpgw']->db->query("select count(*) from phpgw_config");
|
||||
@$GLOBALS['phpgw']->db->query("select count(config_name) from phpgw_config");
|
||||
if (! @$GLOBALS['phpgw']->db->next_record())
|
||||
{
|
||||
$setup_dir = ereg_replace($PHP_SELF,'index.php','setup/');
|
||||
|
@ -79,7 +79,7 @@
|
||||
if (isset($phpgw_info['navbar']['admin']) && isset($phpgw_info['user']['preferences']['common']['show_currentusers']))
|
||||
{
|
||||
$db = $phpgw->db;
|
||||
$db->query("select count(*) from phpgw_sessions where session_flags != 'A'");
|
||||
$db->query("select count(session_id) from phpgw_sessions where session_flags != 'A'");
|
||||
$db->next_record();
|
||||
$tpl->set_var('current_users','<a href="' . $phpgw->link('/admin/currentusers.php') . '"> '
|
||||
. lang('Current users') . ': ' . $db->f(0) . '</a>');
|
||||
|
@ -106,7 +106,7 @@
|
||||
if (isset($phpgw_info['navbar']['admin']) && isset($phpgw_info['user']['preferences']['common']['show_currentusers']))
|
||||
{
|
||||
$db = $phpgw->db;
|
||||
$db->query('select count(*) from phpgw_sessions');
|
||||
$db->query('select count(session_id) from phpgw_sessions');
|
||||
$db->next_record();
|
||||
$tpl->set_var("current_users",'<a href="' . $phpgw->link('/admin/currentusers.php') . '"> '
|
||||
. lang('Current users') . ': ' . $db->f(0) . '</a>');
|
||||
|
@ -79,7 +79,7 @@
|
||||
if (isset($phpgw_info['navbar']['admin']) && isset($phpgw_info['user']['preferences']['common']['show_currentusers']))
|
||||
{
|
||||
$db = $phpgw->db;
|
||||
$db->query("select count(*) from phpgw_sessions");
|
||||
$db->query("select count(session_id) from phpgw_sessions");
|
||||
$db->next_record();
|
||||
$tpl->set_var('current_users','<a href="' . $phpgw->link('/admin/currentusers.php') . '"> '
|
||||
. lang('Current users') . ': ' . $db->f(0) . '</a>');
|
||||
|
@ -89,7 +89,7 @@
|
||||
if (isset($phpgw_info['navbar']['admin']) && isset($phpgw_info['user']['preferences']['common']['show_currentusers']))
|
||||
{
|
||||
$db = $phpgw->db;
|
||||
$db->query("select count(*) from phpgw_sessions where session_flags != 'A'");
|
||||
$db->query("select count(session_id) from phpgw_sessions where session_flags != 'A'");
|
||||
$db->next_record();
|
||||
$tpl->set_var('current_users','<a style="font-family: Geneva,Arial,Helvetica,sans-serif; font-size: 12pt;" href="' . $phpgw->link('/admin/currentusers.php') . '"> '
|
||||
. lang('Current users') . ': ' . $db->f(0) . '</a>');
|
||||
|
Loading…
Reference in New Issue
Block a user