| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 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 | $page->assign('xorg_title','Polytechnique.org - Administration - Trezo : gestion'); |
| 26 | |
| 27 | $action = clean_request('action'); |
| 28 | $op_id = clean_request('op_id'); |
| 29 | $op_date = clean_request('op_date'); |
| 30 | $op_label = clean_request('op_label'); |
| 31 | $op_credit = clean_request('op_credit'); |
| 32 | $op_debit = clean_request('op_debit'); |
| 33 | |
| 34 | $annee_sel = isset($_REQUEST['annee']) ? $_REQUEST['annee'] : date("Y"); |
| 35 | $mois_sel = isset($_REQUEST['mois']) ? $_REQUEST['mois'] : sprintf("%02u", date('m')); |
| 36 | |
| 37 | $from_date = "$annee_sel-$mois_sel-01"; |
| 38 | $to_date = "$annee_sel-$mois_sel-31"; |
| 39 | $mon_sel = $trim_fr[$mois_sel]." $annee_sel"; |
| 40 | |
| 41 | switch($action) { |
| 42 | case "edit": |
| 43 | if ($op_id) { |
| 44 | $res = $globals->xdb->query("SELECT date,label,credit,debit FROM money_trezo WHERE id={?}", $op_id); |
| 45 | list($op_date,$op_label,$op_credit,$op_debit) = $res->fetchOneRow(); |
| 46 | } |
| 47 | break; |
| 48 | |
| 49 | case "update": |
| 50 | if (isDate($op_date)){ |
| 51 | $mydatefr = explode("/",$op_date); |
| 52 | $mydate = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0]; |
| 53 | } else { |
| 54 | $mydate = date("Y-m-d"); |
| 55 | } |
| 56 | |
| 57 | $sql = "replace into money_trezo set date='$mydate',label='".addslashes($op_label)."'"; |
| 58 | |
| 59 | if ($op_credit) { $sql .= ',credit='.$op_credit; } |
| 60 | if ($op_debit) { $sql .= ",debit=".$op_debit; } |
| 61 | if ($op_id) { $sql .= ",id='$op_id'"; } |
| 62 | |
| 63 | $globals->xdb->execute($sql); |
| 64 | break; |
| 65 | |
| 66 | case "del": |
| 67 | if ($op_id) { |
| 68 | $globals->xdb->execute("DELETE FROM money_trezo WHERE id={?}", $op_id); |
| 69 | } |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | $page->assign('op_id', $op_id); |
| 74 | $page->assign('annee_sel', $annee_sel); |
| 75 | $page->assign('mois_sel', $mois_sel); |
| 76 | $page->assign('op_date', $op_date); |
| 77 | $page->assign('op_label', $op_label); |
| 78 | $page->assign('op_debit', $op_debit); |
| 79 | $page->assign('op_credit', $op_credit); |
| 80 | $page->assign('mon_sel', $mon_sel); |
| 81 | |
| 82 | $page->assign('from_solde', solde_until($from_date)); |
| 83 | $page->assign('to_solde', solde_until($to_date)); |
| 84 | $page->assign('month_arr', $mois_fr); |
| 85 | $page->assign('ops', $globals->xdb->iterator( |
| 86 | "SELECT id,date,label,credit,debit FROM money_trezo WHERE date >= {?} and date <= {?} ORDER BY date", |
| 87 | $from_date, $to_date)); |
| 88 | |
| 89 | $page->run(); |
| 90 | ?> |