E-mail sending only in Editor

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@899 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2009-07-24 10:52:24 +00:00
parent 97b8c7b666
commit 00d9b3618a
5 changed files with 104 additions and 74 deletions

View file

@ -120,6 +120,22 @@ function adminer_select_val($val, $link, $field) {
return call_adminer('select_val', ($link ? "<a href=\"$link\">$return</a>" : $return), $val, $link);
}
/** Print extra text in the end of a select form
* @param array fields holding e-mails
* @return bool whether to print default extra
*/
function adminer_select_extra_display($email_fields) {
call_adminer('select_extra_display', false, $email_fields);
}
/** Process extras in select form
* @param array AND conditions
* @return bool true if processed, false to process other parts of form
*/
function adminer_select_extra_process($where) {
return call_adminer('select_extra_process', false, $where);
}
/** Query printed after execution in the message
* @param string executed query
* @return string

View file

@ -109,18 +109,8 @@ if ($_POST && !$error) {
}
exit;
}
if ($_POST["email"]) {
$sent = 0;
if ($_POST["all"] || $_POST["check"]) {
$field = idf_escape($_POST["email_field"]);
$result = $dbh->query("SELECT DISTINCT $field FROM " . idf_escape($_GET["select"]) . " WHERE $field IS NOT NULL AND $field != ''" . ($where ? " AND " . implode(" AND ", $where) : "") . ($_POST["all"] ? "" : " AND ($where_check)"));
while ($row = $result->fetch_row()) {
$sent += mail($row[0], email_header($_POST["email_subject"]), $_POST["email_message"], "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit" . ($_POST["email_from"] ? "\nFrom: " . email_header($_POST["email_from"]) : ""));
}
$result->free();
}
redirect(remove_from_uri(), lang('%d e-mail(s) have been sent.', $sent));
} elseif (!$_POST["import"]) { // edit
if (!adminer_select_extra_process($where)) {
if (!$_POST["import"]) { // edit
$result = true;
$affected = 0;
$command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : ($_POST["clone"] ? "INSERT INTO " : "UPDATE ")) . idf_escape($_GET["select"]);
@ -176,6 +166,7 @@ if ($_POST && !$error) {
} else {
$error = upload_error($file);
}
}
}
page_header(lang('Select') . ": " . adminer_table_name($table_status), $error);
@ -390,17 +381,7 @@ if (!$columns) {
}
echo "<fieldset><legend>" . lang('CSV Import') . "</legend><div><input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> <input type='submit' name='import' value='" . lang('Import') . "'></div></fieldset>\n";
//! Editor only
$email_fields = array_filter($email_fields); //! should use strlen but compile.php doesn't support array_filter
if ($email_fields) {
echo '<fieldset><legend><a href="#fieldset-email" onclick="return !toggle(\'fieldset-email\');">' . lang('E-mail') . "</a></legend><div id='fieldset-email' class='hidden'>\n";
echo "<p>" . lang('From') . ": <input name='email_from'>\n";
echo lang('Subject') . ": <input name='email_subject'>\n";
echo "<p><textarea name='email_message' rows='15' cols='60'></textarea>\n";
echo "<p>" . (count($email_fields) == 1 ? '<input type="hidden" name="email_field" value="' . htmlspecialchars(key($email_fields)) . '">' : '<select name="email_field">' . optionlist($email_fields) . '</select> ');
echo "<input type='submit' name='email' value='" . lang('Send') . "'$confirm>\n";
echo "</div></fieldset>\n";
}
adminer_select_extra_display(array_filter($email_fields)); //! should use strlen but compile.php doesn't support array_filter
echo "</form>\n";
}

View file

@ -1,10 +1,12 @@
Adminer 2.0.0:
Editor: User friendly data editor
Customization: Adminer class
E-mail sending
Table relations (Editor)
Create single column foreign key in table structure
Table relations (Editor)
Send e-mails (Editor)
Display images in blob (Editor)
Separate types to groups in table creation
Link e-mails in select
Show type in field name title (thanks to Jakub Sochor)
Preselect now() for timestamp columns (thanks to paranoiq)
Clear history (thanks to paranoiq)

View file

@ -118,6 +118,37 @@ function adminer_select_val($val, $link, $field) {
return call_adminer('select_val', ($link ? "<a href=\"$link\">$return</a>" : $return), $val, $link);
}
function adminer_select_extra_display($email_fields) {
global $confirm;
if (call_adminer('select_extra_display', true, $email_fields) && $email_fields) {
echo '<fieldset><legend><a href="#fieldset-email" onclick="return !toggle(\'fieldset-email\');">' . lang('E-mail') . "</a></legend><div id='fieldset-email' class='hidden'>\n";
echo "<p>" . lang('From') . ": <input name='email_from'>\n";
echo lang('Subject') . ": <input name='email_subject'>\n";
echo "<p><textarea name='email_message' rows='15' cols='60'></textarea>\n";
echo "<p>" . (count($email_fields) == 1 ? '<input type="hidden" name="email_field" value="' . htmlspecialchars(key($email_fields)) . '">' : '<select name="email_field">' . optionlist($email_fields) . '</select> ');
echo "<input type='submit' name='email' value='" . lang('Send') . "'$confirm>\n";
echo "</div></fieldset>\n";
}
}
function adminer_select_extra_process($where) {
global $dbh;
if ($_POST["email"]) {
$sent = 0;
if ($_POST["all"] || $_POST["check"]) {
$where_check = "(" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . ")";
$field = idf_escape($_POST["email_field"]);
$result = $dbh->query("SELECT DISTINCT $field FROM " . idf_escape($_GET["select"]) . " WHERE $field IS NOT NULL AND $field != ''" . ($where ? " AND " . implode(" AND ", $where) : "") . ($_POST["all"] ? "" : " AND ($where_check)"));
while ($row = $result->fetch_row()) {
$sent += mail($row[0], email_header($_POST["email_subject"]), $_POST["email_message"], "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit" . ($_POST["email_from"] ? "\nFrom: " . email_header($_POST["email_from"]) : ""));
}
$result->free();
}
redirect(remove_from_uri(), lang('%d e-mail(s) have been sent.', $sent));
}
return call_adminer('select_extra_process', false, $where);
}
function adminer_message_query($query) {
return call_adminer('message_query', "<!--\n" . str_replace("--", "--><!--", $query) . "\n-->", $query);
}

View file

@ -28,4 +28,4 @@ JavaScript data validation
Joining tables - PRIMARY KEY (table, joining)
Simplify search - textual, from-to
Rank, Tree structure
Treat tinyint(1) as bool
Treat tinyint(1) as bool, format date