home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 October / CMCD1004.ISO / Software / Shareware / Programare / cnstats / _funct.php next >
Encoding:
PHP Script  |  2004-07-08  |  12.3 KB  |  345 lines

  1. <?
  2. if (isset($_SERVER["DOCUMENT_ROOT"])) $CNSTATS_DR=$_SERVER["DOCUMENT_ROOT"];
  3. elseif (isset($HTTP_SERVER_VARS["DOCUMENT_ROOT"])) $CNSTATS_DR=$HTTP_SERVER_VARS["DOCUMENT_ROOT"];
  4. elseif (isset($DOCUMENT_ROOT)) $CNSTATS_DR=$DOCUMENT_ROOT;
  5.  
  6. if ($CNSTATS_DR[strlen($CNSTATS_DR)-1]!="/") $CNSTATS_DR.="/";
  7.  
  8. if (!isset($STATS_CONF["dbname"])) include $CNSTATS_DR."cnstats/config.php";
  9.  
  10. if ($COUNTER["resolution"]=="1024") {
  11.     $IMGW=465+230;
  12.     $IMGH=270;
  13.     $TW=695;
  14.     $LW=605;
  15.     $TDW=601;$TDS="style='overflow:hidden;word-wrap:yesbreak-word;word-break: break-all;width: ".$TDW."px;'";
  16.     $TABLE="<table width='".$TW."' cellspacing='1' border='0' cellpadding='3' bgcolor='#D4F3D7' style='table-layout:fixed;' ".$TA.">\n";
  17.     $BBG="bbg1024.gif";
  18.     }
  19. else {
  20.     $IMGW=465;
  21.     $IMGH=270;
  22.     $TW=465;
  23.     $LW=375;
  24.     $TDW=371;$TDS="style='overflow:hidden;word-wrap:yesbreak-word;word-break: break-all;width: ".$TDW."px;'";
  25.     $TABLE="<table width='".$TW."' cellspacing='1' border='0' cellpadding='3' bgcolor='#D4F3D7' style='table-layout:fixed;' ".$TA.">\n";
  26.     $BBG="bbg800.gif";
  27.     }
  28.  
  29. function cnstats_sql_query($query) {
  30.     GLOBAL $LANG,$STATS_CONF,$COUNTER,$HTTP_SERVER_VARS;
  31.  
  32.     if ($STATS_CONF["sqlserver"]="MySql") {
  33.         $r=@mysql_query($query);
  34.         if (mysql_errno()!=0) {
  35.             if ($COUNTER["senderrorsbymail"]=="yes" && !empty($STATS_CONF["cnsoftwarelogin"])) {
  36.                 mail($STATS_CONF["cnsoftwarelogin"],"CNStats MySql Error",">A fatal MySQL error occured\n\n".mysql_error()."\nQuery:\n------------\n".$query."\n-----------\nURL: http://".$HTTP_SERVER_VARS["HTTP_HOST"].$HTTP_SERVER_VARS["REQUEST_URI"]."\nDate: ".date($LANG["datetime_format"]));
  37.                 }
  38.             die("<font color=red><B>A fatal MySQL error occured:</B></font><br><br>\n\n".mysql_error()."<br><br>\n\n $query");                                                       
  39.             }
  40.         }
  41.     return($r);
  42.     }
  43.  
  44. function ShowTable($num) {
  45.     GLOBAL $TABLED,$TABLEC,$TABLEU,$TDW,$TDS,$TW,$LW,$LANG,$TABLE,$CONFIG;
  46.  
  47.     $CONFIG["showlines"]=1;
  48.     if ($CONFIG["showlines"]==1) {
  49.         $max=$sum=0;
  50.         for ($i=0;$i<count($TABLEC);$i++) {
  51.             if ($TABLED[$i]!=$LANG["noreferer"] &&
  52.                 $TABLED[$i]!=$LANG["direct jump"] &&
  53.                 $TABLED[$i]!=$LANG["other queries"] &&
  54.                 $TABLED[$i]!=$LANG["other countries"]
  55.                )
  56.                 if ($max<$TABLEC[$i]) $max=$TABLEC[$i];
  57.             $sum+=$TABLEC[$i];
  58.             }
  59.         if ($max<5) $CONFIG["showlines"]=0;
  60.         }                                                                                                        
  61.  
  62.     print $TABLE;
  63.     for ($i=0;$i<count($TABLEC);$i++) {
  64.         if ($class!="tbl1") $class="tbl1"; else $class="tbl2";
  65.         print "<tr class=".$class."><td valign='top' width='27'><b>".($num+$i+1)."</b></td><td width='".$TDW."' ".$TDS.">";
  66.  
  67.         if (empty($TABLEU[$i])) print $TABLED[$i];
  68.         else print "<a target=_blank href='".$TABLEU[$i]."'>".$TABLED[$i]."</a>";
  69.  
  70.         if ($CONFIG["gauge"]==1) {
  71.             if ($TABLED[$i]!=$LANG["noreferer"] &&
  72.                 $TABLED[$i]!=$LANG["direct jump"] &&
  73.                 $TABLED[$i]!=$LANG["other queries"] &&
  74.                 $TABLED[$i]!=$LANG["other countries"]
  75.                )
  76.                 if ($CONFIG["showlines"]==1) print "<br><img src='img/gauge.gif' alt='".$TABLEC[$i]."' width=".intval($TABLEC[$i]*$LW/$max)." height=7>";
  77.             }
  78.  
  79.         print "</td><td align=right width=45> ".$TABLEC[$i]." ";
  80.     
  81.         /* ╬≥εß≡αµα≥ⁿ ∩≡ε÷σφ≥√ */
  82.         if ($CONFIG["percents"]==1) {
  83.             print "<br><font size=-4 color=#A0A0A0> ".sprintf("%2.2f",$TABLEC[$i]*100/$sum)."% </font>";
  84.             }
  85.  
  86.         print "</td></tr>\n";
  87.         }
  88.     print "</table>\n";
  89.     }
  90.  
  91. function LeftRight($start,$inpage,$num,$count,$marginu=5,$margind=5,$addurl="") {
  92.     GLOBAL $LANG,$DATELINK,$stm,$ftm,$st,$HTTP_GET_VARS;
  93.  
  94.     if ($count==0) return;
  95.  
  96.     $prev=$start-$inpage;
  97.     print "<center><img src='img/none.gif' alt='' width=1 height=".$marginu."><br>";
  98.     if ($prev>=0) 
  99.         print "<a href='index.php?st=".$st."&start=".$prev."&stm=".$stm."&ftm=".$ftm.$addurl.$DATELINK."'><< ".$LANG["prev"]."</a> ";
  100.     print "[ ".$LANG["page"]." ".(1+my_round(0.9999+$start/$inpage))."/".my_round(0.9999+$count/$inpage)." ] ";
  101.     $next=$start+$inpage;
  102.     if ($next<$count)
  103.         print " <a href='index.php?st=".$st."&start=".$next."&stm=".$stm."&ftm=".$ftm.$addurl.$DATELINK."'>".$LANG["next"]." >></a>";
  104.     print "</center><img src='img/none.gif' alt='' width=1 height=".$margind."><br>";
  105.     
  106.     }
  107.  
  108. function strrtolower($str) { 
  109.     $trans=array( 
  110.      "└" => "α", "┴" => "ß", "┬" => "Γ", "├" => "π", "─" => "Σ", "┼" => "σ", 
  111.      "¿" => "╕", "╞" => "µ", "╟" => "τ", "╚" => "Φ", "╔" => "Θ", "╩" => "Ω", 
  112.      "╦" => "δ", "╠" => "∞", "═" => "φ", "╬" => "ε", "╧" => "∩", "╨" => "≡", 
  113.      "╤" => "±", "╥" => "≥", "╙" => "≤", "╘" => "⌠", "╒" => "⌡", "╓" => "÷", 
  114.      "╫" => "≈", "╪" => "°", "┘" => "∙", "▄" => "ⁿ", "█" => "√", "┌" => "·", 
  115.      "▌" => "²", "▐" => "■", "▀" => " ", 
  116.     ); 
  117.     $str=strtr($str, $trans); 
  118.     return($str); 
  119.     } 
  120.  
  121. function DecodePhrase($data,$url) {
  122.     $data=urldecode($data);
  123.  
  124.     $utf8=0;
  125.     if (strstr($url,"ie=utf-8")) $utf8=1;
  126.     if ($utf8==0) if (strstr($url,"oe=utf-8")) $utf8=1;
  127.     if ($utf8==0) if (strstr($url,"oe=UTF-8")) $utf8=1;
  128.     if ($utf8==0) if (strstr($url,"ie=UTF-8")) $utf8=1;
  129.  
  130.     if ($utf8==1) $data=cnstats_unUTF($data);
  131.     
  132.     $p=strpos(" ".$data,"text=");
  133.     if ($p) {
  134.         $data=substr($data,$p+4);
  135.         $data=urldecode($data);
  136.         $data=convert_cyr_string($data,"k","w");
  137.         }
  138.     else $data=urldecode($data);
  139.  
  140.  
  141.     $data=str_replace("+"," ",$data);
  142.     if (strpos($data,"&")) $data=substr($data,0,strpos($data,"&"));
  143.  
  144.     if ($utf8==1) cnstats_unUTF($data);
  145.  
  146.     if ($class!="tbl1") $class="tbl1"; else $class="tbl2";
  147.     return($data);
  148.     }
  149.  
  150. function mysqlconnect() {
  151.     GLOBAL $STATS_CONF;
  152.     @mysql_connect($STATS_CONF["sqlhost"],$STATS_CONF["sqluser"],$STATS_CONF["sqlpassword"]) or die("Error connectiong to database.\n<hr size=1><b>Host:</b> ".$STATS_CONF["sqlhost"]."\n<br><b>Login:</b> ".$STATS_CONF["sqluser"]."\n<br><b>Using password</b>: ".(empty($STATS_CONF["sqlpassword"])?"no":"yes"));
  153.     @mysql_select_db($STATS_CONF["dbname"]) or die("Connecting to MySql...Ok<hr size=1>\nError selecting database<br>\n<B>Database name:</B> ".$STATS_CONF["dbname"]);
  154.     }
  155.  
  156. function getmicrotime(){ 
  157.     list($usec, $sec) = explode(" ",microtime()); 
  158.     return ((float)$usec + (float)$sec); 
  159.     } 
  160.  
  161. function title($title) {
  162.     print "<table cellspacing=0 cellpadding=5 border=0 class='ttl'><tr><td><B>".$title."</B></td></tr></table>\n";
  163.     }
  164.  
  165. function my_round($num) {
  166.     if (strpos($num,".")!=0) return(substr($num,0,strpos($num,".")));
  167.     else return($num);
  168.     }
  169.  
  170. function cnstats_error($err) {
  171.     print "<table bgcolor=red cellspacing=1 cellpadding=5 border=0><tr><td bgcolor=#FFF0F0>";
  172.     print $err;
  173.     print "</td></tr></table>";
  174.     die();
  175.     }
  176.  
  177. function cnstats_mhtml($s) {
  178.     $s=StripSlashes($s);
  179.     $s=str_replace("'","'",$s);
  180.     $s=str_replace("\"",""",$s);
  181.     return($s);
  182.     }
  183.  
  184. function cnstats_themesidebox($title,$content) {
  185. ?>
  186. <table width='100%' cellspacing=1 cellpadding=6 bgcolor='#E0E0E0'><tr><td bgcolor='#F0F0F0' class='title'>
  187. <?=$title;?>
  188. </td></tr><tr><td bgcolor='#F8F8F8'>
  189. <?=$content;?>
  190. </td></tr></table>
  191. <?
  192.     }
  193.  
  194. function cnstats_unUnicode($str) {
  195. $unicode = array(
  196.     "%u0410"=>"└","%u0411"=>"┴","%u0412"=>"┬","%u0413"=>"├","%u0414"=>"─","%u0415"=>"┼",
  197.     "%u0401"=>"¿","%u0416"=>"╞","%u0417"=>"╟","%u0418"=>"╚","%u0419"=>"╔","%u041A"=>"╩",
  198.     "%u041B"=>"╦","%u041C"=>"╠","%u041D"=>"═","%u041E"=>"╬","%u041F"=>"╧","%u0420"=>"╨",
  199.     "%u0421"=>"╤","%u0422"=>"╥","%u0423"=>"╙","%u0424"=>"╘","%u0425"=>"╒","%u0426"=>"╓",
  200.     "%u0427"=>"╫","%u0428"=>"╪","%u0429"=>"┘","%u042A"=>"┌","%u042B"=>"█","%u042C"=>"▄",
  201.     "%u042D"=>"▌","%u042E"=>"▐","%u042F"=>"▀","%u0430"=>"α","%u0431"=>"ß","%u0432"=>"Γ",
  202.     "%u0433"=>"π","%u0434"=>"Σ","%u0435"=>"σ","%u0451"=>"╕","%u0436"=>"µ","%u0437"=>"τ",
  203.     "%u0438"=>"Φ","%u0439"=>"Θ","%u043A"=>"Ω","%u043B"=>"δ","%u043C"=>"∞","%u043D"=>"φ",
  204.     "%u043E"=>"ε","%u043F"=>"∩","%u0440"=>"≡","%u0441"=>"±","%u0442"=>"≥","%u0443"=>"≤",
  205.     "%u0444"=>"⌠","%u0445"=>"⌡","%u0446"=>"÷","%u0447"=>"≈","%u0448"=>"°","%u0449"=>"∙",
  206.     "%u044A"=>"·","%u044B"=>"√","%u044C"=>"ⁿ","%u044D"=>"²","%u044E"=>"■","%u044F"=>" ");
  207.  
  208.     return(strtr($str, $unicode));
  209.     }
  210.  
  211. function cnstats_unUTF($str) {
  212.     $newstr="";
  213.     $l=strlen($str);
  214.     $i=0;
  215.     while ($i<$l) {
  216.         $code=ord($str[$i]);
  217.         if ($code<0x80) $newstr.=$str[$i];
  218.         else {
  219.             $i++;
  220.             $w=$code*256+ord($str[$i]);
  221.  
  222.             if ($w>=0xd090) $b=192+$w-0xd090; else $b=95;
  223.             if ($w>=0xd180 && $w<=0xd18f) $b=240+$w-0xd180;
  224.             $newstr.=chr($b);
  225.             }
  226.         $i++;
  227.         }
  228.     return($newstr);
  229.     }
  230.  
  231. function cNumber($num) {
  232.     $num=strval(intval($num));
  233.     $res="";
  234.     $l=strlen($num);
  235.     $c=-1;
  236.     for ($i=$l;$i>=0;$i--) {
  237.         $c++;
  238.         $res=$num[$i].$res;
  239.         if ($c>2) {$res="`".$res;$c=0;}
  240.         }
  241.     return($res);
  242.     }
  243.  
  244. function gdVersion() {
  245.     if (!function_exists("imagepng")) return(0);
  246.  
  247.     ob_start();
  248.     phpinfo(8);
  249.     $phpinfo=ob_get_contents();
  250.     ob_end_clean();
  251.     $phpinfo=stristr($phpinfo,"gd version");
  252.     $phpinfo=stristr($phpinfo,"version");
  253.  
  254.     $end=strpos($phpinfo,"</tr>");
  255.     if ($end) $phpinfo=substr($phpinfo,0,$end);
  256.     $phpinfo=strip_tags($phpinfo);
  257.  
  258.     if (ereg(".*([0-9]+)\.([0-9]+)\.([0-9]+).*", $phpinfo, $r)) {
  259.         $phpinfo=$r[1].".".$r[2].".".$r[3];
  260.         }
  261.  
  262.     if (version_compare("2.0", $phpinfo)>=1) return(1);
  263.     else return(2);
  264.     }
  265.  
  266. function GetLanguage($code) {
  267.     $lr=mysql_query("SELECT eng FROM cns_languages WHERE code='".mysql_escape_string($code)."';");
  268.     if (mysql_num_rows($lr)==1) return(mysql_result($lr,0,0));
  269.     else return("");
  270.     }
  271.  
  272. function RemoveVar($var,$qs) {
  273.     $vars=explode("&",$qs);
  274.     while (list ($key, $val) = each ($vars)) {
  275.         if (substr($val,0,strlen($var))==$var) unset($vars[$key]);
  276.         }
  277.  
  278.     $qs="";
  279.     reset($vars);
  280.     while (list ($key, $val) = each ($vars)) $qs.=$val."&";    
  281.     $qs=substr($qs,0,-5);
  282.     return($qs);
  283.     }
  284.  
  285. function GenerateFilter($title) {
  286.     $excl=cnstats_sql_query("select txt,id FROM cns_filters WHERE title='".$title."' ORDER BY id");
  287.     while ($a=mysql_fetch_array($excl,MYSQL_ASSOC)) {
  288.         $e=explode("|||",$a["txt"]);
  289.         if ($excl_count==0) $L=""; else $L=$e[1]==0?"AND":"OR";
  290.  
  291.         switch ($e[0]) {
  292.             case 1 : {$F="page";$e[3]=urlencode($e[3]);break;}
  293.             case 3 : {$F="language";break;}
  294.             case 4 : {$F="agent";break;}
  295.             default: {$F="referer";break;}
  296.             }
  297.  
  298.         $e[3]=str_replace("%","\%",$e[3]);
  299.         $e[3]=str_replace("*","%",$e[3]);
  300.         $e[3]=str_replace("!","_",$e[3]);
  301.  
  302.         switch ($e[2]) {
  303.             case 1: {$quer=$quer." ".$L." ".$F." LIKE '%".$e[3]."%'";$excl_count++;break;}
  304.             case 2: {$quer=$quer." ".$L." ".$F." NOT LIKE '%".$e[3]."%'";$excl_count++;break;}
  305.             case 3: {$quer=$quer." ".$L." ".$F." LIKE '".$e[3]."%'";$excl_count++;break;}
  306.             case 4: {$quer=$quer." ".$L." ".$F." NOT LIKE '".$e[3]."%'";$excl_count++;break;}
  307.             case 5: {$quer=$quer." ".$L." ".$F." LIKE '%".$e[3]."'";$excl_count++;break;}
  308.             case 6: {$quer=$quer." ".$L." ".$F." NOT LIKE '%".$e[3]."'";$excl_count++;break;}
  309.             }
  310.         }
  311.     if (!empty($quer)) $quer=" AND (".$quer.")";
  312.     return($quer);
  313.     }
  314.  
  315. function FormFilter($title) {
  316.     GLOBAL $st,$stm,$ftm,$DATELINK,$LANG;
  317.  
  318.     print "<form action='index.php'>\n";
  319.     print "<input type='hidden' name='st' value='".$st."'>\n";
  320.     print "<input type='hidden' name='stm' value='".$stm."'>\n";
  321.     print "<input type='hidden' name='ftm' value='".$ftm."'>\n";
  322.  
  323.     $fields=explode("&",RemoveVar("filter",$DATELINK));
  324.     while (list ($key, $val) = each ($fields)) {
  325.         list ($vkey,$vval)=explode("=",$val);
  326.         if (!empty($vkey)) print "<input type=\"hidden\" name=\"".$vkey."\" value='".cnstats_mhtml(urldecode($vval))."'>\n";
  327.         }
  328.  
  329.     print "<table><tr><td colspan=2>".$LANG["filter"].":</td></tr><tr><td>";
  330.     $excl=cnstats_sql_query("select title FROM cns_filters GROUP BY title ORDER BY id");
  331.     print "<SELECT name='filter'>";
  332.     print "<OPTION value=''>".$LANG["no filter"]."\n";
  333.     while ($a=mysql_fetch_array($excl,MYSQL_ASSOC)) {
  334.         if ($a["title"]==$title) $sel=" selected"; else $sel="";
  335.         print "<OPTION value='".$a["title"]."'".$sel.">".$a["title"]."\n";
  336.         }
  337.     print "</SELECT>\n";
  338.     print "</td><td><input type='image' src='img/go.gif' width='19' height='18' alt='go' border=''0'></td></tr></table>\n";
  339.     print "</form>\n";
  340.     }
  341.  
  342.  
  343. $LANG["softname"]="CNStats 2.2";
  344. $LANG["copyright"]="<a href='http://www.cn-software.com/cnstats/' target='_blank'>".$LANG["softname"]."</a><br>© 2000-2004 <a href='http://www.cn-software.com/' target='_blank'>CN-Software</a>";
  345. ?>