message_for_group_form.inc.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 '../inc/global.inc.php';
  9. \Chamilo\CoreBundle\Framework\Container::$legacyTemplate = 'layout_one_col_no_content.html.twig';
  10. api_block_anonymous_users();
  11. if (api_get_setting('social.allow_social_tool') != 'true') {
  12. api_not_allowed();
  13. }
  14. $tok = Security::get_token();
  15. if (isset($_REQUEST['user_friend'])) {
  16. $info_user_friend=array();
  17. $info_path_friend=array();
  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 = array('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. array('enctype' => 'multipart/form-data')
  61. );
  62. $form->addElement('hidden', 'action', $allowed_action);
  63. $form->addElement('hidden', 'group_id', $group_id);
  64. $form->addElement('hidden', 'parent_id', $message_id);
  65. $form->addElement('hidden', 'message_id', $message_id);
  66. $form->addElement('hidden', 'token', $tok);
  67. if (api_get_setting('message.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(
  94. api_get_setting('message.message_max_upload_filesize')
  95. )
  96. )
  97. );
  98. $form->addButtonSend(get_lang('SendMessage'));
  99. $form->setDefaults(['content' => $message, 'title' => $subject]);
  100. $form->display();
  101. }