message_for_group_form.inc.php 4.1 KB

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