Code

Moved copy&paste into a seperate function
[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         echo $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'>";
449     /* Extension images 
450         group
451         environment
452         appgroup
453         mailgroup
454         acl
455         reference
457      */
458     $posiximg = "<input type='image' class='center' src='images/select_groups.png' 
459                  name='group_group_edit_%KEY%' 
460                  alt='P'  title='"._("Posix")  ."'>";
461     $mailimg  = "<input type='image' class='center' src='images/mailto.png'            
462                  name='mailgroup_group_edit_%KEY%' 
463                   alt='M'  title='"._("Mail")   ."'>";
464     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'  
465                  name='group_group_edit_%KEY%' 
466                   alt='S'  title='"._("Samba")  ."'>";
467     $applimg  = "<input type='image'  class='center' src='images/select_application.png' 
468                  name='appgroup_group_edit_%KEY%' 
469                   alt='A'  title='"._("Application")."'>"; 
470     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'      
471                  name='group_group_edit_%KEY%' 
472                   alt='Ph' title='"._("Phone")  ."'>"; 
473     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'      
474                  name='environment_group_edit_%KEY%' 
475                   alt='E' title='"._("Environment")  ."'>"; 
477     // Space
478     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
481     $divlist = new divlist("groupstab");
482     $divlist->SetHeader(array(
483           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
484           array("string" => _("Groupname")." / "._("Department"), "attach" => "style=''"),
485           array("string" => _("Properties"), "attach" => "style='width:136px;'"),
486           array("string" => _("Actions"), "attach" => "style='width:80px;border-right:0px;text-align:right;'")
487           ));
489     $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
490     $divlist->SetEntriesPerPage(0);
492     foreach($this->departments as $key=> $val){
494       if(!isset($this->config->departments[trim($key)])){
495         $this->config->departments[trim($key)]="";
496       }
498       $non_empty="";
499       $keys= str_replace("/","\/",$key);
500       foreach($this->config->departments as $keyd=>$vald ){
501         if(preg_match("/".$keys."\/.*/",$keyd)){
502           $non_empty="full";
503         }
504       }
507       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
508       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
509       $field3 = array("string" => "&nbsp;", "attach" => "style='width:136px;'");
510       $field4 = array("string" => "&nbsp;", "attach" => "style='width:80px;border-right:0px;text-align:right;'");
512       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
513     }
515     foreach($this->grouplist as $key => $val){
517       if(isset($val['objectClass'])){
518         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;   else $posix   = $empty;
519         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;    else $mail    = $empty;
520         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;   else $samba   = $empty;
521         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;    else $appl    = $empty;
522         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;   else $phone   = $empty;
523         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;     else $enviro  = $empty;
524       }else{
525         $posix=$mail=$samba=$appl=$phone=$empty;
526       }
528       $title = "title='dn:&nbsp;".@LDAP::fix($val['dn'])."'";
530       if(!isset($val['description'][0])){
531         $desc = "";
532       }else{
533         $desc = " - [ ".$val['description'][0]." ]";
534       }      
535       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
536       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
537       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone), "attach" => "style='width:136px;'");  
538       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'");
539       
540       $divlist->AddEntry(array($field1,$field2,$field3,$field4));    
541     }
543     /* Show main page */
544     $smarty->assign("grouplisthead", $listhead);
545     $smarty->assign("grouplist", $divlist->DrawList());
546     $smarty->assign("search_image", get_template_path('images/search.png'));
547     $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
548     $smarty->assign("tree_image", get_template_path('images/tree.png'));
549     $smarty->assign("infoimage", get_template_path('images/info.png'));
550     $smarty->assign("launchimage", get_template_path('images/launch.png'));
551     $smarty->assign("deplist", $this->config->idepartments);
552     foreach( array("guser", "regex", "primarygroups", "mailgroups","appgroups", "sambagroups", "functionalgroups", "subsearch") as $type){
553       $smarty->assign("$type", $groupfilter[$type]);
554     }
556     /* Extend if we are not using javascript */
557     $smarty->assign("apply", apply_filter());
558     $smarty->assign("alphabet", generate_alphabet());
559     $smarty->assign("hint", print_sizelimit_warning());
560     if (isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
561       $smarty->assign("showprimary", "");
562     } else {
563       $smarty->assign("showprimary", "true");
564     }
566     return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
567   }
569   function reload($CreatePosixsList=false)
570   {
571     /* Get config */
572     $groupfilter= get_global('groupfilter');
574     /* Set base for all searches */
575     $base= $_SESSION['CurrentMainBase'];
577     /* Regex filter? */
578     if ($groupfilter['regex'] != ""){
579       $regex= $groupfilter['regex'];
580     } else {
581       $regex= "*";
582     }
584     /* User filter? */
585     $filter= "(objectclass=posixGroup)";
586     $error= "";
587     $error2= "";
588     $this->grouplist= array();
590     /* What are primary groups? */
591     $primaries= array();
592     $ldap= $this->config->get_ldap_link();
593     if (!isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
594       $ldap->cd($base);
595       $ldap->search("(&(uid=$regex)(!(uid=*$))(objectClass=posixAccount)(gidNumber=*))", array("gidNumber", "cn"));
596       show_ldap_error($ldap->get_error());
597       while ($attrs= $ldap->fetch()){
598         $primaries[$attrs['gidNumber'][0]]= $attrs['cn'][0];
599       }
600     }
602     /* Set filter depending on selection */
603     $sfilter= "";
604     if ($groupfilter['appgroups'] == "checked"){
605       $filter.= "(objectClass=gosaApplicationGroup)";
606     }
607     if ($this->config->current['SAMBAVERSION'] == 3){
608       if ($groupfilter['primarygroups'] != "checked"){
609         $sfilter= "(objectClass=sambaGroupMapping)";
610       } elseif ($groupfilter['sambagroups'] == "checked"){
611         $filter.= "(objectClass=sambaGroupMapping)";
612       }
613     }
615     if ($groupfilter['mailgroups'] == "checked"){
616       $filter.= "(objectClass=gosaMailAccount)";
617     }
618     $functional= array();
619     $ldap->cd(get_groups_ou().$base);
620     $ldap->set_size_limit($_SESSION['size_limit']);
621     $ldap->search("(&(cn=$regex)(objectClass=posixGroup)(!(|(objectClass=gosaMailAccount)(objectClass=gosaApplicationGroup)$sfilter)))", array("cn", "gidNumber", "description"));
622     $error2= $ldap->error;
623     while ($attrs= $ldap->fetch()){
624       if (!isset($primaries[$attrs['gidNumber'][0]])){
625         $functional[$attrs['gidNumber'][0]]= $attrs['gidNumber'][0];
626       }
627     }
629     /*
630      * We also need to search for the departments
631      * So we are able to navigate like in konquerer
632      */
634     /* Get all departments within this subtree */
635     $deps= get_list("(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
636         $base, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
638     $this->departments = array();
639     foreach($deps as $value){
640       if(isset($value['description'][0])){
641         $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
642       }else{
643         $this->departments[$value['dn']]= get_sub_department($value['dn']);
644       }
645     }
646     natcasesort($this->departments);
647     /*  Ende department generation
648      */
650     /* Generate grouplist */
651     if ($filter != ""){
652       $filter= "(&(cn=$regex)(objectClass=posixGroup)(|$filter))";
653       if ($groupfilter['guser'] != ""){
654         $filter= "(&(|(memberUID=" . $groupfilter['guser'] . ")(cn=" . $groupfilter['guser'] . "))$filter)";
655       }
656     }
658     /* Depending on $CreatePosixsList we have to create different lists */
660     if ($groupfilter['subsearch'] == "checked"){
661       $res= get_list($filter, $this->ui->subtreeACL, $base, array("cn", "description", "gidNumber"),
662                      GL_SIZELIMIT);
663     } else {
664       $base= get_groups_ou().$base;
665       $res= get_list($filter, $this->ui->subtreeACL, $base, array("cn", "description", "gidNumber"),
666                      GL_SIZELIMIT);
667     }
668     if (preg_match("/size limit/i", $error) || preg_match("/size limit/i", $error2)){
669       $_SESSION['limit_exceeded']= TRUE;
670     }
672     foreach ($res as $value){
673       if ($groupfilter['functionalgroups'] != "checked" && isset($functional[$value['gidNumber'][0]])){
674         continue;
675       }
676       if ($groupfilter['primarygroups'] == "checked"){
677         $this->grouplist[$value['gidNumber'][0]]= $value;
678       } else {
679         if (!isset($primaries[$value['gidNumber'][0]])){
680           $this->grouplist[$value['gidNumber'][0]]= $value;
681         }
682       }
683     }
685     $tmp=array();
687     /* Create result for group management listbox*/
688     foreach($this->grouplist as $tkey => $val ){
689       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
690     }
691     ksort($tmp);
692     $this->grouplist=array();
693     foreach($tmp as $val){
694       $this->grouplist[]=$val;
695     }
696     reset ($this->grouplist);
697   }
699   function remove_from_parent()
700   {
701     /* Optionally execute a command after we're done */
702     $this->postremove();
703   }
708   /* Perform copy & paste requests
709      If copy&paste is in progress this returns a dialog to fix required attributes 
710    */ 
711   function copyPasteHandling($s_action,$s_entry)
712   {
713     /* Paste copied/cutted object in here
714      */
715     if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
716       $this->CopyPasteHandler->save_object();
717       $this->CopyPasteHandler->SetVar("base",$_SESSION['CurrentMainBase']);
718       if($str = $this->CopyPasteHandler->execute()){
719         return( $str);
720       };
721       /* Ensure that the new object is shown in the list now */
722       $this->relaod();
723     }
726     /* Copy current object to CopyHandler
727      */
728     if($s_action == "copy"){
729       $this->CopyPasteHandler->Clear();
731       $dn     = $this->grouplist[trim($s_entry)]['dn'];
732       $acl    = get_permissions ($dn, $this->ui->subtreeACL);
734       $obj    = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
735       $objNew = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], "new");
736       $obj->set_acl($acl);
737       $objNew->set_acl($acl);
738       $this->CopyPasteHandler->Copy($obj,$objNew);
739     }
742     /* Copy current object to CopyHandler
743      */
744     if($s_action == "cut"){
745       $this->CopyPasteHandler->Clear();
746       $dn = $this->grouplist[trim($s_entry)]['dn'];
747       $acl= get_permissions ($dn, $this->ui->subtreeACL);
749       $obj= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
750       $obj->set_acl($acl);
752       $this->CopyPasteHandler->Cut($obj);
753     }
754   }
756   /* Save data to object */
757   function save_object()
758   {
759   }
762   /* Check values */
763   function check()
764   {
765   }
768   /* Save to LDAP */
769   function save()
770   {
771     /* Optionally execute a command after we're done */
772     $this->postcreate();
773   }
775   function adapt_from_template($dn)
776   {
777   }
779   function password_change_needed()
780   {
781   }
783   function show_header($button_text, $text, $disabled= FALSE)
784   {
785   }
787   function remove_lock()
788   {
789     if (isset($this->grouptab->dn)){
790       del_lock ($this->grouptab->dn);
791     }
792   }
796 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
797 ?>