Bonsoir,

C'est ma tournée :)
Ci-joint un patch avec le nécessaire pour envoyer une fiche
d'intervention par mail. Développé sur la version 2.9, patch ok sur la
version 3.

Salutations,

JF
diff -BNaur --exclude=CVS --exclude='*.patch' --exclude='.#*' --exclude='*~' 
--exclude='*.rej' --exclude='*.orig' --exclude='*.bak' --exclude=conf.php 
--exclude=documents --exclude='*.bkp' htdocs.bkp/fichinter/fiche.php 
htdocs/fichinter/fiche.php
--- htdocs.bkp/fichinter/fiche.php      2011-01-17 02:42:31.000000000 +0100
+++ htdocs/fichinter/fiche.php  2011-04-27 21:42:34.000000000 +0200
@@ -58,6 +58,8 @@
        $fichinterid=$fichinter->id;
 }

+if (isset($_GET["msg"])) { $mesg=$_GET["msg"]; }
+
 // Security check
 if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter');
@@ -423,6 +425,163 @@
 }


+
+
+
+/*
+ * Send mail (from comm/propal/fiche.php )
+ */
+if ($_POST['action'] == 'send' && ! $_POST['cancel'])
+{
+       $langs->load('mails');
+
+       $fichinter = new Fichinter($db);
+       if ( $fichinter->fetch($_POST['fichinter_id']) )
+       {
+               $ficheinterref = dol_sanitizeFileName($fichinter->ref);
+               $file = $conf->ficheinter->dir_output . '/' . $ficheinterref . 
'/' . $ficheinterref . '.pdf';
+
+               if (is_readable($file))
+               {
+                       $fichinter->fetch_thirdparty();
+
+                       if ($_POST['sendto'])
+                       {
+                               // Le destinataire a ete fourni via le champ 
libre
+                               $sendto = $_POST['sendto'];
+                               $sendtoid = 0;
+                       }
+                       elseif ($_POST['receiver'])
+                       {
+                               // Le destinataire a ete fourni via la liste 
deroulante
+                               if ($_POST['receiver'] < 0)     // Id du tiers
+                               {
+                                       $sendto = $fichinter->client->email;
+                                       $sendtoid = 0;
+                               }
+                               else    // Id du contact
+                               {
+                                       $sendto = 
$fichinter->client->contact_get_email($_POST['receiver']);
+                                       $sendtoid = $_POST['receiver'];
+                               }
+                       }
+
+                       if (strlen($sendto))
+                       {
+                               $langs->load("commercial");
+
+                               $from = $_POST['fromname'] . ' <' . 
$_POST['frommail'] .'>';
+                               $replyto = $_POST['replytoname']. ' <' . 
$_POST['replytomail'].'>';
+                               $message = $_POST['message'];
+                               $sendtocc = $_POST['sendtocc'];
+                               $deliveryreceipt = $_POST['deliveryreceipt'];
+
+                               if ($_POST['action'] == 'send')
+                               {
+                                       if (strlen($_POST['subject'])) $subject 
= $_POST['subject'];
+                                       else $subject = 
$langs->transnoentities('Intervention').' '.$fichinter->ref;
+                                       $actiontypecode='AC_FICH';
+                                       $actionmsg = 
$langs->transnoentities('MailSentBy').' '.$from.' 
'.$langs->transnoentities('To').' '.$sendto.".\n";
+                                       if ($message)
+                                       {
+                                               
$actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
+                                               
$actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
+                                               $actionmsg.=$message;
+                                       }
+                                       
$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
+                               }
+
+                               // Create form object
+                               
include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
+                               $formmail = new FormMail($db);
+
+                               $attachedfiles=$formmail->get_attached_files();
+                               $filepath = $attachedfiles['paths'];
+                               $filename = $attachedfiles['names'];
+                               $mimetype = $attachedfiles['mimes'];
+
+                               // Envoi de la propal
+                               
require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php');
+                               $mailfile = new 
CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
+                               if ($mailfile->error)
+                               {
+                                       $mesg='<div 
class="error">'.$mailfile->error.'</div>';
+                               }
+                               else
+                               {
+                                       $result=$mailfile->sendfile();
+                                       if ($result)
+                                       {
+                                               $mesg='<div 
class="ok">'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.</div>';
+
+                                               $error=0;
+
+                                               // Initialisation donnees
+                                               $fichinter->sendtoid=$sendtoid;
+                                               
$fichinter->actiontypecode=$actiontypecode;
+                                               $fichinter->actionmsg = 
$actionmsg;
+                                               $fichinter->actionmsg2= 
$actionmsg2;
+                                               
$fichinter->rowid=$fichinter->id;
+
+                                               // Appel des triggers
+                                               include_once(DOL_DOCUMENT_ROOT 
. "/core/class/interfaces.class.php");
+                                               $interface=new Interfaces($db);
+                                               
$result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$fichinter,$user,$langs,$conf);
+                                               if ($result < 0) { $error++; 
$this->errors=$interface->errors; }
+                                               // Fin appel triggers
+
+                                               if ($error)
+                                               {
+                                                       dol_print_error($db);
+                                               }
+                                               else
+                                               {
+                                                       // Redirect here
+                                                       // This avoid sending 
mail twice if going out and then back to page
+                                                       Header('Location: 
'.$_SERVER["PHP_SELF"].'?id='.$fichinter->id.'&msg='.urlencode($mesg));
+                                                       exit;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               $langs->load("other");
+                                               $mesg='<div class="error">';
+                                               if ($mailfile->error)
+                                               {
+                                                       
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
+                                                       
$mesg.='<br>'.$mailfile->error;
+                                               }
+                                               else
+                                               {
+                                                       $mesg.='No mail sent. 
Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
+                                               }
+                                               $mesg.='</div>';
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               $langs->load("other");
+                               $mesg='<div 
class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
+                               dol_syslog('Recipient email is empty');
+                       }
+               }
+               else
+               {
+                       $langs->load("other");
+                       $mesg='<div 
class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
+                       dol_syslog('Failed to read file: '.$file);
+               }
+       }
+       else
+       {
+               $langs->load("other");
+               $mesg='<div 
class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Intervention")).'</div>';
+               dol_syslog('Impossible de lire les donnees de l\'intervention. 
Le fichier intervention n\'a peut-etre pas ete genere.');
+       }
+}
+
+
 /*
  * View
  */
@@ -876,11 +1035,80 @@
                                print '<a class="butActionDelete" 
href="'.$_SERVER["PHP_SELF"].'?id='.$fichinter->id.'&amp;action=delete"';
                                print '>'.$langs->trans('Delete').'</a>';
                        }
+
+
+                       // Send
+                       if ($fichinter->statut == 1 && 
$user->rights->ficheinter->envoyer)
+                       {
+                               $ficheinterref = 
dol_sanitizeFileName($fichinter->ref);
+                               $file = $conf->ficheinter->dir_output . 
'/'.$ficheinterref.'/'.$ficheinterref.'.pdf';
+                               if (file_exists($file))
+                               {
+                                       print '<a class="butAction" 
href="'.$_SERVER["PHP_SELF"].'?id='.$fichinter->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
+                               }
+                               else echo "fichier non existant";
+                       }
+
                }
        }

        print '</div>';

+
+       /*
+        * Action presend
+        *
+        */
+       if ($_GET['action'] == 'presend')
+       {
+               $ref = dol_sanitizeFileName($fichinter->ref);
+               $file = $conf->ficheinter->dir_output . '/' . $ref . '/' . $ref 
. '.pdf';
+
+               print '<br>';
+               print_titre($langs->trans('SendInterventionByMail'));
+
+               // Create form object
+               
include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
+               $formmail = new FormMail($db);
+               $formmail->fromtype = 'user';
+               $formmail->fromid   = $user->id;
+               $formmail->fromname = $user->fullname;
+               $formmail->frommail = $user->email;
+               $formmail->withfrom=1;
+               $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"];
+               $formmail->withtosocid=$societe->id;
+               $formmail->withtocc=1;
+               $formmail->withtoccsocid=0;
+               $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
+               $formmail->withtocccsocid=0;
+               
$formmail->withtopic=$langs->trans('SendInterventionRef','__FICHREF__');
+               $formmail->withfile=1;
+               $formmail->withbody=1;
+               $formmail->withdeliveryreceipt=1;
+               $formmail->withcancel=1;
+
+               // Tableau des substitutions
+               $formmail->substit['__FICHREF__']=$fichinter->ref;
+               // Tableau des parametres complementaires
+               $formmail->param['action']='send';
+               $formmail->param['models']='fichinter_send';
+               $formmail->param['fichinter_id']=$fichinter->id;
+               
$formmail->param['returnurl']=DOL_URL_ROOT.'/fichinter/fiche.php?id='.$fichinter->id;
+
+               // Init list of files
+               if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
+               {
+                       $formmail->clear_attached_files();
+                       
$formmail->add_attached_files($file,$fichinter->ref.'.pdf','application/pdf');
+               }
+
+               $formmail->show_form();
+
+               print '<br>';
+       }
+
+
+
        print '<table width="100%"><tr><td width="50%" valign="top">';
        /*
         * Built documents
diff -BNaur --exclude=CVS --exclude='*.patch' --exclude='.#*' --exclude='*~' 
--exclude='*.rej' --exclude='*.orig' --exclude='*.bak' --exclude=conf.php 
--exclude=documents --exclude='*.bkp' 
htdocs.bkp/includes/modules/modFicheinter.class.php 
htdocs/includes/modules/modFicheinter.class.php
--- htdocs.bkp/includes/modules/modFicheinter.class.php 2011-01-17 
02:43:23.000000000 +0100
+++ htdocs/includes/modules/modFicheinter.class.php     2011-04-27 
21:48:09.000000000 +0200
@@ -127,6 +127,13 @@
     $this->rights[$r][3] = 0;
     $this->rights[$r][4] = 'export';

+      $r++;
+      $this->rights[$r][0] = 68;
+      $this->rights[$r][1] = 'Envoyer les fiches d\'intervention';
+      $this->rights[$r][2] = 'd';
+      $this->rights[$r][3] = 0;
+      $this->rights[$r][4] = 'envoyer';
+
     //Exports
     //--------
     $r=1;
diff -BNaur --exclude=CVS --exclude='*.patch' --exclude='.#*' --exclude='*~' 
--exclude='*.rej' --exclude='*.orig' --exclude='*.bak' --exclude=conf.php 
--exclude=documents --exclude='*.bkp' htdocs.bkp/langs/fr_FR/interventions.lang 
htdocs/langs/fr_FR/interventions.lang
--- htdocs.bkp/langs/fr_FR/interventions.lang   2010-08-04 01:23:53.000000000 
+0200
+++ htdocs/langs/fr_FR/interventions.lang       2011-04-27 19:58:18.000000000 
+0200
@@ -45,3 +45,5 @@
 ArcticNumRefModelError=Activation impossible
 PacificNumRefModelDesc1=Renvoie le numéro sous la forme %syymm-nnnn où yy 
est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans 
remise à 0
 PacificNumRefModelError=Une facture commençant par $syymm existe en base et 
est incompatible avec cette numérotation. Supprimez la ou renommez la pour 
activer ce module.
+SendInterventionByMail=Envoi de la fiche d'intervention par mail
+SendInterventionRef=Envoi Intervention %s
_______________________________________________
Dolibarr-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev

Répondre à