Code

47799858a8de747d4275f5460a6088f32432296c
[gosa.git] / gosa-plugins / dhcp / admin / systems / services / dhcp / class_dhcpAdvanced.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  */
21 class dhcpAdvanced extends plugin
22 {
23     /* Used attributes */
24     var $options= null;
25     var $statements= null;
26     var $show_advanced= FALSE;
27     var $autoStatements= array();
28     var $autoOptions= array();
30     /* attribute list for save action */
31     var $attributes= array();
32     var $objectclasses= array();
33     var $parent;
35     function dhcpAdvanced()
36     {
37         /* This is always an account */
38         $this->initTime = microtime(TRUE);
39         $this->is_account= TRUE;
40         $this->setAutoStatements();
41         $this->setAutoOptions();
43         // Create statistic table entry
44         stats::log('plugin', $class = get_class($this), $category = array($this->acl_category),  $action = 'open',
45                 $amount = 1, $duration = (microtime(TRUE) - $this->initTime));
47     }
49     function execute()
50     {
51         plugin::execute();
53         $acl_writeable = preg_match("/w/",$this->parent->getacl(""));
55         /* Check for interaction */
56         if ($acl_writeable && isset($_POST['add_statement']) && $_POST['addstatement'] != ""){
57             $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addstatement'));
58             $val= preg_replace("/^$key\s*/", '', get_post('addstatement'));
59             $this->statements->add($key,$val);
60         }
61         if ($acl_writeable && isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){
62             $name = preg_replace('/_[0-9]*$/', '', get_post('dhcpstatements'));
63             $key  = preg_replace('/^.*_/', '', get_post('dhcpstatements'));
64             if (in_array($name, $this->autoStatements)){
65                 msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
66             } else {
67                 $this->statements->remove($name,$key);  
68             }
69         }
70         if ($acl_writeable && isset($_POST['add_option']) && $_POST['addoption'] != ""){
71             $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addoption'));
72             $val= preg_replace("/^$key\s*/", '', get_post('addoption'));
73             $this->options->add($key,$val);
74         }
75         if ($acl_writeable && isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){
76             $name = preg_replace('/_[0-9]*$/', '', get_post('dhcpoptions'));
77             $key  = preg_replace('/^.*_/', '', get_post('dhcpoptions'));
78             if (in_array($name, $this->autoOptions)){
79                 msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
80             } else {
81                 $this->options->remove($name,$key);     
82             }
83         }
85         $smarty= get_smarty();
87         /* Assign ACLs */
88         $smarty->assign("acl",$this->parent->getacl(""));
90         /* Assign statements  */
91         $statements= array();
92         foreach ($this->statements->getAll() as $key => $val){
93             if (in_array($key, $this->autoStatements)){
94                 foreach($val as $id => $entry){
95                     $statements[$key."_".$id]= "$key $entry ["._("automatic")."]";
96                 }       
97             } else {
98                 foreach($val as $id => $entry){
99                     $statements[$key."_".$id]= "$key $entry";
100                 }       
101             }
102         }
103         $smarty->assign("dhcpstatements", set_post($statements));
105         /* Assign options  */
106         $options= array();
107         foreach ($this->options->getAll() as $key => $val){
108             if (in_array($key, $this->autoOptions)){
109                 foreach($val as $id => $entry){
110                     $options[$key."_".$id]= "$key $entry ["._("automatic")."]";
111                 }       
112             } else {
113                 foreach($val as $id => $entry){
114                     $options[$key."_".$id]= "$key $entry";
115                 }       
116             }
117         }
118         $smarty->assign("dhcpoptions", set_post($options));
120         /* Show main page */
121         $smarty->assign("show_advanced", $this->show_advanced);
122         return ($smarty->fetch (get_template_path('dhcp_advanced.tpl', TRUE,dirname(__FILE__))));
123     }
125     function remove_from_parent()
126     {
127     }
130     /* Save data to object */
131     function save_object()
132     {
133         if (isset($_POST['show_advanced'])){
134             $this->show_advanced= TRUE;
135         }
136         if (isset($_POST['hide_advanced'])){
137             $this->show_advanced= FALSE;
138         }
139     }
142     /* Check values */
143     function check()
144     {
145         /* Nothing to check here */
146         $message= array();
147         return $message;
148     }
151     /* Save to LDAP */
152     function save()
153     {
154     }
157     function setAutoOptions($addopt= array())
158     {
159         $options= array("routers", "domain-name", "domain-name-servers", "subnet-mask", "broadcast-address");
160         $this->autoOptions= array_merge($options, $addopt);
161     }
164     function setAutoStatements($addstat= array())
165     {
166         $statements= array("filename", "next-server", "get-lease-hostnames", "use-host-decl-names");
167         $this->autoStatements= array_merge($statements, $addstat);
168     }
172 ?>