outbox.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. $logInfo = [
  13. 'tool' => 'Messages',
  14. 'tool_id' => 0,
  15. 'tool_id_detail' => 0,
  16. 'action' => isset($_GET['action']) ? $_GET['action'] : 'outbox',
  17. 'action_details' => '',
  18. ];
  19. Event::registerLog($logInfo);
  20. $allowSocial = api_get_setting('allow_social_tool') == 'true';
  21. $allowMessage = api_get_setting('allow_message_tool') == 'true';
  22. if (isset($_GET['messages_page_nr'])) {
  23. if ($allowSocial && $allowMessage) {
  24. header('Location:outbox.php?pager='.intval($_GET['messages_page_nr']));
  25. exit;
  26. }
  27. }
  28. if ($allowSocial) {
  29. $this_section = SECTION_SOCIAL;
  30. $interbreadcrumb[] = [
  31. 'url' => api_get_path(WEB_PATH).'main/social/home.php',
  32. 'name' => get_lang('SocialNetwork'),
  33. ];
  34. } else {
  35. $this_section = SECTION_MYPROFILE;
  36. $interbreadcrumb[] = ['url' => api_get_path(WEB_PATH).'main/auth/profile.php', 'name' => get_lang('Profile')];
  37. }
  38. $interbreadcrumb[] = [
  39. 'url' => api_get_path(WEB_PATH).'main/messages/inbox.php',
  40. 'name' => get_lang('Messages'),
  41. ];
  42. $actions = '';
  43. if ($allowMessage) {
  44. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.
  45. Display::return_icon('message_new.png', get_lang('ComposeMessage')).'</a>';
  46. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.
  47. Display::return_icon('inbox.png', get_lang('Inbox')).'</a>';
  48. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.
  49. Display::return_icon('outbox.png', get_lang('Outbox')).'</a>';
  50. }
  51. $action = null;
  52. if (isset($_REQUEST['action'])) {
  53. $action = $_REQUEST['action'];
  54. }
  55. $keyword = '';
  56. $social_right_content = '';
  57. if ($allowSocial) {
  58. // Block Social Menu
  59. $social_menu_block = SocialManager::show_social_menu('messages');
  60. $actionsLeft = '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.
  61. Display::return_icon('back.png', get_lang('Back'), [], 32).'</a>';
  62. $form = MessageManager::getSearchForm(api_get_path(WEB_PATH).'main/messages/outbox.php');
  63. if ($form->validate()) {
  64. $values = $form->getSubmitValues();
  65. $keyword = $values['keyword'];
  66. }
  67. $actionsRight = $form->returnForm();
  68. $social_right_content .= Display::toolbarAction(
  69. 'toolbar',
  70. [$actionsLeft, $actionsRight]
  71. );
  72. }
  73. //MAIN CONTENT
  74. if ($action == 'delete') {
  75. $delete_list_id = [];
  76. if (isset($_POST['out'])) {
  77. $delete_list_id = $_POST['out'];
  78. }
  79. if (isset($_POST['id'])) {
  80. $delete_list_id = $_POST['id'];
  81. }
  82. for ($i = 0; $i < count($delete_list_id); $i++) {
  83. MessageManager::delete_message_by_user_sender(
  84. api_get_user_id(),
  85. $delete_list_id[$i]
  86. );
  87. }
  88. $delete_list_id = [];
  89. $social_right_content .= MessageManager::outbox_display($keyword);
  90. } elseif ($action == 'deleteone') {
  91. $delete_list_id = [];
  92. $id = Security::remove_XSS($_GET['id']);
  93. MessageManager::delete_message_by_user_sender(api_get_user_id(), $id);
  94. $delete_list_id = [];
  95. $social_right_content .= MessageManager::outbox_display($keyword);
  96. } else {
  97. $social_right_content .= MessageManager::outbox_display($keyword);
  98. }
  99. $tpl = new Template(get_lang('Outbox'));
  100. // Block Social Avatar
  101. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'messages');
  102. if ($allowSocial) {
  103. $tpl->assign('social_menu_block', $social_menu_block);
  104. $tpl->assign('social_right_content', $social_right_content);
  105. $social_layout = $tpl->get_template('social/inbox.tpl');
  106. $tpl->display($social_layout);
  107. } else {
  108. $content = $social_right_content;
  109. if ($actions) {
  110. $tpl->assign(
  111. 'actions',
  112. Display::toolbarAction('toolbar', [$actions])
  113. );
  114. }
  115. $tpl->assign('content', $content);
  116. $tpl->display_one_col_template();
  117. }