noalyss Version-9
fid.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief Fid for the ajax request for cards
24 * \see fiche_search.php
25 * Valid parameter GET are
26 * - d type = cred, deb, all or filter or any sql where clause if the d starts with [sql]
27 * - j is the legdger
28 * - l field for the label
29 * - t field for the tva_id
30 * - p field for the price (sale)
31 * - b field for the price (purchase)
32 * - FID is the QuickCode
33 *\note if the j is -1 then all the card are shown
34 */
35require_once '../include/constant.php';
36require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
37MaintenanceMode("block.html");
38/**
39 * if not connected, session is expired then exit with a message NOCONX
40 */
41if ( ! isset($_SESSION[SESSION_KEY."g_user"])) {
42 echo "NOCONX";
43 die();
44}
45
47
49global $g_user;
51$g_user->check();
52$g_user->check_dossier(dossier::id());
54
56
57$fLabel=$hi->request("l","string","none");
58$fTva_id=$hi->request("t","string","none");
59$fPrice_sale=$hi->request("p","string","none");
60$fPrice_purchase=$hi->request("b","string","none");
61
62if ( isset($_SESSION[SESSION_KEY.'isValid']) && $_SESSION[SESSION_KEY.'isValid'] == 1)
63{
64 $jrn=$hi->get('j', "number",'-1');
65 $d=$hi->get('d',"string", '');
66 $d=sql_string($d);
67
68 if ( $jrn == -1 )
69 $d='all';
70 if ( strpos($d,'sql') == false )
71 {
72
73 switch ($d)
74 {
75 case 'cred':
76 $filter_jrn=$cn->make_list("select jrn_def_fiche_cred from jrn_def where jrn_def_id=$1",array($jrn));
77 $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
78
79 break;
80 case 'deb':
81 $filter_jrn=$cn->make_list("select jrn_def_fiche_deb from jrn_def where jrn_def_id=$1",array($jrn));
82 $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
83 break;
84 case 'all':
85 $filter_card="";
86 break;
87 case 'filter':
88 $get_cred='jrn_def_fiche_cred';
89 $get_deb='jrn_def_fiche_deb';
90 $deb=$cn->get_value("select $get_deb from jrn_def where jrn_def_id=$1",array($jrn));
91 $cred=$cn->get_value("select $get_cred from jrn_def where jrn_def_id=$1",array($jrn));
92
93 $filter_jrn="";
94
95 if ($deb!=='' && $cred!='')
96 $filter_jrn =$deb.','.$cred;
97 elseif($deb != '')
98 $filter_jrn=$deb;
99 elseif($cred != '')
100 $filter_jrn=$cred;
101
102 $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
103 break;
104 case 'all':
105 $filter_card='';
106 break;
107
108 default:
109 $d= ( empty($d) )?-1:$d;
110 $filter_card="and fd_id in ($d)";
111 }
112 }
113 else
114 {
115 $filter_card=$d;
116 $filter_card=noalyss_str_replace('[sql]','',$d);
117 }
118 $sql="select vw_name,vw_first_name,vw_addr,vw_cp,vw_buy,vw_sell,tva_id
119 from vw_fiche_attr
120 where quick_code=upper($1)". $filter_card;
121
122 $array=$cn->get_array($sql, array($hi->request('FID')));
123
124 if ( empty($array))
125 {
126 echo '{"answer":"nok","flabel":"'.$fLabel.'"}';
127 exit;
128 }
129
130
131 $name=$array[0]['vw_name'];
132 $sell=(isNumber($array[0]['vw_sell']) == 1) ? $array[0]['vw_sell'] : 0 ;
133 $buy=(isNumber($array[0]['vw_buy']) == 1) ?$array[0]['vw_buy']:0;
134
135 $tva_id=$array[0]['tva_id'];
136
137 // Check null
138 $name=($name==null)?" ":noalyss_str_replace('"','',$name);
139 $sell=($sell==null)?"0":noalyss_str_replace('"','',$sell);
140 $buy=($buy==null)?"0":noalyss_str_replace('"','',$buy);
141 $tva_id=($tva_id==null)?" ":noalyss_str_replace('"','',$tva_id);
142 /* store the answer in an array and transform it later into a JSON object */
143 $tmp=array();
144 //$tmp[]=array('flabel',$fLabel);
145 $tmp['flabel']=$fLabel;
146 //$tmp[]=array('name',$name);
147 $tmp['name']=$name." ".$array[0]['vw_first_name'];
148 $tmp['ftva_id']=$fTva_id;
149 $tmp['tva_id']=$tva_id;
150 $tmp['fPrice_sale']=$fPrice_sale;
151 $tmp['sell']=$sell;
152 $tmp['fPrice_purchase']=$fPrice_purchase;
153 $tmp['buy']=$buy;
154 $tmp["answer"]="ok";
155 $a=json_encode($tmp);
156}
157else
158 $a='{"answer":"unauthorized"}';
159header("Content-type: text/html; charset: utf8",true);
160print $a;
161?>
isNumber($p_int)
Definition: ac_common.php:215
MaintenanceMode($p_file)
When you want to prevent users to connect, create a file in noalyss/ (NOALYSS_BASE) with the message ...
Definition: ac_common.php:1663
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:511
set_language()
set the lang thanks the _SESSION['g_lang'] var.
Definition: ac_common.php:754
$input_from id
Definition: balance.inc.php:63
static connect()
manage the http input (get , post, request) and extract from an array
Data & function about connected users.
for($e=0; $e< count($afiche); $e++) exit
$fPrice_sale
Definition: fid.php:59
$cn
Definition: fid.php:48
$fTva_id
Definition: fid.php:58
$fPrice_purchase
Definition: fid.php:60
global $g_user
Definition: fid.php:49
$fLabel
Definition: fid.php:57
if(! isset($_SESSION[SESSION_KEY."g_user"])) $gDossier
if not connected, session is expired then exit with a message NOCONX
Definition: fid.php:46
$hi
Definition: fid.php:55
if(isset($_SESSION[SESSION_KEY. 'isValid']) && $_SESSION[SESSION_KEY. 'isValid']==1) else $a
Definition: fid.php:158
$filter_card
Definition: fid_card.php:60
print
Type of printing.
if( $delta< 0) elseif( $delta==0)
for($i=0;$i< $nb_jrn;$i++) $deb