[SPIP] ~maj v2.1.25-->2.1.26
[velocampus/web/www.git] / www / ecrire / action / dater.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 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15 // http://doc.spip.org/@action_dater_dist
16 function action_dater_dist() {
17
18 $securiser_action = charger_fonction('securiser_action', 'inc');
19 $arg = $securiser_action();
20
21 if (!preg_match(",^\W*(\d+)\W(\w*)$,", $arg, $r)) {
22 spip_log("action_dater_dist $arg pas compris");
23 }
24 else action_dater_post($r);
25 }
26
27 // http://doc.spip.org/@action_dater_post
28 function action_dater_post($r)
29 {
30 include_spip('inc/date');
31 $type = $r[2];
32 $id = $r[1];
33 if (!isset($_REQUEST['avec_redac'])) {
34 $date = dater_table($id, $type);
35 } else {
36 if (_request('avec_redac') == 'non')
37 $annee_redac = $mois_redac = $jour_redac = $heure_redac = $minute_redac = 0;
38 else {
39 $annee_redac = _request('annee_redac');
40 $mois_redac = _request('mois_redac');
41 $jour_redac = _request('jour_redac');
42 $heure_redac = _request('heure_redac');
43 $minute_redac = _request('minute_redac');
44
45 if ($annee_redac<>'' AND $annee_redac < 1001)
46 $annee_redac += 9000;
47 }
48
49 $date = format_mysql_date($annee_redac, $mois_redac, $jour_redac, $heure_redac, $minute_redac);
50 include_spip('inc/modifier');
51 revision_article($r[1],array("date_redac" => $date));
52 }
53
54 // a priori fait doublon avec instituer_xx utilise dans dater_table()
55 // mais on laisse pour ne pas introduire de bug dans cette branche
56 if (($type == 'article')
57 AND $GLOBALS['meta']["post_dates"] == "non") {
58 $t = sql_fetsel("statut, id_rubrique", "spip_articles", "id_article=$id");
59 if ($t['statut'] == 'publie') {
60 include_spip('inc/rubriques');
61 if (strtotime($date) > time())
62 depublier_branche_rubrique_if($t['id_rubrique']);
63 else
64 publier_branche_rubrique($t['id_rubrique']);
65 calculer_prochain_postdate();
66 }
67 }
68 }
69
70 function dater_table($id, $type)
71 {
72 $trouver_table = charger_fonction('trouver_table', 'base');
73 $nom = table_objet($type);
74 $desc = $trouver_table($nom);
75 $table = $desc['table'];
76 $col_id = @$desc['key']["PRIMARY KEY"];
77 if (!$table OR !$col_id) {
78 spip_log("action_dater: table $type ?");
79 return;
80 }
81 include_spip('public/interfaces');
82 $champ = @$GLOBALS['table_date'][$nom];
83 if (!$champ) $champ = 'date';
84 $date = format_mysql_date(_request('annee'), _request('mois'), _request('jour'), _request('heure'), _request('minute'));
85 // utiliser instituer_xx si dispo
86 if (include_spip('action/editer_'.$type) AND function_exists($f='instituer_'.$type)){
87 $f($id,array($champ => $date));
88 }
89 else
90 sql_updateq($table, array($champ => $date), "$col_id=$id");
91 return $date;
92 }
93 ?>