<?php
$dbh = mysql_connect ("localhost", "ramygala_knygos", "Nuoma2007") or die ('Nepavyko prisijungti prie DB, nes ' . mysql_error());
$pa = mysql_select_db ("ramygala_testknygos",$dbh);
mysql_query("SET NAMES 'utf8'");
$sql = "SELECT kultura_tvarkarastis.*, b.id AS id2, b.link AS link2, b.name AS name2, b.g_link FROM kultura_tvarkarastis LEFT JOIN kultura_location AS b ON kultura_tvarkarastis.location_id = b.id ORDER BY date, hour";
$res = mysql_query($sql);
$date_check = "2010-01-01";
$bgcolor = "#FFFFFF";
$data_month_old =0;
$icon = "";
$l_link="";
$l_link0 ="";
$till = "";
$check = true;
echo "<a name='top'></a>";
echo "<p align='center'><a href='#now'>ARTIMIAUSIAS RENGINYS</a></p><hr/>";
echo "<p align='center'><a href='#04'>Balandis</a> - <a href='#05'>Gegužė</a> - <a href='#06'>Birželis</a> - <a href='#07'>Liepa</a> - <a href='#08'>Rugpjūtis</a> - <a href='#09'>Rugsėjis</a> - <a href='#10'>Spalis</a> - <a href='#11'>Lapkritis</a></p>";
$now_date = date('Y-m-d');
echo "<div><font face='Arial' size='2px'><table border='0' cellpading ='0' cellspacing = '0' width = '624px'>";
$i =1;
while (($data = mysql_fetch_array($res, MYSQL_ASSOC)) && $i<=500){
if ($date_check <> $data['date']){
if ($i%2===1){$bgcolor = "#FFFFFF";}
else {$bgcolor = "#EEEEEE";}
$date_check = $data['date'];
$data0 = $data['date'];
$i++;
if ($data['date'] >= $now_date && $check){$data0 ="<a name='now'></a>".$data0; $check = false;}
if ($data['date2']<>""){$data0 = $data0." - <br>".$data['date2'];}
}
else {
$data0 = " ";
if ($data['date2']<>""){$till =$data['date']." - <br>".$data['date2'];}
$skaitliukas = " ";
}
// Nuorodos renginiui kurimas
if ($data['link'] <>"") {$link="<a href='".$data['link']."' target='_blank'> ";$link2 = "</a>";}
//Nuorodos ir paveiksliuko kurimas Google maps nuorodai
if ($data['g_link'] <>"") {$icon = "<a href='".$data['g_link']."'target ='_blank' ><img src='images/globe_icon.gif' height ='12' width ='12' alt='GMaps link' border ='0'/></a>";}
//Nuorodos kurimas rengionio vietai
if ($data['name2']<>"" && $data['link2']<>""){$l_link="<a href='".$data['link2']." ' target ='_blank'>";$l_link0="</a>";$data['location']=$data['name2'];}
$data_month = substr($data['date'], 5,2);
//Tikrinama ar yra tikslus renginio laikas
if ($data['hour']=="00:00:00"){$data['hour'] = "N/A";}
switch ($data_month) {
case 1:
$data_month_name = "Sausis";
break;
case 2:
$data_month_name = "Vasaris";
break;
case 3:
$data_month_name = "Kovas";
break;
case 4:
$data_month_name = "Balandis";
break;
case 5:
$data_month_name = "Gegužė";
break;
case 6:
$data_month_name = "Birželis";
break;
case 7:
$data_month_name = "Liepa";
break;
case 8:
$data_month_name = "Rugpjūtis";
break;
case 9:
$data_month_name = "Rugsėjis";
break;
case 10:
$data_month_name = "Spalis";
break;
case 11:
$data_month_name = "Lapkritis";
break;
case 12:
$data_month_name = "Gruodis";
break;
}
if ($data_month <> $data_month_old){
if ($i <= 2){$link_top="";} else {$link_top="<tr><td> </td><td> </td><td><div align='right'><a href='#top'>Į viršų</a></div></td></tr>";}
$data_month_line = $link_top."<tr><td> </td><td> </td><td><a name='$data_month'></a><h2>$data_month - $data_month_name</h2></td></tr>";
$data_month_old = $data_month;
}
echo $data_month_line."<tr bgcolor=$bgcolor valing=top><td align='center' width ='95px' valign='top' ><b>".$data0,$till."</b> </td><td width ='40px' align='left' valign='top'>".substr($data['hour'], 0, 5)." </td><td width='489px'><b>Pavadinimas: </b> $link".$data['name']." $link2<br><b>Vieta: </b>$l_link".$data['location']." $l_link0 $icon </td></tr>";
//Tikrina ar yra renginio aprasymas, jei nera, nespausdina paskutines eilutes
if ($data['description'] <> "nera"){
echo "<tr bgcolor=$bgcolor valign='top'><td width ='95px'> </td><td width ='40px'> </td><td width ='489px'><b>Aprašymas: </b><br>".$data['description']."<br><br></td></tr>";
}
else {
echo "<tr bgcolor=$bgcolor valign='top'><td width ='95px'><br></td><td width ='40px'> </td><td width ='489px'> </td></tr>";
}
$data_month_line ="";
$link ="";
$link2="";
$l_link ="";
$l_link0="";
$icon = "";
$till = "";
}
echo "</table></font></div>";
mysql_close($dbh);
?>