Group payments by asso
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 24 Nov 2006 16:18:51 +0000 (16:18 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 24 Nov 2006 16:18:51 +0000 (16:18 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1150 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/platalpage.php
modules/payment.php
plugins/function.select_db_table.php
templates/payment/index.tpl

index 788e58f..833fdc7 100644 (file)
@@ -272,7 +272,7 @@ function _hide_email($source)
 function hide_emails($source, &$smarty)
 {
     //prevent email replacement in <script> and <textarea>
-    $tags = array('script', 'textarea');
+    $tags = array('script', 'textarea', 'select');
 
     foreach ($tags as $tag) {
         preg_match_all("!<{$tag}[^>]+>.*?</{$tag}>!is", $source, ${$tag});
index 8ce2dbc..d105f97 100644 (file)
@@ -113,10 +113,10 @@ class PaymentModule extends PLModule
             $pay->prepareform($pay);
         } else {
             $res = XDB::iterator("SELECT  timestamp, montant
-                                              FROM  paiement.transactions
-                                             WHERE  uid = {?} AND ref = {?}
-                                          ORDER BY  timestamp DESC",
-                                            S::v('uid', -1), $ref);
+                                    FROM  paiement.transactions
+                                   WHERE  uid = {?} AND ref = {?}
+                                ORDER BY  timestamp DESC",
+                                 S::v('uid', -1), $ref);
 
             if ($res->total()) $page->assign('transactions', $res);
         }
index 1c7f072..4bb641c 100644 (file)
  ***************************************************************************/
 
 
-function select_options($table,$valeur,$champ="text",$pad=false,$where="") {
-    $sql = "SELECT id,$champ FROM $table $where ORDER BY $champ";
+function select_options($table,$valeur,$champ="text",$pad=false,
+                        $where="",$join="",$group="")
+{
+    $fields = 't.id,' . $champ;
+    $order = $champ;
+    if ($group) {
+        $fields .= ',' . $group;
+        $order = $group . ',' . $order; 
+    } 
+    $sql = "SELECT $fields FROM $table AS t $join $where ORDER BY $order";
     $res = XDB::iterRow($sql);
+    echo $sql;
     $sel = ' selected="selected"';
 
     // on ajoute une entree vide si $pad est vrai
     $html = "";
     if ($pad) {
-       $html.= '<option value="0"'.($valeur==0?$sel:"")."></option>\n";
+        $html.= '<option value="0"'.($valeur==0?$sel:"")."></option>\n";
     }
-    while (list($my_id,$my_text) = $res->next()) {
-       $html .= sprintf("<option value=\"%s\" %s>%s</option>\n", 
+    $optgrp = null;
+    while (list($my_id,$my_text,$my_grp) = $res->next()) {
+        if ($my_grp != $optgrp) {
+            if (!is_null($optgrp)) {
+                $html .= '</optgroup>';
+            }
+            $html .= '<optgroup label="' . addslashes(htmlentities($my_grp)) . '">';
+            $optgrp = $my_grp;
+        }
+        $html .= sprintf("<option value=\"%s\" %s>%s</option>\n", 
                          $my_id, ($valeur==$my_id?$sel:""), $my_text);
     }
+    if (!is_null($optgrp)) {
+        $html .= '</optgroup>';
+    }
     return $html;
 }
 
 function smarty_function_select_db_table($params, &$smarty) {
     if(empty($params['table']))
-       return;
+        return;
     if(empty($params['champ']))
-       $params['champ'] = 'text';
+        $params['champ'] = 'text';
     if(empty($params['pad']) || !($params['pad']))
-       $pad = false;
+        $pad = false;
     else
-       $pad = true;
+        $pad = true;
     if(empty($params['where']))
-       $params['where'] = '';
-    return select_options($params['table'], $params['valeur'],
-                          $params['champ'], $pad, $params['where']);
+        $params['where'] = '';
+    return select_options($params['table'], $params['valeur'], $params['champ'], $pad,
+                          $params['where'], $params['join'], $params['group']);
 }
 
 ?>
index a2726b3..ae4e189 100644 (file)
       <div>
        <!-- infos commercant -->
         {foreach from=$pay->api->infos.commercant key="name" item="value"}
-       <input type="hidden" name="{$name}" value="{$value}" />
+        <input type="hidden" name="{$name}" value="{$value}" />
         {/foreach}
-       <!-- infos client -->
+        <!-- infos client -->
         {foreach from=$pay->api->infos.client key="name" item="value"}
-       <input type="hidden" name="{$name}" value="{$value}" />
+        <input type="hidden" name="{$name}" value="{$value}" />
         {/foreach}
-       <!-- infos commande -->
+        <!-- infos commande -->
         {foreach from=$pay->api->infos.commande key="name" item="value"}
-       <input type="hidden" name="{$name}" value="{$value}" />
+        <input type="hidden" name="{$name}" value="{$value}" />
         {/foreach}
-       
-       <!-- infos divers -->
+
+        <!-- infos divers -->
         {foreach from=$pay->api->infos.divers key="name" item="value"}
-       <input type="hidden" name="{$name}" value="{$value}" />
+        <input type="hidden" name="{$name}" value="{$value}" />
         {/foreach}
-       <input type="submit" value="Valider" />
+        <input type="submit" value="Valider" />
       </div>
       </form>
     </td>
@@ -117,7 +117,8 @@ function payment_submit(form)
       <td>Transaction</td>
       <td>
         <select name="ref" onchange="payment_submit(this.form)">
-          {select_db_table table="`$prefix`paiements" valeur=$pay->id where=" WHERE FIND_IN_SET('old',flags)=0"}
+          {select_db_table table="`$prefix`paiements" valeur=$pay->id where="WHERE FIND_IN_SET('old',t.flags)=0"
+                           join="LEFT JOIN groupex.asso AS g ON (t.asso_id = g.id)" group="g.nom"}
         </select>
         {if $pay->url}
         <br />