<?php

class WizardStepLicenseActivation extends WizardStep
{

    public function run()
    {    
        
        // if post is sent:
        $model = new Licence("ajaxValidation");
        $this->performAjaxValidation($model, 'license-activasion-form');
        
        
        if (isset($_POST["Licence"])) {
            $model->attributes = $_POST["Licence"];
            if ( $model->validate() ) {
                if ( $this->activateLicense($model) ) {
                    $this->setStepIsDone(true);
                    return;
                }
            }
        }
        
        $this->wizardController->render("licenseActivation", array("formModel" => $model));
    }
    
    
    private function activateLicense($model)
    {
            $result = LicenseServer::activateLicense($model);
            if ($result === true) {
                return true;
            }
            Yii::app()->user->setFlash('error', "<strong>Error " . $result['errorCode'] . ": </strong>" . $result['errorMessage']);
            return false;
    }
}