Guest User

Untitled

a guest
Aug 5th, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.21 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Home_model extends CI_Model {
  5.  
  6.     public function checkContact_model()
  7.     {
  8.  
  9.         $this->form_validation->set_rules('name','name','required|trim');
  10.         $this->form_validation->set_rules('email','email','required|trim');
  11.         $this->form_validation->set_rules('mobile','mobile','required|trim');
  12.         $this->form_validation->set_rules('message','message','required|trim');
  13.         if($this->form_validation->run())
  14.         {
  15.             $name = $this->input->post('name');
  16.             $email = $this->input->post('email');
  17.             $mobile = $this->input->post('mobile');
  18.             $message = $this->input->post('message');
  19.             $msg = "Name: '" .$name."'Email: '".$email."'Message: '".$message."'";
  20.  
  21.             $to = "monika.pareek@blueberrysoftech.com";
  22.             //$from = "himanshu.jain@blueberrysoftech.com";
  23.             $headers = 'From: himanshu.jain@blueberrysoftech.com';
  24.  
  25.             $subject = "Form submission";
  26.             $message2 = $msg ;
  27.  
  28.             $result = mail($to,$subject,$message2,$headers);
  29.  
  30.             if($result)
  31.             {
  32.                 redirect(base_url().'Home/');
  33.             }else
  34.             {
  35.                 return 0;
  36.             }
  37.         }
  38.         else
  39.         {
  40.             return 0;
  41.         }
  42.  
  43.     redirect(base_url().'Home');
  44.  
  45.     }
  46.  
  47.     public function registerbuyer()
  48.     {
  49. //
  50. //        echo '<pre>';
  51. //        print_r($this->input->post());
  52. //        echo '</pre>';
  53. //        die();
  54.  
  55.       $this->load->library('form_validation');
  56.       $this->form_validation->set_rules('fullname','Full Name','required');
  57.       $this->form_validation->set_rules('mobile','Mobile number','required|numeric');
  58.       $this->form_validation->set_rules('email','Email Address','required|valid_email');
  59.       $this->form_validation->set_rules('username','Username','required|alpha_dash');
  60.       $this->form_validation->set_rules('password','Password','required');
  61.       $this->form_validation->set_error_delimiters('<div class="error label label-danger">', '</div>');
  62.  
  63.       if($this->form_validation->run())
  64.       {
  65.         $register_data = $this->input->post();
  66.         $register_data['password'] = md5($this->input->post('password'));
  67.  
  68.         $this->db->select('uniqueId');
  69.         $this->db->where('email',$register_data['email']);
  70.         $this->db->where('deactive','false');
  71.         $this->db->or_where('mobile',$register_data['mobile']);
  72.         $this->db->where('deactive','false');
  73.         $register_cust_query = $this->db->get('buyer');
  74.  
  75.         if($register_cust_query->num_rows() > 0)
  76.         {
  77.             $this->session->set_userdata('already_reg',1);
  78.             redirect(base_url().'Home/login');
  79.         }
  80.         else
  81.         {
  82.  
  83.             $this->db->insert('buyer',$register_data);
  84.             $custId = 'CUST'.str_pad($this->db->insert_id(),3,0,STR_PAD_LEFT);
  85.             $this->db->where('id',$this->db->insert_id());
  86.             $this->db->where('deactive','false');
  87.             $this->db->update('buyer',array('uniqueId'=>$custId));
  88.             $this->session->set_userdata('custId',$custId);
  89.             $this->session->set_userdata('custname',$register_data['fullname']);
  90.             $cart_check = $this->cart->contents();
  91.             if(!empty($cart_check))
  92.             {
  93.                 redirect(base_url().'Home/finalstep');
  94.             }
  95.             else
  96.             {
  97.                 redirect(base_url().'Home/my_account');
  98.             }
  99.         }
  100.       }
  101.       else
  102.       {
  103.             return false;
  104. //        $this->session->set_userdata('validation_errors',validation_errors());
  105. //        redirect(base_url().'Home/login');
  106.       }
  107.  
  108.  
  109.     }
  110.  
  111.     public function logincheck()
  112.     {
  113.       $this->db->select('uniqueId,fullname');
  114.       $username = $this->input->post('username');
  115.       $password = md5($this->input->post('password'));
  116.       $this->db->where('username',$username);
  117.       $this->db->where('password',$password);
  118.       $this->db->where('deactive','false');
  119.       $buyer_que = $this->db->get('buyer');
  120.  
  121.       if($buyer_que->num_rows() == 1)
  122.       {
  123.         $custId = $buyer_que->row()->uniqueId;
  124.         $custname = $buyer_que->row()->fullname;
  125.  
  126.         $this->session->set_userdata('custId',$custId);
  127.         $this->session->set_userdata('custname',$custname);
  128.         $cart_check = $this->cart->contents();
  129.         if(!empty($cart_check))
  130.         {
  131.         redirect(base_url().'Home/finalstep');
  132.         }
  133.         else {
  134.           redirect(base_url().'Home/my_account');
  135.         }
  136.  
  137.       }
  138.       else {
  139.         $this->session->set_userdata('not_registered',1);
  140.         redirect(base_url().'Home/login');
  141.       }
  142.  
  143.     }
  144.  
  145.     public function send_mail_model()
  146.     {
  147.  
  148.         foreach($this->cart->contents() as $data)
  149.         {
  150.  
  151.         $message = '<tr>
  152.          <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>
  153.            <div>Quantity : '.$data['qty'].'<br>
  154.              <br>
  155.            Price : '.$data['price'].'<br>
  156. SubTotal :  &nbsp;&nbsp;'.$data['subtotal'].'</div></td>
  157.        </tr>';
  158.       }
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.         $this->load->library('email');
  166.         $email = $this->input->post('email');
  167.         $full_name = $this->input->post('fullname');
  168.         $mobile = $this->input->post('mobile');
  169.         $this->email->from($email, $full_name);
  170.         $this->email->to('er.chiragnagpal@gmail.com');
  171.  
  172.  
  173.  
  174.  
  175.  
  176.         $this->email->subject('Purchase Order Query');
  177.         $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;">
  178.            <div style="font-size:24px;">Best Retail shop to gety your wish</div>
  179.            <div style="font-size:32px; color:#ffbe00;">Ezone Retails</div>
  180.            </td>
  181.            <td width="197" align="right" valign="middle" bgcolor="#000000" style="background-color:#000000; padding:20px; color:#ffffff;"></td>
  182.          </tr>
  183.        </table>
  184.        <table width="600" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#971800" style="background-color:#971800;">
  185.          <tr>
  186.            <td align="center" valign="top" bgcolor="#ffffff" style="background-color:#ffffff;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  187.              <tr>
  188.                <td align="center" valign="top" bgcolor="#971800" style="background-color:#971800; padding:20px; font-family:Georgia, Times New Roman, Times, serif;">
  189.                <div style="color:#fffbe0; font-size:24px;"> Name : '.$full_name.'  <br>'.$email.'</div>
  190.                <div style="font-size:19px; color:#fc9600;"><br>
  191.                  <i>Mobile : '.$mobile.'</i></div>
  192.                </td>
  193.              </tr>
  194.              <tr>
  195.                <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;">
  196.                  </table>'.$message.'
  197.  
  198.                  <table width="100%" border="0" cellspacing="0" cellpadding="10" style="margin-bottom:10px;">
  199.                    <tr>
  200.                      <td align="left" valign="top" style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000000;"><div> <br>
  201.                          <br>
  202.                          <br>
  203.                        <b>Ezone Retails </b><br>
  204.                        Panchsheel Ajmer<br>
  205.                        <b>Phone: </b>(000) 123  4567 </div></td>
  206.                    </tr>
  207.                  </table></td>
  208.              </tr>
  209.            </table></td>
  210.          </tr>
  211.        </table>');
  212.  
  213.         if($this->email->send())
  214.         {
  215.           $this->cart->destroy();
  216.           return "Your Order Send Successfully. We will Contact you Soon.";
  217.  
  218.         }
  219.         else {
  220.           return "Mail Send Error. Please Send Again";
  221.         }
  222.  
  223.  
  224.  
  225.     }
  226.  
  227.  
  228.  
  229.     public function emailSend_model($uid)
  230.     {
  231.        /**********
  232.         email sending to customer code.
  233.         need to check & optimize online.
  234.         *****/
  235.         $this->db->where('deactive','false');
  236.         $this->db->where('uniqueId',$this->session->userdata('custId'));
  237.         $query1 = $this->db->get('buyer');
  238.         if($query1->num_rows()>0)
  239.         {
  240.             $emailto = $query1->row()->email;
  241.         }
  242.  
  243.         if($emailto!='')
  244.         {
  245.                 $config = Array(
  246.                                 'mailtype'  => 'html',
  247.                                 'charset'   => 'iso-8859-1'
  248.                             );
  249.                             $this->load->library('email', $config);
  250.                             $this->email->set_newline("\r\n");
  251.  
  252.                             $data = array(
  253.                                            'success_register' => $uid,
  254.                                      );
  255.  
  256.                             $body = $this->load->view('purchase_invoice',$data,TRUE);
  257.  
  258.                             $from_email = "info@bigserver.in";
  259.  
  260.                             $this->email->from($from_email, 'Satguru HR');
  261.                             $this->email->to($emailto);
  262.                             $this->email->subject('Invoice');
  263.                             $this->email->message($body);
  264.         }
  265.         else
  266.         {
  267.              $msg = "Opps!! No email found, Invoice not send.";
  268.         }
  269.  
  270.         if($this->email->send()) {
  271.             return $msg = "Email sent successfully.!!!";
  272.             return $msg;
  273. //          $this->session->set_userdata("invoiceSent","Email sent successfully.");
  274.         } else {
  275.             $msg = "Opps!! Email not send.";
  276.             return $msg;
  277. //          $this->session->set_userdata("invoiceError",$msg);
  278.         }
  279.  
  280.         /******* email sendind code. ends ***/
  281.     }
  282.  
  283.     public function logout_model()
  284.     {
  285.       $this->session->sess_destroy();
  286.       $this->cart->destroy();
  287.     }
  288.  
  289.  
  290.     public function checkout()
  291.     {
  292.       $cart_val =array();
  293.  
  294.       $custId = $this->session->userdata('custId');
  295.       $cart_check = $this->cart->contents();
  296.  
  297.       if(!empty($cart_check))
  298.       {
  299.         $total_products = count($cart_check);
  300.         $customer_id = $custId;
  301.         $delivery_address = $this->input->post('address_selected');
  302.         $payment_mode = $this->input->post('payment_mode');
  303.         $couponcode = $this->input->post('couponcode');
  304.         $order_date_and_time = date("Y-m-d H:i:s");
  305.  
  306.         $final_amount = 0;
  307.         foreach($this->cart->contents() as $data_cart)
  308.         {
  309.             if($data_cart['price']!='0')
  310.             {
  311.                 $final_amount  += $data_cart['subtotal'];
  312.             }
  313.         }
  314.  
  315.         $final_orders = array(
  316.                         'customer_id'           => $customer_id,
  317.                         'total_products'        => $total_products,
  318.                         'delivery_address'      => $delivery_address,
  319.                         'payment_mode'          => $payment_mode,
  320.                         'order_date_and_time'   => $order_date_and_time,
  321.                         'final_amount'           => $final_amount,
  322.                         'coupon_applied'           => $couponcode
  323.                         );
  324.  
  325.         $this->db->insert('final_orders',$final_orders);
  326.         $lastid = $this->db->insert_id();
  327.         $uid = 'PURODR'.str_pad($lastid,7,0,STR_PAD_LEFT);
  328.  
  329.         $this->db->where('id',$lastid);
  330.         $this->db->update('final_orders',array('unique_id'=>$uid));
  331.  
  332. /*****end of table-1 code
  333. ****/
  334.  
  335.  
  336. /********
  337. orders_summary feilds :
  338. id -> done
  339. unique_id -> done
  340. customer_id -> done
  341. order_id -> done
  342. product_id -> done
  343. quantity -> done
  344. price_per_unit -> done
  345. subtotal -> done
  346. discount_percentage
  347. discount_value
  348.  
  349. purchase
  350.  
  351. ****/
  352.  
  353.           $total_amount = 0;
  354.           foreach($this->cart->contents() as $data_cart)
  355.           {
  356.               if($data_cart['price']!='0')
  357.               {
  358.                     $cart_val['product_id'] = $data_cart['id'];
  359.                     $cart_val['quantity'] = $data_cart['qty'];
  360.                     $cart_val['price_per_unit'] = $data_cart['price'];
  361.                     $cart_val['subtotal'] = $data_cart['subtotal'];
  362.                     $cart_val['customer_id']= $custId;
  363.                     $cart_val['order_id']= $uid;
  364.                     $cart_val['purchase'] = 1;
  365. //                    $cart_val['uniqueId'] = 'TEMP0100';
  366. //                    $total_amount  += $data_cart['subtotal'];
  367. //                    $cart_val['final_amount'] = $final_amount;
  368.  
  369.                     $this->db->insert('orders_summary',$cart_val);
  370.                     $lastInsertId = $this->db->insert_id();
  371.                     $cartId = 'ODRSUM'.str_pad($lastInsertId,8,0,STR_PAD_LEFT);
  372.               }
  373.               else
  374.               {
  375.                 redirect(base_url());
  376.               }
  377.           }
  378.  
  379.  
  380.             if($final_amount!='0')
  381.             {
  382.  
  383.                 $this->db->select('id');
  384.                 $this->db->where('unique_id',NULL);
  385.                 $this->db->where('order_id',$uid);
  386.                 $query = $this->db->get('orders_summary');
  387.  
  388.                 if($query->num_rows()>0)
  389.                 {
  390.                     $lastIds = $query->result_array();
  391.  
  392.                     foreach($lastIds as $data => $value)
  393.                     {
  394.                         $cartId = 'ODRSUM'.str_pad($value['id'],8,0,STR_PAD_LEFT);
  395.  
  396.                         $this->db->where('id',$value['id']);
  397.                         $this->db->update('orders_summary',array('unique_id'=>$cartId));
  398.                     }
  399.  
  400.                 }
  401.  
  402.                 $this->cart->destroy();
  403.  
  404.                 /**********
  405.                 email sending to customer code.
  406.                 need to check & optimize online.
  407.                 *****/
  408. //                $this->db->where('deactive','false');
  409. //                $this->db->where('uniqueId',$this->session->userdata('custId'));
  410. //                $query1 = $this->db->get('buyer');
  411. //                if($query1->num_rows()>0)
  412. //                {
  413. //                    $emailto = $query1->row()->email;
  414. //                }
  415. //
  416. //                if($emailto!='')
  417. //                {
  418. //                        $config = Array(
  419. //                                        'mailtype'  => 'html',
  420. //                                        'charset'   => 'iso-8859-1'
  421. //                                    );
  422. //                                    $this->load->library('email', $config);
  423. //                                    $this->email->set_newline("\r\n");
  424. //
  425. //                                    $data = array(
  426. //                                                   'success_register' => $uid,
  427. //                                             );
  428. //
  429. //                                    $body = $this->load->view('purchase_invoice',$data,TRUE);
  430. //
  431. //                                    $from_email = "info@bigserver.in";
  432. //
  433. //                                    $this->email->from($from_email, 'Satguru HR');
  434. //                                    $this->email->to($emailto);
  435. //                                    $this->email->subject('Invoice');
  436. //                                    $this->email->message($body);
  437. //                }
  438. //                else
  439. //                {
  440. //                     $msg = "Opps!! No email found, Invoice not send.";
  441. //                }
  442. //
  443. //                if($this->email->send()) {
  444. //                  $this->session->set_userdata("invoiceSent","Email sent successfully.");
  445. //                } else {
  446. //                  $this->session->set_userdata("invoiceError",$msg);
  447. //                }
  448.  
  449.                 /******* email sendind code. ends ***/
  450.  
  451.                 return $uid;
  452.             }
  453.           else
  454.           {
  455.             redirect(base_url());
  456.           }
  457.       }
  458.       else
  459.       {
  460.         redirect(base_url());
  461.       }
  462.  
  463.  
  464.     }
  465.  
  466.     public function my_order_model()
  467.     {
  468. //      $custId = $this->session->userdata('custId');
  469. //      $this->db->select('uniqueId');
  470. //      $this->db->where('userId',$custId);
  471. //      $this->db->where('deactive','false');
  472. //      $this->db->group_by('uniqueId');
  473. //      $cart_sum_que = $this->db->get('cart_summary');
  474. //      return $cart_sum_que->result_array();
  475.  
  476.       $custId = $this->session->userdata('custId');
  477.       $this->db->select('unique_id');
  478.       $this->db->where('customer_id',$custId);
  479.       $this->db->where('deactive','false');
  480.       $this->db->group_by('unique_id');
  481.       $this->db->order_by('id','DESC');
  482.       $cart_sum_que = $this->db->get('final_orders');
  483.       return $cart_sum_que->result_array();
  484.  
  485.     }
  486.  
  487.  
  488.     // aadhar work (starts)
  489.     public function myaddressbook_model()
  490.     {
  491.         $custId = $this->session->userdata('custId');
  492.  
  493.         $this->db->where('custId',$custId);
  494.         $this->db->where('deactive','false');
  495.         $myaddresses_que = $this->db->get('myaddresses');
  496.         if($myaddresses_que->num_rows()>0)
  497.         {
  498.             return $myaddresses_que->result_array();
  499.         }
  500.         else
  501.         {
  502.             return 0;
  503.         }
  504.     }
  505.     // aadhar work (ends)
  506.  
  507.  
  508.     public function my_wishlist_model()
  509.     {
  510.       $custId = $this->session->userdata('custId');
  511.       $this->db->select('*');
  512.       $this->db->where('userId',$custId);
  513.       //$this->db->where('deactive','false');
  514.       $this->db->from('wishlist');
  515.       $this->db->join('product','product.uniqueId = wishlist.productId');
  516.       $this->db->group_by('productId');
  517.       $wish_sum_que = $this->db->get();
  518.       return $wish_sum_que->result_array();
  519.  
  520.     }
  521.  
  522.  
  523.     public function myaddresses_model()
  524.     {
  525.  
  526.       $this->db->where('userId',$custId);
  527.       $this->db->where('deactive','false');
  528.       $this->db->from('wishlist');
  529.       $this->db->join('product','product.uniqueId = wishlist.productId');
  530.       $this->db->group_by('productId');
  531.       $wish_sum_que = $this->db->get();
  532.       return $wish_sum_que->result_array();
  533.  
  534.     }
  535.  
  536.     public function updateuniqueKey($unikey)
  537.       {
  538.       $emailId = $this->input->post('emailId');
  539.           $this->db->trans_start();
  540.           $updatedata=array('uniqueKey'=>$unikey);
  541.           $this->db->where('email',$emailId );
  542.           $this->db->where('deactive','false');
  543.           $this->db->update('buyer',$updatedata);
  544.  
  545.           $this->db->trans_complete();
  546.           if($this->db->trans_status()===FALSE)
  547.           {
  548.           return false;
  549.           }
  550.           else
  551.           {
  552.           return true;
  553.           }
  554.       }
  555.  
  556.  
  557.         public function applycoupon_model()
  558.         {
  559.             $couponcode = $this->input->post('couponcode');
  560.             $this->db->where('deactive','false');
  561.             $this->db->where('couponCode',$couponcode);
  562.             $couponQue = $this->db->get('coupon_codes');
  563.             if($couponQue->num_rows() > 0)
  564.             {
  565.                 $this->db->where('deactive','false');
  566.                 $this->db->where('status','1');
  567.                 $this->db->where('couponCode',$couponcode);
  568.                 $couponQue2 = $this->db->get('coupon_codes');
  569.  
  570.                 if($couponQue2->num_rows()>0)
  571.                 {
  572.                     return $returnData = ($couponQue->row()->discount_per);
  573.                 }
  574.                 else
  575.                 {
  576.                     return 1;
  577.                 }
  578.  
  579.             }
  580.             else
  581.             {
  582.                 return 0;
  583.             }
  584.  
  585.         } //  applycoupon_model (aadhar)
  586.  
  587.  
  588.         public function blockInvalidCoupon_model()
  589.         {
  590.                 $couponcode = $this->input->post('couponcode');
  591.                 $this->db->where('deactive','false');
  592.                 $this->db->where('status','1');
  593.                 $this->db->where('couponCode',$couponcode);
  594.                 $couponQue2 = $this->db->get('coupon_codes');
  595.  
  596.                 if($couponQue2->num_rows()>0)
  597.                 {
  598.                     return $returnData = ($couponQue->row()->discount_per);
  599.                 }
  600.                 else
  601.                 {
  602.                     return 4;
  603.                 }
  604.  
  605.         } //  blockInvalidCoupon_model (aadhar)
  606.  
  607.  
  608.         public function contactmail_model()
  609.         {
  610.             $this->form_validation->set_rules('fullname','fullname','required|trim');
  611.             $this->form_validation->set_rules('email','email','required|trim|valid_email');
  612.                 $this->form_validation->set_rules('mobile','mobile','required|trim');
  613.                 $this->form_validation->set_rules('subject','address','required|trim');
  614.                 $this->form_validation->set_rules('message','message','required|trim');
  615.  
  616.             if ($this->form_validation->run() == TRUE)
  617.             {
  618.                     $fullname = $this->input->post('fullname');
  619.                     $email = $this->input->post('email');
  620.                     $mobile = $this->input->post('mobile');
  621.                     $subject = $this->input->post('subject');
  622.                     $message = $this->input->post('message');
  623.  
  624.                     $config = Array(
  625.                                'mailtype'  => 'html',
  626.                                'wordwrap'  => TRUE,
  627.                                'priority'  => 1,
  628.                                'charset'   => 'iso-8859-1'
  629.                            );
  630.                            $this->load->library('email', $config);
  631.                            $this->email->set_newline("\r\n");
  632.  
  633.                            $data = array(
  634.                                           'fullname' => $fullname,
  635.                                           'email' => $email,
  636.                                           'mobile' => $mobile,
  637.                                           'subject' => $subject,
  638.                                           'message' => $message
  639.                                     );
  640.  
  641.                      $body = $this->load->view('contactusApplication',$data,TRUE);
  642.  
  643.                      $from_email = "info@bigserver.in";
  644.  
  645.                      $this->email->from($from_email, 'E-ZONE RETAILS');
  646.                     //  $this->email->to($email);
  647.                      $this->email->to('aadhar41@gmail.com,aadhar.gaur@blueberrysoftech.com');
  648.                      $this->email->subject('Contact Us Request');
  649.                      $this->email->message($body);
  650.  
  651.                     //Send mail
  652.                      if($this->email->send()) {
  653.                        $this->session->set_userdata("email_sent","Email sent successfully.");
  654.                        unlink($path['full_path']);
  655.                        redirect(base_url().'Home/contactUs/');
  656.                      } else {
  657.                        $this->session->set_userdata("email_error",$this->email->print_debugger());
  658.                        redirect(base_url().'Home/contactUs/');
  659.                       //  $this->session->set_userdata("email_error",$msg);
  660.                      }
  661.  
  662.                 }
  663.                 else
  664.                 {
  665.                   $this->session->set_userdata('validation_errors',validation_errors());
  666.                         redirect(base_url()."Home/contactUs");
  667.                 }
  668.  
  669.         }  // contactmail_model.
  670.  
  671.  
  672.  
  673. }
  674. ?>
Add Comment
Please, Sign In to add comment