Code

1c8b3fc7e8edb16b14196065d2837f377fedf85d
[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("filesToAttach");
13   var $objectclasses        = array("whatever");
14   var $use_existing         = false;  
15   var $filesToAttach        = array();
17   var $baseDir              = "../kiosk/";
19   function kioskManagementDialog ($config, $dn= NULL,$attach=false )
20   {
21     $this->config= $config;
22     $this->dn= $dn;
24     if($attach){
25       $this->filesToAttach = $attach;
26     }
27     $this->baseDir = search_config($this->config->data,"environment", "KIOSKPATH");
28   }
30   function execute()
31   {
32     /* Call parent execute */
33     plugin::execute();
35     /* Fill templating stuff */
36     $smarty= get_smarty();
37     $display= "";
39     /* Add new kiosk profile 
40      * in profile directory ($this->baseDir); 
41      */
42     if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile']))){
43       $file = $_FILES['newProfile'];
44       if(!file_exists($this->baseDir.$file['name'])){
45         $this->filesToAttach[$file['name']]=$file;
46         $this->filesToAttach[$file['name']]['contents'] = file_get_contents($file['tmp_name']);
47       }
48     }
50     $only_once = true;
51     foreach($_POST as $name => $value){
53       if((preg_match("/^delkiosk_/",$name))&&($only_once)){
54         $only_once = false;
55         $id  = preg_replace("/^delkiosk_/","",$name);
56         $id = preg_replace("/_.*$/","",$id);
58         $name = preg_replace("/^.*\//i","",base64_decode($id));
60         $filename = $this->baseDir."/".$name;
61    
62         /* check if profile is still in use */ 
63         $ldap = $this->config->get_ldap_link();
64         $ldap->cd($this->config->current['BASE']);
65         $ldap->search("(gotoKioskProfile=*lhs.schema*)",array("cn","uid","gotoKioskProfile"));
66         $used_by = "";
67         $cnt = 3;
68         while(($attrs = $ldap->fetch()) && ($cnt)){
69           $cnt --;
70           $check = preg_replace("/^.*\//i","",$attrs['gotoKioskProfile'][0]);
71           if($check == $name){
72             $used_by .= $attrs['cn'][0].", ";
73           }
74         }
75         $used_by = preg_replace("/, $/","",$used_by);
77         if(!empty($used_by)){
78           print_red(sprintf(_("Can't remove kioks profile, it is still in use by the following objects '%s'."),$used_by));
79         }elseif(isset($this->filesToAttach[$name])){
80           unset($this->filesToAttach[$name]);
81         }else{
83           $res = @unlink($filename);
84           if(!$res){
85             if(!is_writeable($filename)){
86               print_red(sprintf(_("Can't delete '%s'. Error was: permission denied."), $filename));
87             }
88             if(!file_exists($filename)){
89               print_red(sprintf(_("Can't delete '%s'. Error was: file doesn't exist."), $filename));
90             }
91           }
92         }
93       }
94     }
95      
96     /* Delete profile
97      * Delete selected file form $this->baseDir
98      */
99     if((isset($_POST['profileDel']))&&(isset($_POST['gotoKioskProfile']))){
100       $filename = $this->baseDir."/".preg_replace("/^.*\//i","",$_POST['gotoKioskProfile']);
101   
102       $res = @unlink($filename);
103       if(!$res){
104         if(!is_writeable($filename)){
105           print_red(sprintf(_("Can't delete '%s'. Error was: permission denied."), $filename));
106         }
107         if(!file_exists($filename)){
108           print_red(sprintf(_("Can't delete '%s'. Error was: file doesn't exist."), $filename));
109         }
110       
111       }
112     }
114     $divlist = new divSelectBox("KioskProfiles");
115     $divlist -> SetHeight (300);
117     $tmp = $this->getKioskProfiles();
119     foreach($tmp as $val ){
120       $divlist->AddEntry(array(
121                           array("string"=>"<a target='_blank' href='getkiosk.php?id=".$val."'>".$val."</a>"),
122                           array("string"=>"<input type='image' src='images/edittrash.png' class='center' alt='delete' name='delkiosk_".base64_encode($val)."'>" , 
123                                 "attach"=>" style='border-right: 0px;width:24px; text-align:center;' ")
124                               )); 
125     }
126       
128     /*Assign all existing profiles to smarty*/
131     $smarty->assign("divlist",$divlist->DrawList());
133     $smarty->assign("gotoKioskProfiles",$this->getKioskProfiles());
134     $smarty->assign("gotoKioskProfileKeys",array_flip($this->getKioskProfiles()));
136     $display.= $smarty->fetch(get_template_path('kioskManagement.tpl', TRUE,dirname(__FILE__)));
137     return($display);
138   }
140   function save(){
141     return($this->filesToAttach);
142   }
144   function getKioskProfiles($attach = false)
145   {
146     $a_return = array();
147     
148     /* Empty? */
149     if ($this->baseDir == ""){
150       print_red(_("There is no KIOSKPATH defined in your gosa.conf. Can't manage kiosk profiles!"));
151       return ($a_return);
152     }
153     
154     $dir = @opendir($this->baseDir);
155     if(!$dir){
156       print_red(sprintf(_("Kiosk path '%s' is not accessible. Please check the permissions."),$this->baseDir));
157     }else{
158       $a_return = array();
159       while($file = readdir($dir)){
160         if(!preg_match("/^\./", $file)){
161           $name = $file;
162           $a_return[$name] = $name;
163         }
164       }
165     }
167     foreach($this->filesToAttach as $file){
168       $a_return[$file['name']] = $file['name'];
169     }
171     if($attach){
172       foreach($attach as $file){
173         $a_return[$file['name']] = $file['name'];
174       }
175     }
177     return($a_return);
178   }
181 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
182 ?>