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

/***************************************************************************
 *                             viewads.php
 *                            -------------------
 *   begin                : sab, set 8, 2007
 *   copyright            : (C)
 *   email                : hide@address.com
 *   Desc                 : View all ads for you.
 *
 *
 ***************************************************************************/

define('IN_ADSERVER', true);

include_once("./inc/common.inc.php");

/* Check login */
checkLogin($web_address);

// Declare the TPL
$view_Ads_Tpl = new tpl($s_path_Tpl . "/viewads.tpl");

$flag_Text  = 0; // Flag to know that there is at least one text ad
$flag_Img   = 0; // Flag to know that there is at least one image ad
$flag_Flash = 0; // Flag to know that there is at least one flash ad

//If it is an admin looking for ads pending for approval
if(isset($_GET['pend']) && $_GET['pend'] == 1){

	if(get_User_Settings($session['id_User'], "edit_Banners", $web_address) == 1){
		$i_Id_User = 0;
		$q_Where = "WHERE ".$db_Pre."ads.active = 3";
		$s_Warning = (isset($_GET['changed']) ? "Changes made" : "");
	}

}
	//If it is an admin looking to activate or modify ads
	elseif(isset($_GET['state']) && isset($_GET['id_User'])){
		$i_Id_User = $_GET['id_User'];
	}
	//Default case
	else{
		$i_Id_User = $session['id_User'];
		$q_Where = "WHERE ".$db_Pre."ads.id_User = ".$i_Id_User."";
	}

//Needed variables
$s_Banner_Options = "";
$s_Div = "--";
$s_Msg = "";
$s_Active_Add = "";
$s_Categories = "";
$s_Cats_Is = 0;

//Activate or deactivate
if(isset($_GET['state']) && $_GET['id'] != 0 && $_GET['id'] != ""){

	// If he/she can edit banners
	//if(checkuser($session['permissions'], "edit_Banners", "") != 1){
	if(get_User_Settings($session['id_User'], "edit_Banners") != 1){
		$and_Active = "AND active != 3";
	}
		else{
			$and_Active = "";
		}

	// If it will deactivate it can go on or if he has permision to activate ads
	if($_GET['state'] == 0 || $_GET['state'] == 1){
		$q = "
			UPDATE ".$db_Pre."ads
			SET active = ".$_GET['state']."
			WHERE id_Ads = ".$_GET['id']."
			".$and_Active."
			AND id_User = ".$i_Id_User."
		";

		$q_Update_Ads = mysql_query($q) or die("Unable to Update Ad: " . mysql_error());

		$s_Warning = $_lang['viewads_Msg_Changes'];

		//If it is an admin activating ads it will go back to the pending report
		(isset($_GET['id_User']) ? refrescar($web_address . "/viewads.php?pend=1&changed=1", 0, 1) : "");
	}
}

//Delete ads
if(isset($_GET['delete']) && $_GET['id'] != 0 && $_GET['id'] != ""){

	//Type of ad
	if($_GET['type'] == 0){

		//Remove banner
		$s_Path_Ad = $s_path_upload . "/" . $session['id_User'] . "/" . $_GET['data'];

		if(file_exists($s_Path_Ad)){

			if(unlink($s_Path_Ad)){

				$s_Warning = $_lang['viewads_Msg_Deleted'];

				//Query
				$q = "
					DELETE FROM ".$db_Pre."ads
					WHERE id_Ads = ".$_GET['id']."
					AND data = '".$_GET['data']."'
					AND id_User = ".$session['id_User']."
				";

				$q_Delete_Ads = mysql_query($q) or die("Unable to Delete Ad: " . mysql_error());

				if(mysql_affected_rows() > 0){
					$s_Warning .= $_lang['viewads_Msg_Deleted_2'];
				}
					else{
						$s_Warning .= $_lang['viewads_Msg_No_Ads'];
					}
			}
				else{
					$s_Warning = $_lang['viewads_Msg_No_Del'];
				}
		}
			else{
					$s_Warning = $_lang['viewads_Msg_No_Del_2'];
				}
	}
		elseif($_GET['type'] == 1){
			//Query
			$q = "
				DELETE FROM ".$db_Pre."ads
				WHERE id_Ads = ".$_GET['id']."
				AND id_User = ".$session['id_User']."
			";

			$q_Delete_Ads = mysql_query($q) or die("Unable to Delete Ad: " . mysql_error());

			if(mysql_affected_rows() > 0){
				$s_Warning .= $_lang['viewads_Msg_Deleted_2'];
			}
		}
}

//Select all the ads
$q = "
	SELECT ".$db_Pre."ads.*, ".$db_Pre."zones.text
	FROM ".$db_Pre."ads
	INNER JOIN ".$db_Pre."zones ON ".$db_Pre."zones.id_Zone = ".$db_Pre."ads.id_Zone
	".$q_Where."
	ORDER BY ".$db_Pre."ads.id_Zone
";

$q_List_Ads = mysql_query($q) or die("Unable to Get Full list of Ads: " . mysql_error());

$i_Pending_Ads = mysql_num_rows($q_List_Ads);

if($i_Pending_Ads > 0){

	while($row = mysql_fetch_array($q_List_Ads, MYSQL_ASSOC)){

		/* GET to delete ads */
		$s_Get = $row['id_Ads']."&type=".$row['text']."&id=".$row['id_Ads']."&data=".($row['text'] == 0 ? $row['data'] : 0);

		/* Activate deactivate */
		$link_State = ($row['active'] == 1 ?
			"state=0&id=".$row['id_Ads'].($i_Id_User != $session['id_User'] ? "&id_User=" . $row['id_User'] : "")
			: "state=1&id=".$row['id_Ads'].($i_Id_User != $session['id_User'] ? "&id_User=" . $row['id_User'] : ""));

		/* Modify state */
		$mod_State = ($row['active'] == 1 ? $_lang['viewads_Deact'] : $_lang['viewads_Act']);

		$date = date("F d Y H:i:s", $row['timestamp']);
		$view_Ads = ($row['active'] == 1 ? $_lang['viewads_Yes'] : $_lang['viewads_No']);

		/* Image ads */
		if($row['text'] == 0){

			$this_Filename = $s_path_upload . "/" . $row['id_User'] . "/" . $row['data'];
			$s_Img_Address = $web_address . $s_dir_upload . "/" . $row['id_User'] . "/";

			if(file_exists($this_Filename)){
				$s_file_Dimensions = getimagesize($this_Filename);

				//Flash ads
				if(mime_Type(get_User_Settings($session['id_User'], "allow_Formats"), $s_file_Dimensions['mime']) == "flash"){
					$flag_Flash = 1; /* Flag to know that there is at least one Flash ad */

					$a_Details_Flash_Values[] = array(
						$row['id_Ads'],
						$date,
						$view_Ads,
						$row['views'],
						$row['clicks'],
						$row['link'],
						sprintf($_lang['viewads_Dimensions'], $s_file_Dimensions[0], $s_file_Dimensions[1], filesize($this_Filename)/1000),
						$link_State,
						$mod_State,
						$s_Get,
						$row['id_Ads'],
						$s_file_Dimensions[0],
						$s_file_Dimensions[1],
						$s_Img_Address.$row['data'],
					);
				}
				else if(mime_Type(get_User_Settings($session['id_User'], "allow_Formats"), $s_file_Dimensions['mime']) == "img"){

					$flag_Img = 1; /* Flag to know that there is at least one Image ad */

					$a_Details_Img_Values[] = array(
							$_lang['viewads_Ad_Id'],
							$row['id_Ads'],
							$_lang['viewads_Created'],
							$date,
							$_lang['viewads_Active'],
							$view_Ads,
							$_lang['viewads_Times_View'],
							$row['views'],
							$_lang['viewads_Times_Click'],
							$row['clicks'],
							$_lang['viewads_Link'],
							$row['link'],
							sprintf($_lang['viewads_Dimensions'], $s_file_Dimensions[0], $s_file_Dimensions[1], filesize($this_Filename)/1000),
							$s_Img_Address.$row['data'],
							$link_State,
							$mod_State,
							$s_Get,
							$_lang['viewads_Delete'],
							$row['id_Ads'],
							$_lang['viewads_Mod']
					);
				}
			} /* End if file exists */
		} /* End if image ad */
			else{

				$flag_Text = 1; /* Flag to know that there is at least one text ad */

				$a_Details_Text_Values[] = array(
						$_lang['viewads_Ad_Id'],
						$row['id_Ads'],
						$_lang['viewads_Created'],
						$date,
						$_lang['viewads_Active'],
						$view_Ads,
						$_lang['viewads_Times_View'],
						$row['views'],
						$_lang['viewads_Times_Click'],
						$row['clicks'],
						$_lang['viewads_Link'],
						$row['link'],
						$_lang['viewads_Ad_Text'],
						$row['title'],
						$row['data'],
						$link_State,
						$mod_State,
						$s_Get,
						$_lang['viewads_Delete'],
						$row['id_Ads'],
						$_lang['viewads_Mod']
				);
			} /* End else or Text Ad */

	} /* End While */


	// Generate or hide the proper blocks

	//Text ads
	if($flag_Text == 1){

		/* Value array for text ads */
		$a_Details_Text_Keys = array(
				"{VIEW_ADS_ID}",
				"{VIEW_ADS_ADS}",
				"{VIEW_ADS_CREATED}",
				"{VIEW_ADS_TIMESTAMP}",
				"{VIEW_ADS_ACTIVE}",
				"{VIEW_ADS_VIEWADS}",
				"{VIEW_ADS_TIMES_VIEW}",
				"{VIEW_ADS_VIEWS}",
				"{VIEW_ADS_TIMES_CLICK}",
				"{VIEW_ADS_CLICKS}",
				"{VIEW_ADS_LINK_TEXT}",
				"{VIEW_ADS_LINK}",
				"{VIEW_ADS_TEXT}",
				"{VIEW_ADS_TITLE}",
				"{VIEW_ADS_TEXT_DATA}",
				"{VIEW_ADS_STATE_LINK}",
				"{VIEW_ADS_STATE}",
				"{VIEW_ADS_DELETE_LINK}",
				"{VIEW_ADS_DELETE}",
				"{VIEW_ADS_MODIFY_LINK}",
				"{VIEW_ADS_MOD}"
		);

		$view_Ads_Tpl->rBlock_Several($a_Details_Text_Keys, $a_Details_Text_Values, "TEXT_ADS");

	}
		else{
			$view_Ads_Tpl->hideBlock("TEXT_ADS");
		}

	//Image ads
	if($flag_Img == 1){

		// Value array for image ads
		$a_Details_Img_Keys = array(
				"{VIEW_ADS_ID}",
				"{VIEW_ADS_ADS}",
				"{VIEW_ADS_CREATED}",
				"{VIEW_ADS_TIMESTAMP}",
				"{VIEW_ADS_ACTIVE}",
				"{VIEW_ADS_VIEWADS}",
				"{VIEW_ADS_TIMES_VIEW}",
				"{VIEW_ADS_VIEWS}",
				"{VIEW_ADS_TIMES_CLICK}",
				"{VIEW_ADS_CLICKS}",
				"{VIEW_ADS_LINK_TEXT}",
				"{VIEW_ADS_LINK}",
				"{VIEW_ADS_DIMM}",
				"{VIEW_ADS_IMG_ADD}",
				"{VIEW_ADS_STATE_LINK}",
				"{VIEW_ADS_STATE}",
				"{VIEW_ADS_DELETE_LINK}",
				"{VIEW_ADS_DELETE}",
				"{VIEW_ADS_MODIFY_LINK}",
				"{VIEW_ADS_MOD}"
		);

		$view_Ads_Tpl->rBlock_Several($a_Details_Img_Keys, $a_Details_Img_Values, "IMG_ADS");
	}
	else{
		$view_Ads_Tpl->hideBlock("IMG_ADS");
	}

	//There are flash ads
	if($flag_Flash == 1){

		// Value array for flash ads
		$a_Details_Flash_Keys = array(
				"{VIEW_ADS_ADS}",
				"{VIEW_ADS_TIMESTAMP}",
				"{VIEW_ADS_VIEWADS}",
				"{VIEW_ADS_VIEWS}",
				"{VIEW_ADS_CLICKS}",
				"{VIEW_ADS_LINK}",
				"{VIEW_ADS_DIMM}",
				"{VIEW_ADS_STATE_LINK}",
				"{VIEW_ADS_STATE}",
				"{VIEW_ADS_DELETE_LINK}",
				"{VIEW_ADS_MODIFY_LINK}",
				"{VIEW_ADS_FLASH_WIDTH}",
				"{VIEW_ADS_FLASH_HEIGTH}",
				"{VIEW_ADS_FLASH_VALUE}"
		);

		$view_Ads_Tpl->rBlock_Several($a_Details_Flash_Keys, $a_Details_Flash_Values, "FLASH_ADS");
	}
	else{
		$view_Ads_Tpl->hideBlock("FLASH_ADS");
	}

// Main block for ads
$a_View_Ads = array(
	"{VIEW_ADS_PEND}" => (!isset($_GET['pend']) ? $_lang['viewads_View_Current'] : $_lang['viewads_View_Pending']),
	"{VIEW_ADS_TOTAL_ADS}" => sprintf($_lang['viewads_Total'], $i_Pending_Ads),
	"{VIEW_ADS_COMMIT}" => $_lang['viewads_Commit']
);

// Replace Values
$view_Ads_Tpl->rBlock($a_View_Ads, "ADS");

}
	else{
		$s_Warning = $_lang['viewads_Msg_No_Ads_2'];
		$view_Ads_Tpl->hideBlock("ADS");
	}

// Help seccion, this is all you will see if there are no ads
$a_View_Ads_Help = array(
	"{VIEW_ADS_HELP_TITLE}" => $_lang['viewads_Help_Title'],
	"{VIEW_ADS_HELP_TEXT}" => $_lang['viewads_Help_Text']
);

// Replace Values
$view_Ads_Tpl->localize_It($_lang);
$view_Ads_Tpl->rBlock($a_View_Ads_Help, "");

include_once("./header.inc.php");
// Print the tpl
$view_Ads_Tpl->print_Tpl();
include_once("./footer.inc.php");

?>
Return current item: Ads Exchange Server