123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- /* For licensing terms, see /license.txt */
- use Chamilo\CoreBundle\Framework\Container;
- /**
- * @package chamilo.messages
- */
- $cidReset = true;
- api_block_anonymous_users();
- if (isset($_GET['messages_page_nr'])) {
- $social_link = '';
- if ($_REQUEST['f'] == 'social') {
- $social_link = '?f=social';
- }
- if (api_get_setting('social.allow_social_tool') == 'true' &&
- api_get_setting('message.allow_message_tool') == 'true'
- ) {
- header('Location:inbox.php'.$social_link);
- exit;
- }
- }
- if (api_get_setting('message.allow_message_tool') != 'true') {
- api_not_allowed();
- }
- $htmlHeadXtra[] = '<script>
- function show_icon_edit(element_html) {
- ident="#edit_image";
- $(ident).show();
- }
- function hide_icon_edit(element_html) {
- ident="#edit_image";
- $(ident).hide();
- }
- </script>';
- /*
- MAIN CODE
- */
- $nameTools = get_lang('Messages');
- $request = api_is_xml_http_request();
- if (isset($_GET['form_reply']) || isset($_GET['form_delete'])) {
- $info_reply = array();
- $info_delete = array();
- if (isset($_GET['form_reply'])) {
- //allow to insert messages
- $info_reply = explode(base64_encode('&%ff..x'), $_GET['form_reply']);
- $count_reply = count($info_reply);
- $button_sent = urldecode($info_reply[4]);
- }
- if (isset($_GET['form_delete'])) {
- //allow to delete messages
- $info_delete = explode(',', $_GET['form_delete']);
- $count_delete = (count($info_delete) - 1);
- }
- if (isset($button_sent)) {
- $title = urldecode($info_reply[0]);
- $content = str_replace("\\", "", urldecode($info_reply[1]));
- $user_reply = $info_reply[2];
- $user_email_base = str_replace(')', '(', $info_reply[5]);
- $user_email_prepare = explode('(', $user_email_base);
- if (count($user_email_prepare) == 1) {
- $user_email = trim($user_email_prepare[0]);
- } elseif (count($user_email_prepare) == 3) {
- $user_email = trim($user_email_prepare[1]);
- }
- $user_id_by_email = MessageManager::get_user_id_by_email($user_email);
- if ($info_reply[6] == 'save_form') {
- $user_id_by_email = $info_reply[2];
- }
- if (isset($user_reply) && !is_null($user_id_by_email) && strlen($info_reply[0]) > 0) {
- MessageManager::send_message($user_id_by_email, $title, $content);
- Display::addFlash(
- MessageManager::return_message($user_id_by_email, 'confirmation')
- );
- $social_right_content .= MessageManager::inbox_display();
- exit;
- } elseif (is_null($user_id_by_email)) {
- $message_box = get_lang('ErrorSendingMessage');
- Display::return_message(api_xml_http_response_encode($message_box), 'error');
- $social_right_content .= MessageManager::inbox_display();
- exit;
- }
- } elseif (trim($info_delete[0]) == 'delete') {
- for ($i = 1; $i <= $count_delete; $i++) {
- MessageManager::delete_message_by_user_receiver(api_get_user_id(), $info_delete[$i]);
- }
- $message_box = get_lang('SelectedMessagesDeleted');
- Display::return_message(api_xml_http_response_encode($message_box));
- $social_right_content .= MessageManager::inbox_display();
- exit;
- }
- }
- if (isset($_GET['f']) && $_GET['f'] == 'social') {
- $this_section = SECTION_SOCIAL;
- $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'main/social/home.php', 'name' => get_lang('SocialNetwork'));
- $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Inbox'));
- } else {
- $this_section = SECTION_MYPROFILE;
- $interbreadcrumb[] = array(
- 'url' => Container::getRouter()->generate('fos_user_profile_edit'),
- 'name' => get_lang('Profile'),
- );
- }
- $social_parameter = '';
- if (isset($_GET['f']) && $_GET['f'] == 'social' && api_get_setting('social.allow_social_tool') == 'true') {
- $social_parameter = '?f=social';
- } else {
- $actions = null;
- //Comes from normal profile
- if (api_get_setting('social.allow_social_tool') == 'true' &&
- api_get_setting('message.allow_message_tool') == 'true'
- ) {
- $actions .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.
- Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).'</a>';
- }
- if (api_get_setting('message.allow_message_tool') == 'true') {
- $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.
- Display::return_icon('message_new.png', get_lang('ComposeMessage')).'</a>';
- $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.
- Display::return_icon('inbox.png', get_lang('Inbox')).'</a>';
- $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.
- Display::return_icon('outbox.png', get_lang('Outbox')).'</a>';
- }
- }
- //LEFT CONTENT
- if (api_get_setting('social.allow_social_tool') == 'true') {
- //Block Social Menu
- $social_menu_block = SocialManager::show_social_menu('messages');
- }
- //Right content
- $social_right_content = null;
- $keyword = '';
- if (api_get_setting('social.allow_social_tool') == 'true') {
- $actionsLeft = '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php?f=social">'.
- Display::return_icon('new-message.png', get_lang('ComposeMessage'), array(), 32).'</a>';
- $actionsLeft .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php?f=social">'.
- Display::return_icon('outbox.png', get_lang('Outbox'), array(), 32).'</a>';
- $form = MessageManager::getSearchForm(api_get_path(WEB_PATH).'main/messages/inbox.php');
- if ($form->validate()) {
- $values = $form->getSubmitValues();
- $keyword = $values['keyword'];
- }
- $actionsRight = $form->returnForm();
- $social_right_content .= Display::toolbarAction('toolbar', [$actionsLeft, $actionsRight]);
- }
- //MAIN CONTENT
- if (!isset($_GET['del_msg'])) {
- $social_right_content .= MessageManager::inbox_display();
- } else {
- $num_msg = intval($_POST['total']);
- for ($i = 0; $i < $num_msg; $i++) {
- if ($_POST[$i]) {
- //the user_id was necesarry to delete a message??
- Display::addFlash(
- MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_POST['_'.$i])
- );
- }
- }
- $social_right_content .= MessageManager::inbox_display();
- }
- if (api_get_setting('social.allow_social_tool') == 'true') {
- $social_right_content .= '</div>';
- }
- $tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
- // Block Social Avatar
- SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'messages');
- if (api_get_setting('social.allow_social_tool') == 'true') {
- $tpl->addGlobal('social_menu_block', $social_menu_block);
- $tpl->addGlobal('social_right_content', $social_right_content);
- echo $tpl->render('@template_style/social/inbox.html.twig');
- } else {
- $content = $social_right_content;
- echo $actions;
- echo $content;
- }
|