Jump to content

Data from DB


Grimloch

Recommended Posts

OK. What I am trying to do is add the capability in a newsletter sending script on PHP-Fusion ver7, to send an email/newsletter to a single user. Right now the script will send 'individual emails' to every user in db OR the same except using a BCC function on the first username. I am having trouble just getting the select function to work for displaying ALL users from the db. I realize this has probably been addressed many times over but I can't seem to find anything that relates exactly to what I am trying to do. Any help would be appreciated. Here is the 'select code' I'm trying to use.

 

echo "<td class='tbl'></td>\n";
$result = dbquery("SELECT *	FROM ".DB_USERS."");
$user_data = dbarray($result);
echo "<td class='tbl'>Single User <select name='delivery' class='textbox' style='width:170px;'>\n";
for ($i = 0; $i < count($user_data['user_name']); $i++) { echo $user_data['user_name'][$i]; }
echo "</select>\n";
echo "</td></tr>\n<tr>\n";

Link to comment
Share on other sites

I appreciate your response though it didn't really help the overall problem. I think I need to start over. I have a newsletter script written for PHP-Fusion ver7.00.5 which as written, allows you to send newsletters to your membership using either 'ind' individual emails or using 'bcc'. I am trying to modify the script to be able to send to a single user (later I may look at selecting multiple users); delivery type is saved in the db as $delivery. The code I have added so far properly updates the db when I save a newsletter, updating '$delivery' field as either 'ind' or 'bcc' or 'uem'.... uem is a variable I added to cover 'user email' to a single user. I think that I need to use a 'switch(case)' function which I have never used before. So in the code I am about to post, I need to know if this is the proper way to set up a 'switch(case)' scenario. I still have to write the code to actually send to a single user and right now I KNOW that the way I'm selecting a single user is not working right. I'm very new to php programming, so I sure would appreciate some input on this. Thanks in advance. Here's the code so far (complete script):

<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright © 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: newsletters_admin.php
| Author: Digitanium
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../../maincore.php";
require_once THEMES."templates/admin_header.php";

if (!checkrights("NLA") || !defined("iAUTH") || $_GET['aid'] != iAUTH) { redirect("../index.php"); }

include INFUSIONS."newsletters/infusion_db.php";

if (file_exists(INFUSIONS."newsletters/locale/".$settings['locale'].".php")) {
include INFUSIONS."newsletters/locale/".$settings['locale'].".php";
} else {
include INFUSIONS."newsletters/locale/English.php";
}

if (isset($_POST['save'])) {
$subject = addslash($_POST['subject']);
$content = addslash($_POST['content']);
$format = (preg_check("/^(html|plain)$/", $_POST['format']) ? $_POST['format'] : "html");
$delivery = (preg_check("/^(uem|ind|bcc)$/", $_POST['delivery']) ? $_POST['delivery'] : "uem");
if (isset($_GET['newsletter_id']) && isnum($_GET['newsletter_id'])) {
	$result = dbquery("UPDATE ".DB_NEWSLETTERS." SET newsletter_subject='$subject', newsletter_content='".$content."', newsletter_format='".$format."', newsletter_delivery='".$delivery."' WHERE newsletter_id='".$_GET['newsletter_id']."'");
	opentable($locale['nl411']);
	echo "<div style='text-align:center'><br />\n".$locale['nl415']."<br /><br />\n";
	echo "<a href='".FUSION_SELF.$aidlink."'>".$locale['nl421']."</a><br /><br />\n";
	echo "<a href='".ADMIN."index.php".$aidlink."'>".$locale['nl422']."</a><br /><br />\n";
	echo "</div>\n";
	closetable();
} else {
	$result = dbquery("INSERT INTO ".DB_NEWSLETTERS." (newsletter_subject, newsletter_content, newsletter_format, newsletter_delivery, newsletter_datestamp) VALUES('".$subject."', '".$content."', '".$format."', '".$delivery."', '".time()."')");
	opentable($locale['nl410']);
	echo "<div style='text-align:center'><br />\n".$locale['nl414']."<br /><br />\n";
	echo "<a href='".FUSION_SELF.$aidlink."'>".$locale['nl421']."</a><br /><br />\n";
	echo "<a href='".ADMIN."index.php".$aidlink."'>".$locale['nl422']."</a><br /><br />\n";
	echo "</div>\n";
	closetable();
}
} else if (isset($_POST['send'])) {

// Switch case goes here dependant on value of $delivery ... ind OR bcc is 1st case ... uem i.e. single user is 2nd case ... default is to continue
// switch ($delivery)
//    {
//    case ($delivery=='ind' || $delivery=='bcc'):

require_once INFUSIONS."newsletters/newsletters_include.php";
$error = "";
$subject = stripslash($_POST['subject']);
if ($_POST['format'] == "plain") {
	$content = stripslash($_POST['content']);
} else if ($_POST['format'] == "html") {
	$content = "<html>\n<head>\n";
	$content .= "<style type='text/css'>\n<!--\n";
	$content .= "a { color: #0000ff; text-decoration:none; }\n";
	$content .= "a:hover { color: #0000ff; text-decoration: underline; }\n";
	$content .= "body { font-family:Verdana,Tahoma,Arial,Sans-Serif; }\n";
	$content .= "p { font-family:Verdana,Tahoma,Arial,Sans-Serif; }\n";
	$content .= ".td { font-family:Verdana,Tahoma,Arial,Sans-Serif; }\n";
	$content .= "-->\n</style>\n</head>\n<body leftmargin='0' marginwidth='0' topmargin='0' marginheight='0' offset='0' bgcolor='#c0c0c0'>\n";
	$content .= stripslashes($_POST['content'])."\n";
	$content .= "</body>\n</html>\n";
}
_load_PHPMailer();
$mail = new MyMailer;
$mail->Subject = $subject;
if ($_POST['format'] == 'plain') {
	$mail->Body = $content;
} else {
	$mail->AltBody = $locale['nl423'];
	$mail->Body = $content;
  }
$result = dbquery("SELECT tu.user_id, tu.user_name, tu.user_email	FROM ".DB_USERS." tu WHERE user_newsletter='1' AND user_status='0'");
if (dbrows($result)) {
	$rows = dbrows($result); $bcc_list = "";
	while ($data = dbarray($result)) {
		if ($_POST['delivery'] == "bcc") {
			$mail->AddBcc($data['user_email']);
		} else {
			$mail->AddAddress($data['user_email'], $data['user_name']);
			if (!$mail->Send()) {
				$error = $locale['nl418'];
			}
			if ($rows > 1) {
				$mail->ClearAddresses();
			}
		}
  }
  if ($_POST['delivery'] == "bcc") {
		if (!$mail->Send()) {
			$error = $locale['nl418'];
		}
  }
} else {
	$error = $locale['nl419'];
}
opentable($locale['nl412']);
echo "<div style='text-align:center'><br />\n";
if (!$error) {
	echo $locale['nl416']."<br /><br />\n";
} else {
	echo $locale['nl417']."<br /><br />\n".$error."<br /><br />\n";
}
echo "<a href='".FUSION_SELF.$aidlink."'>".$locale['nl421']."</a><br /><br />\n";
echo "<a href='".ADMIN."index.php'>".$locale['nl422']."</a><br /><br />\n";
echo "</div>\n";
closetable();
// break;

//    case ($delivery=='uem'):

// New mail send routine for single user goes here if $delivery is equal to uem

// break;
// default:
//        echo "You should never ever get here";
//        break;
// }
// End of switch case stuff
// Rest of original code is below here

} else if (isset($_POST['delete']) && (isset($_POST['newsletter_id']) && isnum($_POST['newsletter_id']))) {
$result = dbquery("DELETE FROM ".DB_NEWSLETTERS." WHERE newsletter_id='".$_POST['newsletter_id']."'");
opentable($locale['nl413']);
echo "<div style='text-align:center'><br />\n".$locale['nl420']."<br /><br />\n";
echo "<a href='".FUSION_SELF.$aidlink."'>".$locale['nl421']."</a><br /><br />\n";
echo "<a href='".ADMIN."index.php".$aidlink."'>".$locale['nl422']."</a><br /><br />\n";
echo "</div>\n";
closetable();
} else {
if (isset($_POST['preview'])) {
	$subject = phpentities(stripslash($_POST['subject']));
	$content = phpentities(stripslash($_POST['content']));
	$plain = ($_POST['format'] == "plain" ? " checked" : "");
	$html = ($_POST['format'] == "html" ? " checked" : "");
	$uem = ($_POST['delivery'] == "uem" ? " checked" : "");
	$ind = ($_POST['delivery'] == "ind" ? " checked" : "");
	$bcc = ($_POST['delivery'] == "bcc" ? " checked" : "");
	if ($_POST['format'] == "plain") {
		$contentpreview = nl2br(stripslash($_POST['content']));
	} else {
		$contentpreview = stripslash($_POST['content']);
	}
	opentable($subject);
	echo "$contentpreview\n";
	closetable();
	tablebreak();
}
opentable($locale['nl400']);
include INFUSIONS."newsletters/nwsheader_include.php";
$editlist = ""; $sel = "";
$result = dbquery("SELECT * FROM ".DB_NEWSLETTERS." ORDER BY newsletter_datestamp DESC");
if (dbrows($result) != 0) {
	while ($data = dbarray($result)) {
		if (isset($newsletter_id)) $sel = ($newsletter_id == $data['newsletter_id'] ? " selected" : "");
		$editlist .= "<option value='".$data['newsletter_id']."'$sel>".$data['newsletter_subject']."</option>\n";
	}
}
echo "<div style='text-align:center'>\n<form name='selectform' method='post' action='".FUSION_SELF.$aidlink."'>\n";
echo "<select name='newsletter_id' class='textbox' style='width:250px;'>\n".$editlist."</select>\n";
echo "<input type='submit' name='edit' value='".$locale['nl401']."' class='button'>\n";
echo "<input type='submit' name='delete' value='".$locale['nl402']."' onclick='return DeleteNewsletter();' class='button'><br /><br />\n";
echo "<a href='newsletters_subs.php".$aidlink."'>".$locale['nl403']."</a>\n";
echo "</form>\n</div>\n";
closetable();
tablebreak();
if (isset($_POST['edit']) && (isset($_POST['newsletter_id']) && isnum($_POST['newsletter_id']))) {
	$result = dbquery("SELECT * FROM ".DB_NEWSLETTERS." WHERE newsletter_id='".$_POST['newsletter_id']."'");
	if (dbrows($result) != 0) {
		$data = dbarray($result);
		$subject = phpentities(stripslashes($data['newsletter_subject']));
		$content = phpentities(stripslashes($data['newsletter_content']));
		$plain = ($data['newsletter_format'] == "plain" ? " checked='checked'" : "");
		$html = ($data['newsletter_format'] == "html" ? " checked='checked'" : "");
		$uem = ($data['newsletter_delivery'] == "uem" ? " checked='checked'" : "");
		$ind = ($data['newsletter_delivery'] == "ind" ? " checked='checked'" : "");
		$bcc = ($data['newsletter_delivery'] == "bcc" ? " checked='checked'" : "");
	}
}
if ((isset($_POST['newsletter_id']) && isnum($_POST['newsletter_id'])) || (isset($_GET['newsletter_id']) && isnum($_GET['newsletter_id']))) {
	opentable($locale['nl411']);
} else {
	if (!isset($_POST['preview'])) {
		$subject = "";
		$content = "";
		$plain = "";
		$html = "";
		$uem = "";
		$ind = "";
		$bcc = "";
	}
	$action = FUSION_SELF;
	opentable($locale['nl410']);
}
echo "<form name='inputform' method='post' action='".FUSION_SELF.$aidlink."' onSubmit='return ValidateForm(this)'>\n";
echo "<table align='center' cellspacing='0' cellpadding='0' class='center'>\n<tr>\n";
echo "<td width='100' class='tbl'>".$locale['nl430']."</td>\n";
echo "<td class='tbl'><input type='text' name='subject' value='$subject' class='textbox' style='width:250px;'></td>\n";
echo "</tr>\n<tr>\n";
echo "<td valign='top' width='100' class='tbl'>".$locale['nl431']."</td>\n";
echo "<td class='tbl'><textarea name='content' cols='95' rows='15' class='textbox'>$content</textarea></td>\n";
echo "</tr>\n<tr>\n";
echo "<td class='tbl'>".$locale['nl433']."</td>\n";
echo "<td class='tbl'><input type='radio' name='format' value='plain'".$plain.">".$locale['nl434']."\n";
echo "<input type='radio' name='format' value='html'".$html.">".$locale['nl435']."</td>\n";
echo "</tr>\n<tr>\n";
echo "<td colspan='2' align='left' valign='top'><table cellpadding='0' cellspacing='0' border='0'><tr>\n";
echo "<td class='tbl' align='left'>".$locale['nl439']."</td>\n";
echo "<td class='tbl'><input type='radio' name='delivery' value='ind'".$ind.">".$locale['nl440']."\n";
echo "<input type='radio' name='delivery' value='bcc'".$bcc.">".$locale['nl441']."</td>\n";
echo "<td class='tbl'><input type='radio' name='delivery' value='uem'".$uem.">".$locale['nl442']."</td>\n";
echo "</tr>\n</table>\n";
echo "</td>\n</tr>\n<tr>\n";

// Begin area for testing new single user email send code

echo "<td class='tbl'></td>\n";
echo "<td class='tbl'>".$locale['nl443']." <select name='sendto'  class='textbox' style='width:150px;'>";
$result = dbquery("SELECT * FROM ".DB_USERS." WHERE user_level<'104' ORDER BY user_name");
if (dbrows($result) != 0) {
while ($data = dbarray($result)) {

            $selected = ( isset($_GET['user_email']) && $_GET['user_email'] == $data['user_email']) ? 'selected="selected"' : '';

            echo "<option value='".$data['user_email']."'$selected>".$data['user_name']."</option>\n";
          }

}
echo "</select></td>\n";
echo "</tr>\n<tr>\n";

// End area for new code testing

echo "<td align='center' colspan='2' class='tbl'><br />\n";
echo "<input type='submit' name='preview' value='".$locale['nl436']."' class='button'>\n";
echo "<input type='submit' name='save' value='".$locale['nl437']."' class='button'>\n";
echo "<input type='submit' name='send' value='".$locale['nl438']."' class='button'></td>\n";
echo "</tr>\n</table>\n</form>\n";
closetable();
echo "<script language=\"JavaScript\">
function DeleteNewsletter() {
return confirm('".$locale['nl451']."');
}
function ValidateForm(frm) {
if(frm.subject.value=='') {
	alert('".$locale['nl450']."');
	return false;
}
}
</script>\n";
}

require_once THEMES."templates/footer.php";
?>

 

I have where I think the switch code should go as comments.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.