Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
69b9de08b8
@ -63,7 +63,7 @@ if (! empty($_POST['removedfile']))
|
|||||||
/*
|
/*
|
||||||
* Send mail
|
* Send mail
|
||||||
*/
|
*/
|
||||||
if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
|
if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'] && !$_POST['modelselected'])
|
||||||
{
|
{
|
||||||
$langs->load('mails');
|
$langs->load('mails');
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
|
|||||||
* $formmail->proprietes=1 ou chaine ou tableau de valeurs
|
* $formmail->proprietes=1 ou chaine ou tableau de valeurs
|
||||||
* $formmail->show_form() affiche le formulaire
|
* $formmail->show_form() affiche le formulaire
|
||||||
*/
|
*/
|
||||||
class FormMail
|
class FormMail extends Form
|
||||||
{
|
{
|
||||||
var $db;
|
var $db;
|
||||||
|
|
||||||
@ -71,6 +71,8 @@ class FormMail
|
|||||||
|
|
||||||
var $error;
|
var $error;
|
||||||
|
|
||||||
|
public $lines_model;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -242,7 +244,7 @@ class FormMail
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$out='';
|
$out='';
|
||||||
|
|
||||||
// Define list of attached files
|
// Define list of attached files
|
||||||
$listofpaths=array();
|
$listofpaths=array();
|
||||||
$listofnames=array();
|
$listofnames=array();
|
||||||
@ -263,8 +265,11 @@ class FormMail
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get message template
|
// Get message template
|
||||||
$arraydefaultmessage=$this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs);
|
$model_id=0;
|
||||||
|
if (array_key_exists('models_id',$this->param)) {
|
||||||
|
$model_id=$this->param["models_id"];
|
||||||
|
}
|
||||||
|
$arraydefaultmessage=$this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, $model_id);
|
||||||
|
|
||||||
$out.= "\n<!-- Debut form mail -->\n";
|
$out.= "\n<!-- Debut form mail -->\n";
|
||||||
if ($this->withform == 1)
|
if ($this->withform == 1)
|
||||||
@ -277,6 +282,27 @@ class FormMail
|
|||||||
{
|
{
|
||||||
$out.= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n";
|
$out.= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
|
||||||
|
if ($result<0) {
|
||||||
|
setEventMessage($this->error,'errors');
|
||||||
|
}
|
||||||
|
$modelmail_array=array();
|
||||||
|
foreach($this->lines_model as $line) {
|
||||||
|
$modelmail_array[$line->id]=$line->label;
|
||||||
|
}
|
||||||
|
if (count($modelmail_array>0)) {
|
||||||
|
$out.= '<table class="nobordernopadding" width="100%"><tr><td width="20%">'."\n";
|
||||||
|
$out.= $langs->trans('SelectMailModel').':'.$this->selectarray('modelmailselected', $modelmail_array,$model_id);
|
||||||
|
$out.= '</td>';
|
||||||
|
$out.= '<td width="5px">';
|
||||||
|
if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
|
||||||
|
$out.= '</td>';
|
||||||
|
$out.= '<td><input class="flat" type="submit" value="'.$langs->trans('Valid').'" name="modelselected" id="modelselected"></td>';
|
||||||
|
$out.= '</tr></table>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$out.= '<table class="border" width="100%">'."\n";
|
$out.= '<table class="border" width="100%">'."\n";
|
||||||
|
|
||||||
// Substitution array
|
// Substitution array
|
||||||
@ -617,8 +643,8 @@ class FormMail
|
|||||||
$defaultmessage = dol_nl2br($defaultmessage);
|
$defaultmessage = dol_nl2br($defaultmessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
|
if (isset($_POST["message"]) && ! $_POST['modelselected']) $defaultmessage=$_POST["message"];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$defaultmessage=make_substitutions($defaultmessage,$this->substit);
|
$defaultmessage=make_substitutions($defaultmessage,$this->substit);
|
||||||
@ -690,9 +716,10 @@ class FormMail
|
|||||||
* @param string $type_template Get message for key module
|
* @param string $type_template Get message for key module
|
||||||
* @param string $user Use template public or limited to this user
|
* @param string $user Use template public or limited to this user
|
||||||
* @param Translate $outputlangs Output lang object
|
* @param Translate $outputlangs Output lang object
|
||||||
|
* @param int $id Id template to find
|
||||||
* @return array array('topic'=>,'content'=>,..)
|
* @return array array('topic'=>,'content'=>,..)
|
||||||
*/
|
*/
|
||||||
private function getEMailTemplate($db, $type_template, $user, $outputlangs)
|
private function getEMailTemplate($db, $type_template, $user, $outputlangs,$id=0)
|
||||||
{
|
{
|
||||||
$ret=array();
|
$ret=array();
|
||||||
|
|
||||||
@ -702,6 +729,7 @@ class FormMail
|
|||||||
$sql.= " AND entity IN (".getEntity("c_email_templates").")";
|
$sql.= " AND entity IN (".getEntity("c_email_templates").")";
|
||||||
$sql.= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".$user->id.")";
|
$sql.= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".$user->id.")";
|
||||||
if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')";
|
if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')";
|
||||||
|
if (!empty($id)) $sql.= " AND rowid=".$id;
|
||||||
$sql.= $db->order("lang,label","ASC");
|
$sql.= $db->order("lang,label","ASC");
|
||||||
//print $sql;
|
//print $sql;
|
||||||
|
|
||||||
@ -745,5 +773,96 @@ class FormMail
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find if template exists
|
||||||
|
* Search into table c_email_templates
|
||||||
|
*
|
||||||
|
* @param string $type_template Get message for key module
|
||||||
|
* @param string $user Use template public or limited to this user
|
||||||
|
* @param Translate $outputlangs Output lang object
|
||||||
|
* @return int <0 if KO,
|
||||||
|
*/
|
||||||
|
public function isEMailTemplate($type_template, $user, $outputlangs)
|
||||||
|
{
|
||||||
|
$ret=array();
|
||||||
|
|
||||||
|
$sql = "SELECT label, topic, content, lang";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX.'c_email_templates';
|
||||||
|
$sql.= " WHERE type_template='".$this->db->escape($type_template)."'";
|
||||||
|
$sql.= " AND entity IN (".getEntity("c_email_templates").")";
|
||||||
|
$sql.= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".$user->id.")";
|
||||||
|
if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')";
|
||||||
|
$sql.= $this->db->order("lang,label","ASC");
|
||||||
|
//print $sql;
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num= $this->db->num_rows($resql);
|
||||||
|
$this->db->free($resql);
|
||||||
|
return $num;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find if template exists
|
||||||
|
* Search into table c_email_templates
|
||||||
|
*
|
||||||
|
* @param string $type_template Get message for key module
|
||||||
|
* @param string $user Use template public or limited to this user
|
||||||
|
* @param Translate $outputlangs Output lang object
|
||||||
|
* @return int <0 if KO,
|
||||||
|
*/
|
||||||
|
public function fetchAllEMailTemplate($type_template, $user, $outputlangs)
|
||||||
|
{
|
||||||
|
$ret=array();
|
||||||
|
|
||||||
|
$sql = "SELECT rowid, label, topic, content, lang";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX.'c_email_templates';
|
||||||
|
$sql.= " WHERE type_template='".$this->db->escape($type_template)."'";
|
||||||
|
$sql.= " AND entity IN (".getEntity("c_email_templates").")";
|
||||||
|
$sql.= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".$user->id.")";
|
||||||
|
if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')";
|
||||||
|
$sql.= $this->db->order("lang,label","ASC");
|
||||||
|
//print $sql;
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$this->lines_model=array();
|
||||||
|
while ($obj = $this->db->fetch_object($resql)) {
|
||||||
|
$line = new ModelMailLine();
|
||||||
|
$line->id=$obj->rowid;
|
||||||
|
$line->label=$obj->label;
|
||||||
|
$line->topic=$obj->topic;
|
||||||
|
$line->content=$obj->lacontentbel;
|
||||||
|
$line->lang=$obj->lang;
|
||||||
|
$this->lines_model[]=$line;
|
||||||
|
|
||||||
|
}
|
||||||
|
$this->db->free($resql);
|
||||||
|
return $num;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ModelMailLine
|
||||||
|
{
|
||||||
|
public $id;
|
||||||
|
public $label;
|
||||||
|
public $topic;
|
||||||
|
public $content;
|
||||||
|
public $lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -732,3 +732,4 @@ ShortThursday=T
|
|||||||
ShortFriday=F
|
ShortFriday=F
|
||||||
ShortSaturday=S
|
ShortSaturday=S
|
||||||
ShortSunday=S
|
ShortSunday=S
|
||||||
|
SelectMailModel=Select email template
|
||||||
@ -2163,7 +2163,10 @@ else
|
|||||||
|
|
||||||
print '</div>'."\n";
|
print '</div>'."\n";
|
||||||
|
|
||||||
|
//Select mail models is same action as presend
|
||||||
|
if (!empty(GETPOST('modelselected'))) {
|
||||||
|
$action = 'presend';
|
||||||
|
}
|
||||||
if ($action == 'presend')
|
if ($action == 'presend')
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -2185,7 +2188,7 @@ else
|
|||||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
|
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
|
||||||
$newlang = $_REQUEST['lang_id'];
|
$newlang = $_REQUEST['lang_id'];
|
||||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
|
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
|
||||||
$newlang = $object->client->default_lang;
|
$newlang = $object->default_lang;
|
||||||
|
|
||||||
// Cree l'objet formulaire mail
|
// Cree l'objet formulaire mail
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||||
@ -2246,6 +2249,7 @@ else
|
|||||||
// Tableau des parametres complementaires du post
|
// Tableau des parametres complementaires du post
|
||||||
$formmail->param['action']=$action;
|
$formmail->param['action']=$action;
|
||||||
$formmail->param['models']=$modelmail;
|
$formmail->param['models']=$modelmail;
|
||||||
|
$formmail->param['models_id']=GETPOST('modelmailselected','int');
|
||||||
$formmail->param['socid']=$object->id;
|
$formmail->param['socid']=$object->id;
|
||||||
$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?socid='.$object->id;
|
$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?socid='.$object->id;
|
||||||
|
|
||||||
@ -2255,7 +2259,6 @@ else
|
|||||||
$formmail->clear_attached_files();
|
$formmail->clear_attached_files();
|
||||||
$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
|
$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
|
||||||
}
|
}
|
||||||
|
|
||||||
print $formmail->get_form();
|
print $formmail->get_form();
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user