New function get_account_id(). This will take either an account_id # as either an integer or a string and return a true intval(account_id) or take a string of a users lid and return the account_id as an integer

This commit is contained in:
skeeter 2001-03-19 20:25:04 +00:00
parent 3523adab62
commit b9da94fd2e
10 changed files with 92 additions and 77 deletions

View File

@ -58,10 +58,8 @@
var $db;
var $account_id;
var $data;
var $memberships = Array();
var $members;
function accounts()
function accounts_()
{
global $phpgw;
$this->db = $phpgw->db;
@ -120,11 +118,11 @@
$this->create($account_name, $account_type, $first_name, $last_name, $passwd);
}
function delete($account_id)
function delete($account_id = '')
{
global $phpgw, $phpgw_info;
$account_lid = $this->id2name($account_id);
$account_lid = $this->id2name(get_account_id($account_id));
$ds = $phpgw->common->ldapConnect();
$sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uid=".$account_lid);
$allValues = ldap_get_entries($ds, $sri);
@ -212,10 +210,11 @@
}
}
function get_type($account_id)
function get_type($accountid = '')
{
global $phpgw, $phpgw_info;
$account_id = get_account_type($accountid);
$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();
@ -335,10 +334,12 @@
return $accountid;
}
function getDNforID($_account_id)
function getDNforID($_accountid = '')
{
global $phpgw;
$_account_id = get_account_id($_accountid);
$ds = $phpgw->common->ldapConnect();
$sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=$_account_id");

View File

@ -25,21 +25,23 @@
class accounts extends accounts_
{
var $memberships = Array();
var $members = Array();
/**************************************************************************\
* Standard constructor for setting $this->account_id *
* This constructor sets the account id, if string is sent, converts to id *
* I might move this to the accounts_shared if it stays around *
\**************************************************************************/
function accounts($account_id = False)
function accounts($account_id = '')
{
global $phpgw, $phpgw_info;
$this->db = $phpgw->db;
if ($account_id != False) {
$this->account_id = $account_id;
}
$this->account_id = get_account_id($account_id);
}
function read()
@ -63,20 +65,13 @@
return $this->data;
}
function memberships($account_id = False)
function memberships($accountid = '')
{
global $phpgw_info, $phpgw;
if ($account_id == False)
{
$account_id = $phpgw_info['user']['account_id'];
}
elseif (gettype($account_id) == 'string')
{
$account_id = $this->name2id($account_id);
}
$account_id = get_account_id($accountid);
$security_equals = Array();
$security_equals = $phpgw->acl->get_location_list_for_id('phpgw_group', 1, intval($account_id));
$security_equals = $phpgw->acl->get_location_list_for_id('phpgw_group', 1, $account_id);
if ($security_equals == False)
{
@ -93,21 +88,14 @@
return $this->memberships;
}
function members ($account_id = False)
function members ($accountid = '')
{
global $phpgw_info, $phpgw;
if ($account_id == False)
{
$account_id = $phpgw_info['user']['account_id'];
}
elseif (gettype($account_id) == 'string')
{
$account_id = $this->name2id($account_id);
}
$account_id = get_account_id($accountid);
$security_equals = Array();
$acl = CreateObject('phpgwapi.acl');
$security_equals = $acl->get_ids_for_location(intval($account_id), 1, 'phpgw_group');
$security_equals = $acl->get_ids_for_location($account_id, 1, 'phpgw_group');
unset($acl);
if ($security_equals == False)

View File

@ -31,13 +31,10 @@
var $db;
var $account_id;
var $data;
var $memberships;
var $members;
function accounts()
function accounts_()
{
global $phpgw;
$this->db = $phpgw->db;
}
@ -166,14 +163,15 @@
}
}
function get_type($account_id)
function get_type($accountid)
{
global $phpgw, $phpgw_info;
$account_id = get_account_id($accountid);
$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");
return $this->db->f('account_type');
} else {
return False;
}

View File

@ -54,11 +54,11 @@
Example1: acl->acl(5); // 5 is the user id <br>
@param account_id int-the user id
*/
function acl($account_id = False)
function acl($account_id = '')
{
global $phpgw, $phpgw_info;
$this->db = $phpgw->db;
if ($account_id != False){ $this->account_id = $account_id; }
$this->account_id = get_account_id($account_id);
}
/**************************************************************************\
@ -358,6 +358,7 @@ It should use the values in the $this->data
$this->db->query($sql ,__LINE__,__FILE__);
return True;
}
/*!
@function delete_repository
@abstract delete repository information for an app
@ -365,7 +366,8 @@ It should use the values in the $this->data
@param $location location
@param $account_id account id
*/
function delete_repository($app, $location, $account_id){
function delete_repository($app, $location, $accountid = ''){
$account_id = get_account_type($accountid,$this->account_id);
$sql = "delete from phpgw_acl where acl_appname like '".$app."'"
. " and acl_location like '".$location."' and "
. " acl_account = ".$account_id;
@ -380,9 +382,9 @@ It should use the values in the $this->data
@param $required ?
@param $account_id account id defaults to $phpgw_info['user']['account_id'];
*/
function get_app_list_for_id($location, $required, $account_id = False){
function get_app_list_for_id($location, $required, $accountid = ''){
global $phpgw, $phpgw_info;
if ($account_id == False){ $account_id = $this->account_id; }
$account_id = get_account_id($accountid,$this->account_id);
$sql = "select acl_appname, acl_rights from phpgw_acl where acl_location = '$location' and ";
$sql .= 'acl_account = '.$account_id;
$this->db->query($sql ,__LINE__,__FILE__);
@ -397,6 +399,7 @@ It should use the values in the $this->data
}
return $apps;
}
/*!
@function get_location_list_for_id
@abstract get location list for id
@ -405,11 +408,11 @@ It should use the values in the $this->data
@param $required required
@param $account_id optional defaults to $phpgw_info['user']['account_id'];
*/
function get_location_list_for_id($app, $required, $account_id = False){
function get_location_list_for_id($app, $required, $accountid = ''){
global $phpgw, $phpgw_info;
if ($account_id == False){ $account_id = $phpgw_info['user']['account_id']; }
$account_id = get_account_id($accountid);
$sql = "select acl_location, acl_rights from phpgw_acl where acl_appname = '$app' and ";
$sql .= "acl_account = '".$account_id."'";
$sql .= "acl_account = ".$account_id;
$this->db->query($sql ,__LINE__,__FILE__);
$rights = 0;
if ($this->db->num_rows() == 0 ){ return False; }
@ -449,21 +452,20 @@ It should use the values in the $this->data
}
return $accounts;
}
/*!
@function get_user_applications
@abstract get a list of applications a user has rights to
@param $account_id optional defaults to $phpgw_info['user']['account_id'];
@result $apps array containing list of apps
*/
function get_user_applications($account_id = False)
function get_user_applications($accountid = '')
{
global $phpgw, $phpgw_info;
$db2 = $this->db;
if ($account_id == False){
$account_id = $phpgw_info['user']['account_id'];
}
$account_id = get_account_id($accountid);
$memberships = $phpgw->accounts->memberships($account_id);
$sql = "select acl_appname, acl_rights from phpgw_acl where acl_location = 'run' and "
. 'acl_account in ';

View File

@ -40,11 +40,11 @@
@abstract standard constructor for setting $this->account_id
@param $account_id account id
*/
function applications($account_id = False)
function applications($account_id = '')
{
global $phpgw, $phpgw_info;
$this->db = $phpgw->db;
if ($account_id != False){ $this->account_id = $account_id; }
$this->account_id = get_account_id($account_id);
}
/**************************************************************************\

View File

@ -43,15 +43,12 @@
}
}
function change_password($old_passwd, $new_passwd, $_account_id="")
function change_password($old_passwd, $new_passwd, $_accountid="")
{
global $phpgw_info, $phpgw;
$encrypted_passwd = md5($new_passwd);
if ("" == $_account_id)
{
$_account_id = $phpgw_info["user"]["account_id"];
}
$_account_id = get_account_id($_accountid);
$phpgw->db->query("update phpgw_accounts set account_pwd='" . md5($new_passwd) . "' "
. "where account_id='" . $_account_id . "'",__LINE__,__FILE__);

View File

@ -126,14 +126,11 @@
return $cats;
}
function categories($account_id = '',$app_name = '')
function categories($accountid = '',$app_name = '')
{
global $phpgw, $phpgw_info;
if (! $account_id)
{
$account_id = $phpgw_info['user']['account_id'];
}
$account_id = get_account_id($accountid);
if (! $app_name)
{

View File

@ -329,12 +329,13 @@
@abstract grab the owner name
@param $id account id
*/
function grab_owner_name($id)
function grab_owner_name($accountid = '')
{
global $phpgw;
$account_id = get_account_id($accountid);
$db = $phpgw->db;
$db->query('select account_lid,account_firstname,account_lastname from phpgw_accounts where account_id='.$id,__LINE__,__FILE__);
$db->query('select account_lid,account_firstname,account_lastname from phpgw_accounts where account_id='.$account_id,__LINE__,__FILE__);
$db->next_record();
return $phpgw->common->display_fullname($db->f('account_lid'),$db->f('account_firstname'),$db->f('account_lastname'));
@ -995,14 +996,11 @@
@param $prefs
@param $account_id -optional defaults to : phpgw_info['user']['account_id']
*/
function create_emailpreferences($prefs,$account_id=0)
function create_emailpreferences($prefs,$accountid='')
{
global $phpgw, $phpgw_info;
if($account_id==0)
{
$account_id = $phpgw_info['user']['account_id'];
}
$account_id = get_account_id($accountid);
/* Add default preferences info */
if (!isset($prefs['email']['userid']))

View File

@ -46,11 +46,11 @@
@abstract Standard constructor for setting $this->account_id
@discussion Author:
*/
function preferences($account_id = False)
function preferences($account_id = '')
{
global $phpgw, $phpgw_info;
$this->db = $phpgw->db;
if ($account_id != False){ $this->account_id = $account_id; }
$this->account_id = get_account_id($account_id);
}
/**************************************************************************\

View File

@ -388,3 +388,37 @@
}
}
error_reporting(7);
function get_account_id($account_id = '',$default_id = '')
{
global $phpgw, $phpgw_info;
if (gettype($account_id) == 'integer')
{
return $account_id;
}
elseif ($account_id == '')
{
if ($default_id == '')
{
return $phpgw_info['user']['account_id'];
}
elseif (gettype($default_id) == 'string')
{
return $phpgw->accounts->name2id($default_id);
}
return intval($default_id);
}
elseif (gettype($account_id) == 'string')
{
if($phpgw->accounts->exists(intval($account_id)) == True)
{
return intval($account_id);
}
else
{
return $phpgw->accounts->name2id($account_id);
}
}
}