<?php
/*
 * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

$logfiles = array_combine($logfiles, $logfiles);

$form = new sly_Form('index.php', 'GET', 'Log-Viewer');
$form->addHiddenValue('page', 'devutilslogviewer');
$form->add(new sly_Form_Input_Text('directory', 'Verzeichnis', $directory));
$form->setResetButton(null);
$form->getSubmitButton()->setAttribute('value', 'Verzeichnis ändern');
$form->getSubmitButton()->setAttribute('name', '');

if (sly_Core::getVersion('X.Y') !== '0.7') {
	$form->setCsrfEnabled(false);
}

print $form->render();

$form->clearElements();
$form->addHiddenValue('directory', $directory);
$form->beginFieldset('Logdatei');
$form->add(new sly_Form_Select_DropDown('logfile', 'Logdatei', array($logfile), $logfiles));
$form->add($rev = new sly_Form_Input_Checkbox('reverse', 'umkehren', '1', 'Die Datei soll rückwärts ausgegeben werden.'));
$rev->setChecked($reverse);
$form->getSubmitButton()->setAttribute('value', 'Daten abrufen');

print $form->render();

if ($logfile) {
	$params = json_encode(compact('logfile', 'directory', 'format', 'reverse'));
	$params = base64_encode(gzcompress($params));

	if (!is_array($lines)) {
		print sly_Helper_Message::warn('Die Datei ist zu groß ('.sly_Util_String::formatFilesize($lines).').');
	}
	elseif (empty($lines)) {
		print sly_Helper_Message::info('Die Datei ist leer. / Es wurden keine passenden Elemente gefunden.');
	}
	else {
		?>
		<div class="rex-area">
			<h2 class="rex-hl2"><?php print sly_html($logfile) ?> (<a href="index.php?page=devutilslogviewer&amp;get=<?php print urlencode($params) ?>">Permanent-Link</a>)</h2>
			<div class="rex-area-content devutils-logcontainer"><?php $short = true; include dirname(__FILE__).'/log.phtml' ?></div>
		</div>
		<?php
	}
}
