Code

Fixed layout
[gosa.git] / plugins / admin / ogroups / class_ogroupManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2004 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_ogroups.inc";
22 class ogroupManagement extends plugin
23 {
24   /* Definitions */
25   var $plHeadline= "Object groups";
26   var $plDescription= "This does something";
28   /* attribute list for save action */
29   var $attributes= array();
30   var $objectclasses= array();
31   var $obtypes= array();
32   var $ogroup;
34   function ogroupManagement ($config, $dn= NULL)
35   {
36     /* Include config object */
37     $this->config= $config;
38     $this->ui= get_userinfo();
40     /* Fill translation array */
41     $this->obtypes= array(      "posixAccount" => _("UNIX accounts"),
42         "posixGroup" => _("Groups"),
43         "gosaDepartment" => _("Departments"),
44         "gosaApplication" => _("Applications"),
45         "goServer" => _("Servers"),
46         "gotoTerminal" => _("Thin Clients"),
47         "gotoWorkstation" => _("Workstations"),
48         "goFonHardware" => _("Phone"),
49         "gotoPrinter" => _("Printer"));
50     asort($this->obtypes);
52     /* Get global filter config */
53     if (!is_global("ogroupfilter")){
54       $ui= get_userinfo();
55       $base= get_base_from_people($ui->dn);
56       $ogroupfilter= array(     "usergroups" => "checked",
57           "groupgroups" => "checked",
58           "appgroups" => "checked",
59           "depgroups" => "checked",
60           "servergroups" => "checked",
61           "wsgroups" => "checked",
62           "prtgroups" => "checked",
63           "tcgroups" => "checked",
64           "fongroups" => "checked",
65           "depselect" => $base,
66           "regex" => "*");
67       register_global("ogroupfilter", $ogroupfilter);
68     }
69   }
71   function execute()
72   {
73     /* Prepare template */
74     $smarty= get_smarty();
76     $ogroupfilter= get_global("ogroupfilter");
77     $s_action   = "";
78     $s_entry    = "";
80     foreach( array("depselect", "regex") as $type){
81       if (isset($_POST[$type])){
82         $ogroupfilter[$type]= $_POST[$type];
83       }
84     }
85     if (isset($_POST['regex'])){
86       foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
87             "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups") as $type){
89         if (isset($_POST[$type])) {
90           $ogroupfilter[$type]= "checked";
91         } else {
92           $ogroupfilter[$type]= "";
93         }
94       }
95     }
96     if (isset($_GET['search'])){
97       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
98       if ($s == "**"){
99         $s= "*";
100       }
101       $ogroupfilter['regex']= $s;
102     }
104     /* Test Posts */
105     foreach($_POST as $key => $val){
106       // Post for delete
107       if(preg_match("/group_del.*/",$key)){
108         $s_action = "del";
109         $s_entry  = preg_replace("/group_".$s_action."_/i","",$key);
110         // Post for edit
111       }elseif(preg_match("/group_edit_.*/",$key)){
112         $s_action="edit";
113         $s_entry  = preg_replace("/group_".$s_action."_/i","",$key);
114         // Post for new
115       }elseif(preg_match("/dep_back.*/i",$key)){
116         $s_action="back";
117       }elseif(preg_match("/group_new.*/",$key)){
118         $s_action="new";
119       }elseif(preg_match("/dep_home.*/i",$key)){
120         $s_action="home";
121       }elseif(preg_match("/group_tplnew.*/i",$key)){
122         $s_action="new_tpl";
123       }elseif(preg_match("/group_chgpw.*/i",$key)){
124         $s_action="change_pw";
125         $s_entry  = preg_replace("/group_chgpw_/i","",$key);
126       }elseif(preg_match("/dep_root.*/i",$key)){
127         $s_action="root";
128       }
129     }
130     $s_entry  = preg_replace("/_.$/","",$s_entry);
132     /* Department changed? */
133     if(isset($_POST['depselect']) && $_POST['depselect']){
134       $ogroupfilter['depselect']= $_POST['depselect'];
135     }
137     /* Start for New List Managment */
138     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
139       $s_action="open";
140       $s_entry = base64_decode($_GET['dep_id']);
141       $ogroupfilter['depselect']= "".$this->config->departments[trim($s_entry)];
142     }
144     /* If Backbutton is Posted */
145     if($s_action=="back"){
146       $base_back          = preg_replace("/^[^,]+,/","",$ogroupfilter['depselect']);
147       $base_back          = convert_department_dn($base_back);
149       if(isset($this->config->departments[trim($base_back)])){
150         $ogroupfilter['depselect']= $this->config->departments[trim($base_back)];
151       }else{
152         $ogroupfilter['depselect']= $this->config->departments["/"];
153       }
154       register_global("ogroupfilter", $ogroupfilter);
155     }
157     /* Homebutton is posted */
158     if($s_action=="home"){
159       $ogroupfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
160       $ogroupfilter['depselect']=(preg_replace("/^[^,]+,/","",$ogroupfilter['depselect']));
161     }
163     /* root posted */ 
164     if($s_action=="root"){
165       $ogroupfilter['depselect']=($this->config->current['BASE']);
166     }
168     // Edit if
169     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
170       $s_action ="edit";
171       $s_entry  = $_GET['id'];
172     }
174     register_global("ogroupfilter", $ogroupfilter);
176     $this->reload();
178     /* Check for exeeded sizelimit */
179     if (($message= check_sizelimit()) != ""){
180       return($message);
181     }
183     /* New group? */
184     if ($s_action=="new"){
186       /* By default we set 'dn' to 'new', all relevant plugins will
187          react on this. */
188       $this->dn= "new";
190       /* Create new usertab object */
191       $this->ogroup= new ogrouptabs($this->config,
192           $this->config->data['TABS']['OGROUPTABS'], $this->dn);
193       $this->ogroup->set_acl(array(':all'));
194     }
196     if ($s_action=="del"){
198       /* Get 'dn' from posted 'uid' */
199       $this->dn= $this->ogrouplist[$s_entry]['dn'];
201       /* Load permissions for selected 'dn' and check if
202          we're allowed to remove this 'dn' */
203       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
204       $this->acl= get_module_permission($acl, "ogroup", $this->dn);
205       if (chkacl($this->acl, "delete") == ""){
207         /* Check locking, save current plugin in 'back_plugin', so
208            the dialog knows where to return. */
209         if (($user= get_lock($this->dn)) != ""){
210           return(gen_locked_message ($user, $this->dn));
211         }
213         /* Lock the current entry, so nobody will edit it during deletion */
214         add_lock ($this->dn, $this->ui->dn);
215         $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), $this->dn));
216         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
217       } else {
219         /* Obviously the user isn't allowed to delete. Show message and
220            clean session. */
221         print_red (_("You are not allowed to delete this object group!"));
222       }
223     }
225     /* Confirmation for deletion has been passed. Group should be deleted. */
226     if (isset($_POST['delete_group_confirm'])){
228       /* Some nice guy may send this as POST, so we've to check
229          for the permissions again. */
230       if (chkacl($this->acl, "delete") == ""){
232         /* Delete request is permitted, perform LDAP action */
233         $this->ogroup= new ogrouptabs($this->config,
234             $this->config->data['TABS']['OGROUPTABS'], $this->dn);
235         $this->ogroup->set_acl(array($this->acl));
236         $this->ogroup->delete ();
237         gosa_log ("Object group'".$this->dn."' has been removed");
238         unset ($this->ogroup);
239         $this->ogroup= NULL;
241         /* Group list has changed, reload it. */
242         $this->reload ();
243       } else {
245         /* Normally this shouldn't be reached, send some extra
246            logs to notify the administrator */
247         print_red (_("You are not allowed to delete this object group!"));
248         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
249       }
251       /* Remove lock file after successfull deletion */
252       del_lock ($this->dn);
253       unset($_SESSION['objectinfo']);
254     }
257     /* Delete group canceled? */
258     if (isset($_POST['delete_cancel'])){
259       del_lock ($this->dn);
260       unset($_SESSION['objectinfo']);
261     }
263     if ($s_action=="edit"){
265       /* Get 'dn' from posted 'uid', must be unique */
266       $this->dn= $this->ogrouplist[$s_entry]['dn'];
268       /* Check locking, save current plugin in 'back_plugin', so
269          the dialog knows where to return. */
270       if (($user= get_lock($this->dn)) != ""){
271         return(gen_locked_message ($user, $this->dn));
272       }
274       /* Lock the current entry, so everyone will get the
275          above dialog */
276       add_lock ($this->dn, $this->ui->dn);
278       /* Set up the users ACL's for this 'dn' */
279       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
281       /* Register grouptab to trigger edit dialog */
282       $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],
283           $this->dn);
284       $this->ogroup->set_acl($acl);
285       $_SESSION['objectinfo']= $this->dn;
286     }
288     /* Finish button has been pressed */
289     if (isset($_POST['edit_finish'])){
291       /* Check tabs, will feed message array */
292       $message= $this->ogroup->check();
294       /* Save, or display error message? */
295       if (count($message) == 0){
297         /* Save user data to ldap */
298         $this->ogroup->save();
299         gosa_log ("Object group'".$this->dn."' has been saved");
301         /* Group has been saved successfully, remove lock from
302            LDAP. */
303         if ($this->dn != "new"){
304           del_lock ($this->dn);
305         }
307         /* There's no page reload so we have to read new users at
308            this point. */
309         $this->reload ();
310         unset ($this->ogroup);
311         $this->ogroup= NULL;
312         unset ($_SESSION['objectinfo']);
314       } else {
315         /* Ok. There seem to be errors regarding to the tab data,
316            show message and continue as usual. */
317         show_errors($message);
318       }
319     }
321     /* Cancel dialogs */
322     if (isset($_POST['edit_cancel'])){
323       del_lock ($this->ogroup->dn);
324       unset ($this->ogroup);
325       $this->ogroup= NULL;
326       unset($_SESSION['objectinfo']);
327     }
329     /* Show dialog if object is present */
330     if ($this->ogroup){
331       $display= $this->ogroup->execute();
333       /* Don't show buttons if tab dialog requests this */
334       if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
335         $display.= "<p style=\"text-align:right\">\n";
336         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
337         $display.= "&nbsp;\n";
338         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
339         $display.= "</p>";
340       }
341       return ($display);
342     }
344     /* Prepare departments */
345     $options= "";
346     foreach ($this->config->idepartments as $key => $value){
347             if ($ogroupfilter['depselect'] == $key){
348                     $options.= "<option selected value='$key'>$value</option>";
349             } else {
350                     $options.= "<option value='$key'>$value</option>";
351             }
352     }
354     // Managment
355     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
356       " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
357       " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."'
358 name='dep_root' alt='"._("Root")."'>&nbsp;".
359       " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."'
360  alt='"._("Home")."' name='dep_home'>&nbsp;".
361       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
362       " <input type='image' align='middle' src='images/list_new_ogroup.png' title='"._("Create new object group")."' alt='"._("new")."' name='group_new'>".
363       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
364       _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
365       " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
366       "</div>";
369     $actions = "<input type='image' src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
370     $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
372     // Defining Links
373     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
375     // image Buttons
376     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
377     $userimg  = "<img src='images/select_groups.png' alt='User'    title='%s'>";
379     // Extension images
380     $mailimg  = "<img src='images/mailto.png'             alt='M'  title='"._("Mail")   ."'>";
382     // Space
383     $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
385     // List Setup
386     $divlist = new divlist("ogroubstab");
387     $divlist->SetHeader(array(
388           array("string" => "&nbsp;","attach"=>"style='width:20px;'"),
389           array("string" => _("Name of object groups")." / "._("Departments")),
390           array("string" => _("Properties") ,"attach"=>"style='width:50px;'"),
391           array("string" => _("Actions")    ,"attach"=>"style='width:50px;border:none;'")
392           ));
395     $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
396     $divlist->SetEntriesPerPage(20);
398     foreach($this->departments as $key=> $val){
400       if(!isset($this->config->departments[trim($key)])){
401         $this->config->departments[trim($key)]="";
402       }
404       $non_empty="";
405       $keys= str_replace("/","\/",$key);
406       foreach($this->config->departments as $keyd=>$vald ){
407         if(preg_match("/".$keys."\/.*/",$keyd)){
408           $non_empty="full";
409         }
410       }
414       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='"._("Department")."'>");
415       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
416       $field3 = array("string" => "&nbsp;");
417       $field4 = array("string" => "&nbsp;","attach"=>"style='text-align:right;border:none'");
419       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
420     }
422     // Assigning ogroups 
423     foreach($this->ogrouplist as $key => $val){
425       if(isset($val['mail'])){
426         $mail = $mailimg;
427       }else{
428         $mail = $empty;
429       }
431       $title = "title='dn : ".$val['dn']."'";
433       if(!isset($val['description'][0])){
434         $desc = "";
435       }else{
436         $desc = " - [ ".$val['description'][0]." ]";
437       }
438       $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">");
439       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)),"attach"=>$title);
440       $field3 = array("string" => $this->convert_list($val)."&nbsp;".$mail);
441       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions),"attach"=>"style='text-align:right;border:none'");
443       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
444     }
451     /* Show main page */
452     $smarty->assign("search_image", get_template_path('images/search.png'));
453     $smarty->assign("tree_image", get_template_path('images/tree.png'));
454     $smarty->assign("infoimage", get_template_path('images/info.png'));
455     $smarty->assign("launchimage", get_template_path('images/launch.png'));
456     $smarty->assign("deplist", $this->config->idepartments);
458     $smarty->assign("groupshead", $listhead);
459     $smarty->assign("groups", $divlist->DrawList());
461     foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
462           "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups", "regex", "depselect") as $type){
463       $smarty->assign("$type", $ogroupfilter[$type]);
464     }
466     $smarty->assign("hint", print_sizelimit_warning());
467     $smarty->assign("apply", apply_filter());
468     $smarty->assign("alphabet", generate_alphabet());
469     return ($smarty->fetch (get_template_path('headpage.tpl', TRUE)));
470   }
473   function convert_list($input)
474   {
475     $temp= "";
478     $conv= array(   
479         "U" => array("select_user.png",_("User")),
480         "G" => array("select_groups.png",_("Group")),
481         "A" => array("select_application.png",_("Application")),
482         "D" => array("select_department.png",_("Department")),
483         "S" => array("select_server.png",_("Server")),
484         "F" => array("select_phone.png",_("Phone")),
485         "W" => array("select_workstation.png",_("Workstation")),
486         "T" => array("select_terminal.png",_("Terminal")),
487         "P" => array("select_printer.png",_("Printer")));
489     /* Assemble picture */
490     $type= $input['gosaGroupObjects'][0];
491     $type= preg_replace("/[^A-Z]/i","",$type);
492     if (isset($type[0])){
493       $p1['pic']= $conv[$type[0]][0];
494       $p1['tit']= $conv[$type[0]][1];
495       $p1['alt']= $type[0];
496     } else {
497       $p1['pic']= "empty.png";
498       $p1['tit']= "";
499       $p1['alt']= "";
500     }
501     if (isset($type[1])){
502       $p2['pic']= $conv[$type[1]][0];
503       $p2['alt']= $type[1];
504       $p2['tit']= $conv[$type[1]][1];
505     } else {
506       $p2['pic']= "empty.png";
507       $p2['alt']= "";
508       $p2['tit']= "";
509     }
510     $temp = "<img src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
511     $temp.= "<img src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
512     return ($temp);
513   }
516   function reload()
517   {
518     /* Get config */
519     $ogroupfilter= get_global('ogroupfilter');
521     /* Set base for all searches */
522     $base= $ogroupfilter['depselect'];
524     /* Regex filter? */
525     if ($ogroupfilter['regex'] != ""){
526       $regex= $ogroupfilter['regex'];
527     } else {
528       $regex= "*";
529     }
531     /* User filter? */
532     $this->oogrouplist= array();
534     /* Generate oogrouplist filter */
535     $filter= "";
537     if ($ogroupfilter['usergroups'] == "checked"){
538       $filter.= "(gosaGroupObjects=*U*)";
539     }
540     if ($ogroupfilter['groupgroups'] == "checked"){
541       $filter.= "(gosaGroupObjects=*G*)";
542     }
543     if ($ogroupfilter['appgroups'] == "checked"){
544       $filter.= "(gosaGroupObjects=*A*)";
545     }
546     if ($ogroupfilter['depgroups'] == "checked"){
547       $filter.= "(gosaGroupObjects=*D*)";
548     }
549     if ($ogroupfilter['servergroups'] == "checked"){
550       $filter.= "(gosaGroupObjects=*S*)";
551     }
552     if ($ogroupfilter['wsgroups'] == "checked"){
553       $filter.= "(gosaGroupObjects=*W*)";
554     }
555     if ($ogroupfilter['prtgroups'] == "checked"){
556       $filter.= "(gosaGroupObjects=*P*)";
557     }
558     if ($ogroupfilter['tcgroups'] == "checked"){
559       $filter.= "(gosaGroupObjects=*T*)";
560     }
561     if ($ogroupfilter['fongroups'] == "checked"){
562       $filter.= "(gosaGroupObjects=*F*)";
563     }
565     if ($filter != ""){
566       $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames)(|$filter))";
567     } else {
568       $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames))";
569     }
570     $res= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("*"), TRUE);
571     $this->ogrouplist= $res;
572     ksort ($this->ogrouplist);
573     reset ($this->ogrouplist);
576     /* NEW LIST MANAGMENT
577      * We also need to search for the departments
578      * So we are able to navigate like in konquerer
579      */
580     $base2 = preg_replace("/ou=people,/i","",$base);
582     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
583                               TRUE, $base2, array("ou", "description"), TRUE);
585    
587     $this->departments= array();
588     $tmp = array();
589     foreach ($res3 as $value){
590       $tmp[strtolower($value['dn']).$value['dn']]=$value;
591     }
592     ksort($tmp);
593     foreach($tmp as $value){
594       if($value["description"][0]!=".."){
595         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
596       }else{
597         $this->departments[$value['dn']]=$value["description"][0];
598       }
599     }
600     /* END NEW LIST MANAGMENT
601      */
603     $tmp=array();
604     foreach($this->ogrouplist as $tkey => $val ){
605       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
606     }
607     ksort($tmp);
608     $this->ogrouplist=array();
609     foreach($tmp as $val){
610       $this->ogrouplist[]=$val;
611     }
612     reset ($this->ogrouplist);
616   }
620 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
621 ?>