/********************************************************************************* 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 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 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 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 CFixExtraInfoBuilder::Build(CWholePage* pPage) { m_pPage = pPage; InitPage(m_pPage, "FIXEXTRAINFO",true); CUser* pViewer = m_InputContext.GetCurrentUser(); //This builder can only be used by a logged in user if (pViewer == NULL) { m_pPage->SetError("NULL viewer in CFixExtraInfoBuilder::Build()"); return true; } // Is the user mighty enough? if (!pViewer->GetIsSuperuser()) { m_pPage->SetError("User doesn't have the necessary privileges"); return true; } int ih2g2id = m_InputContext.GetParamInt("h2g2id"); int iclubid = m_InputContext.GetParamInt("clubid"); int iType = m_InputContext.GetParamInt("type"); bool bUpdate = m_InputContext.ParamExists("update"); if (iclubid > 0) { CClub Club(m_InputContext); if (Club.InitialiseViaClubID(iclubid,true)) { ih2g2id = Club.GetArticleID(); } else { m_pPage->SetError("failed to initialise club"); return true; } } // We need a valid h2g2id at this point if (ih2g2id <= 0) { m_pPage->SetError("invalid params"); return true; } CGuideEntry Guide(m_InputContext); if (!Guide.Initialise(ih2g2id,m_InputContext.GetSiteID(), pViewer, true,true,true)) { m_pPage->SetError("Failed to initialise using h2g2id"); return true; } CExtraInfo ExtraInfo; Guide.GetExtraInfo(ExtraInfo); CTDVString sOriginalExtraInfo; ExtraInfo.GetInfoAsXML(sOriginalExtraInfo); int iOriginalStatus = Guide.GetStatus(); int iStatus = iOriginalStatus; int iOriginalType = Guide.GetType(); if (!Guide.IsDeleted()) { // Do we need to change the status of the article? Yes, if it was written by the right people // Scan the EXTRAINFO for group information, and if the "BBCStaff" group is found, it's // an official article, so change the status to 1 CTDVString sExtraInfo; ExtraInfo.GetInfoAsXML(sExtraInfo); CXMLTree* pTree = CXMLTree::Parse(sExtraInfo); if (pTree != NULL) { CXMLTree* pNode = pTree->FindFirstTagName("GROUP"); while (pNode != NULL) { CTDVString sValue; pNode->GetAttribute("NAME",sValue); if (sValue.CompareText("BBCStaff")) { iStatus = 1; } pNode = pNode->FindNextTagNode("GROUP"); } delete pTree; } } // No longer need the <EDITOR> tag in extrainfo ExtraInfo.RemoveInfoItem("EDITOR"); if (!Guide.IsTypeOfClub()) { // If it has a <REASON> tag, get ride of it ExtraInfo.RemoveInfoItem("REASON"); // Regenerate the Autodescription tag CTDVString sBodyText; Guide.GetBody(sBodyText); ExtraInfo.GenerateAutoDescription(sBodyText); } else { // It's a club CTDVString sReasonXML; if (ExtraInfo.GetInfoItem("REASON", sReasonXML)) { // Move <REASON> tag from Extrainfo to inside the <GUIDE> tag of the body ExtraInfo.RemoveInfoItem("REASON"); if (!Guide.AddInside("GUIDE",sReasonXML)) { m_pPage->SetError("unable to add REASON to guide"); return true; } CTDVString sBodyText; Guide.GetBody(sBodyText); if (!Guide.UpdateBody(sBodyText)) { m_pPage->SetError("unable to update body of guide"); return true; } } } if (bUpdate) { // Update the entry's extrainfo field in the DB if (!Guide.UpdateExtraInfoEntry(ExtraInfo)) { m_pPage->SetError("unable to update guide extra info"); return true; } // Update the entry's type field in the DB, if necessary if (iType > 0) { if (!Guide.UpdateType(iType)) { m_pPage->SetError("unable to update guide type value"); return true; } } // Update the entry's status field in the DB if (!Guide.UpdateStatus(iStatus)) { m_pPage->SetError("unable to update the status"); return true; } m_pPage->AddInside("H2G2","<EXTRAINFOUPDATED/>"); } else { // Don't update the database, just show the original and new settings m_pPage->AddInside("H2G2","<ORIGINALSETTINGS/>"); m_pPage->AddInside("ORIGINALSETTINGS",sOriginalExtraInfo); CTDVString sXML; sXML << "<ORIGINALSTATUS>" << iOriginalStatus << "</ORIGINALSTATUS>"; m_pPage->AddInside("ORIGINALSETTINGS",sXML); sXML.Empty(); sXML << "<ORIGINALTYPE>" << iOriginalType << "</ORIGINALTYPE>"; m_pPage->AddInside("ORIGINALSETTINGS",sXML); CTDVString sExtraInfo; ExtraInfo.GetInfoAsXML(sExtraInfo); m_pPage->AddInside("H2G2","<NEWSETTINGS/>"); m_pPage->AddInside("NEWSETTINGS",sExtraInfo); sXML.Empty(); sXML << "<NEWSTATUS>" << iStatus << "</NEWSTATUS>"; m_pPage->AddInside("NEWSETTINGS",sXML); sXML.Empty(); if (iType > 0) { sXML << "<NEWTYPE>" << iType << "</NEWTYPE>"; } else { sXML << "<NOTCHANGINGTYPE/>"; } m_pPage->AddInside("NEWSETTINGS",sXML); } return true; }