fc5d5073aac639a3ecd3a20e1de448080143a993
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"=>_("Name")." / "._("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"),
85 sprintf(_("Show %s groups"),_("primary")), true);
86 $this->AddCheckBox("ShowSambaGroups", msgPool::selectToView(_("samba groups mappings"),"enabled"),
87 sprintf(_("Show %s groups"),_("samba")), true);
88 $this->AddCheckBox("ShowApplicationGroups", msgPool::selectToView(_("application settings"),"enabled"),
89 sprintf(_("Show %s groups"),_("application")), true);
90 $this->AddCheckBox("ShowMailGroups", msgPool::selectToView(_("mail settings"),"enabled"),
91 sprintf(_("Show %s groups"),_("mail")), true);
92 $this->AddCheckBox("ShowFunctionalGroups", _("Select to see normal groups that have only functional aspects"),
93 sprintf(_("Show %s groups"),_("functional")), true);
94 $this->AddCheckBox(SEPERATOR);
96 /* Add SubSearch checkbox */
97 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"),msgPool::selectToView("","subsearch_small"), false);
99 /* Name ,Text ,Default , Connect with alphabet */
100 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
101 $this->AddRegex ("UserRegex", _("User name of which groups are shown"), "*" , false, "images/search_user.png");
102 }
105 function GenHeader()
106 {
107 /* Prepare departments,
108 which are shown in the listbox on top of the listbox
109 */
110 $options= "";
114 /* Get all departments within this subtree */
115 $ui= get_userinfo();
116 $first = "";
117 $found = FALSE;
118 $base = $this->config->current['BASE'];
122 /* Add base */
123 $tmp = array();
124 $tmp[] = array("dn"=>$this->config->current['BASE']);
125 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
126 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
128 $deps = array();
129 foreach($tmp as $tm){
130 $deps[$tm['dn']] = $tm['dn'];
131 }
133 /* Load possible departments */
134 $ui= get_userinfo();
135 $tdeps= $ui->get_module_departments("groups");
136 $ids = $this->config->idepartments;
137 $first = "";
138 $found = FALSE;
139 foreach($ids as $dep => $name){
140 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
142 /* Keep first base dn in mind, we could need this
143 * info if no valid base was found
144 */
145 if(empty($first)) {
146 $first = $dep['dn'];
147 }
149 $value = $ids[$dep];
150 if ($this->selectedBase == $dep){
151 $found = TRUE;
152 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
153 } else {
154 $options.= "<option value='".$dep."'>$value</option>";
155 }
156 }
157 }
159 /* The currently used base is not visible with your acl setup.
160 * Set base to first useable base.
161 */
162 if(!$found){
163 $this->selectedBase = $first;
164 }
166 /* Get acls */
167 $acls = $ui->get_permissions($this->selectedBase,"groups/group");
168 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
171 /* Add default header */
172 $listhead = MultiSelectWindow::get_default_header();
174 /* Add department selection */
175 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
176 " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
177 "'> ";
180 /* Create Layers menu */
181 $s = ".|"._("Actions")."|\n";
182 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
183 " "._("Create")."|\n";
186 /* Append create options */
187 if(preg_match("/c/",$acl_all)) {
188 $s.= "...|<input class='center' type='image' src='images/list_new_group.png' alt=''>".
189 " "._("Group")."|group_new|\n";
190 }
192 /* Multiple options */
193 $s.= "..|---|\n";
194 $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
195 " "._("Edit")."|"."multiple_edit|\n";
196 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
197 " "._("Remove")."|"."remove_multiple|\n";
199 /* Add event tag */
200 if(class_available("DaemonEvent")){
201 $events = DaemonEvent::get_event_types(USER_EVENT);
202 if(count($events['BY_CLASS'])){
203 $s.= "..|---|\n";
204 foreach($events['BY_CLASS'] as $name => $event){
205 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|event_".$name."\n";
206 }
207 }
208 }
210 /* Add multiple copy & cut icons */
211 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
212 $s.= "..|---|\n";
213 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
214 " "._("Copy")."|"."multiple_copy_systems|\n";
215 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
216 " "._("Cut")."|"."multiple_cut_systems|\n";
218 if($this->parent->CopyPasteHandler->entries_queued()){
219 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
220 $s.="..|".$img." "._("Paste")."|editPaste|\n";
221 }else{
222 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
223 $s.="..|".$img." "._("Paste")."\n";
224 }
225 }
227 /* Add snapshot icons */
228 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
229 $s .= "..|---|\n";
230 $s .= $this->get_snapshot_header(TRUE);
231 }
233 $this->SetDropDownHeaderMenu($s);
235 $this->SetListHeader($listhead);
236 }
238 function execute()
239 {
240 $this->ClearElementsList();
241 $this->GenHeader();
242 }
244 function setEntries($groups)
245 {
246 // Defining Links
247 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
249 // image Buttons
250 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
251 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
253 /* Dynamic action col, depending on snapshot icons */
254 $action_col_size = 80;
255 if($this->parent->snapshotEnabled()){
256 $action_col_size += 38;
257 }
259 /* Assign extension images */
260 $posiximg = "<input type='image' class='center' src='images/select_groups.png'
261 name='group_group_edit_%KEY%' alt='P' title='"._("Posix") ."'>";
262 $mailimg = "<input type='image' class='center' src='images/mailto.png'
263 name='mailgroup_group_edit_%KEY%' alt='M' title='"._("Mail") ."'>";
264 $sambaimg = "<input type='image' class='center' src='images/select_winstation.png'
265 name='group_group_edit_%KEY%' alt='S' title='"._("Samba") ."'>";
266 $applimg = "<input type='image' class='center' src='images/select_application.png'
267 name='appgroup_group_edit_%KEY%' alt='A' title='"._("Application")."'>";
268 $phoneimg = "<input type='image' class='center' src='images/select_phone.png'
269 name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone") ."'>";
270 $envimg = "<input type='image' class='center' src='images/smallenv.png'
271 name='environment_group_edit_%KEY%' alt='E' title='"._("Environment") ."'>";
273 // Space
274 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
276 // User and Template Images
277 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
279 $ui = get_userinfo();
281 // Test Every Entry and generate divlist Array
282 foreach($groups as $key => $val){
284 /* Create action icons - copy & paste icons */
285 $acl = $ui->get_permissions($val['dn'],"groups/group");
286 $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
288 $actions= "";
289 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
290 $actions.= "<input class='center' type='image'
291 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
292 $actions.= "<input class='center' type='image'
293 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
294 }
296 /* Add edit icon */
297 $actions.= "<input class='center' type='image'
298 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
300 /* Add snapshot functionality */
301 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
302 $actions.= $this->GetSnapShotActions($val['dn']);
303 }
305 if(preg_match("/d/",$acl)){
306 $actions.= "<input class='center' type='image'
307 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
308 }
311 $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
313 if(isset($val['objectClass'])){
314 if(in_array("posixGroup", $val['objectClass'])) $posix = $posiximg;
315 if(in_array("gosaMailAccount", $val['objectClass'])) $mail = $mailimg;
316 if(in_array("sambaGroupMapping", $val['objectClass'])) $samba = $sambaimg;
317 if(in_array("gosaApplicationGroup", $val['objectClass'])) $appl = $applimg;
318 if(in_array("goFonPickupGroup", $val['objectClass'])) $phone = $phoneimg;
319 if(in_array("gotoEnvironment", $val['objectClass'])) $enviro= $envimg;
320 }
322 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
324 if(!isset($val['description'][0])){
325 $desc = "";
326 }else{
327 $desc = " - [ ".$val['description'][0]." ]";
328 }
330 /* FAIrelease tag from groupApplications */
331 if(isset($val['FAIrelease'][0])){
332 $desc .= " (".$val['FAIrelease'][0].")";
333 }
335 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
336 "attach" => "style='width:20px;'");
338 /* Cutted objects should be displayed in light grey */
339 $display = $val['cn'][0].$desc;
340 if($this->parent->CopyPasteHandler){
341 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
342 if($queue_data['dn'] == $val['dn']) {
343 $display = "<font color='#999999'>".$display."</font>";
344 break;
345 }
346 }
347 }
349 $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
350 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
351 $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix." ".$enviro." ".$mail." ".$samba." ".$appl." ".$phone), "attach" => "style='width:136px;'");
352 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
354 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
355 }
357 /* Create summary string for list footer */
358 $num_deps=0;
359 if(!$this->SubSearch){
360 $num_deps = count($this->Added_Departments);
361 }
362 $num_grps = count($groups);
364 $num_grp_str = _("Number of listed groups");
365 $num_dep_str = _("Number of listed departments");
367 $str = "<img class='center' src='images/select_groups.png'
368 title='".$num_grp_str."' alt='".$num_grp_str."'> ".$num_grps." ";
369 $str.= "<img class='center' src='images/folder.png'
370 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
372 $this->set_List_Bottom_Info($str);
374 }
376 function Save()
377 {
378 MultiSelectWindow :: Save();
379 }
381 function save_object()
382 {
383 /* Save automatic created POSTs like regex, checkboxes */
384 MultiSelectWindow::save_object();
385 }
386 }
387 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
388 ?>