View file o5on.ru/mod_operators.php

File size: 1.88Kb
<?php
### Данные по IP
function defineOperator ($ip)
{
	$ips = explode('.', $ip);
	$ipnum = $ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256;

	$sql_result = mysql_query ("SELECT `top_operators`.`id` FROM `top_operators` INNER JOIN `top_ip` ON `top_ip`.`id_operator` = `top_operators`.`id` WHERE ".$ipnum." BETWEEN `top_ip`.`ip1` AND `top_ip`.`ip2` LIMIT 1; ");
	if (mysql_num_rows($sql_result))
	{
		$id_operator = mysql_fetch_assoc($sql_result);
		return $id_operator['id'];
	}
	else return 0;
}

$id_operator = defineOperator ($_SERVER['REMOTE_ADDR']);
/*
if($id_operator=="0"){
$rez=mysql_query ("SELECT * FROM `new_operators` WHERE `ip_new`='".$_SERVER['REMOTE_ADDR']."';");
if (mysql_affected_rows()!=0){}
else{
$ins_str = "INSERT INTO `new_operators` SET `ip_new`='".$_SERVER['REMOTE_ADDR']."'";
               	if (mysql_query ($ins_str)) {
                     @mysql_query("OPTIMIZE TABLE `new_operators`");
                     @mysql_query("ANALYZE TABLE `new_operators`");

                } else {
                    $msg = " ".mysql_error()." ";

                }

}}
*/
$week_day = date("w");
$today = date("Ymd");

$result = mysql_query("SELECT * FROM `top_operators_stat` WHERE `date` = ".$today." AND `day_week` = ".$week_day." AND `uid` = ".$uid." AND `id_operator` = ".$id_operator." LIMIT 1;");
if (!mysql_num_rows($result))
{
	$nextMonday=date("Ymd",mktime(0,0,0,date("m"),date("d")+32));
	mysql_query("INSERT INTO `top_operators_stat` VALUES ('', ".$uid.", ".$nextMonday.", ".$today.", ".$week_day.", ".$id_operator.", 0);");
	$operator_count 	= 0;
}
else
{
	$row 				= mysql_fetch_array($result);
	$operator_count 	= $row['count'];
}
$operator_count ++;
### сохранение
mysql_query("UPDATE `top_operators_stat` SET `count` = ".$operator_count." WHERE `date` = ".$today." AND `day_week` = ".$week_day." AND `uid` = ".$uid."  AND `id_operator` = ".$id_operator." LIMIT 1;");

?>