From f328172e16c619d30889fac830e873f2eeef857a Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Fri, 5 Aug 2011 07:43:47 +0000
Subject: [PATCH] earning_name renamed to earning_provider

---
 .gitattributes                                |  1 +
 inc/db/lib.php                                |  2 +-
 inc/extensions/ext-earning.php                |  4 +-
 inc/extensions/ext-forced.php                 |  9 +-
 inc/filter/earning_filter.php                 |  4 +-
 inc/filter/forced_filter.php                  |  3 +-
 inc/functions.php                             |  2 +-
 inc/language/earning_de.php                   |  4 +-
 inc/language/forced_de.php                    |  2 +-
 inc/libs/earning_functions.php                | 10 +-
 inc/libs/forced_functions.php                 | 10 +-
 .../admin/what-list_forced_campaigns.php      | 95 +++++++++++++++++++
 inc/modules/member/what-earning.php           |  2 +-
 inc/xml-functions.php                         |  4 +-
 .../member/member_earning_data_invalid.tpl    |  4 +-
 .../member/member_earning_popup_form_row.tpl  |  4 +-
 .../html/member/member_earning_popup_row.tpl  |  2 +-
 17 files changed, 134 insertions(+), 28 deletions(-)
 create mode 100644 inc/modules/admin/what-list_forced_campaigns.php

diff --git a/.gitattributes b/.gitattributes
index f93f232da8..60f5bfe0fc 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -533,6 +533,7 @@ inc/modules/admin/what-list_coupon.php svneol=native#text/plain
 inc/modules/admin/what-list_doubler.php svneol=native#text/plain
 inc/modules/admin/what-list_email_max_rec.php svneol=native#text/plain
 inc/modules/admin/what-list_forced_ads.php svneol=native#text/plain
+inc/modules/admin/what-list_forced_campaigns.php svneol=native#text/plain
 inc/modules/admin/what-list_holiday.php svneol=native#text/plain
 inc/modules/admin/what-list_links.php svneol=native#text/plain
 inc/modules/admin/what-list_network_api_translation.php svneol=native#text/plain
diff --git a/inc/db/lib.php b/inc/db/lib.php
index d703948c98..c18c0adaa1 100644
--- a/inc/db/lib.php
+++ b/inc/db/lib.php
@@ -48,7 +48,7 @@ if (isIncludeReadable($inc)) {
 	loadIncludeOnce($inc);
 } else {
 	// Bye, bye...
-	die('Cannot load database abstraction layer <u>' . getConfig('_DB_TYPE') . '</u> -&gt; R.I.P.');
+	debug_report_bug(__FILE__, __LINE__, 'Cannot load database abstraction layer <u>' . getConfig('_DB_TYPE') . '</u> -&gt; R.I.P.');
 }
 
 // [EOF]
diff --git a/inc/extensions/ext-earning.php b/inc/extensions/ext-earning.php
index 4934f2a78c..52f103d50b 100644
--- a/inc/extensions/ext-earning.php
+++ b/inc/extensions/ext-earning.php
@@ -62,10 +62,10 @@ switch (getExtensionMode()) {
 		addCreateTableSql('earning_data', "
 `earning_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
 `earning_group` VARCHAR(255) NOT NULL DEFAULT 'INVALID',
-`earning_name` VARCHAR(255) NOT NULL DEFAULT 'INVALID',
+`earning_provider` VARCHAR(255) NOT NULL DEFAULT 'INVALID',
 `earning_sorting` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
 PRIMARY KEY (`earning_id`),
-UNIQUE `earning_group_name` (`earning_group`,`earning_name`)",
+UNIQUE `earning_group_name` (`earning_group`,`earning_provider`)",
 			'Registered (extra) earnings');
 
 		// User->earnings connection table
diff --git a/inc/extensions/ext-forced.php b/inc/extensions/ext-forced.php
index fc0eb66b93..1c8c17f759 100644
--- a/inc/extensions/ext-forced.php
+++ b/inc/extensions/ext-forced.php
@@ -134,7 +134,7 @@ INDEX (`forced_stats_userid`)",
 		addMemberMenuSql('extras', 'book_forced', 'Forced-Kampagne buchen', 3);
 
 		// Register Forced-PopUps with earning_data table
-		addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_earning_data` (`earning_group`,`earning_name`,`earning_sorting`) VALUES ('POPUP','FORCED_POPUP',1)");
+		addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_earning_data` (`earning_group`,`earning_provider`,`earning_sorting`) VALUES ('POPUP','FORCED_POPUP',1)");
 
 		// Register filters
 		registerFilter('add_forced_ads_types', 'FORCED_AD_TYPE_DEFAULTS', false, true, isExtensionDryRun());
@@ -152,8 +152,11 @@ INDEX (`forced_stats_userid`)",
 		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='forced'");
 		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what` IN ('forced_banner','forced_textlink','book_forced') LIMIT 3");
 
-		// Unregister Forced-PopUps from earning_data
-		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_earning_data` WHERE `earning_name`='FORCED_POPUP' LIMIT 1");
+		// Is earning_data there?
+		if (isSqlTableCreated('earning_data')) {
+			// Unregister Forced-PopUps from earning_data
+			addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_earning_data` WHERE `earning_provider`='FORCED_POPUP' LIMIT 1");
+		} // END - if
 
 		// Remove filter
 		unregisterFilter(__FUNCTION__, __LINE__, 'add_forced_ads_types', 'FORCED_AD_TYPE_DEFAULTS', true, isExtensionDryRun());
diff --git a/inc/filter/earning_filter.php b/inc/filter/earning_filter.php
index 3378375c5f..1c93328607 100644
--- a/inc/filter/earning_filter.php
+++ b/inc/filter/earning_filter.php
@@ -52,7 +52,7 @@ function FILTER_ADD_EARNING_GROUP_POPUP ($filterData) {
 	// Now check if the user has subscription and amount left
 	$result = SQL_QUERY_ESC("SELECT
 	d.`earning_id`,
-	d.`earning_name`,
+	d.`earning_provider`,
 	u.`earning_current_amount`,
 	u.`earning_daily_amount`
 FROM
@@ -80,7 +80,7 @@ ORDER BY
 			$content = merge_array($content, $filterData);
 
 			// Construct callback function name
-			$callbackName = 'get' . capitalizeUnderscoreString($content['earning_name']) . 'DataByEarningArray';
+			$callbackName = 'get' . capitalizeUnderscoreString($content['earning_provider']) . 'DataByEarningArray';
 
 			// And call it
 			$content = call_user_func($callbackName, $content);
diff --git a/inc/filter/forced_filter.php b/inc/filter/forced_filter.php
index 2ddd254bdf..7b9bb28931 100644
--- a/inc/filter/forced_filter.php
+++ b/inc/filter/forced_filter.php
@@ -65,11 +65,12 @@ function FILTER_FORCED_AD_TYPE_DEFAULTS ($data) {
 function FILTER_FORCED_POPUP_TABLE_DATA ($filterData) {
 	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
 	// Is this the right filter?
-	if ($filterData['earning_name'] == 'FORCED_POPUP') {
+	if ($filterData['earning_provider'] == 'FORCED_POPUP') {
 		// Set group
 		$filterData['earning_group'] = 'POPUP';
 
 		// Get max/min/count of all popups
+		// @TODO This part is unfinished
 		//die(__FUNCTION__.':OK!');
 	} // END - if
 
diff --git a/inc/functions.php b/inc/functions.php
index df40ef0d65..26d0bafc5a 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2173,7 +2173,7 @@ function handleFieldWithBraces ($field) {
 // Converts a zero or NULL to word 'NULL'
 function makeZeroToNull ($number) {
 	// Is it a valid username?
-	if ((!is_null($number)) && ($number > 0)) {
+	if ((!is_null($number)) && (!empty($number)) && ($number > 0)) {
 		// Always secure it
 		$number = bigintval($number);
 	} else {
diff --git a/inc/language/earning_de.php b/inc/language/earning_de.php
index 96a721c987..37411a49e9 100644
--- a/inc/language/earning_de.php
+++ b/inc/language/earning_de.php
@@ -44,7 +44,7 @@ if (!defined('__SECURITY')) {
 addMessages(array(
 	// Member strings
 	'MEMBER_EARNINGS_404' => "Es wurden noch keine Zusatzverdienste durch die Administratoren eingerichtet. Bitte kommen Sie sp&auml;ter hier erneut vorbei.",
-	'MEMBER_EARNING_POPUP_FORM_TITLE' => "Zusatzverdienst durch PopUps - Kategorie: {%%pipe,translateEarningName=%s%%}",
+	'MEMBER_EARNING_POPUP_FORM_TITLE' => "Zusatzverdienst durch PopUps - Kategorie: {%%pipe,translateEarningProvider=%s%%}",
 	'MEMBER_EARNING_ENTER_DAILY_POPUP_AMOUNT' => "Wie viele PopUps wollen Sie im Login t&auml;glich maximal sehen?",
 	'MEMBER_EARNING_SUBSCRIBE_SUBMIT' => "Zusatzverdienst aktivieren",
 	'MEMBER_EARNING_DATA_MIN_POINTS' => "Mindestens verdienbar:",
@@ -52,7 +52,7 @@ addMessages(array(
 	'MEMBER_EARNING_DATA_COUNT' => "Anzahl Verdiensteintr&auml;ge:",
 	'MEMBER_EARNING_DATA_EXCLUDE_USERID' => "Ausgeschlossene Mitgliedsnummer:",
 	'MEMBER_EARNING_DATA_GROUP' => "Gruppe Zusatzverdienst:",
-	'MEMBER_EARNING_DATA_NAME' => "Bezeichnung Zusatzverdienst:",
+	'MEMBER_EARNING_DATA_PROVIDER' => "Bezeichnung Zusatzverdienst:",
 	'MEMBER_EARNING_CHANGE_DAILY_POPUP_AMOUNT' => "&Auml;ndern von t&auml;glich maximal eingeblendeten PopUps:",
 	'MEMBER_EARNING_CHANGE_IS_ACTIVE' => "Zusatzverdienst aktiv?",
 	'MEMBER_EARNING_POINTS' => "Bereits erzielter Zusatzverdienst:",
diff --git a/inc/language/forced_de.php b/inc/language/forced_de.php
index cad4041102..09cf5c39e0 100644
--- a/inc/language/forced_de.php
+++ b/inc/language/forced_de.php
@@ -68,7 +68,7 @@ addMessages(array(
 	'ADMIN_FORCED_ADS_ADDED' => "Hinzugef&uuml;gt",
 
 	// Earning names
-	'EARNING_NAME_FORCED_POPUP' => "Forced-PopUp",
+	'EARNING_PROVIDER_FORCED_POPUP' => "Forced-PopUp",
 ));
 
 // [EOF]
diff --git a/inc/libs/earning_functions.php b/inc/libs/earning_functions.php
index 809fda2563..b0300dbcf0 100644
--- a/inc/libs/earning_functions.php
+++ b/inc/libs/earning_functions.php
@@ -46,18 +46,18 @@ function translateEarningGroup ($earningGroup) {
 }
 
 // Translates the "earning name" into human-readable
-function translateEarningName ($earningName) {
-	return sprintf("{--EARNING_NAME_%s--}", $earningName);
+function translateEarningProvider ($earningProvider) {
+	return sprintf("{--EARNING_PROVIDER_%s--}", $earningProvider);
 }
 
 /*
  * Generates a table (with templates) to display data for extra earnings (to
  * the member) by given "earning name".
  *
- * @param	$earningName	Name of the earning
+ * @param	$earningProvider	Name of the earning
  * @return	$output			Generated HTML output
  */
-function generateMemberEarningDataTable ($earningName) {
+function generateMemberEarningDataTable ($earningProvider) {
 	// Init array for filter
 	$filterData = array(
 		// Minimum points to get
@@ -72,7 +72,7 @@ function generateMemberEarningDataTable ($earningName) {
 		// "earning group"
 		'earning_group'          => 'INVALID',
 		// "earning name" again
-		'earning_name'           => $earningName
+		'earning_provider'       => $earningProvider
 	);
 
 	// Run the filter chain to get the data
diff --git a/inc/libs/forced_functions.php b/inc/libs/forced_functions.php
index cd2aba8ba1..84dceb8851 100644
--- a/inc/libs/forced_functions.php
+++ b/inc/libs/forced_functions.php
@@ -54,8 +54,12 @@ function doTemplateForcedAdTypeSelectionBox ($templateName, $clear = false, $def
 
 // Translate the status IN/OUT
 function translateForcedAdType ($status) {
-	// Is the status empty?
-	if (empty($status)) {
+	// Is the status null or empty?
+	if (is_null($status)) {
+		// Is NULL
+		$status = 'NULL';
+	} elseif (empty($status)) {
+		// Is empty (string)
 		$status = 'EMPTY';
 	} // END - if
 
@@ -77,7 +81,7 @@ function translateForcedAdType ($status) {
 
 // "Getter" for an array of data from all Forced-PopUps
 function getForcedPopupDataByEarningArray ($content) {
-	die(__FUNCTION__ . ':content=<pre>'.print_r($content,true).'</pre>');
+	debug_report_bug(__FUNCTION__, __LINE__, 'content=' . print_r($content, true));
 }
 
 // [EOF]
diff --git a/inc/modules/admin/what-list_forced_campaigns.php b/inc/modules/admin/what-list_forced_campaigns.php
new file mode 100644
index 0000000000..4656edd2a1
--- /dev/null
+++ b/inc/modules/admin/what-list_forced_campaigns.php
@@ -0,0 +1,95 @@
+<?php
+/************************************************************************
+ * Mailer v0.2.1-FINAL                                Start: 08/04/2011 *
+ * ===================                          Last change: 08/04/2011 *
+ *                                                                      *
+ * -------------------------------------------------------------------- *
+ * File              : what-list_forced_campaigns.php                   *
+ * -------------------------------------------------------------------- *
+ * Short description : List/add Forced-Ads                              *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung  : Auflisten/Hinzufuegen von Forced-Werbemitteln    *
+ * -------------------------------------------------------------------- *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * -------------------------------------------------------------------- *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
+ * For more information visit: http://www.mxchange.org                  *
+ *                                                                      *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or    *
+ * (at your option) any later version.                                  *
+ *                                                                      *
+ * This program is distributed in the hope that it will be useful,      *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+ * GNU General Public License for more details.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with this program; if not, write to the Free Software          *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
+ * MA  02110-1301  USA                                                  *
+ ************************************************************************/
+
+// Some security stuff...
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+	die();
+} // END - if
+
+// Add description as navigation point
+addYouAreHereLink('admin', __FILE__);
+
+// By default show the list...
+$show = true;
+
+// Check for 'url_id' element
+if ((countRequestPost() > 0) && ((!isPostRequestElementSet('forced_campaigns_id')) || (!is_array(postRequestElement('forced_campaigns_id'))) || (count(postRequestElement('forced_campaigns_id')) == 0))) {
+	// Not found so output message
+	displayMessage('{--ADMIN_FORCED_CAMPAIGNS_NO_SELECTIONS--}');
+
+	// Abort here
+	return;
+} // END - if
+
+// Edit or delete button hit?
+if (isFormSent('add')) {
+	// Add new forced ad
+	showEntriesByXmlCallback('admin_add_do_forced_campaigns');
+} elseif (isFormSent('edit')) {
+	// Show entries for editing
+	showEntriesByXmlCallback('admin_edit_show_forced_campaigns');
+
+	// Do not show the list of URLs after this template
+	$show = false;
+} elseif (isFormSent('do_edit')) {
+	// Change data of entries
+	showEntriesByXmlCallback('admin_edit_do_forced_campaigns');
+} elseif (isFormSent('delete')) {
+	// Show entries for deletion
+	showEntriesByXmlCallback('admin_delete_show_forced_campaigns');
+
+	// Do not show the list of URLs after this template
+	$show = false;
+} elseif (isFormSent('do_delete')) {
+	// Remove entries from database
+	showEntriesByXmlCallback('admin_delete_do_forced_campaigns');
+}
+
+// Show entries?
+if ($show === false) {
+	// No, a form has already been show
+	return false;
+} // END - if
+
+// List all URLs
+showEntriesByXmlCallback('admin_list_forced_campaigns');
+
+// Display form for adding a forced-ad
+loadTemplate('admin_add_forced_campaign');
+
+// [EOF]
+?>
diff --git a/inc/modules/member/what-earning.php b/inc/modules/member/what-earning.php
index a9ffe4f708..27c2a9a3ae 100644
--- a/inc/modules/member/what-earning.php
+++ b/inc/modules/member/what-earning.php
@@ -59,7 +59,7 @@ if (isFormSent()) {
 $result = SQL_QUERY('SELECT
 	d.`earning_id`,
 	d.`earning_group`,
-	d.`earning_name`
+	d.`earning_provider`
 FROM
 	`{?_MYSQL_PREFIX?}_earning_data` AS d
 ORDER BY
diff --git a/inc/xml-functions.php b/inc/xml-functions.php
index 09373597f1..6011378073 100644
--- a/inc/xml-functions.php
+++ b/inc/xml-functions.php
@@ -185,7 +185,9 @@ function xmlCharacterHandler ($resource, $characters) {
 		// Nothing to handle
 		return;
 	} // END - if
-	die('characters[]='.strlen($characters));
+
+	// @TODO Handle characters
+	die(__FUNCTION__ . ':characters[]='.strlen($characters));
 }
 
 // Checks if given type is valid, makes all lower-case
diff --git a/templates/de/html/member/member_earning_data_invalid.tpl b/templates/de/html/member/member_earning_data_invalid.tpl
index 303357540f..e3aefafe15 100644
--- a/templates/de/html/member/member_earning_data_invalid.tpl
+++ b/templates/de/html/member/member_earning_data_invalid.tpl
@@ -23,8 +23,8 @@
 		<strong>{%pipe,translateEarningGroup=$content[earning_group]%}</strong>
 	</div>
 	<div style="padding-top:3px;padding-bottom:3px" class="bottom">
-		{--MEMBER_EARNING_DATA_NAME--}<br />
-		<strong>{%pipe,translateEarningName=$content[earning_name]%}</strong>
+		{--MEMBER_EARNING_DATA_PROVIDER--}<br />
+		<strong>{%pipe,translateEarningProvider=$content[earning_provider]%}</strong>
 	</div>
 	<div class="table_footer notice">
 		{--MEMBER_EARNING_DATA_INVALID_NOTE--}
diff --git a/templates/de/html/member/member_earning_popup_form_row.tpl b/templates/de/html/member/member_earning_popup_form_row.tpl
index 267e31f130..dda9314841 100644
--- a/templates/de/html/member/member_earning_popup_form_row.tpl
+++ b/templates/de/html/member/member_earning_popup_form_row.tpl
@@ -2,14 +2,14 @@
 <form accept-charset="UTF-8" id="earning_$content[earning_id]" action="{%url=modules.php?module=login&amp;what=earning%}" method="post">
 <div class="table dashed">
 <div class="table_header bottom">
-	<strong>{%message,MEMBER_EARNING_POPUP_FORM_TITLE=$content[earning_name]%}</strong>
+	<strong>{%message,MEMBER_EARNING_POPUP_FORM_TITLE=$content[earning_provider]%}</strong>
 </div>
 <div class="bottom" style="height:25px;padding-top:5px">
 	{--MEMBER_EARNING_ENTER_DAILY_POPUP_AMOUNT--}
 	<input type="text" class="form_field" name="earning_daily_amount" size="5" maxlength="20" />
 </div>
 <div class="bottom">
-	{%pipe,generateMemberEarningDataTable=$content[earning_name]%}
+	{%pipe,generateMemberEarningDataTable=$content[earning_provider]%}
 </div>
 <div class="table_footer">
 	<input type="hidden" name="earning_id" value="$content[earning_id]" />
diff --git a/templates/de/html/member/member_earning_popup_row.tpl b/templates/de/html/member/member_earning_popup_row.tpl
index 20d763be3c..fe10b6e4f6 100644
--- a/templates/de/html/member/member_earning_popup_row.tpl
+++ b/templates/de/html/member/member_earning_popup_row.tpl
@@ -2,7 +2,7 @@
 <form accept-charset="UTF-8" id="earning_$content[earning_id]" action="{%url=modules.php?module=login&amp;what=earning%}" method="post">
 <div class="table dashed">
 <div class="table_header bottom">
-	<strong>{%message,MEMBER_EARNING_POPUP_FORM_TITLE=$content[earning_name]%}</strong>
+	<strong>{%message,MEMBER_EARNING_POPUP_FORM_TITLE=$content[earning_provider]%}</strong>
 </div>
 <div class="bottom" style="padding-top:5px;padding-bottom:5px">
 	{--MEMBER_EARNING_CHANGE_DAILY_POPUP_AMOUNT--}
-- 
2.39.5