email_editor.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script contains the code to edit and send an e-mail to one of
  5. * the platform's users.
  6. * It can be called from the JavaScript library email_links.lib.php which
  7. * overtakes the mailto: links to use the internal interface instead.
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. * @author Julio Montoya <gugli100@gmail.com> Updating form with formvalidator
  10. */
  11. // name of the language file that needs to be included
  12. use ChamiloSession as Session;
  13. require_once '../inc/global.inc.php';
  14. if (empty($_user['user_id'])) {
  15. api_not_allowed(true);
  16. }
  17. if (empty($_SESSION['origin_url'])) {
  18. $origin_url = $_SERVER['HTTP_REFERER'];
  19. Session::write('origin_url', $origin_url);
  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'), array('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 = array(
  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. $_user['mail']
  70. );
  71. UserManager::send_message_in_outbox(
  72. $email_administrator,
  73. $user_id,
  74. $title,
  75. $content
  76. );
  77. } else {
  78. api_mail_html(
  79. '',
  80. $email_administrator,
  81. $title,
  82. $text,
  83. get_lang('Anonymous')
  84. );
  85. }
  86. $orig = $_SESSION['origin_url'];
  87. Session::erase('origin_url');
  88. header('location:'.$orig);
  89. exit;
  90. }
  91. Display::display_header(get_lang('SendEmail'));
  92. $form->display();
  93. Display::display_footer();