dolibarr  13.0.2
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 {
40  $action = '';
41  $socid = $user->socid;
42 }
43 
44 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
45 $sortfield = GETPOST("sortfield", 'alpha');
46 $sortorder = GETPOST("sortorder", 'alpha');
47 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
48 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
49 $offset = $limit * $page;
50 $pageprev = $page - 1;
51 $pagenext = $page + 1;
52 if (!$sortorder) $sortorder = "ASC";
53 if (!$sortfield) $sortfield = "p.name";
54 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
55 
56 
57 /*
58  * Mode liste
59  */
60 
61 $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";
62 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
63 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."socpeople as p, ".MAIN_DB_PREFIX."c_stcomm as st";
64 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
65 $sql .= " WHERE s.fk_stcomm = st.id";
66 $sql .= " AND s.fournisseur = 1";
67 $sql .= " AND s.rowid = p.fk_soc";
68 $sql .= " AND s.entity IN (".getEntity('societe').")";
69 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
70 
71 if (dol_strlen($stcomm)) {
72  $sql .= " AND s.fk_stcomm=$stcomm";
73 }
74 
75 if (dol_strlen($begin)) {
76  $sql .= " AND p.name LIKE '$begin%'";
77 }
78 
79 if ($contactname) {
80  $sql .= " AND p.name LIKE '%".strtolower($contactname)."%'";
81  $sortfield = "p.name";
82  $sortorder = "ASC";
83 }
84 
85 if ($socid) {
86  $sql .= " AND s.rowid = ".$socid;
87 }
88 
89 $sql .= " ORDER BY $sortfield $sortorder ";
90 $sql .= $db->plimit($limit, $offset);
91 
92 $result = $db->query($sql);
93 if ($result)
94 {
95  $num = $db->num_rows($result);
96 
97  $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
98  print_barre_liste($title." (".$langs->trans("Suppliers").")", $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num);
99 
100  print '<table class="liste centpercent">';
101  print '<tr class="liste_titre">';
102  print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, "", "", $sortfield, $sortorder);
103  print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, "", "", $sortfield, $sortorder);
104  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, "", "", $sortfield, $sortorder);
105  print_liste_field_titre("Email");
106  print_liste_field_titre("Phone");
107  print "</tr>\n";
108 
109  $i = 0;
110  while ($i < min($num, $limit))
111  {
112  $obj = $db->fetch_object($result);
113 
114  print '<tr class="oddeven">';
115 
116  print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'">'.img_object($langs->trans("ShowContact"), "contact").' '.$obj->lastname.'</a></td>';
117  print '<td>'.$obj->firstname.'</td>';
118  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
119  print '<td>'.$obj->email.'</td>';
120  print '<td>'.$obj->phone.'</td>';
121 
122  print "</tr>\n";
123  $i++;
124  }
125  print "</table>";
126  $db->free($result);
127 } else {
128  dol_print_error($db);
129 }
130 
131 // End of page
132 llxFooter();
133 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Empty header.
Definition: wrapper.php:45
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59