Code

Cutted objects will be displayed in light grey in the management lists now.
[gosa.git] / plugins / admin / systems / 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 plugin
22 {
23   /* Used attributes */
24   var $cn= "";
25   var $options= array();
26   var $statements= array();
27   var $orig_cn= "";
28   var $network;
29   var $advanced;
31   /* attribute list for save action */
32   var $attributes= array();
33   var $objectclasses= array();
35   function dhcpGroup($attrs)
36   {
37     /* Load statements / options */
38     if (is_array($attrs)){
39       $this->dn= $attrs['dn'];
40       $this->cn= $attrs['cn'][0];
41       $this->new= FALSE;
43       /* Load options */
44       if (isset($attrs['dhcpOption'])){
45         foreach ($attrs['dhcpOption'] as $opt){
46           $idx= preg_replace('/\s.+$/', '', $opt);
47           $value= preg_replace('/^[^\s]+\s/', '', $opt);
48           $this->options[$idx]= $value;
49         }
50       }
52       /* Load statements */
53       if (isset($attrs['dhcpStatements'])){
54         foreach ($attrs['dhcpStatements'] as $opt){
55           $idx= preg_replace('/\s.+$/', '', $opt);
56           $value= preg_replace('/^[^\s]+\s/', '', $opt);
57           $this->statements[$idx]= $value;
58         }
59       }
61     } else {
62       /* We keep the parent dn here if it's new */
63       $this->dn= $attrs;
64       $this->new= TRUE;
65     }
67     /* Load network module */
68     $this->network= new dhcpNetwork();
69     $this->network->options= $this->options;
70     $this->network->statements= $this->statements;
71     $this->advanced= new dhcpAdvanced();
72     $this->advanced->options= $this->options;
73     $this->advanced->statements= $this->statements;
74     $this->advanced->setAutoStatements(array("fixed-address"));
76     /* Save CN for later reference */
77     $this->orig_cn= $this->cn;
78   }
80   function execute()
81   {
82     $smarty= get_smarty();
83     $smarty->assign("cn", $this->cn);
85     /* Show main page */
86     $display= $smarty->fetch (get_template_path('dhcp_group.tpl', TRUE)).$this->network->execute();
88     /* Merge arrays for advanced view */
89     foreach (array("options", "statements") as $type){
90       $tmp= array_merge($this->$type, $this->network->$type);
91       $this->advanced->$type= $tmp;
92     }
94     $display.= $this->advanced->execute();
96     /* Merge back for removals */
97     foreach (array("options", "statements") as $type){
98       $this->$type= $this->advanced->$type;
99       $this->network->$type= $this->advanced->$type;
100     }
102     /* Add footer */
103     $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
104                "&nbsp;<input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
107     return ($display);
108   }
111   function remove_from_parent()
112   {
113   }
116   /* Save data to object */
117   function save_object()
118   {
119     /* Save cn */
120     if (isset($_POST['cn'])){
121       $this->cn= validate($_POST['cn']);
122     }
124     /* Save sub-objects */
125     $this->network->save_object();
126     $this->advanced->save_object();
128     /* Merge arrays for advanced view */
129     foreach (array("options", "statements") as $type){
130       $tmp= array_merge($this->$type, $this->network->$type);
131       $this->advanced->$type= $tmp;
132     }
133   }
136   /* Check values */
137   function check($cache)
138   {
139     $message= array();
141     /* All required fields are set? */
142     if ($this->cn == ""){
143       $message[]= _("Required field 'Name' is not filled.");
144     }
145     if (!preg_match('/^[a-z0-9_-]*$/i', $this->cn)){
146       $message[]= _("Field 'Name' contains illegal characters.");
147     }
149     return $message;
150   }
153   /* Save to LDAP */
154   function save()
155   {
156     /* Merge arrays for network and advanced view */
157     foreach (array("options", "statements") as $type){
158       $tmp= array_merge($this->$type, $this->network->$type, $this->advanced->$type);
159       $this->$type= $tmp;
160     }
162     /* Add cn if we're new */
163     if ($this->new){
164       $this->dn= "cn=".$this->cn.",".$this->dn;
165     } else {
166       $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->dn);
167     }
169     /* Assemble new entry - options */
170     $this->attrs['dhcpOption']= array();
171     if (isset ($this->options) && count ($this->options)){
172       foreach ($this->options as $key => $val){
173         $this->attrs['dhcpOption'][]= "$key $val";
174       }
175     }
177     /* Assemble new entry - statements */
178     $this->attrs['dhcpStatements']= array();
179     if (isset ($this->statements) && count ($this->statements)){
180       foreach ($this->statements as $key => $val){
181         $this->attrs['dhcpStatements'][]= "$key $val";
182       }
183     }
185     /* Move dn to the result */
186     $this->attrs['dn']= $this->dn;
187     $this->attrs['cn']= array($this->cn);
188     $this->attrs['objectClass']= array('top', 'dhcpGroup', 'dhcpOptions');
189     $this->attrs['MODIFIED']= TRUE;
191     return ($this->attrs);
192   }
197 ?>