send_message.php 4.3 KB

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