dolibarr  13.0.2
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 {
55  $return_arr = array();
56 
57  // Define filter on text typed
58  $socid = $_GET['newcompany'] ? $_GET['newcompany'] : '';
59  if (!$socid) $socid = $_GET['socid'] ? $_GET['socid'] : '';
60  if (!$socid) $socid = $_GET['id_fourn'] ? $_GET['id_fourn'] : '';
61 
62  $sql = "SELECT rowid, nom";
63  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
64  $sql .= " WHERE s.entity IN (".getEntity('societe').")";
65  if ($socid)
66  {
67  $sql .= " AND (";
68  // Add criteria on name/code
69  if (!empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index
70  {
71  $sql .= "nom LIKE '".$db->escape($socid)."%'";
72  $sql .= " OR code_client LIKE '".$db->escape($socid)."%'";
73  $sql .= " OR code_fournisseur LIKE '".$db->escape($socid)."%'";
74  } else {
75  $sql .= "nom LIKE '%".$db->escape($socid)."%'";
76  $sql .= " OR code_client LIKE '%".$db->escape($socid)."%'";
77  $sql .= " OR code_fournisseur LIKE '%".$db->escape($socid)."%'";
78  }
79  if (!empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql .= " OR rowid = '".$db->escape($socid)."'";
80  $sql .= ")";
81  }
82  //if (GETPOST("filter")) $sql.= " AND (".GETPOST("filter", "alpha").")"; // Add other filters
83  $sql .= " ORDER BY nom ASC";
84 
85  //dol_syslog("ajaxcompanies", LOG_DEBUG);
86  $resql = $db->query($sql);
87  if ($resql)
88  {
89  while ($row = $db->fetch_array($resql))
90  {
91  $label = $row['nom'];
92  if ($socid) $label = preg_replace('/('.preg_quote($socid, '/').')/i', '<strong>$1</strong>', $label, 1);
93  $row_array['label'] = $label;
94  $row_array['value'] = $row['nom'];
95  $row_array['key'] = $row['rowid'];
96 
97  array_push($return_arr, $row_array);
98  }
99 
100  echo json_encode($return_arr);
101  } else {
102  echo json_encode(array('nom'=>'Error', 'label'=>'Error', 'key'=>'Error', 'value'=>'Error'));
103  }
104 } else {
105  echo json_encode(array('nom'=>'ErrorBadParameter', 'label'=>'ErrorBadParameter', 'key'=>'ErrorBadParameter', 'value'=>'ErrorBadParameter'));
106 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1214
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232