<?php

// function tdit($action)
//  returns a string with This Day in Tech Quote(s).
//  Specify 'all' or 'random' as the $action parameter to print all entries for
//  today, or just a single random one repectively.

function tdit($action) {
date_default_timezone_set('Europe/London');

$month=date("m");
$day=date("d");


$results='<ul class="tdit_list">';
if ($db = new SQLite3('tdit.db')) {
	$res=$db->query("SELECT * FROM 'tdit' WHERE day = \"$day\" AND month = \"$month\"");
$i=0;

$r=array();

	while ($row = $res->fetchArray()) {
		array_push($r,"<li>On this day in ".$row['year']." - ".htmlentities($row['event']."\n", ENT_IGNORE,'UTF-8').'</li>');
  }

 if ($action!="random") {

    foreach($r as $ln) $results.=$ln;
    } else  {
		$rnd=rand(0,count($r)-1);
		$results=$r[$rnd];
 }

 return($results."</ul>");
 }
$db->close();
}


// function tditdm($action,$day,$month)
//  returns a string with This Day in Tech Quote(s) for the specified $day and $month
//  Specify 'all' or 'random' as the $action parameter to print all entries for
//  today, or just a single random one repectively.


function tdit_dm($action,$day,$month) {
date_default_timezone_set('Europe/London');

$results='<ul class="tdit_list">';
if ($db = new SQLite3('tdit.db')) {
	$res=$db->query("SELECT * FROM 'tdit' WHERE day = \"$day\" AND month = \"$month\"");
$i=0;

$r=array();

	while ($row = $res->fetchArray()) {
		array_push($r,"<li>On this day in ".$row['year']." - ".htmlentities($row['event']."\n", ENT_IGNORE,'UTF-8').'</li>');
  }

 if ($action!="random") {

    foreach($r as $ln) $results.=$ln;
    } else  {
		$rnd=rand(0,count($r)-1);
		$results=$r[$rnd];
 }

 return($results."</ul>");
 }
$db->close();
}
?>