* Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005 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 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/contact/fiche.php \ingroup societe \brief Onglet général d'un contact \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/vcard/vcard.class.php"); $langs->load("companies"); $langs->load("users"); $error = array(); $socid=$_GET["socid"]?$_GET["socid"]:$_POST["socid"]; if ($_GET["action"] == 'create_user' && $user->admin) { // Recuperation contact actuel $contact = new Contact($db); $result = $contact->fetch($_GET["id"]); // Creation user $nuser = new User($db); $nuser->nom = $contact->name; $nuser->prenom = $contact->firstname; $nuser->create_from_contact($contact); } if ($_POST["action"] == 'add') { $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->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; } $error=array($contact->error); } } if ($_POST["action"] == 'confirm_delete' AND $_POST["confirm"] == 'yes') { $contact = new Contact($db); $contact->old_name = $_POST["old_name"]; $contact->old_firstname = $_POST["old_firstname"]; $result = $contact->delete($_GET["id"]); Header("Location: index.php"); exit; } if ($_POST["action"] == 'update') { $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->note = $_POST["note"]; $result = $contact->update($_POST["contactid"], $user); if ($contact->error) { $error = $contact->error; } } /* * * */ llxHeader(); $form = new Form($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); } $h=0; $head[$h][0] = DOL_URL_ROOT.'/contact/fiche.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("General"); $hselected=$h; $h++; $head[$h][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("PersonalInformations"); $h++; $head[$h][0] = DOL_URL_ROOT.'/contact/exportimport.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("ExportImport"); $h++; $head[$h][0] = DOL_URL_ROOT.'/contact/info.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("Info"); $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); } /* * Confirmation de la suppression du contact * */ if ($_GET["action"] == 'delete') { $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],"Supprimer le contact","Êtes-vous sûr de vouloir supprimer ce contact ?","confirm_delete"); print '
'; } 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 ''; if ($socid) { // On remplit avec le numéro de la société par défaut if (strlen(trim($contact->phone_pro)) == 0) { $contact->phone_pro = $objsoc->tel; } print ''; print ''; print ''; print ''; } else { print ''; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "
'.$langs->trans("Company").''.$objsoc->nom.'
'.$langs->trans("Company").''; //print $form->select_societes('','socid',''); print $langs->trans("ContactNotLinkedToCompany"); print '
'.$langs->trans("UserTitle").''; print $form->select_civilite($contact->civilite_id); print '
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
Poste/Fonction
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; print '
'.$langs->trans("Country").''; $form->select_pays($contact->fk_pays); print '
Tel ProTel Perso
Portable'.$langs->trans("Fax").'
'.$langs->trans("Email").'
Jabberid
'.$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 ''; if ($contact->socid > 0) { $objsoc = new Societe($db); $objsoc->fetch($contact->socid); print ''; } else { print ''; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($conf->mailing->enabled) { $langs->load("mails"); print ''; print ''; } else { print ''; } print ''; print ''; print ''; $contact->load_ref_elements(); if ($conf->facture->enabled) { print ''; } if ($conf->contrat->enabled) { print ''; } print ''; print ''; print '
'.$langs->trans("Company").''.$objsoc->nom_url.'
'.$langs->trans("Company").''; print $langs->trans("ContactNotLinkedToCompany"); print '
'.$langs->trans("UserTitle").''; print $form->select_civilite($contact->civilite_id); print '
'.$langs->trans("Lastname").''.$langs->trans("Firstname").'
Poste/Fonction
'.$langs->trans("Address").'
'.$langs->trans("Zip").' / '.$langs->trans("Town").' '; print '
'.$langs->trans("Country").''; $form->select_pays($contact->fk_pays); print '
Tel ProTel Perso
Portable'.$langs->trans("Fax").'
'.$langs->trans("EMail").''.$langs->trans("NbOfEMailingsReceived").''.$contact->getNbOfEMailings().' 
Jabberid
'.$langs->trans("Note").''; print '
'.$langs->trans("ContactForInvoices").''; print $contact->ref_facturation?$contact->ref_facturation:$langs->trans("NoContactForAnyInvoice"); print '
'.$langs->trans("ContactForContracts").''; print $contact->ref_contrat?$contact->ref_contrat:$langs->trans("NoContactForAnyContract"); print '
'.$langs->trans("DolibarrLogin").''; if ($contact->user_id) print ''.$contact->user_login.''; else print $langs->trans("NoDolibarrAccess"); print '
'; print "
"; } elseif ($_GET["id"]) { /* * Fiche en mode visualisation * */ print ''; if ($contact->socid > 0) { $objsoc = new Societe($db); $objsoc->fetch($contact->socid); print ''; } else { print ''; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($conf->mailing->enabled) { $langs->load("mails"); print ''; print ''; } else { print ''; } print ''; print ''; print ''; $contact->load_ref_elements(); if ($conf->facture->enabled) { print ''; } if ($conf->contrat->enabled) { print ''; } print ''; print "
'.$langs->trans("Company").''.$objsoc->nom_url.'
'.$langs->trans("Company").''; print $langs->trans("ContactNotLinkedToCompany"); print '
'.$langs->trans("UserTitle").''; print $form->civilite_name($contact->civilite_id); print '
'.$langs->trans("Lastname").''.$contact->name.''.$langs->trans("Firstname").''.$contact->firstname.'
Poste/Fonction'.$contact->poste.'
'.$langs->trans("Address").''.$contact->address.'
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$contact->cp.' '; print $contact->ville.'
'.$langs->trans("Country").''; print $contact->pays; print '
Tel Pro'.$contact->phone_pro.'Tel Perso'.$contact->phone_perso.'
Portable'.$contact->phone_mobile.''.$langs->trans("Fax").''.$contact->fax.'
'.$langs->trans("EMail").''; if ($contact->email && ! ValidEmail($contact->email)) { print ''.$langs->trans("ErrorBadEMail",$contact->email).""; } else { print $contact->email; } print ''.$langs->trans("NbOfEMailingsReceived").''.$contact->getNbOfEMailings().' 
Jabberid'.$contact->jabberid.'
'.$langs->trans("Note").''; print nl2br($contact->note); print '
'.$langs->trans("ContactForInvoices").''; print $contact->ref_facturation?$contact->ref_facturation:$langs->trans("NoContactForAnyInvoice"); print '
'.$langs->trans("ContactForContracts").''; print $contact->ref_contrat?$contact->ref_contrat:$langs->trans("NoContactForAnyContract"); print '
'.$langs->trans("DolibarrLogin").''; if ($contact->user_id) print ''.$contact->user_login.''; else print $langs->trans("NoDolibarrAccess"); print '
"; print ""; // Barre d'actions if (! $user->societe_id) { print '
'; if ($user->rights->societe->contact->creer) { print ''.$langs->trans('Edit').''; } if (! $contact->user_id && $user->admin) { print ''.$langs->trans("CreateDolibarrLogin").''; } if ($user->rights->societe->contact->supprimer) { print ''.$langs->trans('Delete').''; } print "

"; } // Historique des actions sur ce contact print_titre ($langs->trans("TasksHistoryForThisContact")); $histo=array(); $numaction = 0 ; // Recherche histo sur actioncomm $sql = "SELECT a.id, ".$db->pdate("a.datea")." as da, a.note, a.percent as percent,"; $sql.= " c.code as acode, c.libelle,"; $sql.= " u.rowid as user_id, u.code"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u "; $sql.= " WHERE fk_contact = ".$contact->id; $sql.= " AND u.rowid = a.fk_user_author"; $sql.= " AND c.id=a.fk_action"; $sql.= " ORDER BY a.datea DESC, a.id DESC"; $resql=$db->query($sql); if ($resql) { $i = 0 ; $num = $db->num_rows($resql); $var=true; while ($i < $num) { $obj = $db->fetch_object($resql); $histo[$numaction]=array('type'=>'action','id'=>$obj->id,'date'=>$obj->da,'note'=>$obj->note,'percent'=>$obj->percent, 'acode'=>$obj->acode,'libelle'=>$obj->libelle, 'userid'=>$obj->user_id,'code'=>$obj->code); $numaction++; $i++; } } else { dolibarr_print_error($db); } // Recherche histo sur mailing $sql = "SELECT m.rowid as id, ".$db->pdate("mc.date_envoi")." as da, m.titre as note, '100' as percent,"; $sql.= " 'AC_EMAILING' as acode,"; $sql.= " u.rowid as user_id, u.code"; $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u "; $sql.= " WHERE mc.email = '".$contact->email."'"; $sql.= " AND mc.statut = 1"; $sql.= " AND u.rowid = m.fk_user_valid"; $sql.= " AND mc.fk_mailing=m.rowid"; $sql.= " ORDER BY mc.date_envoi DESC, m.rowid DESC"; $resql=$db->query($sql); if ($resql) { $i = 0 ; $num = $db->num_rows($resql); $var=true; while ($i < $num) { $obj = $db->fetch_object($resql); $histo[$numaction]=array('type'=>'mailing','id'=>$obj->id,'date'=>$obj->da,'note'=>$obj->note,'percent'=>$obj->percent, 'acode'=>$obj->acode,'libelle'=>$obj->libelle, 'userid'=>$obj->user_id,'code'=>$obj->code); $numaction++; $i++; } } else { dolibarr_print_error($db); } // Affichage actions sur contact print ''; print ''; print ''; print ''; print ''; print ''; print ''; foreach ($histo as $key=>$value) { $var=!$var; print ""; // Date print ""; // Status/Percent if ($histo[$key]['percent'] < 100) { print ""; } else { print ""; } // Action print ''; // Note print ''; // Author print '"; print "\n"; } print "
'.$langs->trans("Date").''.$langs->trans("Status").''.$langs->trans("Actions").''.$langs->trans("Comments").''.$langs->trans("Author").'
". dolibarr_print_date($histo[$key]['date'],"%d %b %Y %H:%M") ."".$histo[$key]['percent']."%".$langs->trans("Done")."'; if ($histo[$key]['type']=='action') { print ''.img_object($langs->trans("ShowTask"),"task").' '; $transcode=$langs->trans("Action".$histo[$key]['acode']); $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:$histo[$key]['libelle']); print dolibarr_trunc($libelle,30); print ''; } if ($histo[$key]['type']=='mailing') { print ''.img_object($langs->trans("ShowEMailing"),"email").' '; $transcode=$langs->trans("Action".$histo[$key]['acode']); $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:'Send mass mailing'); print dolibarr_trunc($libelle,30); print ''; } print ''.dolibarr_trunc($histo[$key]['note'], 30).''; if ($histo[$key]['code']) { print ''.img_object($langs->trans("ShowUser"),'user').' '.$histo[$key]['code'].''; } else print " "; print "
"; print '
'; } $db->close(); llxFooter('$Date$ - $Revision$'); ?>