dolibarr  18.0.0-alpha
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 
32 // Load Dolibarr environment
33 require '../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
35 
36 $object = new Societe($db);
37 
38 $usesublevelpermission = '';
39 
40 // Security check
41 restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission);
42 
43 
44 /*
45  * View
46  */
47 
48 // Ajout directives pour resoudre bug IE
49 //header('Cache-Control: Public, must-revalidate');
50 //header('Pragma: public');
51 
52 //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
53 top_httphead();
54 
55 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
56 
57 dol_syslog(join(',', $_GET));
58 
59 
60 // Generation liste des societes
61 if (GETPOST('newcompany') || GETPOST('socid', 'int') || GETPOST('id_fourn')) {
62  $return_arr = array();
63 
64  // Define filter on text typed
65  $socid = GETPOST('newcompany');
66  if (!$socid) $socid = GETPOST('socid');
67  if (!$socid) $socid = GETPOST('id_fourn');
68 
69  $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";
70  $sql .= " , c.label as country, d.nom as departement";
71  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
72  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = s.fk_pays";
73  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON d.rowid = s.fk_departement";
74  $sql .= " WHERE s.entity IN (".getEntity('societe').")";
75  if ($socid) {
76  $sql .= " AND (";
77  // Add criteria on name/code
78  if (!empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) { // Can use index
79  $sql .= "s.nom LIKE '".$db->escape($db->escapeforlike($socid))."%'";
80  $sql .= " OR s.code_client LIKE '".$db->escape($db->escapeforlike($socid))."%'";
81  $sql .= " OR s.code_fournisseur LIKE '".$db->escape($db->escapeforlike($socid))."%'";
82  } else {
83  $sql .= "s.nom LIKE '%".$db->escape($db->escapeforlike($socid))."%'";
84  $sql .= " OR s.code_client LIKE '%".$db->escape($db->escapeforlike($socid))."%'";
85  $sql .= " OR s.code_fournisseur LIKE '%".$db->escape($db->escapeforlike($socid))."%'";
86  }
87  if (!empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) {
88  $sql .= " OR s.rowid = ".((int) $socid);
89  }
90  $sql .= ")";
91  }
92  if ($user->socid > 0) {
93  $sql .= " AND s.rowid = ".((int) $user->socid);
94  }
95  //if (GETPOST("filter")) $sql.= " AND (".GETPOST("filter", "alpha").")"; // Add other filters
96  $sql .= " ORDER BY s.nom ASC";
97 
98  //dol_syslog("ajaxcompanies", LOG_DEBUG);
99  $resql = $db->query($sql);
100 
101  if ($resql) {
102  while ($row = $db->fetch_array($resql)) {
103  $label = $row['nom'];
104  if ($socid) $label = $label;
105  $row_array['label'] = $label;
106  $row_array['value'] = $row['nom'];
107  $row_array['key'] = $row['rowid'];
108  $row_array['name_alias'] = $row['name_alias'];
109  $row_array['code_client'] = $row['code_client'];
110  $row_array['code_fournisseur'] = $row['code_fournisseur'];
111  $row_array['address'] = $row['address'];
112  $row_array['zip'] = $row['zip'];
113  $row_array['town'] = $row['town'];
114  $row_array['email'] = $row['email'];
115  $row_array['siren'] = $row['siren'];
116  $row_array['siret'] = $row['siret'];
117  $row_array['ape'] = $row['ape'];
118  $row_array['idprof4'] = $row['idprof4'];
119  $row_array['client'] = $row['client'];
120  $row_array['fournisseur'] = $row['fournisseur'];
121  $row_array['datec'] = $row['datec'];
122  $row_array['logo'] = $row['logo'];
123  $row_array['country'] = $row['country'];
124  $row_array['departement'] = $row['departement'];
125 
126  array_push($return_arr, $row_array);
127  }
128 
129  echo json_encode($return_arr);
130  } else {
131  echo json_encode(array('nom'=>'Error', 'label'=>'Error', 'key'=>'Error', 'value'=>'Error'));
132  }
133 } else {
134  echo json_encode(array('nom'=>'ErrorBadParameter', 'label'=>'ErrorBadParameter', 'key'=>'ErrorBadParameter', 'value'=>'ErrorBadParameter'));
135 }
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:50
top_httphead
if(!defined('NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1480
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:745
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:567
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1685
restrictedArea
restrictedArea(User $user, $features, $object=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:350