Code

Added tooltip for pictures
[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 $goLdapServer="";
17   var $goTerminalServer="";
18   var $goSyslogServer="";
19   var $goCupsServer="";
21   /* attribute list for save action */
22   var $ignore_account= TRUE;
23   var $attributes       = array("goLdapBase","goXdmcpIsEnabled","goFontPath");
24   var $possible_objectclasses= array( "goNfsServer", "goNtpServer", "goServer", "goLdapServer",
25                                       "goTerminalServer", "goSyslogServer", "goCupsServer");
26   var $objectclasses    = array("top","goServer"); 
27   var $additionaloc     = array( "goNfsServer"     => array("goExportEntry"),
28                                  "goNtpServer"     => array("goTimeSource"),
29                                  "goLdapServer"    => array("goLdapBase"),
30                                  "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
31                                  "goSyslogServer"  => array(),
32                                  "goCupsServer"    => array());
34   function servservice ($config, $dn= NULL)
35   {
36     plugin::plugin ($config, $dn);
37     
38     /* Assemble final object class list */
39     foreach ($this->additionaloc as $oc => $dummy){
40       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
41         $this->objectclasses[$oc]= $oc;
42       }
43     }
45     /* Load arrays */
46     foreach (array("goTimeSource", "goExportEntry") as $name){
47       $tmp= array();
48       if (isset($this->attrs[$name])){
49         for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
50           $tmp[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
51         }
52       }
53       $this->$name= $tmp;
54     }
56     /* Always is account... */
57     $this->is_account= TRUE;
58   }
61   function execute()
62   {
63     /* Fill templating stuff */
64     $smarty= get_smarty();
66     $smarty->assign("staticAddress", "");
68     /* Here we add a new entry  */
69     if(isset($_POST['NewNfsAdd']) && $_POST['NewNfsExport'] != "") {
70       $this->goExportEntry[$_POST['NewNfsExport']]= $_POST['NewNfsExport'];
71       asort($this->goExportEntry);
72     }
74     /* Deleting an Entry, is a bit more complicated than adding one*/
75     if(isset($_POST['DelNfsEnt']) && isset($_POST['goExportEntry'])) {
76       foreach ($_POST['goExportEntry'] as $entry){
77         if (isset($this->goExportEntry[$entry])){
78           unset($this->goExportEntry[$entry]);
79         }
80       }
81     }
83     /* Here we add a new entry  */
84     if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
85       $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
86       asort($this->goTimeSource);
87     }
89     /* Deleting an Entry, is a bit more complicated than adding one*/
90     if(isset($_POST['DelNTPEnt'])) {
91       foreach ($_POST['goTimeSource'] as $entry){
92         if (isset($this->goTimeSource[$entry])){
93           unset($this->goTimeSource[$entry]);
94         }
95       }
96     }
98     /* Attributes */
99     foreach ($this->attributes as $attr){
100       $smarty->assign("$attr", $this->$attr);
101       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
102       $smarty->assign($attr."State","");
103     }
105     /* Arrays */
106     foreach (array("goTimeSource", "goExportEntry") as $name){
107       $smarty->assign("$name", $this->$name);
108       $smarty->assign("$name"."ACL", chkacl($this->acl, $name));
109       $smarty->assign($name."State","");
110     }
112     /* Classes... */
113     foreach ($this->additionaloc as $oc => $dummy){
114       if (isset($this->objectclasses[$oc])){
115         $smarty->assign("$oc", "checked");
116         $smarty->assign("$oc"."State", "");
117         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
119       } else {
120         $smarty->assign("$oc", "");
121         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
122         $smarty->assign("$oc"."State", "disabled");
123       }
124     }
126     /* Different handling for checkbox */
127     if($this->goXdmcpIsEnabled == "true"){
128       $smarty->assign("goXdmcpIsEnabled","checked");
129     } else {
130       $smarty->assign("goXdmcpIsEnabled","");
131     }
133     return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
134   }
137   function remove_from_parent()
138   {
139     /* This cannot be removed... */
140   }
143   /* Save data to object */
144   function save_object()
145   {
146     if (isset($_POST['servicetab'])){
147       plugin::save_object();
149       /* Save checkbox state */
150       foreach ($this->additionaloc as $oc => $dummy){
151         if (chkacl($this->acl, $oc) == ""){
152           if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
153             $this->objectclasses[$oc]= $oc;
154           } else {
155             unset($this->objectclasses[$oc]);
156           }
157         }
158       }
160       /* Save xdmcp is enabled flag */
161       if (isset($_POST['goXdmcpIsEnabled'])){
162         $this->goXdmcpIsEnabled= "true";
163       } else {
164         $this->goXdmcpIsEnabled= "false";
165       }
166         
167     }
168   }
171   /* Check supplied data */
172   function check()
173   {
174     $message= array();
175   
176     
177   
178     if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
179       $message[]=_("Terminal server, must have fontpath specified.");
180     }
182     return ($message);
183   }
186   /* Save to LDAP */
187   function save()
188   {
189     /* Normalize lazy objectclass arrays */
190     $objectclasses= array();
191     foreach($this->objectclasses as $oc){
192       $objectclasses[]= $oc;
193     }
194     $this->objectclasses= $objectclasses;
196     plugin::save();
198     $tmp= array();
200     /* Remove all from this plugin */
201     foreach($this->attrs['objectClass'] as $oc){
202       if (!in_array_ics($oc, $this->possible_objectclasses)){
203         $tmp[]= $oc;
204       }
205     }
207     /* Merge our current objectclasses */
208     foreach($this->objectclasses as $oc){
209       if (!in_array_ics($oc, $tmp)){
210         $tmp[]= $oc;
211       }
212     }
214     /* Reassign cleaned value */
215     $this->attrs['objectClass']= $tmp;
217     /* Remove illegal attributes */
218     foreach ($this->additionaloc as $oc => $attrs){
219       if (!in_array($oc, $this->objectclasses)){
220         foreach ($attrs as $attr){
221           $this->attrs[$attr]= array();
222         }
223       }
224     }
226     /* Arrays */
227     foreach (array("goTimeSource", "goExportEntry") as $name){
228       $this->attrs[$name]= array();
229       foreach ($this->$name as $element){
230         $this->attrs[$name][]= $element;
231       }
232     }
234     /* Write to LDAP */
235     $ldap= $this->config->get_ldap_link();
236     $ldap->cd($this->dn);
237     $ldap->modify($this->attrs);
238     show_ldap_error($ldap->get_error());
239     
240     /* Optionally execute a command after we're done */
241     if ($this->initially_was_account == $this->is_account){
242       if ($this->is_modified){
243         $this->handle_post_events("mofify");
244       }
245     } else {
246       $this->handle_post_events("add");
247     }
248   }
252 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
253 ?>