dolibarr  9.0.0
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
4  * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
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 <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 
29 // Load translation files required by the page
30 $langs->load("companies");
31 
32 $sortfield=GETPOST('sortfield', 'alpha');
33 $sortorder=GETPOST('sortorder', 'alpha');
34 $page=GETPOST('page', 'int');
35 if (! $sortorder) $sortorder="ASC";
36 if (! $sortfield) $sortfield="p.name";
37 if ($page < 0) { $page = 0; }
38 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
39 $offset = $limit * $page ;
40 
41 $type=GETPOST('type', 'alpha');
42 $search_lastname=GETPOST('search_nom')?GETPOST('search_nom'):GETPOST('search_lastname'); // For backward compatibility
43 $search_firstname=GETPOST('search_firstname')?GETPOST('search_firstname'):GETPOST('search_firstname'); // For backward compatibility
44 $search_company=GETPOST('search_societe')?GETPOST('search_societe'):GETPOST('search_company'); // For backward compatibility
45 $contactname=GETPOST('contactname');
46 $begin=GETPOST('begin','alpha');
47 
48 // Security check
49 $socid = GETPOST('socid','int');
50 if ($user->societe_id) $socid=$user->societe_id;
51 $result = restrictedArea($user, 'societe',$socid,'');
52 
53 
54 /*
55  * View
56  */
57 
58 llxHeader('',$langs->trans("Contacts"));
59 
60 if ($type == "c" || $type == "p")
61 {
62  $label = $langs->trans("Customers");
63  $urlfiche="card.php";
64 }
65 if ($type == "f")
66 {
67  $label = $langs->trans("Suppliers");
68  $urlfiche="card.php";
69 }
70 
71 /*
72  * List mode
73  */
74 
75 $sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm";
76 $sql.= ", p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
77 $sql.= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
78 if (! $user->rights->societe->client->voir && ! $socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
79 $sql.= " ".MAIN_DB_PREFIX."socpeople as p";
80 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
81 $sql.= " WHERE s.fk_stcomm = st.id";
82 $sql.= " AND p.entity IN (".getEntity('socpeople').")";
83 if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
84 if ($type == "c") $sql.= " AND s.client IN (1, 3)";
85 if ($type == "p") $sql.= " AND s.client IN (2, 3)";
86 if ($type == "f") $sql.= " AND s.fournisseur = 1";
87 if ($socid) $sql.= " AND s.rowid = ".$socid;
88 
89 if (dol_strlen($stcomm))
90 {
91  $sql.= " AND s.fk_stcomm=".$db->escape($stcomm);
92 }
93 
94 if (! empty($search_lastname))
95 {
96  $sql.= " AND p.name LIKE '%".$db->escape($search_lastname)."%'";
97 }
98 
99 if (! empty($search_firstname))
100 {
101  $sql.= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
102 }
103 
104 if (! empty($search_company))
105 {
106  $sql.= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
107 }
108 
109 if (! empty($contactname)) // acces a partir du module de recherche
110 {
111  $sql.= " AND (p.name LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
112  $sortfield = "p.name";
113  $sortorder = "ASC";
114 }
115 
116 $sql.= $db->order($sortfield,$sortorder);
117 $sql.= $db->plimit($limit+1, $offset);
118 
119 $resql = $db->query($sql);
120 if ($resql)
121 {
122  $num = $db->num_rows($resql);
123 
124  $param="&type=".$type;
125 
126  $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
127  print_barre_liste($title.($label?" (".$label.")":""),$page, $_SERVER["PHP_SELF"], $param,$sortfield,$sortorder,"",$num);
128 
129  print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
130 
131  print '<table class="liste" width="100%">';
132  print '<tr class="liste_titre">';
133  print_liste_field_titre("Lastname",$_SERVER["PHP_SELF"],"p.name", $begin, $param,"",$sortfield,$sortorder);
134  print_liste_field_titre("Firstname",$_SERVER["PHP_SELF"],"p.firstname", $begin, $param,"",$sortfield,$sortorder);
135  print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom", $begin, $param,"",$sortfield,$sortorder);
136  print_liste_field_titre("Email");
137  print_liste_field_titre("Phone");
138  print "</tr>\n";
139 
140  print '<tr class="liste_titre">';
141  print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
142  print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
143  print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
144  print '<td class="liste_titre">&nbsp;</td>';
145  print '<td class="liste_titre" align="right"><input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'"></td>';
146  print "</tr>\n";
147 
148  $i = 0;
149  while ($i < min($num,$limit))
150  {
151  $obj = $db->fetch_object($resql);
152 
153  print '<tr class="oddeven">';
154  print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"),"contact");
155  print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
156  print "<td>$obj->firstname</TD>";
157 
158  print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"),"company").'</a>&nbsp;';
159  print "<a href=\"".$urlfiche."?socid=".$obj->rowid."\">$obj->name</a></td>\n";
160 
161  print '<td>'.dol_print_phone($obj->email,$obj->cidp,$obj->rowid,'AC_EMAIL').'</td>';
162 
163  print '<td>'.dol_print_phone($obj->phone,$obj->country_code,$obj->cidp,$obj->rowid,'AC_TEL').'&nbsp;</td>';
164 
165  print "</tr>\n";
166  $i++;
167  }
168  print "</table>";
169 
170  print '</form>';
171 
172  $db->free($resql);
173 }
174 else
175 {
176  dol_print_error($db);
177 }
178 
179 // End of page
180 llxFooter();
181 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
llxHeader()
Empty header.
Definition: wrapper.php:44
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
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)