Code

Fixed icons of member objects in object group overview.
[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   var $CopyPasteHandler = NULL;
35   var $DivListOGroup    = NULL;
37   function ogroupManagement ($config, $dn= NULL)
38   {
39     /* Include config object */
40     $this->config= $config;
41     $this->ui= get_userinfo();
43     /* Copy & Paste enabled ?
44      */
45     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE'] ))){
46       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
47     }
49     /* Div lsit management */
50     $this->DivListOGroup = new divListOGroup($this->config,$this);
51   }
53   function execute()
54   {
55     /* Call parent execute */
56     plugin::execute();
58     /****************
59       Variable intialisation && Check posts for commands  
60      ****************/
62     $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/");
64     $smarty     = get_smarty();
65     $s_action   = "";
66     $s_entry    = "";
68     /* Test Posts */
69     foreach($_POST as $key => $val){
70       // Post for delete
71       if(preg_match("/^group_del.*/",$key)){
72         $s_action = "del";
73         $s_entry  = preg_replace("/^group_".$s_action."_/i","",$key);
74         // Post for edit
75       }elseif(preg_match("/^group_edit_.*/",$key)){
76         $s_action="edit";
77         $s_entry  = preg_replace("/^group_".$s_action."_/i","",$key);
78         // Post for new
79       }elseif(preg_match("/^group_new.*/",$key)){
80         $s_action="new";
81       }elseif(preg_match("/^group_tplnew.*/i",$key)){
82         $s_action="new_tpl";
83       }elseif(preg_match("/^group_chgpw.*/i",$key)){
84         $s_action="change_pw";
85         $s_entry  = preg_replace("/group_chgpw_/i","",$key);
86       }elseif(preg_match("/^editPaste.*/i",$key)){
87         $s_action="editPaste";
88       }elseif(preg_match("/^copy_.*/",$key)){
89         $s_action="copy";
90         $s_entry  = preg_replace("/^copy_/i","",$key);
91       }elseif(preg_match("/^cut_.*/",$key)){
92         $s_action="cut";
93         $s_entry  = preg_replace("/^cut_/i","",$key);
94       }elseif(preg_match("/_group_edit_/",$key)){
95         $type = preg_replace("/_group_edit_.*$/","",$key);
96         $s_action="edit";
97         $s_entry  = preg_replace("/".$type."_group_edit_/i","",$key);
98         $_POST['arg'] = $type;
99       }
100     }
101     $s_entry  = preg_replace("/_.$/","",$s_entry);
103     // Edit if
104     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
105       $s_action ="edit";
106       $s_entry  = $_GET['id'];
107     }
110     /****************
111       Copy & Paste handling 
112      ****************/
114     /* Display the copy & paste dialog, if it is currently open */
115     $ret = $this->copyPasteHandling($s_action,$s_entry);
116     if($ret){
117       return($ret);
118     }
120     /****************
121       Create a new object group 
122      ****************/
124     /* New group? */
125     if ($s_action=="new"){
127       /* By default we set 'dn' to 'new', all relevant plugins will
128          react on this. */
129       $this->dn= "new";
131       /* Create new usertab object */
132       $this->ogroup= new ogrouptabs($this->config,$this->config->data['TABS']['OGROUPTABS'], $this->dn,"ogroups");
133       $this->ogroup->set_acl_base($this->DivListOGroup->selectedBase);
134     }
137     /****************
138       Delete object group
139      ****************/
141     if ($s_action=="del"){
143       /* Get 'dn' from posted 'uid' */
144       $this->dn= $this->ogrouplist[$s_entry]['dn'];
146       /* Load permissions for selected 'dn' and check if
147          we're allowed to remove this 'dn' */
148       $acl = $this->ui->get_permissions($this->dn,"ogroup");
149       if(preg_match("/d/",$acl)){
151         /* Check locking, save current plugin in 'back_plugin', so
152            the dialog knows where to return. */
153         if (($user= get_lock($this->dn)) != ""){
154           return(gen_locked_message ($user, $this->dn));
155         }
157         /* Lock the current entry, so nobody will edit it during deletion */
158         add_lock ($this->dn, $this->ui->dn);
159         $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), @LDAP::fix($this->dn)));
160         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
161       } else {
163         /* Obviously the user isn't allowed to delete. Show message and
164            clean session. */
165         print_red (_("You are not allowed to delete this object group!"));
166       }
167     }
170     /****************
171       Delete confirmed 
172      ****************/
174     /* Confirmation for deletion has been passed. Group should be deleted. */
175     if (isset($_POST['delete_group_confirm'])){
177       /* Some nice guy may send this as POST, so we've to check
178          for the permissions again. */
179       $acl = $this->ui->get_permissions($this->dn,"groups");
180       if(preg_match("/d/",$acl)){
182         /* Delete request is permitted, perform LDAP action */
183         $this->ogroup= new ogrouptabs($this->config,
184             $this->config->data['TABS']['OGROUPTABS'], $this->dn);
185         $this->ogroup->set_acl(array($this->acl));
186         $this->ogroup->delete ();
187         gosa_log ("Object group'".$this->dn."' has been removed");
188         unset ($this->ogroup);
189         $this->ogroup= NULL;
190       } else {
192         /* Normally this shouldn't be reached, send some extra
193            logs to notify the administrator */
194         print_red (_("You are not allowed to delete this object group!"));
195         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
196       }
198       /* Remove lock file after successfull deletion */
199       del_lock ($this->dn);
200       unset($_SESSION['objectinfo']);
201     }
204     /****************
205       Delete object group Canceled
206      ****************/
208     /* Delete group canceled? */
209     if (isset($_POST['delete_cancel'])){
210       del_lock ($this->dn);
211       unset($_SESSION['objectinfo']);
212     }
215     /****************
216       Edit group
217      ****************/
219     if (($s_action=="edit") && (! isset($this->ogroup->config)) ){
221       /* Get 'dn' from posted 'uid', must be unique */
222       $this->dn= $this->ogrouplist[$s_entry]['dn'];
224       /* Check locking, save current plugin in 'back_plugin', so
225          the dialog knows where to return. */
226       if (($user= get_lock($this->dn)) != ""){
227         return(gen_locked_message ($user, $this->dn));
228       }
230       /* Lock the current entry, so everyone will get the
231          above dialog */
232       add_lock ($this->dn, $this->ui->dn);
234       /* Register grouptab to trigger edit dialog */
235       $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $this->dn, "ogroups");
236       $this->ogroup->set_acl_base($this->dn);
237       $_SESSION['objectinfo']= $this->dn;
238     }
241     /****************
242       Edit finished save 
243      ****************/
245     /* Finish button has been pressed */
246     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->ogroup->config)) ){
248       /* Check tabs, will feed message array */
249       $message= $this->ogroup->check();
251       /* Save, or display error message? */
252       if (count($message) == 0){
254         /* Save user data to ldap */
255         $this->ogroup->save();
256         gosa_log ("Object group'".$this->dn."' has been saved");
258         if (!isset($_POST['edit_apply'])){
259           /* Group has been saved successfully, remove lock from
260              LDAP. */
261           if ($this->dn != "new"){
262             del_lock ($this->dn);
263           }
265           unset ($this->ogroup);
266           $this->ogroup= NULL;
267           unset ($_SESSION['objectinfo']);
268         }
269       } else {
270         /* Ok. There seem to be errors regarding to the tab data,
271            show message and continue as usual. */
272         show_errors($message);
273       }
274     }
277     /****************
278       Cancel edit object group
279      ****************/
281     /* Cancel dialogs */
282     if (isset($_POST['edit_cancel'])){
283       del_lock ($this->ogroup->dn);
284       unset ($this->ogroup);
285       $this->ogroup= NULL;
286       unset($_SESSION['objectinfo']);
287     }
290     /****************
291       Display open dialogs 
292      ****************/
294     /* Show dialog if object is present */
295     if (isset($this->ogroup->config)){
296       $display= $this->ogroup->execute();
298       /* Don't show buttons if tab dialog requests this */
299       if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
300         $display.= "<p style=\"text-align:right\">\n";
301         $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
302         $display.= "&nbsp;\n";
303         if ($this->dn != "new"){
304           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
305           $display.= "&nbsp;\n";
306         }
307         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
308         $display.= "</p>";
309       }
310       return ($display);
311     }
314     /****************
315       Display list 
316      ****************/
318     /* Check if there is a snapshot dialog open */
319     $base = $this->DivListOGroup->selectedBase;
320     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
321       return($str);
322     }
324     /* Display dialog with group list */
325     $this->DivListOGroup->parent = $this;
326     $this->DivListOGroup->execute();
328     /* Add departments if subsearch is disabled */
329     if(!$this->DivListOGroup->SubSearch){
330       $this->DivListOGroup->AddDepartments($this->DivListOGroup->selectedBase,4);
331     }
332     $this->reload ();
333     $this->DivListOGroup->setEntries($this->ogrouplist);
334     return($this->DivListOGroup->Draw());
335   }
338   /* Return departments, that will be included within snapshot detection */
339   function get_used_snapshot_bases()
340   {
341     return(array(get_groups_ou().$this->DivListOGroup->selectedBase));
342   }
344   
346   function convert_list($input)
347   {
348     $temp= "";
350     $conv= array(   
351         "U" => array("select_user.png"        ,_("User")        , "ogroup"),
352         "G" => array("select_groups.png"      ,_("Group")       , "ogroup"),
353         "A" => array("select_application.png" ,_("Application") , "ogroup"),
354         "D" => array("select_department.png"  ,_("Department")  , "ogroup"),
355         "S" => array("select_server.png"      ,_("Server")      , "ogroup"),
356         "F" => array("select_phone.png"       ,_("Phone")       , "phonequeue"),
357         "W" => array("select_workstation.png" ,_("Workstation") , "workstartup"),
358         "T" => array("select_terminal.png"    ,_("Terminal")    , "termgroup"),
359         "P" => array("select_printer.png"     ,_("Printer")     , "ogroup"));
361     /* Assemble picture */
362     $type= $input['gosaGroupObjects'][0];
363     $type= preg_replace("/[^A-Z]/i","",$type);
364     if (isset($type[0])){
365       $p1['pic']= $conv[$type[0]][0];
366       $p1['tit']= $conv[$type[0]][1];
367       $p1['alt']= $type[0];
368       $p1['lnk']= $conv[$type[0]][2];
369       $html_object_1 = "<input type='image' name='".$p1['lnk']."_group_edit_%KEY' ";
370     } else {
371       $p1['pic']= "empty.png";
372       $p1['tit']= "";
373       $p1['alt']= "";
374       $p1['lnk']= "";//$conv[$type[0]][2];
375       $html_object_1 = "<img ";
376     }
378     if (isset($type[1])){
379       $p2['pic']= $conv[$type[1]][0];
380       $p2['alt']= $type[1];
381       $p2['tit']= $conv[$type[1]][1];
382       $p2['lnk']= $conv[$type[1]][2];
383       $html_object_2 = "<input type='image' name='".$p2['lnk']."_group_edit_%KEY' ";
384     } else {
385       $p2['pic']= "empty.png";
386       $p2['alt']= "";
387       $p2['tit']= "";
388       $p2['lnk']= ""; //$conv[$type[0]][2];
389       $html_object_2 = "<img ";
390     }
391     
392     $html_object_1 = "<input type='image' ";
393       
394     $temp = $html_object_1." class='center' id='iconA".preg_replace("/_/","",$p1['lnk']."_group_edit_%KEY")."' 
395       src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
396     $temp.= $html_object_2." class='center' id='iconB".preg_replace("/_/","",$p2['lnk']."_group_edit_%KEY")."' 
397       src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
398     return ($temp);
399   }
402   function reload()
403   {
404     /* Set base for all searches && initialise some vars */
405     $this->ogrouplist= array();
406     $base     = $this->DivListOGroup->selectedBase;
407     $filter   = "(gosaGroupObjects=[])";
408     $Regex    = $this->DivListOGroup->Regex;
410     $chk = array(
411         "UserGroups"          => "(gosaGroupObjects=*U*)" ,
412         "GroupGroups"         => "(gosaGroupObjects=*G*)" ,
413         "ApplicationGroups"   => "(gosaGroupObjects=*A*)" ,
414         "DepartmentGroups"    => "(gosaGroupObjects=*D*)" ,
415         "ServerGroups"        => "(gosaGroupObjects=*S*)" ,
416         "WorkstationGroups"   => "(gosaGroupObjects=*W*)" ,
417         "TerminalGroups"      => "(gosaGroupObjects=*T*)" ,
418         "PrinterGroups"       => "(gosaGroupObjects=*P*)" ,
419         "PhoneGroups"         => "(gosaGroupObjects=*F*)" );
420     /* Create filter */ 
421     foreach($chk as $chkBox => $FilterPart){
422       if($this->DivListOGroup->$chkBox){
423         $filter .=  $FilterPart;
424       }
425     }
426     $filter= "(&(cn=$Regex)(objectClass=gosaGroupOfNames)(|$filter))";
428     if($this->DivListOGroup->SubSearch){
429       $res= get_list($filter, "ogroups", $base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH);
430     }else{
431       $res= get_list($filter, "ogroups", get_groups_ou().$base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT );
432     }
434     $this->ogrouplist= $res;
435     ksort ($this->ogrouplist);
436     reset ($this->ogrouplist);
437     $tmp=array();
438     foreach($this->ogrouplist as $tkey => $val ){
439       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
440     }
441     ksort($tmp);
442     $this->ogrouplist=array();
443     foreach($tmp as $val){
444       $this->ogrouplist[]=$val;
445     }
446     reset ($this->ogrouplist);
447   }
450   function copyPasteHandling($s_action,$s_entry)
451   {
452     if($this->CopyPasteHandler){
454       /* Paste copied/cutted object in here
455        */
456       if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
457         $this->CopyPasteHandler->save_object();
458         $this->CopyPasteHandler->SetVar("base", $this->DivListOGroup->selectedBase);
459         return($this->CopyPasteHandler->execute());
460       }
462       /* Copy current object to CopyHandler
463        */
464       if($s_action == "copy"){
465         $this->CopyPasteHandler->Clear();
466         $dn       =   $this->ogrouplist[$s_entry]['dn'];
467         $obj      =   new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
468         $objNew   =   new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], "new");
470         $types_of_tabs = $obj->by_object['ogroup']->gosaGroupObjects;
471         $objNew->by_object['ogroup']->gosaGroupObjects = $types_of_tabs;    
472         $objNew->reload($types_of_tabs);
474         $this->CopyPasteHandler->Copy($obj,$objNew);
475       }
477       /* Copy current object to CopyHandler
478        */
479       if($s_action == "cut"){
480         $this->CopyPasteHandler->Clear();
481         $dn       =   $this->ogrouplist[$s_entry]['dn'];
482         $obj      =   new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'], $dn);
483         $this->CopyPasteHandler->Cut($obj);
484       }
485     }
486   }
489   function save_object()
490   {
491     $this->DivListOGroup->save_object();
492   }
496 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
497 ?>