Ignore:
Timestamp:
11/03/11 13:24:14 (13 years ago)
Author:
wmerlotto
Message:

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo ExpressoAdmin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php

    r3530 r5133  
    44include_once(PHPGW_API_INC.'/class.common.inc.php'); 
    55include_once('class.functions.inc.php'); 
     6include_once('class.db_functions.inc.php'); 
    67 
    78function ldapRebind($ldap_connection, $ldap_url) 
     
    2223        var $functions; 
    2324        var $manager_contexts; 
     25        var $db_functions; 
    2426         
    2527        function ldap_functions(){               
     
    4143                } 
    4244                 
     45                $this->db_functions = new db_functions(); 
    4346                $this->functions = new functions; 
    4447                $manager_acl = $this->functions->read_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid']); 
     
    4649        } 
    4750 
    48         function create_shared_accounts($params) 
    49                 { 
    50                         /* Begin: Access verification */ 
    51                          
    52                         if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'add_shared_accounts')) 
     51        function noAccess( $context, $target, $label = false ) 
     52                { 
     53            if( !$label ) 
     54                $label = str_replace( '_', ' ', $target ); 
     55                         
     56            if (!$this->functions->check_acl( $_SESSION['phpgw_info']['expresso']['user']['account_lid'], $target )) 
    5357                        { 
    5458                                $return['status'] = false; 
    55                                 $return['msg'] = $this->functions->lang('You do not have right to create shared accounts') . "."; 
     59                $return['msg'] = $this->functions->lang("You do not have right to $label") . "."; 
    5660                                return $return; 
    5761                        } 
    5862                         
    5963                        $access_granted = false; 
     64 
    6065                        foreach ($this->manager_contexts as $idx=>$manager_context) 
    6166                        { 
    62                                 if (stristr($params['context'], $manager_context)) 
     67                    if (stristr($context, $manager_context)) 
    6368                                { 
    6469                                        $access_granted = true; 
     
    7378                                return $return; 
    7479                        }                        
     80 
     81            return( false ); 
     82        } 
     83         
     84        function create_institutional_accounts($params) 
     85        { 
     86                /* Begin: Access verification */ 
     87                $forbidden = $this->noAccess( $params['context'], 'add_institutional_accounts', 'create institutional accounts' ); 
     88 
     89                if( $forbidden ) 
     90                    return( $forbidden ); 
     91//              if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'add_institutional_accounts')) 
     92//              { 
     93//                      $return['status'] = false; 
     94//                      $return['msg'] = $this->functions->lang('You do not have right to create institutional accounts') . "."; 
     95//                      return $return; 
     96//              } 
     97//               
     98//              $access_granted = false; 
     99//              foreach ($this->manager_contexts as $idx=>$manager_context) 
     100//              { 
     101//                      if (stristr($params['context'], $manager_context)) 
     102//                      { 
     103//                              $access_granted = true; 
     104//                              break; 
     105//                      } 
     106//              } 
     107//              if (!$access_granted) 
     108//              { 
     109//                      $return['status'] = false; 
     110//                      $return['msg'] = $this->functions->lang('You do not have access to this organization') . "."; 
     111//                      return $return; 
     112//              } 
    75113                        /* End: Access verification */ 
    76114         
     115                /* Begin: Validation */ 
     116                if ( (empty($params['cn'])) || (empty($params['mail'])) ) 
     117                { 
     118                        $result['status'] = false; 
     119                        $result['msg']  = $this->functions->lang('Field mail or name is empty'); 
     120                        return $result; 
     121                } 
     122 
     123                if (! eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $params['mail']) ) 
     124                { 
     125                        $result['status'] = false; 
     126                        $result['msg']  = $this->functions->lang('Field mail is not formed correcty') . '.'; 
     127                        return $result; 
     128                } 
     129 
     130                $uid = 'institutional_account_' . $params['mail']; 
     131                $dn = "uid=$uid," . $params['context']; 
     132 
     133                $filter = "(mail=".$params['mail'].")"; 
     134                $justthese = array("cn"); 
     135                $search = @ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     136                $entries = @ldap_get_entries($this->ldap,$search); 
     137                if ($entries['count'] != 0) 
     138                { 
     139                        $result['status'] = false; 
     140                        $result['msg'] = $this->functions->lang('Field mail already in use'); 
     141                        return $result; 
     142                } 
     143                /* End: Validation */ 
     144                                                 
     145                $info = array(); 
     146                $info['cn']                                     = $params['cn']; 
     147                $info['sn']                                     = $params['cn']; 
     148                $info['uid']                            = $uid; 
     149                $info['mail']                           = $params['mail']; 
     150                $info['description']            = iconv("ISO-8859-1","UTF-8//TRANSLIT",$params['desc']); 
     151                $info['phpgwAccountType']       = 'i'; 
     152                $info['objectClass'][]          = 'inetOrgPerson'; 
     153                $info['objectClass'][]          = 'phpgwAccount'; 
     154                $info['objectClass'][]          = 'top'; 
     155                $info['objectClass'][]          = 'person'; 
     156                $info['objectClass'][]          = 'qmailUser'; 
     157                $info['objectClass'][]          = 'organizationalPerson'; 
     158                 
     159                if ($params['accountStatus'] == 'on') 
     160                { 
     161                        $info['accountStatus'] = 'active'; 
     162                } 
     163                if ($params['phpgwAccountVisible'] == 'on') 
     164                { 
     165                        $info['phpgwAccountVisible'] = '-1'; 
     166                } 
     167                 
     168                if (!empty($params['owners'])) 
     169                { 
     170                        foreach($params['owners'] as $index=>$uidnumber) 
     171                        { 
     172                                $info['mailForwardingAddress'][] = $this->uidnumber2mail($uidnumber); 
     173                        } 
     174                }                
     175                 
     176                $result = array(); 
     177                if (!@ldap_add ( $this->ldap, $dn, $info )) 
     178                { 
     179                        $result['status'] = false; 
     180                        $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->create_institutional_accounts'; 
     181                        $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
     182                } 
     183                else 
     184                        $result['status'] = true; 
     185                 
     186                return $result; 
     187        } 
     188         
     189        function save_institutional_accounts($params) 
     190        { 
     191                /* Begin: Access verification */ 
     192                $forbidden = $this->noAccess( $params['context'], 'edit_institutional_accounts' ); 
     193 
     194                if( $forbidden ) 
     195                    return( $forbidden ); 
     196//              if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'edit_institutional_accounts')) 
     197//              { 
     198//                      $return['status'] = false; 
     199//                      $return['msg'] = $this->functions->lang('You do not have right to edit institutional accounts') . "."; 
     200//                      return $return; 
     201//              } 
     202//              $access_granted = false; 
     203//              foreach ($this->manager_contexts as $idx=>$manager_context) 
     204//              { 
     205//                      if (stristr($params['context'], $manager_context)) 
     206//                      { 
     207//                              $access_granted = true; 
     208//                              break; 
     209//                      } 
     210//              } 
     211//              if (!$access_granted) 
     212//              { 
     213//                      $return['status'] = false; 
     214//                      $return['msg'] = $this->functions->lang('You do not have access to this organization') . "."; 
     215//                      return $return; 
     216//              } 
     217                /* End: Access verification */ 
    77218                                 
    78219                        /* Begin: Validation */ 
     
    80221                        { 
    81222                                $result['status'] = false; 
     223                        $result['msg']  = $this->functions->lang('Field mail or name is empty') . '.'; 
     224                        return $result; 
     225                } 
     226 
     227                if (! eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $params['mail']) ) 
     228                { 
     229                        $result['status'] = false; 
     230                        $result['msg']  = $this->functions->lang('Field mail is not formed correcty') . '.'; 
     231                        return $result; 
     232                } 
     233 
     234                $uid = 'institutional_account_' . $params['mail']; 
     235                $dn = strtolower("uid=$uid," . $params['context']); 
     236                $anchor = strtolower($params['anchor']); 
     237 
     238                $filter = "(mail=".$params['mail'].")"; 
     239                $justthese = array("cn"); 
     240                $search = @ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     241                $entries = @ldap_get_entries($this->ldap,$search); 
     242                 
     243                if ( ($entries['count'] > 1) || (($entries['count'] == 1) && ($entries[0]['dn'] != $anchor)) ) 
     244                { 
     245                        $result['status'] = false; 
     246                        $result['msg'] = $this->functions->lang('Field mail already in use.'); 
     247                        return $result; 
     248                } 
     249                /* End: Validation */ 
     250                 
     251                $result = array(); 
     252                $result['status'] = true; 
     253                 
     254                if ($anchor != $dn) 
     255                { 
     256                        if (!@ldap_rename($this->ldap, $anchor, "uid=$uid", $params['context'], true)) 
     257                        { 
     258                                $result['status'] = false; 
     259                                $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->save_institutional_accounts: ldap_rename'; 
     260                                $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
     261                        } 
     262                } 
     263                 
     264                $info = array(); 
     265                $info['cn']                                     = $params['cn']; 
     266                $info['sn']                                     = $params['cn']; 
     267                $info['uid']                            = $uid; 
     268                $info['mail']                           = $params['mail']; 
     269                 
     270                if ($params['accountStatus'] == 'on') 
     271                        $info['accountStatus'] = 'active'; 
     272                else 
     273                        $info['accountStatus'] = array(); 
     274                 
     275                if ($params['phpgwAccountVisible'] == 'on') 
     276                        $info['phpgwAccountVisible'] = '-1'; 
     277                else 
     278                        $info['phpgwAccountVisible'] = array(); 
     279                 
     280                if ($params['desc'] != '') 
     281                        $info['description'] = utf8_encode($params['desc']); 
     282                else 
     283                        $info['description'] = array(); 
     284                 
     285                if (!empty($params['owners'])) 
     286                { 
     287                        foreach($params['owners'] as $index=>$uidnumber) 
     288                        { 
     289                                $mailForwardingAddress = $this->uidnumber2mail($uidnumber); 
     290                                if ($mailForwardingAddress != '') 
     291                                        $info['mailForwardingAddress'][] = $mailForwardingAddress; 
     292                        } 
     293                } 
     294                else 
     295                        $info['mailForwardingAddress'] = array(); 
     296                 
     297                if (!@ldap_modify ( $this->ldap, $dn, $info )) 
     298                { 
     299                        $result['status'] = false; 
     300                        $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->save_institutional_accounts: ldap_modify'; 
     301                        $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
     302                } 
     303 
     304                return $result; 
     305        } 
     306 
     307        function save_shared_accounts($params) 
     308        { 
     309                /* Begin: Access verification */ 
     310                $forbidden = $this->noAccess( $params['context'], 'edit_shared_accounts' ); 
     311 
     312                if( $forbidden ) 
     313                    return $forbidden; 
     314                 
     315                /* Begin: Validation */ 
     316                if(!$params['desc']) 
     317                { 
     318                    $result['status'] = false; 
     319                    $result['msg']  = $this->functions->lang('Field description is empty');     return $result; 
     320 
     321                } 
     322 
     323                if ( (empty($params['cn'])) || (empty($params['mail'])) ) 
     324                { 
     325                        $result['status'] = false; 
     326                        $result['msg']  = $this->functions->lang('Field mail or name is empty') . '.'; 
     327                        return $result; 
     328                } 
     329 
     330                if (! eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $params['mail']) ) 
     331                { 
     332                        $result['status'] = false; 
     333                        $result['msg']  = $this->functions->lang('Field mail is not formed correcty') . '.'; 
     334                        return $result; 
     335                }                        
     336 
     337                $dnReal = "uid=".$params['uid']."," . $params['context']; 
     338                $dn = strtolower("uid=".$params['uid']."," . $params['context']); 
     339                $anchor = strtolower($params['anchor']); 
     340 
     341                 
     342                $filter = "(mail=".$params['mail'].")"; 
     343                $justthese = array("cn","uidnumber"); 
     344                $search = @ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     345                $entries = @ldap_get_entries($this->ldap,$search); 
     346 
     347                //DEBUG: Alteracao para compatibilizar com LDAP da CAIXA. 
     348                // estas funcoes do ExpressoAdmin nao levam em consideracao o DN do objeto encontrado 
     349                // e o "codigo" assume que o DN comeca com UID quando na CAIXA comeca com CN. 
     350 
     351                // Se for encontrado somente um objeto e este estiver diferente do ANCHOR, entao pega o DN  
     352                // do resultado da busca 
     353                if ( ($entries['count'] == 1) && (utf8_decode($entries[0]['dn']) != $anchor) ) 
     354                { 
     355                        // Forca o DN 
     356                        $dn = strtolower (utf8_decode($entries[0]['dn'])); 
     357                        $dnReal = $entries[0]['dn']; 
     358                        $anchor = $dn; 
     359                } 
     360                 
     361                if ( ($entries['count'] > 1) || (($entries['count'] == 1) && (strtolower(utf8_decode($entries[0]['dn'])) != $anchor)) ) 
     362                { 
     363                        $result['status'] = false; 
     364                        $result['msg'] = $this->functions->lang('Field mail already in use.'); 
     365                        return $result; 
     366                } 
     367                /* End: Validation */ 
     368 
     369                $result = array(); 
     370                $result['status'] = true;               
     371 
     372                if ($anchor != $dn) 
     373                { 
     374                        if (!@ldap_rename($this->ldap, $params['anchor'], "uid=$params[uid]", $params['context'], true)) 
     375                        { 
     376                                $result['status'] = false; 
     377                                $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->save_shared_accounts: ldap_rename'; 
     378                                $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
     379                        } 
     380                } 
     381                 
     382                $info = array(); 
     383                $info['cn']             = utf8_encode($params['cn']); 
     384                $info['sn']             = utf8_encode($params['cn']); 
     385                $info['uid']            = $params['uid']; 
     386                $info['mail']           = $params['mail']; 
     387 
     388 
     389                $del = array(); 
     390 
     391                if( $params['mailalternateaddress'] ) 
     392                        $info['mailalternateaddress'] = $params['mailalternateaddress']; 
     393                else 
     394                    $del['mailalternateaddress'] = array(); 
     395 
     396                if ($params['accountStatus'] == 'on') 
     397                        $info['accountStatus'] = 'active'; 
     398                else 
     399                        $info['accountStatus'] = array(); 
     400                 
     401                if ($params['phpgwAccountVisible'] == 'on') 
     402                        $info['phpgwAccountVisible'] = '-1'; 
     403                else 
     404                        $info['phpgwAccountVisible'] = array(); 
     405                 
     406                if ($params['desc'] != '') 
     407                        $info['description'] = utf8_encode($params['desc']); 
     408                else 
     409                        $info['description'] = array(); 
     410 
     411                ldap_set_option ($this->ldap, LDAP_OPT_PROTOCOL_VERSION, 3); 
     412 
     413                if( !empty( $del ) ) 
     414                    @ldap_mod_del( $this->ldap, $dnReal, $del ); 
     415 
     416                if (!@ldap_modify ( $this->ldap,$dnReal, $info )) 
     417                { 
     418                        $result['status'] = false; 
     419                        $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->save_shared_accounts: ldap_modify'; 
     420                        $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
     421                } 
     422                //print_r($info);echo "Teste $dn".$result['msg'];exit(); 
     423                return $result; 
     424        } 
     425 
     426        function create_shared_accounts($params) 
     427        { 
     428                /* Begin: Access verification */ 
     429 
     430                $forbidden = $this->noAccess( $params['context'], 'add_shared_accounts', 'create shared accounts' ); 
     431 
     432                if( $forbidden ) 
     433                    return( $forbidden ); 
     434 
     435                /* End: Access verification */ 
     436 
     437                         
     438                /* Begin: Validation */ 
     439 
     440                if(!$params['desc']) 
     441                { 
     442                    $result['status'] = false; 
     443                    $result['msg']  = $this->functions->lang('Field description is empty');     return $result; 
     444 
     445                } 
     446 
     447                if ( (empty($params['cn'])) || (empty($params['mail'])) ) 
     448                { 
     449                        $result['status'] = false; 
    82450                                $result['msg']  = $this->functions->lang('Field mail or name is empty');        return $result; 
    83451                        } 
     
    96464                        if ($entries['count'] != 0) 
    97465                        { 
    98                                 $result['status'] = false; 
    99                                 $result['msg'] = $this->functions->lang('Field mail already in use'); 
    100                                 return $result; 
    101                         } 
     466                        $result['status'] = false; 
     467                        $result['msg'] = $this->functions->lang('Field mail already in use'); 
     468                        return $result; 
     469                } 
     470 
     471                // Leio o ID a ser usado na criação do objecto. Esta função já incrementa o ID no BD. 
     472                $next_id = ($this->db_functions->get_next_id('accounts')); 
     473                if ((!is_numeric($next_id['id'])) || (!$next_id['status'])) 
     474                { 
     475                        $return['status'] = false; 
     476                        $return['msg'] = $this->functions->lang('problems getting user id') . ".\n" . $id['msg']; 
     477                        return $return; 
     478                } 
     479                else 
     480                { 
     481                        $id = $next_id['id']; 
     482                        } 
     483 
    102484                        /* End: Validation */ 
    103485                                                         
    104486                        $info = array(); 
    105                         $info['cn']                                     = $params['cn']; 
    106                         $info['sn']                                     = $params['cn']; 
     487                $info['cn']                                     = utf8_encode($params['cn']); 
     488                $info['sn']                                     = utf8_encode($params['cn']); 
     489                $info['uidnumber']                                      = $id; 
     490                $info['homeDirectory']                          = '/dev/null'; 
     491                $info['gidNumber']                                      = '1000'; 
    107492                        $info['uid']                            = $params['uid']; 
    108493                        $info['mail']                           = $params['mail']; 
    109494                        $info['description'] = utf8_encode($params['desc']);                     
    110495                        $info['phpgwAccountType']       = 's'; 
    111                         $info['objectClass'][]          = 'inetOrgPerson'; 
    112                         $info['objectClass'][]          = 'phpgwAccount'; 
    113                         $info['objectClass'][]          = 'top'; 
    114                         $info['objectClass'][]          = 'person'; 
    115                         $info['objectClass'][]          = 'qmailUser'; 
    116                         $info['objectClass'][]          = 'organizationalPerson'; 
     496                $info['objectClass'][0]         = 'inetOrgPerson'; 
     497                $info['objectClass'][1]         = 'phpgwAccount'; 
     498                $info['objectClass'][2]         = 'top'; 
     499                $info['objectClass'][3]         = 'person'; 
     500                $info['objectClass'][4]         = 'qmailUser'; 
     501                $info['objectClass'][5]         = 'organizationalPerson'; 
     502                $info['objectClass'][6]         = 'posixAccount'; 
    117503                         
    118504                        if ($params['accountStatus'] == 'on') 
     
    124510                                $info['phpgwAccountVisible'] = '-1'; 
    125511                        } 
     512                if( !empty( $params['mailalternateaddress'] ) ) 
     513                        $info['mailalternateaddress'] = $params['mailalternateaddress']; 
    126514                         
    127515                        /*if (!empty($params['owners'])) 
     
    338726                                */ 
    339727                                 
    340                                 $filter = "(objectClass=organizationalUnit)"; 
     728                                $filter = "(ou=*)"; 
    341729                                $justthese = array("ou"); 
    342730                                $search = ldap_list($ldap_connection2, $context, $filter, $justthese); 
     
    437825                                 
    438826                                        $filter = "(&(phpgwAccountType=u)(cpf=$cpf))"; 
    439                                         $justthese = array("cn","uid","mail"); 
     827                                        $justthese = array("cn","uid"); 
    440828                                        $search = ldap_search($local_ldap_connection, $context, $filter, $justthese); 
    441829                                        $entries = ldap_get_entries($local_ldap_connection,$search); 
    442830                                 
    443                                         if ( ($entries['count'] > 0 ) && (strcasecmp($uid, $entries[0]['uid'][0]) != 0) ) 
     831                                        if ( ($entries['count'] != 1) && (strcasecmp($uid, $entries[0]['uid'][0]) != 0) ) 
    444832                                        { 
    445833                                                if ($entries['count'] > 0) 
    446834                                                { 
    447                                                                 $entries_text = ""; 
     835                                                        $result['question'] = $this->functions->lang('Field CPF used by') . ":\n"; 
    448836                                                                for ($i=0; $i<$entries['count']; $i++) 
    449837                                                                        { 
    450838                                                                                if (strcasecmp($uid, $entries[$i]['uid'][0]) != 0) 
    451                                                                                         $entries_text .= $entries[$i]['cn'][0] ." - ".$entries[0]['uid'][0] ." - ".$entries[$i]['mail'][0]."\n"; 
     839                                                                        $result['question'] .= "- " . $entries[$i]['cn'][0] . "\n"; 
    452840                                                                        } 
    453                                                                 if ($this->current_config['expressoAdmin_deny_same_cpf'] == 'false' )  
    454                                                                 {                                                                
    455                                                                         $result['question']  = $this->functions->lang('Field CPF used by') . ":\n"; 
    456                                                                         $result['question'] .= $entries_text; 
    457841                                                                        $result['question'] .= $this->functions->lang("Do you want to continue anyway") . "?"; 
    458842                                                                        return $result; 
    459                                                                 } else { 
    460                                                                         $result['status'] = false; 
    461                                                                         $result['msg']  = $this->functions->lang('Field CPF cannot be duplicated') . ".\n"; 
    462                                                                         $result['msg'] .= $this->functions->lang('Field CPF used by') . ":\n"; 
    463                                                                         $result['msg'] .= $entries_text; 
    464                                                                         return $result; 
    465                                                                 }                                                                
    466                                                                          
    467843                                                } 
    468844                                        } 
     
    487863                $justthese = array("uid"); 
    488864                $i=1; 
    489                 $login = array("status" => False,"msg" => $this->functions->lang("Login generator disabled")); 
     865                $login = array("status" => False,"msg" => lang("Login generator disabled")); 
     866                 
    490867                if( (isset($this->current_config['expressoAdmin_loginGenScript'])) &&  
    491868                                ($this->current_config['expressoAdmin_loginGenScript'])) { 
     
    501878                                return array( 
    502879                                        "status" => False, 
    503                                         "msg" => $this->functions->lang("Login interface not implemented (contact suport)") 
     880                                        "msg" => lang("Login interface not implemented (contact suport)") 
    504881                                ); 
    505882                        } 
     
    6651042        } 
    6661043 
     1044        function get_available( $params, $justthese = false, $targetTypes = false ) 
     1045        { 
     1046            $search = $params['sentence'] ? $params['sentence'] : $params['filter']; 
     1047                 
     1048            if( !$justthese ) 
     1049                $justthese = array('cn', 'uidNumber','uid'); 
     1050         
     1051            if( !$targetTypes ) 
     1052                $targetTypes = 'u'; 
     1053         
     1054            $ldapService = ServiceLocator::getService('ldap'); 
     1055                         
     1056            $entries = $ldapService->accountSearch( $search, $justthese, $params['context'], $targetTypes, 'cn' ); 
     1057 
     1058            return( $entries ); 
     1059        } 
     1060                         
     1061        function get_options( $entries, $label, $value = false, $uid = false ) 
     1062                { 
     1063            if( !$value ) 
     1064                $value = $label; 
     1065 
     1066            $options = ''; 
     1067            foreach( $entries as  $entry ) 
     1068                        { 
     1069                if( $uid ) 
     1070                    $entry[$label] .= '('.$entry[$uid].')'; 
     1071 
     1072                $options .= '<option value='.$entry[$value].'>'.$entry[$label].'</option>'; 
     1073                } 
     1074 
     1075        return $options; 
     1076        } 
     1077         
     1078        function get_json( $entries, $label, $value = false, $uid = false ) 
     1079        { 
     1080            if( !$value ) 
     1081                $value = $label; 
     1082 
     1083            $options = array(); 
     1084 
     1085            foreach( $entries as  $entry ) 
     1086            { 
     1087                if( $uid ) 
     1088                    $entry[$label] .= '('.$entry[$uid].')'; 
     1089 
     1090                 $options[] = '"'.$entry[$value].'"'.':'.'"'.$entry[$label].'"'; 
     1091 
     1092                        } 
     1093 
     1094             return "{".implode(',',$options)."}"; 
     1095        } 
     1096 
     1097 
    6671098        //Busca usuários de um contexto e já retorna as options do select; 
    6681099        function get_available_users($params) 
    669         { 
    670                 $context = $params['context']; 
    671                 $recursive = $params['recursive']; 
    672                 $justthese = array("cn", "uidNumber"); 
    673                 $filter="(phpgwAccountType=u)"; 
    674                  
    675                 if ($recursive == 'true') 
    676                         $groups_list=ldap_search($this->ldap, $context, $filter, $justthese); 
    677                 else 
    678                 $groups_list=ldap_list($this->ldap, $context, $filter, $justthese); 
    679          
    680         $entries = ldap_get_entries($this->ldap, $groups_list); 
    681          
    682                 for ($i=0; $i<$entries["count"]; $i++){ 
    683                         $u_tmp[$entries[$i]["uidnumber"][0]] = $entries[$i]["cn"][0]; 
    684                 } 
    685                          
    686                 if (count($u_tmp)) 
    687                         natcasesort($u_tmp); 
    688  
    689                 $i = 0; 
    690                 $users = array(); 
    691                          
    692                 if (count($u_tmp)) 
    693                 { 
    694                         foreach ($u_tmp as $uidnumber => $cn) 
    695                         { 
    696                                 $options .= "<option value=$uidnumber>$cn</option>"; 
    697                         } 
    698                         unset($u_tmp); 
    699                 } 
    700  
    701         return $options; 
    702         } 
    703         //Busca usuarios de um contexto e ja retorna as options do select; 
     1100                                { 
     1101             $entries = $this->get_available($params ); 
     1102 
     1103//              $options = ''; 
     1104//              foreach ($entries as  $value) 
     1105//                  $options .= '<option value='.$value['uidnumber'].'>'.$value['cn'].'('.$value['uid'].')</option>'; 
     1106 
     1107             return $this->get_options( $entries, 'cn', 'uidnumber', 'uid' ); 
     1108        } 
     1109 
     1110        //Busca usuários e contas compartilhadas de um contexto e já retorna as options do select; 
     1111        function get_available_users_and_shared_acounts($params) 
     1112        { 
     1113             $entries = $this->get_available($params, array('cn', 'uidNumber','uid'), array('u','s') ); 
     1114//              $options = ''; 
     1115//              foreach ($entries as  $value) 
     1116//                  $options .= '<option value='.$value['uidnumber'].'>'.$value['cn'].'('.$value['uid'].')</option>'; 
     1117                 
     1118             return $this->get_options( $entries, 'cn', 'uidnumber', 'uid' ); 
     1119        } 
     1120                 
    7041121        function get_available_users2($params) 
    7051122        { 
    706                 $context= $params['context']; 
    707                 $justthese = array("cn", "uid"); 
    708                 $filter = "(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"; 
    709  
    710             if ($this->ldap) 
    711             { 
    712                         $sr=ldap_search($this->ldap, $context, $filter, $justthese); 
    713                         $entries = ldap_get_entries($this->ldap, $sr);                   
    714  
    715                         for ($i=0; $i<$entries["count"]; $i++){                          
    716                                         $u_tmp[$entries[$i]["uid"][0]] = $entries[$i]["cn"][0]; 
    717                         } 
    718  
    719                         natcasesort($u_tmp); 
    720  
    721                         $i = 0; 
    722                         $users = array(); 
    723  
    724                         if (count($u_tmp)) 
    725                         { 
    726                                 foreach ($u_tmp as $uidnumber => $cn) 
    727                                 { 
    728                                         $options .= "<option value=$uidnumber>$cn</option>"; 
    729                                 } 
    730                                 unset($u_tmp); 
    731                         }                        
    732                 return $options; 
    733                 } 
    734         } 
     1123             $entries = $this->get_available($params, array('cn', 'uid') ); 
     1124                 
     1125//              $options = array(); 
     1126//              foreach ($entries as $value) 
     1127//                  $options[] = '"'.$value['uid'].'"'.':'.'"'.$value['cn'].'('.$value['uid'].')'.'"'; 
     1128                 
     1129             return $this->get_json( $entries, 'cn', 'uid', 'uid' ); 
     1130        } 
     1131 
     1132        function get_available_users3($params) 
     1133                { 
     1134             $ldapService = ServiceLocator::getService('ldap'); 
     1135             $groups = $ldapService->accountSearch($params['filter'], array('gidNumber','cn','uid'), $params['context'], 'g', 'cn'); 
     1136             $users = $ldapService->accountSearch($params['filter'], array('uidNumber','cn','uid'), $params['context'], 'u', 'cn'); 
     1137 
     1138             $user_options =''; 
     1139             $group_options =''; 
     1140             $user_options2 =''; 
     1141             $group_options2 =''; 
     1142 
     1143             foreach($groups as  $group) 
     1144             { 
     1145                $group_options .= '<option  value="'.$group['gidnumber'].'">'.$group['cn'].' ('.$group['gidnumber'].')</option>'."\n"; 
     1146                $group_options2 .= '<option  value="'.$group['gidnumber'].',G">'.$group['cn'].' ('.$group['gidnumber'].')</option>'."\n"; 
     1147                } 
     1148 
     1149             foreach($users as $user) 
     1150             { 
     1151                $user_options .= '<option  value="'.$user['uid'].'">'.$user['cn'].' ('.$user['uid'].')</option>'."\n"; 
     1152                $user_options2 .= '<option  value="'.$user['uid'].',U">'.$user['cn'].' ('.$user['uid'].')</option>'."\n"; 
     1153 
     1154             } 
     1155 
     1156            return array("users" => $user_options, "groups" => $group_options , "users2" => $user_options2, "groups2" => $group_options2); 
     1157        } 
     1158 
     1159        /** 
     1160         * @abstract Busca usuários de um contexto e retorna já formatado com as options do select. 
     1161         * @params array params com as informações do formulário com os dados do contexto e etc. 
     1162         * @return array com os usuários do contexto já com a formatação das options do select. 
     1163         */ 
     1164        function get_available_users_messages_size($params) 
     1165                        { 
     1166/*             $ldapService = ServiceLocator::getService('ldap'); 
     1167             $entries = $ldapService->accountSearch($params['sentence'], array('cn', 'uidNumber','uid'), $params['context'], 'u', 'cn'); 
     1168             $options = array(); 
     1169 
     1170             foreach ($entries as $value) 
     1171                 $options[] = '"'.$value['uid'].'"'.':'.'"'.$value['cn'].'('.$value['uid'].')'.'"';*/ 
     1172                  
     1173            $entries = $this->get_available( $params, array('cn', 'uid') ); 
     1174 
     1175             return $this->get_json( $entries, 'cn', 'uid','uid' ); 
     1176                        } 
     1177 
     1178        /** 
     1179         * @abstract Busca usuários e grupos de um contexto e retorna já formatado com as options do select. 
     1180         * @params array params com as informações do formulário com os dados do contexto e etc. 
     1181         * @return array com os usuários do contexto já com a formatação das options do select. 
     1182         */ 
     1183        function get_available_users_and_groups_messages_size($params) 
     1184        { 
     1185             $ldapService = ServiceLocator::getService('ldap'); 
     1186             $groups = $ldapService->accountSearch($params['sentence'], array('gidNumber','cn','uid'), $params['context'], 'g', 'cn'); 
     1187             $users = $ldapService->accountSearch($params['sentence'], array('cn','uid'), $params['context'], 'u', 'cn'); 
     1188             $optionsUsers = array(); 
     1189             $optionsGroups = array(); 
     1190             foreach ($users as $value) 
     1191                 $optionsUsers[] = '"'.$value['uid'].'"'.':'.'"'.$value['cn'].'('.$value['uid'].')'.'"'; 
     1192 
     1193             foreach ($groups as $value) 
     1194                 $optionsGroups[] = '"'.$value['gidNumber'].'"'.':'.'"'.$value['cn'].'('.$value['uid'].')'.'"'; 
     1195 
     1196             return "{".implode(',',$optionsUsers).implode(',',$optionsGroups)."}"; 
     1197        } 
     1198 
     1199   
    7351200        //Busca usuários e listas de um contexto e já retorna as options do select; 
    7361201        function get_available_users_and_maillist($params) 
    737         { 
     1202                        { 
     1203 
     1204             $ldapService = ServiceLocator::getService('ldap'); 
     1205             $users = $ldapService->accountSearch($params['sentence'], array('cn', 'mail','uid'), $params['context'], 'u', 'cn'); 
     1206             $listas = $ldapService->accountSearch($params['sentence'], array('cn', 'mail','uid'), $params['context'], 'l', 'cn'); 
     1207             $options = ''; 
     1208             if(count($listas) > 0) 
     1209                                { 
     1210                 $options .= '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('email lists').'&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n"; 
     1211                 foreach ($listas as  $value) 
     1212                    $options .= '<option value='.$value['mail'].'>'.$value['cn'].'('.$value['uid'].')</option>'; 
     1213                                } 
     1214 
     1215             if(count($users) > 0) 
     1216             { 
     1217                $options .= '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('users').'&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n"; 
     1218                foreach ($users as  $value) 
     1219                    $options .= '<option value='.$value['mail'].'>'.$value['cn'].'('.$value['uid'].')</option>'; 
     1220                        } 
     1221              
     1222             return $options; 
     1223                } 
     1224                 
     1225        function get_available_groups($params) 
     1226                { 
     1227//              $ldapService = ServiceLocator::getService('ldap'); 
     1228//              $entries = $ldapService->accountSearch($params['sentence'], array('cn', 'gidnumber'), $params['context'], 'g', 'cn'); 
     1229//              $options = ''; 
     1230//  
     1231//              foreach ($entries as  $value) 
     1232//                  $options .= '<option value='.$value['gidnumber'].'>'.$value['cn'].'</option>'; 
     1233                  
     1234            $entries = $this->get_available( $params, array( 'cn', 'gidNumber' ), 'g' ); 
     1235 
     1236             return $this->get_options( $entries, 'cn', 'gidnumber' ); 
     1237                } 
     1238                         
     1239        function get_available_maillists($params) 
     1240        { 
     1241                if ( !$ldapMasterConnect = $this->ldapMasterConnect() ) 
     1242                        return false; 
     1243                         
    7381244                $context = $params['context']; 
    739                 $recursive = $params['recursive']; 
    740                  
    741                 //Usado para retirar a própria lista das possibilidades de inclusão. 
    742                 $denied_uidnumber = $params['denied_uidnumber']; 
    743                  
    744                 $justthese = array("cn", "uidNumber", "mail"); 
    745                  
    746                 $users_filter="(phpgwAccountType=u)"; 
    747                 $lists_filter = $denied_uidnumber == '' ? "(phpgwAccountType=l)" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber)))"; 
    748                  
    749                 $users = Array(); 
    750                 $lists = Array();                
    751  
    752                 /* folling referral connection */ 
    753                 $ldap_conn_following_ref = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host']); 
    754                 if ($ldap_conn_following_ref) 
    755                 { 
    756                         ldap_set_option($ldap_conn_following_ref, LDAP_OPT_PROTOCOL_VERSION, 3); 
    757                         ldap_set_option($ldap_conn_following_ref, LDAP_OPT_REFERRALS, 1); 
    758  
    759                         if ( ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') ) 
    760                                 ldap_bind($ldap_conn_following_ref, $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'], $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw']); 
    761                 } 
    762                 else 
    763                         return false; 
    764  
    765                 if ($recursive == 'true') 
    766                         $users_search = ldap_search($ldap_conn_following_ref, $context, $users_filter, $justthese); 
    767                 else 
    768                         $users_search = ldap_list($ldap_conn_following_ref, $context, $users_filter, $justthese); 
    769  
    770                 /* email lists */ 
    771                 if($params['listSearch'] == 'true'){ 
    772                         if ($recursive == 'true') 
    773                                 $lists_search = ldap_search($ldap_conn_following_ref, $context, $lists_filter, $justthese);                      
    774                         else                     
    775                                 $lists_search = ldap_list($ldap_conn_following_ref, $context, $lists_filter, $justthese); 
    776  
    777                         $lists_entries = ldap_get_entries($ldap_conn_following_ref, $lists_search); 
    778  
    779                         for ($i=0; $i<$lists_entries["count"]; $i++) 
    780                         { 
    781                                 $l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0]; 
    782                         } 
    783  
    784                         if (count($l_tmp)) 
    785                                 natcasesort($l_tmp); 
    786  
    787                         $i = 0; 
    788                         $lists = array(); 
    789  
    790                         $options .= '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('email lists').'&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";         
    791                         if (count($l_tmp)) 
    792                         { 
    793                                 foreach ($l_tmp as $mail => $cn) 
    794                                 { 
    795                                         $options .= "<option value=$mail>$cn</option>"; 
    796                                 } 
    797                                 unset($l_tmp); 
    798                         } 
    799                 } 
    800                  
    801                 /* users */ 
    802                 $users_entries = ldap_get_entries($ldap_conn_following_ref, $users_search); 
    803                 for ($i=0; $i<$users_entries["count"]; $i++) 
    804                 { 
    805                         $u_tmp[$users_entries[$i]["mail"][0]] = $users_entries[$i]["cn"][0]; 
    806                 } 
    807                          
    808                 if (count($u_tmp)) 
    809                         natcasesort($u_tmp); 
    810                          
    811                 $i = 0; 
    812                 $users = array(); 
    813                  
    814                 $options .= '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('users').'&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n"; 
    815                          
    816                 if (count($u_tmp)) 
    817                 { 
    818                         foreach ($u_tmp as $mail => $cn) 
    819                         { 
    820                                 $options .= "<option value=$mail class='line-above'>$cn</option>"; 
    821                         } 
    822                         unset($u_tmp); 
    823                 } 
    824                  
    825                 ldap_close($ldap_conn_following_ref); 
     1245                $justthese = array("uid","mail","uidNumber"); 
     1246                $maillists=ldap_list($ldapMasterConnect, $context, ("(phpgwAccountType=l)"), $justthese); 
     1247                ldap_sort($ldapMasterConnect, $maillists, "uid"); 
     1248                 
     1249                $entries = ldap_get_entries($ldapMasterConnect, $maillists); 
     1250                         
     1251                $options = '';                   
     1252                for ($i=0; $i<$entries['count']; $i++) 
     1253                        { 
     1254                        $options .= "<option value=" . $entries[$i]['uid'][0] . ">" . $entries[$i]['uid'][0] . " (" . $entries[$i]['mail'][0] . ")" . "</option>"; 
     1255                } 
     1256                 
     1257        ldap_close($ldapMasterConnect); 
    8261258                return $options; 
    8271259        } 
    8281260 
    829         function get_available_groups($params) 
    830         { 
    831                 $context = $params['context']; 
    832                 $justthese = array("cn", "gidNumber"); 
    833         $groups_list=ldap_list($this->ldap, $context, ("(phpgwAccountType=g)"), $justthese); 
    834         ldap_sort($this->ldap, $groups_list, "cn"); 
     1261        function get_available_institutional_account($params) 
     1262        { 
     1263            if ( !$ldapMasterConnect = $this->ldapMasterConnect() ) 
     1264                    return false; 
     1265 
     1266            $filtro =utf8_encode($params['filter']); 
     1267            $context =utf8_encode($params['context']);//adicionado 
     1268            $justthese = array("uid","mail","uidNumber"); 
     1269            $maillists=ldap_list($ldapMasterConnect, $context, ("(&(phpgwAccountType=i)(mail=*$filtro*))"), $justthese); 
     1270            ldap_sort($ldapMasterConnect, $maillists, "uid"); 
    8351271         
    836         $entries = ldap_get_entries($this->ldap, $groups_list); 
     1272            $entries = ldap_get_entries($ldapMasterConnect, $maillists); 
    8371273                 
    8381274                $options = ''; 
    8391275                for ($i=0; $i<$entries['count']; $i++) 
    8401276                { 
    841                         $options .= "<option value=" . $entries[$i]['gidnumber'][0] . ">" . $entries[$i]['cn'][0] . "</option>"; 
     1277                            $options .= "<option value=" . $entries[$i]['mail'][0] . ">" . $entries[$i]['mail'][0] . "</option>"; 
    8421278                } 
    8431279         
     1280            ldap_close($ldapMasterConnect); 
     1281 
     1282 
    8441283        return $options;                 
    8451284        } 
    8461285         
    847         function get_available_maillists($params) 
     1286        function get_available_shared_account($params) 
    8481287        { 
    8491288                if ( !$ldapMasterConnect = $this->ldapMasterConnect() ) 
    8501289                        return false; 
    8511290                 
    852                 $context = $params['context']; 
     1291            $filtro =utf8_encode($params['filter']); 
     1292            $context =utf8_encode($params['context']);//adicionado 
    8531293                $justthese = array("uid","mail","uidNumber"); 
    854         $maillists=ldap_list($ldapMasterConnect, $context, ("(phpgwAccountType=l)"), $justthese); 
     1294            $maillists=ldap_search($ldapMasterConnect, $context, ("(&(phpgwAccountType=s)(mail=*$filtro*))"), $justthese); 
    8551295        ldap_sort($ldapMasterConnect, $maillists, "uid"); 
    8561296         
     
    8601300                for ($i=0; $i<$entries['count']; $i++) 
    8611301                { 
    862                         $options .= "<option value=" . $entries[$i]['uid'][0] . ">" . $entries[$i]['uid'][0] . " (" . $entries[$i]['mail'][0] . ")" . "</option>"; 
     1302                            $options .= "<option value=" . $entries[$i]['mail'][0] . ">" . $entries[$i]['mail'][0] . "</option>"; 
    8631303                } 
    8641304         
     
    11321572                                $result['departmentnumber']             = $entry[0]['departmentnumber'][0]; 
    11331573                                $result['givenname']                    = $entry[0]['givenname'][0]; 
    1134                                 $result['sn']                                   = $entry[0]['sn'][0]; 
     1574                                $result['sn']                                   = utf8_decode($entry[0]['sn'][0]); 
    11351575                                $result['telephonenumber']              = $entry[0]['telephonenumber'][0]; 
    11361576                                $result['passwd_expired']               = $entry[0]['phpgwlastpasswdchange'][0]; 
     
    11921632                        for ($i=0; $i<$entries['count']; $i++) 
    11931633                        { 
    1194                                 $result['groups_ldap'][ $entries[$i]['gidnumber'][0] ] = $entries[$i]['cn'][0]; 
     1634                                $result['groups_ldap'][ $entries[$i]['gidnumber'][0] ] = utf8_decode($entries[$i]['cn'][0]); 
     1635                        } 
     1636                        } 
     1637                } 
     1638                if (is_array($result)) 
     1639                        return $result; 
     1640                else 
     1641                        return false; 
     1642        } 
     1643 
     1644 
     1645        function get_user_cn_by_uid($uid) 
     1646        { 
     1647            foreach ($this->manager_contexts as $index=>$context) 
     1648            { 
     1649 
     1650                    $justthese = array("cn"); 
     1651                    $filter="(&(phpgwAccountType=u)(uid=".$uid."))"; 
     1652                    $search = ldap_search($this->ldap, $context, $filter, $justthese); 
     1653                    $entry = ldap_get_entries($this->ldap, $search); 
     1654                    if($entry) 
     1655                        return utf8_decode($entry[0]['cn'][0]); 
     1656            } 
     1657            return null; 
     1658        } 
     1659 
     1660        function get_group_cn_by_gidnumber($gidnumber) 
     1661        { 
     1662            foreach ($this->manager_contexts as $index=>$context) 
     1663                { 
     1664                 
     1665                    $justthese = array("cn"); 
     1666                    $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; 
     1667                    $search = ldap_search($this->ldap, $context, $filter, $justthese); 
     1668                    $entry = ldap_get_entries($this->ldap, $search); 
     1669                    if($entry) 
     1670                        return utf8_decode($entry[0]['cn'][0]); 
     1671                        } 
     1672            return null; 
     1673                } 
     1674                 
     1675         
     1676        function get_user_info_by_uid($uid) 
     1677        { 
     1678                foreach ($this->manager_contexts as $index=>$context) 
     1679                { 
     1680                        $filter="(&(phpgwAccountType=u)(uid=".$uid."))"; 
     1681                        $justthese = array("cn"); 
     1682                        $search = ldap_search($this->ldap, $context, $filter); 
     1683                        $entry = ldap_get_entries($this->ldap, $search); 
     1684                         
     1685                        if ($entry['count']) 
     1686                        { 
     1687                                //Pega o dn do setor do usuario. 
     1688                                $entry[0]['dn'] = strtolower($entry[0]['dn']); 
     1689                                $sector_dn_array = explode(",", $entry[0]['dn']); 
     1690                                for($i=1; $i<count($sector_dn_array); $i++) 
     1691                                        $sector_dn .= $sector_dn_array[$i] . ','; 
     1692                                //Retira ultimo pipe. 
     1693                                $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); 
     1694                 
     1695                                $result['context']                              = $sector_dn; 
     1696                                $result['uid']                                  = $entry[0]['uid'][0]; 
     1697                                $result['cn']                                   = utf8_decode($entry[0]['cn'][0]); 
     1698                                $result['uidnumber']                    = $entry[0]['uidnumber'][0]; 
     1699                                $result['gidnumber']                    = $entry[0]['gidnumber'][0]; 
     1700                                $result['departmentnumber']             = $entry[0]['departmentnumber'][0]; 
     1701                                $result['givenname']                    = $entry[0]['givenname'][0]; 
     1702                                $result['sn']                                   = $entry[0]['sn'][0]; 
     1703                                $result['telephonenumber']              = $entry[0]['telephonenumber'][0]; 
     1704                                $result['passwd_expired']               = $entry[0]['phpgwlastpasswdchange'][0]; 
     1705                                $result['phpgwaccountstatus']   = $entry[0]['phpgwaccountstatus'][0]; 
     1706                                $result['phpgwaccountvisible']  = $entry[0]['phpgwaccountvisible'][0]; 
     1707                                $result['accountstatus']                = $entry[0]['accountstatus'][0]; 
     1708                                $result['mail']                                 = $entry[0]['mail'][0]; 
     1709                                $result['mailalternateaddress'] = $entry[0]['mailalternateaddress']; 
     1710                                $result['mailforwardingaddress']= $entry[0]['mailforwardingaddress']; 
     1711                                $result['deliverymode']                 = $entry[0]['deliverymode'][0]; 
     1712                                $result['userPasswordRFC2617']  = $entry[0]['userpasswordrfc2617'][0]; 
     1713 
     1714                                //Photo 
     1715                                if ($entry[0]['jpegphoto']['count'] == 1) 
     1716                                        $result['photo_exist'] = 'true'; 
     1717                 
     1718                                // Samba 
     1719                                for ($i=0; $i<$entry[0]['objectclass']['count']; $i++) 
     1720                                { 
     1721                                        if ($entry[0]['objectclass'][$i] == 'sambaSamAccount') 
     1722                                                $result['sambaUser'] = true; 
     1723                                } 
     1724                                if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($result['sambaUser'])) 
     1725                                { 
     1726                                        $result['sambaaccflags'] = $entry[0]['sambaacctflags'][0]; 
     1727                                        $result['sambalogonscript'] = $entry[0]['sambalogonscript'][0]; 
     1728                                        $result['homedirectory'] = $entry[0]['homedirectory'][0]; 
     1729                                        $a_tmp = explode("-", $entry[0]['sambasid'][0]); 
     1730                                        array_pop($a_tmp); 
     1731                                        $result['sambasid'] = implode("-", $a_tmp); 
     1732                                } 
     1733 
     1734                                // Verifica o acesso do gerente aos atributos corporativos 
     1735                                if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'manipulate_corporative_information')) 
     1736                                { 
     1737                                        $result['corporative_information_employeenumber']= $entry[0]['employeenumber'][0]; 
     1738                                        $result['corporative_information_cpf']                  = $entry[0]['cpf'][0]; 
     1739                                        $result['corporative_information_rg']                   = $entry[0]['rg'][0]; 
     1740                                        $result['corporative_information_rguf']                 = $entry[0]['rguf'][0]; 
     1741                                        $result['corporative_information_description']  = utf8_decode($entry[0]['description'][0]); 
     1742                                } 
     1743                                 
     1744                                // MailLists 
     1745                                $result['maillists_info'] = $this->get_user_maillists($result['mail']); 
     1746                                if($result['maillists_info']) 
     1747                                { 
     1748                                        foreach ($result['maillists_info'] as $maillist) 
     1749                                        { 
     1750                                                $result['maillists'][] = $maillist['uid']; 
     1751                                        } 
     1752                                } 
     1753                                 
     1754                                // Groups 
     1755                                $justthese = array("gidnumber","cn"); 
     1756                                $filter="(&(phpgwAccountType=g)(memberuid=".$result['uid']."))"; 
     1757                                $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     1758                        ldap_sort($this->ldap, $search, "cn"); 
     1759                        $entries = ldap_get_entries($this->ldap, $search); 
     1760                        for ($i=0; $i<$entries['count']; $i++) 
     1761                        { 
     1762                                $result['groups_ldap'][ $entries[$i]['gidnumber'][0] ] = utf8_decode($entries[$i]['cn'][0]); 
    11951763                        } 
    11961764                        } 
     
    12401808        } 
    12411809         
    1242         function get_group_info($gidnumber,$use_global_context=false) 
    1243         { 
    1244                 $array_context = $use_global_context ? Array(0 => $GLOBALS['phpgw_info']['server']['ldap_context']) : $this->manager_contexts; 
    1245                 foreach ($array_context as $index=>$context) 
     1810        function get_group_info($gidnumber) 
     1811        { 
     1812                foreach ($this->manager_contexts as $index=>$context) 
    12461813                { 
    12471814                        $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; 
     
    12721839                         
    12731840                                        // Montagem dinamica do filtro 
    1274                                         $filter="(&(phpgwAccountType=u)(|"; 
     1841                                        $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s))(|"; 
    12751842                                        for ($k=0; (($k<10) && ($i<$entry[0]['memberuid']['count'])); $k++) 
    12761843                                        { 
     
    14752042                if (count($gidnumbers)) 
    14762043                { 
    1477                         $justthese = array("cn"); 
     2044                        $justthese = array("cn","uid"); 
    14782045                        $i = 0; 
    14792046                        foreach ($gidnumbers as $gidnumber) 
     
    14872054                                         
    14882055                                else 
     2056                                { 
     2057                                        $result['groups_info'][$i]['uid'] = $entry[0]['uid'][0]; 
    14892058                                        $result['groups_info'][$i]['cn'] = $entry[0]['cn'][0]; 
     2059                                } 
    14902060                                $result['groups_info'][$i]['gidnumber'] = $gidnumber; 
    14912061                         
     
    15102080        { 
    15112081                $justthese = array("uid"); 
    1512                 $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uidNumber=".$uidnumber."))"; 
     2082                $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=l))(uidNumber=".$uidnumber."))"; 
    15132083                $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
    15142084                $entry = ldap_get_entries($this->ldap, $search); 
     
    15222092                $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
    15232093                $entry = ldap_get_entries($this->ldap, $search); 
    1524                 return $entry[0]['cn'][0]; 
     2094                return utf8_decode($entry[0]['cn'][0]); 
     2095        } 
     2096 
     2097        function uid2uidnumber($uid) 
     2098        { 
     2099                $justthese = array("uidNumber"); 
     2100                $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=l))(uid=".$uid."))"; 
     2101                $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     2102                $entry = ldap_get_entries($this->ldap, $search); 
     2103                return $entry[0]['uidnumber'][0]; 
    15252104        } 
    15262105 
     
    19472526                $search = ldap_search($this->ldap, $context, $filter, $justthese); 
    19482527            $count_entries = ldap_count_entries($this->ldap, $search); 
    1949              
     2528                 
    19502529            if ($count_entries > 0) 
    19512530                return true; 
    19522531            else 
    19532532                return false; 
    1954         } 
    1955          
     2533                } 
     2534                 
    19562535        function add_sambadomain($sambadomainname, $sambasid, $context) 
    19572536        { 
     
    19652544                 
    19662545                if (!@ldap_add ( $this->ldap, $dn, $entry )) 
    1967                 { 
     2546                        { 
    19682547                        $return['status'] = false; 
    19692548                        $result['msg'] = $this->functions->lang('Error on function') . " ldap_functions->add_sambadomain ($dn)" . ".\n" . $this->functions->lang('Server returns') . ': ' . ldap_error($this->ldap); 
     
    19742553                return $return; 
    19752554        } 
    1976          
     2555                 
    19772556        function delete_sambadomain($sambadomainname) 
    19782557        { 
     
    19812560                $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter); 
    19822561            $entry = ldap_get_entries($this->ldap, $search); 
    1983           
     2562                 
    19842563                if ($entry['count'] != 0) 
    1985             { 
     2564                { 
    19862565                        $dn = $entry[0]['dn']; 
    19872566                         
     
    19912570                                $result['msg'] = $this->functions->lang('Error on function') . " ldap_functions->delete_sambadomain ($sambadomainname)" . ".\n" . $this->functions->lang('Server returns') . ': ' . ldap_error($this->ldap); 
    19922571                        } 
    1993             } 
    1994              
     2572                } 
     2573                 
    19952574                return $return; 
    19962575        } 
    19972576         
    19982577        function search_user($params) 
    1999         { 
    2000                 $search = $params['search']; 
    2001                 $justthese = array("cn","uid", "mail"); 
    2002         $users_list=ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], "(&(phpgwAccountType=u) (|(cn=*$search*)(mail=$search*)) )", $justthese); 
    2003          
    2004         if (ldap_count_entries($this->ldap, $users_list) == 0) 
    2005         { 
    2006                 $return['status'] = 'false'; 
    2007                 $result['msg'] = $this->functions->lang('Any result was found') . '.'; 
    2008                 return $return; 
    2009         } 
    2010          
    2011         ldap_sort($this->ldap, $users_list, "cn"); 
    2012          
    2013         $entries = ldap_get_entries($this->ldap, $users_list); 
    2014                  
    2015                 $options = ''; 
    2016                 for ($i=0; $i<$entries['count']; $i++) 
    2017                 { 
    2018                         $options .= "<option value=" . $entries[$i]['uid'][0] . ">" . $entries[$i]['cn'][0] . " (".$entries[$i]['mail'][0].")" . "</option>"; 
    2019                 } 
    2020          
     2578                { 
     2579             $ldapService = ServiceLocator::getService('ldap'); 
     2580             $entries = $ldapService->accountSearch($params['search'], array('cn','uid', "mail"), $params['context'], 'u', 'cn'); 
     2581 
     2582             if (count($entries) == 0) 
     2583             { 
     2584                    $return['status'] = 'false'; 
     2585                    $return['msg'] = $this->functions->lang('Any result was found') . '.'; 
     2586                    return $return; 
     2587                } 
     2588             $options = ''; 
     2589 
     2590             foreach ($entries as  $value) 
     2591                 $options .= '<option value='.$value['uid'].'>'.$value['cn'].'('.$value['mail'].')'.'</option>'; 
     2592     
    20212593        return $options;                 
    2022         } 
    2023          
    2024         function create_institutional_accounts($params) 
    2025         { 
    2026                 /* Begin: Access verification */ 
    2027                 if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'add_institutional_accounts')) 
    2028                 { 
    2029                         $return['status'] = false; 
    2030                         $return['msg'] = $this->functions->lang('You do not have right to create institutional accounts') . "."; 
    2031                         return $return; 
    2032                 } 
    2033                  
    2034                 $access_granted = false; 
    2035                 foreach ($this->manager_contexts as $idx=>$manager_context) 
    2036                 { 
    2037                         if (stristr($params['context'], $manager_context)) 
    2038                         { 
    2039                                 $access_granted = true; 
    2040                                 break; 
    2041                         } 
    2042                 } 
    2043                 if (!$access_granted) 
    2044                 { 
    2045                         $return['status'] = false; 
    2046                         $return['msg'] = $this->functions->lang('You do not have access to this organization') . "."; 
    2047                         return $return; 
    2048                 } 
    2049                 /* End: Access verification */ 
    2050  
    2051                 /* Begin: Validation */ 
    2052                 if ( (empty($params['cn'])) || (empty($params['mail'])) ) 
    2053                 { 
    2054                         $result['status'] = false; 
    2055                         $result['msg']  = $this->functions->lang('Field mail or name is empty'); 
    2056                         return $result; 
    2057                 } 
    2058  
    2059                 if (! eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $params['mail']) ) 
    2060                 { 
    2061                         $result['status'] = false; 
    2062                         $result['msg']  = $this->functions->lang('Field mail is not formed correcty') . '.'; 
    2063                         return $result; 
    2064                 } 
    2065  
    2066                 $uid = 'institutional_account_' . $params['mail']; 
    2067                 $dn = "uid=$uid," . $params['context']; 
    2068  
    2069                 $filter = "(mail=".$params['mail'].")"; 
    2070                 $justthese = array("cn"); 
    2071                 $search = @ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
    2072                 $entries = @ldap_get_entries($this->ldap,$search); 
    2073                 if ($entries['count'] != 0) 
    2074                 { 
    2075                         $result['status'] = false; 
    2076                         $result['msg'] = $this->functions->lang('Field mail already in use'); 
    2077                         return $result; 
    2078                 } 
    2079                 /* End: Validation */ 
    2080                                                  
    2081                 $info = array(); 
    2082                 $info['cn']                                     = iconv("ISO-8859-1","UTF-8//TRANSLIT",$params['cn']); 
    2083                 $info['sn']                                     = iconv("ISO-8859-1","UTF-8//TRANSLIT",$params['cn']); 
    2084                 $info['uid']                            = $uid; 
    2085                 $info['mail']                           = $params['mail']; 
    2086                 $info['description']            = iconv("ISO-8859-1","UTF-8//TRANSLIT",$params['desc']); 
    2087                 $info['phpgwAccountType']       = 'i'; 
    2088                 $info['objectClass'][]          = 'inetOrgPerson'; 
    2089                 $info['objectClass'][]          = 'phpgwAccount'; 
    2090                 $info['objectClass'][]          = 'top'; 
    2091                 $info['objectClass'][]          = 'person'; 
    2092                 $info['objectClass'][]          = 'qmailUser'; 
    2093                 $info['objectClass'][]          = 'organizationalPerson'; 
    2094                  
    2095                 if ($params['accountStatus'] == 'on') 
    2096                 { 
    2097                         $info['accountStatus'] = 'active'; 
    2098                 } 
    2099                 if ($params['phpgwAccountVisible'] == 'on') 
    2100                 { 
    2101                         $info['phpgwAccountVisible'] = '-1'; 
    2102                 } 
    2103                  
    2104                 if (!empty($params['owners'])) 
    2105                 { 
    2106                         foreach($params['owners'] as $index=>$uidnumber) 
    2107                         { 
    2108                                 $info['mailForwardingAddress'][] = $this->uidnumber2mail($uidnumber); 
    2109                         } 
    2110                 }                
    2111                  
    2112                 $result = array(); 
    2113                 if (!@ldap_add ( $this->ldap, $dn, $info )) 
    2114                 { 
    2115                         $result['status'] = false; 
    2116                         $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->create_institutional_accounts'; 
    2117                         $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
    2118                 } 
    2119                 else 
    2120                         $result['status'] = true; 
    2121                  
    2122                 return $result; 
    2123         } 
    2124          
    2125         function save_institutional_accounts($params) 
    2126         { 
    2127                 /* Begin: Access verification */ 
    2128                 if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'edit_institutional_accounts')) 
    2129                 { 
    2130                         $return['status'] = false; 
    2131                         $return['msg'] = $this->functions->lang('You do not have right to edit institutional accounts') . "."; 
    2132                         return $return; 
    2133                 } 
    2134                 $access_granted = false; 
    2135                 foreach ($this->manager_contexts as $idx=>$manager_context) 
    2136                 { 
    2137                         if (stristr($params['context'], $manager_context)) 
    2138                         { 
    2139                                 $access_granted = true; 
    2140                                 break; 
    2141                         } 
    2142                 } 
    2143                 if (!$access_granted) 
    2144                 { 
    2145                         $return['status'] = false; 
    2146                         $return['msg'] = $this->functions->lang('You do not have access to this organization') . "."; 
    2147                         return $return; 
    2148                 } 
    2149                 /* End: Access verification */ 
    2150                  
    2151                 /* Begin: Validation */ 
    2152                 if ( (empty($params['cn'])) || (empty($params['mail'])) ) 
    2153                 { 
    2154                         $result['status'] = false; 
    2155                         $result['msg']  = $this->functions->lang('Field mail or name is empty') . '.'; 
    2156                         return $result; 
    2157                 } 
    2158  
    2159                 if (! eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $params['mail']) ) 
    2160                 { 
    2161                         $result['status'] = false; 
    2162                         $result['msg']  = $this->functions->lang('Field mail is not formed correcty') . '.'; 
    2163                         return $result; 
    2164                 } 
    2165  
    2166                 $uid = 'institutional_account_' . $params['mail']; 
    2167                 $dn = strtolower("uid=$uid," . $params['context']); 
    2168                 $anchor = strtolower($params['anchor']); 
    2169  
    2170                 $filter = "(mail=".$params['mail'].")"; 
    2171                 $justthese = array("cn"); 
    2172                 $search = @ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
    2173                 $entries = @ldap_get_entries($this->ldap,$search); 
    2174                  
    2175                 if ( ($entries['count'] > 1) || (($entries['count'] == 1) && ($entries[0]['dn'] != $anchor)) ) 
    2176                 { 
    2177                         $result['status'] = false; 
    2178                         $result['msg'] = $this->functions->lang('Field mail already in use.'); 
    2179                         return $result; 
    2180                 } 
    2181                 /* End: Validation */ 
    2182                  
    2183                 $result = array(); 
    2184                 $result['status'] = true; 
    2185                  
    2186                 if ($anchor != $dn) 
    2187                 { 
    2188                         if (!@ldap_rename($this->ldap, $anchor, "uid=$uid", $params['context'], true)) 
    2189                         { 
    2190                                 $result['status'] = false; 
    2191                                 $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->save_institutional_accounts: ldap_rename'; 
    2192                                 $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
    2193                         } 
    2194                 } 
    2195                  
    2196                 $info = array(); 
    2197                 $info['cn']                                     = $params['cn']; 
    2198                 $info['sn']                                     = $params['cn']; 
    2199                 $info['uid']                            = $uid; 
    2200                 $info['mail']                           = $params['mail']; 
    2201                  
    2202                 if ($params['accountStatus'] == 'on') 
    2203                         $info['accountStatus'] = 'active'; 
    2204                 else 
    2205                         $info['accountStatus'] = array(); 
    2206                  
    2207                 if ($params['phpgwAccountVisible'] == 'on') 
    2208                         $info['phpgwAccountVisible'] = '-1'; 
    2209                 else 
    2210                         $info['phpgwAccountVisible'] = array(); 
    2211                  
    2212                 if ($params['desc'] != '') 
    2213                         $info['description'] = utf8_encode($params['desc']); 
    2214                 else 
    2215                         $info['description'] = array(); 
    2216                  
    2217                 if (!empty($params['owners'])) 
    2218                 { 
    2219                         foreach($params['owners'] as $index=>$uidnumber) 
    2220                         { 
    2221                                 $mailForwardingAddress = $this->uidnumber2mail($uidnumber); 
    2222                                 if ($mailForwardingAddress != '') 
    2223                                         $info['mailForwardingAddress'][] = $mailForwardingAddress; 
    2224                         } 
    2225                 } 
    2226                 else 
    2227                         $info['mailForwardingAddress'] = array(); 
    2228                  
    2229                 if (!@ldap_modify ( $this->ldap, $dn, $info )) 
    2230                 { 
    2231                         $result['status'] = false; 
    2232                         $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->save_institutional_accounts: ldap_modify'; 
    2233                         $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
    2234                 } 
    2235  
    2236                 return $result; 
    22372594        } 
    22382595         
     
    22572614                        for ($i=0; $i<$entries['count']; $i++) 
    22582615                        { 
    2259                                 $tr = "<tr class='normal' onMouseOver=this.className='selected' onMouseOut=this.className='normal'><td onClick=edit_institutional_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['cn'][0] . "</td><td onClick=edit_institutional_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['mail'][0] . "</td><td align='center' onClick=delete_institutional_accounts('".$entries[$i]['uid'][0]."')><img HEIGHT='16' WIDTH='16' src=./expressoAdmin1_2/templates/default/images/delete.png></td></tr>"; 
    2260                                 $trs[$tr] = $entries[$i]['cn'][0]; 
     2616                                $tr = "<tr class='normal' onMouseOver=this.className='selected' onMouseOut=this.className='normal'><td onClick=edit_institutional_account('".$entries[$i]['uid'][0]."')>" . utf8_decode($entries[$i]['cn'][0]) . "</td><td onClick=edit_institutional_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['mail'][0] . "</td><td align='center' onClick=delete_institutional_accounts('".$entries[$i]['uid'][0]."')><img HEIGHT='16' WIDTH='16' src=./expressoAdmin1_2/templates/default/images/delete.png></td></tr>"; 
     2617                                $trs[$tr] = utf8_decode($entries[$i]['cn'][0]); 
    22612618                        } 
    22622619                } 
     
    22992656                else 
    23002657                { 
    2301                         $tmp_user_context = split(",", $entrie[0]['dn']); 
     2658                        $tmp_user_context = split(",", utf8_decode($entrie[0]['dn'])); 
    23022659                        $tmp_reverse_user_context = array_reverse($tmp_user_context); 
    23032660                        array_pop($tmp_reverse_user_context); 
     
    23072664                        $return['accountStatus']                = $entrie[0]['accountstatus'][0]; 
    23082665                        $return['phpgwAccountVisible']  = $entrie[0]['phpgwaccountvisible'][0]; 
    2309                         $return['cn']                                   = $entrie[0]['cn'][0]; 
     2666                        $return['cn']                                   = utf8_decode($entrie[0]['cn'][0]); 
    23102667                        $return['mail']                                 = $entrie[0]['mail'][0]; 
    23112668                        $return['description']                  = utf8_decode($entrie[0]['description'][0]); 
     
    23192676                                        if (!$tmp) {} 
    23202677                                        else 
    2321                                                 $a_cn[$tmp['uidnumber']] = $tmp['cn']; 
     2678                                                $a_cn[$tmp['uidnumber']] = $tmp['cn'].'('.$tmp['uid'].')'; 
    23222679                                } 
    23232680                                natcasesort($a_cn); 
     
    23412698 
    23422699                $input = $params['input']; 
    2343                 $justthese = array("cn", "mail", "uid"); 
     2700                $justthese = array("cn", "dn", "mail", "uid"); 
    23442701                $trs = array(); 
    23452702                                 
     
    23512708                        for ($i=0; $i<$entries['count']; $i++) 
    23522709                        { 
    2353                                 $tr = "<tr class='normal' onMouseOver=this.className='selected' onMouseOut=this.className='normal'><td onClick=edit_shared_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['cn'][0] . "</td><td onClick=edit_shared_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['mail'][0] . "</td><td align='center' onClick=delete_shared_accounts('".$entries[$i]['uid'][0]."')><img HEIGHT='16' WIDTH='16' src=./expressoAdmin1_2/templates/default/images/delete.png></td></tr>"; 
    2354                                 $trs[$tr] = $entries[$i]['cn'][0]; 
     2710                                $tr = "<tr class='normal' onMouseOver=this.className='selected' onMouseOut=this.className='normal'><td onClick=edit_shared_account('".$entries[$i]['uid'][0]."')>" . utf8_decode($entries[$i]['cn'][0]) . "</td><td onClick=edit_shared_account('".$entries[$i]['uid'][0]."')>" . utf8_decode($entries[$i]['cn'][0]). " (" . $entries[$i]['uid'][0] . ")" . "</td><td onClick=edit_shared_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['mail'][0] . "<td align='center' onClick=delete_shared_accounts('".$entries[$i]['uid'][0]."')><img HEIGHT='16' WIDTH='16' src=./expressoAdmin1_2/templates/default/images/delete.png></td></tr>"; 
     2711                                $trs[$tr] = utf8_decode($entries[$i]['cn'][0]); 
    23552712                        } 
    23562713                } 
     
    23712728        } 
    23722729         
    2373         function save_shared_accounts($params) 
    2374         { 
    2375                         /* Begin: Access verification */ 
    2376                         if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'edit_shared_accounts')) 
    2377                         { 
    2378                                 $return['status'] = false; 
    2379                                 $return['msg'] = $this->functions->lang('You do not have right to edit shared accounts') . "."; 
    2380                                 return $return; 
    2381                         } 
    2382                         $access_granted = false; 
    2383                         foreach ($this->manager_contexts as $idx=>$manager_context) 
    2384                         { 
    2385                                 if (stristr($params['context'], $manager_context)) 
    2386                                 { 
    2387                                         $access_granted = true; 
    2388                                         break; 
    2389                                 } 
    2390                         } 
    2391                         if (!$access_granted) 
    2392                         { 
    2393                                 $return['status'] = false; 
    2394                                 $return['msg'] = $this->functions->lang('You do not have access to this organization') . "."; 
    2395                                 return $return; 
    2396                         } 
    2397                         /* End: Access verification */ 
    2398                          
    2399                         /* Begin: Validation */ 
    2400                         if ( (empty($params['cn'])) || (empty($params['mail'])) ) 
    2401                         { 
    2402                                 $result['status'] = false; 
    2403                                 $result['msg']  = $this->functions->lang('Field mail or name is empty') . '.'; 
    2404                                 return $result; 
    2405                         } 
    2406          
    2407                         if (! eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $params['mail']) ) 
    2408                         { 
    2409                                 $result['status'] = false; 
    2410                                 $result['msg']  = $this->functions->lang('Field mail is not formed correcty') . '.'; 
    2411                                 return $result; 
    2412                         }                        
    2413                          
    2414                         $dn = strtolower("uid=$params[uid]," . $params['context']); 
    2415                         $anchor = strtolower($params['anchor']); 
    2416                          
    2417                         $filter = "(mail=".$params['mail'].")"; 
    2418                         $justthese = array("cn"); 
    2419                         $search = @ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
    2420                         $entries = @ldap_get_entries($this->ldap,$search); 
    2421                          
    2422                         if ( ($entries['count'] > 1) || (($entries['count'] == 1) && ($entries[0]['dn'] != $anchor)) ) 
    2423                         { 
    2424                                 $result['status'] = false; 
    2425                                 $result['msg'] = $this->functions->lang('Field mail already in use.'); 
    2426                                 return $result; 
    2427                         } 
    2428                         /* End: Validation */ 
    2429  
    2430                         $result = array(); 
    2431                         $result['status'] = true; 
    2432                          
    2433                         if ($anchor != $dn) 
    2434                         { 
    2435                                 if (!@ldap_rename($this->ldap, $anchor, "uid=$params[uid]", $params['context'], true)) 
    2436                                 { 
    2437                                         $result['status'] = false; 
    2438                                         $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->save_shared_accounts: ldap_rename'; 
    2439                                         $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
    2440                                 } 
    2441                         } 
    2442                          
    2443                         $info = array(); 
    2444                         $info['cn']                                     = $params['cn']; 
    2445                         $info['sn']                                     = $params['cn']; 
    2446                         $info['uid']                            = $params['uid']; 
    2447                         $info['mail']                           = $params['mail']; 
    2448                          
    2449                         if ($params['accountStatus'] == 'on') 
    2450                                 $info['accountStatus'] = 'active'; 
    2451                         else 
    2452                                 $info['accountStatus'] = array(); 
    2453                          
    2454                         if ($params['phpgwAccountVisible'] == 'on') 
    2455                                 $info['phpgwAccountVisible'] = '-1'; 
    2456                         else 
    2457                                 $info['phpgwAccountVisible'] = array(); 
    2458                          
    2459                         if ($params['desc'] != '') 
    2460                                 $info['description'] = utf8_encode($params['desc']); 
    2461                         else 
    2462                                 $info['description'] = array(); 
    2463                          
    2464                         if (!@ldap_modify ( $this->ldap, $dn, $info )) 
    2465                         { 
    2466                                 $result['status'] = false; 
    2467                                 $result['msg']  = $this->functions->lang('Error on function') . ' ldap_functions->save_shared_accounts: ldap_modify'; 
    2468                                 $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap); 
    2469                         } 
    2470                         //print_r($info);echo "Teste $dn".$result['msg'];exit(); 
    2471                         return $result; 
    2472         }        
    2473          
    24742730        function get_shared_account_data($params) 
    24752731        { 
     
    25012757                        $return['status'] = 'true'; 
    25022758                        $return['accountStatus']                = $entrie[0]['accountstatus'][0]; 
     2759 
    25032760                        $return['phpgwAccountVisible']  = $entrie[0]['phpgwaccountvisible'][0]; 
    2504                         $return['cn']                                   = $entrie[0]['cn'][0]; 
     2761                        $return['cn']                   = utf8_decode($entrie[0]['cn'][0]); 
    25052762                        $return['mail']                                 = $entrie[0]['mail'][0]; 
    25062763                        $return['description']                  = utf8_decode($entrie[0]['description'][0]); 
    2507                          
    2508                 } 
     2764                        $return['dn']                   = utf8_decode($entrie[0]['dn']); 
     2765                        $return['mailalternateaddress'] = $entrie[0]['mailalternateaddress']; 
     2766                } 
     2767                 
     2768 
     2769                 
    25092770                 
    25102771                return $return; 
     
    25122773        function mailforwardingaddress2uidnumber($mail) 
    25132774        { 
    2514                 $justthese = array("uidnumber","cn"); 
     2775                $justthese = array("uidnumber","cn", "uid"); 
    25152776        $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], ("(&(phpgwAccountType=u)(mail=$mail))"), $justthese); 
    25162777        $entrie = ldap_get_entries($this->ldap, $search); 
     
    25202781                { 
    25212782                        $return['uidnumber'] = $entrie[0]['uidnumber'][0]; 
    2522                         $return['cn'] = $entrie[0]['cn'][0]; 
     2783                        $return['cn'] = utf8_decode($entrie[0]['cn'][0]); 
     2784                        $return['uid'] = $entrie[0]['uid'][0]; 
     2785                        return $return; 
     2786                } 
     2787        } 
     2788 
     2789        function uid2mailforwardingaddress($uid) 
     2790        { 
     2791                $justthese = array("mail"); 
     2792        $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], ("(&(phpgwAccountType=u)(uid=$uid))"), $justthese); 
     2793        $entrie = ldap_get_entries($this->ldap, $search); 
     2794                if ($entrie['count'] != 1) 
     2795                        return false; 
     2796                else 
     2797                { 
     2798                        $return['mail'] = $entrie[0]['mail'][0]; 
    25232799                        return $return; 
    25242800                } 
     
    25532829                }                
    25542830                 
    2555                 $dn = $entrie[0]['dn']; 
     2831                $dn = utf8_decode($entrie[0]['dn']); 
    25562832                if (!@ldap_delete($this->ldap, $dn)) 
    25572833                { 
     
    26292905        } 
    26302906 
    2631         function search_available_users_and_maillist($params) 
    2632         { 
    2633                 $context = $params['context']; 
    2634                 $recursive = $params['recursive']; 
    2635                  $filtro =utf8_encode($params['filter']); 
    2636                 //Usado para retirar a própria lista das possibilidades de inclusão. 
    2637                 $denied_uidnumber = $params['denied_uidnumber']; 
    2638                  
    2639                 $justthese = array("cn", "uidNumber", "mail");                           
    2640                  
    2641                 $users_filter="(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1))(phpgwaccountstatus=A)(|(cn=*$filtro*)(mail=$filtro*)))"; 
    2642                 $lists_filter = $denied_uidnumber == '' ? "(&(phpgwAccountType=l)(cn=*$filtro*))" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber))(|(cn=*$filtro*)(mail=$filtro*)))"; 
    2643                  
    2644                 $users = Array(); 
    2645                 $lists = Array();                
    2646  
    2647                 /* folling referral connection */ 
    2648                 $ldap_conn_following_ref = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host']); 
    2649                 if ($ldap_conn_following_ref) 
    2650                 { 
    2651                         ldap_set_option($ldap_conn_following_ref, LDAP_OPT_PROTOCOL_VERSION, 3); 
    2652                         ldap_set_option($ldap_conn_following_ref, LDAP_OPT_REFERRALS, 1); 
    2653  
    2654                         if ( ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') ) 
    2655                                 ldap_bind($ldap_conn_following_ref, $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'], $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw']); 
    2656                 } 
    2657                 else 
    2658                         return false; 
    2659                  
    2660                 if ($recursive == 'true') 
    2661                         $users_search = ldap_search($ldap_conn_following_ref, $context, $users_filter, $justthese); 
    2662                 else 
    2663                         $users_search = ldap_list($ldap_conn_following_ref, $context, $users_filter, $justthese); 
    2664                  
    2665                 /* email lists */ 
    2666                 if($params['listSearch'] == 'true'){ 
    2667                         if ($recursive == 'true') 
    2668                                 $lists_search = ldap_search($ldap_conn_following_ref, $context, $lists_filter, $justthese);                      
    2669                         else                     
    2670                                 $lists_search = ldap_list($ldap_conn_following_ref, $context, $lists_filter, $justthese); 
    2671                                  
    2672                         $lists_entries = ldap_get_entries($ldap_conn_following_ref, $lists_search); 
    2673                          
    2674                         for ($i=0; $i<$lists_entries["count"]; $i++) 
    2675                         { 
    2676                                 $l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0]; 
    2677                         } 
    2678                                  
    2679                         if (count($l_tmp)) 
    2680                                 natcasesort($l_tmp); 
    2681                                  
    2682                         $i = 0; 
    2683                         $lists = array(); 
    2684                          
    2685                         $options .= '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('email lists').'&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";         
    2686                         if (count($l_tmp)) 
    2687                         { 
    2688                                 foreach ($l_tmp as $mail => $cn) 
    2689                                 { 
    2690                                         $options .= "<option value=$mail>$cn</option>"; 
    2691                                 } 
    2692                                 unset($l_tmp); 
    2693                         } 
    2694                 } 
    2695                  
    2696                 /* users */ 
    2697                 $users_entries = ldap_get_entries($ldap_conn_following_ref, $users_search); 
    2698                 for ($i=0; $i<$users_entries["count"]; $i++) 
    2699                 { 
    2700                         $u_tmp[$users_entries[$i]["mail"][0]] = $users_entries[$i]["cn"][0]; 
    2701                 } 
    2702                          
    2703                 if (count($u_tmp)) 
    2704                         natcasesort($u_tmp); 
    2705                          
    2706                 $i = 0; 
    2707                 $users = array(); 
    2708                  
    2709                 $options .= '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('users').'&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n"; 
    2710                          
    2711                 if (count($u_tmp)) 
    2712                 { 
    2713                         foreach ($u_tmp as $mail => $cn) 
    2714                         { 
    2715                                 $options .= "<option value=$mail class='line-above'>$cn</option>"; 
    2716                         } 
    2717                         unset($u_tmp); 
    2718                 } 
    2719                  
    2720                 ldap_close($ldap_conn_following_ref); 
    2721                 return $options; 
    2722         } 
     2907                 
    27232908 
    27242909} 
Note: See TracChangeset for help on using the changeset viewer.