Code

0636d6c4460fff0caad0c82bb1b6409caae6506c
[gosa.git] / plugins / admin / groups / class_groupManagement.inc
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();
214         
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         
223         $this->CopyPasteHandler->Copy($obj,$objNew);
224       }
227       /* Copy current object to CopyHandler
228        */
229       if($s_action == "cut"){
230         $this->CopyPasteHandler->Clear();
231         $dn = $this->grouplist[trim($s_entry)]['dn'];
232         $acl= get_permissions ($dn, $this->ui->subtreeACL);
234         $obj= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
235         $obj->set_acl($acl);
237         $this->CopyPasteHandler->Cut($obj);
238       }
239     }
242     /* New group? */
243     if ($s_action=="new"){
245       /* By default we set 'dn' to 'new', all relevant plugins will
246          react on this. */
247       $this->dn= "new";
249       /* Create new usertab object */
250       $this->grouptab= new grouptabs($this->config,
251           $this->config->data['TABS']['GROUPTABS'], $this->dn);
252       /* Set up the users ACL's for this 'dn' */
253       $acl= get_permissions ($groupfilter['depselect'], $this->ui->subtreeACL);
254       $this->grouptab->set_acl($acl);
255     }
257     /* Cancel dialogs */
258     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
259       del_lock ($this->grouptab->dn);
260       unset ($this->grouptab);
261       $this->grouptab= NULL;
262       unset($_SESSION['objectinfo']);
263     }
265     /* Finish group edit is triggered by the tabulator dialog, so
266        the user wants to save edited data. Check and save at this
267        point. */
268     if ((isset($_POST['edit_finish'])) && (isset($this->grouptab->config)) ){
270       /* Check tabs, will feed message array */
271       $message= $this->grouptab->check();
273       /* Save, or display error message? */
274       if (count($message) == 0){
276         /* Save user data to ldap */
277         $this->grouptab->save();
278         gosa_log ("Group object'".$this->dn."' has been saved");
280         /* Group has been saved successfully, remove lock from
281            LDAP. */
282         if ($this->dn != "new"){
283           del_lock ($this->dn);
284         }
286         /* There's no page reload so we have to read new users at
287            this point. */
288         $this->reload ();
289         unset ($this->grouptab);
290         $this->grouptab= NULL;
291         unset ($_SESSION['objectinfo']);
293       } else {
294         /* Ok. There seem to be errors regarding to the tab data,
295            show message and continue as usual. */
296         show_errors($message);
297       }
298     }
300     /* User wants to edit data? */
301     if (($s_action=="edit") && (!isset($this->grouptab-> config))){
303       /* Get 'dn' from posted 'uid', must be unique */
304       $this->dn= $this->grouplist[trim($s_entry)]['dn'];
306       /* Check locking, save current plugin in 'back_plugin', so
307          the dialog knows where to return. */
309       $user = get_lock($this->dn);
311       if ($user != ""){
312         return(gen_locked_message ($user, $this->dn));
313       }
315       /* Lock the current entry, so everyone will get the
316          above dialog */
317       add_lock ($this->dn, $this->ui->dn);
319       /* Set up the users ACL's for this 'dn' */
320       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
322       /* Register grouptab to trigger edit dialog */
323       $this->grouptab= new grouptabs($this->config,
324           $this->config->data['TABS']['GROUPTABS'], $this->dn);
325       $this->grouptab->set_acl($acl);
326       $_SESSION['objectinfo']= $this->dn;
327     }
329     /* Remove user was requested */
330     if ($s_action=="del"){
331       /* Get 'dn' from posted 'uid' */
332       $this->dn= $this->grouplist[trim($s_entry)]['dn'];
334       /* Load permissions for selected 'dn' and check if
335          we're allowed to remove this 'dn' */
336       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
337       $this->acl= get_module_permission($acl, "group", $this->dn);
338       if (chkacl($this->acl, "delete") == ""){
340         /* Check locking, save current plugin in 'back_plugin', so
341            the dialog knows where to return. */
342         if (($user= get_lock($this->dn)) != ""){
343           return(gen_locked_message ($user, $this->dn));
344         }
346         /* Lock the current entry, so nobody will edit it during deletion */
347         add_lock ($this->dn, $this->ui->dn);
348         $smarty->assign("info", sprintf(_("You're about to delete the group '%s'."), LDAP::fix($this->dn)));
349         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
350       } else {
352         /* Obviously the user isn't allowed to delete. Show message and
353            clean session. */
354         print_red (_("You are not allowed to delete this group!"));
355       }
356     }
358     /* Confirmation for deletion has been passed. Group should be deleted. */
359     if (isset($_POST['delete_group_confirm'])){
361       /* Some nice guy may send this as POST, so we've to check
362          for the permissions again. */
363       if (chkacl($this->acl, "delete") == ""){
365         /* Delete request is permitted, perform LDAP action */
366         $this->grouptab= new grouptabs($this->config,
367             $this->config->data['TABS']['GROUPTABS'], $this->dn);
368         $this->grouptab->set_acl(array($this->acl));
369         $this->grouptab->delete ();
370         gosa_log ("Group object'".$this->dn."' has been removed");
371         unset ($this->grouptab);
372         $this->grouptab= NULL;
374         /* Group list has changed, reload it. */
375         $this->reload ();
376       } else {
378         /* Normally this shouldn't be reached, send some extra
379            logs to notify the administrator */
380         print_red (_("You are not allowed to delete this group!"));
381         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
382       }
384       /* Remove lock file after successfull deletion */
385       del_lock ($this->dn);
386       unset($_SESSION['objectinfo']);
387     }
390     /* Delete group canceled? */
391     if (isset($_POST['delete_cancel'])){
392       del_lock ($this->dn);
393       unset($_SESSION['objectinfo']);
394     }
396     /* Show tab dialog if object is present */
397     if (isset($this->grouptab->config)){
398       $display= $this->grouptab->execute();
400       /* Don't show buttons if tab dialog requests this */
401       if (!$this->grouptab->by_object[$this->grouptab->current]->dialog){
402         $display.= "<p style=\"text-align:right\">\n";
403         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
404         $display.= "&nbsp;\n";
405         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
406         $display.= "</p>";
407       }
408       return ($display);
409     }
411     /* Prepare departments */
412     $options= "";
413     foreach ($this->config->idepartments as $key => $value){
414             if ($groupfilter['depselect'] == $key){
415                     $options.= "<option selected value='$key'>$value</option>";
416             } else {
417                     $options.= "<option value='$key'>$value</option>";
418             }
419     }
421     /* Create paste icon 
422      */
423     if($this->enableCopyPaste){
424       $Copy_Paste = " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
425       if($this->CopyPasteHandler->isCurrentObjectPastAble()){
426         if($this->CopyPasteHandler->isCurrentCutted()){
427           $img = "images/cutpaste.png";
428         }else{
429           $img = "images/copypaste.png";
430         }
431         $Copy_Paste .= "<input type='image' name='editPaste' class='center'
432           src='".$img."' alt='"._("Paste")."' title='".$this->CopyPasteHandler->GetCurrentDn()."'>&nbsp;";
433       }else{
434         $Copy_Paste .= "<img class='center' src='images/cant_editpaste.png' alt='"._("Can't paste")."'>&nbsp;";
435       }
436     }else{
437       $Copy_Paste ="";
438     }
440     // Managment
441     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
442       " <input type='image' class='center' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
443       " <input type='image' class='center' src='images/list_root.png' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
444       " <input type='image' class='center' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
445       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
446       " <input type='image' class='center' src='images/list_new_group.png' title='"._("Create new group")."' alt='"._("New")."' name='group_new'>&nbsp;".
447       $Copy_Paste.
448       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
449       _("Base")."&nbsp;<select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
450        " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
451       "</div>";
453     
454     if($this->enableCopyPaste){
455       $actions = "<input class='center' type='image'
456         src='images/editdelete.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
457       $actions.= "<input class='center' type='image'
458         src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
459       $actions.= "<input class='center' type='image' 
460         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
461       $actions.= "<input class='center' type='image' 
462         src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
463     }else{
464       $actions = "<input class='center' type='image' 
465         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
466       $actions.= "<input class='center' type='image' 
467         src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
468     }
471     // Defining Links
472     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
474     // image Buttons 
475     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
476     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
479     /* Extension images 
480         group
481         environment
482         appgroup
483         mailgroup
484         acl
485         reference
487      */
488     $posiximg = "<input type='image' class='center' src='images/select_groups.png' 
489                  name='group_group_edit_%KEY%' 
490                  alt='P'  title='"._("Posix")  ."'>";
491     $mailimg  = "<input type='image' class='center' src='images/mailto.png'            
492                  name='mailgroup_group_edit_%KEY%' 
493                   alt='M'  title='"._("Mail")   ."'>";
494     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'  
495                  name='group_group_edit_%KEY%' 
496                   alt='S'  title='"._("Samba")  ."'>";
497     $applimg  = "<input type='image'  class='center' src='images/select_application.png' 
498                  name='appgroup_group_edit_%KEY%' 
499                   alt='A'  title='"._("Application")."'>"; 
500     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'      
501                  name='group_group_edit_%KEY%' 
502                   alt='Ph' title='"._("Phone")  ."'>"; 
503     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'      
504                  name='environment_group_edit_%KEY%' 
505                   alt='E' title='"._("Environment")  ."'>"; 
507     // Space
508     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
511     $divlist = new divlist("groupstab");
512     $divlist->SetHeader(array(
513           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
514           array("string" => _("Groupname")." / "._("Department"), "attach" => "style=''"),
515           array("string" => _("Properties"), "attach" => "style='width:136px;'"),
516           array("string" => _("Actions"), "attach" => "style='width:80px;border-right:0px;text-align:right;'")
517           ));
519     $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
520     $divlist->SetEntriesPerPage(0);
522     foreach($this->departments as $key=> $val){
524       if(!isset($this->config->departments[trim($key)])){
525         $this->config->departments[trim($key)]="";
526       }
528       $non_empty="";
529       $keys= str_replace("/","\/",$key);
530       foreach($this->config->departments as $keyd=>$vald ){
531         if(preg_match("/".$keys."\/.*/",$keyd)){
532           $non_empty="full";
533         }
534       }
537       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
538       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
539       $field3 = array("string" => "&nbsp;", "attach" => "style='width:136px;'");
540       $field4 = array("string" => "&nbsp;", "attach" => "style='width:80px;border-right:0px;text-align:right;'");
542       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
543     }
545     foreach($this->grouplist as $key => $val){
547       if(isset($val['objectClass'])){
548         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;   else $posix   = $empty;
549         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;    else $mail    = $empty;
550         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;   else $samba   = $empty;
551         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;    else $appl    = $empty;
552         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;   else $phone   = $empty;
553         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;     else $enviro  = $empty;
554       }else{
555         $posix=$mail=$samba=$appl=$phone=$empty;
556       }
558       $title = "title='gid : ".$key." - dn : ".$val['dn']."'";
560       if(!isset($val['description'][0])){
561         $desc = "";
562       }else{
563         $desc = " - [ ".$val['description'][0]." ]";
564       }      
565       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
566       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
567       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone), "attach" => "style='width:136px;'");  
568       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'");
569       
570       $divlist->AddEntry(array($field1,$field2,$field3,$field4));    
571     }
573     /* Show main page */
574     $smarty->assign("grouplisthead", $listhead);
575     $smarty->assign("grouplist", $divlist->DrawList());
576     $smarty->assign("search_image", get_template_path('images/search.png'));
577     $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
578     $smarty->assign("tree_image", get_template_path('images/tree.png'));
579     $smarty->assign("infoimage", get_template_path('images/info.png'));
580     $smarty->assign("launchimage", get_template_path('images/launch.png'));
581     $smarty->assign("deplist", $this->config->idepartments);
582     foreach( array("depselect", "guser", "regex", "primarygroups", "mailgroups","appgroups", "sambagroups", "functionalgroups", "subsearch") as $type){
583       $smarty->assign("$type", $groupfilter[$type]);
584     }
586     /* Extend if we are not using javascript */
587     $smarty->assign("apply", apply_filter());
588     $smarty->assign("alphabet", generate_alphabet());
589     $smarty->assign("hint", print_sizelimit_warning());
590     if (isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
591       $smarty->assign("showprimary", "");
592     } else {
593       $smarty->assign("showprimary", "true");
594     }
596     return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
597   }
599   function reload($CreatePosixsList=false)
600   {
601     /* Get config */
602     $groupfilter= get_global('groupfilter');
604     /* Set base for all searches */
605     $base= $groupfilter['depselect'];
607     /* Regex filter? */
608     if ($groupfilter['regex'] != ""){
609       $regex= $groupfilter['regex'];
610     } else {
611       $regex= "*";
612     }
614     /* User filter? */
615     $filter= "(objectclass=posixGroup)";
616     $error= "";
617     $error2= "";
618     $this->grouplist= array();
620     /* What are primary groups? */
621     $primaries= array();
622     $ldap= $this->config->get_ldap_link();
623     if (!isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
624       $ldap->cd($base);
625       $ldap->search("(&(uid=$regex)(!(uid=*$))(objectClass=posixAccount)(gidNumber=*))", array("gidNumber", "cn"));
626       show_ldap_error($ldap->get_error());
627       while ($attrs= $ldap->fetch()){
628         $primaries[$attrs['gidNumber'][0]]= $attrs['cn'][0];
629       }
630     }
632     /* Set filter depending on selection */
633     $sfilter= "";
634     if ($groupfilter['appgroups'] == "checked"){
635       $filter.= "(objectClass=gosaApplicationGroup)";
636     }
637     if ($this->config->current['SAMBAVERSION'] == 3){
638       if ($groupfilter['primarygroups'] != "checked"){
639         $sfilter= "(objectClass=sambaGroupMapping)";
640       } elseif ($groupfilter['sambagroups'] == "checked"){
641         $filter.= "(objectClass=sambaGroupMapping)";
642       }
643     }
645     if ($groupfilter['mailgroups'] == "checked"){
646       $filter.= "(objectClass=gosaMailAccount)";
647     }
648     $functional= array();
649     $ldap->cd(get_groups_ou().$base);
650     $ldap->set_size_limit($_SESSION['size_limit']);
651     $ldap->search("(&(cn=$regex)(objectClass=posixGroup)(!(|(objectClass=gosaMailAccount)(objectClass=gosaApplicationGroup)$sfilter)))", array("cn", "gidNumber", "description"));
652     $error2= $ldap->error;
653     while ($attrs= $ldap->fetch()){
654       if (!isset($primaries[$attrs['gidNumber'][0]])){
655         $functional[$attrs['gidNumber'][0]]= $attrs['gidNumber'][0];
656       }
657     }
659     /*
660      * We also need to search for the departments
661      * So we are able to navigate like in konquerer
662      */
664       $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
665           FALSE, $base, array("ou", "description"), TRUE);
666       $this->departments= array();
667       $tmp = array();
668       foreach ($res3 as $value){
669         $tmp[strtolower($value['dn']).$value['dn']]=$value;
670       }
671       ksort($tmp);
672       foreach($tmp as $value){
673         if(isset($value["description"][0])){
674           $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
675         }else{
676           $this->departments[$value['dn']]= convert_department_dn2($value['dn']);//$value["description"][0];
677         }
678       }
679     /*  Ende department generation
680      */
682     /* Generate grouplist */
683     if ($filter != ""){
684       $filter= "(&(cn=$regex)(objectClass=posixGroup)(|$filter))";
685       if ($groupfilter['guser'] != ""){
686         $filter= "(&(|(memberUID=" . $groupfilter['guser'] . ")(cn=" . $groupfilter['guser'] . "))$filter)";
687       }
688     }
690     /* Depending on $CreatePosixsList we have to create different lists */
692     if ($groupfilter['subsearch'] == "checked"){
693       $res= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("cn", "description", "gidNumber"), TRUE);
694     } else {
695       $base= get_groups_ou().$base;
696       $res= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("cn", "description", "gidNumber"), TRUE);
697     }
698     if (preg_match("/size limit/i", $error) || preg_match("/size limit/i", $error2)){
699       $_SESSION['limit_exceeded']= TRUE;
700     }
702     foreach ($res as $value){
703       if ($groupfilter['functionalgroups'] != "checked" && isset($functional[$value['gidNumber'][0]])){
704         continue;
705       }
706       if ($groupfilter['primarygroups'] == "checked"){
707         $this->grouplist[$value['gidNumber'][0]]= $value;
708       } else {
709         if (!isset($primaries[$value['gidNumber'][0]])){
710           $this->grouplist[$value['gidNumber'][0]]= $value;
711         }
712       }
713     }
715     $tmp=array();
717     /* Create result for group management listbox*/
718     foreach($this->grouplist as $tkey => $val ){
719       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
720     }
721     ksort($tmp);
722     $this->grouplist=array();
723     foreach($tmp as $val){
724       $this->grouplist[]=$val;
725     }
726     reset ($this->grouplist);
727   }
729   function remove_from_parent()
730   {
731     /* Optionally execute a command after we're done */
732     $this->postremove();
733   }
736   /* Save data to object */
737   function save_object()
738   {
739   }
742   /* Check values */
743   function check()
744   {
745   }
748   /* Save to LDAP */
749   function save()
750   {
751     /* Optionally execute a command after we're done */
752     $this->postcreate();
753   }
755   function adapt_from_template($dn)
756   {
757   }
759   function password_change_needed()
760   {
761   }
763   function show_header($button_text, $text, $disabled= FALSE)
764   {
765   }
767   function remove_lock()
768   {
769     if (isset($this->grouptab->dn)){
770       del_lock ($this->grouptab->dn);
771     }
772   }
776 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
777 ?>