Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Home_model extends CI_Model {
- public function checkContact_model()
- {
- $this->form_validation->set_rules('name','name','required|trim');
- $this->form_validation->set_rules('email','email','required|trim');
- $this->form_validation->set_rules('mobile','mobile','required|trim');
- $this->form_validation->set_rules('message','message','required|trim');
- if($this->form_validation->run())
- {
- $name = $this->input->post('name');
- $email = $this->input->post('email');
- $mobile = $this->input->post('mobile');
- $message = $this->input->post('message');
- $msg = "Name: '" .$name."'Email: '".$email."'Message: '".$message."'";
- $to = "monika.pareek@blueberrysoftech.com";
- //$from = "himanshu.jain@blueberrysoftech.com";
- $headers = 'From: himanshu.jain@blueberrysoftech.com';
- $subject = "Form submission";
- $message2 = $msg ;
- $result = mail($to,$subject,$message2,$headers);
- if($result)
- {
- redirect(base_url().'Home/');
- }else
- {
- return 0;
- }
- }
- else
- {
- return 0;
- }
- redirect(base_url().'Home');
- }
- public function registerbuyer()
- {
- //
- // echo '<pre>';
- // print_r($this->input->post());
- // echo '</pre>';
- // die();
- $this->load->library('form_validation');
- $this->form_validation->set_rules('fullname','Full Name','required');
- $this->form_validation->set_rules('mobile','Mobile number','required|numeric');
- $this->form_validation->set_rules('email','Email Address','required|valid_email');
- $this->form_validation->set_rules('username','Username','required|alpha_dash');
- $this->form_validation->set_rules('password','Password','required');
- $this->form_validation->set_error_delimiters('<div class="error label label-danger">', '</div>');
- if($this->form_validation->run())
- {
- $register_data = $this->input->post();
- $register_data['password'] = md5($this->input->post('password'));
- $this->db->select('uniqueId');
- $this->db->where('email',$register_data['email']);
- $this->db->where('deactive','false');
- $this->db->or_where('mobile',$register_data['mobile']);
- $this->db->where('deactive','false');
- $register_cust_query = $this->db->get('buyer');
- if($register_cust_query->num_rows() > 0)
- {
- $this->session->set_userdata('already_reg',1);
- redirect(base_url().'Home/login');
- }
- else
- {
- $this->db->insert('buyer',$register_data);
- $custId = 'CUST'.str_pad($this->db->insert_id(),3,0,STR_PAD_LEFT);
- $this->db->where('id',$this->db->insert_id());
- $this->db->where('deactive','false');
- $this->db->update('buyer',array('uniqueId'=>$custId));
- $this->session->set_userdata('custId',$custId);
- $this->session->set_userdata('custname',$register_data['fullname']);
- $cart_check = $this->cart->contents();
- if(!empty($cart_check))
- {
- redirect(base_url().'Home/finalstep');
- }
- else
- {
- redirect(base_url().'Home/my_account');
- }
- }
- }
- else
- {
- return false;
- // $this->session->set_userdata('validation_errors',validation_errors());
- // redirect(base_url().'Home/login');
- }
- }
- public function logincheck()
- {
- $this->db->select('uniqueId,fullname');
- $username = $this->input->post('username');
- $password = md5($this->input->post('password'));
- $this->db->where('username',$username);
- $this->db->where('password',$password);
- $this->db->where('deactive','false');
- $buyer_que = $this->db->get('buyer');
- if($buyer_que->num_rows() == 1)
- {
- $custId = $buyer_que->row()->uniqueId;
- $custname = $buyer_que->row()->fullname;
- $this->session->set_userdata('custId',$custId);
- $this->session->set_userdata('custname',$custname);
- $cart_check = $this->cart->contents();
- if(!empty($cart_check))
- {
- redirect(base_url().'Home/finalstep');
- }
- else {
- redirect(base_url().'Home/my_account');
- }
- }
- else {
- $this->session->set_userdata('not_registered',1);
- redirect(base_url().'Home/login');
- }
- }
- public function send_mail_model()
- {
- foreach($this->cart->contents() as $data)
- {
- $message = '<tr>
- <td align="left" valign="top" style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#53231a;"><div style="font-size:19px;">'.$data['id'].'<b>'.$data['name'].'</b></div>
- <div>Quantity : '.$data['qty'].'<br>
- <br>
- Price : '.$data['price'].'<br>
- SubTotal : '.$data['subtotal'].'</div></td>
- </tr>';
- }
- $this->load->library('email');
- $email = $this->input->post('email');
- $full_name = $this->input->post('fullname');
- $mobile = $this->input->post('mobile');
- $this->email->from($email, $full_name);
- $this->email->to('er.chiragnagpal@gmail.com');
- $this->email->subject('Purchase Order Query');
- $this->email->message('<table width="600" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td align="left" valign="middle" bgcolor="#000000" style="background-color:#000000; padding:20px; color:#ffffff;">
- <div style="font-size:24px;">Best Retail shop to gety your wish</div>
- <div style="font-size:32px; color:#ffbe00;">Ezone Retails</div>
- </td>
- <td width="197" align="right" valign="middle" bgcolor="#000000" style="background-color:#000000; padding:20px; color:#ffffff;"></td>
- </tr>
- </table>
- <table width="600" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#971800" style="background-color:#971800;">
- <tr>
- <td align="center" valign="top" bgcolor="#ffffff" style="background-color:#ffffff;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td align="center" valign="top" bgcolor="#971800" style="background-color:#971800; padding:20px; font-family:Georgia, Times New Roman, Times, serif;">
- <div style="color:#fffbe0; font-size:24px;"> Name : '.$full_name.' <br>'.$email.'</div>
- <div style="font-size:19px; color:#fc9600;"><br>
- <i>Mobile : '.$mobile.'</i></div>
- </td>
- </tr>
- <tr>
- <td align="left" valign="top" bgcolor="#e7e0b7" style="background-color:#e7e0b7; padding:20px;"><table width="100%" border="0" cellspacing="0" cellpadding="10" style="margin-bottom:10px;">
- </table>'.$message.'
- <table width="100%" border="0" cellspacing="0" cellpadding="10" style="margin-bottom:10px;">
- <tr>
- <td align="left" valign="top" style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000000;"><div> <br>
- <br>
- <br>
- <b>Ezone Retails </b><br>
- Panchsheel Ajmer<br>
- <b>Phone: </b>(000) 123 4567 </div></td>
- </tr>
- </table></td>
- </tr>
- </table></td>
- </tr>
- </table>');
- if($this->email->send())
- {
- $this->cart->destroy();
- return "Your Order Send Successfully. We will Contact you Soon.";
- }
- else {
- return "Mail Send Error. Please Send Again";
- }
- }
- public function emailSend_model($uid)
- {
- /**********
- email sending to customer code.
- need to check & optimize online.
- *****/
- $this->db->where('deactive','false');
- $this->db->where('uniqueId',$this->session->userdata('custId'));
- $query1 = $this->db->get('buyer');
- if($query1->num_rows()>0)
- {
- $emailto = $query1->row()->email;
- }
- if($emailto!='')
- {
- $config = Array(
- 'mailtype' => 'html',
- 'charset' => 'iso-8859-1'
- );
- $this->load->library('email', $config);
- $this->email->set_newline("\r\n");
- $data = array(
- 'success_register' => $uid,
- );
- $body = $this->load->view('purchase_invoice',$data,TRUE);
- $from_email = "info@bigserver.in";
- $this->email->from($from_email, 'Satguru HR');
- $this->email->to($emailto);
- $this->email->subject('Invoice');
- $this->email->message($body);
- }
- else
- {
- $msg = "Opps!! No email found, Invoice not send.";
- }
- if($this->email->send()) {
- return $msg = "Email sent successfully.!!!";
- return $msg;
- // $this->session->set_userdata("invoiceSent","Email sent successfully.");
- } else {
- $msg = "Opps!! Email not send.";
- return $msg;
- // $this->session->set_userdata("invoiceError",$msg);
- }
- /******* email sendind code. ends ***/
- }
- public function logout_model()
- {
- $this->session->sess_destroy();
- $this->cart->destroy();
- }
- public function checkout()
- {
- $cart_val =array();
- $custId = $this->session->userdata('custId');
- $cart_check = $this->cart->contents();
- if(!empty($cart_check))
- {
- $total_products = count($cart_check);
- $customer_id = $custId;
- $delivery_address = $this->input->post('address_selected');
- $payment_mode = $this->input->post('payment_mode');
- $couponcode = $this->input->post('couponcode');
- $order_date_and_time = date("Y-m-d H:i:s");
- $final_amount = 0;
- foreach($this->cart->contents() as $data_cart)
- {
- if($data_cart['price']!='0')
- {
- $final_amount += $data_cart['subtotal'];
- }
- }
- $final_orders = array(
- 'customer_id' => $customer_id,
- 'total_products' => $total_products,
- 'delivery_address' => $delivery_address,
- 'payment_mode' => $payment_mode,
- 'order_date_and_time' => $order_date_and_time,
- 'final_amount' => $final_amount,
- 'coupon_applied' => $couponcode
- );
- $this->db->insert('final_orders',$final_orders);
- $lastid = $this->db->insert_id();
- $uid = 'PURODR'.str_pad($lastid,7,0,STR_PAD_LEFT);
- $this->db->where('id',$lastid);
- $this->db->update('final_orders',array('unique_id'=>$uid));
- /*****end of table-1 code
- ****/
- /********
- orders_summary feilds :
- id -> done
- unique_id -> done
- customer_id -> done
- order_id -> done
- product_id -> done
- quantity -> done
- price_per_unit -> done
- subtotal -> done
- discount_percentage
- discount_value
- purchase
- ****/
- $total_amount = 0;
- foreach($this->cart->contents() as $data_cart)
- {
- if($data_cart['price']!='0')
- {
- $cart_val['product_id'] = $data_cart['id'];
- $cart_val['quantity'] = $data_cart['qty'];
- $cart_val['price_per_unit'] = $data_cart['price'];
- $cart_val['subtotal'] = $data_cart['subtotal'];
- $cart_val['customer_id']= $custId;
- $cart_val['order_id']= $uid;
- $cart_val['purchase'] = 1;
- // $cart_val['uniqueId'] = 'TEMP0100';
- // $total_amount += $data_cart['subtotal'];
- // $cart_val['final_amount'] = $final_amount;
- $this->db->insert('orders_summary',$cart_val);
- $lastInsertId = $this->db->insert_id();
- $cartId = 'ODRSUM'.str_pad($lastInsertId,8,0,STR_PAD_LEFT);
- }
- else
- {
- redirect(base_url());
- }
- }
- if($final_amount!='0')
- {
- $this->db->select('id');
- $this->db->where('unique_id',NULL);
- $this->db->where('order_id',$uid);
- $query = $this->db->get('orders_summary');
- if($query->num_rows()>0)
- {
- $lastIds = $query->result_array();
- foreach($lastIds as $data => $value)
- {
- $cartId = 'ODRSUM'.str_pad($value['id'],8,0,STR_PAD_LEFT);
- $this->db->where('id',$value['id']);
- $this->db->update('orders_summary',array('unique_id'=>$cartId));
- }
- }
- $this->cart->destroy();
- /**********
- email sending to customer code.
- need to check & optimize online.
- *****/
- // $this->db->where('deactive','false');
- // $this->db->where('uniqueId',$this->session->userdata('custId'));
- // $query1 = $this->db->get('buyer');
- // if($query1->num_rows()>0)
- // {
- // $emailto = $query1->row()->email;
- // }
- //
- // if($emailto!='')
- // {
- // $config = Array(
- // 'mailtype' => 'html',
- // 'charset' => 'iso-8859-1'
- // );
- // $this->load->library('email', $config);
- // $this->email->set_newline("\r\n");
- //
- // $data = array(
- // 'success_register' => $uid,
- // );
- //
- // $body = $this->load->view('purchase_invoice',$data,TRUE);
- //
- // $from_email = "info@bigserver.in";
- //
- // $this->email->from($from_email, 'Satguru HR');
- // $this->email->to($emailto);
- // $this->email->subject('Invoice');
- // $this->email->message($body);
- // }
- // else
- // {
- // $msg = "Opps!! No email found, Invoice not send.";
- // }
- //
- // if($this->email->send()) {
- // $this->session->set_userdata("invoiceSent","Email sent successfully.");
- // } else {
- // $this->session->set_userdata("invoiceError",$msg);
- // }
- /******* email sendind code. ends ***/
- return $uid;
- }
- else
- {
- redirect(base_url());
- }
- }
- else
- {
- redirect(base_url());
- }
- }
- public function my_order_model()
- {
- // $custId = $this->session->userdata('custId');
- // $this->db->select('uniqueId');
- // $this->db->where('userId',$custId);
- // $this->db->where('deactive','false');
- // $this->db->group_by('uniqueId');
- // $cart_sum_que = $this->db->get('cart_summary');
- // return $cart_sum_que->result_array();
- $custId = $this->session->userdata('custId');
- $this->db->select('unique_id');
- $this->db->where('customer_id',$custId);
- $this->db->where('deactive','false');
- $this->db->group_by('unique_id');
- $this->db->order_by('id','DESC');
- $cart_sum_que = $this->db->get('final_orders');
- return $cart_sum_que->result_array();
- }
- // aadhar work (starts)
- public function myaddressbook_model()
- {
- $custId = $this->session->userdata('custId');
- $this->db->where('custId',$custId);
- $this->db->where('deactive','false');
- $myaddresses_que = $this->db->get('myaddresses');
- if($myaddresses_que->num_rows()>0)
- {
- return $myaddresses_que->result_array();
- }
- else
- {
- return 0;
- }
- }
- // aadhar work (ends)
- public function my_wishlist_model()
- {
- $custId = $this->session->userdata('custId');
- $this->db->select('*');
- $this->db->where('userId',$custId);
- //$this->db->where('deactive','false');
- $this->db->from('wishlist');
- $this->db->join('product','product.uniqueId = wishlist.productId');
- $this->db->group_by('productId');
- $wish_sum_que = $this->db->get();
- return $wish_sum_que->result_array();
- }
- public function myaddresses_model()
- {
- $this->db->where('userId',$custId);
- $this->db->where('deactive','false');
- $this->db->from('wishlist');
- $this->db->join('product','product.uniqueId = wishlist.productId');
- $this->db->group_by('productId');
- $wish_sum_que = $this->db->get();
- return $wish_sum_que->result_array();
- }
- public function updateuniqueKey($unikey)
- {
- $emailId = $this->input->post('emailId');
- $this->db->trans_start();
- $updatedata=array('uniqueKey'=>$unikey);
- $this->db->where('email',$emailId );
- $this->db->where('deactive','false');
- $this->db->update('buyer',$updatedata);
- $this->db->trans_complete();
- if($this->db->trans_status()===FALSE)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public function applycoupon_model()
- {
- $couponcode = $this->input->post('couponcode');
- $this->db->where('deactive','false');
- $this->db->where('couponCode',$couponcode);
- $couponQue = $this->db->get('coupon_codes');
- if($couponQue->num_rows() > 0)
- {
- $this->db->where('deactive','false');
- $this->db->where('status','1');
- $this->db->where('couponCode',$couponcode);
- $couponQue2 = $this->db->get('coupon_codes');
- if($couponQue2->num_rows()>0)
- {
- return $returnData = ($couponQue->row()->discount_per);
- }
- else
- {
- return 1;
- }
- }
- else
- {
- return 0;
- }
- } // applycoupon_model (aadhar)
- public function blockInvalidCoupon_model()
- {
- $couponcode = $this->input->post('couponcode');
- $this->db->where('deactive','false');
- $this->db->where('status','1');
- $this->db->where('couponCode',$couponcode);
- $couponQue2 = $this->db->get('coupon_codes');
- if($couponQue2->num_rows()>0)
- {
- return $returnData = ($couponQue->row()->discount_per);
- }
- else
- {
- return 4;
- }
- } // blockInvalidCoupon_model (aadhar)
- public function contactmail_model()
- {
- $this->form_validation->set_rules('fullname','fullname','required|trim');
- $this->form_validation->set_rules('email','email','required|trim|valid_email');
- $this->form_validation->set_rules('mobile','mobile','required|trim');
- $this->form_validation->set_rules('subject','address','required|trim');
- $this->form_validation->set_rules('message','message','required|trim');
- if ($this->form_validation->run() == TRUE)
- {
- $fullname = $this->input->post('fullname');
- $email = $this->input->post('email');
- $mobile = $this->input->post('mobile');
- $subject = $this->input->post('subject');
- $message = $this->input->post('message');
- $config = Array(
- 'mailtype' => 'html',
- 'wordwrap' => TRUE,
- 'priority' => 1,
- 'charset' => 'iso-8859-1'
- );
- $this->load->library('email', $config);
- $this->email->set_newline("\r\n");
- $data = array(
- 'fullname' => $fullname,
- 'email' => $email,
- 'mobile' => $mobile,
- 'subject' => $subject,
- 'message' => $message
- );
- $body = $this->load->view('contactusApplication',$data,TRUE);
- $from_email = "info@bigserver.in";
- $this->email->from($from_email, 'E-ZONE RETAILS');
- // $this->email->to($email);
- $this->email->to('aadhar41@gmail.com,aadhar.gaur@blueberrysoftech.com');
- $this->email->subject('Contact Us Request');
- $this->email->message($body);
- //Send mail
- if($this->email->send()) {
- $this->session->set_userdata("email_sent","Email sent successfully.");
- unlink($path['full_path']);
- redirect(base_url().'Home/contactUs/');
- } else {
- $this->session->set_userdata("email_error",$this->email->print_debugger());
- redirect(base_url().'Home/contactUs/');
- // $this->session->set_userdata("email_error",$msg);
- }
- }
- else
- {
- $this->session->set_userdata('validation_errors',validation_errors());
- redirect(base_url()."Home/contactUs");
- }
- } // contactmail_model.
- }
- ?>
Add Comment
Please, Sign In to add comment