fixes, fixes, fixes
authorx2000habouzit <x2000habouzit>
Thu, 8 Jul 2004 12:03:07 +0000 (12:03 +0000)
committerx2000habouzit <x2000habouzit>
Thu, 8 Jul 2004 12:03:07 +0000 (12:03 +0000)
migration of cyberpayment

etat_migration
htdocs/newsletter.php
htdocs/paiement/cyberpaiement_retour.php [new file with mode: 0644]
htdocs/paiement/index.php [new file with mode: 0644]
include/cyberpaiement.inc.php [new file with mode: 0644]
plugins/insert.mkStats.php
templates/paiment/index.tpl [new file with mode: 0644]

index af0ca0d..adc3491 100644 (file)
@@ -17,7 +17,7 @@
 Etat  | Ancien nom                                                               | Nouveau nom
 ------+-[ admin ]---------------------------------+----------------
 ;        | admin/admin_trombino.php                              | 
-;        | admin/comptesPOP.php                                          | ???
+;!       | admin/comptesPOP.php                                          | ???
 ;        | admin/correction_adr.php                              | 
 ;        | admin/evenements.php                                          | 
 ;        | admin/homonymes.php                                           | 
@@ -42,10 +42,6 @@ Etat  | Ancien nom                                                             | Nouveau nom
 ;        | parselogN.php                                                         | stats/...
 ;        | parselogR.php                                                         | stats/...
 ;        | stats.php                                                             | stats/index.php
-------+-[ paiement ]------------------------------+----------------
-;        | paiement/cyberpaiement.inc.php                        | 
-;        | paiement/cyberpaiement_retour.php             | 
-;        | paiement/index.php                                            | 
 ------+-[ emails ... ]----------------------------+----------------
 ;        | routage-mail.php                                              | 
 ------+-[ inscription + mdp ]---------------------+----------------
@@ -104,6 +100,9 @@ x     | admin/utilisateurs.php                                        | - y'a encore du boulot pour que ca valide !
 x        | epouse.php                                                            | - non testé (flemme de faire des su ...)
 x        | parselog.php                                                          | stats/... (non testé, pas de logs sous la main)
 xx       | AccesPermanentOff.php                                         | cookie_off.php
+xx       | paiement/cyberpaiement.inc.php                        | dans include/
+xx       | paiement/cyberpaiement_retour.php             | -
+xx       | paiement/index.php                                            | -
 xx       | AccesPermanentOn.php                                          | cookie_on.php
 xx       | acces_redirect.php                                            | carva_redirect.php
 xx       | acces_smtp.php                                                        | -
index 84cb3a1..061e86d 100644 (file)
@@ -15,8 +15,8 @@ if (($res)&&(list($nl_date, $nl_titre, $nl_text) = mysql_fetch_row($res))) {
     $page->assign('nl_text', $nl_text);
 
     if (isset($_REQUEST['send_mail'])) {
-        require('mailer.inc.php');
-        $mymail = new mailer("info_newsletter@polytechnique.org",
+        require('diogenes.mailer.inc.php');
+        $mymail = new DiogenesMailer("info_newsletter@polytechnique.org",
                 $_SESSION['username']."@polytechnique.org",
                 "[polytechnique.org] ".$nl_titre);
         $mymail->addHeader("From: \"Equipe polytechnique.org\" <info_newsletter@polytechnique.org>");
diff --git a/htdocs/paiement/cyberpaiement_retour.php b/htdocs/paiement/cyberpaiement_retour.php
new file mode 100644 (file)
index 0000000..3f4a7c3
--- /dev/null
@@ -0,0 +1,121 @@
+<?php
+require("auto.prepend.inc.php");
+new_skinned_page('paiment/index.tpl', AUTH_MDP);
+
+require("diogenes.mailer.inc.php");
+
+/* en attendant PHP 4.2, on definit var_export */
+function var_exp(&$var) {
+  ob_start();
+  var_dump($var);
+  $ret = ob_get_contents();
+  ob_end_clean();
+  return $ret;
+}
+
+/* sort en affichant une erreur */
+function erreur($text) {
+  $text .= "\n\n".var_exp($_REQUEST);
+  $mymail = new DiogenesMailer("webmaster","web","erreur lors d'un télépaiement",false);
+  $mymail->setBody($text);
+  $mymail->send();
+  exit;
+}
+
+/* calcule la clé de Luhn d'un nombre */
+function luhn($nombre) {
+  $sum = 0;
+  for ($i = 0; $i < strlen($nombre); $i++) {
+    $digit = substr($nombre,$i,1);
+    if ($i % 2) {
+      if ($digit*2>9) 
+       $sum += 2*$digit - 9;
+      else
+        $sum += 2*$digit;
+    } else {
+      $sum += $digit;
+    }
+  }
+  return $sum % 10;
+}
+
+/* calcule la clé d'acceptation a partir de 5 champs */
+function cle_accept($d1,$d2,$d3,$d4,$d5)
+{
+  $m1 = luhn(strrev($d1.$d5));
+  $m2 = luhn(strrev($d2.$d5));
+  $m3 = luhn(strrev($d3.$d5));
+  $m4 = luhn(strrev($d4.$d5));
+  $n = $m1 + $m2 + $m3 + $m4;
+  $alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+  return substr($alpha,$n-1,1).$m1.$m2.$m3.$m4;
+}
+
+/* user id */
+$uid = clean_request('uid');
+/* reference banque (numero de transaction) */
+$champ901 = clean_request('CHAMP901');
+/* cle d'acceptation */
+$champ905 = clean_request('CHAMP905');
+/* code retour */
+$champ906 = clean_request('CHAMP906');
+/* email renvoye par la banque */
+$champ104 = clean_request('CHAMP104');
+/* reference complete de la commande */
+$champ200 = clean_request('CHAMP200');
+/* montant de la transaction */
+$champ201 = clean_request('CHAMP201');
+/* devise */
+$champ202 = clean_request('CHAMP202');
+$montant = "$champ201 $champ202";
+
+/* on extrait les informations sur l'utilisateur */
+$res = mysql_query("select a.prenom,a.nom,a.promo,a.username,FIND_IN_SET(i.flags,'femme') from auth_user_md5 as a inner join identification as i on a.matricule=i.matricule where a.user_id='$uid'");
+if (!list($prenom,$nom,$promo,$username,$femme) = mysql_fetch_row($res))
+  erreur("uid invalide");
+
+/* on extrait la reference de la commande */
+if (!ereg('-xorg-([0-9]+)$',$champ200,$matches))
+  erreur("référence de commande invalide");
+$ref = $matches[1];
+echo $ref;
+$res = mysql_query("select mail,text,confirmation from paiement.paiements where id='$ref'");
+if (!list($conf_mail,$conf_title,$conf_text) = mysql_fetch_row($res))
+  erreur("référence de commande inconnue");
+
+/* on extrait le code de retour */
+if ($champ906 != "0000") {
+  $res = mysql_query("select rcb.text,c.id,c.text from paiement.codeRCB as rcb left join paiement.codeC as c on rcb.codeC=c.id where rcb.id='$champ906'");
+  if (list($rcb_text,$c_id,$c_text) = mysql_fetch_row($res)) 
+    erreur("erreur lors du paiement : $c_text ($c_id)");
+  else
+    erreur("erreur inconnue lors du paiement");
+}
+
+/* on fait l'insertion en base de donnees */
+mysql_query("insert into paiement.transactions set id='$champ901',uid='$uid',ref='$ref',fullref='$champ200',montant='$montant',cle='$champ905'");
+
+/* on genere le mail de confirmation */
+$conf_text = str_replace("<prenom>",$prenom,$conf_text);
+$conf_text = str_replace("<nom>",$nom,$conf_text);
+$conf_text = str_replace("<promo>",$promo,$conf_text);
+$conf_text = str_replace("<montant>",$montant,$conf_text);
+$conf_text = str_replace("<salutation>",$femme ? "Chère" : "Cher",$conf_text);
+
+$mymail = new DiogenesMailer($conf_mail,$username,$conf_title,false,$conf_mail);
+$mymail->setBody($conf_text);
+$mymail->send();
+
+/* on envoie les details de la transaction à telepaiement@ */
+$mymail = new DiogenesMailer("webmaster","telepaiement",$conf_title,false);
+$msg = "utilisateur : $prenom $nom ($uid)\n".
+       "mail : $username@polytechnique.org\n\n".
+       "paiement : $conf_title ($conf_mail)\n".
+       "reference : $champ200\n".
+       "montant : $montant\n\n".
+       "dump de REQUEST:\n".
+       var_exp($_REQUEST);
+$mymail->setBody($msg);
+$mymail->send();
+
+?>
diff --git a/htdocs/paiement/index.php b/htdocs/paiement/index.php
new file mode 100644 (file)
index 0000000..b839d93
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+require("auto.prepend.inc.php");
+new_skinned_page('paiment/index.tpl', AUTH_MDP);
+require('profil.inc.php');
+setlocale(LC_NUMERIC,'fr_FR');
+
+
+// initialisation
+$op = isset($_REQUEST['op']) ? $_REQUEST['op'] : 'select';
+$methode = isset($_REQUEST['methode']) ? $_REQUEST['methode'] : 0;
+$erreur = Array();
+
+// on recupere les infos relatives a la transaction choisie
+$ref = isset($_REQUEST['ref']) ? $_REQUEST['ref'] : 0;
+$res = $globals->db->query("SELECT text,url,flags,mail,montant_min,montant_max,montant_def FROM paiement.paiements WHERE id=$ref");
+
+if (!list($ref_text,$ref_url,$ref_flags,$ref_mail,$montant_min,$montant_max,$montant_def) = mysql_fetch_row($res)) {
+    $erreur[] = "La transaction selectionnée n'est pas valide.";
+}
+$ref_flags = new flagset($ref_flags);
+
+if($ref_flags->hasflag('old')){
+    $erreur[] = "La transaction selectionnée est périmée.";
+    //Don x.org, toujours valable :)
+    $ref = 0;
+    $res = $globals->db->query("SELECT text,url,flags,mail,montant_min,montant_max,montant_def FROM paiement.paiements WHERE id=$ref");
+    if (!list($ref_text,$ref_url,$ref_flags,$ref_mail,$montant_min,$montant_max,$montant_def) = mysql_fetch_row($res)) {
+        $erreur[] = "La transaction selectionnée n'est pas valide.";
+    }
+    $ref_flags = new flagset($ref_flags);
+}
+
+// on remplace les points par des virgules
+$montant_min=strtr($montant_min,".",",");
+$montant_max=strtr($montant_max,".",",");
+$montant_def=strtr($montant_def,".",",");
+
+// on recupere les infos relatives à la methode choisie
+$methode = isset($_REQUEST['methode']) ? $_REQUEST['methode'] : 0;
+$res = $globals->db->query("SELECT include FROM paiement.methodes WHERE id=$methode");
+if (!list($methode_include) = mysql_fetch_row($res)) {
+    $erreur[] = "La méthode de paiement sélectionnée n'est pas valide.";
+}
+
+// verifications
+$montant = (($op=="submit") && isset($_REQUEST['montant'])) ? $_REQUEST['montant'] : $montant_def;
+$montant = strtr($montant, ".", ",");
+
+// on ajoute les centimes
+if (ereg("^[0-9]+$",$montant))
+$montant .= ",00";
+elseif (ereg("^[0-9]+,[0-9]$",$montant))
+$montant .= "0";
+
+// on verifie que le montant est bien formatté
+if (!ereg("^[0-9]+,[0-9]{2}$",$montant)) {
+    $erreur[] = "Montant invalide.";
+    $montant = $montant_def;
+}
+
+if ($montant < $montant_min) {
+    $erreur[] = "Montant inférieur au minimum autorisé ($montant_min).";
+    $montant = $montant_min;
+}
+
+if ($montant > $montant_max) {
+    $erreur[] = "Montant supérieur au maximum autorisé ($montant_max).";
+    $montant = $montant_max;
+}
+
+$page->assign('op',$op);
+$page->assign('erreur',$erreur);
+$page->assign('montant',$montant);
+
+$page->assign('methode',$methode);
+$page->assign('methode_include',$methode_include);
+
+$page->assign('ref',$ref);
+$page->assign('ref_url',$ref_url);
+
+$page->run();
+?>
diff --git a/include/cyberpaiement.inc.php b/include/cyberpaiement.inc.php
new file mode 100644 (file)
index 0000000..d02f020
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+
+global $baseurl,$ref_flags,$ref_text,$ref_mail,$ref,$montant,
+       $username, $nom, $prenom ;
+
+// on construit l'adresse de retour pour le robot de la banque
+$roboturl = str_replace("https://","http://",$baseurl)."/paiement/cyberpaiement_retour.php?uid={$_SESSION['uid']}&amp;CHAMPBPX";
+
+// on construit l'adresse de retour pour l'utilisateur
+$returnurl = "$baseurl/";
+if (! isset($_COOKIE[session_name()]))
+  $returnurl .= "?".SID;
+
+// on constuit la reference de la transaction
+$prefix = ($ref_flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
+$fullref = substr("$prefix-xorg-$ref",-15);
+
+// on recupere les infos sur l'utilisateur
+$res = mysql_query("select username, nom, prenom from auth_user_md5 where user_id={$_SESSION['uid']}");
+list($username,$nom,$prenom) = mysql_fetch_row($res);
+mysql_free_result($res);
+?>
+
+<form method="POST" action="https://ecom.cimetz.com/telepaie/cgishell.exe/epaie01.exe">
+<!-- infos commercant -->
+<input type="hidden" name="CHAMP000" value="510879" />
+<input type="hidden" name="CHAMP001" value="5965" />
+<input type="hidden" name="CHAMP002" value="5429159012" />
+<input type="hidden" name="CHAMP003" value="I" />
+<input type="hidden" name="CHAMP004" value="Polytechnique.org" />
+<input type="hidden" name="CHAMP005" value="<?php echo $roboturl; ?>" />
+<input type="hidden" name="CHAMP006" value="Polytechnique.org" />
+<input type="hidden" name="CHAMP007" value="<?php echo $returnurl; ?>" />
+<input type="hidden" name="CHAMP008" value="<?php echo $ref_mail; ?>" />
+<!-- infos client -->
+<input type="hidden" name="CHAMP100" value="<?php echo $nom; ?>" />
+<input type="hidden" name="CHAMP101" value="<?php echo $prenom; ?>" />
+<input type="hidden" name="CHAMP102" value="." />
+<input type="hidden" name="CHAMP103" value="." />
+<input type="hidden" name="CHAMP104" value="<?php echo $username; ?>@polytechnique.org" />
+<input type="hidden" name="CHAMP106" value="." />
+<input type="hidden" name="CHAMP107" value="." />
+<input type="hidden" name="CHAMP108" value="." />
+<input type="hidden" name="CHAMP109" value="." />
+<input type="hidden" name="CHAMP110" value="." />
+<!-- infos commande -->
+<input type="hidden" name="CHAMP200" value="<?php echo $fullref; ?>" />
+<input type="hidden" name="CHAMP201" value="<?php echo $montant; ?>" />
+<input type="hidden" name="CHAMP202" value="EUR" />
+<!-- infos divers -->
+<input type="hidden" name="CHAMP900" value="01" />
+<table class="bicol" width="98%">
+  <tr>
+    <th colspan="2">Paiement via CyberP@iement</th>
+  </tr>
+  <tr>
+    <td><b>Transaction</b></td>
+    <td><?php echo $ref_text; ?></td>
+  </tr>
+  <tr>
+    <td><b>Montant (euros)</b></td>
+    <td><?php echo $montant; ?></td>
+  </tr>
+  <tr>
+    <td>&nbsp;</td>
+    <td><input type="submit" value="Valider" />
+  </tr>
+</table>
+</form>
+
+<p class="normal">
+En cliquant sur "Valider", tu seras
+redirigé<?php if ($_SESSION['femme']) echo "e"; ?> vers le site de la 
+BP Lorraine Champagne, où il te sera demandé de saisir ton numéro de
+carte bancaire. Lorsque le paiement aura été effectué, tu recevras
+une confirmation par email.
+</p>
+
index 7a2e5de..4200637 100644 (file)
@@ -26,8 +26,6 @@ function smarty_insert_mkStats($params, &$smarty)
     mysql_free_result($req);
     $stats_req = ($stats_req ? $stats_req : "-");
 
-    $nbtrk = array(nb_trk(5,2), nb_trk(4,2), nb_trk(5,1), nb_trk(4,1));
-
     $rel = url();
     return <<<EOF
         <table class="bicol"
diff --git a/templates/paiment/index.tpl b/templates/paiment/index.tpl
new file mode 100644 (file)
index 0000000..fac8a80
--- /dev/null
@@ -0,0 +1,61 @@
+{* $Id: index.tpl,v 1.1 2004-07-08 12:03:08 x2000habouzit Exp $ *}
+
+<div class="rubrique">
+  Micropaiments
+</div>
+{dynamic}
+{if $op eq "submit" and !$error}
+{include_php file=$methode_include}
+{else}
+{foreach from=$erreur item=e}
+<p class="erreur">{$e}</p>
+{/foreach}
+
+<form method="POST" action="{$smarty.server.PHP_SELF}">
+  <input type="hidden" name="op" value="submit" />
+  <p class="normal"> Si tu ne souhaites pas utiliser notre interface de
+  télépaiement, tu peux virer directement la somme de ton choix sur notre compte
+  30004 00314 00010016782 60. Nous veillerons à ce que ton paiement parvienne à
+  son destinataire.  Pense toutefois à le préciser dans le motif du
+  versement.<br><br></p>
+  <table class="bicol" width="98%">
+    <tr>
+      <th colspan="2">Effectuer un télépaiement</th>
+    </tr>
+    <tr>
+      <td>Transaction</td>
+      <td>
+        <select name="ref" onChange="this.form.op.value='select'; this.form.submit();">
+          {select_db_table table="paiement.paiements" valeur=$ref where=" WHERE FIND_IN_SET('old',flags)=0"}
+        </select>
+        {if $ref_url}
+        <a target="_blank" href="{$ref_url}">plus d'informations</a>
+        {/if}
+      </td>
+    </tr>
+    <tr>
+      <td>Méthode</td>
+      <td>
+        <select name="methode">
+          {select_db_table table="paiement.methodes" valeur={$methode});
+        </select>
+      </td>
+    </tr>
+    <tr>
+      <td>Montant (euros)</td>
+      <td><input type="text" name="montant" size="13" value="{$montant}" /></td>
+    </tr>
+    <tr>
+      <td>&nbsp;</td>
+      <td>
+        <input type="submit" value="Continuer" />
+      </td>
+    </tr>
+  </table>
+</form>
+
+{/if}
+
+{/dynamic}
+
+{* vim:set et sw=2 sts=2 sws=2: *}