email_editor.php 3.5 KB

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