Location: PHPKode > projects > MJGUEST > mjguest/mjguest.php
<?php
	
	/*
	+----------------------------------------------------------------
	|
	|	MJGUEST 6.8 GT Series
	|	=============================================================
	|	Copyright (c) 2002-2008 Giacomo "mdsjack" Menni
	|	Agreement: http://www.mdsjack.bo.it/files/agreement.htm
	|	=============================================================
	|	
	|	Official website:	http://www.mdsjack.bo.it
	|	Script email:		hide@address.com
	|	Agreement info:		hide@address.com
	|	
	|	Visit official forums for further information and support.
	|
	+----------------------------------------------------------------
	|
	|	Hello!
	|	If you're taking a look, you're welcome!
	|	
	|	Many people spent their free time to make this
	|	project so amazing.
	|	If you like this script why don't you join us,
	|	instead of working against us? You will be welcome!
	|	You might give us your suggestion to improve this
	|	application all toghether, making it even better.
	|	
	|	...and you will be part of the Team.
	|
	|	Otherwise, remember that stealing code is a crime.
	|	We will spot you and prosecute to the fullest
	|	extent allowed by law.
	|	
	+----------------------------------------------------------------
	*/
	
	if (!empty($mjguest_embedded_iso)) ob_end_flush();
	
	ob_start();
	ob_implicit_flush(0);
	
	#----- Here we set some php params -----#
	
	set_magic_quotes_runtime(0);
	@ini_set('magic_quotes_sybase',	false);
	
	#----- Embedding management -----#
	
	if (!defined('mjguest_basedir'))
		define('mjguest_basedir', false);
	
#	include (mjguest_basedir.'../../../Kwik-e-mark/kwikemark.class.php');	
#	$s = &new benchmark;
	
	#----- We must require the core of the guestbook -----#
	
	require (mjguest_basedir.'mjguest.core.php');
	
	#----- Let's wake up the core base -----#
	
	$mjguest = new guestbook;
	
	#----- This is the logics of the main routine -----#
	
	$_GET['do'] = empty($_GET['do']) ? null : $_GET['do'];
	
	switch ($_GET['do']):
		
		case null:
		case 'read':
			
			if (empty($_GET['from'])) $_GET['from'] = 0;
			
			$mjguest->gui->startup();
			
			if (mjguest_basedir and $mjguest->settings->param['comment_system']):
				ob_start();
				$mjguest->gui->block('insert');
				$form = ob_get_clean();
			endif;
			
			$mjguest->gui->block('reader_head');
			
			if (!$mjguest->entry->get_set())
				$mjguest->gui->redirect(1, 'guestbook_empty', 'do=write');
			
			while ($mjguest->entry->get_each())
				$mjguest->gui->block('reader_entry', true);
			
			$mjguest->gui->block('reader_foot');
			
			if (mjguest_basedir and $mjguest->settings->param['comment_system'])
				echo $form;
			
		break;
		/*
		case 'redirect':
			
			$mjguest->gui->startup();
			$mjguest->gui->block('redirect');
			
		break;
		*/
		case 'delete':
			
			if (!empty($_GET['id']) and $mjguest->user->get('status') > 1)
				$mjguest->entry->cancel($_GET['id']);
			
			elseif (!empty($_GET['ip']) and $mjguest->user->get('status') == 3)
				$mjguest->entry->ban_guest($_GET['ip']);
			
			else
				$mjguest->gui->redirect(2, 'not_admin', 'do=setup');
			
			$mjguest->gui->redirect(0, 'entry_deleted', "do=read&from={$_GET['from']}");
			
		break;
		
		case 'edit':
			
			if ($mjguest->user->get('status') > 1 /* [CONTROLLO HACKER PER URL DIRETTO (no via icona)] or ([questa entry รจ appena stata scritta da questo user] entro lasso antiflood x questa entry AND user ha scritto questa entry) */ ):
				
				if (!empty($_POST)):
					
					if (trim($_POST['message'])):
					
						$mjguest->entry->update();
						$mjguest->gui->redirect(0, 'entry_modified', "do=read&from={$_GET['from']}#e_{$_GET['id']}");
					
					else:
						$mjguest->gui->redirect(1, 'entry_not_added', "do=read&from={$_GET['from']}#e_{$_GET['id']}");
					endif;
					
				else:
					$mjguest->entry->get_one();
					
					$mjguest->gui->startup();
					$mjguest->gui->block('insert');
					
				endif;
				
			else:
				$mjguest->gui->redirect(2, 'not_admin', 'do=setup');
			endif;
		break;
		
		case 'write':
			
			if ($mjguest->user->get('status') == 1 and $mjguest->entry->check_flood($mjguest->user->get('ip')))
				$mjguest->gui->redirect(1, 'already_signed', 'do=read&from=0');
			
			elseif ($mjguest->user->get('status') == 1 and in_array($mjguest->user->get('ip'), $mjguest->settings->param['banned']))
				$mjguest->gui->redirect(2, 'not_admin', 'do=read&from=0');
			
			if (!empty($_POST)):
				
				if ($_POST['entrycode'] != $mjguest->user->get('entrycode'))
					$mjguest->gui->redirect(1, 'entry_not_added', 'do=write');
				
				elseif ($mjguest->settings->param['captcha'] and ($mjguest->user->get('status') == 1 or mjguest_debugmode) and (md5((int)$_POST['captcha']) != $mjguest->user->get('captcha')))
					$mjguest->gui->redirect(1, 'entry_not_added', 'do=write');
				
				$mjguest->user->set('captcha');
				$mjguest->user->set('entrycode');
				
				if ($mjguest->entry->add()):
					
					if ($mjguest->user->get('status') == 1 and $mjguest->settings->param['notifynewentry'])
						email($mjguest->settings->param['adminmail'].($mjguest->settings->param['mod_account']? ','.$mjguest->settings->param['modmail'] : ''), 'New guestbook entry', ($_POST['name'] ? $_POST['name'] : 'A guest').' wrote: '.$mjguest->entry->detail['message']);
					
					$mjguest->gui->redirect(0, 'entry_added', 'do=read&from=0');
					
				else:
					$mjguest->gui->redirect(1, 'entry_not_added', 'do=write');
				endif;
				
			else:
				$mjguest->user->set('captcha');
				$mjguest->user->set('entrycode');
				
				$mjguest->gui->startup();
				$mjguest->gui->block('insert');
			endif;
			
		break;
		
		case 'reply':
			
			if ($mjguest->user->get('status') > 1):
				
				if (!empty($_POST)):
				
					$mjguest->entry->reply();
					$mjguest->gui->redirect(0, 'entry_modified', "do=read&from={$_GET['from']}#e_{$_GET['id']}");
				
				else:
					$mjguest->entry->get_one();
					
					$mjguest->gui->startup();
					$mjguest->gui->block('insert');
					
				endif;
				
			else:
				$mjguest->gui->redirect(2, 'not_admin', 'do=setup');
			endif;
		break;
		
		case 'approve':
			
			if ($mjguest->user->get('status') > 1):
				
				$mjguest->entry->approve();
				$mjguest->gui->redirect(0, 'entry_modified', "do=read&from={$_GET['from']}#e_{$_GET['id']}");
				
			else:
				$mjguest->gui->redirect(2, 'not_admin', 'do=setup');
			endif;
		break;
		
		case 'setup':
			
			if ($mjguest->user->get('status') > 1):
				
				if (!empty($_POST)):
					
					if (isset($_POST['logout'])):
						$mjguest->user->disconnect();
						$mjguest->gui->redirect(0, 'logged_out', 'do=read&from=0');
					
					else:
						if (isset($_POST['trashdata']))
							$mjguest->entry->trash();
						
						( isset($_POST['restoreconfig'])
						?	$mjguest->settings->restore()
						:	$mjguest->settings->update() )
							?	$mjguest->gui->redirect(0, 'config_updated', 'do=setup')
							:	$mjguest->gui->redirect(2, 'not_admin', 'do=read&from=0');
						
					endif;
					
				else:
					$mjguest->gui->startup();
					
					($mjguest->user->get('status') == 2 and $mjguest->settings->param['mod_account'])
					?	$mjguest->gui->block('cp_mod')
					:	$mjguest->gui->block('cp_admin')
					;
					
				endif;
				
			else:
				
				if (!empty($_POST)):
					
					if ($mjguest->user->authorize()):
						$mjguest->gui->redirect(0, 'logged_in', 'do=setup');
					else:
						$mjguest->gui->redirect(2, 'wrong_pass', 'do=read&from=0');
					endif;
					
				else:
					$mjguest->gui->redirect(2, 'not_admin', 'do=read&from=0');
				endif;
			endif;
			
		break;
		
		default:
			$mjguest->gui->redirect(2, 'not_admin', 'do=read&from=0');
		
	endswitch;
	
	#----- Send everything to the browser -----#
	
	$mjguest->gui->output();
	
	#----- If we are debugging, we can print some useful info -----#
	
	if (mjguest_debugmode):
		echo
		'<style>div#body { float:left;z-index:5; }</style><div style="position: relative; float:left; width: 420px; margin-left: 10px; margin-top: 5px; overflow: auto">',
		'<b>Versione PHP:</b> ', PHP_VERSION, '<br />',
		'<b>php.ini</b> magic_quotes_runtime ', (int) @ini_get('magic_quotes_runtime'), '<br />',
		'<b>php.ini</b> magic_quotes_sybase ', (int) @ini_get('magic_quotes_sybase'), '<br />',
		'<b>php.ini</b> magic_quotes_gpc ', (int) @ini_get('magic_quotes_gpc'), '<br />',
		'<b>Database:</b> ',$mjguest->db->driver,' (',db_type,')<br />',
		'<b>Queries</b> - ', $mjguest->db->tot_queries, '<br />',
	#	'<b>Tempo di esecuzione:</b> ', $s->runtime(0), '<br />',
		'<b>Memoria usata:</b> ', function_exists('memory_get_usage') ? memory_get_usage() : '' , '<br />',
		'<b>Memoria totale:</b> ', @ini_get('memory_limit'), '<br />',
		'<b>Lunghezza buffer</b> - ', ob_get_length(), '<br /><br />',
		'<b>AJAX Response:</b><br /><textarea id="ajax_debug" name="ajax_debug" wrap="off" style="font-family:monospace;font-size:11px;width:395px;height:100px;overflow:auto" readonly="readonly"></textarea><br /><br />',
		'<b>Dati $_SESSION ('.session_id().'):</b> <pre>', print_r($_SESSION), '</pre>',
		'<b>Dati $_POST:</b> <pre>', print_r($_POST), '</pre>',
		'<b>Dati $_FILES:</b> <pre>', print_r($_FILES), '</pre>',
		'<b>Dati $_COOKIE (Key: ',(!empty($_COOKIE['mjguest']) ? print_r($_COOKIE['mjguest']['key']) : ''),'):</b> <pre>',(!empty($_COOKIE['mjguest']) ? print_r($_COOKIE['mjguest']['data']) : ''), '</pre>',
		'<b>Errori PHP soppressi:</b> ', @$php_errormsg, '<br />',
		'<b>Debug Backtrace:</b> <pre>', print_r(@debug_backtrace()), '</pre><br /><br />',
		'</div>',
		'<div style="width:100%;height:300px;overflow:scroll;font-size:150%">', !empty($_GET['phpinfo']) ? phpinfo() : '','</div>'
		;
	endif;
	
	#----- Exit application succesfully -----#
	
	ob_end_flush();
	
	$mjguest->user->save();
	
	unset($mjguest);
	
	if (!empty($mjguest_embedded_iso)) ob_start('ob_utf8_encode');
?>
Return current item: MJGUEST