#!/usr/local/bin/perl
$mail_prog = '/usr/sbin/sendmail' ;
&GetFormInput;
$adv = $field{'adv'} ;	 
	 
	 sub GetFormInput {

	(*fval) = @_ if @_ ;

	local ($buf);
	if ($ENV{'REQUEST_METHOD'} eq 'POST') {
		read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
	}
	else {
		$buf=$ENV{'QUERY_STRING'};
	}
	if ($buf eq "") {
			return 0 ;
		}
	else {
 		@fval=split(/&/,$buf);
		foreach $i (0 .. $#fval){
			($name,$val)=split (/=/,$fval[$i],2);
			$val=~tr/+/ /;
			$val=~ s/%(..)/pack("c",hex($1))/ge;
			$name=~tr/+/ /;
			$name=~ s/%(..)/pack("c",hex($1))/ge;

			if (!defined($field{$name})) {
				$field{$name}=$val;
			}
			else {
				$field{$name} .= ",$val";
				
			}


		   }
		}
return 1;
}

use Fcntl;
use NDBM_File;

tie %hasht, "NDBM_File", "/web/012/wmclicks/public_html/adv/tun/$adv", O_RDWR, 0644;
$number=$hasht{number};
$box = $hasht{box};
$day = $hasht{day};
$hour = $hasht{hour};
untie %hasht;

tie %hash, "NDBM_File", "/web/012/wmclicks/public_html/adv/logs/$adv", O_RDWR, 0644;
$sitename = $hash{sitename};
untie %hash;


print "Content-Type: text/html\n\n";
print "<html><head><title>Информация о рекламодателе $sitename</title></head>";
print "<body BACKGROUND=\"http://wmclicks.com/bg.gif\" TEXT=\"#000000\">";
print "<center><b>Клики</b></center>";
print "<center>Количество кликов в день:";

if ($number == 0)
{
print " неограничено</center>";
}
else
{
print "$number</center>";
}
open (FILE,"/web/012/wmclicks/public_html/adv/today/$adv.dat");
@t=<FILE>;
close (FILE);
print "<br><center>Сегодня сделано кликов: $t[0]</center><br>";	


#DAY TARGETING
@days=split (/,/,$day);

foreach $k (@days)
{
	if ($k == 1)
	{
	$pn=1;
	
	}
	if ($k == 2)
	{
	$vt=1;
	
	}
	if ($k == 3)
	{
	$sr=1;
	
	}
	if ($k == 4)
	{
	$cht=1;
	
	}
	if ($k == 5)
	{
	$pt=1;
	
	}
	if ($k == 6)
	{
	$sb=1;
	
	}
	if ($k == 7)
	{
	$vs=1;
	
	}
}
print "<BR><BR><BR>";
print "<center><b>Таргетинг по дням</b></center>";
print "<center>";
	if ($pn == 1)
	{
	print "Пн <input type=\"checkbox\" name=\"C1\" checked>&nbsp;&nbsp;&nbsp;";
	}
	else
	{
	print "Пн <input type=\"checkbox\" name=\"C1\"> &nbsp;&nbsp;&nbsp;";
	}
	
	if ($vt == 1)
	{
	print "Вт <input type=\"checkbox\" name=\"C2\" checked> &nbsp;&nbsp;&nbsp;";
	}	
	else
	{
	print "Вт <input type=\"checkbox\" name=\"C2\"> &nbsp;&nbsp;&nbsp;";
	}	
	
	
	if ($sr == 1)
	{
	print "Ср <input type=\"checkbox\" name=\"C3\" checked> &nbsp;&nbsp;&nbsp;";
	}
	else
	{
	print "Ср <input type=\"checkbox\" name=\"C3\"> &nbsp;&nbsp;&nbsp;";
	}
	
	if ($cht == 1)
	{
	print "Чт <input type=\"checkbox\" name=\"C4\" checked> &nbsp;&nbsp;&nbsp;";
	}
	else
	{
	print "Чт <input type=\"checkbox\" name=\"C4\"></p> &nbsp;&nbsp;&nbsp;";
	}

	if ($pt == 1)
	{	
	print "Пт <input type=\"checkbox\" name=\"C5\" checked> &nbsp;&nbsp;&nbsp;";
	}
	else
	{
	print "Пт <input type=\"checkbox\" name=\"C5\"> &nbsp;&nbsp;&nbsp;";
	}
	
	if ($sb == 1)
	{
	print "Сб <input type=\"checkbox\" name=\"C6\" checked> &nbsp;&nbsp;&nbsp;";
	}
	else
	{
	print "Сб <input type=\"checkbox\" name=\"C6\"> &nbsp;&nbsp;&nbsp;";
	}

	if ($vs == 1)
	{
	print "Вс <input type=\"checkbox\" name=\"C7\" checked></p> &nbsp;&nbsp;&nbsp;";
	}
	else
	{
	print "Вс <input type=\"checkbox\" name=\"C7\"></p> &nbsp;&nbsp;&nbsp;";
	}

print "</center>";
#HOUR TARGETING
@hours=split (/,/,$hour);

foreach $k (@hours)
{
	if ($k == 1)
	{
	$a1=1;
	
	}
	if ($k == 2)
	{
	$a2=1;
	
	}
	if ($k == 3)
	{
	$a3=1;
	
	}
	if ($k == 4)
	{
	$a4=1;
	
	}
	if ($k == 5)
	{
	$a5=1;
	
	}
	if ($k == 6)
	{
	$a6=1;
	
	}
	if ($k == 7)
	{
	$a7=1;
	
	}
	if ($k == 8)
	{
	$a8=1;
	
	}
	if ($k == 9)
	{
	$a9=1;
	
	}
	if ($k == 10)
	{
	$a10=1;
	
	}
	if ($k == 11)
	{
	$a11=1;
	
	}
	if ($k == 12)
	{
	$a12=1;
	
	}
	if ($k == 13)
	{
	$p1=1;
	
	}
	if ($k == 14)
	{
	$p2=1;
	
	}
	if ($k == 15)
	{
	$p3=1;
	}
	if ($k == 16)
	{
	$p4=1;
	}
	if ($k == 17)
	{
	$p5=1;
	}
	if ($k == 18)
	{
	$p6=1;
	}
	if ($k == 19)
	{
	$p7=1;
	}
	if ($k == 20)
	{
	$p8=1;
	}
	if ($k == 21)
	{
	$p9=1;
	}
	if ($k == 22)
	{
	$p10=1;
	}
	if ($k == 23)
	{
	$p11=1;
	}
	if ($k == 24)
	{
	$p12=1;
	}
	
}
print "<p align=center><b>Таргетинг по часам</b>";

	print "<table border=0 cellpadding=0 cellspacing=0>";
	print "<tr><td>";
	if ($a1 == 1)
	{
	print "<p>0.00 - 1.00 <input type=\"checkbox\" name=\"V1\" checked></p>";
	}
	else
	{
	print "<p>0.00 - 1.00 <input type=\"checkbox\" name=\"V1\"></p>";
	}
	
	if ($a2 == 1)
	{
	print "<p>1.00 - 2.00<input type=\"checkbox\" name=\"V2\" checked></p>";
	}	
	else
	{
	print "<p>1.00 - 2.00<input type=\"checkbox\" name=\"V2\"></p>";
	}	
	
	
	if ($a3 == 1)
	{
	print "<p>2.00 - 3.00<input type=\"checkbox\" name=\"V3\" checked></p>";
	}
	else
	{
	print "<p>2.00 - 3.00<input type=\"checkbox\" name=\"V3\"></p>";
	}
	
	if ($a4 == 1)
	{
	print "<p>3.00 - 4.00<input type=\"checkbox\" name=\"V4\" checked></p>";
	}
	else
	{
	print "<p>3.00 - 4.00<input type=\"checkbox\" name=\"V4\"></p>";
	}
	print "</td><td>";
	if ($a5 == 1)
	{	
	print "<p>4.00 - 5.00<input type=\"checkbox\" name=\"V5\" checked></p>";
	}
	else
	{
	print "<p>4.00 - 5.00<input type=\"checkbox\" name=\"V5\"></p>";
	}
	
	if ($a6 == 1)
	{
	print "<p>5.00 - 6.00<input type=\"checkbox\" name=\"V6\" checked></p>";
	}
	else
	{
	print "<p>5.00 - 6.00<input type=\"checkbox\" name=\"V6\"></p>";
	}

	if ($a7 == 1)
	{
	print "<p>6.00 - 7.00<input type=\"checkbox\" name=\"V7\" checked></p>";
	}
	else
	{
	print "<p>6.00 - 7.00<input type=\"checkbox\" name=\"V7\"></p>";
	}

	if ($a8 == 1)
	{
	print "<p>7.00 - 8.00<input type=\"checkbox\" name=\"V8\" checked></p>";
	}
	else
	{
	print "<p>7.00 - 8.00<input type=\"checkbox\" name=\"V8\"></p>";
	}
	print "</td><td>";
	if ($a9 == 1)
	{
	print "<p>8.00 - 9.00<input type=\"checkbox\" name=\"V9\" checked></p>";
	}
	else
	{
	print "<p>8.00 - 9.00<input type=\"checkbox\" name=\"V9\"></p>";
	}
	
	if ($a10 == 1)
	{
	print "<p>9.00 - 10.00<input type=\"checkbox\" name=\"V10\" checked></p>";
	}
	else
	{
	print "<p>9.00 - 10.00<input type=\"checkbox\" name=\"V10\"></p>";
	}
	
	if ($a11 == 1)
	{
	print "<p>10.00 - 11.00<input type=\"checkbox\" name=\"V11\" checked></p>";
	}
	else
	{
	print "<p>10.00 - 11.00<input type=\"checkbox\" name=\"V11\"></p>";
	}
	
	if ($a12 == 1)
	{
	print "<p>11.00 - 12.00<input type=\"checkbox\" name=\"V12\" checked></p>";
	}
	else
	{
	print "<p>11.00 - 12.00<input type=\"checkbox\" name=\"V12\"></p>";
	}
	print "</td><td>";
	if ($p1 == 1)
	{
	print "<p>12.00 - 13.00 <input type=\"checkbox\" name=\"V13\" checked></p>";
	}
	else
	{
	print "<p>12.00 - 13.00 <input type=\"checkbox\" name=\"V13\"></p>";
	}
	
	if ($p2 == 1)
	{
	print "<p>13.00 - 14.00<input type=\"checkbox\" name=\"V14\" checked></p>";
	}	
	else
	{
	print "<p>13.00 - 14.00<input type=\"checkbox\" name=\"V14\"></p>";
	}	
	
	
	if ($p3 == 1)
	{
	print "<p>14.00 - 15.00<input type=\"checkbox\" name=\"V15\" checked></p>";
	}
	else
	{
	print "<p>14.00 - 15.00<input type=\"checkbox\" name=\"V15\"></p>";
	}
	
	if ($p4 == 1)
	{
	print "<p>15.00 - 16.00<input type=\"checkbox\" name=\"V16\" checked></p>";
	}
	else
	{
	print "<p>15.00 - 16.00<input type=\"checkbox\" name=\"V16\"></p>";
	}
	print "</td><td>";
	if ($p5 == 1)
	{	
	print "<p>16.00 - 17.00<input type=\"checkbox\" name=\"V17\" checked></p>";
	}
	else
	{
	print "<p>16.00 - 17.00<input type=\"checkbox\" name=\"V17\"></p>";
	}
	
	if ($p6 == 1)
	{
	print "<p>17.00 - 18.00<input type=\"checkbox\" name=\"V18\" checked></p>";
	}
	else
	{
	print "<p>17.00 - 18.00<input type=\"checkbox\" name=\"V18\"></p>";
	}

	if ($p7 == 1)
	{
	print "<p>18.00 - 19.00<input type=\"checkbox\" name=\"V19\" checked></p>";
	}
	else
	{
	print "<p>18.00 - 19.00<input type=\"checkbox\" name=\"V19\"></p>";
	}

	if ($p8 == 1)
	{
	print "<p>19.00 - 20.00<input type=\"checkbox\" name=\"V20\" checked></p>";
	}
	else
	{
	print "<p>19.00 - 20.00<input type=\"checkbox\" name=\"V20\"></p>";
	}
	print "</td><td>";
	if ($p9 == 1)
	{
	print "<p>20.00 - 21.00<input type=\"checkbox\" name=\"V21\" checked></p>";
	}
	else
	{
	print "<p>20.00 - 21.00<input type=\"checkbox\" name=\"V21\"></p>";
	}
	
	if ($p10 == 1)
	{
	print "<p>21.00 - 22.00<input type=\"checkbox\" name=\"V22\" checked></p>";
	}
	else
	{
	print "<p>21.00 - 22.00<input type=\"checkbox\" name=\"V22\"></p>";
	}
	
	if ($p11 == 1)
	{
	print "<p>22.00 - 23.00<input type=\"checkbox\" name=\"V23\" checked></p>";
	}
	else
	{
	print "<p>22.00 - 23.00<input type=\"checkbox\" name=\"V23\"></p>";
	}
	
	if ($p12 == 1)
	{
	print "<p>23.00 - 24.00<input type=\"checkbox\" name=\"V24\" checked></p>";
	}
	else
	{
	print "<p>23.00 - 24.00<input type=\"checkbox\" name=\"V24\"></p>";
	}
	print "</td></tr></table>";



print "</body></html>";
