<?php

	function sanitize($field)
	{
		global $dbc;

		$temp = mysqli_real_escape_string($dbc, trim($field));
		return $temp;
	}
	function clean($field)
	{
		global $dbc;
		$temp = htmlspecialchars_decode($field);

		return $temp;
	}
	function getFromDatabase($sql)
	{
		global $dbc;
		$result = mysqli_query($dbc, $sql) or die(mysqli_error($dbc));
		return $result;
	}

	function getAdminNav()
	{
		$currentPage = $_SERVER['REQUEST_URI'];
		$securityLevel = $_SESSION['intSecurityLevel'];

		// $nav = $currentPage.'<br>';
		global $dbc;
		global $first_name;

		// if ($securityLevel == 50 || $first_name == "Kingsway")
		// {
		// 	$nav .= '<h3>Kingsway Mall</h3>';
		// 	$nav .= '<a href="kingsway-contest-listing.php" ';
		// 	if (strpos($currentPage, 'kingsway-contest-listing.php') !== false)
		// 	// if (strcmp($currentPage, 'medicine-hat-contest-listing.php') == 0) 
		// 	{
		// 		$nav .= 'class="active"';
		// 	}
		// 	$nav .='>Kingsway Kindness 2015 Listing</a>';	

		// 	$nav .= '<a href="kingsway-contest-listing-old.php" ';
		// 	if (strpos($currentPage, 'kingsway-contest-listing-old.php') !== false)
		// 	// if (strcmp($currentPage, 'medicine-hat-contest-listing.php') == 0) 
		// 	{
		// 		$nav .= 'class="active"';
		// 	}
		// 	$nav .='>Previous Contest Listing</a>';	
		// }

		if ($securityLevel == 50 || $first_name == "Medicine Hat")
		{
		

			$nav .= '<h3>Medicine Hat</h3>';
			$nav .= '<a href="medicine-hat-contest-listing.php" ';
			if (strpos($currentPage, 'medicine-hat-contest-listing.php') !== false)
			// if (strcmp($currentPage, 'medicine-hat-contest-listing.php') == 0) 
			{
				$nav .= 'class="active"';
			}
			$nav .='>2015 Contest Listing</a>';

			$nav .= '<a href="medicine-hat-contest-listing-old.php" ';
			if (strpos($currentPage, 'medicine-hat-contest-listing-old.php') !== false)
			// if (strcmp($currentPage, 'medicine-hat-contest-listing.php') == 0) 
			{
				$nav .= 'class="active"';
			}
			$nav .='>Previous Contest Listing</a>';

		}

		if ($securityLevel == 50 || $first_name == "Peter Pond")
		{
		

			$nav .= '<h3>Peter Pond Mall</h3>';
			$nav .= '<a href="shop-win-drive.php" ';
			if (strpos($currentPage, 'shop-win-drive.php') !== false)
			// if (strcmp($currentPage, 'medicine-hat-contest-listing.php') == 0) 
			{
				$nav .= 'class="active"';
			}
			$nav .='>Shop. Win. Drive.</a>';
			
			$nav .= '<a href="polaris-rzr.php" ';
			if (strpos($currentPage, 'polaris-rzr.php') !== false)
			// if (strcmp($currentPage, 'medicine-hat-contest-listing.php') == 0) 
			{
				$nav .= 'class="active"';
			}
			$nav .='>Polaris RZR</a>';

		}

		if ($securityLevel == 50 || $first_name == "Park Place")
		{
			$nav .= '<h3>Park Place</h3>';
			$nav .= '<a href="park-place-2018.php" ';
			
			if (strpos($currentPage, 'park-place-2018.php') !== false)
			{
				$nav .= 'class="active"';
			}
			$nav .= '>Park Place 2018</a>';

			$nav .= '<a href="our-favorite-things-2016.php" ';
			
			if (strpos($currentPage, 'our-favorite-things-2016.php') !== false)
			{
				$nav .= 'class="active"';
			}
			$nav .= '>Our Favorite Things</a>';

			$nav .= '<a href="eat-free-for-a-year.php" ';
			
			if (strpos($currentPage, 'eat-free-for-a-year.php') !== false)
			{
				$nav .= 'class="active"';
			}
			$nav .= '>Eat Free For A Year</a>';


			// $nav .= '<a href="park-place-contest-listing-old.php" ';
			
			// if (strpos($currentPage, 'park-place-contest-listing-old.php') !== false)
			// {
			// 	$nav .= 'class="active"';
			// }
			// $nav .= '>Previous Contest Listing</a>';
		}

		$nav .= '<h3>People</h3>';
		
		if ($securityLevel == 50)
		{
			// $nav .= '<h3>People</h3>';
			$nav .= '<a href="user-listing.php" ';
			// if (strcmp($currentPage, 'user-listing.php') == 0) 
			if (strpos($currentPage, 'user-listing.php') !== false)
			{
				$nav .= 'class="active"';
			}
			$nav .='>CMS Users</a>';
		}

		$nav .= '<h3>Settings</h3>';

		return $nav;
	}

	function getLoginNav()
	{
		$currentPage = substr($_SERVER['REQUEST_URI'], 7);
		$securityLevel = $_SESSION['intSecurityLevel'];
		// echo 'not cropped ' . $_SERVER['REQUEST_URI'];
		// $nav = $currentPage;
		global $dbc;
		global $first_name;
		// echo "loged in as "  . $first_name;
		// if ($securityLevel == 50 || $first_name == "Kingsway")
		// {
		// 	$nav .= '<h3>Kingsway Mall</h3>';
		// 	$nav .= '<a href="../cmsAdmin/kingsway-contest-listing.php" ';
		// 	if (strpos($currentPage, 'kingsway-contest-listing.php') !== false)
		// 	// if (strcmp($currentPage, 'medicine-hat-contest-listing.php') == 0) 
		// 	{
		// 		$nav .= 'class="active"';
		// 	}
		// 	$nav .='>Kingsway Kindness 2015 Listing</a>';	

		// 	$nav .= '<a href="../cmsAdmin/kingsway-contest-listing-old.php" ';
		// 	if (strpos($currentPage, 'kingsway-contest-listing-old.php') !== false)
		// 	// if (strcmp($currentPage, 'medicine-hat-contest-listing.php') == 0) 
		// 	{
		// 		$nav .= 'class="active"';
		// 	}
		// 	$nav .='>Previous Contest Listing</a>';	
		// }

		if ($securityLevel == 50 || $first_name == "Medicine Hat")
		{
		
			$nav .= '<h3>Medicine Hat</h3>';

			$nav .= '<a href="../cmsAdmin/medicine-hat-contest-listing.php" ';
			// if (strcmp($currentPage, 'medicine-hat-contest-listing.php') == 0) 
			if (strpos($currentPage, 'medicine-hat-contest-listing.php') !== false)
			{
				$nav .= 'class="active"';
			}
			$nav .='>Contest Listing</a>';
		}


		if ($securityLevel == 50 || $first_name == "Park Place")
		{
			$nav .= '<h3>Park Place</h3>';
			$nav .= '<a href="../cmsAdmin/park-place-contest-listing.php" ';
			// if (strcmp($currentPage, 'park-place-contest-listing.php') == 0) 
			if (strpos($currentPage, 'park-place-contest-listing.php') !== false)
			{
				$nav .= 'class="active"';
			}
			$nav .= '>Contest Listing</a>';
		}

		$nav .= '<h3>People</h3>';

		if ($securityLevel == 50)
		{
			//add check for security level ==50 for viewing users
			$nav .= '<a href="../cmsAdmin/user-listing.php" title="Click here to view all users currently allowed to create and edit pages. Only administrators have the right to view this page. From here you can also add or edit users. " ';
			// if (strcmp($currentPage, 'user-listing.php') == 0) 
			if (strpos($currentPage, 'user-listing.php') !== false)
			{
				$nav .= 'class="active"';
			}
			$nav .='>CMS Users</a>';
		}

		$nav .= '<h3>Settings</h3>';

		if (strcmp($_SESSION['updateSiteMap'], '1') == 0)
		{
			$nav .= '<a class="highlight" href="../cmsAdmin/newXML.php" title="If you see this it means that your sitemap.xml file needs to be updated. Click here to generate a new sitemap for Google.">Update SiteXML</a>';	
		}
		$nav .= '<a href="change_password.php" ';
		// if (strcmp($currentPage, 'change_password.php') == 0)
		if (strpos($currentPage, 'change_password.php') !== false)
		{
			$nav .= 'class="active"';
		}
		$nav .= '>Change Password</a>';
		$nav .= '<a href="logout.php" ';

		if (strcmp($currentPage, 'logout.php') == 0)
		{
			$nav .= 'class="active"';
			
		}
		$nav .= '>Logout</a>';
		$nav .= '<a href="../cmsAdmin/">Control Panel</a>';	
		$nav .='<a href="../">Preview Main Site</a>';


		
		return $nav;
	}

	function getLogNav()
	{
		global $dbc;
		$currentPage = substr($_SERVER['REQUEST_URI'], 14);
		// $nav .= $currentPage;
		
		if ((isset($_SESSION['strFirstName'])) || ($loggedIn == 1) )
		{

			$nav .= '<a href="'.BASE_URL.'change_password.php" title="Click here to change your password. "';
			if (strcmp($currentPage, 'change_password.php') == 0) 
			{
				$nav .= 'class="active"';
			}
			$nav .='>Change your Password</a>';
			$nav .= '<a href="'.BASE_URL.'logout.php" title="Click here to logout.">Logout </a>';	
			$nav .= '<a href="'.BASE_URL.'../" target="_blank" title="Click here to go to the public area of your website.">Preview Main Site</a>';	
		}
		else
		{
			$nav .= '<a href="'.BASE_URL.'login.php" title="Click here to login to the control panel.">Login </a>';
			$nav .= '<a href="'.BASE_URL.'forgot_password.php" title="Click here if you\'ve forgotten your password. It will be reset.">Forgot your Password</a>';
			$nav .= '<a href="'.BASE_URL.'../" target="_blank" title="Click here to go to the public area of your website.">Main Site</a>';	
		}
		return $nav;
	}

?>