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 = 90;
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 /* Add Copy & Paste header */
223 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
225 /* Add snapshot icons */
226 $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
228 $this->SetDropDownHeaderMenu($s);
229 $this->SetListHeader($listhead);
230 }
233 function execute()
234 {
235 $this->ClearElementsList();
236 $this->GenHeader();
237 }
239 function setEntries($list)
240 {
241 /* Add Copy & Paste buttons if copy&paste is enabled
242 */
243 // Defining Links
244 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
245 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
246 $userimg = "<img class='center' src='plugins/groups/images/groups.png' alt='User' title='%s'>";
247 $mailimg = "<img class='center' src='plugins/ogroups/images/mail.png' alt='M' title='"._("Mail") ."'>";
248 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
250 /* Dynamic action col, depending on snapshot icons */
251 $action_col_size = 90;
252 if($this->parent->snapshotEnabled()){
253 $action_col_size += 38;
254 }
256 $ui = get_userinfo();
258 // Assigning ogroups
259 foreach($list as $key => $val){
261 $actions = "";
263 /* Create action icons */
264 $acl = $ui->get_permissions($val['dn'],"ogroups/ogroup");
265 $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
267 /* Add copy & cut functionality */
268 $actions.= $this->parent->get_copypaste_action($val['dn'],"ogroups","ogroup");
270 $actions.= "<input class='center' type='image'
271 src='images/lists/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
273 $actions.= $this->parent->get_snapshot_action($val['dn'],$this->module);
275 if(preg_match("/d/",$acl)){
276 $actions.= "<input class='center' type='image'
277 src='images/lists/trash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
278 }else{
279 $actions.= "<img class='center' src='images/empty.png' alt=' '
280 title='".msgPool::permDelete()."'>";
281 }
283 if(isset($val['mail'])){
284 $mail = $mailimg;
285 }else{
286 $mail = $empty;
287 }
288 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
289 if(!isset($val['description'][0])){
290 $desc = "";
291 }else{
292 $desc = " - [ ".$val['description'][0]." ]";
293 }
295 /* Cutted objects should be displayed in light grey */
296 $display = $val['cn'][0].$desc;
297 if($this->parent->CopyPasteHandler){
298 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
299 if($queue_data['dn'] == $val['dn']) {
300 $display = "<font color='#999999'>".$display."</font>";
301 break;
302 }
303 }
304 }
306 /* Create each field */
307 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
308 "attach" => "style='width:20px;'");
309 $field1 = array("string" => "<img src='plugins/ogroups/images/ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
310 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
311 $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))." ".$mail, "attach" => "style='width:136px;'");
312 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
314 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
315 }
318 /* Create summary string for list footer */
319 $num_deps=0;
320 if(!$this->SubSearch){
321 $num_deps = count($this->Added_Departments);
322 }
323 $num_objs = count($list);
325 $num_obj_str = _("Number of listed object groups");
326 $num_dep_str = _("Number of listed departments");
328 $str = "<img class='center' src='plugins/ogroups/images/ogroup.png'
329 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
330 $str.= "<img class='center' src='images/lists/folder.png'
331 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
333 $this->set_List_Bottom_Info($str);
334 }
336 function Save()
337 {
338 MultiSelectWindow :: Save();
339 }
341 function save_object()
342 {
343 /* Save automatic created POSTs like regex, checkboxes */
344 MultiSelectWindow::save_object();
345 }
346 }
347 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
348 ?>