source: branches/2.2/phpgwapi/templates/classic/listUsers.php @ 3404

Revision 3404, 7.1 KB checked in by valmir.sena, 14 years ago (diff)

Ticket #1386 - Implementar possibilidade de compartilhar agenda com um GRUPO - branch22

  • Property svn:executable set to *
Line 
1<?php                   
2        $current = $_GET['currentApp'];
3        $GLOBALS['phpgw_info']['flags'] = array(
4                'noheader' => True,
5                'nonavbar' => True,
6                'currentapp' => $current
7        );
8       
9        include('../../../header.inc.php');
10        //include('../../../admin/templates/celepar/head.inc.php');
11               
12        $owner   =  $_SESSION['owner'];
13        $acl_app =  $_SESSION['acl_app'];
14       
15        if(!$acl_app)
16                $acl_app = $current;
17
18        if(!@is_object($GLOBALS['phpgw']->js))  {
19               
20                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
21        }
22               
23        $GLOBALS['phpgw']->common->phpgw_header();     
24       
25       
26        $t = &$GLOBALS['phpgw']->template;                                             
27        // seta o Template
28        $t->set_file(array('addUser_t' => '../../../phpgwapi/templates/classic/listUsers.tpl'));
29
30        $obj_account = CreateObject('phpgwapi.accounts',$owner);
31
32        $post_select_organization = $_POST['select_organization'];
33        $post_select_sector = $_POST['select_sector'];
34        $change_organization = $_POST['change_organization'];
35        $search_users = $_POST['search_users'];
36       
37        $obj_org_sector = CreateObject('phpgwapi.sector_search_ldap');
38        $cn='*';
39        if ((!$post_select_organization) && (!$post_select_sector) && (!$search_users)) //primeira vez
40        {
41                $user_org = $obj_account->get_organization($GLOBALS['phpgw_info']['user']['account_dn']);
42                $user_sector = $obj_account->get_sector($GLOBALS['phpgw_info']['user']['account_dn']);
43                $user_context = $obj_account->get_context($GLOBALS['phpgw_info']['user']['account_dn']);
44               
45                $organizations_info = $obj_org_sector->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
46                @asort($organizations_info);
47                @reset($organizations_info);                                   
48                $sectors_info = $obj_org_sector->sector_search('ou='.$user_org.','.$GLOBALS['phpgw_info']['server']['ldap_context']);
49        }
50        else if(($post_select_organization) && ($post_select_sector) && (!$search_users))//mudou uma das combos
51        {
52                $user_org = $post_select_organization;
53                $user_sector = $post_select_sector;
54                if ($change_organization == "True")
55                        $user_context = 'ou='.$user_org.','.$GLOBALS['phpgw_info']['server']['ldap_context'];
56                else
57                        $user_context = $post_select_sector;
58                $organizations_info = $obj_org_sector->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
59                @asort($organizations_info);
60                @reset($organizations_info);                                   
61                $sectors_info = $obj_org_sector->sector_search('ou='.$user_org.','.$GLOBALS['phpgw_info']['server']['ldap_context']);
62        }
63        else if ($search_users)//foi preenchida a caixa de busca independente
64        {
65                $user_context = $GLOBALS['phpgw_info']['server']['ldap_context'];
66                system('echo "CONTEXT: '.$user_context.'" >/tmp/controle');
67                $organizations_info = $obj_org_sector->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
68                @asort($organizations_info);
69                @reset($organizations_info);
70                $sectors_info = $obj_org_sector->sector_search('ou='.$post_select_organization.','.$GLOBALS['phpgw_info']['server']['ldap_context']);
71                @reset($sector_info);
72                $cn='*'.$search_users.'*';
73        }
74       
75        foreach($organizations_info as $organization)
76        {
77                $combo_organization .= '<option value="' . $organization . '"';         
78               
79                if (!$post_select_organization)
80                {
81                        if($organization == $user_org)
82                        {
83                                $combo_organization .= ' selected';
84                        }
85                }
86                else
87                {
88                        if($organization == $post_select_organization)
89                        {
90                                $combo_organization .= ' selected';
91                        }
92                }       
93                $combo_organization .= '>' .$organization.'</option>'."\n";
94        }
95       
96        $combo_sector .= '<option value="ou='.$user_org.','.$GLOBALS['phpgw_info']['server']['ldap_context'].'"> --------- </option>'."\n";
97        foreach($sectors_info as $sector)
98        {
99                $combo_sector .= '<option value="' . $sector->sector_context . '"';
100
101                if (!$post_select_sector)
102                {
103                        if($sector->sector_name == $user_sector)
104                                $combo_sector .= ' selected';
105                }
106                else
107                {
108                        if($sector->sector_context == $post_select_sector)
109                                $combo_sector .= ' selected';
110                }
111                $combo_sector .= '>' .$sector->sector_name.'</option>'."\n";
112        }                       
113       
114        // Monta lista de Grupos e Usuários
115        $users = Array();
116        $groups = Array();
117        $justthese = array("phpgwaccountvisible","uidNumber","cn","phpgwaccounttype","gidnumber");
118       
119        $typeAccount = 'u';
120       
121        if($_GET['type'])
122                $typeAccount = $_GET['type'];
123
124        $ldap_host =$GLOBALS['phpgw_info']['server']['ldap_host'];
125        $ds = $GLOBALS['phpgw']->common->ldapConnect();
126    if ($ds)
127    {
128                if( $acl_app == 'calendar' ){
129                        $sr=ldap_search($ds, $user_context, ("(&(cn=$cn)(|(phpgwaccounttype=u)(phpgwaccounttype=g)))"),$justthese);
130                        $info = ldap_get_entries($ds, $sr);
131                       
132                        for ($i=0; $i<$info["count"]; $i++)
133                                {
134                                        if ($info[$i]["phpgwaccountvisible"][0] == '-1')
135                                                continue;
136                                        if( $info[$i]["phpgwaccounttype"][0] == 'u')
137                                                $users[$uids=$info[$i]["uidnumber"][0]] = Array('name'  =>      $uids=$info[$i]["cn"][0], 'type'        =>      u );
138                                        else
139                                                $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name' =>      $uids=$info[$i]["cn"][0], 'type'        =>      g );
140                                }
141                }
142                else{
143                $sr=ldap_search($ds, $user_context, ("(&(cn=$cn)(phpgwaccounttype=".$typeAccount."))"),$justthese);
144                $info = ldap_get_entries($ds, $sr);
145                        if($typeAccount == 'u'){
146                                for ($i=0; $i<$info["count"]; $i++)
147                                {
148                                        if ($info[$i]["phpgwaccountvisible"][0] == '-1')
149                                                continue;
150                                        $users[$uids=$info[$i]["uidnumber"][0]] = Array('name'  =>      $uids=$info[$i]["cn"][0], 'type'        =>      u );
151                                }
152                        }
153                        else {
154                                for ($i=0; $i<$info["count"]; $i++)     
155                                        $users[$uids=$info[$i]["gidnumber"][0]] = Array('name'  =>      $uids=$info[$i]["cn"][0], 'type'        =>      g);             
156                       
157                        }
158                }       
159        }
160        ldap_close($ds);
161       
162        @asort($users);
163        @reset($users);
164        @asort($groups);
165        @reset($groups);
166
167       
168        $options ='';
169
170       
171        if($current == 'preferences'){
172                if( count($users) > 0 ){
173                        $options .= '<option value="-1" disabled="disabled">------------------- '.lang('users').' ------------------ </option>';
174                        foreach($users as $id => $user_array) {
175                                if($owner != $id){
176                                        $newId = 'u_'.$acl_app.'['.$id;                 
177                                        $options .= '<option  value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n";
178                                }
179                        }
180                }
181                if( count($groups) > 0 ){
182                        $options .= '<option value="-1" disabled="disabled">------------------- '.lang('groups').' ------------------ </option>';
183                        foreach($groups as $id => $groups_array) {
184                                if($owner != $id){
185                                        $newId = 'g_'.$acl_app.'['.$id;                 
186                                        $options .= '<option  value="'.$newId.'">'.utf8_decode($groups_array['name']).'</option>'."\n";
187                                }
188                        }
189                }
190        }
191        else if($current == 'admin') {
192                foreach($users as $id => $user_array) {         
193                        $options .= '<option  value="'.$id.'">'.utf8_decode($user_array['name']).'</option>'."\n";
194                }               
195        }
196
197        $t->set_var ('lang_Organization',lang('Organization'));
198        $t->set_var ('lang_Sector',lang('Sector'));
199        $t->set_var ('lang_Calendar',lang('Calendar'));
200        $t->set_var ('lang_Add_Participants',lang('Add Participants'));
201        $t->set_var ('lang_to_Search',lang('to Search'));
202        $t->set_var ('lang_Close',lang('Close'));
203        $t->set_var ('lang_Add',lang('Add'));
204       
205        if($current == 'preferences')
206                $t->set_var ('addUser','javascript:addUserAcl()');
207        else
208                $t->set_var ('addUser','javascript:addUser()');
209               
210        $t->set_var('options',$options);
211        $t->set_var('combo_organization', $combo_organization);
212        $t->set_var('combo_sector', $combo_sector);
213        $t->parse('out','addUser_t',true);
214        $t->p('out');
215        $GLOBALS['phpgw']->common->phpgw_exit();       
216?>
Note: See TracBrowser for help on using the repository browser.