Code

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