Advertisement
citstudio

Email Newsletter 3 : Controllers

Jun 23rd, 2014
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.36 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('BASEPATH'))
  4.     exit('No direct script access allowed');
  5.  
  6. class Registration extends CI_Controller {
  7.  
  8.     public function __construct() {
  9.         parent::__construct();
  10.         $this->data['site_title'] = 'Registration';
  11.         $this->data['current_url'] = current_url();
  12.     }
  13.  
  14.     public function unsubscribe() {
  15.         $email = $this->input->get('m');
  16.         $this->db->query("UPDATE mt_guest SET unsubscribe='Y' WHERE email '".$email."'"));
  17.         $this->data['page_title'] = "Thank you";
  18.         $this->data['message'] = "You will be no longer to receive our offers.";
  19.     $this->load->view('yourFile',$this->data);
  20.     }
  21.  
  22.     public function complete_subscribe() {
  23.         if ($this->input->server('REQUEST_METHOD') == 'POST') {
  24.             $this->load->helper("citstudio-mailer/mailer");
  25.             $this->load->library("SMTP_validateEmail");
  26.  
  27.             $data['mail'] = $email = $this->input->post('mail-subscriber');
  28.             $data['code'] = $code = $this->input->post('verification-code');
  29.             $data['name'] = $name = $this->input->post('name-subscriber');
  30.  
  31.             $mx_email_validator = new SMTP_validateEmail();
  32.             $check_mx_email = $mx_email_validator->validEmail($email);
  33.             if (!$check_mx_email) {
  34.                 $this->data['page_title'] = "Subscribe Signup Error";
  35.                 $this->data['pages'] = $this->data['error_pages'] . "subscribe";
  36.                 $this->data['message'] = "We're Sorry, we're only send great Information to a Human";
  37.         $this->load->view('yourFile',$this->data);
  38.             } else {
  39.                 if ($this->subscribe_check($email, TRUE, $data)) {
  40.                     $content = subscribe_finish($data['mail'], $data['name']);
  41.                     $dump = sendmail($content);
  42.                     redirect(base_url(), 'refresh');
  43.                 } else {
  44.                     $this->data['page_title'] = "Subscribe Signup Error " . $mail;
  45.                     $this->data['message'] = "We're Sorry, email already taken.";
  46.             $this->load->view('yourFile',$this->data); 
  47.                 }
  48.             }
  49.         } else {
  50.             $this->data['page_title'] = "Subscribe Signup Error";
  51.             $this->data['message'] = "We're Sorry, we're only send great Information to a Human";
  52.             $this->load->view('yourFile',$this->data);
  53.         }
  54.     }
  55.  
  56.     public function subscribe_check($mail, $insert = FALSE, $data = NULL) {
  57.         $result = TRUE;
  58.         $rec = $this->db->query("SELECT * FROM mt_guest WHERE email='".$mail."' AND type='SUBSCRIBER'")->result_array();
  59.         if (sizeof($rec) > 0) {
  60.             $result = FALSE;
  61.         }
  62.         if ($insert) {
  63.             $email = $data['mail'];
  64.             $name = $data['name'];
  65.             $code = $data['code'];
  66.         $this->db->query("INSERT INTO mt_guest (fields) VALUES (value)")
  67.             $this->crud->create("mt_guest", $in);
  68.             $result = TRUE;
  69.         }
  70.         return $result;
  71.     }
  72.  
  73.     public function subscribe() {
  74.         // check if mail-subscriber parameter are provided
  75.         $mail = @$_REQUEST["mail-subscriber"];
  76.         $code = @$_GET["activation-code"];
  77.  
  78.  
  79.         if (isset($mail)) {
  80.  
  81.             $this->load->helper("citstudio-mailer/mailer");
  82.             $this->load->library("SMTP_validateEmail");
  83.  
  84.             $mx_email_validator = new SMTP_validateEmail();
  85.             $check_mx_email = $mx_email_validator->validEmail($mail);
  86.             if (!$check_mx_email) {
  87.                 $this->data['page_title'] = "Subscribe Signup Error";
  88.                 $this->data['pages'] = $this->data['error_pages'] . "subscribe";
  89.                 $this->data['message'] = "We're Sorry, we're only send great Information to a Human";
  90.         $this->load->view('yourFile',$this->data);
  91.             } else {
  92.                 $this->data['email'] = $mail;
  93.                 if (!$this->subscribe_check($mail)) {
  94.                     $this->data['page_title'] = "Subscribe Signup Error " . $mail;
  95.                     $this->data['message'] = "We're Sorry, email already taken.";
  96.             $this->load->view('yourFile',$this->data);
  97.                 } else {
  98.                     $_subscribe["email"] = $mail;
  99.                     $_subscribe["confirmation_code"] = md5("code" . " Subscribe" . $mail);
  100.  
  101.                     if ($this->input->server('REQUEST_METHOD') == 'GET') {
  102.                         $this->data['activation_code'] = $_subscribe["confirmation_code"];
  103.                     } else {
  104.                         if (!isset($code)) {
  105.                             $content = subscribe_verify_content($mail, $_subscribe["confirmation_code"]);
  106.                             $dump = sendmail($content);
  107.                         }
  108.  
  109.                         $this->data['activation_code'] = "";
  110.                         if (isset($code)) {
  111.                             $this->data['activation_code'] = $code;
  112.                         }
  113.                     }
  114.                     $this->data['page_title'] = "Subscribe Signup";
  115.                     $this->data['pages'] = $this->data['view'];
  116.                 $this->load->view('yourFile',$this->data);
  117.                 }
  118.             }
  119.         } else {
  120.             $this->data['page_title'] = "Subscribe Signup Error";
  121.             $this->data['message'] = "We're Sorry. The page cannot be found.";
  122.         }
  123.         $this->load->view('yourFile',$this->data);
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement