<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
	/*
 * http://ir.php.net/date $tomorrow = mktime(0, 0, 0, date("m") , date("d")+1, date("Y")); $lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y")); $nextyear = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1); $today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm $today = date("m.d.y"); // 03.10.01 $today = date("j, n, Y"); // 10, 3, 2001 $today = date("Ymd"); // 20010310 $today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01 $today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day. $today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001 $today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month $today = date("H:i:s"); ----------------------- d	Day of the month, 2 digits with leading zeros	01 to 31 D	A textual representation of a day, three letters	Mon through Sun j	Day of the month without leading zeros	1 to 31 l (lowercase 'L')	A full textual representation of the day of the week	Sunday through Saturday N	ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)	1 (for Monday) through 7 (for Sunday) S	English ordinal suffix for the day of the month, 2 characters	st, nd, rd or th. Works well with j w	Numeric representation of the day of the week	0 (for Sunday) through 6 (for Saturday) z	The day of the year (starting from 0)	0 through 365 Week	---	--- W	ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)	Example: 42 (the 42nd week in the year) Month	---	--- F	A full textual representation of a month, such as January or March	January through December m	Numeric representation of a month, with leading zeros	01 through 12 M	A short textual representation of a month, three letters	Jan through Dec n	Numeric representation of a month, without leading zeros	1 through 12 t	Number of days in the given month	28 through 31 Year	---	--- L	Whether it's a leap year	1 if it is a leap year, 0 otherwise. o	ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)	Examples: 1999 or 2003 Y	A full numeric representation of a year, 4 digits	Examples: 1999 or 2003 y	A two digit representation of a year	Examples: 99 or 03 Time	---	--- a	Lowercase Ante meridiem and Post meridiem	am or pm A	Uppercase Ante meridiem and Post meridiem	AM or PM B	Swatch Internet time	000 through 999 g	12-hour format of an hour without leading zeros	1 through 12 G	24-hour format of an hour without leading zeros	0 through 23 h	12-hour format of an hour with leading zeros	01 through 12 H	24-hour format of an hour with leading zeros	00 through 23 i	Minutes with leading zeros	00 to 59 s	Seconds, with leading zeros	00 through 59 u	Microseconds (added in PHP 5.2.2)	Example: 54321 Timezone	---	--- e	Timezone identifier (added in PHP 5.1.0)	Examples: UTC, GMT, Atlantic/Azores I (capital i)	Whether or not the date is in daylight saving time	1 if Daylight Saving Time, 0 otherwise. O	Difference to Greenwich time (GMT) in hours	Example: +0200 P	Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)	Example: +02:00 T	Timezone abbreviation	Examples: EST, MDT ... Z	Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.	-43200 through 50400 ----------------------- Jalali Date function by Milad Rastian (miladmovie AT yahoo DOT com) //The main function which convert Gregorian to Jalali calendars is: // Copyright (C) 2000 Roozbeh Pournader and Mohammad Toossi //you can see complete note of those function in down of the page AND JALAI DATE FUNCTION this function is simillar than date function in PHP you can find more about it in http://jdf.farsiprojects.com Copyright (C)2003 FARSI PROJECTS GROUP
 */
class Persiandate {
	function jdate($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') {
		$T_sec = 0; /* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */
		
		if ($time_zone != 'local')
			date_default_timezone_set ( ($time_zone == '') ? 'Asia/Tehran' : $time_zone );
		$ts = $T_sec + (($timestamp == '' or $timestamp == 'now') ? time () : $this->tr_num ( $timestamp ));
		$date = explode ( '_', date ( 'H_i_j_n_O_P_s_w_Y', $ts ) );
		list ( $j_y, $j_m, $j_d ) = $this->gregorian_to_jalali ( $date [8], $date [3], $date [2] );
		$doy = ($j_m < 7) ? (($j_m - 1) * 31) + $j_d - 1 : (($j_m - 7) * 30) + $j_d + 185;
		$kab = ($j_y % 33 % 4 - 1 == ( int ) ($j_y % 33 * .05)) ? 1 : 0;
		$sl = strlen ( $format );
		$out = '';
		for($i = 0; $i < $sl; $i ++) {
			$sub = substr ( $format, $i, 1 );
			if ($sub == '\\') {
				$out .= substr ( $format, ++ $i, 1 );
				continue;
			}
			switch ($sub) {
				
				case 'E' :
				case 'R' :
				case 'x' :
				case 'X' :
					$out .= 'http://jdf.scr.ir';
					break;
				
				case 'B' :
				case 'e' :
				case 'g' :
				case 'G' :
				case 'h' :
				case 'I' :
				case 'T' :
				case 'u' :
				case 'Z' :
					$out .= date ( $sub, $ts );
					break;
				
				case 'a' :
					$out .= ($date [0] < 12) ? 'ق.ظ' : 'ب.ظ';
					break;
				
				case 'A' :
					$out .= ($date [0] < 12) ? 'قبل از ظهر' : 'بعد از ظهر';
					break;
				
				case 'b' :
					$out .= ( int ) ($j_m / 3.1) + 1;
					break;
				
				case 'c' :
					$out .= $j_y . '/' . $j_m . '/' . $j_d . ' ،' . $date [0] . ':' . $date [1] . ':' . $date [6] . ' ' . $date [5];
					break;
				
				case 'C' :
					$out .= ( int ) (($j_y + 99) / 100);
					break;
				
				case 'd' :
					$out .= ($j_d < 10) ? '0' . $j_d : $j_d;
					break;
				
				case 'D' :
					$out .= $this->jdate_words ( array (
							'kh' => $date [7] 
					), ' ' );
					break;
				
				case 'f' :
					$out .= $this->jdate_words ( array (
							'ff' => $j_m 
					), ' ' );
					break;
				
				case 'F' :
					$out .= $this->jdate_words ( array (
							'mm' => $j_m 
					), ' ' );
					break;
				
				case 'H' :
					$out .= $date [0];
					break;
				
				case 'i' :
					$out .= $date [1];
					break;
				
				case 'j' :
					$out .= $j_d;
					break;
				
				case 'J' :
					$out .= $this->jdate_words ( array (
							'rr' => $j_d 
					), ' ' );
					break;
				
				case 'k' :
					$out .= $this->tr_num ( 100 - ( int ) ($doy / ($kab + 365) * 1000) / 10, $tr_num );
					break;
				
				case 'K' :
					$out .= $this->tr_num ( ( int ) ($doy / ($kab + 365) * 1000) / 10, $tr_num );
					break;
				
				case 'l' :
					$out .= $this->jdate_words ( array (
							'rh' => $date [7] 
					), ' ' );
					break;
				
				case 'L' :
					$out .= $kab;
					break;
				
				case 'm' :
					$out .= ($j_m > 9) ? $j_m : '0' . $j_m;
					break;
				
				case 'M' :
					$out .= $this->jdate_words ( array (
							'km' => $j_m 
					), ' ' );
					break;
				
				case 'n' :
					$out .= $j_m;
					break;
				
				case 'N' :
					$out .= $date [7] + 1;
					break;
				
				case 'o' :
					$jdw = ($date [7] == 6) ? 0 : $date [7] + 1;
					$dny = 364 + $kab - $doy;
					$out .= ($jdw > ($doy + 3) and $doy < 3) ? $j_y - 1 : (((3 - $dny) > $jdw and $dny < 3) ? $j_y + 1 : $j_y);
					break;
				
				case 'O' :
					$out .= $date [4];
					break;
				
				case 'p' :
					$out .= $this->jdate_words ( array (
							'mb' => $j_m 
					), ' ' );
					break;
				
				case 'P' :
					$out .= $date [5];
					break;
				
				case 'q' :
					$out .= $this->jdate_words ( array (
							'sh' => $j_y 
					), ' ' );
					break;
				
				case 'Q' :
					$out .= $kab + 364 - $doy;
					break;
				
				case 'r' :
					$key = $this->jdate_words ( array (
							'rh' => $date [7],
							'mm' => $j_m 
					) );
					$out .= $date [0] . ':' . $date [1] . ':' . $date [6] . ' ' . $date [4] . ' ' . $key ['rh'] . '، ' . $j_d . ' ' . $key ['mm'] . ' ' . $j_y;
					break;
				
				case 's' :
					$out .= $date [6];
					break;
				
				case 'S' :
					$out .= 'ام';
					break;
				
				case 't' :
					$out .= ($j_m != 12) ? (31 - ( int ) ($j_m / 6.5)) : ($kab + 29);
					break;
				
				case 'U' :
					$out .= $ts;
					break;
				
				case 'v' :
					$out .= $this->jdate_words ( array (
							'ss' => substr ( $j_y, 2, 2 ) 
					), ' ' );
					break;
				
				case 'V' :
					$out .= $this->jdate_words ( array (
							'ss' => $j_y 
					), ' ' );
					break;
				
				case 'w' :
					$out .= ($date [7] == 6) ? 0 : $date [7] + 1;
					break;
				
				case 'W' :
					$avs = (($date [7] == 6) ? 0 : $date [7] + 1) - ($doy % 7);
					if ($avs < 0)
						$avs += 7;
					$num = ( int ) (($doy + $avs) / 7);
					if ($avs < 4) {
						$num ++;
					} elseif ($num < 1) {
						$num = ($avs == 4 or $avs == (($j_y % 33 % 4 - 2 == ( int ) ($j_y % 33 * .05)) ? 5 : 4)) ? 53 : 52;
					}
					$aks = $avs + $kab;
					if ($aks == 7)
						$aks = 0;
					$out .= (($kab + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0' . $num : $num);
					break;
				
				case 'y' :
					$out .= substr ( $j_y, 2, 2 );
					break;
				
				case 'Y' :
					$out .= $j_y;
					break;
				
				case 'z' :
					$out .= $doy;
					break;
				
				default :
					$out .= $sub;
			}
		}
		return ($tr_num != 'en') ? $this->tr_num ( $out, 'fa', '.' ) : $out;
	}
	
	/* F */
	function jstrftime($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') {
		$T_sec = 0; /* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */
		
		if ($time_zone != 'local')
			date_default_timezone_set ( ($time_zone == '') ? 'Asia/Tehran' : $time_zone );
		$ts = $T_sec + (($timestamp == '' or $timestamp == 'now') ? time () : $this->tr_num ( $timestamp ));
		$date = explode ( '_', date ( 'h_H_i_j_n_s_w_Y', $ts ) );
		list ( $j_y, $j_m, $j_d ) = $this->gregorian_to_jalali ( $date [7], $date [4], $date [3] );
		$doy = ($j_m < 7) ? (($j_m - 1) * 31) + $j_d - 1 : (($j_m - 7) * 30) + $j_d + 185;
		$kab = ($j_y % 33 % 4 - 1 == ( int ) ($j_y % 33 * .05)) ? 1 : 0;
		$sl = strlen ( $format );
		$out = '';
		for($i = 0; $i < $sl; $i ++) {
			$sub = substr ( $format, $i, 1 );
			if ($sub == '%') {
				$sub = substr ( $format, ++ $i, 1 );
			} else {
				$out .= $sub;
				continue;
			}
			switch ($sub) {
				
				/* Day */
				case 'a' :
					$out .= $this->jdate_words ( array (
							'kh' => $date [6] 
					), ' ' );
					break;
				
				case 'A' :
					$out .= $this->jdate_words ( array (
							'rh' => $date [6] 
					), ' ' );
					break;
				
				case 'd' :
					$out .= ($j_d < 10) ? '0' . $j_d : $j_d;
					break;
				
				case 'e' :
					$out .= ($j_d < 10) ? ' ' . $j_d : $j_d;
					break;
				
				case 'j' :
					$out .= str_pad ( $doy + 1, 3, 0, STR_PAD_LEFT );
					break;
				
				case 'u' :
					$out .= $date [6] + 1;
					break;
				
				case 'w' :
					$out .= ($date [6] == 6) ? 0 : $date [6] + 1;
					break;
				
				/* Week */
				case 'U' :
					$avs = (($date [6] < 5) ? $date [6] + 2 : $date [6] - 5) - ($doy % 7);
					if ($avs < 0)
						$avs += 7;
					$num = ( int ) (($doy + $avs) / 7) + 1;
					if ($avs > 3 or $avs == 1)
						$num --;
					$out .= ($num < 10) ? '0' . $num : $num;
					break;
				
				case 'V' :
					$avs = (($date [6] == 6) ? 0 : $date [6] + 1) - ($doy % 7);
					if ($avs < 0)
						$avs += 7;
					$num = ( int ) (($doy + $avs) / 7);
					if ($avs < 4) {
						$num ++;
					} elseif ($num < 1) {
						$num = ($avs == 4 or $avs == (($j_y % 33 % 4 - 2 == ( int ) ($j_y % 33 * .05)) ? 5 : 4)) ? 53 : 52;
					}
					$aks = $avs + $kab;
					if ($aks == 7)
						$aks = 0;
					$out .= (($kab + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0' . $num : $num);
					break;
				
				case 'W' :
					$avs = (($date [6] == 6) ? 0 : $date [6] + 1) - ($doy % 7);
					if ($avs < 0)
						$avs += 7;
					$num = ( int ) (($doy + $avs) / 7) + 1;
					if ($avs > 3)
						$num --;
					$out .= ($num < 10) ? '0' . $num : $num;
					break;
				
				/* Month */
				case 'b' :
				case 'h' :
					$out .= $this->jdate_words ( array (
							'km' => $j_m 
					), ' ' );
					break;
				
				case 'B' :
					$out .= $this->jdate_words ( array (
							'mm' => $j_m 
					), ' ' );
					break;
				
				case 'm' :
					$out .= ($j_m > 9) ? $j_m : '0' . $j_m;
					break;
				
				/* Year */
				case 'C' :
					$out .= substr ( $j_y, 0, 2 );
					break;
				
				case 'g' :
					$jdw = ($date [6] == 6) ? 0 : $date [6] + 1;
					$dny = 364 + $kab - $doy;
					$out .= substr ( ($jdw > ($doy + 3) and $doy < 3) ? $j_y - 1 : (((3 - $dny) > $jdw and $dny < 3) ? $j_y + 1 : $j_y), 2, 2 );
					break;
				
				case 'G' :
					$jdw = ($date [6] == 6) ? 0 : $date [6] + 1;
					$dny = 364 + $kab - $doy;
					$out .= ($jdw > ($doy + 3) and $doy < 3) ? $j_y - 1 : (((3 - $dny) > $jdw and $dny < 3) ? $j_y + 1 : $j_y);
					break;
				
				case 'y' :
					$out .= substr ( $j_y, 2, 2 );
					break;
				
				case 'Y' :
					$out .= $j_y;
					break;
				
				/* Time */
				case 'H' :
					$out .= $date [1];
					break;
				
				case 'I' :
					$out .= $date [0];
					break;
				
				case 'l' :
					$out .= ($date [0] > 9) ? $date [0] : ' ' . ( int ) $date [0];
					break;
				
				case 'M' :
					$out .= $date [2];
					break;
				
				case 'p' :
					$out .= ($date [1] < 12) ? 'قبل از ظهر' : 'بعد از ظهر';
					break;
				
				case 'P' :
					$out .= ($date [1] < 12) ? 'ق.ظ' : 'ب.ظ';
					break;
				
				case 'r' :
					$out .= $date [0] . ':' . $date [2] . ':' . $date [5] . ' ' . (($date [1] < 12) ? 'قبل از ظهر' : 'بعد از ظهر');
					break;
				
				case 'R' :
					$out .= $date [1] . ':' . $date [2];
					break;
				
				case 'S' :
					$out .= $date [5];
					break;
				
				case 'T' :
					$out .= $date [1] . ':' . $date [2] . ':' . $date [5];
					break;
				
				case 'X' :
					$out .= $date [0] . ':' . $date [2] . ':' . $date [5];
					break;
				
				case 'z' :
					$out .= date ( 'O', $ts );
					break;
				
				case 'Z' :
					$out .= date ( 'T', $ts );
					break;
				
				/* Time and Date Stamps */
				case 'c' :
					$key = $this->jdate_words ( array (
							'rh' => $date [6],
							'mm' => $j_m 
					) );
					$out .= $date [1] . ':' . $date [2] . ':' . $date [5] . ' ' . date ( 'P', $ts ) . ' ' . $key ['rh'] . '، ' . $j_d . ' ' . $key ['mm'] . ' ' . $j_y;
					break;
				
				case 'D' :
					$out .= substr ( $j_y, 2, 2 ) . '/' . (($j_m > 9) ? $j_m : '0' . $j_m) . '/' . (($j_d < 10) ? '0' . $j_d : $j_d);
					break;
				
				case 'F' :
					$out .= $j_y . '-' . (($j_m > 9) ? $j_m : '0' . $j_m) . '-' . (($j_d < 10) ? '0' . $j_d : $j_d);
					break;
				
				case 's' :
					$out .= $ts;
					break;
				
				case 'x' :
					$out .= substr ( $j_y, 2, 2 ) . '/' . (($j_m > 9) ? $j_m : '0' . $j_m) . '/' . (($j_d < 10) ? '0' . $j_d : $j_d);
					break;
				
				/* Miscellaneous */
				case 'n' :
					$out .= "\n";
					break;
				
				case 't' :
					$out .= "\t";
					break;
				
				case '%' :
					$out .= '%';
					break;
				
				default :
					$out .= $sub;
			}
		}
		return ($tr_num != 'en') ? $this->tr_num ( $out, 'fa', '.' ) : $out;
	}
	
	/* F */
	function jmktime($h = '', $m = '', $s = '', $jm = '', $jd = '', $jy = '', $is_dst = -1) {
		$h = $this->tr_num ( $h );
		$m = $this->tr_num ( $m );
		$s = $this->tr_num ( $s );
		$jm = $this->tr_num ( $jm );
		$jd = $this->tr_num ( $jd );
		$jy = $this->tr_num ( $jy );
		if ($h == '' and $m == '' and $s == '' and $jm == '' and $jd == '' and $jy == '') {
			return mktime ();
		} else {
			list ( $year, $month, $day ) = $this->jalali_to_gregorian ( $jy, $jm, $jd );
			return mktime ( $h, $m, $s, $month, $day, $year, $is_dst );
		}
	}
	
	/* F */
	function jgetdate($timestamp = '', $none = '', $tz = 'Asia/Tehran', $tn = 'en') {
		$ts = ($timestamp == '') ? time () : $this->tr_num ( $timestamp );
		$jdate = explode ( '_', $this->jdate ( 'F_G_i_j_l_n_s_w_Y_z', $ts, '', $tz, $tn ) );
		return array (
				'seconds' => $this->tr_num ( ( int ) $this->tr_num ( $jdate [6] ), $tn ),
				'minutes' => $this->tr_num ( ( int ) $this->tr_num ( $jdate [2] ), $tn ),
				'hours' => $jdate [1],
				'mday' => $jdate [3],
				'wday' => $jdate [7],
				'mon' => $jdate [5],
				'year' => $jdate [8],
				'yday' => $jdate [9],
				'weekday' => $jdate [4],
				'month' => $jdate [0],
				0 => $this->tr_num ( $ts, $tn ) 
		);
	}
	
	/* F */
	function jcheckdate($jm, $jd, $jy) {
		$jm = $this->tr_num ( $jm );
		$jd = $this->tr_num ( $jd );
		$jy = $this->tr_num ( $jy );
		$l_d = ($jm == 12) ? (($jy % 33 % 4 - 1 == ( int ) ($jy % 33 * .05)) ? 30 : 29) : 31 - ( int ) ($jm / 6.5);
		return ($jm > 0 and $jd > 0 and $jy > 0 and $jm < 13 and $jd <= $l_d) ? true : false;
	}
	
	/* F */
	function tr_num($str, $mod = 'en', $mf = '٫') {
		$num_a = array (
				'0',
				'1',
				'2',
				'3',
				'4',
				'5',
				'6',
				'7',
				'8',
				'9',
				'.' 
		);
		$key_a = array (
				'۰',
				'۱',
				'۲',
				'۳',
				'۴',
				'۵',
				'۶',
				'۷',
				'۸',
				'۹',
				$mf 
		);
		return ($mod == 'fa') ? str_replace ( $num_a, $key_a, $str ) : str_replace ( $key_a, $num_a, $str );
	}
	
	/* F */
	function jdate_words($array, $mod = '') {
		foreach ( $array as $type => $num ) {
			$num = ( int ) $this->tr_num ( $num );
			switch ($type) {
				
				case 'ss' :
					$sl = strlen ( $num );
					$xy3 = substr ( $num, 2 - $sl, 1 );
					$h3 = $h34 = $h4 = '';
					if ($xy3 == 1) {
						$p34 = '';
						$k34 = array (
								'ده',
								'یازده',
								'دوازده',
								'سیزده',
								'چهارده',
								'پانزده',
								'شانزده',
								'هفده',
								'هجده',
								'نوزده' 
						);
						$h34 = $k34 [substr ( $num, 2 - $sl, 2 ) - 10];
					} else {
						$xy4 = substr ( $num, 3 - $sl, 1 );
						$p34 = ($xy3 == 0 or $xy4 == 0) ? '' : ' و ';
						$k3 = array (
								'',
								'',
								'بیست',
								'سی',
								'چهل',
								'پنجاه',
								'شصت',
								'هفتاد',
								'هشتاد',
								'نود' 
						);
						$h3 = $k3 [$xy3];
						$k4 = array (
								'',
								'یک',
								'دو',
								'سه',
								'چهار',
								'پنج',
								'شش',
								'هفت',
								'هشت',
								'نه' 
						);
						$h4 = $k4 [$xy4];
					}
					$array [$type] = (($num > 99) ? str_ireplace ( array (
							'12',
							'13',
							'14',
							'19',
							'20' 
					), array (
							'هزار و دویست',
							'هزار و سیصد',
							'هزار و چهارصد',
							'هزار و نهصد',
							'دوهزار' 
					), substr ( $num, 0, 2 ) ) . ((substr ( $num, 2, 2 ) == '00') ? '' : ' و ') : '') . $h3 . $p34 . $h34 . $h4;
					break;
				
				case 'mm' :
					$key = array (
							'فروردین',
							'اردیبهشت',
							'خرداد',
							'تیر',
							'مرداد',
							'شهریور',
							'مهر',
							'آبان',
							'آذر',
							'دی',
							'بهمن',
							'اسفند' 
					);
					$array [$type] = $key [$num - 1];
					break;
				
				case 'rr' :
					$key = array (
							'یک',
							'دو',
							'سه',
							'چهار',
							'پنج',
							'شش',
							'هفت',
							'هشت',
							'نه',
							'ده',
							'یازده',
							'دوازده',
							'سیزده',
							'چهارده',
							'پانزده',
							'شانزده',
							'هفده',
							'هجده',
							'نوزده',
							'بیست',
							'بیست و یک',
							'بیست و دو',
							'بیست و سه',
							'بیست و چهار',
							'بیست و پنج',
							'بیست و شش',
							'بیست و هفت',
							'بیست و هشت',
							'بیست و نه',
							'سی',
							'سی و یک' 
					);
					$array [$type] = $key [$num - 1];
					break;
				
				case 'rh' :
					$key = array (
							'یکشنبه',
							'دوشنبه',
							'سه شنبه',
							'چهارشنبه',
							'پنجشنبه',
							'جمعه',
							'شنبه' 
					);
					$array [$type] = $key [$num];
					break;
				
				case 'sh' :
					$key = array (
							'مار',
							'اسب',
							'گوسفند',
							'میمون',
							'مرغ',
							'سگ',
							'خوک',
							'موش',
							'گاو',
							'پلنگ',
							'خرگوش',
							'نهنگ' 
					);
					$array [$type] = $key [$num % 12];
					break;
				
				case 'mb' :
					$key = array (
							'حمل',
							'ثور',
							'جوزا',
							'سرطان',
							'اسد',
							'سنبله',
							'میزان',
							'عقرب',
							'قوس',
							'جدی',
							'دلو',
							'حوت' 
					);
					$array [$type] = $key [$num - 1];
					break;
				
				case 'ff' :
					$key = array (
							'بهار',
							'تابستان',
							'پاییز',
							'زمستان' 
					);
					$array [$type] = $key [( int ) ($num / 3.1)];
					break;
				
				case 'km' :
					$key = array (
							'فر',
							'ار',
							'خر',
							'تی‍',
							'مر',
							'شه‍',
							'مه‍',
							'آب‍',
							'آذ',
							'دی',
							'به‍',
							'اس‍' 
					);
					$array [$type] = $key [$num - 1];
					break;
				
				case 'kh' :
					$key = array (
							'ی',
							'د',
							'س',
							'چ',
							'پ',
							'ج',
							'ش' 
					);
					$array [$type] = $key [$num];
					break;
				
				default :
					$array [$type] = $num;
			}
		}
		return ($mod == '') ? $array : implode ( $mod, $array );
	}
	
	/**
	 * Convertor from and to Gregorian and Jalali (Hijri_Shamsi,Solar) Functions
	 * Copyright(C)2011, Reza Gholampanahi [ http://jdf.scr.ir/jdf ] version 2.50
	 */
	
	/* F */
	function gregorian_to_jalali($g_y, $g_m, $g_d, $mod = '') {
		$g_y = $this->tr_num ( $g_y );
		$g_m = $this->tr_num ( $g_m );
		$g_d = $this->tr_num ( $g_d ); /* <= :اين سطر ، جزء تابع اصلي نيست */
		$d_4 = $g_y % 4;
		$g_a = array (
				0,
				0,
				31,
				59,
				90,
				120,
				151,
				181,
				212,
				243,
				273,
				304,
				334 
		);
		$doy_g = $g_a [( int ) $g_m] + $g_d;
		if ($d_4 == 0 and $g_m > 2)
			$doy_g ++;
		$d_33 = ( int ) ((($g_y - 16) % 132) * .0305);
		$a = ($d_33 == 3 or $d_33 < ($d_4 - 1) or $d_4 == 0) ? 286 : 287;
		$b = (($d_33 == 1 or $d_33 == 2) and ($d_33 == $d_4 or $d_4 == 1)) ? 78 : (($d_33 == 3 and $d_4 == 0) ? 80 : 79);
		if (( int ) (($g_y - 10) / 63) == 30) {
			$a --;
			$b ++;
		}
		if ($doy_g > $b) {
			$jy = $g_y - 621;
			$doy_j = $doy_g - $b;
		} else {
			$jy = $g_y - 622;
			$doy_j = $doy_g + $a;
		}
		if ($doy_j < 187) {
			$jm = ( int ) (($doy_j - 1) / 31);
			$jd = $doy_j - (31 * $jm ++);
		} else {
			$jm = ( int ) (($doy_j - 187) / 30);
			$jd = $doy_j - 186 - ($jm * 30);
			$jm += 7;
		}
		return ($mod == '') ? array (
				$jy,
				$jm,
				$jd 
		) : $jy . $mod . $jm . $mod . $jd;
	}
	
	/* F */
	function jalali_to_gregorian($j_y, $j_m, $j_d, $mod = '') {
		$j_y = $this->tr_num ( $j_y );
		$j_m = $this->tr_num ( $j_m );
		$j_d = $this->tr_num ( $j_d ); /* <= :اين سطر ، جزء تابع اصلي نيست */
		$d_4 = ($j_y + 1) % 4;
		$doy_j = ($j_m < 7) ? (($j_m - 1) * 31) + $j_d : (($j_m - 7) * 30) + $j_d + 186;
		$d_33 = ( int ) ((($j_y - 55) % 132) * .0305);
		$a = ($d_33 != 3 and $d_4 <= $d_33) ? 287 : 286;
		$b = (($d_33 == 1 or $d_33 == 2) and ($d_33 == $d_4 or $d_4 == 1)) ? 78 : (($d_33 == 3 and $d_4 == 0) ? 80 : 79);
		if (( int ) (($j_y - 19) / 63) == 20) {
			$a --;
			$b ++;
		}
		if ($doy_j <= $a) {
			$gy = $j_y + 621;
			$gd = $doy_j + $b;
		} else {
			$gy = $j_y + 622;
			$gd = $doy_j - $a;
		}
		foreach ( array (
				0,
				31,
				($gy % 4 == 0) ? 29 : 28,
				31,
				30,
				31,
				30,
				31,
				31,
				30,
				31,
				30,
				31 
		) as $gm => $v ) {
			if ($gd <= $v)
				break;
			$gd -= $v;
		}
		return ($mod == '') ? array (
				$gy,
				$gm,
				$gd 
		) : $gy . $mod . $gm . $mod . $gd;
	}
	
	/* [ jdf.php ] version 2.55 ?> Download new version from [ http://jdf.scr.ir ] */
}
?>