Scripts
Navigatie balk voor een kalender
Na wat rond gekeken te hebben kon ik geen leuke navigatie balk vinden voor mijn kalender die gebasseerd was op http://www.phphulp.nl/php/scripts/1/142/ Nu heb ik er zelf een gemaakt die eventueel stand-alone te gebruiken is. Voor de CSS freaks is het ook mogelijk om de tekst deels of helemaal te verwijderen, zoals bij het voorbeeld. Je hoeft alleen de mysql gegevens in te voeren en de 'actionurl' op te geven. Je kunt nooit verder terug gaan dan de oudste datum en nooit verder dan vandaag. Dus als er geen data's zitten in mySQL geeft hij dus geen knoppen weer Versie toelichting: 1.0.1 - kleine wijzegingen in opzet van weergeven. 1.0.2 - CSS-error bij .2day, gewijzigd alle "2day" naar "now" De rest mogen jullie zelf ontdekken ;)
navigatie-balk-voor-een-kalender
<!-- navigation.php -->
<?php
/* Copyright Notice
THIS NOTICE MAY NOT BE DELETED
Date Navigation Row
Author: Tessa Bakker
E-mail: tess A T shoekje D O T NL
Version: 1.0.2
Release: 2005/01/30
Language: all (dutch by default)
Script: PHP, MySQL, xHTML
End Copyricht Notice */
/* EXPLANATION OF SCRIPT: This script gives 7 buttons with can be used for browsing
a day, month or year backwards or forwards and a button to return to the date of today.
All the buttons are XHTML valid and useable for CSS
Users can't browse before first mysql date and after today
To remove the previous function change de if-statements with: $mysqlFirstLocalDate or date($_LOCAL_DATE['short']);
Posibility to use this script:
< ?php require ("dutch.php"); ? >
<table>
<tr>... rows with dates for calendar ...</tr>
< ?php require ("navigation.php";) ? >
</table>
Your mySQL database needs a table with a 'date' row using the type: date
FOR date explainations visit:
php date(): http://www.php.net/manual/nl/function.date.php
php strftime: http://www.php.net/manual/nl/function.strftime.php
mysql DATE_FORMAT(): http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
*/
//basic settings
$actionurl = "pagina.php?date="; //link from the page that has to be loaded with the new date
$table = "dairy";
//database settings
$server = 'localhost';
$username= 'username';
$password= 'wachtwoord';
$db = 'naam database';
$connectie = mysql_connect($server,$username,$password)or die (mysql_error());
mysql_select_db($db,$connectie)or die (mysql_error());
/** Get the date from a send link **/
if (empty($_GET['date'])){ //if 'date' is empty; use the date of today
$day = date("d");
$month = date("m");
$year = date ("Y");
}else{
$givenDate = ($_GET['date']);
$splitDate = explode ('-',$givenDate);
$day = $splitDate[$_LOCAL_DATE_PLACE['day']];
$month = $splitDate[$_LOCAL_DATE_PLACE['month']];
$year = $splitDate[$_LOCAL_DATE_PLACE['year']];
}
/** Look into the MySQL database for start and end date **/
$queryFirstDate = "SELECT DATE_FORMAT(date,'%Y%m%d') as mathdate, DATE_FORMAT(date,'".$_LOCAL_DATE_MYSQL['short']."') as localdate FROM ".$table." ORDER BY date ASC LIMIT 0,1";
$resultFirstDate = mysql_query($queryFirstDate) or die (mysql_error());
$mathdate = mysql_fetch_row($resultFirstDate);
$mysqlFirstDate = $mathdate[0];
$mysqlFirstLocalDate = $mathdate[1];
//day -1
if ($mysqlFirstDate < date("Ymd", mktime(0, 0, 0, $month, $day, $year)))
{
if (date("Ymd", mktime(0, 0, 0, $month, $day, $year)) > date("Ymd"))
{
$cellPrevDay = date($_LOCAL_DATE['short']);
}
else
{
$cellPrevDay = date($_LOCAL_DATE['short'], mktime(0, 0, 0, $month, $day-1, $year));
//month-1
if ($mysqlFirstDate <= date("Ymd", mktime(0, 0, 0, $month-1, $day, $year)))
{
if (date("Ymd", mktime(0, 0, 0, $month, $day, $year)) > date("Ymd"))
{
$cellPrevMonth = date($_LOCAL_DATE['short']);
}
else
{
$cellPrevMonth = date($_LOCAL_DATE['short'], mktime(0, 0, 0, $month-1, $day, $year));
//year-1
if ($mysqlFirstDate <= date("Ymd", mktime(0, 0, 0, $month, $day, $year-1)))
{
if (date("Ymd", mktime(0, 0, 0, $month, $day, $year)) > date("Ymd"))
$cellPrevYear = date($_LOCAL_DATE['short']);
else
$cellPrevYear = date($_LOCAL_DATE['short'], mktime(0, 0, 0, $month, $day, $year-1));
}
elseif (!($mysqlFirstLocalDate == $cellPrevMonth))
{
$cellPrevYear = $mysqlFirstLocalDate;
}
}
}
elseif (!($mysqlFirstLocalDate == $cellPrevDay))
{
$cellPrevMonth = $mysqlFirstLocalDate;
}
}
}
//day +1
if (date("Ymd") >= date("Ymd", mktime( 0, 0, 0, $month, $day+1, $year)))
{
if (date("Ymd", mktime(0, 0, 0, $month, $day, $year)) < $mysqlFirstDate)
{
$cellNextDay = $mysqlFirstLocalDate;
}
else
{
$cellNextDay = date($_LOCAL_DATE['short'],mktime(0, 0, 0, $month, $day+1, $year));
//month +1
if (date("Ymd") >= date("Ymd", mktime( 0, 0, 0, $month+1, $day, $year)))
{
if (date("Ymd", mktime(0, 0, 0, $month, $day, $year)) < $mysqlFirstDate)
{
$cellNextMonth = $mysqlFirstLocalDate;
}
else
{
$cellNextMonth = date($_LOCAL_DATE['short'],mktime(0, 0, 0, $month+1, $day, $year));
//year +1
if (date("Ymd") >= date("Ymd", mktime( 0, 0, 0, $month, $day, $year+1)))
{
if (date("Ymd", mktime(0, 0, 0, $month, $day, $year)) < $mysqlFirstDate)
$cellNextYear = $mysqlFirstLocalDate;
else
$cellNextYear = date($_LOCAL_DATE['short'],mktime(0, 0, 0, $month, $day, $year+1));
}
elseif(date("Ymd",mktime(0, 0, 0, $month+1, $day, $year)) < date("Ymd"))
{
$cellNextYear = date($_LOCAL_DATE['short']);
}
}
}
elseif(date("Ymd",mktime(0, 0, 0, $month, $day+1, $year)) < date("Ymd"))
{
$cellNextMonth = date($_LOCAL_DATE['short']);
}
}
}
/** replace cell information with xhtml and css functions **/
if (isset($cellPrevYear))
$cellPrevYear = "<a class=\"apyear\" href=\"".$actionurl.$cellPrevYear."\" title=\"".$_LANGUAGE['goto']." ".$cellPrevYear."\"><span class=\"extnav\">".$_LANGUAGE['prev(year)']." </span><span class=\"spyear\">".$_LANGUAGE['year']."</span></a>\n";
if (isset($cellPrevMonth))
$cellPrevMonth = "<a class=\"apmonth\" href=\"".$actionurl.$cellPrevMonth."\" title=\"".$_LANGUAGE['goto']." ".$cellPrevMonth."\"><span class=\"extnav\">".$_LANGUAGE['prev(month)']." </span><span class=\"spmonth\">".$_LANGUAGE['month']."</span></a>\n";
if (isset($cellPrevDay))
$cellPrevDay = "<a class=\"apday\" href=\"".$actionurl.$cellPrevDay."\" title=\"".$_LANGUAGE['goto']." ".$cellPrevDay."\"><span class=\"extnav\">".$_LANGUAGE['prev(day)']." </span><span class=\"spday\">".$_LANGUAGE['day']."</span></a>\n";
if (isset($cellNextYear))
$cellNextYear = "<a class=\"anyear\" href=\"".$actionurl.$cellNextYear."\" title=\"".$_LANGUAGE['goto']." ".$cellNextYear."\"><span class=\"extnav\">".$_LANGUAGE['next(year)']." </span><span class=\"snyear\">".$_LANGUAGE['year']."</span></a>\n";
if (isset($cellNextMonth))
$cellNextMonth = "<a class=\"anmonth\" href=\"".$actionurl.$cellNextMonth."\" title=\"".$_LANGUAGE['goto']." ".$cellNextMonth."\"><span class=\"extnav\">".$_LANGUAGE['next(month)']." </span><span class=\"snmonth\">".$_LANGUAGE['month']."</span></a>\n";
if (isset($cellNextDay))
$cellNextDay = "<a class=\"anday\" href=\"".$actionurl.$cellNextDay."\" title=\"".$_LANGUAGE['goto']." ".$cellNextDay."\"><span class=\"extnav\">".$_LANGUAGE['next(day)']." </span><span class=\"snday\">".$_LANGUAGE['day']."</span></a>\n";
/** create the xhtml navigation table **/
//creating proper html with a css-style
echo "<html>\n<head>\n<title>Example</title>\n<style type=\"text/css\" media=\"all\">\n@import \"http://location/of/your/css/file.css";
\n</style>\n</head>\n<body>\n";
//table
echo "<table>\n"; // << you can delete this is you put you navigation bar as a hole row into your calendar
echo "<tr class=\"navigation\"><td class=\"pyear\">".$cellPrevYear."</td><td class=\"pmonth\">".$cellPrevMonth."</td><td class=\"pday\">".$cellPrevDay."</td><td class=\"goto2day\"><a class=\"agoto2day\" href=\"".$actionurl.date($_LOCAL_DATE['short'])."\" title=\"".$_LANGUAGE['goto']." ".$_LANGUAGE['today']."\"><span class=\"sgoto2day\">".$_LANGUAGE['today']."</span></a></td><td class=\"nday\">".$cellNextDay."</td><td class=\"nmonth\">".$cellNextMonth."</td><td class=\"nyear\">".$cellNextYear."</td></tr>\n";
echo "</table>\n"; // << you can delete this is you put you navigation bar as a hole row into your calendar
echo "</body>\n</html>";
?>
<!-- dutch.php -->
<?php
/** Start Date Settings **/
setlocale (LC_ALL, 'nld_nld'); //Local settings Windows Platform
setlocale (LC_ALL, 'nl_NL'); //Local settings UNIX/Linux Platform
$_LOCAL_DATE['medium'] = 'd-m-Y'; //date()
$_LOCAL_DATE['short'] = 'd-m-Y'; //date()
$_LOCAL_DATE_MYSQL['short'] = '%d-%m-%Y'; //DATE_FORMAT()
$_LOCAL_DATE_EREG['short'] = '([0-9]{2})-([0-9]{2})-([0-9]{4})'; //change the number between the {}
$_LOCAL_DATE_PLACE['day'] = '0'; //0 = first place, 2= last place
$_LOCAL_DATE_PLACE['month'] = '1';
$_LOCAL_DATE_PLACE['year'] = '2';
/** End Date Settings **/
/** Begin Translations for the Navigation Menu **/
$_LANGUAGE['today'] = 'vandaag';
$_LANGUAGE['year'] = 'jaar';
$_LANGUAGE['month'] = 'maand';
$_LANGUAGE['day'] = 'dag';
$_LANGUAGE['prev(year)'] = 'vorig';
$_LANGUAGE['prev(month)'] = 'vorige';
$_LANGUAGE['prev(day)'] = 'vorige';
$_LANGUAGE['next(year)'] = 'volgend';
$_LANGUAGE['next(month)'] = 'volgende';
$_LANGUAGE['next(day)'] = 'volgende';
$_LANGUAGE['goto'] = 'Ga naar';
/** End Translations for the Navigation Menu **/
?>
Reacties
0