$query=$this->db->query("SELECT username FROM ".TABLE_USER.", ".TABLE_EMAIL." WHERE ".TABLE_USER.".uid=".TABLE_EMAIL.".uid AND email=?",array($email));
$query=$this->db->query("SELECT gid FROM ".TABLE_EMAIL_LIST." WHERE uid=?",array((int)$uid));
if(isset($query->rows)){
foreach($query->rowsas$q){
if(is_numeric($q['gid'])&&$q['gid']>0){
$uids.=",".$q['gid'];
}
}
}
$query=$this->db->query("SELECT email FROM ".TABLE_EMAIL." WHERE uid IN ($uids)");
foreach($query->rowsas$q){
array_push($data,$q['email']);
}
}
return$data;
}
publicfunctionget_additional_uids($uid=0){
$data=array();
if($uid>0){
$query=$this->db->query("SELECT gid FROM ".TABLE_EMAIL_LIST." WHERE uid=?",array((int)$uid));
if(isset($query->rows)){
foreach($query->rowsas$q){
array_push($data,$q['gid']);
}
}
}
return$data;
}
publicfunctiongetEmailAddress($username=''){
$query=$this->db->query("SELECT ".TABLE_EMAIL.".email AS email FROM ".TABLE_EMAIL.",".TABLE_USER." WHERE ".TABLE_EMAIL.".uid=".TABLE_USER.".uid AND ".TABLE_USER.".username=? LIMIT 1",array($username));
if(isset($query->row['email'])){
return$query->row['email'];
}
return"";
}
publicfunctiongetEmails($username=''){
$emails="";
$query=$this->db->query("SELECT ".TABLE_EMAIL.".email AS email FROM ".TABLE_EMAIL.",".TABLE_USER." WHERE ".TABLE_EMAIL.".uid=".TABLE_USER.".uid AND ".TABLE_USER.".username=?",array($username));
foreach($query->rowsas$q){
$emails.=$q['email']."\n";
}
returnpreg_replace("/\n$/","",$emails);
}
publicfunctiongetEmailsByUid($uid=0){
$emails="";
$query=$this->db->query("SELECT email FROM ".TABLE_EMAIL." WHERE uid=?",array((int)$uid));
foreach($query->rowsas$q){
$emails.=$q['email']."\n";
}
returnpreg_replace("/\n$/","",$emails);
}
publicfunctiongetUserByDN($dn=''){
if($dn==''){returnarray();}
$query=$this->db->query("SELECT * FROM ".TABLE_USER." WHERE dn=?",array($dn));
if($query->num_rows==1){
return$query->row;
}
returnarray();
}
publicfunctiongetUserByUid($uid=0){
if(!is_numeric($uid)||(int)$uid<0){
returnarray();
}
$query=$this->db->query("SELECT * FROM ".TABLE_USER." WHERE uid=?",array((int)$uid));
return$query->row;
}
publicfunctiongetUserByEmail($email=''){
if($email==''){
returnarray();
}
$query=$this->db->query("SELECT * FROM ".TABLE_USER.",".TABLE_EMAIL." WHERE ".TABLE_USER.".uid=".TABLE_EMAIL.".uid AND email=?",array($email));
return$query->row;
}
publicfunctiongetUsernameByEmail($email=''){
$username="";
if($email==''){return$username;}
$query=$this->db->query("SELECT username FROM ".TABLE_USER." WHERE uid IN (SELECT uid FROM ".TABLE_EMAIL." WHERE email=?)",array($email));
$query=$this->db->query("SELECT ".TABLE_USER.".uid, isadmin, username, realname, domain, email FROM ".TABLE_USER.",".TABLE_EMAIL."$where_cond group by ".TABLE_USER.".uid $_order$limit");
$query=$this->db->query("UPDATE ".TABLE_USER." SET password=? WHERE uid=?",array(crypt($user['password']),(int)$user['uid']));
if($this->db->countAffected()!=1){return0;}
}
$query=$this->db->query("UPDATE ".TABLE_USER." SET username=?, realname=?, domain=?, dn=?, isadmin=? WHERE uid=?",array($user['username'],$user['realname'],$user['domain'],@$user['dn'],$user['isadmin'],(int)$user['uid']));
/* first, remove all his email addresses */
$query=$this->db->query("DELETE FROM ".TABLE_EMAIL." WHERE uid=?",array((int)$user['uid']));
/* then add all the emails we have from the CGI post input */
foreach($emailsas$email){
$email=rtrim($email);
$query=$this->db->query("INSERT INTO ".TABLE_EMAIL." (uid, email) VALUES(?,?)",array((int)$user['uid'],$email));