//getmicrotime();
include ("sql.class.php");
include ("conf.php");
$sql= new sql();
$sql->conn($conf['user'],$conf['pass'],$conf['db'],$conf['host']);
echo "document.write(\"".doro()."\");";
/*
function getmicrotime(){
return microtime();
}
function getmicrotime2(){
$mc=microtime();
$oc=getmicrotime();
return ($mc - $oc);
}
*/
function doro(){
global $sql;
global $conf;
$dir=$conf['ban_path']."/";
$sql->query("SELECT * FROM ".$conf['tabela']." WHERE rotator='$_GET[id]' AND sila>0");
$ile=$sql->ile();
if ($ile==0){
if (!$_GET['w']){$_GET['w']==400;}if (!$_GET['h']){$_GET['h']==200;}
$b.="";
}
else{
$sql->getdata();
$a=$sql->wynik[0];
$baner=losuj_baner($_GET['id']);
$cnazwa=$baner['nazwa'];
$cid=$baner['id'];
$clink=$baner['link'];
if (is_file($dir.$cnazwa)==true){
$ext=get_ext($cnazwa);
$z=getimagesize($dir.$cnazwa);
}else{
$_GET['w']=200;$_GET['h']=100;
$ext="jpg";
}
if (!$_GET['w'] && !$_GET['h'] ){$_GET['w']=$z[0];$_GET['h']=$z[1];}
if ($ext=="swf"){
#####FLASH#####
$b.="";
}else{
######IMAGE####
if ($clink!=""){
$b.="";
}else{
$b.="";
}
}
dodaj($cnazwa,"prze",1);
}
return $b;
}
function get_ext($filename){
$a=explode(".",$filename);
$c=count($a);
$to=$c-1;
return strtolower($a[$to]);
}
function losuj_baner($rotator){
global $sql;
global $conf;
$sql->query("SELECT SUM(sila) sumsila FROM ".$conf['tabela']." WHERE rotator='$rotator' AND sila>0");
$sql->getdata();
$suma=$sql->wynik[0]['sumsila'];
//echo $suma;
$sql->query("SELECT * FROM ".$conf['tabela']." WHERE rotator='$rotator' AND sila>0");
$sql->getdata();
$w=$sql->wynik;
$il=$sql->ile();
$d=0;
if ($w[0]['rnd']==1){
srand((double)microtime()*1000000);
$rand=rand(1,$suma);
$z=-1;
while($d<$rand){
$d=$d+$w[++$z]['sila'];
if ($z>150){$d=100000000;}
}
if ($z>150){return array("nazwa"=>"overflow","id"=>0,"link"=>"");}else{return array("nazwa"=>$w[$z]['nazwa'],"id"=>$w[$z]['id'],"link"=>$w[$z]['link']);}
}else{
while ($d<$il){
$tmp=floor($w[$d]['prze']/(($w[$d]['sila']/$suma)*$w[$d]['los']));
//echo $suma;
$sql->query("UPDATE ".$conf['tabela']." SET tmp='$tmp' WHERE id='".$w[$d++][id]."'");
}
$sql->query("SELECT * FROM ".$conf['tabela']." WHERE rotator='$rotator' AND sila>0 ORDER BY tmp ASC, sila DESC");
$sql->getdata();
return array("nazwa"=>$sql->wynik[0]['nazwa'],"id"=>$sql->wynik[0]['id'],"link"=>$sql->wynik[0]['link']);
}
}
function dodaj($nazwa,$what,$ile){
global $sql;
global $conf;
$sql->query("UPDATE ".$conf['tabela']." SET ".$what."=".$what."+'".$ile."' WHERE nazwa='".$nazwa."'");
}
function http_link($link){
$link=str_replace("http://","",$link);
return "http://".$link;
}
$sql->disconn();
//echo getmicrotime2();
?>