Code

Updated Post handling
[gosa.git] / plugins / admin / systems / class_dhcpService.inc
1 <?php
2 /*
3   This code is part of GOsa (https://gosa.gonicus.de)
4   Copyright (C) 2003-2007  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 dhcpService extends dhcpPlugin
22 {
23   /* Used attributes */
24   var $dhcpPrimaryDN= "";
25   var $orig_dhcpPrimaryDN= "";
26   var $ddns_styles= array('none', 'interim', 'ad-hoc');
28   /* attribute list for save action */
29   var $objectclasses= array('top', 'dhcpService');
32   function dhcpService($attrs)
33   {
34     dhcpPlugin::dhcpPlugin($attrs);
36     /* Load statements / options */
37     if (!$this->new){
38       /* Load attributes */
39       $this->dhcpPrimaryDN= $attrs['dhcpPrimaryDN'][0];
40     } else {
41       /* We keep the parent dn here if it's new */
42       $this->statements['default-lease-time']= 600;
43       $this->statements['max-lease-time']= 1700;
44       $this->statements['authoritative']= TRUE;
45       $this->statements['ddns-update-style']= 'none';
46     }
48     $this->advanced->setAutoStatements(array("default-lease-time", "max-lease-time", "authoritative", "server-identifier", "ddns-update-style"));
49     $this->advanced->setAutoOptions(array("server-name"));
51     /* Save for later action */
52     $this->orig_dhcpPrimaryDN= $this->dhcpPrimaryDN;
53   }
56   function execute()
57   {
58     /* Show main page */
59     $smarty= get_smarty();
61     $smarty->assign('ddns_styles', $this->ddns_styles);
62     foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $value){
63       if (isset($this->statements[preg_replace('/_/', '-', $value)])){
64         $smarty->assign("$value", $this->statements[preg_replace('/_/', '-', $value)]);
65       } else {
66         $smarty->assign("$value", "");
67       }
68     }
70     if (isset($this->statements['authoritative'])){
71       $smarty->assign("authoritative", "checked");
72     } else {
73       $smarty->assign("authoritative", "");
74     }
76     /* Show main page */
77     $display= $smarty->fetch(get_template_path('dhcp_service.tpl', TRUE)).$this->network->execute();
79     /* Merge arrays for advanced view */
80     foreach (array("options", "statements") as $type){
81       $this->advanced->$type= $this->$type + $this->network->$type;;
82     }
84     $display.= $this->advanced->execute();
86     /* Merge back for removals */
87     foreach (array("options", "statements") as $type){
88       $this->$type= $this->advanced->$type;
89       $this->network->$type= $this->advanced->$type;
90     }
92     /* Add footer */
93     $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
94       "&nbsp;<input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
97     return ($display);
99   }
101   function remove_from_parent()
102   {
103   }
106   /* Save data to object */
107   function save_object()
108   {
109     /* No need to save in the first time */
110     if (!isset($_POST['ddns_update_style'])){
111       return;
112     }
114     /* Save remaining attributes */
115     foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $val){
116       $tval= preg_replace('/_/', '-', $val);
117       if ($_POST[$val] != ""){
118         $this->statements[$tval]= validate(get_post($val));
119       } else {
120         unset ($this->statements[$tval]);
121       }
122     }
123     if (isset($_POST['authoritative'])){
124       $this->statements['authoritative']= "";
125     } else {
126       unset($this->statements['authoritative']);
127     }
129     dhcpPlugin::save_object();
130   }
133   /* Check values */
134   function check()
135   {
136     $message= array();
137     return $message;
138   }
141   /* Save to LDAP */
142   function save()
143   {
144     global $config;
145     $this->attrs= array();
147     /* Get and set server name */
148     $ldap= $config->get_ldap_link();
149     $ldap->cat($this->dhcpPrimaryDN, array('cn'));
150     $res= $ldap->fetch();
151     $server_name= $res['cn'][0];
152     
153     dhcpPlugin::save();
155     $this->attrs['dhcpPrimaryDN']= array($this->dhcpPrimaryDN);
156     $this->removeOption('server-name');
157     $this->attrs['dhcpOption'][]= "server-name $server_name";
159     return ($this->attrs);
160   }
161   
163 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
164 ?>