<?php
/**
 * ______________________________________________________________________
 * 
 *  _____                 _       _             _                        
 * /  __ \               (_)     | |           (_)                       
 * | /  \/_ __ ___  _ __  _  ___ | |__   __   ___  _____      _____ _ __ 
 * | |   | '__/ _ \| '_ \| |/ _ \| '_ \  \ \ / / |/ _ \ \ /\ / / _ \ '__|
 * | \__/\ | | (_) | | | | | (_) | |_) |  \ V /| |  __/\ V  V /  __/ |   
 *  \____/_|  \___/|_| |_| |\___/|_.__/    \_/ |_|\___| \_/\_/ \___|_|   
 *                      _/ |                                             
 *                     |__/                                              
 * ______________________________________________________________________
 * 
 * The cronjob viewer for centralized monitoring of cronjobs using
 * Axels cronrwapper (see <https://github.com/axelhahn/cronwrapper>).
 * 
 * You can browse all servers to see 
 * - the last status of all cronjobs
 * - results an execution times of running jonbs
 * - a timeline for all jobs running > 60s
 * 
 * 
 * Free software. Open Source. GNU GPL 3.
 * SOURCE: <https://git-repo.iml.unibe.ch/iml-open-source/cronlog-viewer>
 * 
 * ______________________________________________________________________
 * 
 * AJAX HELPER
 *
 * @license GNU GPL 3.0
 * @author Axel Hahn <axel.hahn@iml.unibe.ch>
 */

require_once 'classes/cronlog-renderer.class.php';


$sMode='html';
$sItem=isset($_GET['item']) && $_GET['item'] ? $_GET['item'] : false;
$sServer=isset($_GET['server']) && $_GET['server'] ? $_GET['server'] : false;


$sHtml='';
$oCL = new cronlogrenderer();
if($sServer){
    $oCL->setServer($sServer);
}
switch ($sItem){
    case 'cronhistory':
        if($sServer==='ALL'){
            $sHtml.=$oCL->renderJoblistOfAllServers();
        } else {
            $sHtml.=$oCL->renderJoblist();
        }
        break;
    case 'cronlogs':
        if($sServer==='ALL'){
            $sHtml.=$oCL->renderCronlogsOfAllServers();
        } else {
            $sHtml.=$oCL->renderCronlogs();
        }
        break;
    case 'graph':
        if($sServer==='ALL'){
            $sHtml.=$oCL->renderJobGraphOfAllServers();
        } else {
            $sHtml.=$oCL->renderJobGraph();
        }
        break;
    case 'instances':
        $sHtml.=$oCL->renderInstances($sServer);
        break;
    case 'selectserver':
        $sHtml.=$oCL->renderServerlist($sServer);
        break;
    case 'showlog':
        $sLogfile=isset($_GET['logfile']) && $_GET['logfile'] ? $_GET['logfile'] : false;
        $sHtml.=$oCL->renderLogfile($sLogfile);
        break;
    default:
        header('HTTP/1.0 400 Bad request');
        die('unknown item ['.$sItem.'] ... or it is not implemented yet.');
}
echo $sHtml;