Formatting, and merged expires field into sql

This commit is contained in:
Miles Lott 2001-05-02 09:38:37 +00:00
parent 99ff1cb575
commit cee6081e38
2 changed files with 132 additions and 119 deletions

View File

@ -456,13 +456,13 @@
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
$account_id = get_account_id($accountid); $account_id = get_account_id($accountid);
$this->db->query("SELECT account_type FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__); $this->db->query("SELECT account_type FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
if ($this->db->num_rows()) if ($this->db->num_rows())
{ {
$this->db->next_record(); $this->db->next_record();
return $this->db->f("account_type"); return $this->db->f("account_type");
} }
else else
{ {
return False; return False;

View File

@ -24,14 +24,14 @@
/* $Id$ */ /* $Id$ */
$phpgw_info["server"]["global_denied_users"] = array(); $phpgw_info["server"]["global_denied_users"] = array();
$phpgw_info["server"]["global_denied_groups"] = array(); $phpgw_info["server"]["global_denied_groups"] = array();
class accounts_ class accounts_
{ {
var $db; var $db;
var $account_id; var $account_id;
var $data; var $data;
function accounts_() function accounts_()
{ {
@ -45,17 +45,18 @@
$this->db->query("select * from phpgw_accounts where account_id='" . $this->account_id . "'",__LINE__,__FILE__); $this->db->query("select * from phpgw_accounts where account_id='" . $this->account_id . "'",__LINE__,__FILE__);
$this->db->next_record(); $this->db->next_record();
$this->data["userid"] = $this->db->f("account_lid"); $this->data['userid'] = $this->db->f('account_lid');
$this->data["account_id"] = $this->db->f("account_id"); $this->data['account_id'] = $this->db->f('account_id');
$this->data["account_lid"] = $this->db->f("account_lid"); $this->data['account_lid'] = $this->db->f('account_lid');
$this->data["firstname"] = $this->db->f("account_firstname"); $this->data['firstname'] = $this->db->f('account_firstname');
$this->data["lastname"] = $this->db->f("account_lastname"); $this->data['lastname'] = $this->db->f('account_lastname');
$this->data["fullname"] = $this->db->f("account_firstname")." ".$this->db->f("account_lastname"); $this->data['fullname'] = $this->db->f('account_firstname').' '.$this->db->f('account_lastname');
$this->data["lastlogin"] = $this->db->f("account_lastlogin"); $this->data['lastlogin'] = $this->db->f('account_lastlogin');
$this->data["lastloginfrom"] = $this->db->f("account_lastloginfrom"); $this->data['lastloginfrom'] = $this->db->f('account_lastloginfrom');
$this->data["lastpasswd_change"] = $this->db->f("account_lastpwd_change"); $this->data['lastpasswd_change'] = $this->db->f('account_lastpwd_change');
$this->data["account_type"] = $this->db->f("account_type"); $this->data['account_type'] = $this->db->f('account_type');
$this->data["status"] = $this->db->f("account_status"); $this->data['status'] = $this->db->f('account_status');
$this->data['expires'] = $this->db->f('account_expires');
return $this->data; return $this->data;
} }
@ -63,11 +64,12 @@
{ {
$this->db->query("update phpgw_accounts set account_lid='" . $this->data["account_lid"] $this->db->query("update phpgw_accounts set account_lid='" . $this->data["account_lid"]
. "', account_firstname='" . $this->data['firstname'] . "', account_firstname='" . $this->data['firstname']
. "', account_lastname='" . $this->data['lastname'] . "', account_lastname='" . $this->data['lastname'] . "', account_status='"
. "', account_status='" . $this->data['status'] . $this->data['status'] . "', account_expires='" . $this->data['expires'] . "' where account_id='"
. "' where account_id='" . $this->account_id . "'",__LINE__,__FILE__); . $this->account_id . "'",__LINE__,__FILE__);
} }
function delete($accountid = '') function delete($accountid = '')
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
@ -82,119 +84,128 @@
} }
function get_list($_type='both',$start = '',$sort = '', $order = '', $query = '', $offset = '') function get_list($_type='both',$start = '',$sort = '', $order = '', $query = '', $offset = '')
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
if ($offset) if ($offset)
{
$limitclause = $phpgw->db->limit($start,$offset);
}
elseif ($start && !$offset)
{
$limitclause = $phpgw->db->limit($start);
}
if (! $sort)
{
$sort = "desc";
}
if ($order)
{
$orderclause = "order by $order $sort";
}
else
{
$orderclause = "order by account_lid,account_lastname,account_firstname asc";
}
switch($_type)
{
case 'accounts':
$whereclause = "where account_type = 'u'";
break;
case 'groups':
$whereclause = "where account_type = 'g'";
break;
default:
$whereclause = "";
}
if ($query)
{
if ($whereclause)
{ {
$whereclause .= ' and ( '; $limitclause = $phpgw->db->limit($start,$offset);
}
elseif ($start && !$offset)
{
$limitclause = $phpgw->db->limit($start);
}
if (! $sort)
{
$sort = "desc";
}
if ($order)
{
$orderclause = "order by $order $sort";
} }
else else
{ {
$whereclause .= ' where '; $orderclause = "order by account_lid,account_lastname,account_firstname asc";
} }
$whereclause .= " account_firstname like '%$query%' OR account_lastname like " switch($_type)
. "'%$query%' OR account_lid like '%$query%' ";
if ($whereclause)
{ {
$whereclause .= ' ) '; case 'accounts':
$whereclause = "where account_type = 'u'";
break;
case 'groups':
$whereclause = "where account_type = 'g'";
break;
default:
$whereclause = "";
} }
if ($query)
{
if ($whereclause)
{
$whereclause .= ' and ( ';
}
else
{
$whereclause .= ' where ';
}
$whereclause .= " account_firstname like '%$query%' OR account_lastname like "
. "'%$query%' OR account_lid like '%$query%' ";
if ($whereclause)
{
$whereclause .= ' ) ';
}
}
$sql = "select * from phpgw_accounts $whereclause $orderclause $limitclause";
$this->db->query($sql,__LINE__,__FILE__);
while ($this->db->next_record()) {
$accounts[] = Array(
'account_id' => $this->db->f('account_id'),
'account_lid' => $this->db->f('account_lid'),
'account_type' => $this->db->f('account_type'),
'account_firstname' => $this->db->f('account_firstname'),
'account_lastname' => $this->db->f('account_lastname'),
'account_status' => $this->db->f('account_status',
'account_expires' => $this->db->f('account_expires')
);
}
return $accounts;
} }
$sql = "select * from phpgw_accounts $whereclause $orderclause $limitclause"; function name2id($account_lid)
$this->db->query($sql,__LINE__,__FILE__); {
while ($this->db->next_record()) { global $phpgw, $phpgw_info;
$accounts[] = Array(
"account_id" => $this->db->f("account_id"), $this->db->query("SELECT account_id FROM phpgw_accounts WHERE account_lid='".$account_lid."'",__LINE__,__FILE__);
"account_lid" => $this->db->f("account_lid"), if($this->db->num_rows())
"account_type" => $this->db->f("account_type"), {
"account_firstname" => $this->db->f("account_firstname"), $this->db->next_record();
"account_lastname" => $this->db->f("account_lastname"), return $this->db->f('account_id');
"account_status" => $this->db->f("account_status") }
); else
{
return False;
}
} }
return $accounts;
}
function name2id($account_lid) function id2name($account_id)
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
$this->db->query("SELECT account_id FROM phpgw_accounts WHERE account_lid='".$account_lid."'",__LINE__,__FILE__); $this->db->query("SELECT account_lid FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
if($this->db->num_rows()) { if($this->db->num_rows())
$this->db->next_record(); {
return $this->db->f('account_id'); $this->db->next_record();
}else{ return $this->db->f('account_lid');
return False; }
} else
} {
return False;
}
}
function id2name($account_id) function get_type($accountid)
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
$this->db->query("SELECT account_lid FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
if($this->db->num_rows()) {
$this->db->next_record();
return $this->db->f('account_lid');
}else{
return False;
}
}
function get_type($accountid) $account_id = get_account_id($accountid);
{ $this->db->query("SELECT account_type FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
global $phpgw, $phpgw_info; if ($this->db->num_rows())
{
$account_id = get_account_id($accountid); $this->db->next_record();
$this->db->query("SELECT account_type FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__); return $this->db->f('account_type');
if ($this->db->num_rows()) { }
$this->db->next_record(); else
return $this->db->f('account_type'); {
} else { return False;
return False; }
} }
}
function exists($account_lid) function exists($account_lid)
{ {
@ -210,6 +221,8 @@
return $this->db->f(0) > 0; return $this->db->f(0) > 0;
} }
// !! NOTE: We should pass an array to this to make updates easier, plus I need to add account_expires
// I didn't want to risk breaking too much code at once, I will do this soon. (jengo)
function create($account_type, $account_lid, $account_pwd, $account_firstname, $account_lastname, $account_status, $account_id='', $account_home='',$account_shell='') function create($account_type, $account_lid, $account_pwd, $account_firstname, $account_lastname, $account_status, $account_id='', $account_home='',$account_shell='')
{ {
//echo '<br>in create for account_lid: "'.$account_lid.'"'; //echo '<br>in create for account_lid: "'.$account_lid.'"';