Code

444df8cf0ae3410562407ef4ab59a24a81847c20
[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 $objectclasses    = array("top","goServer"); 
25   var $additionaloc     = array( "goNfsServer"     => array("goExportEntry"),
26                                  "goNtpServer"     => array("goTimeSource"),
27                                  "goLdapServer"    => array("goLdapBase"),
28                                  "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
29                                  "goSyslogServer"  => array(),
30                                  "goCupsServer"    => array());
32   function servservice ($config, $dn= NULL)
33   {
34     plugin::plugin ($config, $dn);
35     
36     /* Assemble final object class list */
37     foreach ($this->additionaloc as $oc => $dummy){
38       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
39         $this->objectclasses[$oc]= $oc;
40       }
41     }
43     /* Load arrays */
44     foreach (array("goTimeSource", "goExportEntry") as $name){
45       $tmp= array();
46       if (isset($this->attrs[$name])){
47         for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
48           $tmp[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
49         }
50       }
51       $this->$name= $tmp;
52     }
54     /* Always is account... */
55     $this->is_account= TRUE;
56   }
59   function execute()
60   {
61     /* Fill templating stuff */
62     $smarty= get_smarty();
64     $smarty->assign("staticAddress", "");
66     /* Here we add a new entry  */
67     if(isset($_POST['NewNfsAdd']) && $_POST['NewNfsExport'] != "") {
68       $this->goExportEntry[$_POST['NewNfsExport']]= $_POST['NewNfsExport'];
69       asort($this->goExportEntry);
70     }
72     /* Deleting an Entry, is a bit more complicated than adding one*/
73     if(isset($_POST['DelNfsEnt']) && isset($_POST['goExportEntry'])) {
74       foreach ($_POST['goExportEntry'] as $entry){
75         if (isset($this->goExportEntry[$entry])){
76           unset($this->goExportEntry[$entry]);
77         }
78       }
79     }
81     /* Here we add a new entry  */
82     if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
83       $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
84       asort($this->goTimeSource);
85     }
87     /* Deleting an Entry, is a bit more complicated than adding one*/
88     if(isset($_POST['DelNTPEnt'])) {
89       foreach ($_POST['goTimeSource'] as $entry){
90         if (isset($this->goTimeSource[$entry])){
91           unset($this->goTimeSource[$entry]);
92         }
93       }
94     }
96     /* Attributes */
97     foreach ($this->attributes as $attr){
98       $smarty->assign("$attr", $this->$attr);
99       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
100       $smarty->assign($attr."State","");
101     }
103     /* Arrays */
104     foreach (array("goTimeSource", "goExportEntry") as $name){
105       $smarty->assign("$name", $this->$name);
106       $smarty->assign("$name"."ACL", chkacl($this->acl, $name));
107       $smarty->assign($name."State","");
108     }
110     /* Classes... */
111     foreach ($this->additionaloc as $oc => $dummy){
112       if (isset($this->objectclasses[$oc])){
113         $smarty->assign("$oc", "checked");
114         $smarty->assign("$oc"."State", "");
115         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
117       } else {
118         $smarty->assign("$oc", "");
119         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
120         $smarty->assign("$oc"."State", "disabled");
121       }
122     }
124     /* Different handling for checkbox */
125     if($this->goXdmcpIsEnabled == "true"){
126       $smarty->assign("goXdmcpIsEnabled","checked");
127     } else {
128       $smarty->assign("goXdmcpIsEnabled","");
129     }
131     return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
132   }
135   function remove_from_parent()
136   {
137     /* This cannot be removed... */
138   }
141   /* Save data to object */
142   function save_object()
143   {
144     if (isset($_POST['servicetab'])){
145       plugin::save_object();
147       /* Save checkbox state */
148       foreach ($this->additionaloc as $oc => $dummy){
149         if (chkacl($this->acl, $oc) == ""){
150           if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
151             $this->objectclasses[$oc]= $oc;
152           } else {
153             unset($this->objectclasses[$oc]);
154           }
155         }
156       }
158       /* Save xdmcp is enabled flag */
159       if (isset($_POST['goXdmcpIsEnabled'])){
160         $this->goXdmcpIsEnabled= "true";
161       } else {
162         $this->goXdmcpIsEnabled= "false";
163       }
164         
165     }
166   }
169   /* Check supplied data */
170   function check()
171   {
172     $message= array();
174     return ($message);
175   }
178   /* Save to LDAP */
179   function save()
180   {
181     /* Normalize lazy objectclass arrays */
182     $objectclasses= array();
183     foreach($this->objectclasses as $oc){
184       $objectclasses[]= $oc;
185     }
186     $this->objectclasses= $objectclasses;
188     plugin::save();
190     /* Normalize objectclasses */
191     $this->attrs['objectClass']= $this->objectclasses;
193     /* Remove illegal attributes */
194     foreach ($this->additionaloc as $oc => $attrs){
195       if (!in_array($oc, $this->objectclasses)){
196         foreach ($attrs as $attr){
197           $this->attrs[$attr]= array();
198         }
199       }
200     }
202     /* Arrays */
203     foreach (array("goTimeSource", "goExportEntry") as $name){
204       $this->attrs[$name]= array();
205       foreach ($this->$name as $element){
206         $this->attrs[$name][]= $element;
207       }
208     }
210     /* Write to LDAP */
211     $ldap= $this->config->get_ldap_link();
212     $ldap->cd($this->dn);
213     $ldap->modify($this->attrs);
214     show_ldap_error($ldap->get_error());
215     
216     /* Optionally execute a command after we're done */
217     if ($this->initially_was_account == $this->is_account){
218       if ($this->is_modified){
219         $this->handle_post_events("mofify");
220       }
221     } else {
222       $this->handle_post_events("add");
223     }
224   }
228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
229 ?>