Code

Added empty lines
[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     /* Check if goShareServer is defined */
75     if((isset($this->attrs['objectClass']))&&(is_array($this->attrs['objectClass']))){ 
76       if(in_array("goShareServer",$this->attrs['objectClass'])){
77         $this->goShareServer = true;    
78       }
79     }
80   }
82   function addToList($entry){
83     $key =  key($entry);
84     $this->goExportEntry[$key]=$entry[$key];
85   }
87   function deleteFromList($id){
88     unset($this->goExportEntry[$id]);
89   }
92   function execute()
93   {
94         /* Call parent execute */
95         plugin::execute();
97     /* Fill templating stuff */
98     $smarty= get_smarty();
100     $smarty->assign("staticAddress", "");
102     if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntry']))){
103       $this->deleteFromList($_POST['goExportEntry']);
104     }
106     if(isset($_POST['NewNfsAdd'])){
107       $this->o_subWindow = new servnfs($this->config, $this->dn);
108       $this->dialog = true;
109     }
111     if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntry']))){
112       $entry = $this->goExportEntry[$_POST['goExportEntry']];
113       $this->o_subWindow = new servnfs($this->config, $this->dn,$entry);
114       $this->dialog = true;
115     }
117     if(isset($this->o_subWindow)){
118     $this->o_subWindow->save_object(TRUE);
119     }
121     /* Save NFS setup */
122     if(isset($_POST['NFSsave'])){
123       if(count($this->o_subWindow->check())>0){
124         foreach($this->o_subWindow->check() as $msg) {
125           print_red($msg);
126         }
127       }else{
128         $this->o_subWindow->save_object();
129         $newone = $this->o_subWindow->save();
130         $this->addToList($newone) ;
131         unset($this->o_subWindow);
132         $this->dialog = false;
133       }
134     }
135     
136     /* Cancel NFS setup */
137     if(isset($_POST['NFScancel'])){
138       unset($this->o_subWindow);
139       $this->dialog = false;
140     }
141   
142     /* Execute NFS setup dialog*/
143     if(isset($this->o_subWindow)){
144       return $this->o_subWindow->execute(); 
145     }
147     /* Here we add a new entry  */
148     if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
149       $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
150       asort($this->goTimeSource);
151     }
153     /* Deleting an Entry, is a bit more complicated than adding one*/
154     if(isset($_POST['DelNTPEnt'])) {
155       foreach ($_POST['goTimeSource'] as $entry){
156         if (isset($this->goTimeSource[$entry])){
157           unset($this->goTimeSource[$entry]);
158         }
159       }
160     }
162     /* Attributes */
163     foreach ($this->attributes as $attr){
164       $smarty->assign("$attr", $this->$attr);
165       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
166       $smarty->assign($attr."State","");
167     }
168     
169     $tellSmarty=array();
170     foreach($this->goExportEntry as $name=>$values){
171        $tmp = split("\|",$values);
172        $tellSmarty[$name] = $tmp[0]." ".$tmp[4];
173     }
174     $smarty->assign("goExportEntry",array_keys($tellSmarty));
175     $smarty->assign("goExportEntryKeys",($tellSmarty));
176     $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
178     $smarty->assign("goTimeSource", $this->goTimeSource);
179     $smarty->assign("goTimeSourceACL", chkacl($this->acl, "goTimeSource"));
180     $smarty->assign("goTimeSourceState","");
181     
183     /* Classes... */
184     foreach ($this->additionaloc as $oc => $dummy){
185       if (isset($this->objectclasses[$oc])){
186         $smarty->assign("$oc", "checked");
187         $smarty->assign("$oc"."State", "");
188         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
190       } else {
191         $smarty->assign("$oc", "");
192         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
193         $smarty->assign("$oc"."State", "disabled");
194       }
195     }
197     if(!$this->goShareServer){
198       $smarty->assign("goShareServerState", " disabled ");
199       $smarty->assign("goExportEntryACL", " disabled ");
200     }else{
201       $smarty->assign("goShareServerState", "  ");
202       $smarty->assign("goExportEntryACL", "  ");
203     }
205     /* Different handling for checkbox */
206     if($this->goXdmcpIsEnabled == "true"){
207       $smarty->assign("goXdmcpIsEnabled","checked");
208     } else {
209       $smarty->assign("goXdmcpIsEnabled","");
210     }
212     return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
213   }
216   function remove_from_parent()
217   {
218     /* This cannot be removed... */
219   }
222   /* Save data to object */
223   function save_object()
224   {
225     if (isset($_POST['servicetab'])){
226       plugin::save_object();
228       /* Save checkbox state */
229       foreach ($this->additionaloc as $oc => $dummy){
230         if (chkacl($this->acl, $oc) == ""){
231           if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
232             $this->objectclasses[$oc]= $oc;
233           } else {
234             unset($this->objectclasses[$oc]);
235           }
236         }
237       }
239       /* Save xdmcp is enabled flag */
240       if (isset($_POST['goXdmcpIsEnabled'])){
241         $this->goXdmcpIsEnabled= "true";
242       } else {
243         $this->goXdmcpIsEnabled= "false";
244       }
245         
246       /* Save xdmcp is enabled flag */
247       if (isset($_POST['goShareServer'])){
248         $this->goShareServer = true;
249       } else {
250         $this->goShareServer = false;
251       }
252     }
253   }
256   /* Check supplied data */
257   function check()
258   {
259     $message= array();
260   
261     if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
262       $message[]=_("Terminal server, must have fontpath specified.");
263     }
265     return ($message);
266   }
269   /* Save to LDAP */
270   function save()
271   {
272     plugin::save();
274     $tmp= array();
276     /* Remove all from this plugin */
277     foreach($this->attrs['objectClass'] as $oc){
278       if (!in_array_ics($oc, $this->possible_objectclasses)){
279         $tmp[]= $oc;
280       }
281     }
282     
283     /* Merge our current objectclasses */
284     foreach($this->objectclasses as $oc){
285       if (!in_array_ics($oc, $tmp)){
286         $tmp[]= $oc;
287       }
288     }
290     /* Reassign cleaned value */
291     $this->attrs['objectClass']= $tmp;
293     /* Arrays */
294     foreach (array("goTimeSource", "goExportEntry") as $name){
295       $this->attrs[$name]= array();
296       foreach ($this->$name as $element){
297         $this->attrs[$name][]= $element;
298       }
299     }
300  
301     /* Remove illegal attributes */
302     foreach ($this->additionaloc as $oc => $attrs){
303       if (!in_array($oc, $this->objectclasses)){
304         foreach ($attrs as $attr){
305           $this->attrs[$attr]= array();
306         }
307       }
308     }
310     /* Write to LDAP */
311     $ldap= $this->config->get_ldap_link();
312     $ldap->cd($this->dn);
313     $ldap->modify($this->attrs);
314     show_ldap_error($ldap->get_error());
315     
316     /* Optionally execute a command after we're done */
317     if ($this->initially_was_account == $this->is_account){
318       if ($this->is_modified){
319         $this->handle_post_events("mofify");
320       }
321     } else {
322       $this->handle_post_events("add");
323     }
324   }
328 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
329 ?>