Location: PHPKode > projects > EasyFest > new/fun_admin.php
<?php

function connectToDB() 
{
	global $link, $dbhost, $dbuser, $dbpass, $dbname;

	($link = mysql_pconnect("$dbhost", "$dbuser", "")) || die("Couldn't connect to MySQL");

	// select db:
	mysql_select_db("$dbname", $link) || die("Couldn't open db: $dbname. Error if any was: ".mysql_error() );
} // end func dbConnect();

function displayErrors($messages) 
{
?>

	<style type="text/css">
	/*body{font-family: Arial, Helvetica; font-size: 10pt}*/
	p,ul,li{font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#CCCCCC;}
	h1{font-size: 12pt}
	</style>

<?php
	print("<b>There were problems with the previous action.  Following is a list of the error messages generated:</b>\n<ul>\n");

	foreach($messages as $msg)
	{
		print("<li>$msg</li>\n");
	}
	print("</ul>\n");
} // end func displayErrors($messages)

function displayErrorMsg($messages) 
{
?>	
	<style type="text/css">
	/*body{font-family: Arial, Helvetica; font-size: 10pt}*/
	h5{font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#FF0000}
	</style>
<?php	
	foreach($messages as $msg){
		print("<h5>\n$msg\n</h5>");
	}
}

function checkactivity()
{
	$inactive = 60*30;

// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION["timeout"]) ) 
{
   $session_life = time() - $_SESSION["timeout"];
   if($session_life > $inactive)
        { 
      // go to login page when idle
     header("Location: logout.php?warning=sessiontimeout"); 
   }
}
$_SESSION['timeout'] = time();
}

function checkLoggedIn($status)
{
	
	switch($status)
	{
		// if yes, check user is logged in:
		// ie for actions where, yes, user must be logged in(!)
		case "yes":
			if(!isset($_SESSION["adminloggedIn"]))
			{
				header("Location:admin_login.php");//change ...........
				exit;
			}
			break;
			
		case "no":
			if( isset($_SESSION["adminloggedIn"] ) && $_SESSION["adminloggedIn"] === true )
			{
				
				header("Location: index.php");
			}
			break;
	}
	// if got here, all ok, return true:
	return true;
}

// end func checkLoggedIn($status)

function checkPass($user, $password) {
	global $link;
	
	//$password = md5($password);
	
	//$pwd = substr($password,0,10);
	
		$query= "SELECT UserId,UserName FROM users WHERE UserName='$user' and Password='$password' and Type='0' ";
	$result=@mysql_query($query, $link)
		or die(" checkPass fatal error: ".mysql_error());
		
	// Check exactly one row is found:
	if(mysql_num_rows($result)==1) {
		$row=mysql_fetch_array($result);
		return $row;
	}
	
	return false;
} /*
function enterEndTime( $num ){

	$team = $_SESSION['team'];
	$query="SELECT level FROM cmr WHERE team='$team'";
	$result=mysql_query($query)
		or die(" enterEndTime fatal error1: ".mysql_error());

	// Check exactly one row is found:
	if(mysql_num_rows($result)==1) {
		$row=mysql_fetch_array($result);
		//return $row;
	}		
	
	foreach($row as $lev){ }
	if( $lev <= $num )
	{
		if( $num == 1 )
		{
			$end_time = date("Y-m-d H:i:s");
			$end_time = substr($end_time,10,14);
			
			$query="SELECT level FROM glh_time WHERE team='$team' AND level='$num'";
			$result=mysql_query($query) or die(" enterEndTime fatal error2: ".mysql_error());
			// Check exactly one row is found:
			if(mysql_num_rows($result) == 1) {
				$query="UPDATE glh_time SET end='$end_time' where team='$team' AND level='$num'";
				$result=mysql_query($query)
				or die(" enterEndTime fatal error3: ".mysql_error());
			}
		}
		else {
			$end_time = date("Y-m-d H:i:s");
			$end_time = substr($end_time,10,14);
					
			$query="SELECT level FROM glh_time WHERE team='$team' AND level='$num'";
			$result=mysql_query($query) or die(" enterEndTime fatal error4: ".mysql_error());
	
			// Check exactly one row is found:
			if(mysql_num_rows($result) == 1) {
				$query="UPDATE glh_time SET end='$end_time' where team='$team' AND level='$num'";
				$result=mysql_query($query)
				or die(" enterEndTime fatal error5: ".mysql_error());
			}
		}
	}
		
} */
function cleanMemberSession($UserName) {

   
	//$_SESSION["fname"]=$fname;
	$_SESSION["UserName"]=$UserName;
	$_SESSION["adminloggedIn"]=true;
	
} // end func cleanMemberSession($login, $pass)


function flushMemberSession() {
	// use unset to destroy the session variables

	//unset($_SESSION["fname"]);
	unset($_SESSION["UserName"]);
	unset($_SESSION["loggedIn"]);
	unset($_SESSION["adminloggedIn"]);
	session_destroy();

	return true; echo "hello";
} // send func flushMemberSession()


function doCSS() {
?>
<style type="text/css">
/*body{font-family: Arial, Helvetica; font-size: 10pt}*/
body,p,td{font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#CCCCCC}
a{font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#FFFFFF}
ul{list-style:none;margin:0;padding:0;}
li{float:left;}
ol li{float:none;}
h1{font-size: 12pt}
</style>
	<?php
} // end func doCSS()
/*

# function validates HTML form field data passed to it:
function field_validator($field_descr, $field_data, $field_type, $min_length="", $max_length="", $field_required=1) {
	# array for storing error messages
	global $messages;

	# first, if no data and field is not required, just return now:
	if(!$field_data && !$field_required){ return; }

	# initialize a flag variable - used to flag whether data is valid or not
	$field_ok=false;

	# this is the regexp for email validation:
	$email_regexp="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|";
	$email_regexp.="(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";

	# a hash array of "types of data" pointing to "regexps" used to validate the data:
	$data_types=array(
		"email"=>$email_regexp,
		"digit"=>"^[0-9]$",
		"number"=>"^[0-9]+$",
		"alpha"=>"^[a-zA-Z]+$",
		"alpha_space"=>"^[a-zA-Z ]+$",
		"alphanumeric"=>"^[a-zA-Z0-9]+$",
		"alphanumeric_space"=>"^[a-zA-Z0-9 ]+$",
		"string"=>""
	);

	# check for required fields
	if ($field_required && empty($field_data)) {
		$messages[] = "$field_descr is a required field.";
		return;
	}

	# if field type is a string, no need to check regexp:
	if ($field_type == "string") {
		$field_ok = true;
	} else {
		# Check the field data against the regexp pattern:
		$field_ok = ereg($data_types[$field_type], $field_data);
	}

	# if field data is bad, add message:
	if (!$field_ok) {
		$messages[] = "Please enter a valid $field_descr.";
		return;
	}

	# field data min length checking:
	if ($field_ok && ($min_length > 0)) {
		if (strlen($field_data) < $min_length) {
			$messages[] = "$field_descr is invalid, it should be at least $min_length character(s).";
			return;
		}
	}

	# field data max length checking:
	if ($field_ok && ($max_length > 0)) {
		if (strlen($field_data) > $max_length) {
			$messages[] = "$field_descr is invalid, it should be less than $max_length characters.";
			return;
		}
	}
}
*/
?>
Return current item: EasyFest