[SPIP] ~2.1.12 -->2.1.25
[velocampus/web/www.git] / www / ecrire / inc / date.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 //
14 if (!defined('_ECRIRE_INC_VERSION')) return;
15
16 // http://doc.spip.org/@my_sel
17 function my_sel($num, $tex, $comp) {
18 return "<option value='$num'" . (($num != $comp) ? '' : " selected='selected'") .
19 ">$tex</option>\n";
20 }
21
22 // http://doc.spip.org/@format_mysql_date
23 function format_mysql_date($annee=0, $mois=0, $jour=0, $h=0, $m=0, $s=0) {
24 $annee = sprintf("%04s",$annee);
25 $mois = sprintf("%02s",$mois);
26
27 if ($annee == "0000") $mois = 0;
28 if ($mois == "00") $jour = 0;
29
30 return sprintf("%04u",$annee) . '-' . sprintf("%02u",$mois) . '-'
31 . sprintf("%02u",$jour) . ' ' . sprintf("%02u",$h) . ':'
32 . sprintf("%02u",$m) . ':' . sprintf("%02u",$s);
33 }
34
35
36 // http://doc.spip.org/@afficher_mois
37 function afficher_mois($mois, $attributs, $autre=false){
38 return
39 "<select $attributs>\n" .
40 (!$autre ? '' : my_sel("00",_T('mois_non_connu'),$mois)) .
41 my_sel("01", _T('date_mois_1'), $mois) .
42 my_sel("02", _T('date_mois_2'), $mois) .
43 my_sel("03", _T('date_mois_3'), $mois) .
44 my_sel("04", _T('date_mois_4'), $mois) .
45 my_sel("05", _T('date_mois_5'), $mois) .
46 my_sel("06", _T('date_mois_6'), $mois) .
47 my_sel("07", _T('date_mois_7'), $mois) .
48 my_sel("08", _T('date_mois_8'), $mois) .
49 my_sel("09", _T('date_mois_9'), $mois) .
50 my_sel("10", _T('date_mois_10'), $mois) .
51 my_sel("11", _T('date_mois_11'), $mois) .
52 my_sel("12", _T('date_mois_12'), $mois) .
53 "</select>\n";
54 }
55
56 // http://doc.spip.org/@afficher_annee
57 function afficher_annee($annee, $attributs, $debut=null, $fin=null) {
58
59 if (!isset($debut)) $debut = $annee - 8;
60 if (!isset($fin)) $fin = max($annee, date('Y')) + 3;
61
62 if ($fin - $debut > 15)
63 return "<input type='text' value='$annee' size='4' $attributs />";
64
65 $res = ($annee > $debut) ? '' : my_sel($annee,$annee,$annee);
66 for ($i=$debut; $i < $fin; $i++) {
67 $res .= my_sel($i,$i,$annee);
68 }
69 // plus de choix... on met une vieille date arbitraire, et au tour
70 // suivant on aura un champ input a la place du select (pas genial...)
71 $res .= my_sel(date('Y')-10,'&nbsp; ...',$annee);
72 return "<select $attributs>\n$res</select>\n";
73 }
74
75 // http://doc.spip.org/@afficher_jour
76 function afficher_jour($jour, $attributs, $autre=false){
77
78 $res = (!$autre ? "" : my_sel("00",_T('jour_non_connu_nc'),$jour));
79 for($i=1;$i<32;$i++){
80 if ($i<10){$aff="&nbsp;".$i;}else{$aff=$i;}
81 $res .= my_sel($i,$aff,$jour);
82 }
83 return "<select $attributs>\n$res</select>\n";
84 }
85
86 // http://doc.spip.org/@afficher_heure
87 function afficher_heure($heure, $attributs, $autre=false){
88 $res = '';
89 for($i=0;$i<=23;$i++){
90 $aff = sprintf("%02s", $i);
91 $res .= my_sel($i,$aff,$heure);
92 }
93 return "<select $attributs>\n$res</select>\n";
94 }
95
96 // http://doc.spip.org/@afficher_minute
97 function afficher_minute($minute, $attributs, $autre=false){
98 $res = '';
99 for($i=0;$i<=59;$i+=5){
100 $aff = sprintf("%02s", $i);
101 $res .= my_sel($i,$aff,$minute);
102
103 if ($minute>$i AND $minute<$i+5)
104 $res .= my_sel($minute,sprintf("%02s", $minute),$minute);
105 }
106 return "<select $attributs>\n$res</select>\n";
107 }
108
109
110 // http://doc.spip.org/@afficher_jour_mois_annee_h_m
111 function afficher_jour_mois_annee_h_m($date, $heures, $minutes, $suffixe='')
112 {
113 return
114 afficher_jour(jour($date), "name='jour$suffixe' id='jour$suffixe' size='1' class='verdana1'") .
115 afficher_mois(mois($date), "name='mois$suffixe' id='mois$suffixe' size='1' class='verdana1'") .
116 afficher_annee(annee($date), "name='annee$suffixe' id='annee$suffixe' class='verdana1'", date('Y')-1) .
117 "&nbsp; <input type='text' class='verdana1' name='heures$suffixe' id='heures$suffixe' value=\"".$heures."\" size='3'/>&nbsp;".majuscules(_T('date_mot_heures'))."&nbsp;" .
118 "<input type='text' class='verdana1' name='minutes$suffixe' id='minutes$suffixe' value=\"$minutes\" size='3'/>";
119 }
120
121 ?>