<?php

class versionUtil {

  private $logger = "";
  public $VERSION_AFM02  = "AFM02VERSION";    public $VERSION_DATABASE_AFM02  = "AFM02DATABASEVERSION";
  public $VERSION_AFM03  = "AFM03VERSION";    public $VERSION_DATABASE_AFM03  = "AFM03DATABASEVERSION";
  public $VERSION_AFM032 = "AFM032VERSION";   public $VERSION_DATABASE_AFM032 = "AFM032DATABASEVERSION";
  public $VERSION_AFM04  = "AFM04VERSION";    public $VERSION_DATABASE_AFM04  = "AFM04DATABASEVERSION";
  public $VERSION_AFM90  = "AFM90VERSION";    public $VERSION_DATABASE_AFM90  = "AFM90DATABASEVERSION";

  function __construct() {
    $this->logger = new logger(basename(__FILE__));
  }

  public function setAllVersion() {
    $dbutilVer = null;
    try {
      global $dbutil;
      $sqlVer = "select CLS1,R01,R02";
      $sqlVer .= " from axm994 where cls='VER' ";

      $ret = $dbutil->select($sqlVer);
      if($ret != null) {
        foreach($ret as $d) {
          //error_log('@|'.var_dump($d,true));
          if(1==2) {
          } else if($d["cls1"] == "AFM02")  {
              $GLOBALS[$this->VERSION_AFM02]          = $this->nvlVersion($d["r01"]);
              $GLOBALS[$this->VERSION_DATABASE_AFM02] = $this->nvlVersion($d["r02"]);
          } else if($d["cls1"] == "AFM03")  {
              $GLOBALS[$this->VERSION_AFM03]          = $this->nvlVersion($d["r01"]);
              $GLOBALS[$this->VERSION_DATABASE_AFM03] = $this->nvlVersion($d["r02"]);
          } else if($d["cls1"] == "AFM032") {
              $GLOBALS[$this->VERSION_AFM032]         = $this->nvlVersion($d["r01"]);
              $GLOBALS[$this->VERSION_DATABASE_AFM032]= $this->nvlVersion($d["r02"]);
          } else if($d["cls1"] == "AFM04")  {
              $GLOBALS[$this->VERSION_AFM04]          = $this->nvlVersion($d["r01"]);
              $GLOBALS[$this->VERSION_DATABASE_AFM04] = $this->nvlVersion($d["r02"]);
          } else if($d["cls1"] == "AFM90")  {
              $GLOBALS[$this->VERSION_AFM90]          = $this->nvlVersion($d["r01"]);
              $GLOBALS[$this->VERSION_DATABASE_AFM90] = $this->nvlVersion($d["r02"]);
          }
        }
      }
    } catch(userException $ue) {
      $dbutil->rollback();
    } catch(Exception $e) {
      $dbutil->rollback();
    }
    return;
  }
  private function nvlVersion($version) {
    global $stringUtil;
    if($stringUtil->isEmpty($version)){
      return "20190701000000";
    } else {
      return $version;
    }
  }
}

?>
