Code

Fixed, problem: a new conference appeared 2 times in extensions table.
[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");
10   var $goExportEntry    = array();
11   var $goTimeSource     = array();
12   var $goLdapBase       = "";
13   var $goXdmcpIsEnabled = "";
14   var $goFontPath       = "";
15   var $goNTPServer      = "";
16   var $goShareServer    = false;
17   var $goLdapServer     = "";
18   var $goTerminalServer = "";
19   var $goSyslogServer   = "";
20   var $goCupsServer     = "";
21   var $o_subWindow      = NULL;
23   /* attribute list for save action */
24   var $ignore_account= TRUE;
25   var $attributes       = array("goLdapBase","goXdmcpIsEnabled","goFontPath");
26   var $possible_objectclasses= array( "goShareServer", "goNtpServer", "goServer", "goLdapServer",
27                                       "goTerminalServer", "goSyslogServer", "goCupsServer");
28   var $objectclasses    = array( "top","goServer"); 
29   var $additionaloc     = array( "goShareServer"     => array("goExportEntry"),
30                                  "goNtpServer"     => array("goTimeSource"),
31                                  "goLdapServer"    => array("goLdapBase"),
32                                  "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
33                                  "goSyslogServer"  => array(),
34                                  "goCupsServer"    => array());
36   function servservice ($config, $dn= NULL)
37   {
38     plugin::plugin ($config, $dn);
39     
40     /* Assemble final object class list */
41     foreach ($this->additionaloc as $oc => $dummy){
42       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
43         $this->objectclasses[$oc]= $oc;
44       }
45     }
47     /* Load arrays */
48     foreach (array("goTimeSource") as $name){
49       $tmp= array();
50       if (isset($this->attrs[$name])){
51         for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
52           $tmp[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
53         }
54       }
55       $this->$name= $tmp;
56     }
58     $tmp =array();
59     $tmp2=array();
60     if(isset($this->attrs['goExportEntry'])){
61       unset($this->attrs['goExportEntry']['count']);
62       if((isset($this->attrs['goExportEntry']))&&(isset($this->attrs['goExportEntry']))){
63         foreach($this->attrs['goExportEntry'] as $entry){
64           $tmp2= split("\|",$entry);
65           $tmp[$tmp2[0]]= $entry;
66         }
67       }
68     }
69     $this->goExportEntry = $tmp;
71     /* Always is account... */
72     $this->is_account= TRUE;
74     if(is_array($this->attrs['objectClass'])){ 
75       if(in_array("goShareServer",$this->attrs['objectClass'])){
76         $this->goShareServer = true;    
77       }
78     }
79   }
81   function addToList($entry){
82     $key =  key($entry);
83     $this->goExportEntry[$key]=$entry[$key];
84   }
86   function deleteFromList($id){
87     unset($this->goExportEntry[$id]);
88   }
91   function execute()
92   {
93     /* Fill templating stuff */
94     $smarty= get_smarty();
96     $smarty->assign("staticAddress", "");
98     if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntry']))){
99       $this->deleteFromList($_POST['goExportEntry']);
100     }
102     if(isset($_POST['NewNfsAdd'])){
103       $this->o_subWindow = new servnfs($this->config, $this->dn);
104       $this->dialog = true;
105     }
107     if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntry']))){
108       $entry = $this->goExportEntry[$_POST['goExportEntry']];
109       $this->o_subWindow = new servnfs($this->config, $this->dn,$entry);
110       $this->dialog = true;
111     }
113     if(isset($this->o_subWindow)){
114     $this->o_subWindow->save_object(TRUE);
115     }
117     /* Save NFS setup */
118     if(isset($_POST['NFSsave'])){
119       if(count($this->o_subWindow->check())>0){
120         foreach($this->o_subWindow->check() as $msg) {
121           print_red($msg);
122         }
123       }else{
124         $this->o_subWindow->save_object();
125         $newone = $this->o_subWindow->save();
126         $this->addToList($newone) ;
127         unset($this->o_subWindow);
128         $this->dialog = false;
129       }
130     }
131     
132     /* Cancel NFS setup */
133     if(isset($_POST['NFScancel'])){
134       unset($this->o_subWindow);
135       $this->dialog = false;
136     }
137   
138     /* Execute NFS setup dialog*/
139     if(isset($this->o_subWindow)){
140       return $this->o_subWindow->execute(); 
141     }
143     /* Here we add a new entry  */
144     if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
145       $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
146       asort($this->goTimeSource);
147     }
149     /* Deleting an Entry, is a bit more complicated than adding one*/
150     if(isset($_POST['DelNTPEnt'])) {
151       foreach ($_POST['goTimeSource'] as $entry){
152         if (isset($this->goTimeSource[$entry])){
153           unset($this->goTimeSource[$entry]);
154         }
155       }
156     }
158     /* Attributes */
159     foreach ($this->attributes as $attr){
160       $smarty->assign("$attr", $this->$attr);
161       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
162       $smarty->assign($attr."State","");
163     }
164     
165     $tellSmarty=array();
166     foreach($this->goExportEntry as $name=>$values){
167        $tmp = split("\|",$values);
168        $tellSmarty[$name] = $tmp[0]." ".$tmp[4];
169     }
170     $smarty->assign("goExportEntry",array_keys($tellSmarty));
171     $smarty->assign("goExportEntryKeys",($tellSmarty));
172     $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
174     $smarty->assign("goTimeSource", $this->goTimeSource);
175     $smarty->assign("goTimeSourceACL", chkacl($this->acl, "goTimeSource"));
176     $smarty->assign("goTimeSourceState","");
177     
179     /* Classes... */
180     foreach ($this->additionaloc as $oc => $dummy){
181       if (isset($this->objectclasses[$oc])){
182         $smarty->assign("$oc", "checked");
183         $smarty->assign("$oc"."State", "");
184         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
186       } else {
187         $smarty->assign("$oc", "");
188         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
189         $smarty->assign("$oc"."State", "disabled");
190       }
191     }
193     if(!$this->goShareServer){
194       $smarty->assign("goShareServerState", " disabled ");
195       $smarty->assign("goExportEntryACL", " disabled ");
196     }else{
197       $smarty->assign("goShareServerState", "  ");
198       $smarty->assign("goExportEntryACL", "  ");
199     }
201     /* Different handling for checkbox */
202     if($this->goXdmcpIsEnabled == "true"){
203       $smarty->assign("goXdmcpIsEnabled","checked");
204     } else {
205       $smarty->assign("goXdmcpIsEnabled","");
206     }
208     return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
209   }
212   function remove_from_parent()
213   {
214     /* This cannot be removed... */
215   }
218   /* Save data to object */
219   function save_object()
220   {
221     if (isset($_POST['servicetab'])){
222       plugin::save_object();
224       /* Save checkbox state */
225       foreach ($this->additionaloc as $oc => $dummy){
226         if (chkacl($this->acl, $oc) == ""){
227           if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
228             $this->objectclasses[$oc]= $oc;
229           } else {
230             unset($this->objectclasses[$oc]);
231           }
232         }
233       }
235       /* Save xdmcp is enabled flag */
236       if (isset($_POST['goXdmcpIsEnabled'])){
237         $this->goXdmcpIsEnabled= "true";
238       } else {
239         $this->goXdmcpIsEnabled= "false";
240       }
241         
242       /* Save xdmcp is enabled flag */
243       if (isset($_POST['goShareServer'])){
244         $this->goShareServer = true;
245       } else {
246         $this->goShareServer = false;
247       }
248     }
249   }
252   /* Check supplied data */
253   function check()
254   {
255     $message= array();
256   
257     if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
258       $message[]=_("Terminal server, must have fontpath specified.");
259     }
261     return ($message);
262   }
265   /* Save to LDAP */
266   function save()
267   {
268     plugin::save();
270     $tmp= array();
272     /* Remove all from this plugin */
273     foreach($this->attrs['objectClass'] as $oc){
274       if (!in_array_ics($oc, $this->possible_objectclasses)){
275         $tmp[]= $oc;
276       }
277     }
278     
279     /* Merge our current objectclasses */
280     foreach($this->objectclasses as $oc){
281       if (!in_array_ics($oc, $tmp)){
282         $tmp[]= $oc;
283       }
284     }
286     /* Reassign cleaned value */
287     $this->attrs['objectClass']= $tmp;
289     /* Arrays */
290     foreach (array("goTimeSource", "goExportEntry") as $name){
291       $this->attrs[$name]= array();
292       foreach ($this->$name as $element){
293         $this->attrs[$name][]= $element;
294       }
295     }
296  
297     /* Remove illegal attributes */
298     foreach ($this->additionaloc as $oc => $attrs){
299       if (!in_array($oc, $this->objectclasses)){
300         foreach ($attrs as $attr){
301           $this->attrs[$attr]= array();
302         }
303       }
304     }
306     /* Write to LDAP */
307     $ldap= $this->config->get_ldap_link();
308     $ldap->cd($this->dn);
309     $ldap->modify($this->attrs);
310     show_ldap_error($ldap->get_error());
311     
312     /* Optionally execute a command after we're done */
313     if ($this->initially_was_account == $this->is_account){
314       if ($this->is_modified){
315         $this->handle_post_events("mofify");
316       }
317     } else {
318       $this->handle_post_events("add");
319     }
320   }
324 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
325 ?>