= 24) @mysql_query("DELETE FROM count_24 WHERE uid=$uid ORDER BY id ASC LIMIT 1;"); @mysql_query("INSERT INTO count_24 VALUES ('',$uid,$today,$hour,0,0);"); $hour_count = 0; $hour_host = 0; }else { $hour_count = $row[0]; $hour_host = $row[1]; } $hour_count++; // ---------------------------- посещения за месяц -------------------- $today = date("Ym"); // данные за текущий месяц $result = mysql_query("SELECT count,host FROM months WHERE date=$today AND uid=$uid"); $row=mysql_fetch_row($result); // поверка наличия записи в базе if (empty($row)) { @mysql_query("INSERT INTO months VALUES ('',$uid,$today,0,0);"); $this_month_count = 0; $this_month_host = 0; }else{ $this_month_count = $row[0]; $this_month_host = $row[1]; } $this_month_count++; //-------------------------- недельная статистика---------------- $week_day = date("w"); $today = date("Ymd"); // получаем дату обнуления недельной статистики $result = mysql_query("SELECT next_mon FROM weeks WHERE uid=$uid ORDER BY id ASC LIMIT 1"); $row=mysql_fetch_row($result); if (empty($row)) { // расчитываем дату обнуления $dayNext =$week_day + 7; if ($dayNext > 7){ $dayNext-=7; } $cntDay=8-$dayNext; $nextMonday=date("Ymd",mktime(0,0,0,date("m"),date("d")+$cntDay)); } else $nextMonday = $row[0]; // если сегодня дата обнуления, обнуляем недельную статистику, и расчитываем след дату обнуления if ($today >= $nextMonday) { // расчитываем след дату обнуления $dayNext =$week_day + 7; if ($dayNext > 7){ $dayNext-=7; } $cntDay=8-$dayNext; $nextMonday=date("Ymd",mktime(0,0,0,date("m"),date("d")+$cntDay)); // обнуляем посещения за прошедшую неделю @mysql_query("DELETE FROM `weeks` WHERE uid = $uid"); @mysql_query("DELETE FROM `top_operators_stat` WHERE uid = $uid"); ### Удаление неактивных пользователей $time_stamp = time (); $week_time = 7*24*60*60; $sql_result = mysql_query(" SELECT `uid` FROM `users` WHERE ($time_stamp - `users`.`date`) > $week_time "); while ($result = mysql_fetch_assoc($sql_result)) { $del_uid = $result['uid']; @mysql_query("DELETE FROM `users` WHERE uid = $del_uid"); @mysql_query("DELETE FROM `count_24` WHERE uid = $del_uid"); @mysql_query("DELETE FROM `hits_ip` WHERE uid = $del_uid"); @mysql_query("DELETE FROM `hits_time` WHERE uid = $del_uid"); @mysql_query("DELETE FROM `months` WHERE uid = $del_uid"); @mysql_query("DELETE FROM `online_ip` WHERE uid = $del_uid"); @mysql_query("DELETE FROM `top_operators_stat` WHERE uid = $del_uid"); @mysql_query("DELETE FROM `weeks` WHERE uid = $del_uid"); } } // получаем данные за текущий день недели $result = mysql_query("SELECT count,host FROM weeks WHERE date=$today AND day_week=$week_day AND uid=$uid LIMIT 1"); $row=mysql_fetch_row($result); if (empty($row)) { // расчитываем дату обнуления $dayNext =$week_day + 7; if ($dayNext > 7) { $dayNext-=7; } $cntDay=8-$dayNext; $nextMonday=date("Ymd",mktime(0,0,0,date("m"),date("d")+$cntDay)); $razdel_data = mysql_query("SELECT razdel FROM users WHERE uid=$uid"); $razdel_data_row = mysql_fetch_array($razdel_data); $razd = $razdel_data_row['razdel']; $reg = $razdel_data_row['reg']; @mysql_query("INSERT INTO weeks VALUES ('',$uid,$razd,$reg,$nextMonday,$today,$week_day,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1)"); $week_day_count = 0; $week_day_host = 0; } else{ $week_day_count = $row[0]; $week_day_host = $row[1]; } $week_day_count++; // ======================================== хосты (оптимиз код) =================================== // чтение текущего ip хита из базы $result = mysql_query("SELECT `ip` FROM `hits_ip` WHERE (`ip`='$ip' AND `ua`='$ua') AND `uid`=$uid"); $row=mysql_fetch_row($result); // если адрес отсутствует, плюсуем хост if(empty($row)) { // защита от накрутки $result = mysql_query("SELECT `ip` FROM `hits_ip` WHERE `uid`=$uid ORDER BY `time` DESC LIMIT 1;"); $row = mysql_fetch_array($result); if (empty($row) || ($row['ip'] != $ip)) { $hour_host++; $week_day_host++; $this_month_host++; mysql_query("INSERT INTO `hits_ip` VALUES ($uid,'$ip','$ua',".time().")"); } } // сохранение посещения @mysql_query("UPDATE count_24 SET count=$hour_count,host=$hour_host WHERE hour=$hour AND date=$today AND uid=$uid"); @mysql_query("UPDATE weeks SET count=$week_day_count,host=$week_day_host WHERE date=$today AND day_week=$week_day AND uid=$uid and tesdiq='1' LIMIT 1"); $today = date("Ym"); @mysql_query("UPDATE months SET count=$this_month_count,host=$this_month_host WHERE date=$today AND uid=$uid"); // за сегодня $count_today = $week_day_count; $host_today = $week_day_host; // ------------------------------- онлайн ----------------------------- $today = date("Ymd"); $now=date("ymdHi"); // удаляем записи ip старее online_time минут // del_time время позднее которого записи считаются старыми $del_time = date("ymdHi", mktime(date("H"), date("i")-$online_time)); @mysql_query("DELETE FROM `online_ip` WHERE `uid`=$uid AND `time` <= $del_time"); // --------- онлайн $sql = "SELECT ip FROM online_ip WHERE ip='$ip' AND uid=$uid"; $result = mysql_query($sql); $row=mysql_fetch_row($result); // если адрес отсутствует, записываем if(empty($row)){ mysql_query("INSERT INTO online_ip VALUES ($uid,'$ip',$now,'$user_browser')"); } // подсчитываем онлайн посетителей $result = mysql_query("SELECT count(ip) FROM online_ip WHERE uid=$uid"); $row=mysql_fetch_row($result); $online=(int)$row[0]; // за 24 часа $today = date("Ymd"); $hour = date("H"); $result = mysql_query("SELECT sum(count) FROM count_24 WHERE ((date=$today-1 AND hour>$hour) OR (date=$today AND hour<=$hour)) AND uid=$uid"); $row = mysql_fetch_row($result); $count_24 = (int)$row[0]; // -----------------------Всего--------------------------- $result = mysql_query("SELECT sum(count) FROM months WHERE uid=$uid"); $row=mysql_fetch_row($result); $all_count = (int)$row[0]; /*--------------- $count_today - хиты $host_today - хосты $online - онлайн $count_24 - за 24 часа $all_count - всего -----------------*/ // вывод информации $result = mysql_query("SELECT type FROM users WHERE uid=$uid"); $type=mysql_fetch_row($result); $result = mysql_query("SELECT typeStat FROM users WHERE uid=$uid"); $typeStat=mysql_fetch_row($result); $image=$type[0]; if($type[0]==2 or $type[0]==3 or $type[0]==4 or $type[0]==5){ $image.=$typeStat[0]; } $img = @imageCreateFromGIF("../img/".$image.".gif"); $color = imagecolorallocate($img, 255,225,225); $color2 = imagecolorallocate($img, 255,225,225); ############################################################ // средний 3 if($image==40){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==41){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==42){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==43){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==44){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==45){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==46){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==47){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==48){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==49){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } // средний 3 if($image==50){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$count_today")-3); $y = 3; ///imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2-35, $y+12,"$host_today", $color); imageString($img, 1, $x3+1, $y+12,"$count_today", $color2); } ############################################################ // полный if($image==51){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$online")-3); $x4 = (ImageSX($img) - 5*strlen("$count_24")-3); $x5 = (ImageSX($img) - 5*strlen("$all_count")-3); $y = 3; /////imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2+2, $y+12,"$host_today", $color2); imageString($img, 1, $x3+2, $y+19,"$online", $color2); imageString($img, 1, $x4+2, $y+26,"$count_24", $color2); imageString($img, 1, $x5+2, $y+33,"$all_count", $color2); } // полный if($image==52){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$online")-3); $x4 = (ImageSX($img) - 5*strlen("$count_24")-3); $x5 = (ImageSX($img) - 5*strlen("$all_count")-3); $y = 3; /////imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2+2, $y+12,"$host_today", $color2); imageString($img, 1, $x3+2, $y+19,"$online", $color2); imageString($img, 1, $x4+2, $y+26,"$count_24", $color2); imageString($img, 1, $x5+2, $y+33,"$all_count", $color2); } // полный if($image==53){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$online")-3); $x4 = (ImageSX($img) - 5*strlen("$count_24")-3); $x5 = (ImageSX($img) - 5*strlen("$all_count")-3); $y = 3; /////imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2+2, $y+12,"$host_today", $color2); imageString($img, 1, $x3+2, $y+19,"$online", $color2); imageString($img, 1, $x4+2, $y+26,"$count_24", $color2); imageString($img, 1, $x5+2, $y+33,"$all_count", $color2); } // полный if($image==54){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$online")-3); $x4 = (ImageSX($img) - 5*strlen("$count_24")-3); $x5 = (ImageSX($img) - 5*strlen("$all_count")-3); $y = 3; /////imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2+2, $y+12,"$host_today", $color2); imageString($img, 1, $x3+2, $y+19,"$online", $color2); imageString($img, 1, $x4+2, $y+26,"$count_24", $color2); imageString($img, 1, $x5+2, $y+33,"$all_count", $color2); } // полный if($image==55){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$online")-3); $x4 = (ImageSX($img) - 5*strlen("$count_24")-3); $x5 = (ImageSX($img) - 5*strlen("$all_count")-3); $y = 3; /////imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2+2, $y+12,"$host_today", $color2); imageString($img, 1, $x3+2, $y+19,"$online", $color2); imageString($img, 1, $x4+2, $y+26,"$count_24", $color2); imageString($img, 1, $x5+2, $y+33,"$all_count", $color2); } // полный if($image==56){ ///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3); $x2 = (ImageSX($img) - 5*strlen("$host_today")-3); $x3 = (ImageSX($img) - 5*strlen("$online")-3); $x4 = (ImageSX($img) - 5*strlen("$count_24")-3); $x5 = (ImageSX($img) - 5*strlen("$all_count")-3); $y = 3; /////imageString($img, 1, $x1, $y,"$count_today", $color); imageString($img, 1, $x2+2, $y+12,"$host_today", $color2); imageString($img, 1, $x3+2, $y+19,"$online", $color2); imageString($img, 1, $x4+2, $y+26,"$count_24", $color2); imageString($img, 1, $x5+2, $y+33,"$all_count", $color2); } ############################################################ Header("Content-type: image/gif"); ImageGIF($img); ImageDestroy($img); ?>