New: add advanced rights

This commit is contained in:
Regis Houssin 2012-06-14 20:08:46 +02:00
parent 4f67488bd3
commit 1155b0097b
5 changed files with 83 additions and 58 deletions

View File

@ -40,7 +40,13 @@ $id=(GETPOST('mailid','int') ? GETPOST('mailid','int') : GETPOST('id','int'));
$action=GETPOST('action','alpha'); $action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha'); $confirm=GETPOST('confirm','alpha');
$urlfrom=GETPOST('urlfrom'); $urlfrom=GETPOST('urlfrom');
$message = '';
$mesg='';
if (isset($_SESSION['DolMessage']))
{
$mesg=$_SESSION['DolMessage'];
unset($_SESSION['DolMessage']);
}
$object=new Mailing($db); $object=new Mailing($db);
$result=$object->fetch($id); $result=$object->fetch($id);
@ -140,14 +146,14 @@ if ($action == 'sendallconfirmed' && $confirm == 'yes')
{ {
// Pour des raisons de securite, on ne permet pas cette fonction via l'IHM, // Pour des raisons de securite, on ne permet pas cette fonction via l'IHM,
// on affiche donc juste un message // on affiche donc juste un message
$message='<div class="warning">'.$langs->trans("MailingNeedCommand").'</div>'; $mesg='<div class="warning">'.$langs->trans("MailingNeedCommand").'</div>';
$message.='<br><textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>'; $mesg.='<br><textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>';
$message.='<br><br><div class="warning">'.$langs->trans("MailingNeedCommand2").'</div>'; $mesg.='<br><br><div class="warning">'.$langs->trans("MailingNeedCommand2").'</div>';
$action=''; $action='';
} }
else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
{ {
$message='<div class="warning">'.$langs->trans("NotEnoughPermissions").'</div>'; $mesg='<div class="warning">'.$langs->trans("NotEnoughPermissions").'</div>';
$action=''; $action='';
} }
else else
@ -363,9 +369,8 @@ if ($action == 'sendallconfirmed' && $confirm == 'yes')
dol_syslog($db->error()); dol_syslog($db->error());
dol_print_error($db); dol_print_error($db);
} }
$message='';
$action = '';
$action = '';
} }
} }
@ -379,7 +384,7 @@ if ($action == 'send' && empty($_POST["cancel"]))
$object->sendto = $_POST["sendto"]; $object->sendto = $_POST["sendto"];
if (! $object->sendto) if (! $object->sendto)
{ {
$message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("MailTo")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("MailTo")).'</div>';
$error++; $error++;
} }
@ -387,7 +392,7 @@ if ($action == 'send' && empty($_POST["cancel"]))
{ {
// Le message est-il en html // Le message est-il en html
$msgishtml=-1; // Inconnu par defaut $msgishtml=-1; // Inconnu par defaut
if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1; if (preg_match('/[\s\t]*<html>/i',$object->body)) $msgishtml=1;
// Pratique les substitutions sur le sujet et message // Pratique les substitutions sur le sujet et message
$object->sujet=make_substitutions($object->sujet,$object->substitutionarrayfortest); $object->sujet=make_substitutions($object->sujet,$object->substitutionarrayfortest);
@ -419,11 +424,11 @@ if ($action == 'send' && empty($_POST["cancel"]))
$result=$mailfile->sendfile(); $result=$mailfile->sendfile();
if ($result) if ($result)
{ {
$message='<div class="ok">'.$langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($object->email_from,2),$mailfile->getValidAddress($object->sendto,2)).'</div>'; $mesg='<div class="ok">'.$langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($object->email_from,2),$mailfile->getValidAddress($object->sendto,2)).'</div>';
} }
else else
{ {
$message='<div class="error">'.$langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result.'</div>'; $mesg='<div class="error">'.$langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result.'</div>';
} }
$action=''; $action='';
@ -433,8 +438,6 @@ if ($action == 'send' && empty($_POST["cancel"]))
// Action add emailing // Action add emailing
if ($action == 'add') if ($action == 'add')
{ {
$message='';
$object->email_from = trim($_POST["from"]); $object->email_from = trim($_POST["from"]);
$object->email_replyto = trim($_POST["replyto"]); $object->email_replyto = trim($_POST["replyto"]);
$object->email_errorsto = trim($_POST["errorsto"]); $object->email_errorsto = trim($_POST["errorsto"]);
@ -444,21 +447,21 @@ if ($action == 'add')
$object->bgcolor = trim($_POST["bgcolor"]); $object->bgcolor = trim($_POST["bgcolor"]);
$object->bgimage = trim($_POST["bgimage"]); $object->bgimage = trim($_POST["bgimage"]);
if (! $object->titre) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTitle")); if (! $object->titre) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTitle"));
if (! $object->sujet) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTopic")); if (! $object->sujet) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTopic"));
if (! $object->body) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailBody")); if (! $object->body) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailBody"));
if (! $message) if (! $mesg)
{ {
if ($object->create($user) >= 0) if ($object->create($user) >= 0)
{ {
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit; exit;
} }
$message=$object->error; $mesg=$object->error;
} }
$message='<div class="error">'.$message.'</div>'; $mesg='<div class="error">'.$mesg.'</div>';
$action="create"; $action="create";
} }
@ -472,20 +475,20 @@ if ($action == 'settitre' || $action == 'setemail_from' || $actino == 'setreplyt
else if ($action == 'setemail_replyto') $object->email_replyto = trim(GETPOST('email_replyto','alpha')); else if ($action == 'setemail_replyto') $object->email_replyto = trim(GETPOST('email_replyto','alpha'));
else if ($action == 'setemail_errorsto') $object->email_errorsto = trim(GETPOST('email_errorsto','alpha')); else if ($action == 'setemail_errorsto') $object->email_errorsto = trim(GETPOST('email_errorsto','alpha'));
else if ($action == 'settitre' && empty($object->titre)) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle")); else if ($action == 'settitre' && empty($object->titre)) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
else if ($action == 'setfrom' && empty($object->email_from)) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom")); else if ($action == 'setfrom' && empty($object->email_from)) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom"));
if (! $message) if (! $mesg)
{ {
if ($object->update($user) >= 0) if ($object->update($user) >= 0)
{ {
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit; exit;
} }
$message=$object->error; $mesg=$object->error;
} }
$message='<div class="error">'.$message.'</div>'; $mesg='<div class="error">'.$mesg.'</div>';
$action=""; $action="";
} }
@ -504,7 +507,7 @@ if (! empty($_POST['addfile']))
$action="edit"; $action="edit";
} }
// Action update emailing // Action remove file
if (! empty($_POST["removedfile"])) if (! empty($_POST["removedfile"]))
{ {
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1); $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
@ -530,20 +533,20 @@ if ($action == 'update' && empty($_POST["removedfile"]) && empty($_POST["cancel"
$object->bgcolor = trim($_POST["bgcolor"]); $object->bgcolor = trim($_POST["bgcolor"]);
$object->bgimage = trim($_POST["bgimage"]); $object->bgimage = trim($_POST["bgimage"]);
if (! $object->sujet) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTopic")); if (! $object->sujet) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTopic"));
if (! $object->body) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailBody")); if (! $object->body) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailBody"));
if (! $message) if (! $mesg)
{ {
if ($object->update($user) >= 0) if ($object->update($user) >= 0)
{ {
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit; exit;
} }
$message=$object->error; $mesg=$object->error;
} }
$message='<div class="error">'.$message.'</div>'; $mesg='<div class="error">'.$mesg.'</div>';
$action="edit"; $action="edit";
} }
else else
@ -559,6 +562,8 @@ if ($action == 'confirm_valid' && $confirm == 'yes')
{ {
$object->valid($user); $object->valid($user);
$_SESSION['DolMessage']='<div class="ok">'.$langs->trans("MailingSuccessfullyValidated").'</div>';
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit; exit;
} }
@ -639,7 +644,7 @@ if ($action == 'create')
print_fiche_titre($langs->trans("NewMailing")); print_fiche_titre($langs->trans("NewMailing"));
dol_htmloutput_mesg($message); dol_htmloutput_mesg($mesg);
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailTitle").'</td><td><input class="flat" name="titre" size="40" value="'.$_POST['titre'].'"></td></tr>'; print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailTitle").'</td><td><input class="flat" name="titre" size="40" value="'.$_POST['titre'].'"></td></tr>';
@ -697,8 +702,6 @@ else
dol_fiche_head($head, 'card', $langs->trans("Mailing"), 0, 'email'); dol_fiche_head($head, 'card', $langs->trans("Mailing"), 0, 'email');
dol_htmloutput_mesg($message);
// Confirmation de la validation du mailing // Confirmation de la validation du mailing
if ($action == 'valid') if ($action == 'valid')
{ {
@ -914,7 +917,14 @@ else
if (($object->statut <= 1 && $user->rights->mailing->creer) || $user->rights->mailing->supprimer) if (($object->statut <= 1 && $user->rights->mailing->creer) || $user->rights->mailing->supprimer)
{ {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.(! empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>'; if ($object->statut > 0 && (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->delete))
{
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("DeleteMailing").'</a>';
}
else
{
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.(! empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
}
} }
print '<br><br></div>'; print '<br><br></div>';
@ -1001,10 +1011,7 @@ else
* Mailing en mode edition * Mailing en mode edition
*/ */
$mesgs=array(); dol_htmloutput_mesg($mesg);
if ($mesg) $mesgs[]=$mesg;
if ($message) $message[]=$message;
dol_htmloutput_mesg('',$mesgs);
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';

View File

@ -29,7 +29,7 @@
*/ */
function emailing_prepare_head($object) function emailing_prepare_head($object)
{ {
global $langs, $conf; global $user, $langs, $conf;
$h = 0; $h = 0;
$head = array(); $head = array();
@ -39,6 +39,10 @@ function emailing_prepare_head($object)
$head[$h][2] = 'card'; $head[$h][2] = 'card';
$h++; $h++;
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->recipient) {
return $head;
}
$head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$object->id; $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$object->id;
$head[$h][1] = $langs->trans("MailRecipients"); $head[$h][1] = $langs->trans("MailRecipients");
$head[$h][2] = 'targets'; $head[$h][2] = 'targets';

View File

@ -98,19 +98,35 @@ class modMailing extends DolibarrModules
$this->rights[$r][4] = 'valider'; $this->rights[$r][4] = 'valider';
$r++; $r++;
$this->rights[$r][0] = 228; $this->rights[$r][0] = 229;
$this->rights[$r][1] = 'Envoyer les mailings'; $this->rights[$r][1] = 'Supprimer les mailings';
$this->rights[$r][2] = 'd';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'supprimer';
$r++;
$this->rights[$r][0] = 237;
$this->rights[$r][1] = 'View recipients and info';
$this->rights[$r][2] = 'r';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'mailing_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
$this->rights[$r][5] = 'recipient';
$r++;
$this->rights[$r][0] = 238;
$this->rights[$r][1] = 'Manually send mailings';
$this->rights[$r][2] = 'w'; $this->rights[$r][2] = 'w';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'mailing_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on $this->rights[$r][4] = 'mailing_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
$this->rights[$r][5] = 'send'; $this->rights[$r][5] = 'send';
$r++; $r++;
$this->rights[$r][0] = 229; $this->rights[$r][0] = 239;
$this->rights[$r][1] = 'Supprimer les mailings'; $this->rights[$r][1] = 'Delete mailings after validation and/or sent';
$this->rights[$r][2] = 'd'; $this->rights[$r][2] = 'd';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'supprimer'; $this->rights[$r][4] = 'mailing_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
$this->rights[$r][5] = 'delete';
} }

View File

@ -327,6 +327,7 @@ UrlGenerationParameters=Parameters to secure URLs
SecurityTokenIsUnique=Use a unique securekey parameter for each URL SecurityTokenIsUnique=Use a unique securekey parameter for each URL
EnterRefToBuildUrl=Enter reference for object %s EnterRefToBuildUrl=Enter reference for object %s
GetSecuredUrl=Get calculated URL GetSecuredUrl=Get calculated URL
ButtonHideUnauthorized=Hide buttons unauthorized (instead of seeing gray)
# Modules # Modules
Module0Name=Users & groups Module0Name=Users & groups
@ -553,11 +554,9 @@ Permission221=Read emailings
Permission222=Create/modify emailings (topic, recipients...) Permission222=Create/modify emailings (topic, recipients...)
Permission223=Validate emailings (allows sending) Permission223=Validate emailings (allows sending)
Permission229=Delete emailings Permission229=Delete emailings
Permission231=Define mode of payment Permission237=View recipients and info
Permission232=Create/modify supplier invoices Permission238=Manually send mailings
Permission233=Validate supplier invoices Permission239=Delete mailings after validation or sent
Permission234=Delete supplier invoices
Permission236=Export supplier invoices
Permission241=Read categories Permission241=Read categories
Permission242=Create/modify categories Permission242=Create/modify categories
Permission243=Delete categories Permission243=Delete categories

View File

@ -328,6 +328,7 @@ UrlGenerationParameters=Sécurisation des URLs
SecurityTokenIsUnique=Utiliser un paramètre securekey unique pour chaque URL ? SecurityTokenIsUnique=Utiliser un paramètre securekey unique pour chaque URL ?
EnterRefToBuildUrl=Entrez la référence pour l'objet %s EnterRefToBuildUrl=Entrez la référence pour l'objet %s
GetSecuredUrl=Obtenir l'URL calculée GetSecuredUrl=Obtenir l'URL calculée
ButtonHideUnauthorized=Cacher les boutons non autorisés (au lieu de les voir grisés)
# Modules= undefined # Modules= undefined
Module0Name= Utilisateurs & groupes Module0Name= Utilisateurs & groupes
@ -551,11 +552,9 @@ Permission221= Consulter les mailings
Permission222= Créer/modifier les mailings (sujet, destinataires, etc.) Permission222= Créer/modifier les mailings (sujet, destinataires, etc.)
Permission223= Valider les mailings (permet leur envoi) Permission223= Valider les mailings (permet leur envoi)
Permission229= Supprimer les mailings Permission229= Supprimer les mailings
Permission231= Définir le mode de règlement Permission237= Visualiser les destinataires et les infos
Permission232= Créer/modifier les factures fournisseurs Permission238= Envoyer les mailings manuellement
Permission233= Valider les factures fournisseurs Permission239= Supprimer les mailings après leur validation ou leur envoi
Permission234= Supprimer les factures fournisseurs
Permission236= Exporter les factures fournisseurs et attributs
Permission241= Lire les catégories Permission241= Lire les catégories
Permission242= Créer/modifier les catégories Permission242= Créer/modifier les catégories
Permission243= Supprimer les catégories Permission243= Supprimer les catégories