Просмотр файла MyLounge/myred/include/functions.php

Размер файла: 13.25Kb
<?php
function setlanguage() {
	$lang=getenv(HTTP_ACCEPT_LANGUAGE);
	$lang=substr ($lang, 0, 2);
	$lang.="inc.php";
	if(file_exists("language/$lang")) {
		return $lang;
		}
	else {
		return "eninc.php";
	}
}

function setmenu() {
global $text_1, $text_2, $text_3, $text_4, $text_5, $text_6, $text_7;
	$menu="<table border=\"0\" align=\"center\">
  <tr> 
    <td><a href=\"signup.php\">$text_1</a> || </td>
    <td><a href=\"member.php\">$text_2</a> || </td>
    <td><a href=\"delete.php\">$text_3</a> || </td>
    <td><a href=\"feedback.php\">$text_4</a> || </td>
    <td><a href=\"whois.php\">$text_5</a> || </td>
    <td><a href=\"dyn.php\">$text_6</a> || </td>
    <td><a href=\"stats.php\">$text_7</a></td>
  </tr>
</table>";
	return $menu;
}

function errormsg($errmsg) {
global $text_14, $text_15, $menu, $pagetitle;
	$error="<table cellspacing=\"1\" cellpadding=\"4\" border=\"0\" width=\"500\" align=\"center\">
<tr>
<td align=\"center\">$text_14</td>
</tr>
<tr>
<td align=\"center\">
$errmsg<br>
</td>
</tr>
<tr>
<td align=\"center\">
$text_15
</td>
</tr>
</table>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $error);
$template->myred_print() or die($template->error);
}

// Generate random password - thanks to karl from toastman.com :-)
$i = 1;
$str = "";
Function randomstring($len) { 
  	global $i;
	global $str;
	srand(date( "s")); 
  while($i<$len) { 
   $str.=chr((rand()%26)+97); 
   $i++; 
  } 
  return $str; 
 }

function verify_email($email) {
  if(eregi("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$", trim($email))) {
    return 1;
  } else {
    return 0;
  }
}

// Show an error if client is not logged in 
function checksession() {
	global $userid_login, $text_210;
	if(!isset($userid_login) || empty($userid_login) || $userid_login=="") {
	errormsg($text_210);
	exit;
	}
}

function spider($url1) {
	global $text_20, $text_21, $menu;
	$errortxt="";
	if(!preg_match("=://=", $url1)) {
		$errortxt.="<b>$url1</b> $text_21<br>";
		}
	$fh = @fopen("$url1", "r");
	if(!$fh) {
		$errortxt.="<b>$url1</b> $text_20";
		}
	if($errortxt!="") {
		errormsg($errortxt);
		exit;
		}
	$grabfile = fread($fh, 3000);
	preg_match("|<title[^>]*>(.*)</title>|siU", $grabfile, $title);
	$metatags = get_meta_tags("$url1");

	$title = $title[1];
	$description = $metatags["description"];
	$keywords = $metatags["keywords"];
	$revisit = $metatags["revisit"];

	@fclose($fh);

	return array($title,$description,$keywords,$revisit);
}

class MyredTemplate // Based on a book by Tobias Ratschiller and Till Gerken
{
    var $error = "";                // Last error message will be stored here
    
    var $tags = array();            // For the tag values pairs, as defined by assign()
    
    function MyredTemplate($template_file)
    {
        if(!file_exists($template_file))
        {
            $this->error = "The template file $template_file does not exist.";
        }
        $this->template_file = $template_file;
    }

    function assign($tag, $value)
    {
        if(empty($tag))
        {
            $this->error = "Tag is empty";
            return(false);
        }
        
        $this->tags[$tag] = $value;
        return(true);
    }

    function myred_parse()
    {
        $contents = @implode("", (@file($this->template_file)));

        while(list($key, $value) = each($this->tags))
        {
            $tag = '{'.$key.'}';
            $contents = str_replace($tag, $value, $contents);
        }   
        return($contents);    
    }

    function myred_print()
    {
        $ret = $this->myred_parse();
        if($ret == false)
        {
            return(false);
        }
        print($ret);
        return(true);
    }
}

function percentcalc($part, $total) {
$perc = round((100 * $part / $total), 2);
return $perc;
}

// Show detail stats either for views or for clicks, depending on argument 
function detailstats($adid, $ad_table) {

$result1="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"350\" align=\"center\">
<tr>
<td colspan=\"4\" align=\"center\" bgcolor=\"#dcdcdc\"><b>Summary</b></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"><b>Period</b></td>
<td colspan=\"2\" align=\"center\"><b>Clicks/Views</b></td>
</tr>";

$sql = "SELECT count(ip) as cnt from $ad_table WHERE adid='$adid'"; 
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) { 
$overall = $row["cnt"]; 
} 

$sql = "SELECT COUNT(*) AS cnt, YEAR(date) AS year 
FROM $ad_table WHERE adid='$adid' GROUP BY year ORDER BY year"; 

$year_result = mysql_query($sql); 

while ($row = mysql_fetch_array($year_result)) { 
$year = $row["year"]; 

$result1.="<tr><td colspan=\"2\" align=\"center\">Year $year</td><td colspan=\"2\" align=\"center\">$row[cnt]</td></tr>"; 

$sql = "SELECT COUNT(*) as cnt, MONTHNAME(date) as mn, 
MONTH(date) as month 
FROM $ad_table WHERE adid='$adid' AND YEAR(date) = $year 
GROUP BY mn,month 
ORDER BY month"; 
$result = mysql_query($sql); 

while ($row = mysql_fetch_array($result)) { 
$result1.="<tr><td colspan=\"2\" align=\"center\">Month $row[mn]</td><td colspan=\"2\" align=\"center\">$row[cnt]</td></tr>"; 
} 
$sql = "SELECT COUNT(*) as cnt, WEEK(date) as wk 
FROM $ad_table WHERE adid='$adid' AND YEAR(date) = $year 
GROUP BY wk 
ORDER BY wk"; 
$result = mysql_query($sql); 

while ($row = mysql_fetch_array($result)) { 
$result1.="<tr><td colspan=\"2\" align=\"center\">Week $row[wk]</td><td colspan=\"2\" align=\"center\">$row[cnt]</td></tr>"; 
}} 
$result1.="<tr>
<td colspan=\"4\">&nbsp;</td>
</tr>
<tr>
<td colspan=\"4\" align=\"center\" bgcolor=\"#dcdcdc\"><b>Last seven daily averages</b></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"><b>Weekday</b></td>
<td colspan=\"2\" align=\"center\"><b>Clicks/Views</b></td>
</tr>";

$sql = "SELECT count(*) as cnt, DAYNAME(date) as dnr, 
TO_DAYS(date) as tdr 
FROM $ad_table WHERE adid='$adid' AND date >= DATE_SUB( CURRENT_DATE, INTERVAL 6 day ) 
GROUP BY dnr,tdr 
ORDER BY tdr"; 
$result = mysql_query($sql); 
while ($row = mysql_fetch_array($result)) { 
$result1.="<tr><td colspan=\"2\" align=\"center\">$row[dnr]</td><td colspan=\"2\" align=\"center\">$row[cnt]</td></tr>"; 
} 
$result1.="<tr>
<td colspan=\"4\">&nbsp;</td>
</tr>
<tr>
<td colspan=\"4\" align=\"center\" bgcolor=\"#dcdcdc\"><b>OS Information:</b></td>
</tr>";

$sql = "SELECT count(browser) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%win%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$win = $row["cnt"]; } 

$sql = "SELECT count(browser) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%mac%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$mac = $row["cnt"]; } 

$sql = "SELECT count(browser) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%linux%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$linux = $row["cnt"]; } 

$sql = "SELECT count(browser) as cnt FROM $ad_table WHERE adid='$adid' AND (browser LIKE '%unix%' OR browser 
LIKE '%SunOS%' OR browser LIKE '%FreeBSD%' OR 
browser LIKE '%IRIX%' OR browser LIKE '%HP-UX%' OR browser LIKE '%OSF%' OR 
browser LIKE '%AIX%')"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$unix = $row["cnt"]; } 

$sql = "SELECT count(browser) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%spider%' OR 
browser LIKE '%bot%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$craw = $row["cnt"]; } 

$total = ($win + $mac + $linux + $unix + craw); 
$other = ($overall - $total); 
$winper = percentcalc($win, $total);
$macper = percentcalc($mac, $total);
$linuxper = percentcalc($linux, $total);
$unixper = percentcalc($unix, $total);
$crawper = percentcalc($craw, $total);
$otherper = percentcalc($other, $total);

$result1.="<tr>
<td width=\"25%\" align=\"center\"><b>OS</b></td>
<td width=\"25%\" align=\"center\"><b>Percent</b></td>
<td width=\"25%\" align=\"center\"></td>
<td width=\"25%\" align=\"center\"><b>Clicks/Views</b></td>
</tr>
<tr>
<td width=\"25%\">Windows</td>
<td width=\"25%\" align=\"center\">$winper %</td>
<td width=\"25%\"><img src=\"img/bar.gif\" width=\"$winper\" height=\"8\" border=\"0\" alt=\"\"></td>
<td width=\"25%\" align=\"center\">$win</td>
</tr>
<tr>
<td width=\"25%\">Macintosh</td>
<td width=\"25%\" align=\"center\">$macper %</td>
<td width=\"25%\"><img src=\"img/bar.gif\" width=\"$macper\" height=\"8\" border=\"0\" alt=\"\"></td>
<td width=\"25%\" align=\"center\">$mac</td>
</tr>
<tr>
<td width=\"25%\">Linux</td>
<td width=\"25%\" align=\"center\">$linuxper %</td>
<td width=\"25%\"><img src=\"img/bar.gif\" width=\"$linuxper\" height=\"8\" border=\"0\" alt=\"\"></td>
<td width=\"25%\" align=\"center\">$linux</td>
</tr>
<tr>
<td width=\"25%\">Unix</td>
<td width=\"25%\" align=\"center\">$unixper %</td>
<td width=\"25%\"><img src=\"img/bar.gif\" width=\"$unixper\" height=\"8\" border=\"0\" alt=\"\"></td>
<td width=\"25%\" align=\"center\">$unix</td>
</tr>
<tr>
<td width=\"25%\">Crawlers</td>
<td width=\"25%\" align=\"center\">$crawper %</td>
<td width=\"25%\"><img src=\"img/bar.gif\" width=\"$crawper\" height=\"8\" border=\"0\" alt=\"\"></td>
<td width=\"25%\" align=\"center\">$craw</td>
</tr>
<tr>
<td width=\"25%\">Others</td>
<td width=\"25%\" align=\"center\">$otherper %</td>
<td width=\"25%\"><img src=\"img/bar.gif\" width=\"$otherper\" height=\"8\" border=\"0\" alt=\"\"></td>
<td width=\"25%\" align=\"center\">$other</td>
</tr>
<tr>
<td colspan=\"4\"><b>Total: $overall</b></td>
</tr>
<tr>
<td colspan=\"4\">&nbsp;</td>
</tr>
<tr>
<td colspan=\"4\" align=\"center\" bgcolor=\"#dcdcdc\"><b>Browser Information</b></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"><b>Browser</b></td>
<td colspan=\"2\" align=\"center\"><b>Clicks/Views</b></td>
</tr>
<tr>
<td colspan=\"4\">";

$sql = "SELECT count(ip) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%MSIE%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$ms = $row["cnt"]; } 

$sql = "SELECT count(ip) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%Mozilla%' AND browser 
NOT LIKE '%MSIE%' AND browser NOT LIKE '%Opera%' AND browser NOT LIKE '%iCab%' AND browser NOT LIKE '%Konqueror%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$ns = $row["cnt"]; } 

$sql = "SELECT count(ip) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%Opera%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$opera = $row["cnt"]; } 

$sql = "SELECT count(ip) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%iCab%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$icab = $row["cnt"]; } 

$sql = "SELECT count(ip) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%Lynx%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$lynx = $row["cnt"]; } 

$sql = "SELECT count(ip) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%Konqueror%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$konq = $row["cnt"]; } 

$sql = "SELECT count(ip) as cnt FROM $ad_table WHERE adid='$adid' AND browser LIKE '%spider%' OR browser 
LIKE '%bot%'"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$bots = $row["cnt"]; } 

$total = ($ms + $ns + $opera + $icab + $lynx + $konq + $bots); 
$other = ($overall - $total);

$result1.="<tr><td colspan=\"2\" align=\"center\">MS Internet Explorer</td><td colspan=\"2\" align=\"center\">$ms</td></tr>
<tr><td colspan=\"2\" align=\"center\">Mozilla(Netscape)</td><td colspan=\"2\" align=\"center\">$ns</td></tr>
<tr><td colspan=\"2\" align=\"center\">Opera</td><td colspan=\"2\" align=\"center\">$opera</td></tr>
<tr><td colspan=\"2\" align=\"center\">iCab</td><td colspan=\"2\" align=\"center\">$icab</td></tr>
<tr><td colspan=\"2\" align=\"center\">Lynx</td><td colspan=\"2\" align=\"center\">$lynx</td></tr>
<tr><td colspan=\"2\" align=\"center\">Konqueror</td><td colspan=\"2\" align=\"center\">$konq</td></tr>
<tr><td colspan=\"2\" align=\"center\">Bots,Spiders,Crawlers</td><td colspan=\"2\" align=\"center\">$bots</td></tr>
<tr><td colspan=\"2\" align=\"center\">Other</td><td colspan=\"2\" align=\"center\">$other</td></tr>
<tr><td colspan=\"2\" align=\"center\"><b>Total</b></td><td colspan=\"2\" align=\"center\"><b>$overall</b></td></tr>
<tr>
<td colspan=\"4\">&nbsp;</td>
</tr>
<tr>
<td colspan=\"4\" align=\"center\" bgcolor=\"#dcdcdc\"><b>Top visitors</b></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"><b>IP address</b></td>
<td colspan=\"2\" align=\"center\"><b>Clicks/Views</b></td>
</tr>";

$sql = "SELECT COUNT(ip) AS CNT,ip FROM $ad_table WHERE adid='$adid' GROUP BY ip ORDER BY CNT 
DESC LIMIT 20"; 
$result = mysql_query ($sql); 
while ($row = mysql_fetch_array($result)) { 
$result1.="<tr><td colspan=\"2\" align=\"center\">$row[ip]</td><td colspan=\"2\" align=\"center\">$row[CNT]</td></tr>"; 
} 

$result1.="</table>";
return $result1;
}
?>