Extension ext-earning continued:
authorRoland Häder <roland@mxchange.org>
Wed, 3 Aug 2011 16:11:27 +0000 (16:11 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 3 Aug 2011 16:11:27 +0000 (16:11 +0000)
- JOIN doesn't work if the joined table contains data but with wrong entries,
  so it needs be splitted up into two queries
- Renamed earnings->earning
- TODOs.txt updated

12 files changed:
.gitattributes
DOCS/TODOs.txt
inc/extensions/ext-earning.php
inc/filter/earning_filter.php [new file with mode: 0644]
inc/filter/forced_filter.php
inc/libs/forced_functions.php
inc/modules/member/what-earning.php [new file with mode: 0644]
inc/modules/member/what-earnings.php
inc/template-functions.php
templates/de/html/member/member_earning_popup_form_row.tpl
templates/de/html/member/member_earning_popup_row.tpl
templates/de/html/member/member_footer.tpl

index f465bb5..f93f232 100644 (file)
@@ -212,6 +212,7 @@ inc/filter/bonus_filter.php svneol=native#text/plain
 inc/filter/booking_filter.php svneol=native#text/plain
 inc/filter/cache_filter.php svneol=native#text/plain
 inc/filter/coupon_filter.php svneol=native#text/plain
+inc/filter/earning_filter.php svneol=native#text/plain
 inc/filter/forced_filter.php svneol=native#text/plain
 inc/filter/mediadata_filter.php svneol=native#text/plain
 inc/filter/online_filter.php svneol=native#text/plain
@@ -650,6 +651,7 @@ inc/modules/member/what-booking.php svneol=native#text/plain
 inc/modules/member/what-cash_coupon.php svneol=native#text/plain
 inc/modules/member/what-categories.php svneol=native#text/plain
 inc/modules/member/what-doubler.php svneol=native#text/plain
+inc/modules/member/what-earning.php svneol=native#text/plain
 inc/modules/member/what-earnings.php svneol=native#text/plain
 inc/modules/member/what-guest.php svneol=native#text/plain
 inc/modules/member/what-holiday.php svneol=native#text/plain
index 4af4c41..2d2002d 100644 (file)
 ./inc/modules/admin/what-chk_regs.php:2:// @DEPRECATED
 ./inc/modules/admin/what-config_admins.php:2:// @DEPRECATED
 ./inc/modules/admin/what-config_email.php:2:// @DEPRECATED
+./inc/modules/member/what-earnings.php:2:// @DEPRECATED
 ./inc/modules/member/what-surfbar_book.php:2:// @DEPRECATED
 ./inc/modules/member/what-surfbar_start.php:2:// @DEPRECATED
 ./inc/modules/member/what-surfbar_stats.php:2:// @DEPRECATED
index a4b61dd..4934f2a 100644 (file)
@@ -52,10 +52,10 @@ enableExtensionProductive(false);
 switch (getExtensionMode()) {
        case 'register': // Do stuff when installation is running
                // Add member menu
-               addMemberMenuSql('earn', 'earnings', 'Zusatzverdienste', 2);
+               addMemberMenuSql('earn', 'earning', 'Zusatzverdienste', 2);
 
                // Admin menu
-               addAdminMenuSql('setup', 'list_earnings', 'Zusatzverdienste...', 'Veralten Sie hier bequem alle Zusatzverdienste (wie z.B. verg&uuml;tete PopUps usw.).', 6);
+               addAdminMenuSql('setup', 'list_earning', 'Zusatzverdienste...', 'Veralten Sie hier bequem alle Zusatzverdienste (wie z.B. verg&uuml;tete PopUps usw.).', 6);
 
                // Earning data table
                addDropTableSql('earning_data');
@@ -78,11 +78,15 @@ UNIQUE `earning_group_name` (`earning_group`,`earning_name`)",
 `earning_added` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
 `earning_cancelled` TIMESTAMP NULL DEFAULT NULL,
 `earning_daily_amount` SMALLINT(7) NOT NULL DEFAULT 0,
+`earning_current_amount` SMALLINT(7) NOT NULL DEFAULT 0,
 `earning_points` FLOAT(20,5) NOT NULL DEFAULT 0.00000,
 PRIMARY KEY (`id`),
 UNIQUE `user_earning` (`earning_id`,`earning_userid`),
 INDEX (`earning_userid`)",
                        'User->Earning connections');
+
+               // Register filter
+               registerFilter('member_footer_extras', 'ADD_EARNING_GROUP_POPUP', false, true, isExtensionDryRun());
                break;
 
        case 'remove': // Do stuff when removing extension
@@ -91,18 +95,21 @@ INDEX (`earning_userid`)",
                addDropTableSql('user_earning');
 
                // Delete entries in menus
-               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='earnings' LIMIT 1");
-               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what`='list_earnings' LIMIT 1");
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='earning' LIMIT 1");
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what`='list_earning' LIMIT 1");
+
+               // Unregister filter
+               unregisterFilter(__FUNCTION__, __LINE__, 'member_footer_extras', 'ADD_EARNING_GROUP_POPUP', true, isExtensionDryRun());
                break;
 
        case 'activate': // Do stuff when admin activates this extension
                // SQL commands to run
-               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='earnings' LIMIT 1");
+               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='earning' LIMIT 1");
                break;
 
        case 'deactivate': // Do stuff when admin deactivates this extension
                // SQL commands to run
-               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N', `locked`='Y' WHERE `what`='earnings' LIMIT 1");
+               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N', `locked`='Y' WHERE `what`='earning' LIMIT 1");
                break;
 
        case 'update': // Update an extension
diff --git a/inc/filter/earning_filter.php b/inc/filter/earning_filter.php
new file mode 100644 (file)
index 0000000..3378375
--- /dev/null
@@ -0,0 +1,99 @@
+<?php
+/************************************************************************
+ * Mailer v0.2.1-FINAL                                Start: 08/03/2011 *
+ * ===================                          Last change: 08/03/2011 *
+ *                                                                      *
+ * -------------------------------------------------------------------- *
+ * File              : earning_filter.php                               *
+ * -------------------------------------------------------------------- *
+ * Short description : Filters for ext-earning                          *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung  : Filter fuer ext-earning                          *
+ * -------------------------------------------------------------------- *
+ * $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')) {
+       die();
+} // END - if
+
+// Filter function to add 'earning_group' POPUP
+function FILTER_ADD_EARNING_GROUP_POPUP ($filterData) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
+       // Check if the current userid is same as in $filterData
+       if (getMemberId() != $filterData['userid']) {
+               // Not the same
+               debug_report_bug(__FUNCTION__, __LINE__, 'Validation of userid failed. ' . getMemberId() . '!=' . $filterData['userid']);
+       } // END - if
+
+       // Now check if the user has subscription and amount left
+       $result = SQL_QUERY_ESC("SELECT
+       d.`earning_id`,
+       d.`earning_name`,
+       u.`earning_current_amount`,
+       u.`earning_daily_amount`
+FROM
+       `{?_MYSQL_PREFIX?}_user_earning` AS u
+INNER JOIN
+       `{?_MYSQL_PREFIX?}_earning_data` AS d
+ON
+       u.`earning_id`=d.`earning_id`
+WHERE
+       u.`earning_userid`=%s AND
+       u.`earning_active`='Y' AND
+       u.`earning_current_amount` < u.`earning_daily_amount` AND
+       d.`earning_group`='POPUP'
+ORDER BY
+       d.`earning_sorting` ASC",
+               array(
+                       getMemberId()
+               ), __FUNCTION__, __LINE__);
+
+       // Do we have entries left?
+       if (SQL_NUMROWS($result) > 0) {
+               // Load all names
+               while ($content = SQL_FETCHARRAY($result)) {
+                       // Merge the $filterData array in
+                       $content = merge_array($content, $filterData);
+
+                       // Construct callback function name
+                       $callbackName = 'get' . capitalizeUnderscoreString($content['earning_name']) . 'DataByEarningArray';
+
+                       // And call it
+                       $content = call_user_func($callbackName, $content);
+               } // END - if
+       } // END - if
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Return filter data
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
+       return $filterData;
+}
+
+// [EOF]
+?>
index 4b69b26..2ddd254 100644 (file)
@@ -72,9 +72,9 @@ function FILTER_FORCED_POPUP_TABLE_DATA ($filterData) {
                // Get max/min/count of all popups
                //die(__FUNCTION__.':OK!');
        } // END - if
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
 
        // Return filter data array
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
        return $filterData;
 }
 
index 84f5764..cd2aba8 100644 (file)
@@ -75,5 +75,10 @@ function translateForcedAdType ($status) {
        return $return;
 }
 
+// "Getter" for an array of data from all Forced-PopUps
+function getForcedPopupDataByEarningArray ($content) {
+       die(__FUNCTION__ . ':content=<pre>'.print_r($content,true).'</pre>');
+}
+
 // [EOF]
 ?>
diff --git a/inc/modules/member/what-earning.php b/inc/modules/member/what-earning.php
new file mode 100644 (file)
index 0000000..a9ffe4f
--- /dev/null
@@ -0,0 +1,123 @@
+<?php
+/************************************************************************
+ * Mailer v0.2.1-FINAL                                Start: 07/31/2011 *
+ * ===================                          Last change: 07/31/2011 *
+ *                                                                      *
+ * -------------------------------------------------------------------- *
+ * File              : what-earnings.php                                *
+ * -------------------------------------------------------------------- *
+ * Short description : Extra earnings for the user                      *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung  : Zusatzverdienst fuer die Mitglieder              *
+ * -------------------------------------------------------------------- *
+ * $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')) {
+       die();
+} elseif (!isMember()) {
+       redirectToIndexMemberOnlyModule();
+}
+
+// Add description as navigation point
+addYouAreHereLink('member', __FILE__);
+
+// Is the form sent?
+if (isFormSent()) {
+       // Then handle the extra earning request
+       doMemberEarning(
+               postRequestElement('earning_id'),
+               postRequestElement('earning_daily_amount'),
+               postRequestElement('earning_active')
+       );
+} // END - if
+
+// Check for all earnings
+$result = SQL_QUERY('SELECT
+       d.`earning_id`,
+       d.`earning_group`,
+       d.`earning_name`
+FROM
+       `{?_MYSQL_PREFIX?}_earning_data` AS d
+ORDER BY
+       d.`earning_sorting` ASC', __FILE__, __LINE__);
+
+// Do we have entries?
+if (SQL_NUMROWS($result) > 0) {
+       // Init output
+       $OUT = '';
+
+       // List all entries
+       while ($content = SQL_FETCHARRAY($result)) {
+               // Load user_earning data
+               $result2 = SQL_QUERY_ESC('SELECT
+       u.`earning_active`,
+       UNIX_TIMESTAMP(u.`earning_added`) AS `earning_added`,
+       UNIX_TIMESTAMP(u.`earning_cancelled`) AS `earning_cancelled`,
+       u.`earning_daily_amount`,
+       u.`earning_points`
+FROM
+       `{?_MYSQL_PREFIX?}_user_earning` AS u
+WHERE
+       u.`earning_id`=%s AND
+       u.`earning_userid`=%s
+LIMIT 1',
+                       array(
+                               bigintval($content['earning_id']),
+                               getMemberId()
+                       ), __FILE__, __LINE__);
+
+               // Do we have an entry?
+               if (SQL_NUMROWS($result2) == 1) {
+                       // Load it
+                       $content = merge_array($content, SQL_FETCHARRAY($result2));
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result2);
+
+               // Do we have user_earning data available?
+               if (!isset($content['earning_active'])) {
+                       // Load row template "open subscription"
+                       $OUT .= loadTemplate('member_earning_' . strtolower($content['earning_group']) . '_form_row', true, $content);
+               } else {
+                       // Load row template "already subscribed"
+                       $OUT .= loadTemplate('member_earning_' . strtolower($content['earning_group']) . '_row', true, $content);
+               }
+       } // END - while
+
+       // Load main template
+       loadTemplate('member_earning', false, $OUT);
+} else {
+       // Display message
+       displayMessage('{--MEMBER_EARNINGS_404--}');
+}
+
+// Free result
+SQL_FREERESULT($result);
+
+// [EOF]
+?>
index 3842cd7..f551ef4 100644 (file)
@@ -1,111 +1,3 @@
 <?php
-/************************************************************************
- * Mailer v0.2.1-FINAL                                Start: 07/31/2011 *
- * ===================                          Last change: 07/31/2011 *
- *                                                                      *
- * -------------------------------------------------------------------- *
- * File              : what-earnings.php                                *
- * -------------------------------------------------------------------- *
- * Short description : Extra earnings for the user                      *
- * -------------------------------------------------------------------- *
- * Kurzbeschreibung  : Zusatzverdienst fuer die Mitglieder              *
- * -------------------------------------------------------------------- *
- * $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')) {
-       die();
-} elseif (!isMember()) {
-       redirectToIndexMemberOnlyModule();
-}
-
-// Add description as navigation point
-addYouAreHereLink('member', __FILE__);
-
-// Is the form sent?
-if (isFormSent()) {
-       // Then handle the extra earning request
-       doMemberEarning(
-               postRequestElement('earning_id'),
-               postRequestElement('earning_daily_amount'),
-               postRequestElement('earning_active')
-       );
-} // END - if
-
-// Check for all earnings
-$result = SQL_QUERY_ESC('SELECT
-       d.`earning_id`,
-       d.`earning_group`,
-       d.`earning_name`,
-       u.`earning_active`,
-       UNIX_TIMESTAMP(u.`earning_added`) AS `earning_added`,
-       UNIX_TIMESTAMP(u.`earning_cancelled`) AS `earning_cancelled`,
-       u.`earning_daily_amount`,
-       u.`earning_points`
-FROM
-       `{?_MYSQL_PREFIX?}_earning_data` AS d
-LEFT JOIN
-       `{?_MYSQL_PREFIX?}_user_earning` AS u
-ON
-       d.`earning_id`=u.`earning_id`
-WHERE
-       u.`earning_userid` IS NULL OR
-       u.`earning_userid`=%s
-ORDER BY
-       d.`earning_sorting` ASC',
-       array(
-               getMemberId()
-       ), __FILE__, __LINE__);
-
-// Do we have entries?
-if (SQL_NUMROWS($result) > 0) {
-       // Init output
-       $OUT = '';
-
-       // List all entries
-       while ($content = SQL_FETCHARRAY($result)) {
-               // Do we have user_earning data available?
-               if (is_null($content['earning_active'])) {
-                       // Load row template "open subscription"
-                       $OUT .= loadTemplate('member_earning_' . strtolower($content['earning_group']) . '_form_row', true, $content);
-               } else {
-                       // Load row template "already subscribed"
-                       $OUT .= loadTemplate('member_earning_' . strtolower($content['earning_group']) . '_row', true, $content);
-               }
-       } // END - while
-
-       // Load main template
-       loadTemplate('member_earning', false, $OUT);
-} else {
-       // Display message
-       displayMessage('{--MEMBER_EARNINGS_404--}');
-}
-
-// Free result
-SQL_FREERESULT($result);
-
-// [EOF]
+// @DEPRECATED
 ?>
index 19d2459..889e5c7 100644 (file)
@@ -1859,5 +1859,27 @@ function doTemplateNoYesSelectionBox ($template, $clear, $formField) {
        return $OUT;
 }
 
+// Helper function to add extra content for member area (module=login)
+function doTemplateMemberFooterExtras ($template, $clear) {
+       // Is a member logged in?
+       if (!isMember()) {
+               // This shall not happen
+               debug_report_bug(__FUNCTION__, __LINE__, 'Please use this template helper only for logged-in members.');
+       } // END - if
+
+       // Init filter data
+       $filterData = array(
+               'userid'   => getMemberId(),
+               'template' => $template,
+               'output'   => '',
+       );
+
+       // Run the filter chain
+       $filterData = runFilterChain('member_footer_extras', $filterData);
+
+       // Return output
+       return $filterData['output'];
+}
+
 // [EOF]
 ?>
index e6599d2..267e31f 100644 (file)
@@ -1,5 +1,5 @@
 <div align="center">
-<form accept-charset="UTF-8" id="earning_$content[earning_id]" action="{%url=modules.php?module=login&amp;what=earnings%}" method="post">
+<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>
index 6510c70..20d763b 100644 (file)
@@ -1,5 +1,5 @@
 <div align="center">
-<form accept-charset="UTF-8" id="earning_$content[earning_id]" action="{%url=modules.php?module=login&amp;what=earnings%}" method="post">
+<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>
index be554d5..8773c04 100644 (file)
@@ -4,4 +4,5 @@
        </td>
 </tr>
 </table>
-<!-- Fuss unterhalb des Mitgliederbereiches //-->
+
+{%template,MemberFooterExtras%}