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($parent,&$attrs)
27 {
28 /* Load statements / options */
29 dhcpPlugin::dhcpPlugin($parent,$attrs);
30 }
32 function execute()
33 {
34 $smarty= get_smarty();
35 $smarty->assign("cn", $this->cn);
37 /* Assign ACLs */
38 $smarty->assign("acl",$this->parent->getacl(""));
40 /* Show main page */
41 $display= $smarty->fetch (get_template_path('dhcp_group.tpl', TRUE, dirname(__FILE__))).$this->network->execute();
43 /* Merge arrays for advanced view */
44 $this->fix_options();
45 foreach (array("options", "statements") as $type){
46 $this->advanced->$type= $this->$type + $this->network->$type;
47 }
49 $display.= $this->advanced->execute();
51 /* Merge back for removals */
52 foreach (array("options", "statements") as $type){
53 $this->$type= $this->advanced->$type;
54 $this->network->$type= $this->advanced->$type;
55 }
57 /* Add footer */
58 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
59 if(preg_match("/w/",$this->parent->getacl(""))){
60 $display.= "<input type=submit name='save_dhcp' value='".msgPool::saveButton()."'> ";
61 }
62 $display.= "<input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'>";
63 $display.= "</div>";
65 return ($display);
66 }
69 function remove_from_parent()
70 {
71 }
74 /* Save data to object */
75 function save_object()
76 {
77 /* Save cn */
78 if (preg_match("/w/",$this->parent->getacl("")) && isset($_POST['cn'])){
79 $this->cn= validate(get_post('cn'));
80 }
82 /* Handle global saving */
83 dhcpPlugin::save_object();
84 }
87 /* Check values */
88 function check()
89 {
90 $message= array();
92 $cache = $this->parent->dhcpObjectCache;
94 /* All required fields are set? */
95 if ($this->cn == ""){
96 $message[]= msgPool::required(_("Name"));
97 }
98 if (!preg_match('/^[a-z0-9_-]*$/i', $this->cn)){
99 $message[]= msgPool::invalid(_("Name"),$this->cn,"/[a-z0-9_-]/i");
100 }
102 /* cn already used? */
103 if ($this->orig_cn != $this->cn || $this->new){
105 foreach($cache as $dn => $dummy){
106 if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
107 $message[]= msgPool::duplicated(_("Name"));
108 break;
109 }
110 }
111 }
113 /* Check external plugins */
114 $net= $this->network->check();
115 $adv= $this->advanced->check();
116 $message= array_merge($message, $net, $adv);
118 return $message;
119 }
122 /* Save to LDAP */
123 function save()
124 {
125 dhcpPlugin::save();
126 return ($this->attrs);
127 }
130 }
132 ?>