refactor trezo/gere_operations
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Mon, 13 Dec 2004 00:30:28 +0000 (00:30 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:26:36 +0000 (23:26 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-75

htdocs/trezo/gere_operations.php
templates/trezo/gere_operations.tpl

index 8160241..325794b 100644 (file)
@@ -23,88 +23,69 @@ require_once('xorg.inc.php');
 require_once("money/trezo.inc.php");
 new_admin_page('trezo/gere_operations.tpl');
 
-//Table operations :
-//+--------+---------------+------+-----+------------+----------------+
-//| Field  | Type          | Null | Key | Default    | Extra          |
-//+--------+---------------+------+-----+------------+----------------+
-//| id     | int(11)       |      | PRI | NULL       | auto_increment |
-//| date   | date          |      |     | 0000-00-00 |                |
-//| label  | varchar(80)   |      |     |            |                |
-//| credit | decimal(10,2) |      |     | 0.00       |                |
-//| debit  | decimal(10,2) |      |     | 0.00       |                |
-//+--------+---------------+------+-----+------------+----------------+
-
-$action = clean_request('action');
-$operation_id = clean_request('operation_id');
-$operation_date = clean_request('operation_date');
-$operation_label = clean_request('operation_label');
-$operation_credit = clean_request('operation_credit');
-$operation_debit = clean_request('operation_debit');
+$action    = clean_request('action');
+$op_id     = clean_request('op_id');
+$op_date   = clean_request('op_date');
+$op_label  = clean_request('op_label');
+$op_credit = clean_request('op_credit');
+$op_debit  = clean_request('op_debit');
 
 $annee_sel = isset($_REQUEST['annee']) ? $_REQUEST['annee'] : date("Y");
 $mois_sel  = isset($_REQUEST['mois']) ? $_REQUEST['mois'] : sprintf("%02u", date('m'));
 
-$from_date    = "$annee_sel-$mois_sel-01";
-$to_date      = "$annee_sel-$mois_sel-31";
-$mon_sel      = $trim_fr[$mois_sel]." $annee_sel";
+$from_date = "$annee_sel-$mois_sel-01";
+$to_date   = "$annee_sel-$mois_sel-31";
+$mon_sel   = $trim_fr[$mois_sel]." $annee_sel";
 
 switch($action) {
     case "edit":
-        if ($operation_id) {
-            $res=$globals->db->query("select date,label,credit,debit from money_trezo where id='$operation_id'");
-            list($operation_date,$operation_label,$operation_credit,$operation_debit)=mysql_fetch_row($res);
+        if ($op_id) {
+            $res=$globals->db->query("select date,label,credit,debit from money_trezo where id='$op_id'");
+            list($op_date,$op_label,$op_credit,$op_debit)=mysql_fetch_row($res);
         }
-    break;
+        break;
+
     case "update":
-        $operation_date = clean_request('operation_date');
-        $operation_label = clean_request('operation_label');
-        $operation_credit = clean_request('operation_credit');
-        $operation_debit = clean_request('operation_debit');
-        $sql_add = "";
+        if (isDate($op_date)){
+            $mydatefr = explode("/",$op_date);
+            $mydate   = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0];
+        } else {
+            $mydate   = date("Y-m-d");
+        }
 
-        if ($operation_credit)
-            $sql_add = ',credit='.$operation_credit;
-        if ($operation_debit)
-            $sql_add = $sql_add.",debit=".$operation_debit;
+        $sql = "replace into money_trezo set date='$mydate',label='$op_label'";
 
-        if (isDate($operation_date)){
-            $mydatefr = explode("/",$operation_date);
-            $mydate = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0];
-        }else{
-            $mydate = date("Y-m-d");
-        }
+        if ($op_credit) { $sql .= ',credit='.$op_credit; }
+        if ($op_debit)  { $sql .= ",debit=".$op_debit;   }
+        if ($op_id)     { $sql .= ",id='$op_id'";        }
+        
+        $globals->db->query($sql);
+        break;
 
-        if ($operation_id) {
-            $sql = "update money_trezo set date='".$mydate."',label='".$operation_label."'".$sql_add." where id='".$operation_id."'";
-        } else { 
-            $sql = "insert into money_trezo set date='".$mydate."',label='".$operation_label."'".$sql_add;
-        }
-    break;
     case "del":
-        if ($operation_id) {
-            $globals->db->query("delete from money_trezo where id='".$operation_id."'");
+        if ($op_id) {
+            $globals->db->query("delete from money_trezo where id='".$op_id."'");
         }
-    break;
-
-} // $action
+        break;
+}
 
-$page->assign('operation_id', $operation_id);
+$page->assign('op_id',     $op_id);
 $page->assign('annee_sel', $annee_sel);
-$page->assign('mois_sel', $mois_sel);
-$page->assign('operation_date', $operation_date);
-$page->assign('operation_label', $operation_label);
-$page->assign('operation_debit', $operation_debit);
-$page->assign('operation_credit', $operation_credit);
-$page->assign('mon_sel', $mon_sel);
+$page->assign('mois_sel',  $mois_sel);
+$page->assign('op_date',   $op_date);
+$page->assign('op_label',  $op_label);
+$page->assign('op_debit',  $op_debit);
+$page->assign('op_credit', $op_credit);
+$page->assign('mon_sel',   $mon_sel);
 
 $page->assign('from_solde', solde_until($from_date));
-$page->assign('to_solde', solde_until($to_date));
+$page->assign('to_solde',   solde_until($to_date));
 $page->assign_by_ref('month_arr', $mois_fr);
 
-$sql = "SELECT id,date,label,credit,debit 
-        FROM money_trezo
-        WHERE date >= '$from_date' AND date <= '$to_date' 
-        ORDER BY date";
+$sql = "SELECT  id,date,label,credit,debit 
+          FROM  money_trezo
+         WHERE  date >= '$from_date' AND date <= '$to_date' 
+      ORDER BY  date";
 $page->mysql_assign($sql, 'ops');
 
 $page->run();
index e9c1676..3067add 100644 (file)
@@ -30,7 +30,7 @@
   <table class="bicol">
     <tr>
       <th colspan="2">
-        {if $operation_id}
+        {if $op_id}
         Modifier une opération
         {else}
         Ajouter une opération
     </tr>
     <tr>
       <td>Date (DD/MM/YYYY)</td>
-      <td><input type="text" name="operation_date" size="40"
-        value="{$operation_date|date_format:"%d/%m/%Y"}" /></td>
+      <td><input type="text" name="op_date" size="40"
+        value="{$op_date|date_format:"%d/%m/%Y"}" /></td>
     </tr>
     <tr>
       <td>Description libre</td>
-      <td><input type="text" name="operation_label" size="40" value="{$operation_label}" /></td>
+      <td><input type="text" name="op_label" size="40" value="{$op_label}" /></td>
     </tr>
     <tr>
       <td>Débit</td>
-      <td><input type="text" name="operation_debit" size="40" value="{$operation_debit}" /></td>
+      <td><input type="text" name="op_debit" size="40" value="{$op_debit}" /></td>
     </tr>
     <tr>
       <td>Crédit</td>
-      <td><input type="text" name="operation_credit" size="40" value="{$operation_credit}" /></td>
+      <td><input type="text" name="op_credit" size="40" value="{$op_credit}" /></td>
     </tr>
     <tr>
       <td class="center" colspan="2">
-        <input type="hidden" name="operation_id" value="{$operation_id}" />
+        <input type="hidden" name="op_id" value="{$op_id}" />
         <input type="hidden" name="action" value="update" />
         <input type="hidden" name="annee" value="{$annee_sel}" />
         <input type="hidden" name="mois" value="{$mois_sel}" />
@@ -67,7 +67,7 @@
 </form>
 
 <a href="{$smarty.server.PHP_SELF}">retour</a>
-{elseif $smarty.request.action eq "update" && $operation_id}
+{elseif $smarty.request.action eq "update" && $op_id}
 <strong>modification de l'opération</strong>
 {elseif $smarty.request.action eq "update"}
 <strong>ajout de l'opération</strong>
     <td>
       <form method="post" action="{$smarty.server.PHP_SELF}">
         <div>
-          <input type="hidden" name="operation_id" value="0" />
+          <input type="hidden" name="op_id" value="0" />
           <input type="hidden" name="action" value="edit" />
           <input type="hidden" name="annee" value="{$annee_sel}" />
           <input type="hidden" name="mois" value="{$mois_sel}" />
     <td>
       <form method="post" action="{$smarty.server.PHP_SELF}">
         <div>
-          <input type="hidden" name="operation_id" value="{$op.id}" />
+          <input type="hidden" name="op_id" value="{$op.id}" />
           <input type="hidden" name="annee" value="{$annee_sel}" />
           <input type="hidden" name="mois" value="{$mois_sel}" />
           <input type="submit" name="action" value="edit" />