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

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

//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");

//Permisos y login

//The correct order for permissions in the array
$perm_array = array(
			'group_Name' => 0,
			'edit_Users' => 1,
			'delete_Users' => 2,
			'user_List' => 3,
			'edit_Cat' => 4,
			'edit_Sites' => 5,
			'edit_Banners' => 6,
			'reports' => 7,
			'allow_Restrict_Country' => 8,
			'view_Ratio' => 9,
			'click_Ratio' => 10,
			'def_Ad_State' => 11,
			'def_Website_State' => 12,
			'max_Text_Ads' => 13,
			'max_Img_Ads' => 14,
			'restrict_Cats_Shown' => 15,
			'restrict_Cats_Display' => 16,
			'restrict_Times' => 17,
			'allow_Formats' => 18
		);

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;
}

//Gets all the permissions from an specific user and returns an array with them
function get_Permissions($user_Id, $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 = ".$user_Id."
		";

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

	$row = mysql_fetch_array($q_Get_Permits, MYSQL_ASSOC);

		//This can be a for()  with the $perm_array
		$permissions = 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 $permissions;
}

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

	//Get data from user
	$q = "
		SELECT ".$db_Pre."groups.".$setting." AS setting
		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 = ".$user_Id."
		";

	$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 = $row['permit'];

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

	return $settings;

}


?>
Return current item: Ads Exchange Server