Hi
I want to create a simple calendar on Smarty. I attached an image on how it looks so far.
Here is my code calendar.php file:
<?php
require("libs/Smarty.class.php");
$smarty = new Smarty();
$date = "1/01/2013"; //January 01, 2013
$week_days = array("Sun"=>1, "Mon"=>2, "Tue"=>3, "Wed"=>4, "Thu"=>5, "Fri"=>6, "Sat"=>7);
$total_day_of_month = get_total_day($date);
$starting_day = $week_days[Date("D",strtotime($date))] - 1;
foreach (array_keys($week_days) as $day)
$days[] = $day;
for ($i=0; $i<$starting_day; $i++)
$days[] = " ";
for ($i=1; $i< ($total_day_of_month+1); $i++)
$days[] = $i;
$smarty->assign("title","2013");
$smarty->assign("special_days", $days);
$smarty->assign("TABLE", array ("title" =>"January"));
$smarty->display("calendar.tpl");
$output = $smarty->fetch('calendar.tpl');
function get_total_day($date){
$time_stamp = strtotime($date);
$month_ar = explode("/", $date);
$month = $month_ar[0];
$year = Date("Y",$time_stamp);
for ($i=28; $i<33; $i++){
if (!checkdate($month, $i, $year)){
return ($i - 1);
}}}
?>
Here is my calendar.tpl file:
<!DOCTYPE html>
<html>
<head>
<title>Calendar</title>
</head>
<body>
<center><h1>{$title}</h1></center>
<table>
<tr>
<td>
<center><b>{$TABLE.title}</b></center>
{html_table loop=$special_days cols=7}
</td>
</tr>
</table>
</body>
</html>
The script works for 1 month. In order to make adjustment I have to change $date = "1/01/2013"; //January 01, 2013
to a different month or year.
So I add or modify the code a little so instead of having 1 month I am trying to create 12 months kinda like a calendar for the whole year.
This is what I done so far:
This is my calendar.php file:
<?php
require("libs/Smarty.class.php");
$smarty = new Smarty();
$date = "1/01/2013"; //January 01, 2013
$months = array("January"=>1, "February "=>2, "March"=>3, "April"=>4, "May"=>5, "June"=>6, "July"=>7, "August"=>8, "September"=>9, "October"=>10, "November"=>11, "December"=>12);
$week_days = array("Sun"=>1, "Mon"=>2, "Tue"=>3, "Wed"=>4, "Thu"=>5, "Fri"=>6, "Sat"=>7);
$total_day_of_month = get_total_day($date);
$starting_day = $week_days[Date("D",strtotime($date))] - 1;
foreach (array_keys($week_days) as $day)
$days[] = $day;
for ($i=0; $i<$starting_day; $i++)
$days[] = " ";
for ($i=1; $i< ($total_day_of_month+1); $i++)
$days[] = $i;
$smarty->assign("title","2013");
$smarty->assign("months", $months);
$smarty->assign("special_days", $days);
$smarty->assign("TABLE", array ("title" => $months));
$smarty->display("calendar.tpl");
$output = $smarty->fetch('calendar.tpl');
function get_total_day($date)
{
$time_stamp = strtotime($date);
$month_ar = explode("/", $date);
$month = $month_ar[0];
$year = Date("Y",$time_stamp);
for ($i=28; $i<33; $i++)
{
if (!checkdate($month, $i, $year)){
return ($i - 1);
}}}
?>
My calendar.tpl file is still the same:
<!DOCTYPE html>
<html>
<head>
<title>Calendar</title>
</head>
<body>
<center><h1>{$title}</h1></center>
<table>
<tr>
<td>
<center><b>{$TABLE.title}</b></center>
{html_table loop=$special_days cols=7}
</td>
</tr>
</table>
</body>
</html>
Any Suggestions and explanation will help. I appreciate it. Thanks!