<?php
/*
* Armin Randjbar-Daemi <www.omnistream.co.uk>
* armin.randjbar AT gmail.com
*
* GNU General Public License <opensource.org/licenses/gpl-license.html>
* Demo: http://www.omnistream.co.uk/calendar/
* last modified: march 2008 <ver 1.0>
*/
//include farsinum($str); & farsimonth($jmonth); Functions
require_once ('farsi.function.php');
//GregorianToJalali & JalaliToGregorian Converter
require_once ('Converter.Class.php');
class Calendar extends Converter {
//we show it on Calendar's head
var $shamsi_month_year;
//show today on calendar
var $today;
//we need 2 variables to create the month
var $month_first_day;
var $month_total_days;
//We get Gregorian date from server, and find "first day" & "total days" of Jalali month
//Also returns an array, to create "prev" & "next" links, and show Today.
function Calendar_ThisMonth($year,$month,$day)
{
list($jyear,$jmonth,$jday) = Converter::GregorianToJalali($year,$month,$day);
$this->shamsi_month_year = farsimonth($jmonth)." ".farsinum($jyear);
$this->month_first_day = $this->find_first_day($jmonth,$jyear);
$this->month_total_days = $this->find_total_days($jmonth,$jyear);
$this->today = $jyear."-".$jmonth."-".$jday;
return array($jyear,$jmonth);
}
//We get Jalali "Year" & "Month" from $_GET[] and find "first day" & "total days" of Jalali month.
function Calendar_OtherMonth($jyear,$jmonth)
{
$this->shamsi_month_year = farsimonth($jmonth)." ".farsinum($jyear);
$this->month_first_day = $this->find_first_day($jmonth,$jyear);
$this->month_total_days = $this->find_total_days($jmonth,$jyear);
$this->today = $this->find_today();
}
function find_first_day($jmonth,$jyear)
{
list($gyear,$gmonth,$gday) = Converter::JalaliToGregorian($jyear,$jmonth,'1');
return date('w', mktime(0, 0, 0, $gmonth, $gday, $gyear));
}
function find_total_days($jmonth,$jyear)
{
if($jmonth!=12) {
return $this->j_days_in_month[$jmonth-1];
} else {
//I don't like this part of the code :|
$temp1 = Converter::JalaliToGregorian($jyear,'12','29');
$temp2 = Converter::JalaliToGregorian($jyear+1,'1','1');
if ($temp2[2]-$temp1[2]==2) return 30;
else return 29;
}
}
function find_today()
{
$gyear = date('Y');
$gmonth = date('n');
$gday = date('j');
list($jyear,$jmonth,$jday) = Converter::GregorianToJalali($gyear,$gmonth,$gday);
return $jyear."-".$jmonth."-".$jday;
}
}//Class END
?>