Location: PHPKode > projects > Article System > include/modules/admin/include/test.php
<?php

/*
 *	Article System
 *	Online journal management tool written in PHP/MySQL/PostgreSQL.
 *	This code is available at http://sourceforge.net/projects/artsys
 *
 *	Copyright (C) 2001-2005 Jan Hnatek
 *	Distributed under the terms of the GNU General Public License
 *
 *	Date:	  05/08/2005
 *	Version:  0.6   	
 */

###############################################################################
# ADMIN PART
# admin information page
#

	// TODO: style fixes
	function adm_info ($text) {	echo "<p class=\"head\">*** $text ***</p>\n";	}
	function ainfo ($text) {	echo $text.'<br>';	}
	function aalert ($text) {	echo '<span style="color: red">'.$text.'</span><br>'; 	}

###############################################################################

	adm_info ('configuration checks (fix in public/config.php)');
	file_exists ($config["image_dir"]) && is_writeable ($config["image_dir"]) ?
		ainfo ('image dir: ok') :
		aalert ("image dir: FAILED - ({$config["image_dir"]}) <br>
			either does not exist or is not writable for webserver!");
	// TODO: test world-writability
	// TODO: moderate rights for others .. ?
	file_exists ($config["upload_dir"]) && is_writeable ($config["upload_dir"])  ?
		ainfo ('upload dir: ok') :
		aalert ("image dir: FAILED - ({$config["upload_dir"]}) <br>
			either does not exist or is not writable for webserver!<br>
			note, that it should be world-writable");

	adm_info ("logging and debug system check (fix in public/config.php)");
	if (empty ($config['debug_level']))
		aalert ("debug level: ZERO - no messages will be displayed (not even FATAL ERRORS!)");
	else {
		ainfo ("debug level ok, testing: (3 or 5 messages shown)");
		echo "<blockquote>";
		debug ("TEST MLOG_DEBUG: std debug message");
		debug_db ("TEST MLOG_DEBUG_DB: db query debugging");
		notice ("TEST MLOG_NOTICE: notice/info");
		warning ("TEST MLOG_WARNING: warning message");
		error ("TEST MLOG_ERROR: (FATAL) error message");
		echo "</blockquote>";
	}

/*	// TASET TESTS * /
	$a = array (
		"a"	=> 'style="color: green"',
        "p" => "class=author",
		"td" => "", //array ('style="background-color: green"', 'style="background-color: yellow"'),
		"tr" => array ('style="background-color: red"', 'style="background-color: yellow"'),
		"table" => 'style="background-color: gray"',
		"thead" => 'style="background-color: green"',
	);
	$d = array (
		array ("0", "b", "c", "d"),
		array ("1", "b", "c", "d"),
		array ("2", "f", "g", "h"),
		array ("3", "c", "y", "z"),
	);
	echo '</form>';
	echo '<form name="t1_list">';
    $t = new taset ($a, "warning");
	$table1 = new list_table ($d, true, "t1_list");
	$table1->use_header (array ("", "A", "B", "C"));
	$table1->use_checkboxes (array (0), "B");
	$table1->render ();
	echo '</form>';

	echo '<form name="t2_list">';
	$table2 = new list_table_taset ($d, $t, true, "t2_list");
	$table2->use_header (array ("", "A", "B", "C"));
	$table2->use_checkboxes (array (0), "A");
	$table2->render ();
	echo '</form>';

?>	<br>
	<a href="." <?= $t->get('a'); ?>>ahoj</a>
	<p <?= $t->get('p'); ?>>test</p>
	<!-- <h1 <?= $t->get('h1'); ?>>test2</h1> -->
	<table border="1">
	<tr>
<?	for ($i=0; $i<10; $i++) {
		echo "<td ". $t->get ("td") .">test</td>";
	}
?>	</tr>
	</table>
<?
/**/

/* 	// IMAGES TESTS
	adm_info ("images tests");
	debug ($images->get_filename (1));
	debug ($images->get_dir (1));
	debug ($images->get_url (1));
	echo $images->preview_button (1);
/**/

/*	// DUMP TESTS
	// TODO: class.dump.php is mysql specific
	// it runs under pgsql, but generates mysql dump :-)
	if ($config["db_type"] == "mysql") {
		echo "<br>";
		adm_info ("db dump");
		require (INCLUDE_DIR ."/classes/class.dump.php");
		require (INCLUDE_DIR ."/tables.php");
		$dump =& new dump ($db, $tables);
		//echo "<pre>".$dump->get_dump ()."</pre>";
		echo $dump->get_dump_link ($config["upload_dir"], $config["upload_url"]);

		echo "<hr>";
	}
/**/

/*	// DUMP TESTS
	// TODO: move to a function (most likely to db object)
	// NOTE: this does not work with different www and db host
	mt_srand ((double) microtime() * 1000);
	$dumpfile = sprintf ("dump.%s.%s.gz", date ('Y-m-d'), mt_rand ());
	$tmp = "$config["upload_dir"]/$dumpfile";
	if ($config["db_type"] == "mysql") {
		system ("rm -f $config["upload_dir"]/dump.200*.gz");
		system ("mysqldump -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME | gzip >$tmp", $retval);
		if ($retval != -1) {
			echo '<p>This is your backup: <a href="', $config["upload_url"], '/', $dumpfile, '">', $dumpfile, '</a><br></p>';
		} else
			info ("db dump failed");
	}
*/


	adm_info ("common info");
	echo "PHP version: ", phpversion (), "<br>";
	//echo "&nbsp;&nbsp; register_globals: ", ini_get ('register_globals'), "<br>";
	echo "database engine: ", $config["db_type"], "<br>";
	if ($config["db_type"] == "mysql") {
		echo "&nbsp;&nbsp; {$config["db_type"]} server version: ", mysql_get_server_info(), "<br>";
		echo "&nbsp;&nbsp; {$config["db_type"]} client version: ", mysql_get_client_info(), "<br>";
		echo "&nbsp;&nbsp; {$config["db_type"]} host : ", mysql_get_host_info(), "<br>";
		echo "&nbsp;&nbsp; {$config["db_type"]} protocol: ", mysql_get_proto_info(), "<br>";
  	} elseif ($config["db_type"] == "postgres") {
		//echo "&nbsp;&nbsp; $config["db_type"] server version: ", mysql_get_server_info(), "<br>";
		//echo "&nbsp;&nbsp; $config["db_type"] client version: ", mysql_get_client_info(), "<br>";
		echo "&nbsp;&nbsp; {$config["db_type"]} host : ", pg_host(), "<br>";
		//echo "&nbsp;&nbsp; $config["db_type"] protocol: ", mysql_get_proto_info(), "<br>";
		echo "&nbsp;&nbsp; {$config["db_type"]} client encoding : ", pg_client_encoding(), "<br>";
	}
	echo "<br>";
	$http_vars = array (
		'SERVER_NAME',			'SERVER_SOFTWARE',
		'SERVER_PROTOCOL',		'REQUEST_METHOD',
		'HTTP_HOST',			'HTTP_ACCEPT_CHARSET',
		'HTTP_ACCEPT_ENCODING',	'HTTP_ACCEPT_LANGUAGE',
		'HTTP_CONNECTION',
	);
	foreach ($http_vars as $tmp)
		if (isset ($_SERVER[$tmp]))
			echo strtolower ($tmp), ": ", $_SERVER[$tmp], "<br>";

	adm_info ("list of sessions");
	$db->exec ("SELECT * FROM Sessions;");
	if (!($num = $db->num_rows ())) {
		echo "<b>Result empty.</b>";
	} else {
		echo "<table border=1 cellpadding=2 cellspacing=0>";
		for ($j=0; $j<$num; $j++) {
	        $row = $db->get_result ();
			echo "<tr>";
			for ($i=0; $i < count ($row); $i++)	{
				echo "<td style=\"font-size:8pt\">";
				echo $row[$i];
				echo "</td>";
			}
			echo "</tr>";
		}
		echo "</table>";
	}

	adm_info ("RTE (richedit) browser test");
	$editor =& new richedit ("items",
		"<img src=\"./gui/img/richedit.gif\" alt=\"Richedit editor\" border=0>");
  	echo "client browser: ", $editor->browser;
	if ($editor->check_browser ())
		echo "<br>RTE result: ok, should be available.<br>";
	else
		echo "<br>RTE result: rejected, won't be available.<br>";
	$editor->place ('test', 'win0');

	//info ("other");
	//echo urlencode ("_=");

	adm_info ("user network information");
	echo "remote address: ", $_SERVER['REMOTE_ADDR'], "<br>";
	echo "session saved address: ", $session_data['ip'], "<br>";
	echo "host: ", gethostbyaddr ($_SERVER['REMOTE_ADDR']), "<br>";
	$list = gethostbynamel (gethostbyaddr ($_SERVER['REMOTE_ADDR']));
	echo "list of user addresses: ";
	foreach ($list as $string)
		echo $string, " ; ";

?>
<br>
Return current item: Article System