AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.217.80
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/www/lrsys_projetos/sopizzas/application/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_projetos/sopizzas/application/controllers/createorder.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
//require_once APPPATH."third_party/Services/Twilio.php";
require_once APPPATH."third_party/PinPayment/autoload.php";
use Omnipay\Omnipay;
use Omnipay\Common\CreditCard;
class Createorder extends MY_Restaurant {

  function __construct()
  {
     parent::__construct();
     $this->load->helper("url");
     $this->load->helper('form');
     $this->load->library('form_validation');
     $this->load->library('javascript');
     $this->load->library('cart');
     $this->load->library('mypaypal');
     $this->load->library('myemail');
     $this->load->library('braintree_lib');
     $this->load->model('createorder_model');
     $this->load->model('frontend_model');
     $this->load->model('dashboard_model');
     if($this->session->userdata('user_language'))
      {
        $language = $this->session->userdata('user_language');
      }
      else
      {
        $language = $this->config->item("language");
      }
      $data['user_language'] =  $language;
      //$this->lang->load('frontpage', $language);
      $this->lang->load('restaurantAdmin', $language);
     require_once APPPATH."third_party/Services/Twilio.php";
  }

  function index( $offset = 0 ){
    //$this->test();
    //echo $this->createorder_model->ccEncrypt('123', '1473764063');
    //echo $this->createorder_model->ccDecrypt('UVdbBVQAUQcJAVQIUFNTAlRSAVBRBgY=', '1473764063');
    if ($this->input->server('REQUEST_METHOD') == 'POST') {
      $this->placeOrder();
    }
    else {
      $this->showCreateOrder();
    }
  }
  function testPaypal() {
    $requestParams = array(
        'IPADDRESS' => $_SERVER['REMOTE_ADDR'],          // Get our IP Address
        'PAYMENTACTION' => 'Sale'
    );
    $creditCardDetails = array(
        'CREDITCARDTYPE' => 'Visa',
        'ACCT' => '4032035005184353',
        'EXPDATE' => '102021',          // Make sure this is without slashes (NOT in the format 07/2017 or 07-2017)
        'CVV2' => '123'
    );
    $payerDetails = array(
        'FIRSTNAME' => 'John',
        'LASTNAME' => 'Doe2',
        'COUNTRYCODE' => 'US',
        'STATE' => 'NY',
        'CITY' => 'New York',
        'STREET' => '14 Argyle Rd.',
        'ZIP' => '10010'
    );
    $orderParams = array(
        'AMT' => '5',               // This should be equal to ITEMAMT + SHIPPINGAMT
        'ITEMAMT' => '4',
        'SHIPPINGAMT' => '1',
        'CURRENCYCODE' => 'USD'       // USD for US Dollars
    );
    $item = array(
        'L_NAME0' => 'iPhone',
        'L_DESC0' => 'White iPhone, 16GB',
        'L_AMT0' => '4',
        'L_QTY0' => '1'
    );
    //$paypal = new Paypal();
    $response = $this->mypaypal->request('DoDirectPayment',
        $requestParams + $creditCardDetails + $payerDetails + $orderParams + $item
    );

    if( is_array($response) && $response['ACK'] == 'Success') { // Payment successful
        // We'll fetch the transaction ID for internal bookkeeping
        $transactionId = $response['TRANSACTIONID'];
        echo $transactionId;
        echo '<br>';
        echo "<pre>";
        print_r($response);
        echo "</pre>";
    }
    else
    {
        echo $response['L_SHORTMESSAGE0'];
        echo '<br>';
        echo $response['L_LONGMESSAGE0'];
        echo '<br>';
        echo "<pre>";
        print_r($response);
        echo "</pre>";
           //Echo "There was an error processing Request!";
           //print_r($paypal->_errors);
    }
  }
  function showCreateOrder($error_msg = '') {
    $session_data = $this->session->userdata('logged_in_restaurant');
    $restaurant_id = $session_data['id'];
    //echo $restaurant_id;
    $CategoryList = $this->createorder_model->CategoryByRestaurant($restaurant_id);
    //print_r($CategoryList);
    $data['CategoryList'] = $CategoryList;
    $data['StateList'] = $this->frontend_model->StateList();
    $data['CityList'] = $this->frontend_model->CityList();
    $data['title'] = "Create Order";  
    $data['page'] = "createorder"; 
    $data['error_msg'] = $error_msg; 
    $this->load->view('restaurantadmin/header',$data);
    $this->load->view('restaurantadmin/create_order');
    $this->load->view('restaurantadmin/footer');
  }
  function search_customer() {
    $usersearchkey = $this->input->post('usersearchkey');
    $this->db->select('rt_customer.*, rt_credit_cards.cc_type, rt_credit_cards.cc_number, rt_credit_cards.cc_exp_month, rt_credit_cards.cc_exp_year, rt_credit_cards.cc_cvv, rt_credit_cards.cc_time');
    $this->db->from('rt_customer');
    $this->db->join('rt_credit_cards', 'rt_credit_cards.customer_id = rt_customer.customer_id', 'left outer');
    $this->db->like('customer_name', $usersearchkey, 'both');
    $this->db->limit('10');
    $query = $this->db->get();
    if ($query->num_rows() > 0) {
      $data['response'] = 'true'; //If username exists set true
      $data['search_data'] = array();
      foreach ($query->result() as $key => $value) {
        if ($value->cc_number != '') {
           $CCNumber = $this->createorder_model->ccDecrypt($value->cc_number, $value->cc_time);
          $CCNumberLength = strlen($CCNumber);
          $myCCNumber = substr_replace($CCNumber, 'XXXXXXXXXXXX', 0, $CCNumberLength - 4);
        }
       else {
          $myCCNumber = '';
       }
        $CCCvv = $this->createorder_model->ccDecrypt($value->cc_cvv, $value->cc_time);
        echo "<div style=\"\" class=\"suggestionlist\" onclick=\"setCustDetails('".$value->customer_id."', '".$value->customer_name."', '".$value->customer_lastname."', '".$value->customer_street."', '".$value->customer_zip."', '".$value->customer_phone."', '".$value->customer_email."', '".$value->cc_type."', '".$myCCNumber."', '".$value->cc_exp_month."', '".$value->cc_exp_year."', '".$CCCvv."', '".$value->cc_number.'-|-'.$value->cc_time."')\"><b>".$value->customer_name." ".$value->customer_lastname."</b></div>";
      }
    }
    else {
       // $data['response'] = 'false'; //Set false if user not valid
    }
    //echo json_encode($data);
  }
  function MenuByCategory() {
    $menu_category = $this->input->post('menu_category');
    if ($menu_category) {
      $ItemList = $this->createorder_model->MenuByCategory($menu_category);
      echo json_encode($ItemList);
    }
  }
  function showItemDetails() {
    $menu_id = $this->input->post('id');

    $menudetails=$this->frontend_model->GetMenuDetails($menu_id);

    if($menudetails['menu_photo']!=''){
      $menu_photo_file_path=FCPATH.MENU_IMAGE_PATH_THUMBS.$menudetails['menu_photo'];
      if (file_exists($menu_photo_file_path)) {
            $menu_image_name_with_path=base_url().MENU_IMAGE_PATH_THUMBS.$menudetails['menu_photo'];
         } 
         else {
            $menu_image_name_with_path=base_url().MENU_IMAGE_PATH_THUMBS.MENU_IMAGE_DEFAULT_IMAGE;
         }
      }
      else {
        $menu_image_name_with_path=base_url().MENU_IMAGE_PATH_THUMBS.MENU_IMAGE_DEFAULT_IMAGE;
      }

      $Fixprice='';
      $dataSize='';
      $dataSubAddons='';
      $dataAddonsHeader='';
      $spl_instruction ='';
      $dataAddons ='';
      if($menudetails['sizeoption']=='size') {
        $MenuSize=$this->frontend_model->GetMenuSize($menudetails['id']);
        if(is_array($MenuSize) && sizeof($MenuSize)>0) {
          $dataSize='<span class="col-md-12 col-sm-12 col-xs-12 value-box">
                          <span class="col-md-3 col-sm-4 col-xs-12">
                            Price
                          </span><span class="col-md-9 col-sm-8 col-xs-12 paddingleft0">';
          // making menu size checkbox
          foreach($MenuSize as $key=>$row2) { 
            if ($key == 0) {
              $checked = 'checked';
              $dataSize .= "<input type=\"hidden\" name=\"mySizePrice\" id=\"mySizePrice\" value=\"".trim(htmlentities($row2['menu_slice_price']))."\">
              <input type=\"hidden\" name=\"mySizeName\" id=\"mySizeName\" value=\"".trim(htmlentities($row2['menu_slice_name']))."\">
              <input type=\"hidden\" name=\"mySizeId\" id=\"mySizeId\" value=\"".trim(htmlentities($row2['menu_slice_id']))."\">";
            }
            else {
              $checked = '';
            }
            $dataSize .="
              <span class=\"col-md-6 col-sm-6 col-xs-12\">
                <input name=\"sizegroup\" class=\"\" type=\"radio\" data-size-name=\"".trim(htmlentities($row2['menu_slice_name']))."\"  data-size-id=\"".trim(htmlentities($row2['menu_slice_id']))."\" data-size-price=\"".trim(htmlentities($row2['menu_slice_price']))."\" onclick=\"setSizeDetails(this)\" ".$checked."></input>
      <label for=\"radio\"><span><span></span></span>".htmlentities($row2['menu_slice_name']).' - $'.$row2['menu_slice_price']."</label>
                
              </span>
              ";
          }
          $dataSize .='</span></span>';
        }

      }
      else {
        // fix price
        $Fixprice='<span class="col-md-12 col-sm-12 col-xs-12 value-box">
                    <span class="col-md-3 col-sm-4 col-xs-6">
                      Price
                    </span>
                    <span class="col-md-9 col-sm-8 col-xs-6">
                      $ '.$menudetails['menu_price'].'
                    </span>
                  </span>';
      }

      if($menudetails['menu_addons']=='Yes') {
        $MenuAddonsHeader=$this->frontend_model->GetMenuAddonsHeader($menudetails['id']);
        if(is_array($MenuAddonsHeader) && sizeof($MenuAddonsHeader)>0) {
          foreach($MenuAddonsHeader as $key=>$row3) { 
            $dataSubAddons='';
            $dataAddonsHeader ='<span class="col-md-12 col-sm-12 col-xs-12 value-box">
                          <span class="col-md-3 col-sm-4 col-xs-12">
                            '.$row3['menuaddons_addonsname'].'<br>(Choose up to <span id="addonChooseUpto_'.$row3['menuaddons_id'].'" data-old-count="'.$row3['menuaddons_addonscount'].'" class="commonChooseUpto">'.$row3['menuaddons_addonscount'].'</span>)
                          </span>';

            $MenuSubAddons=$this->frontend_model->GetMenuSubAddons($row3['menuaddons_id']);
            if(is_array($MenuSubAddons) && sizeof($MenuSubAddons)>0) {
              $dataSubAddons ='<span class="col-md-9 col-sm-8 col-xs-12 paddingleft0">';
              foreach($MenuSubAddons as $key=>$row4) { 
                if($row4['menuaddons_price']!='0') {
                  $addonsPrice="$".$row4['menuaddons_price'];
                }
                else {
                  $addonsPrice='Free';
                }
                // addon price and name
                $dataSubAddons .='<span class="col-md-6 col-sm-6 col-xs-12 commonParent addonSingleWrap" id="addonParent_'.$row3['menuaddons_id'].'">
                        <input onclick="addonLimit('.$row3['menuaddons_addonscount'].','.$row4['menuaddons_id'].','.$row3['menuaddons_id'].'); setAddonDetails(this,'.$row3['menuaddons_id'].','.$row4['menuaddons_id'].');" data-addon-id="'.$row4['menuaddons_id'].'" data-addon-name="'.trim(htmlentities($row4['menuaddons_addonsname'])).'" data-addon-price="'.trim(htmlentities($row4['menuaddons_price'])).'" id="advacce_menu_'.$row4['menuaddons_id'].'" class="single-checkbox_'.$row3['menuaddons_id'].' commonCheckbox" name="addons" type="checkbox"></input><label for="checkbox"><span></span>'.$row4['menuaddons_addonsname'].' ('.$addonsPrice.')<br>
                        </label>
                        <br>
                        <i class="fa fa-minus-square-o fa-lg" style="cursor:pointer" aria-hidden="true" data-addon-id="'.$row4['menuaddons_id'].'" data-addon-name="'.trim(htmlentities($row4['menuaddons_addonsname'])).'" data-addon-price="'.trim(htmlentities($row4['menuaddons_price'])).'" onclick="changeAddonCount(this, '.$row4['menuaddons_id'].', '.$row3['menuaddons_id'].', \''."d".'\', '.$row3['menuaddons_addonscount'].')"></i>
                         <span class="commonAddonQuantity" id="addon-qty-'.$row4['menuaddons_id'].'" onchange="setAddonDetails(this,'.$row3['menuaddons_id'].','.$row4['menuaddons_id'].')">1</span>
                         <i class="fa fa-plus-square-o fa-lg" style="cursor:pointer" aria-hidden="true" data-addon-id="'.$row4['menuaddons_id'].'" data-addon-name="'.trim(htmlentities($row4['menuaddons_addonsname'])).'" data-addon-price="'.trim(htmlentities($row4['menuaddons_price'])).'" onclick="changeAddonCount(this, '.$row4['menuaddons_id'].', '.$row3['menuaddons_id'].', \''."i".'\', '.$row3['menuaddons_addonscount'].')"></i>
                      </span>';
              }
              $dataAddons .=$dataAddonsHeader.$dataSubAddons.'</span></span>';
            }
            $dataAddons .= '<input type="hidden" name="myAddonList[]" class="commonMyAddonList" id="myAddonList_'.$row3['menuaddons_id'].'">';                            
          }
        }                      
      }


      if($menudetails['menu_spl_instruction']!='No'){

        $spl_instruction = '<span class="col-md-12 col-sm-12 col-xs-12 value-box">
                                <span class="col-md-3 col-sm-4 col-xs-12">
                                  Special Instructions
                                </span>
                                <span class="col-md-9 col-sm-8 col-xs-12">
                                  <textarea class="areatext" style="" class="form-control" rows="5" id="mySpclInst" name="mySpclInst"></textarea>
                                  <p>Example: extra cheese, side of dressing, etc.<br>Additional charges may apply.</p>
                                </span>
                              </span>';
      }
      $optionList = '';
      for ($i=1; $i < 21; $i++) { 
        $optionList .= '<option value="'.$i.'">'.$i.'</option>';
      }
      $dataPopup = '<div class="modal-dialog">
                        <input type="hidden" name="myMenuId" id="myMenuId" value="'.$menudetails['id'].'">
                        <input type="hidden" name="myMenuName" id="myMenuName" value="'.$menudetails['menu_name'].'">
                        <input type="hidden" name="myMenuPrice" id="myMenuPrice" value="'.$menudetails['menu_price'].'">
                        <input type="hidden" name="myMenuType" id="myMenuType" value="'.$menudetails['sizeoption'].'">
                        
                        <!-- Modal content-->
                        <div class="modal-content">
                          <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"></button>
                            <h4 class="modal-title text-center">Add item to cart</h4>
                          </div>
                          <div class="modal-body">
                            <div class="col-md-12 col-sm-12 custom-padding-0">
                              <div class="col-md-8 col-sm-8">
                                <h3> '.$menudetails['menu_name'].'</h3>
                                <p style="font-size:15px;">'.$menudetails['menu_description'].'</p>
                              </div>
                              <div class="col-md-4 col-sm-4" style="display: none;">
                                <img src="'.$menu_image_name_with_path.'" class="addcart-img">
                              </div>
                            </div>
                            <div class="col-md-12 custom-padding-0 price-body">
                              <span class="col-md-12 col-sm-12 col-xs-12 value-box">
                                <span class="col-md-3 col-sm-4 col-xs-6">
                                  Quantity
                                </span>
                                <span class="col-md-9 col-sm-8 col-xs-6">
                                  <select style="padding: 7px;" data-old-qty="1" class="" id="myMenuQty" name="myMenuQty" onchange="resetAddon(this)">
                                    '.$optionList.'
                                  </select>
                                </span>
                              </span>
                              '.$Fixprice.'
                              '.$dataSize.'
                              '.$dataAddons.'

                              '.$spl_instruction.'

                              <div class="clearfix"></div>
                              <div class="col-md-12 text-center mct30">
                                <button type="button" class="btn btn-info cos-mh-btn" style="float:none;" onclick="addOrder()">Add to Cart</button>
                              </div>
                            </div>
                          </div>
                          <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                          </div>
                        </div>
                      </div>';

    echo $dataPopup;
  }
  function showEditItemDetails() {
    $menu_id = $this->input->post('id');
    $rowid = $this->input->post('rowid');
    $cartEditId = '<input type="hidden" id="cartEditId" name="cartEditId" value="'.$rowid.'">';

    $menudetails=$this->frontend_model->GetMenuDetails($menu_id);

    if ($this->cart->contents()[$rowid]) {
      $oldContent = $this->cart->contents()[$rowid];
      $oldQty = $oldContent['qty'];
      if ($oldContent['size_name'] != '') {
        $oldSizeId = $oldContent['size_id'];
        $oldSizeName = $oldContent['size_name'];
      }
      $oldPrice = $oldContent['price'];
      $oldInstruction = $oldContent['instruction'];
      if (is_array($oldContent['addons']) && count($oldContent['addons']) > 0) {
        $oldIfAddons = true;
        $oldAddons = $oldContent['addons'];
      }
      else {
        $oldIfAddons = false;
      }
    }

    if($menudetails['menu_photo']!=''){
      $menu_photo_file_path=FCPATH.MENU_IMAGE_PATH_THUMBS.$menudetails['menu_photo'];
      if (file_exists($menu_photo_file_path)) {
            $menu_image_name_with_path=base_url().MENU_IMAGE_PATH_THUMBS.$menudetails['menu_photo'];
         } 
         else {
            $menu_image_name_with_path=base_url().MENU_IMAGE_PATH_THUMBS.MENU_IMAGE_DEFAULT_IMAGE;
         }
      }
      else {
        $menu_image_name_with_path=base_url().MENU_IMAGE_PATH_THUMBS.MENU_IMAGE_DEFAULT_IMAGE;
      }

      $Fixprice='';
      $dataSize='';
      $dataSubAddons='';
      $dataAddonsHeader='';
      $spl_instruction ='';
      $dataAddons ='';
      if($menudetails['sizeoption']=='size') {
        $MenuSize=$this->frontend_model->GetMenuSize($menudetails['id']);
        if(is_array($MenuSize) && sizeof($MenuSize)>0) {
          $dataSize='<span class="col-md-12 col-sm-12 col-xs-12 value-box">
                          <span class="col-md-3 col-sm-4 col-xs-12">
                            Price
                          </span><span class="col-md-9 col-sm-8 col-xs-12 paddingleft0">';
          // making menu size checkbox
          $checkSize = 1;
          foreach($MenuSize as $key=>$row2) { 
            if ($row2['menu_slice_id'] == $oldSizeId) {
              $checkSize++;
              $checked = 'checked';
              $dataSize .= "<input type=\"hidden\" name=\"mySizePrice\" id=\"mySizePrice\" value=\"".trim(htmlentities($row2['menu_slice_price']))."\">";
              $dataSize .="
              <span class=\"col-md-6 col-sm-6 col-xs-12\">
                <input name=\"sizegroup\" class=\"\" type=\"radio\" data-size-id=\"".trim(htmlentities($row2['menu_slice_id']))."\" data-size-name=\"".trim(htmlentities($row2['menu_slice_name']))."\" data-size-price=\"".trim(htmlentities($row2['menu_slice_price']))."\" onclick=\"setSizeDetails(this)\" ".$checked."></input>
      <label for=\"radio\"><span><span></span></span>".htmlentities($row2['menu_slice_name']).' - $'.$row2['menu_slice_price']."</label>
                
              </span>
              <input type=\"hidden\" name=\"mySizeName\" id=\"mySizeName\" value=\"".trim(htmlentities($row2['menu_slice_name']))."\">
              <input type=\"hidden\" name=\"mySizeId\" id=\"mySizeId\" value=\"".trim(htmlentities($row2['menu_slice_id']))."\">";
            }
            else {
              $checked = '';
              $dataSize .="
              <span class=\"col-md-6 col-sm-6 col-xs-12\">
                <input name=\"sizegroup\" class=\"\" type=\"radio\" data-size-id=\"".trim(htmlentities($row2['menu_slice_id']))."\" data-size-name=\"".trim(htmlentities($row2['menu_slice_name']))."\" data-size-price=\"".trim(htmlentities($row2['menu_slice_price']))."\" onclick=\"setSizeDetails(this)\" ".$checked."></input>
      <label for=\"radio\"><span><span></span></span>".htmlentities($row2['menu_slice_name']).' - $'.$row2['menu_slice_price']."</label>
                
              </span>
              ";
            }
          }
          if ($checkSize == 1) {
            $dataSize .="<input type=\"hidden\" name=\"mySizeName\" id=\"mySizeName\" value=\"\">
              <input type=\"hidden\" name=\"mySizeId\" id=\"mySizeId\" value=\"\"></span></span>";
          }
          else {
            $dataSize .="</span></span>";
          }
        }

      }
      else {
        // fix price
        $Fixprice='<span class="col-md-12 col-sm-12 col-xs-12 value-box">
                    <span class="col-md-3 col-sm-4 col-xs-6">
                      Price
                    </span>
                    <span class="col-md-9 col-sm-8 col-xs-6">
                      $ '.$menudetails['menu_price'].'
                    </span>
                  </span>';
      }

      if($menudetails['menu_addons']=='Yes') {
        $MenuAddonsHeader=$this->frontend_model->GetMenuAddonsHeader($menudetails['id']);
        if(is_array($MenuAddonsHeader) && sizeof($MenuAddonsHeader)>0) {
          foreach($MenuAddonsHeader as $key=>$row3) { 
            $dataSubAddons='';
            $dataAddonsHeader ='<span class="col-md-12 col-sm-12 col-xs-12 value-box">
                          <span class="col-md-3 col-sm-4 col-xs-12">
                            '.$row3['menuaddons_addonsname'].'<br>(Choose up to <span id="addonChooseUpto_'.$row3['menuaddons_id'].'" data-old-count="'.$row3['menuaddons_addonscount'].'" class="commonChooseUpto">'.($row3['menuaddons_addonscount'] * $oldQty).'</span>)
                          </span>';

            $MenuSubAddons=$this->frontend_model->GetMenuSubAddons($row3['menuaddons_id']);
            if(is_array($MenuSubAddons) && sizeof($MenuSubAddons)>0) {
              $dataSubAddons ='<span class="col-md-9 col-sm-8 col-xs-12 paddingleft0">';
              foreach($MenuSubAddons as $key=>$row4) { 
                if($row4['menuaddons_price']!='0') {
                  $addonsPrice="$".$row4['menuaddons_price'];
                }
                else {
                  $addonsPrice='Free';
                }
                // addon price and name
                if (isset($oldAddons[$row4['menuaddons_id']])) {
                  $addon_qty = $oldAddons[$row4['menuaddons_id']]['addon_qty'];
                  $addonChecked = 'checked';
                }
                else {
                  $addon_qty = 1;
                  $addonChecked = '';
                }
                $dataSubAddons .='<span class="col-md-6 col-sm-6 col-xs-12 commonParent addonSingleWrap" id="addonParent_'.$row3['menuaddons_id'].'">
                        <input '.$addonChecked.' onclick="addonLimit('.$row3['menuaddons_addonscount'].','.$row4['menuaddons_id'].','.$row3['menuaddons_id'].'); setAddonDetails(this,'.$row3['menuaddons_id'].','.$row4['menuaddons_id'].');" data-addon-id="'.$row4['menuaddons_id'].'" data-addon-name="'.trim(htmlentities($row4['menuaddons_addonsname'])).'" data-addon-price="'.trim(htmlentities($row4['menuaddons_price'])).'" id="advacce_menu_'.$row4['menuaddons_id'].'" class="single-checkbox_'.$row3['menuaddons_id'].' commonCheckbox" name="addons" type="checkbox"></input><label for="checkbox"><span></span>'.$row4['menuaddons_addonsname'].' ('.$addonsPrice.')<br>
                        </label>
                        <br>
                        <i class="fa fa-minus-square-o fa-lg" style="cursor:pointer" aria-hidden="true" data-addon-id="'.$row4['menuaddons_id'].'" data-addon-name="'.trim(htmlentities($row4['menuaddons_addonsname'])).'" data-addon-price="'.trim(htmlentities($row4['menuaddons_price'])).'" onclick="changeAddonCount(this, '.$row4['menuaddons_id'].', '.$row3['menuaddons_id'].', \''."d".'\', '.$row3['menuaddons_addonscount'].')"></i>
                         <span class="commonAddonQuantity" id="addon-qty-'.$row4['menuaddons_id'].'">'.$addon_qty.'</span>
                         <i class="fa fa-plus-square-o fa-lg" style="cursor:pointer" aria-hidden="true" data-addon-id="'.$row4['menuaddons_id'].'" data-addon-name="'.trim(htmlentities($row4['menuaddons_addonsname'])).'" data-addon-price="'.trim(htmlentities($row4['menuaddons_price'])).'" onclick="changeAddonCount(this, '.$row4['menuaddons_id'].', '.$row3['menuaddons_id'].', \''."i".'\', '.$row3['menuaddons_addonscount'].')"></i>
                      </span>';
              }
              $dataAddons .=$dataAddonsHeader.$dataSubAddons.'</span></span>';
            }
            if ($oldIfAddons) {
              $myString = '';
              foreach ($oldAddons as $oldKey => $oldValue) {
                if ($oldValue['parent_id'] == $row3['menuaddons_id']) {
                  $myString .= ','.$oldValue['addon_original_name'].'|'.$oldValue['addon_price'].'|'.$oldValue['addon_qty'].'|'.$oldValue['addon_id'].'|'.$oldValue['parent_id'];
                }
              }
              $dataAddons .= '<input type="hidden" name="myAddonList[]" class="commonMyAddonList" id="myAddonList_'.$row3['menuaddons_id'].'" value="'.$myString.'">';
            }
            else {
              $dataAddons .= '<input type="hidden" name="myAddonList[]" class="commonMyAddonList" id="myAddonList_'.$row3['menuaddons_id'].'">';
            }                            
          }
        }                      
      }


      if($menudetails['menu_spl_instruction']!='No'){

        $spl_instruction = '<span class="col-md-12 col-sm-12 col-xs-12 value-box">
                                <span class="col-md-3 col-sm-4 col-xs-12">
                                  Special Instructions
                                </span>
                                <span class="col-md-9 col-sm-8 col-xs-12">
                                  <textarea class="areatext" style="" class="form-control" rows="5" id="mySpclInst" name="mySpclInst">'.$oldInstruction.'</textarea>
                                  <p>Example: extra cheese, side of dressing, etc.<br>Additional charges may apply.</p>
                                </span>
                              </span>';
      }
      $optionList = '';
      for ($i=1; $i < 21; $i++) { 
        if ($i == $oldQty) {
          $selected = 'selected';
        }
        else {
          $selected = '';
        }
        $optionList .= '<option value="'.$i.'" '.$selected.'>'.$i.'</option>';
      }
      $dataPopup = '<div class="modal-dialog">
                        <input type="hidden" name="myMenuId" id="myMenuId" value="'.$menudetails['id'].'">
                        <input type="hidden" name="myMenuName" id="myMenuName" value="'.$menudetails['menu_name'].'">
                        <input type="hidden" name="myMenuPrice" id="myMenuPrice" value="'.$menudetails['menu_price'].'">
                        <input type="hidden" name="myMenuType" id="myMenuType" value="'.$menudetails['sizeoption'].'">
                        '.$cartEditId.'
                        <!-- Modal content-->
                        <div class="modal-content">
                          <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"></button>
                            <h4 class="modal-title text-center">Update Cart Item</h4>
                          </div>
                          <div class="modal-body">
                            <div class="col-md-12 col-sm-12 custom-padding-0">
                              <div class="col-md-8 col-sm-8">
                                <h3> '.$menudetails['menu_name'].'</h3>
                                <p style="font-size:15px;">'.$menudetails['menu_description'].'</p>
                              </div>
                              <div class="col-md-4 col-sm-4" style="display: none;">
                                <img src="'.$menu_image_name_with_path.'" class="addcart-img">
                              </div>
                            </div>
                            <div class="col-md-12 custom-padding-0 price-body">
                              <span class="col-md-12 col-sm-12 col-xs-12 value-box">
                                <span class="col-md-3 col-sm-4 col-xs-6">
                                  Quantity
                                </span>
                                <span class="col-md-9 col-sm-8 col-xs-6">
                                  <select style="padding: 7px;" data-old-qty="'.$oldQty.'" class="" id="myMenuQty" name="myMenuQty" onchange="resetAddon(this)">
                                    '.$optionList.'
                                  </select>
                                </span>
                              </span>
                              '.$Fixprice.'
                              '.$dataSize.'
                              '.$dataAddons.'

                              '.$spl_instruction.'

                              <div class="clearfix"></div>
                              <div class="col-md-12 text-center mct30">
                                <button type="button" class="btn btn-info cos-mh-btn" style="float:none;" onclick="addOrder()">Update Cart</button>
                              </div>
                            </div>
                          </div>
                          <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                          </div>
                        </div>
                      </div>';

    echo $dataPopup;
  }
  function addOrder() {
    //print_r($this->input->post());
    //$cart = $this->cart->contents();
    if ($this->input->post('cartEditId')) {
      $data = array(
        'rowid' => $this->input->post('cartEditId'),
        'qty'   => 0
      );
      $this->cart->update($data);
    }
    $menu_id = $this->input->post('myMenuId');
    $menu_qty = $this->input->post('myMenuQty');
    $menu_price = $this->input->post('myMenuPrice');
    $menu_name = $this->input->post('myMenuName');
    
    $menu_size = $this->input->post('myMenuType');
    $menu_addon_array = $this->input->post('myAddonList');
    $menu_size_name = $this->input->post('mySizeName');
    $menu_size_id = $this->input->post('mySizeId');
    $menu_size_price = $this->input->post('mySizePrice');
    $menu_spcl_inst = $this->input->post('mySpclInst');
    if ($menu_spcl_inst == '0' || $menu_spcl_inst == 0) {
      $menu_spcl_inst = '';
    }

    if (is_array($menu_addon_array)) {
      $menu_addon_string = implode(',', $menu_addon_array);
    }
    else {
      $menu_addon_string = '';
    }

    $addonArray = array();

    $menuExist = 0;

    if ($menuExist == 0) {
      if ($menu_size == 'size' && $menu_size_name != '') {
        $menu_name = $menu_name;
        $menu_price = $menu_size_price;
      }

      if ($menu_addon_string != '') {
        $menu_addon = array_filter(explode(',', $menu_addon_string));
        foreach ($menu_addon as $key => $value) {
          $myArray = explode('|', $value);
          $addonArray[$myArray[3]]['addon_name'] = $myArray[0]." (".$myArray[2]." x $".$myArray[1].")";
          $addonArray[$myArray[3]]['addon_original_name'] = $myArray[0];
          $addonArray[$myArray[3]]['addon_price'] = $myArray[1];
          $addonArray[$myArray[3]]['addon_qty'] = $myArray[2];
          $addonArray[$myArray[3]]['addon_id'] = $myArray[3];
          $addonArray[$myArray[3]]['parent_id'] = $myArray[4];
        }
      }
      $options = array('size_id' => $menu_size_id, 'addons' => $addonArray);
      $data = array(
          'id'              =>  intval($menu_id),
          'qty'             =>  intval($menu_qty),
          'price'           =>  floatval($menu_price),
          'name'            =>  $menu_name,
          'size_name'       =>  $menu_size_name,
          'size_id'         =>  $menu_size_id,
          'addons'          =>  $addonArray,
          'instruction'     =>  $menu_spcl_inst,
          'options'         =>  $options
        );
      $this->cart->insert($data);
    }
    $this->updateCartView();
    //print_r($this->cart->contents());
    //$this->cart->destroy();
  }
  function changeOrderType() {
    $orderType = $this->input->post('orderType');
    $this->updateCartView($orderType);
  }
  function updateCartView($orderType = '') {
    //$cart = array_reverse($this->cart->contents());
    if ($orderType == '') {
      if ($this->session->userdata('cartData')) {
        $cartData = $this->session->userdata('cartData');
        if (isset($cartData['orderType'])) {
          $orderType = $cartData['orderType'];
        }
      }
    }
    $cart = $this->cart->contents();
    $myHtml = '';
    $subtotal = 0;
    $grandtotal = 0;
    if ($cart) {
      $myHtml .= '<div class="table-responsive">
                    <table class="table table-hover table-bordered" id="add-cart">
                      <tbody>';
      foreach ($cart as $key => $value) {
        $subtotal = $subtotal + $value['subtotal'];
        if ($value['size_name'] != '') {
          $name = $value['name'].' ('.$value['size_name'].')';
        }
        else {
          $name = $value['name'];
        }
      $addonsHtml = '';
      $itemAddonPrice = 0;
      if (is_array($value['addons']) && count($value['addons']) > 0) {
        //$addonsHtml .= '<div class="cartItemAddon">';
        $i = 1;
        foreach ($value['addons'] as $keys => $values) {
          $itemAddonPrice = $itemAddonPrice + floatval($values['addon_price']) * $values['addon_qty'];
          $subtotal = $subtotal + (floatval($values['addon_price']) * $values['addon_qty']);
          if ($i > 1) {
            //$addonsHtml .= ', ';
          }
          if ($addonsHtml == '') {
            $addonsHtml .= '<div class="cartItemAddon"><strong><u>Addons</u></strong></div>';
          }
          $addonsHtml .= '<div class="cartItemAddon">'.$values['addon_name'].'</div>';
          $i++;
        }
        //$addonsHtml .= '</div>';
      }
      $myHtml .=       '<tr class="cartItemRow" id="row_'.$value['rowid'].'">
                          <td style="width: 10%;"><i class="fa fa-lg fa-edit" style="cursor:pointer" aria-hidden="true" onclick="editOrder(\''.$value['rowid'].'\', '.$value['id'].')"></i></td>
                          <td style="width: 10%;">'.$value['qty'].'</td>
                          <td style="width: 70%; font-size: 13px;">
                            '.$name.'
                            '.$addonsHtml.'
                          </td>
                          <td style="width: 22%;">$'.number_format(($value['price'] * $value['qty']) + $itemAddonPrice, 2, '.', '').'</td>
                          <td style="width: 10%;"><img src="'.base_url().'assets/img/cancel.png" style="cursor:pointer" onclick="deleteFromCart(\''.$value['rowid'].'\')"></td>
                        </tr>';

      }
      $myHtml .=      '</tbody>
                    </table>
                  </div>';
      $session_data = $this->session->userdata('logged_in_restaurant');
      $restaurant_id = $session_data['id'];
      $restOrderType = $this->createorder_model->restOrderType($restaurant_id);
      $orderTypeHtml = '';
      if (isset($restOrderType->restaurant_delivery) && $restOrderType->restaurant_delivery == 'Yes') {
        $checked = '';
        if ($orderType == 'delivery') {
          $checked = 'checked';
        }
        else if($orderType == '' && $restOrderType->restaurant_pickup == 'No' && $restOrderType->restaurant_dinein == 'No') {
          $checked = 'checked';
          $orderType = 'delivery';
        }
        $orderTypeHtml .= '<span class="midAlign">
                              <input type="radio" data-type="delivery" onclick="changeOrderType(this)" name="order_type" class="orderTypeClass" '.$checked.'>
                              <label>Delivery</label>
                            </span>';
      }
      if (isset($restOrderType->restaurant_pickup) && $restOrderType->restaurant_pickup == 'Yes') {
        $checked = '';
        if ($orderType == 'pickup') {
          $checked = 'checked';
        }
        else if($orderType == '' && $restOrderType->restaurant_delivery == 'No' && $restOrderType->restaurant_dinein == 'No') {
          $checked = 'checked';
          $orderType = 'pickup';
        }
        $orderTypeHtml .= '<span class="midAlign">
                              <input type="radio" data-type="pickup" onclick="changeOrderType(this)" name="order_type" class="orderTypeClass" '.$checked.'>
                              <label>Pickup</label>
                            </span>';
      }
      if (isset($restOrderType->restaurant_dinein) && $restOrderType->restaurant_dinein == 'Yes') {
        $checked = '';
        if ($orderType == 'dinein') {
          $checked = 'checked';
        }
        else if($orderType == '' && $restOrderType->restaurant_delivery == 'No' && $restOrderType->restaurant_pickup == 'No') {
          $checked = 'checked';
          $orderType = 'dinein';
        }
        $orderTypeHtml .= '<span class="midAlign">
                              <input type="radio" data-type="dinein" onclick="changeOrderType(this)" name="order_type" class="orderTypeClass" '.$checked.'>
                              <label>Dine-In</label>
                            </span>';
      }
      // cart countings
      $salesTax = $this->createorder_model->restSalesTax($restaurant_id);
      // $taxAmount = $subtotal * ($salesTax / 100);
      // $subtotalWithTax = $subtotal + $taxAmount;
      $deliveryCharge = $this->createorder_model->deliveryCharge();
      if ($orderType != 'delivery') {
        $deliveryCharge = 0.00;
      }
      $subtotalWithDelCharge = $subtotal + $deliveryCharge;
      $taxAmount = $subtotalWithDelCharge * ($salesTax / 100);
      $subtotalWithTaxWithDelCharge = $subtotalWithDelCharge + $taxAmount;
      $subtotalWithTax = $subtotalWithTaxWithDelCharge;
      $myHtml .= '<div class="table-responsive">
                    <table class="table table-hover table-bordered" id="">
                      <tbody>
                        <tr class="">
                          <td class="text-right" width="75%">Item Price:</td>
                          <td width="25%">$'.number_format($subtotal, 2, '.', '').'</td>
                        </tr>
                        <tr style="color: rgb(11, 80, 158);">
                          <td class="text-right" width="75%">Delivery Charge:</td>
                          <td width="20%">$'.number_format($deliveryCharge, 2, '.', '').'</td>
                        </tr>
                        <tr class="">
                          <td class="text-right" width="75%">Tax('.number_format($salesTax, 2, '.', '').' %):</td>
                          <td width="20%">$'.number_format($taxAmount, 2, '.', '').'</td>
                        </tr>
                      </tbody>
                      <tbody id="delivery-charge1">
                        <tr style="font-weight:600;">
                          <td class="text-right" width="75%">Subtotal:</td>
                          <td width="20%">$'.number_format($subtotalWithTax, 2, '.', '').'</td>
                        </tr>
                      </tbody>
                      <tbody class="hideInCheckout" id="popGrandTotalRow">
                        <tr style="font-weight:600;">
                          <td class="text-right" width="75%">Total:</td>
                          <td width="20%" id="cartPopTotal">$'.number_format($subtotalWithTaxWithDelCharge, 2, '.', '').'</td>
                        </tr>
                      </tbody>
                      <tbody class="hideInCheckout">
                        <tr style="font-weight:600;text-align:center;">
                          <td colspan="3">
                            '.$orderTypeHtml.'
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>';
    }
    else {
      $myHtml = '<div class="table-responsive">
                    <table class="table table-hover table-bordered" id="add-cart">
                      <tbody>
                        <tr class="text-center">
                          <td>
                            No items added yet!
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>';
    }
    $data['subtotal'] = isset($subtotal)?number_format($subtotal, 2, '.', ''):0;
    $data['taxAmount'] = isset($taxAmount)?number_format($taxAmount, 2, '.', ''):0;
    $data['subtotalWithTax'] = isset($subtotalWithTax)?number_format($subtotalWithTax, 2, '.', ''):0;
    $data['deliveryCharge'] = isset($deliveryCharge)?number_format($deliveryCharge, 2, '.', ''):0;
    $data['subtotalWithTaxWithDelCharge'] = isset($subtotalWithTaxWithDelCharge)?number_format($subtotalWithTaxWithDelCharge, 2, '.', ''):0;
    $data['orderType'] = $orderType;
    /*if ($this->session->userdata('cartData')) {
      $this->session->unset_userdata('cartData');
    }
    $this->session->set_userdata('cartData', $data);*/
    $data['myHtml'] = $myHtml;
    echo json_encode($data);
  }
  function deleteFromCart() {
    $rowid = $this->input->post('rowid');
    $data = array(
        'rowid' => $rowid,
        'qty'   => 0
      );
    $this->cart->update($data);
    $this->updateCartView();
  }
  function updateCartCount() {
    $rowid = $this->input->post('rowid');
    $qty = $this->input->post('qty');
    $data = array(
        'rowid' => $rowid,
        'qty'   => $qty
      );
    $this->cart->update($data);
    $this->updateCartView();
  }
  function testPolygon() {
    $address = 'Metropolitan Life North Building, 11 Madison Ave, New York, NY 10010, USA';
    $delivery_details = $this->createorder_model->restaurantDeliveryDetails($restaurant_id = 171);
    echo "<pre>";
    print_r($delivery_details);
    echo "</pre>";
    $restaurant_id = 0;
    $isDeliveryAvailable = false;
    $deliveryZone = 0;
    $deliveryCharge = 0;
    $minOrderPrice = 0;
    if(isset($delivery_details->delivery_zone_1) && $this->mypolygon->checkPolygon($address, $delivery_details->delivery_zone_1, '')) {
      echo "Checking in 1<br>";
      $isDeliveryAvailable = true;
      $deliveryZone = 1;
      $deliveryCharge = $delivery_details->restaurant_delivery_charge;
      $minOrderPrice = $delivery_details->restaurant_minorder_price;
    }
    else if(isset($delivery_details->delivery_zone_2) && $this->mypolygon->checkPolygon($address, $delivery_details->delivery_zone_2, '')) {
      echo "Checking in 2<br>";
      $isDeliveryAvailable = true;
      $deliveryZone = 2;
      $deliveryCharge = $delivery_details->restaurant_delivery_charge_2;
      $minOrderPrice = $delivery_details->restaurant_minorder_price_2;
    }
    else if(isset($delivery_details->delivery_zone_3) && $this->mypolygon->checkPolygon($address, $delivery_details->delivery_zone_3, '')) {
      echo "Checking in 3<br>";
      $isDeliveryAvailable = true;
      $deliveryZone = 3;
      $deliveryCharge = $delivery_details->restaurant_delivery_charge_3;
      $minOrderPrice = $delivery_details->restaurant_minorder_price_3;
    }

    $data['isDeliveryAvailable'] = $isDeliveryAvailable;
    $data['deliveryZone'] = $deliveryZone;
    $data['deliveryCharge'] = $deliveryCharge;
    $data['minOrderPrice'] = $minOrderPrice;

    echo json_encode($data);
  }
  function checkDeliveryArea() {
    // print_r($this->input->post());
    $customer_street = $this->input->post('customer_street');
    $customer_zip = $this->input->post('customer_zip');
    $customer_city = $this->input->post('customer_city');
    $customer_state = $this->input->post('customer_state');
    $address = '';
    if ($customer_street !== '') {
      $address .= $customer_street;
    }
    if ($customer_zip !== '') {
      if ($address !== '') {
        $address .= ', ';
      }
      $address .= $customer_zip;
    }
    if ($customer_city !== '') {
      if ($address !== '') {
        $address .= ', ';
      }
      $address .= $customer_city;
    }
    if ($customer_state !== '') {
      if ($address !== '') {
        $address .= ', ';
      }
      $address .= $customer_state;
    }

    $restaurant_id = 0;
    $isDeliveryAvailable = false;
    $deliveryZone = 0;
    $deliveryCharge = 0;
    $minOrderPrice = 0;

    if ($this->session->userdata('logged_in_restaurant')) {
      $myArray = $this->session->userdata('logged_in_restaurant');
      $restaurant_id = $myArray['id'];
    }
    if ($restaurant_id !== 0) {
      $delivery_details = $this->createorder_model->restaurantDeliveryDetails($restaurant_id);
      // echo json_encode($delivery_details); exit();
      if(isset($delivery_details->delivery_zone_1) && $this->mypolygon->checkPolygon($address, $delivery_details->delivery_zone_1, '')) {
        $isDeliveryAvailable = true;
        $deliveryZone = 1;
        $deliveryCharge = $delivery_details->restaurant_delivery_charge;
        $minOrderPrice = $delivery_details->restaurant_minorder_price;
      }
      else if(isset($delivery_details->delivery_zone_2) && $this->mypolygon->checkPolygon($address, $delivery_details->delivery_zone_2, '')) {
        $isDeliveryAvailable = true;
        $deliveryZone = 2;
        $deliveryCharge = $delivery_details->restaurant_delivery_charge_2;
        $minOrderPrice = $delivery_details->restaurant_minorder_price_2;
      }
      else if(isset($delivery_details->delivery_zone_3) && $this->mypolygon->checkPolygon($address, $delivery_details->delivery_zone_3, '')) {
        $isDeliveryAvailable = true;
        $deliveryZone = 3;
        $deliveryCharge = $delivery_details->restaurant_delivery_charge_3;
        $minOrderPrice = $delivery_details->restaurant_minorder_price_3;
      }
    }

    $data['isDeliveryAvailable'] = $isDeliveryAvailable;
    $data['deliveryZone'] = $deliveryZone;
    $data['deliveryCharge'] = $deliveryCharge;
    $data['minOrderPrice'] = $minOrderPrice;

    if ($this->session->userdata('delivery_details')) {
      $this->session->unset_userdata('delivery_details');
    }
    $this->session->set_userdata('delivery_details', $data);

    echo json_encode($data);
  }
  function placeOrder() {
    $this->form_validation->set_rules('customer_id', 'customer_id', 'trim');
    $this->form_validation->set_rules('tempCode', 'tempCode', 'trim');
    $this->form_validation->set_rules('customer_name', 'customer_name', 'trim');
    $this->form_validation->set_rules('customer_lastname', 'customer_lastname', 'trim');
    $this->form_validation->set_rules('customer_email', 'customer_email', 'trim');
    $this->form_validation->set_rules('customer_phone', 'customer_phone', 'trim');
    $this->form_validation->set_rules('customer_street', 'customer_street', 'trim');
    $this->form_validation->set_rules('customer_buildtype', 'customer_buildtype', 'trim');
    $this->form_validation->set_rules('customer_city', 'customer_city', 'trim');
    $this->form_validation->set_rules('customer_state', 'customer_state', 'trim');
    $this->form_validation->set_rules('customer_zip', 'customer_zip', 'trim');
    $this->form_validation->set_rules('instructions', 'instructions', 'trim');
    $this->form_validation->set_rules('cc_number', 'cc_number', 'trim');
    $this->form_validation->set_rules('cc_type', 'cc_type', 'trim');
    $this->form_validation->set_rules('cc_exp_month', 'cc_exp_month', 'trim');
    $this->form_validation->set_rules('cc_exp_year', 'cc_exp_year', 'trim');
    $this->form_validation->set_rules('cc_cvv', 'cc_cvv', 'trim');
    $validationStatus = $this->form_validation->run();
    /*echo "<pre>";
    print_r ($this->input->post());
    echo "</pre>";
    exit();*/
    $now = date('Y-m-d H:i:s');
    // customer details
    $customer_id = $this->input->post('customer_id');
    /*$customer_full_name = $this->input->post('customer_full_name'); //none
    $space = strrpos($customer_full_name, ' '); //none
    $length = strlen($customer_full_name); //none
    if ($space != 0) {
      $customername = substr($customer_full_name, 0, $space);
      $customerlastname = substr($customer_full_name, $space, $length);
    }
    else {
      $customername = $customer_full_name;
      $customerlastname = '';
    }*/
    $customername = $this->input->post('customer_name');
    $customerlastname = $this->input->post('customer_lastname');
    $customer_email = $this->input->post('customer_email');
    $customer_phone = $this->input->post('customer_phone');
    $customer_street = $this->input->post('customer_street');
    $customer_buildtype = $this->input->post('customer_buildtype');
    $customer_zip = $this->input->post('customer_zip');
    $customer_state = $this->input->post('customer_state');
    $customer_city = $this->input->post('customer_city');
    // card details 
    $time = time();
    $cc_type = $this->input->post('cc_type');
    $cc_number_clean = str_replace(' ', '', $this->input->post('cc_number'));
    $cc_number = $this->createorder_model->ccEncrypt($cc_number_clean, $time);
    $cc_exp_month = $this->input->post('cc_exp_month');
    $cc_exp_year = $this->input->post('cc_exp_year');
    $cc_cvv = $this->createorder_model->ccEncrypt($this->input->post('cc_cvv'), $time);

    $tempCode = $this->input->post('tempCode');
    if ($tempCode != '') {
      $tempCode_array = explode('-|-', $tempCode);
      $oldCode = $this->createorder_model->ccDecrypt($tempCode_array[0], $tempCode_array[1]);
    }
    else {
      $oldCode = '';
    }
    // cart details
    $subtotal = $this->input->post('subtotal');
    $itemTotal = $subtotal;
    $taxAmount = $this->input->post('taxAmount');
    $subtotalWithTax = $this->input->post('subtotalWithTax');
    $deliveryCharge = $this->input->post('deliveryCharge');
    $subtotalWithTaxWithDelCharge = $this->input->post('subtotalWithTaxWithDelCharge');
    $orderType = $this->input->post('orderType');
    $discountOption = $this->input->post('discountOption');
    $cart_discount = $this->input->post('cart_discount');
    $paymentOption = $this->input->post('paymentOption');
    if ($discountOption == 'fix') {
      $discount_fix = $cart_discount;
      $discount_per = 0;
      $discountvalue = $discount_fix;
    }
    else if ($discountOption == 'per') {
      $discount_per = $cart_discount;
      $discount_fix = 0;
      $discountvalue = $subtotal * ($discount_per / 100);
    }
    $subtotal = $subtotal - $discountvalue;
    $subtotalWithDelCharge = $subtotal + $deliveryCharge;
    $subtotalWithTax = $subtotalWithDelCharge + $taxAmount;
    $subtotalWithTaxWithDelCharge = $subtotalWithTax;
    $subtotalWithTaxWithDelCharge = $subtotalWithTaxWithDelCharge;
    // $grandTotal = $subtotalWithTaxWithDelCharge - $discountvalue;
    $grandTotal = number_format($subtotalWithTaxWithDelCharge, 2, '.', '');
    // other details
    $instructions = $this->input->post('instructions');
    // restaurant details
    $session_data = $this->session->userdata('logged_in_restaurant');
    $restaurant_id = $session_data['id'];
    $restaurant_name = $this->createorder_model->restName($restaurant_id);
    $restaurant_sales_tax = $this->createorder_model->restSalesTax($restaurant_id);
    $commission = $this->createorder_model->restaurantCommission($restaurant_id, $itemTotal, $deliveryCharge, $taxAmount, $discountvalue);
    $this->db->select('braintree_sub_merchant_id');
    $this->db->from('rt_restaurant');
    $this->db->where('restaurant_id', $restaurant_id);
    $restQuery = $this->db->get();
    $restData = $restQuery->row();
    $braintree_sub_merchant_id = $restData->braintree_sub_merchant_id;
    
    $ccDetails = $this->createorder_model->getCCDetails($customer_id);

    if ($oldCode == $cc_number_clean || !is_numeric($cc_number_clean)) {
      $btCardNumber = $ccDetails->cc_number;
      $btCardExpMonth = $ccDetails->cc_exp_month;
      $btCardExpYear = $ccDetails->cc_exp_year;
      $btCardCVV = $ccDetails->cc_cvv;
    }
    else {
      $btCardNumber = $cc_number_clean;
      $btCardExpMonth = $cc_exp_month;
      $btCardExpYear = $cc_exp_year;
      $btCardCVV = $this->input->post('cc_cvv');
    }
    $RestaurantShare = number_format($itemTotal + $taxAmount - $discountvalue - $commission, 2, '.', '');
    $WebsiteShare = number_format($grandTotal - $RestaurantShare, 2, '.', '');
    /*$result = Braintree_Transaction::sale(array(
                  'merchantAccountId' => $braintree_sub_merchant_id,
                  'amount' => $RestaurantShare,
                  'serviceFeeAmount' => $WebsiteShare,
                      'creditCard' => array(
                      'number' => $btCardNumber,
                      'cardholderName' => '',
                      'expirationDate' => $btCardExpMonth.'/'.$btCardExpYear,
                      'cvv' => $btCardCVV
                  ),
                      'options' => array(
                        'submitForSettlement' => true,
                        'holdInEscrow' => true
                      ),
              ));
    if($result->success && $result->transaction->id) { 
        $transactionId = $result->transaction->id;
        //echo $transactionId;
        $cc_status_up = array(
            'transaction_id'  => $transactionId,
            'paypal_status'   => 'success'
          );
        $this->db->where('orderid', $orderid);
        $this->db->update('rt_order', $cc_status_up);
    }
    else {
      $this->session->set_flashdata('error_msg', 'Unable to process the order');
      $this->showCreateOrder($error_msg = 'Unable to process the order');
    }*/
      /*
         * Pin Payment Gateway charge card
         */
      $SECRET_KEY = $this->config->item("pin_payment_key");
      $IS_LIVE = $this->config->item("pin_payment_is_live");
      $IS_TEST = false;
      if(!$IS_LIVE) $IS_TEST = true;
      $gateway = Omnipay::create('Pin');
      // Initialise the gateway
      $gateway->initialize(array(
          'secretKey' => $SECRET_KEY,
          'testMode'  => $IS_TEST, // Or false when you are ready for live transactions
      ));
      // Create a credit card object
      // This card can be used for testing.
      // See https://pin.net.au/docs/api/test-cards for a list of card
      // numbers that can be used for testing.
      $card = new CreditCard(array(
          'firstName'    => $customername,
          'lastName'     => $customerlastname,
          'number'       => $btCardNumber,
          'expiryMonth'  => $btCardExpMonth,
          'expiryYear'   => $btCardExpYear,
          'cvv'          => $btCardCVV,
          'email'        => $customer_email,
          'billingAddress1'       => $customer_street,
          'billingCountry'        => 'AU',
          'billingCity'           => $customer_city,
          'billingPostcode'       => $customer_zip,
          'billingState'          => $customer_state,
      ));
      // Do a purchase transaction on the gateway
      $transaction = $gateway->purchase(array(
          'description'              => 'Order form '.SITENAME,
          'amount'                   => number_format($grandTotal, 2, '.', ''),
          'currency'                 => 'AUD',
          'clientIp'                 => $_SERVER['REMOTE_ADDR'],
          'card'                     => $card,
      ));
      $response = $transaction->send();
      //$this->pr($response);
     /* if ($response->isSuccessful()) {
          $transactionId = $response->getTransactionReference();
          $cc_status_up = array(
              'transaction_id'  => $transactionId,
              'paypal_status'   => 'success'
          );
          $this->db->where('orderid', $orderid);
          $this->db->update('rt_order', $cc_status_up);
      }*/
      if ($response->isSuccessful()) {
      $this->db->trans_start();
      $this->db->select('customer_id');
      $this->db->from('rt_customer');
      $this->db->where('customer_email', $customer_email);
      $custQuery = $this->db->get();
      $custData = $custQuery->row();
      if ($custQuery->num_rows() > 0) {
        $customer_id = $custData->customer_id;
      }
      if (!isset($customer_id) || $customer_id == '') {
        $customer_data_in = array(
            'customer_name'           =>    $customername,
            'customer_lastname'       =>    $customerlastname,
            'customer_email'          =>    $customer_email,
            'customer_phone'          =>    $customer_phone,
            'customer_street'         =>    $customer_street,
            'customer_buildtype'      =>    $customer_buildtype,
            'customer_zip'            =>    $customer_zip,
            'customer_state'            =>    $customer_state,
            'customer_city'            =>    $customer_city,
            'addeddate'               =>    $now
          );
        $this->db->insert('rt_customer', $customer_data_in);
        $customer_id = $this->db->insert_id();
        /*if ($paymentOption == 'cc') {
          $card_data_in = array(
              'customer_id'  =>  $customer_id,
              'cc_type'  =>  $cc_type,
              'cc_number'  =>  $cc_number,
              'cc_exp_month'  =>  $cc_exp_month,
              'cc_exp_year'  =>  $cc_exp_year,
              'cc_cvv'  =>  $cc_cvv,
              'cc_time'  =>  $time
            );
          $this->db->insert('rt_credit_cards', $card_data_in);
        }*/
      }
      /*echo "<pre>";
      print_r ($customer_data_in);
      print_r ($card_data_in);
      echo "</pre>";*/
      $this->db->select('driver_payout');
      $this->db->from('rt_sitesetting');
      $query = $this->db->get();
      $myData = $query->row();
      $driver_commission = $myData->driver_payout;
      $address = $customer_street.' '.$customer_buildtype.' '.$customer_zip;
      if($address!='') {
         $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
         // We convert the JSON to an array
         $geo = json_decode($geo, true);
         // If everything is cool
         if ($geo['status'] = 'OK') {
         // We set our values
         $latitude = isset($geo['results'][0]['geometry']['location']['lat'])? $geo['results'][0]['geometry']['location']['lat']: DEFAULT_LAT;
         $longitude = isset($geo['results'][0]['geometry']['location']['lng'])? $geo['results'][0]['geometry']['location']['lng'] : DEFAULT_LONG;
         }
         else {
           $latitude = DEFAULT_LAT;
           $longitude = DEFAULT_LONG;
         }
       }
       else {
         $latitude = DEFAULT_LAT;
         $longitude = DEFAULT_LONG;
       }

      $stateName = $customer_state;
      $cityName = $customer_city;
      if ($stateName != '') {
        $customer_street .= ', '.$stateName;
      }
      if ($cityName != '') {
        $customer_street .= ', '.$cityName;
      }
      if ($customer_zip != '') {
        $customer_street .= ', '.$customer_zip;
      }
      $dbOrderType = '';
      if ($orderType == 'delivery') {
        $dbOrderType = 'Delivery';
      }
      else if ($orderType == 'pickup') {
        $dbOrderType = 'Pickup';
      }
      else if ($orderType == 'dinein') {
        $dbOrderType = 'Dine-In';
      }
      $order_data_in = array(
          'restaurant_id'         =>    $restaurant_id,
          'restaurant_name'       =>    $restaurant_name,
          'customer_id'           =>    $customer_id,
          'usertype'              =>    'C',
          'customername'          =>    $customername,
          'customerlastname'      =>    $customerlastname,
          'customeremail'         =>    $customer_email,
          'customercellphone'     =>    $customer_phone,
          'deliverydoornumber'    =>    $customer_buildtype,
          'deliverystreet'        =>    $customer_street,
          'deliveryzip'           =>    $customer_zip,
          'deliverystate'           =>    $customer_state,
          'deliverycity'           =>    $customer_city,
          'deliverytype'          =>    $dbOrderType,
          'deliverydate'          =>    $now,
          'deliverytime'          =>    'ASAP',
          'instructions'          =>    $instructions,
          // 'menuprice_total'       =>    $subtotal,
          'menuprice_total'       =>    $itemTotal,
          'tax_per'               =>    $restaurant_sales_tax,
          'taxvalue'              =>    $taxAmount,
          'discount_fix'          =>    $discount_fix,
          'discount_per'          =>    $discount_per,
          'discountvalue'         =>    $discountvalue,
          // 'ordersubtotal'         =>    $subtotal+$taxAmount+$deliveryCharge,
          'ordersubtotal'         =>    $itemTotal+$taxAmount+$deliveryCharge,
          'delivery_charged'      =>    $deliveryCharge,
          'driver_commission'     =>    $driver_commission,
          'ordertotalprice'       =>    $grandTotal,
          'payment_type'          =>    strtoupper($paymentOption),
          'paypal_status'         =>   'failed',
          'status'                =>    'In Preparation',
          'orderdate'             =>    $now,
          'commission'            =>    $commission,
          'deliverylatitude'      =>    $latitude,
          'deliverylongitude'     =>    $longitude
        );
      $this->db->insert('rt_order', $order_data_in);
      $orderid = $this->db->insert_id();
      $ordergenerateid = 'ORD'.$orderid;
      $orderid_code_up = array('ordergenerateid' => $ordergenerateid);
      $this->db->where('orderid', $orderid);
      $this->db->update('rt_order', $orderid_code_up);
      $cart = $this->cart->contents();
      foreach ($cart as $key => $value) {
        $menuid = $value['id'];
        $quantity = $value['qty'];
        if ($value['size_name'] != '') {
          $menuname = $value['name'].' ('.$value['size_name'].')';
        }
        else {
          $menuname = $value['name'];
        }
        $menuprice = $value['price'];
        $tot_menuprice = $value['subtotal'];
        $addonsname = '';
        $addonsprice = 0;
        if (is_array($value['addons']) && count($value['addons']) > 0) {
          foreach ($value['addons'] as $keys => $values) {
            if ($addonsname == '') {
              $addonsname .= ', ';
            }
            $addonsname .= $values['addon_name'];
            $addonsprice = $addonsprice + (floatval($values['addon_price']) * $values['addon_qty']);
            //$tot_menuprice = $tot_menuprice + floatval($values['addon_price']);
          }
          $tot_menuprice = $tot_menuprice + $addonsprice;
        }
        $specialinstruction = isset($value['instruction'])?$value['instruction']:'';
        $cart_data_in = array(
            'menuid'        => $menuid,
            'quantity'      => $quantity,
            'menuname'      => $menuname,
            'menuprice'     => $menuprice,
            'tot_menuprice' => $tot_menuprice,
            'addonsname'    => $addonsname,
            'addonsprice'   => $addonsprice,
            'orderid'       => $orderid,
            'restaurantid'  => $restaurant_id,
            'specialinstruction'  => $specialinstruction,
            'addeddate'     => $now
          );
        $this->db->insert('rt_restaurant_cart', $cart_data_in);
      }
      $this->db->trans_complete();
      if ($this->db->trans_status() === FALSE) {
        $this->db->trans_rollback();
      }
      else {
        $this->db->trans_commit();
        $this->cart->destroy();
      }
      if ($response->isSuccessful()) {
          if ($orderType == 'delivery') {
              $this->notifyDriver($orderid);
          }
        $transactionId = $result->transaction->id;
        $cc_status_up = array(
            'transaction_id'  => $transactionId,
            'paypal_status'   => 'success'
          );
        $this->db->where('orderid', $orderid);
        $this->db->update('rt_order', $cc_status_up);
      }
      else {
        $this->session->set_flashdata('error_msg', $this->lang->line('Unabletoprocesstheorder'));
        $this->showCreateOrder();
      }
      $orderShort = $this->createorder_model->orderShortDetails($orderid);
      $orderLong = $this->createorder_model->orderLongDetails($orderid);
      $this->db->select('rest.order_receive_type, rest.restaurant_contact_email');
      $this->db->from('rt_order as ord');
      $this->db->join('rt_restaurant as rest', 'rest.restaurant_id = ord.restaurant_id', 'left');
      $this->db->where('ord.orderid', $orderid);
      $restQuery = $this->db->get();
      $restData = $restQuery->row();
      $orderReceiveTypeString = $restData->order_receive_type;
      $restaurantEmail = $restData->restaurant_contact_email;
      $orderReceiveTypeArray = array_filter(explode(',', $orderReceiveTypeString));
      $orderReceiveEmail = false;
      if (in_array('email', $orderReceiveTypeArray)) {
        $orderReceiveEmail = true;
      }
      $cart_items = '';
      if ($orderLong) {
        foreach ($orderLong as $key => $value) {
          $cart_items .= '<tr class="even" style="">';
          $cart_items .=     '<td style="text-align: center;">'.($key+1).'</td>';
          if($value->addonsname != "")
          {
          $cart_items .=     '<td style="text-align: center;">'.trim(htmlentities($value->menuname)).'<br /><span style="font-size: 12px;">'.trim(htmlentities($value->addonsname)).'</span></td>';
          }
          else {
          $cart_items .=     '<td style="text-align: center;">'.trim(htmlentities($value->menuname)).'</td>';
          }
          $cart_items .=     '<td style="text-align: center;">'.$value->quantity.'</td>';
          $cart_items .=     '<td style="text-align: center;">$'.$value->menuprice.'</td>';
          $cart_items .=     '<td style="text-align: center;">$'.$value->tot_menuprice.'</td>';
          $cart_items .=   '</tr>';
        }
      }
      /*echo "<pre>";
      print_r ($orderShort);
      print_r ($orderLong);
      echo "</pre>";
      exit();*/
      if (isset($orderShort) && isset($orderLong)) {
        /*echo "<pre>";
        print_r ($orderShort);
        print_r ($orderLong);
        echo "</pre>";
        exit();*/
        $image_path = base_url().'assets/';
        $variables = array();
        $to = $orderShort->customeremail;

        $variables['order_id'] = 'ORD'.$orderShort->orderid;
        $variables['customer_email'] = $orderShort->customeremail;
        $variables['customer_name'] = $orderShort->customername.' '.$orderShort->customerlastname;
        $variables['total_item_price_label'] = 'Item Price';
        $variables['total_item_price'] = number_format($orderShort->menuprice_total, 2, '.', '');
        $variables['tax_label'] = 'Tax('.$orderShort->tax_per.'%)';
        $variables['tax_amount'] = number_format($orderShort->taxvalue, 2, '.', '');
        $variables['sub_total_label'] = 'Sub Total';
        $variables['sub_total_amount'] = number_format($orderShort->ordersubtotal, 2, '.', '');
        $variables['delivery_charge_label'] = 'Delivery Charge';
        $variables['delivery_charge_amount'] = number_format($orderShort->delivery_charged, 2, '.', '');
        $variables['tips_label'] = 'Tips';
        $variables['tips_amount'] = $orderShort->tip == ''?0.00:number_format($orderShort->tip, 2, '.', '');
        $variables['offer_label'] = 'Coupon Discount';
        $variables['offer_amount'] = number_format($orderShort->offervalue, 2, '.', '')==''?0.00:number_format($orderShort->offervalue, 2, '.', '');
        $variables['grand_total_label'] = 'Grand Total';
        $variables['grand_total'] = number_format($orderShort->ordertotalprice, 2, '.', '');
        $variables['cart_items'] = $cart_items;

        $variables['image_path'] = $image_path;
        $variables['to_email'] = $to;
        //$variables['sender_email'] = SITE_CONTACT_EMAIL;
        $variables['site_address'] = SITE_ADDRESS;
        $variables['sender_name'] = SITENAME;
        $variables['site_name'] = SITENAME;
        $template_name = 'customer_order';
        $mail_data = $this->frontend_model->getEmailTemplate($template_name);
        $mailcontent=htmlspecialchars_decode($mail_data->template);
        $subject = $mail_data->subject;
        foreach($variables as $key => $value) {
          $mailcontent = str_replace('{{'.$key.'}}', $value, $mailcontent);
        }
        $this->send_my_mail($to,$subject,$mailcontent);
        $this->db->select('twilio_sid, twilio_token, twilio_from_no');
        $this->db->from('rt_sitesetting');
        $this->db->limit('1');
        $queryTwilio = $this->db->get();
        $client = new Services_Twilio($queryTwilio->row()->twilio_sid, $queryTwilio->row()->twilio_token);
        $twiloErr = "";
        try {
          $cusno=str_replace(array( '(', ')' , ' ' , '-' , '+'), '', $orderShort->customercellphone);
          $message = $client->account->messages->create(array(
              "From" => $queryTwilio->row()->twilio_from_no,//"+15005550006", // From a valid Twilio number
              "To" => '+'.$cusno, // Text this number
              "Body" => "You have ordered successfully. Your order no #ORD".$orderShort->orderid."",
            ));
        }
        catch(Exception $e) 
        {
          //echo 'Message: ' .$e->getMessage();
          $twiloErr = $e->getMessage();
          $this->send_my_mail('earthtechnology7@gmail.com', 'Twilio Error', $twiloErr);
        }
        if ($orderReceiveEmail) {
          $this->send_my_mail($restaurantEmail,'Copy of Order',$mailcontent);
        }
        redirect('restaurantadmin/restaurantorders');
      }
    }
      else {
          $this->session->set_flashdata('error_msg', $this->lang->line('Unabletoprocesstheorder'));
          $this->showCreateOrder();
      }
  }
  function notifyDriver($orderid) {
    $now = date('Y-m-d H:i:s');
    //$orderid = $this->input->post('orderid');
    $why = $this->input->post('why');
    if ($why == 're') {
      $myArray = array(
          'isdriver_assign'   => 0,
          'delivery_status'   => 0,
          'driverid'          => 0,
          'drivername'        => 0,
          'status'            => 'In Preparation',
        );
      $this->db->trans_start();
      $this->db->where('orderid',$orderid);
      $this->db->update('rt_order',$myArray);
      $this->db->trans_complete();
    }
    $nowTime = date('H:i');
    $this->db->where('notify_order_id', $orderid);
    $this->db->delete('rt_driver_notify');
    $assigned_driver_in = array('notify_order_id' => $orderid, 'notify_time' => $nowTime);
    $this->db->insert('rt_driver_notify', $assigned_driver_in);
    $order_arr=array('isdriver_assign' => 1, 'driver_assign_time' => $now);
    $this->db->trans_start();
    $this->db->where('orderid',$orderid);
    $this->db->update('rt_order',$order_arr);
    $this->db->trans_complete();
    $Driver_List = $this->dashboard_model->get_driver_list();
    if(is_array($Driver_List) && sizeof($Driver_List)>0) {
     foreach($Driver_List as $row) {  
      $result = $this->dashboard_model->check_driver($row['driver_id']);
      if(!$result) {
        $deviceToken = $row['ios_device_token'];//'b5ad9dc757a7489d0b1a1fc84f43701a8effb42c5914ad984d356f9aa568410c';
        $deviceTokenAndroid = $row['android_device_token'];
        $registrationIdsArray = array($deviceTokenAndroid); //do7bKiXoN2w:APA91bHud2WQJSB2AeotpNh78lSaLqQScn8oNvu7vohgiOretzselRLvv6XIpMbH7wE66651dh-CMEik5W946lJpmQQ4kNrwRMyyoW-3fYln-NkU_8uHZMxtaX_da--YISTSgKXzkSTD
        if($deviceToken!='') {
          $passphrase = '';
          $message = 'New order is placed. Please check.';
          $ctx = stream_context_create();
          stream_context_set_option($ctx, 'ssl', 'local_cert', 'dine2you.pem');
          //stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
          $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
          $body['aps'] = array('alert' => $message, 'badge' => 1, 'sound' => 'oldcash.wav', 'order_id'=>$orderid);
          $payload = json_encode($body);
          if (!$fp) {
                 exit("Failed to connect: $err $errstr" . PHP_EOL);
          }
          //$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
          $msg = chr(0) . pack('n', 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack('n', strlen($payload)) . $payload; 
          $result = fwrite($fp, $msg, strlen($msg));
          fclose($fp);
        }
        if($deviceTokenAndroid != "") {
          $apiKey = ANDROID_PUSH_API;//AIzaSyAfAtTYhdwxYR9csZtyI3wOlAMl-JjcViw
          $message = 'New order is placed. Please check.';
          $messageData = array('message'=> $message, 'title'=> "New delivery task", 'appredirect'=> "",'order_id'=>$orderid);
          $headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey);
          $data = array(
            'data' => $messageData,
            'registration_ids' => $registrationIdsArray//do7bKiXoN2w:APA91bHud2WQJSB2AeotpNh78lSaLqQScn8oNvu7vohgiOretzselRLvv6XIpMbH7wE66651dh-CMEik5W946lJpmQQ4kNrwRMyyoW-3fYln-NkU_8uHZMxtaX_da--YISTSgKXzkSTD
          );
          $ch = curl_init();
          curl_setopt( $ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send" );
          curl_setopt( $ch, CURLOPT_POST, true );
          curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); 
          curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
          curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
          curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
          curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($data) );
          $response = curl_exec($ch);
          curl_close($ch);
        }
      }
     }
   }
   return true;
  }
  function send_my_mail($mail_To,$mail_subject,$mail_Body,$mail_CC="")
  {
      $mail_From = SITENAME;

      $mail = new PHPMailer();

      //Your SMTP servers details

      $mail->IsSMTP(); // set mailer to use SMTP
      $mail->Host = SMTP_HOST; // specify main and backup server or localhost
      $mail->SMTPAuth = true; // turn on SMTP authentication
      $mail->Username = SMTP_USER; // SMTP username
      $mail->Password = SMTP_PASSWORD; // SMTP password It should be same as that of the SMTP user

      //$mail->PluginDir = "/home/phpaucti/public_html/website_development/coding/includes/";
      $mail->From = $mail->Username; //Default From email same as smtp user
      $mail->FromName = $mail_From;
      $emailArr = explode(',',$mail_To);
      foreach($emailArr AS $emailVal) {
      $mail->AddAddress($emailVal, ""); //Email address where you wish to receive/collect those emails.
      }

      /*$emailCCArr = explode(',',$mail_CC);
      foreach($emailCCArr AS $emailCCVal) {
      $mail->AddCC($emailCCVal, ""); //Email address where you wish to receive/collect those emails.
      }*/


      $mail->WordWrap = 100; // set word wrap to 50 characters
      $mail->IsHTML(true); // set email format to HTML
      $mail->Subject = $mail_subject;
      $message = $mail_Body;
      $mail->Body = $message;

      if(!$mail->Send())
      {
      /*echo "Message could not be sent. <p>";
      echo "Mailer Error: " . $mail->ErrorInfo;
      exit;*/
      }
      else
      {
      //echo 'ok';
      }

  }

  function generateTransactionId($length = 17){
    $chars =  'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.'0123456789';
    $str = '';
    $max = strlen($chars) - 1;
    for ($i=0; $i < $length; $i++)
     $str .= $chars[rand(0, $max)];

    return $str;
  }

}

Anon7 - 2022
AnonSec Team