From b9da94fd2e1ca22c37489b79e968f785a9bd5e83 Mon Sep 17 00:00:00 2001 From: skeeter Date: Mon, 19 Mar 2001 20:25:04 +0000 Subject: [PATCH] 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 --- phpgwapi/inc/class.accounts_ldap.inc.php | 17 +++++----- phpgwapi/inc/class.accounts_shared.inc.php | 36 ++++++++-------------- phpgwapi/inc/class.accounts_sql.inc.php | 20 ++++++------ phpgwapi/inc/class.acl.inc.php | 26 ++++++++-------- phpgwapi/inc/class.applications.inc.php | 4 +-- phpgwapi/inc/class.auth_sql.inc.php | 7 ++--- phpgwapi/inc/class.categories.inc.php | 9 ++---- phpgwapi/inc/class.common.inc.php | 12 +++----- phpgwapi/inc/class.preferences.inc.php | 4 +-- phpgwapi/inc/functions.inc.php | 34 ++++++++++++++++++++ 10 files changed, 92 insertions(+), 77 deletions(-) diff --git a/phpgwapi/inc/class.accounts_ldap.inc.php b/phpgwapi/inc/class.accounts_ldap.inc.php index 4024974c44..d8e848d8ce 100644 --- a/phpgwapi/inc/class.accounts_ldap.inc.php +++ b/phpgwapi/inc/class.accounts_ldap.inc.php @@ -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"); diff --git a/phpgwapi/inc/class.accounts_shared.inc.php b/phpgwapi/inc/class.accounts_shared.inc.php index 3ffb56ff7e..af037e48bd 100644 --- a/phpgwapi/inc/class.accounts_shared.inc.php +++ b/phpgwapi/inc/class.accounts_shared.inc.php @@ -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) diff --git a/phpgwapi/inc/class.accounts_sql.inc.php b/phpgwapi/inc/class.accounts_sql.inc.php index 94f3000d1d..b9714ca425 100644 --- a/phpgwapi/inc/class.accounts_sql.inc.php +++ b/phpgwapi/inc/class.accounts_sql.inc.php @@ -31,15 +31,12 @@ var $db; var $account_id; var $data; - var $memberships; - var $members; - function accounts() - { - global $phpgw; - - $this->db = $phpgw->db; - } + function accounts_() + { + global $phpgw; + $this->db = $phpgw->db; + } function read_repository() { @@ -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; } diff --git a/phpgwapi/inc/class.acl.inc.php b/phpgwapi/inc/class.acl.inc.php index e2fc6768be..4628c25069 100644 --- a/phpgwapi/inc/class.acl.inc.php +++ b/phpgwapi/inc/class.acl.inc.php @@ -54,11 +54,11 @@ Example1: acl->acl(5); // 5 is the user id
@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 '; diff --git a/phpgwapi/inc/class.applications.inc.php b/phpgwapi/inc/class.applications.inc.php index e357e5197c..f5e4d028ad 100755 --- a/phpgwapi/inc/class.applications.inc.php +++ b/phpgwapi/inc/class.applications.inc.php @@ -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); } /**************************************************************************\ diff --git a/phpgwapi/inc/class.auth_sql.inc.php b/phpgwapi/inc/class.auth_sql.inc.php index c43e9ea269..08bd5e6e1d 100644 --- a/phpgwapi/inc/class.auth_sql.inc.php +++ b/phpgwapi/inc/class.auth_sql.inc.php @@ -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__); diff --git a/phpgwapi/inc/class.categories.inc.php b/phpgwapi/inc/class.categories.inc.php index da9bf32a24..ecc907ba4e 100644 --- a/phpgwapi/inc/class.categories.inc.php +++ b/phpgwapi/inc/class.categories.inc.php @@ -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) { @@ -227,4 +224,4 @@ } } } -?> \ No newline at end of file +?> diff --git a/phpgwapi/inc/class.common.inc.php b/phpgwapi/inc/class.common.inc.php index 43148076fd..58b4bb5793 100644 --- a/phpgwapi/inc/class.common.inc.php +++ b/phpgwapi/inc/class.common.inc.php @@ -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'])) diff --git a/phpgwapi/inc/class.preferences.inc.php b/phpgwapi/inc/class.preferences.inc.php index 6a3ae8d0cc..a0a7d001dd 100644 --- a/phpgwapi/inc/class.preferences.inc.php +++ b/phpgwapi/inc/class.preferences.inc.php @@ -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); } /**************************************************************************\ diff --git a/phpgwapi/inc/functions.inc.php b/phpgwapi/inc/functions.inc.php index ceacd02772..ca3c96bbf7 100644 --- a/phpgwapi/inc/functions.inc.php +++ b/phpgwapi/inc/functions.inc.php @@ -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); + } + } + } +