Code

Udpate sudo class variable type
[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   public $config;
26   private $list         =array();
27   private $Targets_used =array();
29   /* Current base */
30   public $departments        = array();
32   /* Regex */
33   protected $Regex              = "*";
35   /* CheckBoxes, to change default values modify $this->AddCheckBox */
36   protected $user       ;
37   protected $group      ;
39   /* Subsearch checkbox */
40   protected $SubSearch          ;
41   protected $parent             ;
42   protected $ui                 ;
44   function target_list_users(&$config,$Targets_used)
45   {
46     MultiSelectWindow::MultiSelectWindow($config, "Targetselection", array("users"));
48     $this->Targets_used  = $Targets_used;
50     $this->SetInformation(  _("Select the target objects"));
51     $this->SetTitle(        _("Available members"));
52     $this->SetSummary(      _("Available members"));
53     $this->SetHeadpageMode(FALSE);
55     /* set Page header */
56     $chk = "<input type='checkbox' id='select_all' name='select_all'
57       onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
58     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
60     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
61     $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''"));
63     $this->AddCheckBox("user",    _("Select to see users") ,_("Show users"), true);
64     $this->AddCheckBox("group",   _("Select to see groups"),_("Show groups"), true);
66     /* Add SubSearch checkbox */
67     $this->AddCheckBox(SEPERATOR);
69     /* Add SubSearch checkbox */
70     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
72     /* Name,Text,Default  , Connect with alphabet  */
73     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
74     $this->EnableAplhabet(TRUE);
75   }
78   function GenHeader()
79   {
80     $options= "";
82     /* Get all departments within this subtree */
83     $ui= get_userinfo();
84     $first = "";
85     $found = FALSE;
86     $base = $this->config->current['BASE'];
88     /* Add base */
89     $tmp = array();
90     $tmp[] = array("dn"=>$this->config->current['BASE']);
91     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
92           array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
94     $deps = array();
95     foreach($tmp as $tm){
96       $deps[$tm['dn']] = $tm['dn'];
97     }
99     /* Load possible departments */
100     $ui= get_userinfo();
101     $tdeps= $ui->get_module_departments("users");
102     $ids = $this->config->idepartments;
103     $first = "";
104     $found = FALSE;
105     foreach($ids as $dep => $name){
106       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
108         /* Keep first base dn in mind, we could need this
109          *  info if no valid base was found
110          */
111         if(empty($first)) {
112           $first = $dep['dn'];
113         }
115         $value = $ids[$dep];
116         if ($this->selectedBase == $dep){
117           $found = TRUE;
118           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
119         } else {
120           $options.= "<option value='".$dep."'>$value</option>";
121         }
122       }
123     }
125     /* The currently used base is not visible with your acl setup.
126      * Set base to first useable base.
127      */
128     if(!$found){
129       $this->selectedBase = $first;
130     }
132     /* Get copy & paste icon */
133     $acls  = $ui->get_permissions($this->selectedBase,"user/user");
134     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"users");
136     /* Add default header */
137     $listhead = MultiSelectWindow::get_default_header();
139     /* Add department selector */
140     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
141       " <input class='center' type='image' src='images/lists/submit.png' align='middle'
142       title='"._("Apply")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
143     $listhead .="</div>";
145     $this->SetListHeader($listhead);
146   }
149   function execute()
150   {
151     $this->ClearElementsList();
152     $this->GenHeader();
153     $this->reload();
154     $this->SetEntries($this->list);
155     return($this->Draw());
156   }
159   function SetEntries($list)
160   {
161     /* Add Copy & Paste buttons if copy&paste is enabled
162      */
163     // Defining Links
164     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
166     $ui = get_userinfo();
168     // Assigning users
169     foreach($list as $key => $val){
171       if(in_array($val['cn'][0],$this->Targets_used)) continue;
173       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
174       if(!isset($val['description'][0])){
175         $desc = "";
176       }else{
177         $desc = " - [ ".$val['description'][0]." ]";
178       }
180       $img1 = "<img src='images/select_user.png'  alt='"._("User")."'  ".$title.">";
181       $img2 = "<img src='plugins/groups/images/groups.png' alt='"._("Group")."' ".$title.">";
183       if(in_array("posixGroup",$val['objectClass'])){
184         $img = $img2;
185       }else{
186         $img = $img1;
187       }
189       /* Create each field */
190       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
191           "attach" => "style='width:20px;'");
192       $field1 = array("string" => $img, 
193           "attach" => "style='text-   align:center;width: 20px;'");
194       $field2 = array("string" => $val['cn'][0].$desc, 
195           "attach" => "style='border-right:0px;' ".$title);
197       $this->AddElement(array($field0,$field1,$field2));
198     }
199   }
202   function save()
203   { 
204     $ret = array();
205     $items = $this->list_get_selected_items();
206     foreach($items as $item){
207       $ret[] = $this->list[$item];
208     }
209     return($ret);
210   }
213   function save_object()
214   {
215     MultiSelectWindow::save_object();
216   }
219   function reload()
220   {
221     /* Set base for all searches && initialise some vars */
222     $this->list= array();
223     $base     = $this->selectedBase;
224     $Regex    = $this->Regex;
226     /* Create filter */
228     if($this->SubSearch){
229       $res = array();
230       if($this->user){
231         $filter   = "(&(objectClass=person)(objectClass=gosaAccount))";
232         $filter= "(&(|(cn=".$Regex.")(uid=".$Regex."))(|".$filter."))";
233         $res= array_merge($res,get_sub_list($filter, array("users"), array(get_people_ou()),$base, 
234               array("cn","uid","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH));
235       }
236       if($this->group){
237         $filter   = "(objectClass=posixGroup)";
238         $filter= "(&(|(cn=".$Regex.")(uid=".$Regex."))(|".$filter."))";
239         $res= array_merge($res,get_sub_list($filter, array("groups"), array(get_groups_ou()),$base, 
240               array("cn","uid","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH));
241       }
242     }else{
243       $res = array();
244       if($this->user){
245         $filter   = "(&(objectClass=person)(objectClass=gosaAccount))";
246         $filter= "(&(|(cn=".$Regex.")(uid=".$Regex."))(|".$filter."))";
247         $res= array_merge($res,get_list($filter, array("users"), get_people_ou().$base, 
248               array("cn","uid","objectClass","description"), GL_SIZELIMIT ));
249       }
250       if($this->group){
251         $filter   = "(objectClass=posixGroup)";
252         $filter= "(&(|(cn=".$Regex.")(uid=".$Regex."))(|".$filter."))";
253         $res= array_merge($res,get_list($filter, array("groups"), get_groups_ou().$base, 
254               array("cn","uid","objectClass","description"), GL_SIZELIMIT ));
255       }
256     }
258     $this->list= $res;
259     ksort ($this->list);
260     reset ($this->list);
261     $tmp=array();
262     foreach($this->list as $tkey => $val ){
263       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
264     }
265     ksort($tmp);
266     $this->list=array();
267     foreach($tmp as $val){
268       $this->list[]=$val;
269     }
270     reset ($this->list);
271   }
273   function list_get_selected_items()
274   {
275     $ids = array();
276     foreach($_POST as $name => $value){
277       if(preg_match("/^item_selected_[0-9]*$/",$name)){
278         $id   = preg_replace("/^item_selected_/","",$name);
279         $ids[$id] = $id;
280       }
281     }
282     return($ids);
283   }
286 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
287 ?>