Code

W3c conform, Save will only Save if Plugins is loaded
[gosa.git] / plugins / admin / systems / class_servService.inc
1 <?php
3 class servservice extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage server basic objects";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
11   var $goExportEntry  = array();
12   var $goTimeSource   = array();
13   var $goLdapBase= "";
14   var $goXdmcpIsEnabled ="";
15   var $goFontPath= "";
16   var $goNTPServer="";
17   var $goLdapServer="";
18   var $goTerminalServer="";
19   var $goSyslogServer="";
20   var $goCupsServer="";
23   /* attribute list for save action */
24   var $attributes       = array("goExportEntry","goTimeSource","goLdapBase","goXdmcpIsEnabled","goFontPath" );
25   var $objectclasses    = array("top","goServer"); 
26   var $additionaloc     = array(
27                 
28                           "goNfsServer"     => array("goExportEntry"),
29                           "goNtpServer"     => array("goTimeSource"),
30                           "goLdapServer"    => array("goLdapBase"),
31                           "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
32                           "goSyslogServer"  => array(),
33                           "goCupsServer"    => array()                           
34                           );
44   function servservice ($config, $dn= NULL)
45   {
46     plugin::plugin ($config, $dn);
48     foreach ($this->additionaloc as $oc => $dummy){
49       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
50         $this->objectclasses[$oc]= $oc;
51       }
52     }
53     /* Always is account... */
54     $this->is_account= TRUE;
55   }
59   function execute()
60   {
61     /* Fill templating stuff */
62     $smarty= get_smarty();
64     
65     /*  
66     Handling for Nfs Export Entries
67     */
69     /* Here we add a new entry  */
70     if(isset($_POST['NewNfsAdd']))
71       {
72       $this->attrs['goExportEntry'][]=$_POST['NewNfsExport'];
73       }
74      
75     /* Deleting an Entry, is a bit more complicated than adding one*/
76     if(isset($_POST['DelNfsEnt']))
77       {
78       /* Go through all entries an skip the selected (The one we want to delete)*/
79       foreach($this->attrs['goExportEntry'] as $key => $val)
80         {
81         /* Add all entries in an new Array, because when deleting one entry, the could be broken*/
82         if(($val != $_POST['goExportEntry'] ))
83           {
84           /* Skip the entry that we want to delete*/
85           $new_arr[]=$val;
86           }
87         }
88       /* Deleting complete so add result to the attrs */
89       $this->attrs['goExportEntry']=$new_arr;
90       }
92     /* Set the entry which we want to show in the frontend */
93     if(isset($this->attrs['goExportEntry']))
94       {
95       $this->goExportEntry = ($this->attrs['goExportEntry']);
96       unset($this->goExportEntry['count']);
97       }
100    /*
101     Handling for NTP Export Entries
102     */
104     /* Here we add a new entry  */
105     if(isset($_POST['NewNTPAdd']))
106       {
107       $this->attrs['goTimeSource'][]=$_POST['NewNTPExport'];
108       }
109     
110     /*Deleting an Entry, is a bit more complicated than adding one*/
111     if(isset($_POST['DelNTPEnt']))
112       {
113       /* Go through all entries an skip the selected (The one we want to delete)*/
114       foreach($this->attrs['goTimeSource'] as $key => $val)
115         {
116         /* Add all entries in an new Array, because wehn deleting one entry, the could be broken*/
117         if($val != $_POST['goTimeSource'] )
118           {
119           /* Skip the entry that we want to delete*/
120           $new_arr[]=$val;
121           }
122         }
123       /* Deleting complete so add result to the attrs */
124       $this->attrs['goTimeSource']=$new_arr;
125       }
127     /* Set the entry which we want to show in the frontend */
128     if(isset($this->attrs['goTimeSource']))
129       {
130       $this->goTimeSource = ($this->attrs['goTimeSource']);
131       unset($this->goTimeSource['count']);
132       }
136  
137     /* Attributes... */
138     foreach ($this->attributes as $attr){
139       $smarty->assign("$attr", $this->$attr);
140       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
141       $smarty->assign($attr."State","");
142     }
145     /* Classes... */
146 foreach ($this->additionaloc as $oc => $dummy){
147       if (isset($this->objectclasses[$oc])){
148         $smarty->assign("$oc", "checked");
149         $smarty->assign("$oc"."State", "");
150         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
152       } else {
153         $smarty->assign("$oc", "");
154         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
155         $smarty->assign("$oc"."State", "disabled");
156       }
157     }
160   if(isset($this->attrs['goXdmcpIsEnabled'])&&($this->attrs['goXdmcpIsEnabled']=="1"))
161     $smarty->assign("goXdmcpIsEnabled","checked");
163   return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
164   }
166   function remove_from_parent()
167   {
168     /* This cannot be removed... */
169   }
172   /* Save data to object */
173   function save_object()
174   {
175     if (isset($_POST['servicetab'])){
176       plugin::save_object();
178       /* Save checkbox state */
179       foreach ($this->additionaloc as $oc => $dummy){
180         if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
181           $this->objectclasses[$oc]= $oc;
182         } else {
183           unset($this->objectclasses[$oc]);
184         }
185       }
186     }
187  
188   }
191   /* Check supplied data */
192   function check()
193   {
194     $message= array();
196     return ($message);
197   }
200   /* Save to LDAP */
201   function save()
202   {
203    
204     /* Normalize lazy objectclass arrays */
205     $objectclasses= array();
206     foreach($this->objectclasses as $oc){
207       $objectclasses[]= $oc;
208     }
209     plugin::save();
210  
211     $test = $this->objectclasses;
212     $tmp = array_flip($this->attrs['objectClass']);
213    
214     
215  
216     foreach($this->additionaloc as $key=>$val) {
217       unset($tmp[$key]);
218       }
219    
221     $classes = (array_flip(array_merge(array_flip($test),$tmp)));
223     unset($this->attrs['objectClass']);
225     foreach($classes as $class){
226       $this->attrs['objectClass'][]=$class;
227     }
228       
230     /* Remove unneeded attributes */
231     foreach ($this->additionaloc as $oc => $attrs){
232       if (!in_array($oc, $this->attrs['objectClass'])){
233         foreach ($attrs as $attr){
234           $this->attrs[$attr]= array();
235         }
236       }
237     }
238     $this->attrs = array_reverse($this->attrs);
240     /* Check if we are able to set these attributes */
241 #fixme : It Would be better to check ObjectClass rights to, but what is to do if there are insuficient rights 
242     foreach($this->additionaloc as $oc => $attrs)
243     {
244       foreach($attrs as $val)
245       {
246       if(chkacl($this->acl,$val)=="")
247         {
248         unset($this->attrs[$val]);
249         unset($this->$val);
250         }
251       }
252     }
253     
254     /* Write to LDAP */
255     $ldap= $this->config->get_ldap_link();
256     $ldap->cd($this->dn);
257     $ldap->modify($this->attrs);
258     show_ldap_error($ldap->get_error());
259     /* Optionally execute a command after we're done */
260     if ($this->initially_was_account == $this->is_account){
261       if ($this->is_modified){
262         $this->handle_post_events("mofify");
263       }
264     } else {
265       $this->handle_post_events("add");
266     }
267   }
271 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
272 ?>