1 <?php
3 class divListGroup extends MultiSelectWindow
4 {
6 /* Current base */
7 var $selectedBase = "";
8 var $departments = array();
10 /* Regex */
11 var $Regex = "*";
12 var $UserRegex = "*";
14 /* CheckBoxes, to change default values modify $this->AddCheckBox */
15 var $ShowPrimaryGroups;
16 var $ShowSambaGroups;
17 var $ShowApplicationGroups;
18 var $ShowMailGroups;
19 var $ShowFunctionalGroups;
21 /* Subsearch checkbox */
22 var $SubSearch = false;
24 var $parent ;
25 var $ui ;
27 function divListGroup (&$config, &$parent)
28 {
29 MultiSelectWindow::MultiSelectWindow($config, "Groups", "groups");
31 $this->parent = &$parent;
32 $this->ui = get_userinfo();
34 /* Set list strings */
35 $this->SetTitle(_("List of groups"));
36 $this->SetSummary(_("List of groups"));
37 $this->EnableAplhabet (true);
39 /* Result page will look like a headpage */
40 $this->SetHeadpageMode();
41 $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."));
43 /* Disable buttonsm */
44 $this->EnableCloseButton(false);
45 $this->EnableSaveButton (false);
47 /* Dynamic action col, depending on snapshot icons */
48 $action_col_size = 80;
49 if($this->parent->snapshotEnabled()){
50 $action_col_size += 38;
51 }
53 /* Toggle all selected / deselected */
54 $chk = "<input type='checkbox' id='select_all' name='select_all'
55 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
57 /* set Page header */
58 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
59 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
60 $this->AddHeader(array("string"=>_("Groupname / Department")));
61 $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
62 $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
64 /* Text ,Value ,Name ,Is selected */
65 $this->AddCheckBox("ShowPrimaryGroups", _("Select to see groups that are primary groups of users"), _("Show primary groups"), true);
66 $this->AddCheckBox("ShowSambaGroups", _("Select to see groups that have samba groups mappings"), _("Show samba groups"), true);
67 $this->AddCheckBox("ShowApplicationGroups", _("Select to see groups that have applications configured"), _("Show application groups"),true);
68 $this->AddCheckBox("ShowMailGroups", _("Select to see groups that have mail settings"), _("Show mail groups"), true);
69 $this->AddCheckBox("ShowFunctionalGroups", _("Select to see normal groups that have only functional aspects"), _("Show functional groups"), true);
70 $this->AddCheckBox(SEPERATOR);
72 /* Add SubSearch checkbox */
73 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
75 /* Name ,Text ,Default , Connect with alphabet */
76 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
77 $this->AddRegex ("UserRegex", _("User name of which groups are shown"), "*" , false, "images/search_user.png");
78 }
81 function GenHeader()
82 {
83 /* Prepare departments,
84 which are shown in the listbox on top of the listbox
85 */
86 $options= "";
90 /* Get all departments within this subtree */
91 $ui= get_userinfo();
92 $first = "";
93 $found = FALSE;
94 $base = $this->config->current['BASE'];
98 /* Add base */
99 $tmp = array();
100 $tmp[] = array("dn"=>$this->config->current['BASE']);
101 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
102 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
104 $deps = array();
105 foreach($tmp as $tm){
106 $deps[$tm['dn']] = $tm['dn'];
107 }
109 /* Load possible departments */
110 $ui= get_userinfo();
111 $tdeps= $ui->get_module_departments("groups");
112 $ids = $this->config->idepartments;
113 $first = "";
114 $found = FALSE;
115 foreach($ids as $dep => $name){
116 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
118 /* Keep first base dn in mind, we could need this
119 * info if no valid base was found
120 */
121 if(empty($first)) {
122 $first = $dep['dn'];
123 }
125 $value = $ids[$dep];
126 if ($this->selectedBase == $dep){
127 $found = TRUE;
128 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
129 } else {
130 $options.= "<option value='".$dep."'>$value</option>";
131 }
132 }
133 }
135 /* The currently used base is not visible with your acl setup.
136 * Set base to first useable base.
137 */
138 if(!$found){
139 $this->selectedBase = $first;
140 }
142 /* Get acls */
143 $acls = $ui->get_permissions($this->selectedBase,"groups/group");
144 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
147 /* Add default header */
148 $listhead = MultiSelectWindow::get_default_header();
150 /* Add department selection */
151 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
152 " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
153 "'> ";
156 /* Create Layers menu */
157 $s = ".|"._("Actions")."|\n";
158 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
159 " "._("Create")."|\n";
162 /* Append create options */
163 if(preg_match("/c/",$acl_all)) {
164 $s.= "...|<input class='center' type='image' src='images/list_new_group.png' alt=''>".
165 " "._("Group")."|group_new|\n";
166 }
168 /* Multiple options */
169 $s.= "..|---|\n";
170 $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
171 " "._("Edit")."|"."multiple_edit|\n";
172 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
173 " "._("Remove")."|"."remove_multiple|\n";
175 /* Add multiple copy & cut icons */
176 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
177 $s.= "..|---|\n";
178 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
179 " "._("Copy")."|"."multiple_copy_systems|\n";
180 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
181 " "._("Cut")."|"."multiple_cut_systems|\n";
183 if($this->parent->CopyPasteHandler->entries_queued()){
184 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
185 $s.="..|".$img." "._("Paste")."|editPaste|\n";
186 }else{
187 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
188 $s.="..|".$img." "._("Paste")."\n";
189 }
190 }
192 /* Add snapshot icons */
193 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
194 $s .= "..|---|\n";
195 $s .= $this->get_snapshot_header(TRUE);
196 }
198 $this->SetDropDownHeaderMenu($s);
200 $this->SetListHeader($listhead);
201 }
203 function execute()
204 {
205 $this->ClearElementsList();
206 $this->GenHeader();
207 }
209 function setEntries($groups)
210 {
211 // Defining Links
212 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
214 // image Buttons
215 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
216 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
218 /* Dynamic action col, depending on snapshot icons */
219 $action_col_size = 80;
220 if($this->parent->snapshotEnabled()){
221 $action_col_size += 38;
222 }
224 /* Assign extension images */
225 $posiximg = "<input type='image' class='center' src='images/select_groups.png'
226 name='group_group_edit_%KEY%' alt='P' title='"._("Posix") ."'>";
227 $mailimg = "<input type='image' class='center' src='images/mailto.png'
228 name='mailgroup_group_edit_%KEY%' alt='M' title='"._("Mail") ."'>";
229 $sambaimg = "<input type='image' class='center' src='images/select_winstation.png'
230 name='group_group_edit_%KEY%' alt='S' title='"._("Samba") ."'>";
231 $applimg = "<input type='image' class='center' src='images/select_application.png'
232 name='appgroup_group_edit_%KEY%' alt='A' title='"._("Application")."'>";
233 $phoneimg = "<input type='image' class='center' src='images/select_phone.png'
234 name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone") ."'>";
235 $envimg = "<input type='image' class='center' src='images/smallenv.png'
236 name='environment_group_edit_%KEY%' alt='E' title='"._("Environment") ."'>";
238 // Space
239 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
241 // User and Template Images
242 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
244 $ui = get_userinfo();
246 // Test Every Entry and generate divlist Array
247 foreach($groups as $key => $val){
249 /* Create action icons - copy & paste icons */
250 $acl = $ui->get_permissions($val['dn'],"groups/group");
251 $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
253 $actions= "";
254 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
255 $actions.= "<input class='center' type='image'
256 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
257 $actions.= "<input class='center' type='image'
258 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
259 }
261 /* Add edit icon */
262 $actions.= "<input class='center' type='image'
263 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
265 /* Add snapshot functionality */
266 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
267 $actions.= $this->GetSnapShotActions($val['dn']);
268 }
270 if(preg_match("/d/",$acl)){
271 $actions.= "<input class='center' type='image'
272 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
273 }
276 $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
278 if(isset($val['objectClass'])){
279 if(in_array("posixGroup", $val['objectClass'])) $posix = $posiximg;
280 if(in_array("gosaMailAccount", $val['objectClass'])) $mail = $mailimg;
281 if(in_array("sambaGroupMapping", $val['objectClass'])) $samba = $sambaimg;
282 if(in_array("gosaApplicationGroup", $val['objectClass'])) $appl = $applimg;
283 if(in_array("goFonPickupGroup", $val['objectClass'])) $phone = $phoneimg;
284 if(in_array("gotoEnvironment", $val['objectClass'])) $enviro= $envimg;
285 }
287 $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 /* FAIrelease tag from groupApplications */
296 if(isset($val['FAIrelease'][0])){
297 $desc .= " (".$val['FAIrelease'][0].")";
298 }
300 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
301 "attach" => "style='width:20px;'");
303 /* Cutted objects should be displayed in light grey */
304 $display = $val['cn'][0].$desc;
305 if($this->parent->CopyPasteHandler){
306 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
307 if($queue_data['dn'] == $val['dn']) {
308 $display = "<font color='#999999'>".$display."</font>";
309 break;
310 }
311 }
312 }
314 $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
315 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
316 $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix." ".$enviro." ".$mail." ".$samba." ".$appl." ".$phone), "attach" => "style='width:136px;'");
317 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
319 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
320 }
322 /* Create summary string for list footer */
323 $num_deps=0;
324 if(!$this->SubSearch){
325 $num_deps = count($this->Added_Departments);
326 }
327 $num_grps = count($groups);
329 $num_grp_str = _("Number of listed groups");
330 $num_dep_str = _("Number of listed departments");
332 $str = "<img class='center' src='images/select_groups.png'
333 title='".$num_grp_str."' alt='".$num_grp_str."'> ".$num_grps." ";
334 $str.= "<img class='center' src='images/folder.png'
335 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
337 $this->set_List_Bottom_Info($str);
339 }
341 function Save()
342 {
343 MultiSelectWindow :: Save();
344 }
346 function save_object()
347 {
348 /* Save automatic created POSTs like regex, checkboxes */
349 MultiSelectWindow::save_object();
350 }
351 }
352 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
353 ?>