Friday, January 31, 2014

Calendar function in php - free coding

Calendar function in php - free coding 

example 

sms.php



Add the following  script before body of your file 


<Script language="JavaScript">
<!--


function GetDate(CtrlName){
        var cAssetValue=showModalDialog("calendar.php",0,"dialogWidth:175px;dialogHeight:210px");
Date_Fill(cAssetValue,CtrlName);
}


function Date_Fill(Mydate,Ctrl) {
var now = new Date(Mydate);
var day = now.getDate();
var month = now.getMonth() + 1;
day = ((day >9) ? "" : "0") + day;
month = ((month >9) ? "" : "0") + month;
var year = now.getYear();
if (year <= 99) {
year = "19" + year;
}
document.form1.item(Ctrl).value=day + "-" + month + "-" + year;
form1.action = "sms.php";
form1.target = "_parent";
form1.submit();

}



-->
</script>



<body>
<?php
if ($_POST['From_Date'] == "") {
$from_date = date("d-m-Y");
}
else {
$from_date = $_POST['From_Date'];

}
list($day1, $month1, $year1) = split('[-,/]', $from_date);

$From = $year1 . "-" . $month1 . "-" . $day1;

?>

<form name="form1" action="sms.php" method="post" >
<input type="hidden" name="hidvar1" >

 Select Date  <input id="myTextBox" type="text" name="From_Date" value="<?php echo $from_date;?>" size="12" maxlength="12" unselectable="on"><img src="/pics/Icon_calendar.gif" border="0" style="cursor: hand" alt="Calender" onclick="GetDate('From_Date')">

</form>
</body>




calendar.php file coding 

copy the following lines and save as calendar.php


<?php
header("Pragma: no-cache");
header("Cache-Control: no-cache, must-revalidate");
?>
<html>
<!-- Creation date: 15-07-2003 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Calender</title>

<Script language="VbScript">
<!--
Dim CellSpan,MaxDay,SDate,CMonth,C_Date,NMonth,NDate,LDate,Scell,SDay,SDayNo
C_Date=Date
returnValue=Date

Sub Year_Change()
if Len(Year(C_Date))<=2 then
if Year(C_Date)>50 then
MyStr=1900+Year(C_Date)
Else
MyStr=2000+Year(C_Date)
End if
YearView.Value=MyStr
Else
YearView.Value=Year(C_Date)
End if
End Sub

Sub MonthView_OnChange()
MyDate=Monthview.Value & " 1, " & Year(C_Date)
C_Date=CDate(MyDate)
MonthTxt.Value=Month(C_Date)
YearTxt.Value=Year(C_Date)
SelDate.Value=Dateserial(YearTxt.Value,MonthTxt.Value,DayTxt.Value)
Change_Days()
if Month(C_Date)=Month(Date) then
Call Mark_CurrDate()
End if
End sub

Sub YearView_OnChange()
C_Date=Dateserial(YearView.Value,Month(C_Date),1)
MonthTxt.Value=Month(C_Date)
YearTxt.Value=Year(C_Date)
SelDate.Value=Dateserial(YearTxt.Value,MonthTxt.Value,DayTxt.Value)
Change_Days()
if Month(C_Date)=Month(Date) then
Call Mark_CurrDate()
End if
End sub

Sub Mark_CurrDate()
if Year(C_Date) <> Year(Date) then
Exit sub
End if
Call Year_Change()
MonthView.Value=Monthname(Month(C_Date))
B=cStr(Day(Date))
For A=1 to 35
Set Astr=document.all.item("Cell"&A)
if B = Astr.value then
Astr.style.color="Blue"
Astr.Style.Fontweight ="bold"
End if
Set Astr=Nothing
Next
End Sub

Sub Cell_Click(CNo)
if PrvCell.Value <> "" then
Set Astr=document.all.item(PrvCell.Value)
if Ucase(Astr.style.Color) <> "BLUE" then
Astr.style.color="Black"
Astr.Style.Fontweight ="Normal"
End if
Set Astr=Nothing
End if
Set Astr=document.all.item("Cell"&CNo)
PrvCell.Value="Cell"&CNo
if Ucase(Astr.style.Color) <> "BLUE" then
Astr.style.color="Red"
Astr.Style.Fontweight ="bold"
End if
DayTxt.Value=Astr.Value
Set Astr=Nothing
SelDate.Value=Dateserial(YearTxt.Value,MonthTxt.Value,DayTxt.Value)
End sub

Sub Cell_DblClick(CNo)
Set Astr=document.all.item("Cell"&CNo)
Astr.style.color="Blue"
Astr.Style.Fontweight ="bold"
DayTxt.Value=Astr.Value
Set Astr=Nothing
returnValue=Dateserial(YearTxt.Value,MonthTxt.Value,DayTxt.Value)
Window.Close
End sub


Sub Back_OnClick
if Month(C_Date)=1 then
C_Date=Dateserial(Year(C_Date)-1,12,1)
Call Year_Change()
Else
C_Date=Dateserial(Year(C_Date),Month(C_Date)-1,1)
End if
MonthTxt.Value=Month(C_Date)
YearTxt.Value=Year(C_Date)
SelDate.Value=Dateserial(YearTxt.Value,MonthTxt.Value,DayTxt.Value)
Change_Days()
if Month(C_Date)=Month(Date) then
Call Mark_CurrDate()
End if
End sub

Sub Front_OnClick
if Month(C_Date)=12 then
C_Date=Dateserial(Year(C_Date)+1,1,1)
Call Year_Change()
Else
C_Date=Dateserial(Year(C_Date),Month(C_Date)+1,1)
End if
MonthTxt.Value=Month(C_Date)
YearTxt.Value=Year(C_Date)
SelDate.Value=Dateserial(YearTxt.Value,MonthTxt.Value,DayTxt.Value)
Change_Days()
if Month(C_Date)=Month(Date) then
Call Mark_CurrDate()
End if
End Sub

Sub Change_Days()
MonthView.Value=Monthname(Month(C_Date))
SDayNo=1
CellSpan=7
NMonth=Month(C_Date)+1
NDate=Dateserial(Year(C_Date),NMonth,1)
LDate=NDate-1
MaxDay=Day(LDate)
SDate=Dateserial(Year(C_Date),Month(C_Date),1)
Sday=WeekDay(SDate)
CellRet="No"
if MaxDay=31 and Sday=7 then
Set Astr=document.all.item("Cell1")
Astr.Value="30"
Astr.style.color="Black"
Astr.Style.Fontweight ="Normal"
Astr.Disabled=False
Set Astr=Nothing
Set Astr=document.all.item("Cell2")
Astr.Value="31"
Astr.style.color="Black"
Astr.Style.Fontweight ="Normal"
Astr.Disabled=False
Set Astr=Nothing
CellRet="Yes"
Elseif Maxday=30 and Sday=7 then
Set Astr=document.all.item("Cell1")
Astr.Value="30"
Astr.style.color="Black"
Astr.Style.Fontweight ="Normal"
Astr.Disabled=False
Set Astr=Nothing
Set Astr=document.all.item("Cell2")
Astr.Value=""
Astr.Disabled=True
Set Astr=Nothing
CellRet="Yes"
Elseif Maxday=31 and Sday=6 then
Set Astr=document.all.item("Cell1")
Astr.Value="31"
Astr.style.color="Black"
Astr.Style.Fontweight ="Normal"
Astr.Disabled=False
Set Astr=Nothing
Set Astr=document.all.item("Cell2")
Astr.Value=""
Astr.Disabled=True
Set Astr=Nothing
CellRet="Yes"
End if


For A=1 to 7
if Sday<=A then
Set Astr=document.all.item("Cell"&A)
Astr.Value=SDayNo
Astr.style.color="Black"
Astr.Style.Fontweight ="Normal"
Astr.Disabled=False
Set Astr=Nothing
SDayNo=SdayNo+1
Elseif A<3 then
if CellRet="No" then
Set Astr=document.all.item("Cell"&A)
Astr.Value=""
Astr.Disabled=True
Set Astr=Nothing
End if
Else
Set Astr=document.all.item("Cell"&A)
Astr.Value=""
Astr.Disabled=True
Set Astr=Nothing
End if
Next
For A=1 to 4
For B=1 to 7
CellSpan=CellSpan+1
if MaxDay>=SDayNo then
Set Astr=document.all.item("Cell"&CellSpan)
Astr.Value=SDayNo
Astr.style.color="Black"
Astr.Style.Fontweight ="Normal"
Astr.Disabled=False
Set Astr=Nothing
SDayNo=SdayNo+1
Else
Set Astr=document.all.item("Cell"&CellSpan)
Astr.Value=""
Astr.Disabled=True
Set Astr=Nothing
End if
Next
Next

End Sub

Sub OK_Onclick
returnValue=Dateserial(YearTxt.Value,MonthTxt.Value,DayTxt.Value)
Window.Close
End Sub

Sub Cancel_OnClick
returnValue=Date
Window.Close
End Sub
-->
</Script>

<script language="Javascript">

</script>
</head>

<body onload="Mark_CurrDate()">
<?php
$today = getdate();
?>
<input type="hidden" name="YearTxt" value='<?php echo date("Y"); ?>'>
<input type="hidden" name="MonthTxt" value='<?php echo date("m"); ?>'>
<input type="hidden" name="DayTxt" value='<?php echo date("d"); ?>'>
<input type="hidden" name="PrvCell" value="">
<center>
<table border="1" align="center" cellspacing="0"><tr><td><table border="0" cellspacing="0"><tr><td><input type="button" Name="Back" value="<<" style="background: transparent; width:10px; font:9px; color: Navy; border: none; cursor: hand"></td><td>
<select name="MonthView" style="background: transparent; width: 75px; color: navy; font: 10px">
<?php
for ($a=1; $a <= 12; $a++) {?>
<option value='<?php echo date("F", mktime(0,0,0,$a,1,2000));?>'><?php echo date("F", mktime(0,0,0,$a,1,2000));?></option>
<?php } ?>
</select></td><td>
<select name="YearView" style="background: transparent; width: 48px; color: navy; font:10px">
<?php for ($a=1951; $a <= 2049; $a++) { ?>
<option value='<?php echo $a; ?>'> <?php echo $a; ?></option>
<?php } ?>
</select></td><td>
<input type="button" Name="Front" value=">>" style="background: transparent; width: 11px; font:9px; color: navy; border: none; cursor: hand"></td></tr></table></td></tr>
<tr><td>
<Table border="1" align="center" cellspacing="0">

<!--Calendar Day Names Header Starts Here -->

<tr>
<?php for ($a=1; $a <= 7; $a++) {?>
<th align="center" style="font: 11px; color: navy"><?php echo date("D", mktime(0,0,0,10,$a,2000));?></th>
<?php } ?>
</tr>

<!--Calendar Day Numbers Starts Here -->

<?php
$SDayNo = 1;
$CellSpan = 7 ;
$NMonth = date("m") + 1;
$NDate = getdate(mktime(0,0,0,$NMonth,1,date("Y")));
$LDate=getdate(mktime(0,0,0,$NMonth,1-1,date("Y")));
$MaxDay=date("d", mktime(0,0,0,$NMonth,1-1,date("Y")));
$SDate=getdate(mktime(0,0,0,date("m"),1,date("Y")));
$Sday=$SDate["wday"]+1;
?>
<tr>
<?php $CellRet = "No";
 if ($MaxDay == 31 and $Sday == 7){
 ?>
<td align="center"><input type="button" Name="Cell1" value="30" style="background: transparent;  width: 15px; height: 15px;  font: 9px; border: none; cursor: hand; font: xx-small;" onclick="Cell_Click(1)" ondblclick="Cell_DblClick(1)"></td>
<td align="center"><input type="button" Name="Cell2" value="31" style="background: transparent;  width: 15px; height: 15px;  font: 9px; border: none; cursor: hand" onclick=Cell_Click(2) ondblclick=Cell_DblClick(2)></td>
<?php $CellRet = "Yes";
}
elseif ($MaxDay == 30 and $Sday == 7) {
?>
<td align="center"><input type="button" Name="Cell1" value="30" style="background: transparent;  width: 15px; height: 15px;  font: 9px; border: none; cursor: hand" onclick="Cell_Click('1')" ondblclick="Cell_DblClick('1')"></td>
<td align="center"><input type="button" Name="Cell2" value="" style="background: transparent; width: 15px; height: 15px;  font: 9px; border: none; cursor: hand" onclick="Cell_Click('2')" ondblclick="Cell_DblClick('2')" disabled></td>
<?php $CellRet = "Yes";
}
elseif ($MaxDay == 31 and $Sday == 6) {
?>
<td align="center"><input type="button" Name="Cell1" value="31" style="background: transparent;  width: 15px; height: 15px;  font: 9px; border: none; cursor: hand" onclick="Cell_Click('1')" ondblclick="Cell_DblClick('1')"></td>
<td align="center"><input type="button" Name="Cell2" value="" style="background: transparent; width: 15px; height: 15px;  font: 9px; border: none; cursor: hand" onclick="Cell_Click('2')" ondblclick="Cell_DblClick('2')" disabled></td>
<?php $CellRet = "Yes" ;
}
?>

<?php for ($a=1; $a <= 7; $a++){
if ($Sday <= $a) {
?>
<td align="center"><input type="button" Name='Cell<?php echo $a; ?>' value='<?php echo $SDayNo; ?>' style="background: transparent; width: 15px; height: 15px;  font: 9px; border: none; cursor: hand" onclick="Cell_Click(<?php echo "'" . $a . "'"; ?>)" ondblclick="Cell_DblClick(<?php echo "'" . $a . "'"; ?>)"></td>
<?php $SDayNo = $SDayNo +1;
}
elseif ($a < 3) {
if ($CellRet == "No") {
?>
<td align="center"><input type="button" Name='Cell<?php echo $a; ?>' value="" style="background: transparent; width: 15px; height: 15px;  font: 9px; border: none; cursor: hand" onclick="Cell_Click(<?php echo "'" . $a . "'"; ?>)" ondblclick="Cell_DblClick(<?php echo "'" . $a . "'"; ?>)" disabled></td>
<?php
}
}
else {
?>
<td align="center"><input type="button" Name='Cell<?php echo $a; ?>' value="" style="background: transparent; width: 15px; height: 15px;  font: 9px; border: none; cursor: hand" onclick="Cell_Click(<?php echo "'" . $a . "'"; ?>)" ondblclick="Cell_DblClick(<?php echo "'" . $a . "'"; ?>)" disabled></td>
<?php
}
}
?>
<!--Filling Dates -->
</tr>
<?php for ($a=1; $a <=4; $a++) {
?>
<tr>
<?php for ($b=1; $b <= 7; $b++) {
$CellSpan = $CellSpan + 1 ;
 if ($MaxDay >= $SDayNo) {
?>
<td align="center"><input type="button"  Name='Cell<?php echo $CellSpan; ?>' value='<?php echo $SDayNo; ?>' style="background: transparent; width: 15px; height: 15px;  font: 9px; border: none; cursor: hand" onclick="Cell_Click(<?php echo "'" . $CellSpan . "'"; ?>)" ondblclick="Cell_DblClick(<?php echo "'" . $CellSpan . "'" ;?>)"></td>
<?php $SDayNo = $SDayNo + 1 ;
}
else {
?>
<td align="center"><input type="button"  Name='Cell<?php echo $CellSpan; ?>' value="" style="background: transparent;width: 15px; height: 15px; font: 9px; border: none; cursor: hand" onclick="Cell_Click(<?php echo "'" . $CellSpan . "'"; ?>)" ondblclick="Cell_DblClick(<?php echo "'" . $CellSpan . "'"; ?>)" disabled></td>
<?php }
}
?>
</tr>
<?php
}
?>

</table>
<input type="hidden" name="SelDate" size="20" maxlength="15" disabled style="background: transparent; text-align: center; border: none" align="absmiddle"  Value='<?php echo (date("d") . " " . date("M") . " " . date("Y"));?>'>
</td></tr></table>
</center>

</body>

</html>

Labels

AJAX (1) Answers (1) Apache (1) Array (16) bug (1) C (1) C++ (1) Calendar (1) Class (1) Commands (1) Cookies (2) Database (2) Date (7) Days (1) explode (1) File Upload (1) FILES (1) firewall (1) fix (1) Functions (26) GET (1) GMT (1) JavaScript (2) localhost (1) Mail (1) Menu (1) MYSQL (13) PERL (1) PHP (36) php.ini (1) POST (1) preg_match (1) Questions (1) Script (1) SMS (2) Solution (1) String (1) Time (5) Time Zone (1) Vista (1) Wamp Server (1) windows 7 (2) XML (1)

Popular Posts

Popular Posts