IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

[Dates] Pb récupération de date du calendrier


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Inscrit en
    Mai 2007
    Messages
    177
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 177
    Points : 65
    Points
    65
    Par défaut [Dates] Pb récupération de date du calendrier
    Bonjour,

    Je suis totalement novice en javascript, et du coup je préfèrerais trouver une solution en php, cependant je pense que c'est impossible.
    Voilà mes deux problèmes :

    J'ai une page de recherche : Search.html :

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
    		<div id="contenu">
    			<p>	
    				<FORM action="Results.php" method="post">
    					<table width=640px>
    						<tr>
    							<td>Complaint number : <br>(year - number) </td>
    							<td><INPUT TYPE=text NAME=CompNb1 size=5 maxlength=4> - <INPUT TYPE=text NAME=CompNb2 size=5 maxlength=4></td>
    						</tr>
    						<tr>
    							<td width=25%><br>Complainant name : </td>
    							<td width=75%><br><INPUT TYPE=text NAME=CompName size=30></td>
    						</tr>
    					</table>
     
    					<table width=100%>
    						<tr>
    							<td width=25%>Status : 
    								<select name=status>
    									<option value="%"></option>
    									<option value="Op">Opened</option> 
    									<option value="UI">Under investigation</option> 
    									<option value="SP">Solution proposed</option>
    									<option value="SA">Solution applied</option> 
    									<option value="Cl">Closed</option>
    								</select>
    							</td>
    							<td width=27%>Problem type : 
    								<select name=problemType>
    									<option value="%"></option>
    									<option value="NEP">No existing process</option> 
    									<option value="PNC">Process not cleard</option> 
    									<option value="PNA">Process not applied</option>
    									<option value="Del">Delay</option> 
    									<option value="Oth">Other</option> 
    								</select>
    							</td>
    							<td width=15%>Origin : 
    								<br><select name=natco>
    									<option value="%"></option>
    									<option value="CE">CE</option> 
    									<option value="AD">A-D</option> 
    									<option value="AE">A-E</option>
    									<option value="AF">A-F</option> 
    									<option value="AU">A-UK</option>
    								</select>
    							</td>
    							<td width=25%>LOS :  
    								<br><select name=los>
    									<option value="%"></option>
    									<option value="DM">DM</option> 
    									<option value="SD">SD</option> 
    									<option value="RM">RM</option>
    									<option value="Ot">Other</option> 
    								</select>
    							</td>
    						</tr>
    					</table>
    					<br>
    					<table>
    						<tr>
    							<td width=25%>Complaint reception date : <br><i></td>
    							<td width=75%>between the <INPUT TYPE=date NAME=date1 size=6 maxlength=10> and <INPUT TYPE=date NAME=date2 size=6 maxlength=10></td>
    						</tr>
    						<tr>
    							<td><br><INPUT TYPE=submit VALUE="      Ok      "></td>
    							<td><br><i>Help : The date must be seized in the form YYYY-MM-DD</i></td>
    							<td></td>
    							<td></td>
    						<tr>
    					</table>
    				</FORM>
    			</p>
    		</div>

    Et j'ai donc une saisie de deux dates pour lesquelles je souhaiterais gérer un calendrier.
    Voilà le code de mon calendrier : calendar.php :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
     
    <html>
    <head>
    <style>
    div#calendar th
    			{
    				color : darkblue;
    				font-size:13;
    				font-family:Helvetica;
    				font-weight:400;
    				text-decoration: none ;
    			}
     
    			div#calendar th a
    			{
    				color : darkblue;
    				font-size:13;
    				font-family:Helvetica;
    				font-weight:400;
    				text-decoration: none ;
    			}
     
     
    </style>
    </head>
    <body>
     
    <?php
    //Creating general vars
    $year = date("Y");
    if(!isset($_GET['month'])) $monthnb = date("n");
    else {
        $monthnb = $_GET['month'];
        $year = $_GET['year'];
        if($monthnb <= 0) {
            $monthnb = 12;
            $year = $year - 1;
        }
        elseif($monthnb > 12) {
            $monthnb = 1;
            $year = $year + 1;
        }
    }
    $day = date("w");
    $nbdays = date("t", mktime(0,0,0,$monthnb,1,$year));
    $firstday = date("w",mktime(0,0,0,$monthnb,1,$year));
     
    //Replace the number of the day by its french name
    $daytab[1] = 'Mon';
    $daytab[2] = 'Tue';
    $daytab[3] = 'Wed';
    $daytab[4] = 'Thu';
    $daytab[5] = 'Fri';
    $daytab[6] = 'Sat';
    $daytab[7] = 'Sun';
     
    //Build the calendar table
    $calendar = array();
    $z = (int)$firstday;
    if($z == 0) $z =7;
    for($i = 1; $i <= ($nbdays/5); $i++){
        for($j = 1; $j <= 7 && $j-$z+1+(($i*7)-7) <= $nbdays; $j++){
            if($j < $z && ($j-$z+1+(($i*7)-7)) <= 0){
                    $calendar[$i][$j] = null;
            }
            else {
                $calendar[$i][$j] = $j-$z+1+(($i*7)-7);            
            }
        }
    }
     
    //Replace the number of the month by its french name
    switch($monthnb) {
        case 1: $month = 'January'; break;
        case 2: $month = 'February'; break;
        case 3: $month = 'March'; break;
        case 4: $month = 'April'; break;
        case 5: $month = 'May'; break;
        case 6: $month = 'June'; break;
        case 7: $month = 'July'; break;
        case 8: $month = 'August'; break;
        case 9: $month = 'September';    break;
        case 10: $month = 'October'; break;
        case 11: $month = 'November';    break;
        case 12: $month = 'December';    break;
    }
    ?>
    <div id="calendar">
        <table width=25% border=1>
            <tr>
                <th><span class="linkcal"><a href="calendar.php?month=<?php echo $monthnb - 1; ?>&year=<?php echo $year; ?>"><img src='img/bef.bmp'></a></span></th>
                <th colspan="5" class="headcal"><b><?php echo($month.' '.$year);  ?></b></th>
                <th><span class="linkcal"><a href="calendar.php?month=<?php echo $monthnb + 1; ?>&year=<?php echo $year; ?>"><img src='img/aft.bmp'></a></span></th>
            </tr>
            <?php
                echo('<tr>');
                for($i = 1; $i <= 7; $i++){
                    echo('<th width=5%><i>'.$daytab[$i].'</i></th>');
                }
                echo('</tr>');
                for($i = 1; $i <= count($calendar); $i++) {
                    echo('<tr>');
                    for($j = 1; $j <= 7 && $j-$z+1+(($i*7)-7) <= $nbdays; $j++){
                        if($j-$z+1+(($i*7)-7) == date("j") && $monthnb == date("n") && $year == date("Y")) echo('<th class="current"><a href="...">'.$calendar[$i][$j].'</a></th>');
                        else echo('<th><a href=\"\">'.$calendar[$i][$j].'</a></th>');
                    }
                    echo('</tr>');
                }
            ?>
        </table>
    </div>
    </body>
    </html>
    Seulement je voudrais savoir comment récupérer le jour, le mois et l'année, si on clique sur un des jour (j'ai mis "..." dans le a href car je ne sais pas comment le gérer)?

    De plus je voudrais mettre en place une gestion assez commune du calendrier. Sur ma page de recherche à côté des input de dates, je voudrais avoir une petit icône représentant un calendrier (ça je saurais faire je pense). Mais une fois cliqué sur cette icône je souhaiterais qu'un popup s'ouvre avec mon calendrier. Et qu'une fois avoir cliqué sur le jour du calendrier, que le popup se ferme, et renvoie dans le input de la date associée, l'année-le mois-le jour sélectionné dans le calendrier.
    Est ce possible ?

  2. #2
    Rédacteur
    Avatar de Yoshio
    Homme Profil pro
    Inscrit en
    Septembre 2005
    Messages
    1 732
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 732
    Points : 2 853
    Points
    2 853
    Par défaut
    Passe un paramètre via $_GET dans l'url.

    Ex :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <a href="index.php?date=10">10</a>
    tu recupère la valeur par $_GET['date'].

  3. #3
    Membre du Club
    Inscrit en
    Mai 2007
    Messages
    177
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 177
    Points : 65
    Points
    65
    Par défaut
    Merci mais comme fait on puisque c'est une variable qui change tout le temps et que donc on ne peut pas la fixer à 10 ?

  4. #4
    Membre du Club
    Inscrit en
    Mai 2007
    Messages
    177
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 177
    Points : 65
    Points
    65
    Par défaut
    Voilà le code que j'ai dans mon calendar.php :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
     
    <html>
    <head>
    <style>
    div#calendar th
    			{
    				color : darkblue;
    				font-size:13;
    				font-family:Helvetica;
    				font-weight:400;
    				text-decoration: none ;
    			}
     
    			div#calendar th a
    			{
    				color : darkblue;
    				font-size:13;
    				font-family:Helvetica;
    				font-weight:400;
    				text-decoration: none ;
    			}
     
     
    </style>
    </head>
    <body>
     
    <?php
    //Creating general vars
    $year = date("Y");
    if(!isset($_GET['month'])) $monthnb = date("n");
    else {
        $monthnb = $_GET['month'];
        $year = $_GET['year'];
        if($monthnb <= 0) {
            $monthnb = 12;
            $year = $year - 1;
        }
        elseif($monthnb > 12) {
            $monthnb = 1;
            $year = $year + 1;
        }
    }
    $day = date("w");
    $nbdays = date("t", mktime(0,0,0,$monthnb,1,$year));
    $firstday = date("w",mktime(0,0,0,$monthnb,1,$year));
     
    //Replace the number of the day by its french name
    $daytab[1] = 'Mon';
    $daytab[2] = 'Tue';
    $daytab[3] = 'Wed';
    $daytab[4] = 'Thu';
    $daytab[5] = 'Fri';
    $daytab[6] = 'Sat';
    $daytab[7] = 'Sun';
     
    //Build the calendar table
    $calendar = array();
    $z = (int)$firstday;
    if($z == 0) $z =7;
    for($i = 1; $i <= ($nbdays/5); $i++){
        for($j = 1; $j <= 7 && $j-$z+1+(($i*7)-7) <= $nbdays; $j++){
            if($j < $z && ($j-$z+1+(($i*7)-7)) <= 0){
                    $calendar[$i][$j] = null;
            }
            else {
                $calendar[$i][$j] = $j-$z+1+(($i*7)-7);            
            }
        }
    }
     
    //Replace the number of the month by its french name
    switch($monthnb) {
        case 1: $month = 'January'; break;
        case 2: $month = 'February'; break;
        case 3: $month = 'March'; break;
        case 4: $month = 'April'; break;
        case 5: $month = 'May'; break;
        case 6: $month = 'June'; break;
        case 7: $month = 'July'; break;
        case 8: $month = 'August'; break;
        case 9: $month = 'September';    break;
        case 10: $month = 'October'; break;
        case 11: $month = 'November';    break;
        case 12: $month = 'December';    break;
    }
    ?>
    <div id="calendar">
        <table width=25% border=1>
            <tr>
                <th><span class="linkcal"><a href="calendar.php?month=<?php echo $monthnb - 1; ?>&year=<?php echo $year; ?>"><img src='img/bef.bmp'></a></span></th>
                <th colspan="5" class="headcal"><b><?php echo($month.' '.$year);  ?></b></th>
                <th><span class="linkcal"><a href="calendar.php?month=<?php echo $monthnb + 1; ?>&year=<?php echo $year; ?>"><img src='img/aft.bmp'></a></span></th>
            </tr>
            <?php
                echo('<tr>');
                for($i = 1; $i <= 7; $i++){
                    echo('<th width=5%><i>'.$daytab[$i].'</i></th>');
                }
                echo('</tr>');
                for($i = 1; $i <= count($calendar); $i++) {
                    echo('<tr>');
                    for($j = 1; $j <= 7 && $j-$z+1+(($i*7)-7) <= $nbdays; $j++){
                        if($j-$z+1+(($i*7)-7) == date("j") && $monthnb == date("n") && $year == date("Y")) 
    					{
    						$date=$calendar[$i][$j];
    						echo('<th class="current"><a href="Search.html?date=$date" target=_parent>'.$calendar[$i][$j].'</a></th>');
    					}
                        else echo('<th><a href="Search.php?date=$date">'.$calendar[$i][$j].'</a></th>');
                    }
                    echo('</tr>');
                }
            ?>
        </table>
    </div>
    </body>
    </html>
    Et celui dans mon search.html qui est censé récupérer la variable de la date !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
     
    		<div id="contenu">
    			<p>	
    				<FORM action="Results.php" method="post">
    					<table width=640px>
    						<tr>
    							<td>Complaint number : <br>(year - number) </td>
    							<td><INPUT TYPE=text NAME=CompNb1 size=5 maxlength=4> - <INPUT TYPE=text NAME=CompNb2 size=5 maxlength=4></td>
    						</tr>
    						<tr>
    							<td width=25%><br>Complainant name : </td>
    							<td width=75%><br><INPUT TYPE=text NAME=CompName size=30></td>
    						</tr>
    					</table>
     
    					<table width=100%>
    						<tr>
    							<td width=25%>Status : 
    								<select name=status>
    									<option value="%"></option>
    									<option value="Opened">Opened</option> 
    									<option value="Under investigation">Under investigation</option> 
    									<option value="Solution proposed">Solution proposed</option>
    									<option value="Solution applied">Solution applied</option> 
    									<option value="Closed">Closed</option>
    								</select>
    							</td>
    							<td width=27%>Problem type : 
    								<select name=problemType>
    									<option value="%"></option>
    									<option value="No existing process">No existing process</option> 
    									<option value="Process not clear">Process not clear</option> 
    									<option value="Process not applied">Process not applied</option>
    									<option value="Delay">Delay</option> 
    									<option value="Other">Other</option> 
    								</select>
    							</td>
    							<td width=15%>Origin : 
    								<br><select name=natco>
    									<option value="%"></option>
    									<option value="CE">CE</option> 
    									<option value="A-D">A-D</option> 
    									<option value="A-E">A-E</option>
    									<option value="A-F">A-F</option> 
    									<option value="A-UK">A-UK</option>
    								</select>
    							</td>
    							<td width=25%>LOS :  
    								<br><select name=los>
    									<option value="%"></option>
    									<option value="DM">DM</option> 
    									<option value="SD">SD</option> 
    									<option value="RM">RM</option>
    									<option value="Other">Other</option> 
    								</select>
    							</td>
    						</tr>
    					</table>
    					<br>
    					<table>
    						<tr>
    							<? 
    							$date=$_GET['date'];
    							echo"$date"; 
    							?>
    							<td width=25%>Complaint reception date : <br><i></td>
    							<td width=75%>between the <INPUT TYPE=date NAME=date1 size=6 maxlength=10> <a href="calendar.php" target=_blank><img src='img/calendar.bmp'></a> and <INPUT TYPE=date NAME=date2 size=6 maxlength=10> <a href="calendar.php" target=_blank><img src='img/calendar.bmp'></a></td>
    						</tr>
    						<tr>
    							<td><br><INPUT TYPE=submit VALUE="      Ok      "></td>
    							<td><br><i>Help : The date must be seized in the form YYYY-MM-DD</i></td>
    							<td></td>
    							<td></td>
    						<tr>
    					</table>
    				</FORM>
    			</p>
    		</div>

  5. #5
    Rédacteur
    Avatar de Yoshio
    Homme Profil pro
    Inscrit en
    Septembre 2005
    Messages
    1 732
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 732
    Points : 2 853
    Points
    2 853
    Par défaut
    Je n'ai pas lu ton code mais à chaque jour correspondra un nombre différent.
    Tu construit pas ton calendrier à la main mais avec des boucle donc pour faire changer le 10 bah tu prend la variable de ta boucle.

    Il te suffit ensuite dans ton search de faire un truc du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    if (isset($_GET['day']) && isset($_GET['month']) ... )
    {
        $day = intval($_GET['day']);
        $month = ...
    }
    else
    {
        $day = 1;
        ...
    }
    pour récupéré la date sur laquel on a cliquer je voit pas ou est le problème ?

  6. #6
    Membre du Club
    Inscrit en
    Mai 2007
    Messages
    177
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 177
    Points : 65
    Points
    65
    Par défaut
    Merci beaucoup ça m'a beaucoup aidé et du coup je suis arrivée à l'adapter à mon code. C'est chouette !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [11gR2] Récupération de dates par rapport à la date du jour
    Par juju05 dans le forum SQL
    Réponses: 2
    Dernier message: 15/10/2014, 16h06
  2. [PowerShell] Récupération de dates par rapport à la date du jour
    Par dimdelille dans le forum Scripts/Batch
    Réponses: 0
    Dernier message: 28/01/2013, 12h31
  3. Réponses: 2
    Dernier message: 21/03/2007, 16h06
  4. [Date/Heure] récupération d'une heure en base
    Par Rayley dans le forum JDBC
    Réponses: 12
    Dernier message: 04/01/2006, 20h34
  5. récupération des dates d'un fichier
    Par Bleuarff dans le forum Langage
    Réponses: 6
    Dernier message: 22/11/2005, 01h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo