Code

Fixed comment
[gosa.git] / plugins / admin / systems / class_workstationService.inc
index f6b76e5ded6c5b9f9d042cfca8d471d87a292ca8..51982ff1f7d2e3384742c9ee2bc808869bceda72 100644 (file)
@@ -2,11 +2,6 @@
 
 class workservice extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Manage terminal service aspects";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   var $gotoScannerEnable;
   /* Generic terminal attributes */
   var $gotoXMonitor= "";
@@ -15,6 +10,7 @@ class workservice extends plugin
   var $gotoXColordepth= "";
   var $gotoXHsync= "";
   var $gotoXVsync= "";
+  var $AutoSync = false;
   var $gotoXKbModel= "";
   var $gotoXKbLayout= "";
   var $gotoXKbVariant= "";
@@ -30,22 +26,10 @@ class workservice extends plugin
   var $cn= "";
   var $orig_dn= "";
   var $XMethods= array();
-  var $XDrivers= array("unknown", "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
-      "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
-      "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
-      "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga");
-  var $XResolutions= array("default", "640x480", "800x600", "1024x768", "1152x864", "1280x1024",
-      "1400x1050", "1600x1200");
-  var $XColordepths= array("default", "8", "15", "16", "24");
-  var $XKbModels= array ("default", "btc9000", "chicony", "compaq", "dell", "dell101", "everex",
-      "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
-      "logiinetnav", "logiinternet", "macintosh", "microsoft",
-      "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
-      "pc105", "rapidaccess", "rapidaccess2", "winbook");
-  var $XKbLayouts= array ("default", "de", "intl", "us");
-  var $XKbVariants= array ("default", "nodeadkeys", "basic");
-  var $MouseTypes= array("AUTO", "ImPS/2", "PS/2", "Microsoft", "Logitech");
-  var $MousePorts= array("AUTO", "/dev/ttyS0", "/dev/ttyS1", "/dev/psaux", "/dev/input/mice");
+  var $XDrivers= array();
+  var $XResolutions = array();
+  var $MouseTypes= array();
+  var $MousePorts= array();
   var $hardware_list= array();
   var $used_hardware= array();
 
@@ -59,20 +43,98 @@ class workservice extends plugin
       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
   var $objectclasses= array("GOhard");
 
+  var $XColordepths     =array();
+  var $XKbModels        =array();
+  var $XKbLayouts       =array();
+  var $XKbVariants      =array();
 
-  function workservice ($config, $dn= NULL)
+  function workservice ($config, $dn= NULL, $parent= NULL)
   {
-    plugin::plugin ($config, $dn);
+    plugin::plugin ($config, $dn, $parent);
+
+    $this->XResolutions= array( 
+        "640x480"   =>  "640x480",
+        "800x600"   =>  "800x600",
+        "1024x768"  =>  "1024x768",
+        "1152x864"  =>  "1152x864", 
+        "1280x1024" =>  "1280x1024",
+        "1400x1050" =>  "1400x1050", 
+        "1600x1200" =>  "1600x1200");
+
+    if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
+      $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
+
+      if(is_readable($file)){
+        $str = file_get_contents($file);
+        $lines = split("\n",$str);
+        foreach($lines as $line){
+          $line = trim($line);
+          if(!empty($line)){
+            $this->XResolutions[$line]=$line;
+          }
+        }
+        //natcasesort($this->gotoXResolutions);
+      }else{
+        print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
+      }
+    }
+
+    /* Get list of available xdrivers */
+    $this->XDrivers = $this->getListOfXDrivers();
+
+    array_unshift($this->XDrivers, "["._("unknown")."]");
+    $this->XColordepths= array( 
+        "8"        => "8 " ._("bit"), 
+        "15"       => "15 "._("bit"),      
+        "16"       => "16 "._("bit"),   
+        "24"       => "24 "._("bit"));
+
+    foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
+          "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
+          "logiinetnav", "logiinternet", "macintosh", "microsoft",
+          "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
+          "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
+      $this->XKbModels[$type] = $type;
+    }
+
+    $this->MouseTypes= array("ImPS/2" => "ImPS/2", "PS/2" => "PS/2", "Microsoft" => "Microsoft", 
+                              "Logitech" => "Logitech");
+
+    $this->MousePorts= array("/dev/ttyS0"  =>"/dev/ttyS0", 
+                             "/dev/ttyS1"       => "/dev/ttyS1",          "/dev/psaux"  =>"/dev/psaux", 
+                             "/dev/input/mice"  => "/dev/input/mice");
+
+    /* Additional values will be extracted from CONFIG_DIR/gosa/keyboardLayouts */
+    $this->XKbLayouts= array ("de"=> "de","intl" =>"intl","us" =>"us");
+    $this->XKbVariants= array ("basic"=>"basic", "nodeadkeys"=>"nodeadkeys");
+
+    /* try to read additional keyboard layouts 
+     */
+    if(file_exists(CONFIG_DIR."/keyboardLayouts")){
+      if(is_readable(CONFIG_DIR."/keyboardLayouts")){
+        $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
+        $tmp = split("\n",$str);
+        foreach($tmp as $entry){
+          if((!empty($entry)) && (!preg_match("/^#/",$entry))){
+            $entry = trim($entry);
+            $tmp2 = split ("\:",$entry);
+            $la =   trim($tmp2[0]);   // What would be saved to ldap
+            $da =   trim($tmp2[1]);   // This wis displayed in the listbox
+            $this->XKbLayouts [ $la] = $da;  
+          } 
+        }
+      }
+    }
 
     /* Initialize methods */
-    $this->XMethods["default"]= _("default");
     $this->XMethods["indirect"]= _("show chooser");
     $this->XMethods["query"]= _("direct");
-#$this->XMethods["squery"]= _("direct via ssh");
-#$this->XMethods["nquery"]= _("direct via nx");
+    #$this->XMethods["squery"]= _("direct via ssh");
+    #$this->XMethods["nquery"]= _("direct via nx");
     $this->XMethods["load"]= _("load balanced");
-#$this->XMethods["sload"]= _("load balanced via ssh");
-#$this->XMethods["nload"]= _("load balanced via nx");
+    #$this->XMethods["sload"]= _("load balanced via ssh");
+    #$this->XMethods["nload"]= _("load balanced via nx");
     $this->XMethods["rdp"]= _("Windows RDP");
     $this->XMethods["citrix"]= _("ICA client");
 
@@ -104,14 +166,74 @@ class workservice extends plugin
       }
     }
 
+    if(preg_match("/\+/",$this->gotoXHsync)){
+      $this->AutoSync = true;
+      $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
+      $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
+    }
+
     $this->hardware_list["automatic"]= _("automatic");
     ksort($this->hardware_list);
+
+    /* Load hardware list */
+    $ldap= $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
+    if ($ldap->count() == 1){
+      $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
+                  "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
+      $attrs= $ldap->fetch();
+
+      foreach ($map as $name){
+        if (!isset($attrs[$name][0])){
+          continue;
+        }
+        
+        switch ($name){
+          case 'gotoXResolution':
+            $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
+            break;
+          case 'gotoXColordepth':
+            $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
+            break;
+          case 'gotoXKbModel':
+            $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
+            break;
+          case 'gotoXKbLayout':
+            $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
+            break;
+          case 'gotoXKbVariant':
+            $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
+            break;
+          case 'gotoXMouseType':
+            $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
+            break;
+          case 'gotoXMouseport':
+            $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
+            break;
+        }
+
+      }
+
+    }
+
+    /* Workaround to fill in inherited values if we've specified an objectclass */
+    if (isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
+      $this->XResolutions= array('default' => _("inherited"));
+      $this->XColordepths= array('default' => _("inherited"));
+      $this->XKbModels= array('default' => _("inherited"));
+      $this->XKbLayouts= array('default' => _("inherited"));
+      $this->XKbVariants= array('default' => _("inherited"));
+      $this->MouseTypes= array('AUTO' => _("inherited"));
+      $this->MousePorts= array('AUTO' => _("inherited"));
+    }
   }
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
+
     /* Do we need to flip is_account state? */
     if (isset($_POST['modify_state'])){
       $this->is_account= !$this->is_account;
@@ -129,10 +251,13 @@ class workservice extends plugin
 
     /* Arrays */ 
     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
-          "XKbModels", "XKbLayouts", "XKbVariants",
+          "XKbModels", "XKbVariants",
           "MouseTypes", "MousePorts") as $val){
       $smarty->assign("$val", $this->$val);
     }
+    $smarty->assign("XKbLayouts"    ,$this->XKbLayouts);
+    $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
+
     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
@@ -167,8 +292,8 @@ class workservice extends plugin
     /* Phone stuff */
     $smarty->assign ("goFonHardware", $this->goFonHardware);
     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
-         _("Choose the phone located at the current terminal")."\" ".
-         chkacl($this->acl, "goFonHardware").">\n";
+      _("Choose the phone located at the current terminal")."\" ".
+      chkacl($this->acl, "goFonHardware").">\n";
     foreach ($this->hardware_list as $cn => $description){
       if ($cn == $this->goFonHardware){
         $selected= "selected";
@@ -185,6 +310,15 @@ class workservice extends plugin
     $hl.= "</select>\n";
     $smarty->assign ("hardware_list", $hl);
     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
+    $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
+
+    if($this->AutoSync){
+      $smarty->assign("AutoSyncCHK"," checked ");
+      $smarty->assign("hiddenState"," disabled ");
+    }else{
+      $smarty->assign("AutoSyncCHK"," ");
+      $smarty->assign("hiddenState","");
+    }
 
     /* Show main page */
     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
@@ -192,71 +326,67 @@ class workservice extends plugin
 
   function remove_from_parent()
   {
-    /* This is not necessary, i think 
-     * Remove should be called from workGeneric ... 
-     */
-    /*$ldap= $this->config->get_ldap_link();
-    $ldap->rmdir($this->dn);
-    show_ldap_error($ldap->get_error());
     $this->handle_post_events("remove");
-    */
-   
-    /* This only removes the attributes from this tab, 
-     * and not hte whole entry 
-     */ 
-    $ldap= $this->config->get_ldap_link();
-    plugin::remove_from_parent();
-    $ldap->cd($this->dn);
-    $ldap->modify($this->attrs);
-    show_ldap_error($ldap->get_error());}
-
+  }
 
   /* Save data to object */
   function save_object()
   {
     plugin::save_object();
 
+    if(isset($_POST['gotoXDriver']) && chkacl($this->acl,"AutoSync") == ""){
+      if(isset($_POST['AutoSync'])){
+        $this->AutoSync = true;
+      }else{
+        $this->AutoSync = false;
+      }
+    }
   }
 
-
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     /* Default entries can use blank hsync/vsync entries */
     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
 
-      /* Check vsync for correct usage */
-      $val= preg_replace ("/\s/", "", $this->gotoXVsync);
-      if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
-          && chkacl ($this->acl, "gotoXVsync") == ""){
-
-        $message[]= _("Please specify a valid VSync range.");
-      } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
-        list($v1,$v2)= split ("-", $val);
-        if ($v2 != ""){
-          if ($v1 > $v2){
-            $message[]= _("Please specify a valid VSync range.");
+      /* But only if no auto sync is enabled... */
+      if (!$this->AutoSync){
+
+        /* Check vsync for correct usage */
+        $val= preg_replace ("/\s/", "", $this->gotoXVsync);
+        if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
+            && chkacl ($this->acl, "gotoXVsync") == ""){
+
+          $message[]= _("Please specify a valid VSync range.");
+        } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
+          list($v1,$v2)= preg_split ("/[-+]/", $val);
+          if ($v2 != ""){
+            if ($v1 > $v2){
+              $message[]= _("Please specify a valid VSync range.");
+            }
           }
         }
-      }
 
-      /* Check hsync for correct usage */
-      $val= preg_replace ("/\s/", "", $this->gotoXHsync);
-      if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
-          && chkacl ($this->acl, "gotoXHsync") == ""){
-
-        $message[]= _("Please specify a valid HSync range.");
-      } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
-        list($v1,$v2)= split ("-", $val);
-        if ($v2 != ""){
-          if ($v1 > $v2){
-            $message[]= _("Please specify a valid HSync range.");
+        /* Check hsync for correct usage */
+        $val= preg_replace ("/\s/", "", $this->gotoXHsync);
+        if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
+            && chkacl ($this->acl, "gotoXHsync") == ""){
+
+          $message[]= _("Please specify a valid HSync range.");
+        } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
+          list($v1,$v2)= preg_split ("/[-+]/", $val);
+          if ($v2 != ""){
+            if ($v1 > $v2){
+              $message[]= _("Please specify a valid HSync range.");
+            }
           }
         }
       }
     }
+
     return ($message);
   }
 
@@ -264,6 +394,11 @@ class workservice extends plugin
   /* Save to LDAP */
   function save()
   {
+    /* remove objectclass GOhard if this is an ogroup tab */
+    if(isset($this->parent->by_object['ogroup'])){
+      $this->objectclasses = array();
+    }
+
     plugin::save();
 
     /* Strip out 'default' values */
@@ -277,14 +412,42 @@ class workservice extends plugin
       }
     }
 
+    if($this->AutoSync){
+      $this->attrs['gotoXHsync'] = "30+55";
+      $this->attrs['gotoXVsync'] = "50+70";
+    }
+
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->dn);
-    $ldap->modify($this->attrs);
-    show_ldap_error($ldap->get_error());
+    $this->cleanup();
+    $ldap->modify ($this->attrs); 
+
+    show_ldap_error($ldap->get_error(), _("Saving workstation services failed"));
     $this->handle_post_events("modify");
   }
 
+
+  function getListOfXDrivers()
+  {
+    $drivers = array();
+
+    /* Generate a list of xdrivers from CONFIG_DIR/xdrivers */
+    if (file_exists(CONFIG_DIR.'/xdrivers')){
+      $xdrivers = file (CONFIG_DIR.'/xdrivers');
+      foreach ($xdrivers as $line){
+        if (!preg_match ("/^#/", $line)){
+          $drivers[]= trim($line);
+        }
+      }
+    } else {
+      $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
+          "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv", "nvidia",
+          "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
+          "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
+    }
+    return($drivers);
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: