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 private $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 targets"));
52 $this->SetSummary( _("Available targets"));
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" => " ", "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")." <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='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
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 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
165 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
167 $ui = get_userinfo();
169 // Assigning users
170 foreach($list as $key => $val){
172 if(in_array($val['cn'][0],$this->Targets_used)) continue;
174 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
175 if(!isset($val['description'][0])){
176 $desc = "";
177 }else{
178 $desc = " - [ ".$val['description'][0]." ]";
179 }
181 $img1 = "<img src='images/select_user.png' alt='"._("User")."' ".$title.">";
182 $img2 = "<img src='plugins/groups/images/groups.png' alt='"._("Group")."' ".$title.">";
184 if(in_array("posixGroup",$val['objectClass'])){
185 $img = $img2;
186 }else{
187 $img = $img1;
188 }
190 /* Create each field */
191 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
192 "attach" => "style='width:20px;'");
193 $field1 = array("string" => $img,
194 "attach" => "style='text- align:center;width: 20px;'");
195 $field2 = array("string" => $val['cn'][0].$desc,
196 "attach" => "style='border-right:0px;' ".$title);
198 $this->AddElement(array($field0,$field1,$field2));
199 }
200 }
203 function save()
204 {
205 $ret = array();
206 $items = $this->list_get_selected_items();
207 foreach($items as $item){
208 $ret[] = $this->list[$item];
209 }
210 return($ret);
211 }
214 function save_object()
215 {
216 MultiSelectWindow::save_object();
217 }
220 function reload()
221 {
222 /* Set base for all searches && initialise some vars */
223 $this->list= array();
224 $base = $this->selectedBase;
225 $Regex = $this->Regex;
227 /* Create filter */
229 if($this->SubSearch){
230 $res = array();
231 if($this->user){
232 $filter = "(&(objectClass=person)(objectClass=gosaAccount))";
233 $filter= "(&(|(cn=".$Regex.")(uid=".$Regex."))(|".$filter."))";
234 $res= array_merge($res,get_sub_list($filter, array("users"), array(get_people_ou()),$base,
235 array("cn","uid","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH));
236 }
237 if($this->group){
238 $filter = "(objectClass=posixGroup)";
239 $filter= "(&(|(cn=".$Regex.")(uid=".$Regex."))(|".$filter."))";
240 $res= array_merge($res,get_sub_list($filter, array("groups"), array(get_groups_ou()),$base,
241 array("cn","uid","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH));
242 }
243 }else{
244 $res = array();
245 if($this->user){
246 $filter = "(&(objectClass=person)(objectClass=gosaAccount))";
247 $filter= "(&(|(cn=".$Regex.")(uid=".$Regex."))(|".$filter."))";
248 $res= array_merge($res,get_list($filter, array("users"), get_people_ou().$base,
249 array("cn","uid","objectClass","description"), GL_SIZELIMIT ));
250 }
251 if($this->group){
252 $filter = "(objectClass=posixGroup)";
253 $filter= "(&(|(cn=".$Regex.")(uid=".$Regex."))(|".$filter."))";
254 $res= array_merge($res,get_list($filter, array("groups"), get_groups_ou().$base,
255 array("cn","uid","objectClass","description"), GL_SIZELIMIT ));
256 }
257 }
259 $this->list= $res;
260 ksort ($this->list);
261 reset ($this->list);
262 $tmp=array();
263 foreach($this->list as $tkey => $val ){
264 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
265 }
266 ksort($tmp);
267 $this->list=array();
268 foreach($tmp as $val){
269 $this->list[]=$val;
270 }
271 reset ($this->list);
272 }
274 function list_get_selected_items()
275 {
276 $ids = array();
277 foreach($_POST as $name => $value){
278 if(preg_match("/^item_selected_[0-9]*$/",$name)){
279 $id = preg_replace("/^item_selected_/","",$name);
280 $ids[$id] = $id;
281 }
282 }
283 return($ids);
284 }
285 }
287 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
288 ?>