var BASEURL='https://C.environment.playbridgedoctor.com/';
////////////////////////////////////////////////////////////////////////////////
// common
////////////////////////////////////////////////////////////////////////////////
jQuery('body').on('click', '.exit', function() {
GoMainMenu();
});
function isAdmin() {
if (sPlayerName == 'admin' || sPlayerName == 'support' || sPlayerName == 'graeme' || sPlayerName == 'asden' || sPlayerName == 'jillee') {
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Content Pages
////////////////////////////////////////////////////////////////////////////////
var currentid;
var currenttitle;
var ForumLastType, ForumLastId;
var slidenumber = 0;
var numberofslides = 0;
var sometext;
jQuery('body').on('click', '.slide-up', function() {
slidenumber--;
if (slidenumber < 0) {
slidenumber = numberofslides - 1;
}
showSlide();
});
jQuery('body').on('click', '.slide-down', function() {
slidenumber++;
if (slidenumber >= numberofslides) {
slidenumber = 0;
}
showSlide();
});
jQuery('body').on('click', '.lessonsandquestions', function() {
var linkid;
linkid = jQuery(this).attr('id');
loadingForum();
ServerRequestContent({
type: 'post',
linkid: 1
});
});
jQuery('body').on('click', '.pagelist', function() {
var linkid;
linkid = jQuery(this).attr('id');
loadingForum();
ServerRequestContent({
type: 'pagelist',
linkid: linkid
});
});
jQuery('body').on('click', '.postlist', function() {
var linkid;
linkid = jQuery(this).attr('id');
loadingForum();
ServerRequestContent({
type: 'postlist',
linkid: linkid
});
});
jQuery('body').on('click', '.recent', function() {
var linkid;
linkid = jQuery(this).attr('id');
loadingForum();
ServerRequestContent({
type: 'recent',
linkid: linkid
});
});
jQuery('body').on('click', '.page', function() {
var linkid;
linkid = jQuery(this).attr('id');
loadingForum();
ServerRequestContent({
type: 'page',
linkid: linkid
});
});
jQuery('body').on('click', '.post', function() {
var linkid;
linkid = jQuery(this).attr('id');
loadingForum();
ServerRequestContent({
type: 'post',
linkid: linkid
});
});
jQuery('body').on('click', '.backtoactivelist', function() {
alert(currenttitle);
});
jQuery('body').on('click', '.newquestion', function() {
loadingForum();
ServerRequestContent({
type: 'post',
linkid: 37
});
});
jQuery('body').on('click', '.addforumcomment', function() {
if (jQuery('#mycomment').val() == '') {
//alert ('Write something in the box and then send');
} else {
var comment = jQuery('#mycomment').serialize();
ServerRequestContent({
type: 'addcomment',
linkid: currentid,
comment: comment
});
}
});
jQuery('body').on('click', '.addpost', function() {
if (jQuery('#mycomment').val() == '') {
//alert ('Write something in the box and then send');
} else {
var comment = jQuery('#mycomment').serialize();
jQuery('#main').html("add post");
ServerRequestContent({
type: 'addpost',
linkid: 0,
comment: comment
});
}
});
jQuery('body').on('click', '.deletepost', function() {
var linkid;
linkid = jQuery(this).attr('id').split('-')[1];
ServerRequestContent({
type: 'deletepost',
linkid: linkid
});
});
jQuery('body').on('click', '.approvecomment-0', function() {
var linkid;
linkid = jQuery(this).attr('id').split('-')[1];
ServerRequestContent({
type: 'approvecomment',
linkid: linkid
});
});
jQuery('body').on('click', '.approvecomment-1', function() {
var linkid;
linkid = jQuery(this).attr('id').split('-')[1];
ServerRequestContent({
type: 'unapprovecomment',
linkid: linkid
});
});
jQuery('body').on('click', '.approvepost', function() {
var linkid;
linkid = jQuery(this).attr('id').split('-')[1];
ServerRequestContent({
type: 'approvepost',
linkid: linkid
});
});
jQuery('body').on('click', '.unapprovepost', function() {
var linkid;
linkid = jQuery(this).attr('id').split('-')[1];
ServerRequestContent({
type: 'unapprovepost',
linkid: linkid
});
});
jQuery('body').on('click', '.deletecomment', function() {
var linkid;
linkid = jQuery(this).attr('id').split('-')[1];
ServerRequestContent({
type: 'deletecomment',
linkid: linkid
});
});
function loadingForum() {
jQuery('#main').html("Loading... ");
}
function ServerRequestContent(ob) {
ForumLastType = ob.type;
ForumLastId = ob.linkid;
jQuery('#comments').hide();
var url = BASEURL + "php/content.php";
var sData = 'mydomain=' + mydomain + '&userid=' + iUserID + '&type=' + ob.type + '&linkid=' + ob.linkid + '¤ttitle=' + currenttitle + '&';
sData += 'email=' + encodeURIComponent(PagesGetCookie('EmailAddress')) + '&pass=' + encodeURIComponent(PagesGetCookie('Pass')) + '&';
//alert(sData)
if (ob.type == 'addcomment' || ob.type == 'addpost') {
sData += ob.comment + '&';
}
jQuery.ajax({
type: "POST",
url: url,
data: sData,
dataType: 'json',
success: updateForum,
error: OnError,
cache: false
});
}
function OnError(xhr, errorType, exception) {
jQuery('#main').html("Error connecting to server, sorry. Please try again later.");
}
function updateForum(data) {
function showComments(comments, full) {
for (var i in comments) {
var comment = comments[i];
var link = "
" + comment.user + " " + comment.created;
if (comment.approved == 0) {
link += " ...";
}
if (full) link += " wrote in reply to " + comment.titlestring;
link += "
" + comment.content;
if (isAdmin()) {
link += " approved: " + comment.approved + "delete: " + comment.cid + "";
}
link += "
";
jQuery('#comments').append(link);
}
}
if (data.error != 'none') {
jQuery('#main').html(data.error);
} else {
function toMonth(t) {
if (t == '05') {
t = 'May';
}
return t;
}
var newcomment = '
';
if (sRole == 'ok') {
newcomment += '\
POST COMMENT
';
} else {
newcomment += '
' +
'Only Premium members can post to the forums ' +
'Subscribe' +
'
';
}
newcomment += '
'
var newpost = '
\
\
POST QUESTION
';
switch (data.type) {
case "pagelist":
jQuery('#main').html(''); //data.main
for (var i in data.list) {
var str = data.list[i];
var res = str.replace(/_/g, " ");
//var link = "
" + res + "
";
var link = "
" + res + "
";
jQuery('#main').append(link);
}
break;
case "postlist":
jQuery('#main').html(''); //data.main
jQuery('#comments').html("");
jQuery('#comments').show();
// todo: first two records will need a special case
// First, build our data structure
function getHandNumber(title) {
var sections = title.split('_');
if (sections.length != 5) return 9999; // arbitrarily high number for ordering
return Number(sections[sections.length - 1]);
}
function getDisplayTitle(title) {
var sections = title.split('_')
if (sections.length != 5) {
return 'Comment From Practice Hand'
} else {
return 'Competition Hand ' + String(sections[sections.length - 1])
}
}
function getPostSummary(postText, letterCount) {
var pos = postText.indexOf(' ', letterCount)
if (pos === -1) pos = 100;
var htmlPos= postText.indexOf('<')
pos = htmlPos > -1 && htmlPos < pos ? htmlPos : pos;
if (pos > 150) {
// This is too long and the author does not like spaces. Trim and move on
return postText.slice(0, 150) + '...[More]';
}
if (postText.length -1 > pos) {
// The text will be clipped
return postText.slice(0, pos) + '...[More]';
}
}
function getDisplayDate(createdDate) {
var dateBits = createdDate.split('-')
var dateObj = new Date(Date.UTC(dateBits[0], dateBits[1]-1, dateBits[2]))
function getEnding(dateNum) {
if (String(dateNum).slice(-2,-1) === '1') return 'th'
var lastDigit = String(dateNum).slice(-1);
return ({ '1': 'st', '2': 'nd', '3': 'rd' })[lastDigit] || 'th'
}
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'];
return dateObj.getUTCDate() + getEnding(dateObj.getUTCDate()) + ' ' + months[dateObj.getUTCMonth()]
}
// Build up the forum data struture to be used in the render function
var forumStructure = data.list.reduce(function(days, post) {
var forumEntry = {
pid: post.pid,
handNumber: getHandNumber(post.title),
title: getDisplayTitle(post.title),
displaySummary: getPostSummary(post.content, 100),
author: post.username,
replyCount: post.replyCount
// todo: presumably this should store every time an individual user opened a thread?
//hasNewPosts: post.hasNewPosts
}
var existingDay = -1
for (i=0; i -1) {
days[i].hands.push(forumEntry)
} else {
days.push({
created: post.created,
displayDate: getDisplayDate(post.created),
hands: [forumEntry]
})
}
return days
}, [])
// Now, order it - newest first, then lowest hands first
forumStructure.sort(function(a,b) {
if (a.created < b.created) return 1
if (a.created > b.created) return -1
return 0
})
for (var index in forumStructure) {
forumStructure[index].hands.sort(function(a, b) {
return a.handNumber - b.handNumber
})
}
function createForumHtml(forumStructure) {
var start = '
Comments/Questions from Lessons and Game pages are all displayed here. Comments from Lessons and Practice hands appear here immediately. Comments from Competition Hands are delayed until after that day\'s competition ends.
';
var link = '
Ask a Bridge Question
';
var html = start + link + '
'
var hand
for (var index in forumStructure) {
html += '
' + forumStructure[index].displayDate + '
';
html += '
';
for (var handIndex in forumStructure[index].hands) {
hand = forumStructure[index].hands[handIndex]
html += '
' + hand.title + '
';
html += '
' + hand.displaySummary + ' '
html += 'Posted by ' + hand.author;
if (Number(hand.replyCount)) {
html += ' (' + hand.replyCount + (hand.replyCount === 1 ? ' reply)' : ' replies)');
}
html += '
'
}
html += '
';
}
return html;
}
// Finally, inject into the DOM
jQuery('#main').append(createForumHtml(forumStructure))
break;
case "recent":
jQuery('#main').html('');
jQuery('#comments').html("");
jQuery('#comments').show();
showComments(data.list, true);
break;
case "page":
currentid = data.linkid;
currenttitle = data.linkid;
jQuery('#main').html("");
if (jQuery(data.main).hasClass('slideshow')) {
sometext = data.main;
numberofslides = jQuery(sometext).children().length;
showSlide();
jQuery('#main').append("
prev
next
")
} else {
jQuery('.maincontent').html(data.main);
}
jQuery('#comments').html("");
jQuery('#comments').show();
showComments(data.comments, false);
jQuery('#comments').append(newcomment);
break;
case "post":
currentid = data.linkid;
var main = data.main;
currenttitle = main.title;
var title;
var titleStr = main.title;
if (main.user == 'admin') {
var titleArr = titleStr.split('_');
if (titleArr[0] == 'compete') {
title = '' + titleArr[3] + ' ' + toMonth(titleArr[2]) + ', 20' + titleArr[1] + ' - Compete - Hand ' + titleArr[4] + ' ';
} else if (titleArr[0] == 'hands') {
title = 'Practice Hand ' + titleArr[2];
} else {
title = '' + titleStr + ' ';
}
} else {
title = "" + main.user + " " + titleStr;
}
var div = "
" + title + "
" + main.content;
if (isAdmin()) {
if (main.approved == 0) {
div += " approved: " + main.approved + "";
} else {
div += " approved: " + main.approved + "";
}
div += " delete: " + main.pid + "";
}
div += "
";
jQuery('#main').html(div);
jQuery('#comments').html("");
jQuery('#comments').show();
showComments(data.comments, false);
jQuery('#comments').append(newcomment);
break;
case "addpost":
currentid = data.main.pid;
var main = data.main;
currenttitle = main.title;
var div = "
" + main.created + " " + main.user + "
" + main.content;
if (isAdmin()) {
div += " delete: " + main.pid + "";
}
div += "
";
jQuery('#main').html(div);
jQuery('#comments').html("");
jQuery('#comments').show();
jQuery('#comments').append(newcomment);
break;
case "addcomment":
jQuery('#comments').html("");
jQuery('#comments').show();
showComments(data.comments);
jQuery('#comments').append(newcomment);
break;
case "deletepost":
jQuery('#main').html(data.main + " post: " + data.linkid);
break;
case "approvecomment":
jQuery('#main').html(data.main + " comment: " + data.linkid);
break;
case "unapprovecomment":
jQuery('#main').html(data.main + " comment: " + data.linkid);
break;
case "approvepost":
jQuery('#main').html(data.main + " post: " + data.linkid);
break;
case "unapprovepost":
jQuery('#main').html(data.main + " post: " + data.linkid);
break;
case "deletecomment":
jQuery('#main').html(data.main + " comment: " + data.linkid);
break;
}
}
}
function showSlide() {
var txt = jQuery(jQuery(sometext).children()[slidenumber]).html();
if (slidenumber == 0) {
jQuery('.maincontent').html("