Ignore:
Timestamp:
01/04/10 15:23:37 (14 years ago)
Author:
valmir.sena
Message:

Ticket #849 - Criacao de caixas compartilhadas pelo administrador, commit inicial com as principais mudancas

File:
1 edited

Legend:

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

    r1523 r1913  
    126126        } 
    127127         
    128         function delete_user($uid) 
     128        function delete_mailbox($uid) 
    129129        { 
    130130                $result['status'] = true; 
     
    137137                { 
    138138                        $result['status'] = false; 
    139                         $result['msg'] = $this->functions->lang('it was not possible to delete users mailbox') . ".\n"; 
     139                        $result['msg'] = $this->functions->lang('it was not possible to delete mailbox') . ".\n"; 
    140140                        $result['msg'] .= $this->functions->lang('Server returns') . ': ' . imap_last_error(); 
    141141                } 
     
    193193                return $result; 
    194194        } 
    195          
     195        function empty_user_inbox($params){ 
     196               if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox')) 
     197                { 
     198                        $result['status'] = false; 
     199                        $result['msg'] = $this->functions->lang('You do not have access to clean an user inbox'); 
     200                        return $result; 
     201                } else return $this->empty_inbox($params); 
     202                 
     203        } 
     204        function empty_shared_account_inbox($params){ 
     205            if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_shared_accounts_inbox')) 
     206                { 
     207                        $result['status'] = false; 
     208                        $result['msg'] = $this->functions->lang('You do not have right to empty an shared account inbox'); 
     209                        return $result; 
     210                } else return $this->empty_inbox($params); 
     211        } 
    196212        function empty_inbox($params) 
    197213        { 
    198214                // Verifica o acesso do gerente 
    199                 if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox')) 
    200                 { 
    201                         $result['status'] = false; 
    202                         $result['msg'] = $this->functions->lang('You do not have access to clean an user inbox'); 
    203                         return $result; 
    204                 } 
    205                  
    206                 if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 
     215                if (!($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox') || 
     216                      $this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_shared_accounts_inbox') 
     217                  )) 
     218                { 
     219                        $result['status'] = false; 
     220                        $result['msg'] = $this->functions->lang('You do not have access to clean an inbox'); 
     221                        return $result; 
     222                } 
     223 
     224                if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 
    207225                { 
    208226                        $imap_options = '/tls/novalidate-cert'; 
     
    241259                        { 
    242260                                $result['status'] = false; 
    243                                 $result['msg'] = $this->functions->lang('It was not possible clean the users inbox') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error(); 
     261                                $result['msg'] = $this->functions->lang('It was not possible clean the inbox') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error(); 
    244262                        } 
    245263                } 
     
    251269                return $result; 
    252270        } 
     271        function getaclfrombox($params) 
     272        { 
     273                $boxacl = $params['uid']; 
     274                 
     275                $return = array();       
     276                 
     277                $mbox_acl = imap_getacl($this->imap, "user" . $this->imapDelimiter . $boxacl); 
     278                 
     279                foreach ($mbox_acl as $user => $acl) 
     280                { 
     281                        if ($user != $boxacl ) 
     282                        { 
     283                                $return[$user] = $acl; 
     284                        } 
     285                } 
     286                return $return; 
     287        } 
     288        function setaclfrombox($user, $acl, $mailbox) 
     289        { 
     290                $serverString = '{'.$this->imap_server.':'.$this->imap_port.'/novalidate-cert}'; 
     291                $mailboxes_list = imap_getmailboxes($this->imap, $serverString, "user".$this->imapDelimiter.$mailbox.$this->imapDelimiter."*");                 
     292                $result = Array(); 
     293                $result['status'] = true; 
     294                if (is_array($mailboxes_list)) 
     295                { 
     296                        $folder = str_replace($serverString, "", imap_utf7_encode("user".$this->imapDelimiter.$mailbox)); 
     297                        $folder = str_replace("&-", "&", $folder); 
     298 
     299                        if (imap_setacl ($this->imap, $folder, $user, $acl) ) { 
     300                            foreach ($mailboxes_list as $key => $val) 
     301                            { 
     302                                    $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); 
     303                                    $folder = str_replace("&-", "&", $folder); 
     304                                    if (!imap_setacl ($this->imap, $folder, $user, $acl)) 
     305                                    { 
     306                                            $result['status'] = false; 
     307                                            $result['msg']  = $this->functions->lang('Error on function') . ' imap_functions->setaclfrombox: imap_setacl'; 
     308                                            $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . imap_last_error(); 
     309                                            break; 
     310                                    } 
     311                            } 
     312                        } else { 
     313                            $result['status'] = false; 
     314                            $result['msg']  = $this->functions->lang('Error on function') . ' imap_functions->setaclfrombox: imap_setacl'; 
     315                            $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . imap_last_error(); 
     316                            break; 
     317                        } 
     318                } 
     319                return $result; 
     320        } 
     321        function save_shared_account($params){            
     322            //Rename mailbox 
     323            $result = Array(); 
     324            $result['status'] = true; 
     325            if($params['uid'] != $params['old_uid'] ){ 
     326                    $result = $this->rename_mailbox($params['old_uid'], $params['uid']); 
     327                    if(!$result['status']) return $result; 
     328            } 
     329 
     330            //Begin edit Quota 
     331            $quota = $this->get_user_info($params['uid'] ); 
     332 
     333            if ( $quota['mailquota'] != $params['mailquota'] ){ 
     334                    if(!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_shared_accounts_quote') ) 
     335                    { 
     336                                $result['status'] = false; 
     337                                $result['msg'] = $this->functions->lang('You do not have access to edit an shared account inbox quota'); 
     338                                return $result; 
     339                    } else $this->change_user_quota($params['old_uid'], $params['mailquota']); 
     340            } 
     341            //End Edit Quota 
     342  
     343            /* Begin Set ACL */ 
     344            //Old users set in the box 
     345            $owners_acl_old = $this->getaclfrombox($params); 
     346            //new settings 
     347            $owners_acl_new = unserialize($params['owners_acl']); 
     348 
     349            $owners_to_remove = array_diff_assoc($owners_acl_old,$owners_acl_new); 
     350            $owners_to_add = array_diff_assoc($owners_acl_new,$owners_acl_old); 
     351 
     352            //Find modified users 
     353            $tmp_update = array_diff_assoc($owners_acl_old,$owners_to_remove); 
     354            $owners_to_update = Array(); 
     355            foreach($tmp_update  as $user => $acl){ 
     356                if($owners_acl_old[$user] != $acl){ 
     357                    $owners_to_update[$user] = $acl; 
     358                } 
     359            } 
     360             
     361            //Check Modify manage acl 
     362             
     363            if( (count($owners_to_remove) > 0 || count($owners_to_add) > 0 || count($owners_to_update) > 0) && !$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_shared_accounts_acl') ){ 
     364                $result['status'] = false; 
     365                $result['msg'] = $this->functions->lang('You do not have access to edit an shared account inbox acl'); 
     366                return $result; 
     367            } 
     368             
     369            if( is_array($owners_acl_new)){ 
     370                foreach($owners_to_remove as $user => $acl){ 
     371                    $params['user'] = $user; 
     372                    $params['acl'] = "none"; 
     373                    $user = $params['user']; 
     374                    $result = $this->setaclfrombox($user,"none",$params['uid']); 
     375                } 
     376                //add new users 
     377                foreach($owners_to_add as $user => $acl){ 
     378                    $params['user'] = $user; 
     379                    $params['acl'] = $acl; 
     380                    $result = $this->setaclfrombox($user,$acl,$params['uid']); 
     381                } 
     382                //update users 
     383                 foreach($owners_to_update as $user => $acl){ 
     384                    $params['user'] = $user; 
     385                    $params['acl'] = $acl; 
     386                    $result = $this->setaclfrombox($user,$acl,$params['uid']); 
     387                }                
     388            } 
     389            /* End Set Acl */ 
     390            return $result; 
     391        } 
    253392} 
Note: See TracChangeset for help on using the changeset viewer.