-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
list.php
436 lines (389 loc) · 18.6 KB
/
list.php
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <[email protected]>
* Copyright (C) 2004-2011 Laurent Destailleur <[email protected]>
* Copyright (C) 2005-2012 Regis Houssin <[email protected]>
* Copyright (C) 2012 Marcos García <[email protected]>
*
* 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:https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/societe/list.php
* \ingroup societe
* \brief Page to show a third party
*/
// Load Dolibarr environment
$res=0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
// Try main.inc.php into web root detected using web root caluclated from SCRIPT_FILENAME
$tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; }
if (! $res && $i > 0 && file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include substr($tmp, 0, ($i+1))."/main.inc.php";
if (! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include dirname(substr($tmp, 0, ($i+1)))."/main.inc.php";
// Try main.inc.php using relative path
if (! $res && file_exists("../main.inc.php")) $res=@include "../main.inc.php";
if (! $res && file_exists("../../main.inc.php")) $res=@include "../../main.inc.php";
if (! $res && file_exists("../../../main.inc.php")) $res=@include "../../../main.inc.php";
if (! $res) die("Include of main fails");
include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
$langs->load("companies");
$langs->load("customers");
$langs->load("suppliers");
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid=$user->socid;
$result = restrictedArea($user, 'societe', $socid, '');
$search_all=trim(GETPOSTISSET('search_all')?GETPOST('search_all', 'alpha'):GETPOST('sall', 'alpha'));
$search_nom=trim(GETPOST("search_nom"));
$search_nom_only=trim(GETPOST("search_nom_only"));
$search_ville=trim(GETPOST("search_ville"));
$socname=trim(GETPOST("socname"));
$search_idprof1=trim(GETPOST('search_idprof1'));
$search_idprof2=trim(GETPOST('search_idprof2'));
$search_idprof3=trim(GETPOST('search_idprof3'));
$search_idprof4=trim(GETPOST('search_idprof4'));
$search_idprof5=trim(GETPOST('search_idprof5'));
$search_idprof6=trim(GETPOST('search_idprof6'));
$search_sale=trim(GETPOST("search_sale"));
$search_categ=trim(GETPOST("search_categ"));
$mode=GETPOST("mode");
$modesearch=GETPOST("mode_search");
$search_type=trim(GETPOST('search_type'));
// Load variable for pagination
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
// If $page is not defined, or '' or -1 or if we click on clear filters
$page = 0;
}
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="s.nom";
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array(
's.nom'=>"ThirdPartyName",
's.code_client'=>"CustomerCode",
's.email'=>"EMail",
's.url'=>"URL",
's.tva_intra'=>"VATIntra"
);
/*
* Actions
*/
// Recherche
if ($mode == 'search') {
$search_nom=$socname;
$sql = "SELECT s.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
if ($search_sale || !$user->hasRight('societe', 'client', 'voir') && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
// We'll need this table joined to the select in order to filter by categ
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
$sql.= " WHERE s.entity IN (".getEntity('societe', 1).")";
$sql.= " AND (";
$sql.= " s.nom LIKE '%".$db->escape($socname)."%'";
$sql.= " OR s.code_client LIKE '%".$db->escape($socname)."%'";
$sql.= " OR s.email LIKE '%".$db->escape($socname)."%'";
$sql.= " OR s.url LIKE '%".$db->escape($socname)."%'";
if (isModEnabled("barcode")) {
$sql.= "OR s.barcode LIKE '".$db->escape($socname)."'";
}
$sql.= ")";
if (!$user->hasRight('societe', 'client', 'voir') && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
if ($search_categ) $sql.= " AND s.rowid = cs.fk_soc"; // Join for the needed table to filter by categ
if (! $user->hasRight('societe', 'lire') || ! $user->hasRight('fournisseur', 'lire')) {
if (! $user->hasRight('fournisseur', 'lire')) $sql.=" AND s.fourn != 1";
}
// Insert sale filter
if ($search_sale) {
$sql .= " AND sc.fk_user = ".$search_sale;
}
// Insert categ filter
if ($search_categ) {
$sql .= " AND cs.fk_categorie = ".$search_categ;
}
// Filter on type of thirdparty
if ($search_type > 0 && in_array($search_type, array('1,3','2,3'))) $sql .= " AND s.client IN (".$db->escape($search_type).")";
if ($search_type > 0 && in_array($search_type, array('4'))) $sql .= " AND s.fournisseur = 1";
if ($search_type == '0') $sql .= " AND s.client = 0 AND s.fournisseur = 0";
$result=$db->query($sql);
if ($result) {
if ($db->num_rows($result) == 1) {
$obj = $db->fetch_object($result);
$socid = $obj->rowid;
header("Location: ".DOL_URL_ROOT."/societe/soc.php?socid=".$socid);
exit;
}
$db->free($result);
}
}
// Do we click on purge search criteria ?
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) {
$search_categ='';
$search_sale='';
$socname="";
$search_nom="";
$search_ville="";
$search_idprof1='';
$search_idprof2='';
$search_idprof3='';
$search_idprof4='';
$search_type='';
}
/*
* View
*/
$form=new Form($db);
$htmlother=new FormOther($db);
$companystatic=new Societe($db);
$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('', $langs->trans("ThirdParty"), $help_url);
if ($socname) {
$search_nom=$socname;
}
/*
* Mode Liste
*/
/*
REM: Regle sur droits "Voir tous les clients"
Utilisateur interne socid=0 + Droits voir tous clients => Voit toute societe
Utilisateur interne socid=0 + Pas de droits voir tous clients => Ne voit que les societes liees comme commercial
Utilisateur externe socid=x + Droits voir tous clients => Ne voit que lui meme
Utilisateur externe socid=x + Pas de droits voir tous clients => Ne voit que lui meme
*/
$title=$langs->trans("ListOfThirdParties");
$sql = "SELECT s.rowid, s.nom as name, s.town, s.datec,";
$sql.= " st.libelle as stcomm, s.prefix_comm, s.client, s.fournisseur, s.canvas, s.status as status,";
$sql.= " s.siren as idprof1, s.siret as idprof2, ape as idprof3, idprof4 as idprof4";
// We'll need these fields in order to filter by sale (including the case where the user can only see his prospects)
if ($search_sale) $sql .= ", sc.fk_soc, sc.fk_user";
// We'll need these fields in order to filter by categ
if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_soc";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX."c_stcomm as st";
// We'll need this table joined to the select in order to filter by sale
if ($search_sale || !$user->hasRight('societe', 'client', 'voir')) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
// We'll need this table joined to the select in order to filter by categ
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
$sql.= " WHERE s.fk_stcomm = st.id";
$sql.= " AND s.entity IN (".getEntity('societe', 1).")";
if (! $user->hasRight('societe', 'client', 'voir') && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
if ($search_categ) $sql.= " AND s.rowid = cs.fk_soc"; // Join for the needed table to filter by categ
if (! $user->hasRight('fournisseur', 'lire')) $sql.=" AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
// Insert sale filter
if ($search_sale) {
$sql .= " AND sc.fk_user = ".$search_sale;
}
// Insert categ filter
if ($search_categ) {
$sql .= " AND cs.fk_categorie = ".$search_categ;
}
if ($search_nom_only) {
$sql.= " AND s.nom LIKE '%".$db->escape($search_nom_only)."%'";
}
if ($search_all) $sql.= natural_search(array_keys($fieldstosearchall), $search_all);
if ($search_nom) {
$sql.= " AND (";
$sql.= "s.nom LIKE '%".$db->escape($search_nom)."%'";
$sql.= " OR s.code_client LIKE '%".$db->escape($search_nom)."%'";
$sql.= " OR s.email LIKE '%".$db->escape($search_nom)."%'";
$sql.= " OR s.url LIKE '%".$db->escape($search_nom)."%'";
$sql.= ")";
}
if ($search_ville) $sql .= " AND s.town LIKE '%".$db->escape($search_ville)."%'";
if ($search_idprof1) $sql .= " AND s.siren LIKE '%".$db->escape($search_idprof1)."%'";
if ($search_idprof2) $sql .= " AND s.siret LIKE '%".$db->escape($search_idprof2)."%'";
if ($search_idprof3) $sql .= " AND s.ape LIKE '%".$db->escape($search_idprof3)."%'";
if ($search_idprof4) $sql .= " AND s.idprof4 LIKE '%".$db->escape($search_idprof4)."%'";
if ($search_idprof5) $sql .= " AND s.idprof5 LIKE '%".$db->escape($search_idprof5)."%'";
if ($search_idprof6) $sql .= " AND s.idprof6 LIKE '%".$db->escape($search_idprof6)."%'";
// Filter on type of thirdparty
if ($search_type > 0 && in_array($search_type, array('1,3','2,3'))) $sql .= " AND s.client IN (".$db->escape($search_type).")";
if ($search_type > 0 && in_array($search_type, array('4'))) $sql .= " AND s.fournisseur = 1";
if ($search_type == '0') $sql .= " AND s.client = 0 AND s.fournisseur = 0";
//print $sql;
// Count total nb of records
$nbtotalofrecords = '';
if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
}
$sql.= $db->order($sortfield, $sortorder);
$sql.= $db->plimit($conf->liste_limit+1, $offset);
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$params = "&socname=".$socname."&search_nom=".$search_nom."&search_ville=".$search_ville;
$params.= '&search_idprof1='.$search_idprof1;
$params.= '&search_idprof2='.$search_idprof2;
$params.= '&search_idprof3='.$search_idprof3;
$params.= '&search_idprof4='.$search_idprof4;
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
// Show delete result message
if (GETPOST('delsoc')) {
dol_htmloutput_mesg($langs->trans("CompanyDeleted", GETPOST('delsoc')), '', 'ok');
}
$langs->load("other");
$textprofid=array();
foreach (array(1,2,3,4) as $key) {
$label=$langs->transnoentities("ProfId".$key.$mysoc->country_code);
$textprofid[$key]='';
if ($label != "ProfId".$key.$mysoc->country_code) { // Get only text between ()
if (preg_match('/\((.*)\)/i', $label, $reg)) $label=$reg[1];
$textprofid[$key]=$langs->trans("ProfIdShortDesc", $key, $mysoc->country_code, $label);
}
}
if ($search_all) {
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall).'</div>';
}
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
print '<input type="hidden" name="token" value="'.newToken().'">';
// Filter on categories
/* Not possible in this page because list is for ALL third parties type
$moreforfilter='';
if (isModEnabled("categorie"))
{
$moreforfilter.=$langs->trans('Categories'). ': ';
$moreforfilter.=$htmlother->select_categories(2,$search_categ,'search_categ');
$moreforfilter.=' ';
}
// If the user can view prospects other than his'
if ($user->rights->societe->client->voir || $socid)
{
$moreforfilter.=$langs->trans('SalesRepresentatives'). ': ';
$moreforfilter.=$htmlother->select_salesrepresentatives($search_sale,'search_sale',$user, 0, 1, 'maxwidth300');
}
if ($moreforfilter)
{
print '<tr class="liste_titre">';
print '<td class="liste_titre" colspan="8">';
print $moreforfilter;
print '</td></tr>';
}
*/
print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">';
// Lines of titles
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom", "", $params, "", $sortfield, $sortorder);
print_liste_field_titre($langs->trans("Town"), $_SERVER["PHP_SELF"], "s.town", "", $params, '', $sortfield, $sortorder);
print_liste_field_titre($form->textwithpicto($langs->trans("ProfId1Short"), $textprofid[1], 1, 0), $_SERVER["PHP_SELF"], "s.siren", "", $params, 'nowrap="nowrap"', $sortfield, $sortorder);
print_liste_field_titre($form->textwithpicto($langs->trans("ProfId2Short"), $textprofid[2], 1, 0), $_SERVER["PHP_SELF"], "s.siret", "", $params, 'nowrap="nowrap"', $sortfield, $sortorder);
print_liste_field_titre($form->textwithpicto($langs->trans("ProfId3Short"), $textprofid[3], 1, 0), $_SERVER["PHP_SELF"], "s.ape", "", $params, 'nowrap="nowrap"', $sortfield, $sortorder);
print_liste_field_titre($form->textwithpicto($langs->trans("ProfId4Short"), $textprofid[4], 1, 0), $_SERVER["PHP_SELF"], "s.idprof4", "", $params, 'nowrap="nowrap"', $sortfield, $sortorder);
print '<td></td>';
print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "s.status", "", $params, 'align="right"', $sortfield, $sortorder);
print "</tr>\n";
// Fields title search
print '<tr class="liste_titre">';
print '<td class="liste_titre">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
if (! empty($search_nom_only) && empty($search_nom)) $search_nom=$search_nom_only;
print '<input class="flat" type="text" name="search_nom" value="'.$search_nom.'">';
print '</td><td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_ville" value="'.$search_ville.'">';
print '</td>';
// IdProf1
print '<td class="liste_titre">';
print '<input class="flat" size="8" type="text" name="search_idprof1" value="'.$search_idprof1.'">';
print '</td>';
// IdProf2
print '<td class="liste_titre">';
print '<input class="flat" size="8" type="text" name="search_idprof2" value="'.$search_idprof2.'">';
print '</td>';
// IdProf3
print '<td class="liste_titre">';
print '<input class="flat" size="8" type="text" name="search_idprof3" value="'.$search_idprof3.'">';
print '</td>';
// IdProf4
print '<td class="liste_titre">';
print '<input class="flat" size="8" type="text" name="search_idprof4" value="'.$search_idprof4.'">';
print '</td>';
// Type (customer/prospect/supplier)
print '<td class="liste_titre" align="middle">';
print '<select class="flat" name="search_type">';
print '<option value="-1"'.($search_type==''?' selected="selected"':'').'> </option>';
print '<option value="1,3"'.($search_type=='1,3'?' selected="selected"':'').'>'.$langs->trans('Customer').'</option>';
if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2,3"'.($search_type=='2,3'?' selected="selected"':'').'>'.$langs->trans('Prospect').'</option>';
//if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="3"'.($search_type=='3'?' selected="selected"':'').'>'.$langs->trans('ProspectCustomer').'</option>';
print '<option value="4"'.($search_type=='4'?' selected="selected"':'').'>'.$langs->trans('Supplier').'</option>';
print '<option value="0"'.($search_type=='0'?' selected="selected"':'').'>'.$langs->trans('Others').'</option>';
print '</select></td>';
// Status
print '<td class="liste_titre" align="right">';
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print ' ';
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</td>';
print "</tr>\n";
$var=true;
while ($i < min($num, $conf->liste_limit)) {
$obj = $db->fetch_object($resql);
$var=!$var;
print "<tr $bc[$var]><td>";
$companystatic->id=$obj->rowid;
$companystatic->name=$obj->name;
$companystatic->canvas=$obj->canvas;
$companystatic->client=$obj->client;
$companystatic->status=$obj->status;
print $companystatic->getNomUrl(1, '', 24);
print "</td>\n";
print "<td>".$obj->town."</td>\n";
print "<td>".$obj->idprof1."</td>\n";
print "<td>".$obj->idprof2."</td>\n";
print "<td>".$obj->idprof3."</td>\n";
print "<td>".$obj->idprof4."</td>\n";
print '<td class="center">';
$s='';
if (($obj->client==1 || $obj->client==3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
$companystatic->name=$langs->trans("Customer");
$s.=$companystatic->getNomUrl(0, 'customer');
}
if (($obj->client==2 || $obj->client==3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
if ($s) $s.=" / ";
$companystatic->name=$langs->trans("Prospect");
$s.=$companystatic->getNomUrl(0, 'prospect');
}
if (isModEnabled("fournisseur") && $obj->fournisseur) {
if ($s) $s.=" / ";
$companystatic->name=$langs->trans("Supplier");
$s.=$companystatic->getNomUrl(0, 'supplier');
}
print $s;
print '</td>';
print '<td align="right">'.$companystatic->getLibStatut(3).'</td>';
print '</tr>'."\n";
$i++;
}
$db->free($resql);
print "</table>";
print '</div>';
print '</form>';
} else {
dol_print_error($db);
}
llxFooter();
$db->close();