MailEffect.class.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. Effet de workflow
  4. Envois un mail a une ou plusieurs adresses
  5. */
  6. class MailEffect{
  7. //Descriptif du type d'effet
  8. public static function manifest($key = null){
  9. $manifest = array(
  10. 'slug' => 'mail',
  11. 'label' => 'Envoyer un e-mail',
  12. 'class' => get_called_class(),
  13. 'path' => __FILE__,
  14. 'icon' => 'fas fa-envelope-open-text',
  15. 'color' => '#ff9f43',
  16. );
  17. if(!isset($key)) return $manifest;
  18. return isset($manifest[$key]) ? $manifest[$key] : '' ;
  19. }
  20. //méthode d'affichage de l'effet
  21. public static function form($item){
  22. $html = '';
  23. $class = get_called_class();
  24. ob_start();
  25. ?>
  26. <div class="input-group">
  27. <div class="input-group-text input-group-prepend">
  28. Pour :
  29. </div>
  30. <input type="text" data-id="to" class="form-control" value="<?php echo isset($item['to']) ? $item['to'] : '' ?>" placeholder="jdoe@doe.com, jmith@smithcorp.com">
  31. </div>
  32. <div class="input-group mt-2">
  33. <div class="input-group-text input-group-prepend">
  34. Titre :
  35. </div>
  36. <input type="text" data-id="title" class="form-control" value="<?php echo isset($item['title']) ? $item['title'] : '' ?>" placeholder="Bonjour,...">
  37. </div>
  38. <textarea data-id="message" data-type="wysiwyg"><?php echo isset($item['message']) ? $item['message'] : '' ?></textarea>
  39. <?php
  40. $html = ob_get_clean();
  41. return $html;
  42. }
  43. public static function run($effect,$parameters = array()){
  44. global $conf;
  45. $logs = '';
  46. try{
  47. if( in_array($parameters['workflow']['type'] , array( Workflow::TYPE_ENTITY, Workflow::TYPE_LIST)) ){
  48. if(isset($parameters['current'])) $parameters['current'] = $parameters['current']->toArray();
  49. if(isset($parameters['old'])) $parameters['old'] = $parameters['old']->toArray();
  50. }
  51. $effect->values['title'] = template($effect->values['title'],$parameters,true);
  52. $effect->values['message'] = template($effect->values['message'],$parameters,true);
  53. $expeditor = $conf->get('workflow_mail_from') != '' ? $conf->get('workflow_mail_from'): PROGRAM_NAME.' <workflow@'.PROGRAM_NAME.'.fr>';
  54. $reply = $conf->get('workflow_mail_reply') != '' ? $conf->get('workflow_mail_reply'): $expeditor;
  55. $mail = new Mail();
  56. $mail->expeditor = $expeditor;
  57. $mail->reply = $reply;
  58. $mail->title = $effect->values['title'];
  59. $mail->message = html_entity_decode($effect->values['message']);
  60. $mail->recipients['to'][] = $effect->values['to'];
  61. $logs = 'Sujet: "'.$mail->title.'" pour '.implode($mail->recipients['to']);
  62. $mail->send();
  63. }catch(Exception $e){
  64. $logs .= '<span class="text-danger"><br>Erreur : '.$e->getMessage().'</span>';
  65. }
  66. return $logs;
  67. }
  68. }
  69. ?>