Location: PHPKode > projects > WebArchive > phparchive.0.1.82.beta/calendar.php
<?php
/**
 * @version $Id: calendar.php,v 1.3 2003/12/14 01:42:32 freedev Exp $
 * @author Vincenzo D'Amore <hide@address.com>
 * @package wa_tools
*/

/**
 * base common function and constants declaration required
 */
require_once("./wacommon.inc.php");

if ($GLOBALS['WA_LOCATION'] == "IT")
{
	$WA_DateDelim = "/";
	$WA_monthArray = array('Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre');
	$WA_weekdayList  = array('Domenica', 'Luned&igrave;', 'Marted&igrave;', 'Mercoled&igrave;', 'Gioved&igrave;', 'Venerd&igrave;', 'Sabato');
	$WA_weekdayArray = array('Do', 'Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa');
}
else // EN
{
	$WA_DateDelim = "-";
	$WA_monthArray = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	$WA_weekdayList  = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
	$WA_weekdayArray = array('Su','Mo','Tu','We','Th','Fr','Sa');
}

function dayofweek($day,$month,$year)
{

/* Check date for validity */
	if (!checkdate($month,$day,$year))
		return -1;

	$a=(int)((14-$month) / 12);
	$y=$year-$a;
	$m=$month + (12*$a) - 2;

	$retval=($day + $y + (int)($y/4) - (int)($y/100) + (int)($y/400) + (int)((31*$m)/12)) % 7;
	return $retval;
}

//	CheckSession();
PrintHTMLHeader("Calendar", "");

$wa_day = intval(date("d"));
$wa_month = intval(date("m"));
$wa_year = intval(date("Y"));
$keyfield = "";
$keyform = "";

if (isset($_GET["waday"]))
	$wa_day = $_GET["waday"];
if (isset($_GET["wamonth"]))
	$wa_month = $_GET["wamonth"];
if (isset($_GET["wayear"]))
	$wa_year = $_GET["wayear"];

if (isset($_GET["KeyField"]))
	$keyfield = $_GET["KeyField"];
if (isset($_GET["KeyForm"]))
	$keyform = $_GET["KeyForm"];

while (!checkdate($wa_month,$wa_day,$wa_year))
{
	if ($wa_day > 28)
		$wa_day--;
	else
		break;
}

if (!checkdate($wa_month,$wa_day,$wa_year))
{
	$wa_day = date("d");
	$wa_month = (date("m") + 0);
	$wa_year = date("Y");
}


?>
<body class="BodyStandard">
<!-- script type="text/javascript" Language="JavaScript1.2" src="<?php echo $GLOBALS['WA_ABSOLUTE_URI']; ?>javascripts/handleform.js"></script-->
<script type="text/javascript" Language="JavaScript1.2" src="javascripts/handleform.js"></script>
<script type='text/javascript' Language='JavaScript1.2'>
function formDataChange(day, addmonth, addyear)
{
	var curField = '<?php echo $keyfield; ?>';
	var IdForm = '<?php echo $keyform; ?>';
	var today = Date();
	var waday = parseInt(getFormElementByName(document.forms["WACalendar"], "textDay").value);
	var wamonth = parseInt(getFormElementByName(document.forms["WACalendar"], "seleMonth").value);
	var wayear = parseInt(getFormElementByName(document.forms["WACalendar"], "textYear").value);

	if (parseInt(waday) == 0)
		day = today.getDay();
	if (parseInt(wamonth) == 0)
		wamonth = today.getMonth();
	if (parseInt(wayear) == 0)
		wayear = today.getFullYear();

	if (addyear != 0)
		wayear += parseInt(addyear);
	if (addmonth != 0)
		wamonth += parseInt(addmonth);
	if (day != 0)
		waday = day;

	if (wamonth < 1)
	{
		wamonth = 12;
		wayear--;
	}
	else
		if(wamonth > 12)
		{
			wamonth = 1;
			wayear++;
		}

	var newhref = "?waday=" + waday + "&wamonth=" + wamonth + "&wayear=" + wayear;
	newhref += "&KeyField="+curField+"&KeyForm="+IdForm;
	location.href = newhref;
}

function formSetToday()
{
	var curField = '<?php echo $keyfield; ?>';
	var IdForm = '<?php echo $keyform; ?>';
	var newhref = "?KeyField="+curField+"&KeyForm="+IdForm;
	location.href = newhref;
}

function GetBackDate(IdForm, KeyField, curDate)
{
	if ((IdForm) && (KeyField))
	{
		var formname = "formBuild_" + IdForm;
		var pForm = window.opener.document.forms[formname];
		var seleAnno = "seleAnno" + KeyField;
		var seleMese = "seleMese" + KeyField;
		var seleGiorno = "seleGiorno" + KeyField;
		var gg = getFormElementByName(document.forms["WACalendar"], "textDay").value
		var mm = getFormElementByName(document.forms["WACalendar"], "seleMonth").value
		var yy = getFormElementByName(document.forms["WACalendar"], "textYear").value
		if (pForm)
		{
			getFormElementByName(pForm, seleAnno).value = yy;
			getFormElementByName(pForm, seleMese).options[mm].selected = true;
			getFormElementByName(pForm, seleGiorno).options[gg].selected = true;
		}
		else
			alert("Parent Form lost, reload calendar window. Press Ok to close this calendar.");
	}
	else
		alert("Parent Form lost, reload calendar window. Press Ok to close this calendar.");
	window.close();
}

</script>
<form name="WACalendar" method="GET" action="">
<table border="0" cellpadding="0" cellspacing="0" class="FormTableE">
	<tr>
		<td class="ButtonsTable" align="center">
		<?php
			echo "<input type='text' class='Inputs' name='textDay' value='".$wa_day."' size='2' readonly>&nbsp;";
			echo "<select class='Selects' name='seleMonth' onchange='javascript:formDataChange(0,0,0);'>";
			while (list ($chiave, $valore) = each ($WA_monthArray))
			{
				echo "<option value='".($chiave + 1)."'";
				if ($wa_month == ($chiave + 1))
					echo " selected ";
				echo ">".$valore;
			}
			echo "</select>&nbsp;";
			echo "<input type='text' class='Inputs' name='textYear' value='".$wa_year."' size='4' onchange='javascript:formDataChange(0,0,0);'>";
		?>
			&nbsp;<input type="button" class="ButtonsSmall" name="cmdGo" value="<?php echo WA_CMD_GO; ?>" onclick="javascript:formDataChange(0,0,0);">
		</td>
	</tr>
	<tr>
		<td class="ButtonsTable" align="center">
			<input type="button" class="ButtonsSmall" name="cmdYearRight" value="&nbsp;&lt;&lt;&nbsp;" onclick="javascript:formDataChange(0,0,-1);">
			<input type="button" class="ButtonsSmall" name="cmdMonthRight" value="&nbsp;&lt;&nbsp;" onclick="javascript:formDataChange(0,-1,0);">
			<input type="button" class="ButtonsSmall" name="cmdToday" value="<?php echo WA_CMD_TODAY; ?>" onclick="javascript:formSetToday();">
			<input type="button" class="ButtonsSmall" name="cmdYearLeft" value="&nbsp;&gt;&nbsp;" onclick="javascript:formDataChange(0,+1,0);">
			<input type="button" class="ButtonsSmall" name="cmdMonthLeft" value="&nbsp;&gt;&gt;&nbsp;" onclick="javascript:formDataChange(0,0,+1);">
		</td>
	</tr>
	<tr>
		<td>
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td colspan="7">
				<table width="100%" border="0" cellpadding="0" cellspacing="0" class="MenuCellSelectOver">
				<tr>
				<?php

				$nday = dayofweek(1, $wa_month, $wa_year);
				for ($i = 0; $i < 7; $i++)
					echo "<td align='center'>".$WA_weekdayArray[$i]."</td>";
				?>
				</tr>
				</table>
				</tr>
				<tr>
				<?php
				for ($i = 0; $i < $nday; $i++)
					echo "<td align='center'></td>";
				$i = 0;
				while ($i <= 31)
				{
					$i++;
					$nday = dayofweek($i, $wa_month, $wa_year);
					if ( $nday == 0 )
						echo "</tr><tr>";
					elseif (($nday == -1) || ($i > 31))
						break;
					if ($i == $wa_day)
						$class = "MenuCellOver";
					else
						$class = "MenuCell";

//					echo "<td align='center' class='".$class."' onclick='javascript:formDataChange(".$i.",0,0);'>";
					echo "<td align='center' class='".$class."'>";
					echo "<a href='javascript:formDataChange(".$i.",0,0);' class='".$class."'>";
					echo $i;
					echo "</a></td>";
				}
				$i--;
				$nday = dayofweek($i, $wa_month, $wa_year);
				for ($i = $nday; $i < 6; $i ++)
					echo "<td align='center'></td>";
				?>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="ButtonsTable" align="center">
		<?php
//			echo $wa_day.$WA_DateDelim.$WA_monthArray[$wa_month-1].$WA_DateDelim.$wa_year;
		?>
			&nbsp;<input type="button" class="ButtonsSmall" name="cmdAttach" value="<?php echo WA_CMD_UPDATE; ?>" onclick="javascript:GetBackDate(<?php echo "'".$keyform."', '".$keyfield."'" ?> )">
		</td>
	</tr>
</table>
</form>
</body>
</html>
Return current item: WebArchive