note 43547 added to ref.calendar
| From: | pmezaFROMrednaranjaIScom at rn2 dot php dot net | Date: | Fri, 25 Jun 2004 01:02:14 +0000 |
| Subject: | note 43547 added to ref.calendar | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-71628@lists.php.net to get a copy of this message | ||
I had a similar need as wasiq911 but I need a code snipet to easy date insertion into a form.
Starting from wasiq911 code, I finished a function that makes date capturing easier.
This code still needs some tuning to repost the other form variables, but does the job on selecting
a single date and may be used as a popup date selection box.
<?php
function calendario($alterthis) {
function calurl($month,$year,$str,$day=1)
{
global $alterthis;
if($month>12) {$month-=12;$year+=1;}
if($month<1) {$month+=12;$year-=1;}
echo "<a href=\"".$_SERVER['PHP_SELF']."?__month=$month"
."&__year=$year&__day=$day&".$alterar
."=$year-$month-$day\">".$str." </a>";
}
// Get the calender info
if($_GET["__year"]) $__year=$_GET["__year"];
else $__year=date("Y");
if($_GET["__month"]) $__month=$_GET["__month"];
else $__month=date("m");
$__mk= mktime(0, 0, 0, $__month, 1, $__year);
$__day=date("w",$__mk);
$t_days = cal_days_in_month(CAL_GREGORIAN, $__month, $__year);
echo '<table border = "0"><tr><th bgcolor =
"yellow">';
calurl($__month,$__year-1," << ");
calurl($__month-1,$__year,"<");
echo '</th><th bgcolor = "yellow" colspan =
"5">'.date("F Y",$__mk)
.'</th><th bgcolor = "yellow">';
calurl($__month+1,$__year," > ");
calurl($__month,$__year+1," >>");
echo
'</th></tr><tr><th>Sun</th><th>Mon</th><th>Tue</th>
<th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>';
for ($i = 0; $i <= $t_days; $i++) {
if ($__day > 6) {
echo "</tr>\n<tr>\n";
$__day = 0; }
//------------------------------------------------//
if ($i == date("j",$__mk)) {
echo "<td align = \"center\"><b>";
calurl($__month,$__year,$i,$i);
echo "</b></td>\n";
$__day++;
}
else if ($i > 0) {
echo "<td align = \"center\">";
calurl($__month,$__year,$i,$i);
echo "</td>\n";
$__day++;
}
else if ($__day > 0)
echo "<tr><td colspan = \"$__day\"></td>\n";
//-----------------------------------------------//
if ($i == $t_days && $__day < 6)
echo "<td colspan = \"".(7 -
$__day)."\"></td>\n</tr>\n";
}
echo "</table>";
}
//here ends the function, now lets test it with an input field
$fecha=$_GET["fecha"];
?>
La fecha es: <input type="text" name="fecha"
value="<?=$fecha?>">
<?
$alterthis="fecha";
calendario($alterthis);
?>
Good day all.
----
Manual Page -- http://www.php.net/manual/en/ref.calendar.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43547
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43547&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43547&report=yes
Search -- http://master.php.net/manage/user-notes.php