]> git.joonet.de Git - adminer.git/commitdiff
E-mail sending only in Editor
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 24 Jul 2009 10:52:24 +0000 (10:52 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 24 Jul 2009 10:52:24 +0000 (10:52 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@899 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/include/adminer.inc.php
adminer/select.inc.php
changes.txt
editor/include/adminer.inc.php
todo.txt

index a91850f7afebed957b829b830873df95ebdd0ced..bfb1263fe9898eefbbe01977a89a7de8383b6f88 100644 (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
index 537928b5988e6aeba836b92bcb0bd9a20fcb5441..0db2463bc141fde173e4b28c99b564720d304344 100644 (file)
@@ -109,72 +109,63 @@ 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
-               $result = true;
-               $affected = 0;
-               $command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : ($_POST["clone"] ? "INSERT INTO " : "UPDATE ")) . idf_escape($_GET["select"]);
-               if (!$_POST["delete"]) {
-                       $set = array();
-                       foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
-                               $val = process_input($name, $fields[$name]);
-                               if ($_POST["clone"]) {
-                                       $set[] = ($val !== false ? $val : idf_escape($name));
-                               } elseif ($val !== false) {
-                                       $set[] = idf_escape($name) . " = $val";
+       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"]);
+                       if (!$_POST["delete"]) {
+                               $set = array();
+                               foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
+                                       $val = process_input($name, $fields[$name]);
+                                       if ($_POST["clone"]) {
+                                               $set[] = ($val !== false ? $val : idf_escape($name));
+                                       } elseif ($val !== false) {
+                                               $set[] = idf_escape($name) . " = $val";
+                                       }
                                }
+                               $command .= ($_POST["clone"] ? "\nSELECT " . implode(", ", $set) . "\nFROM " . idf_escape($_GET["select"]) : " SET\n" . implode(",\n", $set));
                        }
-                       $command .= ($_POST["clone"] ? "\nSELECT " . implode(", ", $set) . "\nFROM " . idf_escape($_GET["select"]) : " SET\n" . implode(",\n", $set));
-               }
-               if ($_POST["delete"] || $set) {
-                       if ($_POST["all"] || ($primary === array() && $_POST["check"])) {
-                               $result = queries($command . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
-                               $affected = $dbh->affected_rows;
-                       } else {
-                               foreach ((array) $_POST["check"] as $val) {
-                                       // where is not unique so OR can't be used
-                                       $result = queries($command . "\nWHERE " . where_check($val) . "\nLIMIT 1");
-                                       if (!$result) {
-                                               break;
+                       if ($_POST["delete"] || $set) {
+                               if ($_POST["all"] || ($primary === array() && $_POST["check"])) {
+                                       $result = queries($command . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
+                                       $affected = $dbh->affected_rows;
+                               } else {
+                                       foreach ((array) $_POST["check"] as $val) {
+                                               // where is not unique so OR can't be used
+                                               $result = queries($command . "\nWHERE " . where_check($val) . "\nLIMIT 1");
+                                               if (!$result) {
+                                                       break;
+                                               }
+                                               $affected += $dbh->affected_rows;
                                        }
-                                       $affected += $dbh->affected_rows;
                                }
                        }
-               }
-               query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result, false, !$result);
-               //! display edit page in case of an error
-       } elseif (is_string($file = get_file("csv_file"))) {
-               $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
-               $cols = "";
-               $rows = array(); //! packet size
-               preg_match_all('~("[^"]*"|[^"\\n]+)+~', $file, $matches);
-               foreach ($matches[0] as $key => $val) {
-                       $row = array();
-                       preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $matches2);
-                       if (!$key && !array_diff($matches2[1], array_keys($fields))) { //! doesn't work with column names containing ",\n
-                               // first row corresponds to column names - use it for table structure
-                               $cols = " (" . implode(", ", array_map('idf_escape', $matches2[1])) . ")";
-                       } else {
-                               foreach ($matches2[1] as $col) {
-                                       $row[] = (!strlen($col) ? "NULL" : $dbh->quote(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
+                       query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result, false, !$result);
+                       //! display edit page in case of an error
+               } elseif (is_string($file = get_file("csv_file"))) {
+                       $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
+                       $cols = "";
+                       $rows = array(); //! packet size
+                       preg_match_all('~("[^"]*"|[^"\\n]+)+~', $file, $matches);
+                       foreach ($matches[0] as $key => $val) {
+                               $row = array();
+                               preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $matches2);
+                               if (!$key && !array_diff($matches2[1], array_keys($fields))) { //! doesn't work with column names containing ",\n
+                                       // first row corresponds to column names - use it for table structure
+                                       $cols = " (" . implode(", ", array_map('idf_escape', $matches2[1])) . ")";
+                               } else {
+                                       foreach ($matches2[1] as $col) {
+                                               $row[] = (!strlen($col) ? "NULL" : $dbh->quote(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
+                                       }
+                                       $rows[] = "\n(" . implode(", ", $row) . ")";
                                }
-                               $rows[] = "\n(" . implode(", ", $row) . ")";
                        }
+                       $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . "$cols VALUES" . implode(",", $rows));
+                       query_redirect(queries(), remove_from_uri("page"), lang('%d row(s) has been imported.', $dbh->affected_rows), $result, false, !$result);
+               } else {
+                       $error = upload_error($file);
                }
-               $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . "$cols VALUES" . implode(",", $rows));
-               query_redirect(queries(), remove_from_uri("page"), lang('%d row(s) has been imported.', $dbh->affected_rows), $result, false, !$result);
-       } else {
-               $error = upload_error($file);
        }
 }
 
@@ -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";
        }
index 2679f4ccf471c1cb6fbab969ed50fea7971d7a03..0f75f025329e0a05970fe3a016eab39cee15377c 100644 (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)
index 8103e43bca49c8865914d28012b9ee2b8752038a..b5d51d7069481f9aec352cb26975b1dd71835733 100644 (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);
 }
index 4a540ba9cd9079e04218dd971ac8a2147e2b05d1..c909968a5f1bf4723760a1310a42491a6475ef7c 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -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