<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class License extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('LicenseManager', NULL, 'license_manager');
        $this->load->helper(array('url', 'form'));
    }

    public function index()
    {
        $this->output->set_output($this->load->view('license/activation', array(
            'status' => $this->license_manager->status(FALSE), 'flash' => $this->session->flashdata('license_message')
        ), TRUE));
    }

    public function activate()
    {
        if (strtoupper($this->input->method()) !== 'POST') show_404();
        $key = trim((string) $this->input->post('license_key', TRUE));
        $result = $this->license_manager->activate($key);
        $this->session->set_flashdata('license_message', $result);
        redirect('license');
    }

    public function recheck()
    {
        if (strtoupper($this->input->method()) !== 'POST') show_404();
        $result = $this->license_manager->recheck();
        $this->session->set_flashdata('license_message', $result);
        redirect('license');
    }
}

