Code

Updated sudo classes
[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       ;
40   /* Subsearch checkbox */
41   var $SubSearch          ;
42   var $parent             ;
43   var $ui                 ;
44  
45  
46   function target_list_users(&$config,$Targets_used)
47   {
48     MultiSelectWindow::MultiSelectWindow($config, "Targetselection", array("users"));
50     $this->Targets_used = $Targets_used;
51     
52     $this->SetInformation(  _("Select the target objects"));
53     $this->SetTitle(        _("Available targets"));
54     $this->SetSummary(      _("Available targets"));
55     $this->SetHeadpageMode(FALSE);
56     
57     /* set Page header */
58     $chk = "<input type='checkbox' id='select_all' name='select_all'
59                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
60     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
62     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
63     $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''"));
65     /* Add SubSearch checkbox */
66     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
68     /* Name,Text,Default  , Connect with alphabet  */
69     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
70     $this->EnableAplhabet(TRUE);
71   }
74   function GenHeader()
75   {
76     $options= "";
78     /* Get all departments within this subtree */
79     $ui= get_userinfo();
80     $first = "";
81     $found = FALSE;
82     $base = $this->config->current['BASE'];
84     /* Add base */
85     $tmp = array();
86     $tmp[] = array("dn"=>$this->config->current['BASE']);
87     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
88                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
90     $deps = array();
91     foreach($tmp as $tm){
92       $deps[$tm['dn']] = $tm['dn'];
93     }
95     /* Load possible departments */
96     $ui= get_userinfo();
97     $tdeps= $ui->get_module_departments("users");
98     $ids = $this->config->idepartments;
99     $first = "";
100     $found = FALSE;
101     foreach($ids as $dep => $name){
102       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
104         /* Keep first base dn in mind, we could need this
105          *  info if no valid base was found
106          */
107         if(empty($first)) {
108           $first = $dep['dn'];
109         }
111         $value = $ids[$dep];
112         if ($this->selectedBase == $dep){
113           $found = TRUE;
114           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
115         } else {
116           $options.= "<option value='".$dep."'>$value</option>";
117         }
118       }
119     }
121     /* The currently used base is not visible with your acl setup.
122      * Set base to first useable base.
123      */
124     if(!$found){
125       $this->selectedBase = $first;
126     }
128     /* Get copy & paste icon */
129     $acls  = $ui->get_permissions($this->selectedBase,"user/user");
130     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"users");
132     /* Add default header */
133     $listhead = MultiSelectWindow::get_default_header();
135     /* Add department selector */
136     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
137       " <input class='center' type='image' src='images/list_submit.png' align='middle'
138       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
139     $listhead .="</div>";
141     $this->SetListHeader($listhead);
142   }
145   function execute()
146   {
147     $this->ClearElementsList();
148     $this->GenHeader();
149     $this->reload();
150     $this->SetEntries($this->list);
151     return($this->Draw());
152   }
154   
155   function SetEntries($list)
156   {
157       /* Add Copy & Paste buttons if copy&paste is enabled
158      */
159     // Defining Links
160     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
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       $img = "<img src='images/select_user.png' alt='"._("Use")."' ".$title.">";
179       /* Create each field */
180       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
181                       "attach" => "style='width:20px;'");
182       $field1 = array("string" => $img, 
183                       "attach" => "style='text-   align:center;width: 20px;'");
184       $field2 = array("string" => $val['cn'][0].$desc, 
185                       "attach" => "style='border-right:0px;' ".$title);
187       $this->AddElement(array($field0,$field1,$field2));
188     }
189   }
191   
192   function save()
193   { 
194     $ret = array();
195     $items = $this->list_get_selected_items();
196     foreach($items as $item){
197       $ret[] = $this->list[$item];
198     }
199     return($ret);
200   }
203   function save_object()
204   {
205     MultiSelectWindow::save_object();
206   }
208   
209   function reload()
210   {
211     /* Set base for all searches && initialise some vars */
212     $this->list= array();
213     $base     = $this->selectedBase;
214     $filter   = "(&(objectClass=person)(objectClass=gosaAccount))";
215     $Regex    = $this->Regex;
217     /* Create filter */
218     $filter= "(&(cn=".$Regex.")(|".$filter."))";
220     if($this->SubSearch){
221       $res= get_sub_list($filter, array("users"), array(get_people_ou()),$base, 
222             array("cn","uid","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH);
223     }else{
224       $res= get_list($filter, array("users"), get_people_ou().$base, 
225             array("cn","uid","objectClass","description"), GL_SIZELIMIT );
226     }
228     $this->list= $res;
229     ksort ($this->list);
230     reset ($this->list);
231     $tmp=array();
232     foreach($this->list as $tkey => $val ){
233       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
234     }
235     ksort($tmp);
236     $this->list=array();
237     foreach($tmp as $val){
238       $this->list[]=$val;
239     }
240     reset ($this->list);
241   }
243   function list_get_selected_items()
244   {
245     $ids = array();
246     foreach($_POST as $name => $value){
247       if(preg_match("/^item_selected_[0-9]*$/",$name)){
248         $id   = preg_replace("/^item_selected_/","",$name);
249         $ids[$id] = $id;
250       }
251     }
252     return($ids);
253   }
257 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
258 ?>