Ho completato lo scipt con il passaggio del dato campo via $_GET e con la possibilità di usare due date. aaaa/mm/gg e gg/mm/aaaa.
Volevo allegare il file ma non posso perchè non accetta ne txt ne php. quindi metto tutto il codice.
Esempio del passaggio del dato campo via $_GET. e dell'apertura del calendario in pop
codice:
<form name="form1" method="post" action="">
<input name="campo1" type="text" id="campo1">
<input name="Submit2" type="button" onClick="MM_openBrWindow('calendario.php?campo=campo1','','width=400,height=400')" value="calendario">
</p>
<input name="campo2" type="text" id="campo2">
<input name="Submit22" type="button" onClick="MM_openBrWindow('calendario.php?campo=campo2','','width=400,height=400')" value="calendario">
</p>
<input type="submit" name="Submit" value="Invia">
</p>
</form>
File calendario.php
Codice PHP:
<link href="up.css" rel="stylesheet" type="text/css">
<?
echo "<script language=\"Javascript\">
function Selezionato(w_data)
{
window.opener.document.form1." . $_GET['campo'] . ".value = w_data;
setTimeout('window.close()',100);
}
</script> ";
//Variabile per visualizza mese corrente
//----------------- This function is to do the HTML header chore ---------------------
function print_HTML_header()
{
global $flag;
/* echo "Mese: ".$_GET['month'];
echo "
Anno: ".$_GET['year']; */
$flag = (isset($_GET['month']) && ($_GET['month'] <> date("m") || $_GET['year'] <> date("Y"))) ? 1 : 0;
echo "<HTML>\n<HEAD>\n<STYLE>\n".
"\n</STYLE>".
"<TITLE>Calendario\n</TITLE>\n</HEAD>\n<BODY BACKGROUND='images/bg.gif'>\n\n".
"<P ALIGN='center' CLASS='content'>Seleziona la data in cui pubblicare la news:</P>";
}
//----------------- Funzione per la chiusura dei tag HTML -----------------//
function print_HTML_footer()
{
echo "</BODY></HTML>";
}
//----------------- Funzione che stampa il calendario -----------------//
function print_calendar($mon,$year)
{
global $dates, $first_day, $start_day, $flag;
$first_day = mktime(0,0,0,$mon,1,$year);
$start_day = date("w",$first_day);
$res = getdate($first_day);
$month_name = $res["month"];
$no_days_in_month = date("t", $first_day); // t -> numero dei giorno del mese
//Controllo se il primo giorno del mese è una Domenica altrimenti riempio di spazi fino ad arrivare al primo giorno
for ($i = 01; $i <= $start_day;$i++)
$dates[01][$i] = " ";
$row = 01;
$col = $start_day + 1;
$num = 01; //contatore dei giorni del mese
while($num <= 31){
if ($num > $no_days_in_month) break; //se non ci sono più giorni nel mese esco da ciclo
else{
$dates[$row][$col] = $num;
if (($col + 1) > 7){ //se sono arrivato alla fine della settimana devo scendere di una riga
$row += 1;
$col = 1;
}else
$col += 1;
$num += 1;
}//fine if-else
}//fine while
$mon_num = date("n",$first_day); //calcolo del numero del mese -> n = senza eventuali 0
$temp_yr = $next_yr = $prev_yr = $year; //imposto l'anno di visualizzazione
$prev = $mon_num - 1;
$next = $mon_num + 1;
//Se Gennaio è il mese corrente imposto il mese precedente a Dicembre dell'anno precedente
if ($mon_num == 1){
$prev_yr = $year - 1;
$prev = 12;
}
//Se il dicembre è il mese corrente imposto il mese successivo a Gennaio dell'anno successivo
if ($mon_num == 12){
$next_yr = $year + 1;
$next = 1;
}
echo "<DIV ALIGN='center'><TABLE BORDER=0 WIDTH=350 CELLSPACING=0";
//trasformo i mesi dal formato standard a quello italiano
if (date("F", $first_day) == 'January') { $mese = 'Gennaio'; $n = '01'; }
elseif (date("F", $first_day) == 'February') { $mese = 'Febbraio'; $n = '02'; }
elseif (date("F", $first_day) == 'March') { $mese = 'Marzo'; $n = '03'; }
elseif (date("F", $first_day) == 'April') { $mese = 'Aprile'; $n = '04'; }
elseif (date("F", $first_day) == 'May') { $mese = 'Maggio'; $n = '05'; }
elseif (date("F", $first_day) == 'June') { $mese = 'Giugno'; $n = '06'; }
elseif (date("F", $first_day) == 'July') { $mese = 'Luglio'; $n = '07'; }
elseif (date("F", $first_day) == 'August') { $mese = 'Agosto'; $n = '08'; }
elseif (date("F", $first_day) == 'September') { $mese = 'Settembre'; $n = '09'; }
elseif (date("F", $first_day) == 'October') { $mese = 'Ottobre'; $n = '10'; }
elseif (date("F", $first_day) == 'November') { $mese = 'Novembre'; $n = '11'; }
elseif (date("F", $first_day) == 'December') { $mese = 'Dicembre'; $n = '12'; }
//imposto le variabili per navigare negli anni
$anno_dopo = $year + 1;
$anno_prima = $year - 1;
//ricevo da GET la variabile contenente il mese in visualizzazione
$month = $_GET['month'];
if ($month == ''){ $month = date("m"); }
echo "\n<TR ALIGN='center'><TD BGCOLOR='#4682B4' ALIGN='left' CLASS='titoli'> ".
"[url='calendario.php?month=$prev&year=$prev_yr&campo=". $_GET[']<img src=\"images/prev_month.gif\" border=0 title=\"Mese precedente\">[/url] </TD>".
"<TD COLSPAN=5 BGCOLOR='#4682B4' ALIGN='center' CLASS='corrente'>[B]".$mese." ".$temp_yr."[/B]</TD>".
"<TD BGCOLOR='#4682B4' ALIGN='right' CLASS='titoli'> ".
"[url='calendario.php?month=$next&year=$next_yr&campo=". $_GET[']<img src=\"images/next_month.gif\" border=0 title=\"Mese Successivo\"> [/url] </TD></TR>";
echo "\n<TR ALIGN='center' CLASS='content'><TD CLASS='content' BGCOLOR=\"#87CEFA\">[B]Dom[/B]</TD><TD CLASS='content' BGCOLOR=\"#87CEFA\">[B]Lun[/B]</TD><TD CLASS='content' BGCOLOR=\"#87CEFA\">[B]Mar[/B]</TD>";
echo "<TD CLASS='content' BGCOLOR=\"#87CEFA\">[B]Mer[/B]</TD><TD CLASS='content' BGCOLOR=\"#87CEFA\">[B]Gio[/B]</TD><TD CLASS='content' BGCOLOR=\"#87CEFA\">[B]Ven[/B]</TD><TD CLASS='content' BGCOLOR=\"#87CEFA\">[B]Sab[/B]</TD></TR>";
echo "<TR><TD COLSPAN=7> </TR><TR ALIGN='center'>";
$end = ($start_day > 4)? 6:5;
//ciclo che mi scrive i giorni!!
for ($row = 01; $row <= $end; $row++){
for ($col = 01; $col <= 07; $col++){
if ($dates[$row][$col] == '') $dates[$row][$col] = ' ';
if (!strcmp($dates[$row][$col], ' ')) $count += 1;
$t1 = $dates[$row][$col];
if ($t1==""){
$t = "";
}elseif ($t1>0 and $t1<10){
$t = "0" . $t1;
}else{
$t = $t1;
}
//Visualizzazione gg/mm/aaaa
//$var = $t.'/'.$mon.'/'.$year;
//visualizzazione aaaa/mm/gg
$var = $year . "/" . $mon . "/" . $t;
//Controllo se la data è oggi la evidenzio
if (($t == date("d")) && ($mon == date("m")) && ($year == date("Y"))){
echo "\n<TD CLASS='corrente' BGCOLOR=\"#4682B4\">";
//echo "<a href=\"java script:Selezionato('$var')\" TITLE=\"$var\">";
echo "<a href=\"#\" onclick=\"Selezionato('$var');return false;\" TITLE=\"$var\">";
echo $t."</a></TD>";
}else{ //Se il giorno non c'è metto uno spazio
echo "\n<TD CLASS='titoli' BGCOLOR=\"#87CEFA\">".(($t == " " )? " " :"<a href=\"#\" onclick=\"Selezionato('$var');return false;\" TITLE=\"$var\">".$t)."</a>
";
}
}//fine for -colonne
if (($row + 1) != ($end+1))
echo "</TR>\n<TR ALIGN='center'>";
else
echo "</TR>";
}//fine for - righe
echo "<TR><TD ALIGN=\"left\" BGCOLOR=\"#4682B4\"><a href=\"calendario.php?month=$month&year=$anno_prima&campo=". $_GET['campo'] ."\" title=\"Anno precedente\"><img src=\"images/prev_year.gif\" border=0 title=\"Anno precedente\"></a></TD><TD COLSPAN=5 BGCOLOR=\"#4682B4\"> </TD><TD ALIGN=\"right\" BGCOLOR=\"#4682B4\"><a href=\"calendario.php?month=$month&year=$anno_dopo&campo=". $_GET['campo'] ."\" title=\"Anno Successivo\"><img src=\"images/next_year.gif\" border=0 title=\"Anno successivo\"></a></TD></TR>";
echo "\n</TABLE>
";
/* echo $flag. ' - '; */
if ($flag == '1'){
echo "<A HREF=\"calendario.php?campo=" . $_GET['campo'] . "\" CLASS=\"content\">Visualizza il mese corrente</A></DIV>";
}
}
//----------Main Loop-----------
//Se il mese non è presente lo setto a quello corrente
$month = (empty($month)) ? date("m") : $month;
//Se l'anno non è presente lo setto a quello corrente
$year = (empty($year)) ? date("Y") : $year;
print_HTML_header();
print_calendar($month,$year);
print_HTML_footer();
?>
ciao ciao