added email-address to the accounts-data (ldap untested so far!)

This commit is contained in:
Ralf Becker 2004-07-04 17:27:42 +00:00
parent 7fbc1c9248
commit 8bfb6cfb07
7 changed files with 150 additions and 110 deletions

View File

@ -203,7 +203,7 @@
//echo "<p>accounts::search(".print_r($param,True).")</p>\n";
$this->setup_cache();
$account_search = &$this->cache['account_search'];
$serial = serialize($param);
if (isset($account_search[$serial]))
@ -218,9 +218,9 @@
else
{
$serial2 = $serial;
if (is_numeric($param['type']) || $param[$app] || $param['type'] == 'owngroups') // do we need to limit the search on a group or app?
if (is_numeric($param['type']) || $param['app'] || $param['type'] == 'owngroups') // do we need to limit the search on a group or app?
{
$app = $param[$app];
$app = $param['app'];
unset($param['app']);
if (is_numeric($param['type']))
{
@ -239,7 +239,7 @@
if (!isset($account_search[$serial2])) // check if we already did this general search
{
$account_search[$serial2]['data'] = array();
$accounts = accounts_::get_list($param['type'],'',$param['sort'],$param['order'],$param['query'],'',$param['query_type']);
$accounts = accounts_::get_list($param['type'],$param['start'],$param['sort'],$param['order'],$param['query'],$param['offset'],$param['query_type']);
if (!$accounts) $accounts = array();
foreach($accounts as $data)
{
@ -290,7 +290,7 @@
$account_search[$serial]['total'] = $this->total;
}
}
//echo "<p>accounts::search(...)=<pre>".print_r($account_search[$serial]['data'],True).")</pre>\n";
//echo "<p>accounts::search('$serial')=<pre>".print_r($account_search[$serial]['data'],True).")</pre>\n";
return $account_search[$serial]['data'];
}
@ -598,25 +598,25 @@
);
}
function name2id($account_lid)
function name2id($name,$which='account_lid')
{
$this->setup_cache();
$name_list = &$this->cache['name_list'];
if(@isset($name_list[$account_lid]) && $name_list[$account_lid])
if(@isset($name_list[$which][$name]) && $name_list[$which][$name])
{
return $name_list[$account_lid];
return $name_list[$which][$name];
}
/* Don't bother searching for empty account_lid */
if(empty($account_lid))
if(empty($name))
{
return False;
}
return $name_list[$account_lid] = accounts_::name2id($account_lid);
return $name_list[$which][$name] = accounts_::name2id($name,$which);
}
function id2name($account_id)
function id2name($account_id,$which='account_lid')
{
$this->setup_cache();
$id_list = &$this->cache['id_list'];
@ -626,11 +626,11 @@
return False;
}
if($id_list[$account_id])
if($id_list[$account_id][$which])
{
return $id_list[$account_id];
return $id_list[$account_id][$which];
}
return $id_list[$account_id] = accounts_::id2name($account_id);
return $id_list[$account_id][$which] = accounts_::id2name($account_id,$which);
}
function get_type($accountid)

View File

@ -79,7 +79,7 @@
$this->data['lastname'] = $GLOBALS['phpgw']->translation->convert($allValues[0]['sn'][0],'utf-8');
if(isset($allValues[0]['mail'][0]))
{
$this->data['mailaddress'] = $allValues[0]['mail'][0];
$this->data['email'] = $allValues[0]['mail'][0];
}
}
$this->data['account_dn'] = $allValues[0]['dn'];
@ -184,6 +184,10 @@
{
$newData['phpgwaccountexpires'] = $this->data['expires'];
}
if($this->data['email'])
{
$newData['mail'] = $this->data['email'];
}
$newAccountID = $newData['uid'];
$oldAccountID = $newData['uid'];
@ -259,7 +263,7 @@
for($i=0;$i<count($members);$i++)
{
$currname = $this->id2name($members[$i]['account_id']);
if(!$this->isin_array($currname,$entry['memberuid']))
if(!in_array($currname,$entry['memberuid']))
{
$newData['memberuid'][] = $currname;
}
@ -290,7 +294,7 @@
for($i=0;$i<count($members);$i++)
{
$currname = $this->id2name($members[$i]['account_id']);
if(!$this->isin_array($currname,$newData['memberuid']))
if(!in_array($currname,$newData['memberuid']))
{
$newData['memberuid'][] = $currname;
}
@ -392,16 +396,6 @@
}
}
function isin_array($needle,$haystack='')
{
if(!@is_array($haystack))
{
return False;
}
for($i=0;$i<count($haystack) && $haystack[$i] !=$needle;$i++);
return ($i!=count($haystack));
}
function delete($accountid = '')
{
$account_id = get_account_id($accountid);
@ -502,7 +496,7 @@
'firstname' => 'sn',
'lastname' => 'givenname',
'lid' => 'uid',
'email' => 'email',
'email' => 'mail',
);
$filter .= '('.$to_ldap[$query_type].'=*'.$query.'*)';
break;
@ -524,7 +518,8 @@
'account_type' => $allVals['phpgwaccounttype'][0],
'account_firstname' => $GLOBALS['phpgw']->translation->convert($allVals['givenname'][0],'utf-8'),
'account_lastname' => $GLOBALS['phpgw']->translation->convert($allVals['sn'][0],'utf-8'),
'account_status' => $allVals['phpgwaccountstatus'][0]
'account_status' => $allVals['phpgwaccountstatus'][0],
'account_email' => $allVals['mail'][0],
);
}
}
@ -553,7 +548,8 @@
'account_type' => $allVals['phpgwaccounttype'][0],
'account_firstname' => $GLOBALS['phpgw']->translation->convert($allVals['givenname'][0],'utf-8'),
'account_lastname' => $GLOBALS['phpgw']->translation->convert($allVals['sn'][0],'utf-8'),
'account_status' => $allVals['phpgwaccountstatus'][0]
'account_status' => $allVals['phpgwaccountstatus'][0],
'account_email' => $allVals['mail'][0],
);
}
}
@ -566,7 +562,7 @@
}
else
{
$filter = "(&(gidnumber=*)(phpgwaccounttype=*)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))";
$filter = "(&(gidnumber=*)(phpgwaccounttype=*)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)(mail=*$query*)))";
}
$sri = ldap_search($this->ds, $this->group_context, $filter);
$allValues = ldap_get_entries($this->ds, $sri);
@ -591,7 +587,8 @@
'account_type' => $allVals['phpgwaccounttype'][0],
'account_firstname' => $allVals['givenname'][0],
'account_lastname' => $allVals['sn'][0],
'account_status' => $allVals['phpgwaccountstatus'][0]
'account_status' => $allVals['phpgwaccountstatus'][0],
'account_email' => $allVals['mail'][0],
);
}
}
@ -627,7 +624,7 @@
return False;
}
function name2id($account_lid)
function name2id($name,$which='account_lid')
{
$sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . (string)$account_lid . ')(phpgwaccounttype=g))');
$allValues = ldap_get_entries($this->ds, $sri);
@ -637,7 +634,13 @@
return (int)$allValues[0]['gidnumber'][0];
}
$sri = ldap_search($this->ds, $this->user_context, '(&(uid=' . (string)$account_lid . ')(phpgwaccounttype=u))');
$to_ldap = array(
'account_lid' => 'uid',
'account_email' => 'mail',
);
if (!isset($to_ldap[$which])) return False;
$sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . (string)$name . ')(phpgwaccounttype=u))');
$allValues = ldap_get_entries($this->ds, $sri);
@ -649,7 +652,7 @@
return False;
}
function id2name($account_id)
function id2name($account_id,$which='account_lid')
{
$allValues = array();
$sri = ldap_search($this->ds, $this->group_context, '(&(gidnumber=' . (int)$account_id . ')(phpgwaccounttype=g))');
@ -660,13 +663,22 @@
return $allValues[0]['cn'][0];
}
$to_ldap = array(
'account_lid' => 'uid',
'account_email' => 'mail',
'account_firstname' => 'surname',
'account_lastname' => 'cn',
'account_type' => 'phpgwaccounttype',
);
if (!isset($to_ldap[$which])) return False;
$allValues = array();
$sri = ldap_search($this->ds, $this->user_context, '(&(uidnumber=' . (int)$account_id . ')(phpgwaccounttype=u))');
$allValues = ldap_get_entries($this->ds, $sri);
if (@$allValues[0]['uid'][0])
if (@$allValues[0][$to_ldap[$which]][0])
{
return $allValues[0]['uid'][0];
return $allValues[0][$to_ldap[$which]][0];
}
return False;
}
@ -890,6 +902,14 @@
'utf-8'
);
}
if($account_info['account_email'])
{
$entry['mail'] = $GLOBALS['phpgw']->translation->convert(
$account_info['account_email'],
$GLOBALS['phpgw']->translation->charset(),
'utf-8'
);
}
$entry['uid'] = $account_info['account_lid'];
$entry['uidnumber'] = $account_id;
$entry['gidnumber'] = $account_info['account_primary_group'];

View File

@ -38,9 +38,11 @@
function accounts_()
{
copyobj($GLOBALS['phpgw']->db,$this->db);
unset($this->query_types['email']);
//copyobj($GLOBALS['phpgw']->db,$this->db);
$this->db = is_object($GLOBALS['phpgw']->db) ? $GLOBALS['phpgw']->db : $GLOBALS['phpgw_setup']->db;
$this->table = 'phpgw_accounts';
$this->db->set_app('phpgwapi'); // to load the right table-definitions for insert, select, update, ...
}
function list_methods($_type='xmlrpc')
@ -82,7 +84,7 @@
*/
function read_repository()
{
$this->db->query('SELECT * FROM phpgw_accounts WHERE account_id=' . (int)$this->account_id,__LINE__,__FILE__);
$this->db->select($this->table,'*',array('account_id'=>$this->account_id),__LINE__,__FILE__);
$this->db->next_record();
$this->data['userid'] = $this->db->f('account_lid');
@ -98,6 +100,7 @@
$this->data['expires'] = $this->db->f('account_expires');
$this->data['person_id'] = $this->db->f('person_id');
$this->data['account_primary_group'] = $this->db->f('account_primary_group');
$this->data['email'] = $this->db->f('account_email');
return $this->data;
}
@ -108,15 +111,18 @@
*/
function save_repository()
{
$this->db->query('UPDATE phpgw_accounts SET'
. " account_firstname='" . $this->db->db_addslashes($this->data['firstname'])
. "', account_lastname='" . $this->db->db_addslashes($this->data['lastname'])
. "', account_status='". $this->db->db_addslashes($this->data['status'])
. "', account_expires=" . (int)$this->data['expires']
. ($this->data['account_lid']?", account_lid='".$this->db->db_addslashes($this->data['account_lid'])."'":'')
. ', person_id='.(int)$this->data['person_id']
. ', account_primary_group='.(int)$this->data['account_primary_group']
. ' WHERE account_id=' . (int)$this->account_id,__LINE__,__FILE__);
$this->db->update($this->table,array(
'account_firstname' => $this->data['firstname'],
'account_lastname' => $this->data['lastname'],
'account_status' => $this->data['status'],
'account_expires' => $this->data['expires'],
'account_lid' => $this->data['account_lid'],
'person_id' => $this->data['person_id'],
'account_primary_group' => $this->data['account_primary_group'],
'account_email' => $this->data['email'],
),array(
'account_id' => $this->account_id
),__LINE__,__FILE__);
}
function delete($accountid = '')
@ -124,9 +130,8 @@
$account_id = get_account_id($accountid);
/* Do this last since we are depending upon this record to get the account_lid above */
$tables_array = Array('phpgw_accounts');
$this->db->lock($tables_array);
$this->db->query('DELETE FROM phpgw_accounts WHERE account_id=' . (int)$account_id,__LINE__,__FILE__);
$this->db->lock(Array($this->table));
$this->db->delete($this->table,array('account_id'=>$account_id),__LINE__,__FILE__);
$this->db->unlock();
}
@ -184,18 +189,19 @@
case 'firstname':
case 'lastname':
case 'lid':
case 'email':
$query = $this->db->quote('%'.$query.'%');
$whereclause .= " account_$query_type LIKE $query )";
break;
}
}
$sql = "SELECT * FROM phpgw_accounts $whereclause $orderclause";
$sql = "SELECT * FROM $this->table $whereclause $orderclause";
if ($offset)
{
$this->db->limit_query($sql,$start,__LINE__,__FILE__,$offset);
}
elseif ($start !== '')
elseif (is_numeric($start))
{
$this->db->limit_query($sql,$start,__LINE__,__FILE__);
}
@ -214,61 +220,60 @@
'account_status' => $this->db->f('account_status'),
'account_expires' => $this->db->f('account_expires'),
'person_id' => $this->db->f('person_id'),
'account_primary_group' => $this->db->f('account_primary_group')
'account_primary_group' => $this->db->f('account_primary_group'),
'account_email' => $this->db->f('account_email'),
);
}
$this->db->query("SELECT count(*) FROM phpgw_accounts $whereclause");
$this->db->query("SELECT count(*) FROM $this->table $whereclause");
$this->db->next_record();
$this->total = $this->db->f(0);
return $accounts;
}
function name2id($account_lid)
/**
* converts a name / unique value from the accounts-table (account_lid,account_email) to an id
*/
function name2id($name,$which='account_lid')
{
$this->db->query("SELECT account_id FROM phpgw_accounts WHERE account_lid='".$this->db->db_addslashes($account_lid)."'",__LINE__,__FILE__);
if($this->db->num_rows())
$this->db->select($this->table,'account_id',array($which=>$name),__LINE__,__FILE__);
if($this->db->next_record())
{
$this->db->next_record();
return (int)$this->db->f('account_id');
}
return False;
}
function id2name($account_id)
/**
* converts an id to the corresponding value of the accounts-table (account_lid,account_email,account_firstname,...)
*/
function id2name($account_id,$which='account_lid')
{
$this->db->query('SELECT account_lid FROM phpgw_accounts WHERE account_id=' . (int)$account_id,__LINE__,__FILE__);
if($this->db->num_rows())
$this->db->select($this->table,$this->db->name_quote($which),array('account_id'=>$account_id),__LINE__,__FILE__);
if($this->db->next_record())
{
$this->db->next_record();
return $this->db->f('account_lid');
return $this->db->f(0);
}
return False;
}
function get_type($account_id)
{
$this->db->query('SELECT account_type FROM phpgw_accounts WHERE account_id=' . (int)$account_id,__LINE__,__FILE__);
if ($this->db->num_rows())
{
$this->db->next_record();
return $this->db->f('account_type');
}
return False;
return $this->id2name($account_id,'account_type');
}
function exists($account_lid)
{
static $by_id, $by_lid;
$sql = 'SELECT count(account_id) FROM phpgw_accounts WHERE ';
$where = array();
if(is_numeric($account_lid))
{
if(@isset($by_id[$account_lid]) && $by_id[$account_lid] != '')
{
return $by_id[$account_lid];
}
$sql .= 'account_id=' . $account_lid;
$where['account_id'] = $account_lid;
}
else
{
@ -276,10 +281,10 @@
{
return $by_lid[$account_lid];
}
$sql .= "account_lid = '".$this->db->db_addslashes($account_lid)."'";
$where['account_lid'] = $account_lid;
}
$this->db->query($sql,__LINE__,__FILE__);
$this->db->select($this->table,'count(*)',$where,__LINE__,__FILE__);
$this->db->next_record();
$ret_val = $this->db->f(0) > 0;
if(is_numeric($account_lid))
@ -302,24 +307,9 @@
// account_id already used => discard it
unset($account_info['account_id']);
}
$this->db->query('INSERT INTO phpgw_accounts ('.(isset($account_info['account_id'])?'account_id,':'')
. 'account_lid,account_type,account_pwd,'
. 'account_firstname,account_lastname,account_status,account_expires,person_id,'
. 'account_primary_group) VALUES ('
. (isset($account_info['account_id'])?(int)$account_info['account_id'].',':'')
. "'" . $this->db->db_addslashes($account_info['account_lid'])
. "','" . $this->db->db_addslashes($account_info['account_type'])
. "','" . $GLOBALS['phpgw']->common->encrypt_password($account_info['account_passwd'], True)
. "', '" . $this->db->db_addslashes($account_info['account_firstname'])
. "','" . $this->db->db_addslashes($account_info['account_lastname'])
. "','" . $this->db->db_addslashes($account_info['account_status'])
. "'," . (int)$account_info['account_expires']
. ',' . (int)$account_info['person_id']
. ',' . (int)$account_info['account_primary_group'] . ')',__LINE__,__FILE__);
$this->db->insert($this->table,$account_info,False,__LINE__,__FILE__);
$accountid = $this->db->get_last_insert_id('phpgw_accounts','account_id');
return $accountid;
return $this->db->get_last_insert_id($this->table,'account_id');
}
function auto_add($accountname, $passwd, $default_prefs = False, $default_acls = False, $expiredate = 0, $account_status = 'A')
@ -363,6 +353,7 @@
'account_status' => $account_status,
'account_expires' => $expires,
'account_primary_group' => $primary_group,
'account_email' => $GLOBALS['auto_create_acct']['email'],
);
$this->db->transaction_begin();
@ -420,6 +411,7 @@
$GLOBALS['hook_values']['account_status'] = $acct_info['account_status'];
$GLOBALS['hook_values']['account_firstname'] = $acct_info['account_lid'];
$GLOBALS['hook_values']['account_lastname'] = 'eGW Account';
$GLOBALS['hook_values']['account_email'] = $acct_info['account_passwd'];
$GLOBALS['phpgw']->hooks->process($GLOBALS['hook_values']+array(
'location' => 'addaccount'
),False,True); // called for every app now, not only enabled ones
@ -429,15 +421,14 @@
function get_account_name($accountid,&$lid,&$fname,&$lname)
{
$db = $GLOBALS['phpgw']->db;
$db->query('SELECT account_lid,account_firstname,account_lastname FROM phpgw_accounts WHERE account_id=' . (int)$accountid,__LINE__,__FILE__);
if (!$db->next_record())
$this->db->select($this->table,'account_lid,account_firstname,account_lastname',array('account_id'=>$accountid),__LINE__,__FILE__);
if (!$this->db->next_record())
{
return False;
}
$lid = $db->f('account_lid');
$fname = $db->f('account_firstname');
$lname = $db->f('account_lastname');
$lid = $this->db->f('account_lid');
$fname = $this->db->f('account_firstname');
$lname = $this->db->f('account_lastname');
return True;
}

View File

@ -806,6 +806,11 @@
{
return $this->data['email']['address'];
}
// if email-address is set in the account, return it
if ($email = $GLOBALS['phpgw']->accounts->id2name($account_id,'account_email'))
{
return $email;
}
$prefs_email_address = $GLOBALS['phpgw']->accounts->id2name($account_id);
if (strstr($prefs_email_address,'@') === False)
{

View File

@ -14,7 +14,7 @@
/* Basic information about this app */
$setup_info['phpgwapi']['name'] = 'phpgwapi';
$setup_info['phpgwapi']['title'] = 'phpgwapi';
$setup_info['phpgwapi']['version'] = '1.0.0';
$setup_info['phpgwapi']['version'] = '1.0.0.000';
$setup_info['phpgwapi']['versions']['current_header'] = '1.27';
$setup_info['phpgwapi']['enable'] = 3;
$setup_info['phpgwapi']['app_order'] = 1;
@ -54,3 +54,4 @@

View File

@ -64,7 +64,8 @@
'account_expires' => array('type' => 'int','precision' => '4'),
'account_type' => array('type' => 'char','precision' => '1'),
'person_id' => array('type' => 'int','precision' => '4'),
'account_primary_group' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0')
'account_primary_group' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
'account_email' => array('type' => 'varchar','precision' => '100')
),
'pk' => array('account_id'),
'fk' => array(),

View File

@ -1268,14 +1268,6 @@
$test[] = '0.9.99.024';
function phpgwapi_upgrade0_9_99_024()
{
/*
$sql = "SELECT ae1.contact_id,ae1.contact_name,ae1.contact_value,ae2.contact_value FROM phpgw_addressbook_extra ae1 LEFT JOIN phpgw_addressbook_extra ae2 ON ae1.contact_id==ae2.contact_id AND ae1.contact_name == ae2.contact_name WHERE ae1.contact_value != ae2.contact_vaue";
$GLOBALS['phpgw_setup']->oProc->query($sql,__LINE__,__FILE__);
while ($GLOBALS['phpgw_setup']->oProc->next_record())
{
}
*/
$GLOBALS['phpgw_setup']->oProc->RefreshTable('phpgw_addressbook_extra',array(
'fd' => array(
'contact_id' => array('type' => 'int','precision' => '4','nullable' => False),
@ -1378,4 +1370,34 @@
$GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.0';
return $GLOBALS['setup_info']['calendar']['currentver'];
}
$test[] = '1.0.0';
function phpgwapi_upgrade1_0_0()
{
$GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_accounts','account_email',array(
'type' => 'varchar',
'precision' => '100'
));
$GLOBALS['phpgw_setup']->oProc->query("SELECT config_value FROM phpgw_config WHERE config_app='phpgwapi' AND config_name='mail_suffix'",__LINE__,__FILE__);
$mail_domain = $GLOBALS['phpgw_setup']->oProc->next_record() ? $GLOBALS['phpgw_setup']->oProc->f(0) : '';
// copy the email-addresses from the preferences of the mail-app (if set) to the new field
$db2 = $GLOBALS['phpgw_setup']->oProc->m_odb;
$sql = "SELECT account_id,account_lid,preference_value FROM phpgw_accounts LEFT JOIN phpgw_preferences ON account_id=preference_owner AND preference_app='email' WHERE account_type = 'u'";
$GLOBALS['phpgw_setup']->oProc->query($sql,__LINE__,__FILE__);
while ($GLOBALS['phpgw_setup']->oProc->next_record())
{
$email_prefs = unserialize($GLOBALS['phpgw_setup']->oProc->f('preference_value'));
$account_lid = $GLOBALS['phpgw_setup']->oProc->f('account_lid');
$db2->update('phpgw_accounts',array(
'account_email' => $email_prefs['address'] ? $email_prefs['address'] : $account_lid.(strstr($account_lid,'@')===False?'@'.$mail_domain:''),
),array(
'account_id' => $GLOBALS['phpgw_setup']->oProc->f('account_id')
),__LINE__,__FILE__);
}
$GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.0.000';
return $GLOBALS['setup_info']['phpgwapi']['currentver'];
}
?>