Page 1 sur 1

calendrier au lieu de combo box

Posté : 01 janv. 2007, 20:49
par daplus
Bonne Année 2007 à tous et à toutes,

Je tourne en rond depuis une journée sur l'utilisation d'un calendrier au lieu de rentrer des dates à la main sur un input (ce qui marche parfaitement).

J'ai également créé mon calendrier entièrement en PHP.

Mes problèmes:

- le programme ne s'arrête pas sur le script calendrier.php, afin d'y choisir la date
- ensuite comment réintégrer les données dy, mth, yr dans project_edit.php pour qu'elles soient prises en compte par le form puis reprise par le UPDATE?

J'ai essayé en include(), c'est pire

J'ai regardé sur le web, mais cela ne change pas les problèmes

au départ il y a le script project_view.php, ou en cliquant sur edit en face d'un projet on se rend à:

script project-edit.php
<?php

session_start();

if ($at_id > 0 ) {$v_at_id0=$at_id;} else {if ( $v_at_id0 & !$at_id ) {$at_id=$v_at_id0;}}
if ($atp_id > 0 ) {$v_atp_id0=$atp_id;} else {if ( $v_atp_id0 & !$atp_id ) {$atp_id=$v_atp_id0;}}

//echo "<font color=#FFFFFF>ep 8 at_id $at_id v_at_id0 $v_at_id0 atp_id $atp_id v_atp_id0 $v_atp_id0</font><br>";

?>

<html>
<head>
<title>Project</title>
</head>
<body link="blue" alink="blue" vlink="blue" background="images_ATFS/1580_2.gif">

<?php

include "include/get_root_atfs.inc";

if ($submit) {

    $today = date("Y-m-d");

    $sql = "UPDATE atproject SET atp_at_id='$atp_at_id',atp_ref='$atp_ref',atp_start='$atp_start',atp_end='$atp_end',atp_quoted='$atp_quoted',$atp_awarded='$atp_awarded',atp_rogress='$atp_rogress',atp_cpl_inv='$atp_cpl_inv',atp_invoice='$atp_invoice',atp_paym_pb='$atp_paym_pb',atp_completed='$atp_completed',atp_modified='$today' WHERE atp_id=$atp_id";

  // run SQL against the DB

    echo"<table border=0 bgcolor=#FFFFFF><tr><td>";

    $result = mysql_query($sql);

    echo "Record updated/edited!<p>";

    echo "<a href='edaddel_project.php'>Continue</a>";

    echo"</table>";

} else {

echo "ln 42 atp_id $atp_id<br>";

  ?>

  <P>

  <a name="bottom"></a>

  <?php

    echo"<table border=0 bgcolor=#FFFFFF><tr><td>";

	echo "<b>Modify a PROJECT</b>";
  ?>

  <P>

  <form method="post" action="<?php echo $PHP_SELF?>">

  <?php

  include "include/get_root_atfs.inc";

    $sql = "SELECT * FROM atproject WHERE atp_id=$atp_id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

    $atp_id = $myrow["atp_id"];

    $atp_at_id = $myrow["atp_at_id"];
    $codetargetadr = $myrow["atp_at_id"];

    $atp_ref = $myrow["atp_ref"];

    $atp_start = $myrow["atp_start"];

    $atp_end = $myrow["atp_end"];

    $atp_quoted = $myrow["atp_quoted"];

    $atp_awarded = $myrow["atp_awarded"];

    $atp_rogress = $myrow["atp_rogress"];

    $atp_cpl_inv = $myrow["atp_cpl_inv"];

    $atp_invoice = $myrow["atp_invoice"];

    $atp_paym_pb = $myrow["atp_paym_pb"];

    $atp_completed = $myrow["atp_completed"];

    $v_prog= 'project_edit.php';

?>

    <input type=hidden name="atp_id" value="<?php echo $atp_id ?>">

  <table border=0>

  <tr><td><font face=Arial size=2>Address</font></td><td>

    <SELECT name = "atp_at_id">

  <?php

    $resultoptiontadr = mysql_query ("SELECT * FROM ataddress ORDER BY at_name1");

  while($opt_lineadr=mysql_fetch_array ($resultoptiontadr))

    if ($opt_lineadr[0]== $codetargetadr) {

	echo "<option SELECTED value=$opt_lineadr[0]>$opt_lineadr[1] > $opt_lineadr[2]</option>\n";

	 } else {

    echo "<option value=$opt_lineadr[0]>$opt_lineadr[1] > $opt_lineadr[2]</option>\n";

	 }

 ?>

  </SELECT></td></tr>

  <tr><td>Project Nr</td><td><input type="Text" name="atp_ref" size="10" value="<?php echo $atp_ref ?>">

<?php

    $v_display = 'Project Starting Date';

    echo "<a href='calendar.php?prog=$prog' target=_blank><img src='images_ATFS/cal_thb_30.gif' width=30 height=23 alt='Project Starting Date' border=0></a>";

    $v_date_start = date ("Y-m-d", mktime (0,0,0,$mth,$dy,$yr));

    //$v_display = 'Project Ending Date';

    //include "calendar.php";

    //$v_date_end = date ("Y-m-d", mktime (0,0,0,$mth,$dy,$yr));

    //echo "v_date_start $v_date_start v_date_start $v_date_start<br>";

?>

  <!-- <tr><td>Starting Date</td><td><input type="Date" name="atp_start" size="10" value="<?php echo $atp_start ?>">

  <tr><td>Closing Date</td><td><input type="Date" name="atp_end" size="10" value="<?php echo $atp_end ?>"> -->

  <tr><td>Quoted</td><td><input type="Text" name="atp_quoted" size="10" value="<?php echo $atp_quoted ?>"> Quote Nr

  <tr><td>Awarded</td><td><input type="Text" name="atp_awarded" size="1" value="<?php echo $atp_awarded ?>"> Y or empty

  <tr><td>In Progress</td><td><input type="Text" name="atp_rogress" size="1" value="<?php echo $atp_rogress ?>"> Y or empty

  <tr><td>Completed before Invoicing</td><td><input type="Text" name="atp_cpl_inv" size="1" value="<?php echo $atp_cpl_inv ?>"> Y or empty

  <tr><td>Invoiced</td><td><input type="Text" name="atp_invoice" size="10" value="<?php echo $atp_invoice ?>"> Invoice Number

  <tr><td>Payment Delinquent</td><td><input type="Text" name="atp_paym_pb" size="1" value="<?php echo $atp_paym_pb ?>"> Y or empty

  <tr><td>Project completed</td><td><input type="Text" name="atp_completed" size="1" value="<?php echo $atp_completed ?>"> Y or empty

  </table>

  <input type="Submit" name="submit" value="Enter information">
  <a href="javascript:history.go(-1)">BACK</a>

  </form>

<?php

}

  echo "</table>";

?>

</body>

</html>
script calendar.php
<?php

session_start();

echo "$v_display<br>";

include "include/get_root_da_erp.inc";

        //parameters
        $border_color = green;
        $border_thickness = 3;
        $title_background = "#FFD700";    // #FFD700 = gold
        $font = arial;
        $title_font_size = 2;
        $title_font_color = green;
        $day_name_font_size = 2;    // Mon, Tue, Wed, ...
        $day_name_font_color = brown;
        $day_name_background = "#FFCCFF";
        $day_background_color = "CCCCCC";  //#CCCCCC light grey   1,2,3,4,5,6,7,....
        $day_font_color = blue;
        $day_font_size = 3;
        $language = e;

        if ( $month_chosen == '') { $base = date ("D M d m Y"); }  else {

        if ( $month_chosen == 'plus') { $base = date ("D M d m Y", mktime (0,0,0,$mth+1,$dy,$yr)); }

        if ( $month_chosen == 'minus') { $base = date ("D M d m Y", mktime (0,0,0,$mth-1,$dy,$yr)); }

        }

        $new_day = substr($base,8,2);

        $new_month = substr($base,11,2);

        // getting the full name of the month like: 'September'

        $resultmn = mysql_query ("SELECT * FROM calgal WHERE cag_typ = 'MONTH' && cag_lg ='$language' && cag_abr3 = '$new_month'",$db);

        while ($myrowmn = mysql_fetch_array($resultmn)) {

        $new_month_name = $myrowmn["cag_descr"];

        }

        $new_year = substr($base,14,4);

        $new_day_name_short = substr($base,0,3);

        //getting the weekday nr like: 1,2,3,...

        $resultdnr = mysql_query ("SELECT * FROM calgal WHERE cag_typ = 'DAY' && cag_lg ='$language' && cag_abr5 = '$new_day_name_short'",$db);

        while ($myrowdnr = mysql_fetch_array($resultdnr)) {

        $v_day_nr = $myrowdnr["cag_abr3"];

        }

        // getting the last day of the month

        $last_day = cal_days_in_month(CAL_GREGORIAN, $new_month, $new_year);

    echo "<br><table border=$border_thickness bordercolor=$border_color><tr><td colspan=7 bgcolor=$title_background>";

  echo "<table border=0 width=100%><tr><td align=left width=30><a href=\"calendar.php?month_chosen=minus&&dy=$new_day&&mth=$new_month&&yr=$new_year\"><img src=\"images_ATFS/b_minus.gif\" width=30 height=20 alt=\"previous month\" border=0></a><td align=center><b><font face=$font size=$title_font_size color=$title_font_color>$new_month_name $new_year</font></b><td align=right width=30><a href=\"calendar.php?month_chosen=plus&&dy=$new_day&&mth=$new_month&&yr=$new_year\"><img src=\"images_ATFS/b_plus.gif\" width=30 height=20 alt=\"next month\" border=0></a></table>";

  echo "<tr>";

      // here are the name of the days 'Monday to Sunday'

      $resultdyname = mysql_query ("SELECT * FROM calgal WHERE cag_typ = 'DAY' && cag_lg ='$language'",$db);

        while ($myrowdyname = mysql_fetch_array($resultdyname)) {

        $v_dayname_short = substr($myrowdyname["cag_descr"],0,3);

        echo "<td bgcolor=$day_name_background><font face=$font size=$day_name_font_size color=$day_name_font_color>$v_dayname_short</font>";

        }

    echo "<tr>";

        //listing the days, positionning the 1st day on the correct weekday

        for($i = 1; $i <= $last_day; $i++){

        $v_date_calcul_date = date ("D d-m-Y", mktime (0,0,0,$new_month,$i,$new_year));

        $v_day_name_short = date ("D", mktime (0,0,0,$new_month,$i,$new_year));

      $resultdyname2 = mysql_query ("SELECT * FROM calgal WHERE cag_typ = 'DAY' && cag_lg ='$language' && cag_abr5='$v_day_name_short'",$db);

        while ($myrowdyname2 = mysql_fetch_array($resultdyname2)) {

        $v_weekday = 100+$myrowdyname2["cag_abr3"]-100;

        if ( $v_weekday == 1 ) { echo "<tr>"; }

        if ( $i == 1 && $v_weekday > 1) {

        for ($j = 1; $j< ($v_weekday); $j++ )

        { echo "<td>&nbsp;"; }

        }

        echo "<td align=right bgcolor=$day_background_color><a href=\"cal_date.php?dy=$i&&mth=$new_month&&yr=$new_year&prog=$prog\" style=\"text-decoration:none\"><font face=$font size=$day_font_size color=$day_font_color>$i</font></a>";

        }

        if ( $v_weekday < 7  && $i == $last_day) { for ($k = $v_weekday; $k < 7; $k++ ) { echo "<td>&nbsp;"; } }

        }

    echo "</table>";

?>
Merci d'avance à ceux et celles qui pourront prendre du temps à me répondre.

Posté : 01 janv. 2007, 21:00
par Xenon_54
Tu peux être intéressé par cette librairie de YUI:
http://developer.yahoo.com/yui/calendar/

Merci Xenon_54

Posté : 01 janv. 2007, 21:58
par daplus
J'ai téléchargé le dll, ai trouvé une forme de calendrier qui m'intéresse.

Mais je ne vois pas comment intégrer ce calendrier Yahoo ou bien celui que j'ai développé moi-même dans:
  <form method="post" action="<?php echo $PHP_SELF?>">

  <?php

  include "include/get_root_atfs.inc";

    $sql = "SELECT * FROM atproject WHERE atp_id=$atp_id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

    $atp_id = $myrow["atp_id"];

    $atp_at_id = $myrow["atp_at_id"];
    $codetargetadr = $myrow["atp_at_id"];

    $atp_ref = $myrow["atp_ref"];

    $atp_start = $myrow["atp_start"];

    $atp_end = $myrow["atp_end"];

    $atp_quoted = $myrow["atp_quoted"];

    $atp_awarded = $myrow["atp_awarded"];

    $atp_rogress = $myrow["atp_rogress"];

    $atp_cpl_inv = $myrow["atp_cpl_inv"];

    $atp_invoice = $myrow["atp_invoice"];

    $atp_paym_pb = $myrow["atp_paym_pb"];

    $atp_completed = $myrow["atp_completed"];

    $atp_modified = $myrow["atp_modified"];

?>

    <input type=hidden name="atp_id" value="<?php echo $atp_id ?>">

  <table border=0>

  <tr><td><font face=Arial size=2>Address</font></td><td>

    <SELECT name = "atp_at_id">

  <?php

    $resultoptiontadr = mysql_query ("SELECT * FROM ataddress ORDER BY at_name1");

  while($opt_lineadr=mysql_fetch_array ($resultoptiontadr))

    if ($opt_lineadr[0]== $codetargetadr) {

	echo "<option SELECTED value=$opt_lineadr[0]>$opt_lineadr[1] > $opt_lineadr[2]</option>\n";

	 } else {

    echo "<option value=$opt_lineadr[0]>$opt_lineadr[1] > $opt_lineadr[2]</option>\n";

	 }

 ?>

  </SELECT></td></tr>

  <tr><td>Project Nr</td><td><input type="Text" name="atp_ref" size="10" value="<?php echo $atp_ref ?>">

  <tr><td>Starting Date</td><td><input type="Date" name="atp_start" size="10" value="<?php echo $atp_start ?>">

  <tr><td>Closing Date</td><td><input type="Date" name="atp_end" size="10" value="<?php echo $atp_end ?>">

  <tr><td>Quoted</td><td><input type="Text" name="atp_quoted" size="10" value="<?php echo $atp_quoted ?>"> Quote Nr

  <tr><td>Awarded</td><td><input type="Text" name="atp_awarded" size="1" value="<?php echo $atp_awarded ?>"> Y or empty

  <tr><td>In Progress</td><td><input type="Text" name="atp_rogress" size="1" value="<?php echo $atp_rogress ?>"> Y or empty

  <tr><td>Completed before Invoicing</td><td><input type="Text" name="atp_cpl_inv" size="1" value="<?php echo $atp_cpl_inv ?>"> Y or empty

  <tr><td>Invoiced</td><td><input type="Text" name="atp_invoice" size="10" value="<?php echo $atp_invoice ?>"> Invoice Number

  <tr><td>Payment Delinquent</td><td><input type="Text" name="atp_paym_pb" size="1" value="<?php echo $atp_paym_pb ?>"> Y or empty

  <tr><td>Project completed</td><td><input type="Text" name="atp_completed" size="1" value="<?php echo $atp_completed ?>"> Y or empty

  </table>

  <input type="Submit" name="submit" value="Enter information">
  <a href="javascript:history.go(-1)">BACK</a>

  </form>
et en particulier à la place de:
  <tr><td>Starting Date</td><td><input type="Date" name="atp_start" size="10" value="<?php echo $atp_start ?>">

  <tr><td>Closing Date</td><td><input type="Date" name="atp_end" size="10" value="<?php echo $atp_end ?>">
Merci et bonne année à toi et à ta famille

Posté : 01 janv. 2007, 22:34
par Xenon_54
Ce que tu peux faire, c'est afficher 2 calendriers pour tes dates de début et fin.

Ensuite, lors de la sélection de la date, tu peux récupérer la date et l'afficher dans ton input text. Lors de la soumission, tu pourras alors faire UPDATE avec la valeur.

Donc cet exemple pourrait t'intéresser:
http://developer.yahoo.com/yui/examples ... nts/1.html

Tu peux initialiser la date ainsi:
http://pub.generationphp.net/yui-calendar.html

Merci Xenon 54

Posté : 01 janv. 2007, 23:26
par daplus
Trouves-tu mon calendrier en PHP inutilisable?

Celui de Yahoo est-il plus facile à utiliser?
Si oui dois-je l'insérer avec un lien manuel ou une image qui renvoie à une autre page?

Si je prend celui de yahoo, je dois installer quels fichiers sur mon serveur?

Le .dll complet fait 6 MB zippé.

Que veut dire render?

Que veut dire fired? J'en connais deux significations: mis à la porte d'un job ou bien mettre le feu.

Merci de ton aide

Posté : 01 janv. 2007, 23:49
par Xenon_54
Si je comprends bien, tu renvoies le visiteur sur une nouvelle page pour sélectionner la date. Or, cela te fait quitter le formulaire actuel et les valeurs sont perdus.

Il faut soit:

- Ouvrir une page avec ton script et retourner la date sélectionner dans le champ de la fenêtre appellante pour ensuite fermer le popup.

- Soit afficher un calendrier javascript qui s'affichera par dessus ton form afin de faciliter la sélection de la date dans le champ.

Je viens à l'instant d'intégrer moi-même un calendrier YUI à une application que je développe pour un intranet et c'est vraiment intéressant et facile d'utilisation.

Dans mon cas, j'ai mis 3 selects (form) sur la page avec l'année, le mois et le jour. J'inclue un icone à coté des 3 selects afin d'ouvrir le calendrier javascript. Lorsque la date est sélectionnée dans le calendrier, le mois, l'année et le jour sont automatiquement sélectionnés dans les 3 selects.

Donc ton problème reste soir à:
- ouvrir une popup avec un calendrier généré par PHP comme tu le fais et récupérer la valeur dans ton input. Et ce, afin de ne pas perdre les valeurs actuels.
- Utiliser un calendrier javascript comme expliqué précédemment.