1<?php 2/** 3 * @package tikiwiki 4 */ 5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 6// 7// All Rights Reserved. See copyright.txt for details and a complete list of authors. 8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 9// $Id$ 10 11$section = 'user_messages'; 12require_once('tiki-setup.php'); 13$messulib = TikiLib::lib('message'); 14$access->check_user($user); 15$access->check_feature('feature_messages'); 16$access->check_permission('tiki_p_messages'); 17$maxRecords = $messulib->get_user_preference($user, 'maxRecords', 20); 18 19// Delete messages if the delete button was pressed 20if (isset($_POST["delete"])) { 21 if (isset($_POST["msg"]) && $access->checkCsrfForm(tra('Delete selected messages?'))) { 22 $i = 0; 23 foreach (array_keys($_POST["msg"]) as $msg) { 24 $result = $messulib->delete_message($user, $msg, 'sent'); 25 $i = $i + $result->numRows(); 26 } 27 if ($i) { 28 $msg = $i === 1 ? tr('%0 sent message was deleted', $i) : tr('%0 sent messages were deleted', $i); 29 Feedback::success($msg); 30 } else { 31 Feedback::error(tra('No messages were deleted')); 32 } 33 } elseif (!isset($_POST["msg"])) { 34 Feedback::error(tra('No messages were selected to delete')); 35 }} 36// Archive messages if the archive button was pressed 37if (isset($_POST["archive"])) { 38 if (isset($_POST["msg"]) && $access->checkCsrf()) { 39 $tmp = $messulib->count_messages($user, 'archive'); 40 $i = 0; 41 foreach (array_keys($_POST["msg"]) as $msg) { 42 if (($prefs['messu_archive_size'] > 0) && ($tmp + $i >= $prefs['messu_archive_size'])) { 43 $smarty->assign('msg', tra("Archive is full. Delete some messages from archive first.")); 44 $smarty->display("error.tpl"); 45 die; 46 } 47 $result = $messulib->archive_message($user, $msg, 'sent'); 48 $i = $i + $result->numRows(); 49 } 50 if ($i) { 51 $msg = $i === 1 ? tr('%0 message was archived', $i) : tr('%0 messages were archived', $i); 52 Feedback::success($msg); 53 } else { 54 Feedback::error(tra('No messages were archived')); 55 } 56 } elseif (!isset($_POST["msg"])) { 57 Feedback::error(tra('No messages were selected to archive')); 58 } 59} 60 61// Download messages if the download button was pressed 62if (isset($_REQUEST["download"])) { 63 // if message ids are handed over, use them: 64 if (isset($_REQUEST["msg"])) { 65 foreach (array_keys($_REQUEST["msg"]) as $msg) { 66 $tmp = $messulib->get_message($user, $msg, 'sent'); 67 $items[] = $tmp; 68 } 69 } else { 70 $items = $messulib->get_messages($user, 'sent', '', '', ''); 71 } 72 $smarty->assign_by_ref('items', $items); 73 header("Content-Disposition: attachment; filename=tiki-msg-sent-" . time() . ".txt "); 74 $smarty->display('messu-download.tpl', null, null, null, 'application/download'); 75 die; 76} 77 78if (isset($_REQUEST['filter'])) { 79 if ($_REQUEST['flags'] != '') { 80 $parts = explode('_', $_REQUEST['flags']); 81 $_REQUEST['flag'] = $parts[0]; 82 $_REQUEST['flagval'] = $parts[1]; 83 } 84} 85if (! isset($_REQUEST["priority"])) { 86 $_REQUEST["priority"] = ''; 87} 88if (! isset($_REQUEST["flag"])) { 89 $_REQUEST["flag"] = ''; 90} 91if (! isset($_REQUEST["flagval"])) { 92 $_REQUEST["flagval"] = ''; 93} else { 94 $_REQUEST["flagval"] = $_REQUEST["flagval"] === 'y' ? 'y' : 'n'; 95} 96if (! isset($_REQUEST["sort_mode"])) { 97 $sort_mode = 'date_desc'; 98} else { 99 $sort_mode = $_REQUEST["sort_mode"]; 100} 101if (! isset($_REQUEST["offset"])) { 102 $offset = 0; 103} else { 104 $offset = $_REQUEST["offset"]; 105} 106if (isset($_REQUEST["find"])) { 107 $find = $_REQUEST["find"]; 108} else { 109 $find = ''; 110} 111$smarty->assign_by_ref('flag', $_REQUEST['flag']); 112$smarty->assign_by_ref('priority', $_REQUEST['priority']); 113$smarty->assign_by_ref('flagval', $_REQUEST['flagval']); 114$smarty->assign_by_ref('offset', $offset); 115$smarty->assign_by_ref('sort_mode', $sort_mode); 116$smarty->assign('find', $find); 117// What are we paginating: items 118$items = $messulib->list_user_messages($user, $offset, $maxRecords, $sort_mode, $find, $_REQUEST["flag"], $_REQUEST["flagval"], $_REQUEST['priority'], 'sent'); 119$smarty->assign_by_ref('cant_pages', $items["cant"]); 120$smarty->assign_by_ref('items', $items["data"]); 121$cellsize = 200; 122$percentage = 1; 123if ($prefs['messu_sent_size'] > 0) { 124 $current_number = $messulib->count_messages($user, 'sent'); 125 $smarty->assign('messu_sent_number', $current_number); 126 $smarty->assign('messu_sent_size', $prefs['messu_sent_size']); 127 $percentage = ($current_number / $prefs['messu_sent_size']) * 100; 128 $cellsize = round($percentage / 100 * 200); 129 if ($current_number > $prefs['messu_sent_size']) { 130 $cellsize = 200; 131 } 132 if ($cellsize < 1) { 133 $cellsize = 1; 134 } 135 $percentage = round($percentage); 136} 137$smarty->assign('cellsize', $cellsize); 138$smarty->assign('percentage', $percentage); 139include_once('tiki-section_options.php'); 140include_once('tiki-mytiki_shared.php'); 141$smarty->assign('mid', 'messu-sent.tpl'); 142$smarty->display("tiki.tpl"); 143