コード例 #1
0
ファイル: contact_form.php プロジェクト: tareqy/Caracal
 /**
  * Public function that creates a single instance
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #2
0
ファイル: fdacademy.php プロジェクト: Way2CU/FD-Academy-Site
 /**
  * Constructor
  */
 protected function __construct()
 {
     parent::__construct(__FILE__);
     $mailer = new FdMailer($this);
     if (class_exists('contact_form')) {
         contact_form::getInstance()->registerMailer('fd', $mailer);
     }
 }
コード例 #3
0
ファイル: mandrill.php プロジェクト: tareqy/Caracal
 /**
  * Constructor
  */
 protected function __construct()
 {
     global $section;
     parent::__construct(__FILE__);
     // register mailer
     if (class_exists('contact_form')) {
         $mailer = new Mandrill_Mailer($this->language, $this->settings['api_key']);
         $contact_form = contact_form::getInstance();
         $contact_form->registerMailer('mandrill', $mailer);
     }
     // register backend
     if (class_exists('backend') && $section == 'backend') {
         $backend = backend::getInstance();
         $mandrill_menu = new backend_MenuItem($this->getLanguageConstant('menu_mandrill'), url_GetFromFilePath($this->path . 'images/icon.svg'), window_Open('mandrill_settings', 370, $this->getLanguageConstant('title_settings'), true, true, backend_UrlMake($this->name, 'settings')), $level = 5);
         $backend->addMenu($this->name, $mandrill_menu);
     }
 }
コード例 #4
0
ファイル: contact.php プロジェクト: anilch/Personel
$PAGE->set_context($systemcontext);
$PAGE->set_title(get_string('contact_title', 'local_admission'));
require_login();
$PAGE->set_url('/local/admission/contact.php');
$PAGE->set_heading(get_string('pluginname', 'local_admission'));
$PAGE->navbar->add(get_string('pluginname', 'local_admission'), new moodle_url('/local/admission/viewapplicant.php'));
$PAGE->navbar->add(get_string('contactapplicant', 'local_admission'));
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('manage', 'local_admission'));
$hierarchy = new hierarchy();
$admision = cobalt_admission::get_instance();
if (isset($CFG->allowframembedding) and !$CFG->allowframembedding) {
    echo $OUTPUT->box(get_string('contactapplicants', 'local_admission'));
}
$returnurl = new moodle_url('/local/admission/viewapplicant.php');
$mform = new contact_form(null, array('id' => $id));
$data = $mform->get_data();
$mform->display();
if ($mform->is_cancelled()) {
    redirect($returnurl);
}
if ($data) {
    $user = $DB->get_field('local_admission', 'email', array('id' => $data->id));
    $from = $USER->email;
    $subject = $data->subject;
    $body = $data->message;
    mail($user, $subject, $body, $from);
    $message = get_string('contactsuccess', 'local_admission');
    $style = array('style' => 'notifysuccess');
    $hierarchy->set_confirmation($message, $returnurl, $style);
}
コード例 #5
0
ファイル: user_manager.php プロジェクト: tareqy/Caracal
 /**
  * Show form for selecting email templates for notifying users.
  */
 private function showTemplateSelection()
 {
     if (class_exists('contact_form')) {
         // get contact form and show settings
         $contact_form = contact_form::getInstance();
         $template = new TemplateHandler('email_templates.xml', $this->parent->path . 'templates/');
         $template->setMappedModule($this->parent->name);
         $template->registerTagHandler('cms:templates', $contact_form, 'tag_TemplateList');
         $params = array('form_action' => backend_UrlMake($this->parent->name, 'email_templates_save'), 'cancel_action' => window_Close('system_users_email_templates'));
         $template->restoreXML();
         $template->setLocalParams($params);
         $template->parse();
     } else {
         // contact form module is not active, show message instead
         $template = new TemplateHandler('message.xml', $this->parent->path . 'templates/');
         $template->setMappedModule($this->parent->name);
         $params = array('message' => $this->parent->getLanguageConstant('message_no_contact_form'), 'button' => $this->parent->getLanguageConstant('close'), 'action' => window_Close('system_users_email_templates'));
         $template->restoreXML();
         $template->setLocalParams($params);
         $template->parse();
     }
 }
コード例 #6
0
ファイル: system_mailer.php プロジェクト: tareqy/Caracal
 /**
  * Finalize message and send it to specified addresses.
  *
  * @return boolean
  */
 public function send()
 {
     $result = false;
     $content = '';
     $headers = array();
     $contact_form = contact_form::getInstance();
     // make sure we are not being scammed
     if ($contact_form->detectBots()) {
         trigger_error('Bot detected. Ignoring mail send request!', E_USER_WARNING);
         return $result;
     }
     // ensure we have all the required information
     if (is_null($this->sender) || empty($this->sender)) {
         trigger_error('No sender specified. Can not send email!', E_USER_WARNING);
         return $result;
     }
     if (is_null($this->subject)) {
         trigger_error('No subject specified. Can not send email!', E_USER_WARNING);
         return $result;
     }
     if (is_null($this->plain_body)) {
         trigger_error('Empty message body. Can not send email!', E_USER_WARNING);
         return $result;
     }
     if (count($this->recipients) + count($this->recipients_cc) + count($this->recipients_bcc) == 0) {
         trigger_error('Empty recipient list. Can not send email!', E_USER_WARNING);
         return $result;
     }
     // prepare recipients
     $to = implode(', ', $this->recipients);
     // prepare boundaries
     $boundary = md5(time() . '--global--' . rand() * 10000);
     $content_boundary = md5(time() . '--content--' . rand() * 10000);
     // prepare headers
     $headers['From'] = $this->sender;
     $headers['Cc'] = implode(', ', $this->recipients_cc);
     $headers['Bcc'] = implode(', ', $this->recipients_bcc);
     // add content type to headers
     if (count($this->attachments) == 0) {
         // no attachments available
         if (is_null($this->html_body)) {
             $headers['Content-Type'] = 'text/plain';
             $headers['Content-Transfer-Encoding'] = 'base64';
         } else {
             $headers['Content-Type'] = "multipart/alternative; boundary={$boundary}";
         }
     } else {
         // set proper content type for message with attachments
         $headers['Content-Type'] = "multipart/mixed; boundary={$boundary}";
     }
     // prepare content
     $plain_text_body = $this->replace_fields($this->plain_body);
     $html_body = $this->replace_fields($this->html_body);
     $subject = $this->replace_fields($this->subject);
     // create content
     if ($headers['Content-Type'] == 'text/plain') {
         $content .= base64_encode($plain_text_content) . "\n";
     } else {
         // starting global boundary
         $content .= "--{$boundary}\n";
         if (is_null($this->html_body)) {
             // add plain text body
             $content .= "Content-Type: text/plain; charset=UTF-8\n";
             $content .= "Content-Transfer-Encoding: base64\n\n";
             $content .= base64_encode($plain_text_body) . "\n";
         } else {
             $content .= "Content-Type: multipart/alternative; boundary={$content_boundary}\n\n";
             // add plain text body
             $content .= "--{$content_boundary}\n";
             $content .= "Content-Type: text/plain; charset=UTF-8\n";
             $content .= "Content-Transfer-Encoding: base64\n\n";
             $content .= base64_encode($plain_text_body) . "\n";
             // add html body
             $content .= "--{$content_boundary}\n";
             $content .= "Content-Type: text/html; charset=UTF-8\n";
             $content .= "Content-Transfer-Encoding: base64\n\n";
             $content .= base64_encode($html_body) . "\n";
             $content .= "--{$content_boundary}--\n";
         }
         // add attachments if needed
         if (count($this->attachments) > 0) {
             foreach ($this->attachments as $file) {
                 $name = basename($file);
                 $body .= $this->make_attachment($file, $name, $boundary);
             }
         }
         // add ending boundary
         $content .= "--{$boundary}--\n";
     }
     // send email
     $result = $this->perform_send($to, $subject, $headers, $content);
     return $result;
 }
コード例 #7
0
ファイル: shop.php プロジェクト: tareqy/Caracal
 /**
  * Send email for transaction using specified template.
  *
  * @param object $transaction
  * @param string $template
  * @return boolean
  */
 private function sendTransactionMail($transaction, $template)
 {
     global $language;
     $result = false;
     // require contact form
     if (!class_exists('contact_form')) {
         return $result;
     }
     $email_address = null;
     $contact_form = contact_form::getInstance();
     // template replacement data
     $fields = array('transaction_id' => $transaction->id, 'transaction_uid' => $transaction->uid, 'status' => $transaction->status, 'handling' => $transaction->handling, 'shipping' => $transaction->shipping, 'total' => $transaction->total, 'weight' => $transaction->weight, 'payment_method' => $transaction->payment_method, 'delivery_method' => $transaction->delivery_method, 'remark' => $transaction->remark, 'token' => $transaction->token, 'timestamp' => $transaction->timestamp);
     $timestamp = strtotime($transaction->timestamp);
     $fields['date'] = date($this->getLanguageConstant('format_date_short'), $timestamp);
     $fields['time'] = date($this->getLanguageConstant('format_time_short'), $timestamp);
     // get currency
     $currency_manager = ShopCurrenciesManager::getInstance();
     $currency = $currency_manager->getSingleItem($currency_manager->getFieldNames(), array('id' => $transaction->currency));
     if (is_object($currency)) {
         $fields['currency'] = $currency->currency;
     }
     // add buyer information
     $buyer_manager = ShopBuyersManager::getInstance();
     $buyer = $buyer_manager->getSingleItem($buyer_manager->getFieldNames(), array('id' => $transaction->buyer));
     if (is_object($buyer)) {
         $fields['buyer_first_name'] = $buyer->first_name;
         $fields['buyer_last_name'] = $buyer->last_name;
         $fields['buyer_email'] = $buyer->email;
         $fields['buyer_uid'] = $buyer->uid;
         $email_address = $buyer->email;
     }
     // add system user information
     $user_manager = UserManager::getInstance();
     $user = $user_manager->getSingleItem($user_manager->getFieldNames(), array('id' => $transaction->system_user));
     if (is_object($user)) {
         $fields['user_name'] = $user->username;
         $fields['user_fullname'] = $user->fullname;
         $fields['user_email'] = $user->email;
         if (is_null($email_address) || empty($email_address)) {
             $email_address = $user->email;
         } else {
             if ($email_address != $user->email) {
                 $email_address = $email_address . ',' . $user->email;
             }
         }
     }
     // add buyer address
     $address_manager = ShopDeliveryAddressManager::getInstance();
     $address = $address_manager->getSingleItem($address_manager->getFieldNames(), array('id' => $transaction->address));
     if (is_object($address)) {
         $fields['address_name'] = $address->name;
         $fields['address_street'] = $address->street;
         $fields['address_street2'] = $address->street2;
         $fields['address_phone'] = $address->phone;
         $fields['address_city'] = $address->city;
         $fields['address_zip'] = $address->zip;
         $fields['address_state'] = $address->state;
         $fields['address_country'] = $address->country;
     }
     // create item table
     switch ($transaction->type) {
         case TransactionType::SHOPPING_CART:
             $item_manager = ShopTransactionItemsManager::getInstance();
             $items = $item_manager->getItems($item_manager->getFieldNames(), array('transaction' => $transaction->id));
             if (count($items) > 0) {
                 // create items table
                 $text_table = str_pad($this->getLanguageConstant('column_name'), 40);
                 $text_table .= str_pad($this->getLanguageConstant('column_price'), 8);
                 $text_table .= str_pad($this->getLanguageConstant('column_amount'), 6);
                 $text_table .= str_pad($this->getLanguageConstant('column_item_total'), 8);
                 $text_table .= "\n" . str_repeat('-', 40 + 8 + 6 + 8) . "\n";
                 $html_table = '<table border="0" cellspacing="5" cellpadding="0">';
                 $html_table .= '<thead><tr>';
                 $html_table .= '<td>' . $this->getLanguageConstant('column_name') . '</td>';
                 $html_table .= '<td>' . $this->getLanguageConstant('column_price') . '</td>';
                 $html_table .= '<td>' . $this->getLanguageConstant('column_amount') . '</td>';
                 $html_table .= '<td>' . $this->getLanguageConstant('column_item_total') . '</td>';
                 $html_table .= '</td></thead><tbody>';
                 foreach ($items as $item) {
                     // append item name with description
                     if (empty($data['description'])) {
                         $line = $item->name[$language] . ' (' . $item->description . ')';
                     } else {
                         $line = $item->name[$language];
                     }
                     $line = utf8_wordwrap($line, 40, "\n", true);
                     $line = mb_split("\n", $line);
                     // append other columns
                     $line[0] = $line[0] . str_pad($item->price, 8, ' ', STR_PAD_LEFT);
                     $line[0] = $line[0] . str_pad($item->amount, 6, ' ', STR_PAD_LEFT);
                     $line[0] = $line[0] . str_pad($item->total, 8, ' ', STR_PAD_LEFT);
                     // add this item to text table
                     $text_table .= implode("\n", $line) . "\n\n";
                     // form html row
                     $row = '<tr><td>' . $item->name[$language];
                     if (!empty($item->description)) {
                         $row .= ' <small>' . $item->description . '</small>';
                     }
                     $row .= '</td><td>' . $item->price . '</td>';
                     $row .= '<td>' . $item->amount . '</td>';
                     $row .= '<td>' . $item->total . '</td></tr>';
                     // update subtotal
                     $subtotal += $item->total;
                 }
                 // close text table
                 $text_table .= str_repeat('-', 40 + 8 + 6 + 8) . "\n";
                 $html_table .= '</tbody>';
                 // create totals
                 $text_table .= str_pad($this->getLanguageConstant('column_subtotal'), 15);
                 $text_table .= str_pad($subtotal, 10, ' ', STR_PAD_LEFT) . "\n";
                 $text_table .= str_pad($this->getLanguageConstant('column_shipping'), 15);
                 $text_table .= str_pad($transaction->shipping, 10, ' ', STR_PAD_LEFT) . "\n";
                 $text_table .= str_pad($this->getLanguageConstant('column_handling'), 15);
                 $text_table .= str_pad($transaction->handling, 10, ' ', STR_PAD_LEFT) . "\n";
                 $text_table .= str_repeat('-', 25);
                 $text_table .= str_pad($this->getLanguageConstant('column_total'), 15);
                 $text_table .= str_pad($transaction->total, 10, ' ', STR_PAD_LEFT) . "\n";
                 $html_table .= '<tfoot>';
                 $html_table .= '<tr><td colspan="2"></td><td>' . $this->getLanguageConstant('column_subtotal') . '</td>';
                 $html_table .= '<td>' . $subtotal . '</td></tr>';
                 $html_table .= '<tr><td colspan="2"></td><td>' . $this->getLanguageConstant('column_shipping') . '</td>';
                 $html_table .= '<td>' . $transaction->shipping . '</td></tr>';
                 $html_table .= '<tr><td colspan="2"></td><td>' . $this->getLanguageConstant('column_handling') . '</td>';
                 $html_table .= '<td>' . $transaction->handling . '</td></tr>';
                 $html_table .= '<tr><td colspan="2"></td><td><b>' . $this->getLanguageConstant('column_total') . '</b></td>';
                 $html_table .= '<td><b>' . $transaction->total . '</b></td></tr>';
                 $html_table .= '</tfoot>';
                 // close table
                 $html_table .= '</table>';
                 // add field
                 $fields['item_table'] = $text_table;
             }
             break;
         case TransactionType::SUBSCRIPTION:
             $plan_manager = ShopTransactionPlansManager::getInstance();
             $plan = $plan_manager->getSingleItem($plan_manager->getFieldNames(), array('transaction' => $transaction->id));
             // get payment method
             $plan_data = null;
             if (isset($this->payment_methods[$transaction->payment_method])) {
                 $payment_method = $this->payment_methods[$transaction->payment_method];
                 $plans = $payment_method->get_recurring_plans();
                 if (isset($plans[$plan->plan_name])) {
                     $plan_data = $plans[$plan->plan_name];
                 }
             }
             // populate fields with plan params
             if (is_object($plan) && !is_null($plan_data)) {
                 $fields['plan_text_id'] = $plan->plan_name;
                 $fields['plan_name'] = $plan_data['name'][$language];
             }
             break;
     }
     // we require email address for sending
     if (is_null($email_address) || empty($email_address)) {
         return $result;
     }
     // get mailer
     $mailer = $contact_form->getMailer();
     $sender = $contact_form->getSender();
     $template = $contact_form->getTemplate($template);
     // start creating message
     $mailer->start_message();
     $mailer->set_subject($template['subject']);
     $mailer->set_sender($sender['address'], $sender['name']);
     $mailer->add_recipient($email_address);
     $mailer->set_body($template['plain_body'], $template['html_body']);
     $mailer->set_variables($fields);
     // send email
     $mailer->send();
     return $result;
 }