summaryrefslogtreecommitdiffstats
path: root/vmail-listmessages-html.lsp
blob: 26373cfd3a72aa69c0b5630d269a2c3fbfbd8dd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<% local view, viewlibrary, page_info, session = ... 
require("viewfunctions")
%>

<% -- Pregenerate the list of users
if viewlibrary.check_permission("listusers") and (viewlibrary.check_permission("forwardmessage") or viewlibrary.check_permission("forwardmymessage")) then
	local users = viewlibrary.dispatch_component("listusers", nil, true)
	useroptions = {}
	table.sort(users.value, function(a,b) if a.firstname ~= b.firstname then return a.firstname < b.firstname elseif a.lastname ~= b.lastname then return a.lastname < b.lastname else return a.username < b.username end end)
	for i,u in ipairs(users.value) do
		if u.username ~= session.userinfo.userid then
			useroptions[#useroptions+1] = '<option value="'..html.html_escape(u.username)..'">'..html.html_escape(u.firstname)..' '..html.html_escape(u.lastname)..' ('..html.html_escape(u.username)..')</option>'
		end
	end
	useroptions = table.concat(useroptions)
end
%>
<% -- Pregenerate the list of folders
reversefolders = {}
if viewlibrary.check_permission("listfolders") then
	local folders = viewlibrary.dispatch_component("listfolders", nil, true)
	for i,u in ipairs(folders.value) do
		reversefolders[u.in_folder] = u.label
	end
	if (viewlibrary.check_permission("movemessage") or viewlibrary.check_permission("movemymessage")) then
		if #folders.value <= 1 then
			dontmove = true
		end
		folderoptions = {}
		for i,u in ipairs(folders.value) do
			folderoptions[#folderoptions+1] = '<option value="'..html.html_escape(u.in_folder)..'">'..html.html_escape(u.label)..'</option>'
		end
		folderoptions = table.concat(folderoptions)
	end
end
%>

<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"></script>
<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery.tablesorter.js"></script>
<script type="text/javascript">
	function PlayMessage() {
		$(".temporaryplayer").remove();
		$(this).parent().parent().after("<tr class='temporaryplayer'><td colspan='9'><embed width='100%' height='25px' marginheight='0' marginwidth='0' frameborder='0' scrolling='no' autostart='false' autoplay='false' loop='false' src='" + $(this).attr("href") + "'></embed></TD></TR>");
		return false;
	}
	function HandleMulti() {
		var messages = [];
		$(".multicheck:checked").each(function(){
			messages[messages.length] = this.value;
		});
		$(this).parent().find("[name='message']").attr("value", messages.join(","));
	}
        $(document).ready(function() {
                $("#list").tablesorter({headers: {0:{sorter: false}, 1:{sorter: false}}});
		$("#list").bind("sortStart",function() {
			$(".temporaryplayer").remove();
		});
		$(".playmessage").click(PlayMessage);
<% if viewlibrary.check_permission("deletemessage") or viewlibrary.check_permission("deletemymessage") then %>
		$("#multidelete").click(HandleMulti);
<% end %>
<% if viewlibrary.check_permission("forwardmessage") or viewlibrary.check_permission("forwardmymessage") then %>
		$("#multiforward").click(HandleMulti);
<% end %>
<% if viewlibrary.check_permission("emailmessage") or viewlibrary.check_permission("emailmymessage") then %>
		$("#multiemail").click(HandleMulti);
<% end %>
<% if viewlibrary.check_permission("movemessage") or viewlibrary.check_permission("movemymessage") then %>
		$("#multimove").click(HandleMulti);
<% end %>
        });
</script>

<% displaycommandresults({"deletemessage", "deletemymessage", "forwardmessage", "forwardmymessage", "emailmessage", "emailmymessage", "movemessage", "movemymessage"}, session) %>

<h1>Messages</h1>
<DL>
<TABLE><TR><TD>
<% if viewlibrary.check_permission("deletemessage") or viewlibrary.check_permission("deletemymessage") then %>
	<form id="multidelete" action="<%= html.html_escape(page_info.script..page_info.prefix..page_info.controller) %>/
		<% if viewlibrary.check_permission("deletemessage") then io.write("deletemessage") else io.write("deletemymessage") end %>
		" method="POST">
	<input class="hidden" type="hidden" name="redir"  value="<%= html.html_escape(page_info.orig_action) %>" >
	<input class="hidden" type="hidden" name="message"  value="" >
	<input class="submit" type="submit" value="Delete">
	</form>
<% end %>
<% if viewlibrary.check_permission("forwardmessage") or viewlibrary.check_permission("forwardmymessage") then %>
	<form id="multiforward" action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller) %>/
		<% if viewlibrary.check_permission("forwardmessage") then io.write("forwardmessage") else io.write("forwardmymessage") end %>
		" method="POST">
	<input class="hidden" type="hidden" name="redir"  value="<%= html.html_escape(page_info.orig_action) %>" >
	<input class="hidden" type="hidden" name="message"  value="" >
	<input class="submit" type="submit" value="Forward">
	<select name="newuser" style="width:auto;"><%= (useroptions or "") %></select>
	</form>
<% end %>
<% if viewlibrary.check_permission("emailmessage") or viewlibrary.check_permission("emailmymessage") then %>
	<form id="multiemail" action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller) %>/
		<% if viewlibrary.check_permission("emailmessage") then io.write("emailmessage") else io.write("emailmymessage") end %>
		" method="POST">
	<input class="hidden" type="hidden" name="redir"  value="<%= html.html_escape(page_info.orig_action) %>" >
	<input class="hidden" type="hidden" name="message"  value="" >
	<input class="submit" type="submit" value="E-mail">
	<input class="text" type="text" name="address"  value="" style="width:auto;">
	</form>
<% end %>
<% if viewlibrary.check_permission("movemessage") or viewlibrary.check_permission("movemymessage") then %>
	<% if not dontmove then %>
		<form id="multimove" action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller) %>/
			<% if viewlibrary.check_permission("movemessage") then io.write("movemessage") else io.write("movemymessage") end %>
			" method="POST">
		<input class="hidden" type="hidden" name="redir"  value="<%= html.html_escape(page_info.orig_action) %>" >
		<input class="hidden" type="hidden" name="message"  value="" >
		<input class="submit" type="submit" value="Move">
		<select name="newfolder" style="width:auto;"><%= (folderoptions or "") %></select>
		</form>
	<% end %>
<% end %>
</TD></TR></TABLE>

<TABLE id="list" class="tablesorter"><THEAD>
	<TR style="background:#eee;font-weight:bold;">
		<TH></TH>
		<TH>Action</TH>
		<TH>Date</TH>
		<TH>Time</TH>
		<TH>Caller ID</TH>
		<TH>Priority</TH>
		<TH>Orig Mailbox</TH>
		<TH>Folder</TH>
		<TH>Duration</TH>
	</TR>		
</THEAD><TBODY>
<% for k,v in ipairs( view.value ) do %>
	<TR>
		<TD><input type=checkbox class="multicheck" value="<%= html.html_escape(v.uuid) %>"></TD>
		<TD>
		<% if viewlibrary.check_permission("downloadmessage") then %>
			<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/downloadmessage?message="..v.uuid, label="Download "} %>
			<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/downloadmessage?message="..v.uuid, class="playmessage", label="Play "} %>
		<% elseif viewlibrary.check_permission("downloadmymessage") then %>
			<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/downloadmymessage?message="..v.uuid, label="Download "} %>
			<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/downloadmymessage?message="..v.uuid, class="playmessage", label="Play "} %>
		<% end %>
		</TD>
                <TD><%= html.html_escape(os.date("%x", v.created_epoch)) %></TD>
                <TD><%= html.html_escape(os.date("%X", v.created_epoch)) %></TD>
                <TD><%= html.html_escape(v.cid_number) %></TD>
                <TD><%= html.html_escape(v.read_flags) %></TD>
                <TD><%= html.html_escape(v.username) %></TD>
                <TD><%= html.html_escape(reversefolders[v.in_folder] or v.in_folder) %></TD>
                <TD><%= html.html_escape(v.message_len) %></TD>
	</TR>
<% end %>
</TBODY>
</TABLE>

<% if view.errtxt then %>
<p class="error"><%= html.html_escape(view.errtxt) %></p>
<% end %>
<% if #view.value == 0 then %>
<p>No messages found</p>
<% end %>

</DL>