-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathajax.php
More file actions
209 lines (153 loc) · 5.53 KB
/
Copy pathajax.php
File metadata and controls
209 lines (153 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010 Cyrille de Lambert <info@auguria.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/societe/ajaxcompanies.php
* \brief File to return Ajax response on third parties request
*/
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1');
require '../../main.inc.php';
$langs->loadLangs(array("bills", "dolibarrassistant@dolibarrassistant"));
/*
* View
*/
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
top_httphead();
//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
dol_syslog(join(',', $_GET));
// Retrieve opened conversation
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."dolibarrassistant_conversation WHERE finished=0";
$resql = $db->query($sql);
if($resql){
$obj = $db->fetch_object($resql);
$conversation_subject=$obj->subject;
$question=$obj->question;
}
if ($conversation_subject=="")
{
$return_arr = array();
$row_array['label'] = $langs->trans('CreateBill');
$row_array['value'] = $langs->trans('CreateBill');
$row_array['key'] = 1;
array_push($return_arr, $row_array);
echo json_encode($return_arr);
}
else if ($question=="WhatCustomer")
{
$return_arr = array();
// Define filter on text typed
$socid = $_GET['newcompany']?$_GET['newcompany']:'';
if (! $socid) $socid = $_GET['socid']?$_GET['socid']:'';
if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:'';
$sql = "SELECT rowid, nom";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE s.entity IN (".getEntity('societe').")";
if ($socid)
{
$sql.=" AND (";
// Add criteria on name/code
if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index
{
$sql.="nom LIKE '" . $db->escape($socid) . "%'";
$sql.=" OR code_client LIKE '" . $db->escape($socid) . "%'";
$sql.=" OR code_fournisseur LIKE '" . $db->escape($socid) . "%'";
}
else
{
$sql.="nom LIKE '%" . $db->escape($socid) . "%'";
$sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'";
$sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'";
}
if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'";
$sql.=")";
}
//if (GETPOST("filter")) $sql.= " AND (".GETPOST("filter", "alpha").")"; // Add other filters
$sql.= " ORDER BY nom ASC";
//dol_syslog("ajaxcompanies", LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
while ($row = $db->fetch_array($resql))
{
$label=$row['nom'];
if ($socid) $label=preg_replace('/('.preg_quote($socid, '/').')/i', '<strong>$1</strong>', $label, 1);
$row_array['label'] = $label;
$row_array['value'] = $row['nom'];
$row_array['key'] = $row['rowid'];
array_push($return_arr, $row_array);
}
echo json_encode($return_arr);
}
else
{
echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error'));
}
}
else if ($question=="WhatProduct")
{
$return_arr = array();
$sql = "SELECT *";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= " WHERE p.entity IN (".getEntity('societe').")";
$resql=$db->query($sql);
if ($resql)
{
while ($row = $db->fetch_array($resql))
{
$label=$row['label'];
$row_array['label'] = $label;
$row_array['value'] = $row['label'];
$row_array['key'] = $row['rowid'];
array_push($return_arr, $row_array);
}
echo json_encode($return_arr);
}
}
else if ($question=="AnythingElse")
{
$return_arr = array();
$row_array['label'] = "No, ".$langs->trans('Validate');
$row_array['value'] = "No, ".$langs->trans('Validate');
$row_array['key'] = $row['rowid'];
array_push($return_arr, $row_array);
$sql = "SELECT *";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= " WHERE p.entity IN (".getEntity('societe').")";
$resql=$db->query($sql);
if ($resql)
{
while ($row = $db->fetch_array($resql))
{
$label=$row['label'];
$row_array['label'] = $label;
$row_array['value'] = $row['label'];
$row_array['key'] = $row['rowid'];
array_push($return_arr, $row_array);
}
echo json_encode($return_arr);
}
}