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");
182 $Copy_Paste ="";
183 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
184 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
185 $add_sep = true;
186 }
188 /* Add default header */
189 $listhead = MultiSelectWindow::get_default_header();
192 /* Add department selector */
193 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
194 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
195 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
198 /* Create Layers menu */
199 $s = ".|"._("Actions")."|\n";
200 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
201 " "._("Create")."|\n";
203 /* Append create options */
204 if(preg_match("/c/",$acls)) {
205 $s.= "...|<input class='center' type='image' src='plugins/ogroups/images/new.png' alt=''>".
206 " "._("Object group")."|group_new|\n";
207 }
209 /* Multiple options */
210 $s.= "..|---|\n";
211 # $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
212 # " "._("Edit")."|"."multiple_edit|\n";
214 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
215 " "._("Remove")."|"."remove_multiple_ogroups/|\n";
217 /* Add event tag */
218 if(class_available("DaemonEvent")){
219 $events = DaemonEvent::get_event_types(USER_EVENT);
220 if(count($events['BY_CLASS'])){
221 $s.= "..|---|\n";
222 foreach($events['BY_CLASS'] as $name => $event){
223 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|event_".$name."\n";
224 }
225 }
226 }
228 /* Add multiple copy & cut icons */
229 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
230 $s.= "..|---|\n";
231 $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
232 " "._("Copy")."|"."multiple_copy_systems|\n";
233 $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
234 " "._("Cut")."|"."multiple_cut_systems|\n";
236 if($this->parent->CopyPasteHandler->entries_queued()){
237 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
238 $s.="..|".$img." "._("Paste")."|editPaste|\n";
239 }else{
240 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
241 $s.="..|".$img." "._("Paste")."\n";
242 }
243 }
245 /* Add snapshot icons */
246 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
247 $s .= "..|---|\n";
248 $s .= $this->get_snapshot_header(TRUE);
249 }
251 $this->SetDropDownHeaderMenu($s);
252 $this->SetListHeader($listhead);
253 }
255 function execute()
256 {
257 $this->ClearElementsList();
258 $this->GenHeader();
259 }
261 function setEntries($list)
262 {
263 /* Add Copy & Paste buttons if copy&paste is enabled
264 */
265 // Defining Links
266 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
267 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
268 $userimg = "<img class='center' src='plugins/groups/images/groups.png' alt='User' title='%s'>";
269 $mailimg = "<img class='center' src='plugins/ogroups/images/mail.png' alt='M' title='"._("Mail") ."'>";
270 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
272 /* Dynamic action col, depending on snapshot icons */
273 $action_col_size = 80;
274 if($this->parent->snapshotEnabled()){
275 $action_col_size += 38;
276 }
278 $ui = get_userinfo();
280 // Assigning ogroups
281 foreach($list as $key => $val){
283 /* Create action icons */
284 $actions= "";
285 $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
286 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
287 $actions.= "<input class='center' type='image'
288 src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
289 $actions.= "<input class='center' type='image'
290 src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
291 }
293 $actions.= "<input class='center' type='image'
294 src='images/lists/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
296 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
297 $actions.= $this->GetSnapShotActions($val['dn']);
298 }
300 if(preg_match("/d/",$ui->get_permissions($val['dn'],"ogroups/ogroup"))) {
301 $actions.= "<input class='center' type='image'
302 src='images/lists/trash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
303 }else{
304 $actions.= "<img class='center' src='images/empty.png' alt=' '
305 title='".msgPool::permDelete()."'>";
306 }
309 if(isset($val['mail'])){
310 $mail = $mailimg;
311 }else{
312 $mail = $empty;
313 }
314 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
315 if(!isset($val['description'][0])){
316 $desc = "";
317 }else{
318 $desc = " - [ ".$val['description'][0]." ]";
319 }
321 /* Cutted objects should be displayed in light grey */
322 $display = $val['cn'][0].$desc;
323 if($this->parent->CopyPasteHandler){
324 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
325 if($queue_data['dn'] == $val['dn']) {
326 $display = "<font color='#999999'>".$display."</font>";
327 break;
328 }
329 }
330 }
332 /* Create each field */
333 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
334 "attach" => "style='width:20px;'");
335 $field1 = array("string" => "<img src='plugins/ogroups/images/ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
336 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
337 $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))." ".$mail, "attach" => "style='width:136px;'");
338 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
340 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
341 }
344 /* Create summary string for list footer */
345 $num_deps=0;
346 if(!$this->SubSearch){
347 $num_deps = count($this->Added_Departments);
348 }
349 $num_objs = count($list);
351 $num_obj_str = _("Number of listed object groups");
352 $num_dep_str = _("Number of listed departments");
354 $str = "<img class='center' src='plugins/ogroups/images/ogroup.png'
355 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
356 $str.= "<img class='center' src='images/lists/folder.png'
357 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
359 $this->set_List_Bottom_Info($str);
360 }
362 function Save()
363 {
364 MultiSelectWindow :: Save();
365 }
367 function save_object()
368 {
369 /* Save automatic created POSTs like regex, checkboxes */
370 MultiSelectWindow::save_object();
371 }
372 }
373 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
374 ?>