<?php

/*
 * Copyright (C) 2021 Echedey López Romero <elr@disroot.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// Show errors in screen
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

// Repair output with Tidy
// ini_set('tidy.clean_output', '1');
// Empty web browser cache
header('Cache-Control: no-cache');
header('Pragma: no-cache');

require './calendar.php';

// Main operation thread

$Resultado = '--';
$Month = '';
$Year = '';

if (isset($_POST['mostrar'])) {
    if ($_POST['month'] && $_POST['year']) {
        $Month = intval($_POST['month']);
        $Year = intval($_POST['year']);
        
        if ($Month > 0 && $Month <= 12 && $Year > 0 && $Year < 9999) {
            $Calendar = new Calendar($Month, $Year);
            
            $Resultado = $Calendar->GenerateCalendar();
        } else {
            $Resultado = 'You must set a corrent month and year';
        }
    } else {
        $Resultado = 'You must set a month and a year';
    }
}

require './view.php';
