<?php 
include("../../functions.php");
include("../../configuration.php");
include("../../dbhandle.php");
include("../../security.php");

$date = date('Y-m-d H:i:s');

$cronhash = $_GET['hash'];
$adminhash1 = "SELECT `admin` FROM `Web_Premium_Login` WHERE `id` = '1'";
$adminhash2 = mysql_query($adminhash1) or die($adminhash1."<br/><br/>".mysql_error());
$adminhash3 = mysql_result($adminhash2, 0);
if($cronhash != $adminhash3) {
	die('bad hash');
}else {
	echo "success";
}

// SET THIS CRONJOB TO EVERY DAY (24H)
$usertable = mysql_query("SELECT username FROM Accounts_Classic_Publishers") or die(mysql_error());
while($userrow = mysql_fetch_array($usertable))
{
			$usercode = $userrow['username'];
			$graphdets = mysql_fetch_array(mysql_query("SELECT * FROM Accounts_Classic_Publishers WHERE username='$usercode'"));
			$graphdata[1] = $graphdets['date2'];
			$graphdata[2] = $graphdets['date3'];
			$graphdata[3] = $graphdets['date4'];
			$graphdata[4] = $graphdets['date5'];
			$graphdata[5] = $graphdets['date6'];
			$graphdata[6] = $graphdets['date7'];
			$graphdata[7] = 0;
			mysql_query("UPDATE Accounts_Classic_Publishers SET date1='$graphdata[1]',date2='$graphdata[2]',date3='$graphdata[3]',date4='$graphdata[4]',date5='$graphdata[5]',date6='$graphdata[6]',date7='$graphdata[7]' WHERE username='$usercode'");
}

$usertable = mysql_query("SELECT username FROM Accounts_Classic_Advertisers") or die(mysql_error());
while($userrow = mysql_fetch_array($usertable))
{
			$usercode = $userrow['username'];
			$graphdets = mysql_fetch_array(mysql_query("SELECT * FROM Accounts_Classic_Advertisers WHERE username='$usercode'"));
			$graphdata[1] = $graphdets['date2'];
			$graphdata[2] = $graphdets['date3'];
			$graphdata[3] = $graphdets['date4'];
			$graphdata[4] = $graphdets['date5'];
			$graphdata[5] = $graphdets['date6'];
			$graphdata[6] = $graphdets['date7'];
			$graphdata[7] = 0;
			mysql_query("UPDATE Accounts_Classic_Advertisers SET date1='$graphdata[1]',date2='$graphdata[2]',date3='$graphdata[3]',date4='$graphdata[4]',date5='$graphdata[5]',date6='$graphdata[6]',date7='$graphdata[7]' WHERE username='$usercode'");
}

$stats = mysql_fetch_array(mysql_query("SELECT * FROM Web_Stats"));
$registeredPUB1 = $stats['reg1'];
$registeredPUB2 = $stats['reg2'];
$registeredPUB3 = $stats['reg3'];
$registeredPUB4 = $stats['reg4'];
$registeredPUB5 = $stats['reg5'];
$registeredPUB6 = $stats['reg6'];
$registeredPUB7 = $stats['reg7'];
$registeredADV1 = $stats['areg1'];
$registeredADV2 = $stats['areg2'];
$registeredADV3 = $stats['areg3'];
$registeredADV4 = $stats['areg4'];
$registeredADV5 = $stats['areg5'];
$registeredADV6 = $stats['areg6'];
$registeredADV7 = $stats['areg7'];
$createdlinksC1 = $stats['sclinks1'];
$createdlinksC2 = $stats['sclinks2'];
$createdlinksC3 = $stats['sclinks3'];
$createdlinksC4 = $stats['sclinks4'];
$createdlinksC5 = $stats['sclinks5'];
$createdlinksC6 = $stats['sclinks6'];
$createdlinksC7 = $stats['sclinks7'];
$createdlinksV1 = $stats['svlinks1'];
$createdlinksV2 = $stats['svlinks2'];
$createdlinksV3 = $stats['svlinks3'];
$createdlinksV4 = $stats['svlinks4'];
$createdlinksV5 = $stats['svlinks5'];
$createdlinksV6 = $stats['svlinks6'];
$createdlinksV7 = $stats['svlinks7'];
$PUBcash1 = $stats['membcash1'];
$PUBcash2 = $stats['membcash2'];
$PUBcash3 = $stats['membcash3'];
$PUBcash4 = $stats['membcash4'];
$PUBcash5 = $stats['membcash5'];
$PUBcash6 = $stats['membcash6'];
$PUBcash7 = $stats['membcash7'];
$ADVcash1 = $stats['advcash1'];
$ADVcash2 = $stats['advcash2'];
$ADVcash3 = $stats['advcash3'];
$ADVcash4 = $stats['advcash4'];
$ADVcash5 = $stats['advcash5'];
$ADVcash6 = $stats['advcash6'];
$ADVcash7 = $stats['advcash7'];
mysql_query("UPDATE Web_Stats SET reg1='$registeredPUB2',areg1='$registeredADV2',sclinks1='$createdlinksC2',svlinks1='$createdlinksV2',membcash1='$PUBcash2',advcash1='$ADVcash2' WHERE id='1'");
mysql_query("UPDATE Web_Stats SET reg2='$registeredPUB3',areg2='$registeredADV3',sclinks2='$createdlinksC3',svlinks2='$createdlinksV3',membcash2='$PUBcash3',advcash2='$ADVcash3' WHERE id='1'");
mysql_query("UPDATE Web_Stats SET reg3='$registeredPUB4',areg3='$registeredADV4',sclinks3='$createdlinksC4',svlinks3='$createdlinksV4',membcash3='$PUBcash4',advcash3='$ADVcash4' WHERE id='1'");
mysql_query("UPDATE Web_Stats SET reg4='$registeredPUB5',areg4='$registeredADV5',sclinks4='$createdlinksC5',svlinks4='$createdlinksV5',membcash4='$PUBcash5',advcash4='$ADVcash5' WHERE id='1'");
mysql_query("UPDATE Web_Stats SET reg5='$registeredPUB6',areg5='$registeredADV6',sclinks5='$createdlinksC6',svlinks5='$createdlinksV6',membcash5='$PUBcash6',advcash5='$ADVcash6' WHERE id='1'");
mysql_query("UPDATE Web_Stats SET reg6='$registeredPUB7',areg6='$registeredADV7',sclinks6='$createdlinksC7',svlinks6='$createdlinksV7',membcash6='$PUBcash7',advcash6='$ADVcash7' WHERE id='1'");
mysql_query("UPDATE Web_Stats SET reg7='0',areg7='0',sclinks7='0',svlinks7='0',membcash7='0',advcash7='0' WHERE id='1'");

mysql_query("TRUNCATE TABLE `Web_IPcheck`");

				$query = "SELECT * FROM System_Data";
				$result = mysql_query($query) or die('Error, query failed');
				while($row = mysql_fetch_array($result)){
					$system_versioncheckurl = $row['versioncheckurl'];
					$system_script_version = $row['version'];
				}
    			// 1. URL
					$result1 = file_get_contents($system_versioncheckurl);
					$obj1 = json_decode($result1, true);
					$checkedversion = $obj1['lastversion'];
					if($checkedversion == $system_script_version) {
						$status = 'Your script have latest updates.';
						$statusn = 1;
						$updatelast = mysql_query("UPDATE System_Data SET lastchecked='$date' WHERE id='1'");					
					}else {
						$status = 'Your script is outdated.';
						$statusn = 0;
						$updatelast = mysql_query("UPDATE System_Data SET lastversion='$checkedversion',lastchecked='$date' WHERE id='1'");
					}

?>