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();
62 /* Disable buttonsm */
63 $this->EnableCloseButton(false);
64 $this->EnableSaveButton (false);
66 /* Dynamic action col, depending on snapshot icons */
67 $action_col_size = 80;
68 if($this->parent->snapshotEnabled()){
69 $action_col_size += 38;
70 }
72 /* Toggle all selected / deselected */
73 $chk = "<input type='checkbox' id='select_all' name='select_all'
74 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
76 /* set Page header */
77 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
78 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
79 $this->AddHeader(array("string"=>_("Groupname / Department")));
80 $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
81 $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
83 /* Text ,Value ,Name ,Is selected */
84 $this->AddCheckBox("ShowPrimaryGroups", _("Select to see groups that are primary groups of users"), _("Show primary groups"), true);
85 $this->AddCheckBox("ShowSambaGroups", _("Select to see groups that have samba groups mappings"), _("Show samba groups"), true);
86 $this->AddCheckBox("ShowApplicationGroups", _("Select to see groups that have applications configured"), _("Show application groups"),true);
87 $this->AddCheckBox("ShowMailGroups", _("Select to see groups that have mail settings"), _("Show mail groups"), true);
88 $this->AddCheckBox("ShowFunctionalGroups", _("Select to see normal groups that have only functional aspects"), _("Show functional groups"), true);
89 $this->AddCheckBox(SEPERATOR);
91 /* Add SubSearch checkbox */
92 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
94 /* Name ,Text ,Default , Connect with alphabet */
95 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
96 $this->AddRegex ("UserRegex", _("User name of which groups are shown"), "*" , false, "images/search_user.png");
97 }
100 function GenHeader()
101 {
102 /* Prepare departments,
103 which are shown in the listbox on top of the listbox
104 */
105 $options= "";
109 /* Get all departments within this subtree */
110 $ui= get_userinfo();
111 $first = "";
112 $found = FALSE;
113 $base = $this->config->current['BASE'];
117 /* Add base */
118 $tmp = array();
119 $tmp[] = array("dn"=>$this->config->current['BASE']);
120 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
121 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
123 $deps = array();
124 foreach($tmp as $tm){
125 $deps[$tm['dn']] = $tm['dn'];
126 }
128 /* Load possible departments */
129 $ui= get_userinfo();
130 $tdeps= $ui->get_module_departments("groups");
131 $ids = $this->config->idepartments;
132 $first = "";
133 $found = FALSE;
134 foreach($ids as $dep => $name){
135 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
137 /* Keep first base dn in mind, we could need this
138 * info if no valid base was found
139 */
140 if(empty($first)) {
141 $first = $dep['dn'];
142 }
144 $value = $ids[$dep];
145 if ($this->selectedBase == $dep){
146 $found = TRUE;
147 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
148 } else {
149 $options.= "<option value='".$dep."'>$value</option>";
150 }
151 }
152 }
154 /* The currently used base is not visible with your acl setup.
155 * Set base to first useable base.
156 */
157 if(!$found){
158 $this->selectedBase = $first;
159 }
161 /* Get acls */
162 $acls = $ui->get_permissions($this->selectedBase,"groups/group");
163 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
166 /* Add default header */
167 $listhead = MultiSelectWindow::get_default_header();
169 /* Add department selection */
170 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
171 " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
172 "'> ";
175 /* Create Layers menu */
176 $s = ".|"._("Actions")."|\n";
177 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
178 " "._("Create")."|\n";
181 /* Append create options */
182 if(preg_match("/c/",$acl_all)) {
183 $s.= "...|<input class='center' type='image' src='images/list_new_group.png' alt=''>".
184 " "._("Group")."|group_new|\n";
185 }
187 /* Multiple options */
188 $s.= "..|---|\n";
189 $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
190 " "._("Edit")."|"."multiple_edit|\n";
191 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
192 " "._("Remove")."|"."remove_multiple|\n";
194 /* Add event tag */
195 if(class_available("DaemonEvent")){
196 $events = DaemonEvent::get_event_types(USER_EVENT);
197 if(count($events['BY_CLASS'])){
198 $s.= "..|---|\n";
199 foreach($events['BY_CLASS'] as $name => $event){
200 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|event_".$name."\n";
201 }
202 }
203 }
205 /* Add multiple copy & cut icons */
206 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
207 $s.= "..|---|\n";
208 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
209 " "._("Copy")."|"."multiple_copy_systems|\n";
210 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
211 " "._("Cut")."|"."multiple_cut_systems|\n";
213 if($this->parent->CopyPasteHandler->entries_queued()){
214 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
215 $s.="..|".$img." "._("Paste")."|editPaste|\n";
216 }else{
217 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
218 $s.="..|".$img." "._("Paste")."\n";
219 }
220 }
222 /* Add snapshot icons */
223 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
224 $s .= "..|---|\n";
225 $s .= $this->get_snapshot_header(TRUE);
226 }
228 $this->SetDropDownHeaderMenu($s);
230 $this->SetListHeader($listhead);
231 }
233 function execute()
234 {
235 $this->ClearElementsList();
236 $this->GenHeader();
237 }
239 function setEntries($groups)
240 {
241 // Defining Links
242 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
244 // image Buttons
245 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
246 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
248 /* Dynamic action col, depending on snapshot icons */
249 $action_col_size = 80;
250 if($this->parent->snapshotEnabled()){
251 $action_col_size += 38;
252 }
254 /* Assign extension images */
255 $posiximg = "<input type='image' class='center' src='images/select_groups.png'
256 name='group_group_edit_%KEY%' alt='P' title='"._("Posix") ."'>";
257 $mailimg = "<input type='image' class='center' src='images/mailto.png'
258 name='mailgroup_group_edit_%KEY%' alt='M' title='"._("Mail") ."'>";
259 $sambaimg = "<input type='image' class='center' src='images/select_winstation.png'
260 name='group_group_edit_%KEY%' alt='S' title='"._("Samba") ."'>";
261 $applimg = "<input type='image' class='center' src='images/select_application.png'
262 name='appgroup_group_edit_%KEY%' alt='A' title='"._("Application")."'>";
263 $phoneimg = "<input type='image' class='center' src='images/select_phone.png'
264 name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone") ."'>";
265 $envimg = "<input type='image' class='center' src='images/smallenv.png'
266 name='environment_group_edit_%KEY%' alt='E' title='"._("Environment") ."'>";
268 // Space
269 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
271 // User and Template Images
272 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
274 $ui = get_userinfo();
276 // Test Every Entry and generate divlist Array
277 foreach($groups as $key => $val){
279 /* Create action icons - copy & paste icons */
280 $acl = $ui->get_permissions($val['dn'],"groups/group");
281 $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
283 $actions= "";
284 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
285 $actions.= "<input class='center' type='image'
286 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
287 $actions.= "<input class='center' type='image'
288 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
289 }
291 /* Add edit icon */
292 $actions.= "<input class='center' type='image'
293 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
295 /* Add snapshot functionality */
296 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
297 $actions.= $this->GetSnapShotActions($val['dn']);
298 }
300 if(preg_match("/d/",$acl)){
301 $actions.= "<input class='center' type='image'
302 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
303 }
306 $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
308 if(isset($val['objectClass'])){
309 if(in_array("posixGroup", $val['objectClass'])) $posix = $posiximg;
310 if(in_array("gosaMailAccount", $val['objectClass'])) $mail = $mailimg;
311 if(in_array("sambaGroupMapping", $val['objectClass'])) $samba = $sambaimg;
312 if(in_array("gosaApplicationGroup", $val['objectClass'])) $appl = $applimg;
313 if(in_array("goFonPickupGroup", $val['objectClass'])) $phone = $phoneimg;
314 if(in_array("gotoEnvironment", $val['objectClass'])) $enviro= $envimg;
315 }
317 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
319 if(!isset($val['description'][0])){
320 $desc = "";
321 }else{
322 $desc = " - [ ".$val['description'][0]." ]";
323 }
325 /* FAIrelease tag from groupApplications */
326 if(isset($val['FAIrelease'][0])){
327 $desc .= " (".$val['FAIrelease'][0].")";
328 }
330 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
331 "attach" => "style='width:20px;'");
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 $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
345 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
346 $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix." ".$enviro." ".$mail." ".$samba." ".$appl." ".$phone), "attach" => "style='width:136px;'");
347 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
349 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
350 }
352 /* Create summary string for list footer */
353 $num_deps=0;
354 if(!$this->SubSearch){
355 $num_deps = count($this->Added_Departments);
356 }
357 $num_grps = count($groups);
359 $num_grp_str = _("Number of listed groups");
360 $num_dep_str = _("Number of listed departments");
362 $str = "<img class='center' src='images/select_groups.png'
363 title='".$num_grp_str."' alt='".$num_grp_str."'> ".$num_grps." ";
364 $str.= "<img class='center' src='images/folder.png'
365 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
367 $this->set_List_Bottom_Info($str);
369 }
371 function Save()
372 {
373 MultiSelectWindow :: Save();
374 }
376 function save_object()
377 {
378 /* Save automatic created POSTs like regex, checkboxes */
379 MultiSelectWindow::save_object();
380 }
381 }
382 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
383 ?>