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