CMS  Version 3.9
mail_to.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 /*
35  * Provides a modal dialog "Mail To" form as an alternative
36  * for the often sluggish performance of a user's mail client.
37  *
38  * @author Janice Gallant for Sonjara, Inc.
39  *
40  * 4/15/2011
41  */
42 
43 
44 Fakoli::using("email");
45 Fakoli::usingFeature("auto_form");
46 
47 $to = ConnectionManager::escape($_GET["to"]);
48 $subject = ConnectionManager::escape($_GET["subject"]);
49 $message = ConnectionManager::escape($_GET["message"]);
50 
52 
53 $email->recipients = ($to) ? $to : "";
54 $email->subject = ($subject) ? $subject : "";
55 $email->message = ($message) ? $message : "";
56 
57 $form = new AutoForm($email);
58 $form = new AutoForm($email, "POST", "/action/email/mail_to?to=$to&subject=$subject&message=$message", "MailTo_form");
59 
60 $form->hide("sender_email", "class_name", "name");
61 $form->ajaxSubmit("function(result) {new EmailManager().sendMailTo(result);}", "function() {document.id('{$form->id}_error').set('text','Failed to communicate with server'); }");
62 $form->button("Cancel", "new EmailManager().closeMailToDialog()", null, true);
63 $form->submitLabel = "Send Email";
64 $form->validator->add(new EmailListValidator("recipients", "Recipients"));
65 $form->required("recipients", "subject", "message");
66 $form->override("message", $label = "Message", new TextFieldRenderer($form));
67 $form->getRenderer("message")->rows = 10;
68 $form->override("recipients", $label = "To", new StringFieldRenderer($form));
69 
70 if ($method == "POST")
71 {
72  $obj =& $form->data;
73  $obj->fromPOST();
74  $msg = $form->validator->validate();
75  if ($msg == "")
76  {
77  $mgr = new EmailHandler($obj->recipients, $obj->subject, $obj->message, $user->email);
78  $mgr->send();
79  echo "OK";
80  return;
81  }
82  else
83  {
84  echo $msg;
85  return;
86  }
87 }
88 
89 echo $form->writeScript();
90 
91 $form->drawForm();
92 ?>
Email recipient list validator.
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
global $user
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$form
Definition: mail_to.inc:57
$message
Definition: mail_to.inc:49
$to
Definition: mail_to.inc:47
$email
Definition: mail_to.inc:51
$subject
Definition: mail_to.inc:48
$msg
Definition: save.inc:10