Code

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