2 /************************************************************************
3 * MXChange v0.2.1 Start: 09/28/2003 *
4 * =============== Last change: 08/05/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-send_bonus.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Send out bonus mails to all members *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : An alle Mitglieder Bonus-Mails verschicken *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif (!EXT_IS_ACTIVE("order")) {
39 ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "order"));
43 // Add description as navigation point
44 ADD_DESCR("admin", basename(__FILE__));
46 $whereStatement = " WHERE visible='Y'";
47 if (is_admin()) $whereStatement = "";
48 $EXT_HTML = EXT_IS_ACTIVE("html_mail");
49 if (empty($_GET['mode'])) $_GET['mode'] = "select";
51 if (isset($_POST['ok']))
53 // Check if category and number of receivers is okay
54 $CAT_TABS = "%s"; $CAT_WHERE = ""; $cat = "";
55 if ($_POST['cat'] > 0)
58 $CAT_TABS = "LEFT JOIN "._MYSQL_PREFIX."_user_cats AS c ON d.userid=c.userid";
59 $cat = bigintval($_POST['cat']);
60 $CAT_WHERE = " AND c.cat_id=%d";
62 if (GET_EXT_VERSION("holiday") >= "0.1.3")
64 // Add something for the holiday extension
65 $CAT_WHERE .= " AND d.holiday_active='N'";
68 if (($EXT_HTML) && ($_GET['mode'] == "html"))
70 // Only include HTML receivers
71 $result = SQL_QUERY_ESC("SELECT d.userid FROM "._MYSQL_PREFIX."_user_data AS d ".$CAT_TABS." WHERE d.status='CONFIRMED' AND d.html='Y'".$CAT_WHERE." ORDER BY d.%s %s LIMIT %s",
72 array($cat, $_CONFIG['order_select'], $_CONFIG['order_mode'], bigintval($_POST['receiver'])), __FILE__, __LINE__);
77 $result = SQL_QUERY_ESC("SELECT d.userid FROM "._MYSQL_PREFIX."_user_data AS d ".$CAT_TABS." WHERE d.status='CONFIRMED'".$CAT_WHERE." ORDER BY d.%s %s LIMIT %s",
78 array($cat, $_CONFIG['order_select'], $_CONFIG['order_mode'], bigintval($_POST['receiver'])), __FILE__, __LINE__);
80 if ((SQL_NUMROWS($result) == $_POST['receiver']) && ($_POST['receiver'] > 0))
83 while (list($REC) = SQL_FETCHROW($result))
85 // Add receiver when not empty
86 if (!empty($REC)) $RECEIVER .= ";".$REC;
90 SQL_FREERESULT($result);
91 $RECEIVER = substr($RECEIVER, 1);
93 // Gettings points is oka, so we can add $USED later from
97 if ($_GET['mode'] == "html") $HTML = 'Y';
98 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_bonus
99 (subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, html_msg)
100 VALUES ('%s', '%s', '%s', '%s', '%s', 'NEW', UNIX_TIMESTAMP(), '%s', '%s', '%s', '%s', '%s')",
103 addslashes($_POST['text']),
109 SELECTION_COUNT(explode(";", $RECEIVER)),
110 bigintval($_POST['receiver']),
112 ), __FILE__, __LINE__);
116 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_bonus
117 (subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent)
118 VALUES ('%s', '%s', '%s', '%s', '%s', 'NEW', UNIX_TIMESTAMP(), '%s', '%s', '%s', '%s')",
121 addslashes($_POST['text']),
127 SELECTION_COUNT(explode(";", $RECEIVER)),
128 bigintval($_POST['receiver']),
129 ), __FILE__, __LINE__);
132 // Mail inserted into bonus pool
133 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_SEND);
137 // More entered than can be reached!
138 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MORE_SELECTED);
142 // Redirect to requested URL
146 $result = SQL_QUERY("SELECT id, cat FROM "._MYSQL_PREFIX."_cats".$whereStatement." ORDER BY sort", __FILE__, __LINE__);
147 if (SQL_NUMROWS($result) > 0)
150 if ($_GET['mode'] == "html") $MORE = " AND html='Y'";
151 if (GET_EXT_VERSION("holiday") >= "0.1.3")
153 // Add something for the holiday extension
154 $MORE .= " AND holiday_active='N'";
157 $result_all = SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE status='CONFIRMED' AND receive_mails > 0".$MORE, __FILE__, __LINE__);
158 define('__ALL_VALUE', SQL_NUMROWS($result_all));
159 // Initialize array...
165 // ... and begin loading stuff
166 while (list($id, $cat) = SQL_FETCHROW($result))
169 $CATS['name'][] = $cat;
170 $result_uids = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_cats WHERE cat_id=%d",
171 array(bigintval($id)), __FILE__, __LINE__);
173 while (list($ucat) = SQL_FETCHROW($result_uids))
175 $result_ver = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data
176 WHERE userid=%d AND status='CONFIRMED' AND receive_mails > 0".$MORE." LIMIT 1",
177 array(bigintval($ucat)), __FILE__, __LINE__);
178 $uid_cnt += SQL_NUMROWS($result_ver);
181 SQL_FREERESULT($result_ver);
185 SQL_FREERESULT($result_uids);
186 $CATS['uids'][] = $uid_cnt;
190 SQL_FREERESULT($result);
194 // We got system message so we drop it out to the user
195 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
199 // If HTML extension is active
200 define('__HTML_SELECT', LOAD_TEMPLATE("admin_send_bonus_html", true));
205 define('__HTML_SELECT', "");
210 foreach ($CATS['id'] as $key=>$value)
212 if (strlen($CATS['name'][$key]) > 20) $CATS['name'][$key] = substr($CATS['name'][$key], 0, 17)."...";
213 $OUT .= " <OPTION value=\"".$value."\">".$CATS['name'][$key]." (".$CATS['uids'][$key]." ".USER_IN_CAT.")</OPTION>\n";
215 define('__OPTION_LINES', $OUT);
218 define('__MODE', $_GET['mode']);
221 switch($_GET['mode'])
223 case "html": // HTML mails
224 case "normal": // Normal mails
225 $template = "admin_send_bonus_form";
228 case "select": // Selection
229 $template = "admin_send_bonus_select";
234 LOAD_TEMPLATE($template);
238 // No cateogries are defined yet
239 OUTPUT_HTML("<STRONG><SPAN class=\"member_failed\">".MEMBER_NO_CATS."</SPAN></STRONG>");