Code

added missing template
[gosa.git] / gosa-plugins / goto / admin / systems / services / kiosk / class_goKioskService.inc
1 <?php
3 class goKioskService extends goService{
5     /* This plugin only writes its objectClass */
6     var $objectclasses    = array("goEnvironmentServer");
7     var $attributes       = array("gotoKioskProfile");
8     var $StatusFlag       = "";
10     /* This class can't be assigned twice so it conflicts with itsself */
11     var $conflicts        = array("goKioskService");
13     var $baseDir          = "../kiosk";
14     var $filesToAttach    = array();
15     var $cn               = "unknown";  
16     var $orig_cn          = "unknown";  
17     var $gotoKioskProfiles= array();
18     var $gotoKioskProfile = array();
19     var $server_path      = "http://%cn/kiosk";
21     function goKioskService(&$config, $dn, $parent)
22     {
23         goService::goService($config,$dn);
25         /* Get the current object name. 
26          */
27         if(isset($parent->parent->cn)){
28             $this->cn = &$parent->parent->cn;
29         }elseif(isset($this->attrs['cn'][0])){
30             $this->cn = $this->attrs['cn'][0];
31         }
32         $this->orig_cn = $this->cn;
34         $this->DisplayName = _("Kiosk profile service");
35         $this->baseDir = $this->config->get_cfg_value('environment', 'kioskPath');
36         $this->server_path = preg_replace("/%cn/", $this->cn, $this->server_path);
38         /* Load list of profiles and check if they still exists */
39         if ($this->baseDir == ""){
40         }else{
41             $this->gotoKioskProfiles = array();
42             if(isset($this->attrs['gotoKioskProfile']) && is_array($this->attrs['gotoKioskProfile'])){
43                 for($i = 0 ; $i < $this->attrs['gotoKioskProfile']['count']; $i ++){
44                     $url = $this->attrs['gotoKioskProfile'][$i];
45                     $this->server_path = preg_replace("/\/[^\/]*$/","",$url);
46                     $name= preg_replace("/^.*\//","",$url);
47                     $this->gotoKioskProfiles[] = array('url'     => $url , 
48                             'name'    => $name , 
49                             'initial' =>TRUE,
50                             'exists'  => file_exists($this->baseDir."/".$name));
51                 }
52             }
53         }
55         // Prepare lists
56         $this->kioskList = new sortableListing();
57         $this->kioskList->setDeleteable(true);
58         $this->kioskList->setInstantDelete(true);
59         $this->kioskList->setEditable(true);
60         $this->kioskList->setWidth("100%");
61         $this->kioskList->setHeight("200px");
62         $this->kioskList->setHeader(array(_("Profile")));
63         $this->kioskList->setColspecs(array('*','40px'));
64         $this->kioskList->setDefaultSortColumn(0);
65     }
68     function remove_from_parent()
69     {
70         $ldap = $this->config->get_ldap_link();
71         $ldap->cd($this->config->current['BASE']);
72         $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*/".$this->orig_cn."/*))",array("cn"));
73         if ($ldap->count() != 0){
74             $obj= array();
75             while($attrs = $ldap->fetch()){
76                 $obj[$ldap->getDN()]= $attrs['cn'][0];
77             }    
78             msg_dialog::display(_("Error"), msgPool::stillInUse(_("Kiosk profile service"), msgPool::buildList($obj)), ERROR_DIALOG);
79         }else{
80             goService::remove_from_parent();
81         }
82     }
85     function execute()
86     { 
87         /* log actions */
88         if($this->is_account && !$this->view_logged){
89             $this->view_logged = TRUE;
90             new log("view","server/".get_class($this),$this->dn);
91         }
93         /* Fill templating stuff */
94         $smarty= get_smarty();
95         $smarty->assign("baseDir", set_post($this->baseDir));
96         $smarty->assign("ThisACL", set_post($this->getacl("")));
97         $display= "";
99         /* Download kiosk profile 
100          */
101         $this->kioskList->save_object();
102         $action = $this->kioskList->getAction();
103         if($action['action'] == 'edit'){
104             $id = $this->kioskList->getKey($action['targets'][0]);
105             foreach($this->gotoKioskProfiles as $profile){
106                 $name = $this->baseDir."/".$this->gotoKioskProfiles[$id]['name'];
107                 if(file_exists($name)){
108                     $content = file_get_contents($name);    
109                     send_binary_content($content,$this->gotoKioskProfiles[$id]['name']);
110                 }else{
111                     msg_dialog::display(_("Warning"), sprintf(_("The profile does not exists '%s'!"),
112                                 $this->gotoKioskProfiles[$id]['name']), ERROR_DIALOG);
113                 }
114             }
115         }
118         /* Add new kiosk profile
119          * in profile directory ($this->baseDir);
120          */
121         if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile'])) && $this->acl_is_writeable("")){
122             $file = $_FILES['newProfile'];
123             if(!file_exists($this->baseDir.$file['name'])){
124                 $tmp = array(
125                         'url'     => "" ,
126                         'name'    => $file['name'] ,
127                         'initial' => FALSE,
128                         'tmp_name'=> $file['tmp_name'],
129                         'content' => file_get_contents($file['tmp_name']),
130                         'exists'  => TRUE);
133                 $used = array();
134                 foreach($this->gotoKioskProfiles as $k){
135                     $used[] = $k['name'];
136                 }  
137                 if(in_array($file['name'], $used)){
138                     msg_dialog::display(_("Warning"), msgPool::duplicated(_("Profile")), WARNING_DIALOG);
139                 }else{
140                     $this->gotoKioskProfiles[] = $tmp;
141                 }
142             }
143         }
145         if($action['action'] == 'delete' && $this->acl_is_writeable("")){
146             $id = $this->kioskList->getKey($action['targets'][0]);
147             $name = $this->gotoKioskProfiles[$id]['name'];
148             $filename = $this->baseDir."/".$name;
150             /* check if profile is still in use */
151             $ldap = $this->config->get_ldap_link();
152             $ldap->cd($this->config->current['BASE']);
153             $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*".$name.")",array("cn","uid","gotoKioskProfile"));
155             if ($ldap->count() != 0){
157                 $obj= array();
158                 $found= false;
159                 while(($attrs = $ldap->fetch()) && ($cnt)){
160                     $check = preg_replace("/^.*\//i","",$attrs['gotoKioskProfile'][0]);
161                     if($check == $name){
162                         $obj[$ldap->getDN()]= $attrs['cn'][0];
163                         $found= true;
164                     }
165                 }
167                 if ($found){
168                     msg_dialog::display(_("Error"), msgPool::stillInUse(_("Kiosk profile"), 
169                                 msgPool::buildList($obj)), ERROR_DIALOG);
170                 }
171             }else{
172                 if($this->gotoKioskProfiles[$id]['initial']){
173                     $res = @unlink($filename);
174                     if(!$res){
175                         if(!is_writeable($filename)){
176                             msg_dialog::display(_("Error"), msgPool::cannotDeleteFile($filename), ERROR_DIALOG);
177                         }
178                         if(!file_exists($filename)){
179                             msg_dialog::display(_("Error"), msgPool::fileDoesNotExist($filename), ERROR_DIALOG);
180                         }
181                     }
182                     unset($this->gotoKioskProfiles[$id]);
183                 }
184             }
185         }
187         /* Display list of profiles */
188         $this->kioskList->setAcl($this->getacl(""));
189         $lData = array();
190         foreach($this->gotoKioskProfiles as $key => $val ){
191             $lData[$key] = array('data' => array($val['name']));
192         }
193         $this->kioskList->setListData($this->gotoKioskProfiles, $lData);
194         $this->kioskList->update();
196         /* Assign all existing profiles to smarty */
197         $smarty->assign("kioskList",$this->kioskList->render());
198         $smarty = get_smarty(); 
199         foreach($this->attributes as $attr){
200             $smarty->assign($attr, set_post($this->$attr));
201         }
202         $smarty->assign("server_path", set_post($this->server_path));
203         return($smarty->fetch(get_template_path("goKioskService.tpl",TRUE,dirname(__FILE__))));
204     }
208     function getListEntry()
209     {
210         $fields = goService::getListEntry();
211         $fields['Message']    = _("Kiosk profile service");
212 #$fields['AllowEdit']  = TRUE;
213 #$fields['AllowStart']  = false;
214 #$fields['AllowStop']  = false;
215 #$fields['AllowRestart']  = false;
216         return($fields);
217     }
219     function check()
220     { 
221         $message = plugin::check();
222         return($message);
223     }
225     function save()
226     {
227         goService::save();
229         $method = $this->server_path."/";
230         $method = preg_replace("/\/\/*$/","/",$method);
231         $this->attrs['gotoKioskProfile'] = array();
232         foreach($this->gotoKioskProfiles as $profile){
233             if(!$profile['initial']){
235                 $contents = $profile['content'];
236                 $path = $this->baseDir."/".$profile['name'];
237                 $fp = @fopen($path,"w");
238                 if(!$fp){
239                     msg_dialog::display(_("Error"), msgPool::cannotWriteFile($path), ERROR_DIALOG);
240                 }else{
241                     fwrite($fp,$contents,strlen($contents));
242                     $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
243                 }
244                 @unlink($profile['tmp_name']);
245             }else{
246                 $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
247             }
248         }
249         $ldap = $this->config->get_ldap_link();
250         $ldap->cd($this->config->current['BASE']);
251         $ldap->cd($this->dn);
252         $ldap->modify($this->attrs);
253         if (!$ldap->success()){
254             msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
255         }
256     }
259     function save_object()
260     {
261         if(isset($_POST['goKioskPosted'])){
262             goService::save_object();
263             if(isset($_POST['server_path'])){
264                 $this->server_path = get_post("server_path");
265             }
266         }
267     }  
270     /* Return plugin informations for acl handling */
271     static function plInfo()
272     {
273         return (array(
274                     "plShortName"   => _("Kiosk"),
275                     "plDescription" => _("Kiosk profile management")." ("._("Services").")",
276                     "plSelfModify"  => FALSE,
277                     "plDepends"     => array(),
278                     "plPriority"    => 100,
279                     "plSection"     => array("administration"),
280                     "plCategory"    => array("server"),
281                     "plRequirements"=> array(
282                         'ldapSchema' => array('goEnvironmentServer' => '>=2.7'),
283                         'onFailureDisablePlugin' => array(get_class())
284                         ),
286                     "plProvidedAcls"=> array()
287                     ));
288     }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>