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 $this->fix_options();
42 foreach (array("options", "statements") as $type){
43 $this->advanced->$type= $this->$type + $this->network->$type;
44 }
46 $display.= $this->advanced->execute();
48 /* Merge back for removals */
49 foreach (array("options", "statements") as $type){
50 $this->$type= $this->advanced->$type;
51 $this->network->$type= $this->advanced->$type;
52 }
54 /* Add footer */
55 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>".
56 " <input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'></div>";
59 return ($display);
60 }
63 function remove_from_parent()
64 {
65 }
68 /* Save data to object */
69 function save_object()
70 {
71 /* Save cn */
72 if (isset($_POST['cn'])){
73 $this->cn= validate(get_post('cn'));
74 }
76 /* Handle global saving */
77 dhcpPlugin::save_object();
78 }
81 /* Check values */
82 function check()
83 {
84 $message= array();
86 $cache = $this->parent->dhcpObjectCache;
88 /* All required fields are set? */
89 if ($this->cn == ""){
90 $message[]= msgPool::required(_("Name"));
91 }
92 if (!preg_match('/^[a-z0-9_-]*$/i', $this->cn)){
93 $message[]= msgPool::invalid(_("Name"),$this->cn,"/[a-z0-9_-]/i");
94 }
96 /* cn already used? */
97 if ($this->orig_cn != $this->cn || $this->new){
99 foreach($cache as $dn => $dummy){
100 if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
101 $message[]= msgPool::duplicated(_("Name"));
102 break;
103 }
104 }
105 }
107 /* Check external plugins */
108 $net= $this->network->check();
109 $adv= $this->advanced->check();
110 $message= array_merge($message, $net, $adv);
112 return $message;
113 }
116 /* Save to LDAP */
117 function save()
118 {
119 dhcpPlugin::save();
120 return ($this->attrs);
121 }
124 }
126 ?>