email_editor.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * @author Yannick Warnier <ywarnier@beeznest.org>
  10. * @author Julio Montoya <gugli100@gmail.com> Updating form with formvalidator
  11. */
  12. require_once __DIR__.'/../inc/global.inc.php';
  13. if (empty($_user['user_id'])) {
  14. api_not_allowed(true);
  15. }
  16. if (empty($_SESSION['origin_url'])) {
  17. $origin_url = $_SERVER['HTTP_REFERER'];
  18. Session::write('origin_url', $origin_url);
  19. }
  20. $action = isset($_GET['action']) ? $_GET['action'] : null;
  21. $form = new FormValidator('email_editor', 'post');
  22. $form->addElement('hidden', 'dest');
  23. $form->addElement('text', 'email_address', get_lang('EmailDestination'));
  24. $form->addElement('text', 'email_title', get_lang('EmailTitle'));
  25. $form->freeze('email_address');
  26. $form->addElement('textarea', 'email_text', get_lang('EmailText'), array('rows' => '6'));
  27. $form->addRule('email_address', get_lang('ThisFieldIsRequired'), 'required');
  28. $form->addRule('email_title', get_lang('ThisFieldIsRequired'), 'required');
  29. $form->addRule('email_text', get_lang('ThisFieldIsRequired'), 'required');
  30. $form->addRule('email_address', get_lang('EmailWrong'), 'email');
  31. $form->addButtonSend(get_lang('SendMail'));
  32. switch ($action) {
  33. case 'subscribe_me_to_session':
  34. $sessionName = isset($_GET['session']) ? Security::remove_XSS($_GET['session']) : null;
  35. $objTemplate = new Template();
  36. $objTemplate->assign('session_name', $sessionName);
  37. $objTemplate->assign('user', api_get_user_info());
  38. $mailTemplate = $objTemplate->get_template('mail/subscribe_me_to_session.tpl');
  39. $emailDest = api_get_setting('emailAdministrator');
  40. $emailTitle = get_lang('SubscribeToSessionRequest');
  41. $emailText = $objTemplate->fetch($mailTemplate);
  42. break;
  43. default:
  44. $emailDest = Security::remove_XSS($_REQUEST['dest']);
  45. $emailTitle = Security::remove_XSS($_REQUEST['email_title']);
  46. $emailText = Security::remove_XSS($_REQUEST['email_text']);
  47. }
  48. $defaults = array(
  49. 'dest' => $emailDest,
  50. 'email_address' => $emailDest,
  51. 'email_title' => $emailTitle,
  52. 'email_text' => $emailText
  53. );
  54. $form->setDefaults($defaults);
  55. if ($form->validate()) {
  56. $text = Security::remove_XSS($_POST['email_text'])."\n\n---\n".get_lang('EmailSentFromLMS')." ".api_get_path(WEB_PATH);
  57. $email_administrator = Security::remove_XSS($_POST['dest']);
  58. $user_id = api_get_user_id();
  59. $title = Security::remove_XSS($_POST['email_title']);
  60. $content = Security::remove_XSS($_POST['email_text']);
  61. if (!empty($_user['mail'])) {
  62. api_mail_html(
  63. '',
  64. $email_administrator,
  65. $title,
  66. $text,
  67. api_get_person_name($_user['firstname'], $_user['lastname']),
  68. $_user['mail']
  69. );
  70. UserManager::send_message_in_outbox(
  71. $email_administrator,
  72. $user_id,
  73. $title,
  74. $content
  75. );
  76. } else {
  77. api_mail_html(
  78. '',
  79. $email_administrator,
  80. $title,
  81. $text,
  82. get_lang('Anonymous')
  83. );
  84. }
  85. $orig = $_SESSION['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();