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 }
51 $only_once = true;
52 foreach($_POST as $name => $value){
54 if((preg_match("/^delkiosk_/",$name))&&($only_once)){
55 $only_once = false;
56 $id = preg_replace("/^delkiosk_/","",$name);
57 $id = preg_replace("/_.*$/","",$id);
59 $name = preg_replace("/^.*\//i","",base64_decode($id));
61 $filename = $this->baseDir."/".$name;
63 /* check if profile is still in use */
64 $ldap = $this->config->get_ldap_link();
65 $ldap->cd($this->config->current['BASE']);
66 $ldap->search("(gotoKioskProfile=*lhs.schema*)",array("cn","uid","gotoKioskProfile"));
67 $used_by = "";
68 $cnt = 3;
69 while(($attrs = $ldap->fetch()) && ($cnt)){
70 $cnt --;
71 $check = preg_replace("/^.*\//i","",$attrs['gotoKioskProfile'][0]);
72 if($check == $name){
73 $used_by .= $attrs['cn'][0].", ";
74 }
75 }
76 $used_by = preg_replace("/, $/","",$used_by);
78 if(!empty($used_by)){
79 print_red(sprintf(_("Can't remove kiosk profile, it is still in use by the following objects '%s'."),$used_by));
80 }elseif(isset($this->filesToAttach[$name])){
81 unset($this->filesToAttach[$name]);
82 }else{
84 $res = @unlink($filename);
85 if(!$res){
86 if(!is_writeable($filename)){
87 print_red(sprintf(_("Can't delete '%s'. Error was: permission denied."), $filename));
88 }
89 if(!file_exists($filename)){
90 print_red(sprintf(_("Can't delete '%s'. Errow was: file doesn't exist."), $filename));
91 }
92 }
93 }
94 }
95 }
97 /* Delete profile
98 * Delete selected file form $this->baseDir
99 */
100 if((isset($_POST['profileDel']))&&(isset($_POST['gotoKioskProfile']))){
101 $filename = $this->baseDir."/".preg_replace("/^.*\//i","",$_POST['gotoKioskProfile']);
103 $res = @unlink($filename);
104 if(!$res){
105 if(!is_writeable($filename)){
106 print_red(sprintf(_("Can't delete '%s'. Error was: permission denied."), $filename));
107 }
108 if(!file_exists($filename)){
109 print_red(sprintf(_("Can't delete '%s'. Errow was: file doesn't exist."), $filename));
110 }
112 }
113 }
115 $divlist = new divSelectBox("KioskProfiles");
116 $divlist -> SetHeight (300);
118 $tmp = $this->getKioskProfiles();
120 foreach($tmp as $val ){
121 $divlist->AddEntry(array(
122 array("string"=>"<a target='_blank' href='getkiosk.php?id=".$val."'>".$val."</a>"),
123 array("string"=>"<input type='image' src='images/edittrash.png' class='center' alt='delete' name='delkiosk_".base64_encode($val)."'>" ,
124 "attach"=>" style='border-right: 0px;width:24px; text-align:center;' ")
125 ));
126 }
129 /*Assign all existing profiles to smarty*/
132 $smarty->assign("divlist",$divlist->DrawList());
134 $smarty->assign("gotoKioskProfiles",$this->getKioskProfiles());
135 $smarty->assign("gotoKioskProfileKeys",array_flip($this->getKioskProfiles()));
137 $display.= $smarty->fetch(get_template_path('kioskManagement.tpl', TRUE,dirname(__FILE__)));
138 return($display);
139 }
141 function save(){
142 return($this->filesToAttach);
143 }
145 function getKioskProfiles($attach = false)
146 {
147 $a_return = array();
149 /* Empty? */
150 if ($this->baseDir == ""){
151 print_red(_("There is no KIOSKPATH defined in your gosa.conf. Can't manage kiosk profiles!"));
152 return ($a_return);
153 }
155 $dir = @opendir($this->baseDir);
156 if(!$dir){
157 print_red(sprintf(_("Kiosk path '%s' is not accessible. Please check the permissions."),$this->baseDir));
158 }else{
159 $a_return = array();
160 while($file = readdir($dir)){
161 if(!preg_match("/^\./", $file)){
162 $name = $file;
163 $a_return[$name] = $name;
164 }
165 }
166 }
168 foreach($this->filesToAttach as $file){
169 $a_return[$file['name']] = $file['name'];
170 }
172 if($attach){
173 foreach($attach as $file){
174 $a_return[$file['name']] = $file['name'];
175 }
176 }
178 return($a_return);
179 }
181 }
182 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
183 ?>