Commit 8b2cf13f authored by deuce's avatar deuce
Browse files

This is it baby... the new, the default, the ugly, the templated and

warm-fuzzy msgs web front end!
parent a700ce1d
load("html_inc/msgslib.ssjs");
title="Message Groups";
write_template("header.inc");
template.groups=msg_area.grp_list;
write_template("msgs/groups.inc");
write_template("footer.inc");
load("html_inc/msgslib.ssjs");
if(msgbase.open!=undefined && msgbase.open()==false) {
error(msgbase.last_error);
}
template.group=msg_area.grp_list[g];
if(sub=='mail') {
template.sub=new Object;
template.sub.description="Personal E-Mail";
template.sub.code="mail";
}
else {
template.sub=msg_area.grp_list[g].sub_list[s];
}
template.hdr=msgbase.get_msg_header(false,m);
template.body=msgbase.get_msg_body(false,m,true,true);
if(template.body.indexOf('\x1b[')>=0 || template.body.indexOf('\x01')>=0)
template.body=html_encode(body,true,false,true,true);
else {
template.body=word_wrap(template.body,79);
template.body=html_encode(template.body,true,false,false,false);
}
if(template.hdr != null) {
template.title="Message: "+template.hdr.subject;
}
write_template("header.inc");
write_template("msgs/msg.inc");
write_template("footer.inc");
load("html_inc/msgslib.ssjs");
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);
var total_pages=Math.floor(msgbase.total_msgs/max_messages)-1;
var firstpage=0;
var lastpage=firstpage+max_pages-1;
if(lastpage>total_pages)
lastpage=total_pages;
/* Ensure currpage is inside first/last */
while(currpage>lastpage) {
firstpage++;
lastpage=firstpage+max_pages-1;
if(lastpage>total_pages)
lastpage=total_pages;
}
/* Try adjust so currpage is in the middle of firstpage and lastpage */
while(currpage>firstpage+(max_pages/2) && lastpage<total_pages) {
firstpage++;
lastpage=firstpage+max_pages-1;
if(lastpage>total_pages)
lastpage=total_pages;
}
/* 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];
for(;displayed<max_messages && (hdr=msgbase.get_msg_header(true,last_offset)) != null;last_offset--) {
if(hdr==null)
continue;
if(sub=='mail' && hdr.to!=user.alias && hdr.to!=user.name && hdr.to !=user.netmail)
continue;
template.messages[displayed.toString()]=hdr;
displayed++;
}
write_template("msgs/msgs.inc");
write_template("footer.inc");
msgbase.close();
load("html_inc/msgslib.ssjs");
template.group=msg_area.grp_list[g];
if(sub=='mail') {
template.sub=new Object;
template.sub.description="Personal E-Mail";
template.sub.code="mail";
}
else {
template.sub=msg_area.grp_list[g].sub_list[s];
}
if(sub!='mail') {
if(! msg_area.grp_list[g].sub_list[s].can_post) {
error("You don't have sufficient rights to post in this sub");
}
}
template.title="Post a message";
write_template("header.inc");
write_template("msgs/post.inc");
write_template("footer.inc");
load("html_inc/msgslib.ssjs");
template.group=msg_area.grp_list[g];
if(sub=='mail') {
template.sub=new Object;
template.sub.description="Personal E-Mail";
template.sub.code="mail";
}
else {
template.sub=msg_area.grp_list[g].sub_list[s];
}
if(sub!='mail') {
if(! msg_area.grp_list[g].sub_list[s].can_post) {
error("You don't have sufficient rights to post in this sub");
}
}
if(msgbase.open!=undefined && msgbase.open()==false) {
error(msgbase.last_error);
}
hdr=msgbase.get_msg_header(false,parseInt(http_request.query.reply_to));
template.subject=hdr.subject;
if(template.subject.search(/^re:\s+/i)==-1)
template.subject='Re: '+template.subject;
template.from=hdr.from;
template.body=msgbase.get_msg_body(false,parseInt(http_request.query.reply_to),true,true)
if(this.word_wrap != undefined) {
template.body=quote_msg(word_wrap(template.body,79),79);
}
else {
template.body=template.body.replace(/^(.)/mg,"> $1");
}
msgbase.close();
title="Reply to message";
write_template("header.inc");
write_template("msgs/reply.inc");
write_template("footer.inc");
load("html_inc/msgslib.ssjs");
template.group=msg_area.grp_list[g];
if(sub=='mail') {
template.sub=new Object;
template.sub.description="Personal E-Mail";
template.sub.code="mail";
}
else {
template.sub=msg_area.grp_list[g].sub_list[s];
}
var hdrs = new Object;
if(sub!='mail') {
if(! msg_area.grp_list[g].sub_list[s].can_post) {
error("You don't have sufficient rights to post in this sub");
}
}
else {
hdrs.to_net_type=netaddr_type(http_request.query.to);
if(hdrs.to_net_type!=NET_NONE)
hdrs.to_net_addr=http_request.query.to;
}
hdrs.from=user.alias;
hdrs.to=http_request.query.to;
hdrs.subject=http_request.query.subject;
if(http_request.query.reply_to != undefined) {
hdrs.thread_orig=parseInt(http_request.query.reply_to);
}
if(msgbase.open!=undefined && msgbase.open()==false) {
error(msgbase.last_error);
}
if(!msgbase.save_msg(hdrs,http_request.query.body)) {
error(msgbase.last_error);
}
msgbase.close();
http_reply.status="201 Created";
title="Message posted";
write_template("header.inc");
write_template("msgs/posted.inc");
write_template("footer.inc");
load("html_inc/msgslib.ssjs");
title="Message Subs in "+msg_area.grp_list[g].description;
write_template("header.inc");
template.group=msg_area.grp_list[g];
template.subs=msg_area.grp_list[g].sub_list;
write_template("msgs/subs.inc");
write_template("footer.inc");
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment