/**
  * Extends the startup checks with Barzahlen plugin version check.
  *
  * @return array
  */
 protected function _doStartUpChecks()
 {
     $aMessage = parent::_doStartUpChecks();
     $oxConfig = $this->getConfig();
     $sShopId = $oxConfig->getShopId();
     $sModule = oxConfig::OXMODULE_MODULE_PREFIX . $this->_sModuleId;
     $sPluginCheck = $oxConfig->getShopConfVar('bzPluginCheck', $sShopId, $sModule);
     // only check once a week
     if ($sPluginCheck != null && $sPluginCheck > strtotime("-1 week")) {
         return $aMessage;
     }
     $oxConfig->saveShopConfVar('str', 'bzPluginCheck', time(), $sShopId, $sModule);
     $sBzShopId = $oxConfig->getShopConfVar('bzShopId', $sShopId, $sModule);
     $sShopsystem = 'OXID 4.7/5.0';
     $sShopsystemVersion = $oxConfig->getVersion();
     $sPluginVersion = self::CURRENTVERSION;
     try {
         $oChecker = new Barzahlen_Version_Check();
         $newAvailable = $oChecker->isNewVersionAvailable($sBzShopId, $sShopsystem, $sShopsystemVersion, $sPluginVersion);
     } catch (Exception $e) {
         oxRegistry::getUtils()->writeToLog(date('c') . " " . $e . "\r\r", self::LOGFILE);
     }
     if ($newAvailable) {
         $aMessage['warning'] .= (!empty($aMessage['warning']) ? "<br>" : '') . sprintf(oxRegistry::getLang()->translateString('BZ__NEW_PLUGIN_AVAILABLE'), $oChecker->getNewPluginVersion(), $oChecker->getNewPluginUrl());
     }
     return $aMessage;
 }
 /**
  * Checks for plugin updates. (Once a week.)
  *
  * @param Enlight_Event_EventArgs $args
  */
 public function onBackendIndexPostDispatch(Enlight_Event_EventArgs $args)
 {
     if (file_exists('files/log/barzahlen.check')) {
         $file = fopen('files/log/barzahlen.check', 'r');
         $lastCheck = fread($file, 1024);
         fclose($file);
     } else {
         $lastCheck = 0;
     }
     if (Shopware()->Auth()->hasIdentity() && ($lastCheck == 0 || $lastCheck < strtotime("-1 week"))) {
         if (!file_exists('files/log/')) {
             if (!mkdir('files/log/')) {
                 return;
             }
         }
         $file = fopen('files/log/barzahlen.check', 'w');
         fwrite($file, time());
         fclose($file);
         try {
             $config = $this->Config();
             $shopId = $config->barzahlenShopId;
             $paymentKey = $config->barzahlenPaymentKey;
             $checker = new Barzahlen_Version_Check($shopId, $paymentKey);
             $response = $checker->checkVersion('Shopware 5', Shopware::VERSION, $this->getVersion());
             if ($response != false) {
                 echo '<script type="text/javascript">
                       if(confirm(decodeURI("F%FCr das Barzahlen-Plugin ist eine neue Version (' . (string) $response . ') verf%FCgbar. Jetzt ansehen?"))) {
                         window.location.href = "https://integration.barzahlen.de/de/shopsysteme/shopware";
                       }
                       else {
                         window.location.reload();
                       }</script>';
             }
         } catch (Exception $e) {
             $this->_logError($e);
         }
     }
 }