Code

Some Fixes for environment, added icon for userlist
[gosa.git] / plugins / personal / environment / class_kioskManagementDialog.inc
1 <?php
3 class kioskManagementDialog 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   /* attribute list for save action */
11   var $ignore_account       = TRUE;
12   var $attributes           = array();
13   var $objectclasses        = array("whatever");
14   var $use_existing         = false;  
16   var $baseDir              = "../kioskProfiles/";
17   var $filePrefix           = ".kioskProfile";
19   function kioskManagementDialog ($config, $dn= NULL,$use_existing=false )
20   {
21     $this->use_existing = $use_existing;
22     plugin::plugin ($config, $dn);
23   }
25   function execute()
26   {
27     /* Fill templating stuff */
28     $smarty= get_smarty();
29     $display= "";
31     /* Add new kiosk profile 
32      * Save the new Profile with filePrefix ($this->filePrefix)
33      * in profile directory ($this->baseDir); 
34      */
35     if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile']))){
36       $file = $_FILES['newProfile'];
37       if(!file_exists($this->baseDir.$file['name'])){
38         $name = preg_replace("/\..*$/","",$file['name']).$this->filePrefix;
39         $str  = file_get_contents($file['tmp_name']);
40         $fp   = @fopen($this->baseDir.$name,"w+");
41         if($fp){
42           fwrite($fp,$str,strlen($str));
43           fclose($fp);
44         }else{
45           print_red(_("Can't save kioskProfile. Permission denied.")." ".$this->baseDir);
46         }
47         unlink($file['tmp_name']);;
48       }
49     }
50       
51     /* Delete profile
52      * Delete selected file form $this->baseDir
53      */
54     if((isset($_POST['profileDel']))&&(isset($_POST['gotoKioskProfile']))){
55       $filename = $this->baseDir.$_POST['gotoKioskProfile'].$this->filePrefix;
56   
57       $res = @unlink($filename);
58       if(!$res){
59         if(!is_writeable($filename)){
60           print_red(_("Can't delete '".$filename."' permission denied."));
61         }
62         if(!file_exists($filename)){
63           print_red(_("Can't delete '".$filename."' file don't exists."));
64         }
65       
66       }
67     }
69     /*Assign all existing profiles to smarty*/
70     $smarty->assign("gotoKioskProfiles",$this->getKioskProfiles());
71     $smarty->assign("gotoKioskProfileKeys",array_flip($this->getKioskProfiles()));
73     $display.= $smarty->fetch(get_template_path('kioskManagement.tpl', TRUE,dirname(__FILE__)));
74     return($display);
75   }
77   function getKioskProfiles()
78   {
79     $dir = opendir($this->baseDir);
80     if(!file_exists($this->baseDir)){
81       mkdir($this->baseDir);
82     }
83     $a_return = array();
84     while($file = readdir($dir)){
85       if(preg_match("/".$this->filePrefix."$/i",$file)){
86         $name = preg_replace("/".$this->filePrefix."$/i","",$file);;
87         $a_return[$name] = $name;
88       }
89     }
90     return($a_return);
91   }
93 }
94 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
95 ?>