PageRenderTime 60ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/mailing/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1157 lines | 858 code | 169 blank | 130 comment | 214 complexity | fadc371a47c215fd7f8ab0ee00db76b5 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2012 Laurent Destailleur <eldy@uers.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/comm/mailing/fiche.php
  21. * \ingroup mailing
  22. * \brief Fiche mailing, onglet general
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  32. $langs->load("mails");
  33. if (! $user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->societe_id > 0)) accessforbidden();
  34. $id=(GETPOST('mailid','int') ? GETPOST('mailid','int') : GETPOST('id','int'));
  35. $action=GETPOST('action','alpha');
  36. $confirm=GETPOST('confirm','alpha');
  37. $urlfrom=GETPOST('urlfrom');
  38. $object=new Mailing($db);
  39. $result=$object->fetch($id);
  40. $extrafields = new ExtraFields($db);
  41. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  42. $hookmanager->initHooks(array('mailingcard'));
  43. // Tableau des substitutions possibles
  44. $object->substitutionarray=array(
  45. '__ID__' => 'IdRecord',
  46. '__CAMPAGNEID__' => 'IdCampagne',
  47. '__EMAIL__' => 'EMail',
  48. '__LASTNAME__' => 'Lastname',
  49. '__FIRSTNAME__' => 'Firstname',
  50. '__MAILTOEMAIL__' => 'TagMailtoEmail',
  51. '__OTHER1__' => 'Other1',
  52. '__OTHER2__' => 'Other2',
  53. '__OTHER3__' => 'Other3',
  54. '__OTHER4__' => 'Other4',
  55. '__OTHER5__' => 'Other5',
  56. '__SIGNATURE__' => 'TagSignature',
  57. //'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet
  58. );
  59. if (! empty($conf->global->MAILING_EMAIL_UNSUBSCRIBE))
  60. {
  61. $object->substitutionarray=array_merge(
  62. $object->substitutionarray,
  63. array(
  64. '__CHECK_READ__' => 'TagCheckMail',
  65. '__UNSUBSCRIBE__' => 'TagUnsubscribe'
  66. )
  67. );
  68. }
  69. $object->substitutionarrayfortest=array(
  70. '__ID__' => 'TESTIdRecord',
  71. '__CAMPAGNEID' => 'TESTIdCampagne',
  72. '__EMAIL__' => 'TESTEMail',
  73. '__LASTNAME__' => 'TESTLastname',
  74. '__FIRSTNAME__' => 'TESTFirstname',
  75. '__MAILTOEMAIL__' => 'TESTMailtoEmail',
  76. '__OTHER1__' => 'TESTOther1',
  77. '__OTHER2__' => 'TESTOther2',
  78. '__OTHER3__' => 'TESTOther3',
  79. '__OTHER4__' => 'TESTOther4',
  80. '__OTHER5__' => 'TESTOther5',
  81. '__SIGNATURE__' => (($user->signature && empty($conf->global->MAIL_DO_NOT_USE_SIGN))?$user->signature:''),
  82. //'__PERSONALIZED__' => 'TESTPersonalized' // Not used yet
  83. );
  84. if (!empty($conf->global->MAILING_EMAIL_UNSUBSCRIBE))
  85. {
  86. $object->substitutionarrayfortest=array_merge(
  87. $object->substitutionarrayfortest,
  88. array(
  89. '__CHECK_READ__' => 'TESTCheckMail',
  90. '__UNSUBSCRIBE__' => 'TESTUnsubscribe'
  91. )
  92. );
  93. }
  94. /*
  95. * Actions
  96. */
  97. $parameters=array();
  98. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  99. // Action clone object
  100. if ($action == 'confirm_clone' && $confirm == 'yes')
  101. {
  102. if (empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
  103. {
  104. $mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
  105. }
  106. else
  107. {
  108. $result=$object->createFromClone($object->id,$_REQUEST["clone_content"],$_REQUEST["clone_receivers"]);
  109. if ($result > 0)
  110. {
  111. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
  112. exit;
  113. }
  114. else
  115. {
  116. $mesg=$object->error;
  117. }
  118. }
  119. $action='';
  120. }
  121. // Action send emailing for everybody
  122. if ($action == 'sendallconfirmed' && $confirm == 'yes')
  123. {
  124. if (empty($conf->global->MAILING_LIMIT_SENDBYWEB))
  125. {
  126. // Pour des raisons de securite, on ne permet pas cette fonction via l'IHM,
  127. // on affiche donc juste un message
  128. $mesg='<div class="warning">'.$langs->trans("MailingNeedCommand").'</div>';
  129. $mesg.='<br><textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>';
  130. $mesg.='<br><br><div class="warning">'.$langs->trans("MailingNeedCommand2").'</div>';
  131. $action='';
  132. }
  133. else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
  134. {
  135. $mesg='<div class="warning">'.$langs->trans("NotEnoughPermissions").'</div>';
  136. $action='';
  137. }
  138. else
  139. {
  140. $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
  141. if ($object->statut == 0)
  142. {
  143. dol_print_error('','ErrorMailIsNotValidated');
  144. exit;
  145. }
  146. $id = $object->id;
  147. $subject = $object->sujet;
  148. $message = $object->body;
  149. $from = $object->email_from;
  150. $replyto = $object->email_replyto;
  151. $errorsto = $object->email_errorsto;
  152. // Le message est-il en html
  153. $msgishtml=-1; // Unknown by default
  154. if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
  155. // Warning, we must not use begin-commit transaction here
  156. // because we want to save update for each mail sent.
  157. $nbok=0; $nbko=0;
  158. // On choisit les mails non deja envoyes pour ce mailing (statut=0)
  159. // ou envoyes en erreur (statut=-1)
  160. $sql = "SELECT mc.rowid, mc.nom, mc.prenom, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
  161. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
  162. $sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$object->id;
  163. dol_syslog("fiche.php: select targets sql=".$sql, LOG_DEBUG);
  164. $resql=$db->query($sql);
  165. if ($resql)
  166. {
  167. $num = $db->num_rows($resql); // nb of possible recipients
  168. if ($num)
  169. {
  170. dol_syslog("comm/mailing/fiche.php: nb of targets = ".$num, LOG_DEBUG);
  171. $now=dol_now();
  172. // Positionne date debut envoi
  173. $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi=".$db->idate($now)." WHERE rowid=".$object->id;
  174. $resql2=$db->query($sql);
  175. if (! $resql2)
  176. {
  177. dol_print_error($db);
  178. }
  179. // Loop on each email and send it
  180. $i = 0;
  181. while ($i < $num && $i < $conf->global->MAILING_LIMIT_SENDBYWEB)
  182. {
  183. $res=1;
  184. $obj = $db->fetch_object($resql);
  185. // sendto en RFC2822
  186. $sendto = str_replace(',',' ',$obj->prenom." ".$obj->nom)." <".$obj->email.">";
  187. // Make substitutions on topic and body. From (AA=YY;BB=CC;...) we keep YY, CC, ...
  188. $other=explode(';',$obj->other);
  189. $tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
  190. $tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
  191. $tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
  192. $tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
  193. $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
  194. $substitutionarray=array(
  195. '__ID__' => $obj->source_id,
  196. '__CAMPAGNEID__'=> $id,
  197. '__EMAIL__' => $obj->email,
  198. '__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'" width="1" height="1" style="width:1px;height:1px" border="0"/>',
  199. '__UNSUBSCRIBE__' => '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>',
  200. '__MAILTOEMAIL__' => '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>',
  201. '__LASTNAME__' => $obj->nom,
  202. '__FIRSTNAME__' => $obj->prenom,
  203. '__OTHER1__' => $other1,
  204. '__OTHER2__' => $other2,
  205. '__OTHER3__' => $other3,
  206. '__OTHER4__' => $other4,
  207. '__OTHER5__' => $other5
  208. );
  209. $substitutionisok=true;
  210. complete_substitutions_array($substitutionarray, $langs);
  211. $newsubject=make_substitutions($subject,$substitutionarray);
  212. $newmessage=make_substitutions($message,$substitutionarray);
  213. $arr_file = array();
  214. $arr_mime = array();
  215. $arr_name = array();
  216. $arr_css = array();
  217. $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
  218. if (count($listofpaths))
  219. {
  220. foreach($listofpaths as $key => $val)
  221. {
  222. $arr_file[]=$listofpaths[$key]['fullname'];
  223. $arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
  224. $arr_name[]=$listofpaths[$key]['name'];
  225. }
  226. }
  227. // Fabrication du mail
  228. $mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css);
  229. if ($mail->error)
  230. {
  231. $res=0;
  232. }
  233. if (! $substitutionisok)
  234. {
  235. $mail->error='Some substitution failed';
  236. $res=0;
  237. }
  238. // Send mail
  239. if ($res)
  240. {
  241. $res=$mail->sendfile();
  242. }
  243. if ($res)
  244. {
  245. // Mail successful
  246. $nbok++;
  247. dol_syslog("comm/mailing/fiche.php: ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
  248. $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
  249. $sql.=" SET statut=1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
  250. $resql2=$db->query($sql);
  251. if (! $resql2)
  252. {
  253. dol_print_error($db);
  254. }
  255. else
  256. {
  257. //if cheack read is use then update prospect contact status
  258. if (strpos($message, '__CHECK_READ__') !== false)
  259. {
  260. //Update status communication of thirdparty prospect
  261. $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
  262. dol_syslog("fiche.php: set prospect thirdparty status sql=".$sql, LOG_DEBUG);
  263. $resql2=$db->query($sql);
  264. if (! $resql2)
  265. {
  266. dol_print_error($db);
  267. }
  268. //Update status communication of contact prospect
  269. $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
  270. dol_syslog("fiche.php: set prospect contact status sql=".$sql, LOG_DEBUG);
  271. $resql2=$db->query($sql);
  272. if (! $resql2)
  273. {
  274. dol_print_error($db);
  275. }
  276. }
  277. }
  278. //test if CHECK READ change statut prospect contact
  279. }
  280. else
  281. {
  282. // Mail failed
  283. $nbko++;
  284. dol_syslog("comm/mailing/fiche.php: error for #".$i.($mail->error?' - '.$mail->error:''), LOG_WARNING);
  285. $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
  286. $sql.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
  287. $resql2=$db->query($sql);
  288. if (! $resql2)
  289. {
  290. dol_print_error($db);
  291. }
  292. }
  293. $i++;
  294. }
  295. }
  296. // Loop finished, set global statut of mail
  297. if ($nbko > 0)
  298. {
  299. $statut=2; // Status 'sent partially' (because at least one error)
  300. }
  301. else
  302. {
  303. if ($nbok >= $num) $statut=3; // Send to everybody
  304. else $statut=2; // Status 'sent partially' (because not send to everybody)
  305. }
  306. $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$object->id;
  307. dol_syslog("comm/mailing/fiche.php: update global status sql=".$sql, LOG_DEBUG);
  308. $resql2=$db->query($sql);
  309. if (! $resql2)
  310. {
  311. dol_print_error($db);
  312. }
  313. }
  314. else
  315. {
  316. dol_syslog($db->error());
  317. dol_print_error($db);
  318. }
  319. $action = '';
  320. }
  321. }
  322. // Action send test emailing
  323. if ($action == 'send' && empty($_POST["cancel"]))
  324. {
  325. $error=0;
  326. $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
  327. $object->sendto = $_POST["sendto"];
  328. if (! $object->sendto)
  329. {
  330. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("MailTo")).'</div>';
  331. $error++;
  332. }
  333. if (! $error)
  334. {
  335. // Le message est-il en html
  336. $msgishtml=-1; // Inconnu par defaut
  337. if (preg_match('/[\s\t]*<html>/i',$object->body)) $msgishtml=1;
  338. // Pratique les substitutions sur le sujet et message
  339. $object->sujet=make_substitutions($object->sujet,$object->substitutionarrayfortest);
  340. $object->body=make_substitutions($object->body,$object->substitutionarrayfortest);
  341. $arr_file = array();
  342. $arr_mime = array();
  343. $arr_name = array();
  344. $arr_css = array();
  345. // Ajout CSS
  346. if (!empty($object->bgcolor)) $arr_css['bgcolor'] = (preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor;
  347. if (!empty($object->bgimage)) $arr_css['bgimage'] = $object->bgimage;
  348. // Attached files
  349. $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
  350. if (count($listofpaths))
  351. {
  352. foreach($listofpaths as $key => $val)
  353. {
  354. $arr_file[]=$listofpaths[$key]['fullname'];
  355. $arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
  356. $arr_name[]=$listofpaths[$key]['name'];
  357. }
  358. }
  359. $mailfile = new CMailFile($object->sujet,$object->sendto,$object->email_from,$object->body, $arr_file,$arr_mime,$arr_name,'', '', 0, $msgishtml,$object->email_errorsto,$arr_css);
  360. $result=$mailfile->sendfile();
  361. if ($result)
  362. {
  363. $mesg='<div class="ok">'.$langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($object->email_from,2),$mailfile->getValidAddress($object->sendto,2)).'</div>';
  364. }
  365. else
  366. {
  367. $mesg='<div class="error">'.$langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result.'</div>';
  368. }
  369. $action='';
  370. }
  371. }
  372. // Action add emailing
  373. if ($action == 'add')
  374. {
  375. $object->email_from = trim($_POST["from"]);
  376. $object->email_replyto = trim($_POST["replyto"]);
  377. $object->email_errorsto = trim($_POST["errorsto"]);
  378. $object->titre = trim($_POST["titre"]);
  379. $object->sujet = trim($_POST["sujet"]);
  380. $object->body = trim($_POST["body"]);
  381. $object->bgcolor = trim($_POST["bgcolor"]);
  382. $object->bgimage = trim($_POST["bgimage"]);
  383. if (! $object->titre) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
  384. if (! $object->sujet) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
  385. if (! $object->body) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
  386. if (! $mesg)
  387. {
  388. if ($object->create($user) >= 0)
  389. {
  390. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  391. exit;
  392. }
  393. $mesg=$object->error;
  394. }
  395. $mesg='<div class="error">'.$mesg.'</div>';
  396. $action="create";
  397. }
  398. // Action update description of emailing
  399. if ($action == 'settitre' || $action == 'setemail_from' || $actino == 'setreplyto' || $action == 'setemail_errorsto')
  400. {
  401. $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
  402. if ($action == 'settitre') $object->titre = trim(GETPOST('titre','alpha'));
  403. else if ($action == 'setemail_from') $object->email_from = trim(GETPOST('email_from','alpha'));
  404. else if ($action == 'setemail_replyto') $object->email_replyto = trim(GETPOST('email_replyto','alpha'));
  405. else if ($action == 'setemail_errorsto') $object->email_errorsto = trim(GETPOST('email_errorsto','alpha'));
  406. else if ($action == 'settitre' && empty($object->titre)) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
  407. else if ($action == 'setfrom' && empty($object->email_from)) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom"));
  408. if (! $mesg)
  409. {
  410. if ($object->update($user) >= 0)
  411. {
  412. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  413. exit;
  414. }
  415. $mesg=$object->error;
  416. }
  417. $mesg='<div class="error">'.$mesg.'</div>';
  418. $action="";
  419. }
  420. /*
  421. * Add file in email form
  422. */
  423. if (! empty($_POST['addfile']))
  424. {
  425. $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
  426. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  427. // Set tmp user directory
  428. dol_add_file_process($upload_dir,0,0);
  429. $action="edit";
  430. }
  431. // Action remove file
  432. if (! empty($_POST["removedfile"]))
  433. {
  434. $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
  435. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  436. dol_remove_file_process($_POST['removedfile'],0);
  437. $action="edit";
  438. }
  439. // Action update emailing
  440. if ($action == 'update' && empty($_POST["removedfile"]) && empty($_POST["cancel"]))
  441. {
  442. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  443. $isupload=0;
  444. if (! $isupload)
  445. {
  446. $object->sujet = trim($_POST["sujet"]);
  447. $object->body = trim($_POST["body"]);
  448. $object->bgcolor = trim($_POST["bgcolor"]);
  449. $object->bgimage = trim($_POST["bgimage"]);
  450. if (! $object->sujet) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
  451. if (! $object->body) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
  452. if (! $mesg)
  453. {
  454. if ($object->update($user) >= 0)
  455. {
  456. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  457. exit;
  458. }
  459. $mesg=$object->error;
  460. }
  461. $mesg='<div class="error">'.$mesg.'</div>';
  462. $action="edit";
  463. }
  464. else
  465. {
  466. $action="edit";
  467. }
  468. }
  469. // Action confirmation validation
  470. if ($action == 'confirm_valid' && $confirm == 'yes')
  471. {
  472. if ($object->id > 0)
  473. {
  474. $object->valid($user);
  475. setEventMessage($langs->trans("MailingSuccessfullyValidated"));
  476. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  477. exit;
  478. }
  479. else
  480. {
  481. dol_print_error($db);
  482. }
  483. }
  484. // Resend
  485. if ($action == 'confirm_reset' && $confirm == 'yes')
  486. {
  487. if ($object->id > 0)
  488. {
  489. $db->begin();
  490. $result=$object->valid($user);
  491. if ($result > 0)
  492. {
  493. $result=$object->reset_targets_status($user);
  494. }
  495. if ($result > 0)
  496. {
  497. $db->commit();
  498. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  499. exit;
  500. }
  501. else
  502. {
  503. $mesg=$object->error;
  504. $db->rollback();
  505. }
  506. }
  507. else
  508. {
  509. dol_print_error($db);
  510. }
  511. }
  512. // Action confirmation suppression
  513. if ($action == 'confirm_delete' && $confirm == 'yes')
  514. {
  515. if ($object->delete($object->id))
  516. {
  517. $url= (! empty($urlfrom) ? $urlfrom : 'liste.php');
  518. header("Location: ".$url);
  519. exit;
  520. }
  521. }
  522. if (! empty($_POST["cancel"]))
  523. {
  524. $action = '';
  525. }
  526. /*
  527. * View
  528. */
  529. // fetch optionals attributes and labels
  530. $extralabels=$extrafields->fetch_name_optionals_label('mailing');
  531. llxHeader('',$langs->trans("Mailing"));
  532. $form = new Form($db);
  533. $htmlother = new FormOther($db);
  534. if ($action == 'create')
  535. {
  536. // EMailing in creation mode
  537. print '<form name="new_mailing" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
  538. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  539. print '<input type="hidden" name="action" value="add">';
  540. print_fiche_titre($langs->trans("NewMailing"));
  541. dol_htmloutput_mesg($mesg);
  542. print '<table class="border" width="100%">';
  543. print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailTitle").'</td><td><input class="flat" name="titre" size="40" value="'.$_POST['titre'].'"></td></tr>';
  544. print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailFrom").'</td><td><input class="flat" name="from" size="40" value="'.$conf->global->MAILING_EMAIL_FROM.'"></td></tr>';
  545. print '<tr><td width="25%">'.$langs->trans("MailErrorsTo").'</td><td><input class="flat" name="errorsto" size="40" value="'.(!empty($conf->global->MAILING_EMAIL_ERRORSTO)?$conf->global->MAILING_EMAIL_ERRORSTO:$conf->global->MAIN_MAIL_ERRORS_TO).'"></td></tr>';
  546. // Other attributes
  547. $parameters=array();
  548. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  549. if (empty($reshook) && ! empty($extrafields->attribute_label))
  550. {
  551. foreach($extrafields->attribute_label as $key=>$label)
  552. {
  553. $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
  554. print '<tr><td>'.$label.'</td><td colspan="3">';
  555. print $extrafields->showInputField($key,$value);
  556. print '</td></tr>'."\n";
  557. }
  558. }
  559. print '</table>';
  560. print '</br><br>';
  561. print '<table class="border" width="100%">';
  562. print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailTopic").'</td><td><input class="flat" name="sujet" size="60" value="'.$_POST['sujet'].'"></td></tr>';
  563. print '<tr><td width="25%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
  564. $htmlother->select_color($_POST['bgcolor'],'bgcolor','new_mailing',0);
  565. print '</td></tr>';
  566. print '<tr><td width="25%" class="fieldrequired" valign="top">'.$langs->trans("MailMessage").'<br>';
  567. print '<br><i>'.$langs->trans("CommonSubstitutions").':<br>';
  568. foreach($object->substitutionarray as $key => $val)
  569. {
  570. print $key.' = '.$langs->trans($val).'<br>';
  571. }
  572. print '</i></td>';
  573. print '<td>';
  574. // Editeur wysiwyg
  575. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  576. $doleditor=new DolEditor('body',$_POST['body'],'',320,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,70);
  577. $doleditor->Create();
  578. print '</td></tr>';
  579. print '</table>';
  580. print '<br><center><input type="submit" class="button" value="'.$langs->trans("CreateMailing").'"></center>';
  581. print '</form>';
  582. }
  583. else
  584. {
  585. if ($object->id > 0)
  586. {
  587. $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
  588. $head = emailing_prepare_head($object);
  589. dol_fiche_head($head, 'card', $langs->trans("Mailing"), 0, 'email');
  590. // Confirmation de la validation du mailing
  591. if ($action == 'valid')
  592. {
  593. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("ValidMailing"),$langs->trans("ConfirmValidMailing"),"confirm_valid",'','',1);
  594. if ($ret == 'html') print '<br>';
  595. }
  596. // Confirm reset
  597. else if ($action == 'reset')
  598. {
  599. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("ResetMailing"),$langs->trans("ConfirmResetMailing",$object->ref),"confirm_reset",'','',2);
  600. if ($ret == 'html') print '<br>';
  601. }
  602. // Confirm delete
  603. else if ($action == 'delete')
  604. {
  605. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id.(! empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''),$langs->trans("DeleteAMailing"),$langs->trans("ConfirmDeleteMailing"),"confirm_delete",'','',1);
  606. if ($ret == 'html') print '<br>';
  607. }
  608. if ($action != 'edit')
  609. {
  610. /*
  611. * Mailing en mode visu
  612. */
  613. if ($action == 'sendall')
  614. {
  615. // Define message to recommand from command line
  616. // Pour des raisons de securite, on ne permet pas cette fonction via l'IHM,
  617. // on affiche donc juste un message
  618. if (empty($conf->global->MAILING_LIMIT_SENDBYWEB))
  619. {
  620. // Pour des raisons de securite, on ne permet pas cette fonction via l'IHM,
  621. // on affiche donc juste un message
  622. $mesgembedded.='<div class="warning">'.$langs->trans("MailingNeedCommand").'</div>';
  623. $mesgembedded.='<br><textarea cols="60" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>';
  624. $mesgembedded.='<br><br><div class="warning">'.$langs->trans("MailingNeedCommand2").'</div>';
  625. $_GET["action"]='';
  626. }
  627. else
  628. {
  629. $text='';
  630. if ($conf->file->mailing_limit_sendbyweb == 0)
  631. {
  632. $text.=$langs->trans("MailingNeedCommand");
  633. $text.='<br><textarea cols="60" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>';
  634. $text.='<br><br>';
  635. }
  636. $text.=$langs->trans('ConfirmSendingEmailing').'<br>';
  637. $text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
  638. $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('SendMailing'),$text,'sendallconfirmed',$formquestion,'',1,260);
  639. if ($ret == 'html') print '<br>';
  640. }
  641. }
  642. print '<table class="border" width="100%">';
  643. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/liste.php">'.$langs->trans("BackToList").'</a>';
  644. print '<tr><td width="15%">'.$langs->trans("Ref").'</td>';
  645. print '<td colspan="3">';
  646. print $form->showrefnav($object,'id', $linkback);
  647. print '</td></tr>';
  648. // Description
  649. print '<tr><td>'.$form->editfieldkey("MailTitle",'titre',$object->titre,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
  650. print $form->editfieldval("MailTitle",'titre',$object->titre,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
  651. print '</td></tr>';
  652. // From
  653. print '<tr><td>'.$form->editfieldkey("MailFrom",'email_from',$object->email_from,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
  654. print $form->editfieldval("MailFrom",'email_from',$object->email_from,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
  655. print '</td></tr>';
  656. // Errors to
  657. print '<tr><td>'.$form->editfieldkey("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
  658. print $form->editfieldval("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
  659. print '</td></tr>';
  660. // Status
  661. print '<tr><td width="15%">'.$langs->trans("Status").'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
  662. // Nb of distinct emails
  663. print '<tr><td width="15%">';
  664. print $langs->trans("TotalNbOfDistinctRecipients");
  665. print '</td><td colspan="3">';
  666. $nbemail = ($object->nbemail?$object->nbemail:img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>');
  667. if ($object->statut != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && is_numeric($nbemail) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
  668. {
  669. if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
  670. {
  671. $text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
  672. print $form->textwithpicto($nbemail,$text,1,'warning');
  673. }
  674. else
  675. {
  676. $text=$langs->trans('NotEnoughPermissions');
  677. print $form->textwithpicto($nbemail,$text,1,'warning');
  678. }
  679. }
  680. else
  681. {
  682. print $nbemail;
  683. }
  684. print '</td></tr>';
  685. // Other attributes
  686. $parameters=array();
  687. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  688. if (empty($reshook) && ! empty($extrafields->attribute_label))
  689. {
  690. foreach($extrafields->attribute_label as $key=>$label)
  691. {
  692. $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
  693. print '<tr><td>'.$label.'</td><td colspan="3">';
  694. print $extrafields->showInputField($key,$value);
  695. print "</td></tr>\n";
  696. }
  697. }
  698. print '</table>';
  699. print "</div>";
  700. // Clone confirmation
  701. if ($action == 'clone')
  702. {
  703. // Create an array for form
  704. $formquestion=array(
  705. 'text' => $langs->trans("ConfirmClone"),
  706. array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContent"), 'value' => 1),
  707. array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers").' ('.$langs->trans("FeatureNotYetAvailable").')', 'value' => 0, 'disabled' => true)
  708. );
  709. // Paiement incomplet. On demande si motif = escompte ou autre
  710. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneEMailing'),$langs->trans('ConfirmCloneEMailing',$object->ref),'confirm_clone',$formquestion,'yes',2,240);
  711. }
  712. dol_htmloutput_mesg($mesg);
  713. if($conf->mailjet->enabled)
  714. {
  715. dol_include_once("/mailjet/class/mailjet.class.php");
  716. $langs->load("mailjet@mailjet");
  717. $mailjet=new Mailjet($db);
  718. print $mailjet->statistic($mil->id);
  719. }
  720. /*
  721. * Boutons d'action
  722. */
  723. if (GETPOST("cancel") || $confirm=='no' || $action == '' || in_array($action,array('valid','delete','sendall','clone')))
  724. {
  725. print "\n\n<div class=\"tabsAction\">\n";
  726. if (($object->statut == 0 || $object->statut == 1) && $user->rights->mailing->creer)
  727. {
  728. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditMailing").'</a>';
  729. }
  730. //print '<a class="butAction" href="fiche.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
  731. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
  732. {
  733. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("TestMailing").'</a>';
  734. }
  735. else
  736. {
  737. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=test&amp;id='.$object->id.'">'.$langs->trans("TestMailing").'</a>';
  738. }
  739. if ($object->statut == 0)
  740. {
  741. if ($object->nbemail <= 0)
  742. {
  743. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoTargetYet")).'">'.$langs->trans("ValidMailing").'</a>';
  744. }
  745. else if (empty($user->rights->mailing->valider))
  746. {
  747. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ValidMailing").'</a>';
  748. }
  749. else
  750. {
  751. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=valid&amp;id='.$object->id.'">'.$langs->trans("ValidMailing").'</a>';
  752. }
  753. }
  754. if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->rights->mailing->valider)
  755. {
  756. if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0 || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send))
  757. {
  758. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
  759. }
  760. else
  761. {
  762. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=sendall&amp;id='.$object->id.'">'.$langs->trans("SendMailing").'</a>';
  763. }
  764. }
  765. if ($user->rights->mailing->creer)
  766. {
  767. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=clone&amp;object=emailing&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
  768. }
  769. if (($object->statut == 2 || $object->statut == 3) && $user->rights->mailing->valider)
  770. {
  771. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
  772. {
  773. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ResetMailing").'</a>';
  774. }
  775. else
  776. {
  777. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=reset&amp;id='.$object->id.'">'.$langs->trans("ResetMailing").'</a>';
  778. }
  779. }
  780. if (($object->statut <= 1 && $user->rights->mailing->creer) || $user->rights->mailing->supprimer)
  781. {
  782. if ($object->statut > 0 && (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->delete))
  783. {
  784. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("DeleteMailing").'</a>';
  785. }
  786. else
  787. {
  788. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.(! empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
  789. }
  790. }
  791. print '<br><br></div>';
  792. }
  793. if (! empty($mesgembedded)) dol_htmloutput_mesg($mesgembedded,'','warning',1);
  794. // Affichage formulaire de TEST
  795. if ($action == 'test')
  796. {
  797. print_titre($langs->trans("TestMailing"));
  798. // Create l'objet formulaire mail
  799. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  800. $formmail = new FormMail($db);
  801. $formmail->fromname = $object->email_from;
  802. $formmail->frommail = $object->email_from;
  803. $formmail->withsubstit=1;
  804. $formmail->withfrom=0;
  805. $formmail->withto=$user->email?$user->email:1;
  806. $formmail->withtocc=0;
  807. $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
  808. $formmail->withtopic=0;
  809. $formmail->withtopicreadonly=1;
  810. $formmail->withfile=0;
  811. $formmail->withbody=0;
  812. $formmail->withbodyreadonly=1;
  813. $formmail->withcancel=1;
  814. $formmail->withdeliveryreceipt=0;
  815. // Tableau des substitutions
  816. $formmail->substit=$object->substitutionarrayfortest;
  817. // Tableau des parametres complementaires du post
  818. $formmail->param["action"]="send";
  819. $formmail->param["models"]="body";
  820. $formmail->param["mailid"]=$object->id;
  821. $formmail->param["returnurl"]=$_SERVER['PHP_SELF']."?id=".$object->id;
  822. $formmail->show_form();
  823. print '<br>';
  824. }
  825. // Print mail content
  826. print_fiche_titre($langs->trans("EMail"),'','');
  827. print '<table class="border" width="100%">';
  828. // Subject
  829. print '<tr><td width="15%">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$object->sujet.'</td></tr>';
  830. // Joined files
  831. print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
  832. // List of files
  833. $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
  834. if (count($listofpaths))
  835. {
  836. foreach($listofpaths as $key => $val)
  837. {
  838. print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
  839. print '<br>';
  840. }
  841. }
  842. else
  843. {
  844. print $langs->trans("NoAttachedFiles").'<br>';
  845. }
  846. print '</td></tr>';
  847. // Background color
  848. /*print '<tr><td width="15%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
  849. $htmlother->select_color($object->bgcolor,'bgcolor','edit_mailing',0);
  850. print '</td></tr>';*/
  851. // Message
  852. print '<tr><td valign="top">'.$langs->trans("MailMessage").'</td>';
  853. print '<td colspan="3" bgcolor="'.($object->bgcolor?(preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor:'white').'">';
  854. print dol_htmlentitiesbr($object->body);
  855. print '</td>';
  856. print '</tr>';
  857. print '</table>';
  858. print "<br>";
  859. }
  860. else
  861. {
  862. /*
  863. * Mailing en mode edition
  864. */
  865. dol_htmloutput_mesg($mesg);
  866. print '<table class="border" width="100%">';
  867. // Ref
  868. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">'.$object->id.'</td></tr>';
  869. // Topic
  870. print '<tr><td width="25%">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->titre.'</td></tr>';
  871. // From
  872. print '<tr><td width="25%">'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from,0,0,0,0,1).'</td></tr>';
  873. // To
  874. print '<tr><td width="25%">'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto,0,0,0,0,1).'</td></tr>';
  875. // Status
  876. print '<tr><td width="25%">'.$langs->trans("Status").'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
  877. // Nb of distinct emails
  878. print '<tr><td width="25%">';
  879. print $langs->trans("TotalNbOfDistinctRecipients");
  880. print '</td><td colspan="3">';
  881. $nbemail = ($object->nbemail?$object->nbemail:'<font class="error">'.$langs->trans("NoTargetYet").'</font>');
  882. if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && is_numeric($nbemail) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
  883. {
  884. $text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
  885. print $form->textwithpicto($nbemail,$text,1,'warning');
  886. }
  887. else
  888. {
  889. print $nbemail;
  890. }
  891. print '</td></tr>';
  892. // Other attributes
  893. $parameters=array();
  894. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  895. if (empty($reshook) && ! empty($extrafields->attribute_label))
  896. {
  897. foreach($extrafields->attribute_label as $key=>$label)
  898. {
  899. $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
  900. print '<tr><td>'.$label.'</td><td colspan="3">';
  901. print $extrafields->showInputField($key,$value);
  902. print "</td></tr>\n";
  903. }
  904. }
  905. print '</table>';
  906. print "</div>";
  907. print "\n";
  908. print '<form name="edit_mailing" action="fiche.php" method="post" enctype="multipart/form-data">'."\n";
  909. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  910. print '<input type="hidden" name="action" value="update">';
  911. print '<input type="hidden" name="id" value="'.$object->id.'">';
  912. // Print mail content
  913. print_fiche_titre($langs->trans("EMail"),'','');
  914. print '<table class="border" width="100%">';
  915. // Subject
  916. print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailTopic").'</td><td colspan="3"><input class="flat" type="text" size=60 name="sujet" value="'.$object->sujet.'"></td></tr>';
  917. dol_init_file_process($upload_dir);
  918. // Joined files
  919. $addfileaction='addfile';
  920. print '<tr><td>'.$langs->trans("MailFile").'</td>';
  921. print '<td colspan="3">';
  922. // List of files
  923. $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
  924. // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
  925. $out.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
  926. $out.= '<script type="text/javascript" language="javascript">';
  927. $out.= 'jQuery(document).ready(function () {';
  928. $out.= ' jQuery(".removedfile").click(function() {';
  929. $out.= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
  930. $out.= ' });';
  931. $out.= '})';
  932. $out.= '</script>'."\n";
  933. if (count($listofpaths))
  934. {
  935. foreach($listofpaths as $key => $val)
  936. {
  937. $out.= '<div id="attachfile_'.$key.'">';
  938. $out.= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
  939. $out.= ' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" value="'.($key+1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
  940. $out.= '<br></div>';
  941. }
  942. }
  943. else
  944. {
  945. $out.= $langs->trans("NoAttachedFiles").'<br>';
  946. }
  947. // Add link to add file
  948. $out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
  949. $out.= ' ';
  950. $out.= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
  951. print $out;
  952. print '</td></tr>';
  953. // Background color
  954. print '<tr><td width="25%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
  955. $htmlother->select_color($object->bgcolor,'bgcolor','edit_mailing',0);
  956. print '</td></tr>';
  957. // Message
  958. print '<tr><td width="25%" valign="top">'.$langs->trans("MailMessage").'<br>';
  959. print '<br><i>'.$langs->trans("CommonSubstitutions").':<br>';
  960. foreach($object->substitutionarray as $key => $val)
  961. {
  962. print $key.' = '.$langs->trans($val).'<br>';
  963. }
  964. print '</i></td>';
  965. print '<td colspan="3">';
  966. // Editeur wysiwyg
  967. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  968. $doleditor=new DolEditor('body',$object->body,'',320,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,70);
  969. $doleditor->Create();
  970. print '</td></tr>';
  971. print '<tr><td colspan="4" align="center">';
  972. print '<input type="submit" class="button" value="'.$langs->trans("Save").'" name="save">';
  973. print ' &nbsp; ';
  974. print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel">';
  975. print '</td></tr>';
  976. print '</table>';
  977. print '</form>';
  978. print '<br>';
  979. }
  980. }
  981. else
  982. {
  983. dol_print_error($db,$object->error);
  984. }
  985. }
  986. llxFooter();
  987. $db->close();
  988. ?>