<?php
function diaVar($type)
{
  $data['varShape'] = array (
      array ( 'id' => 'idshaperound', 'name' => 'Round', 'value' => 'ROUND', 'img' => 'round.png' ),
      array ( 'id' => 'idshapeprincess', 'name' => 'Princess', 'value' => 'PRINCESS', 'img' => 'princess.png' ),
      array ( 'id' => 'idshapecushion', 'name' => 'Cushion', 'value' => 'CUSHION', 'img' => 'cushion.png' ),
      array ( 'id' => 'idshaperadiant', 'name' => 'Radiant', 'value' => 'RADIANT', 'img' => 'radiant.png' ),
      array ( 'id' => 'idshapeasscher', 'name' => 'Asscher', 'value' => 'ASSCHER', 'img' => 'asscher.png' ),
      array ( 'id' => 'idshapeemerald', 'name' => 'Emerald', 'value' => 'EMERALD', 'img' => 'emerald.png' ),
      array ( 'id' => 'idshapeoval', 'name' => 'Oval', 'value' => 'OVAL', 'img' => 'oval.png' ),
      array ( 'id' => 'idshapepear', 'name' => 'Pear', 'value' => 'PEAR', 'img' => 'pear.png' ),
      array ( 'id' => 'idshapemarquise', 'name' => 'Marquise', 'value' => 'MARQUISE', 'img' => 'marquise.png' ),
      array ( 'id' => 'idshapeheart', 'name' => 'Heart', 'value' => 'HEART', 'img' => 'heart.png' ),
      array ( 'id' => 'idshapetrillion', 'name' => 'Trillion', 'value' => 'TRILLIANT', 'img' => 'trillion.png' ),
      array ( 'id' => 'idshapeother', 'name' => 'Other', 'value' => 'Other', 'img' => 'other.png' )
  );
  $data['varColor'] = array (
      array ( 'id' => 'col_d', 'name' => 'D', 'value' => 'D' ),
      array ( 'id' => 'col_e', 'name' => 'E', 'value' => 'E' ),
      array ( 'id' => 'col_f', 'name' => 'F', 'value' => 'F' ),
      array ( 'id' => 'col_g', 'name' => 'G', 'value' => 'G' ),
      array ( 'id' => 'col_h', 'name' => 'H', 'value' => 'H' ),
      array ( 'id' => 'col_i', 'name' => 'I', 'value' => 'I' ),
      array ( 'id' => 'col_j', 'name' => 'J', 'value' => 'J' ),
      array ( 'id' => 'col_k', 'name' => 'K', 'value' => 'K' ),
      array ( 'id' => 'col_l', 'name' => 'L', 'value' => 'L' ),
      array ( 'id' => 'col_m', 'name' => 'M', 'value' => 'M' )
  );
  $data['varClarity'] = array (
      array ( 'id' => 'FL', 'name' => 'FL', 'value' => 'FL' ),
      array ( 'id' => 'IF', 'name' => 'IF', 'value' => 'IF' ),
      array ( 'id' => 'VVS1', 'name' => 'VVS1', 'value' => 'VVS1' ),
      array ( 'id' => 'VVS2', 'name' => 'VVS2', 'value' => 'VVS2' ),
      array ( 'id' => 'VS1', 'name' => 'VS1', 'value' => 'VS1' ),
      array ( 'id' => 'VS2', 'name' => 'VS2', 'value' => 'VS2' ),
      array ( 'id' => 'SI1', 'name' => 'SI1', 'value' => 'SI1' ),
      array ( 'id' => 'SI2', 'name' => 'SI2', 'value' => 'SI2' ),
      array ( 'id' => 'SI3', 'name' => 'SI3', 'value' => 'SI3' ),
      array ( 'id' => 'I1', 'name' => 'I1', 'value' => 'I1' ),
      array ( 'id' => 'I2', 'name' => 'I2', 'value' => 'I2' ),
      array ( 'id' => 'I3', 'name' => 'I3', 'value' => 'I3' ),
  );
  $data['varCut'] = array (
      // array ( 'id' => 'id_cut', 'name' => 'Ideal', 'value' => 'Ideal' ),
      array ( 'id' => 'ex_cut', 'name' => 'Excellent', 'value' => 'EX' ),
      array ( 'id' => 'vg_cut', 'name' => 'Very Good', 'value' => 'VG' ),
      array ( 'id' => 'gd_cut', 'name' => 'Good', 'value' => 'G' ),
      array ( 'id' => 'fr_cut', 'name' => 'Fair', 'value' => '' )
  );
  $data['varPolish'] = array (
      array ( 'id' => 'ex_polish', 'name' => 'Excellent', 'value' => 'EX' ),
      array ( 'id' => 'vg_polish', 'name' => 'Very Good', 'value' => 'VG' ),
      array ( 'id' => 'gd_polish', 'name' => 'Good', 'value' => 'G' ),
      array ( 'id' => 'fr_polish', 'name' => 'Fair', 'value' => '' )
  );
  $data['varSymmetry'] = array (
      array ( 'id' => 'ex_symmetry', 'name' => 'Excellent', 'value' => 'EX' ),
      array ( 'id' => 'vg_symmetry', 'name' => 'Very Good', 'value' => 'VG' ),
      array ( 'id' => 'gd_symmetry', 'name' => 'Good', 'value' => 'G' ),
      array ( 'id' => 'fr_symmetry', 'name' => 'Fair', 'value' => '' )
  );
  $data['varFluor'] = array (
      array ( 'id' => 'non_fluor', 'name' => 'None', 'value' => 'None' ),
      array ( 'id' => 'fnt_fluor', 'name' => 'Faint', 'value' => 'Faint' ),
      array ( 'id' => 'med_fluor', 'name' => 'Medium', 'value' => 'Medium' ),
      array ( 'id' => 'stg_fluor', 'name' => 'Strong', 'value' => 'Strong' ),
      array ( 'id' => 'vst_fluor', 'name' => 'Very Strong', 'value' => 'Very Strong' )
  );
  $data['varLab'] = array (
      array ( 'id' => 'lab-GIA', 'name' => 'GIA', 'value' => 'GIA' ),
      array ( 'id' => 'lab-AGS', 'name' => 'AGS', 'value' => 'AGS' ),
      array ( 'id' => 'lab-GSI', 'name' => 'GSI', 'value' => 'GSI' ),
      array ( 'id' => 'lab-IIDGR', 'name' => 'IIDGR', 'value' => 'IIDGR' ),
      array ( 'id' => 'lab-EGLUSA', 'name' => 'EGLUSA', 'value' => 'EGLUSA' ),
      array ( 'id' => 'lab-Other', 'name' => 'Non-Certified', 'value' => 'OTHER' )
  );

  $data['varHA'] = array (
      array ( 'id' => 'ha-EX', 'name' => 'EX', 'value' => 'EX H&A' ),
      array ( 'id' => 'ha-VG', 'name' => 'VG', 'value' => 'VG H&A' ),
      array ( 'id' => 'ha-GD', 'name' => 'GD', 'value' => 'GD H&A' )
  );
  $data['varBrand'] = array (
      array ( 'id' => 'brand-CANADAMARK', 'name' => 'CANADAMARK', 'value' => 'CANADA' ),
      array ( 'id' => 'brand-VG', 'name' => 'VG H&A', 'value' => 'VG H&A' ),
      array ( 'id' => 'brand-EX', 'name' => 'EX H&A', 'value' => 'EX H&A' ),
      array ( 'id' => 'brand-CAN', 'name' => 'CAN H&A', 'value' => 'CAN H&A' )
  );
  $data['varCulet'] = array (
      array ( 'id' => 'culet-NON', 'name' => 'NON', 'value' => 'N' ),
      array ( 'id' => 'culet-VSM', 'name' => 'VSM', 'value' => 'VSM' ),
      array ( 'id' => 'culet-SML', 'name' => 'SML', 'value' => 'SML' ),
      array ( 'id' => 'culet-MED', 'name' => 'MED', 'value' => 'MED' ),
      array ( 'id' => 'culet-LARGE', 'name' => 'LARGE', 'value' => 'LARGE' )
  );
  
  $data['varKeyToSym'] = array (
      array ( 'id' => 'keytosym-1', 'name' => 'Bearding', 'value' => 'Bearding' ),
      array ( 'id' => 'keytosym-2', 'name' => 'Brown patch of color', 'value' => 'Brown patch of color' ),
      array ( 'id' => 'keytosym-3', 'name' => 'Bruise', 'value' => 'Bruise' ),
      array ( 'id' => 'keytosym-4', 'name' => 'Cavity', 'value' => 'Cavity' ),
      array ( 'id' => 'keytosym-5', 'name' => 'Chip', 'value' => 'Chip' ),
      array ( 'id' => 'keytosym-6', 'name' => 'Cleavage', 'value' => 'Cleavage' ),
      array ( 'id' => 'keytosym-7', 'name' => 'Cloud', 'value' => 'Cloud' ),
      array ( 'id' => 'keytosym-8', 'name' => 'Crystal', 'value' => 'Crystal' ),
      array ( 'id' => 'keytosym-9', 'name' => 'Crystal Surface', 'value' => 'Crystal Surface' ),
      array ( 'id' => 'keytosym-10', 'name' => 'Etch Channel', 'value' => 'Etch Channel' ),
      array ( 'id' => 'keytosym-11', 'name' => 'Extra Facet', 'value' => 'Extra Facet' ),
      array ( 'id' => 'keytosym-12', 'name' => 'Feather', 'value' => 'Feather' ),
      array ( 'id' => 'keytosym-13', 'name' => 'Flux Remnant', 'value' => 'Flux Remnant' ),
      array ( 'id' => 'keytosym-14', 'name' => 'Indented Natural', 'value' => 'Indented Natural' ),
      array ( 'id' => 'keytosym-15', 'name' => 'Internal Graining', 'value' => 'Internal Graining' ),
      array ( 'id' => 'keytosym-16', 'name' => 'Internal Inscription', 'value' => 'Internal Inscription' ),
      array ( 'id' => 'keytosym-17', 'name' => 'Internal Laser Drilling', 'value' => 'Internal Laser Drilling' ),
      array ( 'id' => 'keytosym-18', 'name' => 'Knot', 'value' => 'Knot' ),
      array ( 'id' => 'keytosym-19', 'name' => 'Laser Drill Hole', 'value' => 'Laser Drill Hole' ),
      array ( 'id' => 'keytosym-20', 'name' => 'Manufacturing Remnant', 'value' => 'Manufacturing Remnant' ),
      array ( 'id' => 'keytosym-21', 'name' => 'Minor Details of Polish', 'value' => 'Minor Details of Polish' ),
      array ( 'id' => 'keytosym-22', 'name' => 'Natural', 'value' => 'Natural' ),
      array ( 'id' => 'keytosym-23', 'name' => 'Needle', 'value' => 'Needle' ),
      array ( 'id' => 'keytosym-24', 'name' => 'No Inclusion', 'value' => 'No Inclusion' ),
      array ( 'id' => 'keytosym-25', 'name' => 'Pinpoint', 'value' => 'Pinpoint' ),
      array ( 'id' => 'keytosym-26', 'name' => 'Reflecting Surface Graining', 'value' => 'Reflecting Surface Graining' ),
      array ( 'id' => 'keytosym-27', 'name' => 'Surface Graining', 'value' => 'Surface Graining' ),
      array ( 'id' => 'keytosym-28', 'name' => 'Twinning Wisp', 'value' => 'Twinning Wisp' )
  );
  $data['varMatchPairColumn'] = array (
      array ( 'name' => 'stock_id', 'column' => 'stock_id' ),
      array ( 'name' => 'weight', 'column' => 'weight' ),
      array ( 'name' => 'depth', 'column' => 'depth' ),
      array ( 'name' => 'diamond_id', 'column' => 'diamond_id' ),
      array ( 'name' => 'shape', 'column' => 'shape_full' ),
      array ( 'name' => 'color', 'column' => 'color' ),
      array ( 'name' => 'grade', 'column' => 'grade' ),
      array ( 'name' => 'cut', 'column' => 'cut_full' ),
      array ( 'name' => 'polish', 'column' => 'polish_full' ),
      array ( 'name' => 'symmetry', 'column' => 'symmetry_full' ),
      array ( 'name' => 'fluorescence_int', 'column' => 'fluor_full' ),
      array ( 'name' => 'table_d', 'column' => 'table_d' ),
      array ( 'name' => 'cash_price_discount', 'column' => 'cash_price_discount' ),
      array ( 'name' => 'cash_price', 'column' => 'cash_price' ),
      array ( 'name' => 'cash_total_price', 'column' => 'cash_total_price' ),
      array ( 'name' => 'rapnet_discount', 'column' => 'rapnet_discount' ),
      array ( 'name' => 'cost_carat', 'column' => 'cost_carat' ),
      array ( 'name' => 'total_weight', 'column' => 'weight' ),
      array ( 'name' => 'total_price', 'column' => 'total_price' ),
      array ( 'name' => 'lab', 'column' => 'lab' ),
      array ( 'name' => 'report_no', 'column' => 'report_no' ),
      array ( 'name' => 'measurements', 'column' => 'measurements' ),
      array ( 'name' => 'diamond_video', 'column' => 'diamond_video' ),
      array ( 'name' => 'member_comment', 'column' => 'member_comment' )
  );

  $data['varDiaColumn'] = array (
      array ( 'name' => 'Stock#', 'column' => 'stock_id' ),
      array ( 'name' => 'Shape', 'column' => 'shape_full' ),
      array ( 'name' => 'Cts', 'column' => 'weight' ),
      array ( 'name' => 'Color', 'column' => 'color' ),
      array ( 'name' => 'Clarity', 'column' => 'grade' ),
      array ( 'name' => 'Cut', 'column' => 'cut_full' ),
      array ( 'name' => 'Polish', 'column' => 'polish_full' ),
      array ( 'name' => 'Symmetry', 'column' => 'symmetry_full' ),
      array ( 'name' => 'Fluor.', 'column' => 'fluor_full' ),
      array ( 'name' => 'Depth%', 'column' => 'depth' ),
      array ( 'name' => 'Table%', 'column' => 'table_d' ),
      array ( 'name' => 'Cash Disc.', 'column' => 'cash_price_discount' ),
      array ( 'name' => 'COD Price/Ct', 'column' => 'cash_price' ),
      array ( 'name' => 'Total Cash $', 'column' => 'cash_total_price' ),
      array ( 'name' => 'Memo Disc.', 'column' => 'rapnet_discount' ),
      array ( 'name' => 'Memo Price/Ct', 'column' => 'cost_carat' ),
      array ( 'name' => 'Memo Total $', 'column' => 'total_price' ),
      array ( 'name' => 'Lab', 'column' => 'lab' ),
      array ( 'name' => 'Measurements', 'column' => 'measurements' ),
      array ( 'name' => 'Comments', 'column' => 'member_comment' )
  );  

  $data['varTableHeader'] = array (
      array ( 'name' => 'Stock#', 'column' => 'stock_id' ),
      array ( 'name' => 'Shape', 'column' => 'shape_full' ),
      array ( 'name' => 'Cts', 'column' => 'weight' ),
      array ( 'name' => 'Color', 'column' => 'color' ),
      array ( 'name' => 'Clarity', 'column' => 'grade' ),
      array ( 'name' => 'Cut', 'column' => 'cut_full' ),
      array ( 'name' => 'Polish', 'column' => 'polish_full' ),
      array ( 'name' => 'Symmetry', 'column' => 'symmetry_full' ),
      array ( 'name' => 'Fluor.', 'column' => 'fluor_full' ),
      array ( 'name' => 'Depth%', 'column' => 'depth' ),
      array ( 'name' => 'Table%', 'column' => 'table_d' ),
      // array ( 'name' => 'COD Disc.', 'column' => 'cash_price_discount' ),
      array ( 'name' => 'Price/Ct', 'column' => 'cash_price' ),
      // array ( 'name' => 'Total COD $', 'column' => 'cash_total_price' ),
      // array ( 'name' => 'Memo Disc.', 'column' => 'rapnet_discount' ),
      // array ( 'name' => 'Memo Price/Ct', 'column' => 'cost_carat' ),
      // array ( 'name' => 'Memo Total $', 'column' => 'total_price' ),
      array ( 'name' => 'Lab', 'column' => 'lab' ),
      array ( 'name' => 'Measurements', 'column' => 'measurements' ),
      // array ( 'name' => 'Comments', 'column' => 'member_comment' )
  );  

  $var = (!empty($data[$type])) ? $data[$type] : array();
  return  $var;
}

function print_pre($data)
{ 
   echo "<pre>";print_r($data);echo "</pre>";       
}

function print_ex($data)
{ 
   echo "<pre>";print_r($data);echo "</pre>";exit();       
}

// function strRepIn($column, $input) {
//     $value = $input;
//     $str = '';
//     if (!empty($value)) {
//       $replacedStr = implode("','",$value);             
//       $str = " AND $column IN ('$replacedStr')";      
//     }
//     return $str;
//   }

// function strRepBetween($column, $input, $isInt = 0) {
//     $str = '';
//     $from = $input.'_from';
//     $to = $input.'_to';
//     if (trim($from) != '' && trim($to)) {
//       if ($isInt) {
//         $str = " AND $column BETWEEN ($from) AND ($to)";
//       } else {
//         $str = " AND $column BETWEEN ('$from') AND ('$to')";
//       }     
//     }
//     return $str;
//   }

function base_admin()
{ 
   return base_url()."admin/";       
}

function base_front(){
    return base_url()."front/";
}
function base_gb(){
    return "../../easy_diam/";
}
function base_gb_ftp(){
    return "../easy_diam/";
}

// function csrf_field()
// { 
//    $ci =& get_instance();
//    $csrf = array(
//          'name' => $ci->security->get_csrf_token_name(),
//          'hash' => $ci->security->get_csrf_hash()
//          );      
//    return '<input type="hidden" name="'.$csrf['name'].'" value="'.$csrf['hash'].'" />';       
// }

function hashcode($data)
{
   return hash('sha512',$data);
}
function from_email()
{
   // $ci =& get_instance();
   // $ci->db->select('*');
   // $ci->db->from('TBL_USER');      
   // $query=$ci->db->get();
   // return $query->result();
   return 'info@gemsbridge.com';
}
function vendor_id()
{
   $ci =& get_instance();
   $vd_user_id=$ci->session->userdata('vd_user_id');
   $vd_parent_id = $ci->session->userdata('vd_parent_id');
   if($vd_parent_id==0)
   {
     $vendor_id=$vd_user_id;
   }
   else
   {
     $vendor_id=$vd_parent_id;
   }
   return $vendor_id;
}
function shape_img($shape)
{
   if($shape=='ASSCHER')
   {
      return 'assets/images/diamond/ascher.jpg';
   }
   else if($shape=='CUSHION')
   {
      return 'assets/images/diamond/cushion.jpg';
   }
   else if($shape=='EMERALD')
   {
      return 'assets/images/diamond/emerald.jpg';
   }
   else if($shape=='HEART')
   {
      return 'assets/images/diamond/heart.jpg';
   }
   else if($shape=='MARQUISE')
   {
      return 'assets/images/diamond/marquise.jpg';
   }
   else if($shape=='OVAL')
   {
      return 'assets/images/diamond/oval.jpg';
   }
   else if($shape=='PEAR')
   {
      return 'assets/images/diamond/pear.jpg';
   }
   else if($shape=='PRINCESS')
   {
      return 'assets/images/diamond/princess.jpg';
   }
   else if($shape=='RADIANT')
   {
      return 'assets/images/diamond/radiant.jpg';
   }
   else if($shape=='Round' || $shape=='RBC' || $shape=='ROUND')
   {
      return 'assets/images/diamond/round.jpg';
   }     
   
}

function ci_enc($str){
 $new_str = strtr(base64_encode(addslashes(@gzcompress(serialize($str), 9))), '+/=', '-_.');
 return $new_str;	
} 

function ci_dec($str){
 $new_str = unserialize(@gzuncompress(stripslashes(base64_decode(strtr($str, '-_.', '+/=')))));
 return $new_str;
}

function send_mail($recipients, $subject, $message, $from='')
{

    //echo 'ok this called';exit;
 $ci =& get_instance();
 $from_email = ($from=='')? $from : SITE_EMAIL;
 $ci->load->library('email');
 $ci->email->clear(TRUE);
 $ci->email->from($from_email, SITE_NAME); 
 $ci->email->to($recipients);

 $ci->email->set_mailtype("html");
 $ci->email->subject($subject);
 $ci->email->message($message);  
 $ci->email->send();
 return TRUE;
}

function percent($num,$per)
{
   return number_format((($num*$per)/100),2);
}

function message()
{ 
   $ci =& get_instance();
  
   if($ci->session->flashdata('alert_message')){ 
      return '<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 col-lg-offset-2 col-md-offset-2 ">
              <div class="alert alert-success alert-dismissable fade in radius-flat">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                <strong> '.$ci->session->flashdata('alert_message').' </strong>
              </div>
            </div>';
   } 
   if($ci->session->flashdata('error_message')){ 
      return '<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 col-lg-offset-2 col-md-offset-2 ">
              <div class="alert alert-danger alert-dismissable fade in radius-flat">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                <strong>'.$ci->session->flashdata('error_message').' </strong>
              </div>
            </div>';
   }       
}
// function checkLink($url)
// {    
//    $headers = get_headers($url);
//    return substr($headers[0], 9, 3);      
// }

function hasValue($value='') {
   $value = trim($value);
   return (!empty($value) && $value != 'NA' && $value != 0) ? 1 : 0;
}

function checkLink($url)
{    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    curl_exec($ch);
    return curl_getinfo($ch, CURLINFO_HTTP_CODE);      
} 

function strFlat($value)
{
   return strtolower(str_replace(" ", "_", $value)); 
}

function userIp()
{
 if(!empty($_SERVER['HTTP_CLIENT_IP'])){
     $ip = $_SERVER['HTTP_CLIENT_IP'];
 }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
     $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
 }else{
     $ip = $_SERVER['REMOTE_ADDR'];
 }
 return  $ip;
}