email_editor.php 3.5 KB

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