outbox.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.messages
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. api_block_anonymous_users();
  9. if (api_get_setting('allow_message_tool') != 'true') {
  10. api_not_allowed(true);
  11. }
  12. $allowSocial = api_get_setting('allow_social_tool') == 'true';
  13. $allowMessage = api_get_setting('allow_message_tool') == 'true';
  14. if (isset($_GET['messages_page_nr'])) {
  15. if ($allowSocial && $allowMessage) {
  16. header('Location:outbox.php?pager='.intval($_GET['messages_page_nr']));
  17. exit;
  18. }
  19. }
  20. if ($allowSocial) {
  21. $this_section = SECTION_SOCIAL;
  22. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'main/social/home.php', 'name' => get_lang('Social'));
  23. } else {
  24. $this_section = SECTION_MYPROFILE;
  25. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'main/auth/profile.php', 'name' => get_lang('Profile'));
  26. }
  27. $interbreadcrumb[] = array(
  28. 'url' => api_get_path(WEB_PATH).'main/messages/inbox.php',
  29. 'name' => get_lang('Messages')
  30. );
  31. $actions = '';
  32. if ($allowSocial && $allowMessage) {
  33. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.
  34. Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).'</a>';
  35. }
  36. if ($allowMessage) {
  37. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.
  38. Display::return_icon('message_new.png', get_lang('ComposeMessage')).'</a>';
  39. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.
  40. Display::return_icon('inbox.png', get_lang('Inbox')).'</a>';
  41. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.
  42. Display::return_icon('outbox.png', get_lang('Outbox')).'</a>';
  43. }
  44. $info_delete_outbox = array();
  45. $info_delete_outbox = isset($_GET['form_delete_outbox']) ? explode(',', $_GET['form_delete_outbox']) : '';
  46. $count_delete_outbox = count($info_delete_outbox) - 1;
  47. if (isset($info_delete_outbox[0]) && trim($info_delete_outbox[0]) == 'delete') {
  48. for ($i = 1; $i <= $count_delete_outbox; $i++) {
  49. MessageManager::delete_message_by_user_sender(api_get_user_id(), $info_delete_outbox[$i]);
  50. }
  51. $message_box = get_lang('SelectedMessagesDeleted').
  52. '&nbsp
  53. <br><a href="../social/index.php?#remote-tab-3">'.
  54. get_lang('BackToOutbox').
  55. '</a>';
  56. Display::addFlash(
  57. Display::return_message(
  58. api_xml_http_response_encode($message_box),
  59. 'normal',
  60. false
  61. )
  62. );
  63. exit;
  64. }
  65. $action = null;
  66. if (isset($_REQUEST['action'])) {
  67. $action = $_REQUEST['action'];
  68. }
  69. $keyword = '';
  70. $social_right_content = '';
  71. if ($allowSocial) {
  72. // Block Social Menu
  73. $social_menu_block = SocialManager::show_social_menu('messages');
  74. $actionsLeft = '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php?f=social">'.
  75. Display::return_icon('back.png', get_lang('Back'), array(), 32).'</a>';
  76. $form = MessageManager::getSearchForm(api_get_path(WEB_PATH).'main/messages/outbox.php');
  77. if ($form->validate()) {
  78. $values = $form->getSubmitValues();
  79. $keyword = $values['keyword'];
  80. }
  81. $actionsRight = $form->returnForm();
  82. $social_right_content .= Display::toolbarAction(
  83. 'toolbar',
  84. [$actionsLeft, $actionsRight]
  85. );
  86. }
  87. //MAIN CONTENT
  88. if ($action == 'delete') {
  89. $delete_list_id = array();
  90. if (isset($_POST['out'])) {
  91. $delete_list_id = $_POST['out'];
  92. }
  93. if (isset($_POST['id'])) {
  94. $delete_list_id = $_POST['id'];
  95. }
  96. for ($i = 0; $i < count($delete_list_id); $i++) {
  97. MessageManager::delete_message_by_user_sender(
  98. api_get_user_id(),
  99. $delete_list_id[$i]
  100. );
  101. }
  102. $delete_list_id = array();
  103. $social_right_content .= MessageManager::outbox_display($keyword);
  104. } elseif ($action == 'deleteone') {
  105. $delete_list_id = array();
  106. $id = Security::remove_XSS($_GET['id']);
  107. MessageManager::delete_message_by_user_sender(api_get_user_id(), $id);
  108. $delete_list_id = array();
  109. $social_right_content .= MessageManager::outbox_display($keyword);
  110. } else {
  111. $social_right_content .= MessageManager::outbox_display($keyword);
  112. }
  113. $tpl = new Template(get_lang('Outbox'));
  114. // Block Social Avatar
  115. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'messages');
  116. if ($allowSocial) {
  117. $tpl->assign('social_menu_block', $social_menu_block);
  118. $tpl->assign('social_right_content', $social_right_content);
  119. $social_layout = $tpl->get_template('social/inbox.tpl');
  120. $tpl->display($social_layout);
  121. } else {
  122. $content = $social_right_content;
  123. if ($actions) {
  124. $tpl->assign(
  125. 'actions',
  126. Display::toolbarAction('toolbar', [$actions])
  127. );
  128. }
  129. $tpl->assign('content', $content);
  130. $tpl->display_one_col_template();
  131. }