dolibarr 23.0.3
clients.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
32
41$action = GETPOST('action', 'aZ09');
42
43// Secrutiy check
44if ($user->socid > 0) {
45 $action = '';
46 $socid = $user->socid;
47}
48
49if (!$user->hasRight('facture', 'lire')) {
51}
52
53// Load translation files required by the page
54$langs->load("companies");
55
56$mode = GETPOST("mode");
57
58$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
59$sortfield = GETPOST('sortfield', 'aZ09comma');
60$sortorder = GETPOST('sortorder', 'aZ09comma');
61$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
62if (empty($page) || $page == -1) {
63 $page = 0;
64} // If $page is not defined, or '' or -1
65$offset = $limit * $page;
66$pageprev = $page - 1;
67$pagenext = $page + 1;
68if (!$sortfield) {
69 $sortfield = "nom";
70}
71if (!$sortorder) {
72 $sortorder = "ASC";
73}
74
75$sql = null;
76/*
77 * Action
78 */
79
80if ($action == 'note' && $user->hasRight('societe', 'lire')) {
81 $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note = '".$db->escape($note)."' WHERE rowid=".((int) $socid);
82 $result = $db->query($sql);
83}
84
85
86/*
87 * View
88 */
89
90llxHeader();
91
92$thirdpartystatic = new Societe($db);
93
94if ($mode == 'search' && $sql !== null) {
95 $resql = $db->query($sql);
96 if ($resql) {
97 if ($db->num_rows($resql) == 1) {
98 $obj = $db->fetch_object($resql);
99 $socid = $obj->rowid;
100 }
101 $db->free($resql);
102 }
103}
104
105
106// Mode List
107
108$sql = "SELECT s.rowid, s.nom as name, s.client, s.town, s.datec, s.datea";
109$sql .= ", st.libelle as stcomm, s.prefix_comm, s.code_client as code_client_compta, s.code_compta ";
110if (!$user->hasRight('societe', 'client', 'voir')) {
111 $sql .= ", sc.fk_soc, sc.fk_user ";
112}
113$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
114if (!$user->hasRight('societe', 'client', 'voir')) {
115 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
116}
117$sql .= " WHERE s.fk_stcomm = st.id AND s.client in (1, 3)";
118$sql .= " AND s.entity IN (".getEntity('societe').")";
119if (!$user->hasRight('societe', 'client', 'voir')) {
120 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
121}
122if (dol_strlen($stcomm)) {
123 $sql .= " AND s.fk_stcomm=".((int) $stcomm);
124}
125if (GETPOST("search_nom")) {
126 $sql .= natural_search("s.nom", GETPOST("search_nom"));
127}
128if (GETPOST("search_compta")) {
129 $sql .= natural_search("s.code_compta", GETPOST("search_compta"));
130}
131if (GETPOST("search_code_client")) {
132 $sql .= natural_search("s.code_client", GETPOST("search_code_client"));
133}
134if ($socid) {
135 $sql .= " AND s.rowid = ".((int) $socid);
136}
137$sql .= $db->order($sortfield, $sortorder);
138$sql .= $db->plimit($conf->liste_limit + 1, $offset);
139//print $sql;
140
141$resql = $db->query($sql);
142if ($resql) {
143 $num = $db->num_rows($resql);
144 $i = 0;
145
146 $langs->load('commercial');
147
148 print_barre_liste($langs->trans("Customers"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
149
150 print '<form method="GET" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
151
152 print '<table class="liste centpercent">';
153 print '<tr class="liste_titre">';
154
155 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "", 'valign="center"', $sortfield, $sortorder);
156 print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "s.town", "", "", 'valign="center"', $sortfield, $sortorder);
157 print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "", '', $sortfield, $sortorder, 'left ');
158 print_liste_field_titre("AccountancyCode", $_SERVER["PHP_SELF"], "s.code_compta", "", "", '', $sortfield, $sortorder, 'left ');
159 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", $addu, "", '', $sortfield, $sortorder, 'right ');
160 print "</tr>\n";
161
162 // Fields title search
163 print '<tr class="liste_titre">';
164
165 print '<td class="liste_titre left">';
166 print '<input class="flat" type="text" name="search_nom" value="'.GETPOST("search_nom").'"></td>';
167
168 print '<td class="liste_titre">&nbsp;</td>';
169
170 print '<td class="liste_titre left">';
171 print '<input class="flat" type="text" size="10" name="search_code_client" value="'.GETPOST("search_code_client").'">';
172 print '</td>';
173
174 print '<td class="liste_titre left">';
175 print '<input class="flat" type="text" size="10" name="search_compta" value="'.GETPOST("search_compta").'">';
176 print '</td>';
177
178 print '<td colspan="2" class="liste_titre right">';
179 print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"), 'search.png', '', 0, 1).'" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
180 print '</td>';
181 print "</tr>\n";
182
183 while ($i < min($num, $conf->liste_limit)) {
184 $obj = $db->fetch_object($resql);
185
186 print '<tr class="oddeven">';
187 print '<td>';
188 $thirdpartystatic->id = $obj->rowid;
189 $thirdpartystatic->name = $obj->name;
190 $thirdpartystatic->client = $obj->client;
191 print $thirdpartystatic->getNomUrl(1, 'compta');
192 print '</td>';
193 print '<td>'.dolPrintLabel($obj->town).'</td>';
194 print '<td class="left">'.dolPrintLabel($obj->code_client).'</td>';
195 print '<td class="left">'.dolPrintLabel($obj->code_compta_client).'</td>';
196 print '<td class="right">'.dol_print_date($db->jdate($obj->datec)).'</td>';
197 print "</tr>\n";
198 $i++;
199 }
200 print "</table>";
201
202 print '</form>';
203
204 $db->free($resql);
205} else {
206 dol_print_error($db);
207}
208
209llxFooter();
210$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.