public static function is_valid()
 {
     $result = AddonBoilerplateOutfittersLicense::isValid('AddonBoilerplate');
     if ($result !== true) {
         //The license didn't validate as the subscription has expired for the user. Handle it how you would like below
         $admin = BeanFactory::getBean('Administration');
         $admin->retrieveSettings('addonboilerplate');
         $last_sent = $admin->settings['addonboilerplate_licenseemail'];
         $elapsed = 60 * 60;
         if (empty($last_sent) || $last_sent + $elapsed < time()) {
             $admin->saveSetting('addonboilerplate', 'licenseemail', time());
             require_once 'modules/AddonBoilerplate/includes/classes/AddonBoilerplate/Helper.php';
             global $sugar_config, $sugar_version, $sugar_flavor;
             $error_email = AddonBoilerplate_Helper::get_error_email_address();
             /**
                             //send email to the admin user
                             $email_to = $error_email;
                             $subject =  '[CRITICAL] AddonBoilerplate is no longer functioning';
                             $bodyHTML= "
             The license was unable to validate. Please log into your SugarCRM instance, go to Admin->AddonBoilerplate->License Configuration and validate your license.
             
             Site: ".$sugar_config['site_url']."
             SugarCRM Version: ".$sugar_version."
             SugarCRM Edition: ".$sugar_flavor."
             AddonBoilerplate Version: ".AddonBoilerplate_Helper::get_addonboilerplate_version();
                     
                             AddonBoilerplate_Helper::send_email($email_to,$subject,$bodyHTML,'*****@*****.**');
             */
             return $result;
         }
     }
     return $result;
 }
 } else {
     if ($_REQUEST['method'] == 'add') {
         AddonBoilerplateOutfittersLicense::add();
     } else {
         if ($_REQUEST['method'] == 'test') {
             //optional param: user_id - test if a specific user has access to the add-on
             //Sugar 6: /index.php?module=SampleLicenseAddon&action=outfitterscontroller&method=test&to_pdf=1
             //Sugar 7: #bwc/index.php?module=SampleLicenseAddon&action=outfitterscontroller&method=test&to_pdf=1
             $user_id = null;
             if (!empty($_REQUEST['user_id'])) {
                 $user_id = $_REQUEST['user_id'];
             }
             $validate_license = AddonBoilerplateOutfittersLicense::isValid($currentModule, $user_id, true);
             if ($validate_license !== true) {
                 echo "License did NOT validate.<br/><br/>Reason: " . $validate_license;
                 $validated = AddonBoilerplateOutfittersLicense::doValidate($currentModule);
                 if (is_array($validated['result'])) {
                     echo "<br/><br/>Key validation = " . !empty($validated['result']['validated']);
                     require 'modules/' . $currentModule . '/license/config.php';
                     if ($outfitters_config['validate_users'] == true) {
                         echo "<br/>User validation = " . !empty($validated['result']['validated_users']);
                         echo "<br/>Licensed User Count = " . $validated['result']['licensed_user_count'];
                         echo "<br/>Current User Count = " . $validated['result']['user_count'];
                         if ($validated['result']['user_count'] > $validated['result']['licensed_user_count']) {
                             echo "<br/><br/>Additional Users Required = " . ($validated['result']['user_count'] - $validated['result']['licensed_user_count']);
                         }
                     }
                 }
             } else {
                 echo "License validated";
             }
 /**
  * For validation via client-side (used by License Configuration form)
  *
  * Does NOT obey the validation_frequency setting. Validates every time.
  * This function is meant to be used only on the License Configuration screen for a specific add-on
  */
 public static function validate()
 {
     $json = getJSONobj();
     if (empty($_REQUEST['key'])) {
         header('HTTP/1.1 400 Bad Request');
         $response = "Key is required.";
         echo $json->encode($response);
         exit;
     }
     global $sugar_config, $currentModule;
     //load license validation config
     require 'modules/' . $currentModule . '/license/config.php';
     $validated = AddonBoilerplateOutfittersLicense::doValidate($currentModule, $_REQUEST['key']);
     $store = array('last_ran' => time(), 'last_result' => $validated);
     require_once 'modules/Administration/Administration.php';
     $administration = new Administration();
     $serialized = base64_encode(serialize($store));
     $administration->saveSetting('SugarOutfitters', $outfitters_config['shortname'], $serialized);
     if ($validated['success'] === false) {
         header('HTTP/1.1 400 Bad Request');
     } else {
         //use config_override.php...config.php has a higher chance of having rights restricted on servers
         global $currentModule;
         //load license validation config
         require 'modules/' . $currentModule . '/license/config.php';
         require 'modules/Configurator/Configurator.php';
         $cfg = new Configurator();
         $cfg->config['outfitters_licenses'][$outfitters_config['shortname']] = $_REQUEST['key'];
         $cfg->handleOverride();
     }
     echo $json->encode($validated['result']);
 }