<?php
/*
include_once "_c/db.inc";
//start sesji
session_start();
/*
* Wczytanie danych do sesji
*/
$sess_url = "default";
if(isset($HTTP_REFERER) and !empty($HTTP_REFERER))
{
$sess_url = md5($_SERVER['SERVER_NAME']);
}
if(!isset($_SESSION) or !isset($_SESSION[$sess_url]))
{
$baza = new baza_danych("localhost","aa5275_lukasz","fidley","aa5275_lukasz",0);
$baza->otworz();
$SQL = "SELECT DISTINCT * FROM `allegro` WHERE `data_zakonczenia` > now() ORDER BY rand() LIMIT 0,4 ;";
$baza->zapytaj($SQL);
while($row = $baza->pobierzTabliceAsocjacyjna())
{
$_SESSION[$sess_url][] = $row;
}
$baza->zamknij();
}
//przypisujemy dane do zmiennej data
$data = $_SESSION[$sess_url];
//strona,nr produkt itp
$p = (!$p || $p > 4 || $p < 1)? '0' : $p-1;
//typ, domylnie na obrazek
$t = (!$t)? "i" : $t;
if(isset($nim))
{
header("Content-type: image/png");
exit;
}
switch($t)
{
default:
/* image - obrazek */
header("Content-type: image/png");
$img_width = 150;
$img_height = 150;
$im = imagecreatetruecolor($img_width, $img_height);
$tlo = imagecolorallocate($im, 255, 255, 255);
$bialy = imagecolorallocate($im,250,250,250);
$czarny = imagecolorallocate($im,0,0,0);
imagefilledrectangle($im, 0, 0, $img_width, $img_height, $tlo);
$im2 = @imagecreatefromjpeg($data[$p]['obrazek']); /* Attempt to open */
if (!$im2) { /* See if it failed */
/* Output an errmsg */
imagestring($im, 2, 5, 5, "Error loading $imgname", $czarny);
imagejpeg($im);
exit();
}
else
{
$im2_h = imagesy($im2);
$im2_w = imagesx($im2);
$posx = round(($img_width-$im2_w)/2);
$posx = ($posx< 0)? 0 : $posx;
$posy = round(($img_height-$im2_h)/2);
$posy = ($posy< 0)? 0 : $posy;
imagecopy($im, $im2, $posx, $posy, 0, 0, $im2_w, $im2_h);
}
// Napis w kilku liniach
$font = 2;
$font_width = imagefontwidth($font);
$font_height = 11;
$opis = $data[$p]['opis'];
$opis_width = strlen($opis);
$krok = 0;
while( ($opis_width+2)*$font_width > 2*$font_width )
{
$opis_text = substr($opis,0,ceil ( ( $img_width - ( 2*$font_width ) ) /$font_width ));
$opis = substr($opis, ceil ( ( $img_width - ( 2*$font_width ) ) /$font_width ) );
$opis_width = strlen($opis);
ImageString($im,$font,($font_width +0),($krok*$font_height),$opis_text,$bialy);
ImageString($im,$font,($font_width +2),(($krok*$font_height) +2),$opis_text,$bialy);
ImageString($im,$font,($font_width +1),(($krok*$font_height) +1),$opis_text,$czarny);
$krok++;
}
// Cena
$c = "{$data[$p]['cena']}";
$c_pos = round(($img_width -(strlen($c)*imagefontwidth(5)))/2);
ImageString($im,5,$c_pos-1,$img_height-21,$c,$bialy);
ImageString($im,5,$c_pos+1,$img_height-19,$c,$bialy);
ImageString($im,5,$c_pos,$img_height-20,$c,$czarny);
// The text to draw
//$text = '-)-(-agi TTF';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, round($img_height/2), $czarny, $font, $text);
imagepng($im);
exit();
break;
case "u":
/* url = link */
if(isset($data[$p]['link']))
{
header("Location:
http://allegro.pl/{$data[$p]['link']}");
exit();
}
else
{
header("Location:
http://allegro.pl/{$data[$p]['link']}");
}
break;
}
?>