• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Email Library Issues

#1
I have the code 
$this->load->library('email');
which loads the library properly, or i thought...
however when i try
$this->email->from(EMAIL_FROM);
i get this
Fatal error: Call to a member function from() on a non-object in /var/screenu-www/screenu-web/screenu/application/models/customers_model.php on line 147
Reply

#2
You might try swapping out your /system/ directory for a fresh copy. Besides that, you might try turning on debug logging and see if there are any hints.
Reply

#3
(01-05-2016, 03:41 PM)skunkbad Wrote: You might try swapping out your /system/ directory for a fresh copy. Besides that, you might try turning on debug logging and see if there are any hints.

Dude, seriously? One guy has his system/ dir messed up and now everybody has to be advised to check that by default?
Reply

#4
(01-05-2016, 05:07 PM)Narf Wrote:
(01-05-2016, 03:41 PM)skunkbad Wrote: You might try swapping out your /system/ directory for a fresh copy. Besides that, you might try turning on debug logging and see if there are any hints.

Dude, seriously? One guy has his system/ dir messed up and now everybody has to be advised to check that by default?

LOL. Every once in a while I am right.
Reply

#5
(01-05-2016, 08:11 PM)skunkbad Wrote:
(01-05-2016, 05:07 PM)Narf Wrote:
(01-05-2016, 03:41 PM)skunkbad Wrote: You might try swapping out your /system/ directory for a fresh copy. Besides that, you might try turning on debug logging and see if there are any hints.

Dude, seriously? One guy has his system/ dir messed up and now everybody has to be advised to check that by default?

LOL. Every once in a while I am right.
Well here is the thing so I have two types of creating new user that calls on the email library. One type works perfectly and the other doesn't work. And the code is basically the same.... It is also within the same controller file.
Reply

#6
(01-05-2016, 11:14 PM)acheng16 Wrote:
(01-05-2016, 08:11 PM)skunkbad Wrote:
(01-05-2016, 05:07 PM)Narf Wrote:
(01-05-2016, 03:41 PM)skunkbad Wrote: You might try swapping out your /system/ directory for a fresh copy. Besides that, you might try turning on debug logging and see if there are any hints.

Dude, seriously? One guy has his system/ dir messed up and now everybody has to be advised to check that by default?

LOL. Every once in a while I am right.
Well here is the thing so I have two types of creating new user that calls on the email library. One type works perfectly and the other doesn't work. And the code is basically the same.... It is also within the same controller file.

Unless you show us some code, we really have no chance of helping you.
Reply

#7
(01-06-2016, 12:06 AM)skunkbad Wrote:
(01-05-2016, 11:14 PM)acheng16 Wrote:
(01-05-2016, 08:11 PM)skunkbad Wrote:
(01-05-2016, 05:07 PM)Narf Wrote:
(01-05-2016, 03:41 PM)skunkbad Wrote: You might try swapping out your /system/ directory for a fresh copy. Besides that, you might try turning on debug logging and see if there are any hints.

Dude, seriously? One guy has his system/ dir messed up and now everybody has to be advised to check that by default?

LOL. Every once in a while I am right.
Well here is the thing so I have two types of creating new user that calls on the email library. One type works perfectly and the other doesn't work. And the code is basically the same.... It is also within the same controller file.

Unless you show us some code, we really have no chance of helping you.

Controller:
PHP Code:
<?php

if (!defined('BASEPATH'))
    exit(
'No direct script access allowed');

class 
Register extends Public_controller {

    public function 
__construct() {
        
parent::__construct();
    }

    public function 
index() {
        
redirect('/private/register/information');
    }

    
// Demo Signup - Step 1
    
public function demo() {
        
$this->head->add('js'PRIVATE_JS '/register/information.js');
        
$this->head->add('js'GLOBAL_LIB '/cropit/jquery.cropit.js');
        
$this->head->add('css'GLOBAL_LIB '/cropit/cropit.css');
        
$this->load->library('head');
        
$this->load->library('form_validation');
        
$this->load->library('email');
        
$this->load->library('display_library');
        
$this->load->library('less_library');
        
$this->load->helper('state_helper');
        
$this->load->helper('common_helper');
        
$this->load->model('products_model');

        
$this->head->set_title('ScreenU Sign Up | Demonstration');

        
$data = array();
        
$data['page_title'] = 'ScreenU Sign Up';
        
$data['states'] = state_array();
        
$data['products'] = $this->products_model->load();

        
// Are we in the middle of a sign up?
        
$pending_customer_id $this->session->userdata('customer_id');

        
// fill form with pending information if we have it, and we're not submitting new form data
        
if ($pending_customer_id != '' && empty($_POST)):
            
$this->load->model('customers_model');
            
$this->customers_model->customer_id $pending_customer_id;
            
$pending_customer $this->customers_model->load();

            if (empty(
$pending_customer)):// if for some reason our database record went away mid-signup...
                
redirect('private/register/reset');
            else:
                foreach (
$pending_customer[0] as $k => $v):
                    
$_POST[$k] = $v;
                endforeach;
            endif;
        endif;

        
$this->form_validation
            
->set_rules('organization''Organization''required')
            ->
set_rules('contact_first_name''First Name''required')
            ->
set_rules('contact_last_name''Last Name''required');
        if (
$pending_customer_id == ''):
            
$this->form_validation->set_rules('email''Email''required|valid_email|callback_check_email|strtolower');
        else:
            
$this->form_validation->set_rules('email''Email''required|valid_email');
        endif;

        
$this->form_validation->set_rules('phone''Phone''required|min_length[10]')
            ->
set_rules('address_1''Address''required')
            ->
set_rules('city''City''required')
            ->
set_rules('state''State''required')
            ->
set_rules('product_id''Product''required');

        if (
$this->form_validation->run() === TRUE) {
            
$this->load->model('customers_model');
            
$this->load->model('user_model');
            if (
$pending_customer_id != '') { // Has the user resubmitted this page? delete existing customer/user data and re-save
                
$this->customers_model->delete($pending_customer_id);
                
$this->user_model->delete_by_customer_id($pending_customer_id);
                unset(
$pending_customer_id);
                
$this->session->unset_userdata('customer_id');
            }
            
$customer_id $this->customers_model->add_demo();
            
$this->session->set_userdata(array('customer_id' => $customer_id'product_id' => $this->input->post('product_id')));

            
redirect('private/register/demo_confirmation');
        }

        
$this->load->view('private/register/demo'$data);
    }

    
// Regular Sign Up - Step 1
    
public function information() {

        
// are we already logged in? Log 'em out...
        
$this->auth_lib->clear();
        
$this->session->unset_userdata('customer_id');

        
$this->head->add('js'PRIVATE_JS '/register/information.js');
        
$this->head->add('js'GLOBAL_LIB '/cropit/jquery.cropit.js');
        
$this->head->add('css'GLOBAL_LIB '/cropit/cropit.css');
        
$this->load->library('head');
        
$this->load->library('form_validation');
        
$this->load->library('display_library');
        
$this->load->library('less_library');
        
$this->load->library('email');
        
$this->load->helper('state_helper');
        
$this->load->helper('common_helper');
        
$this->load->model('products_model');

        
$this->head->set_title('ScreenU Sign Up | Information');

        
$data = array();
        
$data['page_title'] = 'ScreenU Sign Up';
        
$data['states'] = state_array();
        
$data['products'] = $this->products_model->load();
        
$data['terms'] = array(=> '1 year'=> '2 year (10% discount)'=> '3 year (20% discount)');

        
// Are we in the middle of a sign up?
        
$pending_customer_id $this->session->userdata('customer_id');

        
// fill form with pending information if we have it, and we're not submitting new form data
        
if ($pending_customer_id != '' && empty($_POST)):
            
$this->load->model('customers_model');
            
$this->customers_model->customer_id $pending_customer_id;
            
$pending_customer $this->customers_model->load();

            if (empty(
$pending_customer)):// if for some reason our database record went away mid-signup...
                
redirect('private/register/reset');
            else:
                foreach (
$pending_customer[0] as $k => $v):
                    
$_POST[$k] = $v;
                endforeach;
            endif;
        endif;

        
$this->form_validation->set_rules('contact_first_name''First Name''required')
            ->
set_rules('contact_last_name''Last Name''required')
            ->
set_rules('phone''Phone''required|min_length[10]')
            ->
set_rules('address_1''Address''required')
            ->
set_rules('city''City''required')
            ->
set_rules('state''State''required')
            ->
set_rules('product_id''Product''required')
            ->
set_rules('term''Term''required');

        if (
$pending_customer_id == ''):
            
$this->form_validation->set_rules('email''Email''required|valid_email|callback_check_email[email]|strtolower')
                ->
set_rules('organization''Organization''required|callback_check_organization[organization]');
        else:
            
$this->form_validation->set_rules('email''Email''required|valid_email')
                ->
set_rules('organization''Organization''required');
        endif;


        if (
$this->form_validation->run() === TRUE) {
            
$this->load->model('customers_model');
            
$this->load->model('user_model');
            if (
$pending_customer_id != '') { // Has the user resubmitted this page? delete existing customer/user data and re-save
                
$this->customers_model->delete($pending_customer_id);
                
$this->user_model->delete_by_customer_id($pending_customer_id);
                unset(
$pending_customer_id);
                
$this->session->unset_userdata('customer_id');
            }
            
$customer_id $this->customers_model->add();
            
$this->session->set_userdata(array('customer_id' => $customer_id'term' => $this->input->post('term'), 'product_id' => $this->input->post('product_id')));

            
redirect('private/register/payment');
        }

        
$this->load->view('private/register/information'$data);
    }

    
// Regular Sign Up - Step 2
    
public function payment() {
        
$this->head->add('js'PRIVATE_JS '/register/payment.js');
        
$data['page_title'] = 'ScreenU Sign Up';

        
$this->load->library('form_validation');
        
$this->load->helper('state_helper');
        
$this->load->library('email');
        
$this->load->helper('common_helper');

        
$this->head->set_title('ScreenU Sign Up | Payment');

        
// We need to be in the middle of a signup...
        
$pending_customer_id $this->session->userdata('customer_id');
        
$payment_success false;

        
// ...if not, redirect to first step
        
if ($pending_customer_id == ''):
            
redirect('/private/register/problem');
        else:
            
$this->load->model('customers_model');
            
$this->customers_model->customer_id $pending_customer_id;
            
$pending_customer $this->customers_model->load(true);
            if (
$pending_customer) {
                
$data['customer_id'] = $pending_customer->customer_id;
            } else {
                
redirect('/private/register/problem');
            }
        endif;

        
// Create or get active invoice
        
$this->load->model('invoices_model');
        
$invoice_id $this->invoices_model->check_active_invoice();
        
$this->invoices_model->initialize();
        
$this->invoices_model->invoice_id $invoice_id;
        
$invoice $this->invoices_model->load(true);

        
// Prepare CC request (in case they select payment by CC)
        
$this->load->library('cybersource_library');
        
$data['params'] = $this->cybersource_library->get_params($invoice_id$invoice->total);
        
$data['signature'] = $this->cybersource_library->sign($data['params']);

        
// Check for postback
        
if ($this->input->server('REQUEST_METHOD') == 'POST') {

            
$data = array();
            
$payment_method $this->input->post('paying_by');

            if (
$payment_method == 'invoice') {

                
// Send out welcome email
                
$this->load->model('user_model');
                
$this->user_model->user_id $this->session->userdata('user_id');
                
$signup_user $this->user_model->load(true);

                
$email_data['email'] = $pending_customer->email;
                
$email_data['organization'] = $pending_customer->organization;
                
$email_data['payment_method'] = $payment_method;

                
// Get custom email content
                
$this->load->model('contents_model');
                
$this->contents_model->slug 'registration-email-paid';
                
$email_data['custom_content_paid'] = $this->contents_model->load(true);

                
$this->contents_model->initialize();
                
$this->contents_model->slug 'registration-email-unpaid';
                
$email_data['custom_content_unpaid'] = $this->contents_model->load(true);

                
$this->email->from(EMAIL_FROM);
                
$this->email->to($email_data['email']);
                
$this->email->subject('Welcome to ' SITE_NAME);
                
$this->email->message($this->load->view('public/email/registration'$email_dataTRUE));

                
$this->email->send();

                
// Send admin notice email
                
$this->email->from(EMAIL_FROM);
                
$this->email->to(SITE_EMAIL);
                
$this->email->subject('New Sign Up at ' SITE_NAME);
                
$this->email->message($this->load->view('public/email/registration_admin'$email_dataTRUE));

                
$this->email->send();

                
// remove "pending customer" session
                
$this->session->unset_userdata('customer_id');

                
// go to confirmation page
                
redirect('private/register/confirmation');
            }
        }

        
$this->load->view('private/register/payment'$data);
    }

    
// Regular Sign Up - Successful Payment
    
public function payment_success() {

        
// This method handles all returns from the CyberSource processor. Handle signups vs. renewals by whether we're logged in or not.
        
$logged_in $this->auth_lib->is_role('private');

        if (
$logged_in) {
            
// RENEWAL
            
$this->load->model('payments_model');
            
$this->payments_model->customer_id $this->session->userdata('customer_id');

            
$this->load->model('invoices_model');
            
$invoice_id $this->invoices_model->check_renewal_invoice();

            if (!
$invoice_id) {
                
// problem with transaction
                
$this->session->set_userdata(array('status_message' => 'There was a problem with your transaction.''status_type' => 'bad'));
                
$payment_success false;

                
$this->load->private_view('purchase/problem'$data);
            } else {
                
// Get results from post
                
$result $this->input->post('decision');
                
$ref_num $this->input->post('req_transaction_uuid');
                
$notes json_encode($_POST);

                if (
$result == 'ACCEPT') {
                    if (
$this->payments_model->complete_payment($invoice_id'cc'$ref_num$notes)) {

                        
$data['product_id'] = $this->session->userdata('product_id');
                        
$data['term'] = $this->session->userdata('term');

                        
// Success! Update user and create user
                        
$this->load->model('customers_model');
                        
$this->customers_model->renew_products($this->session->userdata('customer_id'), $data['product_id'], $data['term']);

                        
$this->session->set_userdata(array('status_message' => 'Payment received successfully.''status_type' => 'good'));
                        
$payment_success true;

                        
// Clean up sessions variables
                        
$this->session->unset_userdata('invoice_id');
                        
$this->session->unset_userdata('term');
                        
$this->session->unset_userdata('product_id');

                        
redirect('/private/purchase/confirmation');
                    } else {
                        
// problem with transaction
                        
$this->session->set_userdata(array('status_message' => 'There was a problem completing your order.''status_type' => 'bad'));
                        
$payment_success false;

                        
$this->load->private_view('purchase/problem'$data);
                    }
                } else {
                    
// problem with transaction
                    
$this->session->set_userdata(array('status_message' => 'Your transaction was DECLINED.''status_type' => 'bad'));
                    
$payment_success false;

                    
$this->load->private_view('purchase/try_again'$data);
                }
            }
        } else {
            
// SIGNUP
            // We need to be in the middle of a signup...
            
$pending_customer_id $this->session->userdata('customer_id');

            
// ...if not, redirect to first step
            
if ($pending_customer_id == ''):
                
redirect('/private/register/problem');
            else:
                
$this->load->model('customers_model');
                
$this->customers_model->customer_id $pending_customer_id;
                
$pending_customer $this->customers_model->load(true);
                if (
$pending_customer) {
                    
$data['customer_id'] = $pending_customer->customer_id;
                } else {
                    
redirect('/private/register/problem');
                }
            endif;

            
$this->load->model('payments_model');
            
$this->payments_model->customer_id $pending_customer_id;

            
$this->load->model('invoices_model');
            
$invoice_id $this->invoices_model->check_active_invoice();

            if (!
$invoice_id) {
                
// problem with transaction
                
$this->session->set_userdata(array('status_message' => 'There was a problem with your transaction.''status_type' => 'bad'));
                
$payment_success false;

                
$this->load->view('private/register/problem'$data);
            } else {
                
// Get results from post
                
$result $this->input->post('decision');
                
$ref_num $this->input->post('req_transaction_uuid');
                
$notes json_encode($_POST);

                if (
$result == 'ACCEPT') {
                    if (
$this->payments_model->complete_payment($invoice_id'cc'$ref_num$notes)) {
                        
// Success! Update user and create user
                        
$this->load->model('customers_model');
                        
$this->customers_model->change_status($pending_customer_id'pending_paid');

                        
$this->load->model('user_model');
                        
$this->user_model->activate_by_customer_id($pending_customer_id);

                        
$this->session->set_userdata(array('status_message' => 'Payment received successfully.''status_type' => 'good'));
                        
$payment_success true;

                        
// Clean up sessions variables
                        
$this->auth_lib->clear();
                        
$this->session->unset_userdata('customer_id');
                        
$this->session->unset_userdata('invoice_id');
                        
$this->session->unset_userdata('term');
                        
$this->session->unset_userdata('product_id');

                        
redirect('/private/register/confirmation');
                    } else {
                        
// problem with transaction
                        
$this->session->set_userdata(array('status_message' => 'There was a problem completing your order.''status_type' => 'bad'));
                        
$payment_success false;

                        
$this->load->view('private/register/problem'$data);
                    }
                } else {
                    
// problem with transaction
                    
$this->session->set_userdata(array('status_message' => 'Your transaction was DECLINED.''status_type' => 'bad'));
                    
$payment_success false;

                    
$this->load->view('private/register/try_again'$data);
                }
            }
        } 
// logged in?
    
}

    
// Regular Sign Up - Cancelled Registration
    
public function problem() {

        
$data['page_title'] = 'ScreenU Sign Up';

        
$this->head->set_title('ScreenU Sign Up | Confirmation');

        
$this->load->view('private/register/problem'$data);
    }

    
// Regular Sign Up - Step 3
    
public function confirmation() {
        
$data['page_title'] = 'ScreenU Sign Up';

        
$this->head->set_title('ScreenU Sign Up | Confirmation');

        
$this->load->view('private/register/confirmation'$data);
    }

    
// Demo Sign Up - Step 2 
    
public function demo_confirmation() {
        
$data['page_title'] = 'ScreenU Sign Up';

        
$this->head->set_title('ScreenU Sign Up | Confirmation');

        
$this->load->view('private/register/demo_confirmation'$data);
    }

    
// Used to see if the email is already in use
    
public function check_email($email) {
        
$this->load->model('customers_model');
        
$result $this->customers_model->check_email($email);

        if (
$result) {
            return 
TRUE;
        } else {
            
$this->form_validation->set_message('check_email''That email is already registered');
            return 
FALSE;
        }
    }

    
// Used to see if the email is already in use
    
public function check_organization($organization) {
        
$this->load->model('customers_model');
        
$result $this->customers_model->check_organization($organization);

        if (
$result) {
            return 
TRUE;
        } else {
            
$this->form_validation->set_message('check_organization''That organization name is being used by another ScreenU account.');
            return 
FALSE;
        }
    }

    public function 
opauth_start() {
        
$this->load->library('auth_lib');
        
$this->config->load('Opauth');
        
// We need this so we can redirect once there loged in
        
$this->auth_lib->set_previous_url($this->agent->referrer());
        
$this->load->library('Opauth/Opauth'$this->config->item('opauth_config'), false);
        
$this->opauth->run();
    }

    public function 
opauth_callback() {
        
$this->load->library('auth_lib');
        
$this->load->library('email');
        
$this->load->model('user_model');
        
$this->load->helper('common_helper');

        
// This will try to log the user in based on the uid and provider.
        // If that fails it will register a new
        // First param is the role the uses should be created as if they do not exists (3 = public)
        // Second param is a bool to tell if the user should be created as active or inactive if they do not exist
        
$email_data $this->user_model->validate_oauth(3TRUE);


        
// Send randomly generated password to the users email account.
        
$email_data['social'] = TRUE;
        
$email_data['email'] = $email_data['email'];
        
$email_data['password'] = generate_string(8);

        
$this->email->from(EMAIL_FROM);
        
$this->email->to($email_data['email']);
        
$this->email->subject('Welcome to ' SITE_NAME);
        
$this->email->message($this->load->view('public/email/registration'$email_dataTRUE));

        
$this->email->send();

        if (
$this->auth_lib->previous_url() != '') {
            
redirect($this->auth_lib->previous_url());
        }

        
redirect('home');
    }

    
// Mostly used for JS to check if your logged in
    
public function check_login() {
        
// If they have a role there logged in
        
$logged_in $this->auth_lib->is_role('public');

        if (
$this->input->is_ajax_request() !== TRUE) {
            return 
$logged_in;
        }

        
$data = array('error' => TRUE'message' => 'Not logged in.');

        if (
$logged_in === TRUE) {
            
$data = array('error' => FALSE'message' => 'Logged in.');
        }

        echo 
json_encode($data);
    }

    
// Reset signup process
    
public function reset() {

        
$customer_id $this->session->userdata('customer_id');
        
// delete pending user data
        
if ($customer_id != ''):
            
$this->load->model('customers_model');
            
$this->load->model('user_model');
            
$this->customers_model->delete($customer_id);
            
$this->user_model->delete_by_customer_id($customer_id);

        endif;
        
$this->session->unset_userdata('customer_id');
        
redirect('/private/register/information');
    }

}

/* End of file register.php */
/* Location: ./application/controllers/private/register.php */ 

Model: 
PHP Code:
<?php

if (!defined('BASEPATH'))
    exit(
'No direct script access allowed');

class 
Customers_model extends CI_Model {

    private 
$_primary_table 'customers';
    private 
$_products_table 'products';
    private 
$_customers_products_table 'customers_products';
    public 
$customer_id NULL;
    public 
$results NULL;
    public 
$active_only FALSE;
    public 
$created_since_date NULL;
    public 
$updated_since_date NULL;
    public 
$discount_for_two 0.9;
    public 
$discount_for_three 0.8;

    private function 
_get_data() {
        
$this->load->helper('common_helper');
        
$data['status'] = $this->input->post('status');
        
$data['organization'] = $this->input->post('organization');
        
$data['slug'] = $this->input->post('slug');
        
$data['campus_size'] = $this->input->post('campus_size');
        
$data['contact_title'] = $this->input->post('contact_title');
        
$data['contact_first_name'] = $this->input->post('contact_first_name');
        
$data['contact_last_name'] = $this->input->post('contact_last_name');
        
$data['email'] = $this->input->post('email');
        
$data['phone'] = $this->input->post('phone');
        
$data['address_1'] = $this->input->post('address_1');
        
$data['address_2'] = $this->input->post('address_2');
        
$data['city'] = $this->input->post('city');
        
$data['state'] = $this->input->post('state');
        
$data['zip'] = $this->input->post('zip');
        
        if (
$this->input->post('image-data') !== ''):    
            
$image_path CUSTOMER_IMAGES_PATH;
            
$file generate_string(20) . '.jpg';
            
$file_path $image_path '/' $file;

            
$img_data $_POST['image-data'];
            list(
$t$img_data) = explode(';'$img_data);
            list(
$t$img_data explode(','$img_data);
            
$src base64_decode($img_data);
            
file_put_contents($file_path$src);

            
$data['logo'] = $file;
        endif;
        
$data['updated_at'] = date('Y-m-d H:i:s');

        return 
$data;
    }

    public function 
initialize() {
        
$this->customer_id NULL;
        
$this->slug NULL;
        
$this->email NULL;
        
$this->active_only FALSE;
        
$this->results NULL;
    }


    function 
add_customer_product($customer_id$product_id$term 1) {
        
// single product vs. "both" products
        
if( $product_id == 'both' ):
            
$this->load->model('products_model');
            
$all_products $this->products_model->load();
            foreach( 
$all_products as $all_product ):
                
$data = array(
                    
'customer_id' => $customer_id,
                    
'product_id' => $all_product->product_id,
                    
'original_term' => $term,
                    
'exp_date' => date('Y-m-d H:i:s'strtotime('+' $term ' year')),
                    
'updated_at' => date('Y-m-d H:i:s'),
                    
'created_at' => date('Y-m-d H:i:s'),
                );
                
$return $this->db->insert('customers_products'$data);
            endforeach;
        else:
            
$data = array(
                
'customer_id' => $customer_id,
                
'product_id' => $product_id,
                
'original_term' => $term,
                
'exp_date' => date('Y-m-d H:i:s'strtotime('+' $term ' year')),
                
'updated_at' => date('Y-m-d H:i:s'),
                
'created_at' => date('Y-m-d H:i:s'),
            );

            
$return $this->db->insert('customers_products'$data);
        endif;
        
        return 
$return;
    }

    public function 
add() {
        
$this->load->helper('common_helper');

        
$data $this->_get_data();
        
$data['slug'] = slugify($data['organization']);
        
$data['status'] = 'pending_unpaid'// new customers are always pending to start]
        
$data['created_at'] = date('Y-m-d H:i:s');

        
$this->db->insert($this->_primary_table$data);
        
$customer_id $this->db->insert_id();

        
// add customer products
        
if ($this->input->post('product_id')):
            
$this->add_customer_product($customer_id$this->input->post('product_id'), $this->input->post('term'));
        endif;

        return 
$customer_id;
    }

    public function 
add_demo() {
        echo (
'LOAD');
        
$this->load->library('email');
        if (isset(
$this->load->email)) {
            echo (
'LOADED');
        }
        
$this->load->helper('common_helper');

        
$data $this->_get_data();

        
$data['slug'] = slugify($data['organization']);
        
$data['status'] = 'demo'// demonstration account
        
$data['created_at'] = date('Y-m-d H:i:s');

        
$this->db->insert($this->_primary_table$data);
        
$customer_id $this->db->insert_id();

        
// add customer products
        
if ($this->input->post('product_id')):
            
$this->add_customer_product($customer_id$this->input->post('product_id'));
        endif;

        
$this->load(true);

        
// Create demo user
        
$password generate_string(8);
        
$user_data['customer_id'] = $customer_id;
        
$user_data['role_id'] = 2// default "private" user
        
$user_data['email'] = $data['email'];
        
$user_data['password'] = $password;
        
$user_data['first_name'] = $data['contact_first_name'];
        
$user_data['last_name'] = $data['contact_last_name'];
        
$this->load->model('user_model');
        
$user_id $this->user_model->add($user_data);

        
// Get custom email content
        
$this->load->model('contents_model');
        
$this->contents_model->slug 'demo-email';
        
$user_data['custom_content'] = $this->contents_model->load(true);
        
        
// Send out confirmation email
        
$this->email->from(EMAIL_FROM);
        
$this->email->to($data['email']);
        
$this->email->subject('Demo Account Created at ' SITE_NAME);
        
$this->email->message($this->load->view('public/email/demo'$user_dataTRUE));
        
$this->email->send();        

        return 
$customer_id;
    }

    public function 
edit($customer_id$update_user false) {

        
// get updated form data
        
$data $this->_get_data();

        
// are we activating a customer?
        
$this->customer_id $customer_id;
        
$old_customer $this->load(true);

        if (
$old_customer->status != 'active' && $data['status'] == 'active') {
            
// create user at this point (since we'll need to email password here.
            
$password generate_string(8);
            
$user_data['customer_id'] = $customer_id;
            
$user_data['role_id'] = 2// default "private" user
            
$user_data['email'] = $data['email'];
            
$user_data['password'] = $password;
            
$user_data['first_name'] = $data['contact_first_name'];
            
$user_data['last_name'] = $data['contact_last_name'];
            
$this->load->model('user_model');
            
$user_id $this->user_model->add($user_data);

            
// Get custom email content
            
$this->load->model('contents_model');
            
$this->contents_model->slug 'account-activation-email';
            
$user_data['custom_content'] = $this->contents_model->load(true);

            
// Send out confirmation email
            
$this->load->library('email');
            
$this->email->from(EMAIL_FROM);
            
$this->email->to($data['email']);
            
$this->email->subject('Account Activated at ' SITE_NAME);
            
$this->email->message($this->load->view('public/email/activation'$user_dataTRUE));
            
$this->email->send();
        }
        
$this->customer_id $customer_id;
        
$this->db->where($this->_primary_table '.customer_id'$this->customer_id)
            ->
update($this->_primary_table$data);
        
        if( 
$update_user ):            
            if(
$this->input->post('user_password') !== '' && $this->input->post('user_password') !== FALSE):
                
$this->load->model('user_model');
                
$customer_user $this->user_model->get_customer_user($customer_id);
                
$password_data $this->auth_lib->hash_password($this->input->post('user_password'));
                
$user_data['email'] = $this->input->post('user_email');
                
$user_data['password'] = $password_data['password'];
                
$user_data['salt'] = $password_data['salt'];
                
$this->db->where('user_id'$customer_user->user_id)
                    ->
update('users'$user_data);
            endif;
        endif;
    }

    public function 
delete($customer_id) {
        
$this->db->where('customer_id'$customer_id)
            ->
delete($this->_primary_table);
    }

    public function 
load($single false) {

        if (isset(
$this->customer_id)) {
            
$this->db->where($this->_primary_table '.customer_id'$this->customer_id);
        }

        if (isset(
$this->slug)) {
            
$this->db->where($this->_primary_table '.slug'$this->slug);
        }

        if (isset(
$this->email)) {
            
$this->db->where($this->_primary_table '.email'$this->email);
        }
        
        if (isset(
$this->created_since_date)) {
            
$this->db->where($this->_primary_table '.created_at>=''"' $this->created_since_date '"'false);
        }

        if (isset(
$this->updated_since_date)) {
            
$this->db->where($this->_primary_table '.updated_at>=''"' $this->updated_since_date '"'false);
        }

        if (isset(
$this->status)) {
            if (
is_array($this->status)):
                
$sql_where '1 AND (';
                foreach (
$this->status as $status):
                    
$sql_where .= $this->_primary_table '.status="' $status '" OR ';
                endforeach;
                
$sql_where substr($sql_where,0,strlen($sql_where)-4) . ')';
                
$this->db->where($sql_where,false,false);
            else:
                
$this->db->where($this->_primary_table '.status'$this->status);
            endif;
        }

        
$this->db
            
->select($this->_primary_table '.*')
            ->
select('users.email AS user_email')
            ->
join('users''users.customer_id = ' $this->_primary_table '.customer_id','left')
            ->
group_by($this->_primary_table '.customer_id')
 
                       ->order_by($this->_primary_table '.created_at''DESC');

        
$query $this->db->get($this->_primary_table);

        
$result $query->result();
        
        
//echo $this->db->last_query() . '<br /><br />';
        
        
if( !empty( $result ) ):
            
// get customer's products
            
$this->load->model('products_model');
            
$all_products $this->products_model->load();
            if (
$single == true):
                
$result $result[0];
                foreach( 
$all_products as $all_product ):
                    if( 
$this->has_program($result->customer_id$all_product->product_id) ) $result->products[] = $all_product->product_id;
                endforeach;
            else:
                foreach( 
$result as $v ):
                    foreach( 
$all_products as $all_product ):
                        if( 
$this->has_program($v->customer_id$all_product->product_id) ) $v->products[] = $all_product->product_id;
                    endforeach;
                endforeach;
            endif;
        endif;

        return 
$result;
    }

    public function 
change_status($customer_id$new_status '') {
        
$statuses = array('pending_unpaid''pending_paid''active''suspended');
        if (
$new_status == '' || !in_array($new_status$statuses))
            return 
false;
        
$this->db->where($this->_primary_table '.customer_id'$customer_id)
            ->
update($this->_primary_table, array('status' => $new_status));
    }

    
/**
     * Return whether customer has given program
     * 
     * @param type $customer_id
     * @return boolean
     */
    
public function has_program($customer_id$product_id$check_expired false) {
        
$this->db
            
->select('customers_products.*')
            ->
where('customers_products.customer_id'$customer_id)
            ->
where('customers_products.product_id'$product_id);

        if (
$check_expired) {
            
$this->db->where('customers_products.exp_date>=''"' date('Y-m-d H:i:s') . '"'false);
        }
        
$query $this->db->get('customers_products');

        
$result $query->result();

        
$return = ( empty($result[0]) ? false true );

        return 
$return;
    }
    
    
/**
     * Return all programs that a customer has signed up for
     * @param int $customer_id
     */
    
public function get_customer_programs($customer_id){
        
$query $this->db
                
->select('customers_products.*')
                ->
select('products.price')
                ->
select('products.title')
                ->
join('products''products.product_id = customers_products.product_id','left')
                ->
where('customers_products.customer_id'$customer_id)
                ->
group_by('products.product_id')
                ->
get('customers_products');

        
$results $query->result();

        
$return = ( empty($results) ? false $results );
        
        return 
$return;
        
    }
    
    
/**
     * Return total amount due for a customer based on their programs
     * @param array $customer_programs
     * @return float
     */
    
public function get_customer_amount($customer_programs){
        
$total 0;
        if( 
count$customer_programs ) > ){
            
$total 1500 $customer_programs[0]->original_term;
        } else {
            
$total $customer_programs[0]->price $customer_programs[0]->original_term;
        }
        
$term $customer_programs[0]->original_term;

        if( 
$term == 2){ $total $total $this->discount_for_two; } // 10% discount
        
if( $term == 3){ $total $total $this->discount_for_three; } // 20% discount    
        
        
return $total;
    }
    
    
/**
     * Renew products for a customer
     * @param int $customer_id
     * @param int $product_id
     * @param int $term
     */
    
public function renew_products($customer_id$product_id$term){
        
$this->db->select('products.*')
                ->
group_by('products.product_id');
        
        if( 
$product_id != 'both' ){
            
$this->db->where('products.product_id'$product_id);
        }
        
$query $this->db->get('products');
        
        
$products $query->result();
        
        foreach( 
$products as $product ):
            
// Check if customer already has product
            
$query $this->db
                    
->select('customers_products.*')
                    ->
join('products''products.product_id = customers_products.product_id','left')
                    ->
where('customers_products.customer_id'$customer_id)
                    ->
where('customers_products.product_id'$product->product_id)
                    ->
group_by('products.product_id')
                    ->
get('customers_products');
            
$existing_product $products $query->result();
            
            
$data = array(
                
'customer_id' => $customer_id,
                
'product_id' => $product->product_id,
                
'original_term' => $term,
                
'updated_at' => date('Y-m-d H:i:s'),
            );
            
            if( !empty(
$existing_product) ):
                
$data['exp_date'] = date('Y-m-d H:i:s'strtotime($existing_product[0]->exp_date ' +' $term ' year'));
                
$this->db->where('customers_products.customer_id'$customer_id)
                    ->
where('customers_products.product_id'$product->product_id)
                    ->
update('customers_products'$data);
            else:
                
// insert new
                
$data['exp_date'] = date('Y-m-d H:i:s'strtotime('+' $term ' year'));
                
$data['created_at'] = date('Y-m-d H:i:s');
                
$return $this->db->insert('customers_products'$data);
            endif;
            
        endforeach;
            
        return 
true;
        
    }
    
    
/**
     * Check if an organization name is already in the system
     * @param string $organization
     * @return boolean
     */
    
function check_organization($organization){
        
        
$this->load->helper('common_helper');

        
$slug slugify($organization);
        
        
$this->initialize();
        
$this->slug $slug;
        
$existing_account $this->load(true);
        
        if( 
$existing_account ){
            return 
false;
        } else {
            return 
true;
        }
    }

    
/**
     * Check if an email is already in the system (with a user or customer)
     * @param string $email
     * @return boolean
     */
    
function check_email($email){
        
        
$this->load->model('user_model');
        
$this->user_model->initialize();
        
$this->user_model->email $email;
        
$users $this->user_model->load(true);

        
$this->load->model('customers_model');
        
$this->customers_model->initialize();
        
$this->customers_model->email $email;
        
$customers $this->customers_model->load(true);
        
        if(
count($users) != || count($customers) != 0){
            return 
false;
        } else {
            return 
true;
        }
    }
    
}

/* End of file customers_model.php */
/* Location: ./application/models/customers_model.php */ 

Issue is with the add_demo function.
Reply

#8
maybe your function initialize() replace $this->email (CI library object which u loaded) with NULL value ... then u already dont have email library object .. and u using from funcion on variable $this->email which u defined as NULL
Reply

#9
Do a little debugging:


PHP Code:
// Send out confirmation email
if( ! $this->load->is_loaded('Email') )
    $this->load->library('email');

if( ! 
$this->load->is_loaded('Email') )
    exit('No email library loaded. WTF???');

if( ! 
defined('EMAIL_FROM') )
    exit('No EMAIL_FROM available');

if( ! 
defined('SITE_NAME') )
    exit('No SITE_NAME available');

$message $this->load->view('public/email/demo'$user_dataTRUE);

var_dump$message ); // Or use some other way to check the message

$this->email->from(EMAIL_FROM);
$this->email->to($data['email']);
$this->email->subject('Demo Account Created at ' SITE_NAME);
$this->email->message($message);
$this->email->send(); 
Also, what is your email config? Only default?
Reply

#10
(01-06-2016, 09:03 AM)skunkbad Wrote: Do a little debugging:


PHP Code:
// Send out confirmation email
if( ! $this->load->is_loaded('Email') )
    $this->load->library('email');

if( ! 
$this->load->is_loaded('Email') )
    exit('No email library loaded. WTF???');

if( ! 
defined('EMAIL_FROM') )
    exit('No EMAIL_FROM available');

if( ! 
defined('SITE_NAME') )
    exit('No SITE_NAME available');

$message $this->load->view('public/email/demo'$user_dataTRUE);

var_dump$message ); // Or use some other way to check the message

$this->email->from(EMAIL_FROM);
$this->email->to($data['email']);
$this->email->subject('Demo Account Created at ' SITE_NAME);
$this->email->message($message);
$this->email->send(); 
Also, what is your email config? Only default?

As i suspected the email library just isn't loading. Below is snippet of email.php
PHP Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config['protocol'] = 'mail';
$config['mailpath'] = '/usr/sbin/sendmail -t -i';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = '***********************';
$config['smtp_port'] = '465';

/* End of file email.php */
/* Location: ./application/config/email.php */ 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.