Code

26b6245ac06d6ff78e3d8ccf2c92053cf8b9b83f
[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("goSyslogServer"),
33                           "goCupsServer"    => array("goCupsServer")                           
34                           );
44   function servservice ($config, $dn= NULL)
45   {
46     plugin::plugin ($config, $dn);
48     /* Always is account... */
50     foreach ($this->additionaloc as $oc => $dummy){
51       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
52         $this->objectclasses[$oc]= $oc;
53       }
54     }
55     /* Always is account... */
56     $this->is_account= TRUE;
57   }
61   function execute()
62   {
63     /* Fill templating stuff */
64     $smarty= get_smarty();
66     
67     /*  
68     Handling for Nfs Export Entries
69     */
71     /* Here we add a new entry  */
72     if(isset($_POST['NewNfsAdd']))
73       {
74       $this->attrs['goExportEntry'][]=$_POST['NewNfsExport'];
75       }
76      
77     /* Deleting an Entry, is a bit more complicated than adding one*/
78     if(isset($_POST['DelNfsEnt']))
79       {
80       /* Go through all entries an skip the selected (The one we want to delete)*/
81       foreach($this->attrs['goExportEntry'] as $key => $val)
82         {
83         /* Add all entries in an new Array, because when deleting one entry, the could be broken*/
84         if(($val != $_POST['goExportEntry'] ))
85           {
86           /* Skip the entry that we want to delete*/
87           $new_arr[]=$val;
88           }
89         }
90       /* Deleting complete so add result to the attrs */
91       $this->attrs['goExportEntry']=$new_arr;
92       }
94     /* Set the entry which we want to show in the frontend */
95     if(isset($this->attrs['goExportEntry']))
96       {
97       $this->goExportEntry = ($this->attrs['goExportEntry']);
98       unset($this->goExportEntry['count']);
99       }
102    /*
103     Handling for NTP Export Entries
104     */
106     /* Here we add a new entry  */
107     if(isset($_POST['NewNTPAdd']))
108       {
109       $this->attrs['goTimeSource'][]=$_POST['NewNTPExport'];
110       }
111     
112     /*Deleting an Entry, is a bit more complicated than adding one*/
113     if(isset($_POST['DelNTPEnt']))
114       {
115       /* Go through all entries an skip the selected (The one we want to delete)*/
116       foreach($this->attrs['goTimeSource'] as $key => $val)
117         {
118         /* Add all entries in an new Array, because wehn deleting one entry, the could be broken*/
119         if($val != $_POST['goTimeSource'] )
120           {
121           /* Skip the entry that we want to delete*/
122           $new_arr[]=$val;
123           }
124         }
125       /* Deleting complete so add result to the attrs */
126       $this->attrs['goTimeSource']=$new_arr;
127       }
129     /* Set the entry which we want to show in the frontend */
130     if(isset($this->attrs['goTimeSource']))
131       {
132       $this->goTimeSource = ($this->attrs['goTimeSource']);
133       unset($this->goTimeSource['count']);
134       }
138  
139     /* Attributes... */
140     foreach ($this->attributes as $attr){
141       $smarty->assign("$attr", $this->$attr);
142       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
143     }
146     /* Classes... */
147     foreach ($this->additionaloc as $oc => $dummy){
148       if (isset($this->objectclasses[$oc])){
149         $smarty->assign("$oc", "checked");
150         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
151       } else {
152         $smarty->assign("$oc"."State", "disabled");
153       }
154     }
156   return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
157   }
159   function remove_from_parent()
160   {
161     /* This cannot be removed... */
162   }
165   /* Save data to object */
166   function save_object()
167   {
168      plugin::save_object();
170     /* Save checkbox state */
171     foreach ($this->additionaloc as $oc => $dummy){
172       if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
173         $this->objectclasses[$oc]= $oc;
174       } else {
175         unset($this->objectclasses[$oc]);
176       }
177     }
178  
179   }
182   /* Check supplied data */
183   function check()
184   {
185     $message= array();
187     return ($message);
188   }
191   /* Save to LDAP */
192   function save()
193   {
194     /* Normalize lazy objectclass arrays */
195     $objectclasses= array();
196     foreach($this->objectclasses as $oc){
197       $objectclasses[]= $oc;
198     }
200     $this->objectclasses= $objectclasses;
201     plugin::save();
203     /* Remove objectclasses */
204     unset ($this->attrs['objectClass']);
205     foreach($this->objectclasses as $oc){
206       $this->attrs['objectClass'][]= $oc;
207     }
209     /* Adapt sieve server if needed */
210     if (in_array('goImapServer', $this->objectclasses)){
211       $this->attrs['goImapSieveServer']= preg_replace('/:.*$/', '',
212                                          preg_replace('/^{([^}]+)}$/', '\\1',
213                                          $this->attrs['goImapConnect']));
214     }
216     /* Remove unneeded attributes */
217     foreach ($this->additionaloc as $oc => $attrs){
218       if (!in_array($oc, $this->objectclasses)){
219         foreach ($attrs as $attr){
220           $this->attrs[$attr]= array();
221         }
222       }
223     }
225     /* Write to LDAP */
226     $ldap= $this->config->get_ldap_link();
227     $ldap->cd($this->dn);
228     $ldap->modify($this->attrs);
229     show_ldap_error($ldap->get_error());
231     /* Optionally execute a command after we're done */
232     if ($this->initially_was_account == $this->is_account){
233       if ($this->is_modified){
234         $this->handle_post_events("mofify");
235       }
236     } else {
237       $this->handle_post_events("add");
238     }
240   }
244 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
245 ?>