예제 #1
0
 public function __construct()
 {
     parent::__construct();
     $this->load->helper('mailer');
     $this->mailer_configured = mailer_configured();
     $this->load->helper('template');
 }
예제 #2
0
 public function __construct()
 {
     parent::__construct();
     $this->load->helper('mailer');
     $this->mailer_configured = mailer_configured();
     if ($this->mailer_configured == FALSE) {
         $this->layout->buffer('content', 'mailer/not_configured');
         $this->layout->render();
     }
 }
/**
 * @param $quote_id
 * @param $status string "accepted" or "rejected"
 * @return bool if the email was sent
 */
function email_quote_status($quote_id, $status)
{
    ini_set('display_errors', 'on');
    error_reporting(E_ALL);
    if (!mailer_configured()) {
        return false;
    }
    $CI =& get_instance();
    $CI->load->helper('mailer/phpmailer');
    $quote = $CI->mdl_quotes->where('ip_quotes.quote_id', $quote_id)->get()->row();
    $base_url = base_url('/quotes/view/' . $quote_id);
    $user_email = $quote->user_email;
    $subject = sprintf(trans('quote_status_email_subject'), $quote->client_name, strtolower(lang($status)), $quote->quote_number);
    $body = sprintf(nl2br(trans('quote_status_email_body')), $quote->client_name, strtolower(lang($status)), $quote->quote_number, '<a href="' . $base_url . '">' . $base_url . '</a>');
    return phpmail_send($user_email, $user_email, $subject, $body);
}
예제 #4
0
 public function recur($cron_key = NULL)
 {
     if ($cron_key == $this->mdl_settings->setting('cron_key')) {
         $this->load->model('invoices/mdl_invoices_recurring');
         $this->load->model('invoices/mdl_invoices');
         $this->load->helper('mailer');
         // Gather a list of recurring invoices to generate
         $invoices_recurring = $this->mdl_invoices_recurring->active()->get()->result();
         foreach ($invoices_recurring as $invoice_recurring) {
             // This is the original invoice id
             $source_id = $invoice_recurring->invoice_id;
             // This is the original invoice
             // $invoice = $this->db->where('ip_invoices.invoice_id', $source_id)->get('ip_invoices')->row();
             $invoice = $this->mdl_invoices->get_by_id($source_id);
             // Create the new invoice
             $db_array = array('client_id' => $invoice->client_id, 'invoice_date_created' => $invoice_recurring->recur_next_date, 'invoice_date_due' => $this->mdl_invoices->get_date_due($invoice_recurring->recur_next_date), 'invoice_group_id' => $invoice->invoice_group_id, 'user_id' => $invoice->user_id, 'invoice_number' => $this->mdl_invoices->get_invoice_number($invoice->invoice_group_id), 'invoice_url_key' => $this->mdl_invoices->get_url_key(), 'invoice_terms' => $invoice->invoice_terms);
             // This is the new invoice id
             $target_id = $this->mdl_invoices->create($db_array, FALSE);
             // Copy the original invoice to the new invoice
             $this->mdl_invoices->copy_invoice($source_id, $target_id);
             // Update the next recur date for the recurring invoice
             $this->mdl_invoices_recurring->set_next_recur_date($invoice_recurring->invoice_recurring_id);
             // Email the new invoice if applicable
             if ($this->mdl_settings->setting('automatic_email_on_recur') and mailer_configured()) {
                 $new_invoice = $this->mdl_invoices->get_by_id($target_id);
                 // Set the email body, use default email template if available
                 $this->load->model('email_templates/mdl_email_templates');
                 $email_template_id = $this->mdl_settings->setting('email_invoice_template');
                 if (!$email_template_id) {
                     return;
                 }
                 $email_template = $this->mdl_email_templates->where('email_template_id', $email_template_id)->get();
                 if ($email_template->num_rows() == 0) {
                     return;
                 }
                 $tpl = $email_template->row();
                 $from = !empty($tpl->email_template_from_email) ? array($tpl->email_template_from_email, $tpl->email_template_from_name) : array($invoice->user_email, "");
                 $subject = !empty($tpl->email_template_subject) ? $tpl->email_template_subject : lang('invoice') . ' #' . $new_invoice->invoice_number;
                 email_invoice($target_id, $tpl->email_template_pdf_template, $from, $invoice->client_email, $subject, $tpl->email_template_body, $tpl->email_template_cc, $tpl->email_template_bcc);
                 $this->mdl_invoices->mark_sent($target_id);
             }
         }
     }
 }
예제 #5
0
 public function passwordreset($token = null)
 {
     // Check if a token was provided
     if ($token) {
         $this->db->where('user_passwordreset_token', $token);
         $user = $this->db->get('ip_users');
         $user = $user->row();
         if (empty($user)) {
             // Redirect back to the login screen with an alert
             $this->session->set_flashdata('alert_success', trans('wrong_passwordreset_token'));
             redirect('sessions/passwordreset');
         }
         $formdata = array('user_id' => $user->user_id);
         return $this->load->view('session_new_password', $formdata);
     }
     // Check if the form for a new password was used
     if ($this->input->post('btn_new_password')) {
         $new_password = $this->input->post('new_password');
         $user_id = $this->input->post('user_id');
         if (empty($user_id) || empty($new_password)) {
             $this->session->set_flashdata('alert_error', trans('loginalert_no_password'));
             redirect($_SERVER['HTTP_REFERER']);
         }
         // Call the save_change_password() function from users model
         $this->load->model('users/mdl_users');
         $this->mdl_users->save_change_password($user_id, $new_password);
         // Update the user and set him active again
         $db_array = array('user_passwordreset_token' => '');
         $this->db->where('user_id', $user_id);
         $this->db->update('ip_users', $db_array);
         // Redirect back to the login form
         redirect('sessions/login');
     }
     // Check if the password reset form was used
     if ($this->input->post('btn_reset')) {
         $email = $this->input->post('email');
         if (empty($email)) {
             $this->session->set_flashdata('alert_error', trans('loginalert_user_not_found'));
             redirect($_SERVER['HTTP_REFERER']);
         }
         // Test if a user with this email exists
         if ($this->db->where('user_email', $email)) {
             // Create a passwordreset token
             $email = $this->input->post('email');
             $token = md5(time() . $email);
             // Save the token to the database and set the user to inactive
             $db_array = array('user_passwordreset_token' => $token);
             $this->db->where('user_email', $email);
             $this->db->update('ip_users', $db_array);
             // Send the email with reset link
             $this->load->helper('mailer');
             // Preprare some variables for the email
             $email_resetlink = site_url('sessions/passwordreset/' . $token);
             $email_message = $this->load->view('emails/passwordreset', array('resetlink' => $email_resetlink), true);
             $email_from = 'system@' . preg_replace("/^[\\w]{2,6}:\\/\\/([\\w\\d\\.\\-]+).*\$/", "\$1", base_url());
             // Mail the invoice with the pre-configured mailer if possible
             if (mailer_configured()) {
                 $this->load->helper('mailer/phpmailer');
                 if (phpmail_send($email_from, $email, trans('password_reset'), $email_message)) {
                     $email_failed = true;
                     log_message('error', $this->email->print_debugger());
                 }
             } else {
                 $this->load->library('email');
                 // Set email configuration
                 $config['mailtype'] = 'html';
                 $this->email->initialize($config);
                 // Set the email params
                 $this->email->from($email_from);
                 $this->email->to($email);
                 $this->email->subject(trans('password_reset'));
                 $this->email->message($email_message);
                 // Send the reset email
                 if ($this->email->send()) {
                     $email_failed = true;
                     log_message('error', $this->email->print_debugger());
                 }
             }
             // Redirect back to the login screen with an alert
             if (isset($email_failed)) {
                 $this->session->set_flashdata('alert_success', trans('password_reset_failed'));
             } else {
                 $this->session->set_flashdata('alert_success', trans('email_successfully_sent'));
             }
             redirect('sessions/login');
         }
     }
     return $this->load->view('session_passwordreset');
 }
예제 #6
0
 public function recur($cron_key = null)
 {
     if ($cron_key == $this->mdl_settings->setting('cron_key')) {
         $this->load->model('invoices/mdl_invoices_recurring');
         $this->load->model('invoices/mdl_invoices');
         $this->load->helper('mailer');
         // Gather a list of recurring invoices to generate
         $invoices_recurring = $this->mdl_invoices_recurring->active()->get()->result();
         foreach ($invoices_recurring as $invoice_recurring) {
             // This is the original invoice id
             $source_id = $invoice_recurring->invoice_id;
             // This is the original invoice
             // $invoice = $this->db->where('ip_invoices.invoice_id', $source_id)->get('ip_invoices')->row();
             $invoice = $this->mdl_invoices->get_by_id($source_id);
             // Create the new invoice
             $db_array = array('client_id' => $invoice->client_id, 'invoice_date_created' => $invoice_recurring->recur_next_date, 'invoice_date_due' => $this->mdl_invoices->get_date_due($invoice_recurring->recur_next_date), 'invoice_group_id' => $invoice->invoice_group_id, 'user_id' => $invoice->user_id, 'invoice_number' => $this->mdl_invoices->get_invoice_number($invoice->invoice_group_id), 'invoice_url_key' => $this->mdl_invoices->get_url_key(), 'invoice_terms' => $invoice->invoice_terms);
             // This is the new invoice id
             $target_id = $this->mdl_invoices->create($db_array, false);
             // Copy the original invoice to the new invoice
             $this->mdl_invoices->copy_invoice($source_id, $target_id);
             // Update the next recur date for the recurring invoice
             $this->mdl_invoices_recurring->set_next_recur_date($invoice_recurring->invoice_recurring_id);
             // Email the new invoice if applicable
             if ($this->mdl_settings->setting('automatic_email_on_recur') and mailer_configured()) {
                 $new_invoice = $this->mdl_invoices->get_by_id($target_id);
                 // Set the email body, use default email template if available
                 $this->load->model('email_templates/mdl_email_templates');
                 $email_template_id = $this->mdl_settings->setting('email_invoice_template');
                 if (!$email_template_id) {
                     return;
                 }
                 $email_template = $this->mdl_email_templates->where('email_template_id', $email_template_id)->get();
                 if ($email_template->num_rows() == 0) {
                     return;
                 }
                 $tpl = $email_template->row();
                 // Prepare the attachments
                 $this->load->model('upload/mdl_uploads');
                 $attachment_files = $this->mdl_uploads->get_invoice_uploads($target_id);
                 // Prepare the body
                 $body = $tpl->email_template_body;
                 if (strlen($body) != strlen(strip_tags($body))) {
                     $body = htmlspecialchars_decode($body);
                 } else {
                     $body = htmlspecialchars_decode(nl2br($body));
                 }
                 $from = !empty($tpl->email_template_from_email) ? array($tpl->email_template_from_email, $tpl->email_template_from_name) : array($invoice->user_email, "");
                 $subject = !empty($tpl->email_template_subject) ? $tpl->email_template_subject : trans('invoice') . ' #' . $new_invoice->invoice_number;
                 $pdf_template = $tpl->email_template_pdf_template;
                 $to = $invoice->client_email;
                 $cc = $tpl->email_template_cc;
                 $bcc = $tpl->email_template_bcc;
                 if (email_invoice($target_id, $pdf_template, $from, $to, $subject, $body, $cc, $bcc, $attachment_files)) {
                     $this->mdl_invoices->mark_sent($target_id);
                     $this->mdl_invoice_amounts->calculate($target_id);
                 } else {
                     log_message('warning', 'Invoice ' . $target_id . 'could not be sent. Please review your Email settings.');
                 }
             }
         }
     }
 }