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 dhcpGroup extends dhcpPlugin
22 {
23 /* attribute list for save action */
24 var $objectclasses= array('top', 'dhcpGroup', 'dhcpOptions');
26 function dhcpGroup($attrs)
27 {
28 /* Load statements / options */
29 dhcpPlugin::dhcpPlugin($attrs);
30 }
32 function execute()
33 {
34 $smarty= get_smarty();
35 $smarty->assign("cn", $this->cn);
37 /* Show main page */
38 $display= $smarty->fetch (get_template_path('dhcp_group.tpl', TRUE)).$this->network->execute();
40 /* Merge arrays for advanced view */
41 foreach (array("options", "statements") as $type){
42 $this->advanced->$type= $this->$type + $this->network->$type;
43 }
45 $display.= $this->advanced->execute();
47 /* Merge back for removals */
48 foreach (array("options", "statements") as $type){
49 $this->$type= $this->advanced->$type;
50 $this->network->$type= $this->advanced->$type;
51 }
53 /* Add footer */
54 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
55 " <input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
58 return ($display);
59 }
62 function remove_from_parent()
63 {
64 }
67 /* Save data to object */
68 function save_object()
69 {
70 /* Save cn */
71 if (isset($_POST['cn'])){
72 $this->cn= validate(get_post('cn'));
73 }
75 /* Handle global saving */
76 dhcpPlugin::save_object();
77 }
80 /* Check values */
81 function check($cache)
82 {
83 $message= array();
85 /* All required fields are set? */
86 if ($this->cn == ""){
87 $message[]= _("Required field 'Name' is not filled.");
88 }
89 if (!preg_match('/^[a-z0-9_-]*$/i', $this->cn)){
90 $message[]= _("Field 'Name' contains illegal characters.");
91 }
93 /* cn already used? */
94 if ($this->orig_cn != $this->cn || $this->new){
96 foreach($cache as $dn => $dummy){
97 if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
98 $message[]= _("The name for this host section is already used!");
99 break;
100 }
101 }
102 }
104 /* Check external plugins */
105 $net= $this->network->check();
106 $adv= $this->advanced->check();
107 $message= array_merge($message, $net, $adv);
109 return $message;
110 }
113 /* Save to LDAP */
114 function save()
115 {
116 dhcpPlugin::save();
117 return ($this->attrs);
118 }
121 }
123 ?>