+ // Get an array from all pending campaigns
+ $forcedCampaigns = getArrayFromForcedCampaignsByArray(array_keys(postRequestElement('forced_campaign_id')), 'PENDING');
+
+ // By default all worked (at this point)
+ $activated = TRUE;
+
+ // Run through all entries
+ foreach ($forcedCampaigns as $campaignId => $campaignData) {
+ // Change the status of this campaign
+ if (!changeForcedCampaignStatus($campaignId, 'PENDING', 'ACTIVE', $campaignData)) {
+ // One didn't work, but continue with others
+ $activated = FALSE;
+ } // END - if
+ } // END - foreach
+
+ // Return status
+ return $activated;
+}
+
+// Changes the status of a forced campaign from previous to new status
+function changeForcedCampaignStatus ($campaignId, $prevStatus, $newStatus, $data) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'campaignId=' . $campaignId . ',prevStatus=' . $prevStatus . ',data[]=' . gettype($data) . ',newStatus=' . $newStatus . ' - ENTERED!');
+ // Make new status always lower-case
+ $newStatus = strtolower($newStatus);
+
+ // Prepare array
+ $filterData = array(
+ 'campaign_id' => $campaignId,
+ 'prev_status' => $prevStatus,
+ 'new_status' => $newStatus,
+ 'data' => $data,
+ 'abort' => NULL,
+ );
+
+ // Run pre filter chain
+ $filterData = runFilterChain('pre_change_forced_campaign_status', $filterData);
+
+ // Abort here?
+ if (!is_null($filterData['abort'])) {
+ // Abort here
+ return $filterData['abort'];
+ } // END - if
+
+ // Update the status now
+ // ---------- Comment out for debugging/developing member actions! ---------
+ sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_forced_campaigns` SET `forced_campaign_status`='%s' WHERE `forced_campaign_id`=%s LIMIT 1",
+ array(
+ $newStatus,
+ bigintval($campaignId)
+ ), __FUNCTION__, __LINE__);
+ // ---------- Comment out for debugging/developing member actions! ---------
+
+ // Was that fine?
+ // ---------- Comment out for debugging/developing member actions! ---------
+ if (sqlAffectedRows() != 1) {
+ // No, something went wrong
+ return FALSE;
+ } // END - if
+ // ---------- Comment out for debugging/developing member actions! ---------
+
+ // Run post filter chain
+ $filterData = runFilterChain('post_change_forced_campaign_status', $filterData);
+
+ // Check if generic 'data' is there
+ assert(isset($filterData['data']));
+
+ // All done!
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'campaignId=' . $campaignId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - EXIT!');
+ return TRUE;
+}
+
+// Notify admin(s) with a selected message and content
+function doForcedNotifyAdmin ($messageType, $content) {
+ // Prepare template name
+ $templateName = sprintf('admin_forced_%s', $messageType);
+
+ // Is the user id valid?
+ if (!isValidId($content['forced_campaign_userid'])) {
+ // No, then use admin-only template
+ $templateName = sprintf('admin_only_forced_%s', $messageType);
+ } // END - if
+
+ // Prepare subject
+ $subject = sprintf('{--ADMIN_FORCED_NOTIFY_%s_SUBJECT--}', strtoupper($messageType));
+
+ // Is the subject line there?
+ if ((substr($subject, 0, 1) == '!') && (substr($subject, -1, 1) == '!')) {
+ // Set default subject if following eval() wents wrong
+ $subject = '{%message,ADMIN_FORCED_NOTIFY_DEFAULT_SUBJECT=' . strtoupper($messageType) . '%}';
+ } // END - if
+
+ // Translate some data if present
+ $content = prepareForcedContentForTemplate($content);
+
+ // Send the notification out
+ return sendAdminNotification($subject, $templateName, $content, $content['forced_campaign_userid']);
+}
+
+// Notify the user about the performed action
+function doForcedNotifyMember ($messageType, $content) {
+ // Skip notification if userid is NULL
+ if (!isValidId($content['forced_campaign_userid'])) {
+ // NULL is silently ignored
+ return TRUE;
+ } // END - if
+
+ // Prepare template name
+ $templateName = sprintf('member_forced_%s', $messageType);
+
+ // Prepare subject
+ $subject = sprintf('{--MEMBER_FORCED_NOTIFY_%s_SUBJECT--}', strtoupper($messageType));
+
+ // Is the subject line there?
+ if ((substr($subject, 0, 1) == '!') && (substr($subject, -1, 1) == '!')) {
+ // Set default subject if following eval() wents wrong
+ $subject = '{--MEMBER_FORCED_NOTIFY_DEFAULT_SUBJECT--}';
+ } // END - if
+
+ // Translate some data if present
+ $content = prepareForcedContentForTemplate($content);
+
+ // Load template
+ $mailText = loadEmailTemplate($templateName, $content, $content['forced_campaign_userid']);
+
+ // Send the email
+ return sendEmail($content['forced_campaign_userid'], $subject, $mailText);
+}
+
+// Translates some data for template usage
+// @TODO Can't we use our new expression language instead of this ugly code?
+function prepareForcedContentForTemplate ($content) {
+ // Prepare some code
+ if (isset($content['forced_campaign_created'])) $content['forced_campaign_created'] = generateDateTime($content['forced_campaign_created'], 2);
+
+ // Return translated content
+ return $content;
+}
+
+// ----------------------------------------------------------------------------
+// Template helper functions
+// ----------------------------------------------------------------------------
+
+// Template helper function to create selection box for all forced-ad types
+function doTemplateForcedAdTypeSelectionBox ($templateName, $clear = FALSE, $default = NULL) {
+ // Add all types through the filter
+ $forcedAdTypes = runFilterChain('add_forced_ads_types', array());
+
+ // Handle it over to generateSelectionBoxFromArray()
+ $content = generateSelectionBoxFromArray($forcedAdTypes, 'forced_ads_type', 'type', '', '', '', $default);
+
+ // Return prepared content
+ return $content;
+}
+
+// Template helper function to create selection box for costs visibility
+function doTemplateForcedCostsVisiblitySelectionBox ($templateName, $clear = FALSE, $default = NULL) {
+ // Init array
+ $costsVisibility = array(
+ 0 => array('visibility' => 'ALL'),
+ 1 => array('visibility' => 'MEMBER'),
+ 2 => array('visibility' => 'SPONSOR'),
+ 3 => array('visibility' => 'NONE')
+ );
+
+ // Handle it over to generateSelectionBoxFromArray()
+ $content = generateSelectionBoxFromArray($costsVisibility, 'forced_costs_visibility', 'visibility', '', '', '', $default);
+
+ // Return prepared content
+ return $content;
+}
+
+// Template helper function to create selection box for foreced ads
+function doTemplateForcedAdSelectionBox ($templateName, $clear, $default = NULL) {
+ // Get back an array of all forced popups
+ $forcedAds = getArrayFromForcedAdsByType();
+
+ // Handle it over to generateSelectionBoxFromArray()
+ $content = generateSelectionBoxFromArray($forcedAds, 'forced_ads_id', 'forced_ads_id', '', '', '', $default, 'forced_ads_type');
+
+ // Return prepared content
+ return $content;
+}
+
+// Template helper function to create selection box for foreced costs
+function doTemplateForcedCostsSelectionBox ($templateName, $clear, $default = NULL) {
+ // Get back an array of all forced popups
+ $forcedCosts = getArrayFromForcedCostsByVisibility();
+
+ // Handle it over to generateSelectionBoxFromArray()
+ $content = generateSelectionBoxFromArray($forcedCosts, 'forced_costs_id', 'forced_costs_id', '', '', '', $default, '', TRUE);
+
+ // Return prepared content
+ return $content;
+}
+
+// Template helper function to create selection box for foreced campaign userid
+function doTemplateForcedCampaignUseridSelectionBox ($templateName, $clear, $default = NULL) {
+ // Generate the selection box without all
+ $content = addMemberSelectionBox($default, FALSE, TRUE, TRUE, 'forced_campaign_userid');
+
+ // Return prepared content
+ return $content;
+}
+
+// ----------------------------------------------------------------------------
+// XML call-back functions
+// ----------------------------------------------------------------------------
+
+// For 'doing' add forced-ads, the column-index is required
+function addXmlSpecialAdminAddDoForcedAds () {
+ // So set it all here
+ $GLOBALS['__COLUMN_INDEX']['doXmlCallbackFunction'] = 'column';
+ $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['column_index'] = 'column';
+}
+
+// For 'doing' add forced-campaigns, the column-index is required
+function addXmlSpecialAdminAddDoForcedCampaigns () {
+ // So set it all here
+ $GLOBALS['__COLUMN_INDEX']['doXmlCallbackFunction'] = 'column';
+ $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['column_index'] = 'column';
+}
+
+// For 'doing' add forced-costs, the column-index is required
+function addXmlSpecialAdminAddDoForcedCosts () {
+ // So set it all here
+ $GLOBALS['__COLUMN_INDEX']['doXmlCallbackFunction'] = 'column';
+ $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['column_index'] = 'column';