Code

Apply fix for #4146
[gosa.git] / trunk / gosa-plugins / goto / admin / systems / goto / class_workstationService.inc
index 47a3da9d939fda67aac55933038af92f214ce26e..b5c8e3488a8c06a191593def1f3958031191f15a 100644 (file)
@@ -34,6 +34,7 @@ class workservice extends plugin
   var $hardware_list= array();
   var $used_hardware= array();
   var $ogroup = FALSE;
+  var $member_of_ogroup = FALSE;
 
   /* attribute list for save action */
   var $attributes= array("gotoXMonitor", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
@@ -48,6 +49,8 @@ class workservice extends plugin
   var $XKbLayouts       =array();
   var $XKbVariants      =array();
 
+  var $InheritXYSync = FALSE;
+
   function workservice (&$config, $dn= NULL, $parent= NULL)
   {
     plugin::plugin ($config, $dn, $parent);
@@ -179,10 +182,8 @@ class workservice extends plugin
       }
     }
 
-    if(preg_match("/\+/",$this->gotoXHsync)){
-      $this->AutoSync = true;
-      $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
-      $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
+    if(isset($this->attrs['gotoXHsync']) && isset($this->attrs['gotoXYsync'])) {
+      $this->InheritXYSync = FALSE;
     }
 
     /* Workaround to fill in inherited values if we've specified an objectclass */
@@ -196,7 +197,9 @@ class workservice extends plugin
       $this->XKbVariants= array('default' => _("inherited"));
       $this->MouseTypes= array('default' => _("inherited"));
       $this->MousePorts= array('default' => _("inherited"));
+      $this->member_of_ogroup = TRUE;
     }
+
   }
 
   function execute()
@@ -207,6 +210,12 @@ class workservice extends plugin
     /* Load hardware list */  
     $this->loadHardwareList();
 
+    if(preg_match("/\+/",$this->gotoXHsync)){
+      $this->AutoSync = true;
+      $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
+      $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
+    }
+
     if($this->is_account && !$this->view_logged){
       $this->view_logged = TRUE;
       new log("view","workstation/".get_class($this),$this->dn);
@@ -235,6 +244,8 @@ class workservice extends plugin
       $smarty->assign($name."ACL",$this->getacl($name));
     }
 
+    $smarty->assign("member_of_ogroup", $this->member_of_ogroup);
+
     /* Arrays */ 
     foreach(array("XDrivers", "XResolutions", "XColordepths",
           "XKbModels", "XKbVariants",
@@ -306,6 +317,14 @@ class workservice extends plugin
       $smarty->assign("AutoSyncCHK"," ");
       $smarty->assign("hiddenState","");
     }
+    if($this->InheritXYSync) {
+      $smarty->assign("InheritXYSync", " checked ");
+      $smarty->assign("hiddenState", " disabled ");
+      $smarty->assign("AutoSynchiddenState", " disabled ");
+    } else {
+      $smarty->assign("InheritXYSync", "");
+      $smarty->assign("AutoSynchiddenState", "");
+    }
 
     /* Show main page */
     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
@@ -340,6 +359,13 @@ class workservice extends plugin
         $this->AutoSync = false;
       }
     }
+    if(isset($_POST['workservicePosted'])) {
+      if(isset($_POST['InheritXYSync'])) {
+        $this->InheritXYSync = TRUE;
+      }else {
+        $this->InheritXYSync = FALSE;
+      }
+    } 
   }
 
   /* Check supplied data */
@@ -352,14 +378,18 @@ class workservice extends plugin
     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
 
       /* But only if no auto sync is enabled... */
-      if (!$this->AutoSync){
+      if (!$this->AutoSync && !$this->InheritXYSync){
+
+
+        $vsync_empty = FALSE;
+        $hsync_empty = FALSE;
 
         /* Check vsync for correct usage */
         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
 
         if($this->acl_is_writeable("gotoXVsync")){
           if(empty($val)){
-            $message[]= msgPool::required(_("VSync"));
+            $vsync_empty = TRUE;
           }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
             $message[]= msgPool::invalid(_("VSync"));
           } else{
@@ -376,7 +406,7 @@ class workservice extends plugin
         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
         if($this->acl_is_writeable("gotoXHsync")){
           if(empty($val)){
-            $message[]= msgPool::required(_("HSync"));
+            $hsync_empty = TRUE;
           }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
             $message[]= msgPool::invalid(_("HSync"));
           } else{
@@ -388,6 +418,27 @@ class workservice extends plugin
             }
           }
         }
+
+        /* Decide weither show empty value errors, if this is not an object group it
+         * will always be shown... */
+        $show_errors = TRUE;
+        if ($vsync_empty || $hsync_empty) {
+
+          if (isset($this->attrs['gosaGroupObjects'])) {
+            /* ... but an object group can contain empty values if both values are empty */
+            if ($vsync_empty != $hsync_empty) {
+                $show_errors = TRUE;
+            } else {
+                $show_errors = FALSE;
+            }
+          } 
+          if ($show_errors && $vsync_empty) {
+            $message[]= msgPool::required(_("VSync"));
+          }
+          if ($show_errors && $hsync_empty) {
+            $message[] = msgPool::required(_("HSync"));
+          }
+        }
       }
     }
 
@@ -416,6 +467,11 @@ class workservice extends plugin
       }
     }
 
+    if($this->InheritXYSync) {
+      $this->attrs['gotoXHsync'] = array();
+      $this->attrs['gotoXVsync'] = array();
+    }
+
     if($this->AutoSync){
       $this->attrs['gotoXHsync'] = "30+55";
       $this->attrs['gotoXVsync'] = "50+70";
@@ -452,15 +508,31 @@ class workservice extends plugin
       $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
     }
       if ($ldap->count() == 1){
+        $this->member_of_ogroup = TRUE;
         $attrs= $ldap->fetch();
         $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
-                    "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport", "gotoXDriver");
+                    "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport", "gotoXDriver",
+                    "gotoXVsync", "gotoXHsync"
+                  );
+
         foreach ($map as $name){
         if (!isset($attrs[$name][0])){
           continue;
         }
-        
+
         switch ($name){
+          case 'gotoXHsync':
+            if (empty($this->$name) && !empty($attrs[$name])) {
+              $this->$name = $attrs[$name][0];
+              $this->InheritXYSync = TRUE;
+            }
+            break;
+          case 'gotoXVsync':
+            if (empty($this->$name) && !empty($attrs[$name])) {
+              $this->$name = $attrs[$name][0];
+              $this->InheritXYSync = TRUE;
+            }
+            break;
           case 'gotoXDriver':
             $ogroup_driver = $attrs['gotoXDriver'][0];
             if (in_array($ogroup_driver, $this->XDrivers) && (empty($this->attrs['gotoXDriver']))) {