dolibarr  16.0.5
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2006 Regis Houssin <regis.houssin@inodbox.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 
28 $langs->load("companies");
29 
30 
31 /*
32  * View
33  */
34 
35 llxHeader();
36 
37 // Security check
38 if ($user->socid > 0) {
39  $action = '';
40  $socid = $user->socid;
41 }
42 
43 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
44 $sortfield = GETPOST('sortfield', 'aZ09comma');
45 $sortorder = GETPOST('sortorder', 'aZ09comma');
46 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
47 if (empty($page) || $page == -1) {
48  $page = 0;
49 } // If $page is not defined, or '' or -1
50 $offset = $limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (!$sortorder) {
54  $sortorder = "ASC";
55 }
56 if (!$sortfield) {
57  $sortfield = "p.name";
58 }
59 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
60 
61 
62 /*
63  * Mode liste
64  */
65 
66 $sql = "SELECT s.rowid as socid, s.nom as name, st.libelle as stcomm, p.rowid as cidp, p.lastname, p.firstname, p.email, p.phone";
67 if (empty($user->rights->societe->client->voir) && !$socid) {
68  $sql .= ", sc.fk_soc, sc.fk_user ";
69 }
70 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."socpeople as p, ".MAIN_DB_PREFIX."c_stcomm as st";
71 if (empty($user->rights->societe->client->voir) && !$socid) {
72  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
73 }
74 $sql .= " WHERE s.fk_stcomm = st.id";
75 $sql .= " AND s.fournisseur = 1";
76 $sql .= " AND s.rowid = p.fk_soc";
77 $sql .= " AND s.entity IN (".getEntity('societe').")";
78 if (empty($user->rights->societe->client->voir) && !$socid) {
79  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
80 }
81 
82 if (dol_strlen($stcomm)) {
83  $sql .= " AND s.fk_stcomm=$stcomm";
84 }
85 
86 if (dol_strlen($begin)) {
87  $sql .= " AND p.name LIKE '$begin%'";
88 }
89 
90 if ($contactname) {
91  $sql .= " AND p.name LIKE '%".strtolower($contactname)."%'";
92  $sortfield = "p.name";
93  $sortorder = "ASC";
94 }
95 
96 if ($socid) {
97  $sql .= " AND s.rowid = ".((int) $socid);
98 }
99 
100 $sql .= " ORDER BY $sortfield $sortorder ";
101 $sql .= $db->plimit($limit, $offset);
102 
103 $result = $db->query($sql);
104 if ($result) {
105  $num = $db->num_rows($result);
106 
107  $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
108  print_barre_liste($title." (".$langs->trans("Suppliers").")", $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num);
109 
110  print '<table class="liste centpercent">';
111  print '<tr class="liste_titre">';
112  print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, "", "", $sortfield, $sortorder);
113  print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, "", "", $sortfield, $sortorder);
114  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, "", "", $sortfield, $sortorder);
115  print_liste_field_titre("Email");
116  print_liste_field_titre("Phone");
117  print "</tr>\n";
118 
119  $i = 0;
120  while ($i < min($num, $limit)) {
121  $obj = $db->fetch_object($result);
122 
123  print '<tr class="oddeven">';
124 
125  print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'">'.img_object($langs->trans("ShowContact"), "contact").' '.$obj->lastname.'</a></td>';
126  print '<td>'.$obj->firstname.'</td>';
127  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
128  print '<td>'.$obj->email.'</td>';
129  print '<td>'.$obj->phone.'</td>';
130 
131  print "</tr>\n";
132  $i++;
133  }
134  print "</table>";
135  $db->free($result);
136 } else {
137  dol_print_error($db);
138 }
139 
140 // End of page
141 llxFooter();
142 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
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
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59