Code

Updated directory layout
[gosa.git] / plugins / admin / systems / services / kiosk / class_goKioskService.inc
1 <?php
3 class goKioskService extends goService{
4         
5   /* This plugin only writes its objectClass */
6   var $objectclasses    = array("goEnvironmentServer");
7   var $attributes       = array("gotoKioskProfile","cn");
8   var $StatusFlag       = "";
9  
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 $gotoKioskProfiles= array();
17   var $gotoKioskProfile = array();
19   var $server_path      = "http://%cn/kiosk";
20  
21   function goKioskService(&$config,$dn)
22   {
23     goService::goService($config,$dn);
25     $this->DisplayName = _("Kiosk profile service");
26     $this->baseDir = $this->config->search('environment', 'kioskpath',array('menu','tabs'));
27     $this->server_path = preg_replace("/%cn/", $this->cn, $this->server_path);
29     /* Load list of profiles and check if they still exists */
30     if ($this->baseDir == ""){
31       print_red(_("There is no KIOSKPATH defined in your gosa.conf. Can't manage kiosk profiles!"));
32     }else{
33       $this->gotoKioskProfiles = array();
34       if(isset($this->attrs['gotoKioskProfile']) && is_array($this->attrs['gotoKioskProfile'])){
35         for($i = 0 ; $i < $this->attrs['gotoKioskProfile']['count']; $i ++){
36           $url = $this->attrs['gotoKioskProfile'][$i];
37           $this->server_path = preg_replace("/\/[^\/]*$/","",$url);
38           $name= preg_replace("/^.*\//","",$url);
39           $this->gotoKioskProfiles[] = array('url'     => $url , 
40                                             'name'    => $name , 
41                                             'initial' =>TRUE,
42                                             'exists'  => file_exists($this->baseDir."/".$name));
43         }
44       }
45     }
46   }
49   function remove_from_parent()
50   {
51     $ldap = $this->config->get_ldap_link();
52     $ldap->cd($this->config->current['BASE']);
53     $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*/".$this->cn."/*))",array("cn"));
54     $str ="";
55     $cnt = 3;
56     while($cnt && $attrs = $ldap->fetch()){
57       $str .= $attrs['cn'][0].", ";
58       $cnt --;
59     }    
60     $str = preg_replace("/, $/","",$str);
61     if($cnt != 3){
62       print_red(sprintf(_("Can not remove kiosk profile service, it is currently in use by following user(s) : %s."),$str));
63     }else{
64       goService::remove_from_parent();
65     }
66   }
67   
68   
69   function execute()
70   { 
71     /* log actions */
72     if($this->is_account && !$this->view_logged){
73       $this->view_logged = TRUE;
74       new log("view","server/".get_class($this),$this->dn);
75     }
77     /* Fill templating stuff */
78     $smarty= get_smarty();
79     $display= "";
81     /* Add new kiosk profile
82      * in profile directory ($this->baseDir);
83      */
84     if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile']))){
85       $file = $_FILES['newProfile'];
86       if(!file_exists($this->baseDir.$file['name'])){
87         $tmp = array(
88             'url'     => "" ,
89             'name'    => $file['name'] ,
90             'initial' => FALSE,
91             'tmp_name'=> $file['tmp_name'],
92             'content' => file_get_contents($file['tmp_name']),
93             'exists'  => TRUE);
94         $this->gotoKioskProfiles[] = $tmp;
95       }
96       if(!is_writeable($this->baseDir)){
97         print_red(sprintf(_("Can't save new kiosk profiles, possibly permission denied for folder: '%s'."),$this->baseDir));
98       }
99     }
101     $only_once = true;
102     foreach($_POST as $name => $value){
104       if((preg_match("/^delkiosk_/",$name))&&($only_once)){
105   
106         /* Get id, name and path */
107         $only_once = false;
108         $id = preg_replace("/^delkiosk_/","",$name);
109         $id = preg_replace("/_.*$/","",$id);
110         $name = $this->gotoKioskProfiles[$id]['name'];
111         $filename = $this->baseDir."/".$name;
113         /* check if profile is still in use */
114         $ldap = $this->config->get_ldap_link();
115         $ldap->cd($this->config->current['BASE']);
116         $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*".$name.")",array("cn","uid","gotoKioskProfile"));
117         $used_by = "";
118         $cnt = 3;
119         while(($attrs = $ldap->fetch()) && ($cnt)){
120           $cnt --;
121           $check = preg_replace("/^.*\//i","",$attrs['gotoKioskProfile'][0]);
122           if($check == $name){
123             $used_by .= $attrs['cn'][0].", ";
124           }
125         }
126         $used_by = preg_replace("/, $/","",$used_by);
127         if(!empty($used_by)){
128           print_red(sprintf(_("Can't remove kioks profile, it is still in use by the following objects '%s'."),$used_by));
129         }else{
130           if($this->gotoKioskProfiles[$id]['initial']){
131             $res = @unlink($filename);
132             if(!$res){
133               if(!is_writeable($filename)){
134                 print_red(sprintf(_("Can't delete '%s'. Error was: permission denied."), $filename));
135               }
136               if(!file_exists($filename)){
137                 print_red(sprintf(_("Can't delete '%s'. Error was: file doesn't exist."), $filename));
138               }
139             }
140             unset($this->gotoKioskProfiles[$id]);
141           }
142         }
143       }
144     }
146     /* Display list of profiles */
147     $divlist = new divSelectBox("KioskProfiles");
148     $divlist -> SetHeight (300);
149     foreach($this->gotoKioskProfiles as $key => $val ){
150       $divlist->AddEntry(array(
151             array("string"=>"<a target='_blank' href='getkiosk.php?id=".$val['name']."'>".$val['name']."</a>"),
152             array("string"=>"<input type='image' src='images/edittrash.png'
153               class='center' alt='delete' name='delkiosk_".$key."'>" ,
154               "attach"=>" style='border-right: 0px;width:24px; text-align:center;' ")
155             ));
156     }
158     /* Assign all existing profiles to smarty */
159     $smarty->assign("divlist",$divlist->DrawList());
160     $smarty = get_smarty(); 
161     foreach($this->attributes as $attr){
162       $smarty->assign($attr,$this->$attr);
163     }
164     $smarty->assign("server_path",$this->server_path);
165     return($smarty->fetch(get_template_path("goKioskService.tpl",TRUE,dirname(__FILE__))));
166   }
168   function getListEntry()
169   {
170     $fields = goService::getListEntry();
171     $fields['Message']    = _("Kiosk profile service");
172     $fields['AllowEdit']  = TRUE;
173     $fields['AllowStart']  = false;
174     $fields['AllowStop']  = false;
175     $fields['AllowRestart']  = false;
176     return($fields);
177   }
179   function check()
180   { 
181     $message = plugin::check();
182     return($message);
183   }
185   function save()
186   {
187     goService::save();
189     $method = $this->server_path."/";
190     $method = preg_replace("/\/\/*$/","/",$method);
191     $this->attrs['gotoKioskProfile'] = array();
192     foreach($this->gotoKioskProfiles as $profile){
193       if(!$profile['initial']){
195         $contents = $profile['content'];
196         $path = $this->baseDir."/".$profile['name'];
197         $fp = @fopen($path,"w");
198         if(!$fp){
199           print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
200         }else{
201           fwrite($fp,$contents,strlen($contents));
202           $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
203         }
204         @unlink($profile['tmp_name']);
205       }else{
206         $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
207       }
208     }
209     $ldap = $this->config->get_ldap_link();
210     $ldap->cd($this->config->current['BASE']);
211     $ldap->cd($this->dn);
212     $ldap->modify($this->attrs);
213     show_ldap_error($ldap->get_error(),_("Wohl kaum"));
214   }
216   
217   function save_object()
218   {
219     if(isset($_POST['goKioskPosted'])){
220       goService::save_object();
221       if(isset($_POST['server_path'])){
222         $this->server_path = get_post("server_path");
223       }
224     }
225   }  
228   /* Return plugin informations for acl handling */
229   static function plInfo()
230   {
231     return (array(
232           "plShortName"   => _("Kiosk"),
233           "plDescription" => _("Kiosk profile management")." ("._("Services").")",
234           "plSelfModify"  => FALSE,
235           "plDepends"     => array(),
236           "plPriority"    => 100,
237           "plSection"     => array("administration"),
238           "plCategory"    => array("server"),
240           "plProvidedAcls"=> array()
241           ));
242   }
244 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
245 ?>