Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
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;

}