source: trunk/phpgwapi/inc/class.accounts_contacts.inc.php @ 7673

Revision 7673, 12.2 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare API - Accounts manager for the contacts class                 *
4  * This file written by Miles Lott <milosch@groupwhere.org>                 *
5  * View and manipulate account records using the contacts class             *
6  * Copyright (C) 2000, 2001 Miles Lott                                      *
7  * -------------------------------------------------------------------------*
8  * This library is part of the eGroupWare API                               *
9  * http://www.egroupware.org/api                                            *
10  * ------------------------------------------------------------------------ *
11  * This library is free software; you can redistribute it and/or modify it  *
12  * under the terms of the GNU Lesser General Public License as published by *
13  * the Free Software Foundation; either version 2.1 of the License,         *
14  * or any later version.                                                    *
15  * This library is distributed in the hope that it will be useful, but      *
16  * WITHOUT ANY WARRANTY; without even the implied warranty of               *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
18  * See the GNU Lesser General Public License for more details.              *
19  * You should have received a copy of the GNU Lesser General Public License *
20  * along with this library; if not, write to the Free Software Foundation,  *
21  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
22  \**************************************************************************/
23
24
25
26        /*
27        THIS NEEDS WORK!!!!!!!!! - Milosch
28        But it is a lot closer now...
29        */
30        $GLOBALS['phpgw_info']['server']['global_denied_users'] = array(
31                'root'     => True, 'bin'      => True, 'daemon'   => True,
32                'adm'      => True, 'lp'       => True, 'sync'     => True,
33                'shutdown' => True, 'halt'     => True, 'ldap'     => True,
34                'mail'     => True, 'news'     => True, 'uucp'     => True,
35                'operator' => True, 'games'    => True, 'gopher'   => True,
36                'nobody'   => True, 'xfs'      => True, 'pgsql'    => True,
37                'mysql'    => True, 'postgres' => True, 'oracle'   => True,
38                'ftp'      => True, 'gdm'      => True, 'named'    => True,
39                'alias'    => True, 'web'      => True, 'sweep'    => True,
40                'cvs'      => True, 'qmaild'   => True, 'qmaill'   => True,
41                'qmaillog' => True, 'qmailp'   => True, 'qmailq'   => True,
42                'qmailr'   => True, 'qmails'   => True, 'rpc'      => True,
43                'rpcuser'  => True, 'amanda'   => True, 'apache'   => True,
44                'pvm'      => True, 'squid'    => True, 'ident'    => True,
45                'nscd'     => True, 'mailnull' => True, 'cyrus'    => True,
46                'backup'   => True
47        );
48
49        $GLOBALS['phpgw_info']['server']['global_denied_groups'] = array(
50                'root'      => True, 'bin'       => True, 'daemon'    => True,
51                'sys'       => True, 'adm'       => True, 'tty'       => True,
52                'disk'      => True, 'lp'        => True, 'mem'       => True,
53                'kmem'      => True, 'wheel'     => True, 'mail'      => True,
54                'uucp'      => True, 'man'       => True, 'games'     => True,
55                'dip'       => True, 'ftp'       => True, 'nobody'    => True,
56                'floppy'    => True, 'xfs'       => True, 'console'   => True,
57                'utmp'      => True, 'pppusers'  => True, 'popusers'  => True,
58                'slipusers' => True, 'slocate'   => True, 'mysql'     => True,
59                'dnstools'  => True, 'web'       => True, 'named'     => True,
60                'dba'       => True, 'oinstall'  => True, 'oracle'    => True,
61                'gdm'       => True, 'sweep'     => True, 'cvs'       => True,
62                'postgres'  => True, 'qmail'     => True, 'nofiles'   => True,
63                'ldap'      => True, 'backup'    => True
64        );
65
66        class accounts_
67        {
68                var $db;
69                var $contacts;
70                var $account_id;
71                var $data;
72                var $debug = False;
73                var $qcols = array(
74                        'fn'                     => 'fn',
75                        'n_given'                => 'n_given',
76                        'n_family'               => 'n_family',
77                        'account_lastlogin'      => 'account_lastlogin',
78                        'account_lastloginfrom'  => 'account_lastloginfrom',
79                        'account_lastpwd_change' => 'account_lastpwd_change',
80                        'account_status'         => 'account_status',
81                        'account_expires'        => 'account_expires'
82                );
83
84                function accounts_()
85                {
86                        $this->db       = $GLOBALS['phpgw']->db;
87                        $this->contacts = CreateObject('phpgwapi.contacts',0);
88                }
89
90                function makeobj()
91                {
92                        if(!$this->contacts)
93                        {
94                                $this->contacts = CreateObject('phpgwapi.contacts','0');
95                        }
96                }
97
98                function read_repository()
99                {
100                        $this->makeobj();
101
102                        $allValues = $this->contacts->read_single_entry($this->account_id,$this->qcols);
103
104                        /* Now dump it into the array */
105                        $this->data['userid']            = $allValues[0]['lid'];
106                        $this->data['account_id']            = $allValues[0]['id'];
107                        $this->data['account_lid']           = $allValues[0]['lid'];
108                        $this->data['account_type']      = $allValues[0]['tid'];
109                        $this->data['firstname']             = $allValues[0]['n_given'];
110                        $this->data['lastname']              = $allValues[0]['n_family'];
111                        $this->data['fullname']              = $allValues[0]['fn'];
112                        $this->data['lastlogin']         = $allValues[0]['account_lastlogin'];
113                        $this->data['lastloginfrom']     = $allValues[0]['account_lastloginfrom'];
114                        $this->data['lastpasswd_change'] = $allValues[0]['account_lastpwd_change'];
115                        $this->data['status']            = $allValues[0]['account_status'];
116                        $this->data['expires']           = $allValues[0]['account_expires'];
117                        $this->data['agree_terms']       = $allValues[0]['phpgwagreeterm'][0];
118                        return $this->data;
119                }
120
121                function save_repository()
122                {
123                        $this->makeobj();
124
125                        $entry['id']                        = $this->data['account_id'];
126                        $entry['lid']                       = $this->data['account_lid'];
127                        $entry['tid']                       = $this->data['account_type'];
128                        $entry['fn']                        = sprintf("%s %s", $this->data['firstname'], $this->data['lastname']);
129                        $entry['n_family']                  = $this->data['lastname'];
130                        $entry['n_given']                   = $this->data['firstname'];
131                        $entry['account_lastlogin']         = $this->data['lastlogin'];
132                        $entry['account_lastloginfrom']     = $this->data['lastloginfrom'];
133                        $entry['account_lastpasswd_change'] = $this->data['lastpwd_change'];
134                        $entry['account_status']            = $this->data['status'];
135                        $entry['account_expires']           = $this->data['expires'];
136
137                        if($this->debug) { echo '<br>Updating entry:<br>' . var_dump($entry); }
138                        $this->contacts->update($entry['id'],0,$entry,'public','',$entry['tid']);
139                }
140
141                function add($account_name, $account_type, $first_name, $last_name, $passwd = False)
142                {
143                        $this->create($account_name, $account_type, $first_name, $last_name, $passwd);
144                }
145
146                function delete($accountid = '')
147                {
148                        $this->makeobj();
149
150                        if($this->debug) { echo '<br>Deleting entry:<br>' . $account_id; }
151                        $account_id = get_account_id($accountid);
152                        $this->contacts->delete($account_id);
153                }
154
155                function get_list($_type='both')
156                {
157                        $this->makeobj();
158
159                        switch($_type)
160                        {
161                                case 'accounts':
162                                        $filter = 'tid=u';
163                                        break;
164                                case 'groups':
165                                        $filter = 'tid=g';
166                                        break;
167                                default:
168                                        $filter = 'tid=u,tid=g';
169                        }
170
171                        $allValues = $this->contacts->read(0,0,$this->qcols,'',$filter);
172
173                        /* get user information for each user/group */
174            $allValues_count = count($allValues);
175                        for($i=0;$i<$allValues_count;++$i)
176                        {
177                                $accounts[] = Array(
178                                        'account_id'        => $allValues[$i]['id'],
179                                        'account_lid'       => $allValues[$i]['lid'],
180                                        'account_type'      => $allValues[$i]['tid'],
181                                        'account_firstname' => $allValues[$i]['n_given'],
182                                        'account_lastname'  => $allValues[$i]['n_family'],
183                                        'account_status'    => $allValues[$i]['account_status'],
184                                        'account_expires'   => $allValues[$i]['account_expires']
185                                );
186                        }
187
188                        return $accounts;
189                }
190
191                function name2id($account_lid)
192                {
193                        $qcols = array('id' => 'id');
194                        $this->makeobj();
195                        $allValues = $this->contacts->read(0,0,$qcols,'',"lid=".$account_lid);
196
197                        if($allValues[0]['id'])
198                        {
199                                return (int)$allValues[0]['id'];
200                        }
201                        else
202                        {
203                                return False;
204                        }
205                }
206
207                function id2name($account_id)
208                {
209                        $this->makeobj();
210
211                        $allValues = $this->contacts->read_single_entry($account_id);
212                        if($this->debug) { echo '<br>id2name: '.$allValues[0]['lid']; }
213
214                        if($allValues[0]['lid'])
215                        {
216                                return $allValues[0]['lid'];
217                        }
218                        else
219                        {
220                                return False;
221                        }
222                }
223
224                function get_type($accountid = '')
225                {
226                        $this->makeobj();
227                        $account_id = get_account_id($accountid);
228
229                        $allValues = $this->contacts->read_single_entry($account_id);
230
231                        if ($allValues[0]['tid'])
232                        {
233                                return $allValues[0]['tid'];
234                        }
235                        else
236                        {
237                                return False;
238                        }
239                }
240
241                function exists($account_lid)
242                {
243                        $this->makeobj();
244                        if(is_int($account_lid))
245                        {
246                                $account_id = $account_lid;
247                                settype($account_lid,'string');
248                                $account_lid = $this->id2name($account_id);
249                        }
250
251                        $allValues = $this->contacts->read(0,0,array('n_given' => 'n_given'),'','lid='.$account_lid);
252
253                        if ($allValues[0]['id'])
254                        {
255                                return True;
256                        }
257                        else
258                        {
259                                return False;
260                        }
261                }
262
263                function create($account_info)
264                {
265                        $this->makeobj();
266
267                        if (!$$account_info['account_id'])
268                        {
269                                $account_info['account_id'] = $this->get_nextid();
270                        }
271                        $owner = $GLOBALS['phpgw_info']['user']['account_id'];
272                        $entry['id']       = $account_info['account_id'];
273                        $entry['lid']      = $account_info['account_lid'];
274                        $entry['n_given']  = $account_info['account_firstname'];
275                        $entry['n_family'] = $account_info['account_lastname'];
276                        $entry['password'] = $account_info['account_passwd'];
277                        $entry['account_status']   = $account_info['account_status'];
278                        $entry['account_expires']  = $account_info['account_expires'];
279
280                        if($this->debug) { echo '<br>Adding entry:<br>' . var_dump($entry); }
281                        /* 'public' access, no category id, tid set to account_type */
282                        $this->contacts->add(0,$entry,'public','',$account_info['account_type']);
283                        return;
284                }
285
286                function auto_add($accountname, $passwd, $default_prefs = False, $default_acls = False, $expiredate = 0, $account_status = 'A')
287                {
288                        if (! $expiredate)
289                        {
290                                // expire in 30 days by default
291                                $expiredate = time() + ( ( 60 * 60 ) * (30 * 24) );
292                        }
293
294                        $acct_info = array(
295                                'account_lid'       => $accountname,
296                                'account_type'      => 'u',
297                                'account_passwd'    => $passwd,
298                                'account_firstname' => '',
299                                'account_lastname'  => '',
300                                'account_status'    => $account_status,
301                                'account_expires'   => mktime(2,0,0,date('n',$expiredate), (int)date('d',$expiredate), date('Y',$expiredate))
302                        );
303                        $this->create($acct_info);
304                        $accountid = $this->name2id($accountname);
305
306                        $this->db->transaction_begin();
307                        if (!$default_prefs)
308                        {
309                                $default_prefs = 'a:5:{s:6:"common";a:10:{s:9:"maxmatchs";s:2:"15";s:12:"template_set";s:8:"verdilak";s:5:"theme";s:6:"purple";s:13:"navbar_format";s:5:"icons";s:9:"tz_offset";N;s:10:"dateformat";s:5:"m/d/Y";s:10:"timeformat";s:2:"12";s:4:"lang";s:2:"en";s:11:"default_app";N;s:8:"currency";s:1:"$";}s:11:"addressbook";a:1:{s:0:"";s:4:"True";}:s:8:"calendar";a:4:{s:13:"workdaystarts";s:1:"7";s:11:"workdayends";s:2:"15";s:13:"weekdaystarts";s:6:"Monday";s:15:"defaultcalendar";s:9:"month.php";}}';
310//                              $defaultprefs = 'a:5:{s:6:"common";a:1:{s:0:"";s:2:"en";}s:11:"addressbook";a:1:{s:0:"";s:4:"True";}s:8:"calendar";a:1:{s:0:"";s:13:"workdaystarts";}i:15;a:1:{s:0:"";s:11:"workdayends";}s:6:"Monday";a:1:{s:0:"";s:13:"weekdaystarts";}}';
311                                $this->db->query("insert into phpgw_preferences (preference_owner, preference_value) values ('".$accountid."', '$default_prefs')",__LINE__,__FILE__);
312                        }
313
314                        if (!$default_acls)
315                        {
316                                $apps = Array(
317                                        'addressbook',
318                                        'calendar',
319                                        'email',
320                                        'notes',
321                                        'todo',
322                                        'phpwebhosting',
323                                        'manual'
324                                );
325
326                                $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_rights)values('preferences', 'changepassword', ".$accountid.", 1)",__LINE__,__FILE__);
327                                $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) values('phpgw_group', '1', ".$accountid.", 1)",__LINE__,__FILE__);
328                                @reset($apps);
329                                while(list($key,$app) = each($apps))
330                                {
331                                        $this->db->query("INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) VALUES ('".$app."', 'run', ".$accountid.", 1)",__LINE__,__FILE__);
332                                }
333                        }
334                        $this->db->transaction_commit();
335                        return $accountid;
336                }
337        }
Note: See TracBrowser for help on using the repository browser.