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 = ""; var link = ""; 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 + '