<?php
/************************************************************************
- * MXChange v0.2.1 Start: 09/28/2003 *
- * =============== Last change: 08/05/2004 *
+ * Mailer v0.2.1-FINAL Start: 09/28/2003 *
+ * =================== Last change: 08/05/2004 *
* *
* -------------------------------------------------------------------- *
* File : what-send_bonus.php *
* -------------------------------------------------------------------- *
* Kurzbeschreibung : An alle Mitglieder Bonus-Mails verschicken *
* -------------------------------------------------------------------- *
- * *
+ * $Revision:: $ *
+ * $Date:: $ *
+ * $Tag:: 0.2.1-FINAL $ *
+ * $Author:: $ *
+ * Needs to be in all Files and every File needs "svn propset *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
* -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder *
+ * Copyright (c) 2003 - 2009 by Roland Haeder *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
************************************************************************/
// Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) {
- $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
- require($INC);
-} elseif (!EXT_IS_ACTIVE("order")) {
- ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "order"));
- return;
-}
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+ die();
+} // END - if
// Add description as navigation point
-ADD_DESCR("admin", basename(__FILE__));
-
-$whereStatement = " WHERE visible='Y'";
-if (is_admin()) $whereStatement = "";
-$EXT_HTML = EXT_IS_ACTIVE("html_mail");
-if (empty($_GET['mode'])) $_GET['mode'] = "select";
+addMenuDescription('admin', __FILE__);
-if (isset($_POST['ok']))
-{
- // Check if category and number of receivers is okay
- $CAT_TABS = "%s"; $CAT_WHERE = ""; $cat = "";
- if ($_POST['cat'] > 0)
- {
- // Select category
- $CAT_TABS = "LEFT JOIN "._MYSQL_PREFIX."_user_cats AS c ON d.userid=c.userid";
- $cat = bigintval($_POST['cat']);
- $CAT_WHERE = " AND c.cat_id=%d";
- }
- if (GET_EXT_VERSION("holiday") >= "0.1.3")
- {
- // Add something for the holiday extension
- $CAT_WHERE .= " AND d.holiday_active='N'";
- }
-
- if (($EXT_HTML) && ($_GET['mode'] == "html"))
- {
- // Only include HTML receivers
- $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",
- array($cat, $_CONFIG['order_select'], $_CONFIG['order_mode'], bigintval($_POST['receiver'])), __FILE__, __LINE__);
- }
- else
- {
- // Include all
- $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",
- array($cat, $_CONFIG['order_select'], $_CONFIG['order_mode'], bigintval($_POST['receiver'])), __FILE__, __LINE__);
- }
- if ((SQL_NUMROWS($result) == $_POST['receiver']) && ($_POST['receiver'] > 0))
- {
- $RECEIVER = "";
- while (list($REC) = SQL_FETCHROW($result))
- {
- // Add receiver when not empty
- if (!empty($REC)) $RECEIVER .= ";".$REC;
- }
-
- // Free memory
- SQL_FREERESULT($result);
- $RECEIVER = substr($RECEIVER, 1);
+if (!isExtensionActive('order')) {
+ loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('order'));
+ return;
+} // END - if
- // Gettings points is oka, so we can add $USED later from
- if ($EXT_HTML)
- {
- $HTML = 'N';
- if ($_GET['mode'] == "html") $HTML = 'Y';
- $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_bonus
-(subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, html_msg)
-VALUES ('%s', '%s', '%s', '%s', '%s', 'NEW', UNIX_TIMESTAMP(), '%s', '%s', '%s', '%s', '%s')",
- array(
- $_POST['subject'],
- addslashes($_POST['text']),
- $RECEIVER,
- $_POST['points'],
- $_POST['seconds'],
- $_POST['url'],
- $cat,
- SELECTION_COUNT(explode(";", $RECEIVER)),
- bigintval($_POST['receiver']),
- $HTML
-), __FILE__, __LINE__);
- }
- else
- {
- $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_bonus
-(subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent)
-VALUES ('%s', '%s', '%s', '%s', '%s', 'NEW', UNIX_TIMESTAMP(), '%s', '%s', '%s', '%s')",
- array(
- $_POST['subject'],
- addslashes($_POST['text']),
- $RECEIVER,
- $_POST['points'],
- $_POST['seconds'],
- $_POST['url'],
- $cat,
- SELECTION_COUNT(explode(";", $RECEIVER)),
- bigintval($_POST['receiver']),
-), __FILE__, __LINE__);
- }
+// Set empty mode to "select"
+if (!isGetRequestParameterSet('mode')) setGetRequestParameter('mode', 'select');
- // Mail inserted into bonus pool
- LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_SEND);
- }
- else
- {
- // More entered than can be reached!
- LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MORE_SELECTED);
- }
- if (!empty($URL))
- {
- // Redirect to requested URL
- LOAD_URL($URL);
- }
+if (isFormSent()) {
+ // Deliver bonus mail
+ addNewBonusMail(postRequestArray(), getRequestParameter('mode'));
} else {
- $result = SQL_QUERY("SELECT id, cat FROM "._MYSQL_PREFIX."_cats".$whereStatement." ORDER BY sort", __FILE__, __LINE__);
- if (SQL_NUMROWS($result) > 0)
- {
- $MORE = "";
- if ($_GET['mode'] == "html") $MORE = " AND html='Y'";
- if (GET_EXT_VERSION("holiday") >= "0.1.3")
- {
- // Add something for the holiday extension
- $MORE .= " AND holiday_active='N'";
- }
-
- $result_all = SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE status='CONFIRMED' AND receive_mails > 0".$MORE, __FILE__, __LINE__);
- define('__ALL_VALUE', SQL_NUMROWS($result_all));
- // Initialize array...
- $CATS = array(
- 'id' => array(),
- 'name' => array(),
- 'uids' => array()
- );
- // ... and begin loading stuff
- while (list($id, $cat) = SQL_FETCHROW($result))
- {
- $CATS['id'][] = $id;
- $CATS['name'][] = $cat;
- $result_uids = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_cats WHERE cat_id=%d",
- array(bigintval($id)), __FILE__, __LINE__);
- $uid_cnt = "0";
- while (list($ucat) = SQL_FETCHROW($result_uids))
- {
- $result_ver = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data
-WHERE userid=%d AND status='CONFIRMED' AND receive_mails > 0".$MORE." LIMIT 1",
- array(bigintval($ucat)), __FILE__, __LINE__);
- $uid_cnt += SQL_NUMROWS($result_ver);
-
- // Free memory
- SQL_FREERESULT($result_ver);
- }
-
- // Free memory
- SQL_FREERESULT($result_uids);
- $CATS['uids'][] = $uid_cnt;
- }
-
- // Free memory
- SQL_FREERESULT($result);
-
- if (!empty($MSG))
- {
- // We got system message so we drop it out to the user
- LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
- }
- if ($EXT_HTML)
- {
- // If HTML extension is active
- define('__HTML_SELECT', LOAD_TEMPLATE("admin_send_bonus_html", true));
- }
- else
- {
- // And if not
- define('__HTML_SELECT', "");
- }
-
- // Generate options
- $OUT = "";
- foreach ($CATS['id'] as $key=>$value)
- {
- if (strlen($CATS['name'][$key]) > 20) $CATS['name'][$key] = substr($CATS['name'][$key], 0, 17)."...";
- $OUT .= " <OPTION value=\"".$value."\">".$CATS['name'][$key]." (".$CATS['uids'][$key]." ".USER_IN_CAT.")</OPTION>\n";
- }
- define('__OPTION_LINES', $OUT);
-
- // Store send mode
- define('__MODE', $_GET['mode']);
-
- // Select template
- switch($_GET['mode'])
- {
- case "html": // HTML mails
- case "normal": // Normal mails
- $template = "admin_send_bonus_form";
+ // Get all available users
+ $content['all'] = translateComma(getTotalReceivers(getRequestParameter('mode')));
+
+ // Prepare option lines
+ $content['options_lines'] = generateCategoryOptionsList(getRequestParameter('mode'));
+
+ // Store send mode
+ $content['mode'] = getRequestParameter('mode');
+
+ $content['html_select'] = '';
+ if (isExtensionActive('html_mail')) {
+ // If HTML extension is active
+ $content['html_select'] = loadTemplate('admin_send_bonus_html', true);
+ } // END - if
+
+ // Select template
+ switch(getRequestParameter('mode')) {
+ case 'html': // HTML mails
+ case 'normal': // Normal mails
+ $template = 'admin_send_bonus_form';
break;
- case "select": // Selection
- $template = "admin_send_bonus_select";
+ case 'select': // Selection
+ $template = 'admin_send_bonus_select';
break;
- }
+ } // END - switch
- // Load template
- LOAD_TEMPLATE($template);
- }
- else
- {
- // No cateogries are defined yet
- OUTPUT_HTML("<STRONG><SPAN class=\"member_failed\">".MEMBER_NO_CATS."</SPAN></STRONG>");
- }
+ // Load template
+ loadTemplate($template, false, $content);
}
-//
+// [EOF]
?>