* Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2007 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * * 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. */ /** * \file htdocs/contact/fiche.php * \ingroup societe * \brief Onglet g�n�ral d'un contact * \version $Id$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/actioncomm.class.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/contact.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formcompany.class.php"); $langs->load("companies"); $langs->load("users"); $error = array(); $socid=$_GET["socid"]?$_GET["socid"]:$_POST["socid"]; // Security check $contactid = isset($_GET["id"])?$_GET["id"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'contact', $contactid, 'socpeople'); /* * Actions */ // Creation utilisateur depuis contact if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer) { // Recuperation contact actuel $contact = new Contact($db); $result = $contact->fetch($_GET["id"]); if ($result > 0) { // Creation user $nuser = new User($db); $result=$nuser->create_from_contact($contact,$_POST["login"]); if ($result < 0) { $msg=$nuser->error; } } else { $msg=$contact->error; } } // Creation contact if ($_POST["action"] == 'add' && $user->rights->societe->contact->creer) { $contact = new Contact($db); $contact->socid = $_POST["socid"]; $contact->name = $_POST["name"]; $contact->firstname = $_POST["firstname"]; $contact->civilite_id = $_POST["civilite_id"]; $contact->poste = $_POST["poste"]; $contact->address = $_POST["address"]; $contact->cp = $_POST["cp"]; $contact->ville = $_POST["ville"]; $contact->fk_pays = $_POST["pays_id"]; $contact->email = $_POST["email"]; $contact->phone_pro = $_POST["phone_pro"]; $contact->phone_perso = $_POST["phone_perso"]; $contact->phone_mobile = $_POST["phone_mobile"]; $contact->fax = $_POST["fax"]; $contact->jabberid = $_POST["jabberid"]; $contact->priv = $_POST["priv"]; $contact->note = $_POST["note"]; if (! $_POST["name"]) { array_push($error,$langs->trans("ErrorFieldRequired",$langs->trans("Lastname"))); $_GET["action"]="create"; } if ($_POST["name"]) { $id = $contact->create($user); if ($id > 0) { Header("Location: fiche.php?id=".$id); exit; } else { $error=array($contact->error); $_GET["action"] = 'create'; } } } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->societe->contact->supprimer) { $contact = new Contact($db); $result=$contact->fetch($_GET["id"]); $contact->old_name = $_POST["old_name"]; $contact->old_firstname = $_POST["old_firstname"]; $result = $contact->delete(); Header("Location: index.php"); exit; } if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer) { $contact = new Contact($db); $contact->old_name = $_POST["old_name"]; $contact->old_firstname = $_POST["old_firstname"]; $contact->socid = $_POST["socid"]; $contact->name = $_POST["name"]; $contact->firstname = $_POST["firstname"]; $contact->civilite_id = $_POST["civilite_id"]; $contact->poste = $_POST["poste"]; $contact->address = $_POST["address"]; $contact->cp = $_POST["cp"]; $contact->ville = $_POST["ville"]; $contact->fk_pays = $_POST["pays_id"]; $contact->email = $_POST["email"]; $contact->phone_pro = $_POST["phone_pro"]; $contact->phone_perso = $_POST["phone_perso"]; $contact->phone_mobile = $_POST["phone_mobile"]; $contact->fax = $_POST["fax"]; $contact->jabberid = $_POST["jabberid"]; $contact->priv = $_POST["priv"]; $contact->note = $_POST["note"]; $result = $contact->update($_POST["contactid"], $user); if ($result > 0) { $contact->old_name=''; $contact->old_firstname=''; } else { $error = $contact->error; } } /* * View */ llxHeader(); $form = new Form($db); $formcompany = new FormCompany($db); if ($socid) { $objsoc = new Societe($db); $objsoc->fetch($socid); } /* * Onglets */ if ($_GET["id"] > 0) { // Si edition contact deja existant $contact = new Contact($db); $return=$contact->fetch($_GET["id"], $user); if ($return <= 0) { dolibarr_print_error('',$contact->error); $_GET["id"]=0; } /* * Affichage onglets */ $head = contact_prepare_head($contact); dolibarr_fiche_head($head, 'general', $langs->trans("Contact")); } /* * Confirmation de la suppression du contact */ if ($user->rights->societe->contact->supprimer) { if ($_GET["action"] == 'delete') { $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete"); print '
'; } } if ($user->rights->societe->contact->creer) { if ($_GET["action"] == 'create') { /* * Fiche en mode creation * */ print_fiche_titre($langs->trans("AddContact")); // Affiche les erreurs if (sizeof($error)) { print "
"; print join("
",$error); print "
\n"; } print '
'; print '
'; print ''; print ''; // Name print ''; print ''; // Company if ($socid) { print ''; print ''; print ''; print ''; } else { print ''; } // Civility print ''; print ''; // Address if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->address)) == 0) $contact->address = $objsoc->adresse; // Predefined with third party print ''; if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->cp)) == 0) $contact->cp = $objsoc->cp; // Predefined with third party if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->ville)) == 0) $contact->ville = $objsoc->ville; // Predefined with third party print ''; if (strlen(trim($contact->fk_pays)) == 0) $contact->fk_pays = $objsoc->pays_id; // Predefined with third party print ''; if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->phone_pro)) == 0) $contact->phone_pro = $objsoc->tel; // Predefined with third party print ''; print ''; if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->fax)) == 0) $contact->fax = $objsoc->fax; // Predefined with third party print ''; print ''; // EMail if (($objsoc->typent_code == 'TE_PRIVATE') && strlen(trim($contact->email)) == 0) $contact->email = $objsoc->email; // Predefined with third party print ''; // Jabberid print ''; // Visibility print ''; // Note print ''; print ''; print "
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
'.$langs->trans("Company").''.$objsoc->nom.'
'.$langs->trans("Company").''; print $form->select_societes('','socid','',1); //print $form->select_societes('','socid',''); //print $langs->trans("ContactNotLinkedToCompany"); print '
'.$langs->trans("UserTitle").''; print $formcompany->select_civilite($contact->civilite_id); print '
'.$langs->trans("PostOrFunction").'
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; print '
'.$langs->trans("Country").''; $form->select_pays($contact->fk_pays); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); print '
'.$langs->trans("PhonePro").''.$langs->trans("PhonePerso").'
'.$langs->trans("PhoneMobile").''.$langs->trans("Fax").'
'.$langs->trans("Email").'
Jabberid
'.$langs->trans("ContactVisibility").''; $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate")); $form->select_array('priv',$selectarray,$contact->priv,0); print '
'.$langs->trans("Note").'

"; print "
"; } elseif ($_GET["action"] == 'edit' && $_GET["id"]) { /* * Fiche en mode edition * */ // Affiche les erreurs if (sizeof($error)) { print "
"; print join("
",$error); print "
\n"; } print '
'; print ''; print ''; print ''; print ''; print ''; print ''; // Ref print ''; // Name print ''; print ''; // Company print ''; print ''; print ''; // Civility print ''; print ''; // Address print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($conf->mailing->enabled) { $langs->load("mails"); print ''; print ''; } else { print ''; } print ''; // Jabberid print ''; // Visibility print ''; print ''; $contact->load_ref_elements(); if ($conf->commande->enabled) { print ''; } if ($conf->propal->enabled) { print ''; } if ($conf->contrat->enabled) { print ''; } if ($conf->facture->enabled) { print ''; } // Login Dolibarr print ''; print ''; print '
'.$langs->trans("Ref").''; print $contact->ref; print '
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
'.$langs->trans("Company").''; print $form->select_societes($contact->socid?$contact->socid:-1,'socid','',1); print '
'.$langs->trans("UserTitle").''; print $formcompany->select_civilite($contact->civilite_id); print '
'.$langs->trans("PostOrFunction" ).'
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; print '
'.$langs->trans("Country").''; $form->select_pays($contact->fk_pays); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); print '
'.$langs->trans("PhonePro").''.$langs->trans("PhonePerso").'
'.$langs->trans("PhoneMobile").''.$langs->trans("Fax").'
'.$langs->trans("EMail").''.$langs->trans("NbOfEMailingsReceived").''.$contact->getNbOfEMailings().' 
Jabberid
'.$langs->trans("ContactVisibility").''; $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate")); $form->select_array('priv',$selectarray,$contact->priv,0); print '
'.$langs->trans("Note").''; print '
'.$langs->trans("ContactForOrders").''; print $contact->ref_commande?$contact->ref_commande:$langs->trans("NoContactForAnyOrder"); print '
'.$langs->trans("ContactForProposals").''; print $contact->ref_propal?$contact->ref_propal:$langs->trans("NoContactForAnyProposal"); print '
'.$langs->trans("ContactForContracts").''; print $contact->ref_contrat?$contact->ref_contrat:$langs->trans("NoContactForAnyContract"); print '
'.$langs->trans("ContactForInvoices").''; print $contact->ref_facturation?$contact->ref_facturation:$langs->trans("NoContactForAnyInvoice"); print '
'.$langs->trans("DolibarrLogin").''; if ($contact->user_id) { $dolibarr_user=new User($db); $dolibarr_user->id=$contact->user_id; $result=$dolibarr_user->fetch(); print $dolibarr_user->getLoginUrl(1); } else print $langs->trans("NoDolibarrAccess"); print '
'; print ''; print '   '; print ''; print '
'; print "
"; } } if ($_GET["id"] && $_GET["action"] != 'edit') { $objsoc = new Societe($db); /* * Fiche en mode visualisation * */ if ($msg) { $langs->load("errors"); print '
'.$langs->trans($msg).'
'; } if ($_GET["action"] == 'create_user') { $login=strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4)); // Cr�e un tableau formulaire $formquestion=array( array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)); $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$contact->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion); print '
'; } print ''; // Ref print ''; // Name print ''; print ''; // Company if ($contact->socid > 0) { $objsoc->fetch($contact->socid); print ''; } else { print ''; } // Civility print ''; print ''; // Address print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($conf->mailing->enabled) { $langs->load("mails"); print ''; print ''; } else { print ''; } print ''; // Jabberid print ''; print ''; print ''; $contact->load_ref_elements(); if ($conf->commande->enabled) { print ''; } if ($conf->propal->enabled) { print ''; } if ($conf->contrat->enabled) { print ''; } if ($conf->facture->enabled) { print ''; } print ''; print "
'.$langs->trans("Ref").''; print $form->showrefnav($contact,'id'); print '
'.$langs->trans("Lastname").''.$contact->name.''.$langs->trans("Firstname").''.$contact->firstname.'
'.$langs->trans("Company").''.$objsoc->getNomUrl(1).'
'.$langs->trans("Company").''; print $langs->trans("ContactNotLinkedToCompany"); print '
'.$langs->trans("UserTitle").''; print $contact->getCivilityLabel(); print '
'.$langs->trans("PostOrFunction" ).''.$contact->poste.'
'.$langs->trans("Address").''.nl2br($contact->address).'
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$contact->cp.' '; print $contact->ville.'
'.$langs->trans("Country").''; print $contact->pays; print '
'.$langs->trans("PhonePro").''.dol_print_phone($contact->phone_pro,$contact->pays_code,$contact->id,$contact->socid,'AC_TEL').''.$langs->trans("PhonePerso").''.dol_print_phone($contact->phone_perso,$contact->pays_code,$contact->id,$contact->socid,'AC_TEL').'
'.$langs->trans("PhoneMobile").''.dol_print_phone($contact->phone_mobile,$contact->pays_code,$contact->id,$contact->socid,'AC_TEL').''.$langs->trans("Fax").''.dol_print_phone($contact->fax,$contact->pays_code,$contact->id,$contact->socid,'AC_FAX').'
'.$langs->trans("EMail").''.dol_print_email($contact->email,$contact->id,$contact->socid,'AC_EMAIL').''.$langs->trans("NbOfEMailingsReceived").''.$contact->getNbOfEMailings().' 
Jabberid'.$contact->jabberid.'
'.$langs->trans("ContactVisibility").''; print $contact->LibPubPriv($contact->priv); print '
'.$langs->trans("Note").''; print nl2br($contact->note); print '
'.$langs->trans("ContactForOrders").''; print $contact->ref_commande?$contact->ref_commande:$langs->trans("NoContactForAnyOrder"); print '
'.$langs->trans("ContactForProposals").''; print $contact->ref_propal?$contact->ref_propal:$langs->trans("NoContactForAnyProposal"); print '
'.$langs->trans("ContactForContracts").''; print $contact->ref_contrat?$contact->ref_contrat:$langs->trans("NoContactForAnyContract"); print '
'.$langs->trans("ContactForInvoices").''; print $contact->ref_facturation?$contact->ref_facturation:$langs->trans("NoContactForAnyInvoice"); print '
'.$langs->trans("DolibarrLogin").''; if ($contact->user_id) { $dolibarr_user=new User($db); $dolibarr_user->id=$contact->user_id; $result=$dolibarr_user->fetch(); print $dolibarr_user->getLoginUrl(1); } else print $langs->trans("NoDolibarrAccess"); print '
"; print ""; // Barre d'actions if (! $user->societe_id) { print '
'; if ($user->rights->societe->contact->creer) { print ''.$langs->trans('Modify').''; } if (! $contact->user_id && $user->rights->user->user->creer) { print ''.$langs->trans("CreateDolibarrLogin").''; } if ($user->rights->societe->contact->supprimer) { print ''.$langs->trans('Delete').''; } print "

"; } print show_actions_todo($conf,$langs,$db,$objsoc,$contact); print show_actions_done($conf,$langs,$db,$objsoc,$contact); } $db->close(); llxFooter('$Date$ - $Revision$'); ?>