<?php
/*
** Funktionen für den Test der Installation
** 
** Copyright   : Reto Haldemann
** Author      : Reto Haldemann v/o Mistral
** Version     : 0.9
** Datum       : 19.12.2004
** Lizenz      : GPL                                                                 *

*/
function test_start_table($title) {
    $tpl = '<h3>'.$title.'</h3>';
    $tpl .= '<table class="config">';
    $tpl .= '<tr>';
    $tpl .= '<td class="config1"></td>';
    $tpl .= '<td class="config2"></td>';
    $tpl .= '<td class="config3"></td>';
    $tpl .= '</tr>';
    return $tpl;
}


function test_end_table() {
    return '</table>';
}


// ---------------------------------------------------------------------------


function test_write_folder( $folder ) {
    $tpl = '<tr>';
    $tpl .= '<td>' . $folder . '/</td>';
    $tpl .= '<td>';
    
    if (file_exists( "../$folder" ))
    {
        if (is_writable( "../$folder" ))
        {
            $tpl .= '<strong><span style="color:green">Beschreibbar</span></strong></td>';
        } else {
            $tpl .= '<strong><span style="color:red">Schreibgeschützt</span></strong></td>';
        }
        $tpl .= '<td>'. substr( decoct( fileperms("../$folder" )), -4).'</td>';
    } else {
        $tpl .= 'Nicht vorhanden</td>';
        $tpl .= '<td></td>';
    }
    $tpl .= '</tr>';
    return $tpl;
}

function test_folder( ) {
    $tpl = test_start_table( 'Schreibrechte auf Verzeichnisse');
    
    $tpl .= test_write_folder( 'backend/logs' );
    $tpl .= test_write_folder( 'backend/plugins' );
    $tpl .= test_write_folder( 'backend/upload/in' );
    $tpl .= test_write_folder( 'backend/upload/out' );
    if (file_exists('../projekt01')) {
        $tpl .= test_write_folder( 'projekt01/cms/css' );
        $tpl .= test_write_folder( 'projekt01/cms/js' );
        $tpl .= test_write_folder( 'projekt01/media' );
        $tpl .= test_write_folder( 'projekt01/media/img' );
        $tpl .= test_write_folder( 'projekt01/media/pdf' );
        $tpl .= test_write_folder( 'projekt01/media/swf' );
        $tpl .= test_write_folder( 'projekt01/media/zip' );
        $tpl .= test_write_folder( 'projekt01/logs' );
    } else {
        $tpl .= test_write_folder( 'cms/css' );
        $tpl .= test_write_folder( 'cms/js' );
        $tpl .= test_write_folder( 'media' );
        $tpl .= test_write_folder( 'media/img' );
        $tpl .= test_write_folder( 'media/pdf' );
        $tpl .= test_write_folder( 'media/swf' );
        $tpl .= test_write_folder( 'media/zip' );
        $tpl .= test_write_folder( 'logs' );
    }
    
    $tpl .= test_end_table();
    return $tpl;
}


// ---------------------------------------------------------------------------

function test_configuration_row($title, $boolean , $desc ) {
    $tpl = '<tr>';
    $tpl .= '<td>' . $title . '</td>';
    $tpl .= '<td>';
    
    if ($boolean) {
        $tpl .= '<strong><span style="color:green">Vorhanden</span></strong> ';
    } else {
        $tpl .= '<strong><span style="color:red">Nicht&nbsp;vorhanden</span></strong> '; 
    }
    $tpl .= '<td><span class="small">' . $desc . '</span></td>';
    
    $tpl .= '</tr>';
    return $tpl;
}

function test_configuration( ) {
    $tpl = test_start_table( 'Konfiguration');
    
    $tpl .= test_configuration_row('config.php' , @file_exists('../backend/inc/config.php') , '' );
    
    $tpl .= test_end_table();
    return $tpl;
}

function test_PHP_check( ) {
    $tpl = test_start_table( 'PHP-Check');
    
    $tpl .= test_configuration_row('PHP version >= 4.0.3'          , phpversion() < '4.0.3'?0:1                , phpversion() );
    $tpl .= test_configuration_row('&nbsp; - MySQL support'        , @function_exists( 'mysql_connect' )       , '' );
    $tpl .= test_configuration_row('&nbsp; - zlib'                 , extension_loaded('zlib')                  , 'Empfohlen' );
    $tpl .= test_configuration_row('&nbsp; - gdlib'                , extension_loaded('gd')                    , 'Empfohlen zum Erstellen der Thumbnails' );
    $tpl .= test_configuration_row('&nbsp; - bclib BCMath support' , extension_loaded('bcmath')                , 'Einige Module können Probleme bereiten (z.B. Pic-Galerie)' );
    
    $tpl .= test_end_table();
    return $tpl;
}


// ---------------------------------------------------------------------------


function test_get_php_configuration_value($value) {
	if (ini_get($value) == '1') 
	{
		return 'ON';
	} else {
		return 'OFF';
	}
}


function test_PHP_config( ) {
    $tpl = test_start_table( 'PHP-Einstellungen');
    
    $tpl .= '<tr>';
    $tpl .= '<td class="config1"><strong>Parameter</strong></td>';
    $tpl .= '<td class="config2"><strong>Erforderlich</strong></td>';
    $tpl .= '<td class="config3"><strong>Eingestellt</strong></td>';
    $tpl .= '</tr>';
    
    $php_settings = array(array ('Safe Mode','safe_mode','OFF'),
        array ('File Uploads','file_uploads','ON'),
    );
                  
    foreach ($php_settings as $phpset) {
        $tpl .= '<tr>';
        $tpl .= '<td>'.$phpset[0].'</td>';
        $tpl .= '<td>'.$phpset[2].'</td>';
        $tpl .= '<td>';
        if ( test_get_php_configuration_value($phpset[1]) == $phpset[2] ) {
            $tpl .= '<strong><span style="color:green">';
        } else {
            $tpl .= '<strong><span style="color:red">';
        }
        $tpl .= test_get_php_configuration_value($phpset[1]);
        $tpl .= '</span></strong>';
        $tpl .= '</td></tr>';
    }
    
    $tpl .= test_end_table();
    return $tpl;
}

?>