/** * Show the interface for viewing/editing an individual campaign * * @param $campaign string The name of the campaign to view * @throws ErrorPageError */ function listCampaignDetail($campaign) { $c = new AdCampaign($campaign); // Todo: Convert the rest of this page to use this object try { if ($c->isArchived()) { $this->getOutput()->setSubtitle($this->msg('promoter-archive-edit-prevented')); $this->editable = false; // Todo: Fix this gross hack to prevent editing } } catch (AdCampaignExistenceException $ex) { throw new ErrorPageError('promoter', 'promoter-campaign-doesnt-exist'); } // Handle form submissions from campaign detail interface $request = $this->getRequest(); if ($this->editable && $request->wasPosted()) { // If what we're doing is actually serious (ie: not updating the ad // filter); process the request. Recall that if the serious request // succeeds, the page will be reloaded again. if ($request->getCheck('ad-search') == false) { // Check authentication token if ($this->getUser()->matchEditToken($request->getVal('authtoken'))) { // Handle removing campaign if ($request->getVal('archive')) { AdCampaign::setBooleanCampaignSetting($campaign, 'archived', 1); } $initialCampaignSettings = AdCampaign::getCampaignSettings($campaign); // Handle enabling/disabling campaign if ($request->getCheck('enabled')) { AdCampaign::setBooleanCampaignSetting($campaign, 'enabled', 1); } else { AdCampaign::setBooleanCampaignSetting($campaign, 'enabled', 0); } // Handle adding of ads to the campaign $adsToAdd = $request->getArray('addAds'); if ($adsToAdd) { $weight = $request->getArray('weight'); foreach ($adsToAdd as $adName) { $adId = Ad::fromName($adName)->getId(); $result = AdCampaign::addAdTo($campaign, $adName, $weight[$adId]); if ($result !== true) { $this->showError($result); } } } // Handle removing of ads from the campaign $adToRemove = $request->getArray('removeAds'); if ($adToRemove) { foreach ($adToRemove as $ad) { AdCampaign::removeAdFor($campaign, $ad); } } // Handle weight changes $updatedWeights = $request->getArray('weight'); $balanced = $request->getCheck('balanced'); if ($updatedWeights) { foreach ($updatedWeights as $adId => $weight) { if ($balanced) { $weight = 25; } AdCampaign::updateWeight($campaign, $adId, $weight); } } $finalCampaignSettings = AdCampaign::getCampaignSettings($campaign); $campaignId = AdCampaign::getCampaignId($campaign); /* AdCampaign::logCampaignChange( 'modified', $campaignId, $this->getUser(), $initialCampaignSettings, $finalCampaignSettings ); */ // If there were no errors, reload the page to prevent duplicate form submission if (!$this->promoterError) { $this->getOutput()->redirect($this->getPageTitle()->getLocalUrl(array('method' => 'listCampaignDetail', 'campaign' => $campaign))); return; } } else { $this->showError('sessionfailure'); } } } $htmlOut = ''; // Begin AdCampaign detail form $htmlOut .= Xml::openElement('div', array('class' => 'prefsection')); if ($this->editable) { $htmlOut .= Xml::openElement('form', array('method' => 'post', 'action' => $this->getPageTitle()->getLocalURL(array('method' => 'listCampaignDetail', 'campaign' => $campaign)))); } $output_detail = $this->campaignDetailForm($campaign); $output_assigned = $this->assignedAdsForm($campaign); $output_ads = $this->addAdsForm($campaign); $htmlOut .= $output_detail; // Catch for no ads so that we don't double message if ($output_assigned == '' && $output_ads == '') { $htmlOut .= $this->msg('promoter-no-ads')->escaped(); $htmlOut .= Xml::element('p'); $newPage = $this->getTitleFor('CampaignAd', 'add'); $htmlOut .= Linker::link($newPage, $this->msg('promoter-add-ad')->escaped()); $htmlOut .= Xml::element('p'); } elseif ($output_assigned == '') { $htmlOut .= Xml::fieldset($this->msg('promoter-assigned-ads')->text()); $htmlOut .= $this->msg('promoter-no-ads-assigned')->escaped(); $htmlOut .= Xml::closeElement('fieldset'); if ($this->editable) { $htmlOut .= $output_ads; } } else { $htmlOut .= $output_assigned; if ($this->editable) { $htmlOut .= $output_ads; } } if ($this->editable) { $htmlOut .= Html::hidden('authtoken', $this->getUser()->getEditToken()); // Submit button $htmlOut .= Xml::tags('div', array('class' => 'pr-buttons'), Xml::submitButton($this->msg('promoter-modify')->text())); } if ($this->editable) { $htmlOut .= Xml::closeElement('form'); } $htmlOut .= Xml::closeElement('div'); $this->getOutput()->addHTML($htmlOut); }