msgs.ssjs 2.86 KB
Newer Older
1
load("html_inc/msgslib.ssjs");
2
load("html_inc/mime_decode.ssjs");
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

if(msgbase.open!=undefined && msgbase.open()==false) {
	error(msgbase.last_error);
}

/* Ensure that offset is an even multiple of max_messages */
offset-=offset%max_messages;

if(offset<0)
	offset=0;

if(offset > 0)  {
	if(offset<max_messages)  {
		offset=max_messages;
	}
}
var currpage=Math.floor(offset/max_messages);
20
var total_pages=Math.floor(msgbase.total_msgs/max_messages);
21
22
23
24
25
var firstpage=0;
var lastpage=firstpage+max_pages-1;
if(lastpage>total_pages)
	lastpage=total_pages;
/* Ensure currpage is inside first/last */
26
var lcount=0;
27
while(currpage>lastpage) {
28
	lcount++;
29
30
31
32
	firstpage++;
	lastpage=firstpage+max_pages-1;
	if(lastpage>total_pages)
		lastpage=total_pages;
33
34
	if(lcount>5000)
		currpage=lastpage;
35
36
37
}

/* Try adjust so currpage is in the middle of firstpage and lastpage */
38
lcount=0;
39
while(currpage>firstpage+(max_pages/2) && lastpage<total_pages) {
40
	lcount++;
41
42
43
44
	firstpage++;
	lastpage=firstpage+max_pages-1;
	if(lastpage>total_pages)
		lastpage=total_pages;
45
46
	if(lcount>5000)
		break;
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
}

/* Build the links now */
template.pagelinks='';
for(var page=firstpage;page<=lastpage;page++) {
	if(currpage==page)
		template.pagelinks += '<b>'+(page+1)+'</b> ';
	else
		template.pagelinks += "<a href=\""+path+'?msg_grp='+g+'&msg_sub='+encodeURIComponent(sub)+'&offset='+(page*max_messages)+'">'+(page+1)+'</a> ';
}


hdr=msgbase.get_msg_header(true,msgbase.total_msgs-1-offset-max_messages);
if(hdr!=null)  {
	template.pagelinks+='<a href="'+path+'?msg_grp='+g+'&msg_sub='+encodeURIComponent(sub)+'&offset='+(offset+max_messages)+'">NEXT</a>';
}

if(offset>0) {
	template.pagelinks='<a href="'+path+'?msg_grp='+g+'&msg_sub='+encodeURIComponent(sub)+'&offset='+(offset-max_messages)+'">PREV</a> '+template.pagelinks;
}

if(sub=='mail') {
	template.title="Messages in E-Mail";
	template.sub=new Object;
	template.sub.description="Personal E-Mail";
	template.sub.code="mail";
}
else {
	template.title="Messages in "+msg_area.grp_list[g].sub_list[s].description;
	template.sub=msg_area.grp_list[g].sub_list[s];
}

if(sub!='mail')  {
	if(! msg_area.grp_list[g].sub_list[s].can_read)  {
		error("You don't have sufficient rights to read this sub");
	}
}

write_template("header.inc");
last_offset=msgbase.total_msgs-1-offset;
var displayed=0;
template.messages=new Array;
template.group=msg_area.grp_list[g];

91
for(;displayed<max_messages && ((hdr=msgbase.get_msg_header(true,last_offset)) != null);last_offset--) {
92
93
	if(hdr==null)
		continue;
deuce's avatar
deuce committed
94
95
	if(hdr.subject=='')
		hdr.subject="-- No Subject --";
96
97
98
	if(sub=='mail' && hdr.to!=user.alias && hdr.to!=user.name && hdr.to !=user.netmail)
		continue;
	template.messages[displayed.toString()]=hdr;
99
 	template.messages[displayed.toString()].attachments=count_attachments(hdr,msgbase.get_msg_body(true,last_offset,true,true));
100
101
102
103
104
	displayed++;
}
write_template("msgs/msgs.inc");
write_template("footer.inc");
msgbase.close();