* Copyright (C) 2010 Laurent Destailleur * Copyright (C) 2010-2011 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/societe/commerciaux.php * \ingroup societe * \brief Page of links to sales representatives */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $langs->load("companies"); $langs->load("commercial"); $langs->load("customers"); $langs->load("suppliers"); $langs->load("banks"); // Security check $socid = isset($_GET["socid"])?$_GET["socid"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe','',''); $hookmanager->initHooks(array('salesrepresentativescard','globalcard')); /* * Actions */ if($_GET["socid"] && $_GET["commid"]) { $action = 'add'; if ($user->rights->societe->creer) { $soc = new Societe($db); $soc->id = $_GET["socid"]; $soc->fetch($_GET["socid"]); $parameters=array('id'=>$_GET["commid"]); $reshook=$hookmanager->executeHooks('doActions',$parameters,$soc,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) $soc->add_commercial($user, $_GET["commid"]); header("Location: commerciaux.php?socid=".$soc->id); exit; } else { header("Location: commerciaux.php?socid=".$_GET["socid"]); exit; } } if($_GET["socid"] && $_GET["delcommid"]) { $action = 'delete'; if ($user->rights->societe->creer) { $soc = new Societe($db); $soc->id = $_GET["socid"]; $soc->fetch($_GET["socid"]); $parameters=array('id'=>$_GET["delcommid"]); $reshook=$hookmanager->executeHooks('doActions',$parameters,$soc,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) $soc->del_commercial($user, $_GET["delcommid"]); header("Location: commerciaux.php?socid=".$soc->id); exit; } else { header("Location: commerciaux.php?socid=".$_GET["socid"]); exit; } } /* * View */ $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; llxHeader('',$langs->trans("ThirdParty"),$help_url); $form = new Form($db); if ($_GET["socid"]) { $soc = new Societe($db); $soc->id = $_GET["socid"]; $result=$soc->fetch($_GET["socid"]); $action='view'; $head=societe_prepare_head2($soc); dol_fiche_head($head, 'salesrepresentative', $langs->trans("ThirdParty"),0,'company'); /* * Fiche societe en mode visu */ print ''; print ''; print ''; print ''; print 'global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>'; print $soc->code_client; if ($soc->check_codeclient() <> 0) print ' '.$langs->trans("WrongCustomerCode"); print ''; if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field { print ''; } print ''; print ''; print ""; print '"; print '"; print ''; print ''; print ''; print ''; // Liste les commerciaux print ''; print '"; print '
'.$langs->trans('ThirdPartyName').''; print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom'); print '
'.$langs->trans('CustomerCode').''.$langs->trans('Prefix').''.$soc->prefix_comm.'
".$langs->trans('Address')."".nl2br($soc->address)."
'.$langs->trans('Zip').''.$soc->zip."'.$langs->trans('Town').''.$soc->town."
'.$langs->trans('Country').''.$soc->country.'
'.$langs->trans('Phone').''.dol_print_phone($soc->phone,$soc->country_code,0,$soc->id,'AC_TEL').''.$langs->trans('Fax').''.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'
'.$langs->trans('Web').''; if ($soc->url) { print 'http://'.$soc->url.''; } print '
'.$langs->trans("SalesRepresentatives").''; $sql = "SELECT u.rowid, u.lastname, u.firstname"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE sc.fk_soc =".$soc->id; $sql .= " AND sc.fk_user = u.rowid"; $sql .= " ORDER BY u.lastname ASC "; dol_syslog('societe/commerciaux.php::list salesman sql = '.$sql,LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); $parameters=array('socid'=>$soc->id); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$obj,$action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { null; // actions in normal case } print ''; print img_object($langs->trans("ShowUser"),"user").' '; print dolGetFirstLastname($obj->firstname, $obj->lastname)."\n"; print ' '; if ($user->rights->societe->creer) { print ''; print img_delete(); print ''; } print '
'; $i++; } $db->free($resql); } else { dol_print_error($db); } if($i == 0) { print $langs->trans("NoSalesRepresentativeAffected"); } print "
'; print "\n"; if ($user->rights->societe->creer && $user->rights->societe->client->voir) { /* * Liste * */ $langs->load("users"); $title=$langs->trans("ListOfUsers"); $sql = "SELECT u.rowid, u.lastname, u.firstname, u.login"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; if (! empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND u.statut<>0 "; $sql.= " ORDER BY u.lastname ASC "; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; print_titre($title); // Lignes des titres print ''; print ''; print ''; print ''; print ''; print "\n"; $var=True; while ($i < $num) { $obj = $db->fetch_object($resql); $var=!$var; print "'; print ''; print ''."\n"; $i++; } print "
'.$langs->trans("Name").''.$langs->trans("Login").' 
"; print ''; print img_object($langs->trans("ShowUser"),"user").' '; print dolGetFirstLastname($obj->firstname, $obj->lastname)."\n"; print ''; print ''.$obj->login.''.$langs->trans("Add").'
"; $db->free($resql); } else { dol_print_error($db); } } } $db->close(); llxFooter();