Plugins  LAST
 All Data Structures Files Functions Variables Pages
ajax.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 require_once NOALYSS_INCLUDE.'/lib/class_database.php';
21 require_once('include/class_bank_item.php');
22 require_once('bank_constant.php');
23 
24 extract($_GET);
25 $cn=Dossier::connect();
26 $html='';$extra='';$ctl='';
28 $r="";
29 switch($act) {
30  case 'set_suggest':
31  ////////////////////////////////////////////////////////////////////
32  // set the selection coming from display_suggest
33  ////////////////////////////////////////////////////////////////////
34  $id=HtmlInput::default_value_get("id", 0);
35  $suggest_id=HtmlInput::default_value_get("suggest_id",0);
36  // Retrieve info
37  $a_suggest=$cn->get_array("select
38  a.id,
39  a.jr_id,
40  b.jr_internal,
41  a.f_id,
42  (select ad_value from fiche_detail where ad_id=23 and f_id=a.f_id) as qcode
43  from
44  jrn as b
45  join importbank.suggest_bank as a on (a.jr_id=b.jr_id)
46  where
47  a.id=$1", array($suggest_id));
48  if ( count($a_suggest)==1)
49  {
50  $cn->exec_sql("
51  update importbank.temp_bank set status='W',tp_rec=$1,f_id=$2
52  where
53  id=$3
54  ",
55  array
56  (
57  $a_suggest[0]['jr_id'],
58  $a_suggest[0]['f_id'],
59  $id)
60  );
61  $a_json=array('tiers'=>HtmlInput::card_detail($a_suggest[0]['qcode']),
62  'concop'=>HtmlInput::detail_op($a_suggest[0]['jr_id'],$a_suggest[0]['jr_internal']),
63  'status'=>'<span style=\"color:red;background-color:white\">Attente</span>'
64  );
65  echo json_encode($a_json);
66  } else {
67  $a_json=array('tiers'=>"",
68  'concop'=>"",
69  'status'=>'Error'
70  );
71  echo json_encode($a_json);
72 
73  }
74  return;
75  break;
76  case 'display_suggest':
77  ////////////////////////////////////////////////////////////////////
78  // If several rows are found for an import bank (temp_bank) then
79  // display the different possibilities
80  ////////////////////////////////////////////////////////////////////
81  $id=HtmlInput::default_value_get("id", 0);
82  $plugin_code=HtmlInput::default_value_get('plugin_code',"");
83  echo HtmlInput::title_box(_("Suggestion"), "display_suggest_box");
84  /*
85  * Display operation
86  */
87  $bi_sql=new Temp_Bank_Sql($cn,$id);
88  $date=_('date');
89  $label=_('Libellé');
90  $other_info=_("Autre information");
91  $amount=_('Montant');
92  $str_tiers=_('Tiers');
93  echo "<table>";
94  echo "<tr>";
95  echo td($date);
96  echo td($bi_sql->tp_date);
97  echo "</tr>";
98  echo "<tr>";
99  echo td($str_tiers);
100  echo td($bi_sql->tp_third);
101  echo "</tr>";
102  echo "<tr>";
103  echo td($label);
104  echo td($bi_sql->libelle);
105  echo "</tr>";
106  echo "<tr>";
107  echo td($amount);
108  echo td($bi_sql->amount);
109  echo "</tr>";
110 
111  echo "<tr>";
112  echo td($other_info);
113  echo td($bi_sql->tp_extra);
114  echo "</tr>";
115 
116  echo " </table>";
117  $a_suggest=$cn->get_array("select
118  a.id,
119  a.jr_id,
120  b.jr_internal,
121  a.f_id,
122  b.jr_date,
123  b.jr_pj_number,
124  b.jr_comment,
125  (select ad_value from fiche_detail where ad_id=23 and f_id=a.f_id) as qcode
126  from
127  jrn as b
128  join importbank.suggest_bank as a on (a.jr_id=b.jr_id)
129  where
130  temp_bank_id=$1", array($id));
131  $nb_asuggest=count($a_suggest);
132  echo "<ul style=\"list-style:none\">";
133  for ($i=0;$i<$nb_asuggest;$i++) {
134  echo '<li>'.
135  HtmlInput::button("get{$i}", _('choisir'), sprintf("onclick=\"select_suggest('%s','%s','%s','%s')\"",$dossier_id,$plugin_code,$id,$a_suggest[$i]['id'])).
136  h($a_suggest[$i]['jr_date']). " " .
137  HtmlInput::card_detail($a_suggest[$i]['qcode']).
138  h($a_suggest[$i]['jr_pj_number']). " " .
139  HtmlInput::detail_op($a_suggest[$i]['jr_id'], $a_suggest[$i]['jr_internal'])." ".
140  h($a_suggest[$i]['jr_comment'])." " .
141  "</li>";
142  }
143  echo '</ul>';
144  echo '<p style="text-align:center">';
145  echo HtmlInput::button_close("display_suggest_box");
146  echo '</p>';
147  return;
148  break;
149  case 'check_all':
150  /////////////////////////////////////////////////////////////////////
151  // Check all the rows or unchecked
152  /////////////////////////////////////////////////////////////////////
153  require_once 'include/class_import_bank.php';
154  $import_id=HtmlInput::default_value_get("import_id", 0);
155  $checked=HtmlInput::default_value_get("checked", 0);
156  $status=HtmlInput::default_value_get("status", 0);
158  $cn->exec_sql("
159  update importbank.temp_bank set is_checked = $2
160  where import_id=$1 $sql",
161  array($import_id,$checked));
162  $r="ok";
163  break;
164  case 'save_check':
165  ////////////////////////////////////////////////////////////////////
166  // Save the checked row into the table temp_bank
167  ////////////////////////////////////////////////////////////////////
168  $id=HtmlInput::default_value_get("row_id", 0);
169  $state=HtmlInput::default_value_get("state", 0);
170  if ($id == 0 )return;
171  if ( $state == 0 ) {
172  //upate in temp_bank
173  $cn->exec_sql("update importbank.temp_bank set is_checked = 0 where id= $1 ",
174  array($id));
175  } else {
176  $cn->exec_sql("update importbank.temp_bank set is_checked = 1 where id= $1 ",
177  array($id));
178  }
179  return;
180  case 'display_tiers':
181  ////////////////////////////////////////////////////////////////////
182  // Choose a tiers and set it for several operations
183  ////////////////////////////////////////////////////////////////////
184  echo "<div>";
185  // count the number of rows selected
186  $import_id=HtmlInput::default_value_get("import_id", 0);
187  $count=$cn->get_value("select count(*) from importbank.temp_bank where "
188  . " is_checked = 1 and import_id = $1",
189  array($import_id));
190  echo HtmlInput::title_box(_("Choix du tiers pour les opérations sélectionnées"), "select_tiers_div");
191  if ( $import_id == 0 || $count == 0) {
192  echo '<p class="warning">';
193  echo (_("Rien n'est sélectionné"));
194  echo '</p>';
195  echo '<p>';
196  echo HtmlInput::button("cancel", _("Fermer"),
197  " onclick=\"removeDiv('select_tiers_div')\"");
198  echo '</p>';
199  return;
200  } else {
201  echo '<p>';
202  echo _('Nombre de lignes choisies')." ".$count;
203  echo '</p>';
204  }
205  $status=HtmlInput::default_value_get("status", 0);
206  echo '<form method="get" id="display_tiers_frm" onsubmit="selected_set_tiers(\'display_tiers_frm\');return false">';
207  echo HtmlInput::array_to_hidden(array("ac","gDossier","import_id","plugin_code"), $_GET);
208  echo HtmlInput::hidden("sa", "purge");
209  echo HtmlInput::hidden("sb", "list");
210  echo HtmlInput::hidden("id", $import_id);
211  echo HtmlInput::hidden("form_action2", "selected_record");
212  echo HtmlInput::hidden("form_action", "selected_record");
213  echo HtmlInput::hidden("select_action", "1");
214  echo HtmlInput::hidden("fil_status", $status);
215  $w=new ICard();
216  $w->jrn=$cn->get_value("select jrn_def_id from importbank.format_bank as a "
217  . "join importbank.import as b on (a.id=b.format_bank_id) "
218  . "where b.id=$1",array($import_id));
219  $w->name='fiche1000';
220  $w->extra='filter';
221  $w->typecard='deb';
222  $w->set_dblclick("fill_ipopcard(this);");
223  $w->set_attribute('ipopup','ipopcard');
224  $w->set_attribute('label','e_third');
225  $w->set_attribute('typecard','deb');
226  $w->set_callback('filter_card');
227  $w->set_function('fill_data');
228  $w->set_attribute('inp','fiche');
229  $w->autocomplete=1;
230  $w->choice="choice_suggest";
231  $w->choice_create=0;
232  echo HtmlInput::hidden('p_jrn',$w->jrn);
233  echo $w->input();
234  echo $w->search();
235  ?>
236 <span id="e_third"></span>
237 <ul style="list-style: none">
238  <li style="display:inline;"><?php echo HtmlInput::submit("set_selected", _("Confirmer"));?></li>
239  <li style="display:inline;"><?php echo HtmlInput::button("cancel", _("Fermer")," onclick=\"removeDiv('select_tiers_div')\"");?></li>
240 </ul>
241 </div>
242 <div id="div_suggest" style="position:float;float:left;height:30em">
243  <h2><?php echo "Suggestion";?></h2>
244  <div id="choice_suggest" class="autocomplete_fixed" style="position: static;height:auto" >
245 
246  </div>
247  </div>
248 
249 <?php echo '</form>';
250  return;
251 case 'show':
252  /*
253  * Show detail operation and let you save it or remove it
254  *array (
255  'gDossier' => '77',
256  'plugin_code' => 'IMPBANK',
257  'act' => 'show',
258  'id' => '15967',
259  'ctl' => 'div15967',
260  )
261  */
262  ob_start();
263  $ctl=$_GET['ctl'];
264  $bi=new Bank_Item($id);
265  $r='';
266  global $msg;
267  $msg='';
268 
269  if ( isset($_GET['remove'] ))
270  {
271  $msg="Opération a effacer";
272  $bi->show_delete($ctl);
273 
274  $bi_sql=new Temp_Bank_Sql($cn,$id);
275  $bi_sql->status='D';
276  $bi_sql->update();
277  $extra='{"id":"'.$id.'","msg":"<span style=\"color:red\">Effacer</span>"}';
278 
279  }
280  else if ( isset($_GET['recup'] ))
281  {
282  $msg="Opération récupérée";
283  $bi_sql=new Temp_Bank_Sql($cn,$id);
284  $bi_sql->status='N';
285  $bi_sql->update();
286  $bi->show_item($ctl);
287  $extra='{"id":"'.$id.'","msg":"<span style=\"color:red\">Récupérer</span>"}';
288 
289  }
290 
291  else
292  if (isset($_GET['save']))
293  {
294  $f_id="";
295  $concerned=HtmlInput::default_value_get("e_concerned".$id, NULL);
296  $concop_json="";
297  $tiers_json="";
298  if ($concerned == "" ) $concerned=null;
299  // If we introduce a qcode , find the f_id
300  if ($_GET['fiche'.$id] != '')
301  {
302  $f_id=$cn->get_value('select f_id from fiche_Detail
303  where
304  ad_value=upper(trim($1)) and ad_id=23',array($_GET['fiche'.$id]));
305  $status='W';
306  $msg_json='<span style=\"color:red;background-color:white\">Attente</span>';
307  $tiers_json=HtmlInput::card_detail(trim(strtoupper($_GET['fiche'.$id])));
308  if ($concerned!=null)
309  {
310  $internal=$cn->get_value("select jr_internal from jrn where jr_id=$1",
311  array($_GET['e_concerned'.$id]));
312  if ($internal!="")
313  {
314  $concop_json=HtmlInput::detail_op($_GET['e_concerned'.$id],
315  $internal);
316  }
317  }
318  }
319  if ($f_id == '') {
320  $f_id=null;
321  $status='N';
322  $msg_json='<span style=\"color:red;background-color:white\">Nouveau</span>';
323  }
324 
325  $bi_sql=new Temp_Bank_Sql($cn,$id);
326  $bi_sql->f_id=$f_id;
327  $rec=$_GET['e_concerned'.$id];
328  $bi_sql->tp_rec=(trim($rec) != '')?trim($rec):null;
329  $bi_sql->status=$status;
330  $bi_sql->libelle=$_GET['libelle'];
331  $bi_sql->amount=$_GET['amount'];
332  $bi_sql->tp_extra=$_GET['tp_extra'];
333  $bi_sql->tp_third=$_GET['tp_third'];
334  $bi_sql->tp_date=$_GET['tp_date'];
335 
336  $bi_sql->update();
337 
338  $msg="Attente";
339  $bi->show_item($ctl);
340  $a_extra=array("id"=>$id,"msg"=>$msg_json,"tiers"=>$tiers_json,"concop"=>$concop_json);
341  $extra=json_encode($a_extra);
342  }
343  else
344  $bi->show_item($ctl);
345  $r=ob_get_contents();
346  ob_end_clean();
347 }
348 $html=escape_xml($r);
349 $extra=escape_xml($extra);
350 header('Content-type: text/xml; charset=UTF-8');
351 echo <<<EOF
352 <?xml version="1.0" encoding="UTF-8"?>
353 <data>
354 <ctl>$ctl</ctl>
355 <code>$html</code>
356 <extra>$extra</extra>
357 </data>
358 EOF;
359 ?>
$msg
$note style
$select_type id
$act
Definition: ajax.php:5
$html
Definition: ajax.php:32
$r
Definition: ajax.php:28
$categorie_appel extra
$rec
Definition: show_import.php:39
global $cn
Definition: ajax.php:27
$ctl
Definition: ajax.php:31
$dossier_id
Definition: ajax.php:27
$a_suggest
Definition: show_list.php:105
$plugin_code
Definition: show_list.php:101
$extra
Definition: ajax.php:33
$sql
static convert_status_sql($p_param)
Convert the status (0 to 5 to importbank.temp_bank.status which is a letter (N New T Transfered W wai...