dc27c533356b0224c10a8eda49edfcf3ebcd23eb
[gosa.git] / branches / old / gosa-plugins / goto / admin / systems / services / kiosk / class_goKioskService.inc
1 <?php
3 class goKioskService extends goService{
5 /* This plugin only writes its objectClass */
6 var $objectclasses = array("goEnvironmentServer");
7 var $attributes = array("gotoKioskProfile");
8 var $StatusFlag = "";
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 $orig_cn = "unknown";
17 var $gotoKioskProfiles= array();
18 var $gotoKioskProfile = array();
19 var $server_path = "http://%cn/kiosk";
21 function goKioskService(&$config, $dn, $parent)
22 {
23 goService::goService($config,$dn);
25 /* Get the current object name.
26 */
27 if(isset($parent->parent->cn)){
28 $this->cn = &$parent->parent->cn;
29 }elseif(isset($this->attrs['cn'][0])){
30 $this->cn = $this->attrs['cn'][0];
31 }
32 $this->orig_cn = $this->cn;
34 $this->DisplayName = _("Kiosk profile service");
35 $this->baseDir = $this->config->search('environment', 'kioskpath',array('menu','tabs'));
36 $this->server_path = preg_replace("/%cn/", $this->cn, $this->server_path);
38 /* Load list of profiles and check if they still exists */
39 if ($this->baseDir == ""){
40 # msg_dialog::display(_("Configuration error"),
41 # msgPool::cmdnotfound("KIOSKPATH",_("Kiosk profile service")), ERROR_DIALOG);
42 }else{
43 $this->gotoKioskProfiles = array();
44 if(isset($this->attrs['gotoKioskProfile']) && is_array($this->attrs['gotoKioskProfile'])){
45 for($i = 0 ; $i < $this->attrs['gotoKioskProfile']['count']; $i ++){
46 $url = $this->attrs['gotoKioskProfile'][$i];
47 $this->server_path = preg_replace("/\/[^\/]*$/","",$url);
48 $name= preg_replace("/^.*\//","",$url);
49 $this->gotoKioskProfiles[] = array('url' => $url ,
50 'name' => $name ,
51 'initial' =>TRUE,
52 'exists' => file_exists($this->baseDir."/".$name));
53 }
54 }
55 }
56 }
59 function remove_from_parent()
60 {
61 $ldap = $this->config->get_ldap_link();
62 $ldap->cd($this->config->current['BASE']);
63 $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*/".$this->orig_cn."/*))",array("cn"));
64 if ($ldap->count() != 0){
65 $obj= array();
66 while($attrs = $ldap->fetch()){
67 $obj[$ldap->getDN()]= $attrs['cn'][0];
68 }
69 msg_dialog::display(_("Error"), msgPool::stillInUse(_("Kiosk profile service"), msgPool::buildList($obj)), ERROR_DIALOG);
70 }else{
71 goService::remove_from_parent();
72 }
73 }
76 function execute()
77 {
78 /* log actions */
79 if($this->is_account && !$this->view_logged){
80 $this->view_logged = TRUE;
81 new log("view","server/".get_class($this),$this->dn);
82 }
84 /* Fill templating stuff */
85 $smarty= get_smarty();
86 $smarty->assign("baseDir",$this->baseDir);
87 $smarty->assign("ThisACL",$this->getacl(""));
88 $display= "";
90 /* Download kiosk profile
91 */
92 if(isset($_GET['getkiosk'])){
93 $id = $_GET['getkiosk'];
95 foreach($this->gotoKioskProfiles as $profile){
96 if($profile['name'] == $id){
97 $name = $this->baseDir."/".$id;
98 if(file_exists($name)){
99 $content = file_get_contents($name);
100 send_binary_content($content,$id);
101 }
102 }
103 }
104 }
107 /* Add new kiosk profile
108 * in profile directory ($this->baseDir);
109 */
110 if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile'])) && $this->acl_is_writeable("")){
111 $file = $_FILES['newProfile'];
112 if(!file_exists($this->baseDir.$file['name'])){
113 $tmp = array(
114 'url' => "" ,
115 'name' => $file['name'] ,
116 'initial' => FALSE,
117 'tmp_name'=> $file['tmp_name'],
118 'content' => file_get_contents($file['tmp_name']),
119 'exists' => TRUE);
120 $this->gotoKioskProfiles[] = $tmp;
121 }
122 }
124 $only_once = true;
125 foreach($_POST as $name => $value){
127 if((preg_match("/^delkiosk_/",$name))&&($only_once) && $this->acl_is_writeable("")){
129 /* Get id, name and path */
130 $only_once = false;
131 $id = preg_replace("/^delkiosk_/","",$name);
132 $id = preg_replace("/_.*$/","",$id);
133 $name = $this->gotoKioskProfiles[$id]['name'];
134 $filename = $this->baseDir."/".$name;
136 /* check if profile is still in use */
137 $ldap = $this->config->get_ldap_link();
138 $ldap->cd($this->config->current['BASE']);
139 $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*".$name.")",array("cn","uid","gotoKioskProfile"));
141 if ($ldap->count() != 0){
143 $obj= array();
144 $found= false;
145 while(($attrs = $ldap->fetch()) && ($cnt)){
146 $check = preg_replace("/^.*\//i","",$attrs['gotoKioskProfile'][0]);
147 if($check == $name){
148 $obj[$ldap->getDN()]= $attrs['cn'][0];
149 $found= true;
150 }
151 }
153 if ($found){
154 msg_dialog::display(_("Error"), msgPool::stillInUse(_("Kiosk profile"), msgPool::buildList($obj)), ERROR_DIALOG);
155 }
156 }else{
157 if($this->gotoKioskProfiles[$id]['initial']){
158 $res = @unlink($filename);
159 if(!$res){
160 if(!is_writeable($filename)){
161 msg_dialog::display(_("Error"), msgPool::cannotDeleteFile($filename), ERROR_DIALOG);
162 }
163 if(!file_exists($filename)){
164 msg_dialog::display(_("Error"), msgPool::fileDoesNotExist($filename), ERROR_DIALOG);
165 }
166 }
167 unset($this->gotoKioskProfiles[$id]);
168 }
169 }
170 }
171 }
173 /* Display list of profiles */
174 $divlist = new divSelectBox("KioskProfiles");
175 $divlist -> SetHeight (300);
178 foreach($this->gotoKioskProfiles as $key => $val ){
179 $del = " ";
180 if($this->acl_is_writeable("")){
181 $del = "<input type='image' src='images/lists/trash.png'
182 class='center' alt='delete' name='delkiosk_".$key."'>";
183 }
184 $divlist->AddEntry(array(
185 array("string"=>"<a href='?plug=".$_GET['plug']."&getkiosk=".$val['name']."'>".$val['name']."</a>"),
186 array("string"=>$del,
187 "attach"=>" style='border-right: 0px;width:24px; text-align:center;' ")
188 ));
189 }
191 /* Assign all existing profiles to smarty */
192 $smarty->assign("divlist",$divlist->DrawList());
193 $smarty = get_smarty();
194 foreach($this->attributes as $attr){
195 $smarty->assign($attr,$this->$attr);
196 }
197 $smarty->assign("server_path",$this->server_path);
198 return($smarty->fetch(get_template_path("goKioskService.tpl",TRUE,dirname(__FILE__))));
199 }
203 function getListEntry()
204 {
205 $fields = goService::getListEntry();
206 $fields['Message'] = _("Kiosk profile service");
207 #$fields['AllowEdit'] = TRUE;
208 #$fields['AllowStart'] = false;
209 #$fields['AllowStop'] = false;
210 #$fields['AllowRestart'] = false;
211 return($fields);
212 }
214 function check()
215 {
216 $message = plugin::check();
217 return($message);
218 }
220 function save()
221 {
222 goService::save();
224 $method = $this->server_path."/";
225 $method = preg_replace("/\/\/*$/","/",$method);
226 $this->attrs['gotoKioskProfile'] = array();
227 foreach($this->gotoKioskProfiles as $profile){
228 if(!$profile['initial']){
230 $contents = $profile['content'];
231 $path = $this->baseDir."/".$profile['name'];
232 $fp = @fopen($path,"w");
233 if(!$fp){
234 msg_dialog::display(_("Error"), msgPool::cannotWriteFile($path), ERROR_DIALOG);
235 }else{
236 fwrite($fp,$contents,strlen($contents));
237 $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
238 }
239 @unlink($profile['tmp_name']);
240 }else{
241 $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
242 }
243 }
244 $ldap = $this->config->get_ldap_link();
245 $ldap->cd($this->config->current['BASE']);
246 $ldap->cd($this->dn);
247 $ldap->modify($this->attrs);
248 if (!$ldap->success()){
249 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
250 }
251 }
254 function save_object()
255 {
256 if(isset($_POST['goKioskPosted'])){
257 goService::save_object();
258 if(isset($_POST['server_path'])){
259 $this->server_path = get_post("server_path");
260 }
261 }
262 }
265 /* Return plugin informations for acl handling */
266 static function plInfo()
267 {
268 return (array(
269 "plShortName" => _("Kiosk"),
270 "plDescription" => _("Kiosk profile management")." ("._("Services").")",
271 "plSelfModify" => FALSE,
272 "plDepends" => array(),
273 "plPriority" => 100,
274 "plSection" => array("administration"),
275 "plCategory" => array("server"),
277 "plProvidedAcls"=> array()
278 ));
279 }
280 }
281 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
282 ?>