Code

Add vacation message stuff
[gosa.git] / plugins / personal / environment / class_kioskManagementDialog.inc
1 <?php
3 class kioskManagementDialog extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account       = TRUE;
7   var $attributes           = array("filesToAttach");
8   var $objectclasses        = array("whatever");
9   var $use_existing         = false;  
10   var $filesToAttach        = array();
12   var $baseDir              = "../kiosk/";
14   function kioskManagementDialog ($config, $dn= NULL,$attach=false )
15   {
16     $this->config= $config;
17     $this->dn= $dn;
19     if($attach){
20       $this->filesToAttach = $attach;
21     }
22     $this->baseDir = search_config($this->config->data,"environment", "KIOSKPATH");
23   }
25   function execute()
26   {
27         /* Call parent execute */
28         plugin::execute();
30     /* Fill templating stuff */
31     $smarty= get_smarty();
32     $display= "";
34     $smarty->assign("gotoKioskProfileACL",chkacl($this->acl,"gotoKioskProfile"));
36     foreach($this->attributes as $attr){
37       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
38     }
40     /* Add new kiosk profile 
41      * in profile directory ($this->baseDir); 
42      */
43     if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile']))){
44       $file = $_FILES['newProfile'];
45       if(!file_exists($this->baseDir.$file['name'])){
46         $this->filesToAttach[$file['name']]=$file;
47         $this->filesToAttach[$file['name']]['contents'] = file_get_contents($file['tmp_name']);
48       }
49     }
50      
51     $only_once = true;
52     foreach($_POST as $name => $value){
53       
54       if((preg_match("/^delkiosk_/",$name))&&($only_once)){
55         $only_once = false;
56         $id  = preg_replace("/^delkiosk_/","",$name);
57         $id = preg_replace("/_.*$/","",$id);
58     
59         $name = preg_replace("/^.*\//i","",base64_decode($id));
60         
61         $filename = $this->baseDir."/".$name;
63         if(isset($this->filesToAttach[$name])){
64           unset($this->filesToAttach[$name]);
65         }else{
67           $res = @unlink($filename);
68           if(!$res){
69             if(!is_writeable($filename)){
70               print_red(sprintf(_("Can't delete '%s'. Error was: permission denied."), $filename));
71             }
72             if(!file_exists($filename)){
73               print_red(sprintf(_("Can't delete '%s'. Errow was: file doesn't exist."), $filename));
74             }
75           }
76         }
77       }
78     }
80     /* Delete profile
81      * Delete selected file form $this->baseDir
82      */
83     if((isset($_POST['profileDel']))&&(isset($_POST['gotoKioskProfile']))){
84       $filename = $this->baseDir."/".preg_replace("/^.*\//i","",$_POST['gotoKioskProfile']);
85   
86       $res = @unlink($filename);
87       if(!$res){
88         if(!is_writeable($filename)){
89           print_red(sprintf(_("Can't delete '%s'. Error was: permission denied."), $filename));
90         }
91         if(!file_exists($filename)){
92           print_red(sprintf(_("Can't delete '%s'. Errow was: file doesn't exist."), $filename));
93         }
94       
95       }
96     }
98     $divlist = new divSelectBox("KioskProfiles");
99     $divlist -> SetHeight (300);
101     $tmp = $this->getKioskProfiles();
103     foreach($tmp as $val ){
104       $divlist->AddEntry(array(
105                           array("string"=>"<a target='_blank' href='getkiosk.php?id=".$val."'>".$val."</a>"),
106                           array("string"=>"<input type='image' src='images/edittrash.png' class='center' alt='delete' name='delkiosk_".base64_encode($val)."'>" , 
107                                 "attach"=>" style='border-right: 0px;width:24px; text-align:center;' ")
108                               )); 
109     }
110       
112     /*Assign all existing profiles to smarty*/
115     $smarty->assign("divlist",$divlist->DrawList());
117     $smarty->assign("gotoKioskProfiles",$this->getKioskProfiles());
118     $smarty->assign("gotoKioskProfileKeys",array_flip($this->getKioskProfiles()));
120     $display.= $smarty->fetch(get_template_path('kioskManagement.tpl', TRUE,dirname(__FILE__)));
121     return($display);
122   }
124   function save(){
125     return($this->filesToAttach);
126   }
128   function getKioskProfiles($attach = false)
129   {
130     $a_return = array();
131     
132     /* Empty? */
133     if ($this->baseDir == ""){
134       print_red(_("There is no KIOSKPATH defined in your gosa.conf. Can't manage kiosk profiles!"));
135       return ($a_return);
136     }
137     
138     $dir = @opendir($this->baseDir);
139     if(!$dir){
140       print_red(sprintf(_("Kiosk path '%s' is not accessible. Please check the permissions."),$this->baseDir));
141     }else{
142       $a_return = array();
143       while($file = readdir($dir)){
144         if(!preg_match("/^\./", $file)){
145           $name = $file;
146           $a_return[$name] = $name;
147         }
148       }
149     }
151     foreach($this->filesToAttach as $file){
152       $a_return[$file['name']] = $file['name'];
153     }
155     if($attach){
156       foreach($attach as $file){
157         $a_return[$file['name']] = $file['name'];
158       }
159     }
161     return($a_return);
162   }
165 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
166 ?>