message_for_group_form.inc.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Form for group message.
  5. *
  6. * @package chamilo.social
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') != 'true') {
  12. api_not_allowed();
  13. }
  14. $tok = Security::get_token();
  15. if (isset($_REQUEST['user_friend'])) {
  16. $info_user_friend = [];
  17. $info_path_friend = [];
  18. $userfriend_id = intval($_REQUEST['user_friend']);
  19. $info_user_friend = api_get_user_info($userfriend_id);
  20. $info_path_friend = UserManager::get_user_picture_path_by_id($userfriend_id, 'web');
  21. }
  22. $group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null;
  23. $message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null;
  24. $actions = ['add_message_group', 'edit_message_group', 'reply_message_group'];
  25. $allowed_action = isset($_GET['action']) && in_array($_GET['action'], $actions) ? Security::remove_XSS($_GET['action']) : '';
  26. $to_group = '';
  27. $subject = '';
  28. $message = '';
  29. $usergroup = new UserGroup();
  30. if (!empty($group_id) && $allowed_action) {
  31. $group_info = $usergroup->get($group_id);
  32. $is_member = $usergroup->is_group_member($group_id);
  33. if ($group_info['visibility'] == GROUP_PERMISSION_CLOSED && !$is_member) {
  34. api_not_allowed(true);
  35. }
  36. $to_group = $group_info['name'];
  37. if (!empty($message_id)) {
  38. $message_info = MessageManager::get_message_by_id($message_id);
  39. if ($allowed_action == 'reply_message_group') {
  40. $subject = get_lang('Reply').': '.api_xml_http_response_encode($message_info['title']);
  41. } else {
  42. $subject = api_xml_http_response_encode($message_info['title']);
  43. $message = api_xml_http_response_encode($message_info['content']);
  44. }
  45. }
  46. }
  47. $page_item = !empty($_GET['topics_page_nr']) ? intval($_GET['topics_page_nr']) : 1;
  48. $param_item_page = isset($_GET['items_page_nr']) && isset($_GET['topic_id']) ? ('&items_'.intval($_GET['topic_id']).'_page_nr='.(!empty($_GET['topics_page_nr']) ? intval($_GET['topics_page_nr']) : 1)) : '';
  49. if (isset($_GET['topic_id'])) {
  50. $param_item_page .= '&topic_id='.intval($_GET['topic_id']);
  51. }
  52. $page_topic = isset($_GET['topics_page_nr']) ? intval($_GET['topics_page_nr']) : 1;
  53. $anchor_topic = isset($_GET['anchor_topic']) ? Security::remove_XSS($_GET['anchor_topic']) : null;
  54. $url = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$group_id.'&anchor_topic='.$anchor_topic.'&topics_page_nr='.$page_topic.$param_item_page;
  55. $form = new FormValidator(
  56. 'form',
  57. 'post',
  58. $url,
  59. null,
  60. ['enctype' => 'multipart/form-data']
  61. );
  62. $form->addHidden('action', $allowed_action);
  63. $form->addHidden('group_id', $group_id);
  64. $form->addHidden('parent_id', $message_id);
  65. $form->addHidden('message_id', $message_id);
  66. $form->addHidden('token', $tok);
  67. $tpl = new Template(get_lang('Groups'));
  68. if (api_get_setting('allow_message_tool') === 'true') {
  69. // Normal message
  70. $user_info = api_get_user_info($userfriend_id);
  71. $height = 180;
  72. if ($allowed_action === 'add_message_group') {
  73. $form->addElement('text', 'title', get_lang('Title'));
  74. $height = 140;
  75. }
  76. $config = ['ToolbarSet' => 'Messages'];
  77. $form->addHtmlEditor('content', get_lang('Message'), true, false, $config);
  78. $form->addElement(
  79. 'label',
  80. get_lang('AttachmentFiles'),
  81. '<div id="link-more-attach">
  82. <a class="btn btn-default" href="javascript://" onclick="return add_image_form()">
  83. '.get_lang('AddOneMoreFile').'
  84. </a>
  85. </div>'
  86. );
  87. $form->addElement('label', null, '<div id="filepaths"></div>');
  88. $form->addElement(
  89. 'file',
  90. 'attach_1',
  91. sprintf(
  92. get_lang('MaximunFileSizeX'),
  93. format_file_size(api_get_setting('message_max_upload_filesize'))
  94. )
  95. );
  96. $form->addButtonSend(get_lang('SendMessage'));
  97. $form->setDefaults(['content' => $message, 'title' => $subject]);
  98. $tpl->assign('content', $form->returnForm());
  99. }
  100. $tpl->displayBlankTemplateNoHeader();