Ajout d'un fichier .gitignore
[spip_souscriptions.git] / action / editer_souscription_don.php
1 <?php
2 if (!defined("_ECRIRE_INC_VERSION")) return;
3
4 function action_editer_souscription_don_dist($arg=null) {
5   if (is_null($arg)){
6     $securiser_action = charger_fonction('securiser_action', 'inc');
7     $arg = $securiser_action();
8   }
9
10   if (!$id_souscription_don = intval($arg)){
11     $id_souscription_don = don_inserer();
12   }
13
14   if (!$id_souscription_don)
15     return array(0,'');
16
17   $err = don_modifier($id_souscription_don);
18
19   return array($id_souscription_don, $err);
20 }
21
22
23 /**
24  * Inserer une nouvelle donation en en base
25  *
26  * @return bool
27  */
28 function don_inserer() {
29
30   $champs = array('date_souscription' => date('Y-m-d H:i:s'));
31         
32   // Envoyer aux plugins
33   $champs = pipeline('pre_insertion',
34                      array('args' => array('table' => 'spip_souscription_dons'),
35                            'data' => $champs)
36                      );
37
38   $id_souscription_don = sql_insertq("spip_souscription_dons", $champs);
39
40   pipeline('post_insertion',
41            array('args' => array('table' => 'spip_souscription_dons',
42                                  'id_objet' => $id_souscription_don),
43                  'data' => $champs)
44            );
45
46   return $id_souscription_don;
47 }
48
49 /**
50  * Modifier une donation
51  *
52  * $c est un contenu (par defaut on prend le contenu via _request())
53  *
54  * @param int $id_souscription_don
55  * @param array|bool $set
56  * @return string
57  */
58 function don_modifier($id_souscription_don, $set=false) {
59   include_spip('inc/modifier');
60
61   $c = collecter_requests(
62                           // white list
63                           array('courriel',
64                                 'recu_fiscal',
65                                 'envoyer_info',
66                                 'prenom',
67                                 'nom',
68                                 'adresse',
69                                 'code_postal',
70                                 'ville',
71                                 'id_souscription_campagne',
72                                 'type_souscription'),
73                           // black list
74                           array('statut', 'date'),
75                           // donnees eventuellement fournies
76                           $set
77                           );
78
79
80   $inserer_transaction = charger_fonction('inserer_transaction', 'bank');
81   $id_transaction = $inserer_transaction(_request('montant'),
82                                          '', /* montant_ht */
83                                          '', /* id_auteur */
84                                          $id_souscription_don, /* auteur_id => id_souscription_don */
85                                          _request('courriel'));
86
87   if(!$id_transaction) {
88     return "Identifiant de transaction introuvable..."; /* FIXME: à rendre traduisible. */
89   }
90
91   $c = array_merge($c, array("id_transaction" => $id_transaction));
92
93   if($err = objet_modifier_champs('souscription_don', $id_souscription_don, array(), $c))
94     return $err;
95 }