Scripts
Kalender met sql
Deze kalender heb ik op me site geimplementeerd in het inlogsysteem van reto credits mede voor hem. Ik heb helaas geen test omgeving meer omdat hij al operationeel is en ik eigenlijk niet zo'n zin had om nieuwe test omgeving op te zetten vandaar. Het bestaat uit 4 bestandjes die moeten even aangepast worden naar eigen instellingen!!! Dit moet in de database die je moet aanmaken CREATE TABLE agenda ( id int(11) NOT NULL auto_increment, datum date default NULL, evenement varchar(255) default NULL, omschrijving varchar(255) default NULL, PRIMARY KEY (`id`) ) TYPE=MyISAM;
kalender-met-sql
/////// admin_verwijder.php ////////
<?php
require_once('config.php');
//require_once('forms.php');
?>
<form action="" method="post">
<table width=410" border="0" align="center" cellspacing="0" cellpadding="0">
<tr>
<td height="5"><img src="images/spacer.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="5" bgcolor="CCCCCC">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="4"> </td>
<td>Verwijder agendapunt</td>
<td width="4"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="5"><img src="images/spacer.gif" width="1" height="1"></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="E7EBEF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4"> </td>
<td width="120" align="left">Datum: jjjj-mm-dd</td>
<td width="274" align="right"><input type="text" name="datum" size="30"></td>
<td width="12"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="30" align="left" valign="middle" bgcolor="CCCCCC">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4"> </td>
<td width="197" align="left"> </td>
<input type="hidden" value="1" name="afhandeling">
<td width="197" align="right"><input type="submit" value="Verwijder" name="submit"></td>
<td width="12"> </td>
</tr>
</table>
</td>
</tr>
</form>
<?php
require_once('config.php');
if ($submit)
{
$actie = "DELETE FROM agenda WHERE datum='".mysql_real_escape_string($_POST['datum'])."'";
mysql_query($actie);
}
?>
///////////// admin_voegtoe.php /////////////
<?php
require_once('config.php');
//require_once('forms.php');
?>
<form action="" method="post">
<table width=410" border="0" align="center" cellspacing="0" cellpadding="0">
<tr>
<td height="5"><img src="images/spacer.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="5" bgcolor="CCCCCC">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="4"> </td>
<td>Voeg agendapunt toe</td>
<td width="4"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="5"><img src="images/spacer.gif" width="1" height="1"></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="E7EBEF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4"> </td>
<td width="120" align="left">Datum: jjjj-mm-dd</td>
<td width="274" align="right"><input type="text" name="datum" size="30"></td>
<td width="12"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="E7EBEF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4"> </td>
<td width="120" align="left">Evenement:</td>
<td width="274" align="right"><input type="text" name="evenement" size="30"></td>
<td width="12"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="E7EBEF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4"> </td>
<td width="120" align="left">Omschrijving:</td>
<td width="274" align="right"><input type="text" name="omschrijving" size="30"></td>
<td width="12"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="5"><img src="images/spacer.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="left" valign="middle" bgcolor="CCCCCC">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4"> </td>
<td width="197" align="left"> </td>
<input type="hidden" value="1" name="afhandeling">
<td width="197" align="right"><input type="submit" value="Voeg toe" name="submit"></td>
<td width="12"> </td>
</tr>
</table>
</td>
</tr>
</form>
<?php
if ($submit)
{
$query = "INSERT INTO agenda (datum, evenement, omschrijving)
VALUES ('".$_POST['datum']."', '".$_POST['evenement']."', '".$_POST['omschrijving']."')";
$result = mysql_query($query) or die (mysql_error());
}
?>
///////////// agenda.php ///////////
<?php
error_reporting(E_ALL);
if (!isset($_GET['maand']))
$_GET['maand'] = date('m');
if (!isset($_GET['jaar']))
$_GET['jaar'] = date('Y');
require_once('config.php');
require_once('functions.php');
/* haal alles op uit de database, horende bij de variabelen in de URL */
$query = "SELECT * FROM agenda WHERE MONTH(datum) = '".$_GET['maand']."' AND YEAR(datum)='".$_GET['jaar']."' ORDER BY datum ASC";
$result = mysql_query($query) or die (mysql_error());
$array_dat = array();
$array_eve = array();
$array_oms = array();
while ($row = mysql_fetch_assoc($result))
{
/* stop alle gegevens in arrays, om deze middels de functie Agenda door te geven */
$array_dat[]= $row["datum"];
$array_eve[]= $row["evenement"];
$array_oms[]= $row["omschrijving"];
}
Agenda($array_dat, $array_eve, $array_oms);
function Agenda($datum, $evenement, $omschrijving)
{
?>
<table width="400" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="E7EBEF">
<td width="4"> </td>
<td align="center"><?php get_navigatie(); ?></td>
<td width="4"> </td>
</tr>
</table>
<table>
<tr>
<td height="5"><img src="images/spacer.gif" width="1" height="1"></td>
</tr>
</table>
<table width="400" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="CCCCCC">
<td width="4"> </td>
<td align="center"><?php get_maand_jaar(); ?></td>
<td width="4"> </td>
</tr>
</table>
<table>
<tr>
<td height="5"><img src="images/spacer.gif" width="1" height="1"></td>
</tr>
</table>
<table width="400" border="0" cellpadding="0" cellspacing="0">
<?php
/*
Als er een maand is geset in de URL, 1 optellen bij de maand
mktime(X,X,X,X,0,X) geeft namelijk de laatste dag van de
vorige maand terug. Dit gebeurd echter in een timestamp.
Met strftime deze omzetten naar de dag (dus 28, 29, 30 of 31)
Zo weten we het aantal dagen in die maand
*/
$timestamp = mktime(0,0,0,$_GET['maand']+1,0,$_GET['jaar']);
$aantaldagen = date('t', $timestamp);
for ($int=1;$int<=$aantaldagen;$int++)
{
$color = ($int % 2 == 0) ? "E7EBEF" : "FFFFFF";
echo '<tr bgcolor="#'.$color.'">';
?>
<td width="4"> </td>
<td width="40" valign="top" align="center"><?php get_dag($int); ?></td>
<td width="10" valign="top" align="right"><?php echo $int; ?></td>
<td width="16"> </td>
<td width="326">
<?php for ($int2=0;$int2<count($datum);$int2++)
{
$tmp = $datum[$int2];
if (substr($datum[$int2], -2) == $int)
{
echo $evenement[$int2];
echo "<br>";
}
}
?>
////////// config.php //////////
<?php
mysql_connect ("localhost","inlognaam","password");
mysql_select_db("database naam");
?>
//////////// function.php /////////////
<?php
function get_maand_jaar()
{
if (!isset($_GET['maand']) || empty($_GET['maand']))
{
$maand = date("m") -1;
}
else
{
$maand = $_GET['maand'] -1;
}
if (!isset($_GET['jaar']) || empty($_GET['jaar']))
{
$jaar = date("Y");
}
else
{
$jaar = $_GET['jaar'];
}
$array_maand = array ('januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober',
'november', 'december');
echo $array_maand[(int)$maand] . " ".$jaar;
}
function get_dag($int)
{
if (!isset($_GET['maand']) || empty($_GET['maand']))
{
$maand = date("m");
}
else
{
$maand = $_GET['maand'];
}
if (!isset($_GET['jaar']) || empty($_GET['jaar']))
{
$jaar = date("Y");
}
else
{
$jaar = $_GET['jaar'];
}
$timestamp = mktime(0,0,0,$maand,$int,$jaar);
$weekdag = strftime("%w", $timestamp);
$array_dag = array('Zo','Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za');
echo $array_dag[$weekdag];
}
function get_navigatie()
{
if (!isset($_GET['maand']) || empty($_GET['maand']))
{
$maand = date("m");
}
else
{
$maand = $_GET['maand'];
}
if (!isset($_GET['jaar']) || empty($_GET['jaar']))
{
$jaar = date("Y");
}
else
{
$jaar = $_GET['jaar'];
}
$array_maand = array ('dummy','jan', 'feb', 'mrt', 'apr', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec');
$vorig_jaar = $jaar -1;
$volgend_jaar = $jaar +1;
echo "<a href=agenda.php?maand=$maand&jaar=$vorig_jaar><<</a>
 ";
for ($int=1;$int<count($array_maand);$int++)
{
echo "<a href=agenda.php?maand=$int&jaar=$jaar>$array_maand[$int]</a>
 ";
}
echo " 
<a href=agenda.php?maand=$maand&jaar=$volgend_jaar>>></a>";
}
?>
Reacties
0