Mesaje recente

Members
Stats
  • Total Posts: 17,786
  • Total Topics: 1,234
  • Online today: 340
  • Online ever: 340
  • (Today at 00:10)
Users Online
Users: 0
Guests: 132
Total: 132

calendar in php

Started by kquizak, 07 January 2007, 22:16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kquizak

m-am tot gandit cum sa fac un calendar ...si am reusit...pentru ce ce nu vor sa piarda vremea prea mult(mie mi-a luat vreo 3h 1/2 pana am ajuns la forma asta) aveti mai jos codul.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>calendar</title>
  </head>
  <body>

<?
error_reporting('0');
class calendar
{

function getData(){
if(!isset($_GET['data'])){
$data = mktime(0,0,0,date('m'), date('d'), date('Y'));
} else {
$data = $_GET['data'];
}
return $data;
}

function reprezentare($data){

$zi=date('d',$data);
$ziNume=date('D',$data);
$luna=date('m',$data);
$an=date('Y',$data);
$lunaNume=date('M',$data);
$nrZileLuna=cal_days_in_month(0,$luna,$an);
$inceput_luna = mktime(0,0,0,$luna, 1, $an);
$prima_zi_din_luna = date('D', $inceput_luna);

$previous_link = "<a href=\"".$_SERVER['PHP_SELF']."?data=";
if($luna == 1){
$previous_link .= mktime(0,0,0,12,$zi,($an -1));
} else {
$previous_link .= mktime(0,0,0,($luna -1),$zi,$an);
}
$previous_link .= "\"><< Pre</a>";

$next_link = "<a href=\"".$_SERVER['PHP_SELF']."?data=";
if($luna == 12){
$next_link .= mktime(0,0,0,1,$zi,($an + 1));
} else {
$next_link .= mktime(0,0,0,($luna +1),$zi,$an);
}
$next_link .= "\">Urm >></a>";

echo "<table cellpadding='15' cellspacing='1'>
<TBODY align='center' valign='center' bgcolor='lightGray' >
<tr>
<TD>".$previous_link."</td>
<td colspan='5'>".$lunaNume." ".$an."</td>
<TD>".$next_link."</td>
</tr>";
echo "
<TR align='center' valign='center'>
<TD><b>L</b></TD>
<TD><b>M</b></TD>
<TD><b>Mi</b></TD>
<td><b>J</b></td>
<TD><b>V</b></TD>
<TD><b>S</b></TD>
<TD><b>D</b></TD>
</TR>
<TR>
";

switch($prima_zi_din_luna){
case "Mon": $pozitie = 0; break;
case "Tue": $pozitie = 1; break;
case "Wed": $pozitie = 2; break;
case "Thu": $pozitie = 3; break;
case "Fri": $pozitie = 4; break;
case "Sat": $pozitie = 5; break;
case "Sun": $pozitie = 6; break;
}

for($i=1;$i<=$nrZileLuna;$i++){
$calendar[$i]=$i;
}
if($pozitie==0){
//unshift nimic
}
elseif($pozitie==1){
//unshift matrice 1 pozitie
array_unshift($calendar,"");
}
elseif($pozitie==2){
//unshift matrice 2 pozitii
array_unshift($calendar,"","");
}
elseif($pozitie==3){
//unshift matrice 3 pozitii
array_unshift($calendar,"","","");
}
elseif($pozitie==4){
//unshift matrice 4 pozitii
array_unshift($calendar,"","","","");
}
elseif($pozitie==5){
//unshift matrice 5 pozitii
array_unshift($calendar,"","","","","");
}
elseif($pozitie==6){
//unshift matrice 6 pozitii
array_unshift($calendar,"","","","","","");
}

//reprezentam matricea
$contor=0;
foreach($calendar as $dt){
if($contor%7==0){
$data=mktime(0,0,0,$luna,$dt,$an);
echo "</tr><tr>";
echo "<td><a href='pagina_in_care_dorim rezultatul?data=".$data."'>".$dt."</a></td>";
$contor++;
}
else{
echo "<td><a href='pagina_in_care_dorim rezultatul?data=".$data."'>".$dt."</a>";
$contor++;
}
}

}

}

?>
</TBODY>
</table>
  </body>
</html>

si se acceseaza asa:

include_once("calphp.php");
$cal=new calendar;
$cal->reprezentare($cal->getData());

daca aveti ceva de adaugat...feel free...(ma astept la unele solutii mai elegante...nu e punctul meu forte)
network-tools.ath.cx ---nmap yourself