* Copyright (C) 2003 Éric Seigne
* Copyright (C) 2004 Laurent Destailleur
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
/**
\file htdocs/comm/contact.php
\ingroup commercial
\brief Liste des contacts
\version $Revision$
*/
require("./pre.inc.php");
$langs->load("companies");
$user->getrights('propale');
$user->getrights('fichinter');
$user->getrights('commande');
$user->getrights('projet');
llxHeader('','Contacts Clients');
$sortorder=$_GET["sortorder"];
$sortfield=$_GET["sortfield"];
$page=$_GET["page"];
$socid=$_GET["socid"];
$type=$_GET["type"];
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$action = '';
$socid = $user->societe_id;
}
if ($sortorder == "")
{
$sortorder="ASC";
}
if ($sortfield == "")
{
$sortfield="p.name";
}
if ($page == -1) { $page = 0 ; }
$limit = $conf->liste_limit;
$offset = $limit * $page ;
if ($type == "c")
{
$label = " clients";
$urlfiche="fiche.php";
}
if ($type == "p")
{
$label = " prospects";
$urlfiche="prospect/fiche.php";
}
if ($type == "f")
{
$label = " fournisseurs";
$urlfiche="fiche.php";
}
/*
*
* Mode liste
*
*
*/
$sql = "SELECT s.idp, s.nom, st.libelle as stcomm";
$sql .= ", p.idp as cidp, p.name, p.firstname, p.email, p.phone ";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= " , ".MAIN_DB_PREFIX."socpeople as p";
$sql .= " , ".MAIN_DB_PREFIX."c_stcomm as st";
$sql .= " WHERE s.fk_stcomm = st.id AND s.idp = p.fk_soc";
if ($type == "c") $sql .= " AND s.client = 1";
if ($type == "p") $sql .= " AND s.client = 2";
if ($type == "f") $sql .= " AND s.fournisseur = 1";
if (strlen($stcomm))
{
$sql .= " AND s.fk_stcomm=$stcomm";
}
if (strlen($begin)) // filtre sur la premiere lettre du nom
{
$sql .= " AND upper(p.name) like '$begin%'";
}
if (trim($_GET["search_nom"]))
{
$sql .= " AND p.name like '%".trim($_GET["search_nom"])."%'";
}
if (trim($_GET["search_prenom"]))
{
$sql .= " AND p.firstname like '%".trim($_GET["search_prenom"])."%'";
}
if (trim($_GET["search_societe"]))
{
$sql .= " AND s.nom like '%".trim($_GET["search_societe"])."%'";
}
if ($_GET[contactname]) // acces a partir du module de recherche
{
$sql .= " AND ( lower(p.name) like '%".strtolower($_GET[contactname])."%' OR lower(p.firstname) like '%".strtolower($_GET[contactname])."%') ";
$sortfield = "lower(p.name)";
$sortorder = "ASC";
}
if ($socid) {
$sql .= " AND s.idp = $socid";
}
$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($limit+1, $offset);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
print_barre_liste("Liste des contacts $label",$page, "contact.php", "&type=$type",$sortfield,$sortorder,"",$num);
print '';
print '';
print_liste_field_titre($langs->trans("Lastname"),"contact.php","lower(p.name)", $begin,"&type=$type","",$sortfield);
print_liste_field_titre($langs->trans("Firstname"),"contact.php","lower(p.firstname)", $begin,"&type=$type","",$sortfield);
print_liste_field_titre($langs->trans("Company"),"contact.php","lower(s.nom)", $begin,"&type=$type","",$sortfield);
print '| '.$langs->trans("Email").' | ';
print ''.$langs->trans("Phone").' | ';
print "
\n";
print '';
$var=True;
$i = 0;
while ($i < min($num,$limit))
{
$obj = $db->fetch_object();
$var=!$var;
print "";
print '| '.img_file();
print ' '.$obj->name.' | ';
print "$obj->firstname | ";
print ' ';
print "idp\">$obj->nom | \n";
print ''.$obj->email.' | ';
print ''.dolibarr_print_phone($obj->phone).' | ';
print "
\n";
$i++;
}
print "
";
$db->free();
}
else
{
dolibarr_print_error($db);
}
$db->close();
llxFooter("Dernière modification $Date$ révision $Revision$");
?>