0337d704 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2004 Polytechnique.org * |
4 | * http://opensource.polytechnique.org/ * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * |
10 | * * |
11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * |
15 | * * |
16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
22 | require_once('xorg.inc.php'); |
23 | require_once("money/trezo.inc.php"); |
24 | new_admin_page('trezo/gere_operations.tpl'); |
25 | |
26 | $action = clean_request('action'); |
27 | $op_id = clean_request('op_id'); |
28 | $op_date = clean_request('op_date'); |
29 | $op_label = clean_request('op_label'); |
30 | $op_credit = clean_request('op_credit'); |
31 | $op_debit = clean_request('op_debit'); |
32 | |
33 | $annee_sel = isset($_REQUEST['annee']) ? $_REQUEST['annee'] : date("Y"); |
34 | $mois_sel = isset($_REQUEST['mois']) ? $_REQUEST['mois'] : sprintf("%02u", date('m')); |
35 | |
36 | $from_date = "$annee_sel-$mois_sel-01"; |
37 | $to_date = "$annee_sel-$mois_sel-31"; |
38 | $mon_sel = $trim_fr[$mois_sel]." $annee_sel"; |
39 | |
40 | switch($action) { |
41 | case "edit": |
42 | if ($op_id) { |
43 | $res = $globals->xdb->query("SELECT date,label,credit,debit FROM money_trezo WHERE id={?}", $op_id); |
44 | list($op_date,$op_label,$op_credit,$op_debit) = $res->fetchOneRow(); |
45 | } |
46 | break; |
47 | |
48 | case "update": |
49 | if (isDate($op_date)){ |
50 | $mydatefr = explode("/",$op_date); |
51 | $mydate = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0]; |
52 | } else { |
53 | $mydate = date("Y-m-d"); |
54 | } |
55 | |
56 | $sql = "replace into money_trezo set date='$mydate',label='".addslashes($op_label)."'"; |
57 | |
58 | if ($op_credit) { $sql .= ',credit='.$op_credit; } |
59 | if ($op_debit) { $sql .= ",debit=".$op_debit; } |
60 | if ($op_id) { $sql .= ",id='$op_id'"; } |
61 | |
62 | $globals->xdb->execute($sql); |
63 | break; |
64 | |
65 | case "del": |
66 | if ($op_id) { |
67 | $globals->xdb->execute("DELETE FROM money_trezo WHERE id={?}", $op_id); |
68 | } |
69 | break; |
70 | } |
71 | |
72 | $page->assign('op_id', $op_id); |
73 | $page->assign('annee_sel', $annee_sel); |
74 | $page->assign('mois_sel', $mois_sel); |
75 | $page->assign('op_date', $op_date); |
76 | $page->assign('op_label', $op_label); |
77 | $page->assign('op_debit', $op_debit); |
78 | $page->assign('op_credit', $op_credit); |
79 | $page->assign('mon_sel', $mon_sel); |
80 | |
81 | $page->assign('from_solde', solde_until($from_date)); |
82 | $page->assign('to_solde', solde_until($to_date)); |
83 | $page->assign('month_arr', $mois_fr); |
84 | $page->assign('ops', $globals->xdb->iterator( |
85 | "SELECT id,date,label,credit,debit FROM money_trezo WHERE date >= {?} and date <= {?} ORDER BY date", |
86 | $from_date, $to_date)); |
87 | |
88 | $page->run(); |
89 | ?> |