<?php
	
	if( !$this->network->id ) {
		$this->redirect('home');
	}
	if( !$this->user->is_logged ) {
		$this->redirect('home');
	}
	
	$db2->query('SELECT 1 FROM users WHERE iduser="'.$this->user->id.'" AND is_network_admin=1 LIMIT 1');
	if( 0 == $db2->num_rows() ) {
		$this->redirect('dashboard');
	}
	
	
	/*************************************************************************/
	// needed before proceeding
	require_once('_all-required-language.php');
	
	$this->load_langfile('global/global.php');	
	$this->load_langfile('inside/admin.php');

	/*************************************************************************/
	
	
	require_once('_all-required-dashboard-admin.php');
	

	/*************************************************************************/

	$D->optionactive_admin = 6;
	$D->tabsmenu_active = 1;
	
	$D->codad = '';
	if ($this->param('a')) $D->codad = $this->param('a');

	if (!empty($D->codad)) {

		$r = $this->db2->query("SELECT * FROM my_ads WHERE code='".$D->codad."' LIMIT 1");
		
		if (!$obj = $this->db2->fetch_object($r)) $this->redirect($C->SITE_URL.'admin/ads');
		else $D->ad = $obj;

		$D->ad->headline = stripslashes($D->ad->headline);
		$D->ad->descriptionline1 = stripslashes($D->ad->descriptionline1);
		$D->ad->descriptionline2 = stripslashes($D->ad->descriptionline2);
		
		$this->load_template('admin_ads-details.php');
	
	} else {
	
		$listsads = $this->db2->fetch_all('SELECT * FROM my_ads ORDER BY created DESC');
		$D->htmlAds = '';
		foreach ($listsads as $oneads) {
			$D->ad = $oneads;
			$D->ad->headline = stripslashes($D->ad->headline);
			$D->withPlan = $D->ad->typeaction != 0 ? TRUE : FALSE;
			$D->withCredit = FALSE;
			if ($D->withPlan) {
				if ($D->ad->typeaction == 1) $D->withCredit = $D->ad->impressions_available > $D->ad->num_impressions_unique ? TRUE : FALSE;
				if ($D->ad->typeaction == 2) $D->withCredit = $D->ad->clicks_available > $D->ad->num_clicks_unique ? TRUE : FALSE;
			}
			$D->htmlAds .= $this->load_template('__admin-ads-one-ad.php', FALSE);
		}
		unset($listsads, $oneads);
	
		$this->load_template('admin_ads.php');

	}		
?>