messu-mailbox.php 5.05 KB
Newer Older
lrargerich's avatar
lrargerich committed
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
3
// 
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6
// $Id$
changi67's avatar
changi67 committed
7

8
$section = 'user_messages';
9 10
require_once ('tiki-setup.php');
include_once ('lib/messu/messulib.php');
11 12
$access->check_user($user);
$access->check_feature('feature_messages');
13
$access->check_permission('tiki_p_messages');
14 15 16 17
$maxRecords = $messulib->get_user_preference($user, 'mess_maxRecords', 20);
// auto-archiving of read mails?
$mess_archiveAfter = $messulib->get_user_preference($user, 'mess_archiveAfter', 0);
$smarty->assign_by_ref('mess_archiveAfter', $mess_archiveAfter);
changi67's avatar
changi67 committed
18
if ($mess_archiveAfter > 0) {
19 20 21 22 23 24 25
	// get date of last check. if not set yet, set it to 'before 10 minutes'
	$mess_archiveLast = $messulib->get_user_preference($user, 'mess_archiveLast', $tikilib->now - 600);
	// only run auto-archive job every 10 minutes:
	if ($tikilib->now - $mess_archiveLast >= 600) {
		$messulib->set_user_preference($user, 'mess_archiveLast', $tikilib->now);
		$messulib->archive_messages($user, $mess_archiveAfter);
	}
changi67's avatar
changi67 committed
26
}
lrargerich's avatar
lrargerich committed
27
// Mark messages if the mark button was pressed
28
if (isset($_REQUEST["mark"]) && isset($_REQUEST["msg"])) {
29 30 31 32
	foreach(array_keys($_REQUEST["msg"]) as $msg) {
		$parts = explode('_', $_REQUEST['action']);
		$messulib->flag_message($user, $msg, $parts[0], $parts[1]);
	}
lrargerich's avatar
lrargerich committed
33 34
}
// Delete messages if the delete button was pressed
35
if (isset($_REQUEST["delete"]) && isset($_REQUEST["msg"])) {
36 37 38 39
	check_ticket('messu-mailbox');
	foreach(array_keys($_REQUEST["msg"]) as $msg) {
		$messulib->delete_message($user, $msg);
	}
lrargerich's avatar
lrargerich committed
40
}
41 42
// Archive messages if the archive button was pressed
if (isset($_REQUEST["archive"]) && isset($_REQUEST["msg"])) {
43 44 45 46 47 48 49 50 51 52 53
	check_ticket('messu-mailbox');
	$tmp = $messulib->count_messages($user, 'archive');
	foreach(array_keys($_REQUEST["msg"]) as $msg) {
		if (($prefs['messu_archive_size'] > 0) && ($tmp >= $prefs['messu_archive_size'])) {
			$smarty->assign('msg', tra("Archive is full. Delete some messages from archive first."));
			$smarty->display("error.tpl");
			die;
		}
		$messulib->archive_message($user, $msg);
		$tmp++;
	}
changi67's avatar
changi67 committed
54
}
55 56
// Download messages if the download button was pressed
if (isset($_REQUEST["download"])) {
57 58 59 60 61 62 63 64 65 66 67 68 69 70
	check_ticket('messu-mailbox');
	// if message ids are handed over, use them:
	if (isset($_REQUEST["msg"])) {
		foreach(array_keys($_REQUEST["msg"]) as $msg) {
			$tmp = $messulib->get_message($user, $msg, 'messages');
			$items[] = $tmp;
		}
	} else {
		$items = $messulib->get_messages($user, 'messages', '', '', '');
	}
	$smarty->assign_by_ref('items', $items);
	header("Content-Disposition: attachment; filename=tiki-msg-mailbox-" . time("U") . ".txt ");
	$smarty->display('messu-download.tpl', null, null, 'application/download');
	die;
changi67's avatar
changi67 committed
71
}
72
if (isset($_REQUEST['filter'])) {
73 74 75 76 77
	if ($_REQUEST['flags'] != '') {
		$parts = explode('_', $_REQUEST['flags']);
		$_REQUEST['flag'] = $parts[0];
		$_REQUEST['flagval'] = $parts[1];
	}
changi67's avatar
changi67 committed
78 79 80
}
$orig_or_reply = "r";
if (!isset($_REQUEST["replyto"])) $_REQUEST["replyto"] = '';
81
if (isset($_REQUEST["origto"])) {
82 83
	$_REQUEST["replyto"] = $_REQUEST["origto"];
	$orig_or_reply = "o";
changi67's avatar
changi67 committed
84 85 86 87
}
if (!isset($_REQUEST["priority"])) $_REQUEST["priority"] = '';
if (!isset($_REQUEST["flag"])) $_REQUEST["flag"] = '';
if (!isset($_REQUEST["flagval"])) $_REQUEST["flagval"] = '';
88
if (!isset($_REQUEST["sort_mode"])) {
89
	$sort_mode = 'date_desc';
90
} else {
91
	$sort_mode = $_REQUEST["sort_mode"];
92 93
}
if (!isset($_REQUEST["offset"])) {
94
	$offset = 0;
95
} else {
96
	$offset = $_REQUEST["offset"];
97 98
}
if (isset($_REQUEST["find"])) {
99
	$find = $_REQUEST["find"];
100
} else {
101
	$find = '';
102 103 104 105 106 107 108 109
}
$smarty->assign_by_ref('flag', $_REQUEST['flag']);
$smarty->assign_by_ref('priority', $_REQUEST['priority']);
$smarty->assign_by_ref('flagval', $_REQUEST['flagval']);
$smarty->assign_by_ref('offset', $offset);
$smarty->assign_by_ref('sort_mode', $sort_mode);
$smarty->assign('find', $find);
// What are we paginating: items
changi67's avatar
changi67 committed
110
$items = $messulib->list_user_messages($user, $offset, $maxRecords, $sort_mode, $find, $_REQUEST["flag"], $_REQUEST["flagval"], $_REQUEST['priority'], '', $_REQUEST["replyto"], $orig_or_reply);
111
$smarty->assign_by_ref('cant_pages', $items["cant"]);
112
$smarty->assign_by_ref('mess_maxRecords', $maxRecords);
113
$smarty->assign_by_ref('items', $items["data"]);
114 115
$cellsize = 200;
$percentage = 1;
changi67's avatar
changi67 committed
116
if ($prefs['messu_mailbox_size'] > 0) {
117 118 119 120 121 122 123 124
	$current_number = $messulib->count_messages($user);
	$smarty->assign('messu_mailbox_number', $current_number);
	$smarty->assign('messu_mailbox_size', $prefs['messu_mailbox_size']);
	$percentage = ($current_number / $prefs['messu_mailbox_size']) * 100;
	$cellsize = round($percentage / 100 * 200);
	if ($current_number > $prefs['messu_mailbox_size']) $cellsize = 200;
	if ($cellsize < 1) $cellsize = 1;
	$percentage = round($percentage);
125 126 127
}
$smarty->assign('cellsize', $cellsize);
$smarty->assign('percentage', $percentage);
128 129
include_once ('tiki-section_options.php');
include_once ('tiki-mytiki_shared.php');
130
ask_ticket('messu-mailbox');
131
$smarty->assign('mid', 'messu-mailbox.tpl');
132
$smarty->display("tiki.tpl");