Code

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