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();
33 var $parent;
35 function dhcpAdvanced()
36 {
37 /* This is always an account */
38 $this->is_account= TRUE;
39 $this->setAutoStatements();
40 $this->setAutoOptions();
41 }
43 function execute()
44 {
45 /* Check for interaction */
46 if (isset($_POST['add_statement']) && $_POST['addstatement'] != ""){
47 $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addstatement'));
48 $val= preg_replace("/^$key\s*/", '', get_post('addstatement'));
49 $this->statements[$key]= $val;
50 }
51 if (isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){
52 $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpstatements'));
53 if (in_array($key, $this->autoStatements)){
54 msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
55 } else {
56 unset($this->statements[$key]);
57 }
58 }
59 if (isset($_POST['add_option']) && $_POST['addoption'] != ""){
60 $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addoption'));
61 $val= preg_replace("/^$key\s*/", '', get_post('addoption'));
62 $this->options[$key]= $val;
63 }
64 if (isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){
65 $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpoptions'));
66 if (in_array($key, $this->autoOptions)){
67 msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
68 } else {
69 unset($this->options[$key]);
70 }
71 }
73 $smarty= get_smarty();
75 /* Assign ACLs */
76 $smarty->assign("acl",$this->parent->getacl(""));
78 /* Assign arrays */
79 $statements= array();
80 foreach ($this->statements as $key => $val){
81 if (in_array($key, $this->autoStatements)){
82 $statements[$key]= "$key $val ["._("automatic")."]";
83 } else {
84 $statements[$key]= "$key $val";
85 }
86 }
87 $smarty->assign("dhcpstatements", $statements);
88 $options= array();
89 foreach ($this->options as $key => $val){
90 if (in_array($key, $this->autoOptions)){
91 $options[$key]= "$key $val ["._("automatic")."]";
92 } else {
93 $options[$key]= "$key $val";
94 }
95 }
96 $smarty->assign("dhcpoptions", $options);
98 /* Show main page */
99 $smarty->assign("show_advanced", $this->show_advanced);
100 return ($smarty->fetch (get_template_path('dhcp_advanced.tpl', TRUE,dirname(__FILE__))));
101 }
103 function remove_from_parent()
104 {
105 }
108 /* Save data to object */
109 function save_object()
110 {
111 if (isset($_POST['show_advanced'])){
112 $this->show_advanced= TRUE;
113 }
114 if (isset($_POST['hide_advanced'])){
115 $this->show_advanced= FALSE;
116 }
117 }
120 /* Check values */
121 function check()
122 {
123 /* Nothing to check here */
124 $message= array();
125 return $message;
126 }
129 /* Save to LDAP */
130 function save()
131 {
132 }
135 function setAutoOptions($addopt= array())
136 {
137 $options= array("routers", "domain-name", "domain-name-servers", "subnet-mask", "broadcast-address");
138 $this->autoOptions= array_merge($options, $addopt);
139 }
142 function setAutoStatements($addstat= array())
143 {
144 $statements= array("filename", "next-server", "get-lease-hostnames", "use-host-decl-names");
145 $this->autoStatements= array_merge($statements, $addstat);
146 }
148 }
150 ?>