message_for_group_form.inc.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. 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('form', 'post', $url, null, array('enctype' => 'multipart/form-data'));
  55. $form->addElement('hidden', 'action', $allowed_action);
  56. $form->addElement('hidden', 'group_id', $group_id);
  57. $form->addElement('hidden', 'parent_id', $message_id);
  58. $form->addElement('hidden', 'message_id', $message_id);
  59. $form->addElement('hidden', 'token', $tok);
  60. $tpl = new Template(get_lang('Groups'));
  61. if (api_get_setting('allow_message_tool')=='true') {
  62. // Normal message
  63. $user_info = api_get_user_info($userfriend_id);
  64. $height = 180;
  65. if ($allowed_action == 'add_message_group') {
  66. $form->addElement('text', 'title', get_lang('Title'));
  67. $height = 140;
  68. }
  69. $config = ['ToolbarSet' => 'Messages'];
  70. $form->addHtmlEditor('content', get_lang('Message'), true, false, $config);
  71. $form->addElement('label', null, get_lang('AttachmentFiles'));
  72. $form->addElement('label', null, '<div id="link-more-attach">
  73. <a class="btn btn-default" href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>'
  74. );
  75. $form->addElement('html', '<span id="filepaths"></span>');
  76. $form->addElement('file', 'attach_1', sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))));
  77. $form->addElement('html', '</div>');
  78. $form->addButtonSend(get_lang('SendMessage'));
  79. $form->setDefaults(['content' => $message, 'title' => $subject]);
  80. $form->display();
  81. }
  82. $tpl->display_blank_template();