Code

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