1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_group.inc";
22 class groupManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Groups";
26 var $plDescription= "This does something";
27 var $departments = array();
29 /* Dialog attributes */
30 var $grouptab= NULL;
31 var $grouplist= array();
32 var $ui= NULL;
33 var $acl= "";
35 var $CopyPasteHandler ;
36 var $enableCopyPaste = false;
38 function groupManagement ($config, $ui)
39 {
40 /* Save configuration for internal use */
41 $this->config= $config;
42 $this->ui= $ui;
44 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
45 $this->enableCopyPaste = true;
46 }
47 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
49 /* Get global filter config */
50 if (!is_global("groupfilter")){
51 $base= get_base_from_people($ui->dn);
52 $groupfilter= array("primarygroups" => "checked",
53 "mailgroups" => "checked",
54 "sambagroups" => "checked",
55 "appgroups" => "checked",
56 "functionalgroups" => "checked",
57 "guser" => "*",
58 "subsearch" => "",
59 "depselect" => $base,
60 "regex" => "*");
61 register_global("groupfilter", $groupfilter);
62 }
63 }
65 function execute()
66 {
67 /* Call parent execute */
68 plugin::execute();
70 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/");
72 /* Save data */
73 $groupfilter= get_global("groupfilter");
74 $s_action = "";
75 $s_entry = "";
77 if (!isset($this->grouptab)){
78 foreach( array("depselect", "guser", "regex") as $type){
79 if (isset($_POST[$type])){
80 $groupfilter[$type]= $_POST[$type];
81 }
82 }
83 if (isset($_POST['regex'])){
84 foreach( array("primarygroups", "sambagroups", "mailgroups", "appgroups",
85 "functionalgroups", "subsearch") as $type){
87 if (isset($_POST[$type])) {
88 $groupfilter[$type]= "checked";
89 } else {
90 $groupfilter[$type]= "";
91 }
92 }
93 }
94 if (isset($_GET['search'])){
95 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
96 if ($s == "**"){
97 $s= "*";
98 }
99 $groupfilter['regex']= $s;
100 }
101 register_global("groupfilter", $groupfilter);
102 }
105 /* Test Posts */
106 foreach($_POST as $key => $val){
107 // Post for delete
108 if(preg_match("/^group_del.*/",$key)){
109 $s_action = "del";
110 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
111 // Post for edit
112 }elseif(preg_match("/^group_edit_.*/",$key)){
113 $s_action="edit";
114 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
115 // Post for new
116 }elseif(preg_match("/^dep_back.*/i",$key)){
117 $s_action="back";
118 }elseif(preg_match("/^group_new.*/",$key)){
119 $s_action="new";
120 }elseif(preg_match("/^dep_home.*/i",$key)){
121 $s_action="home";
122 }elseif(preg_match("/^group_tplnew.*/i",$key)){
123 $s_action="new_tpl";
124 }elseif(preg_match("/^group_chgpw.*/i",$key)){
125 $s_action="change_pw";
126 $s_entry = preg_replace("/group_chgpw_/i","",$key);
127 }elseif(preg_match("/^dep_root.*/i",$key)){
128 $s_action="root";
129 }elseif(preg_match("/_group_edit_/",$key)){
130 $type = preg_replace("/_group_edit_.*$/","",$key);
131 $s_action="edit";
132 $s_entry = preg_replace("/".$type."_group_edit_/i","",$key);
133 $_POST['arg'] = $type;
134 }elseif(preg_match("/^editPaste.*/i",$key)){
135 $s_action="editPaste";
136 }elseif(preg_match("/^copy_.*/",$key)){
137 $s_action="copy";
138 $s_entry = preg_replace("/^copy_/i","",$key);
139 }elseif(preg_match("/^cut_.*/",$key)){
140 $s_action="cut";
141 $s_entry = preg_replace("/^cut_/i","",$key);
142 }
143 }
144 $s_entry = preg_replace("/_.$/","",$s_entry);
146 /* Start for New List Managment */
147 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
148 $s_action="open";
149 $s_entry = base64_decode($_GET['dep_id']);
150 $groupfilter['depselect']= "".$this->config->departments[trim($s_entry)];
151 }
153 // Edit if
154 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
155 $s_action ="edit";
156 $s_entry = $_GET['id'];
157 }
159 /* Department changed? */
160 if(isset($_POST['depselect']) && $_POST['depselect']){
161 $groupfilter['depselect']= $_POST['depselect'];
162 }
164 /* Homebutton is posted */
165 if($s_action=="home"){
166 $groupfilter['depselect']= (preg_replace("/^[^,]+,/","",$this->ui->dn));
167 $groupfilter['depselect']= (preg_replace("/^[^,]+,/","",$groupfilter['depselect']));
168 }
170 if($s_action=="root"){
171 $groupfilter['depselect']=($this->config->current['BASE']);
172 }
174 /* If Backbutton is Posted */
175 if($s_action == "back"){
176 $base_back= preg_replace("/^[^,]+,/","",$groupfilter['depselect']);
177 $base_back= convert_department_dn($base_back);
179 if(isset($this->config->departments[trim($base_back)])){
180 $groupfilter['depselect']= $this->config->departments[trim($base_back)];
181 }else{
182 $groupfilter['depselect']= $this->config->departments["/"];
183 }
184 }
185 register_global("groupfilter", $groupfilter);
187 $smarty= get_smarty();
189 /* Prepare formular */
190 $this->reload();
192 /* Check for exeeded sizelimit */
193 if (($message= check_sizelimit()) != ""){
194 return($message);
195 }
197 /* Only perform copy / paste if it is enabled
198 */
199 if($this->enableCopyPaste){
201 /* Paste copied/cutted object in here
202 */
203 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
204 $this->CopyPasteHandler->save_object();
205 $this->CopyPasteHandler->SetVar("base",$groupfilter['depselect']);
206 return($this->CopyPasteHandler->execute());
207 }
210 /* Copy current object to CopyHandler
211 */
212 if($s_action == "copy"){
213 $this->CopyPasteHandler->Clear();
215 $dn = $this->grouplist[trim($s_entry)]['dn'];
216 $acl = get_permissions ($dn, $this->ui->subtreeACL);
218 $obj = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
219 $objNew = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], "new");
220 $obj->set_acl($acl);
221 $objNew->set_acl($acl);
222 $this->CopyPasteHandler->Copy($obj,$objNew);
224 foreach($this->CopyPasteHandler->current->by_object as $name => $obj){
225 foreach(array('is_account','gotoHotplugDevices','gotoLogonScripts',
226 'gotoProfileServers','gotoProfileFlag_C','gotoProfileFlag_L',
227 'gotoPrinter','useProfile','OrigCn','Categories') as $attr){
228 if(isset($obj->$attr)){
229 $this->CopyPasteHandler->current->by_object[$name]->$attr = $obj->$attr;
230 }
231 }
232 }
233 }
236 /* Copy current object to CopyHandler
237 */
238 if($s_action == "cut"){
239 $this->CopyPasteHandler->Clear();
240 $dn = $this->grouplist[trim($s_entry)]['dn'];
241 $acl= get_permissions ($dn, $this->ui->subtreeACL);
243 $obj= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
244 $obj->set_acl($acl);
246 $this->CopyPasteHandler->Cut($obj);
247 }
248 }
251 /* New group? */
252 if ($s_action=="new"){
254 /* By default we set 'dn' to 'new', all relevant plugins will
255 react on this. */
256 $this->dn= "new";
258 /* Create new usertab object */
259 $this->grouptab= new grouptabs($this->config,
260 $this->config->data['TABS']['GROUPTABS'], $this->dn);
261 /* Set up the users ACL's for this 'dn' */
262 $acl= get_permissions ($groupfilter['depselect'], $this->ui->subtreeACL);
263 $this->grouptab->set_acl($acl);
264 }
266 /* Cancel dialogs */
267 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
268 del_lock ($this->grouptab->dn);
269 unset ($this->grouptab);
270 $this->grouptab= NULL;
271 unset($_SESSION['objectinfo']);
272 }
274 /* Finish group edit is triggered by the tabulator dialog, so
275 the user wants to save edited data. Check and save at this
276 point. */
277 if ((isset($_POST['edit_finish'])) && (isset($this->grouptab->config)) ){
279 /* Check tabs, will feed message array */
280 $message= $this->grouptab->check();
282 /* Save, or display error message? */
283 if (count($message) == 0){
285 /* Save user data to ldap */
286 $this->grouptab->save();
287 gosa_log ("Group object'".$this->dn."' has been saved");
289 /* Group has been saved successfully, remove lock from
290 LDAP. */
291 if ($this->dn != "new"){
292 del_lock ($this->dn);
293 }
295 /* There's no page reload so we have to read new users at
296 this point. */
297 $this->reload ();
298 unset ($this->grouptab);
299 $this->grouptab= NULL;
300 unset ($_SESSION['objectinfo']);
302 } else {
303 /* Ok. There seem to be errors regarding to the tab data,
304 show message and continue as usual. */
305 show_errors($message);
306 }
307 }
309 /* User wants to edit data? */
310 if (($s_action=="edit") && (!isset($this->grouptab-> config))){
312 /* Get 'dn' from posted 'uid', must be unique */
313 $this->dn= $this->grouplist[trim($s_entry)]['dn'];
315 /* Check locking, save current plugin in 'back_plugin', so
316 the dialog knows where to return. */
318 $user = get_lock($this->dn);
320 if ($user != ""){
321 return(gen_locked_message ($user, $this->dn));
322 }
324 /* Lock the current entry, so everyone will get the
325 above dialog */
326 add_lock ($this->dn, $this->ui->dn);
328 /* Set up the users ACL's for this 'dn' */
329 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
331 /* Register grouptab to trigger edit dialog */
332 $this->grouptab= new grouptabs($this->config,
333 $this->config->data['TABS']['GROUPTABS'], $this->dn);
334 $this->grouptab->set_acl($acl);
335 $_SESSION['objectinfo']= $this->dn;
336 }
338 /* Remove user was requested */
339 if ($s_action=="del"){
340 /* Get 'dn' from posted 'uid' */
341 $this->dn= $this->grouplist[trim($s_entry)]['dn'];
343 /* Load permissions for selected 'dn' and check if
344 we're allowed to remove this 'dn' */
345 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
346 $this->acl= get_module_permission($acl, "group", $this->dn);
347 if (chkacl($this->acl, "delete") == ""){
349 /* Check locking, save current plugin in 'back_plugin', so
350 the dialog knows where to return. */
351 if (($user= get_lock($this->dn)) != ""){
352 return(gen_locked_message ($user, $this->dn));
353 }
355 /* Lock the current entry, so nobody will edit it during deletion */
356 add_lock ($this->dn, $this->ui->dn);
357 $smarty->assign("info", sprintf(_("You're about to delete the group '%s'."), LDAP::fix($this->dn)));
358 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
359 } else {
361 /* Obviously the user isn't allowed to delete. Show message and
362 clean session. */
363 print_red (_("You are not allowed to delete this group!"));
364 }
365 }
367 /* Confirmation for deletion has been passed. Group should be deleted. */
368 if (isset($_POST['delete_group_confirm'])){
370 /* Some nice guy may send this as POST, so we've to check
371 for the permissions again. */
372 if (chkacl($this->acl, "delete") == ""){
374 /* Delete request is permitted, perform LDAP action */
375 $this->grouptab= new grouptabs($this->config,
376 $this->config->data['TABS']['GROUPTABS'], $this->dn);
377 $this->grouptab->set_acl(array($this->acl));
378 $this->grouptab->delete ();
379 gosa_log ("Group object'".$this->dn."' has been removed");
380 unset ($this->grouptab);
381 $this->grouptab= NULL;
383 /* Group list has changed, reload it. */
384 $this->reload ();
385 } else {
387 /* Normally this shouldn't be reached, send some extra
388 logs to notify the administrator */
389 print_red (_("You are not allowed to delete this group!"));
390 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
391 }
393 /* Remove lock file after successfull deletion */
394 del_lock ($this->dn);
395 unset($_SESSION['objectinfo']);
396 }
399 /* Delete group canceled? */
400 if (isset($_POST['delete_cancel'])){
401 del_lock ($this->dn);
402 unset($_SESSION['objectinfo']);
403 }
405 /* Show tab dialog if object is present */
406 if (isset($this->grouptab->config)){
407 $display= $this->grouptab->execute();
409 /* Don't show buttons if tab dialog requests this */
410 if (!$this->grouptab->by_object[$this->grouptab->current]->dialog){
411 $display.= "<p style=\"text-align:right\">\n";
412 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
413 $display.= " \n";
414 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
415 $display.= "</p>";
416 }
417 return ($display);
418 }
420 /* Prepare departments */
421 $options= "";
422 foreach ($this->config->idepartments as $key => $value){
423 if ($groupfilter['depselect'] == $key){
424 $options.= "<option selected value='$key'>$value</option>";
425 } else {
426 $options.= "<option value='$key'>$value</option>";
427 }
428 }
430 /* Create paste icon
431 */
432 if($this->enableCopyPaste){
433 $Copy_Paste = " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
434 if($this->CopyPasteHandler->isCurrentObjectPastAble()){
435 if($this->CopyPasteHandler->isCurrentCutted()){
436 $img = "images/cutpaste.png";
437 }else{
438 $img = "images/copypaste.png";
439 }
440 $Copy_Paste .= "<input type='image' name='editPaste' class='center'
441 src='".$img."' alt='"._("Paste")."' title='".$this->CopyPasteHandler->GetCurrentDn()."'> ";
442 }else{
443 $Copy_Paste .= "<img class='center' src='images/cant_editpaste.png' alt='"._("Can't paste")."'> ";
444 }
445 }else{
446 $Copy_Paste ="";
447 }
449 // Managment
450 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
451 " <input type='image' class='center' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
452 " <input type='image' class='center' src='images/list_root.png' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
453 " <input type='image' class='center' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
454 " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'> ".
455 " <input type='image' class='center' src='images/list_new_group.png' title='"._("Create new group")."' alt='"._("New")."' name='group_new'> ".
456 $Copy_Paste.
457 " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'> ".
458 _("Base")." <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
459 " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
460 "</div>";
463 if($this->enableCopyPaste){
464 $actions = "<input class='center' type='image'
465 src='images/editdelete.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
466 $actions.= "<input class='center' type='image'
467 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
468 $actions.= "<input class='center' type='image'
469 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
470 $actions.= "<input class='center' type='image'
471 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
472 }else{
473 $actions = "<input class='center' type='image'
474 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
475 $actions.= "<input class='center' type='image'
476 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
477 }
480 // Defining Links
481 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
483 // image Buttons
484 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
485 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
488 /* Extension images
489 group
490 environment
491 appgroup
492 mailgroup
493 acl
494 reference
496 */
497 $posiximg = "<input type='image' class='center' src='images/select_groups.png'
498 name='group_group_edit_%KEY%'
499 alt='P' title='"._("Posix") ."'>";
500 $mailimg = "<input type='image' class='center' src='images/mailto.png'
501 name='mailgroup_group_edit_%KEY%'
502 alt='M' title='"._("Mail") ."'>";
503 $sambaimg = "<input type='image' class='center' src='images/select_winstation.png'
504 name='group_group_edit_%KEY%'
505 alt='S' title='"._("Samba") ."'>";
506 $applimg = "<input type='image' class='center' src='images/select_application.png'
507 name='appgroup_group_edit_%KEY%'
508 alt='A' title='"._("Application")."'>";
509 $phoneimg = "<input type='image' class='center' src='images/select_phone.png'
510 name='group_group_edit_%KEY%'
511 alt='Ph' title='"._("Phone") ."'>";
512 $envimg = "<input type='image' class='center' src='images/smallenv.png'
513 name='environment_group_edit_%KEY%'
514 alt='E' title='"._("Environment") ."'>";
516 // Space
517 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
520 $divlist = new divlist("groupstab");
521 $divlist->SetHeader(array(
522 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
523 array("string" => _("Groupname")." / "._("Department"), "attach" => "style=''"),
524 array("string" => _("Properties"), "attach" => "style='width:136px;'"),
525 array("string" => _("Actions"), "attach" => "style='width:80px;border-right:0px;text-align:right;'")
526 ));
528 $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
529 $divlist->SetEntriesPerPage(0);
531 foreach($this->departments as $key=> $val){
533 if(!isset($this->config->departments[trim($key)])){
534 $this->config->departments[trim($key)]="";
535 }
537 $non_empty="";
538 $keys= str_replace("/","\/",$key);
539 foreach($this->config->departments as $keyd=>$vald ){
540 if(preg_match("/".$keys."\/.*/",$keyd)){
541 $non_empty="full";
542 }
543 }
546 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
547 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
548 $field3 = array("string" => " ", "attach" => "style='width:136px;'");
549 $field4 = array("string" => " ", "attach" => "style='width:80px;border-right:0px;text-align:right;'");
551 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
552 }
554 foreach($this->grouplist as $key => $val){
556 if(isset($val['objectClass'])){
557 if(in_array("posixGroup", $val['objectClass'])) $posix = $posiximg; else $posix = $empty;
558 if(in_array("gosaMailAccount", $val['objectClass'])) $mail = $mailimg; else $mail = $empty;
559 if(in_array("sambaGroupMapping", $val['objectClass'])) $samba = $sambaimg; else $samba = $empty;
560 if(in_array("gosaApplicationGroup", $val['objectClass'])) $appl = $applimg; else $appl = $empty;
561 if(in_array("goFonPickupGroup", $val['objectClass'])) $phone = $phoneimg; else $phone = $empty;
562 if(in_array("gotoEnvironment", $val['objectClass'])) $enviro= $envimg; else $enviro = $empty;
563 }else{
564 $posix=$mail=$samba=$appl=$phone=$empty;
565 }
567 $title = "title='gid : ".$key." - dn : ".$val['dn']."'";
569 if(!isset($val['description'][0])){
570 $desc = "";
571 }else{
572 $desc = " - [ ".$val['description'][0]." ]";
573 }
574 $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
575 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
576 $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix." ".$enviro." ".$mail." ".$samba." ".$appl." ".$phone), "attach" => "style='width:136px;'");
577 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'");
579 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
580 }
582 /* Show main page */
583 $smarty->assign("grouplisthead", $listhead);
584 $smarty->assign("grouplist", $divlist->DrawList());
585 $smarty->assign("search_image", get_template_path('images/search.png'));
586 $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
587 $smarty->assign("tree_image", get_template_path('images/tree.png'));
588 $smarty->assign("infoimage", get_template_path('images/info.png'));
589 $smarty->assign("launchimage", get_template_path('images/launch.png'));
590 $smarty->assign("deplist", $this->config->idepartments);
591 foreach( array("depselect", "guser", "regex", "primarygroups", "mailgroups","appgroups", "sambagroups", "functionalgroups", "subsearch") as $type){
592 $smarty->assign("$type", $groupfilter[$type]);
593 }
595 /* Extend if we are not using javascript */
596 $smarty->assign("apply", apply_filter());
597 $smarty->assign("alphabet", generate_alphabet());
598 $smarty->assign("hint", print_sizelimit_warning());
599 if (isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
600 $smarty->assign("showprimary", "");
601 } else {
602 $smarty->assign("showprimary", "true");
603 }
605 return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
606 }
608 function reload($CreatePosixsList=false)
609 {
610 /* Get config */
611 $groupfilter= get_global('groupfilter');
613 /* Set base for all searches */
614 $base= $groupfilter['depselect'];
616 /* Regex filter? */
617 if ($groupfilter['regex'] != ""){
618 $regex= $groupfilter['regex'];
619 } else {
620 $regex= "*";
621 }
623 /* User filter? */
624 $filter= "(objectclass=posixGroup)";
625 $error= "";
626 $error2= "";
627 $this->grouplist= array();
629 /* What are primary groups? */
630 $primaries= array();
631 $ldap= $this->config->get_ldap_link();
632 if (!isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
633 $ldap->cd($base);
634 $ldap->search("(&(uid=$regex)(!(uid=*$))(objectClass=posixAccount)(gidNumber=*))", array("gidNumber", "cn"));
635 show_ldap_error($ldap->get_error());
636 while ($attrs= $ldap->fetch()){
637 $primaries[$attrs['gidNumber'][0]]= $attrs['cn'][0];
638 }
639 }
641 /* Set filter depending on selection */
642 $sfilter= "";
643 if ($groupfilter['appgroups'] == "checked"){
644 $filter.= "(objectClass=gosaApplicationGroup)";
645 }
646 if ($this->config->current['SAMBAVERSION'] == 3){
647 if ($groupfilter['primarygroups'] != "checked"){
648 $sfilter= "(objectClass=sambaGroupMapping)";
649 } elseif ($groupfilter['sambagroups'] == "checked"){
650 $filter.= "(objectClass=sambaGroupMapping)";
651 }
652 }
654 if ($groupfilter['mailgroups'] == "checked"){
655 $filter.= "(objectClass=gosaMailAccount)";
656 }
657 $functional= array();
658 $ldap->cd(get_groups_ou().$base);
659 $ldap->set_size_limit($_SESSION['size_limit']);
660 $ldap->search("(&(cn=$regex)(objectClass=posixGroup)(!(|(objectClass=gosaMailAccount)(objectClass=gosaApplicationGroup)$sfilter)))", array("cn", "gidNumber", "description"));
661 $error2= $ldap->error;
662 while ($attrs= $ldap->fetch()){
663 if (!isset($primaries[$attrs['gidNumber'][0]])){
664 $functional[$attrs['gidNumber'][0]]= $attrs['gidNumber'][0];
665 }
666 }
668 /*
669 * We also need to search for the departments
670 * So we are able to navigate like in konquerer
671 */
673 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
674 FALSE, $base, array("ou", "description"), TRUE);
675 $this->departments= array();
676 $tmp = array();
677 foreach ($res3 as $value){
678 $tmp[strtolower($value['dn']).$value['dn']]=$value;
679 }
680 ksort($tmp);
681 foreach($tmp as $value){
682 if(isset($value["description"][0])){
683 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
684 }else{
685 $this->departments[$value['dn']]= convert_department_dn2($value['dn']);//$value["description"][0];
686 }
687 }
688 /* Ende department generation
689 */
691 /* Generate grouplist */
692 if ($filter != ""){
693 $filter= "(&(cn=$regex)(objectClass=posixGroup)(|$filter))";
694 if ($groupfilter['guser'] != ""){
695 $filter= "(&(|(memberUID=" . $groupfilter['guser'] . ")(cn=" . $groupfilter['guser'] . "))$filter)";
696 }
697 }
699 /* Depending on $CreatePosixsList we have to create different lists */
701 if ($groupfilter['subsearch'] == "checked"){
702 $res= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("cn", "description", "gidNumber"), TRUE);
703 } else {
704 $base= get_groups_ou().$base;
705 $res= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("cn", "description", "gidNumber"), TRUE);
706 }
707 if (preg_match("/size limit/i", $error) || preg_match("/size limit/i", $error2)){
708 $_SESSION['limit_exceeded']= TRUE;
709 }
711 foreach ($res as $value){
712 if ($groupfilter['functionalgroups'] != "checked" && isset($functional[$value['gidNumber'][0]])){
713 continue;
714 }
715 if ($groupfilter['primarygroups'] == "checked"){
716 $this->grouplist[$value['gidNumber'][0]]= $value;
717 } else {
718 if (!isset($primaries[$value['gidNumber'][0]])){
719 $this->grouplist[$value['gidNumber'][0]]= $value;
720 }
721 }
722 }
724 $tmp=array();
726 /* Create result for group management listbox*/
727 foreach($this->grouplist as $tkey => $val ){
728 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
729 }
730 ksort($tmp);
731 $this->grouplist=array();
732 foreach($tmp as $val){
733 $this->grouplist[]=$val;
734 }
735 reset ($this->grouplist);
736 }
738 function remove_from_parent()
739 {
740 /* Optionally execute a command after we're done */
741 $this->postremove();
742 }
745 /* Save data to object */
746 function save_object()
747 {
748 }
751 /* Check values */
752 function check()
753 {
754 }
757 /* Save to LDAP */
758 function save()
759 {
760 /* Optionally execute a command after we're done */
761 $this->postcreate();
762 }
764 function adapt_from_template($dn)
765 {
766 }
768 function password_change_needed()
769 {
770 }
772 function show_header($button_text, $text, $disabled= FALSE)
773 {
774 }
776 function remove_lock()
777 {
778 if (isset($this->grouptab->dn)){
779 del_lock ($this->grouptab->dn);
780 }
781 }
783 }
785 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
786 ?>