Ignore:
Timestamp:
09/05/07 11:18:58 (17 years ago)
Author:
niltonneto
Message:

* empty log message *

File:
1 edited

Legend:

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

    r63 r64  
    1818                        'delete_managers'       => True, 
    1919                        'edit_managers'         => True, 
     20                        'copy_managers'         => True, 
    2021                        'validate'                      => True 
    2122                ); 
     
    3031                        $c->read_repository(); 
    3132                        $this->config = $c->config_data; 
     33                         
     34                        if(!@is_object($GLOBALS['phpgw']->js)) 
     35                        { 
     36                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); 
     37                        } 
     38                        $GLOBALS['phpgw']->js->validate_file('jscode','connector','expressoAdmin1_2');#diretorio, arquivo.js, aplicacao 
     39                        $GLOBALS['phpgw']->js->validate_file('jscode','managers','expressoAdmin1_2'); 
    3240                } 
    3341 
     
    6068                        $p->set_block('managers','row','row'); 
    6169                        $p->set_block('managers','row_empty','row_empty'); 
     70                        $tpl_vars = $p->get_undefined('body'); 
    6271 
    6372                        $var = Array( 
    6473                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.add_managers'), 
    6574                                'tr_color'                      => '#DDDDDD', 
    66                                 'th_bg'                 => $GLOBALS['phpgw_info']['theme']['th_bg'], 
    67                                 'lang_add_manager'      => lang('Add Manager'), 
    68                                 'lang_manager_lid'      => lang('Manager LID'), 
    69                                 'lang_manager_cn'       => lang('Manager name'), 
    70                                 'lang_context'          => lang('Context'), 
    71                                 'lang_edit'             => lang('Edit'), 
    72                                 'lang_delete'           => lang('Delete') 
     75                                'th_bg'                 => $GLOBALS['phpgw_info']['theme']['th_bg'] 
    7376                        ); 
    7477 
    75                         // le do banco de dados para pegar os administradors. 
     78                        // Cria dinamicamente os langs 
     79                        foreach ($tpl_vars as $atribute) 
     80                        { 
     81                                $lang = strstr($atribute, 'lang_'); 
     82                                if($lang !== false) 
     83                                { 
     84                                        $p->set_var($atribute, $this->make_lang($atribute)); 
     85                                } 
     86                        } 
     87 
     88                        // Le BD para pegar os administradors. 
    7689                        $query = 'SELECT manager_lid,context FROM phpgw_expressoadmin ORDER by manager_lid'; 
    7790                        $GLOBALS['phpgw']->db->query($query); 
     
    87100                                foreach($managers as $array_managers) 
    88101                                { 
     102                                        $managers_context = ""; 
     103                                        $a_managers_context = split("%", $array_managers['context']); 
     104 
     105                                        foreach ($a_managers_context as $context) 
     106                                        { 
     107                                                $managers_context .= "$context<br>"; 
     108                                        } 
     109                                         
    89110                                        $filter="(&(phpgwAccountType=u)(uid=".$array_managers['manager_lid']."))"; 
    90111                                        $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     
    92113                                        $p->set_var('manager_lid', $array_managers[manager_lid]); 
    93114                                        $p->set_var('manager_cn', $ldap_result[0]['cn'][0] == '' ? '<font color=red>NAO ENCONTRADO NO LDAP</font>' : $ldap_result[0]['cn'][0]); 
    94                                         $p->set_var('context', $array_managers[context]); 
     115                                        $p->set_var('context', $managers_context); 
    95116                                        $p->set_var('link_edit',$this->row_action('edit','edit_managers',$array_managers[manager_lid],$array_managers[context])); 
    96117                                        $p->set_var('link_delete',$this->row_action('delete','delete_managers',$array_managers[manager_lid],$array_managers[context])); 
     118                                        $p->set_var('link_copy',"<a href='#' onClick='javascript:copy_manager(\"".$array_managers['manager_lid']."\");'>Copiar</a>"); 
    97119                                        $p->fp('rows','row',True); 
    98120                                } 
     
    116138                        $p->set_file(array('managers' => 'managers_form.tpl')); 
    117139                        $p->set_block('managers','form','form'); 
     140                        $tpl_vars = $p->get_undefined('form'); 
    118141 
    119142                        // Imprime o NavBar 
     
    122145                        $GLOBALS['phpgw']->common->phpgw_header(); 
    123146                         
     147                        // Seta variaveis javascript necessárias 
     148                        $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url']; 
     149                        $scripts_java = '<script type="text/javascript" src="'.$webserver_url.'/expressoAdmin1_2/js/jscode/expressoadmin.js"></script>'; 
     150                         
     151                        // App, create list of available apps 
     152                        $applications_list = $this->make_app_list(); 
     153                         
     154                        $input_context_fields = '<input type="text" size=60></input><br>'; 
     155                         
     156                        // Seta variaveis que estao no TPL 
     157                        $var = Array( 
     158                                'scripts_java'                  =>      $scripts_java,   
     159                                'action'                                => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.validate'), 
     160                                'display_samba_suport'  => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none', 
     161                                'type'                                  => "add", 
     162                                'color_bg1'                             => "#E8F0F0", 
     163                                'color_bg2'                             => "#D3DCE3", 
     164                                'color_font1'                   => "#DDDDDD", 
     165                                'color_font2'                   => "#EEEEEE", 
     166                                'input_context_fields'  => $input_context_fields, 
     167                                'error_messages'                => $_POST['error_messages'] == '' ? '' : '<script language="JavaScript">alert("'.$_POST['error_messages'].'");</script>',  
     168                                'manager_lid'                   => $_POST['manager_lid'], 
     169                                'context'                               => $_POST['context'], 
     170                                'app_list'                              => $applications_list 
     171                        ); 
     172                        $p->set_var($var); 
     173                         
     174                        // Cria dinamicamente os langs e seta acls 
     175                        foreach ($tpl_vars as $atribute) 
     176                        { 
     177                                $acl  = strstr($atribute, 'acl_'); 
     178                                $lang = strstr($atribute, 'lang_'); 
     179                                // Recuperar os valores das ACLS 
     180                                if ($acl !== false) 
     181                                { 
     182                                        $p->set_var($atribute, $_POST[$atribute] != '' ? 'checked' : '');  
     183                                } 
     184                                // Setar os langs do tpl. 
     185                                elseif($lang !== false) 
     186                                { 
     187                                        $p->set_var($atribute, $this->make_lang($atribute)); 
     188                                } 
     189                        } 
     190                         
     191                        echo $p->fp('out','form'); 
     192                } 
     193         
     194                function delete_managers() 
     195                { 
     196                        // Criar uma verificação e jogar a query para o BO. 
     197                        $context = $_GET['context']; 
     198                        $manager_lid = $_GET['manager_lid']; 
     199                         
     200                        $query = "DELETE FROM phpgw_expressoadmin WHERE manager_lid = '".$manager_lid."' AND context = '" . $context ."'"; 
     201                        $GLOBALS['phpgw']->db->query($query); 
     202                         
     203                        // Remove Gerente da tabela dos apps 
     204                        $query = "DELETE FROM phpgw_expressoadmin_apps WHERE " 
     205                        . "manager_lid = '".$manager_lid."' AND " 
     206                        . "context = '".$context."'"; 
     207                        $GLOBALS['phpgw']->db->query($query);            
     208                         
     209                        // Remove Gerente na ACL do expressoadmin 
     210                        $accounts = CreateObject('phpgwapi.accounts'); 
     211                        $manager_id = $accounts->name2id($_GET['manager_lid']); 
     212                        $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'expressoadmin' AND acl_account = '" . $manager_id . "'";  
     213                        $GLOBALS['phpgw']->db->query($sql);                      
     214                         
     215                        ExecMethod('expressoAdmin1_2.uimanagers.list_managers'); 
     216                } 
     217         
     218                function edit_managers() 
     219                { 
     220                        // Caso nao seja admin, sai. 
     221                        if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin')) 
     222                        { 
     223                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php')); 
     224                        } 
     225                         
     226                        // Verifica se eh a primeira entrada, ai eu tenho o get, senao pego o post. 
     227                        if ($_GET['manager_lid'] != '') 
     228                        { 
     229                                $first_time = true; 
     230                                $_POST['manager_lid']   = $_GET['manager_lid']; 
     231                                $_POST['context']               = $_GET['context']; 
     232                                $old_manager_lid                = $_GET['manager_lid']; 
     233                                $old_context                    = $_GET['context']; 
     234                        } 
     235                        elseif ($_POST['manager_lid'] != '') 
     236                        { 
     237                                $first_time             = false; 
     238                                $old_manager_lid        = $_POST['old_manager_lid']; 
     239                                $old_context            = $_POST['old_context'];                                 
     240                        } 
     241                         
     242                        if ($first_time) 
     243                        { 
     244                                //Pego ACL do gerente 
     245                                $manager = $this->functions->read_acl($_GET['manager_lid']); 
     246                                //Cria vetor da ACL 
     247                                $manager_acl = $this->functions->make_array_acl($manager['acl']); 
     248 
     249                                //Pesquisa no Banco e pega os valores dos apps. 
     250                                $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $_GET['manager_lid'] . "' AND context = '" . $_GET['context'] . "'"; 
     251                                $GLOBALS['phpgw']->db->query($query); 
     252                                $i=0; 
     253                                $manager[0]['apps'] = array(); 
     254                                while($GLOBALS['phpgw']->db->next_record()) 
     255                                { 
     256                                        $tmp[$i] = $GLOBALS['phpgw']->db->row(); 
     257                                        $_POST['applications_list'][$tmp[$i]['app']] = 1; 
     258                                        $manager[0]['apps'][$tmp[$i]['app']] = 1; 
     259                                        $i++; 
     260                                } 
     261                        } 
     262                         
     263                        // Seta o template 
     264                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); 
     265                        $p->set_file(array('managers' => 'managers_form.tpl')); 
     266                        $p->set_block('managers','form','form'); 
     267                        $tpl_vars = $p->get_undefined('form'); 
     268                         
     269                        // Imprime o NavBar 
     270                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']); 
     271                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Managers'); 
     272                        $GLOBALS['phpgw']->common->phpgw_header(); 
     273 
    124274                        // Seta variaveis javas necessárias 
    125275                        $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url']; 
    126                         $scripts_java = ''; 
    127                         $scripts_java .= '<script type="text/javascript" src="'.$webserver_url.'/expressoAdmin1_2/js/jscode/expressoadmin.js"></script>'; 
    128                          
     276                        $scripts_java = '<script type="text/javascript" src="'.$webserver_url.'/expressoAdmin1_2/js/jscode/expressoadmin.js"></script>'; 
     277 
    129278                        // App, create list of available apps 
     279                        $applications_list = $this->make_app_list($manager[0]['apps']); 
     280 
     281                        $a_context = split("%", $_POST['context']); 
     282                        foreach ($a_context as $context) 
     283                                $input_context_fields .= '<input type="text" value="'.$context.'" size=60></input><br>'; 
     284 
     285                        $var = Array( 
     286                                'scripts_java'  => $scripts_java, 
     287                                'action'                => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.validate'), 
     288                                'display_samba_suport'  => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none', 
     289                                'color_bg1'             => "#E8F0F0", 
     290                                'color_bg2'             => "#D3DCE3", 
     291                                'color_font1'   => "#DDDDDD", 
     292                                'color_font2'   => "#EEEEEE", 
     293                                'type'                  => "edit", 
     294                                'error_messages'=> $_POST['error_messages'] == '' ? '' : '<script language="JavaScript1.3">alert("'.$_POST['error_messages'].'");</script>', 
     295                                'manager_lid'   => $_POST['manager_lid'], 
     296                                'context'               => $_POST['context'], 
     297                                 
     298                                'input_context_fields' => $input_context_fields, 
     299                                 
     300                                // Para o update no banco, preciso saber oq foi alterado e para que. 
     301                                // Talvez so o manager e o contexto. 
     302                                'old_manager_lid'       => $old_manager_lid, 
     303                                'old_context'           => $old_context, 
     304                                'app_list'                      => $applications_list 
     305                        ); 
     306                        $p->set_var($var); 
     307                         
     308                        // Cria dinamicamente os langs e seta acls 
     309                        foreach ($tpl_vars as $atribute) 
     310                        { 
     311                                $acl  = strstr($atribute, 'acl_'); 
     312                                $lang = strstr($atribute, 'lang_'); 
     313                                // Recuperar os valores das ACLS 
     314                                if ($acl !== false) 
     315                                { 
     316                                        if ($first_time) 
     317                                                $p->set_var($atribute, $manager_acl[$atribute] != '' ? 'checked' : ''); 
     318                                        else 
     319                                                $p->set_var($atribute, $_POST[$atribute] != '' ? 'checked' : '');  
     320                                } 
     321                                // Setar os langs do tpl. 
     322                                elseif($lang !== false) 
     323                                { 
     324                                        $p->set_var($atribute, $this->make_lang($atribute)); 
     325                                } 
     326                        } 
     327                         
     328                        echo $p->fp('out','form'); 
     329                } 
     330                 
     331                function validate() 
     332                {        
     333                        $accounts = CreateObject('phpgwapi.accounts'); 
     334                        $errors = array(); 
     335                         
     336                        // verifica se o manager existe. caso retorne 1 existe e eh uma conta de usuario. 
     337                        $manager_lid_exists = $accounts->exists($_POST['manager_lid']); 
     338                        if ($manager_lid_exists != 1) 
     339                        { 
     340                                $_POST['error_messages'] = lang("Manager LID don't exist."); 
     341                                if ($_POST['type'] == 'add')     
     342                                        $this->add_managers(); 
     343                                elseif ($_POST['type'] == 'edit') 
     344                                        $this->edit_managers(); 
     345                                return; 
     346                        } 
     347                         
     348                        // Verifica se o contexto existe. 
     349                        $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 
     350                        $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 
     351                        $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 
     352                        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 
     353                        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 
     354                        ldap_bind($ldap_conn,$dn,$passwd); 
     355         
     356                        $contexts = split("%", $_POST['context']); 
     357                         
     358                        foreach ($contexts as $index=>$context) 
     359                        { 
     360                                $sr=@ldap_list($ldap_conn, $context, "cn=*"); 
     361                                if (!$sr) 
     362                                { 
     363                                        $_POST['error_messages'] = lang("Context don't exist") . ": $context";                   
     364                                        ldap_close($ldap_conn); 
     365                                        if ($_POST['type'] == 'add')     
     366                                                $this->add_managers(); 
     367                                        elseif ($_POST['type'] == 'edit') 
     368                                                $this->edit_managers(); 
     369                                        return; 
     370                                } 
     371                        } 
     372                         
     373                        if ($_POST['type'] == 'add') 
     374                        { 
     375                                //Verifica se ja existe o manager com aquele contexto cadastrado 
     376                                $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $_POST['manager_lid'] . "' AND context = '" . $_POST['context'] . "'";                            
     377                                $GLOBALS['phpgw']->db->query($query); 
     378                                $num_registros = 0; 
     379                                while($GLOBALS['phpgw']->db->next_record()) 
     380                                { 
     381                                        $tmp[] = $GLOBALS['phpgw']->db->row(); 
     382                                        $num_registros++; 
     383                                } 
     384                                if ($num_registros != 0) 
     385                                { 
     386                                        $_POST['error_messages'] = lang('Este Gerente, neste contexto já exite !!'); 
     387                                        $this->add_managers(); 
     388                                        return; 
     389                                } 
     390                        } 
     391                         
     392                        if ($_POST['type'] == 'add') 
     393                                ExecMethod('expressoAdmin1_2.bomanagers.add_managers'); 
     394                        elseif ($_POST['type'] == 'edit') 
     395                                ExecMethod('expressoAdmin1_2.bomanagers.edit_managers'); 
     396                         
     397                        return true; 
     398                } 
     399                 
     400                function copy_managers() 
     401                { 
     402                         
     403                         
     404                         
     405                        /* 
     406                        echo '<pre>'; 
     407                        print_r($_GET); 
     408                        $manager_lid = $_GET['manager_lid']; 
     409                         
     410                        //Pego ACL do gerente 
     411                        $manager = $this->functions->read_acl($manager_lid); 
     412                        //Cria vetor da ACL 
     413                        $manager_acl = $this->functions->make_array_acl($manager[0]['acl']); 
     414 
     415                        //Pesquisa no Banco e pega os valores dos apps. 
     416                        $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $manager_lid . "' AND context = '" . $_GET['context'] . "'"; 
     417                        $GLOBALS['phpgw']->db->query($query); 
     418                        $i=0; 
     419                        $manager[0]['apps'] = array(); 
     420                        while($GLOBALS['phpgw']->db->next_record()) 
     421                        { 
     422                                $tmp[$i] = $GLOBALS['phpgw']->db->row(); 
     423                                $_POST['applications_list'][$tmp[$i]['app']] = 1; 
     424                                $manager[0]['apps'][$tmp[$i]['app']] = 1; 
     425                                $i++; 
     426                        } 
     427 
     428                        print_r($manager); 
     429                         
     430                        */ 
     431                } 
     432                 
     433                function make_lang($ram_lang) 
     434                { 
     435                        $a_lang = split("_", $ram_lang); 
     436                        $a_lang_reverse  = array_reverse ( $a_lang, true ); 
     437                        //Retira o lang do array. 
     438                        array_pop ( $a_lang_reverse ); 
     439                        $a_lang  = array_reverse ( $a_lang_reverse, true ); 
     440                        $a_new_lang = implode ( " ", $a_lang ); 
     441                        return lang($a_new_lang); 
     442                } 
     443                 
     444                function make_app_list($manager_app_list) 
     445                { 
    130446                        $this->nextmatchs = createobject('phpgwapi.nextmatchs'); 
    131447                        $apps = CreateObject('phpgwapi.applications',$_account_id); 
    132448                        $db_perms = $apps->read_account_specific(); 
    133449                        $availableApps = $GLOBALS['phpgw_info']['apps']; 
     450                         
    134451                        uasort($availableApps,create_function('$a,$b','return strcasecmp($a["title"],$b["title"]);')); 
    135  
     452                         
    136453                        // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box. 
    137454                        $applications_list = ''; 
     
    141458                        $total_apps = count($availableApps); 
    142459                        $i = 0; 
     460 
    143461                        foreach($availableApps as $app => $data) 
    144462                        { 
     
    146464                                if (($i +1) % 3 == 1) 
    147465                                { 
    148                                         if ($_POST['applications_list'][$app] == 1) 
     466                                        if ($manager_app_list[$app] == 1) 
    149467                                                $checked = 'checked'; 
    150468                                        else 
     
    159477                                if (($i +1) % 3 == 2) 
    160478                                { 
    161                                         if ($_POST['applications_list'][$app] == 1) 
     479                                        if ($manager_app_list[$app] == 1) 
    162480                                                $checked = 'checked'; 
    163481                                        else 
     
    172490                                if (($i +1) % 3 == 0) 
    173491                                { 
    174                                         if ($_POST['applications_list'][$app] == 1) 
     492                                        if ($manager_app_list[$app] == 1) 
    175493                                                $checked = 'checked'; 
    176494                                        else 
     
    184502                                $i++; 
    185503                        } 
    186                                  
    187                         // Seta variaveis que estao no TPL 
    188                         $var = Array( 
    189                                 'scripts_java'                  =>      $scripts_java,   
    190                                 'action'                                => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.validate'), 
    191                                 'display_samba_suport'  => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none', 
    192                                  
    193                                 'type'                                  => "add", 
    194                                 'color_bg1'                             => "#E8F0F0", 
    195                                 'color_bg2'                             => "#D3DCE3", 
    196                                 'color_font1'                   => "#DDDDDD", 
    197                                 'color_font2'                   => "#EEEEEE", 
    198                                 'lang_back'                                             => lang('Back'), 
    199                                 'lang_add_save_manager'                 => lang('Add Manager'), 
    200                                 'lang_manager_lid'                              => lang('Manager LID'), 
    201                                 'lang_context'                                  => lang('Context'), 
    202                                 'lang_type_access'                              => lang('Tipo de acessos'), 
    203                                 'lang_add_users'                                => lang('Add users'), 
    204                                 'lang_edit_users'                               => lang('Edit users'), 
    205                                 'lang_delete_users'                             => lang('Delete users'), 
    206                                 'lang_view_users'                               => lang('View user'), 
    207                                 'lang_rename_user'                              => lang('Rename users'), 
    208                                 'lang_view_user'                                => lang('View users'), 
    209                                 'lang_manipulate_corporative_information' => lang('Manipulate corporative information'), 
    210                                 'lang_add_groups'                               => lang('Add groups'), 
    211                                 'lang_edit_groups'                              => lang('Edit groups'), 
    212                                 'lang_delete_groups'                    => lang('Delete groups'), 
    213                                 'lang_edit_email_attribute_from_the_groups'     =>      lang('Edit email attribute from the groups'), 
    214                                 'lang_change_user_password'             => lang('Change users password'), 
    215                                 'lang_change_users_quote'               => lang('Change users quote'), 
    216                                 'lang_set_user_default_password'=> lang('Set default users password'), 
    217                                 'lang_empty_user_inbox'                 => lang('Empty user inbox'), 
    218                                 'lang_edit_sambausers_attributes'=> lang('Edit SAMBA users attributes'), 
    219                                 'lang_edit_sambadomains'                => lang('Edit SAMBA domains'), 
    220                                 'lang_add_email_lists'                  => lang('Add email lists'), 
    221                                 'lang_edit_email_lists'                 => lang('Edit email lists'), 
    222                                 'lang_delete_email_lists'               => lang('Delete email lists'), 
    223                                 'lang_view_email_lists'                 => lang('View email lists'), 
    224                                 'lang_create_orgs'                              => lang('Create Organizations'), 
    225                                 'lang_edit_orgs'                                => lang('Edit Organizations'), 
    226                                 'lang_delete_orgs'                              => lang('Delete Organizations'), 
    227                                 'lang_view_global_sessions'             => lang('View sessions (global)'), 
    228                                 'lang_view_logs'                                => lang('View logs'), 
    229                                 'lang_create_computers'                 => lang('Create computers'), 
    230                                 'lang_edit_computers'                   => lang('Edit computers'), 
    231                                 'lang_delete_computers'                 => lang('Delete computers'), 
    232                                 'error_messages'                                => $_POST['error_messages'] == '' ? '' : '<script language="JavaScript1.3">alert("'.$_POST['error_messages'].'");</script>',  
    233                                 'manager_lid'                                   => $_POST['manager_lid'], 
    234                                 'context'                                               => $_POST['context'], 
    235                                 'add_users'                                     => $_POST['add_users'] != '' ? 'checked' : '', 
    236                                 'edit_users'                                    => $_POST['edit_users'] != '' ? 'checked' : '', 
    237                                 'view_users'                                    => $_POST['view_users'] != '' ? 'checked' : '', 
    238                                 'manipulate_corporative_information' => $_POST['manipulate_corporative_information'] != '' ? 'checked' : '', 
    239                                 'delete_users'                                  => $_POST['delete_users'] != '' ? 'checked' : '', 
    240                                 'add_groups'                                    => $_POST['add_groups'] != '' ? 'checked' : '', 
    241                                 'edit_groups'                                   => $_POST['edit_groups'] != '' ? 'checked' : '', 
    242                                 'delete_groups'                                 => $_POST['delete_groups'] != '' ? 'checked' : '', 
    243                                 'change_users_password'                 => $_POST['change_users_password'] != '' ? 'checked' : '', 
    244                                 'change_users_quote'                    => $_POST['change_users_quote'] != '' ? 'checked' : '', 
    245                                 'set_user_default_password'             => $_POST['set_user_default_password'] != '' ? 'checked' : '', 
    246                                 'edit_sambausers_attributes'    => $_POST['edit_sambausers_attributes'] != '' ? 'checked' : '', 
    247                                 'edit_sambadomains'                             => $_POST['edit_sambadomains'] != '' ? 'checked' : '', 
    248                                 'add_maillists'                                 => $_POST['add_maillists'] != '' ? 'checked' : '', 
    249                                 'edit_maillists'                                => $_POST['edit_maillists'] != '' ? 'checked' : '', 
    250                                 'delete_maillists'                              => $_POST['delete_maillists'] != '' ? 'checked' : '', 
    251                                 'create_sectors'                                => $_POST['create_sectors'] != '' ? 'checked' : '', 
    252                                 'edit_sectors'                                  => $_POST['edit_sectors'] != '' ? 'checked' : '', 
    253                                 'delete_sectors'                                => $_POST['delete_sectors'] != '' ? 'checked' : '', 
    254                                 'view_global_sessions'                  => $_POST['view_global_sessions'] != '' ? 'checked' : '', 
    255                                 'view_logs'                                             => $_POST['view_logs'] != '' ? 'checked' : '', 
    256  
    257                                 'app_list'                                              => $applications_list 
    258                         ); 
    259                         $p->set_var($var); 
    260                         echo $p->fp('out','form'); 
    261                 } 
    262          
    263                 function delete_managers() 
    264                 { 
    265                         // Criar uma verificação e jogar a query para o BO. 
    266                         $context = $_GET['context']; 
    267                         $manager_lid = $_GET['manager_lid']; 
    268                          
    269                         $query = "DELETE FROM phpgw_expressoadmin WHERE manager_lid = '".$manager_lid."' AND context = '" . $context ."'"; 
    270                         $GLOBALS['phpgw']->db->query($query); 
    271                          
    272                         // Remove Gerente da tabela dos apps 
    273                         $query = "DELETE FROM phpgw_expressoadmin_apps WHERE " 
    274                         . "manager_lid = '".$manager_lid."' AND " 
    275                         . "context = '".$context."'"; 
    276                         $GLOBALS['phpgw']->db->query($query);            
    277                          
    278                         // Remove Gerente na ACL do expressoadmin 
    279                         $accounts = CreateObject('phpgwapi.accounts'); 
    280                         $manager_id = $accounts->name2id($_GET['manager_lid']); 
    281                         $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'expressoadmin' AND acl_account = '" . $manager_id . "'";  
    282                         $GLOBALS['phpgw']->db->query($sql);                      
    283                          
    284                         ExecMethod('expressoAdmin1_2.uimanagers.list_managers'); 
    285                 } 
    286          
    287                 function edit_managers() 
    288                 { 
    289                         // Caso nao seja admin, sai. 
    290                         if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin')) 
    291                         { 
    292                                 $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php')); 
    293                         } 
    294                          
    295                         // Verifica se eh a primeira entrada, ai eu tenho o get, senao pego o post. 
    296                         if ($_GET['manager_lid'] != '') 
    297                         { 
    298                                 $_POST['manager_lid']   = $_GET['manager_lid']; 
    299                                 $_POST['context']               = $_GET['context']; 
    300                                 $old_manager_lid                = $_GET['manager_lid']; 
    301                                 $old_context                    = $_GET['context']; 
    302                                 $first_time = true; 
    303                         } 
    304                         elseif ($_POST['manager_lid'] != '') 
    305                         { 
    306                                 $old_manager_lid        = $_POST['old_manager_lid']; 
    307                                 $old_context            = $_POST['old_context'];                                 
    308                                 $first_time             = false; 
    309                         } 
    310                          
    311                         if ($first_time) 
    312                         { 
    313                                 //Pesquisa no Banco e pega os valores da ACL 
    314                                 $query = "SELECT * FROM phpgw_expressoadmin WHERE manager_lid = '" . $_GET['manager_lid'] . "' AND context = '" . $_GET['context'] . "'"; 
    315                                 $GLOBALS['phpgw']->db->query($query); 
    316                                 while($GLOBALS['phpgw']->db->next_record()) 
    317                                 { 
    318                                         $manager[] = $GLOBALS['phpgw']->db->row(); 
    319                                 } 
    320                          
    321                                 //Pesquisa no Banco e pega os valores dos apps. 
    322                                 $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $_GET['manager_lid'] . "' AND context = '" . $_GET['context'] . "'"; 
    323                                 $GLOBALS['phpgw']->db->query($query); 
    324                                 $i=0; 
    325                                 $manager[0]['apps'] = array(); 
    326                                 while($GLOBALS['phpgw']->db->next_record()) 
    327                                 { 
    328                                         $tmp[$i] = $GLOBALS['phpgw']->db->row(); 
    329                                         $_POST['applications_list'][$tmp[$i]['app']] = 1; 
    330                                         $manager[0]['apps'][$tmp[$i]['app']] = 1; 
    331                                         $i++; 
    332                                 } 
    333                          
    334                                 //Cria vetor da ACL 
    335                                 $acl = $this->functions->make_array_acl($manager[0]['acl']); 
    336                                 $_POST['add_users']                             = $acl['add_users']; 
    337                                 $_POST['edit_users']                    = $acl['edit_users']; 
    338                                 $_POST['delete_users']                  = $acl['delete_users']; 
    339                                 $_POST['rename_users']                  = $acl['rename_users']; 
    340                                 $_POST['view_users']                    = $acl['view_users']; 
    341                                 $_POST['manipulate_corporative_information'] = $acl['manipulate_corporative_information']; 
    342                                 $_POST['add_groups']                    = $acl['add_groups']; 
    343                                 $_POST['edit_groups']                   = $acl['edit_groups']; 
    344                                 $_POST['delete_groups']                 = $acl['delete_groups']; 
    345                                 $_POST['edit_email_groups']             = $acl['edit_email_groups']; 
    346                                 $_POST['change_users_password'] = $acl['change_users_password']; 
    347                                 $_POST['change_users_quote']    = $acl['change_users_quote']; 
    348                                 $_POST['set_user_default_password']     = $acl['set_user_default_password']; 
    349                                 $_POST['empty_user_inbox']              = $acl['empty_user_inbox']; 
    350                                 $_POST['edit_sambausers_attributes'] = $acl['edit_sambausers_attributes']; 
    351                                 $_POST['edit_sambadomains']     = $acl['edit_sambadomains']; 
    352                                 $_POST['add_maillists']                 = $acl['add_maillists']; 
    353                                 $_POST['edit_maillists']                = $acl['edit_maillists']; 
    354                                 $_POST['delete_maillists']              = $acl['delete_maillists']; 
    355                                 $_POST['create_sectors']                = $acl['create_sectors']; 
    356                                 $_POST['edit_sectors']                  = $acl['edit_sectors']; 
    357                                 $_POST['delete_sectors']                = $acl['delete_sectors']; 
    358                                 $_POST['create_computers']              = $acl['create_computers']; 
    359                                 $_POST['edit_computers']                = $acl['edit_computers']; 
    360                                 $_POST['delete_computers']              = $acl['delete_computers']; 
    361                                 $_POST['view_global_sessions']  = $acl['view_global_sessions']; 
    362                                 $_POST['view_logs']                             = $acl['view_logs']; 
    363                         } 
    364                          
    365                         // Seta o template 
    366                         $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); 
    367                         //$accounts = CreateObject('phpgwapi.accounts'); 
    368                         $p->set_file(array('managers' => 'managers_form.tpl')); 
    369                         $p->set_block('managers','form','form'); 
    370                          
    371                         // Imprime o NavBar 
    372                         unset($GLOBALS['phpgw_info']['flags']['nonavbar']); 
    373                         $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Managers'); 
    374                         $GLOBALS['phpgw']->common->phpgw_header(); 
    375  
    376                         // Seta variaveis javas necessárias 
    377                         $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url']; 
    378                         $scripts_java = ''; 
    379                         $scripts_java .= '<script type="text/javascript" src="'.$webserver_url.'/expressoAdmin1_2/js/jscode/expressoadmin.js"></script>'; 
    380  
    381                         // App, create list of available apps 
    382                         $this->nextmatchs = createobject('phpgwapi.nextmatchs'); 
    383                         $apps = CreateObject('phpgwapi.applications',$_account_id); 
    384                         $db_perms = $apps->read_account_specific(); 
    385                         $availableApps = $GLOBALS['phpgw_info']['apps']; 
    386                          
    387                         uasort($availableApps,create_function('$a,$b','return strcasecmp($a["title"],$b["title"]);')); 
    388                          
    389                         // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box. 
    390                         $applications_list = ''; 
    391                         $app_col1 = ''; 
    392                         $app_col2 = ''; 
    393                         $app_col3 = ''; 
    394                         $total_apps = count($availableApps); 
    395                         $i = 0; 
    396  
    397                         foreach($availableApps as $app => $data) 
    398                         { 
    399                                 // 1 coluna  
    400                                 if (($i +1) % 3 == 1) 
    401                                 { 
    402                                         if ($_POST['applications_list'][$app] == 1) 
    403                                                 $checked = 'checked'; 
    404                                         else 
    405                                                 $checked = ''; 
    406                                         $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n", 
    407                                         $data['title'],$app,$checked, $disabled); 
    408                                          
    409                                         if ($i == ($total_apps-1)) 
    410                                                 $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1); 
    411                                 } 
    412                                 // 2 coluna 
    413                                 if (($i +1) % 3 == 2) 
    414                                 { 
    415                                         if ($_POST['applications_list'][$app] == 1) 
    416                                                 $checked = 'checked'; 
    417                                         else 
    418                                                 $checked = ''; 
    419                                         $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n", 
    420                                         $data['title'],$app,$checked, $disabled); 
    421                                          
    422                                         if ($i == ($total_apps-1)) 
    423                                                 $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1,$app_col2); 
    424                                 } 
    425                                 // 3 coluna  
    426                                 if (($i +1) % 3 == 0) 
    427                                 { 
    428                                         if ($_POST['applications_list'][$app] == 1) 
    429                                                 $checked = 'checked'; 
    430                                         else 
    431                                                 $checked = ''; 
    432                                         $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n", 
    433                                         $data['title'],$app,$checked, $disabled); 
    434                                          
    435                                         // Cria nova linha 
    436                                         $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1, $app_col2, $app_col3);                                         
    437                                 } 
    438                                 $i++; 
    439                         } 
    440  
    441                         $var = Array( 
    442                                 'scripts_java' => $scripts_java, 
    443                                 'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.validate'), 
    444                                 'display_samba_suport'  => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none', 
    445                                 'color_bg1'     => "#E8F0F0", 
    446                                 'color_bg2'     => "#D3DCE3", 
    447                                 'color_font1'   => "#DDDDDD", 
    448                                 'color_font2'   => "#EEEEEE", 
    449                                 'type'                  => "edit", 
    450                                 'lang_back'                                             => lang('Back'), 
    451                                 'lang_add_save_manager'                 => lang('Save'), 
    452                                 'lang_manager_lid'                              => lang('Manager LID'), 
    453                                 'lang_context'                                  => lang('Contexto'), 
    454                                 'lang_type_access'                              => lang('Tipo de acessos'), 
    455                                 'lang_add_users'                                => lang('Add users'), 
    456                                 'lang_edit_users'                               => lang('Edit users'), 
    457                                 'lang_delete_users'                             => lang('Delete users'), 
    458                                 'lang_view_users'                               => lang('View users'), 
    459                                 'lang_rename_user'                              => lang('Rename users'), 
    460                                 'lang_view_user'                                => lang('View users'), 
    461                                 'lang_manipulate_corporative_information' => lang('Manipulate corporative information'), 
    462                                 'lang_add_groups'                               => lang('Add groups'), 
    463                                 'lang_edit_groups'                              => lang('Edit groups'), 
    464                                 'lang_delete_groups'                    => lang('Delete groups'), 
    465                                 'lang_edit_email_attribute_from_the_groups'     =>      lang('Edit email attribute from the groups'), 
    466                                 'lang_change_user_password'             => lang('Change users password'), 
    467                                 'lang_change_users_quote'               => lang('Change users quote'), 
    468                                 'lang_set_user_default_password'=> lang('Set default user password'), 
    469                                 'lang_empty_user_inbox'                 => lang('Empty user inbox'), 
    470                                 'lang_edit_sambausers_attributes'=> lang('Edit SAMBA users attributes'), 
    471                                 'lang_edit_sambadomains'                => lang('Edit SAMBA domains'), 
    472                                 'lang_add_email_lists'                  => lang('Add email lists'), 
    473                                 'lang_edit_email_lists'                 => lang('Edit email lists'), 
    474                                 'lang_delete_email_lists'               => lang('Delete email lists'), 
    475                                 'lang_view_email_lists'                 => lang('View email lists'), 
    476                                 'lang_create_orgs'                              => lang('Create Organizations'), 
    477                                 'lang_edit_orgs'                                => lang('Edit Organizations'), 
    478                                 'lang_delete_orgs'                              => lang('Delete Organizations'), 
    479                                 'lang_view_sessions'                    => lang('View sessions (local)'), 
    480                                 'lang_view_global_sessions'             => lang('View sessions (global)'), 
    481                                 'lang_view_logs'                                => lang('View Logs'), 
    482                                 'lang_create_computers'                 => lang('Create computers'), 
    483                                 'lang_edit_computers'                   => lang('Edit computers'), 
    484                                 'lang_delete_computers'                 => lang('Delete computers'),                             
    485                                 'error_messages'                                => $_POST['error_messages'] == '' ? '' : '<script language="JavaScript1.3">alert("'.$_POST['error_messages'].'");</script>', 
    486                                 'manager_lid'                                   => $_POST['manager_lid'], 
    487                                 'context'                                               => $_POST['context'], 
    488                                 'add_users'                                     => $_POST['add_users'] != '' ? 'checked' : '', 
    489                                 'edit_users'                                    => $_POST['edit_users'] != '' ? 'checked' : '', 
    490                                 'delete_users'                                  => $_POST['delete_users'] != '' ? 'checked' : '', 
    491                                 'rename_users'                                  => $_POST['rename_users'] != '' ? 'checked' : '', 
    492                                 'view_users'                                    => $_POST['view_users'] != '' ? 'checked' : '', 
    493                                 'manipulate_corporative_information' => $_POST['manipulate_corporative_information'] != '' ? 'checked' : '', 
    494                                 'add_groups'                                    => $_POST['add_groups'] != '' ? 'checked' : '', 
    495                                 'edit_groups'                                   => $_POST['edit_groups'] != '' ? 'checked' : '', 
    496                                 'delete_groups'                                 => $_POST['delete_groups'] != '' ? 'checked' : '', 
    497                                 'edit_email_groups'                             => $_POST['edit_email_groups'] != '' ? 'checked' : '', 
    498                                 'change_users_password'                 => $_POST['change_users_password'] != '' ? 'checked' : '', 
    499                                 'change_users_quote'                    => $_POST['change_users_quote'] != '' ? 'checked' : '', 
    500                                 'set_user_default_password'             => $_POST['set_user_default_password'] != '' ? 'checked' : '', 
    501                                 'empty_user_inbox'                              => $_POST['empty_user_inbox'] != '' ? 'checked' : '', 
    502                                 'edit_sambausers_attributes'    => $_POST['edit_sambausers_attributes'] != '' ? 'checked' : '', 
    503                                 'edit_sambadomains'                             => $_POST['edit_sambadomains'] != '' ? 'checked' : '', 
    504                                 'add_maillists'                                 => $_POST['add_maillists'] != '' ? 'checked' : '', 
    505                                 'edit_maillists'                                => $_POST['edit_maillists'] != '' ? 'checked' : '', 
    506                                 'delete_maillists'                              => $_POST['delete_maillists'] != '' ? 'checked' : '', 
    507                                 'create_sectors'                                => $_POST['create_sectors'] != '' ? 'checked' : '', 
    508                                 'edit_sectors'                                  => $_POST['edit_sectors'] != '' ? 'checked' : '', 
    509                                 'delete_sectors'                                => $_POST['delete_sectors'] != '' ? 'checked' : '', 
    510                                 'create_computers'                              => $_POST['create_computers'] != '' ? 'checked' : '', 
    511                                 'edit_computers'                                => $_POST['edit_computers'] != '' ? 'checked' : '', 
    512                                 'delete_computers'                              => $_POST['delete_computers'] != '' ? 'checked' : '', 
    513                                 'view_sessions'                                 => $_POST['view_sessions'] != '' ? 'checked' : '', 
    514                                 'view_global_sessions'                  => $_POST['view_global_sessions'] != '' ? 'checked' : '', 
    515                                 'view_logs'                                             => $_POST['view_logs'] != '' ? 'checked' : '', 
    516                                  
    517                                 // Para o update no banco, preciso saber oq foi alterado e para que. 
    518                                 // Talvez so o manager e o contexto. 
    519                                 'old_manager_lid'       => $old_manager_lid, 
    520                                 'old_context'           => $old_context, 
    521                                 'app_list'                      => $applications_list 
    522                         ); 
    523                         $p->set_var($var); 
    524                         echo $p->fp('out','form'); 
    525                 } 
    526                  
    527                 function validate() 
    528                 {        
    529                         $accounts = CreateObject('phpgwapi.accounts'); 
    530                         $errors = array(); 
    531                          
    532                         // verifica se o manager existe. caso retorne 1 existe e eh uma conta de usuario. 
    533                         $manager_lid_exists = $accounts->exists($_POST['manager_lid']); 
    534                         if ($manager_lid_exists != 1) 
    535                         { 
    536                                 $_POST['error_messages'] = lang("Manager LID don't exist."); 
    537                                 if ($_POST['type'] == 'add')     
    538                                         $this->add_managers(); 
    539                                 elseif ($_POST['type'] == 'edit') 
    540                                         $this->edit_managers(); 
    541                                 return; 
    542                         } 
    543                          
    544                         // Verifica se o contexto existe. 
    545                         $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 
    546                         $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 
    547                         $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 
    548                         ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 
    549                         ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 
    550                         ldap_bind($ldap_conn,$dn,$passwd); 
    551                          
    552                         $sr=@ldap_list($ldap_conn, $_POST['context'], "cn=*"); 
    553                         if (!$sr) 
    554                         { 
    555                                 $_POST['error_messages'] = lang("Context don't exist.");                         
    556                                 ldap_close($ldap_conn); 
    557                                 if ($_POST['type'] == 'add')     
    558                                         $this->add_managers(); 
    559                                 elseif ($_POST['type'] == 'edit') 
    560                                         $this->edit_managers(); 
    561                                 return; 
    562                         } 
    563                          
    564                         if ($_POST['type'] == 'add') 
    565                         { 
    566                                 //Verifica se ja existe o manager com aquele contexto cadastrado 
    567                                 $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $_POST['manager_lid'] . "' AND context = '" . $_POST['context'] . "'";                            
    568                                 $GLOBALS['phpgw']->db->query($query); 
    569                                 $num_registros = 0; 
    570                                 while($GLOBALS['phpgw']->db->next_record()) 
    571                                 { 
    572                                         $tmp[] = $GLOBALS['phpgw']->db->row(); 
    573                                         $num_registros++; 
    574                                 } 
    575                                 if ($num_registros != 0) 
    576                                 { 
    577                                         $_POST['error_messages'] = lang('Este Gerente, neste contexto já exite !!'); 
    578                                         $this->add_managers(); 
    579                                         return; 
    580                                 } 
    581                         } 
    582                          
    583                         if ($_POST['type'] == 'add') 
    584                                 ExecMethod('expressoAdmin1_2.bomanagers.add_managers'); 
    585                         elseif ($_POST['type'] == 'edit') 
    586                                 ExecMethod('expressoAdmin1_2.bomanagers.edit_managers'); 
    587                          
    588                         return true; 
     504                        return $applications_list; 
    589505                } 
    590506        } 
Note: See TracChangeset for help on using the changeset viewer.