Code

Applied planned layout modifications
[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       $this->reload();
136     }
138     /* Start for New List Managment */
139     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
140       $s_action="open";
141       $s_entry = base64_decode($_GET['dep_id']);
142       $ogroupfilter['depselect']= "".$this->config->departments[trim($s_entry)];
143       $this->reload();
144     }
146     /* If Backbutton is Posted */
147     if($s_action=="back"){
148       $base_back          = preg_replace("/^[^,]+,/","",$ogroupfilter['depselect']);
149       $base_back          = convert_department_dn($base_back);
151       if(isset($this->config->departments[trim($base_back)])){
152         $ogroupfilter['depselect']= $this->config->departments[trim($base_back)];
153       }else{
154         $ogroupfilter['depselect']= $this->config->departments["/"];
155       }
156       register_global("ogroupfilter", $ogroupfilter);
157       $this->reload();
158     }
160     /* Homebutton is posted */
161     if($s_action=="home"){
162       $ogroupfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
163       $ogroupfilter['depselect']=(preg_replace("/^[^,]+,/","",$ogroupfilter['depselect']));
164       $this->reload();
165     }
167     /* root posted */ 
168     if($s_action=="root"){
169       $ogroupfilter['depselect']=($this->config->current['BASE']);
170       $this->reload();
171     }
173     // Edit if
174     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
175       $s_action ="edit";
176       $s_entry  = $_GET['id'];
177     }
179     register_global("ogroupfilter", $ogroupfilter);
181     /* Prepare formular */
182     if (!isset($this->ogroup) &&
183         !isset($_POST['new_group']) &&
184         !isset($_POST['delete_group']) &&
185         !isset($_POST['select_group'])){
186       $this->reload();
187     }
189     /* Check for exeeded sizelimit */
190     if (($message= check_sizelimit()) != ""){
191       return($message);
192     }
194     /* New group? */
195     if ($s_action=="new"){
197       /* By default we set 'dn' to 'new', all relevant plugins will
198          react on this. */
199       $this->dn= "new";
201       /* Create new usertab object */
202       $this->ogroup= new ogrouptabs($this->config,
203           $this->config->data['TABS']['OGROUPTABS'], $this->dn);
204       $this->ogroup->set_acl(array(':all'));
205     }
207     if ($s_action=="del"){
209       /* Get 'dn' from posted 'uid' */
210       $this->dn= $this->ogrouplist[$s_entry]['dn'];
212       /* Load permissions for selected 'dn' and check if
213          we're allowed to remove this 'dn' */
214       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
215       $this->acl= get_module_permission($acl, "ogroup", $this->dn);
216       if (chkacl($this->acl, "delete") == ""){
218         /* Check locking, save current plugin in 'back_plugin', so
219            the dialog knows where to return. */
220         if (($user= get_lock($this->dn)) != ""){
221           return(gen_locked_message ($user, $this->dn));
222         }
224         /* Lock the current entry, so nobody will edit it during deletion */
225         add_lock ($this->dn, $this->ui->dn);
226         $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), $this->dn));
227         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
228       } else {
230         /* Obviously the user isn't allowed to delete. Show message and
231            clean session. */
232         print_red (_("You are not allowed to delete this object group!"));
233       }
234     }
236     /* Confirmation for deletion has been passed. Group should be deleted. */
237     if (isset($_POST['delete_group_confirm'])){
239       /* Some nice guy may send this as POST, so we've to check
240          for the permissions again. */
241       if (chkacl($this->acl, "delete") == ""){
243         /* Delete request is permitted, perform LDAP action */
244         $this->ogroup= new ogrouptabs($this->config,
245             $this->config->data['TABS']['OGROUPTABS'], $this->dn);
246         $this->ogroup->set_acl(array($this->acl));
247         $this->ogroup->delete ();
248         gosa_log ("Object group'".$this->dn."' has been removed");
249         unset ($this->ogroup);
250         $this->ogroup= NULL;
252         /* Group list has changed, reload it. */
253         $this->reload ();
254       } else {
256         /* Normally this shouldn't be reached, send some extra
257            logs to notify the administrator */
258         print_red (_("You are not allowed to delete this object group!"));
259         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
260       }
262       /* Remove lock file after successfull deletion */
263       del_lock ($this->dn);
264       unset($_SESSION['objectinfo']);
265     }
268     /* Delete group canceled? */
269     if (isset($_POST['delete_cancel'])){
270       del_lock ($this->dn);
271       unset($_SESSION['objectinfo']);
272     }
274     if ($s_action=="edit"){
276       /* Get 'dn' from posted 'uid', must be unique */
277       $this->dn= $this->ogrouplist[$s_entry]['dn'];
279       /* Check locking, save current plugin in 'back_plugin', so
280          the dialog knows where to return. */
281       if (($user= get_lock($this->dn)) != ""){
282         return(gen_locked_message ($user, $this->dn));
283       }
285       /* Lock the current entry, so everyone will get the
286          above dialog */
287       add_lock ($this->dn, $this->ui->dn);
289       /* Set up the users ACL's for this 'dn' */
290       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
292       /* Register grouptab to trigger edit dialog */
293       $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],
294           $this->dn);
295       $this->ogroup->set_acl($acl);
296       $_SESSION['objectinfo']= $this->dn;
297     }
299     /* Finish button has been pressed */
300     if (isset($_POST['edit_finish'])){
302       /* Check tabs, will feed message array */
303       $message= $this->ogroup->check();
305       /* Save, or display error message? */
306       if (count($message) == 0){
308         /* Save user data to ldap */
309         $this->ogroup->save();
310         gosa_log ("Object group'".$this->dn."' has been saved");
312         /* Group has been saved successfully, remove lock from
313            LDAP. */
314         if ($this->dn != "new"){
315           del_lock ($this->dn);
316         }
318         /* There's no page reload so we have to read new users at
319            this point. */
320         $this->reload ();
321         unset ($this->ogroup);
322         $this->ogroup= NULL;
323         unset ($_SESSION['objectinfo']);
325       } else {
326         /* Ok. There seem to be errors regarding to the tab data,
327            show message and continue as usual. */
328         show_errors($message);
329       }
330     }
332     /* Cancel dialogs */
333     if (isset($_POST['edit_cancel'])){
334       del_lock ($this->ogroup->dn);
335       unset ($this->ogroup);
336       $this->ogroup= NULL;
337       unset($_SESSION['objectinfo']);
338     }
340     /* Show dialog if object is present */
341     if ($this->ogroup){
342       $display= $this->ogroup->execute();
344       /* Don't show buttons if tab dialog requests this */
345       if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
346         $display.= "<p style=\"text-align:right\">\n";
347         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
348         $display.= "&nbsp;\n";
349         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
350         $display.= "</p>";
351       }
352       return ($display);
353     }
355     /* Prepare departments */
356     $options= "";
357     foreach ($this->config->idepartments as $key => $value){
358             if ($ogroupfilter['depselect'] == $key){
359                     $options.= "<option selected value='$key'>$value</option>";
360             } else {
361                     $options.= "<option value='$key'>$value</option>";
362             }
363     }
365     // Managment
366     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
367       " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
368       " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."'
369 name='dep_root' alt='"._("Root")."'>&nbsp;".
370       " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."'
371  alt='"._("Home")."' name='dep_home'>&nbsp;".
372       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
373       " <input type='image' align='middle' src='images/list_new_ogroup.png' title='"._("Create new object group")."' alt='"._("new")."' name='group_new'>".
374       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
375       _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
376       " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
377       "</div>";
380     $actions = "<input type='image' src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
381     $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
383     // Defining Links
384     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
386     // image Buttons
387     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
388     $userimg  = "<img src='images/select_groups.png' alt='User'    title='%s'>";
390     // Extension images
391     $mailimg  = "<img src='images/mailto.png'             alt='M'  title='"._("Mail")   ."'>";
393     // Space
394     $empty    = "<img src='images/nothing.png' style='width:16px;height:16px;' alt=''>";
396     // List Setup
397     $divlist = new divlist();
398     $divlist->SetHeader(array(
399           array("string" => "&nbsp;","attach"=>"style='width:20px;'"),
400           array("string" => _("Name of object groups")." / "._("Departments")),
401           array("string" => _("Properties") ,"attach"=>"style='width:50px;'"),
402           array("string" => _("Actions")    ,"attach"=>"style='width:50px;border:none;'")
403           ));
406     $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
407     $divlist->SetEntriesPerPage(20);
409     foreach($this->departments as $key=> $val){
411       $field1 = array("string" => "<img src='images/folder.png' alt='"._("Department")."'>");
412       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
413       $field3 = array("string" => "&nbsp;");
414       $field4 = array("string" => "&nbsp;","attach"=>"style='text-align:right;border:none'");
416       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
417     }
419     // Assigning ogroups 
420     foreach($this->ogrouplist as $key => $val){
422       if(isset($val['mail'])){
423         $mail = $mailimg;
424       }else{
425         $mail = $empty;
426       }
428       $title = "title='gid : ".$key." - dn : ".$val['dn']."'";
430       if(!isset($val['description'][0])){
431         $desc = "";
432       }else{
433         $desc = " - [ ".$val['description'][0]." ]";
434       }
435       $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."'>");
436       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)),"attach"=>$title);
437       $field3 = array("string" => $this->convert_list($val)."&nbsp;".$mail);
438       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions),"attach"=>"style='text-align:right;border:none'");
440       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
441     }
448     /* Show main page */
449     $smarty->assign("search_image", get_template_path('images/search.png'));
450     $smarty->assign("tree_image", get_template_path('images/tree.png'));
451     $smarty->assign("infoimage", get_template_path('images/info.png'));
452     $smarty->assign("launchimage", get_template_path('images/launch.png'));
453     $smarty->assign("deplist", $this->config->idepartments);
455     $smarty->assign("groupshead", $listhead);
456     $smarty->assign("groups", $divlist->DrawList());
458     foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
459           "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups", "regex", "depselect") as $type){
460       $smarty->assign("$type", $ogroupfilter[$type]);
461     }
463     $smarty->assign("hint", print_sizelimit_warning());
464     $smarty->assign("apply", apply_filter());
465     $smarty->assign("alphabet", generate_alphabet());
466     return ($smarty->fetch (get_template_path('headpage.tpl', TRUE)));
467   }
470   function convert_list($input)
471   {
472     $temp= "";
475     $conv= array(   "U" => "select_user.png",
476         "G" => "select_groups.png",
477         "A" => "select_application.png",
478         "D" => "select_department.png",
479         "S" => "select_server.png",
480         "F" => "select_phone.png",
481         "W" => "select_workstation.png",
482         "T" => "select_terminal.png",
483         "P" => "select_printer.png");
485     /* Assemble picture */
486     $type= $input['gosaGroupObjects'][0];
487     $type= preg_replace("/[^A-Z]/i","",$type);
488     if (isset($type[0])){
489       $p1['pic']= $conv[$type[0]];
490       $p1['alt']= $type[0];
491     } else {
492       $p1['pic']= "empty.png";
493       $p1['alt']= "";
494     }
495     if (isset($type[1])){
496       $p2['pic']= $conv[$type[1]];
497       $p2['alt']= $type[1];
498     } else {
499       $p2['pic']= "empty.png";
500       $p2['alt']= "";
501     }
502     $temp = "<img src='images/".$p1['pic']."' alt='".$p1['alt']."'>";
503     $temp.= "<img src='images/".$p2['pic']."' alt='".$p2['alt']."'>";
504     return ($temp);
505   }
508   function reload()
509   {
510     /* Get config */
511     $ogroupfilter= get_global('ogroupfilter');
513     /* Set base for all searches */
514     $base= $ogroupfilter['depselect'];
516     /* Regex filter? */
517     if ($ogroupfilter['regex'] != ""){
518       $regex= $ogroupfilter['regex'];
519     } else {
520       $regex= "*";
521     }
523     /* User filter? */
524     $this->oogrouplist= array();
526     /* Generate oogrouplist filter */
527     $filter= "";
529     if ($ogroupfilter['usergroups'] == "checked"){
530       $filter.= "(gosaGroupObjects=*U*)";
531     }
532     if ($ogroupfilter['groupgroups'] == "checked"){
533       $filter.= "(gosaGroupObjects=*G*)";
534     }
535     if ($ogroupfilter['appgroups'] == "checked"){
536       $filter.= "(gosaGroupObjects=*A*)";
537     }
538     if ($ogroupfilter['depgroups'] == "checked"){
539       $filter.= "(gosaGroupObjects=*D*)";
540     }
541     if ($ogroupfilter['servergroups'] == "checked"){
542       $filter.= "(gosaGroupObjects=*S*)";
543     }
544     if ($ogroupfilter['wsgroups'] == "checked"){
545       $filter.= "(gosaGroupObjects=*W*)";
546     }
547     if ($ogroupfilter['prtgroups'] == "checked"){
548       $filter.= "(gosaGroupObjects=*P*)";
549     }
550     if ($ogroupfilter['tcgroups'] == "checked"){
551       $filter.= "(gosaGroupObjects=*T*)";
552     }
553     if ($ogroupfilter['fongroups'] == "checked"){
554       $filter.= "(gosaGroupObjects=*F*)";
555     }
557     if ($filter != ""){
558       $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames)(|$filter))";
559     } else {
560       $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames))";
561     }
562     $res= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("*"), TRUE);
563     $this->ogrouplist= $res;
564     ksort ($this->ogrouplist);
565     reset ($this->ogrouplist);
568     /* NEW LIST MANAGMENT
569      * We also need to search for the departments
570      * So we are able to navigate like in konquerer
571      */
572     $base2 = preg_replace("/ou=people,/i","",$base);
574     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
575                               TRUE, $base2, array("ou", "description"), TRUE);
577     $this->departments= array();
578     foreach ($res3 as $value){
579       if($value["description"][0]!=".."){
580         $this->departments[$value['dn']]= convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
581       }else{
582         $this->departments[$value['dn']]=$value["description"][0];
583       }
584     }
586     /* END NEW LIST MANAGMENT
587      */
592   }
596 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
597 ?>