Location: PHPKode > projects > WebArchive > phparchive.0.1.82.beta/wacommon.inc.php
<?php
/**
 *
 * @version $Id: wacommon.inc.php,v 1.11 2004/01/06 16:30:39 freedev Exp $
 * @package wa_common
 * @author Vincenzo D'Amore <hide@address.com>
 */

/**
 * Load system constants and messages.
 *
 */
require_once("./includes/constants.inc.php");
require_once("./messages.inc.php");

/**
 *
 *
 */
function WAGlobalInit()
{
	$GLOBALS["WA_PATH"] = dirname(__FILE__);
	require_once("./config.inc.php");
	if (file_exists($GLOBALS["WA_PATH"].'/config.custom.inc.php'))
	{
		require_once("./config.custom.inc.php");
	}

//	$GLOBALS['WA_DOCROOT_DIR'] = AppendSlash($GLOBALS['WA_DOCROOT_DIR']);
	$GLOBALS['WA_UPLOAD_DIR'] = AppendSlash($GLOBALS['WA_UPLOAD_DIR']);
	$GLOBALS['WA_ABSOLUTE_URI'] = AppendSlash($GLOBALS['WA_ABSOLUTE_URI']);
	$GLOBALS['WA_DOWNLOAD_URI'] = AppendSlash($GLOBALS['WA_DOWNLOAD_URI']);

	WAMessagesLoad();
}

/**
 * function: AppendSlash
 * parameters: $sDir
 * description:
 */
function AppendSlash($sDir)
{
	if (($sDir[strlen($sDir)-1]!='/') &&
		($sDir[strlen($sDir)-1]!='\\') )
		$sDir.='/';
	return $sDir;
}

/**
 * Useful to append SessionId at urls
 *
 * parameters: $uri
 */
function AddSessionInUrl($uri)
{
	if (!empty($uri))
	{
		$uriRe = parse_url($uri);
		$newUrl = "";
		if (!empty($uriRe['scheme']) )
			$newUrl = $uriRe['scheme']."://";
		if (!empty($uriRe['host']) )
			$newUrl .= $uriRe['host'];
		if (!empty($uriRe['path']) )
			$newUrl .= $uriRe['path'];
//		$newUrl .= "?".WA_SESSION_NAME."=".session_id();
		$newUrl .= "?".SID;
		if (!empty($uriRe['query']) )
			$newUrl .= "&amp;".str_replace("&", "&amp;", $uriRe['query']);
		if (!empty($uriRe['fragment']) )
			$newUrl .= "#".$uriRe['fragment'];
		return $newUrl;
	}	
}

function PrintHTMLHeader($sTitle, $sRedirect = "", $iSec = "0")
{
	if (!isset($_SESSION["gsStyleName"]))
		$sStyleName = WA_CURRENT_CSS_FILE;
	else
		$sStyleName = $_SESSION["gsStyleName"];

	$sRedirect = AddSessionInUrl($sRedirect);
//	$uri = parse_url($GLOBALS['WA_ABSOLUTE_URI']);

//	$uri['path'] = AppendSlash($uri['path']);

//	echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
//	echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
	echo '<html><head><title>'.$sTitle.'</title>';
	if (!empty($sRedirect))
		echo "<META HTTP-EQUIV='Refresh' CONTENT='".$iSec.";URL=".$sRedirect."'>";
//	echo '<link rel="stylesheet" href="styles/'.$sStyleName.'" src="styles/'.$sStyleName.'" type="text/css">';
//	echo '<link rel="shortcut icon" href="'.$uri['path'].'images/wa_ico.png">';
//	echo '<link rel="stylesheet" title="Standard" href="'.$uri['path'].'styles/'.$sStyleName.'" type="text/css">';
//	echo '<link rel="alternate stylesheet" title="Medium" href="'.$uri['path'].'styles/common.css" type="text/css">';
	echo '<link rel="shortcut icon" href="images/wa_ico.png">';
	echo '<link rel="stylesheet" title="Standard" href="styles/'.$sStyleName.'" type="text/css">';
	echo '<link rel="alternate stylesheet" title="Medium" href="styles/common_small.css" type="text/css">';
	echo '<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">';
	echo '<META http-equiv="Default-Style" content="Standard">';
	echo '</head>';
}

/**
 *
 *
 */
 
function StartMainTable()
{
	echo '<script type="text/javascript" Language="JavaScript1.2" src="javascripts/handleform.js"></script>';
	echo "<!--- Main Table Start -->";
	echo '<table width="100%" border="0" cellspacing="2" cellpadding="2">';
	echo '<tr>';
	echo '<td></td>';
	echo '</tr>';
	echo '<tr>';
    echo '<td>';
}

/**
 *
 *
 */
 
function EndMainTable($ChildUIDForm)
{
	echo "</td></tr></table>";
	echo "<!--- Main Table End -->";
	// Funzioni Javascript
	EchoWAWindowOpen();
	echo "<script type='text/javascript' Language='JavaScript1.2'>\n";
	if (isset($ChildUIDForm))
	{
echo <<<END
function formLocationChange(currentWindow)
{

END;
	echo "	var IdForm = '".$ChildUIDForm."';\n";
echo <<<END
		if (IdForm.length > 0)
		{
			var hrefDest = "#FormHRef" + IdForm;
			var hrefStart = "" + currentWindow.location.href;
			if (hrefStart.substr(hrefStart.length - hrefDest.length, hrefDest.length) != hrefDest)
			{
				location.href = hrefDest;
			}
		}
		return null;
}

END;
	}
	echo "</script>";
}


/**
 * propagate WA_SESSION in popup
 *
 */
 
function EchoWAWindowOpen()
{
	echo '<script type="text/javascript" Language="JavaScript1.2">';
	echo 'function WAOpenPopup(curWindow, urlString, paramString, val1, val2){';
	echo 'var WA_SESSION = "'. WA_SESSION_NAME."=".session_id().'"; ';
	echo 'var newUrlString = urlString + "?" + WA_SESSION + "&" + paramString;';
	echo 'return curWindow.open(newUrlString, val1 , val2); }';
	echo '</script>';
}

/**
 *
 *
 */
function ShowArrayContent(&$myArray)
{
	reset ($myArray);
	echo "<pre>";
	while (list ($chiave, $valore) = each ($myArray)) {
		echo $chiave ." => [". $valore. "]\n";
	}
	echo "</pre>";
}

function WACreateSession($bNewSession)
{
	$bRC = false;

//	$bRC = setcookie("PHPSESSID",$PHPSESSID,time()+3600);
	if ($GLOBALS['WA_PRIVATE_SESSIONS'])
	{
		ini_set("session.use_cookies", "0");
		ini_set("session.use_only_cookies", "0");
		ini_set("session.use_trans_sid", "0");
		ini_set("url_rewriter.tags", "");
	}
//	ini_set("url_rewriter.tags", "a=href,area=href,frame=src,input=src,form=fakeentry");
	session_name(WA_SESSION_NAME);
	
	if (!session_start())
	{
		echo WA_MSG_ERROR_START_SESSION;
		if (!empty($GLOBALS['WA_DIRECTORY_SESSIONS']))
			die("ERROR! ( set the session.save_path in the php.ini )");
//		echo "<BR>";
		die(WA_REDIRECT_LOGOUT_PAGE);
	}
	return $bRC;
}

/**
 * Start a new session
 *
 * This function check if the custom directory for session handling is configured
 * then start a new session otherwise show an error message.
 */
function WAStartSession($bNewSession)
{
//	header("Cache-control: private, no-cache");

	if (empty($GLOBALS['WA_DIRECTORY_SESSIONS']))
	{
		WACreateSession($bNewSession);
	}
	elseif (session_save_path($GLOBALS['WA_DIRECTORY_SESSIONS']))
	{
		WACreateSession($bNewSession);
	}
	else
	{
		die(WA_MSG_ERROR_START_SESSION."(".$GLOBALS['WA_DIRECTORY_SESSIONS'].")<BR>");
	}
}

/**
 * Check if there is an enabled session
 *
 * This function check if the custom directory for session handling is configured
 * then start a new session otherwise show an error message.
 */
function CheckSession()
{
	WAStartSession(false);

	$client_fingerprint  = md5($_SERVER['HTTP_USER_AGENT'].$_SERVER['HTTP_ACCEPT'].$_SERVER['HTTP_ACCEPT_ENCODING']);

	if ((!isset($_SESSION["gbLoggedIn"])) || 
		(!$_SESSION["gbLoggedIn"]) )
//		($_SESSION["gsUserFingerprint"] != $client_fingerprint))
	{
		session_unset();
		session_destroy() ;
		die(WA_REDIRECT_LOGOUT_PAGE);
	}
}

WAGlobalInit();

?>
Return current item: WebArchive