CMS  Version 3.9
email_helper.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::using("email", "captcha");
8 
10 {
11  static function displaySendResultMessage($msg)
12  {
13  global $config;
14 
15  $class = "";
16  if ($msg==1)
17  {
18  $text = "Your message has been sent.";
19  }
20  elseif($msg==2)
21  {
22  $class = "fail";
23  $text = "The email could not be sent. Please contact <a href=\"mailto:{$config['email_contact']}\">{$config["email_name"]}</a> for help.";
24  }
25 
26  if($msg)
27  {
28  echo "<div id='message_send_result' class='{$class}'>{$text}</div>\n";
29  }
30  }
31 
32  static function buildContactUsForm($form, $requiredMessage = true)
33  {
34  global $user;
35 
36  if($user)
37  {
38  $form->data->set("full_name", $user->first_name . " " . $user->last_name);
39  $form->data->set("email", $user->email);
40  $form->readOnly("full_name", "email");
41  }
42 
43  $form->required("full_name", "email", "subject");
44  if ($requiredMessage) $form->required("message");
45 
46  $form->submitLabel = "Send";
47  $form->formCSS = "form";
48  $form->regexp("email", "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", "Please supply a valid email address containing a domain name.");
49 
50  $form->alias("email", "Your Email");
52  if(count($topicList) > 0)
53  {
54  $aboutSelect = new SelectFieldRenderer($form, "contact_topic_id" , "About", $topicList);
55  }
56  else
57  {
58  $form->hide("contact_topic_id");
59  }
60 
61  $captchaMode = Settings::getValue("email", "use_captcha");
62  if ($captchaMode == "Always" || ($captchaMode == "Anonymous Only" && !$user))
63  {
64  $captchaMgr = new CaptchaManager();
65  $captchaMgr->addCaptchaToForm($form);
66  }
67 
68  $form->customSaveHandler = array(EmailHelper, sendContactUs);
69 
70  return $form;
71  }
72 
82  function sendContactUs($form)
83  {
84  $contactUs =& $form->data;
85 
86  $email = new EmailTemplate();
87  $email->sender_email = $contactUs->email;
88 
89  $email->recipients = Settings::getValue('email', 'default_contact_us_recipient');
90  if (!$email->recipients)
91  {
92  $email->recipients = Settings::getValue('email', 'email_from');
93  }
94 
95  $contactTopic = $contactUs->ContactTopic();
96  if($contactTopic && $contactTopic->recipients)
97  {
98  $email->recipients = $contactTopic->recipients;
99  }
100 
101  if($contactTopic)
102  {
103  $email->subject = $contactTopic->topic . " ";
104  }
105 
106  $email->subject .= $contactUs->subject;
107  $email->message = "Message From: {$contactUs->full_name} {$contactUs->email}</br></br>" . $contactUs->message;
108 
110 
111  // can be empty
112  $mgr->attachments = $contactUs->get("attachment");
113  $rtn = $mgr->sendEmail();
114 
115  if(!$rtn)
116  {
117  $form->msg = "Email send failed.";
118  }
119 
120  $contactUs->save();
121  return $rtn;
122  }
123 }?>
$form
Provides a central management class for event handlers and common functionality for the captcha compo...
static formatList()
Definition: contact_us.inc:84
static displaySendResultMessage($msg)
static buildContactUsForm($form, $requiredMessage=true)
sendContactUs($form)
customSaveHandler callback for contact_us form.
Takes an email template and an obj of any DataItem class and sends email to a list of recipients afte...
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
global $user
$captchaMode
if(! $contact_us_id) $contactUs
$topicList
Definition: group_form.inc:53
global $config
Definition: import.inc:4
$msg
Definition: save.inc:10