New: Send by mail permissions are not really protected permission because user can still view file and send it manually by email or from pdf reader menu. So i moved it as an ADVANCE permission.

This commit is contained in:
Laurent Destailleur 2011-05-05 07:25:31 +00:00
parent a694166fc2
commit 04babd9297
10 changed files with 3461 additions and 3218 deletions

View File

@ -1559,14 +1559,18 @@ if ($id > 0 || ! empty($ref))
} }
// Send // Send
if ($object->statut == 1 && $user->rights->propale->envoyer) if ($object->statut == 1)
{ {
$propref = dol_sanitizeFileName($object->ref); $propref = dol_sanitizeFileName($object->ref);
$file = $conf->propale->dir_output . '/'.$propref.'/'.$propref.'.pdf'; $file = $conf->propale->dir_output . '/'.$propref.'/'.$propref.'.pdf';
if (file_exists($file)) if (file_exists($file))
{
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propale->propal_advance->send)
{ {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
} }
else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
}
} }
// Create an order // Create an order

View File

@ -1914,15 +1914,16 @@ else
// Send // Send
if ($object->statut > 0) if ($object->statut > 0)
{
if ($user->rights->commande->envoyer)
{ {
$comref = dol_sanitizeFileName($object->ref); $comref = dol_sanitizeFileName($object->ref);
$file = $conf->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf'; $file = $conf->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf';
if (file_exists($file)) if (file_exists($file))
{
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send))
{ {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
} }
else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
} }
} }

View File

@ -2624,30 +2624,38 @@ else
} }
// Send by mail // Send by mail
if (($object->statut == 1 || $object->statut == 2) && $user->rights->facture->envoyer) if (($object->statut == 1 || $object->statut == 2))
{ {
if ($objectidnext) if ($objectidnext)
{ {
print '<span class="butActionRefused" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('SendByMail').'</span>'; print '<span class="butActionRefused" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('SendByMail').'</span>';
} }
else else
{
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send)
{ {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
} }
else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
}
} }
if ($conf->global->FACTURE_SHOW_SEND_REMINDER) // For backward compatibility if ($conf->global->FACTURE_SHOW_SEND_REMINDER) // For backward compatibility
{ {
if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0 && $user->rights->facture->envoyer) if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0)
{ {
if ($objectidnext) if ($objectidnext)
{ {
print '<span class="butActionRefused" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('SendRemindByMail').'</span>'; print '<span class="butActionRefused" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('SendRemindByMail').'</span>';
} }
else else
{
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send)
{ {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&amp;action=prerelance&amp;mode=init">'.$langs->trans('SendRemindByMail').'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&amp;action=prerelance&amp;mode=init">'.$langs->trans('SendRemindByMail').'</a>';
} }
else print '<a class="butActionRefused" href="#">'.$langs->trans('SendRemindByMail').'</a>';
}
} }
} }

View File

@ -58,6 +58,8 @@ if ($_GET["id"] > 0 || ! empty($_GET["ref"]))
$fichinterid=$fichinter->id; $fichinterid=$fichinter->id;
} }
$mesg=GETPOST("msg");
// Security check // Security check
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter'); $result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter');
@ -422,6 +424,159 @@ if ($_GET['action'] == 'down' && $user->rights->ficheinter->creer)
exit; exit;
} }
/*
* Send mail
*/
if ($_POST['action'] == 'send' && ! $_POST['cancel'] && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send))
{
$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 * View
@ -546,7 +701,7 @@ elseif ($fichinterid)
$societe=new Societe($db); $societe=new Societe($db);
$societe->fetch($fichinter->socid); $societe->fetch($fichinter->socid);
if ($mesg) print $mesg."<br>"; if ($mesg) dol_htmloutput_errors($mesg)."<br>";
$head = fichinter_prepare_head($fichinter); $head = fichinter_prepare_head($fichinter);
@ -870,6 +1025,21 @@ elseif ($fichinterid)
print '>'.$langs->trans("Modify").'</a>'; print '>'.$langs->trans("Modify").'</a>';
} }
// Send
if ($fichinter->statut == 1)
{
$ficheinterref = dol_sanitizeFileName($fichinter->ref);
$file = $conf->ficheinter->dir_output . '/'.$ficheinterref.'/'.$ficheinterref.'.pdf';
if (file_exists($file))
{
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$fichinter->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
}
else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
}
}
// Delete // Delete
if (($fichinter->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer) if (($fichinter->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer)
{ {
@ -881,6 +1051,59 @@ elseif ($fichinterid)
print '</div>'; 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">'; print '<table width="100%"><tr><td width="50%" valign="top">';
/* /*
* Built documents * Built documents

View File

@ -1767,10 +1767,14 @@ else
} }
// Send by mail // Send by mail
if (($fac->statut == 1 || $fac->statut == 2) && $user->rights->facture->envoyer) if (($fac->statut == 1 || $fac->statut == 2))
{
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->fournisseur->supplier_invoice_advance->send)
{ {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$fac->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$fac->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
} }
else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
}
//Make payments //Make payments

View File

@ -130,7 +130,8 @@ class modCommande extends DolibarrModules
$this->rights[$r][1] = 'Envoyer les commandes clients'; $this->rights[$r][1] = 'Envoyer les commandes clients';
$this->rights[$r][2] = 'd'; $this->rights[$r][2] = 'd';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'envoyer'; $this->rights[$r][4] = 'order_advance';
$this->rights[$r][5] = 'send';
$r++; $r++;
$this->rights[$r][0] = 87; $this->rights[$r][0] = 87;

View File

@ -145,7 +145,8 @@ class modFacture extends DolibarrModules
$this->rights[$r][1] = 'Envoyer les factures par mail'; $this->rights[$r][1] = 'Envoyer les factures par mail';
$this->rights[$r][2] = 'a'; $this->rights[$r][2] = 'a';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'envoyer'; $this->rights[$r][4] = 'invoice_advance';
$this->rights[$r][5] = 'send';
$r++; $r++;
$this->rights[$r][0] = 16; $this->rights[$r][0] = 16;

View File

@ -129,7 +129,7 @@ class modFicheinter extends DolibarrModules
$r++; $r++;
$this->rights[$r][0] = 68; $this->rights[$r][0] = 68;
$this->rights[$r][1] = 'Envoyer les fiches d\'intervention'; $this->rights[$r][1] = 'Envoyer les fiches d\'intervention par courriel';
$this->rights[$r][2] = 'r'; $this->rights[$r][2] = 'r';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'ficheinter_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on $this->rights[$r][4] = 'ficheinter_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on

View File

@ -215,8 +215,8 @@ class modFournisseur extends DolibarrModules
$this->rights[$r][1] = 'Envoyer les factures par mail'; $this->rights[$r][1] = 'Envoyer les factures par mail';
$this->rights[$r][2] = 'a'; $this->rights[$r][2] = 'a';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'facture'; $this->rights[$r][4] = 'supplier_invoice_advance';
$this->rights[$r][5] = 'envoyer'; $this->rights[$r][5] = 'send';
$r++; $r++;
$this->rights[$r][0] = 1236; $this->rights[$r][0] = 1236;

View File

@ -134,7 +134,8 @@ class modPropale extends DolibarrModules
$this->rights[$r][1] = 'Envoyer les propositions commerciales aux clients'; // libelle de la permission $this->rights[$r][1] = 'Envoyer les propositions commerciales aux clients'; // libelle de la permission
$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour) $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
$this->rights[$r][4] = 'envoyer'; $this->rights[$r][4] = 'propal_advance';
$this->rights[$r][5] = 'send';
$r++; $r++;
$this->rights[$r][0] = 26; // id de la permission $this->rights[$r][0] = 26; // id de la permission