From 9ff348dfb57c290e5eaeba7511a7cd94e6d39793 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 5 Mar 2011 16:27:26 +0000 Subject: [PATCH] Work on SMS features --- htdocs/admin/sms.php | 22 +- htdocs/comm/propal.php | 2 +- htdocs/commande/fiche.php | 2 +- htdocs/compta/facture.php | 2 +- htdocs/core/class/html.formmail.class.php | 8 +- htdocs/core/class/html.formsms.class.php | 304 ++++++++++++++++++++++ htdocs/fourn/commande/fiche.php | 12 +- htdocs/fourn/facture/fiche.php | 2 +- htdocs/langs/en_US/admin.lang | 3 + htdocs/langs/fr_FR/admin.lang | 3 + htdocs/langs/fr_FR/sms.lang | 49 ++++ htdocs/lib/functions.lib.php | 12 +- htdocs/societe/class/societe.class.php | 59 +++-- 13 files changed, 433 insertions(+), 47 deletions(-) create mode 100755 htdocs/core/class/html.formsms.class.php create mode 100755 htdocs/langs/fr_FR/sms.lang diff --git a/htdocs/admin/sms.php b/htdocs/admin/sms.php index c3043be927a..a787e39bcc7 100755 --- a/htdocs/admin/sms.php +++ b/htdocs/admin/sms.php @@ -29,7 +29,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); $langs->load("companies"); $langs->load("products"); $langs->load("admin"); -$langs->load("mails"); +$langs->load("sms"); $langs->load("other"); $langs->load("errors"); @@ -241,7 +241,7 @@ else $var=!$var; print ''.$langs->trans("MAIN_MAIL_SMS_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).''; print ''.$conf->global->MAIN_MAIL_SMS_FROM; - if (!empty($conf->global->MAIN_MAIL_SMS_FROM) && ! isValidEmail($conf->global->MAIN_MAIL_SMS_FROM)) print img_warning($langs->trans("ErrorBadEMail")); + if (!empty($conf->global->MAIN_MAIL_SMS_FROM) && ! isValidPhone($conf->global->MAIN_MAIL_SMS_FROM)) print img_warning($langs->trans("ErrorBadPhone")); print ''; // Autocopy to @@ -310,22 +310,20 @@ else // Cree l'objet formulaire mail include_once(DOL_DOCUMENT_ROOT."/core/class/html.formsms.class.php"); $formsms = new FormSms($db); - $formsms->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_SMS_FROM); - $formsms->fromsms = (isset($_POST['fromsms'])?$_POST['fromsms']:$conf->global->MAIN_MAIL_SMS_FROM); + $formsms->fromtype='user'; + $formsms->fromid=$user->id; + $formsms->fromsms = (isset($_POST['fromsms'])?$_POST['fromsms']:($conf->global->MAIN_MAIL_SMS_FROM?$conf->global->MAIN_MAIL_SMS_FROM:$user->user_mobile)); $formsms->withfromreadonly=0; $formsms->withsubstit=0; $formsms->withfrom=1; $formsms->witherrorsto=1; - $formsms->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->email?$user->email:1); - $formsms->withtocc=(isset($_POST['sendtocc'])?$_POST['sendtocc']:1); - $formsms->withtoccc=(isset($_POST['sendtoccc'])?$_POST['sendtoccc']:1); + $formsms->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->user_mobile?$user->user_mobile:1); $formsms->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test")); $formsms->withtopicreadonly=0; $formsms->withfile=2; $formsms->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("PredefinedMailTest")); $formsms->withbodyreadonly=0; $formsms->withcancel=1; - $formsms->withdeliveryreceipt=1; $formsms->withfckeditor=0; // Tableau des substitutions $formsms->substit=$substitutionarrayfortest; @@ -335,13 +333,7 @@ else $formsms->param["mailid"]=$mil->id; $formsms->param["returnurl"]=DOL_URL_ROOT."/admin/sms.php"; - // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') - { - $formsms->clear_attached_files(); - } - - $formsms->show_form('addfile','removefile'); + $formsms->show_form(); print '
'; } diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 5b90362d37d..9eacdd5907c 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -459,7 +459,7 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] } else // Id du contact { - $sendto = $object->client->contact_get_email($_POST['receiver']); + $sendto = $object->client->contact_get_property($_POST['receiver'],'email'); $sendtoid = $_POST['receiver']; } } diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 1cdf829ea19..eeff76857db 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -936,7 +936,7 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] } else // Id du contact { - $sendto = $object->client->contact_get_email($_POST['receiver']); + $sendto = $object->client->contact_get_property($_POST['receiver'],'email'); $sendtoid = $_POST['receiver']; } } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index ed39096c199..4e20d3d95a0 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1176,7 +1176,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a } else // Id du contact { - $sendto = $object->client->contact_get_email($_POST['receiver']); + $sendto = $object->client->contact_get_property($_POST['receiver'],'email'); $sendtoid = $_POST['receiver']; } } diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 622efdd532e..53cd66a694f 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -179,10 +179,10 @@ class FormMail } /** - * \brief Show the form to input an email - * \param addfileaction Name of action when posting file attachments - * \param removefileaction Name of action when removing file attachments - * \remarks this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files + * Show the form to input an email + * this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files + * @param addfileaction Name of action when posting file attachments + * @param removefileaction Name of action when removing file attachments */ function show_form($addfileaction='addfile',$removefileaction='removefile') { diff --git a/htdocs/core/class/html.formsms.class.php b/htdocs/core/class/html.formsms.class.php new file mode 100755 index 00000000000..f5ea6025118 --- /dev/null +++ b/htdocs/core/class/html.formsms.class.php @@ -0,0 +1,304 @@ + + * Copyright (C) 2010 Juanjo Menent + * + * 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/core/class/html.formmail.class.php + * \ingroup core + * \brief Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire + * \version $Id$ + */ +require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php"); + + +/** \class FormSms + * \brief Classe permettant la generation du formulaire d'envoi de Sms + * \remarks Utilisation: $formsms = new FormSms($db) + * \remarks $formsms->proprietes=1 ou chaine ou tableau de valeurs + * \remarks $formsms->show_form() affiche le formulaire + */ +class FormSms +{ + var $db; + + var $fromname; + var $fromsms; + var $replytoname; + var $replytomail; + var $toname; + var $tomail; + + var $withsubstit; // Show substitution array + var $withfrom; + var $withto; + var $withtopic; + var $withbody; + + var $withfromreadonly; + var $withreplytoreadonly; + var $withtoreadonly; + var $withtopicreadonly; + var $withcancel; + + var $substit=array(); + var $param=array(); + + var $error; + + + /** + * \brief Constructeur + * \param DB handler d'acces base de donnee + */ + function FormSms($DB) + { + $this->db = $DB; + + $this->withfrom=1; + $this->withto=1; + $this->withtopic=1; + $this->withbody=1; + + $this->withfromreadonly=1; + $this->withreplytoreadonly=1; + $this->withtoreadonly=0; + $this->withtopicreadonly=0; + $this->withbodyreadonly=0; + + return 1; + } + + /** + * Show the form to input an email + * this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files + */ + function show_form() + { + global $conf, $langs, $user; + + $langs->load("other"); + $langs->load("mails"); + $langs->load("sms"); + + $form=new Form($DB); + + print "\n\n"; + print "
param["returnurl"]."\">\n"; + print ''; + foreach ($this->param as $key=>$value) + { + print "\n"; + } + print "\n"; + + // Substitution array + if ($this->withsubstit) + { + print "\n"; + } + + // From + if ($this->withfrom) + { + if ($this->withfromreadonly) + { + print ''; + print "\n"; + print "\n"; + } + else + { + print "\n"; + } + } + + // To + if ($this->withto || is_array($this->withto)) + { + print '\n"; + } + + // Topic + /* + if ($this->withtopic) + { + $this->withtopic=make_substitutions($this->withtopic,$this->substit,$langs); + + print ""; + print ""; + print "\n"; + }*/ + + // Message + if ($this->withbody) + { + $defaultmessage=$langs->transnoentities("ThisIsATestMessage"); + + if ($this->param["models"]=='body') { $defaultmessage=$this->withbody; } + /*if ($this->param["models"]=='facture_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoice"); } + if ($this->param["models"]=='facture_relance') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoiceReminder"); } + if ($this->param["models"]=='propal_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendProposal"); } + if ($this->param["models"]=='order_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrder"); } + if ($this->param["models"]=='order_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierOrder"); } + if ($this->param["models"]=='invoice_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierInvoice"); } */ + $defaultmessage=make_substitutions($defaultmessage,$this->substit,$langs); + if (isset($_POST["message"])) $defaultmessage=$_POST["message"]; + $defaultmessage=str_replace('\n',"\n",$defaultmessage); + + print ""; + print ""; + print "\n"; + } + + print "\n"; + print "
"; + $help=""; + foreach($this->substit as $key => $val) + { + $help.=$key.' -> '.$langs->trans($val).'
'; + } + print $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"),$help); + print "
".$langs->trans("SmsFrom").""; + if ($this->fromtype == 'user') + { + $langs->load("users"); + $fuser=new User($this->db); + $fuser->fetch($this->fromid); + print $fuser->getNomUrl(1); + print '   '; + } + if ($this->fromsms) + { + print $this->fromsms; + } + else + { + if ($this->fromtype) + { + $langs->load("errors"); + print ' <'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'> '; + } + } + print "
".$langs->trans("SmsFrom").""; + print ''; + print "
'; + print $form->textwithpicto($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); + print ''; + if ($this->withtoreadonly) + { + print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; + } + else + { + print "withto)?"30":"60")."\" name=\"sendto\" value=\"".(! is_array($this->withto) && ! is_numeric($this->withto)? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto) :"")."\">"; + if ($this->withtosocid > 0) + { + $liste=array(); + $liste[0]=' '; + $soc=new Societe($this->db); + $soc->fetch($this->withtosocid); + foreach ($soc->thirdparty_and_contact_email_array() as $key=>$value) + { + $liste[$key]=$value; + } + print " ".$langs->trans("or")." "; + //var_dump($_REQUEST);exit; + print $form->selectarray("receiver", $liste, isset($_REQUEST["receiver"])?$_REQUEST["receiver"]:0); + } + } + print "
".$langs->trans("MailTopic").""; + if ($this->withtopicreadonly) + { + print $this->withtopic; + print "withtopic."\">"; + } + else + { + print "withtopic) ."\">"; + } + print "
".$langs->trans("SmsText").""; + if ($this->withbodyreadonly) + { + print nl2br($defaultmessage); + print ''; + } + else + { + // Editeur wysiwyg + require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); + $doleditor=new DolEditor('message',$defaultmessage,'',128,'dolibarr_notes','In',true,false,$this->withfckeditor,3,72); + $doleditor->Create(); + } + print "
"; + print "trans("SendSms")."\""; + print ">"; + if ($this->withcancel) + { + print "     "; + print "trans("Cancel")."\">"; + } + print "
\n"; + + print "
\n"; + print "\n"; + } + + + /** + * \brief Affiche la partie de formulaire pour saisie d'un sms + * \param withtopic 1 pour proposer a la saisie le sujet + * \param withbody 1 pour proposer a la saisie le corps du message + * \param withfile 1 pour proposer a la saisie l'ajout d'un fichier joint + * \todo Fonction a virer quand fichier /comm/mailing.php vire (= quand ecran dans /comm/mailing prets) + */ + function sms_topicmessagefile($withtopic=1,$withbody=1,$withfile=1,$defaultbody) + { + global $langs; + + $langs->load("other"); + + print ""; + + // Topic + if ($withtopic) + { + print ""; + print ""; + print ""; + } + + // Message + if ($withbody) + { + print ""; + print ""; + print ""; + } + + print "
".$langs->trans("MailTopic").""; + print ""; + print "
".$langs->trans("MailText").""; + print ""; + print "
"; + } + +} + +?> diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index b40414834ac..ef31e077a9d 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -155,7 +155,7 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer) $tva_tx = get_default_tva($societe,$mysoc,$product->id); $type = $product->type; - + // Local Taxes $localtax1_tx= get_localtax($tva_tx, 1, $societe); $localtax2_tx= get_localtax($tva_tx, 2, $societe); @@ -187,11 +187,11 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer) $type=$_POST["type"]; $desc=$_POST['dp_desc']; $tva_tx = price2num($_POST['tva_tx']); - + // Local Taxes $localtax1_tx= get_localtax($tva_tx, 1, $societe); $localtax2_tx= get_localtax($tva_tx, 2, $societe); - + if (! $_POST['dp_desc']) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
'; @@ -258,10 +258,10 @@ if ($action == 'updateligne' && $user->rights->fournisseur->commande->creer && $ $societe=new Societe($db); $societe->fetch($commande->socid); - + $localtax1_tx=get_localtax($_POST['tva_tx'],1,$societe); $localtax2_tx=get_localtax($_POST['tva_tx'],2,$societe); - + $result = $commande->updateline($_POST['elrowid'], $_POST['eldesc'], $_POST['pu'], @@ -637,7 +637,7 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] } else // Id du contact { - $sendto = $commande->client->contact_get_email($_POST['receiver']); + $sendto = $commande->client->contact_get_property($_POST['receiver'],'email'); $sendtoid = $_POST['receiver']; } } diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 7b59df11e62..5367038da1e 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -687,7 +687,7 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] } else // Id du contact { - $sendto = $facturefourn->client->contact_get_email($_POST['receiver']); + $sendto = $facturefourn->client->contact_get_property($_POST['receiver'],'email'); $sendtoid = $_POST['receiver']; } } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 4574ceafac1..9796c29d3d4 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -231,6 +231,9 @@ MAIN_MAIL_SENDMODE=Method to use to send EMails MAIN_MAIL_SMTPS_ID=SMTP ID if authentication required MAIN_MAIL_SMTPS_PW=SMTP Password if authentication required MAIN_MAIL_EMAIL_TLS= Use TLS (SSL) encrypt +MAIN_DISABLE_ALL_SMS=Disable all SMS sendings (for test purposes or demos) +MAIN_SMS_SENDMODE=Method to use to send SMS +MAIN_MAIL_SMS_FROM=Sender phone number for Sms sending FeatureNotAvailableOnLinux=Feature not available on Unix like systems. Test your sendmail program locally. SubmitTranslation=If translation for this language is not complete or you find errors, you can correct this by editing files into directory langs/%s and submit modified files on www.dolibarr.org forum. ModuleSetup=Module setup diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 2dccf68e0d0..09a5fc491d9 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -232,6 +232,9 @@ MAIN_MAIL_SENDMODE= Méthode d'envoi des mails MAIN_MAIL_SMTPS_ID= SMTP Authentification ID si authentification SMTP requise MAIN_MAIL_SMTPS_PW= SMTP Authentification Password si authentification SMTP requise MAIN_MAIL_EMAIL_TLS= Utilisation du cryptage TLS (SSL) +MAIN_DISABLE_ALL_SMS=Désactiver globalement tout envoi de Sms (pour mode test ou démos) +MAIN_SMS_SENDMODE=Méthode d'envoi des SMS +MAIN_MAIL_SMS_FROM=Téléphone émetteur pour envoi Sms FeatureNotAvailableOnLinux= Fonctionnalité non disponible sous systèmes Unix. Tester votre sendmail localement. SubmitTranslation=Si la traduction pour cette langue est incomplète ou si vous trouvez des erreurs, vous pouvez les corriger en éditant les fichiers dans le répertoire langs/%s et soumettre les modifications sur le forum www.dolibarr.fr. ModuleSetup= Configuration du module diff --git a/htdocs/langs/fr_FR/sms.lang b/htdocs/langs/fr_FR/sms.lang new file mode 100755 index 00000000000..d9406d1a59c --- /dev/null +++ b/htdocs/langs/fr_FR/sms.lang @@ -0,0 +1,49 @@ +# Dolibarr language file - fr_FR - mails +CHARSET=UTF-8 +Sms=Sms +SmsSetup=Configuration des Sms +SmsDesc=Cet écran vous permet de définir les options globales d'utilisation des fonctions SMS. +SmsCard=Fiche SMS +AllSms=Toutes les campagnes SMS +SmsTargets=Destinataires +SmsRecipients=Destinataires +SmsRecipient=Destinataire +SmsTitle=Description +SmsFrom=Émetteur +SmsTo=Destinataire(s) +SmsTopic=Sujet du mail +SmsText=Message +SmsMessage=Message du mail +ShowSms=Afficher Sms +ListOfSms=Liste des campagnes SMS +NewSms=Nouvelle campagne SMS +EditSms=Éditer sms +ResetSms=Nouvel envoi +DeleteSms=Supprimer campagne Sms +DeleteASms=Supprimer une campagne Sms +PreviewSms=Prévisualiser Sms +PrepareSms=Préparer Sms +CreateSms=Créer Sms +SmsResult=Résultat de l'envoi de Sms +TestSms=Tester Sms +ValidSms=Valider Sms +ApproveSms=Approuver Sms +SmsStatusDraft=Brouillon +SmsStatusValidated=Validé +SmsStatusApproved=Approuvé +SmsStatusSent=Envoyé +SmsStatusSentPartialy=Envoyé partiellement +SmsStatusSentCompletely=Envoyé complètement +SmsStatusError=Erreur +SmsStatusNotSent=Non envoyé +SmsSuccessfulySent=Sms correctement envoyé (de %s à %s) +ErrorSmsRecipientIsEmpty=Le numéro du destinataire est vide +WarningNoSmsAdded=Aucun nouvel numéro de téléphone à ajouter à la liste des destinataires. +ConfirmValidSms=Confirmez-vous la validation de cette campagne ? +ConfirmResetMailing=Attention, en réinitialisant la campagne Sms %s, vous autorisez son émission en masse une nouvelle fois. Est-ce bien ce que vous voulez faire ? +ConfirmDeleteMailing=Confirmez-vous la suppression de la campagne ? +NbOfRecipients=Nombre de destinataires +NbOfUniqueSms=Nb de téléphone uniques +NbOfSms=Nbre de téléphone +ThisIsATestMessage=Ceci est un message de test +SendSms=Envoyer SMS diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index d0dc37d9aa9..c1d6495a5c8 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1056,7 +1056,7 @@ function dol_print_ip($ip,$mode=0) /** * Return true if email syntax is ok. * @param address email (Ex: "toto@titi.com", "John Do ") - * @return boolean true if email syntax is OK, false if KO or empty string/ + * @return boolean true if email syntax is OK, false if KO or empty string */ function isValidEmail($address) { @@ -1075,6 +1075,16 @@ function isValidEmail($address) } } +/** + * Return true if phone number syntax is ok. + * @param address phone (Ex: "0601010101") + * @return boolean true if phone syntax is OK, false if KO or empty string + */ +function isValidPhone($address) +{ + return true; +} + /** * Make a strlen call. Works even if mbstring module not enabled. diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 6f44160242f..b9fac82cbed 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1409,14 +1409,14 @@ class Societe extends CommonObject /** - * \brief Renvoie la liste des contacts emails existant pour la societe - * \return array tableau des contacts emails + * Return list of contacts emails existing for third party + * @return array Array of contacts emails */ function thirdparty_and_contact_email_array() { global $langs; - $contact_email = $this->contact_email_array(); + $contact_email = $this->contact_property_array('email'); if ($this->email) { if (empty($this->name)) $this->name=$this->nom; @@ -1427,14 +1427,33 @@ class Societe extends CommonObject } /** - * \brief Renvoie la liste des contacts emails existant pour la societe - * \return array tableau des contacts emails + * Return list of contacts mobile phone existing for third party + * @return array Array of contacts emails */ - function contact_email_array() + function thirdparty_and_contact_phone_array() { - $contact_email = array(); + global $langs; - $sql = "SELECT rowid, email, name, firstname"; + $contact_phone = $this->contact_property_array('mobile'); + if ($this->tel) + { + if (empty($this->name)) $this->name=$this->nom; + // TODO: Tester si tel non deja present dans tableau contact + $contact_phone[-1]=$langs->trans("ThirdParty").': '.dol_trunc($this->nom,16)." <".$this->tel.">"; + } + return $contact_phone; + } + + /** + * Return list of contacts emails or mobile existing for third party + * @param mode 'email' or 'mobile' + * @return array Array of contacts emails or mobile + */ + function contact_property_array($mode='email') + { + $contact_property = array(); + + $sql = "SELECT rowid, email, phone_mobile, name, firstname"; $sql.= " FROM ".MAIN_DB_PREFIX."socpeople"; $sql.= " WHERE fk_soc = '".$this->id."'"; $resql=$this->db->query($sql); @@ -1447,7 +1466,9 @@ class Societe extends CommonObject while ($i < $nump) { $obj = $this->db->fetch_object($resql); - $contact_email[$obj->rowid] = trim($obj->firstname." ".$obj->name)." <".$obj->email.">"; + if ($mode == 'email') $property=$obj->email; + else if ($mode == 'mobile') $property=$obj->phone_mobile; + $contact_property[$obj->rowid] = trim($obj->firstname." ".$obj->name)." <".$property.">"; $i++; } } @@ -1456,7 +1477,7 @@ class Societe extends CommonObject { dol_print_error($this->db); } - return $contact_email; + return $contact_property; } @@ -1492,13 +1513,18 @@ class Societe extends CommonObject } /** - * Return email of contact from its id + * Return property of contact from its id * @param rowid id of contact + * @param mode 'email' or 'mobile' * @return string email of contact */ - function contact_get_email($rowid) + function contact_get_property($rowid,$mode) { - $sql = "SELECT rowid, email, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE rowid = '".$rowid."'"; + $contact_property=''; + + $sql = "SELECT rowid, email, phone_mobile, name, firstname"; + $sql.= " FROM ".MAIN_DB_PREFIX."socpeople"; + $sql.= " WHERE rowid = '".$rowid."'"; $resql=$this->db->query($sql); if ($resql) @@ -1507,13 +1533,12 @@ class Societe extends CommonObject if ($nump) { - $obj = $this->db->fetch_object($resql); - $contact_email = "$obj->firstname $obj->name <$obj->email>"; - + if ($mode == 'email') $contact_property = "$obj->firstname $obj->name <$obj->email>"; + else if ($mode == 'mobile') $contact_property = $obj->phone_mobile; } - return $contact_email; + return $contact_property; } else {