dolibarr  16.0.5
ajaxcompanies.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
3  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2010 Cyrille de Lambert <info@auguria.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
26 if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal
27 if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
28 if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
29 if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
30 if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
31 if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1');
32 
33 require '../../main.inc.php';
34 
35 
36 /*
37  * View
38  */
39 
40 // Ajout directives pour resoudre bug IE
41 //header('Cache-Control: Public, must-revalidate');
42 //header('Pragma: public');
43 
44 //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
45 top_httphead();
46 
47 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
48 
49 dol_syslog(join(',', $_GET));
50 
51 
52 // Generation liste des societes
53 if (GETPOST('newcompany') || GETPOST('socid', 'int') || GETPOST('id_fourn')) {
54  $return_arr = array();
55 
56  // Define filter on text typed
57  $socid = $_GET['newcompany'] ? $_GET['newcompany'] : '';
58  if (!$socid) $socid = $_GET['socid'] ? $_GET['socid'] : '';
59  if (!$socid) $socid = $_GET['id_fourn'] ? $_GET['id_fourn'] : '';
60 
61  $sql = "SELECT s.rowid, s.nom, s.name_alias, s.code_client, s.code_fournisseur, s.address, s.zip, s.town, s.email, s.siren, s.siret, s.ape, s.idprof4, s.client, s.fournisseur, s.datec, s.logo";
62  $sql .= " , c.label as country, d.nom as departement";
63  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
64  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = s.fk_pays";
65  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON d.rowid = s.fk_departement";
66  $sql .= " WHERE s.entity IN (".getEntity('societe').")";
67  if ($socid) {
68  $sql .= " AND (";
69  // Add criteria on name/code
70  if (!empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) { // Can use index
71  $sql .= "s.nom LIKE '".$db->escape($socid)."%'";
72  $sql .= " OR s.code_client LIKE '".$db->escape($socid)."%'";
73  $sql .= " OR s.code_fournisseur LIKE '".$db->escape($socid)."%'";
74  } else {
75  $sql .= "s.nom LIKE '%".$db->escape($socid)."%'";
76  $sql .= " OR s.code_client LIKE '%".$db->escape($socid)."%'";
77  $sql .= " OR s.code_fournisseur LIKE '%".$db->escape($socid)."%'";
78  }
79  if (!empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql .= " OR s.rowid = '".$db->escape($socid)."'";
80  $sql .= ")";
81  }
82  //if (GETPOST("filter")) $sql.= " AND (".GETPOST("filter", "alpha").")"; // Add other filters
83  $sql .= " ORDER BY s.nom ASC";
84 
85  //dol_syslog("ajaxcompanies", LOG_DEBUG);
86  $resql = $db->query($sql);
87 
88  if ($resql) {
89  while ($row = $db->fetch_array($resql)) {
90  $label = $row['nom'];
91  if ($socid) $label = $label;
92  $row_array['label'] = $label;
93  $row_array['value'] = $row['nom'];
94  $row_array['key'] = $row['rowid'];
95  $row_array['name_alias'] = $row['name_alias'];
96  $row_array['code_client'] = $row['code_client'];
97  $row_array['code_fournisseur'] = $row['code_fournisseur'];
98  $row_array['address'] = $row['address'];
99  $row_array['zip'] = $row['zip'];
100  $row_array['town'] = $row['town'];
101  $row_array['email'] = $row['email'];
102  $row_array['siren'] = $row['siren'];
103  $row_array['siret'] = $row['siret'];
104  $row_array['ape'] = $row['ape'];
105  $row_array['idprof4'] = $row['idprof4'];
106  $row_array['client'] = $row['client'];
107  $row_array['fournisseur'] = $row['fournisseur'];
108  $row_array['datec'] = $row['datec'];
109  $row_array['logo'] = $row['logo'];
110  $row_array['country'] = $row['country'];
111  $row_array['departement'] = $row['departement'];
112 
113  array_push($return_arr, $row_array);
114  }
115 
116  echo json_encode($return_arr);
117  } else {
118  echo json_encode(array('nom'=>'Error', 'label'=>'Error', 'key'=>'Error', 'value'=>'Error'));
119  }
120 } else {
121  echo json_encode(array('nom'=>'ErrorBadParameter', 'label'=>'ErrorBadParameter', 'key'=>'ErrorBadParameter', 'value'=>'ErrorBadParameter'));
122 }
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1407
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742