Code

Prepared dhcp plugins for ACLs.
[gosa.git] / gosa-plugins / dhcp / admin / systems / services / dhcp / class_dhcpGroup.inc
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;'><input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>".
59                "&nbsp;<input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'></div>";
62     return ($display);
63   }
66   function remove_from_parent()
67   {
68   }
71   /* Save data to object */
72   function save_object()
73   {
74     /* Save cn */
75     if (isset($_POST['cn'])){
76       $this->cn= validate(get_post('cn'));
77     }
79     /* Handle global saving */
80     dhcpPlugin::save_object();
81   }
84   /* Check values */
85   function check()
86   {
87     $message= array();
89     $cache = $this->parent->dhcpObjectCache;
91     /* All required fields are set? */
92     if ($this->cn == ""){
93       $message[]= msgPool::required(_("Name"));
94     }
95     if (!preg_match('/^[a-z0-9_-]*$/i', $this->cn)){
96       $message[]= msgPool::invalid(_("Name"),$this->cn,"/[a-z0-9_-]/i");
97     }
99     /* cn already used? */
100     if ($this->orig_cn != $this->cn || $this->new){
102       foreach($cache as $dn => $dummy){
103         if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
104           $message[]= msgPool::duplicated(_("Name"));
105           break;
106         }
107       }
108     }
110     /* Check external plugins */
111     $net= $this->network->check();
112     $adv= $this->advanced->check();
113     $message= array_merge($message, $net, $adv);
115     return $message;
116   }
119   /* Save to LDAP */
120   function save()
121   {
122     dhcpPlugin::save();
123     return ($this->attrs);
124   }
129 ?>