dolibarr 21.0.0-alpha
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 Frédéric France <frederic.france@free.fr>
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
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
31
32$action = GETPOST('action', 'aZ09');
33
34// Secrutiy check
35if ($user->socid > 0) {
36 $action = '';
37 $socid = $user->socid;
38}
39
40if (!$user->hasRight('facture', 'lire')) {
42}
43
44// Load translation files required by the page
45$langs->load("companies");
46
47$mode = GETPOST("mode");
48
49$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
50$sortfield = GETPOST('sortfield', 'aZ09comma');
51$sortorder = GETPOST('sortorder', 'aZ09comma');
52$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
53if (empty($page) || $page == -1) {
54 $page = 0;
55} // If $page is not defined, or '' or -1
56$offset = $limit * $page;
57$pageprev = $page - 1;
58$pagenext = $page + 1;
59if (!$sortfield) {
60 $sortfield = "nom";
61}
62if (!$sortorder) {
63 $sortorder = "ASC";
64}
65
66/*
67 * Action
68 */
69
70if ($action == 'note' && $user->hasRight('societe', 'lire')) {
71 $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note = '".$db->escape($note)."' WHERE rowid=".((int) $socid);
72 $result = $db->query($sql);
73}
74
75
76/*
77 * View
78 */
79
80llxHeader();
81
82$thirdpartystatic = new Societe($db);
83
84if ($mode == 'search') {
85 $resql = $db->query($sql);
86 if ($resql) {
87 if ($db->num_rows($resql) == 1) {
88 $obj = $db->fetch_object($resql);
89 $socid = $obj->rowid;
90 }
91 $db->free($resql);
92 }
93}
94
95
96// Mode List
97
98$sql = "SELECT s.rowid, s.nom as name, s.client, s.town, s.datec, s.datea";
99$sql .= ", st.libelle as stcomm, s.prefix_comm, s.code_client as code_client_compta, s.code_compta ";
100if (!$user->hasRight('societe', 'client', 'voir')) {
101 $sql .= ", sc.fk_soc, sc.fk_user ";
102}
103$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
104if (!$user->hasRight('societe', 'client', 'voir')) {
105 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
106}
107$sql .= " WHERE s.fk_stcomm = st.id AND s.client in (1, 3)";
108$sql .= " AND s.entity IN (".getEntity('societe').")";
109if (!$user->hasRight('societe', 'client', 'voir')) {
110 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
111}
112if (dol_strlen($stcomm)) {
113 $sql .= " AND s.fk_stcomm=".((int) $stcomm);
114}
115if (GETPOST("search_nom")) {
116 $sql .= natural_search("s.nom", GETPOST("search_nom"));
117}
118if (GETPOST("search_compta")) {
119 $sql .= natural_search("s.code_compta", GETPOST("search_compta"));
120}
121if (GETPOST("search_code_client")) {
122 $sql .= natural_search("s.code_client", GETPOST("search_code_client"));
123}
124if ($socid) {
125 $sql .= " AND s.rowid = ".((int) $socid);
126}
127$sql .= $db->order($sortfield, $sortorder);
128$sql .= $db->plimit($conf->liste_limit + 1, $offset);
129//print $sql;
130
131$resql = $db->query($sql);
132if ($resql) {
133 $num = $db->num_rows($resql);
134 $i = 0;
135
136 $langs->load('commercial');
137
138 print_barre_liste($langs->trans("Customers"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
139
140 print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
141
142 print '<table class="liste centpercent">';
143 print '<tr class="liste_titre">';
144
145 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "", 'valign="center"', $sortfield, $sortorder);
146 print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "s.town", "", "", 'valign="center"', $sortfield, $sortorder);
147 print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "", '', $sortfield, $sortorder, 'left ');
148 print_liste_field_titre("AccountancyCode", $_SERVER["PHP_SELF"], "s.code_compta", "", "", '', $sortfield, $sortorder, 'left ');
149 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", $addu, "", '', $sortfield, $sortorder, 'right ');
150 print "</tr>\n";
151
152 // Fields title search
153 print '<tr class="liste_titre">';
154
155 print '<td class="liste_titre left">';
156 print '<input class="flat" type="text" name="search_nom" value="'.GETPOST("search_nom").'"></td>';
157
158 print '<td class="liste_titre">&nbsp;</td>';
159
160 print '<td class="liste_titre left">';
161 print '<input class="flat" type="text" size="10" name="search_code_client" value="'.GETPOST("search_code_client").'">';
162 print '</td>';
163
164 print '<td class="liste_titre left">';
165 print '<input class="flat" type="text" size="10" name="search_compta" value="'.GETPOST("search_compta").'">';
166 print '</td>';
167
168 print '<td colspan="2" class="liste_titre right">';
169 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")).'">';
170 print '</td>';
171 print "</tr>\n";
172
173 while ($i < min($num, $conf->liste_limit)) {
174 $obj = $db->fetch_object($resql);
175
176 print '<tr class="oddeven">';
177 print '<td>';
178 $thirdpartystatic->id = $obj->rowid;
179 $thirdpartystatic->name = $obj->name;
180 $thirdpartystatic->client = $obj->client;
181 print $thirdpartystatic->getNomUrl(1, 'compta');
182 print '</td>';
183 print '<td>'.dolPrintLabel($obj->town).'</td>';
184 print '<td class="left">'.dolPrintLabel($obj->code_client).'</td>';
185 print '<td class="left">'.dolPrintLabel($obj->code_compta_client).'</td>';
186 print '<td class="right">'.dol_print_date($db->jdate($obj->datec)).'</td>';
187 print "</tr>\n";
188 $i++;
189 }
190 print "</table>";
191
192 print '</form>';
193
194 $db->free($resql);
195} else {
196 dol_print_error($db);
197}
198
199llxFooter();
200$db->close();
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:70
Class to manage third parties objects (customers, suppliers, prospects...)
llxFooter()
Footer empty.
Definition document.php:107
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.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.