Code

Replaced in_array calls for gosa-plugins
[gosa.git] / gosa-plugins / opsi / admin / opsiLicenses / class_licenseGeneric.inc
index d37719ae8062f94a9abf49350dc985a521d0c832..1a2a0c7682b4659df379da6f842bb432c59deb5e 100644 (file)
@@ -24,6 +24,7 @@
 class licenseGeneric extends plugin 
 {
 
+  // License attributes
   var $si = NULL;
   var $data = array();
   var $cn = "";
@@ -31,10 +32,12 @@ class licenseGeneric extends plugin
   var $description = "";  
   var $partner = "";
 
+  // Date attributes 
   var $conclusionDate = "";
   var $expirationDate = "";
   var $notificationDate = "";
 
+  // License model related attribues
   var $licenseModel = "";
   var $licenseKey = array();
   var $orig_licenseModel = "";
@@ -74,6 +77,7 @@ class licenseGeneric extends plugin
   
   function init()
   {
+    // Extract license information out of the license object ($this->data)
     $this->boundToHost = array('0'=>"");
     $this->usedByHost = array('0'=>"");
     $this->licenseKey = array('0'=>"");
@@ -81,6 +85,13 @@ class licenseGeneric extends plugin
       foreach($this->attributes as $attr){
         $this->$attr = $this->data[$attr];
       }
+
+      // Fix dates 
+      foreach(array("notificationDate","expirationDate","conclusionDate") as $date) {
+        if(!empty($this->$date)){
+          $this->$date = date("d.m.Y",strtotime($this->$date));
+        }
+      }
     }
 
     $this->orig_cn = $this->cn;
@@ -102,7 +113,7 @@ class licenseGeneric extends plugin
 
     $smarty = get_smarty();
 
-    // Assign ACls 
+    // Assign attributes and its ACls 
     $plInfo = $this->plInfo();
     foreach($plInfo['plProvidedAcls'] as $name => $desc){
       $smarty->assign("{$name}ACL",$this->getacl($name));
@@ -111,30 +122,32 @@ class licenseGeneric extends plugin
       $smarty->assign($attr,$this->$attr);
     }
 
+    // Assign list of available license models
     $smarty->assign("licenseModels",array(
           "RETAIL" => _("Retail"),
           "OEM"=>_("OEM"),
-          "VOLUME" => _("Volume"),
-          "CONCURRENT" => _("Concurrent")));
-
+          "VOLUME" => _("Volume")));
 
+    $smarty->assign("usePrototype", "true");
     $smarty->assign("init_successfull", $this->init_successfull);
     $smarty->assign("initially_was_account", $this->initially_was_account);
     $smarty->assign("hosts", $this->getHosts());
 
     $ui = get_userinfo();
-
     $acl_base = $this->dn;
     if($acl_base == "new"){
       $acl_base = $this->config->current['BASE'];
     }
-
     $smarty->assign("licenseACL", $ui->get_permissions($acl_base,"opsi/licensePoolGeneric","licenses"));
     $smarty->assign("writeable", preg_match("/w/",$ui->get_permissions($acl_base,"opsi/licensePoolGeneric","licenses")));
-
     $smarty->assign("notUsedHosts", array_diff($this->getHosts(), $this->usedByHost));
     $smarty->assign("boundToHost", $this->boundToHost[0]);
     $smarty->assign("licenseKey", $this->licenseKey[0]);
+
+    foreach(array("notificationDate","expirationDate","conclusionDate") as $date) {
+      $smarty->assign($date."Writeable", $this->acl_is_writeable($date));
+    }
+
     return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
   }
 
@@ -162,8 +175,8 @@ class licenseGeneric extends plugin
       if(isset($_POST['addLicenseUsage']) && isset($_POST['selectedHostToAdd'])){
         $host = get_post('selectedHostToAdd');
         if(!empty($host) && 
-            in_array($host,$this->getHosts()) && 
-            !in_array($host, $this->usedByHost)){
+            in_array_strict($host,$this->getHosts()) && 
+            !in_array_strict($host, $this->usedByHost)){
           $this->usedByHost[] = $host;
         }
       }
@@ -203,16 +216,16 @@ class licenseGeneric extends plugin
 
     // Very simple date input checks
     if(!empty($this->expirationDate) && 
-       !preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/",$this->expirationDate)){
-      $message[] = msgPool::invalid(_("Expiration date"),$this->expirationDate,"","2009-02-23");
+       !preg_match("/^[0-9]{2}\.[0-9]{2}\.[0-9]{4}$/",$this->expirationDate)){
+      $message[] = msgPool::invalid(_("Expiration date"),$this->expirationDate,"","23.02.2009");
     }
     if(!empty($this->conclusionDate) && 
-       !preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/",$this->conclusionDate)){
-      $message[] = msgPool::invalid(_("Expiration date"),$this->conclusionDate,"","2009-02-23");
+       !preg_match("/^[0-9]{2}\.[0-9]{2}\.[0-9]{4}$/",$this->conclusionDate)){
+      $message[] = msgPool::invalid(_("Expiration date"),$this->conclusionDate,"","23.02.2009");
     }
     if(!empty($this->notificationDate) && 
-       !preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/",$this->notificationDate)){
-      $message[] = msgPool::invalid(_("Expiration date"),$this->notificationDate,"","2009-02-23");
+       !preg_match("/^[0-9]{2}\.[0-9]{2}\.[0-9]{4}$/",$this->notificationDate)){
+      $message[] = msgPool::invalid(_("Expiration date"),$this->notificationDate,"","23.02.2009");
     }
 
     if(empty($this->cn)){
@@ -240,6 +253,14 @@ class licenseGeneric extends plugin
     foreach($this->attributes as $target){
       $data[$target] = $this->$target;
     }
+    
+    // Return opsi like dates.
+    foreach(array("notificationDate","expirationDate","conclusionDate") as $date) {
+      if(!empty($this->$date)){
+        $data[$date] = date("Y-m-d",strtotime($this->$date));
+      }
+    }
+
     return($data);
   }
  
@@ -250,7 +271,7 @@ class licenseGeneric extends plugin
           "plDescription" => _("License generic"),
           "plSelfModify"  => FALSE,
           "plDepends"     => array(),
-          "plPriority"    => 1,
+          "plPriority"    => 8,
           "plSection"     => array("administration"),
           "plCategory"    => array("opsi"),
           "plProvidedAcls"=> array(