source: branches/2.0/phpgwapi/inc/class.accounts_ldap.inc.php @ 837

Revision 837, 40.0 KB checked in by niltonneto, 15 years ago (diff)

Ticket #493 - Corrigido problema ao editar o número do telefone em dados pessoais.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare API - Accounts manager for LDAP                               *
4        * Written by Joseph Engo <jengo@phpgroupware.org>                          *
5        *        and Lars Kneschke <lkneschke@phpgw.de>                            *
6        *        and Miles Lott <milos@groupwhere.org>                             *
7        *        and Bettina Gille <ceb@phpgroupware.org>                          *
8        * View and manipulate account records using LDAP                           *
9        * Copyright (C) 2000 - 2002 Joseph Engo, Lars Kneschke                     *
10        * Copyright (C) 2003 Lars Kneschke, Bettina Gille                          *
11        * ------------------------------------------------------------------------ *
12        * This library is part of the eGroupWare API                               *
13        * http://www.egroupware.org                                                *
14        * ------------------------------------------------------------------------ *
15        * This library is free software; you can redistribute it and/or modify it  *
16        * under the terms of the GNU Lesser General Public License as published by *
17        * the Free Software Foundation; either version 2.1 of the License,         *
18        * or any later version.                                                    *
19        * This library is distributed in the hope that it will be useful, but      *
20        * WITHOUT ANY WARRANTY; without even the implied warranty of               *
21        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
22        * See the GNU Lesser General Public License for more details.              *
23        * You should have received a copy of the GNU Lesser General Public License *
24        * along with this library; if not, write to the Free Software Foundation,  *
25        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
26        \**************************************************************************/
27
28        class accounts_
29        {
30                var $db;
31                var $ds;
32                var $account_id;
33                var $data;
34                var $user_context  = '';
35                var $group_context = '';
36                var $total;
37
38                function accounts_()
39                {
40                        $this->ds = $GLOBALS['phpgw']->common->ldapConnect();
41                        if(!$this->ds)
42                                $this->ds = $GLOBALS['phpgw']->common->ldapConnect();
43                        if(!@is_object($GLOBALS['phpgw']->translation))
44                        {
45                                $GLOBALS['phpgw']->translation = CreateObject('phpgwapi.translation');
46                        }
47                        $this->user_context  = $GLOBALS['phpgw_info']['server']['ldap_context'];
48                        $this->group_context = $GLOBALS['phpgw_info']['server']['ldap_group_context'];
49                }
50
51                function read_repository()
52                {
53                        $acct_type = $this->get_type($this->account_id);
54
55                        /* search the dn for the given uid */
56                        if(($acct_type == 'g') && $this->group_context)
57                        {
58                                /* jakjr: using justthese with ldap_search */
59                                $justthese = array("gidnumber", "cn");
60                                $sri = @ldap_search($this->ds, $this->group_context, ("(&(gidnumber=" . (int)$this->account_id.")(phpgwaccounttype=g))"), $justthese);
61                        }
62                        else
63                        {
64                                /* jakjr: using justthese with ldap_search */
65                                $justthese = array("uidnumber", "gidnumber", "uid", "cn", "givenname", "sn", "mail", "phpgwaccountstatus", "phpgwaccountexpires", "phpgwaccounttype", "phpgwlastpasswdchange","phpgwagreeterm","telephonenumber");
66                                $sri = @ldap_search($this->ds, $this->user_context, ("(&(uidnumber=" . (int)$this->account_id.")(phpgwaccounttype=u))"), $justthese);
67                        }
68                        if(!$sri)
69                                return null;
70                        $allValues = ldap_get_entries($this->ds, $sri);
71
72                        /* Now dump it into the array; take first entry found */
73                        if($acct_type =='g')
74                        {
75                                $this->data['account_id']   = $allValues[0]['gidnumber'][0];
76                                $this->data['account_lid']  = $allValues[0]['cn'][0];
77                                $this->data['firstname']    = $GLOBALS['phpgw']->translation->convert($allValues[0]['cn'][0],'utf-8');
78                                $this->data['lastname']     = lang('Group');
79                        }
80                        else
81                        {
82                                $this->data['account_id']  = $allValues[0]['uidnumber'][0];
83                                $this->data['account_primary_group'] = $allValues[0]['gidnumber'][0];
84                                $this->data['account_lid'] = $allValues[0]['uid'][0];
85                                $this->data['firstname']   = $GLOBALS['phpgw']->translation->convert($allValues[0]['givenname'][0],'utf-8');
86                                $this->data['lastname']    = $GLOBALS['phpgw']->translation->convert($allValues[0]['sn'][0],'utf-8');
87                                if(isset($allValues[0]['mail'][0]))
88                                {
89                                        $this->data['email'] = $allValues[0]['mail'][0];
90                                }
91                                $this->data['telephonenumber']   = $allValues[0]['telephonenumber'][0];
92                                /* jakjr: this is not used for expressoLivre */
93                                /*
94                                $this->data['lastlogin']         = $allValues[0]['phpgwaccountlastlogin'][0];
95                                $this->data['lastloginfrom']     = $allValues[0]['phpgwaccountlastloginfrom'][0];
96                                */
97                                $this->data['lastpasswd_change'] = @$allValues[0]['phpgwlastpasswdchange'][0];
98                                $this->data['status']            = trim($allValues[0]['phpgwaccountstatus'][0]);
99                                $this->data['expires']           = $allValues[0]['phpgwaccountexpires'][0];
100                                $this->data['type']              = $allValues[0]['phpgwaccounttype'][0];
101                                $this->data['agree_terms']   = $allValues[0]['phpgwagreeterm'][0];
102                        }
103                        $this->data['account_dn']  = $allValues[0]['dn'];
104                        $this->data['fullname']    = $GLOBALS['phpgw']->translation->convert($allValues[0]['cn'][0],'utf-8');
105
106                        /* jakjr: this is not used for expressoLivre */
107                        /*
108                        if ($GLOBALS['phpgw_info']['server']['ldap_extra_attributes'])
109                        {
110                                $this->data['homedirectory']  = $allValues[0]['homedirectory'][0];
111                                $this->data['loginshell'] = $allValues[0]['loginshell'][0];
112                        }
113                        */
114                        return $this->data;
115                }
116
117                function save_repository()
118                {
119                        #_debug_array($this->data);
120                        $acct_type = $this->get_type($this->account_id);
121
122                        /* search the dn for the given u/gidnumber */
123                        if(($acct_type == 'g') && $this->group_context)
124                        {
125                                $sri = ldap_search($this->ds, $this->group_context, ("(&(gidnumber=" . (int)$this->account_id.")(phpgwaccounttype=g))"));
126                        }
127                        else
128                        {
129                                $sri = ldap_search($this->ds, $this->user_context, ("(&(uidnumber=" . (int)$this->account_id.")(phpgwaccounttype=u))"));
130                        }
131                        $allValues = ldap_get_entries($this->ds, $sri);
132
133                        $this->data['account_type'] = $allValues[0]['phpgwaccounttype'][0];
134
135                        if($acct_type == 'u')
136                        {
137                                // data for posixaccount
138                                $newData['cn'] = $GLOBALS['phpgw']->translation->convert(sprintf("%s %s",
139                                        $this->data['firstname'],
140                                        $this->data['lastname']),$GLOBALS['phpgw']->translation->charset(),'utf-8'
141                                );
142                                $newData['uid'] = $GLOBALS['phpgw']->translation->convert(
143                                        $this->data['account_lid'],
144                                        $GLOBALS['phpgw']->translation->charset(),'utf-8'
145                                );
146                                if($this->data['lastname'])
147                                {
148                                        $newData['sn'] = $GLOBALS['phpgw']->translation->convert(
149                                                $this->data['lastname'],
150                                                $GLOBALS['phpgw']->translation->charset(),'utf-8'
151                                        );
152                                }
153
154                                if($this->data['firstname'])
155                                {
156                                        $newData['givenname'] = $GLOBALS['phpgw']->translation->convert(
157                                                $this->data['firstname'],
158                                                $GLOBALS['phpgw']->translation->charset(),'utf-8'
159                                        );
160                                }
161                                if ($GLOBALS['phpgw_info']['server']['ldap_extra_attributes'])
162                                {
163                                        $newData['homedirectory'] = $this->data['homedirectory'];
164                                        $newData['loginshell']    = $this->data['loginshell'];
165                                }
166                                else
167                                {
168                                        // the posixaccount schema requires this
169                                        $entry['homedirectory'] = '/home/'.$this->data['account_lid'];
170                                        $entry['loginshell']    = '/bin/false';
171                                }
172                                if($this->data['account_primary_group'])
173                                {
174                                        $newData['gidnumber'] = $this->data['account_primary_group'];
175                                }
176                                if($this->data['lastlogin'])
177                                {
178                                        $newData['phpgwaccountlastlogin'] = $this->data['lastlogin'];
179                                }
180                                if($this->data['lastloginfrom'])
181                                {
182                                        $newData['phpgwaccountlastloginfrom'] = $this->data['lastloginfrom'];
183                                }
184                                if($this->data['lastpasswd_change'])
185                                {
186                                        $newData['phpgwlastpasswdchange'] = $this->data['lastpasswd_change'];
187                                }
188                                if($this->data['status'])
189                                {
190                                        $newData['phpgwaccountstatus'] = $this->data['status'];
191                                }
192                                else
193                                {
194                                        $newData['phpgwaccountstatus'] = array();
195                                }
196                                if($this->data['expires'])
197                                {
198                                        $newData['phpgwaccountexpires'] = $this->data['expires'];
199                                }
200                                if($this->data['email'])
201                                {
202                                        $newData['mail'] = $this->data['email'];
203                                }
204
205                                $newAccountID = $newData['uid'];
206                                $oldAccountID = $newData['uid'];
207                        }
208                        else
209                        {
210                                // data for posixgroup
211                                $newData['cn'] = $GLOBALS['phpgw']->translation->convert(
212                                        $this->data['account_lid'],
213                                        $GLOBALS['phpgw']->translation->charset(), 'utf-8'
214                                );
215                                $newData['gidnumber'] = $this->account_id;
216                                $newGroupID = $newData['cn'];
217                                $oldGroupID = $newData['cn'];
218                        }
219                        if($this->data['type'])
220                        {
221                                $newData['phpgwaccounttype'] = $this->data['type'];
222                        }
223
224                        /*
225                        Changing the uid:  Need to delete and add new, since
226                        PHP cannot change the dn for the entry.
227                        */
228                        if ($acct_type == 'g')
229                        {
230                                $test = $allValues[0]['cn'][0];
231                        }
232                        else
233                        {
234                                $test = $allValues[0]['uid'][0];
235                        }
236                        if($GLOBALS['phpgw']->translation->convert($test,'utf-8') != $this->data['account_lid'])
237                        {
238                                $oldData = $allValues[0];
239                                $oldDN   = $oldData['dn'];
240                                // remove all unneeded fields
241                                unset($oldData['dn']);
242                                unset($oldData['count']);
243                                foreach($oldData as $key => $value)
244                                {
245                                        if(is_numeric($key))
246                                        {
247                                                // remove the key, its no ldap key
248                                                unset($oldData[$key]);
249                                        }
250                                        else
251                                        {
252                                                // remove the count key
253                                                if($oldData[$key]['count'] == 1)
254                                                {
255                                                        $oldData[$key] = $value[0];
256                                                }
257                                                else
258                                                {
259                                                        unset($oldData[$key]['count']);
260                                                }
261                                        }
262                                }
263
264                                $oldAccountID = $oldData['uid'];
265                                $oldGroupID   = $oldData['cn'];
266
267                                // merge the old data with the new one
268                                $newData = array_merge($oldData, $newData);
269
270                                /* Groups */
271                                if($this->data['account_type'] == 'g' && $this->group_context )
272                                {
273                                        $newDN = 'cn='.$this->data['account_lid'].','.$this->group_context;
274                                        $members = $this->member($this->account_id);
275                                        $newData['memberuid'] = array();
276                                        for($i=0;$i<count($members);$i++)
277                                        {
278                                                $currname = $this->id2name($members[$i]['account_id']);
279                                                if(!in_array($currname,$entry['memberuid']))
280                                                {
281                                                        $newData['memberuid'][] = $currname;
282                                                }
283                                        }
284                                }
285                                /* Accounts */
286                                else
287                                {
288                                        $newDN = 'uid='.$this->data['account_lid'].','.$this->user_context;
289                                }
290                                // delete the old account
291                                ldap_delete($this->ds,$oldDN);
292
293                                // add the new account
294                                #_debug_array($newData);
295                                ldap_add($this->ds, $newDN, $newData);
296                        }
297                        /* Normal behavior for save_repository
298                           update Account */
299                        else
300                        {
301                                // add the list group members
302                                if($this->data['account_type'] == 'g' && $this->group_context )
303                                {
304                                        $members = $this->member($this->account_id);
305                                        #_debug_array($members);
306                                        $newData['memberuid'] = array();
307                                        for($i=0;$i<count($members);$i++)
308                                        {
309                                                $currname = $this->id2name($members[$i]['account_id']);
310                                                if(!in_array($currname,$newData['memberuid']))
311                                                {
312                                                        $newData['memberuid'][] = $currname;
313                                                }
314                                        }
315                                }
316                                // modify the DN
317                                ldap_modify($this->ds, $allValues[0]['dn'], $newData);
318                        }
319
320                        if ($this->data['account_type'] == 'u')
321                        {
322                                // lets check for groups, the user needs to be removed
323
324                                // first lets search for the groups, the user is currently member of
325                                // and from which he needs to be removed
326                                $filter    = "(&(objectclass=posixgroup)(memberuid=" . (int)$oldAccountID . "))";
327                                $justThese = array('memberuid','gidnumber');
328                                $sri = ldap_search($this->ds, $this->group_context, $filter, $justThese);
329                                if($sri)
330                                {
331                                        $allValues = ldap_get_entries($this->ds, $sri);
332                                        if($allValues['count'] > 0)
333                                        {
334                                                unset($allValues['count']);
335                                                foreach($allValues as $key)
336                                                {
337                                                        #_debug_array($key);
338                                                        #_debug_array($this->data['account_groups']);
339                                                        // delete the old accountid from any group
340                                                        if($newAccountID != $oldAccountID)
341                                                        {
342                                                                $dn = $key['dn'];
343                                                                $newData = array();
344                                                                $newData['memberuid'] = $key['memberuid'];
345                                                                unset($newData['memberuid']['count']);
346                                                                // remove the uid from memberuid
347                                                                $newData['memberuid'] = array_flip($newData['memberuid']);
348                                                                unset($newData['memberuid'][$oldAccountID]);
349                                                                # $newData['memberuid'] = array_values(sort(array_flip($newData['memberuid'])));
350                                                                $newData['memberuid'] = array_values(array_flip($newData['memberuid']));
351                                                                ldap_mod_replace($this->ds, $dn, $newData);
352                                                                #print ldap_error($this->ds);
353                                                        }
354                                                        else
355                                                        {
356                                                                if(!in_array($key['gidnumber'][0],$this->data['account_groups']))
357                                                                {
358                                                                        $dn = $key['dn'];
359                                                                        $newData = array();
360                                                                        $newData['memberuid'] = $key['memberuid'];
361                                                                        unset($newData['memberuid']['count']);
362                                                                        // remove the uid from memberuid
363                                                                        $newData['memberuid'] = array_flip($newData['memberuid']);
364                                                                        unset($newData['memberuid'][$oldAccountID]);
365                                                                        $newData['memberuid'] = array_values(sort(array_flip($newData['memberuid'])));
366                                                                        ldap_mod_replace($this->ds, $dn, $newData);
367                                                                        #print ldap_error($this->ds);
368                                                                }
369                                                        }
370                                                }
371                                        }
372                                }
373
374                                // lets check group the user needs to be added
375                                foreach($this->data['account_groups'] as $key => $value)
376                                {
377                                        // search for the group
378                                        $filter    = 'gidnumber=' . (int)$value;
379                                        $justThese = array('memberuid');
380                                        $sri = ldap_search($this->ds, $this->group_context, $filter, $justThese);
381                                        if($sri)
382                                        {
383                                                $allValues = ldap_get_entries($this->ds, $sri);
384                                                // if the user is not member of this group, add him
385                                                if(is_array($allValues[0]['memberuid']))
386                                                {
387                                                        // this group has already some members
388                                                        if(!in_array($newData['uid'],$allValues[0]['memberuid']))
389                                                        {
390                                                                $dn = $allValues[0]['dn'];
391                                                                $newData = array();
392                                                                $newData['memberuid'] = $allValues[0]['memberuid'];
393                                                                unset($newData['memberuid']['count']);
394                                                                $newData['memberuid'][] = $newAccountID;
395                                                                $newData['memberuid'] = array_values(array_unique($newData['memberuid']));
396                                                                ldap_mod_replace($this->ds, $dn, $newData);
397                                                        }
398                                                }
399                                                else
400                                                {
401                                                        // this group has no members
402                                                        $dn = $allValues[0]['dn'];
403                                                        $newData = array();
404                                                        $newData['memberuid'][] = $newAccountID;
405                                                        ldap_mod_replace($this->ds, $dn, $newData);
406                                                }
407                                        }
408                                }
409                        }
410                }
411
412                function delete($accountid = '')
413                {
414                        $account_id = get_account_id($accountid);
415                        $account_lid = $this->id2name((int)$account_id);
416
417                        $filter = "(&(gidnumber=" . (int)$account_id.")(phpgwaccounttype=g))";
418                        $sri = ldap_search($this->ds, $this->group_context, $filter);
419                        if($sri)
420                        {
421                                $allValues = ldap_get_entries($this->ds, $sri);
422                        }
423
424                        if(!$allValues[0]['dn'])
425                        {
426                                $sri = ldap_search($this->ds, $this->user_context, "(&(uid=" . (string)$account_lid.")(phpgwaccounttype=u))");
427                                if($sri)
428                                {
429                                        $allValues = ldap_get_entries($this->ds, $sri);
430                                        $accountID = $allValues['0']['uid'][0];
431                                        $wasAccount = True;
432                                }
433                        }
434
435                        if ($allValues[0]['dn'])
436                        {
437                                $del = ldap_delete($this->ds, $allValues[0]['dn']);
438                        }
439
440                        if($wasAccount)
441                        {
442                                // remove the user from any group he is member of
443                                $filter    = "(&(objectclass=posixgroup)(memberuid=" . (int)$accountID . "))";
444                                $justThese = array('memberuid','gidnumber');
445                                $sri = ldap_search($this->ds, $this->group_context, $filter, $justThese);
446                                if($sri)
447                                {
448                                        $allValues = ldap_get_entries($this->ds, $sri);
449                                        if($allValues['count'] > 0)
450                                        {
451                                                unset($allValues['count']);
452                                                foreach($allValues as $key)
453                                                {
454                                                        $dn = $key['dn'];
455                                                        $newData = array();
456                                                        $newData['memberuid'] = $key['memberuid'];
457                                                        unset($newData['memberuid']['count']);
458                                                        // remove the uid from memberuid
459                                                        $newData['memberuid'] = array_flip($newData['memberuid']);
460                                                        unset($newData['memberuid'][$accountID]);
461                                                        $newData['memberuid'] = array_unique(array_flip($newData['memberuid']));
462                                                        ldap_mod_replace($this->ds, $dn, $newData);
463                                                }
464                                        }
465                                }
466                        }
467                }
468
469                function get_list($_type='both', $start = '',$sort = '', $order = '', $query = '', $offset = '',$query_type='')
470                {
471                        //print "\$_type=$_type, \$start=$start , \$sort=$sort, \$order=$order, \$query=$query, \$offset=$offset, \$query_type=$query_type<br>";
472                        $query = strtolower($query);
473
474                        if($_type == 'accounts' || $_type == 'both')
475                        {
476                                $filter = "(&(uidnumber=*)(phpgwaccounttype=u)";
477                                if (!empty($query) && $query != '*')
478                                {
479                                        switch($query_type)
480                                        {
481                                                case 'all':
482                                                default:
483                                                        $query = '*'.$query;
484                                                        // fall-through
485                                                case 'start':
486                                                        $query .= '*';
487                                                        // fall-through
488                                                case 'exact':
489                                                        $filter .= "(|(uid=$query)(sn=$query)(cn=$query)(givenname=$query)(mail=$query))";
490                                                        break;
491                                                case 'firstname':
492                                                case 'lastname':
493                                                case 'lid':
494                                                case 'email':
495                                                        $to_ldap = array(
496                                                                'firstname' => 'givenname',
497                                                                'lastname'  => 'sn',
498                                                                'lid'       => 'uid',
499                                                                'email'     => 'mail',
500                                                        );
501                                                        $filter .= '('.$to_ldap[$query_type].'=*'.$query.'*)';
502                                                        break;
503                                        }
504                                }
505                                $filter .= ')';
506
507                                $sri = ldap_search($this->ds, $this->user_context, $filter);
508                                $allValues = ldap_get_entries($this->ds, $sri);
509                                while (list($null,$allVals) = @each($allValues))
510                                {
511                                        settype($allVals,'array');
512                                        $test = @$allVals['uid'][0];
513                                        if (!$GLOBALS['phpgw_info']['server']['global_denied_users'][$test] && $allVals['uid'][0])
514                                        {
515                                                $accounts[] = Array(
516                                                        'account_id'        => $allVals['uidnumber'][0],
517                                                        'account_lid'       => $allVals['uid'][0],
518                                                        'account_type'      => $allVals['phpgwaccounttype'][0],
519                                                        'account_firstname' => $GLOBALS['phpgw']->translation->convert($allVals['givenname'][0],'utf-8'),
520                                                        'account_lastname'  => $GLOBALS['phpgw']->translation->convert($allVals['sn'][0],'utf-8'),
521                                                        'account_status'    => $allVals['phpgwaccountstatus'][0],
522                                                        'account_email'     => $allVals['mail'][0],
523                                                );
524                                        }
525                                }
526                        }
527                        if ($_type == 'groups' || $_type == 'both')
528                        {
529                                if(empty($query) || $query == '*')
530                                {
531                                        $filter = '(&(gidnumber=*)(phpgwaccounttype=g))';
532                                }
533                                else
534                                {
535                                        $filter = "(&(gidnumber=*)(phpgwaccounttype=g)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))";
536                                }
537                                $sri = ldap_search($this->ds, $this->group_context, $filter);
538                                $allValues = ldap_get_entries($this->ds, $sri);
539                                while (list($null,$allVals) = @each($allValues))
540                                {
541                                        settype($allVals,'array');
542                                        $test = $allVals['cn'][0];
543                                        if (!$GLOBALS['phpgw_info']['server']['global_denied_groups'][$test] && $allVals['cn'][0])
544                                        {
545                                                $accounts[] = Array(
546                                                        'account_id'        => $allVals['gidnumber'][0],
547                                                        'account_lid'       => $allVals['cn'][0],
548                                                        'account_type'      => $allVals['phpgwaccounttype'][0],
549                                                        'account_firstname' => $GLOBALS['phpgw']->translation->convert($allVals['givenname'][0],'utf-8'),
550                                                        'account_lastname'  => $GLOBALS['phpgw']->translation->convert($allVals['sn'][0],'utf-8'),
551                                                        'account_status'    => $allVals['phpgwaccountstatus'][0],
552                                                        'account_email'     => $allVals['mail'][0],
553                                                );
554                                        }
555                                }
556                        }
557                        // sort the array
558                        $arrayFunctions = CreateObject('phpgwapi.arrayfunctions');
559                        if(empty($order))
560                        {
561                                $order = 'account_lid';
562                        }
563                        $sortedAccounts = $arrayFunctions->arfsort($accounts,explode(',',$order),$sort);
564                        $this->total = count($accounts);
565
566                        // return only the wanted accounts
567
568                        if (is_array($sortedAccounts))
569                        {
570                                reset($sortedAccounts);
571                                if(is_int($start) && is_int($offset))
572                                {
573                                        return array_slice($sortedAccounts, $start, $offset);
574                                }
575                                elseif(is_int($start))
576                                {
577                                        return array_slice($sortedAccounts, $start, $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']);
578                                }
579                                else
580                                {
581                                        return $sortedAccounts;
582                                }
583                        }
584                        return False;
585                }
586
587                function name2id($name,$which='account_lid')
588                {
589                        /* jakjr: change search position */
590                        $to_ldap = array(
591                                'account_lid'   => 'uid',
592                                'account_email' => 'mail',
593                        );
594                        if (!isset($to_ldap[$which])) return False;
595                       
596                        $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . (string)$name . ')(phpgwaccounttype=u))', array("uidnumber"));
597                        $allValues = ldap_get_entries($this->ds, $sri);
598
599                        if (@$allValues[0]['uidnumber'][0])
600                        {
601                                return (int)$allValues[0]['uidnumber'][0];
602                        }
603
604                        if ($which == 'account_lid')    // groups only support account_lid
605                        {
606                                $sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . (string)$name . ')(phpgwaccounttype=g))', array("gidnumber"));
607                                $allValues = ldap_get_entries($this->ds, $sri);
608       
609                                if (@$allValues[0]['gidnumber'][0])
610                                {
611                                        return (int)$allValues[0]['gidnumber'][0];
612                                }
613                        }
614                       
615                        return False;
616                }
617
618                function id2name($account_id,$which='account_lid')
619                {
620                        if ($which == 'account_lid' || $which == 'account_type')        // groups only support account_lid and account_type
621                        {
622                                $allValues = array();
623                                /* jakjr: using justthese with ldap_search */
624                                $sri = @ldap_search($this->ds, $this->group_context, '(&(gidnumber=' . (int)$account_id . ')(phpgwaccounttype=g))', array("cn"));
625                                if(!$sri)
626                                        return False;
627                                $allValues = ldap_get_entries($this->ds, $sri);
628       
629                                $attr = $which == 'account_lid' ? 'cn' : 'phpgwaccounttype';
630                                if (@$allValues[0]['cn'][0])
631                                {
632                                        return $allValues[0]['cn'][0];
633                                }
634                        }
635                        $to_ldap = array(
636                                'account_lid'   => 'uid',
637                                'account_email' => 'mail',
638                                'account_firstname' => 'surname',
639                                'account_lastname'  => 'cn',
640                                'account_type'      => 'phpgwaccounttype',
641                        );
642                        if (!isset($to_ldap[$which])) return False;
643
644                        $allValues = array();
645                        /* jakjr: using justthese with ldap_search */
646                        $justthese = array("uid","mail","surname","cn","phpgwaccounttype");
647                        $sri = @ldap_search($this->ds, $this->user_context, '(&(uidnumber=' . (int)$account_id . ')(phpgwaccounttype=u))', $justthese);
648                        if(!$sri)
649                                return False;
650                        $allValues = ldap_get_entries($this->ds, $sri);
651
652                        if (@$allValues[0][$to_ldap[$which]][0])
653                        {
654                                return $allValues[0][$to_ldap[$which]][0];
655                        }
656                        return False;
657                }
658
659                function get_type($account_id)
660                {
661                        $allValues = array();
662                        /* jakjr: using justthese with ldap_search */
663                        $sri = @ldap_search($this->ds, $this->user_context, '(&(uidnumber=' . (int)$account_id . ')(phpgwaccounttype=u))', array("phpgwaccounttype"));
664                        if(!$sri)
665                                return False;
666                        $allValues = ldap_get_entries($this->ds, $sri);
667
668                        if ($allValues[0]['phpgwaccounttype'][0])
669                        {
670                                return $allValues[0]['phpgwaccounttype'][0];
671                        }
672
673                        $allValues = array();
674                        /* jakjr: using justthese with ldap_search */
675                        $sri = @ldap_search($this->ds, $this->group_context, '(&(gidnumber=' . (int)$account_id . ')(phpgwaccounttype=g))', array("phpgwaccounttype"));
676                        if(!$sri)
677                                return False;
678                        $allValues = ldap_get_entries($this->ds, $sri);
679
680                        if ($allValues[0]['phpgwaccounttype'][0])
681                        {
682                                return $allValues[0]['phpgwaccounttype'][0];
683                        }
684                        return False;
685                }
686
687                /*
688                 * returns nonzero if $account exists in LDAP: 0: nowhere 1: user accounts, 2: group accounts, 3: both
689                 * $account can be an account_id (LDAP: uidnumber) or an account_lid (LDAP: uid) (is determinded by ettype($account) == 'integer')
690                 */
691                function exists($account)
692                {
693                        /* This sets up internal caching variables for this functon */
694                        static $by_id, $by_lid;
695                        $users  = array();
696                        $groups = array();
697
698                        if(is_int($account))
699                        {
700                                $ldapgroup = 'gidnumber';
701                                $ldapacct  = 'uidnumber';
702                                $account   = (int)$account;
703                                /* If data is cached, use it. */
704                                if(@isset($by_id[$account]) && @$by_id[$account])
705                                {
706                                        return $by_id[$account];
707                                }
708                        }
709                        else
710                        {
711                                $ldapgroup = 'cn';
712                                $ldapacct  = 'uid';
713                                /* If data is cached, use it. */
714                                if(@isset($by_lid[$account]) && @$by_lid[$account])
715                                {
716                                        return $by_lid[$account];
717                                }
718                        }
719
720                        $acct_type = $this->get_type($account);
721
722                        if ($acct_type == 'g' && $this->group_context)
723                        {
724                                $sri = @ldap_search($this->ds, $this->group_context, $ldapgroup . '=' . $account);
725                                if(!$sri)
726                                        return False;
727                                $groups = ldap_get_entries($this->ds, $sri);
728                        }
729                        $sri = @ldap_search($this->ds, $this->user_context, $ldapacct . '=' . $account);
730                        if(!$sri)
731                                return False;
732                        $users = ldap_get_entries($this->ds, $sri);
733
734                        if ($users[0]['dn'])
735                        {
736                                $in += 1;
737                        }
738                        if ($groups[0]['dn'])
739                        {
740                                $in += 2;
741                        }
742                        /* This sets up internal caching for this function */
743                        if($ldapgroup == 'gidnumber')
744                        {
745                                $by_id[$account] = $in;
746                                $by_lid[$this->id2name($account)] = $in;
747                        }
748                        else
749                        {
750                                $by_lid[$account] = $in;
751                                $by_id[$this->name2id($account)] = $in;
752                        }
753
754                        return $in;
755                }
756
757                function create($account_info,$default_prefs=True)
758                {
759                        /* echo '<br>in create for account_lid: "'.$account_lid.'"'; */
760                        if (empty($account_info['account_id']) || !$account_info['account_id'])
761                        {
762                                $account_id = $this->get_nextid($account_info['account_type']);
763                                /* echo '<br>using'.$account_id;exit; */
764                        }
765                        else
766                        {
767                                $account_id = $account_info['account_id'];
768                        }
769                        $entry['userpassword']              = $account_info['account_passwd'];
770                        $entry['phpgwaccounttype']          = $account_info['account_type'];
771                        $entry['phpgwaccountexpires']       = $account_info['account_expires'];
772
773                        if($account_info['account_type'] == 'g')
774                        {
775                                $sri = @ldap_search($this->ds, $this->group_context, 'cn=' . (string)$account_info['account_lid']);
776                        }
777                        else
778                        {
779                                $sri = @ldap_search($this->ds, $this->user_context, 'uid=' . (string)$account_info['account_lid']);
780                        }
781                        if(!$sri)
782                                return False;
783                        $allValues = ldap_get_entries($this->ds, $sri);
784
785                        if ($GLOBALS['phpgw_info']['server']['ldap_extra_attributes'] && $account_info['account_type'] != 'g')
786                        {
787                                $entry['homedirectory'] = $account_info['homedirectory'] && $account_info['homedirectory'] != $GLOBALS['phpgw_info']['server']['ldap_account_home'] ? $account_info['homedirectory'] : $GLOBALS['phpgw_info']['server']['ldap_account_home'].SEP.$account_info['account_lid'];
788                                $entry['loginshell'] = $account_info['loginshell'] ? $account_info['loginshell'] : $GLOBALS['phpgw_info']['server']['ldap_account_shell'];
789                        }
790                        elseif($account_info['account_type'] != 'g')
791                        {
792                                $entry['homedirectory'] = '/home/'.$account_info['account_lid'];
793                                $entry['loginshell'] = '/bin/false';
794                        }
795
796                        if ($allValues[0]['dn'])
797                        {
798                                /* This should keep the password from being overwritten here on ldap import */
799                                unset($entry['userpassword']);
800                                $entry['gidnumber'] = $account_id;
801
802                                while (list($key,$val) = each($entry))
803                                {
804                                        $tmpentry = '';
805                                        $tmpentry[$key] = trim($val); /* must trim! */
806                                        /* echo '<br>'.$key.' '.$val; */
807                                        if ($tmpentry[$key])
808                                        {
809                                                if (!$allValues[0][$key][0])
810                                                {
811                                                        /* attribute was not in LDAP, add it */
812                                                        ldap_mod_add($this->ds, $allValues[0]['dn'], $tmpentry);
813                                                }
814                                                else
815                                                {
816                                                        /* attribute was in LDAP, modify it */
817                                                        ldap_modify($this->ds, $allValues[0]['dn'], $tmpentry);
818                                                }
819                                        }
820                                }
821
822                                if ($account_info['account_type'] == 'g')
823                                {
824                                        $tmpentry['objectclass'][0] = 'top';
825                                        $tmpentry['objectclass'][1] = 'posixGroup';
826                                        $tmpentry['objectclass'][2] = 'phpgwAccount';
827                                }
828                                else
829                                {
830                                        $tmpentry['uidnumber']      = $account_id;
831                                        $tmpentry['objectclass'][0] = 'top';
832                                        $tmpentry['objectclass'][1] = 'person';
833                                        $tmpentry['objectclass'][2] = 'organizationalPerson';
834                                        $tmpentry['objectclass'][3] = 'inetOrgPerson';
835                                        $tmpentry['userpassword']   = $GLOBALS['phpgw']->common->encrypt_password($account_info['account_passwd'],False);
836                                        /* $tmpentry['objectclass'][4] = 'account'; Causes problems with some LDAP servers */
837                                        $tmpentry['objectclass'][4] = 'posixAccount';
838                                        $tmpentry['objectclass'][5] = 'shadowAccount';
839                                        $tmpentry['objectclass'][6] = 'phpgwAccount';
840                                        $tmpentry['phpgwaccountstatus']    = $account_info['account_status'];
841                                        $tmpentry['phpgwaccounttype']      = $account_info['account_type'];
842                                        $tmpentry['phpgwaccountexpires']   = $account_info['account_expires'];
843                                }
844                                ldap_modify($this->ds, $allValues[0]['dn'], $tmpentry);
845                        }
846                        else
847                        {
848                                /* Not already there, we will add it */
849                                if ($account_info['account_type'] == 'g')
850                                {
851                                        $dn = 'cn='.$account_info['account_lid'] . ',' . $this->group_context;
852                                        unset($entry['homedirectory']);
853                                        unset($entry['loginshell']);
854                                        $entry['objectclass'][0] = 'top';
855                                        $entry['objectclass'][1] = 'posixGroup';
856                                        $entry['objectclass'][2] = 'phpgwAccount';
857                                        $entry['cn']             = $GLOBALS['phpgw']->translation->convert($account_info['account_lid'],$GLOBALS['phpgw']->translation->charset(),'utf-8');
858                                        $entry['gidnumber']      = $account_id;
859                                        #$entry['userpassword']   = $GLOBALS['phpgw']->common->encrypt_password($account_info['account_passwd']);
860                                        $entry['description']    = 'phpgw-created group';
861                                }
862                                else
863                                {
864                                        $dn = 'uid=' . $account_info['account_lid'] . ',' . $this->user_context;
865
866                                        $entry['cn'] = $GLOBALS['phpgw']->translation->convert(
867                                                sprintf(
868                                                        "%s %s",
869                                                        $account_info['account_firstname'],
870                                                        $account_info['account_lastname']
871                                                ),
872                                                $GLOBALS['phpgw']->translation->charset(),
873                                                'utf-8'
874                                        );
875
876                                        $entry['sn'] = $GLOBALS['phpgw']->translation->convert(
877                                                $account_info['account_lastname'],
878                                                $GLOBALS['phpgw']->translation->charset(),
879                                                'utf-8'
880                                        );
881
882                                        if($account_info['account_firstname'])
883                                        {
884                                                $entry['givenname'] = $GLOBALS['phpgw']->translation->convert(
885                                                        $account_info['account_firstname'],
886                                                        $GLOBALS['phpgw']->translation->charset(),
887                                                        'utf-8'
888                                                );
889                                        }
890                                        if($account_info['account_email'])
891                                        {
892                                                $entry['mail'] = $GLOBALS['phpgw']->translation->convert(
893                                                        $account_info['account_email'],
894                                                        $GLOBALS['phpgw']->translation->charset(),
895                                                        'utf-8'
896                                                );
897                                        }
898                                        $entry['uid']            = $account_info['account_lid'];
899                                        $entry['uidnumber']      = $account_id;
900                                        $entry['gidnumber']      = $account_info['account_primary_group'];
901                                        $entry['userpassword']   = $GLOBALS['phpgw']->common->encrypt_password($account_info['account_passwd']);
902                                        $entry['objectclass'][0] = 'top';
903                                        $entry['objectclass'][1] = 'person';
904                                        $entry['objectclass'][2] = 'organizationalPerson';
905                                        $entry['objectclass'][3] = 'inetOrgPerson';
906                                        $entry['objectclass'][4] = 'posixAccount';
907                                        $entry['objectclass'][5] = 'shadowAccount';
908                                        $entry['objectclass'][6] = 'phpgwAccount';
909                                        if($account_info['account_status'])
910                                        {
911                                                $entry['phpgwaccountstatus']    = $account_info['account_status'];
912                                        }
913                                        $entry['phpgwaccounttype']      = $account_info['account_type'];
914                                        $entry['phpgwaccountexpires']   = $account_info['account_expires'];
915                                }
916
917                                #_debug_array($entry);
918
919                                // stop processing if ldap_add fails
920                                if(!ldap_add($this->ds, $dn, $entry))
921                                {
922                                        return false;
923                                }
924                        }
925                        // print ldap_error($this->ds);
926
927                        // lets check group the user needs to be added
928                        if($account_info['account_type'] == 'u')
929                        {
930                                @settype($account_info['account_groups'],'array');
931                                foreach($account_info['account_groups'] as $key => $value)
932                                {
933                                        // search for the group
934                                        $filter    = 'gidnumber=' . (int)$value;
935                                        $justThese = array('memberuid');
936                                        $sri = ldap_search($this->ds, $this->group_context, $filter, $justThese);
937                                        if($sri)
938                                        {
939                                                $allValues = ldap_get_entries($this->ds, $sri);
940                                                // if the user is not member of this group, add him
941                                                if(is_array($allValues[0]['memberuid']))
942                                                {
943                                                        // this group has already some members
944                                                        if(!in_array($account_info['account_lid'],$allValues[0]['memberuid']))
945                                                        {
946                                                                $dn = $allValues[0]['dn'];
947                                                                $newData = array();
948                                                                $newData['memberuid'] = $allValues[0]['memberuid'];
949                                                                unset($newData['memberuid']['count']);
950                                                                $newData['memberuid'][] = $account_info['account_lid'];
951                                                                $newData['memberuid'] = array_unique($newData['memberuid']);
952                                                                ldap_mod_replace($this->ds, $dn, $newData);
953                                                                #print ldap_error($this->ds)."<br>";
954                                                        }
955                                                }
956                                                else
957                                                {
958                                                        // this group has no members
959                                                        $dn = $allValues[0]['dn'];
960                                                        $newData = array();
961                                                        $newData['memberuid'][] = $account_info['account_lid'];
962                                                        ldap_mod_replace($this->ds, $dn, $newData);
963                                                }
964                                        }
965                                }
966                        }
967
968                        if($account_id && is_object($GLOBALS['phpgw']->preferences) && $default_prefs)
969                        {
970                                $GLOBALS['phpgw']->preferences->create_defaults($account_id);
971                        }
972
973                        return $account_id;
974                }
975
976                function auto_add($accountname, $passwd, $default_prefs = False, $default_acls = False, $expiredate = 0, $account_status = 'A')
977                {
978                        if ($expiredate == 0)
979                        {
980                                if(isset($GLOBALS['phpgw_info']['server']['auto_create_expire']) == True)
981                                {
982                                        if($GLOBALS['phpgw_info']['server']['auto_create_expire'] == 'never')
983                                        {
984                                                $expires = -1;
985                                        }
986                                        else
987                                        {
988                                                $expiredate = time() + $GLOBALS['phpgw_info']['server']['auto_create_expire'];
989                                        }
990                                }
991                        }
992                        else
993                        {
994                                /* expire in 30 days by default */
995                                $expiredate = time() + ((60 * 60) * (30 * 24));
996                        }
997
998                        if ($expires != -1)
999                        {
1000                                $expires = mktime(2,0,0,date('n',$expiredate), (int)date('d',$expiredate), date('Y',$expiredate));
1001                        }
1002
1003                        $default_group_id  = $this->name2id($GLOBALS['phpgw_info']['server']['default_group_lid']);
1004                        if (!$default_group_id)
1005                        {
1006                                $default_group_id = (int) $this->name2id('Default');
1007                        }
1008                        $primary_group = $GLOBALS['auto_create_acct']['primary_group'] &&
1009                                $this->get_type((int)$GLOBALS['auto_create_acct']['primary_group']) == 'g' ?
1010                                (int) $GLOBALS['auto_create_acct']['primary_group'] : $default_group_id;
1011
1012                        $acct_info = array(
1013                                'account_lid'       => $accountname,
1014                                'account_type'      => 'u',
1015                                'account_passwd'    => $passwd,
1016                                'account_firstname' => $GLOBALS['auto_create_acct']['firstname'] ? $GLOBALS['auto_create_acct']['firstname'] : 'New',
1017                                'account_lastname'  => $GLOBALS['auto_create_acct']['lastname'] ? $GLOBALS['auto_create_acct']['lastname'] : 'User',
1018                                'account_status'    => $account_status,
1019                                'account_expires'   => $expires,
1020                                'account_primary_group' => $primary_group,
1021                        );
1022
1023                        /* attempt to set an email address */
1024                        if (isset($GLOBALS['auto_create_acct']['email']) == True && $GLOBALS['auto_create_acct']['email'] != '')
1025                        {
1026                                $acct_info['account_email'] = $GLOBALS['auto_create_acct']['email'];
1027                        }
1028                        elseif(isset($GLOBALS['phpgw_info']['server']['mail_suffix']) == True && $GLOBALS['phpgw_info']['server']['mail_suffix'] != '')
1029                        {
1030                                $acct_info['account_email'] = $accountname . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix'];
1031                        }
1032
1033                        $this->db->transaction_begin();
1034 
1035                        $this->create($acct_info,$default_prefs);  /* create the account */
1036
1037                        $accountid = $this->name2id($accountname); /* grab the account id or an error code */
1038
1039                        if ($accountid) /* begin account setup */
1040                        {
1041                                if($primary_group)
1042                                {
1043                                        $this->db->query("INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) VALUES('phpgw_group', "
1044                                                . $primary_group . ", " . $accountid . ", 1)",__LINE__,__FILE__);
1045                                }
1046
1047                                /* FIXME - we are assuming the auth method is capable of password changing
1048                                 * $this->db->query("INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights)VALUES('preferences', 'changepassword', ".$accountid.", 1)",__LINE__,__FILE__);
1049                                 */
1050
1051                                /* if we have an mail address set it in the uesrs' email preference */
1052                                if (isset($GLOBALS['auto_create_acct']['email']) && $GLOBALS['auto_create_acct']['email'] != '')
1053                                {
1054                                        $GLOBALS['phpgw']->acl->acl($accountid);        /* needed als preferences::save_repository calls acl */
1055                                        $GLOBALS['phpgw']->preferences->preferences($accountid);
1056                                        $GLOBALS['phpgw']->preferences->read_repository();
1057                                        $GLOBALS['phpgw']->preferences->add('email','address',$GLOBALS['auto_create_acct']['email']);
1058                                        $GLOBALS['phpgw']->preferences->save_repository();
1059                                }
1060                                /* use the default mail domain to set the uesrs' email preference  */
1061                                elseif(isset($GLOBALS['phpgw_info']['server']['mail_suffix']) && $GLOBALS['phpgw_info']['server']['mail_suffix'] != '')
1062                                {
1063                                        $GLOBALS['phpgw']->acl->acl($accountid);        /* needed als preferences::save_repository calls acl */
1064                                        $GLOBALS['phpgw']->preferences->preferences($accountid);
1065                                        $GLOBALS['phpgw']->preferences->read_repository();
1066                                        $GLOBALS['phpgw']->preferences->add('email','address', $accountname . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix']);
1067                                        $GLOBALS['phpgw']->preferences->save_repository();
1068                                }
1069
1070                                /* commit the new account transaction */
1071                                $this->db->transaction_commit();
1072
1073                                /* does anyone know what the heck this is required for? */
1074                                $GLOBALS['hook_values']['account_lid']  = $acct_info['account_lid'];
1075                                $GLOBALS['hook_values']['account_id']   = $accountid;
1076                                $GLOBALS['hook_values']['new_passwd']   = $acct_info['account_passwd'];
1077                                $GLOBALS['hook_values']['account_status'] = $acct_info['account_status'];
1078                                $GLOBALS['hook_values']['account_firstname'] = $acct_info['account_firstname'];
1079                                $GLOBALS['hook_values']['account_lastname'] = $acct_info['account_lastname'];
1080                                $GLOBALS['phpgw']->hooks->process($GLOBALS['hook_values']+array(
1081                                        'location' => 'addaccount'
1082                                ),False,True);  // called for every app now, not only enabled ones
1083
1084                        } /* end account setup */
1085                        else /* if no account id abort the account creation */
1086                        {
1087                                $this->db->transaction_abort();
1088                        }
1089
1090                        /*
1091                         * If we succeeded in creating the account (above), return the accountid, else,
1092                         * return the error value from $this->name2id($accountname)
1093                         */
1094                        return $accountid;
1095                } /* end auto_add() */
1096
1097                function get_account_name($account_id,&$lid,&$fname,&$lname)
1098                {
1099                        $acct_type = $this->get_type($account_id);
1100
1101                        /* jakjr: using justthese with ldap_search */
1102                        $justthese = array("cn","uid","givenname","sn");
1103
1104                        /* search the dn for the given uid */
1105                        if(($acct_type == 'g') && $this->group_context)
1106                        {
1107                                $sri = @ldap_search($this->ds, $this->group_context, '(&(gidnumber=' . (int)$account_id . ')(phpgwAccountType=g))', $justthese);
1108                        }
1109                        else
1110                        {
1111                                $sri = @ldap_search($this->ds, $this->user_context, '(&(uidnumber=' . (int)$account_id . ')(phpgwAccountType=u))', $justthese);
1112                        }
1113                        if(!$sri)
1114                                return False;
1115                        $allValues = ldap_get_entries($this->ds, $sri);
1116
1117                        if($acct_type =='g')
1118                        {
1119                                $lid   = $GLOBALS['phpgw']->translation->convert($allValues[0]['cn'][0],'utf-8');
1120                                $fname = $GLOBALS['phpgw']->translation->convert($allValues[0]['cn'][0],'utf-8');
1121                                $lname = lang('Group');
1122                        }
1123                        else
1124                        {
1125                                $lid   = $GLOBALS['phpgw']->translation->convert($allValues[0]['uid'][0],'utf-8');
1126                                $fname = $GLOBALS['phpgw']->translation->convert($allValues[0]['givenname'][0],'utf-8');
1127                                $lname = $GLOBALS['phpgw']->translation->convert($allValues[0]['sn'][0],'utf-8');
1128                        }
1129                        return !empty($lid);
1130                }
1131
1132                function getDNforID($_accountid = '')
1133                {
1134                        $_account_id = get_account_id($_accountid);
1135
1136                        $sri = @ldap_search($this->ds, $this->user_context, 'uidnumber=' . (int)$_account_id);
1137                        if(!$sri)
1138                                return False;
1139                        $allValues = ldap_get_entries($this->ds, $sri);
1140
1141                        return $allValues[0]['dn'];
1142                }
1143               
1144                //by JakJr, add organization support
1145                function get_context($dn)
1146                {
1147                        return substr($dn, (strpos($dn, ',')+1));
1148                }
1149
1150                //by JakJr, add organization support
1151                function get_organization($dn)
1152                {
1153                        $ldap_context = $GLOBALS['phpgw_info']['server']['ldap_context'];
1154                        $end = (strpos($dn, $ldap_context)-1);
1155                        $tmp =  substr($dn, 0, $end);
1156                        $begin = (strrpos($tmp, '=')+1);
1157                        return substr($dn, $begin, ($end - $begin));
1158                }
1159
1160                //by JakJr, add organization support
1161                function get_sector($dn)
1162                {
1163                        $context = $this->get_context($dn);
1164                        $begin = (strpos($context, '=')+1);
1165                        $end = (strpos($context, ',') - $begin);
1166                        return substr($context, $begin, $end);
1167                }
1168               
1169                function id2fullname($account_id)
1170                {
1171                        $allValues = array();
1172                        $sri = @ldap_search($this->ds, $this->user_context, '(&(uidnumber=' . (int)$account_id . ')(phpgwaccounttype=u))');
1173                        if(!$sri)
1174                                return False;
1175                        $allValues = ldap_get_entries($this->ds, $sri);
1176                        if (@$allValues[0]['cn'][0])
1177                        {
1178                                return $allValues[0]['cn'][0];
1179                        }
1180                        return False;
1181               }
1182
1183                function mail2fullname($mail)
1184                {
1185                        $allValues = array();
1186                        $sri = @ldap_search($this->ds, $this->user_context, '(&(mail=' . $mail . ')(phpgwaccounttype=u))');
1187                        if(!$sri)
1188                                return False;
1189                        $allValues = ldap_get_entries($this->ds, $sri);
1190                        if (@$allValues[0]['cn'][0])
1191                        {
1192                                return $allValues[0]['cn'][0];
1193                        }
1194                        return False;
1195                }
1196        }
1197?>
Note: See TracBrowser for help on using the repository browser.