Code

Updated trunk, introduced gosa-core
[gosa.git] / plugins / 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= array();
25   var $statements= array();
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();
34   function dhcpAdvanced()
35   {
36     /* This is always an account */
37     $this->is_account= TRUE;
38     $this->setAutoStatements();
39     $this->setAutoOptions();
40   }
42   function execute()
43   {
44     /* Check for interaction */
45     if (isset($_POST['add_statement']) && $_POST['addstatement'] != ""){
46       $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addstatement'));
47       $val= preg_replace("/^$key\s*/", '', get_post('addstatement'));
48       $this->statements[$key]= $val;
49     }
50     if (isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){
51       $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpstatements'));
52       if (in_array($key, $this->autoStatements)){
53         print_red(_("Can't delete automatic statements. Please use the fields above."));
54       } else {
55         unset($this->statements[$key]); 
56       }
57     }
58     if (isset($_POST['add_option']) && $_POST['addoption'] != ""){
59       $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addoption'));
60       $val= preg_replace("/^$key\s*/", '', get_post('addoption'));
61       $this->options[$key]= $val;
62     }
63     if (isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){
64       $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpoptions'));
65       if (in_array($key, $this->autoOptions)){
66         print_red(_("Can't delete automatic options. Please use the fields above."));
67       } else {
68         unset($this->options[$key]);    
69       }
70     }
72     $smarty= get_smarty();
74     /* Assign arrays */
75     $statements= array();
76     foreach ($this->statements as $key => $val){
77       if (in_array($key, $this->autoStatements)){
78         $statements[$key]= "$key $val ["._("automatic")."]";
79       } else {
80         $statements[$key]= "$key $val";
81       }
82     }
83     $smarty->assign("dhcpstatements", $statements);
84     $options= array();
85     foreach ($this->options as $key => $val){
86       if (in_array($key, $this->autoOptions)){
87         $options[$key]= "$key $val ["._("automatic")."]";
88       } else {
89         $options[$key]= "$key $val";
90       }
91     }
92     $smarty->assign("dhcpoptions", $options);
94     /* Show main page */
95     $smarty->assign("show_advanced", $this->show_advanced);
96     return ($smarty->fetch (get_template_path('dhcp_advanced.tpl', TRUE,dirname(__FILE__))));
97   }
99   function remove_from_parent()
100   {
101   }
104   /* Save data to object */
105   function save_object()
106   {
107     if (isset($_POST['show_advanced'])){
108       $this->show_advanced= TRUE;
109     }
110     if (isset($_POST['hide_advanced'])){
111       $this->show_advanced= FALSE;
112     }
113   }
116   /* Check values */
117   function check()
118   {
119     /* Nothing to check here */
120     $message= array();
121     return $message;
122   }
125   /* Save to LDAP */
126   function save()
127   {
128   }
131   function setAutoOptions($addopt= array())
132   {
133     $options= array("routers", "domain-name", "domain-name-servers", "subnet-mask", "broadcast-address");
134     $this->autoOptions= array_merge($options, $addopt);
135   }
138   function setAutoStatements($addstat= array())
139   {
140     $statements= array("filename", "next-server", "get-lease-hostnames", "use-host-decl-names");
141     $this->autoStatements= array_merge($statements, $addstat);
142   }
146 ?>