phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc/accounts/class.accounts_.inc.php, 1.1.2.


From: nomail
Subject: [Phpgroupware-cvs] phpgwapi/inc/accounts/class.accounts_.inc.php, 1.1.2.2
Date: Tue, 14 Dec 2004 21:11:00 +0100

Update of /phpgwapi/inc/accounts
Modified Files:
        Branch: proposed-0_9_18-branch
          class.accounts_.inc.php

date: 2004/12/14 20:11:00;  author: fipsfuchs;  state: Exp;  lines: +123 -4

Log Message:
moved common stuff from childs to parent
smarter rdn handling for ldap
=====================================================================
Index: phpgwapi/inc/accounts/class.accounts_.inc.php
diff -u phpgwapi/inc/accounts/class.accounts_.inc.php:1.1.2.1 
phpgwapi/inc/accounts/class.accounts_.inc.php:1.1.2.2
--- phpgwapi/inc/accounts/class.accounts_.inc.php:1.1.2.1       Fri Dec 10 
15:28:40 2004
+++ phpgwapi/inc/accounts/class.accounts_.inc.php       Tue Dec 14 20:11:00 2004
@@ -685,7 +685,11 @@
                
                function create($data, $default_prefs = true)
                {
-                       $this->set_data($data);
+                       if($data['account_id'] && 
is_object($GLOBALS['phpgw']->preferences) && $default_prefs)
+                       {
+                               
$GLOBALS['phpgw']->preferences->create_defaults($data['account_id']);
+                       }
+                       return $data['account_id'];
                }
                
                function set_data($data)
@@ -693,7 +697,7 @@
                        $this->account_id        = (int)$data['account_id']    
? (int)$data['account_id']   : $this->account_id;
                        $this->lid               = $data['account_lid']        
? $data['account_lid']       : $this->lid;
                        $this->firstname         = $data['account_firstname']  
? $data['account_firstname'] : $this->firstname;
-                       $this->lastname          = $data['account_lastname']   
? $data['account_lastname'] : $this->lastname;
+                       $this->lastname          = $data['account_lastname']   
? $data['account_lastname']  : $this->lastname;
                        $this->password          = $data['account_passwd']     
? $data['account_passwd']    : $this->password;
                        $data['account_status']  = !$data['account_status']    
? $data['status']            : $data['account_status'];
                        $this->status            = $data['account_status']     
? $data['account_status']    : $this->status;
@@ -701,6 +705,121 @@
                        $this->expires           = $data['account_expires']    
? $data['account_expires']   : $this->expires;
                        $this->person_id         = $data['person_id']          
? $data['person_id']         : $this->person_id;
                        return true;
-               }                       
+               }
+               
+               function get_account_data($account_id)
+               {
+                       $this->account_id = $account_id; // what is this good 
for? (get is not set)
+                       $this->read_repository();
+
+                       $data[$this->data['account_id']]['lid']       = 
$this->data['account_lid'];
+                       $data[$this->data['account_id']]['firstname'] = 
$this->data['firstname'];
+                       $data[$this->data['account_id']]['lastname']  = 
$this->data['lastname'];
+                       $data[$this->data['account_id']]['fullname']  = 
$this->data['fullname'];
+                       
+                       // type or account_type, this is the question
+                       $data[$this->data['account_id']]['type']      = 
strlen($this->data['account_type']) ? $this->data['account_type'] : 
$this->data['type'] ;
+                       $data[$this->data['account_id']]['person_id'] = 
$this->data['person_id'];
+                       return $data;
+               }
+
+               /**
+               * Create a non existing but authorized user 
+               *
+               * @param string $accountname User name
+               * @param string $passwd User password
+               * @param boolean $default_prefs Default preferences for this 
new user
+               * @param boolean $default_acls Acls (modules) for this new user
+               * @param integer $expiredate Expire date of this account. '-1' 
for never. Defaults to 'in 30 days'
+               * @param char $account_status Status for new user. 'A' for 
active user.
+               * @return integer Account id 
+               */
+               function auto_add($accountname, $passwd, $default_prefs = 
false, $default_acls = false, $expiredate = 0, $account_status = 'A')
+               {
+                       if ($expiredate)
+                       {
+                               $expires = mktime(2,0,0,date('n',$expiredate), 
intval(date('d',$expiredate)), date('Y',$expiredate));
+                       }
+                       else
+                       {
+                               
if($GLOBALS['phpgw_info']['server']['auto_create_expire'])
+                               {
+                                       
if($GLOBALS['phpgw_info']['server']['auto_create_expire'] == 'never')
+                                       {
+                                               $expires = -1;
+                                       }
+                                       else
+                                       {
+                                               $expiredate = time() + 
$GLOBALS['phpgw_info']['server']['auto_create_expire'];
+                                               $expires   = 
mktime(2,0,0,date('n',$expiredate), intval(date('d',$expiredate)), 
date('Y',$expiredate));
+                                       }
+                               }
+                               else
+                               {
+                                       /* expire in 30 days by default */
+                                       $expiredate = time() + ( ( 60 * 60 ) * 
(30 * 24) );
+                                       $expires   = 
mktime(2,0,0,date('n',$expiredate), intval(date('d',$expiredate)), 
date('Y',$expiredate));
+                               }
+                       }
+
+                       $acct_info = array(
+                               'account_lid'       => $accountname,
+                               'account_type'      => 'u',
+                               'account_passwd'    => $passwd,
+                               'account_firstname' => '',
+                               'account_lastname'  => '',
+                               'account_status'    => $account_status,
+                               'account_expires'   => $expires,
+                               'person_id'         => 'NULL'
+                       );
+
+                       $this->db->transaction_begin();
+                       $this->create($acct_info, $default_prefs);
+                       $accountid = $this->name2id($accountname); //slow - a 
create should set the new accountid
+
+                       // this should be done via the acl class not direct db 
calls
+                       if ($default_acls == false)
+                       {
+                               $default_group_lid = 
intval($GLOBALS['phpgw_info']['server']['default_group_lid']);
+                               $default_group_id  = 
$this->name2id($default_group_lid);
+                               $defaultgroupid = $default_group_id ? 
$default_group_id : $this->name2id('Default');
+                               if ($defaultgroupid)
+                               {
+                                       $this->db->query('INSERT INTO phpgw_acl 
(acl_appname, acl_location, acl_account, acl_rights)'
+                                               . "VALUES('phpgw_group', " . 
$defaultgroupid . ', ' 
+                                               .       intval($accountid) . ', 
1'
+                                               . ')',__LINE__,__FILE__);
+                                       $this->db->query('INSERT INTO phpgw_acl 
(acl_appname, acl_location, acl_account, acl_rights)'
+                                               . "VALUES('preferences' , 
'changepassword', " 
+                                               .       intval($accountid) . ', 
1'
+                                               . ')',__LINE__,__FILE__);
+                               }
+                               else
+                               {
+                                       // If they don't have a default group, 
they need some sort of permissions.
+                                       // This generally doesn't / shouldn't 
happen, but will (jengo)
+                                       $this->db->query("insert into phpgw_acl 
(acl_appname, acl_location, acl_account, acl_rights) values('preferences', 
'changepassword', " . $accountid . ', 1)',__LINE__,__FILE__);
+
+                                       $apps = Array(
+                                               'addressbook',
+                                               'calendar',
+                                               'email',
+                                               'notes',
+                                               'todo',
+                                               'phpwebhosting',
+                                               'manual'
+                                       );
+
+                                       @reset($apps);
+                                       while(list($key,$app) = each($apps))
+                                       {
+                                               $this->db->query("INSERT INTO 
phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) VALUES ('" . 
$app . "', 'run', " . intval($accountid) . ', 1)',__LINE__,__FILE__);
+                                       }
+                               }
+                       }
+                       $this->db->transaction_commit();
+                       return $accountid;
+               }
+               
        }
 ?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]