email_editor.inc.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if (empty($_user['user_id'])) {
  16. api_not_allowed(true);
  17. }
  18. if (empty($_SESSION['origin_url'])) {
  19. $origin_url = $_SERVER['HTTP_REFERER'];
  20. Session::write('origin_url',$origin_url);
  21. }
  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'), array('class' => 'span5'));
  26. $form->freeze('email_address');
  27. $form->addElement('textarea', 'email_text', get_lang('EmailText'), array('class' => 'span5', '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->addElement('button', 'submit', get_lang('SendMail'));
  33. $defaults = array(
  34. 'dest' => Security::remove_XSS($_REQUEST['dest']),
  35. 'email_address' => Security::remove_XSS($_REQUEST['dest']),
  36. 'email_title' => Security::remove_XSS($_POST['email_title']),
  37. 'email_text' => Security::remove_XSS($_POST['email_text'])
  38. );
  39. $form->setDefaults($defaults);
  40. if ($form->validate()) {
  41. $text = Security::remove_XSS($_POST['email_text'])."\n\n---\n".get_lang('EmailSentFromDokeos')." ".api_get_path(WEB_PATH);
  42. $email_administrator=Security::remove_XSS($_POST['dest']);
  43. $user_id=api_get_user_id();
  44. $title=Security::remove_XSS($_POST['email_title']);
  45. $content=Security::remove_XSS($_POST['email_text']);
  46. if (!empty($_user['mail'])) {
  47. api_mail_html('',$email_administrator,$title,$text,api_get_person_name($_user['firstname'],$_user['lastname']), $_user['mail']);
  48. UserManager::send_message_in_outbox ($email_administrator,$user_id,$title, $content);
  49. } else {
  50. api_mail_html('',$email_administrator,$title,$text,get_lang('Anonymous'));
  51. }
  52. $orig = $_SESSION['origin_url'];
  53. Session::erase('origin_url');
  54. header('location:'.$orig);
  55. exit;
  56. }
  57. Display::display_header(get_lang('SendEmail'));
  58. $form->display();
  59. Display::display_footer();