ab32f37de1f38c766f7eb61e090cbe4e4e1dd104
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 divListGroup extends MultiSelectWindow
24 {
26 /* Current base */
27 var $selectedBase = "";
28 var $departments = array();
30 /* Regex */
31 var $Regex = "*";
32 var $UserRegex = "*";
34 /* CheckBoxes, to change default values modify $this->AddCheckBox */
35 var $ShowPrimaryGroups;
36 var $ShowSambaGroups;
37 var $ShowApplicationGroups;
38 var $ShowMailGroups;
39 var $ShowFunctionalGroups;
41 /* Subsearch checkbox */
42 var $SubSearch = false;
44 var $parent ;
45 var $ui ;
47 function divListGroup (&$config, &$parent)
48 {
49 MultiSelectWindow::MultiSelectWindow($config, "Groups", "groups");
51 $this->parent = &$parent;
52 $this->ui = get_userinfo();
54 /* Set list strings */
55 $this->SetTitle(_("List of groups"));
56 $this->SetSummary(_("List of groups"));
57 $this->EnableAplhabet (true);
59 /* Result page will look like a headpage */
60 $this->SetHeadpageMode();
61 $this->SetInformation(_("This menu allows you to add, edit and remove selected groups. You may want to use the range selector on top of the group listbox, when working with a large number of groups."));
63 /* Disable buttonsm */
64 $this->EnableCloseButton(false);
65 $this->EnableSaveButton (false);
67 /* Dynamic action col, depending on snapshot icons */
68 $action_col_size = 80;
69 if($this->parent->snapshotEnabled()){
70 $action_col_size += 38;
71 }
73 /* Toggle all selected / deselected */
74 $chk = "<input type='checkbox' id='select_all' name='select_all'
75 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
77 /* set Page header */
78 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
79 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
80 $this->AddHeader(array("string"=>_("Groupname / Department")));
81 $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
82 $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
84 /* Text ,Value ,Name ,Is selected */
85 $this->AddCheckBox("ShowPrimaryGroups", _("Select to see groups that are primary groups of users"), _("Show primary groups"), true);
86 $this->AddCheckBox("ShowSambaGroups", _("Select to see groups that have samba groups mappings"), _("Show samba groups"), true);
87 $this->AddCheckBox("ShowApplicationGroups", _("Select to see groups that have applications configured"), _("Show application groups"),true);
88 $this->AddCheckBox("ShowMailGroups", _("Select to see groups that have mail settings"), _("Show mail groups"), true);
89 $this->AddCheckBox("ShowFunctionalGroups", _("Select to see normal groups that have only functional aspects"), _("Show functional groups"), true);
90 $this->AddCheckBox(SEPERATOR);
92 /* Add SubSearch checkbox */
93 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
95 /* Name ,Text ,Default , Connect with alphabet */
96 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
97 $this->AddRegex ("UserRegex", _("User name of which groups are shown"), "*" , false, "images/search_user.png");
98 }
101 function GenHeader()
102 {
103 /* Prepare departments,
104 which are shown in the listbox on top of the listbox
105 */
106 $options= "";
110 /* Get all departments within this subtree */
111 $ui= get_userinfo();
112 $first = "";
113 $found = FALSE;
114 $base = $this->config->current['BASE'];
118 /* Add base */
119 $tmp = array();
120 $tmp[] = array("dn"=>$this->config->current['BASE']);
121 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
122 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
124 $deps = array();
125 foreach($tmp as $tm){
126 $deps[$tm['dn']] = $tm['dn'];
127 }
129 /* Load possible departments */
130 $ui= get_userinfo();
131 $tdeps= $ui->get_module_departments("groups");
132 $ids = $this->config->idepartments;
133 $first = "";
134 $found = FALSE;
135 foreach($ids as $dep => $name){
136 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
138 /* Keep first base dn in mind, we could need this
139 * info if no valid base was found
140 */
141 if(empty($first)) {
142 $first = $dep['dn'];
143 }
145 $value = $ids[$dep];
146 if ($this->selectedBase == $dep){
147 $found = TRUE;
148 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
149 } else {
150 $options.= "<option value='".$dep."'>$value</option>";
151 }
152 }
153 }
155 /* The currently used base is not visible with your acl setup.
156 * Set base to first useable base.
157 */
158 if(!$found){
159 $this->selectedBase = $first;
160 }
162 /* Get acls */
163 $acls = $ui->get_permissions($this->selectedBase,"groups/group");
164 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
167 /* Add default header */
168 $listhead = MultiSelectWindow::get_default_header();
170 /* Add department selection */
171 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
172 " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
173 "'> ";
176 /* Create Layers menu */
177 $s = ".|"._("Actions")."|\n";
178 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
179 " "._("Create")."|\n";
182 /* Append create options */
183 if(preg_match("/c/",$acl_all)) {
184 $s.= "...|<input class='center' type='image' src='images/list_new_group.png' alt=''>".
185 " "._("Group")."|group_new|\n";
186 }
188 /* Multiple options */
189 $s.= "..|---|\n";
190 $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
191 " "._("Edit")."|"."multiple_edit|\n";
192 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
193 " "._("Remove")."|"."remove_multiple|\n";
195 /* Add event tag */
196 if(class_available("DaemonEvent_notify")){
197 $events = DaemonEvent::get_event_types( USER_EVENT);
198 $event = $events['BY_CLASS']['DaemonEvent_notify'];
199 $s.= "..|---|\n";
200 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_DaemonEvent_notify\n";
201 }
204 /* Add multiple copy & cut icons */
205 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
206 $s.= "..|---|\n";
207 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
208 " "._("Copy")."|"."multiple_copy_systems|\n";
209 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
210 " "._("Cut")."|"."multiple_cut_systems|\n";
212 if($this->parent->CopyPasteHandler->entries_queued()){
213 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
214 $s.="..|".$img." "._("Paste")."|editPaste|\n";
215 }else{
216 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
217 $s.="..|".$img." "._("Paste")."\n";
218 }
219 }
221 /* Add snapshot icons */
222 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
223 $s .= "..|---|\n";
224 $s .= $this->get_snapshot_header(TRUE);
225 }
227 $this->SetDropDownHeaderMenu($s);
229 $this->SetListHeader($listhead);
230 }
232 function execute()
233 {
234 $this->ClearElementsList();
235 $this->GenHeader();
236 }
238 function setEntries($groups)
239 {
240 // Defining Links
241 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
243 // image Buttons
244 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
245 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
247 /* Dynamic action col, depending on snapshot icons */
248 $action_col_size = 80;
249 if($this->parent->snapshotEnabled()){
250 $action_col_size += 38;
251 }
253 /* Assign extension images */
254 $posiximg = "<input type='image' class='center' src='images/select_groups.png'
255 name='group_group_edit_%KEY%' alt='P' title='"._("Posix") ."'>";
256 $mailimg = "<input type='image' class='center' src='images/mailto.png'
257 name='mailgroup_group_edit_%KEY%' alt='M' title='"._("Mail") ."'>";
258 $sambaimg = "<input type='image' class='center' src='images/select_winstation.png'
259 name='group_group_edit_%KEY%' alt='S' title='"._("Samba") ."'>";
260 $applimg = "<input type='image' class='center' src='images/select_application.png'
261 name='appgroup_group_edit_%KEY%' alt='A' title='"._("Application")."'>";
262 $phoneimg = "<input type='image' class='center' src='images/select_phone.png'
263 name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone") ."'>";
264 $envimg = "<input type='image' class='center' src='images/smallenv.png'
265 name='environment_group_edit_%KEY%' alt='E' title='"._("Environment") ."'>";
267 // Space
268 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
270 // User and Template Images
271 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
273 $ui = get_userinfo();
275 // Test Every Entry and generate divlist Array
276 foreach($groups as $key => $val){
278 /* Create action icons - copy & paste icons */
279 $acl = $ui->get_permissions($val['dn'],"groups/group");
280 $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
282 $actions= "";
283 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
284 $actions.= "<input class='center' type='image'
285 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
286 $actions.= "<input class='center' type='image'
287 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
288 }
290 /* Add edit icon */
291 $actions.= "<input class='center' type='image'
292 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
294 /* Add snapshot functionality */
295 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
296 $actions.= $this->GetSnapShotActions($val['dn']);
297 }
299 if(preg_match("/d/",$acl)){
300 $actions.= "<input class='center' type='image'
301 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
302 }
305 $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
307 if(isset($val['objectClass'])){
308 if(in_array("posixGroup", $val['objectClass'])) $posix = $posiximg;
309 if(in_array("gosaMailAccount", $val['objectClass'])) $mail = $mailimg;
310 if(in_array("sambaGroupMapping", $val['objectClass'])) $samba = $sambaimg;
311 if(in_array("gosaApplicationGroup", $val['objectClass'])) $appl = $applimg;
312 if(in_array("goFonPickupGroup", $val['objectClass'])) $phone = $phoneimg;
313 if(in_array("gotoEnvironment", $val['objectClass'])) $enviro= $envimg;
314 }
316 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
318 if(!isset($val['description'][0])){
319 $desc = "";
320 }else{
321 $desc = " - [ ".$val['description'][0]." ]";
322 }
324 /* FAIrelease tag from groupApplications */
325 if(isset($val['FAIrelease'][0])){
326 $desc .= " (".$val['FAIrelease'][0].")";
327 }
329 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
330 "attach" => "style='width:20px;'");
332 /* Cutted objects should be displayed in light grey */
333 $display = $val['cn'][0].$desc;
334 if($this->parent->CopyPasteHandler){
335 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
336 if($queue_data['dn'] == $val['dn']) {
337 $display = "<font color='#999999'>".$display."</font>";
338 break;
339 }
340 }
341 }
343 $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
344 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
345 $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix." ".$enviro." ".$mail." ".$samba." ".$appl." ".$phone), "attach" => "style='width:136px;'");
346 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
348 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
349 }
351 /* Create summary string for list footer */
352 $num_deps=0;
353 if(!$this->SubSearch){
354 $num_deps = count($this->Added_Departments);
355 }
356 $num_grps = count($groups);
358 $num_grp_str = _("Number of listed groups");
359 $num_dep_str = _("Number of listed departments");
361 $str = "<img class='center' src='images/select_groups.png'
362 title='".$num_grp_str."' alt='".$num_grp_str."'> ".$num_grps." ";
363 $str.= "<img class='center' src='images/folder.png'
364 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
366 $this->set_List_Bottom_Info($str);
368 }
370 function Save()
371 {
372 MultiSelectWindow :: Save();
373 }
375 function save_object()
376 {
377 /* Save automatic created POSTs like regex, checkboxes */
378 MultiSelectWindow::save_object();
379 }
380 }
381 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
382 ?>