bool CUserPageBuilder::CreateRecentApprovedArticles(CUser& PageOwner, CArticleList& RecentApprovals) { bool bSuccess = false; int iUserID = 0; // if we have a page owner and can get their ID then create the most recent // article list for them bSuccess = !PageOwner.IsEmpty() && PageOwner.GetUserID(&iUserID) && RecentApprovals.CreateRecentApprovedArticlesList(iUserID,100); // return success or failure return bSuccess; }
bool CUserPageBuilder::CreateSubscribedToUsersRecentArticles(CUser& PageOwner, int iSiteID, CArticleSubscriptionList& SubscribedUsersArticles) { bool bSuccess = false; int iUserID = 0; // if we have a page owner and can get their ID then create the most recent articles by users they have subscribed to. bSuccess = !PageOwner.IsEmpty() && PageOwner.GetUserID(&iUserID) && SubscribedUsersArticles.GetRecentArticles(iUserID, iSiteID); // return success or failure return bSuccess; }
VOID CUserMgr::ChangePwd(UINT32 dwUserID, TCHAR* pszPasswd) { CSDMutexLock lock(m_oMutex); CSessionID2UserMapItr itr; for(itr = m_mapPlayerID2User.begin(); itr != m_mapPlayerID2User.end(); itr++) { CUser* poUser = itr->second; if (poUser->GetUserID() == dwUserID) { poUser->ChangePwd(pszPasswd); } } }
bool CUserPageBuilder::CreateRecentPosts(CUser& PageOwner, CUser* pViewer, CPostList& RecentPosts) { bool bSuccess = false; int iUserID = 0; // if we have a page owner and can get their ID then create the most recent // post list for them bSuccess = !PageOwner.IsEmpty() && PageOwner.GetUserID(&iUserID) && RecentPosts.CreateRecentPostsList(pViewer, iUserID,100); // return created object or NULL for failure return bSuccess; }
bool CVotePageBuilder::AddClubLinksXml() { CLink Link(m_InputContext); bool bShowPrivateClubLinks = false; CUser* pUser = m_InputContext.GetCurrentUser(); if (pUser != NULL) { CClub club(m_InputContext); bShowPrivateClubLinks = pUser->GetIsEditor() || club.IsUserInTeamMembersOfClub(pUser->GetUserID(), m_iObjectID); } Link.GetClubLinks(m_iObjectID, NULL, bShowPrivateClubLinks); return m_pPage->AddInside("VOTING-PAGE", &Link); }
void CUserMgr::ReleaseUser(UINT32 dwUserID) { CSDMutexLock lock(m_oMutex); CSessionID2UserMapItr itr; for(itr = m_mapPlayerID2User.begin(); itr != m_mapPlayerID2User.end();) { CUser* poUser = itr->second; if(poUser->GetUserID() == dwUserID) { m_oUserPool.Free(poUser); m_mapPlayerID2User.erase(itr++); } else { itr++; } } }
/********************************************************************************* bool CVotePageBuilder::RemoveUserVote() Author: Mark Howitt Created: 06/08/2004 Inputs: - Outputs: - Returns: true if ok, false if not. Purpose: Removes a users vote from a given vote. *********************************************************************************/ bool CVotePageBuilder::RemoveUserVote() { if (m_InputContext.GetAllowRemoveVote() != 1) { m_pPage->SetError("Votes cannot be removed for this site"); return false; } // Set the action flag m_pPage->AddInside("VOTING-PAGE","<ACTION>removeuservote</ACTION>"); // Get the basic info CUser* pUser = m_InputContext.GetCurrentUser(); if (pUser == NULL) { // We can't do anything if we're not logged in! m_pPage->SetError("UserNotLoggedIn"); return false; } // Get the voteid from the url int iVoteID = m_InputContext.GetParamInt("voteid"); int iUserID = m_InputContext.GetParamInt("userid"); // Check to see if the user is an editor or not if ( ( pUser->GetUserID() != iUserID ) && !pUser->GetIsEditor() && !pUser->GetIsSuperuser() ) { // We can't do anything if we're not an editor! m_pPage->SetError("UserNotAuthorised"); return false; } // Now revome the vote for the user in the given vote. if (!m_CurrentVote.RemoveUsersVote(iVoteID,iUserID)) { m_pPage->SetError(m_CurrentVote.GetLastErrorMessage()); return false; } // Now insert the vote XML, and return the verdict! return m_pPage->AddInside("VOTING-PAGE",&m_CurrentVote); }
bool CPollContentRating::Vote() { // Create with VOTING-PAGE element as root CTDVString sXML; sXML << "<" << GetRootElement() << "></" << GetRootElement() << ">"; if(!CreateFromXMLText(sXML, 0, true)) { TDVASSERT(false, "CPollContentRating::Vote() CreateFromXMLText failed"); return false; } // Get redirect URL CTDVString sRedirectURL; if(!m_InputContext.GetParamString("s_redirectto",sRedirectURL) || sRedirectURL.IsEmpty()) { // Skin must set s_redirectto for content rating polls TDVASSERT(false, "CPollContentRating::Vote() 's_redirectto' parameter not found."); if(!AddErrorElement(GetRootElement(), ERRORCODE_BADPARAMS, "'s_redirectto' not set by skin")) { TDVASSERT(false, "CPollContentRating::Vote() AddErrorElement failed"); return false; } return true; } // Initialise the UserID int nUserID = 0; CTDVString sBBCUID; // Get User CUser *pUser = m_InputContext.GetCurrentUser(); // Check PollID int nPollID = GetPollID(); if(nPollID < 1) { TDVASSERT(false, "CPollContentRating::Vote() Invalid Poll ID"); AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_BADPOLLID, "Invalid PollID"); SetRedirectURL(sRedirectURL); return false; } if (!m_bAllowAnonymousRating) //Normal way needs to be logged in to vote { if(!pUser) // Not logged in? { AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_NEEDUSER, "User not logged in"); SetRedirectURL(sRedirectURL); return true; } if(!pUser->GetUserID(&nUserID)) { TDVASSERT(false, "CPollContentRating::Vote() pUser->GetUserID failed"); AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_UNSPECIFIED, "CPollContentRating::Vote() pUser->GetUserID failed"); SetRedirectURL(sRedirectURL); return false; } } else //Anonymous rating { // Get the UID For the current user. m_InputContext.GetBBCUIDFromCookie(sBBCUID); if(pUser) // If logged in get the user id? { if(!pUser->GetUserID(&nUserID)) { TDVASSERT(false, "CPollAnonymousContentRating::Vote() Anonymous Rating pUser->GetUserID failed"); AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_UNSPECIFIED, "CPollContentRating::Vote() Anonymous Rating pUser->GetUserID failed"); SetRedirectURL(sRedirectURL); return false; } } } // Don't allow page author to vote CStoredProcedure SP; m_InputContext.InitialiseStoredProcedureObject(&SP); // Get article id std::vector<int> vecArticleIDs; if(!SP.PollGetItemIDs(vecArticleIDs, GetPollID(), (int)CPoll::ITEMTYPE_ARTICLE)) { TDVASSERT(false, "CPollContentRating::Vote() SP.PollGetItemIDs failed"); AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_UNSPECIFIED, "CPollContentRating::Vote() SP.PollGetItemIDs failed"); SetRedirectURL(sRedirectURL); return false; } // Check whether poll is linked with an article if(!vecArticleIDs.empty()) { // CR polls can only be linked to a single article TDVASSERT(vecArticleIDs.size()==1, "ContentRating poll is linked to more than one article. Using first one."); int nAuthorID = 0; if(!SP.PollGetArticleAuthorID(nAuthorID, vecArticleIDs[0])) { TDVASSERT(false, "CPollContentRating::Vote() SP.PollGetArticleAuthorID failed"); return false; } // Do author check if(nAuthorID == nUserID) { AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_AUTHORCANNOTVOTE, "Page author cannot vote on his article"); SetRedirectURL(sRedirectURL); return true; // Not a failure, just don't let him vote } } // Get users response int nResponse = m_InputContext.GetParamInt("response"); // Check response if(nResponse < 0) { AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_BADPARAMS, "Invalid 'response' parameter"); SetRedirectURL(sRedirectURL); return true; } //If limits defined - check within limits. if ( m_nResponseMin >= 0 && nResponse < m_nResponseMin ) { AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_BADPARAMS, "Invalid 'response' parameter"); SetRedirectURL(sRedirectURL); return true; } if ( m_nResponseMax >= 0 && nResponse > m_nResponseMax ) { AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_BADPARAMS, "Invalid 'response' parameter"); SetRedirectURL(sRedirectURL); return true; } m_InputContext.InitialiseStoredProcedureObject(&SP); if(!m_bAllowAnonymousRating) { // Call stored procedure to update database if (!SP.PollContentRatingVote(nPollID, nUserID, nResponse)) { TDVASSERT(false, "CPollContentRating::Vote() SP.PollContentRatingVote failed"); AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_UNSPECIFIED, "Failed to save vote to database"); SetRedirectURL(sRedirectURL); return false; } } else //Anonymous Rating { // Call stored procedure to update database if (!SP.PollAnonymousContentRatingVote(nPollID, nUserID, nResponse, sBBCUID)) { TDVASSERT(false, "CPollContentRating::Vote() SP.AnonymousPollContentRatingVote failed"); AddPollErrorCodeToURL(sRedirectURL, ERRORCODE_UNSPECIFIED, "Failed to save vote to database"); SetRedirectURL(sRedirectURL); return false; } } // Redirect back to page where poll resides SetRedirectURL(sRedirectURL); return true; }
bool CUserPageBuilder::CreateUserInterface(CUser* pViewer, CUser& Owner, CGuideEntry& Masthead, CPageUI &Interface) { // TODO: will need to take into account viewing users preferences at some // point if they are allowed to switch off some buttons bool bSuccess = Interface.Initialise(pViewer); // I've guessed at what the URLs might look like => should the url // parameters be filled in at this time as well? if (bSuccess) { bool bDiscuss = true; bool bEdit = false; bool bViewerActive = false; int iViewerID = 0; int iOwnerID = 0; int iForumID = 0; // get the ID of the forum if we have been given a masthead article and // it actually has a forum (which it should) if (!Masthead.IsEmpty()) { iForumID = Masthead.GetForumID(); } if (iForumID == 0) { bDiscuss = false; } // check if we have a registered viewer and also if this happens to be their // own home page and set the appropriate button flags if (pViewer != NULL && pViewer->GetActive(&bViewerActive) && bViewerActive) { if (pViewer->GetUserID(&iViewerID) && !Owner.IsEmpty() && Owner.GetUserID(&iOwnerID) && iViewerID == iOwnerID && iViewerID != 0) { // also if this is their own home page they have // an edit page button bEdit = true; } } // TODO: forum ID seems to not work??? CTDVString sDiscuss = "AddThread?forum="; sDiscuss << iForumID << "&article="; int ih2g2ID = 0; CTDVString sEditLink = ""; // get masthead ID if there is one if (!Owner.IsEmpty()) { ih2g2ID = Owner.GetMasthead(); } else if (!Masthead.IsEmpty()) { ih2g2ID = Masthead.GetH2G2ID(); } sEditLink << "/UserEdit" << ih2g2ID << "?Masthead=1"; sDiscuss << ih2g2ID; // now set the apppropriate buttons in the UI object // currently you only get the eidt page button if this is actually your homepage, i.e. you // wont get it if you have editor status bSuccess = Interface.SetDiscussVisibility(bDiscuss, sDiscuss) && Interface.SetEditPageVisibility(bEdit, sEditLink); // TODO: may wish to fail in this case, but just log the error currently TDVASSERT(bSuccess, "Couldn't set a visibility option in CUserPageBuilder::CreateUserInterface()"); } // if something went wrong then delete object and return NULL // return object or NULL for failure return bSuccess; }
bool CUserPageBuilder::AddClubsUserBelongsTo(CWholePage* pPage,int iUserID) { CStoredProcedure SP; m_InputContext.InitialiseStoredProcedureObject(&SP); if (!SP.GetAllClubsThatUserBelongsTo(iUserID)) { TDVASSERT(false, "No stored procedure created"); return false; } CTDVString sXML, sClubName, sDateCreated; int iClubID = 0; sXML << "<USERMYCLUBS>"; sXML << "<CLUBSSUMMARY>"; while (!SP.IsEOF()) { int iOwner = SP.GetIntField("Owner"); int iHidden = SP.GetIntField("Hidden"); SP.GetField("Name",sClubName); SP.GetField("DateCreated",sDateCreated); iClubID = SP.GetIntField("ClubID"); // if club is hidden, hide if the user is not allowed to see it if(iHidden > 0) { bool bHide = true; CUser* pViewingUser = m_InputContext.GetCurrentUser(); if (pViewingUser != NULL) { CClub Club(m_InputContext); Club.InitialiseViaClubID(iClubID); bHide = !Club.CanUserEditClub(pViewingUser->GetUserID(),iClubID) && !pViewingUser->HasSpecialEditPermissions(Club.GetArticleID()); } if (bHide) { sClubName = "hidden"; } } CTDVDateTime dDateCreated = SP.GetDateField("DateCreated"); CTDVString sDate; dDateCreated.GetAsXML(sDate); sXML << "<CLUB ID='" << iClubID << "'>"; sXML << "<NAME>" << sClubName << "</NAME>"; sXML << "<MEMBERSHIPSTATUS>"; if (SP.GetIntField("Owner") == 1) { sXML << "Owner"; } else { sXML << "Supporter"; } sXML << "</MEMBERSHIPSTATUS>"; sXML << "<DATECREATED>" << sDate << "</DATECREATED>"; sXML << "<MEMBERSHIPCOUNT>" << SP.GetIntField("MembershipCount") << "</MEMBERSHIPCOUNT>"; sXML << "</CLUB>"; SP.MoveNext(); } sXML << "</CLUBSSUMMARY>"; sXML << "</USERMYCLUBS>"; pPage->AddInside("H2G2",sXML); return true; }
bool CModeratePostsBuilder::Build(CWholePage* pWholePage) { InitPage(pWholePage, "POST-MODERATION", true); bool bSuccess = true; // do an error page if not an editor or moderator. CUser* pViewer = m_InputContext.GetCurrentUser(); if (pViewer == NULL || !(pViewer->GetIsEditor() || pViewer->GetIsModerator()) ) { bSuccess = bSuccess && pWholePage->SetPageType("ERROR"); bSuccess = bSuccess && pWholePage->AddInside("H2G2", "<ERROR TYPE='NOT-EDITOR'>You cannot perform moderation unless you are logged in as an Editor or Moderator.</ERROR>"); return true; } //Process Actions. if ( ! Process(pWholePage,pViewer) ) { SetDNALastError("CModeratePostsBuilder::Build","Build","Unable to process"); pWholePage->AddInside("H2G2",GetLastErrorAsXMLString()); } //Handle s_returnto. if ( bSuccess && CheckAndUseRedirectIfGiven(pWholePage) ) return bSuccess; //Handle 'Oldstyle' redirect - necessary to handle multiple submit buttons for the same form. if ( m_InputContext.ParamExists("Done") ) { CTDVString sRedirect = "Moderate?newstyle=1"; if ( m_InputContext.GetParamInt("fastmod") == 1 ) sRedirect += "&fastmod=1"; return pWholePage->Redirect(sRedirect); } //Produce XML for page. // find out if we are processing referrals or not bool bReferrals = m_InputContext.GetParamInt("Referrals") == 1; bool bAlerts = m_InputContext.GetParamInt("Alerts") == 1; bool bLockedItems = m_InputContext.GetParamInt("Locked") == 1; //Viewing users locked items only. bool bHeldItems = m_InputContext.GetParamInt("Held") == 1; int iShow = 10; if ( m_InputContext.ParamExists("show") ) iShow = m_InputContext.GetParamInt("show"); bool bFastMod = m_InputContext.GetParamInt("fastmod") != 0; int iModClassId = 0; if ( m_InputContext.ParamExists("ModClassId") ) iModClassId = m_InputContext.GetParamInt("ModClassId"); //Filter on moderation items for a specific post. int iPostId = 0; if ( m_InputContext.ParamExists("PostFilterId") ) iPostId = m_InputContext.GetParamInt("PostFilterId"); //Add Moderation Classes CModerationClasses modclasses(m_InputContext); if ( modclasses.GetModerationClasses() ) bSuccess = bSuccess && pWholePage->AddInside("H2G2",&modclasses); else if ( modclasses.ErrorReported() ) bSuccess && bSuccess && pWholePage->AddInside("H2G2",modclasses.GetLastErrorAsXMLString() ); //Add Moderation Failure - Reasons CModReasons reasons(m_InputContext); if ( reasons.GetModReasons(iModClassId) ) bSuccess = bSuccess && pWholePage->AddInside("H2G2",&reasons); //Add Refereee List CRefereeList referees(m_InputContext); if ( referees.FetchTheList() ) bSuccess = bSuccess && pWholePage->AddInside("H2G2",&referees); //Add Site List //CTDVString sSiteXML; //bSuccess = bSuccess && m_InputContext.GetSiteListAsXML(&sSiteXML, 2); //bSuccess = bSuccess && pWholePage->AddInside("H2G2", sSiteXML); CBasicSiteList sitelist(m_InputContext); if ( !sitelist.PopulateList() ) pWholePage->AddInside("H2G2",sitelist.GetLastErrorAsXMLString()); else bSuccess = bSuccess && pWholePage->AddInside("H2G2",sitelist.GetAsXML2()); //Add User Moderation Statuses CUserStatuses modstatuses(m_InputContext); if ( modstatuses.GetUserStatuses() ) pWholePage->AddInside("H2G2",&modstatuses); else if ( modstatuses.ErrorReported() ) pWholePage->AddInside("H2G2",modstatuses.GetLastErrorAsXMLString()); //Add Distress Messages CModerationDistressMessages distressmsgs(m_InputContext); if ( distressmsgs.GetDistressMessages(iModClassId) ) pWholePage->AddInside("H2G2",&distressmsgs); else pWholePage->AddInside("H2G2",distressmsgs.GetLastErrorAsXMLString() ); CModeratePosts moderate(m_InputContext); if ( !moderate.GetPosts( pViewer->GetUserID(), bAlerts, bReferrals, bLockedItems, bHeldItems, iModClassId, iPostId, iShow, bFastMod ) ) pWholePage->AddInside("H2G2",moderate.GetLastErrorAsXMLString() ); else pWholePage->AddInside("H2G2",&moderate); TDVASSERT(bSuccess, "CModeratePostsBuilder::Build() failed"); return bSuccess; }
bool CReviewSubmissionForum::RemoveThreadFromForum(CUser& mViewer,int iReviewForumID,int iH2G2ID, int* iThreadID,int* iForumID,bool *pbSuccessful,bool bHasPermission /*false*/) { if (iReviewForumID <= 0 || iH2G2ID <= 0) { TDVASSERT(false,"Bad ReviewForum ID in CReviewSubmissionForum::RemoveThreadFromForum"); *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","RMBADID","Bad arguments for this action"); } //Initialise the article CGuideEntry mGuideEntry(m_InputContext); if (!mGuideEntry.Initialise(iH2G2ID,0, false,true,false,false,false)) { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","NOARTICLE","Failed to Get Article details"); } //create a storedprocedure CStoredProcedure mSP; if (!m_InputContext.InitialiseStoredProcedureObject(&mSP)) { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","DBERROR","A database error has occured"); } //check the article is in review if (!mSP.FetchReviewForumMemberDetails(iH2G2ID)) { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","BADH2G2ID","The article is not in a review forum"); } int iSubmitterID = mSP.GetIntField("SubmitterID"); int iPostID = mSP.GetIntField("PostID"); *iThreadID = mSP.GetIntField("ThreadID"); *iForumID = mSP.GetIntField("ForumID"); int iActualReviewForumID = mSP.GetIntField("ReviewForumID"); //make sure that we are in the right review forum for the article if (iReviewForumID != iActualReviewForumID) { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","BADRFID","The article is in a different review forum"); } //Permission has been verified by the caller so don't check if (!bHasPermission) { //ok if you're an editor if (!mViewer.GetIsEditor()) { //ok if you are the author if (!(mGuideEntry.GetEditorID() == mViewer.GetUserID())) { //ok if you are the submitter if (!(mViewer.GetUserID() == iSubmitterID)) { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","BADUSER","You do not have permission to move the thread"); } } } } //initialise the review forum CReviewForum mReviewForum(m_InputContext); if (!mReviewForum.InitialiseViaReviewForumID(iReviewForumID)) { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","NOREVIEW","Invalid Review Forum ID"); } //move the thread mSP.MoveThread(*iThreadID,mGuideEntry.GetForumID()); if (!mSP.GetBoolField("Success")) { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","NOMOVE","Failed to move thread to article"); } if (!mSP.RemoveArticleFromPeerReview(iH2G2ID)) { mSP.UndoThreadMove(*iThreadID,0); if (!mSP.GetBoolField("Success")) { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","HALFMOVE","The thread has been moved, but not from review"); } else { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","NOMOVE","Failed to move thread to article"); } } //Update the entry mSP.ForceUpdateEntry(iH2G2ID); //update the post details CTDVString sPostSubject,sPostText,sNewSubject; mSP.FetchPostDetails(iPostID); mSP.GetField("Subject",sPostSubject); mSP.GetField("Text",sPostText); sNewSubject = mReviewForum.GetReviewForumName(); sNewSubject << ": " << sPostSubject; mSP.UpdatePostDetails(NULL,iPostID,sNewSubject,sPostText,NULL,false,false,true); //update the thread first subject details mSP.UpdateThreadFirstSubject(*iThreadID,sNewSubject); //post the success story CTDVString sArticleSubject; mGuideEntry.GetSubject(sArticleSubject); CTDVString xmlText = ""; xmlText << "<SUBMIT-REVIEW-FORUM><MOVEDTHREAD>" << "<H2G2ID>" << iH2G2ID << "</H2G2ID>" << "<SUBJECT>" << sArticleSubject << "</SUBJECT>" << "<REVIEWFORUM ID='" << iReviewForumID << "'>" << "<REVIEWFORUMNAME>" << mReviewForum.GetReviewForumName() << "</REVIEWFORUMNAME>" << "<URLFRIENDLYNAME>" << mReviewForum.GetURLFriendlyName() << "</URLFRIENDLYNAME>" << "</REVIEWFORUM></MOVEDTHREAD></SUBMIT-REVIEW-FORUM>"; if (!CreateFromXMLText(xmlText)) { *pbSuccessful = false; return GracefulError("SUBMIT-REVIEW-FORUM","XMLERROR","There was an XML error"); } *pbSuccessful = true; return true; }
bool CUserPageBuilder::Build(CWholePage* pWholePage) { // introducing the players - these will point to the XML objects required // to construct a user page CPageUI Interface(m_InputContext); CUser* pViewer = NULL; CUser Owner(m_InputContext); CGuideEntry Masthead(m_InputContext); CForum PageForum(m_InputContext); CForum Journal(m_InputContext); CPostList RecentPosts(m_InputContext); CArticleList RecentArticles(m_InputContext); CArticleList RecentApprovals(m_InputContext); CCommentsList RecentComments(m_InputContext); CArticleSubscriptionList SubscribedUsersArticles(m_InputContext); CTDVString sSecretKey; int iSecretKey = 0; int iUserID = 0; // the user ID in the URL bool bRegistering = false; bool bSuccess = true; // our success flag // get the user ID from the URL => zero if not present // TODO: something appropriate if no ID provided iUserID = m_InputContext.GetParamInt("UserID"); // now get the secret key if there is one // we may need to process it so get it as a string if (m_InputContext.GetParamString("Key", sSecretKey)) { // if the secret key start with "3D" we must strip this off // - it is caused by a mime encoding problem, 3D is the ascii hex for = if (sSecretKey.Find("3D") == 0) { sSecretKey = sSecretKey.Mid(2); } iSecretKey = atoi(sSecretKey); if (iSecretKey > 0) { // if there is a secret key then it is a registration attempt bRegistering = true; } } // now give appropriate page depending on whether this is a registration or not if (bRegistering) { // CStoredProcedure* pSP = m_InputContext.CreateStoredProcedureObject(); CTDVString sPageContent = ""; CTDVString sPageSubject = ""; // CTDVString sCookie; // check we got our SP okay // if (pSP == NULL) // { // bSuccess = false; // } // if so then call the activate user method, which should return us a nice // warm cookie if all goes well // if (bSuccess) // { // bSuccess = pSP->ActivateUser(iUserID, iSecretKey, &sCookie); // make sure cookie is not empty // if (sCookie.IsEmpty()) // { // bSuccess = false; // } // } // if okay then build page with the cookie in and a message to the user if (bSuccess) { // we have a cookie and we are prepared to use it // TODO: what about the MEMORY tag? // TODO: put this in stylesheet? Deal with delayed refresh? // CTDVString sCookieXML = "<SETCOOKIE><COOKIE>" + sCookie + "</COOKIE></SETCOOKIE>"; // sPageSubject = "Registration in process ..."; // sPageContent << "<GUIDE><BODY>"; // sPageContent << "<P>Thank you for registering as an official Researcher for The Hitch Hiker's "; // sPageContent << "Guide to the Galaxy: we do hope you enjoy contributing to the Guide.</P>"; // sPageContent << "<P>Please wait while you are transferred to <LINK BIO=\"U" << iUserID << "\">"; // sPageContent << "your Personal Home Page</LINK> ... or click the link if nothing happens.</P>"; // sPageContent << "</BODY></GUIDE>"; // pWholePage = CreateSimplePage(sPageSubject, sPageContent); // if (pWholePage == NULL) // { // bSuccess = false; // } if (bSuccess) { bSuccess = InitPage(pWholePage, "USERPAGE",false); } // put the cookie xml inside the H2G2 tag // bSuccess = pWholePage->AddInside("H2G2", sCookieXML); // CTDVString sUserXML = ""; // sUserXML << "<REGISTERING-USER>"; // sUserXML << "<USER>"; // sUserXML << "<USERNAME></USERNAME>"; // sUserXML << "<USERID>" << iUserID << "</USERID>"; // sUserXML << "</USER>"; // sUserXML << "</REGISTERING-USER>"; // bSuccess = pWholePage->AddInside("H2G2", sUserXML); // bSuccess = bSuccess && pWholePage->SetPageType("REGISTER-CONFIRMATION"); CTDVString sRedirect; sRedirect << "ShowTerms" << iUserID; sRedirect << "?key=" << sSecretKey; pWholePage->Redirect(sRedirect); } else { sPageSubject = "Sorry ..."; sPageContent << "<GUIDE><BODY>"; sPageContent << "<P>The URL you've given is wrong. Please re-check your email, or <LINK HREF=\"/Register\">click here to re-enter your email address</LINK>.</P>"; sPageContent << "</BODY></GUIDE>"; bSuccess = CreateSimplePage(pWholePage, sPageSubject, sPageContent); } // make sure we delete the SP if any // delete pSP; // pSP = NULL; } else { // get or create all the appropriate xml objects pViewer = m_InputContext.GetCurrentUser(); bool bGotMasthead = false; bool bGotPageForum = false; bool bGotJournal = false; bool bGotRecentPosts = false; bool bGotRecentArticles = false; bool bGotRecentApprovals = false; bool bGotRecentComments = false; bool bGotSubscribedToUsersRecentArticles = false; bool bGotOwner = CreatePageOwner(iUserID, Owner); CreatePageTemplate(pWholePage); if (m_InputContext.IncludeUsersGuideEntryInPersonalSpace() || (m_InputContext.GetParamInt("i_uge") == 1) || m_InputContext.IncludeUsersGuideEntryForumInPersonalSpace() || (m_InputContext.GetParamInt("i_ugef") == 1)) { bGotMasthead = CreatePageArticle(iUserID, Owner, Masthead); if (m_InputContext.IncludeUsersGuideEntryForumInPersonalSpace() || (m_InputContext.GetParamInt("i_ugef") == 1)) { // GuideEntry forum can not be returned if GuideEntry is not being returned. bGotPageForum = CreatePageForum(pViewer, Masthead, PageForum); } } bool bGotInterface = CreateUserInterface(pViewer, Owner, Masthead, Interface); // Only display other information if the page has a valid masthead if (bGotMasthead) { if (m_InputContext.IncludeJournalInPersonalSpace() || (m_InputContext.GetParamInt("i_j") == 1)) { bGotJournal = CreateJournal(Owner, pViewer, Journal); } if (m_InputContext.IncludeRecentPostsInPersonalSpace() || (m_InputContext.GetParamInt("i_rp") == 1)) { bGotRecentPosts = CreateRecentPosts(Owner, pViewer, RecentPosts); } if (m_InputContext.IncludeRecentCommentsInPersonalSpace() || (m_InputContext.GetParamInt("i_rc") == 1)) { bGotRecentComments = CreateRecentComments(Owner, pViewer, RecentComments); } if (m_InputContext.IncludeRecentGuideEntriesInPersonalSpace() || (m_InputContext.GetParamInt("i_rge") == 1)) { bGotRecentArticles = CreateRecentArticles(Owner, RecentArticles); bGotRecentApprovals = CreateRecentApprovedArticles(Owner, RecentApprovals); } if (m_InputContext.IncludeUploadsInPersonalSpace() || (m_InputContext.GetParamInt("i_u") == 1)) { CTDVString sUploadsXML; CUpload Upload(m_InputContext); Upload.GetUploadsForUser(iUserID,sUploadsXML); pWholePage->AddInside("H2G2",sUploadsXML); } if (m_InputContext.IncludeRecentArticlesOfSubscribedToUsersInPersonalSpace() || (m_InputContext.GetParamInt("i_rasu") == 1)) { bGotSubscribedToUsersRecentArticles = CreateSubscribedToUsersRecentArticles(Owner, m_InputContext.GetSiteID(), SubscribedUsersArticles); } } // See if the user wants to swap to this site and change their masthead and journal (if it exists) /* This feature is now redundant. There's no concept of a homesite. if (m_InputContext.ParamExists("homesite")) { if (pViewer == NULL) { // error: Not registered - ignore request } else if (!bGotOwner) { // error - no actual owner, ignore request } else if (pViewer->GetIsEditor()) { int iCurrentSiteID = m_InputContext.GetSiteID(); int iThisSite = iCurrentSiteID; if (bGotMasthead) { iCurrentSiteID = Masthead.GetSiteID(); } if ( iThisSite != iCurrentSiteID && m_InputContext.CanUserMoveToSite(iCurrentSiteID, iThisSite)) { CStoredProcedure SP; m_InputContext.InitialiseStoredProcedureObject(&SP); if (bGotMasthead) { SP.MoveArticleToSite(Masthead.GetH2G2ID(), m_InputContext.GetSiteID()); //delete pMasthead; Masthead.Destroy(); bGotMasthead = CreatePageArticle(iUserID, Owner, Masthead); } int iJournal; Owner.GetJournal(&iJournal); if (iJournal > 0) { SP.MoveForumToSite(iJournal, m_InputContext.GetSiteID()); } int iPrivateForum; if (Owner.GetPrivateForum(&iPrivateForum)) { SP.MoveForumToSite(iPrivateForum, m_InputContext.GetSiteID()); } pWholePage->AddInside("H2G2", "<SITEMOVED RESULT='success'/>"); } } } */ // check that all the *required* objects have been created successfully // note that pViewer can be NULL if an unregistered viewer // pOwner can be NULL if we are serving a default page because this user ID // does not exist // bGotJournal can be false if the user doesn't exist, or has no journal // bGotRecentPosts can be false if the user doesn't exist // pRecentArticles can be NULL if the user doesn't exist // pRecentApprovals can be NULL if the user doesn't exist // bGotPageForum can be false if there is no masthead, or if it has no forum yet // pMasthead could be NULL if the user has not created one yet if (pWholePage->IsEmpty() || bGotInterface == false) { bSuccess = false; } // now add all the various subcomponents into the whole page xml // add owner of page if (bSuccess) { // if we have a page owner then put their details in, otherwise make // up a pretend user from the ID we were given if (bGotOwner) { bSuccess = pWholePage->AddInside("PAGE-OWNER", &Owner); } else { CTDVString sPretendUserXML = ""; sPretendUserXML << "<USER><USERID>" << iUserID << "</USERID>"; sPretendUserXML << "<USERNAME>Researcher " << iUserID << "</USERNAME></USER>"; bSuccess = pWholePage->AddInside("PAGE-OWNER", sPretendUserXML); } } // there should always be an interface but check anyway if (bSuccess && bGotInterface) { bSuccess = pWholePage->AddInside("H2G2", &Interface); } if (bSuccess && m_InputContext.ParamExists("clip")) { CTDVString sSubject; if (bGotOwner) { Owner.GetUsername(sSubject); } else { sSubject << "U" << iUserID; } bool bPrivate = m_InputContext.GetParamInt("private") > 0; CLink Link(m_InputContext); if ( Link.ClipPageToUserPage("userpage", iUserID, sSubject, NULL, pViewer, bPrivate) ) pWholePage->AddInside("H2G2", &Link); } // if masthead NULL stylesheet should do the default response if (bSuccess && bGotMasthead && (m_InputContext.IncludeUsersGuideEntryInPersonalSpace() || (m_InputContext.GetParamInt("i_uge") == 1))) { bSuccess = pWholePage->AddInside("H2G2", &Masthead); } // add page forum if there is one => this is the forum associated with // the guide enty that is the masthead for this user if (bSuccess && bGotPageForum && (m_InputContext.IncludeUsersGuideEntryForumInPersonalSpace() || (m_InputContext.GetParamInt("i_ugef") == 1))) { bSuccess = pWholePage->AddInside("H2G2", &PageForum); } // add journal if it exists if (bSuccess && bGotJournal) { bSuccess = pWholePage->AddInside("JOURNAL", &Journal); } // add recent posts if they exist, this may add an empty // POST-LIST tag if the user exists but has never posted if (bSuccess && bGotRecentPosts) { bSuccess = pWholePage->AddInside("RECENT-POSTS", &RecentPosts); } // add recent articles if they exist, this may add an empty // ARTICLES-LIST tag if the user exists but has never written a guide entry if (bSuccess && bGotRecentArticles) { bSuccess = pWholePage->AddInside("RECENT-ENTRIES", &RecentArticles); // add the user XML for the owner too if (bGotOwner) { bSuccess = bSuccess && pWholePage->AddInside("RECENT-ENTRIES", &Owner); } } // add recent articles if they exist, this may add an empty // ARTICLES-LIST tag if the user exists but has never had an entry approved if (bSuccess && bGotRecentApprovals) { bSuccess = pWholePage->AddInside("RECENT-APPROVALS", &RecentApprovals); // add the user XML for the owner too if (bGotOwner) { bSuccess = bSuccess && pWholePage->AddInside("RECENT-APPROVALS", &Owner); } } // add recent comments if they exist, this may add an empty // COMMENTS-LIST tag if the user exists but has never posted if (bSuccess && bGotRecentComments) { bSuccess = pWholePage->AddInside("RECENT-COMMENTS", &RecentComments); } if (bSuccess && bGotSubscribedToUsersRecentArticles) { bSuccess = pWholePage->AddInside("RECENT-SUBSCRIBEDARTICLES", &SubscribedUsersArticles); } CTDVString sSiteXML; m_InputContext.GetSiteListAsXML(&sSiteXML); bSuccess = bSuccess && pWholePage->AddInside("H2G2", sSiteXML); if (bGotMasthead && (m_InputContext.IncludeWatchInfoInPersonalSpace() || (m_InputContext.GetParamInt("i_wi") == 1))) { CWatchList WatchList(m_InputContext); bSuccess = bSuccess && WatchList.Initialise(iUserID); bSuccess = bSuccess && pWholePage->AddInside("H2G2",&WatchList); int iSiteID = m_InputContext.GetSiteID(); bSuccess = bSuccess && WatchList.WatchingUsers(iUserID, iSiteID); bSuccess = bSuccess && pWholePage->AddInside("H2G2",&WatchList); } CWhosOnlineObject Online(m_InputContext); bSuccess = bSuccess && Online.Initialise(NULL, 1, true); bSuccess = bSuccess && pWholePage->AddInside("H2G2", &Online); if (bGotMasthead && (m_InputContext.IncludeClubsInPersonalSpace() || (m_InputContext.GetParamInt("i_c") == 1))) { if (pViewer != NULL && pViewer->GetUserID() == iUserID) { CClub Club(m_InputContext); Club.GetUserActionList(iUserID, 0, 20); pWholePage->AddInside("H2G2", &Club); } // Now add all the clubs the user belongs to CCurrentClubs Clubs(m_InputContext); if (bSuccess && Clubs.CreateList(iUserID,true)) { bSuccess = pWholePage->AddInside("H2G2",&Clubs); } } if (bGotMasthead && bSuccess && (m_InputContext.IncludePrivateForumsInPersonalSpace() || (m_InputContext.GetParamInt("i_pf") == 1))) { pWholePage->AddInside("H2G2", "<PRIVATEFORUM/>"); CForum Forum(m_InputContext); int iPrivateForum = 0; if (bGotOwner) { Owner.GetPrivateForum(&iPrivateForum); } Forum.GetThreadList(pViewer, iPrivateForum, 10,0); pWholePage->AddInside("PRIVATEFORUM", &Forum); // Now check to see if the user has alerts set for their private forum if (bGotOwner) { CEmailAlertList Alert(m_InputContext); Alert.GetUserEMailAlertSubscriptionForForumAndThreads(iUserID,iPrivateForum); pWholePage->AddInside("PRIVATEFORUM", &Alert); } } if (bGotMasthead && bSuccess && (m_InputContext.IncludeLinksInPersonalSpace() || (m_InputContext.GetParamInt("i_l") == 1))) { CTDVString sLinkGroup; m_InputContext.GetParamString("linkgroup", sLinkGroup); if (bGotOwner && pViewer != NULL && Owner.GetUserID() == pViewer->GetUserID()) { ManageClippedLinks(pWholePage); } if (bGotOwner) { CLink Link(m_InputContext); bool bShowPrivate = (pViewer != NULL && Owner.GetUserID() == pViewer->GetUserID()); Link.GetUserLinks(Owner.GetUserID(), sLinkGroup, bShowPrivate); pWholePage->AddInside("H2G2", &Link); Link.GetUserLinkGroups(Owner.GetUserID()); pWholePage->AddInside("H2G2", &Link); } } if (bGotMasthead && m_InputContext.IncludeTaggedNodesInPersonalSpace() || (m_InputContext.GetParamInt("i_tn") == 1)) { //Get the Users Crumtrail - all the nodes + ancestors the user is tagged to . CCategory CCat(m_InputContext); if ( bSuccess && CCat.GetUserCrumbTrail(Owner.GetUserID()) ) { bSuccess = pWholePage->AddInside("H2G2",&CCat); } } if (bSuccess && bGotMasthead) { CTDVString sPostCodeXML; CTDVString sNoticeXML; if (m_InputContext.IncludeNoticeboardInPersonalSpace() || (m_InputContext.GetParamInt("i_n") == 1) || m_InputContext.IncludePostcoderInPersonalSpace() || (m_InputContext.GetParamInt("i_p") == 1)) { if (pViewer != NULL) { // Insert the notice board information! CTDVString sPostCodeToFind; if(pViewer->GetPostcode(sPostCodeToFind)) { int iSiteID = m_InputContext.GetSiteID(); CNotice Notice(m_InputContext); if (!Notice.GetLocalNoticeBoardForPostCode(sPostCodeToFind,iSiteID,sNoticeXML,sPostCodeXML)) { sNoticeXML << "<NOTICEBOARD><ERROR>FailedToFindLocalNoticeBoard</ERROR></NOTICEBOARD>"; } } else { //if the user has not entered a postcode then flag an Notice Board error sNoticeXML << "<NOTICEBOARD><ERROR>UserNotEnteredPostCode</ERROR></NOTICEBOARD>"; } } else { sNoticeXML << "<NOTICEBOARD><ERROR>UserNotLoggedIn</ERROR></NOTICEBOARD>"; } if (m_InputContext.IncludeNoticeboardInPersonalSpace() || (m_InputContext.GetParamInt("i_n") == 1)) { bSuccess = pWholePage->AddInside("H2G2",sNoticeXML); } } if (m_InputContext.IncludePostcoderInPersonalSpace() || (m_InputContext.GetParamInt("i_p") == 1)) { // Insert the postcoder if it's not empty if (bSuccess && !sPostCodeXML.IsEmpty()) { bSuccess = bSuccess && pWholePage->AddInside("H2G2",sPostCodeXML); } } } if (m_InputContext.IncludeSiteOptionsInPersonalSpace() || (m_InputContext.GetParamInt("i_so") == 1)) { // Return SiteOption SystemMessageOn if set. if (bSuccess && m_InputContext.IsSystemMessagesOn(m_InputContext.GetSiteID())) { CTDVString sSiteOptionSystemMessageXML = "<SITEOPTION><NAME>UseSystemMessages</NAME><VALUE>1</VALUE></SITEOPTION>"; bSuccess = bSuccess && pWholePage->AddInside("H2G2",sSiteOptionSystemMessageXML); } } /* Mark Howitt 11/8/05 - Removing the civic data from the user page as it is nolonger used by any sites. The only place civic data is used now is on the postcoder page. //include civic data if (bSuccess) { if ( m_InputContext.GetSiteID( ) == 16 ) { CTDVString sActualPostCode; bool bFoundLocalInfo = false; // First check to see if there is a postcode in the URL if (m_InputContext.ParamExists("postcode")) { // Get the postcode and use this to display the noticeboard if (m_InputContext.GetParamString("postcode", sActualPostCode)) { //dont do any validations bFoundLocalInfo = true; } } //next if no postcode variable is included in URL //or if the specified postcode value is invalid //or if the specified postcode value has no entries on the db if (!bFoundLocalInfo) { // No postcode given, try to get the viewing users postcode if we have one. if (pViewer) { if (pViewer->GetPostcode(sActualPostCode)) { if ( sActualPostCode.IsEmpty( ) == false) { //dont do any validations bFoundLocalInfo = true; } } } else { //try session cookie, if any CTDVString sPostCodeToFind; CPostcoder postcoder(m_InputContext); CTDVString sActualPostCode = postcoder.GetPostcodeFromCookie(); if ( !sActualPostCode.IsEmpty() ) { //dont do any validations bFoundLocalInfo = true; } } } if ( bFoundLocalInfo ) { if (!sActualPostCode.IsEmpty()) { bool bHitPostcode = false; CPostcoder cPostcoder(m_InputContext); cPostcoder.MakePlaceRequest(sActualPostCode, bHitPostcode); if (bHitPostcode) { CTDVString sXML = "<CIVICDATA POSTCODE='"; sXML << sActualPostCode << "'/>"; pWholePage->AddInside("H2G2", sXML); bSuccess = pWholePage->AddInside("CIVICDATA",&cPostcoder); } } } } } */ } return bSuccess; }
bool CEditRecentPostBuilder::Build(CWholePage* pPage) { bool bSuccess = InitPage(pPage, "EDIT-RECENT-POST",false); CUser* pViewer = m_InputContext.GetCurrentUser(); if ( !pViewer ) { SetDNALastError("EditRecentPostBuilder", "NotLoggedIn", "User not logged in."); pPage->AddInside("H2G2", GetLastErrorAsXMLString()); return true; } // Check to see if the site is closed bool bSiteClosed = false; if (!m_InputContext.IsSiteClosed(m_InputContext.GetSiteID(),bSiteClosed)) { SetDNALastError("CEditRecentPostBuilder::Build", "FailedGettingSiteDetails", "Failed to get site details."); pPage->AddInside("H2G2", GetLastErrorAsXMLString()); return true; } if (bSiteClosed && !pViewer->GetIsEditor()) { SetDNALastError("CEditRecentPostBuilder::Build", "SiteClosed", "Site is currently closed!!!"); pPage->AddInside("H2G2", GetLastErrorAsXMLString()); return true; } // Initialise edit form // int iPostID = m_InputContext.GetParamInt("PostID"); if (iPostID <= 0) { SetDNALastError("EditRecentPostBuilder", "INPUTPARAMS", "Please supply a valid PostID"); pPage->AddInside("H2G2", GetLastErrorAsXMLString()); return true; } // Get the Guide Entry details // int iH2G2ID = m_InputContext.GetParamInt("H2G2ID"); bool bIsGuideEntryOwner = false; m_ForumPostEditForm.SetPostID( iPostID ); if ( !m_ForumPostEditForm.LoadPostDetails() ) { pPage->AddInside("H2G2",m_ForumPostEditForm.GetLastErrorAsXMLString()); return true; } if (iH2G2ID > 0 && m_InputContext.DoesSiteAllowOwnerHiding(m_ForumPostEditForm.GetSiteID())) { int iOwnerID = 0; int iGuideEntryForumID = 0; //The Owner of the Guide Entry is trying to hide a post CGuideEntry::GetGuideEntryOwner(m_InputContext, iH2G2ID, iOwnerID, iGuideEntryForumID); bIsGuideEntryOwner = (pViewer->GetUserID() == iOwnerID && iGuideEntryForumID == m_ForumPostEditForm.GetForumID()); } else { // Check user has permissions if (!m_ForumPostEditForm.CheckUserCanEditRecentPost()) { SetDNALastError("EditRecentPostBuilder", "CANTEDIT", "Unable to edit post - Invalid permissions/post no longer editable."); pPage->AddInside("H2G2", GetLastErrorAsXMLString()); return true; } } if (m_InputContext.ParamExists("Update")) { CTDVString sSubject, sText; bSuccess = bSuccess && m_InputContext.GetParamString("Subject", sSubject); bSuccess = bSuccess && m_InputContext.GetParamString("Text", sText); // Check content CForumPostEditForm::PostUpdateError errorType; if (m_ForumPostEditForm.ValidatePostDetails(sSubject, sText, errorType)) { // Does it require premoderation? bool bForceModerateAndHide = false; if (errorType == CForumPostEditForm::CONTAINSPROFANITIES) { bForceModerateAndHide = true; } bSuccess = bSuccess && m_ForumPostEditForm.ProcessForumPostUpdate(pViewer,sSubject, sText, NULL, true, bForceModerateAndHide,false); if (bSuccess) { m_ForumPostEditForm.AddStatusMessage("<MESSAGE TYPE='UPDATE-OK'>Post updated successfully</MESSAGE>"); } } } else if ( m_InputContext.ParamExists("Hide") ) { //Hide the entire thread if user is author if (m_ForumPostEditForm.GetUserId() == pViewer->GetUserID() || bIsGuideEntryOwner ) { if ( m_ForumPostEditForm.HidePost(CStoredProcedure::HIDDENSTATUSUSERHIDDEN) ) m_ForumPostEditForm.AddStatusMessage("<MESSAGE TYPE='HIDE-OK'>Post hidden successfully</MESSAGE>"); } else { pPage->AddInside("H2G2",CreateErrorXMLString("EditRecentPostBuilder","Hide","User not author - Hide Failed.")); } } else if ( m_InputContext.ParamExists("UnHide") ) { //Allow UnHide if user is author. if (m_ForumPostEditForm.GetUserId() == pViewer->GetUserID() || bIsGuideEntryOwner) { if ( m_ForumPostEditForm.UnhidePost() ) m_ForumPostEditForm.AddStatusMessage("<MESSAGE TYPE='UNHIDE-OK'>Post unhidden successfully</MESSAGE>"); } else { pPage->AddInside("H2G2",CreateErrorXMLString("EditRecentPostBuilder","Hide","User not author - Hide Failed.")); } } else if (m_InputContext.ParamExists("Cancel")) { m_ForumPostEditForm.Cancel(); } else if ( m_InputContext.ParamExists("Preview") ) { //Validate user-input and setup PostEditForm with preview data. CTDVString sSubject; CTDVString sText; CForumPostEditForm::PostUpdateError errorType; if ( !m_InputContext.GetParamString("Text", sText) || !m_InputContext.GetParamString("Subject",sSubject) ) { SetDNALastError("CEditRecentPost::Build","Invalid Parameters","Invalid parameters provided for Preview"); pPage->AddInside("H2G2",GetLastErrorAsXMLString()); } else if ( m_ForumPostEditForm.ValidatePostDetails(sSubject, sText, errorType) ) { m_ForumPostEditForm.SetPreviewSubject(sSubject); m_ForumPostEditForm.SetPreviewText(sText); } } if (m_ForumPostEditForm.Build()) { pPage->AddInside("H2G2", &m_ForumPostEditForm); } // Add any errors if (m_ForumPostEditForm.ErrorReported()) { pPage->AddInside("H2G2", m_ForumPostEditForm.GetLastErrorAsXMLString()); } return true; }
bool CModerateMediaAssetsBuilder::Build( CWholePage* pWholePage) { InitPage(pWholePage, "MEDIAASSET-MODERATION", true); bool bSuccess = true; // do an error page if not an editor or moderator // otherwise proceed with the process recommendation page CUser* pViewer = m_InputContext.GetCurrentUser(); if (pViewer == NULL || !(pViewer->GetIsEditor() || pViewer->GetIsModerator())) { bSuccess = bSuccess && pWholePage->SetPageType("ERROR"); bSuccess = bSuccess && pWholePage->AddInside("H2G2", "<ERROR TYPE='NOT-EDITOR'>You cannot perform moderation unless you are logged in as an Editor or Moderator.</ERROR>"); return true; } //Process Actions. if ( ! Process(pWholePage,pViewer) ) { SetDNALastError("CModerateMediaAssetsBuilder::Build","Build","Unable to process"); pWholePage->AddInside("H2G2",GetLastErrorAsXMLString()); } //Produce XML for page. // find out if we are processing referrals or not bool bReferrals = m_InputContext.GetParamInt("Referrals") == 1; bool bAlerts = m_InputContext.GetParamInt("Alerts") == 1; bool bLockedItems = m_InputContext.GetParamInt("Locked") == 1 && pViewer->GetIsSuperuser(); bool bHeldItems = m_InputContext.GetParamInt("Held") == 1; int iShow = 10; if ( m_InputContext.ParamExists("show") ) iShow = m_InputContext.GetParamInt("show"); //bool bFastMod = m_InputContext.GetParamInt("fastmod") != 0; //Add Moderation Classes CModerationClasses modclasses(m_InputContext); if ( modclasses.GetModerationClasses() ) bSuccess = bSuccess && pWholePage->AddInside("H2G2",&modclasses); else if ( modclasses.ErrorReported() ) bSuccess && bSuccess && pWholePage->AddInside("H2G2",modclasses.GetLastErrorAsXMLString() ); //Add Moderation Failure - Reasons CModReasons reasons(m_InputContext); if ( reasons.GetModReasons(0) ) bSuccess = bSuccess && pWholePage->AddInside("H2G2",&reasons); //Add Refereee List CRefereeList referees(m_InputContext); if ( referees.FetchTheList() ) bSuccess = bSuccess && pWholePage->AddInside("H2G2",&referees); //Add Site List CTDVString sSiteXML; bSuccess = bSuccess && m_InputContext.GetSiteListAsXML(&sSiteXML, 2); bSuccess = bSuccess && pWholePage->AddInside("H2G2", sSiteXML); CModerateMediaAssets moderate(m_InputContext); if ( !moderate.GetAssets( pViewer->GetUserID(), bAlerts, bReferrals, bLockedItems, bHeldItems, iShow ) ) pWholePage->AddInside("H2G2",moderate.GetLastErrorAsXMLString() ); else pWholePage->AddInside("H2G2",&moderate); TDVASSERT(bSuccess, "CModerateMediaAssetsBuilder::Build() failed"); return bSuccess; }
bool CNewUserDetailsPageBuilder::Build(CWholePage* pWholePage) { // pointer to the xml objects we are going to need CUser* pViewer = NULL; // get or create all the appropriate xml objects // first get the current user object and test that it isn't NULL pViewer = m_InputContext.GetCurrentUser(); TDVASSERT(pViewer != NULL, "CNewUserDetailsPageBuilder::Build() called with NULL current user"); CTDVString sPageError; bool bSuccess = true; bool bUpdateWasValid = true; // make a boolean variable to assess the validity of the submission // If the person is unregistered, show/deal with new password request // Also do this if 'unregcmd' exists as a parameter, so a // registered person can still request a new password. bool bRequest = false; CTDVString sRequestFormCommand = NULL; if (m_InputContext.GetParamString("unregcmd", sRequestFormCommand)) { bRequest = true; } if (bRequest || pViewer == NULL) { CTDVString sMessage; CTDVString sMessageType = ""; bool bSubmission = false; CTDVString sUpdateError = NULL; if (bSuccess && bRequest) { if (sRequestFormCommand.CompareText("Submit")) { bSubmission = true; } } if (bSuccess && bSubmission) { CTDVString sEmail; CTDVString sLoginname; CTDVString sUserid; bUpdateWasValid = bUpdateWasValid && m_InputContext.GetParamString("email", sEmail); bUpdateWasValid = bUpdateWasValid && m_InputContext.GetParamString("loginname", sLoginname); bUpdateWasValid = bUpdateWasValid && m_InputContext.GetParamString("userid", sUserid); while (sUserid.GetLength() > 0 && (sUserid[0] == 'u' || sUserid[0] == 'U' || sUserid[0] == ' ')) { sUserid.RemoveLeftChars(1); } /* if loginname is empty, fall back on userid */ if (bUpdateWasValid && sLoginname.IsEmpty()) { CUser TempUser(m_InputContext); if (TempUser.CreateFromID(atoi(sUserid))) { bUpdateWasValid = TempUser.GetLoginName(sLoginname); } else { bUpdateWasValid = false; } } if (bUpdateWasValid) { CRegisterObject RegObj(m_InputContext); bUpdateWasValid = RegObj.RequestPassword(sLoginname, sEmail); if (bUpdateWasValid) { sMessage = "A new password has been set and is being sent to you via email."; sMessageType = "newpasswordsent"; } else { sMessage = "The username or nickname you entered was not valid, or did not match the email address you provided."; sMessageType = "newpasswordfailed"; } } } bSuccess = InitPage(pWholePage, "USERDETAILS",true,false); if (pViewer != NULL) { pViewer->SetIDNameVisible(); pViewer->SetIDNameEmailVisible(); pWholePage->AddInside("VIEWING-USER", pViewer); } CTDVString formXML; formXML << "<USER-DETAILS-UNREG>"; formXML << "<MESSAGE TYPE='" << sMessageType << "'>" << sMessage << "</MESSAGE>"; formXML << "</USER-DETAILS-UNREG>"; bSuccess = pWholePage->AddInside("H2G2", formXML); } else // We are registered, handle userdetails form { // before anything else find out whether we are dealing with a request to view // the page or a submit request to update the details bool bSubmission = false; CTDVString sFormCommand = NULL; CTDVString sUpdateError; CTDVString sUpdateType; if (m_InputContext.ParamExists("setskin")) { CTDVString sNewSkin; if(m_InputContext.GetParamString("NewSkin", sNewSkin)) { pViewer->SetPrefSkin(sNewSkin); bSuccess = pViewer->UpdateDetails(); bSuccess = bSuccess && m_InputContext.SetSkin(sNewSkin); if (bSuccess) { sUpdateError = "Your new skin has been set"; sUpdateType = "skinset"; } } } // if a submit request then it will have a CGI parameter called 'cmd' // with the value 'submit' if (bSuccess) { if (m_InputContext.GetParamString("cmd", sFormCommand)) { if (sFormCommand.CompareText("Submit")) { bSubmission = true; } } } if ((pViewer != NULL) && pViewer->GetIsBannedFromPosting()) { bUpdateWasValid = false; sUpdateError = "Not allowed"; sUpdateType = "restricteduser"; } if ( bUpdateWasValid && bSubmission && bUpdateWasValid ) { bUpdateWasValid = UpdateUserDetails(pViewer, sUpdateError, sUpdateType); } bSuccess = bSuccess && InitPage(pWholePage, "USERDETAILS",true); // now add the XML for the FORM and its contents int iUserID = pViewer->GetUserID(); CTDVString sUsername; // CTDVString sFirstNames; // CTDVString sLastName; CTDVString sEmail; CTDVString sPrefSkin; int iPrefUserMode; int iPrefForumStyle; CTDVString sPrefXML; CTDVString sSiteSuffix; CTDVString sRegion; // get the users settings, which may have just been updated... bSuccess = bSuccess && pViewer->GetUsername(sUsername); // bSuccess = bSuccess && pViewer->GetFirstNames(sFirstNames); // bSuccess = bSuccess && pViewer->GetLastName(sLastName); bSuccess = bSuccess && pViewer->GetEmail(sEmail); bSuccess = bSuccess && pViewer->GetPrefSkin(&sPrefSkin); bSuccess = bSuccess && pViewer->GetPrefUserMode(&iPrefUserMode); bSuccess = bSuccess && pViewer->GetPrefForumStyle(&iPrefForumStyle); bSuccess = bSuccess && pViewer->GetPrefXML(&sPrefXML); bSuccess = bSuccess && pViewer->GetSiteSuffix(sSiteSuffix); bSuccess = bSuccess && pViewer->GetRegion(sRegion); // construct the XML for the FORM and then insert it inside the body of the page if (bSuccess) { // TODO: is this the only XML we need to output? CTDVString sMessage; CTDVString sMessageType = ""; if (sUpdateError.IsEmpty() && bSubmission) { sMessage = "Your details have been updated"; sMessageType="detailsupdated"; } else { sMessage = sUpdateError; sMessageType = sUpdateType; } // escape all XML sequences in the name fields before showing them in the form CXMLObject::EscapeAllXML(&sUsername); // CXMLObject::EscapeAllXML(&sFirstNames); // CXMLObject::EscapeAllXML(&sLastName); // now build the XML representation of the form for editing user details CTDVString formXML; formXML << "<USER-DETAILS-FORM>"; formXML << "<MESSAGE TYPE='" << sMessageType << "'>" << sMessage << "</MESSAGE>"; formXML << "<USERID>" << iUserID << "</USERID>"; formXML << "<USERNAME>" << sUsername << "</USERNAME>"; // formXML << "<FIRST-NAMES>" << sFirstNames << "</FIRST-NAMES>"; // formXML << "<LAST-NAME>" << sLastName << "</LAST-NAME>"; formXML << "<EMAIL-ADDRESS>" << sEmail << "</EMAIL-ADDRESS>"; formXML << "<REGION>" << sRegion << "</REGION>"; formXML << "<PREFERENCES>" << "<SKIN>" << sPrefSkin << "</SKIN>" << "<USER-MODE>" << iPrefUserMode << "</USER-MODE>" << "<FORUM-STYLE>" << iPrefForumStyle << "</FORUM-STYLE>" << "<SITESUFFIX>" << sSiteSuffix << "</SITESUFFIX>" << "</PREFERENCES>"; formXML << "<SITEPREFERENCES>" << sPrefXML << "</SITEPREFERENCES>"; formXML << "</USER-DETAILS-FORM>"; bSuccess = pWholePage->AddInside("H2G2", formXML); //Insert Regions XML into page if they exist. CTDVString delimit = m_InputContext.GetCurrentSiteOptionString("KeyPhrases","DelimiterToken"); CThreadSearchPhrase tsp(m_InputContext,delimit); if ( bSuccess && tsp.GetSiteKeyPhrasesXML() ) { pWholePage->AddInside("H2G2","<THREADSEARCHPHRASE/>"); pWholePage->AddInside("H2G2/THREADSEARCHPHRASE",&tsp); } } } /* end of 'we are registered user' if */ if (!bSuccess && pWholePage != NULL) { // if haven't been able to produce a page then create a simple error page CTDVString sPageXML = "<ARTICLE>"; sPageXML << "<SUBJECT>Error Page</SUBJECT>"; sPageXML << "<GUIDE><BODY>"; if (sPageError.IsEmpty()) { sPageXML << "User Details Page could not be displayed due to unspecified strangeness"; } else { sPageXML << "User Details Page could not be displayed: " << sPageError; } sPageXML << "</BODY></GUIDE></ARTICLE>"; bSuccess = InitPage(pWholePage, "ERRORPAGE",true,false); bSuccess = bSuccess && pWholePage->AddInside("H2G2", sPageXML); } return bSuccess; }
bool CMorePagesBuilder::Build(CWholePage* pPage) { int iUserID = m_InputContext.GetParamInt("userid"); int iNumShow = m_InputContext.GetParamInt("show"); if (iNumShow == 0) { iNumShow = 25; } int iNumSkipped = m_InputContext.GetParamInt("skip"); if (iNumSkipped <0) { iNumSkipped = 0; } // type is either 1 (approved) 2 (normal) 3 (cancelled) or 4 (normal and approved) int iType = m_InputContext.GetParamInt("type"); if (iType < CArticleList::ARTICLELISTTYPE_FIRST || iType > CArticleList::ARTICLELISTTYPE_LAST) { iType = CArticleList::ARTICLELISTTYPE_APPROVED; } // See if we've been given a specified type to search for int iGuideType = 0; if (m_InputContext.ParamExists("guidetype")) { iGuideType = m_InputContext.GetParamInt("guidetype"); } CUser* pViewingUser = m_InputContext.GetCurrentUser(); // all the XML objects we need to build the page CUser PageOwner(m_InputContext); // Now initialise those objects that need it. bool bPageSuccess = false; bPageSuccess = InitPage(pPage, "MOREPAGES",true); TDVASSERT(bPageSuccess, "Failed to initialise WholePage in MorePagesBuilder"); bool bSuccess = bPageSuccess; if ((iType == CArticleList::ARTICLELISTTYPE_CANCELLED) && ((pViewingUser == NULL) || (pViewingUser->GetUserID() != iUserID))) { bSuccess = false; pPage->SetError("You cannot view the cancelled entries of another user"); } // now get the owner of the guide entries and put their xml in the page if (bSuccess) { bSuccess = PageOwner.CreateFromID(iUserID); bSuccess = bSuccess && pPage->AddInside("H2G2", "<PAGE-OWNER></PAGE-OWNER>"); bSuccess = bSuccess && pPage->AddInside("PAGE-OWNER", &PageOwner); } CTDVString sXML = "<ARTICLES USERID='"; sXML << iUserID << "' WHICHSET='" << iType << "'/>"; bSuccess = bSuccess && pPage->AddInside("H2G2", sXML); bSuccess = bSuccess && AddArticlesToPage(iType,pPage,iUserID, iNumShow, iNumSkipped,iGuideType); // add the XML for the owner of the articles bSuccess = bSuccess && pPage->AddInside("ARTICLES", &PageOwner); CTDVString sSiteXML; m_InputContext.GetSiteListAsXML(&sSiteXML); bSuccess = bSuccess && pPage->AddInside("H2G2", sSiteXML); // OK, I think that's us done. return bPageSuccess; }
/********************************************************************************* bool CVotePageBuilder::CreateNewVote() Author: Mark Howitt Created: 20/05/2004 Inputs: - Outputs: - Returns: true if ok, false if not Purpose: Creates a new vote for a given club or noticeboard *********************************************************************************/ bool CVotePageBuilder::CreateNewVote() { // Set the action flag m_pPage->AddInside("VOTING-PAGE","<ACTION>new</ACTION>"); // The user must be logged in before we can do this! CUser* pUser = m_InputContext.GetCurrentUser(); if (pUser == NULL) { m_pPage->SetError("UserNotLoggedIn"); return false; } // Get the basic info if (!GetCommonInfo(false)) { return false; } // First check the Objectid to atach the vote to. m_iObjectID = m_InputContext.GetParamInt("objectid"); if (m_iObjectID <= 0) { m_pPage->SetError("NoObjectID"); return false; } // Get the type from the url m_iType = m_InputContext.GetParamInt("type"); // Check to make sure the current user is the owner of the club or that they are an editor bool bIsAllowed = pUser->GetIsEditor() || pUser->GetIsSuperuser(); if (!bIsAllowed) { // Check to see if the user is a member of a club or thread owner m_CurrentVote.IsUserAuthorisedToCreateVote(m_iObjectID,m_iType,pUser->GetUserID(),bIsAllowed); if (!bIsAllowed) { m_pPage->SetError("UserNotAuthorised"); return false; } } // Get the closing date for the vote int iDay = m_InputContext.GetParamInt("day"); int iMonth = m_InputContext.GetParamInt("month"); int iYear = m_InputContext.GetParamInt("year"); m_tClosingDate = NULL; CTDVString sDate; if (iDay > 0 && iMonth > 0 && iYear > 0) { m_tClosingDate.SetDate(iYear,iMonth,iDay); } if (m_tClosingDate > m_tClosingDate.GetCurrentTime()) { sDate << (-m_tClosingDate.DaysElapsed()); } // Now see if we want to do a simple yes no vote m_bSimpleYesNo = m_InputContext.GetParamInt("useyesno") > 0 ? true : false; // Now create the new object m_iVoteID = m_CurrentVote.CreateVote(m_iType,m_tClosingDate,m_iOwnerID,m_bSimpleYesNo); // Make sure the vote id is valid! if (m_iVoteID <= 0) { m_pPage->SetError("FailedToCreateVote"); return false; } CTDVString sXML; CDBXMLBuilder XML; XML.Initialise(&sXML); XML.AddIntTag("VOTEID",m_iVoteID); XML.OpenTag("OBJECT",true); if (m_iType == VOTETYPE_CLUB) { XML.AddAttribute("TYPE","CLUB"); } else if (m_iType == VOTETYPE_NOTICE) { XML.AddAttribute("TYPE","NOTICE"); } XML.AddIntAttribute("ID",m_iObjectID,true); XML.CloseTag("OBJECT"); XML.AddTag("CLOSINGDATE",sDate); m_CurrentVote.GetCreatedDate(m_tDateCreated); XML.AddDateTag("CREATEDDATE",m_tDateCreated,true); // Now upsate the ClubVotes table with the new vote m_CurrentVote.AddVoteToClubTable(m_iVoteID,m_iObjectID,&m_sVoteName); XML.AddTag("VOTENAME",m_sVoteName); // Put the XML into the page and return return m_pPage->AddInside("VOTING-PAGE",sXML); }
/********************************************************************************* bool CVotePageBuilder::GetCommonInfo(bool bGetVoteInfo) Author: Mark Howitt Created: 21/05/2004 Inputs: bGetVoteInfo - A flag that when true includes the info on the current vote id bNeedResponseInfo - true to include <RESPONSE> element. response cgi parameter must be set Outputs: - Returns: - Purpose: Gets all the common information on the current vote. *********************************************************************************/ bool CVotePageBuilder::GetCommonInfo(bool bGetVoteInfo, bool bNeedResponseInfo) { // Get the current user CUser* pViewingUser = m_InputContext.GetCurrentUser(); m_iUserID = 0; if (pViewingUser) { // Get the id of the current viewing user m_iUserID = pViewingUser->GetUserID(); } // Get the UID For the current user. m_InputContext.GetBBCUIDFromCookie(m_sBBCUID); // Initialise the XML Builder ready to create the XML CStoredProcedure SP; CTDVString sXML; CDBXMLBuilder XML; XML.Initialise(&sXML,&SP); // Start with the USER info bool bOk = XML.OpenTag("USER"); bOk = bOk && XML.AddIntTag("USERID",m_iUserID); // Get the user name if we have a valid UserID if (m_iUserID > 0) { m_InputContext.InitialiseStoredProcedureObject(&SP); if (!SP.GetUserDetailsFromID(m_iUserID,m_InputContext.GetSiteID())) { TDVASSERT(false, "Failed to find user name from id"); } else { bOk = bOk && XML.DBAddTag("USERNAME",NULL,true,true,&m_sUserName); bOk = bOk && XML.DBAddTag("FIRSTNAMES",NULL,false); bOk = bOk && XML.DBAddTag("LASTNAME",NULL,false); bOk = bOk && XML.DBAddTag("AREA",NULL,false); bOk = bOk && XML.DBAddTag("TITLE",NULL,false); bOk = bOk && XML.DBAddTag("SITESUFFIX",NULL,false); bOk = bOk && XML.DBAddIntTag("JOURNAL", NULL, false); bOk = bOk && XML.DBAddIntTag("STATUS", NULL, false); bOk = bOk && XML.DBAddIntTag("TAXONOMYNODE", NULL, false); bOk = bOk && XML.DBAddIntTag("ACTIVE"); //get the groups to which this user belongs to CTDVString sGroupXML; bOk = bOk && m_InputContext.GetUserGroups(sGroupXML, m_iUserID); sXML = sXML + sGroupXML; } } // Close and add to the page bOk = bOk && XML.CloseTag("USER"); bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); // Check to if we require vote info if (bOk && bGetVoteInfo) { // First get the vote ID m_iVoteID = m_InputContext.GetParamInt("voteid"); // Now setup the Vote Object if (!m_CurrentVote.GetVote(m_iVoteID)) { m_pPage->SetError("InvalidVoteID"); return false; } // Get the type from the url m_iType = m_InputContext.GetParamInt("type"); sXML.Empty(); sXML << "<VOTETYPE>" << m_iType << "</VOTETYPE>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); // First check to see if the user has already voted! // If the user id is 0 then we need to do a cookie check! bool bAlreadyVoted = false; if (!m_CurrentVote.HasUserAlreadyVoted(m_iVoteID,m_iUserID,m_sBBCUID,bAlreadyVoted)) { m_pPage->SetError("FailedCheckingAlreadyVoted"); return false; } sXML.Empty(); sXML << "<ALREADYVOTED>" << bAlreadyVoted << "</ALREADYVOTED>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); // Check to see if the current vote is closed? m_bVoteClosed = false; if (!m_CurrentVote.IsVoteClosed(m_bVoteClosed)) { m_pPage->SetError("DontKnowIfVoteClosed"); return false; } sXML.Empty(); sXML << "<VOTECLOSED>" << m_bVoteClosed << "</VOTECLOSED>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); // Get the details from the vote m_CurrentVote.GetVoteName(m_sVoteName); sXML.Empty(); sXML << "<VOTEID>" << m_iVoteID << "</VOTEID>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); sXML.Empty(); sXML << "<VOTENAME>" << m_sVoteName << "</VOTENAME>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); // Get the club id for the vote m_iObjectID = 0; if (!m_CurrentVote.GetObjectIDFromVoteID(m_iVoteID,m_iType,m_iObjectID)) { m_pPage->SetError("InvalidObjectID"); return false; } // Output the correct type of XML if (m_iType == VOTETYPE_CLUB) { sXML.Empty(); sXML << "<OBJECT TYPE='CLUB' ID='" << m_iObjectID << "'/>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); // Get the Club OwnerID CClub Club(m_InputContext); Club.InitialiseViaClubID(m_iObjectID); m_iOwnerID = Club.GetOwnerTeamID(); } else if (m_iType == VOTETYPE_NOTICE) { // Get the NodeID from the ThreadID // Copy the Object id passed in through th eurl into the threadid varaible as the objectid // is actually the threadid for the notice being voted on. m_iThreadID = m_iObjectID; CNotice Notice(m_InputContext); Notice.GetNodeIDFromThreadID(m_iThreadID,m_InputContext.GetSiteID(),m_iObjectID); CTDVString sPostCode; m_InputContext.GetParamString("postcode",sPostCode); sXML.Empty(); sXML << "<OBJECT TYPE='NOTICE' ID='" << m_iObjectID << "' POSTCODE='" << sPostCode << "'/>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); } else { m_pPage->SetError("InvalidObjectID"); return false; } if (bNeedResponseInfo) { // Get the users response if (!m_InputContext.ParamExists("response")) { m_pPage->SetError("NoResponse"); return false; } m_iResponse = m_InputContext.GetParamInt("response"); sXML.Empty(); sXML << "<RESPONSE>" << m_iResponse << "</RESPONSE>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); } // Now get the date the vote was created CTDVString sDate; m_CurrentVote.GetCreatedDate(m_tDateCreated); m_tDateCreated.GetRelativeDate(sDate); sXML.Empty(); sXML << "<DATECREATED>" << sDate << "</DATECREATED>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); // Now get the closing date for the vote sDate.Empty(); m_CurrentVote.GetClosingDate(m_tClosingDate); if (m_tClosingDate != NULL) { sDate << (-m_tClosingDate.DaysElapsed()); } sXML.Empty(); sXML << "<CLOSINGDATE>" << sDate << "</CLOSINGDATE>"; bOk = bOk && m_pPage->AddInside("VOTING-PAGE",sXML); } // Set the error message if something went wrong. if (!bOk) { m_pPage->SetError("FailedAddingXMLToPage"); } // Return Ok return bOk; }
bool CPoll::LoadCurrentUserVote(int & nUserVote) { // Check what user voted (if we have a user...) CUser* pUser = m_InputContext.GetCurrentUser(); if (!m_bAllowAnonymousRating) { if(!pUser) // User not logged in { nUserVote = -1; return true; } } CStoredProcedure SP; if(!m_InputContext.InitialiseStoredProcedureObject(&SP)) { TDVASSERT(false, "CPoll::LoadCurrentUserVote m_InputContext.InitialiseStoredProcedureObject failed"); return false; } int nPollID = GetPollID(); if (!m_bAllowAnonymousRating) { if(!SP.GetUserVotes(nPollID, pUser->GetUserID())) { TDVASSERT(false, "CPoll::LoadCurrentUserVote SP.GetUserVotes failed"); return false; } } else { if(pUser) // If logged in get the user id? { if(!SP.GetUserVotes(nPollID, pUser->GetUserID())) { TDVASSERT(false, "CPoll::LoadCurrentUserVote SP.GetUserVotes failed"); return false; } } else { CTDVString sBBCUID = ""; // Get the UID For the current user. m_InputContext.GetBBCUIDFromCookie(sBBCUID); if(!SP.GetBBCUIDVotes(nPollID, sBBCUID)) { TDVASSERT(false, "CPoll::LoadCurrentUserVote SP.GetBBCUIDVotes failed"); return false; } } } // Read in user vote (if we have one!) if(!SP.IsEOF()) { nUserVote = SP.GetIntField("Response"); } else { // User has not voted nUserVote = -1; } return true; }
bool CFrontPageEditor::Build(CWholePage* pPageXML) { InitPage(pPageXML, "FRONTPAGE-EDITOR", true); CPageBody PageBody(m_InputContext); CStoredProcedure SP; m_InputContext.InitialiseStoredProcedureObject(&SP); int iSiteID = m_InputContext.GetSiteID(); bool bFrontPagePreview = false; bool bErrorsFound = false; if(m_InputContext.GetIsInPreviewMode()) { // flag it up if we're editing a MessageBoard config version // using the preview version will have //url: /FrontPageEditor?_previewmode=1 bFrontPagePreview = true; } CUser* pViewer = m_InputContext.GetCurrentUser(); if (pViewer == NULL || !pViewer->GetIsEditor()) { pPageXML->SetPageType("ERROR"); pPageXML->AddInside("H2G2", "<ERROR TYPE='NOT-EDITOR'>You cannot administer a site unless you are logged in as an Editor.</ERROR>"); return true; } // Check to see if we're previewing or storing the page if (m_InputContext.ParamExists("Preview") || m_InputContext.ParamExists("Storepage")) { CTDVString sText; m_InputContext.GetParamString("bodytext", sText); CTDVString sDate; m_InputContext.GetParamString("date", sDate); CTDVString sError = CXMLObject::ParseXMLForErrors(sText); if (!sError.IsEmpty()) { CTDVString sXML = "<FRONTPAGE-PREVIEW-PARSEERROR>"; sXML << sError << "</FRONTPAGE-PREVIEW-PARSEERROR>"; pPageXML->AddInside("H2G2",sXML); bErrorsFound = true; } else { CTDVString sXML = "<ARTICLE>"; sXML << sText << "</ARTICLE>"; pPageXML->AddInside("H2G2", sXML); if (m_InputContext.ParamExists("Storepage")) { CTDVDateTime dDate; if (sDate.IsEmpty() || dDate.ParseDateTime(sDate)) { // Actually store it here... CStoredProcedure SP; m_InputContext.InitialiseStoredProcedureObject(&SP); if(!bFrontPagePreview) { SP.UpdateFrontpage(iSiteID, "frontpage", sText, pViewer->GetUserID(), sDate, NULL); } else { // Setup and initialise the frontpagelayout object CFrontPageLayout FPL(m_InputContext); if (!FPL.InitialisePageBody(m_InputContext.GetSiteID(),true)) { // Get the last error from the object pPageXML->AddInside("H2G2","<ERROR TYPE='FRONTPAGEERROR'>" + FPL.GetLastErrorMessage() + "</ERROR>"); bErrorsFound = true; } else { // Now set the new text and update the preview if (!FPL.SetFrontPageBodyText(sText)) { // Get the last error from the object pPageXML->AddInside("H2G2","<ERROR TYPE='BODYUPDATE'>" + FPL.GetLastErrorMessage() + "</ERROR>"); bErrorsFound = true; } // Update the preview bool bEditedByAnotherUser = false; CTDVString sEditKey; m_InputContext.GetParamString("EditKey", sEditKey); if (!FPL.UpdateFrontPagePreview(pViewer->GetUserID(), sEditKey, bEditedByAnotherUser) || bEditedByAnotherUser) { // We've either had an error or it's being edited by another user! Get the error from the objct pPageXML->AddInside("H2G2","<ERROR TYPE='UPDATEPREVIEW'>" + FPL.GetLastErrorMessage() + "</ERROR>"); bErrorsFound = true; } } } } else { CTDVString sXML = "<FRONTPAGE-PREVIEW-PARSEERROR>The date you supplied was faulty.</FRONTPAGE-PREVIEW-PARSEERROR>"; pPageXML->AddInside("H2G2",sXML); bErrorsFound = true; } } } CTDVString sSkin; m_InputContext.GetParamString("skin", sSkin); int iRegistered = 0; if (m_InputContext.ParamExists("registered")) { iRegistered = 1; } AddEditForm(pPageXML, "", sText, sSkin, sDate, iRegistered); } else { CTDVString sPageType; sPageType << "xmlfrontpage"; if(bFrontPagePreview) { // get xmlfrontpagepreview instead sPageType << "preview"; } PageBody.Initialise(sPageType, iSiteID); CTDVString sSubject; CTDVString sBody; PageBody.GetSubject(&sSubject); PageBody.GetBodyText(&sBody); AddEditForm(pPageXML, sSubject, sBody, "", "", 1); PageBody.AddInside("ARTICLE", "<PREVIEWREGISTERED>1</PREVIEWREGISTERED>"); pPageXML->AddInside("H2G2", &PageBody); } // Check to see if we've been given a redirect? Only do this if we've had no errors! if (!bErrorsFound) { if (CheckAndUseRedirectIfGiven(pPageXML)) { // return true as we've done the redirect, nothing else should be done! return true; } } return true; }
bool CMessageBoardAdmin::ActivateBoard(CTDVString& sRedirect) { int iSiteID = m_InputContext.GetSiteID(); //xml frontpage preview CFrontPageLayout FPLayout(m_InputContext); if(!FPLayout.MakePreviewItemActive(iSiteID)) { return SetDNALastError("CMessageBoardAdmin","ActivateBoard()","Failed to make active FrontPageLayout preview"); } //topics int iEditorID = 0; CUser* pUser = m_InputContext.GetCurrentUser(); if ( pUser && pUser->GetIsEditor() ) { iEditorID = pUser->GetUserID( ); } if (iEditorID == 0) { return SetDNALastError("CMessageBoardAdmin","ActivateBoard()","Failed to make active FrontPageLayout preview- invalid user"); } CTopic Topic(m_InputContext); if(!Topic.MakePreviewTopicsActiveForSite(iSiteID, iEditorID)) { return SetDNALastError("CMessageBoardAdmin","ActivateBoard()","Failed to make active Topic preview"); } // Topic Elements CFrontPageTopicElement TopicElement(m_InputContext); if (!TopicElement.MakePreviewTopicFrontPageElementsActive(iSiteID,iEditorID)) { return SetDNALastError("CMessageBoardAdmin","ActivateBoard","Failed to make the TopicElements Active"); } // Setup Forum Opening And Closing Times if ( !SetupTopicsForumOpeningAndClosingTimes(CTopic::TS_LIVE, iSiteID)) { return SetDNALastError("CMessageBoardAdmin","ActivateBoard","Failed to Setup Forum Opening And Closing Times"); } //text boxes CTextBoxElement TBElem(m_InputContext); if(!TBElem.MakePreviewTextBoxesActive(iSiteID,iEditorID)) { return SetDNALastError("CMessageBoardAdmin", "ActivateBoard()", "Failed to make active TextBoxElements preview"); } //promos CMessageBoardPromo MBPromo(m_InputContext); if(!MBPromo.MakePreviewBoardPromosActive(iSiteID,iEditorID)) { return SetDNALastError("CMessageBoardAdmin", "ActivateBoard()", "Failed to make active MessageBoardPromo preview"); } // Site Config CSiteConfigPreview SiteConfigPreview(m_InputContext); if (!SiteConfigPreview.MakePreviewSiteConfigActive(iSiteID)) { return SetDNALastError("CMessageBoardAdmin", "ActivateBoard()", "Failed to make site config active!"); } // reset the values of MessageBoardAdmin if(!UpdateEveryAdminStatusForSite(AS_UNREAD)) { return SetDNALastError("CMessageBoardAdmin", "ActivateBoard()", "Failed to reset the values of MessageBoard Admin status by siteid"); } sRedirect << "MessageBoardAdmin?cmd=display"; // create a cursory bit of XML if (!CreateFromXMLText("<BOARDACTIVATED>1</BOARDACTIVATED>")) { return false; } return true; }
bool CSSOBuilder::UserNewRegister(bool bFirstTime, bool bCreateXML, bool bSynchronise ) { CUser* pUser = m_InputContext.GetCurrentUser(); //there should be a user because they have just logged in! if (pUser == NULL) { return ErrorMessage("NOTSIGNEDIN","The user was not signed in"); } //user has logged in successfully from the inputcontext and actually if (pUser->IsUserLoggedIn()) { if ( bSynchronise ) { //Synchronisation with SSO is done on creation of new user in DNA. //Synchronisation will also be done in CRipley::HandleRequest() if s_sync=1 specified. //Could have a flag on User indicating that it has been synchronised. if ( !pUser->IsSynchronised() ) { pUser->SynchroniseWithProfile(false); } } if ( bCreateXML ) { CTDVString sPassThrough, sURLParams; GetPassThrough(sPassThrough,sURLParams); CTDVString sNewRegister = "<NEWREGISTER STATUS='LOGGEDIN'>"; if (!sPassThrough.IsEmpty()) { sNewRegister << sPassThrough; } sNewRegister << "<USERID>" << pUser->GetUserID() << "</USERID>"; sNewRegister << "<FIRSTTIME>"; if (bFirstTime) { sNewRegister << "1"; } else { sNewRegister << "0"; } sNewRegister << "</FIRSTTIME></NEWREGISTER>"; m_pPage->AddInside("H2G2",sNewRegister); } // Now set the h2g2 cookie if they are an editor so that // the perl tools will work. CTDVString sCookie; if (pUser->GetIsEditor() && pUser->GetCookie(sCookie)) { /* CTDVString sXML = "<SETCOOKIE><COOKIE>"; sXML << sCookie << "</COOKIE>\n"; sXML << "</SETCOOKIE>"; m_pPage->AddInside("H2G2",sXML); */ //declare cookie instance (can be more than one) CXMLCookie oXMLCookie ("", sCookie, "", false ); //add to page object m_pPage->SetCookie( oXMLCookie ); } } else { return ErrorMessage("NOTLOGGEDIN","The user was not logged in"); } return true; }
bool CSiteConfig::UpdateConfig(CInputContext& inputContext, bool& bMultiStepReady) { bool bOK = true; if (!Initialise()) { return false; } // Initialise this object's underlying XML structure if (!CreateEditConfig()) { SetDNALastError("CSiteConfig","UpdateConfig","Failed to construct XML"); bOK = false; } CUser* pViewer = inputContext.GetCurrentUser(); if (pViewer == NULL || !pViewer->GetIsEditorOnAnySite() ) { SetDNALastError("CSiteConfig","UpdateConfig","You cannot administer a site unless you are logged in as an Editor"); bOK = false; } CMultiStep Multi(m_InputContext, "SITECONFIG"); if (!Multi.ProcessInput() ) { CopyDNALastError("CSiteConfig",Multi); bOK = false; } CStoredProcedure SP; m_InputContext.InitialiseStoredProcedureObject(&SP); bMultiStepReady = false; if (bOK && Multi.ReadyToUse()) { CTDVString sSiteConfigXML; bOK = bOK && Multi.GetAllElementsAsXML(sSiteConfigXML); //Ensure Site Config is enclosed in <SITECONFIG> element if ( sSiteConfigXML.Left(12) != "<SITECONFIG>" ) { sSiteConfigXML = "<SITECONFIG>" + sSiteConfigXML + "</SITECONFIG>"; } // Check it can be parsed CXMLTree* pCurrentConfig = CXMLTree::Parse(sSiteConfigXML); if ( pCurrentConfig == NULL ) { return SetDNALastError("CSiteConfig","UpdateConfig","Failed to create a tree from the current site config"); } CTDVString sEditKey; m_InputContext.GetParamString("EditKey",sEditKey); std::vector<int> vSites; pViewer->GetSitesUserIsEditorOf(pViewer->GetUserID(),vSites); //Get List of sites to update std::vector<int> vSitesToUpdate; for ( int i = 0; i < m_InputContext.GetParamCount("siteId"); ++i ) vSitesToUpdate.push_back( m_InputContext.GetParamInt("siteId",i)); //Update current site if none specified. if ( vSitesToUpdate.size() == 0 ) vSitesToUpdate.push_back(m_InputContext.GetSiteID()); // Handle update of multiple sites. for ( std::vector<int>::iterator iter = vSitesToUpdate.begin(); iter != vSitesToUpdate.end(); ++iter ) { int iSiteId = *iter; //Check user is superuser / editor on site concerned. std::vector<int>::iterator itereditor = std::find(vSites.begin(),vSites.end(), iSiteId); if ( pViewer->GetIsSuperuser() || itereditor != vSites.end() ) { if ( !SetSiteConfig(&SP,iSiteId,sSiteConfigXML,sEditKey) ) { AddInside("SITECONFIG-EDIT",GetLastErrorObject()); } } else { CTDVString sShortName; m_InputContext.GetShortName(sShortName, iSiteId); AddInside("SITECONFIG-EDIT",CreateErrorXMLString("CSiteConfig","NOT-EDITOR","You cannot administer site " + sShortName + " unless you are logged in as an Editor")); } } bMultiStepReady = bOK; } //else //{ // bOK = false; // if ( !ErrorReported() ) // SetDNALastError("CSiteConfig","UpdateConfig","Unable to apply edits. The XML maybe poorly formed."); //} if ( Multi.ErrorReported() ) { CopyDNALastError("CSiteConfig",Multi); bOK = false; } // Add the multistep data, even if an error has occurred CTDVString sXML = Multi.GetAsXML(); AddInside("SITECONFIG-EDIT",sXML); return bOK; }
bool CEditReviewForumBuilder::Build(CWholePage* pPage) { CEditReviewForumForm mForm(m_InputContext); if(!InitPage(pPage, "EDITREVIEW", true)) { return false; } CTDVString sMode; m_InputContext.GetParamString("mode", sMode); if (sMode.GetLength() > 0) { pPage->SetAttribute("H2G2", "MODE", sMode); } //check that they have the privileges CUser* pUser = m_InputContext.GetCurrentUser(); if (pUser == NULL || !pUser->GetIsEditor()) { pPage->AddInside("H2G2","<EDITREVIEWFORM><ERROR TYPE='NOEDIT'>Current User does not have permission to edit the Review Forum</ERROR></EDITREVIEWFORM>"); return true; } CTDVString sAction = "Edit"; if (m_InputContext.ParamExists("action")) { m_InputContext.GetParamString("action",sAction); } if (sAction.CompareText("Update")) { int iReviewForumID = 0; if (m_InputContext.ParamExists("id")) { iReviewForumID = m_InputContext.GetParamInt("id"); } else { pPage->AddInside("H2G2","<EDITREVIEWFORM><ERROR TYPE='BADPARAM'>The parameters are invalid</ERROR></EDITREVIEWFORM>"); return true; } CTDVString sName; CTDVString sURL; bool bRecommendable = false; int iIncubateTime = 0; m_InputContext.GetParamString("name",sName); m_InputContext.GetParamString("url",sURL); if (m_InputContext.ParamExists("recommend")) { if (m_InputContext.GetParamInt("recommend") == 1) { bRecommendable = true; iIncubateTime = m_InputContext.GetParamInt("incubate"); } else { bRecommendable = false; } if (!mForm.RequestUpdate(iReviewForumID,sName,sURL,bRecommendable,iIncubateTime,m_InputContext.GetSiteID())) { pPage->AddInside("H2G2","<EDITREVIEWFORM><ERROR TYPE='UPDATE'>Error occured while updating</ERROR></EDITREVIEWFORM>"); return true; } //sitedata needs to be update for updates m_InputContext.SiteDataUpdated(); m_InputContext.Signal("/Signal?action=recache-site"); } else { pPage->AddInside("H2G2","<EDITREVIEWFORM><ERROR TYPE='BADPARAM'>The parameters are invalid</ERROR></EDITREVIEWFORM>"); return true; } } //we should have a blank form and an add button else if (sAction.CompareText("AddNew")) { pPage->AddInside("H2G2","<EDITREVIEWFORM><BLANKFORM></BLANKFORM></EDITREVIEWFORM>"); return true; } else if (sAction.CompareText("DoAddNew")) { CTDVString sName; CTDVString sURL; bool bRecommendable = false; int iIncubateTime = 0; int iH2G2ID = 0; m_InputContext.GetParamString("name",sName); m_InputContext.GetParamString("url",sURL); if (m_InputContext.ParamExists("recommend")) { if (m_InputContext.GetParamInt("recommend") == 1) { bRecommendable = true; iIncubateTime = m_InputContext.GetParamInt("incubate"); } else { bRecommendable = false; } if (!mForm.DoAddNew(sName,sURL,bRecommendable,iIncubateTime,m_InputContext.GetSiteID(),pUser->GetUserID() )) { pPage->AddInside("H2G2","<EDITREVIEWFORM><ERROR TYPE='UPDATE'>Error occured while updating</ERROR></EDITREVIEWFORM>"); return true; } //sitedata needs to be update for updates m_InputContext.SiteDataUpdated(); m_InputContext.Signal("/Signal?action=recache-site"); } else { pPage->AddInside("H2G2","<EDITREVIEWFORM><ERROR TYPE='BADPARAM'>The parameters are invalid</ERROR></EDITREVIEWFORM>"); return true; } } else //sAction = "edit" { int iReviewForumID = 0; if (m_InputContext.ParamExists("id")) { iReviewForumID = m_InputContext.GetParamInt("id"); } else { pPage->AddInside("H2G2","<EDITREVIEWFORM><ERROR TYPE='BADPARAM'>The parameters are invalid</ERROR></EDITREVIEWFORM>"); return true; } if (!mForm.CreateFromDB(iReviewForumID,m_InputContext.GetSiteID())) { pPage->AddInside("H2G2","<EDITREVIEWFORM><ERROR TYPE='VIEW'>Error occured while creating from database</ERROR></EDITREVIEWFORM>"); return true; } } pPage->AddInside("H2G2",&mForm); return true; }