bb91452dd27445ed37f46df15324d5a6b9f96c2a
1 <?php
3 class target_list extends MultiSelectWindow
4 {
5 var $config;
6 var $list =array();
7 var $Targets_used =array();
9 /* Current base */
10 var $selectedBase = "";
11 var $departments = array();
13 /* Regex */
14 var $Regex = "*";
16 /* CheckBoxes, to change default values modify $this->AddCheckBox */
17 var $ogroups ;
18 var $servers ;
19 var $workstations ;
22 /* Subsearch checkbox */
23 var $SubSearch ;
24 var $parent ;
25 var $ui ;
29 function target_list($config,$Targets_used)
30 {
31 MultiSelectWindow::MultiSelectWindow($config, "Targetselection", array("ogroup","gotomasses"));
33 $this->SetInformation( _("Select the target objects for your scheduled action."));
34 $this->SetTitle( _("Available targets"));
35 $this->SetSummary( _("Available targets"));
36 $this->SetHeadpageMode(FALSE);
38 /* set Page header */
39 $chk = "<input type='checkbox' id='select_all' name='select_all'
40 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
41 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
43 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
44 $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''"));
46 /* Text ,Value, Name, Is selected */
47 $this->AddCheckBox("ogroups", _("Select to see object groups"), _("Show object object groups"), true);
48 $this->AddCheckBox("servers", _("Select to see servers") , _("Show servers"), true);
49 $this->AddCheckBox("workstations", _("Select to see workstations"),_("Show workstations"), true);
51 /* Add SubSearch checkbox */
52 $this->AddCheckBox(SEPERATOR);
53 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
55 /* Name,Text,Default , Connect with alphabet */
56 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
57 $this->EnableAplhabet(TRUE);
58 }
61 function GenHeader()
62 {
63 $options= "";
65 /* Get all departments within this subtree */
66 $ui= get_userinfo();
67 $first = "";
68 $found = FALSE;
69 $base = $this->config->current['BASE'];
71 /* Add base */
72 $tmp = array();
73 $tmp[] = array("dn"=>$this->config->current['BASE']);
74 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
75 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
77 $deps = array();
78 foreach($tmp as $tm){
79 $deps[$tm['dn']] = $tm['dn'];
80 }
82 /* Load possible departments */
83 $ui= get_userinfo();
84 $tdeps= $ui->get_module_departments("ogroups");
85 $ids = $this->config->idepartments;
86 $first = "";
87 $found = FALSE;
88 foreach($ids as $dep => $name){
89 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
91 /* Keep first base dn in mind, we could need this
92 * info if no valid base was found
93 */
94 if(empty($first)) {
95 $first = $dep['dn'];
96 }
98 $value = $ids[$dep];
99 if ($this->selectedBase == $dep){
100 $found = TRUE;
101 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
102 } else {
103 $options.= "<option value='".$dep."'>$value</option>";
104 }
105 }
106 }
108 /* The currently used base is not visible with your acl setup.
109 * Set base to first useable base.
110 */
111 if(!$found){
112 $this->selectedBase = $first;
113 }
115 /* Get copy & paste icon */
116 $acls = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
117 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
119 /* Add default header */
120 $listhead = MultiSelectWindow::get_default_header();
122 /* Add department selector */
123 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
124 " <input class='center' type='image' src='images/list_submit.png' align='middle'
125 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
126 $listhead .="</div>";
128 $this->SetListHeader($listhead);
129 }
132 function execute()
133 {
134 $this->ClearElementsList();
135 $this->GenHeader();
136 $this->reload();
137 $this->SetEntries($this->list);
138 foreach($this->list as $key => $data){
140 }
141 return($this->Draw());
142 }
145 function SetEntries($list)
146 {
147 /* Add Copy & Paste buttons if copy&paste is enabled
148 */
149 // Defining Links
150 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
151 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
153 $ui = get_userinfo();
155 // Assigning ogroups
156 foreach($list as $key => $val){
158 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
159 if(!isset($val['description'][0])){
160 $desc = "";
161 }else{
162 $desc = " - [ ".$val['description'][0]." ]";
163 }
165 $img ="Hmm";
166 if(in_array("goServer",$val['objectClass'])){
167 $img = "<img src='images/select_server.png' alt='"._("Server")."' ".$title.">";
168 }elseif(in_array("gotoWorkstation",$val['objectClass'])){
169 $img = "<img src='images/select_workstation.png' alt='"._("Workstation")."' ".$title.">";
170 }elseif(in_array("gosaGroupOfNames",$val['objectClass'])){
171 $img = "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">";
172 }
174 /* Create each field */
175 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
176 "attach" => "style='width:20px;'");
177 $field1 = array("string" => $img,
178 "attach" => "style='text- align:center;width: 20px;'");
179 $field2 = array("string" => $val['cn'][0].$desc,
180 "attach" => "style='border-right:0px;' ".$title);
182 $this->AddElement(array($field0,$field1,$field2));
183 }
184 }
187 function save()
188 {
189 $ret = array();
190 $items = $this->list_get_selected_items();
191 foreach($items as $item){
192 $ret[] = $this->list[$item];
193 }
194 return($ret);
195 }
198 function save_object()
199 {
200 MultiSelectWindow::save_object();
201 }
204 function reload()
205 {
206 /* Set base for all searches && initialise some vars */
207 $this->list= array();
208 $base = $this->selectedBase;
209 $filter = "";
210 $Regex = $this->Regex;
212 $chk = array(
213 "ogroups" => "(objectClass=gosaGroupOfNames)" ,
214 "servers" => "(objectClass=goServer)" ,
215 "workstations" => "(objectClass=gotoWorkstation)");
217 /* Create filter */
218 foreach($chk as $chkBox => $FilterPart){
219 if($this->$chkBox){
220 $filter .= $FilterPart;
221 }
222 }
223 $filter= "(&(cn=".$Regex.")(|".$filter."))";
225 if($this->SubSearch){
226 $res= get_list($filter, array("ogroups","workstations","servers"), $base,
227 array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH);
228 }else{
229 $res= get_list($filter, "ogroups", get_groups_ou().$base,
230 array("cn","objectClass"), GL_SIZELIMIT );
231 $res= array_merge($res,get_list($filter, "workstation", "ou=workstations,ou=systems,".$base,
232 array("cn","objectClass"), GL_SIZELIMIT ));
233 $res= array_merge($res,get_list($filter, "server", "ou=servers,ou=systems,".$base,
234 array("cn","objectClass"), GL_SIZELIMIT ));
236 }
238 $this->list= $res;
239 ksort ($this->list);
240 reset ($this->list);
241 $tmp=array();
242 foreach($this->list as $tkey => $val ){
243 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
244 }
245 ksort($tmp);
246 $this->list=array();
247 foreach($tmp as $val){
248 $this->list[]=$val;
249 }
250 reset ($this->list);
251 }
253 function list_get_selected_items()
254 {
255 $ids = array();
256 foreach($_POST as $name => $value){
257 if(preg_match("/^item_selected_[0-9]*$/",$name)){
258 $id = preg_replace("/^item_selected_/","",$name);
259 $ids[$id] = $id;
260 }
261 }
262 return($ids);
263 }
264 }
267 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
268 ?>