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$$
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 divListOGroup extends MultiSelectWindow
24 {
26 /* Current base */
27 var $selectedBase = "";
28 var $departments = array();
30 /* Regex */
31 var $Regex = "*";
33 /* CheckBoxes, to change default values modify $this->AddCheckBox */
34 var $UserGroups ;
35 var $GroupGroups ;
36 var $ApplicationGroups ;
37 var $DepartmentGroups ;
38 var $ServerGroups ;
39 var $WorkstationGroups ;
40 var $WindowsGroups ;
41 var $TerminalGroups ;
42 var $PrinterGroups ;
43 var $PhoneGroups ;
46 /* Subsearch checkbox */
47 var $SubSearch ;
48 var $parent ;
49 var $ui ;
51 function divListOGroup (&$config,$parent)
52 {
53 MultiSelectWindow::MultiSelectWindow($config, "OGroups", "ogroups");
55 $this->parent = $parent;
56 $this->ui = get_userinfo();
58 /* Set list strings */
59 $this->SetTitle(_("List of object groups"));
60 $this->SetSummary(_("List of object groups"));
61 $this->EnableAplhabet(true);
63 /* Result page will look like a headpage */
64 $this->SetHeadpageMode();
66 /* Disable buttonsm */
67 $this->EnableCloseButton(false);
68 $this->EnableSaveButton (false);
70 /* Dynamic action col, depending on snapshot icons */
71 $action_col_size = 80;
72 if($this->parent->snapshotEnabled()){
73 $action_col_size += 38;
74 }
76 /* Toggle all selected / deselected */
77 $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
78 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
80 /* set Page header */
81 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
82 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
83 $this->AddHeader(array("string" => _("Object group")." / "._("Department"), "attach" => "style=''"));
84 $this->AddHeader(array("string" => _("Properties"), "attach" => "style='width:136px;'"));
85 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
87 /* Text ,Value ,Name ,Is selected */
88 $str2 = _("Show %s");
89 $this->AddCheckBox("UserGroups" , sprintf($str2, _("user groups")),
90 sprintf($str2, _("user groups")), true);
91 $this->AddCheckBox("GroupGroups" , sprintf($str2, _("nested groups")),
92 sprintf($str2, _("nested groups")), true);
93 $this->AddCheckBox("ApplicationGroups", sprintf($str2, _("application groups")),
94 sprintf($str2, _("application groups")), true);
95 $this->AddCheckBox("DepartmentGroups" , sprintf($str2, _("department groups")),
96 sprintf($str2, _("department groups")), true);
97 $this->AddCheckBox("ServerGroups" , sprintf($str2, _("server groups")),
98 sprintf($str2, _("server groups")), true);
99 $this->AddCheckBox("WorkstationGroups", sprintf($str2, _("workstation groups")),
100 sprintf($str2, _("workstation groups")), true);
101 $this->AddCheckBox("WindowsGroups", sprintf($str2, _("windows workstation groups")),
102 sprintf($str2, _("windows workstation groups")), true);
103 $this->AddCheckBox("TerminalGroups" , sprintf($str2, _("terminal groups")),
104 sprintf($str2, _("terminal groups")), true);
105 $this->AddCheckBox("PrinterGroups" , sprintf($str2, _("printer groups")),
106 sprintf($str2, _("printer groups")), true);
107 $this->AddCheckBox("PhoneGroups" , sprintf($str2, _("phone groups")),
108 sprintf($str2, _("phone groups")), true);
110 /* Add SubSearch checkbox */
111 $this->AddCheckBox(SEPERATOR);
112 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
114 /* Name ,Text ,Default , Connect with alphabet */
115 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
116 }
119 function GenHeader()
120 {
121 /* Prepare departments,
122 which are shown in the listbox on top of the listbox
123 */
124 $options= "";
126 /* Get all departments within this subtree */
127 $ui= get_userinfo();
128 $first = "";
129 $found = FALSE;
130 $base = $this->config->current['BASE'];
132 /* Add base */
133 $tmp = array();
134 $tmp[] = array("dn"=>$this->config->current['BASE']);
135 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
136 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
138 $deps = array();
139 foreach($tmp as $tm){
140 $deps[$tm['dn']] = $tm['dn'];
141 }
143 /* Load possible departments */
144 $ui= get_userinfo();
145 $tdeps= $ui->get_module_departments("ogroups");
146 $ids = $this->config->idepartments;
147 $first = "";
148 $found = FALSE;
149 foreach($ids as $dep => $name){
150 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
152 /* Keep first base dn in mind, we could need this
153 * info if no valid base was found
154 */
155 if(empty($first)) {
156 $first = $dep['dn'];
157 }
159 $value = $ids[$dep];
160 if ($this->selectedBase == $dep){
161 $found = TRUE;
162 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
163 } else {
164 $options.= "<option value='".$dep."'>$value</option>";
165 }
166 }
167 }
169 /* The currently used base is not visible with your acl setup.
170 * Set base to first useable base.
171 */
172 if(!$found){
173 $this->selectedBase = $first;
174 }
176 /* Add a seperator after displaying c&p and snapshot icons ? */
177 $add_sep = false;
179 /* Get copy & paste icon */
180 $acls = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
181 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
184 /* Add default header */
185 $listhead = MultiSelectWindow::get_default_header();
187 /* Add department selector */
188 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
189 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
190 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
193 /* Create Layers menu */
194 $s = ".|"._("Actions")."|\n";
196 /* Append create options */
197 if(preg_match("/c/",$acls)) {
198 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
199 " "._("Create")."|\n";
200 $s.= "...|<input class='center' type='image' src='plugins/ogroups/images/new.png' alt=''>".
201 " "._("Object group")."|group_new|\n";
202 }
204 /* Multiple options */
205 $s.= "..|---|\n";
206 # $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
207 # " "._("Edit")."|"."multiple_edit|\n";
208 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
209 " "._("Remove")."|"."remove_multiple_ogroups/|\n";
211 /* Add event tag */
212 if(class_available("DaemonEvent")){
213 $events = DaemonEvent::get_event_types(USER_EVENT);
214 if(count($events['BY_CLASS'])){
215 $s.= "..|---|\n";
216 foreach($events['BY_CLASS'] as $name => $event){
217 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|event_".$name."\n";
218 }
219 }
220 }
222 if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
223 $s.= "..|---|\n";
224 $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
225 " "._("Copy")."|"."multiple_copy_systems|\n";
227 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(r.*d|d.*r)/",$acl_all)){
228 $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
229 " "._("Cut")."|"."multiple_cut_systems|\n";
230 }
231 }
233 /* Copy & paste icons */
234 if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
235 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
236 $s.="..|".$img." "._("Paste")."|editPaste|\n";
237 }else{
238 $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
239 $s.="..|".$img." "._("Paste")."\n";
240 }
242 /* Add snapshot icons */
243 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
244 $s .= "..|---|\n";
245 $s .= $this->get_snapshot_header(TRUE);
246 }
248 $this->SetDropDownHeaderMenu($s);
249 $this->SetListHeader($listhead);
250 }
253 function execute()
254 {
255 $this->ClearElementsList();
256 $this->GenHeader();
257 }
259 function setEntries($list)
260 {
261 /* Add Copy & Paste buttons if copy&paste is enabled
262 */
263 // Defining Links
264 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
265 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
266 $userimg = "<img class='center' src='plugins/groups/images/groups.png' alt='User' title='%s'>";
267 $mailimg = "<img class='center' src='plugins/ogroups/images/mail.png' alt='M' title='"._("Mail") ."'>";
268 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
270 /* Dynamic action col, depending on snapshot icons */
271 $action_col_size = 80;
272 if($this->parent->snapshotEnabled()){
273 $action_col_size += 38;
274 }
276 $ui = get_userinfo();
278 // Assigning ogroups
279 foreach($list as $key => $val){
281 /* Create action icons */
282 $acl = $ui->get_permissions($val['dn'],"ogroups/ogroup");
283 $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
285 // Cut
286 $actions= "";
287 if(preg_match("/(r.*d|r.*d)/",$acl_all) && $this->parent->CopyPasteHandler){
288 $actions .= "<input class='center' type='image'
289 src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
290 }else{
291 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
292 }
294 // Copy
295 if(preg_match("/r/",$acl_all) && $this->parent->CopyPasteHandler){
296 $actions.= "<input class='center' type='image'
297 src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
298 }else{
299 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
300 }
303 $actions.= "<input class='center' type='image'
304 src='images/lists/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
306 if(preg_match("/(r.*w|w.*r)/",$acl_all)){
307 $actions.= $this->GetSnapShotActions($val['dn']);
308 }else{
309 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
310 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
311 }
313 if(preg_match("/d/",$acl)){
314 $actions.= "<input class='center' type='image'
315 src='images/lists/trash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
316 }else{
317 $actions.= "<img class='center' src='images/empty.png' alt=' '
318 title='".msgPool::permDelete()."'>";
319 }
321 if(isset($val['mail'])){
322 $mail = $mailimg;
323 }else{
324 $mail = $empty;
325 }
326 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
327 if(!isset($val['description'][0])){
328 $desc = "";
329 }else{
330 $desc = " - [ ".$val['description'][0]." ]";
331 }
333 /* Cutted objects should be displayed in light grey */
334 $display = $val['cn'][0].$desc;
335 if($this->parent->CopyPasteHandler){
336 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
337 if($queue_data['dn'] == $val['dn']) {
338 $display = "<font color='#999999'>".$display."</font>";
339 break;
340 }
341 }
342 }
344 /* Create each field */
345 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
346 "attach" => "style='width:20px;'");
347 $field1 = array("string" => "<img src='plugins/ogroups/images/ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
348 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
349 $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))." ".$mail, "attach" => "style='width:136px;'");
350 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
352 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
353 }
356 /* Create summary string for list footer */
357 $num_deps=0;
358 if(!$this->SubSearch){
359 $num_deps = count($this->Added_Departments);
360 }
361 $num_objs = count($list);
363 $num_obj_str = _("Number of listed object groups");
364 $num_dep_str = _("Number of listed departments");
366 $str = "<img class='center' src='plugins/ogroups/images/ogroup.png'
367 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
368 $str.= "<img class='center' src='images/lists/folder.png'
369 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
371 $this->set_List_Bottom_Info($str);
372 }
374 function Save()
375 {
376 MultiSelectWindow :: Save();
377 }
379 function save_object()
380 {
381 /* Save automatic created POSTs like regex, checkboxes */
382 MultiSelectWindow::save_object();
383 }
384 }
385 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
386 ?>