noalyss Version-9
ajax_currency.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta 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 * PhpCompta 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 PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2018) Author Dany De Bontridder <dany@alchimerys.be>
21
22if (!defined('ALLOWED'))
23 die('Appel direct ne sont pas permis');
24
25/**
26 * @file
27 * @brief Ajax response for currency related calls
28 */
30$a_answer=array();
31$a_answer['status']="NOK";
33try
34{
35 $act=$http->request("op");
36}
37catch (Exception $ex)
38{
39 $a_answer['content']=$ex->getMessage();
40 $jsson=json_encode($a_answer, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
41 header('Content-Type: application/json;charset=utf-8');
42 echo $jsson;
43 return;
44}
45
46/* security check */
47/**
48 * check if module CFGCURRENCY
49 */
50if ($g_user->check_module('CFGCURRENCY')==0)
51{
52 return;
53}
54
55/*
56 * Select action
57 */
58switch ($act)
59{
60 case 'CurrencyRateDelete':
61 try
62 {
63 $currency_rate_id=$http->get("currency_rate_id", "number");
64 // check that a least one rate is remaining for this currency
65 // 1. get the currency
66 $currency_id=$cn->get_value("select currency_id from currency_history where id=$1", [$currency_rate_id]);
67
68 // 2. get the number of rate
69 if ($currency_id=="")
70 {
71 throw new Exception(_("Taux inexistant"));
72 }
73 $cnt=$cn->get_value("select count(*) from currency_history where currency_id=$1", [$currency_id]);
74
75 // 3. if number of rate > 1 , then delete
76 if ($cnt>1)
77 {
78 $cn->exec_sql("delete from currency_history where id=$1", [$currency_rate_id]);
79 $a_answer['status']=_("OK");
80 $a_answer['content']=_("Taux effacé");
81 }
82 else
83 {
84 $a_answer['content']=_("Non effacé : Il faut au moins un taux");
85 }
86 }
87 catch (Exception $ex)
88 {
89 $a_answer['content']=$ex->getMessage();
90 }
91 break;
92 case 'CurrencyManage':
93 $table=$http->request('table');
94 $action=$http->request('action');
95 $p_id=$http->request('p_id', "number");
96 $ctl_id=$http->request('ctl');
99
100 $currency_table->set_callback("ajax_misc.php");
101 $currency_table->add_json_param("op", "CurrencyManage");
102
103 /*
104 * we're in ajax part
105 */
106 if ($action=="input")
107 {
108 $currency_table->set_object_name($ctl_id);
109 header('Content-type: text/xml; charset=UTF-8');
110 echo $currency_table->ajax_input()->saveXML();
111 return;
112 }
113 elseif ($action=="save")
114 {
115 $currency_table->set_object_name($ctl_id);
116 header('Content-type: text/xml; charset=UTF-8');
117 echo $currency_table->ajax_save()->saveXML();
118 return;
119 }
120 elseif ($action=="delete")
121 {
122 $currency_table->set_object_name($ctl_id);
123 header('Content-type: text/xml; charset=UTF-8');
124 echo $currency_table->ajax_delete()->saveXML();
125 return;
126 }
127}
128
129$jsson=json_encode($a_answer, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
130if (!headers_sent())
131{
132 header('Content-Type: application/json;charset=utf-8');
133}
134echo $jsson;
global $g_user
if no group available , then stop
$action
catch(Exception $ex) if( $g_user->check_module( 'CFGCURRENCY')==0) switch($act) $jsson
check if module CFGCURRENCY
$http
$a_answer
$err
$ex
Definition: balance.inc.php:45
Manage the configuration of currency , add currency, rate, remove and update Concerned tables are v_c...
manage the http input (get , post, request) and extract from an array
class_currency_history_sql.php
if( $delta< 0) elseif( $delta==0)
$table
Definition: menu.inc.php:103