X-Git-Url: http://olivier.miskin.fr/git/?a=blobdiff_plain;f=action%2Fexporter_souscriptions.php;h=620cacfa851e2910d0f6f90f0a15546b4342c8e8;hb=df311c2591aa33a1a73fea988d05ac1b10267617;hp=85276a9c11c1d38410facab4c2a11a3ac50b76cb;hpb=c57f3b8b837367f7bb93ac84f9605202fe6e8c6c;p=spip_souscriptions.git diff --git a/action/exporter_souscriptions.php b/action/exporter_souscriptions.php index 85276a9..620cacf 100644 --- a/action/exporter_souscriptions.php +++ b/action/exporter_souscriptions.php @@ -6,11 +6,15 @@ function action_exporter_souscriptions_dist($arg=null) { * $arg contient les différents arguments, séparés par des '/'. Une * fois passés dans la fonctions split, il se présente de la manière * suivante : - * argument en position 1 : 'paye' ou 'tous' - * argument en position 2 : type de souscription (dons, adhesion) + * + * argument en position 1 : 'paye', 'commande', 'erreur' ou 'tous' + * argument en position 2 : type de souscription ('dons', + * 'adhesion') + * argument en position 3 : identifiant de la campagne + * argument en position 4 : date de début (au format timestamp) + * argument en position 5 : date de fin (au format timestamp) */ - /* FIXME: permettre de selectionner les exports */ /* FIXME: améliorer la jointure... */ if (is_null($arg)) { @@ -19,70 +23,99 @@ function action_exporter_souscriptions_dist($arg=null) { } /* Vérification des droits de l'utilisateur. */ - if(!autoriser("exporter", "souscriptiondon", '')) { + if(!autoriser("exporter", "souscription", '')) { include_spip('inc/minipres'); echo minipres(); exit; } - $arg = explode("/", $arg); + try { + $arg = explode("/", $arg); - $type_statut = $arg[0]; - $type_souscription = $arg[1]; + if(sizeof($arg) != 5) + throw new Exception(); + + $type_souscription = $arg[0]; + if($type_souscription && !in_array($type_souscription, array('don', 'adhesion'))) + throw new Exception(); + + $statut = $arg[1]; + if($statut && !in_array($statut, array('paye', 'commande', 'erreur'))) + throw new Exception(); + + $id_campagne = $arg[2]; + if($id_campagne && !ctype_digit($id_campagne)) + throw new Exception(); + + $date_debut = $arg[3]; + $date_fin = $arg[4]; + + if(($date_debut && !ctype_digit($date_debut)) || ($date_fin && !ctype_digit($date_fin))) + throw new Exception(); + } + catch(Exception $e) { + include_spip('inc/minipres'); + echo minipres(); + exit; + } /* Préparation de la requête */ $select = "id_souscription, courriel, type_souscription," ."montant, reglee, spip_transactions.statut, date_paiement, mode, autorisation_id," - ."nom, prenom, adresse, code_postal, ville, pays, telephone, recu_fiscal, envoyer_info, date_souscription," + ."nom, prenom, adresse, code_postal, ville, pays, telephone, recu_fiscal, envoyer_info, informer_comite_local, date_souscription," ."spip_souscription_campagnes.id_souscription_campagne, titre"; $from = "spip_souscriptions LEFT JOIN spip_transactions USING(id_transaction) LEFT JOIN spip_souscription_campagnes USING(id_souscription_campagne)"; $where = array(); if($type_souscription) $where[] = "type_souscription='$type_souscription'"; - else - $type_souscription = "tous"; - - if($type_statut == "payes") { - $where[] = "reglee='oui'"; - } - elseif($type_statut == "tous") { - /* Afficher toutes les transactions du type demandé */ - } - else { - include_spip('inc/minipres'); - echo minipres("Argument invalide"); - exit; + if($statut) { + if($statut == "paye") + $where[] = "reglee='oui'"; + elseif($statut == "commande") + $where[] = "spip_transactions.statut='commande'"; + elseif($statut == "erreur") + $where[] = "spip_transactions.statut like 'echec%'"; } + if($id_campagne) + $where[] = "spip_souscription_campagnes.id_souscription_campagne = '$id_campagne'"; + + if($date_debut) + $where[] = "date_souscription > '" . date ("Y-m-d 00:00:00", $date_debut) . "'"; + + if($date_fin) + $where[] = "date_souscription < '" . date ("Y-m-d 23:59:59", $date_fin) . "'"; + $row = sql_select($select, $from, $where); - $entete = array("ID du don", - "Courriel", - "Type de souscription", - "Montant", - "Reglée", - "Statut", - "Date de paiement", - "Mode de paiement", - "ID de l'autorisation", - "Nom", - "Prénom", - "Adresse", - "Code Postal", - "Ville", - "Pays", - "Téléphone", - "Souhaite reçu fiscal", - "Souhaite être informé", - "Date don", - "ID Campagne", - "Titre de la campagne"); + $entete = array(_T("souscription:label_exporter_entete_id_don"), + _T("souscription:label_exporter_entete_courriel"), + _T("souscription:label_exporter_entete_type_souscription"), + _T("souscription:label_exporter_entete_montant"), + _T("souscription:label_exporter_entete_reglee"), + _T("souscription:label_exporter_entete_statut"), + _T("souscription:label_exporter_entete_date_paiement"), + _T("souscription:label_exporter_entete_mode_paiement"), + _T("souscription:label_exporter_entete_id_autorisation"), + _T("souscription:label_exporter_entete_nom"), + _T("souscription:label_exporter_entete_prenom"), + _T("souscription:label_exporter_entete_adresse"), + _T("souscription:label_exporter_entete_code_postal"), + _T("souscription:label_exporter_entete_ville"), + _T("souscription:label_exporter_entete_pays"), + _T("souscription:label_exporter_entete_telephone"), + _T("souscription:label_exporter_entete_recu_fiscal"), + _T("souscription:label_exporter_entete_informer"), + _T("souscription:label_exporter_entete_informer_comite_local"), + _T("souscription:label_exporter_entete_date_don"), + _T("souscription:label_exporter_entete_id_campagne"), + _T("souscription:label_exporter_entete_titre_campagne")); /* Utilisation de la fonction exporter_csv de Bonux */ $exporter_csv = charger_fonction('exporter_csv', 'inc/', true); - $exporter_csv("souscriptions_${type_souscription}_${type_statut}", $row, ',', $entete); + $exporter_csv("souscriptions", $row, ',', $entete); exit(); }