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')) {
27  define('NOTOKENRENEWAL', 1); // Disables token renewal
28 }
29 if (!defined('NOREQUIREMENU')) {
30  define('NOREQUIREMENU', '1');
31 }
32 if (!defined('NOREQUIREHTML')) {
33  define('NOREQUIREHTML', '1');
34 }
35 if (!defined('NOREQUIREAJAX')) {
36  define('NOREQUIREAJAX', '1');
37 }
38 if (!defined('NOREQUIRESOC')) {
39  define('NOREQUIRESOC', '1');
40 }
41 if (!defined('NOCSRFCHECK')) {
42  define('NOCSRFCHECK', '1');
43 }
44 
45 require '../../main.inc.php';
46 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
47 
48 $id = GETPOST('socid', 'int') || GETPOST('id_fourn', 'int');
49 
50 $object = new Societe($db);
51 if ($id > 0) {
52  $object->fetch($id);
53 }
54 
55 // Security check
56 if ($user->socid > 0) {
57  $socid = $user->socid;
58  $object->id = $socid;
59 }
60 restrictedArea($user, 'societe', $object->id, '&societe');
61 
62 
63 /*
64  * View
65  */
66 
67 // Ajout directives pour resoudre bug IE
68 //header('Cache-Control: Public, must-revalidate');
69 //header('Pragma: public');
70 
71 //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
72 top_httphead();
73 
74 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
75 
76 
77 // Generate list of companies
78 if (GETPOST('newcompany') || GETPOST('socid', 'int') || GETPOST('id_fourn', 'int')) {
79  $return_arr = array();
80 
81  // Define filter on text typed
82  $socid = GETPOST('newcompany');
83  if (!$socid) {
84  $socid = GETPOST('socid', 'int');
85  }
86  if (!$socid) {
87  $socid = GETPOST('id_fourn', 'int');
88  }
89 
90  $sql = "SELECT s.rowid, s.nom";
91  if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST)) {
92  $sql .= ", s.client, s.fournisseur, s.code_client, s.code_fournisseur";
93  }
94  if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
95  $sql .= ", s.address, s.zip, s.town";
96  $sql .= ", dictp.code as country_code";
97  }
98  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
99  if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
100  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as dictp ON dictp.rowid = s.fk_pays";
101  }
102  $sql .= " WHERE s.entity IN (".getEntity('societe').")";
103  if ($socid) {
104  $sql .= " AND (";
105  // Add criteria on name/code
106  if (!empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) { // Can use index
107  $sql .= "nom LIKE '".$db->escape($socid)."%'";
108  $sql .= " OR code_client LIKE '".$db->escape($socid)."%'";
109  $sql .= " OR code_fournisseur LIKE '".$db->escape($socid)."%'";
110  } else {
111  $sql .= "nom LIKE '%".$db->escape($socid)."%'";
112  $sql .= " OR code_client LIKE '%".$db->escape($socid)."%'";
113  $sql .= " OR code_fournisseur LIKE '%".$db->escape($socid)."%'";
114  }
115  if (!empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) {
116  $sql .= " OR rowid = ".((int) $socid);
117  }
118  $sql .= ")";
119  }
120  //if (GETPOST("filter")) $sql.= " AND (".GETPOST("filter", "alpha").")"; // Add other filters
121  $sql .= " ORDER BY nom ASC";
122 
123  //dol_syslog("ajaxcompanies", LOG_DEBUG);
124  $resql = $db->query($sql);
125  if ($resql) {
126  while ($row = $db->fetch_array($resql)) {
127  $label = '';
128  if (! empty($conf->global->SOCIETE_ADD_REF_IN_LIST)) {
129  if (($row['client']) && (!empty($row['code_client']))) {
130  $label = $row['code_client'].' - ';
131  }
132  if (($row['fournisseur']) && (!empty($row['code_fournisseur']))) {
133  $label .= $row['code_fournisseur'].' - ';
134  }
135  }
136 
137  $label .= $row['nom'];
138 
139  if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
140  $label .= ($row['address'] ? ' - '.$row['address'] : '').($row['zip'] ? ' - '.$row['zip'] : '').($row['town'] ? ' '.$row['town'] : '');
141  if (!empty($row['country_code'])) {
142  $label .= ', '.$langs->trans('Country'.$row['country_code']);
143  }
144  }
145  if ($socid) {
146  $label = preg_replace('/('.preg_quote($socid, '/').')/i', '<strong>$1</strong>', $label, 1);
147  }
148  $row_array['label'] = $label;
149  $row_array['value'] = $row['nom'];
150  $row_array['key'] = $row['rowid'];
151 
152  array_push($return_arr, $row_array);
153  }
154 
155  echo json_encode($return_arr);
156  } else {
157  echo json_encode(array('nom'=>'Error', 'label'=>'Error', 'key'=>'Error', 'value'=>'Error'));
158  }
159 } else {
160  echo json_encode(array('nom'=>'ErrorBadParameter', 'label'=>'ErrorBadParameter', 'key'=>'ErrorBadParameter', 'value'=>'ErrorBadParameter'));
161 }
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
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
$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