email_editor.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This script contains the code to edit and send an e-mail to one of
  6. * the platform's users.
  7. * It can be called from the JavaScript library email_links.lib.php which
  8. * overtakes the mailto: links to use the internal interface instead.
  9. *
  10. * @author Yannick Warnier <ywarnier@beeznest.org>
  11. * @author Julio Montoya <gugli100@gmail.com> Updating form with formvalidator
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. if (empty(api_get_user_id())) {
  15. api_not_allowed(true);
  16. }
  17. $originUrl = Session::read('origin_url');
  18. if (empty($originUrl)) {
  19. Session::write('origin_url', $_SERVER['HTTP_REFERER']);
  20. }
  21. $action = isset($_GET['action']) ? $_GET['action'] : null;
  22. $form = new FormValidator('email_editor', 'post');
  23. $form->addElement('hidden', 'dest');
  24. $form->addElement('text', 'email_address', get_lang('EmailDestination'));
  25. $form->addElement('text', 'email_title', get_lang('EmailTitle'));
  26. $form->freeze('email_address');
  27. $form->addElement('textarea', 'email_text', get_lang('EmailText'), ['rows' => '6']);
  28. $form->addRule('email_address', get_lang('ThisFieldIsRequired'), 'required');
  29. $form->addRule('email_title', get_lang('ThisFieldIsRequired'), 'required');
  30. $form->addRule('email_text', get_lang('ThisFieldIsRequired'), 'required');
  31. $form->addRule('email_address', get_lang('EmailWrong'), 'email');
  32. $form->addButtonSend(get_lang('SendMail'));
  33. switch ($action) {
  34. case 'subscribe_me_to_session':
  35. $sessionName = isset($_GET['session']) ? Security::remove_XSS($_GET['session']) : null;
  36. $objTemplate = new Template();
  37. $objTemplate->assign('session_name', $sessionName);
  38. $objTemplate->assign('user', api_get_user_info());
  39. $mailTemplate = $objTemplate->get_template('mail/subscribe_me_to_session.tpl');
  40. $emailDest = api_get_setting('emailAdministrator');
  41. $emailTitle = get_lang('SubscribeToSessionRequest');
  42. $emailText = $objTemplate->fetch($mailTemplate);
  43. break;
  44. default:
  45. $emailDest = Security::remove_XSS($_REQUEST['dest']);
  46. $emailTitle = Security::remove_XSS($_REQUEST['email_title']);
  47. $emailText = Security::remove_XSS($_REQUEST['email_text']);
  48. }
  49. $defaults = [
  50. 'dest' => $emailDest,
  51. 'email_address' => $emailDest,
  52. 'email_title' => $emailTitle,
  53. 'email_text' => $emailText,
  54. ];
  55. $form->setDefaults($defaults);
  56. if ($form->validate()) {
  57. $text = Security::remove_XSS($_POST['email_text'])."\n\n---\n".get_lang('EmailSentFromLMS').' '.api_get_path(WEB_PATH);
  58. $email_administrator = Security::remove_XSS($_POST['dest']);
  59. $user_id = api_get_user_id();
  60. $title = Security::remove_XSS($_POST['email_title']);
  61. $content = Security::remove_XSS($_POST['email_text']);
  62. if (!empty($_user['mail'])) {
  63. api_mail_html(
  64. '',
  65. $email_administrator,
  66. $title,
  67. $text,
  68. api_get_person_name($_user['firstname'], $_user['lastname']),
  69. '',
  70. ['reply_to' => [
  71. 'mail' => $_user['mail'],
  72. 'name' => api_get_person_name($_user['firstname'], $_user['lastname']),
  73. ],
  74. ]
  75. );
  76. } else {
  77. api_mail_html(
  78. '',
  79. $email_administrator,
  80. $title,
  81. $text,
  82. get_lang('Anonymous')
  83. );
  84. }
  85. $orig = Session::read('origin_url');
  86. Session::erase('origin_url');
  87. header('Location:'.$orig);
  88. exit;
  89. }
  90. Display::display_header(get_lang('SendEmail'));
  91. $form->display();
  92. Display::display_footer();