/**
  *
  */
 function onAction()
 {
     global $application;
     loadCoreFile('licensekey.php');
     loadCoreFile('licenseaccount.php');
     // sending the registration request
     $lk = new LicenseKey();
     $lac = new LicenseAccountClient();
     $response = $lac->requestUpdateLicense(array("LicenseKey" => $lk->getLicenseKey(), "LicenseDomain" => $lk->getLicenseURL(), "LicenseType" => PRODUCT_VERSION_INTERNAL_TYPE));
     $result_msg = "UNKNOWN_ERROR";
     if ($response['CODE'] == 0 && !empty($response['CERT'])) {
         loadCoreFile('licensecert.php');
         $lc = new LicenseCertificate();
         if ($lc->_save_cert_to_file($response['CERT']) === false) {
             // error saving certificate
             $result_msg = "CERT_ERROR_CANNOT_SAVE";
         } else {
             if ($lc->certificate_status === CERTIFICATE_OK) {
                 // certificate saved successfully
                 $result_msg = "UPDATE_SUCCESS";
             } else {
                 // invalid certificate received
                 $result_msg = "CERT_ERROR_INVALID";
             }
         }
     } else {
         if (!empty($response['CODE'])) {
             // error handling
             $result_msg = "RESPONSE_" . $response['CODE'];
         }
     }
     //$request = $application->getInstance('Request');
     modApiFunc('Session', 'set', 'ResultMessage', $result_msg);
     $this->redirect();
 }
 /**
  *
  *
  * @param
  * @return
  */
 function getLicenseInfo($state)
 {
     global $application;
     loadCoreFile('licensekey.php');
     loadCoreFile('licensecert.php');
     //loadCoreFile('licenseclient.class.php');
     $licenseKeyObj = new LicenseKey();
     $licenseKey = $licenseKeyObj->getLicenseKey();
     $licenseCertObj = new LicenseCertificate();
     $mr =& $application->getInstance('MessageResources');
     if ($state !== "LK_NA" || $state !== "APP_REG") {
         $link = '<a href="license_info.php">License Info</a>';
     } else {
         $link = "";
     }
     $license_info = array("license_key" => $licenseKey, "license_message" => $this->storeStatusMessage($state), "license_message_home" => str_replace('{LIP_LINK}', $link, $mr->getMessage('STORE_STATE_HOME_' . $state)), "license_url" => $licenseCertObj->getLicenseURL(), "current_url" => $licenseKeyObj->getLicenseURL(), "current_version_type" => PRODUCT_VERSION_TYPE, "license_registration_date" => "NA");
     return $license_info;
     /*        if ($licenseKey == LICENSE_KEY_UNDEFINED)
             {
                 return $license_info;
             }
             else
             {
                 $licenseClient = new LicenseClient();
                 $licenseInfo = $licenseClient->requestCheckLicense($licenseKey, $licenseKeyObj->getLicenseURL());
     
                 if($licenseInfo === false)
                 {
                     return null;
                 };
     
                 if (is_array($licenseInfo))
                 {
                     return array(
                                  "license_key"          => $licenseKey
                                 ,"license_status"       => ($licenseInfo["LK_STATUS"] == "INVALID"? "0":"1")
                                 ,"license_url"          => ($licenseInfo["LK_STATUS"] == "INVALID"? "NA":$licenseKeyObj->getLicenseURL())
     //                            ,"current_url"          => $licenseKeyObj->getLicenseURL()
                                 ,"version_type"         => ($licenseInfo["LK_PRODUCT_TYPE"] == "INVALID"? "NA":$licenseInfo["LK_PRODUCT_TYPE"])
                                 ,"current_version_type" => PRODUCT_VERSION_TYPE
                                 ,"license_update"       => ($licenseInfo["LK_UPDATE_DATE"] == "INVALID"? "NA":$licenseInfo["LK_UPDATE_DATE"])
                                 ,"license_support"      => ($licenseInfo["LK_SUPPORT_DATE"] == "INVALID"? "NA":$licenseInfo["LK_SUPPORT_DATE"])
                                 ,"message"              => ""
                                 );
                 }
                 else
                 {
                     $license_info["message"] = "LICENSE_WARNING_001";
                     return $license_info;
                 }
             }*/
     //        }
 }
 function updateCertificate()
 {
     loadCoreFile('licensekey.php');
     loadCoreFile('licenseaccount.php');
     // sending the registration request
     $lk = new LicenseKey();
     $lac = new LicenseAccountClient();
     $response = $lac->requestUpdateLicense(array("LicenseKey" => $lk->getLicenseKey(), "LicenseDomain" => $lk->getLicenseURL(), "LicenseType" => PRODUCT_VERSION_INTERNAL_TYPE));
     $result_msg = "UNKNOWN_ERROR";
     if ($response['CODE'] == 0 && !empty($response['CERT'])) {
         loadCoreFile('licensecert.php');
         $lc = new LicenseCertificate();
         if ($lc->_save_cert_to_file($response['CERT']) === false) {
             // error saving certificate
             $result_msg = "CERT_ERROR_CANNOT_SAVE";
         } else {
             if ($lc->certificate_status === CERTIFICATE_OK) {
                 // certificate saved successfully
                 $result_msg = "UPDATE_SUCCESS";
                 // message should not be shown
             } else {
                 // invalid certificate received
                 $result_msg = "CERT_ERROR_INVALID";
             }
         }
     } else {
         if (!empty($response['CODE'])) {
             // error handling
             $result_msg = "RESPONSE_" . $response['CODE'];
             if ($response['CODE'] == 3) {
                 $result_msg = "U_RESPONSE_3";
             }
             // another message for update is used
         }
     }
     if ($result_msg !== "UPDATE_SUCCESS") {
         modApiFunc('Session', 'set', 'ResultMessage', $result_msg);
     }
     return $result_msg;
 }