send_message.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.messages
  5. */
  6. $language_file = array('registration','messages','userInfo','admin');
  7. $cidReset=true;
  8. require_once '../inc/global.inc.php';
  9. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  10. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  11. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  12. if (api_is_anonymous()) {
  13. api_not_allowed();
  14. }
  15. $user_id = intval($_POST['user_id']);
  16. $panel_id = intval($_POST['panel_id']);
  17. $content_message = ($_POST['txt_content']); //check this is filtered on output
  18. $subject_message = ($_POST['txt_subject']); //check this is filtered on output
  19. $user_info = array();
  20. $user_info = api_get_user_info($user_id);
  21. if ($panel_id == 2 || $panel_id == 4 ) {
  22. if (empty($content_message)) {
  23. ?>
  24. <div id="display_response_id" style="height:200px;">
  25. <?php echo api_xml_http_response_encode(get_lang('AddPersonalMessage')); ?> :<br /><br />
  26. <textarea id="txt_area_invite" rows="5" cols="40"></textarea><br />
  27. <?php echo api_xml_http_response_encode(get_lang('YouShouldWriteAMessage')); ?><br /><br />
  28. <button class="save" type="button" value="<?php echo api_xml_http_response_encode(get_lang('SocialAddToFriends')); ?>" onclick="action_database_panel('4','<?php echo $user_id;?>')" >
  29. <?php echo api_xml_http_response_encode(get_lang('SendInvitation')) ?></button>
  30. </div>
  31. <?php
  32. }
  33. } elseif ($panel_id==1) {
  34. if (empty($content_message) || empty($subject_message)) {
  35. ?>
  36. <td height="20"><?php echo api_xml_http_response_encode(get_lang('To')); ?> &nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;<?php echo api_xml_http_response_encode(api_get_person_name($user_info['firstName'], $user_info['lastName'])); ?></td>
  37. <td height="20"><?php echo api_xml_http_response_encode(get_lang('Subject')); ?> :<br/><input id="txt_subject_id" type="text" style="width:200px;"></td>
  38. <td height="20"><?php echo api_xml_http_response_encode(get_lang('Message')); ?> :<br/><textarea id="txt_area_invite" rows="3" cols="25"></textarea></td>
  39. <td height="20"><input type="button" value="<?php echo api_xml_http_response_encode(get_lang('NewMessage')); ?>" onclick="hide_display_message()" />&nbsp;&nbsp;&nbsp; <input type="button" value="<?php echo api_xml_http_response_encode(get_lang('SendMessage')); ?>" onclick="action_database_panel('5','<?php echo $user_id;?>')" /></td>
  40. <?php
  41. }
  42. }elseif ($panel_id==3) {
  43. ?>
  44. <dl>
  45. <dd><a href="javascript:void(0)" onclick="change_panel('2','<?php echo $user_id; ?>')"><?php echo api_xml_http_response_encode(get_lang('SendInviteMessage')); ?></a></dd>
  46. <dd><a href="javascript:void(0)" onclick="change_panel('1','<?php echo $user_id; ?>')"><?php echo api_xml_http_response_encode(get_lang('SendMessage'));?></a></dd>
  47. </dl>
  48. <?php
  49. }elseif($panel_id == 5 && empty($subject_message)) {
  50. ?>
  51. <div id="display_response_id" style="height:200px;">
  52. <?php echo api_xml_http_response_encode(get_lang('To')); ?> :&nbsp;&nbsp;&nbsp;&nbsp;<?php echo api_xml_http_response_encode(api_get_person_name($user_info['firstName'], $user_info['lastName'])); ?>
  53. <br />
  54. <br /><span style="color:red">*</span><?php echo api_xml_http_response_encode(get_lang('Subject')); ?> :<br /><input id="txt_subject_id" type="text" style="width:300px;"><br/>
  55. <br /><?php echo api_xml_http_response_encode(get_lang('Message')); ?> :<br /><textarea id="txt_area_invite" rows="3" cols="40"></textarea>
  56. <?php echo Display::display_error_message(api_xml_http_response_encode(get_lang('YouShouldWriteASubject'))); ?>
  57. <button class="save" type="button" value="<?php echo api_xml_http_response_encode(get_lang('SendMessage')); ?>" onclick="action_database_panel('5','<?php echo $user_id;?>')">
  58. <?php echo api_xml_http_response_encode(get_lang('SendMessage')) ?></button>
  59. </div>
  60. <?php
  61. }
  62. //here we decode to utf8 because this page is called from an ajax popup
  63. $subject_message = api_utf8_decode($subject_message);
  64. $content_message = api_utf8_decode($content_message);
  65. if ($panel_id==4 && !empty($content_message)) {
  66. if ($subject_message=='clear') {
  67. $subject_message=null;
  68. }
  69. SocialManager::send_invitation_friend_user($user_id,$subject_message,$content_message);
  70. } elseif ($panel_id==5 && !empty($subject_message) ) {
  71. SocialManager::send_invitation_friend_user($user_id,$subject_message,$content_message);
  72. }
  73. ?>