noalyss Version-9
ajax_search_filter.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 * NOALYSS 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 (2016) Author Dany De Bontridder <dany@alchimerys.be>
21
22if (!defined('ALLOWED'))
23 die('Appel direct ne sont pas permis');
24
27global $g_user;
28/**
29 * @file
30 * @brief Managed the search filter
31 */
33//---------------------------------------------------------------------------
34// Record the the search filter
35//---------------------------------------------------------------------------
36$op=$http->request("op");
37if ($op=='save_filter')
38{
39 $answer=[];
40 $answer['filter_name']="";
41 $answer['status']='NOK';
42 $answer['filter_id']=0;
43 $answer['message']="";
44 try
45 {
46 $new=new User_filter_SQL($cn, -1);
47 $new->setp("login", $g_user->login);
48 $new->setp("nb_jrn", $http->post("nb_jrn", 'number'));
49 $new->setp("date_start", $http->post("date_start", 'string', NULL));
50 $new->setp("date_end", $http->post("date_end", 'string', NULL));
51 $new->setp("description", $http->post("desc", 'string', NULL));
52 $new->setp("amount_min", $http->post("amount_min", 'number', NULL));
53 $new->setp("amount_max", $http->post("amount_max", 'number', NULL));
54 $new->setp("qcode", $http->post("qcode", 'string', NULL));
55 $new->setp("accounting", $http->post("accounting", 'string', NULL));
56 $new->setp("uf_tag_option",$http->post("tag_option","string",null));
57 $new->setp("date_paid_start",
58 $http->post("date_paid_start", 'string', NULL));
59 $new->setp("date_paid_end", $http->post("date_paid_end", 'string', NULL));
60 $new->setp("ledger_type", $http->post("ledger_type", 'string'));
61 $new->setp("operation_filter", $http->post("operation_filter", 'string', NULL));
62 $new->setp("filter_name", h($http->post("filter_name", 'string')));
63 $new->setp("uf_currency_code", h($http->post("p_currency_code", 'number',-1)));
64 $new->setp("tva_id_search", h($http->post("tva_id_search", 'string',null)));
65 $tag=$http->post("tag","string",'');
66
67 if (is_array($tag) )
68 $new->setp("uf_tag",join(',',$tag));
69 else
70 $new->setp("uf_tag",null);
71 $aJrn=[];
72 $max=$http->post("nb_jrn");
73 for ($i=0; $i<$max; $i++)
74 {
75 $aJrn[]=$http->post("r_jrn".$i, "number");
76 }
77 $new->setp("r_jrn", join(',', $aJrn));
78 if (strlen($new->getp("filter_name"))==0)
79 {
80 throw new Exception(_("Nom ne peut être vide"));
81 }
82 $new->save();
83 $rmAction=sprintf("delete_filter('%s','%s','%s')", trim($http->post('div')), $dossier_id,
84 $new->getp('id'));
85 $answer['filter_name']="";
86 $answer['filter_name'].=sprintf("<a class=\"line\" style=\"display:inline;text-decoration:underline\" onclick=\"load_filter('%s','%s','%s')\">%s</a>",
87 trim($http->post('div')), $dossier_id, $new->getp('id'),
88 $new->getp("filter_name"));
89 $answer['filter_name'].='<span id="'.uniqid().'" onclick="'.$rmAction.'" class="icon" style="display:inline;margin-left:2em">&#xe80f;</span>';;
90 $answer['filter_id']=$new->getp("id");
91 $answer['status']='OK';
92 }
93 catch (Exception $ex)
94 {
95 $answer['status']='NOK';
96 $answer['message']=$ex->getMessage();
97 }
98 header('Content-Type: application/json;charset=utf-8');
99 echo json_encode($answer);
100 return;
101}
102//------------------------------------------------------------------------------
103// Load a filter
104//------------------------------------------------------------------------------
105if ($op=="load_filter")
106{
107 $filter_id=$http->get("filter_id", "number");
108 $div=$http->get("div");
109 $answer=[];
110 $answer['status']='OK';
111 $answer['filter_id']=0;
112 $answer['message']="";
113 $filter=new User_filter_SQL($cn, $filter_id);
115 $result=array_merge($answer, $record);
116
117
118 header('Content-Type: application/json;charset=utf-8');
119 echo json_encode($result);
120 return;
121}
122//-----------------------------------------------------------------------------
123// Display all the existing search filters and allow to load or delete them
124// id of the box is "boxfilter"+{p_div}
125//------------------------------------------------------------------------------
126if ($op=="display_search_filter")
127{
128 $p_div=$http->get("div");
129 $ledger_type=$http->get("ledger_type");
130
131 echo HtmlInput::title_box(_("Filtre"), "boxfilter".$p_div);
132
133
134
135 // Make a list of all search filters with the same ledger_type of the current
136 // user
137 $result=$cn->get_array("
138 select id, filter_name,ledger_type
139 from user_filter
140 where
141 login = $1
142 and ledger_type=$2
143 order by 2 asc
144", [$g_user->login, $ledger_type]);
145 $nb_result=count($result);
146 printf('<ul class="select_table" id="manage%s">', $p_div);
147 $search_filter=new Acc_Ledger_Search($ledger_type,1,$p_div);
148 // Button add filter
149 echo "<li>";
150 echo $search_filter->build_name_filter();
151 echo "</li>";
152
153 echo "<li>";
154 echo HtmlInput::anchor(_("Remise à zéro"), "", "style=\"text-decoration:underline\" onclick=\"reset_filter('$p_div');removeDiv('boxfilter{$p_div}')\"");
155 echo "</li>";
156
157 // Link reset
158 for ($i=0; $i<$nb_result; $i++)
159 {
160 printf(' <li id="manageli%s_%d">', $p_div, $result[$i]["id"]);
161 $rmAction=sprintf("delete_filter('%s','%s','%s')", $p_div, $dossier_id,
162 $result[$i]['id']);
163 printf("<a href=\"javascript:void(0)\" style=\"display:inline;text-decoration:underline\" onclick=\"load_filter('%s','%s','%s');removeDiv('boxfilter%s')\">",
164 $p_div, $dossier_id, $result[$i]["id"],$p_div);
165 echo $result[$i]["filter_name"];
166 echo '</a>';
167 echo '<span id="'.uniqid().'" onclick="'.$rmAction.'" class="icon" style="display:inline;margin-left:2em">&#xe80f;</span>';
168
169 printf("</li>");
170 }
171 echo '</ul>';
172 echo HtmlInput::button_close("boxfilter".$p_div);
173 return;
174}
175//-----------------------------------------------------------------------------
176// Delete a filter_id
177// Check if this filter belong to current user
178//------------------------------------------------------------------------------
179if ($op=="delete_search_operation")
180{
181 $answer=[];
182 $answer['filter_name']="";
183 $answer['status']='NOK';
184 $answer['filter_id']=0;
185 $answer['message']="";
186 try
187 {
188 $p_div=$http->post("div");
189 $filter_id=$http->post("filter_id", "number");
190
191 $answer['div']=$p_div;
192
193 $cn->exec_sql("delete from user_filter where id=$1 and login=$2",[$filter_id,$g_user->login]);
194
195 $answer['filter_id']=$filter_id;
196 $answer['status']="OK";
197 }
198 catch (Exception $ex)
199 {
200 $answer['message']=$ex->getMessage();
201 }
202 header('Content-Type: application/json;charset=utf-8');
203 echo json_encode($answer);
204 return;
205}
206//---------------------------------------------------------------------------------------------------------------
207// display_filter_tag : transform uf_tag into a list of tag , and display those tags in cells
208//----------------------------------------------------------------------------------------------------------------
209if ($op=='display_filter_tag')
210{
211 $tag=$http->request("uf_tag");
212 if ( trim($tag)=="") {return;}
213 $div=$http->request("div");
214 $aTag=explode(',', $tag);
215 if (is_array($aTag))
216 {
217 $nb_tag=count($aTag);
218 for ($j=0; $j<$nb_tag; $j++)
219 {
221 $tag_operation->update_search_cell($div);
222 }
223 }
224 return;
225}
226//---------------------------------------------------------------------------------------------------------------
227// display_list_filter : display a list of saved search alias filter
228//----------------------------------------------------------------------------------------------------------------
229if ($op=='display_list_filter')
230{
231 echo \HtmlInput::title_box("Recherches sauvées",'display_list_filter_div');
232
233 $ledger_search=new Acc_Ledger_Search($http->request("ledger_type"));
234 $ledger_search->display_list_filter();
235?>
236
237
238 <ul class="aligned-block">
239 <li>
240 <?=\HtmlInput::button_close("display_list_filter_div")?>
241 </li>
242 </ul>
243<?php
244 return;
245}
h( $row[ 'oa_description'])
$answer
$div
global $g_user
$filter
$ex
Definition: balance.inc.php:45
static build_array(User_Filter_SQL $user_filter_sql)
use a user_filter row and turns it into an array for javascript purpose
static id()
return the 'gDossier' value after a check
static connect()
static button_close($div_name, $class='smallbutton')
close button for the HTML popup
static anchor($p_text, $p_url="", $p_js="", $p_style=' class="line" ', $p_title="click", array $p_attribute=[])
Return a simple anchor with a url or a javascript if $p_js is not null then p_url will be javascript:...
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".
manage the http input (get , post, request) and extract from an array
concerns the tags linked to an accountancy writing
ORM abstract of the table public.user_filter.
$tag_operation