| 1 | <?php |
| 2 | /* |
| 3 | * Copyright (C) 2003-2005 Polytechnique.org |
| 4 | * http://opensource.polytechnique.org/ |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | require_once 'Plugin/Filter.php'; |
| 22 | require_once 'diogenes/diogenes.hermes.inc.php'; |
| 23 | |
| 24 | /** The MailForm plugin allows you to insert a form to send |
| 25 | * an e-mail to a fixed recipient. |
| 26 | * |
| 27 | * To make use of this plugin, insert {MailForm}in your page |
| 28 | * where the mail form should appear. |
| 29 | */ |
| 30 | class MailForm extends Diogenes_Plugin_Filter |
| 31 | { |
| 32 | /** Plugin name */ |
| 33 | var $name = "MailForm"; |
| 34 | |
| 35 | /** Plugin description */ |
| 36 | var $description = "This plugin allows you to insert a form to send an e-mail to a fixed recipient. To make use of this plugin, insert <b>{MailForm}</b> in your page where the mail form should appear."; |
| 37 | |
| 38 | /** Plugin parameters */ |
| 39 | var $params = array('email' => '', 'title' => '', 'subject_tag' => '[web form] '); |
| 40 | |
| 41 | /** Show an instance of the MailForm plugin. |
| 42 | */ |
| 43 | function show() |
| 44 | { |
| 45 | global $page; |
| 46 | |
| 47 | // get params |
| 48 | $to_email = $this->params['email']; |
| 49 | $form_title = $this->params['title']; |
| 50 | |
| 51 | if (!isvalid_email($to_email)) { |
| 52 | return '<p>You must specify a valid e-mail in the "email" parameter to make use of the MailForm plugin.<p>'; |
| 53 | } |
| 54 | |
| 55 | // get input |
| 56 | $action = clean_request('action'); |
| 57 | $from = clean_request('from'); |
| 58 | |
| 59 | $refer = strip_request('refer'); |
| 60 | if (!$refer) |
| 61 | $refer = $_SERVER['HTTP_REFERER']; |
| 62 | $message = strip_request('message'); |
| 63 | $subject = strip_request('subject'); |
| 64 | |
| 65 | $showform=0; |
| 66 | $output = ''; |
| 67 | switch($action) { |
| 68 | case "mail": |
| 69 | if ((!$subject)||(!$message)||(!$from)) { |
| 70 | $output .= '<p align="center"><strong>Missing fields !</strong></p>'; |
| 71 | $showform=1; |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | if (!isvalid_email($from)) { |
| 76 | $output .= '<p align="center"><strong>Invalid email address !</strong></p>'; |
| 77 | $showform=1; |
| 78 | break; |
| 79 | } |
| 80 | |
| 81 | $mymail = new HermesMailer(); |
| 82 | $mymail->setFrom($from); |
| 83 | $mymail->setSubject($this->params['subject_tag'].$subject); |
| 84 | $mymail->addTo($to_email); |
| 85 | $mymail->setTxtBody($message); |
| 86 | $mymail->send(); |
| 87 | |
| 88 | $output .= '<p align="center"><strong>Message sent !</strong></p>'; |
| 89 | if ($refer!="") { |
| 90 | $output .= '<p align="center">To return to referring web page click <a href="'.$refer.'">here</a></p>'; |
| 91 | } |
| 92 | break; |
| 93 | default: |
| 94 | $showform=1; |
| 95 | } |
| 96 | |
| 97 | if ($showform) { |
| 98 | $output .= |
| 99 | '<br/> |
| 100 | |
| 101 | <form action="'.$page->script_uri().'" method="post"> |
| 102 | |
| 103 | <table class="light"> |
| 104 | <tr> |
| 105 | <th colspan="2">'.$form_title.'</a></th> |
| 106 | </tr> |
| 107 | <tr> |
| 108 | <td>'.__("from").'</td> |
| 109 | <td><input type="text" name="from" size="68" value="'.$from.'" /></td> |
| 110 | </tr> |
| 111 | <tr> |
| 112 | <td>'.__("subject").'</td> |
| 113 | <td><input type="text" name="subject" size="68" value="'.$subject.'" /></td> |
| 114 | </tr> |
| 115 | <tr> |
| 116 | <td>'.__("message").'</td> |
| 117 | <td><textarea name="message" rows="10" cols="70">'.$message.'</textarea></td> |
| 118 | </tr> |
| 119 | <tr> |
| 120 | <td> </td> |
| 121 | <td> |
| 122 | <input type="hidden" name="action" value="mail" /> |
| 123 | <input type="hidden" name="refer" value="'.$refer.'" /> |
| 124 | <input type="submit" value="'.__("Send").'"/> |
| 125 | </td> |
| 126 | </tr> |
| 127 | </table> |
| 128 | |
| 129 | </form>'; |
| 130 | } |
| 131 | return $output; |
| 132 | } |
| 133 | } |
| 134 | ?> |