Code

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