Code

Added Kiosk service
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 8 Oct 2007 10:58:52 +0000 (10:58 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 8 Oct 2007 10:58:52 +0000 (10:58 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7453 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_goKioskService.inc [new file with mode: 0644]
plugins/admin/systems/goKioskService.tpl [new file with mode: 0644]

diff --git a/plugins/admin/systems/class_goKioskService.inc b/plugins/admin/systems/class_goKioskService.inc
new file mode 100644 (file)
index 0000000..0635192
--- /dev/null
@@ -0,0 +1,214 @@
+<?php
+
+class goKioskService extends goService{
+       
+  /* This plugin only writes its objectClass */
+  var $objectclasses    = array("goEnvironmentServer");
+  var $attributes       = array("gotoKioskProfile");
+  var $StatusFlag       = "";
+  /* This class can't be assigned twice so it conflicts with itsself */
+  var $conflicts        = array("goKioskService");
+
+  var $baseDir          = "../kiosk";
+  var $filesToAttach    = array();
+  var $cn               = "unknown";  
+  var $gotoKioskProfiles = array();
+  var $gotoKioskProfile  = array();
+  function goKioskService(&$config,$dn)
+  {
+    goService::goService($config,$dn);
+
+    $this->DisplayName = _("Kiosk profile service");
+    $this->baseDir = $this->config->search('environment', 'kioskpath',array('menu','tabs'));
+
+    /* Load list of profiles and check if they still exists */
+    if ($this->baseDir == ""){
+      print_red(_("There is no KIOSKPATH defined in your gosa.conf. Can't manage kiosk profiles!"));
+    }else{
+      $this->gotoKioskProfiles = array();
+      if(isset($this->attrs['gotoKioskProfile']) && is_array($this->attrs['gotoKioskProfile'])){
+        for($i = 0 ; $i < $this->attrs['gotoKioskProfile']['count']; $i ++){
+          $url = $this->attrs['gotoKioskProfile'][$i];
+          $name= preg_replace("/^.*\/kiosk\//","",$url);
+
+          $this->gotoKioskProfiles[] = array('url'     => $url , 
+                                            'name'    => $name , 
+                                            'initial' =>TRUE,
+                                            'exists'  => file_exists($this->baseDir."/".$name));
+        }
+      }
+    }
+  }
+
+    
+  function execute()
+  { 
+    /* log actions */
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","server/".get_class($this),$this->dn);
+    }
+
+    /* Fill templating stuff */
+    $smarty= get_smarty();
+    $display= "";
+
+    /* Add new kiosk profile
+     * in profile directory ($this->baseDir);
+     */
+    if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile']))){
+      $file = $_FILES['newProfile'];
+      if(!file_exists($this->baseDir.$file['name'])){
+        $tmp = array(
+            'url'     => "" ,
+            'name'    => $file['name'] ,
+            'initial' => FALSE,
+            'tmp_name'=> $file['tmp_name'],
+            'content' => file_get_contents($file['tmp_name']),
+            'exists'  => TRUE);
+        $this->gotoKioskProfiles[] = $tmp;
+      }
+    }
+
+    print_a($_POST);
+
+  
+    $only_once = true;
+    foreach($_POST as $name => $value){
+
+      if((preg_match("/^delkiosk_/",$name))&&($only_once)){
+  
+        /* Get id, name and path */
+        $only_once = false;
+        $id = preg_replace("/^delkiosk_/","",$name);
+        $id = preg_replace("/_.*$/","",$id);
+        $name = $this->gotoKioskProfiles[$id]['name'];
+        $filename = $this->baseDir."/".$name;
+
+        /* check if profile is still in use */
+        $ldap = $this->config->get_ldap_link();
+        $ldap->cd($this->config->current['BASE']);
+        $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*".$name.")",array("cn","uid","gotoKioskProfile"));
+        $used_by = "";
+        $cnt = 3;
+        while(($attrs = $ldap->fetch()) && ($cnt)){
+          $cnt --;
+          $check = preg_replace("/^.*\//i","",$attrs['gotoKioskProfile'][0]);
+          if($check == $name){
+            $used_by .= $attrs['cn'][0].", ";
+          }
+        }
+        $used_by = preg_replace("/, $/","",$used_by);
+        if(!empty($used_by)){
+          print_red(sprintf(_("Can't remove kioks profile, it is still in use by the following objects '%s'."),$used_by));
+        }else{
+          if($this->gotoKioskProfiles[$id]['initial']){
+            $res = @unlink($filename);
+            if(!$res){
+              if(!is_writeable($filename)){
+                print_red(sprintf(_("Can't delete '%s'. Error was: permission denied."), $filename));
+              }
+              if(!file_exists($filename)){
+                print_red(sprintf(_("Can't delete '%s'. Error was: file doesn't exist."), $filename));
+              }
+            }
+            unset($this->gotoKioskProfiles[$id]);
+          }
+        }
+      }
+    }
+
+    /* Display list of profiles */
+    $divlist = new divSelectBox("KioskProfiles");
+    $divlist -> SetHeight (300);
+    foreach($this->gotoKioskProfiles as $key => $val ){
+      $divlist->AddEntry(array(
+            array("string"=>"<a target='_blank' href='getkiosk.php?id=".$val['name']."'>".$val['name']."</a>"),
+            array("string"=>"<input type='image' src='images/edittrash.png'
+              class='center' alt='delete' name='delkiosk_".$key."'>" ,
+              "attach"=>" style='border-right: 0px;width:24px; text-align:center;' ")
+            ));
+    }
+
+    /* Assign all existing profiles to smarty */
+    $smarty->assign("divlist",$divlist->DrawList());
+    $smarty = get_smarty(); 
+    foreach($this->attributes as $attr){
+      $smarty->assign($attr,$this->$attr);
+    }
+    return($smarty->fetch(get_template_path("goKioskService.tpl",TRUE,dirname(__FILE__))));
+  }
+
+  function getListEntry()
+  {
+    $fields = goService::getListEntry();
+    $fields['Message']    = _("Kiosk profile service");
+    $fields['AllowEdit']  = TRUE;
+    $fields['AllowStart']  = false;
+    $fields['AllowStop']  = false;
+    $fields['AllowRestart']  = false;
+    return($fields);
+  }
+
+  function check()
+  { 
+    $message = plugin::check();
+    return($message);
+  }
+
+  function save()
+  {
+    goService::save();
+
+    /* Create server url */
+    if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
+      $method="https://".$this->cn."/kiosk/";
+    }else{
+      $method="http://".$this->cn."/kiosk/";
+    }
+
+    $this->attrs['gotoKioskProfile'] = array();
+    foreach($this->gotoKioskProfiles as $profile){
+      if(!$profile['initial']){
+
+        $contents = $profile['content'];
+        $path = $this->baseDir."/".$profile['name'];
+        $fp = @fopen($path,"w");
+        if(!$fp){
+          print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
+        }else{
+          fwrite($fp,$contents,strlen($contents));
+          $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
+        }
+        @unlink($profile['tmp_name']);
+      }else{
+        $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
+      }
+    }
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->cd($this->dn);
+    $ldap->modify($this->attrs);
+    show_ldap_error($ldap->get_error(),_("Wohl kaum"));
+  }
+
+  /* Return plugin informations for acl handling */
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Kiosk"),
+          "plDescription" => _("Kiosk profile management")." ("._("Services").")",
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 100,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("server"),
+
+          "plProvidedAcls"=> array()
+          ));
+  }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/systems/goKioskService.tpl b/plugins/admin/systems/goKioskService.tpl
new file mode 100644 (file)
index 0000000..18d076d
--- /dev/null
@@ -0,0 +1,21 @@
+<h2><img alt="" class="center" src="images/house.png" align="middle">&nbsp;<LABEL for="gotoKioskProfile">{t}Kiosk profile management{/t}</ LABEL></h2>
+
+    <input type="hidden" name="dialogissubmitted" value="1">
+
+{$divlist}
+<input type="file" size=50 name="newProfile" value="{t}Browse{/t}">
+<input type="submit" name="profileAdd" value="{t}Add{/t}">
+
+<p class='seperator'>&nbsp;</p>
+<div style="width:100%; text-align:right;padding-top:10px;padding-bottom:3px;">
+    <input type='submit' name='SaveService' value='{t}Save{/t}'>
+    &nbsp;
+    <input type='submit' name='CancelService' value='{t}Cancel{/t}'>
+</div>
+<input type="hidden" name="goCupsServerPosted" value="1">
+
+<script language="JavaScript" type="text/javascript">
+  <!-- // First input field on page
+    focus_field('gotoKioskProfile');
+  -->
+</script>