Code

Removed double coding
[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  = NULL;
37   function groupManagement ($config, $ui)
38   {
39     /* Save configuration for internal use */
40     $this->config= $config;
41     $this->ui= $ui;
43     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
44       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
45     }
47     /* Get global filter config */
48     if (!is_global("groupfilter")){
49       $base= get_base_from_people($ui->dn);
50       $groupfilter= array("primarygroups" => "checked",
51           "mailgroups" => "checked",
52           "sambagroups" => "checked",
53           "appgroups" => "checked",
54           "functionalgroups" => "checked",
55           "guser" => "*",
56           "subsearch" => "",
57           "regex" => "*");
58       register_global("groupfilter", $groupfilter);
59     }
60     if(!isset($_SESSION['CurrentMainBase'])){
61       $base = get_base_from_people($ui->dn);
62       $_SESSION['CurrentMainBase'] = $base; 
63     }
64   }
66   function execute()
67   {
68         /* Call parent execute */
69         plugin::execute();
71     $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/");
73     /* Save data */
74     $groupfilter= get_global("groupfilter");
75     $s_action   = "";
76     $s_entry    = "";
78     if (!isset($this->grouptab)){
79       foreach( array( "guser", "regex") as $type){
80         if (isset($_POST[$type])){
81           $groupfilter[$type]= $_POST[$type];
82         } 
83       }
84       if(isset($_POST['CurrentMainBase'])){
85         $_SESSION['CurrentMainBase'] = $_POST['CurrentMainBase'];
86       }
87       if (isset($_POST['regex'])){
88         foreach( array("primarygroups", "sambagroups", "mailgroups", "appgroups",
89               "functionalgroups", "subsearch") as $type){
91           if (isset($_POST[$type])) {
92             $groupfilter[$type]= "checked";
93           } else {
94             $groupfilter[$type]= "";
95           }
96         }
97       }
98       if (isset($_GET['search'])){
99         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
100         if ($s == "**"){
101           $s= "*";
102         }
103         $groupfilter['regex']= $s;
104       }
105       register_global("groupfilter", $groupfilter);
106     }
109     /* Test Posts */
110     foreach($_POST as $key => $val){
111       // Post for delete
112       if(preg_match("/^group_del.*/",$key)){
113         $s_action = "del";
114         $s_entry  = preg_replace("/group_".$s_action."_/i","",$key);
115         // Post for edit
116       }elseif(preg_match("/^group_edit_.*/",$key)){
117         $s_action="edit";
118         $s_entry  = preg_replace("/group_".$s_action."_/i","",$key);
119         // Post for new
120       }elseif(preg_match("/^dep_back.*/i",$key)){
121         $s_action="back";
122       }elseif(preg_match("/^group_new.*/",$key)){
123         $s_action="new";
124       }elseif(preg_match("/^dep_home.*/i",$key)){
125         $s_action="home";
126       }elseif(preg_match("/^group_tplnew.*/i",$key)){
127         $s_action="new_tpl";
128       }elseif(preg_match("/^group_chgpw.*/i",$key)){
129         $s_action="change_pw";
130         $s_entry  = preg_replace("/group_chgpw_/i","",$key);
131       }elseif(preg_match("/^dep_root.*/i",$key)){
132         $s_action="root";
133       }elseif(preg_match("/_group_edit_/",$key)){
134         $type = preg_replace("/_group_edit_.*$/","",$key);
135         $s_action="edit";
136         $s_entry  = preg_replace("/".$type."_group_edit_/i","",$key); 
137         $_POST['arg'] = $type;
138       }elseif(preg_match("/^editPaste.*/i",$key)){
139         $s_action="editPaste";
140       }elseif(preg_match("/^copy_.*/",$key)){
141         $s_action="copy";
142         $s_entry  = preg_replace("/^copy_/i","",$key);
143       }elseif(preg_match("/^cut_.*/",$key)){
144         $s_action="cut";
145         $s_entry  = preg_replace("/^cut_/i","",$key);
146       }
147     }
148     $s_entry  = preg_replace("/_.$/","",$s_entry); 
150     /* Start for New List Managment */
151     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
152       $s_action="open";
153       $s_entry = base64_decode($_GET['dep_id']);
154       $_SESSION['CurrentMainBase']= "".$this->config->departments[trim($s_entry)];
155     }
157     // Edit if
158     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
159       $s_action ="edit";
160       $s_entry  = $_GET['id'];
161     }
163     /* Department changed? */
164     if(isset($_POST['CurrentMainBase']) && $_POST['CurrentMainBase']){
165       $_SESSION['CurrentMainBase']= $_POST['CurrentMainBase'];
166     }
168     /* Homebutton is posted */
169     if($s_action=="home"){
170       //FIXME: This will not work if we've no subdirs (like i.e. ou=people)? See
171       //       class_userManagement.inc for a fix.
172       $_SESSION['CurrentMainBase']= (preg_replace("/^[^,]+,/","",$this->ui->dn));
173       $_SESSION['CurrentMainBase']= (preg_replace("/^[^,]+,/","",$_SESSION['CurrentMainBase']));
174     }
176     if($s_action=="root"){
177       $_SESSION['CurrentMainBase']=($this->config->current['BASE']);
178     }
180     /* If Backbutton is Posted */
181     if($s_action == "back"){
182       $base_back= preg_replace("/^[^,]+,/","",$_SESSION['CurrentMainBase']);
183       $base_back= convert_department_dn($base_back);
185       if(isset($this->config->departments[trim($base_back)])){
186         $_SESSION['CurrentMainBase']= $this->config->departments[trim($base_back)];
187       }else{
188         $_SESSION['CurrentMainBase']= $this->config->departments["/"];
189       }
190     }
191     register_global("groupfilter", $groupfilter);
193     $smarty= get_smarty();
195     /* Prepare formular */
196     $this->reload();
198     /* Check for exeeded sizelimit */
199     if (($message= check_sizelimit()) != ""){
200       return($message);
201     }
203     /* Only perform copy&paste requests if it is enabled
204      */
205     if($this->CopyPasteHandler){
206       if($str = $this->copyPasteHandling($s_action,$s_entry)){
207         return $str;
208       }
209     }
211     /* New group? */
212     if ($s_action=="new"){
214       /* By default we set 'dn' to 'new', all relevant plugins will
215          react on this. */
216       $this->dn= "new";
218       /* Create new usertab object */
219       $this->grouptab= new grouptabs($this->config,
220           $this->config->data['TABS']['GROUPTABS'], $this->dn);
221       /* Set up the users ACL's for this 'dn' */
222       $acl= get_permissions ($_SESSION['CurrentMainBase'], $this->ui->subtreeACL);
223       $this->grouptab->set_acl($acl);
224     }
226     /* Cancel dialogs */
227     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
228       del_lock ($this->grouptab->dn);
229       unset ($this->grouptab);
230       $this->grouptab= NULL;
231       unset($_SESSION['objectinfo']);
232     }
234     /* Finish group edit is triggered by the tabulator dialog, so
235        the user wants to save edited data. Check and save at this
236        point. */
237     if ((isset($_POST['edit_finish'])) && (isset($this->grouptab->config)) ){
239       /* Check tabs, will feed message array */
240       $message= $this->grouptab->check();
242       /* Save, or display error message? */
243       if (count($message) == 0){
245         /* Save user data to ldap */
246         $this->grouptab->save();
247         gosa_log ("Group object'".$this->dn."' has been saved");
249         /* Group has been saved successfully, remove lock from
250            LDAP. */
251         if ($this->dn != "new"){
252           del_lock ($this->dn);
253         }
255         /* There's no page reload so we have to read new users at
256            this point. */
257         $this->reload ();
258         unset ($this->grouptab);
259         $this->grouptab= NULL;
260         unset ($_SESSION['objectinfo']);
262       } else {
263         /* Ok. There seem to be errors regarding to the tab data,
264            show message and continue as usual. */
265         show_errors($message);
266       }
267     }
269     /* User wants to edit data? */
270     if (($s_action=="edit") && (!isset($this->grouptab-> config))){
272       /* Get 'dn' from posted 'uid', must be unique */
273       $this->dn= $this->grouplist[trim($s_entry)]['dn'];
275       /* Check locking, save current plugin in 'back_plugin', so
276          the dialog knows where to return. */
278       $user = get_lock($this->dn);
280       if ($user != ""){
281         return(gen_locked_message ($user, $this->dn));
282       }
284       /* Lock the current entry, so everyone will get the
285          above dialog */
286       add_lock ($this->dn, $this->ui->dn);
288       /* Set up the users ACL's for this 'dn' */
289       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
291       /* Register grouptab to trigger edit dialog */
292       $this->grouptab= new grouptabs($this->config,
293           $this->config->data['TABS']['GROUPTABS'], $this->dn);
294       $this->grouptab->set_acl($acl);
295       $_SESSION['objectinfo']= $this->dn;
296     }
298     /* Remove user was requested */
299     if ($s_action=="del"){
300       /* Get 'dn' from posted 'uid' */
301       $this->dn= $this->grouplist[trim($s_entry)]['dn'];
303       /* Load permissions for selected 'dn' and check if
304          we're allowed to remove this 'dn' */
305       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
306       $this->acl= get_module_permission($acl, "group", $this->dn);
307       if (chkacl($this->acl, "delete") == ""){
309         /* Check locking, save current plugin in 'back_plugin', so
310            the dialog knows where to return. */
311         if (($user= get_lock($this->dn)) != ""){
312           return(gen_locked_message ($user, $this->dn));
313         }
315         /* Lock the current entry, so nobody will edit it during deletion */
316         add_lock ($this->dn, $this->ui->dn);
317         $smarty->assign("info", sprintf(_("You're about to delete the group '%s'."), @LDAP::fix($this->dn)));
318         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
319       } else {
321         /* Obviously the user isn't allowed to delete. Show message and
322            clean session. */
323         print_red (_("You are not allowed to delete this group!"));
324       }
325     }
327     /* Confirmation for deletion has been passed. Group should be deleted. */
328     if (isset($_POST['delete_group_confirm'])){
330       /* Some nice guy may send this as POST, so we've to check
331          for the permissions again. */
332       if (chkacl($this->acl, "delete") == ""){
334         /* Delete request is permitted, perform LDAP action */
335         $this->grouptab= new grouptabs($this->config,
336             $this->config->data['TABS']['GROUPTABS'], $this->dn);
337         $this->grouptab->set_acl(array($this->acl));
338         $this->grouptab->delete ();
339         gosa_log ("Group object'".$this->dn."' has been removed");
340         unset ($this->grouptab);
341         $this->grouptab= NULL;
343         /* Group list has changed, reload it. */
344         $this->reload ();
345       } else {
347         /* Normally this shouldn't be reached, send some extra
348            logs to notify the administrator */
349         print_red (_("You are not allowed to delete this group!"));
350         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
351       }
353       /* Remove lock file after successfull deletion */
354       del_lock ($this->dn);
355       unset($_SESSION['objectinfo']);
356     }
359     /* Delete group canceled? */
360     if (isset($_POST['delete_cancel'])){
361       del_lock ($this->dn);
362       unset($_SESSION['objectinfo']);
363     }
365     /* Show tab dialog if object is present */
366     if (isset($this->grouptab->config)){
367       $display= $this->grouptab->execute();
369       /* Don't show buttons if tab dialog requests this */
370       if (!$this->grouptab->by_object[$this->grouptab->current]->dialog){
371         $display.= "<p style=\"text-align:right\">\n";
372         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
373         $display.= "&nbsp;\n";
374         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
375         $display.= "</p>";
376       }
377       return ($display);
378     }
380     /* Prepare departments */
381     $options= "";
382     foreach ($this->config->idepartments as $key => $value){
383             if ($_SESSION['CurrentMainBase'] == $key){
384                     $options.= "<option selected value='$key'>$value</option>";
385             } else {
386                     $options.= "<option value='$key'>$value</option>";
387             }
388     }
390     /* Create paste icon 
391      */
392     if($this->CopyPasteHandler){
393       $Copy_Paste = " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
394       if($this->CopyPasteHandler->isCurrentObjectPastAble()){
395         if($this->CopyPasteHandler->isCurrentCutted()){
396           $img = "images/cutpaste.png";
397         }else{
398           $img = "images/copypaste.png";
399         }
400         $Copy_Paste .= "<input type='image' name='editPaste' class='center'
401           src='".$img."' alt='"._("Paste")."' title='".$this->CopyPasteHandler->GetCurrentDn()."'>&nbsp;";
402       }else{
403         $Copy_Paste .= "<img class='center' src='images/cant_editpaste.png' alt='"._("Can't paste")."'>&nbsp;";
404       }
405     }else{
406       $Copy_Paste ="";
407     }
409     // Managment
410     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
411       " <input type='image' class='center' src='images/list_root.png' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
412       " <input type='image' class='center' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
413       " <input type='image' class='center' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
414       " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
415       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
416       " <input type='image' class='center' src='images/list_new_group.png' title='"._("Create new group")."' alt='"._("New")."' name='group_new'>&nbsp;".
417       $Copy_Paste.
418       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
419       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
420        " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
421       "</div>";
423     
424     if($this->CopyPasteHandler){
425       $actions = "<input class='center' type='image'
426         src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
427       $actions.= "<input class='center' type='image'
428         src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
429       $actions.= "<input class='center' type='image' 
430         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
431       $actions.= "<input class='center' type='image' 
432         src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
433     }else{
434       $actions = "<input class='center' type='image' 
435         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
436       $actions.= "<input class='center' type='image' 
437         src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
438     }
441     // Defining Links
442     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
444     // image Buttons 
445     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
446     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
448     /* Assign extension images */
449     $posiximg = "<input type='image' class='center' src='images/select_groups.png' 
450                  name='group_group_edit_%KEY%' 
451                  alt='P'  title='"._("Posix")  ."'>";
452     $mailimg  = "<input type='image' class='center' src='images/mailto.png'            
453                  name='mailgroup_group_edit_%KEY%' 
454                   alt='M'  title='"._("Mail")   ."'>";
455     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'  
456                  name='group_group_edit_%KEY%' 
457                   alt='S'  title='"._("Samba")  ."'>";
458     $applimg  = "<input type='image'  class='center' src='images/select_application.png' 
459                  name='appgroup_group_edit_%KEY%' 
460                   alt='A'  title='"._("Application")."'>"; 
461     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'      
462                  name='group_group_edit_%KEY%' 
463                   alt='Ph' title='"._("Phone")  ."'>"; 
464     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'      
465                  name='environment_group_edit_%KEY%' 
466                   alt='E' title='"._("Environment")  ."'>"; 
468     // Space
469     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
471     $divlist = new divlist("groupstab");
472     $divlist->SetHeader(array(
473           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
474           array("string" => _("Groupname")." / "._("Department"), "attach" => "style=''"),
475           array("string" => _("Properties"), "attach" => "style='width:136px;'"),
476           array("string" => _("Actions"), "attach" => "style='width:80px;border-right:0px;text-align:right;'")
477           ));
479     $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
480     $divlist->SetEntriesPerPage(0);
482     foreach($this->departments as $key=> $val){
484       if(!isset($this->config->departments[trim($key)])){
485         $this->config->departments[trim($key)]="";
486       }
488       $non_empty="";
489       $keys= str_replace("/","\/",$key);
490       foreach($this->config->departments as $keyd=>$vald ){
491         if(preg_match("/".$keys."\/.*/",$keyd)){
492           $non_empty="full";
493         }
494       }
497       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
498       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
499       $field3 = array("string" => "&nbsp;", "attach" => "style='width:136px;'");
500       $field4 = array("string" => "&nbsp;", "attach" => "style='width:80px;border-right:0px;text-align:right;'");
502       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
503     }
505     foreach($this->grouplist as $key => $val){
507       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
509       if(isset($val['objectClass'])){
510         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
511         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
512         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
513         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;
514         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
515         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
516       }
518       $title = "title='dn:&nbsp;".@LDAP::fix($val['dn'])."'";
520       if(!isset($val['description'][0])){
521         $desc = "";
522       }else{
523         $desc = " - [ ".$val['description'][0]." ]";
524       }      
525       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
526       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
527       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone), "attach" => "style='width:136px;'");  
528       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'");
529       
530       $divlist->AddEntry(array($field1,$field2,$field3,$field4));    
531     }
533     /* Show main page */
534     $smarty->assign("grouplisthead", $listhead);
535     $smarty->assign("grouplist", $divlist->DrawList());
536     $smarty->assign("search_image", get_template_path('images/search.png'));
537     $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
538     $smarty->assign("tree_image", get_template_path('images/tree.png'));
539     $smarty->assign("infoimage", get_template_path('images/info.png'));
540     $smarty->assign("launchimage", get_template_path('images/launch.png'));
541     $smarty->assign("deplist", $this->config->idepartments);
542     foreach( array("guser", "regex", "primarygroups", "mailgroups","appgroups", "sambagroups", "functionalgroups", "subsearch") as $type){
543       $smarty->assign("$type", $groupfilter[$type]);
544     }
546     /* Extend if we are not using javascript */
547     $smarty->assign("apply", apply_filter());
548     $smarty->assign("alphabet", generate_alphabet());
549     $smarty->assign("hint", print_sizelimit_warning());
550     if (isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
551       $smarty->assign("showprimary", "");
552     } else {
553       $smarty->assign("showprimary", "true");
554     }
556     return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
557   }
559   function reload($CreatePosixsList=false)
560   {
561     /* Get config */
562     $groupfilter= get_global('groupfilter');
564     /* Set base for all searches */
565     $base= $_SESSION['CurrentMainBase'];
567     /* Regex filter? */
568     if ($groupfilter['regex'] != ""){
569       $regex= $groupfilter['regex'];
570     } else {
571       $regex= "*";
572     }
574     /* User filter? */
575     $filter= "(objectclass=posixGroup)";
576     $error= "";
577     $error2= "";
578     $this->grouplist= array();
580     /* What are primary groups? */
581     $primaries= array();
582     $ldap= $this->config->get_ldap_link();
583     if (!isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
584       $ldap->cd($base);
585       $ldap->search("(&(uid=$regex)(!(uid=*$))(objectClass=posixAccount)(gidNumber=*))", array("gidNumber", "cn"));
586       show_ldap_error($ldap->get_error());
587       while ($attrs= $ldap->fetch()){
588         $primaries[$attrs['gidNumber'][0]]= $attrs['cn'][0];
589       }
590     }
592     /* Set filter depending on selection */
593     $sfilter= "";
594     if ($groupfilter['appgroups'] == "checked"){
595       $filter.= "(objectClass=gosaApplicationGroup)";
596     }
597     if ($this->config->current['SAMBAVERSION'] == 3){
598       if ($groupfilter['primarygroups'] != "checked"){
599         $sfilter= "(objectClass=sambaGroupMapping)";
600       } elseif ($groupfilter['sambagroups'] == "checked"){
601         $filter.= "(objectClass=sambaGroupMapping)";
602       }
603     }
605     if ($groupfilter['mailgroups'] == "checked"){
606       $filter.= "(objectClass=gosaMailAccount)";
607     }
608     $functional= array();
609     $ldap->cd(get_groups_ou().$base);
610     $ldap->set_size_limit($_SESSION['size_limit']);
611     $ldap->search("(&(cn=$regex)(objectClass=posixGroup)(!(|(objectClass=gosaMailAccount)(objectClass=gosaApplicationGroup)$sfilter)))", array("cn", "gidNumber", "description"));
612     $error2= $ldap->error;
613     while ($attrs= $ldap->fetch()){
614       if (!isset($primaries[$attrs['gidNumber'][0]])){
615         $functional[$attrs['gidNumber'][0]]= $attrs['gidNumber'][0];
616       }
617     }
619     /*
620      * We also need to search for the departments
621      * So we are able to navigate like in konquerer
622      */
624     /* Get all departments within this subtree */
625     $deps= get_list("(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
626         $base, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
628     $this->departments = array();
629     foreach($deps as $value){
630       if(isset($value['description'][0])){
631         $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
632       }else{
633         $this->departments[$value['dn']]= get_sub_department($value['dn']);
634       }
635     }
636     natcasesort($this->departments);
637     /*  Ende department generation
638      */
640     /* Generate grouplist */
641     if ($filter != ""){
642       $filter= "(&(cn=$regex)(objectClass=posixGroup)(|$filter))";
643       if ($groupfilter['guser'] != ""){
644         $filter= "(&(|(memberUID=" . $groupfilter['guser'] . ")(cn=" . $groupfilter['guser'] . "))$filter)";
645       }
646     }
648     /* Depending on $CreatePosixsList we have to create different lists */
650     if ($groupfilter['subsearch'] == "checked"){
651       $res= get_list($filter, $this->ui->subtreeACL, $base, array("cn", "description", "gidNumber", "objectClass"),
652                      GL_SIZELIMIT);
653     } else {
654       $base= get_groups_ou().$base;
655       $res= get_list($filter, $this->ui->subtreeACL, $base, array("cn", "description", "gidNumber", "objectClass"),
656                      GL_SIZELIMIT);
657     }
658     if (preg_match("/size limit/i", $error) || preg_match("/size limit/i", $error2)){
659       $_SESSION['limit_exceeded']= TRUE;
660     }
662     foreach ($res as $value){
663       if ($groupfilter['functionalgroups'] != "checked" && isset($functional[$value['gidNumber'][0]])){
664         continue;
665       }
666       if ($groupfilter['primarygroups'] == "checked"){
667         $this->grouplist[$value['gidNumber'][0]]= $value;
668       } else {
669         if (!isset($primaries[$value['gidNumber'][0]])){
670           $this->grouplist[$value['gidNumber'][0]]= $value;
671         }
672       }
673     }
675     $tmp=array();
677     /* Create result for group management listbox*/
678     foreach($this->grouplist as $tkey => $val ){
679       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
680     }
681     ksort($tmp);
682     $this->grouplist=array();
683     foreach($tmp as $val){
684       $this->grouplist[]=$val;
685     }
686     reset ($this->grouplist);
687   }
689   function remove_from_parent()
690   {
691     /* Optionally execute a command after we're done */
692     $this->postremove();
693   }
698   /* Perform copy & paste requests
699      If copy&paste is in progress this returns a dialog to fix required attributes 
700    */ 
701   function copyPasteHandling($s_action,$s_entry)
702   {
703     /* Paste copied/cutted object in here
704      */
705     if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
706       $this->CopyPasteHandler->save_object();
707       $this->CopyPasteHandler->SetVar("base",$_SESSION['CurrentMainBase']);
708       if($str = $this->CopyPasteHandler->execute()){
709         return( $str);
710       };
711       /* Ensure that the new object is shown in the list now */
712       $this->relaod();
713     }
716     /* Copy current object to CopyHandler
717      */
718     if($s_action == "copy"){
719       $this->CopyPasteHandler->Clear();
721       $dn     = $this->grouplist[trim($s_entry)]['dn'];
722       $acl    = get_permissions ($dn, $this->ui->subtreeACL);
724       $obj    = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
725       $objNew = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], "new");
726       $obj->set_acl($acl);
727       $objNew->set_acl($acl);
728       $this->CopyPasteHandler->Copy($obj,$objNew);
729     }
732     /* Copy current object to CopyHandler
733      */
734     if($s_action == "cut"){
735       $this->CopyPasteHandler->Clear();
736       $dn = $this->grouplist[trim($s_entry)]['dn'];
737       $acl= get_permissions ($dn, $this->ui->subtreeACL);
739       $obj= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
740       $obj->set_acl($acl);
742       $this->CopyPasteHandler->Cut($obj);
743     }
744   }
746   /* Save data to object */
747   function save_object()
748   {
749   }
752   /* Check values */
753   function check()
754   {
755   }
758   /* Save to LDAP */
759   function save()
760   {
761     /* Optionally execute a command after we're done */
762     $this->postcreate();
763   }
765   function adapt_from_template($dn)
766   {
767   }
769   function password_change_needed()
770   {
771   }
773   function show_header($button_text, $text, $disabled= FALSE)
774   {
775   }
777   function remove_lock()
778   {
779     if (isset($this->grouptab->dn)){
780       del_lock ($this->grouptab->dn);
781     }
782   }
786 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
787 ?>