Location: PHPKode > projects > Ads Exchange Server > estigi_0.1.1_RC2/inc/funcs.inc.php
<?php

/***************************************************************************
 *                             funcs_ini.inc
 *                            -------------------
 *   begin                : sab, abril 1, 2007
 *   copyright            : (C)
 *   email                : hide@address.com
 *
 ***************************************************************************/

//Refresh webpage
function refrescar($destino, $t, $exit = 0){
	echo "<meta http-equiv='refresh' content='$t; URL=".$destino."'>";
	($exit == 1 ? exit : "");
}

//Cookies
function setGalleta($value){
	global $cookieName;
	global $cookieTime;

	setcookie($cookieName, $value, time() + $cookieTime, "/");
}

function readGalleta(){

	global $cookieName;
	global $divisor;
	global $divisor_per;

	$memberData = explode($divisor, $_COOKIE[$cookieName]);

	return array(
	"user_Name" => $memberData[0],
	"id_User"   => $memberData[1],
	"email"     => $memberData[2]
	);

}

function quitarGalleta(){
	global $cookieName;

	setcookie($cookieName, "", time() - 3600, "/");
}

function rehacerGalleta($array, $cambio, $nuevoValor){

	global $divisor;

	if($cambio != ""){
		$array[$cambio]  = $nuevoValor;
	}

	$a_valores = array_values($array); //Saca los valores
	$nuevaGalleta = implode($divisor, $a_valores); //Crea el string con los nuevos valores
	setGalleta($nuevaGalleta);
}

//Inicio de sesion, no se si se ocupa todavia
session_start();
header ("Cache-control: private");

function checkLogin($site){

	global $cookieName;
	global $session;
	$loged = 0;
 
	//If no $site is provided, no redirection will be done, you are just checking if there is someone logged in.
	if($session['id_User'] <= 0){ //Not loged in
		if($site != ""){
			echo "<meta http-equiv='refresh' content='0; URL=".$site."'>";
			exit;
		}
			else
				return $loged;
	}
		else
			return $loged = 1;
}

//Get all permissions for this user
function get_All_User_Settings($id_User){

	global $db_Pre;

	//Get data from user
	$q = "
		SELECT ".$db_Pre."groups.*
		FROM  ".$db_Pre."groups
		INNER JOIN ".$db_Pre."users ON ".$db_Pre."users.id_Group = ".$db_Pre."groups.id_Group
		WHERE ".$db_Pre."users.id_User = ".$id_User."
		";

	$q_Get_Settings = mysql_query($q) or die("Unable to Get Users Settings : " . mysql_error());

	$row = mysql_fetch_array($q_Get_Settings, MYSQL_ASSOC);
		$settings = array(
			'group_Name'         	=> $row['group_Name'],
			'edit_Users'         	=> $row['edit_Users'],
			'delete_Users'       	=> $row['delete_Users'],
			'user_List'          	=> $row['user_List'],
			'edit_Cat'           	=> $row['edit_Cat'],
			'edit_Sites'         	=> $row['edit_Sites'],
			'edit_Banners'       	=> $row['edit_Banners'],
			'reports'            	=> $row['reports'],
			'restrict_Countries' 	=> $row['restrict_Countries'],
			'view_Ratio'         	=> $row['view_Ratio'],
			'click_Ratio' 				=> $row['click_Ratio'],
			'def_Ad_State' 			=> $row['def_Ad_State'],
			'def_Website_State'  	=> $row['def_Website_State'],
			'max_Text_Ads' 			=> $row['max_Text_Ads'],
			'max_Img_Ads' 				=> $row['max_Img_Ads'],
			'restrict_Cats_Shown' 	=> $row['restrict_Cats_Shown'],
			'restrict_Cats_Display' => $row['restrict_Cats_Display'],
			'restrict_Times'			=> $row['restrict_Times'],
			'allow_Formats' 			=> $row['allow_Formats']
		);

	return $settings;

}

//Check specific permissions
function get_User_Settings($id_User, $setting, $site = 0){

	global $user_Settings;

	//If $site is provided it will be sent there if he doesn't have the permissions
	if($site != 0 && $user_Settings[$setting] != 1){
		echo "<meta http-equiv='refresh' content='0; URL=".$site."'>";
		exit;
	}

	return $user_Settings[$setting];

}

//Very simple function just to see if it is an image or a flash
function mime_Type($format, $img_Data){

	if(strpos($format, str_replace("image/", "", $img_Data)) !== FALSE)
		$type  = "img";
	else if(strpos($format, str_replace("application/", "", $img_Data)) !== FALSE)
		$type = "flash";

	else
		$type = 0;

	return $type;

}

//Export as a csv file
function exportCSV($query, $bookTitle, $a_columnas){

	$qColumnas = count($a_columnas) - 1;

	$data = "";

	//Field Name Data

	for ($i = 0; $i <= $qColumnas; $i++){ //Nombres de las columnas

		$data .= $a_columnas[$i].",";

	}

	$data .= "\n";

	//Row Data

	while($row = mysql_fetch_array($query, MYSQL_NUM)){

		for ($j = 0; $j <= $qColumnas; $j++){
			$data .= $row[$j].",";
		}

		$data .= "\n";

	}

	header("Content-type: application/octet-stream");
	header("Content-Disposition: attachment; filename=$bookTitle.csv;");
	header("Content-Type: application/ms-excel");
	header("Pragma: no-cache");
	header("Expires: 0");

	print $data;

}

function exportExcel($query, $bookTitle, $a_columnas){


	$qColumnas = count($a_columnas) - 1;

	//$result = mysql_query($query) or die("Unable to perform query: " . mysql_error());

	//XML Blurb

	$data = "<?xml version='1.0'?>

	<?mso-application progid='Excel.Sheet'?>

	<Workbook xmlns='urn:schemas-microsoft-com:office:spreadsheet' xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns:ss='urn:schemas-microsoft-com:office:spreadsheet' xmlns:html='http://www.w3.org/TR/REC-html40'>

	<Worksheet ss:Name='".$bookTitle."'>

	<Table>

	<Row>";

	//Field Name Data

	for ($i = 0; $i <= $qColumnas; $i++){ //Nombres de las columnas

		$data .= "<Cell><Data ss:Type='String'>".$a_columnas[$i]."</Data></Cell>";

	}

	$data .= "</Row>";

	//Row Data

	while($row = mysql_fetch_array($query, MYSQL_NUM)){

		$data .= "<Row>";

		for ($j = 0; $j <= $qColumnas; $j++){
			$data .= "<Cell><Data ss:Type='String'>".$row[$j]."</Data></Cell>";
		}

		$data .= "</Row>";

	}

	//Final XML Blurb

	$data .= "</Table></Worksheet></Workbook>";

	header("Content-type: application/octet-stream");
	header("Content-Disposition: attachment; filename=$bookTitle.xls;");
	header("Content-Type: application/ms-excel");
	header("Pragma: no-cache");
	header("Expires: 0");

	return $data;

}

/* Record debuging information to a file 
	This can grow very big, so it should be dumped from time to time
	Add: Browsers, lang, robots, etc.
*/
function record_Debugs($path_Main){

	$filename = $path_Main."/DEBUGFILE";

	// Let's make sure the file exists and is writable first.
	if(is_writable($filename)) {
		if ($theFile = fopen($filename, 'a')) {

			// Get all the data that we want
			$dat = getrusage();
			$content = sprintf("Time: %s | Memory: %s Kb| Time Used (Ms) %s | Usage: %s \n", date("Y-M-d H:i:s", time()), memory_get_usage() / 1000, $dat["ru_utime.tv_usec"], basename($_SERVER['SCRIPT_FILENAME']));

			fwrite($theFile, $content);
			fclose($theFile);
		}
	}

}

//Read and display the debug file in a human readable way
function read_Debug($path_Main){

	$filename = $path_Main."/DEBUGFILE";

	$handle1 = fopen($filename, 'r');

	if($handle1){

		$lines = 0;

		while (!eof($handle1)) {

		  $buffer = fgets($handle1, 4096);

			$data = explode("|", $buffer);

			$time   += $data[2];
			$memory += $data[1];
			$lines++;

		}

		return array("tot_Time"   => $time,
					"tot_Memory" => $memory,
 					"avg_Time"   => $time/$lines,
					"avg_Memory" => $memory/$lines
				);

	}
		else{
			
			return 1;
		}
}


?>
Return current item: Ads Exchange Server