New: Adding linked project to mass mailing card (#35723)
* New: Adding linked project to mass mailing card * modify project on mailing card * mailing card load fk_project pre commit fix * only fetch projects with id>0 * fix PHPstan errors regarding mesg * projects related to mass mailings does not have a soc or socid * remove last trace of soc and socid * checking if mesg is set before using it * just loading all projects, because maybe you have a mailing list with workers for a thirdparty? think company party * showing the project during edit * given that action is already something else, it will never not be classify * making PHPstan happy * Adding project column to list of mass mailings. Search, order and click able * pasted the wrong place * no need to check for filtermail * x now also clears project search --------- Co-authored-by: Jon Bendtsen <xcodeauthor@jonb.dk> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
parent
387a42c9ea
commit
a9b468bbcd
3 changed files with 150 additions and 3 deletions
|
|
@ -4,6 +4,7 @@
|
|||
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2021 Waël Almoman <info@almoman.com>
|
||||
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
|
||||
* Copyright (C) 2025 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
|
||||
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
|
@ -40,6 +41,10 @@ require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
|
|||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
if (isModEnabled('project')) {
|
||||
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Conf $conf
|
||||
|
|
@ -58,6 +63,7 @@ $action = GETPOST('action', 'aZ09');
|
|||
$confirm = GETPOST('confirm', 'alpha');
|
||||
$cancel = GETPOST('cancel', 'aZ09');
|
||||
$urlfrom = GETPOST('urlfrom');
|
||||
$projectid = GETPOSTINT('projectid');
|
||||
$backtopageforcancel = GETPOST('backtopageforcancel');
|
||||
|
||||
// Initialize a technical objects
|
||||
|
|
@ -71,6 +77,17 @@ $extrafields->fetch_name_optionals_label($object->table_element);
|
|||
// Load object
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
|
||||
|
||||
// Load object->fk_project
|
||||
if (isset($object->fk_project) && $object->fk_project > 0 ) {
|
||||
dol_syslog('isset($object->fk_project)='.$object->fk_project, LOG_DEBUG);
|
||||
$ret = $object->fetchProject();
|
||||
if ($ret <= 0) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
|
||||
$object->substitutionarray = FormMail::getAvailableSubstitKey('emailing');
|
||||
|
||||
|
|
@ -569,6 +586,7 @@ if (empty($reshook)) {
|
|||
$object->body = (string) GETPOST("bodyemail", 'restricthtml');
|
||||
$object->bgcolor = preg_replace('/^#/', '', (string) GETPOST("bgcolor"));
|
||||
$object->bgimage = (string) GETPOST("bgimage");
|
||||
$object->fk_project = GETPOSTINT('projectid');
|
||||
|
||||
if (!$object->title) {
|
||||
$mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle"));
|
||||
|
|
@ -593,6 +611,23 @@ if (empty($reshook)) {
|
|||
$action = "create";
|
||||
}
|
||||
|
||||
if ($action == 'classin' && $permissiontocreate) {
|
||||
$mesgs = array();
|
||||
$setResult = $object->setProject(GETPOSTINT('projectid'));
|
||||
dol_syslog('Mailing card, action classin, setProject', LOG_DEBUG);
|
||||
if ($setResult) {
|
||||
$result = $object->update($user);
|
||||
if ($result >= 0) {
|
||||
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
|
||||
exit;
|
||||
}
|
||||
$mesg = $object->error;
|
||||
}
|
||||
|
||||
setEventMessages($mesg, $mesgs, 'errors');
|
||||
$action = "";
|
||||
}
|
||||
|
||||
// Action update description of emailing
|
||||
if (($action == 'settitle' || $action == 'setemail_from' || $action == 'setemail_replyto' || $action == 'setreplyto' || $action == 'setemail_errorsto' || $action == 'setevenunsubscribe') && $permissiontovalidatesend) {
|
||||
$upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, getDolGlobalInt('MAILING_USE_NEW_PATH_FOR_FILES') ? 0 : 2, 0, 1, $object, 'mailing');
|
||||
|
|
@ -613,7 +648,7 @@ if (empty($reshook)) {
|
|||
$object->evenunsubscribe = (GETPOST('evenunsubscribe') ? 1 : 0);
|
||||
}
|
||||
|
||||
if (!$mesg) {
|
||||
if (isset($mesg) && !$mesg) {
|
||||
$result = $object->update($user);
|
||||
if ($result >= 0) {
|
||||
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
|
||||
|
|
@ -761,6 +796,10 @@ if (empty($reshook)) {
|
|||
|
||||
$form = new Form($db);
|
||||
$htmlother = new FormOther($db);
|
||||
$formproject = null;
|
||||
if (isModEnabled('project')) {
|
||||
$formproject = new FormProjets($db);
|
||||
}
|
||||
|
||||
$help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing';
|
||||
llxHeader(
|
||||
|
|
@ -806,6 +845,17 @@ if ($action == 'create') { // aaa
|
|||
|
||||
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTitle").'</td><td><input class="flat minwidth300" name="title" value="'.dol_escape_htmltag(GETPOST('title')).'" autofocus="autofocus"></td></tr>';
|
||||
|
||||
// Project
|
||||
if (isModEnabled('project')) {
|
||||
$langs->load("projects");
|
||||
print '<tr class="field_projectid">';
|
||||
print '<td class="titlefieldcreate">' . $langs->trans("Project") . '</td><td class="valuefieldcreate">';
|
||||
print img_picto('', 'project', 'class="pictofixedwidth"') . $formproject->select_projects(-1, (string) $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
|
||||
print ' <a href="' . DOL_URL_ROOT . '/projet/card.php?action=create&status=1&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddProject") . '"></span></a>';
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
|
||||
$arrayoftypes = array("email" => "Email", "sms" => "SMS");
|
||||
print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Type").'</td><td>';
|
||||
|
|
@ -1027,6 +1077,27 @@ if ($action == 'create') { // aaa
|
|||
}
|
||||
$morehtmlstatus .= ') ';
|
||||
}
|
||||
// Project
|
||||
if (isModEnabled('project')) {
|
||||
$langs->load("projects");
|
||||
$morehtmlref .= '<br>';
|
||||
if ($permissiontocreate) {
|
||||
$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
|
||||
if ($action != 'classify') {
|
||||
$morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
|
||||
}
|
||||
$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, -1, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
|
||||
} else {
|
||||
if (!empty($object->fk_project)) {
|
||||
$proj = new Project($db);
|
||||
$proj->fetch($object->fk_project);
|
||||
$morehtmlref .= $proj->getNomUrl(1);
|
||||
if ($proj->title) {
|
||||
$morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
|
||||
|
||||
|
|
@ -1383,6 +1454,26 @@ if ($action == 'create') { // aaa
|
|||
$morehtmlstatus .= ') ';
|
||||
}
|
||||
|
||||
// Project
|
||||
if (isModEnabled('project')) {
|
||||
$langs->load("projects");
|
||||
$morehtmlref .= '<br>';
|
||||
if ($permissiontocreate) {
|
||||
$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
|
||||
$morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
|
||||
$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, -1, (string) $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
|
||||
} else {
|
||||
if (!empty($object->fk_project)) {
|
||||
$proj = new Project($db);
|
||||
$proj->fetch($object->fk_project);
|
||||
$morehtmlref .= $proj->getNomUrl(1);
|
||||
if ($proj->title) {
|
||||
$morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
|
||||
|
||||
print '<div class="fichecenter">';
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
||||
* Copyright (C) 2025 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -185,6 +186,11 @@ class Mailing extends CommonObject
|
|||
*/
|
||||
public $fk_project;
|
||||
|
||||
public $fields = array(
|
||||
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
|
||||
'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Fk project', 'enabled' => "isModEnabled('project')", 'visible' => -1, 'position' => 10),
|
||||
);
|
||||
|
||||
const STATUS_DRAFT = 0;
|
||||
const STATUS_VALIDATED = 1;
|
||||
const STATUS_SENTPARTIALY = 2;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
||||
* Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
|
||||
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2025 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -28,6 +29,9 @@
|
|||
// Load Dolibarr environment
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
|
||||
if (isModEnabled('project')) {
|
||||
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Conf $conf
|
||||
|
|
@ -71,6 +75,9 @@ $search_ref = GETPOST("search_ref", "alpha") ? GETPOST("search_ref", "alpha") :
|
|||
$search_messtype = GETPOST("search_messtype", "alpha");
|
||||
$filteremail = GETPOST('filteremail', 'alpha');
|
||||
|
||||
$search_refproject = GETPOST('search_refproject', 'alpha');
|
||||
$search_project = GETPOST('search_project', 'alpha');
|
||||
|
||||
// Initialize a technical objects
|
||||
$object = new Mailing($db);
|
||||
$extrafields = new ExtraFields($db);
|
||||
|
|
@ -135,6 +142,8 @@ if (empty($reshook)) {
|
|||
}*/
|
||||
$search_ref = '';
|
||||
$search_messtype = '';
|
||||
$search_refproject = '';
|
||||
$search_project = '';
|
||||
$search_all = '';
|
||||
$toselect = array();
|
||||
$search_array_options = array();
|
||||
|
|
@ -157,6 +166,7 @@ if (empty($reshook)) {
|
|||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
$projectstatic = new Project($db);
|
||||
|
||||
$now = dol_now();
|
||||
|
||||
|
|
@ -169,11 +179,13 @@ $morecss = array();
|
|||
// --------------------------------------------------------------------
|
||||
if ($filteremail) {
|
||||
$sql = "SELECT m.rowid, m.messtype, m.titre as title, m.nbemail, m.statut as status, m.date_creat as datec, m.date_envoi as date_envoi,";
|
||||
$sql .= " mc.statut as sendstatut";
|
||||
$sql .= " mc.statut as sendstatut,";
|
||||
$sql .= " pr.rowid as project_id, pr.ref as project_ref, pr.title as project_label";
|
||||
|
||||
$sqlfields = $sql; // $sql fields to remove for count total
|
||||
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON pr.rowid = m.fk_project";
|
||||
$sql .= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
|
||||
$sql .= " AND mc.email = '".$db->escape($filteremail)."'";
|
||||
if ($search_ref) {
|
||||
|
|
@ -185,6 +197,12 @@ if ($filteremail) {
|
|||
if ($search_all) {
|
||||
$sql .= " AND (m.titre LIKE '%".$db->escape($search_all)."%' OR m.sujet LIKE '%".$db->escape($search_all)."%' OR m.body LIKE '%".$db->escape($search_all)."%')";
|
||||
}
|
||||
if ($search_refproject) {
|
||||
$sql .= natural_search('pr.ref', $search_refproject);
|
||||
}
|
||||
if ($search_project) {
|
||||
$sql .= natural_search('pr.title', $search_project);
|
||||
}
|
||||
if (!$sortorder) {
|
||||
$sortorder = "ASC";
|
||||
}
|
||||
|
|
@ -192,11 +210,13 @@ if ($filteremail) {
|
|||
$sortfield = "m.rowid";
|
||||
}
|
||||
} else {
|
||||
$sql = "SELECT m.rowid, m.messtype, m.titre as title, m.nbemail, m.statut as status, m.date_creat as datec, m.date_envoi as date_envoi";
|
||||
$sql = "SELECT m.rowid, m.messtype, m.titre as title, m.nbemail, m.statut as status, m.date_creat as datec, m.date_envoi as date_envoi,";
|
||||
$sql .= " pr.rowid as project_id, pr.ref as project_ref, pr.title as project_label";
|
||||
|
||||
$sqlfields = $sql; // $sql fields to remove for count total
|
||||
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON pr.rowid = m.fk_project";
|
||||
$sql .= " WHERE m.entity = ".((int) $conf->entity);
|
||||
if ($search_ref) {
|
||||
$sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
|
||||
|
|
@ -207,6 +227,12 @@ if ($filteremail) {
|
|||
if ($search_all) {
|
||||
$sql .= " AND (m.titre LIKE '%".$db->escape($search_all)."%' OR m.sujet LIKE '%".$db->escape($search_all)."%' OR m.body LIKE '%".$db->escape($search_all)."%')";
|
||||
}
|
||||
if ($search_refproject) {
|
||||
$sql .= natural_search('pr.ref', $search_refproject);
|
||||
}
|
||||
if ($search_project) {
|
||||
$sql .= natural_search('pr.title', $search_project);
|
||||
}
|
||||
if (!$sortorder) {
|
||||
$sortorder = "ASC";
|
||||
}
|
||||
|
|
@ -301,6 +327,12 @@ if ($search_ref != '') {
|
|||
if ($search_messtype != '') {
|
||||
$param .= '&search_type='.urlencode($search_messtype);
|
||||
}
|
||||
if ($search_refproject != '') {
|
||||
$param .= '&search_refproject='.urlencode($search_refproject);
|
||||
}
|
||||
if ($search_project != '') {
|
||||
$param .= '&search_project='.urlencode($search_project);
|
||||
}
|
||||
if ($optioncss != '') {
|
||||
$param .= '&optioncss='.urlencode($optioncss);
|
||||
}
|
||||
|
|
@ -415,6 +447,12 @@ print '<td class="liste_titre">';
|
|||
print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_all" value="'.dol_escape_htmltag($search_all).'">';
|
||||
print '</td>';
|
||||
print '<td class="liste_titre"> </td>';
|
||||
|
||||
// Project
|
||||
print '<td class="liste_titre">';
|
||||
print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_project" value="'.dol_escape_htmltag($search_project).'">';
|
||||
print '</td>';
|
||||
|
||||
if (!$filteremail) {
|
||||
print '<td class="liste_titre"> </td>';
|
||||
}
|
||||
|
|
@ -455,6 +493,9 @@ if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) {
|
|||
print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "m.titre", $param, "", "", $sortfield, $sortorder);
|
||||
$totalarray['nbfield']++;
|
||||
print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "m.date_creat", $param, "", '', $sortfield, $sortorder, 'center ');
|
||||
|
||||
// Project
|
||||
print_liste_field_titre("Project", $_SERVER["PHP_SELF"], "project_label", $param, "", '', $sortfield, $sortorder);
|
||||
$totalarray['nbfield']++;
|
||||
if (!$filteremail) {
|
||||
$title = $langs->trans("NbOfEMails");
|
||||
|
|
@ -506,6 +547,10 @@ while ($i < $imaxinloop) {
|
|||
$object->id = $obj->rowid;
|
||||
$object->ref = $obj->rowid;
|
||||
|
||||
$projectstatic->id = $obj->project_id;
|
||||
$projectstatic->ref = $obj->project_ref;
|
||||
$projectstatic->title = $obj->project_label;
|
||||
|
||||
// Show here line of result
|
||||
$j = 0;
|
||||
print '<tr data-rowid="'.$object->id.'" class="oddeven row-with-select">';
|
||||
|
|
@ -546,6 +591,11 @@ while ($i < $imaxinloop) {
|
|||
print dol_print_date($db->jdate($obj->datec), 'day');
|
||||
print '</td>';
|
||||
|
||||
// Project
|
||||
print '<td class="nowraponall">';
|
||||
print '<a href="/projet/card.php?id='.((int) $projectstatic->id).'">'.dol_escape_htmltag($projectstatic->title).'</a>';
|
||||
print '</td>';
|
||||
|
||||
// Nb of email
|
||||
if (!$filteremail) {
|
||||
print '<td class="center nowraponall">';
|
||||
|
|
|
|||
Loading…
Reference in a new issue