noalyss Version-9
ajax_poste.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 this file answer to the Ajax request from js/accounting_item.js
24 * - op
25 - sf show form of search
26 - param j : ledger -> php jrn
27 - param c : control for storing the pcm_val -> javascript account
28 - param l : control for storing the pcm_lib -> javascript label
29 - param ctl : the node to update (ipopup)
30 - param q : the acc_query -> javascript query
31 * - ctl (to return)
32 *
33 *
34 */
35if ( ! defined('ALLOWED')) die (_('Non authorisé'));
36
37require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
38require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
39mb_internal_encoding("UTF-8");
40
41extract($_REQUEST, EXTR_SKIP);
42
44
45if ($g_user->check_dossier($dossier_id) == 'X') exit();
46switch ($op2)
47{
48 /*----------------------------------------------------------------------
49 * Show the form and the result
50 *
51 ----------------------------------------------------------------------*/
52case "sf":
53 $ipopup=$ctl;
54 $attr=sprintf('this.ctl=\'%s\';',$ipopup);
55 $ctl.='_content';
56 $it=new IText('acc_query');
57 $it->size=30;
58 $it->value=(isset($q))?$q:'';
59 $str_poste=$it->input();
60 $str_submit=HtmlInput::submit('sf',_('Recherche'),"","smallbutton");
61 $r='';
62 $r.=HtmlInput::title_box(_('Poste Comptable'),'search_account',"close","","y");
63
64
65 $r.='<form id="sp" method="get" onsubmit="'.$attr.'search_get_poste(this);return false;">';
66 ob_start();
67 require_once NOALYSS_TEMPLATE.'/account_search.php';
68 $r.=ob_get_contents();
69 ob_end_clean();
70 $r.=dossier::hidden();
71 $r.=(isset ($c))?HtmlInput::hidden('account',$c):"";
72 $r.=(isset ($l))?HtmlInput::hidden('label',$l):"";
73 $r.=(isset ($j))?HtmlInput::hidden('jrn',$j):"";
74 $r.=(isset ($nover))?HtmlInput::hidden('nover','1'):"";
75 $r.=(isset ($nosearch))?HtmlInput::hidden('nosearch','1'):"";
76 $r.=(isset ($bracket))?HtmlInput::hidden('bracket','1'):"";
77
78
79 $r.='</form>';
80 $sql="
81 select pcm_val,pcm_lib,array_to_string(array_agg(j_qcode) , ',') as acode
82 from tmp_pcmn left join vw_poste_qcode on (j_poste=pcm_val) ";
83 $sep=" where ";
84 /* build the sql stmt */
85 if ( isset($j) && $j > 0 && isNumber($j))
86 {
87 /* create a filter on the ledger */
89 $fd_id=$ledger->build_sql_account($j);
90 if ( $fd_id != '' )
91 {
92 $sql.=" $sep (".$fd_id.')';
93 $sep=" and ";
94 }
95 }
96 /* show result */
97 if ( isset($q) && noalyss_strlentrim($q) > 0)
98 {
100 $sql.=sprintf(" $sep ( pcm_val::text like '%s%%' or pcm_lib::text ilike '%%%s%%') ",
101 $q,$q);
102 }
103 $sql.=' group by pcm_val,pcm_lib,pcm_val_parent, pcm_type order by pcm_val::text limit 50';
104 if ( isset($q) && noalyss_strlentrim($q)> 0 )
105 {
106 $array=$cn->get_array($sql);
107 }
108 if ( ! isset($q) ) $array=array();
109 if ( isset($q) && noalyss_strlentrim($q)==0) $array=array();
110
111 /* set the javascript */
112 for ($i=0;$i<count($array);$i++)
113 {
114 $pcm_val=$array[$i]['pcm_val'];
115 if ( isset($bracket))
116 {
117 $pcm_val='['.$pcm_val.']';
118 }
119 if (isset($nover))
120 {
121 /* no overwrite */
122 $str=sprintf("$('%s').value=$('%s').value+' '+'%s';",
123 $c,$c,$pcm_val);
124
125 }
126 else
127 {
128 $str=sprintf("$('%s').value='%s';",
129 $c,$pcm_val);
130 }
131
132 if ( isset($l) )
133 {
134 $str.=sprintf("set_value('%s',g('%s').innerHTML);",
135 $l,"lib$i");
136
137 }
138 $str.="removeDiv('search_account');";
139 $array[$i]['javascript']=$str;
140 }
141 ob_start();
142
143 require_once NOALYSS_TEMPLATE.'/account_result.php';
144 $r.=ob_get_contents();
145 ob_end_clean();
146
147 $html=$r;
148 $html.=HtmlInput::button_close("search_account");
149 break;
150}
152if (headers_sent() && DEBUGNOALYSS > 0) {
153 echo $html;
154}
155else
156{
157 header('Content-type: text/xml; charset=UTF-8');
158}
159
160echo <<<EOF
161<?xml version="1.0" encoding="UTF-8"?>
162<data>
163<ctl>$ctl</ctl>
164<code>$xml</code>
165</data>
166EOF;
isNumber($p_int)
Definition: ac_common.php:215
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:511
global $g_user
if no group available , then stop
if(headers_sent() &&DEBUGNOALYSS > 0) $html
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
switch($op2) $xml
Definition: ajax_poste.php:151
$dossier_id
Definition: ajax_poste.php:43
$_REQUEST['ac']
Manage the account from the table jrn, jrnx or tmp_pcmn.
static id()
return the 'gDossier' value after a check
static button_close($div_name, $class='smallbutton')
close button for the HTML popup
static hidden($p_name, $p_value, $p_id="")
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Html Input.
Definition: itext.class.php:30
for($e=0; $e< count($afiche); $e++) exit
$str
Definition: fiche.inc.php:91
$fd_id
Definition: fiche.inc.php:104
escape_xml($p_xml)
When data are transfered thanks ajax in a xml document, the xml can not contains some character,...