Code

Updated sudo
[gosa.git] / gosa-plugins / sudo / admin / sudo / class_target_list_users.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id: class_target_list.inc 9850 2008-03-14 14:15:12Z hickert $$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class target_list_users extends MultiSelectWindow
24 {
25   var $config;
26   var $list         =array();
27   var $Targets_used =array();
29   /* Current base */
30   var $selectedBase       = "";
31   var $departments        = array();
33   /* Regex */
34   var $Regex              = "*";
36   /* CheckBoxes, to change default values modify $this->AddCheckBox */
37   var $user       ;
38   var $group      ;
41   /* Subsearch checkbox */
42   var $SubSearch          ;
43   var $parent             ;
44   var $ui                 ;
45  
46  
47   function target_list_users(&$config,$Targets_used)
48   {
49     MultiSelectWindow::MultiSelectWindow($config, "Targetselection", array("users"));
51     $this->Targets_used = $Targets_used;
52     
53     $this->SetInformation(  _("Select the target objects"));
54     $this->SetTitle(        _("Available targets"));
55     $this->SetSummary(      _("Available targets"));
56     $this->SetHeadpageMode(FALSE);
57     
58     /* set Page header */
59     $chk = "<input type='checkbox' id='select_all' name='select_all'
60                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
61     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
63     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
64     $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''"));
66     $this->AddCheckBox("user",    _("Select to see users") ,_("Show users"), true);
67     $this->AddCheckBox("group",   _("Select to see groups"),_("Show groups"), true);
69     /* Add SubSearch checkbox */
70     $this->AddCheckBox(SEPERATOR);
72     /* Add SubSearch checkbox */
73     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
75     /* Name,Text,Default  , Connect with alphabet  */
76     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
77     $this->EnableAplhabet(TRUE);
78   }
81   function GenHeader()
82   {
83     $options= "";
85     /* Get all departments within this subtree */
86     $ui= get_userinfo();
87     $first = "";
88     $found = FALSE;
89     $base = $this->config->current['BASE'];
91     /* Add base */
92     $tmp = array();
93     $tmp[] = array("dn"=>$this->config->current['BASE']);
94     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
95                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
97     $deps = array();
98     foreach($tmp as $tm){
99       $deps[$tm['dn']] = $tm['dn'];
100     }
102     /* Load possible departments */
103     $ui= get_userinfo();
104     $tdeps= $ui->get_module_departments("users");
105     $ids = $this->config->idepartments;
106     $first = "";
107     $found = FALSE;
108     foreach($ids as $dep => $name){
109       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
111         /* Keep first base dn in mind, we could need this
112          *  info if no valid base was found
113          */
114         if(empty($first)) {
115           $first = $dep['dn'];
116         }
118         $value = $ids[$dep];
119         if ($this->selectedBase == $dep){
120           $found = TRUE;
121           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
122         } else {
123           $options.= "<option value='".$dep."'>$value</option>";
124         }
125       }
126     }
128     /* The currently used base is not visible with your acl setup.
129      * Set base to first useable base.
130      */
131     if(!$found){
132       $this->selectedBase = $first;
133     }
135     /* Get copy & paste icon */
136     $acls  = $ui->get_permissions($this->selectedBase,"user/user");
137     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"users");
139     /* Add default header */
140     $listhead = MultiSelectWindow::get_default_header();
142     /* Add department selector */
143     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
144       " <input class='center' type='image' src='images/list_submit.png' align='middle'
145       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
146     $listhead .="</div>";
148     $this->SetListHeader($listhead);
149   }
152   function execute()
153   {
154     $this->ClearElementsList();
155     $this->GenHeader();
156     $this->reload();
157     $this->SetEntries($this->list);
158     return($this->Draw());
159   }
161   
162   function SetEntries($list)
163   {
164       /* Add Copy & Paste buttons if copy&paste is enabled
165      */
166     // Defining Links
167     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
168     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
170     $ui = get_userinfo();
172     // Assigning users
173     foreach($list as $key => $val){
175       if(in_array($val['cn'][0],$this->Targets_used)) continue;
177       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
178       if(!isset($val['description'][0])){
179         $desc = "";
180       }else{
181         $desc = " - [ ".$val['description'][0]." ]";
182       }
184       $img1 = "<img src='images/select_user.png'  alt='"._("User")."'  ".$title.">";
185       $img2 = "<img src='images/select_groups.png' alt='"._("Group")."' ".$title.">";
187       if(in_array("posixGroup",$val['objectClass'])){
188         $img = $img2;
189       }else{
190         $img = $img1;
191       }
193       /* Create each field */
194       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
195                       "attach" => "style='width:20px;'");
196       $field1 = array("string" => $img, 
197                       "attach" => "style='text-   align:center;width: 20px;'");
198       $field2 = array("string" => $val['cn'][0].$desc, 
199                       "attach" => "style='border-right:0px;' ".$title);
201       $this->AddElement(array($field0,$field1,$field2));
202     }
203   }
205   
206   function save()
207   { 
208     $ret = array();
209     $items = $this->list_get_selected_items();
210     foreach($items as $item){
211       $ret[] = $this->list[$item];
212     }
213     return($ret);
214   }
217   function save_object()
218   {
219     MultiSelectWindow::save_object();
220   }
222   
223   function reload()
224   {
225     /* Set base for all searches && initialise some vars */
226     $this->list= array();
227     $base     = $this->selectedBase;
228     $filter   = "(&(objectClass=person)(objectClass=gosaAccount))";
229     $Regex    = $this->Regex;
231     /* Create filter */
232     $filter= "(&(cn=".$Regex.")(|".$filter."))";
234     if($this->SubSearch){
235       $res = array();
236       if($this->user){
237         $filter   = "(&(objectClass=person)(objectClass=gosaAccount))";
238         $filter= "(&(cn=".$Regex.")(|".$filter."))";
239         $res= array_merge($res,get_sub_list($filter, array("users"), array(get_people_ou()),$base, 
240               array("cn","uid","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH));
241       }
242       if($this->group){
243         $filter   = "(objectClass=posixGroup)";
244         $filter= "(&(cn=".$Regex.")(|".$filter."))";
245         $res= array_merge($res,get_sub_list($filter, array("groups"), array(get_groups_ou()),$base, 
246               array("cn","uid","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH));
247       }
248     }else{
249       $res= get_list($filter, array("users"), get_people_ou().$base, 
250             array("cn","uid","objectClass","description"), GL_SIZELIMIT );
251       $res = array();
252       if($this->user){
253         $filter   = "(&(objectClass=person)(objectClass=gosaAccount))";
254         $filter= "(&(cn=".$Regex.")(|".$filter."))";
255         $res= array_merge($res,get_list($filter, array("users"), get_people_ou().$base, 
256               array("cn","uid","objectClass","description"), GL_SIZELIMIT ));
257       }
258       if($this->group){
259         $filter   = "(objectClass=posixGroup)";
260         $filter= "(&(cn=".$Regex.")(|".$filter."))";
261         $res= array_merge($res,get_list($filter, array("groups"), get_groups_ou().$base, 
262               array("cn","uid","objectClass","description"), GL_SIZELIMIT ));
263       }
264     }
266     $this->list= $res;
267     ksort ($this->list);
268     reset ($this->list);
269     $tmp=array();
270     foreach($this->list as $tkey => $val ){
271       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
272     }
273     ksort($tmp);
274     $this->list=array();
275     foreach($tmp as $val){
276       $this->list[]=$val;
277     }
278     reset ($this->list);
279   }
281   function list_get_selected_items()
282   {
283     $ids = array();
284     foreach($_POST as $name => $value){
285       if(preg_match("/^item_selected_[0-9]*$/",$name)){
286         $id   = preg_replace("/^item_selected_/","",$name);
287         $ids[$id] = $id;
288       }
289     }
290     return($ids);
291   }
295 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
296 ?>