email_editor.php 3.0 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. */
  10. // name of the language file that needs to be included
  11. $language_file = "index";
  12. require_once '../inc/global.inc.php';
  13. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  14. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  15. if (empty($_user['user_id'])) {
  16. api_not_allowed(true);
  17. }
  18. //api_protect_course_script(); //not a course script, so no protection
  19. if (empty($_SESSION['origin_url'])) {
  20. $origin_url = $_SERVER['HTTP_REFERER'];
  21. api_session_register('origin_url');
  22. }
  23. /* Process the form and redirect to origin */
  24. if (!empty($_POST['submit_email']) && !empty($_POST['email_title']) && !empty($_POST['email_text'])) {
  25. $text = Security::remove_XSS($_POST['email_text'])."\n\n---\n".get_lang('EmailSentFromDokeos')." ".api_get_path(WEB_PATH);
  26. $email_administrator=Security::remove_XSS($_POST['dest']);
  27. $user_id=api_get_user_id();
  28. $title=Security::remove_XSS($_POST['email_title']);
  29. $content=Security::remove_XSS($_POST['email_text']);
  30. if (!empty($_user['mail'])) {
  31. api_mail('',$email_administrator,$title,$text,api_get_person_name($_user['firstname'],$_user['lastname']), $_user['mail']);
  32. UserManager::send_message_in_outbox ($email_administrator,$user_id,$title, $content);
  33. } else {
  34. api_mail('',$email_administrator,$title,$text,get_lang('Anonymous'));
  35. }
  36. $orig = $_SESSION['origin_url'];
  37. api_session_unregister('origin_url');
  38. header('location:'.$orig);
  39. }
  40. /* Header */
  41. Display::display_header(get_lang('SendEmail'));
  42. ?>
  43. <table border="0">
  44. <form action="" method="POST">
  45. <input type="hidden" name="dest" value="<?php echo Security::remove_XSS($_REQUEST['dest']);?>" />
  46. <tr>
  47. <td>
  48. <label for="email_address"><?php echo get_lang('EmailDestination');?></label>
  49. </td>
  50. <td>
  51. <span id="email_address"><?php echo Security::remove_XSS($_REQUEST['dest']); ?></span>
  52. </td>
  53. </tr>
  54. <tr>
  55. <td>
  56. <label for="email_title"><?php echo get_lang('EmailTitle');?></label>
  57. </td>
  58. <td>
  59. <input name="email_title" id="email_title" value="<?php echo Security::remove_XSS($_POST['email_title']);?>" size="60"></input>
  60. </td>
  61. </tr>
  62. <tr>
  63. <td valign="top">
  64. <label for="email_text"><?php echo get_lang('EmailText');?></label>
  65. </td>
  66. <td>
  67. <?php
  68. echo '<textarea id="email_text" name="email_text" rows="10" cols="80">'.Security::remove_XSS($_POST['email_text']).'</textarea>';
  69. //htmlarea is not used otherwise we have to deal with HTML e-mail and all the related probs
  70. //api_disp_html_area('email_text',$_POST['email_text'],'250px');
  71. ?>
  72. </td>
  73. </tr>
  74. <tr>
  75. <td colspan="2">
  76. <button class="save" type="submit" name="submit_email" value="<?php echo get_lang('SendMail');?>"><?php echo get_lang('SendMail');?></button>
  77. </td>
  78. </tr>
  79. </form>
  80. </table>
  81. <?php
  82. /* Footer */
  83. Display::display_footer();
  84. ?>