* Copyright (C) 2003 Eric Seigne * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/comm/contact.php * \ingroup commercial * \brief Liste des contacts */ require '../main.inc.php'; $langs->load("companies"); $sortfield=GETPOST('sortfield', 'alpha'); $sortorder=GETPOST('sortorder', 'alpha'); $page=GETPOST('page', 'int'); if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="p.name"; if ($page < 0) { $page = 0; } $limit = $conf->liste_limit; $offset = $limit * $page ; $type=GETPOST('type', 'alpha'); $search_lastname=GETPOST('search_nom')?GETPOST('search_nom'):GETPOST('search_lastname'); // For backward compatibility $search_firstname=GETPOST('search_firstname')?GETPOST('search_firstname'):GETPOST('search_firstname'); // For backward compatibility $search_company=GETPOST('search_societe')?GETPOST('search_societe'):GETPOST('search_company'); // For backward compatibility $contactname=GETPOST('contactname'); $begin=GETPOST('begin','alpha'); // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe',$socid,''); /* * View */ llxHeader('','Contacts'); if ($type == "c" || $type == "p") { $label = $langs->trans("Customers"); $urlfiche="card.php"; } if ($type == "f") { $label = $langs->trans("Suppliers"); $urlfiche="card.php"; } /* * Mode liste * */ $sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm"; $sql.= ", p.rowid as cidp, p.name, p.firstname, p.email, p.phone"; $sql.= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,"; $sql.= " ".MAIN_DB_PREFIX."socpeople as p"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc"; $sql.= " WHERE s.fk_stcomm = st.id"; $sql.= " AND p.entity IN (".getEntity('societe', 1).")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($type == "c") $sql.= " AND s.client IN (1, 3)"; if ($type == "p") $sql.= " AND s.client IN (2, 3)"; if ($type == "f") $sql.= " AND s.fournisseur = 1"; if ($socid) $sql.= " AND s.rowid = ".$socid; if (dol_strlen($stcomm)) { $sql.= " AND s.fk_stcomm=".$db->escape($stcomm); } if (! empty($search_lastname)) { $sql.= " AND p.name LIKE '%".$db->escape($search_lastname)."%'"; } if (! empty($search_firstname)) { $sql.= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'"; } if (! empty($search_company)) { $sql.= " AND s.nom LIKE '%".$db->escape($search_company)."%'"; } if (! empty($contactname)) // acces a partir du module de recherche { $sql.= " AND (p.name LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') "; $sortfield = "p.name"; $sortorder = "ASC"; } $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit+1, $offset); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $param="&type=".$type; $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses")); print_barre_liste($title.($label?" (".$label.")":""),$page, $_SERVER["PHP_SELF"], $param,$sortfield,$sortorder,"",$num); print ''; print ''; print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"p.name", $begin, $param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"p.firstname", $begin, $param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom", $begin, $param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Email")); print_liste_field_titre($langs->trans("Phone")); print "\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print ''; $var=True; $i = 0; while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); $var=!$var; print ""; print ''; print ""; print '\n"; print ''; print ''; print "\n"; $i++; } print "
 
'.img_object($langs->trans("ShowContact"),"contact"); print ' '.$obj->name.'$obj->firstname'.img_object($langs->trans("ShowCompany"),"company").' '; print "rowid."\">$obj->name'.dol_print_phone($obj->email,$obj->cidp,$obj->rowid,'AC_EMAIL').''.dol_print_phone($obj->phone,$obj->country_code,$obj->cidp,$obj->rowid,'AC_TEL').' 

"; $db->free($resql); } else { dol_print_error($db); } llxFooter(); $db->close();