2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 08/02/2011 *
4 * =================== Last change: 08/02/2011 *
6 * -------------------------------------------------------------------- *
7 * File : earning_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Functions for ext-earning *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Funktionen fuer ext-earning *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Translates the "earning group" into human-readable
44 function translateEarningGroup ($earningGroup) {
45 return sprintf("{--EARNING_GROUP_%s--}", $earningGroup);
48 // Translates the "earning name" into human-readable
49 function translateEarningProvider ($earningProvider) {
50 return sprintf("{--EARNING_PROVIDER_%s--}", $earningProvider);
54 * Generates a table (with templates) to display data for extra earnings (to
55 * the member) by given "earning name".
57 * @param $earningProvider Name of the earning
58 * @return $output Generated HTML output
60 function generateMemberEarningDataTable ($earningProvider) {
61 // Init array for filter
63 // Minimum points to get
64 'earning_min_points' => 0,
65 // Maximum points to get
66 'earning_max_points' => 0,
67 // Count of all entries
69 // -- The following arry elements are "read-only": --
70 // Exclude current userid
71 'earning_exclude_userid' => getMemberId(),
73 'earning_group' => 'INVALID',
74 // "earning name" again
75 'earning_provider' => $earningProvider
78 // Run the filter chain to get the data
79 $filterData = runFilterChain('member_earning_table_data', $filterData);
81 // Load the proper template and return it
82 $output = loadTemplate('member_earning_data_' . strtolower($filterData['earning_group']), TRUE, $filterData);
89 function doMemberEarning ($earningId, $dailyAmount, $isActive = 'Y') {
90 // Does the user have this?
91 if (countSumTotalData(bigintval($earningId), 'user_earning', 'id', 'earning_id', TRUE, ' AND `earning_userid`=' . getMemberId()) == 1) {
93 $status = updateMemberEarning($earningId, $dailyAmount, $isActive);
95 // Not found, so add it
96 $status = insertMemberEarning($earningId, $dailyAmount, $isActive);
103 // Insert member earning entry
104 function insertMemberEarning ($earningId, $dailyAmount, $isActive = 'Y') {
106 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_earning` (`earning_id`, `earning_userid`, `earning_daily_amount`, `earning_active`) VALUES(%s,%s,%s,'%s')",
108 bigintval($earningId),
110 bigintval($dailyAmount),
112 ), __FUNCTION__, __LINE__);
116 'insert_id' => getSqlInsertId(),
117 'earning_id' => bigintval($earningId),
118 'daily_amount' => bigintval($dailyAmount),
119 'is_active' => $isActive
122 // Load email template
123 $message = loadEmailTemplate('member_earning_added', $content, getMemberId());
126 sendEmail(getMemberId(), '{--MEMBER_EARNING_ADDED_SUBJECT--}', $message);
128 // Send admin notification
129 sendAdminNotification('{--ADMIN_EARNING_INSERTED_SUBJECT--}', 'admin_earning_added', $content, getMemberId());
132 return isValidId($content['insert_id']);
135 // Update a given earning amount
136 function updateMemberEarning ($earningId, $dailyAmount, $isActive = 'Y') {
137 // By default the user does subscribe to an earning
140 // Does the user cancel the earning?
141 if ($isActive == 'N') {
142 // Then update cancellation timestamp as well
143 $moreSql = ',`earning_canceled`=NOW()';
146 // Update database record
147 sqlQueryEscaped("UPDATE
148 `{?_MYSQL_PREFIX?}_user_earning`
150 `earning_daily_amount`=%s,
151 `earning_active`='%s'
157 bigintval($dailyAmount),
159 bigintval($earningId),
161 ), __FUNCTION__, __LINE__);
163 // Determine whether something has changed
164 $status = (!ifSqlHasZeroAffectedRows());
166 // Has the record changed?
167 if ($status === TRUE) {
170 'earning_id' => bigintval($earningId),
171 'daily_amount' => bigintval($dailyAmount),
172 'is_active' => $isActive
175 // Then load email template for user
176 $message = loadEmailTemplate('member_earning_updated', $content, getMemberId());
179 sendEmail(getMemberId(), '{--MEMBER_EARNING_UPDATED_SUBJECT--}', $message);
181 // Send admin notification
182 sendAdminNotification('{--ADMIN_EARNING_UPDATED_SUBJECT--}', 'admin_earning_updated', $content, getMemberId());