Code

cd8788a566b224f6cbe135007099350934f57104
[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 $goXdmcPlsEnabled= "";
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     /* 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     Handling for Nfs Export Entries
68     */
70     /* Here we add a new entry  */
71     if(isset($_POST['NewNfsAdd']))
72       {
73       $this->attrs['goExportEntry'][]=$_POST['NewNfsExport'];
74       }
75     
76       
77      
78     /* Deleting an Entry, is a bit more complicated than adding one*/
79     if(isset($_POST['DelNfsEnt']))
80       {
81       /* Go through all entries an skip the selected (The one we want to delete)*/
82       foreach($this->attrs['goExportEntry'] as $key => $val)
83         {
84         /* Add all entries in an new Array, because when deleting one entry, the could be broken*/
85         if(($val != $_POST['goExportEntry'] ))
86           {
87           /* Skip the entry that we want to delete*/
88           $new_arr[]=$val;
89           }
90         }
91       /* Deleting complete so add result to the attrs */
92       $this->attrs['goExportEntry']=$new_arr;
93       }
95     /* Set the entry which we want to show in the frontend */
96     $this->goExportEntry = ($this->attrs['goExportEntry']);
97     unset($this->goExportEntry['count']);
98    
101    /*
102     Handling for NTP Export Entries
103     */
105     /* Here we add a new entry  */
106     if(isset($_POST['NewNTPAdd']))
107       {
108       $this->attrs['goTimeSource'][]=$_POST['NewNTPExport'];
109       }
110     
111     /*Deleting an Entry, is a bit more complicated than adding one*/
112     if(isset($_POST['DelNTPEnt']))
113       {
114       /* Go through all entries an skip the selected (The one we want to delete)*/
115       foreach($this->attrs['goTimeSource'] as $key => $val)
116         {
117         /* Add all entries in an new Array, because wehn deleting one entry, the could be broken*/
118         if($val != $_POST['goTimeSource'] )
119           {
120           /* Skip the entry that we want to delete*/
121           $new_arr[]=$val;
122           }
123         }
124       /* Deleting complete so add result to the attrs */
125       $this->attrs['goTimeSource']=$new_arr;
126       }
128     /* Set the entry which we want to show in the frontend */
129     $this->goTimeSource = ($this->attrs['goTimeSource']);
130     unset($this->goTimeSource['count']);
134  
135     /* Attributes... */
136     foreach ($this->attributes as $attr){
137       $smarty->assign("$attr", $this->$attr);
138       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
139     }
142     /* Classes... */
143     foreach ($this->additionaloc as $oc => $dummy){
144       if (isset($this->objectclasses[$oc])){
145         $smarty->assign("$oc", "checked");
146         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
147       } else {
148         $smarty->assign("$oc"."State", "disabled");
149       }
150     }
152   return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
153   }
155   function remove_from_parent()
156   {
157     /* This cannot be removed... */
158   }
161   /* Save data to object */
162   function save_object()
163   {
164      plugin::save_object();
166     /* Save checkbox state */
167     foreach ($this->additionaloc as $oc => $dummy){
168       if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
169         $this->objectclasses[$oc]= $oc;
170       } else {
171         unset($this->objectclasses[$oc]);
172       }
173     }
174  
175   }
178   /* Check supplied data */
179   function check()
180   {
181     $message= array();
183     return ($message);
184   }
187   /* Save to LDAP */
188   function save()
189   {
190     /* Normalize lazy objectclass arrays */
191     $objectclasses= array();
192     foreach($this->objectclasses as $oc){
193       $objectclasses[]= $oc;
194     }
196     $this->objectclasses= $objectclasses;
197     plugin::save();
199     /* Remove objectclasses */
200     unset ($this->attrs['objectClass']);
201     foreach($this->objectclasses as $oc){
202       $this->attrs['objectClass'][]= $oc;
203     }
205     /* Adapt sieve server if needed */
206     if (in_array('goImapServer', $this->objectclasses)){
207       $this->attrs['goImapSieveServer']= preg_replace('/:.*$/', '',
208                                          preg_replace('/^{([^}]+)}$/', '\\1',
209                                          $this->attrs['goImapConnect']));
210     }
212     /* Remove unneeded attributes */
213     foreach ($this->additionaloc as $oc => $attrs){
214       if (!in_array($oc, $this->objectclasses)){
215         foreach ($attrs as $attr){
216           $this->attrs[$attr]= array();
217         }
218       }
219     }
221     /* Write to LDAP */
222     $ldap= $this->config->get_ldap_link();
223     $ldap->cd($this->dn);
224     $ldap->modify($this->attrs);
225     show_ldap_error($ldap->get_error());
227     /* Optionally execute a command after we're done */
228     if ($this->initially_was_account == $this->is_account){
229       if ($this->is_modified){
230         $this->handle_post_events("mofify");
231       }
232     } else {
233       $this->handle_post_events("add");
234     }
236   }
240 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
241 ?>