noalyss Version-9
fid_card.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
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 NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22
23/*!\file
24 * \brief this file is used by the autocomplete functionnality
25 *\see ICard
26 * * Received parameters are
27 * - j for the ledger
28 * - e for extra (typecard)poss. values : all , a sql condition or a list of fd_id (fiche_def.fd_id) separated by comma
29 * - type is the ledger type (ach, ven, fin, gl or nothing)
30 * - FID contains the string the user is typing
31 *\note the typecard can be
32 * - cred card for the debit only if j is set
33 * - deb card for the debit only if j is set
34 * - filter card for debit and credit only if j OR type is set
35 * - list of fd_id
36 *
37 */
38
39require_once '../include/constant.php';
40require_once NOALYSS_INCLUDE.'/class/database.class.php';
41require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
42require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
43require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
44MaintenanceMode("block.html");
45
46/**
47 * if not connected, session is expired then exit with a message NOCONX
48 */
49if ( ! isset($_SESSION[SESSION_KEY."g_user"])) {
50 echo "NOCONX";
51 die();
52}
53
55
56$jrn= $http->request("j","number",-1);
57$limit=$http->request("limit","number",12);
58
59$jrn= $http->request("j","number",-1);
62$typecard=$http->request('e');
64
65require_once('class/noalyss_user.class.php');
66global $g_user;
67$g_user=new Noalyss_user($cn);
68$g_user->check();
69$g_user->check_dossier(dossier::id());
71
72if ( $typecard == 'all')
73{
74 $filter_card='';
75}
76else if (strpos($typecard,'sql]')==true)
77{
78 $filter_card= noalyss_str_replace('[sql]', " and ", $typecard);
79} else
80{
82 $filter_card="and fd_id in ($typecard)";
83}
84if ( $jrn != -1 )
85{
86 switch ($typecard)
87 {
88 case 'cred':
89 $filter_jrn=$cn->make_list("select jrn_def_fiche_cred from jrn_def where jrn_def_id=$1",array($jrn));
90 $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
91 break;
92 case 'deb':
93 $filter_jrn=$cn->make_list("select jrn_def_fiche_deb from jrn_def where jrn_def_id=$1",array($jrn));
94 $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
95 break;
96 case 'filter':
97 $get_cred='jrn_def_fiche_cred';
98 $get_deb='jrn_def_fiche_deb';
99 $deb=$cn->get_value("select $get_deb from jrn_def where jrn_def_id=$1",array($jrn));
100 $cred=$cn->get_value("select $get_cred from jrn_def where jrn_def_id=$1",array($jrn));
101
102 $filter_jrn="";
103
104 if ($deb!=='' && $cred!='')
105 $filter_jrn =$deb.','.$cred;
106 elseif($deb != '')
107 $filter_jrn=$deb;
108 elseif($cred != '')
109 $filter_jrn=$cred;
110
111 $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
112
113 break;
114
115 }
116}
117else
118{
119 if (isset($_REQUEST['type']))
120 {
121 if ($_REQUEST['type']=='gl' || $_REQUEST['type']=='') {
122 $filter_card='';
123 }
124 else
125 {
126 $get_cred='jrn_def_fiche_cred';
127 $get_deb='jrn_def_fiche_deb';
128 $type=$http->request("type");
129 $filter_jrn=$cn->make_list("select $get_cred||','||$get_deb as fiche from jrn_def where jrn_def_type=$1",array($type));
130 $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
131
132 }
133 }
134}
135// filter only enable card
136$filter_enable_card=" and f_enable='1' ";
137
138$sql_str="select distinct f_id
139 from fiche
140 join fiche_detail using (f_id)
141 where
142 ad_id in (9,1,23)
143 and ad_value ilike '%'||$1||'%' ".$filter_enable_card.$filter_card.' limit '.$limit;
144
145
146$fid=$http->request("FID");
147
148
149$sql=$cn->get_array($sql_str ,array($fid));
150
151if ($sql != false && sizeof($sql) != 0 )
152{
153 echo "<ul>";
154 $sql_get=$cn->prepare('get_name',"select ad_value from fiche_detail where f_id = $1 and ad_id=$2");
155
156 for ($i =0;$i<12 && $i < count($sql) ;$i++)
157 {
158 $name='';
159 $quick_code='';
160 $desc='';
161
162 $sql_name=$cn->execute('get_name',array($sql[$i]['f_id'],1));
163 if ( Database::num_row($sql_name) == 1) $name=Database::fetch_result($sql_name,0,0);
164
165 $sql_name=$cn->execute('get_name',array($sql[$i]['f_id'],9));
166 if ( Database::num_row($sql_name) == 1) $desc=Database::fetch_result($sql_name,0,0);
167
168 $sql_name=$cn->execute('get_name',array($sql[$i]['f_id'],23));
169 if (Database::num_row($sql_name) == 1) $quick_code=Database::fetch_result($sql_name,0,0);
170 $fid=htmlentities($fid);
171
172 /* Highlight the found pattern with bold format */
173 $name=str_ireplace($fid,'<em>'.$fid.'</em>',h($name));
174 $qcode=str_ireplace($fid,'<em>'.$fid.'</em>',h($quick_code));
175 $desc=str_ireplace($fid,'<em>'.$fid.'</em>',h($desc));
176 printf('<li id="%s">%s <span class="informal">%s %s</span></li>',
179 $name,
180 $desc
181 );
182 }
183 echo '</ul>';
184 if (count($sql) > $limit)
185 {
186 printf ('<i>...'._('Résultat limité à %s').' ...</i>',$limit);
187 }
188}
189else
190{
191 echo "<ul><li>"._("Non trouvé")."</li></ul>";
192}
193?>
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
h( $row[ 'oa_description'])
$_REQUEST['ac']
$input_from id
Definition: balance.inc.php:63
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
static num_row($ret)
wrapper for the function pg_num_rows
static connect()
manage the http input (get , post, request) and extract from an array
$sql
Definition: fid_card.php:149
if(! isset($_SESSION[SESSION_KEY."g_user"])) $http
if not connected, session is expired then exit with a message NOCONX
Definition: fid_card.php:54
$cn
Definition: fid_card.php:61
$fid
Definition: fid_card.php:146
$sql_str
Definition: fid_card.php:138
$filter_card
Definition: fid_card.php:60
$typecard
Definition: fid_card.php:62
global $g_user
Definition: fid_card.php:66
if($typecard=='all') else if(strpos($typecard, 'sql]')==true) else
Definition: fid_card.php:80
$jrn
Definition: fid_card.php:56
$limit
Definition: fid_card.php:57
if( $delta< 0) elseif( $delta==0)
for($i=0;$i< $nb_jrn;$i++) $deb