Просмотр файла Pages/image.php

Размер файла: 9.71Kb
<?php
$sait = $mysqli->query("SELECT `id`,`ban`,`status`,`image`,`imageOther`,`hits`,`hosts` FROM `sait` WHERE `id` = '".$id."'");
if($sait->num_rows > 0)
	{
		$row = $sait->fetch_assoc();
		if($row['ban'] == 0)
			{
				if($row['status'] == 1)
					{
						/* Конец дня */
						$day = mktime(23, 59, 59, date('m'), date('d'), date('Y'));
						
						/* Методы антинакрутки */
						if($_SESSION[$set['code'].'-'.$id])
							{
								if($_SESSION[$set['code'].'-'.$id])
									{
										$Session = 1;
									}
								else
									{
										$Session = 0;
										$_SESSION[$set['code'].'-'.$id] = $time;
									}
							}
						else
							{
								$Session = 0;
								$_SESSION[$set['code'].'-'.$id] = $time;
							}
						
						/* Маленький или большой счётчик */
						if($act != 'small')
							{
								$imageSize = $row['image'];
                                                                $type = 'Big';
							}
						else
							{
								$imageSize = $row['imageOther'];
                                                                $type = 'Small';
							}
						$image = imagecreatefrompng('Data/Counters/'.$type.'/'.$imageSize.'.png');
						$imType = $mysqli->query("SELECT `type` FROM `images` WHERE `name` = '".$imageSize."'")->fetch_assoc();
						
						/* Конец вчерашнего дня */
						$oldDay = mktime(23, 59, 59, date('m'), (date('d')-1), date('Y'));
						
						/* Статистика */
						
						$query = $mysqli->query("SELECT * FROM `shows` WHERE `sid` = '".$id."' AND `ip` = '".ip2long($ip)."' AND `time` > '".$oldDay."' AND `browser` = '".$ua."'");
						if($query->num_rows == 0 AND $Session == 0)
							{
                                                                $countrY = $mysqli->query("SELECT `country` FROM `ip_country` WHERE '".ip2long($ip)."' BETWEEN `start` AND `finish`");
                                                                if($countrY->num_rows > 0)
                                                                    {
                                                                        $countryRow = $countrY->fetch_assoc();
                                                                        $country = $countryRow['country'];
                                                                    }
                                                                $operatorQuery = $mysqli->query("SELECT `operator`,`country` FROM `ip_operator` WHERE '".ip2long($ip)."' BETWEEN `start` AND `finish`");
                                                                if($operatorQuery->num_rows > 0)
                                                                    {
                                                                        $operatorRow = $operatorQuery->fetch_assoc();
                                                                        $operator = $operatorRow['operator'];
                                                                        if(empty($country))
                                                                            {
                                                                                $country = $operatorRow['country'];
                                                                            }
                                                                    }
                                                                 else
                                                                    {
                                                                       if(empty($country))
                                                                            {
                                                                                $country = 'Другая';
                                                                            }
                                                                        $operator = 'Другой';
                                                                    }    
                                                                $uniq = 1;
								$mysqli->query("INSERT INTO `shows` (`sid` ,`time` ,`ip` ,`browser`) VALUES ('".$id."', '".$time."', '".ip2long($ip)."', '".$ua."')");						
								$mysqli->query("UPDATE `sait` SET `hosts` = (`hosts` + 1), `hits` = (`hits` + 1), `allHosts` = (`allHosts` + 1), `allHits` = (`allHits` + 1) WHERE `id` = '".$id."'");
								$mysqli->query("INSERT INTO `operators` (`sid` ,`operator` ,`ip`) VALUES ('".$id."', '".$operator."', '".$ip."')");
								$mysqli->query("INSERT INTO `browsers` (`sid` ,`browser` ,`ip`) VALUES ('".$id."', '".$ua."', '".$ip."')");
								$mysqli->query("INSERT INTO `country` (`sid` ,`country` ,`ip`) VALUES ('".$id."', '".$country."', '".$ip."')");
                                                               
                                                                
                                                        }
						else 
							{
								$uniq = 0;
								$mysqli->query("UPDATE `sait` SET `hits` = (`hits` + 1), `allHits` = (`allHits` + 1) WHERE `id` = '".$id."'");
							}
						
						/* Добавляем в общую статистику хиты и хосты */
						if($uniq == 1)
							{
								$mysqli->query("UPDATE `statistic` SET `value` = (`value` + 1) WHERE `name` = 'hosts'");
								$mysqli->query("UPDATE `statistic` SET `value` = (`value` + 1) WHERE `name` = 'allHosts'");
							}
						$mysqli->query("UPDATE `statistic` SET `value` = (`value` + 1) WHERE `name` = 'hits'");
						$mysqli->query("UPDATE `statistic` SET `value` = (`value` + 1) WHERE `name` = 'allHits'");
						
						/* Статистика по дням */
						$day = $mysqli->query("SELECT * FROM `days` WHERE `sid` = '".$id."' AND `month` = '".date("m")."'");
						if($day->num_rows > 0)
							{
								$dayRow = $day->fetch_assoc();
								if(!empty($dayRow[''.date("d").'']))
									{
										$dayArray = explode('|',$dayRow[''.date("d").'']);
										$hosts = $uniq ? $dayArray[0] + 1 : $dayArray[0];
										$hits = $dayArray[1] + 1;
										$mysqli->query("UPDATE `days` SET `".date("d")."` = '".$hosts."|".$hits."|".$dayArray[2]."|".$dayArray[3]."' WHERE `sid` = '".$id."' AND `month` = '".date("m")."'");
									}
								else
									{
										$mysqli->query("UPDATE `days` SET `".date("d")."` = '1|1|0|0' WHERE `sid` = '".$id."' AND `month` = '".date("m")."'");
									}
							}
						else
							{
								$mysqli->query("INSERT INTO `days` SET `sid` = '".$id."', `month` = '".date("m")."', `".date("d")."` = '1|1|0|0'");
							}
						
						/* Статистика по месяцам */		
						$month = $mysqli->query("SELECT * FROM `month` WHERE `sid` = '".$id."'");
						if($month->num_rows > 0)
							{
								$monthRow = $month->fetch_assoc();
								if(!empty($monthRow[''.date("m").'']))
									{
										$monthArray = explode('|',$monthRow[''.date("m").'']);
										$hosts = $uniq ? $monthArray[0] + 1 : $monthArray[0];
										$hits = $monthArray[1] + 1;
										$mysqli->query("UPDATE `month` SET `".date("m")."` = '".$hosts."|".$hits."|".$monthArray[2]."|".$monthArray[3]."' WHERE `sid` = '".$id."'");
									}
								else
									{
										$mysqli->query("UPDATE `month` SET `".date("m")."` = '1|1|0|0' WHERE `sid` = '".$id."'");
									}
							}
						else
							{
								$mysqli->query("INSERT INTO `month` SET `sid` = '".$id."', `".date("m")."` = '1|1|0|0'");
							}
						
						/* Статистика по часам */
						$hour = (int)date("H");
						if($hour == 23)
							{
								$hourD = '23:00-00:00';
							}
						else
							{												
								if(strlen($hour) == 1)
									{																
										$hourr = '0'.$hour;															
									}
								else
									{
										$hourr = $hour;
									}
								if(strlen($hour + 1) == 1)
									{
										$hour2 = '0'.($hour + 1);
									}
								else
									{
										$hour2 = $hour + 1;
									}
								$hourD = ''.$hourr.':00-'.$hour2.':00';
							}
						$hours = $mysqli->query("SELECT * FROM `hours` WHERE `sid` = '".$id."'");
						if($hours->num_rows > 0)
							{
								$hoursRow = $hours->fetch_assoc();
								if(!empty($hoursRow[''.$hourD.'']))
									{
										$hoursArray = explode('|',$hoursRow[''.$hourD.'']);
										$hosts = $uniq ? $hoursArray[0] + 1 : $hoursArray[0];
										$hits = $hoursArray[1] + 1;
										$mysqli->query("UPDATE `hours` SET `".$hourD."` = '".$hosts."|".$hits."|".$hoursArray[2]."|".$hoursArray[3]."' WHERE `sid` = '".$id."'");
									}
								else
									{
										$mysqli->query("UPDATE `hours` SET `".$hourD."` = '1|1|0|0' WHERE `sid` = '".$id."'");
									}
							}
						else
							{
								$mysqli->query("INSERT INTO `hours` SET `sid` = '".$id."', `".$hourD."` = '1|1|0|0'");
							}
						
						/* Если большой счётчик, то рисуем хосты и хиты */
						if($imType['type'] == 'big')
							{
								$hits = 72 - (strlen($row['hits']) * 5);
								$hosts = 32 - (strlen($row['hosts']) * 5);
								$black = imagecolorallocate($image, 80, 80, 80);
								ImageString($image,1,$hosts,15,$row['hosts'],$black);
								ImageString($image,1,$hits,15,$row['hits'],$black);
							}
					}
				else
					{
						$image = imagecreatefrompng('Data/Counters/System/noactiv.png');
					}
			}
		else
			{
				$image = imagecreatefrompng('Data/Counters/System/block.png');
			}
	}
else
	{
		$image = imagecreatefrompng('Data/Counters/System/dont.png');
	}	
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>