<?php
/**
 * Quote Generator
 * ====================
 * Quote Generator
 * Motto: "Our software will change your business life for the better."
 * The Quote Generator system allows your customer to conveniently receive instant quotes and place orders online.
 * @author      Original author: Quote Generator Plus <quotegeneratorplus@gmail.com>
 * @license     Code and contributions have Copyright (c) 2017
 *              More details: LICENSE.txt
 * @link        Homepage:     http://Wordpress.QuoteGeneratorPlus.com
 * @version     3.0
 */

//------------------------------ Default settings -------------------------------------------
global $wpdb;
if(!isset($wpdb)){
    require_once(ABSPATH .'wp-config.php');
    require_once(ABSPATH .'wp-includes/wp-db.php');
}
include (ABSPATH . "wp-content/plugins/quotegenerator/qg-settings.php");
if(!function_exists('set_html_content_type')) {
    function set_html_content_type() {
	return 'text/html';
    }
}

//------------------------- Form settings -----------------------------
	
for($xv=1; $xv<=$arrsize; $xv++){
    $oname = 'setting_qg'.$xv;
    $ovalue = $arrvalues[$xv];
    
    if ( get_option($oname) == false ) {
	 add_option( $oname, $ovalue, '', 'yes' );
    }else{
	if($xv==2 || $xv==4 || $xv==6 || $xv==7|| $xv==9|| $xv==33|| $xv==34){
	    $nval[$xv] = "#".get_option( $oname );
	}else{
	    $nval[$xv] = get_option( $oname );
	}
	
	if(strtolower($nval[$xv])=='hide'){
           $nval[$xv] = 'display:none;';
	   if($xv==10 || $xv==13 || $xv==14){$colspan--;}

         }else if(strtolower($nval[$xv])=='show'){
             $nval[$xv] = '';
         }
		            
    }
    
}
if(!isset($nval[20])){$nval[20]=0;}

for($xv=1; $xv<=3; $xv++){
    $option_name = 'setting_qgx'.$xv;
	     if ( get_option($option_name) == false ) {
                  add_option( $option_name, 0, '', 'yes' );
	     }else{
		$new_val[$xv] = get_option( $option_name );
	     }
}
  $show_tax2 = 'display:none;';
  $show_tax3 = 'display:none;';
  if(isset($nval[21])){
    if($nval[21]!='' && intval($nval[22])>0){
       $show_tax2 = '';
    }else{
       $show_tax2 = 'display:none;';
       $nval[22]=0;
    }
  }else{
    $nval[22]=0;
  }
  
  if(isset($nval[23])){
    if($nval[23]!='' && intval($nval[24])>0){
       $show_tax3 = '';
    }else{
       $show_tax3 = 'display:none;';
       $nval[24]=0;
    }
  }else{
    $nval[24]=0;
  }
  
   

   
// ---------------------------------- Submit Email --------------------------------------------

if(isset($_POST['oqgb2'])){
  if($_POST['oqgb2']!=""){
    
      $ip = $_SERVER['REMOTE_ADDR'];
      $todayDate = date("Y-m-d H:i:s");
      
      $textouts = '<table style="'.$email_table.' font-size: '. $nval[5].';">';
      $textouts .= '<tr><td style="padding:2px;">Date: '.$todayDate.'</td></tr>';
      $dbfild = '';
      $dbtextouts = '';
      $textouts3='';
      $dbtotl = '';
      
      for($xc=1; $xc<13; $xc++){
	  $nods = "oqgb".$xc;
	  $nodd = $_POST[$nods];
	  $dbfild .= "'".$nodd."',";
	  if($nodd !=""){
	     $textouts .= '<tr><td style="padding:0px 0px 0px 12px;text-align: left;">'.$nodd.'</td></tr>';
	  }
      }
    
      $textouts .= '<tr><td style="padding:0px 0px 0px 12px;text-align: left;">IP: '.$ip.'</td></tr></table>';
      $textouts .= '<table style="text-align: center; width:'. $nval[1].';background: '. $nval[2].'; border:'.$nval[3].'; font-size: '. $nval[8].'; color: '. $nval[7].';">';
      
      $textouts3.= $textouts;
      if(isset($nval[21])){$hd21=$nval[21];}else{$hd21='';}
      if(isset($nval[23])){$hd23=$nval[23];}else{$hd23='';}
      if(isset($nval[25])){$hd25=$nval[25];}else{$hd25='';}
      
      $textouts .= '<tr><th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $hd25.'</th> <th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[26].'</th> <th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[27].'('. $nval[18].')</th> <th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[28].'</th><th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[29].'('. $nval[18].')</th><th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[30].'('. $nval[18].')</th></tr>';
       
       $dbtextouts .= '<tr><th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $hd25.'</th> <th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[26].'</th> <th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[27].'('. $nval[18].')</th> <th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[28].'</th><th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[29].'('. $nval[18].')</th><th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[30].'('. $nval[18].')</th></tr>';
       
       $textouts3.= '<tr><th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[26].'</th><th style="color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].';text-align: center;">'. $nval[28].'</th></tr>';
       
       $vals = array(0,0);
       $valnames = array($nval[35],$nval[36],$nval[37],$nval[38],$nval[19],$hd21,$hd23,$nval[39]);
       $xnumr = 1;
       
       for($x=0; $x<$_POST['qgb11']; $x++){
	
           if ($x%2==0){ $bgr = "#ffffff";}else{ $bgr = "#f7f7f7";} 
           
	   if(floatval($_POST['amnt'.$x])>0 || floatval($_POST['qty'.$x])>0){
	    
	      if(floatval($_POST['price'.$x])!=0){ $data1 = $_POST['price'.$x];}else{$data1 ='';}
	      $outname = $_POST['name'.$x];
	      
	      if(floatval($_POST['qty'.$x])>0.0001){   $data2 = $_POST['qty'.$x];}else{$data2 ='';}

	      if(isset($_POST['qtyssa'.$x]) && isset($_POST['qtyssb'.$x])){ // formula #4
		 $nname = explode("!!!",$_POST['name'.$x]);
		 $outname = $nname[0].'<br>&nbsp; &nbsp;'.$nname[1].': '.$_POST['qtyssa'.$x].'<br>&nbsp; &nbsp;'.$nname[2].': '.$_POST['qtyssb'.$x];
	      }
	      if(isset($_POST['qtyssa'.$x]) && isset($_POST['qtyssb'.$x]) && isset($_POST['qtyssc'.$x])){  // formula #5
		 $nname = explode("!!!",$_POST['name'.$x]);
		 $outname = $nname[0].'<br>&nbsp; &nbsp;'.$nname[1].': '.$_POST['qtyssa'.$x].'<br>&nbsp; &nbsp;'.$nname[2].': '.$_POST['qtyssb'.$x].'<br>&nbsp; &nbsp;'.$nname[3].': '.$_POST['qtyssc'.$x];
	      }
	      
	      if(isset($_POST['f40f'.$x])){ // Formula #6
		if(intval($_POST['f40f'.$x]) >0 ){
		    $nname = explode("!!!",$_POST['name'.$x]);
		    $outname = $nname[0];
		    for($ffval=0;$ffval<intval($_POST['f40f'.$x]);$ffval++){
			$outname .= '<br>&nbsp; &nbsp;'.$nname[($ffval+1)].': '.$_POST['qtyxx'.$x.'_'.$ffval];
		    }
		}
		
	      }else if(isset($_POST['checkqty'.$x])){//check box
		    $outname .= '&nbsp;'.$_POST['price'.$x].' (selected)';
	      }else if(floatval($_POST['qty'.$x])<0.00000001){
		    $outname = '';
	      }


	      if(isset($_POST['qtyn'.$x]) && $data2 ==''){
		 if(floatval($_POST['qtyn'.$x])>0.0001){ $data2 = $_POST['qtyn'.$x];$outname = $_POST['name'.$x];}else{$data2 ='';}
	      }
	      
	      
	      if(floatval($_POST['discnt'.$x])>0){$data3 = $_POST['discnt'.$x];}else{$data3 ='';}
	      if(floatval($_POST['amnt'.$x])>0){  $data4 = $_POST['amnt'.$x];}else{$data4 ='';}
	    
	      $textouts .= '<tr style="background: '.$bgr.'color:'. $nval[4].'; font-size: '. $nval[5].';"><td> </td><td>'.$outname.'</td><td>'.$data1.'</td><td>'.$data2.'</td><td>'.$data3.'</td><td>'.$data4.'</td></tr>';
	      $dbtextouts .= '<tr style="background: '.$bgr.'color:'. $nval[4].'; font-size: '. $nval[5].';"><td> </td><td>'.$outname.'</td><td>'.$data1.'</td><td>'.$data2.'</td><td>'.$data3.'</td><td>'.$data4.'</td></tr>';
	      $textouts3.='<tr><td style="background: '.$bgr.'color:'. $nval[4].'; font-size: '. $nval[5].';">'.$outname.'</td><td style="background: '.$bgr.'color:'. $nval[4].'; font-size: '. $nval[5].';">'.$data2.'</td></tr>';
	      
	      $xnumr++;
           }
           
       }
       
       
       for($x=0; $x<count($valnames); $x++){
           if ($x%2==0){ $bgr = "#f5f5f5";}else{ $bgr = "#f0f0f0";}
           if ($x==7)  { $bgr = $nval[6].';color:'. $nval[4].';';}
	   $nod = 'qgb'.$x;
	   $vals[$x] = $_POST[$nod];
	   if($x!=0){$dbtotl .= "'".$_POST[$nod]."',";}
	   
           if(floatval($vals[$x])!=0){
               $textouts .= '<tr style="background: '.$bgr.'"><td colspan="5" style="text-align: right;">'.$valnames[$x].'</td><td>'.$vals[$x].'</td></tr>';
	       $textouts3.='<tr style="background: '.$bgr.'"><td style="text-align: right;">'.$valnames[$x].'</td><td>'.$vals[$x].'</td></tr>';
           }
       }
       
       $textouts .= '</table>';
       $textouts3.= '</table>';    
       
       
       //--------------- Submit Email -------------------------------------
       
       add_filter( 'wp_mail_content_type', 'set_html_content_type' );
       
       $body ='<html><head><title>Online Order</title></head><body>'.$textouts.'</body></html>';
       $subject = 'Online Order';
       $to = get_option("setting_qgname14");          // get_option( 'admin_email'); // email to admin
       
       $headers = 'From: '.get_option( 'blogname').' <'.$to.'>' . "\r\n";
       $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
       $headers .= 'Reply-To: <'.$to.'>\r\n';
       
       if($to!=""){
	   wp_mail( $to, $subject, $body, $headers );
	}
       //wp_mail( $to, $subject, $body);
        
	
       //-------------------- submit to customer -------------------------
        
	$to = $_POST["oqgb2"];

	if($to!="" && get_option("setting_qgform14") == 'Automatically send an order to the customer.'){
	   sleep(1);
	   wp_mail( $to, $subject, $body, $headers );
	}
	
       remove_filter( 'wp_mail_content_type', 'set_html_content_type' );

       
       
       //------------------- Add 1 to order number -------------------------
       
       if ( get_option("setting_qgname7") !== false ) {
	     $new_value = intval(get_option("setting_qgname7"))+1;
             update_option( "setting_qgname7", $new_value );
        }  else  {
            add_option( "setting_qgname7", "1", '', 'yes' );
        }

 	  
     //--------------------- Show final Order ---------------------------
       
       $textouts2 = '<div style="width:'. $nval[1].';'.$final_message_css.'">'.$nval[40].'</div>';
       echo $textouts2.$deposit_out.$textouts3;   

        
       $doshow=1; // The End

   } //--------------- End of Submited Order ------------------------------
} 

    
    
    
    
//-------------------------------- Read items data  ----------------------------------------------
   
   
   
       
     $tbname = "qg_itemx";
     $sql2 = "SELECT * FROM ".$wpdb->prefix.$tbname." WHERE visible='yes' ORDER BY idn, id";
     $i = 0;
     $thstyle = 'border:none; color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].'; text-align: center;vertical-align: text-top;';
     $moderation2 = $wpdb->get_results($sql2, ARRAY_A);
     $last_row = '';$samesel='';
      
	foreach ( (array) $moderation2 as $row ) {
	    
	  if($row['field_22']==1)  { // select box
	    
	     $new_row = $row['field_24'];
	     
	     if($new_row == $last_row){ // same select box
		$nsbx++;
	        $samesel.='<div id="sells_'.$i.'_'.$nsbx.'" class="css52"><div class="css53"><input name="namesel_'.$i.'_'.$nsbx.'" id="namesel_'.$i.'_'.$nsbx.'" type="hidden" value="'.$row['field_1'].'" />';
		
		if($row['field_6']!=""){
		    $showimad = '<img src="'.$row['field_6'].'" class="css54" alt="Image">';
		}else{
	    	    $showimad = '';
		}
		
		$samesel.='<div class="tbl_select" onmouseover="this.style.background=\''.$selectbox_mouseover.'\';"  onmouseout="this.style.background=\'transparent\';" onclick="setselbox('.$i.','.$nsbx.');">';
		
		$samesel.='<div class="css55">'.$showimad.' &nbsp; &nbsp; &nbsp; &nbsp; <b>'.$row['field_1'].'</b><br>';
		
		if($row['field_2']!=''){  $samesel.='&nbsp; &nbsp;'.$row['field_2'];}
		$samesel.='</div></div>'; 
		$samesel.='<input name="price_'.$i.'_'.$nsbx.'" id="price_'.$i.'_'.$nsbx.'" type="hidden" value="'.$row['field_3'].'" />';
		
		$samesel.='</div></div>';
		
	     }else{
		
		if($samesel != ''){
		   $samesel.='</div>'.$textouts.'</td></tr>';
		   $textout.= $samesel;$samesel='';
		   $i++;
	        }
		
		
	        $last_row = $row['field_24']; // new select box
		$nsbx=1;
		$samesel='';
		$samesel.='<tr><td colspan="'. $colspan.'" class="wightline">&nbsp;</td></tr>';
		
		$samesel.='<tr class="css56"><td class="thstyle"></td>';
		$samesel.='<td colspan="'.($colspan-1).'" class="css40" onclick="showselbox('.$i.','.$nsbx.');" onmouseover="this.style.background=\''.$selectbox_mouseover.'\';"  onmouseout="this.style.background=\''.$selectbox_background.'\';"><img src="'. sprintf("%s/quotegenerator/assets/img/arrowd.png", plugins_url()).'"  alt="Down" class="css57" > &nbsp; &nbsp;</td></tr>';
		
		$samesel.='<tr class="css58"><td class="thstyle">&nbsp; </td>';
		$samesel.='<td colspan="'. ($colspan-1).'" class="tdselect">';

		$samesel.='<input name="name'.$i.'" id="name'.$i.'" type="hidden" value="'.$row['field_1'].'" />';
		$samesel.='<input name="curshow'.$i.'" id="curshow'.$i.'" type="hidden" value="1" />';
		$samesel.='<input name="namesel_'.$i.'_'.$nsbx.'" id="namesel_'.$i.'_'.$nsbx.'" type="hidden" value="'.$row['field_1'].'"  />';
		$samesel.='<input name="price_'.$i.'_'.$nsbx.'" id="price_'.$i.'_'.$nsbx.'" type="hidden" value="'.$row['field_3'].'" />';
		
		$samesel.='<input name="price'.$i.'" id="price'.$i.'" type="hidden" value="'.$row['field_3'].'" />';
		$samesel.='<input name="qty'.$i.'" id="qty'.$i.'" type="hidden" value="0" />';
		$samesel.='<input name="taxb'.$i.'" id="taxb'.$i.'" type="hidden" value="'.$row['field_5'].'" />';
		$samesel.='<input name="discnt'.$i.'" id="discnt'.$i.'" type="hidden" value="" />';
		$samesel.='<input name="amnt'.$i.'" id="amnt'.$i.'" type="hidden" value="" />';
		$samesel.='<input name="checkqtys'.$i.'" id="checkqtys'.$i.'" type="hidden" value="'.$row['field_23'].'" />';

                $samesel.='<div class="tbl2"><div id="sells_'.$i.'_'.$nsbx.'" class="css59"><div class="css60">';


		 if($row['field_6']!=""){
		    $showimad = '<img src="'.$row['field_6'].'" class="css54" alt="Image">';
		 }else{
		    $showimad = '';
		 }
		    
		$show_names = $row['field_1'];
		

			
		$samesel.='<div class="tbl_select" onmouseover="this.style.background=\''.$selectbox_mouseover.'\';"  onmouseout="this.style.background=\'transparent\';" onclick="setselbox('.$i.','.$nsbx.');">';

		$samesel.='<div class="css55">'.$showimad.' &nbsp; &nbsp; &nbsp; &nbsp; <b>'.$show_names.'</b><br>';
		
		if($row['field_2']!=''){  $samesel.='&nbsp; &nbsp;'.$row['field_2'];}
		
		$samesel.='</div></div>';

		$samesel.='</div></div>';
		
		
		
	     }
	     
	     
	  
	  }else if($row['field_22']==3)  { // Header ----------------------------------------------
	    
	    if($samesel != ''){
		$samesel.='</div>'.$textouts.'</td></tr>';
		$textout.= $samesel;
	        $samesel='';
		$i++;
	    }
	    
	    $textout.='<tr><td colspan="'. $colspan.'" class="wightline"> </td></tr>';
	    $textout.='<tr class="css61"><td class="thstyle"></td><td colspan="'. ($colspan-1).'" class="css62">'.$row['field_1'];
	        
		$textout.='<input name="name'.$i.'" id="name'.$i.'" type="hidden" value="'.$row['field_1'].'" />';
	        $textout.='<input name="price'.$i.'" id="price'.$i.'" type="hidden" value="0" />';
		$textout.='<input name="qty'.$i.'" id="qty'.$i.'" type="hidden" value="0" />';
		$textout.='<input name="taxb'.$i.'" id="taxb'.$i.'" type="hidden" value="'.$row['field_5'].'" />';
		$textout.='<input name="discnt'.$i.'" id="discnt'.$i.'" type="hidden" value="" />';
		$textout.='<input name="amnt'.$i.'" id="amnt'.$i.'" type="hidden" value="" />';
		$textout.='<input name="checkqtys'.$i.'" id="checkqtys'.$i.'" type="hidden" value="1" />';
	      
	    $textout.='</td></tr>';
	    $i++;
	  
	  }else{ 
	    
	    // create end of select box -> show select box
	    if($samesel != ''){
		$samesel.='</div>'.$textouts.'</td></tr>';
		$textout.= $samesel;
	        $samesel='';
		$i++;
	    }
	    
	    
	    //------------------------------------------------------------------------------
	    
	    $textout.='<tr><td colspan="'. $colspan.'" class="wightline"> &nbsp; </td></tr>';   
	    
            $textout.='<tr class="css63"><td class="thstyle"> &nbsp; </td>';
	    $textout.='<td class="css64"><input name="name'.$i.'" type="hidden" value="'.$row['field_1'].'" />';
	    
	    if(intval($row['field_23'])!=4 && intval($row['field_23'])!=5 && intval($row['field_23'])!=6){
	         $textout.='<div class="css65">'.$row['field_1'].'</div>';
	    }else{
		 $sel_names = explode("!!!",$row['field_1']);
		 $textout.='<div class="css66">'.$sel_names[0].'</div>';
	    }


	    if($row['field_6']!=""){
		$simg = '<img src="'.$row['field_6'].'" class="css54" alt="Image">';
	    }else{
		$simg = '';
	    }

	    $textout.='<div id="descrpt'.$i.'" class="css67">'.$simg;
	    $textout.='<div class="css68">'.$row['field_2'].'</div></div>';
	    
	    $textout.='<div>';
	   
	   if( intval($row['field_4']) > 0 ){
	       $max_qty = intval($row['field_4']);
	   }else{
	       $max_qty = 10;
	   }
	   
	   $textout.='<input name="taxb'.$i.'" type="hidden" value="'.$row['field_5'].'" />';
	   if( floatval($row['field_5']) > 0 ){
	       $step = floatval($row['field_5']);
	   }else{
	       $step = 1;
	   }
	   
	   
	   
	   $box_type = intval($row['field_22']);
	   $textout.='<input name="checkqtys'.$i.'" id="checkqtys'.$i.'" type="hidden" value="'.$row['field_23'].'" />';
	   
           if($box_type == 0){ // check box --------------------------------------------
	    
               $textout.='<div class="roundedTwo"><input name="checkqty'.$i.'" id="checkqty'.$i.'" type="checkbox" onClick="calclat('.$i.');" onkeypress="handle(this,event)"><label class="check_box" for="checkqty'.$i.'"></label></div>';
               $textout.=' <input name="qty'.$i.'"  id="qty'.$i.'" type="hidden" value="0" onchange="calclat(this)" onkeypress="handle(this,event)"/>'; 
	   
	   }else if($box_type == 2){ // input box --------------------------------------
	    
	       if(intval($row['field_23'])==4 || intval($row['field_23'])==5 ){
		  
		  $nuantity = explode("!!!",$row['field_1']);
		  $quantity = explode("!!!",$row['field_4']);
		  
	          $textout.='<input name="qty'.$i.'" id="qty'.$i.'" type="hidden" value="">';
		  $textout.='<div class="css69">'.$nuantity[1].'</div>';
		 
		  $textout.='<div class="tbl5">';
		  $textout.='<div class="tdinboxq">';
	          $textout.='<input name="qtya'.$i.'" id="qtya'.$i.'" type="text" value="" class="inboxq" /></div>';
	          $textout.='<div class="tdrange">';
	          $textout.='<input name="qtyssa'.$i.'" id="qtyssa'.$i.'" type="range" min="0.0" max="'.$quantity[0].'" value="0" step="'.$step.'" onchange="calclat(this)" onkeypress="handle(this,event)" class="range_style" /></div>';
	          $textout.='</div>';
		  
		  $textout.='<div class="css70">'.$nuantity[2].'</div>';
		  
		  $textout.='<div class="tbl5">';
		  $textout.='<div class="tdinboxq">';
	          $textout.='<input name="qtyb'.$i.'" id="qtyb'.$i.'" type="text" value="" class="inboxq" /></div>';
	          $textout.='<div class="tdrange">';
	          $textout.='<input name="qtyssb'.$i.'" id="qtyssb'.$i.'" type="range" min="0.0" max="'.$quantity[1].'" value="0" step="'.$step.'" onchange="calclat(this)" onkeypress="handle(this,event)" class="range_style" /></div>';
	          $textout.='</div>';
		  
		   if(intval($row['field_23'])==5 ){
		      $textout.='<div class="css70">'.$nuantity[3].'</div>';
		      
		      $textout.='<div class="tbl5">';
		      $textout.='<div class="tdinboxq">';
	              $textout.='<input name="qtyc'.$i.'" id="qtyc'.$i.'" type="text" value="" class="inboxq" /></div>';
	              $textout.='<div class="tdrange">';
	              $textout.='<input name="qtyssc'.$i.'" id="qtyssc'.$i.'" type="range" min="0.0" max="'.$quantity[2].'" value="0" step="'.$step.'" onchange="calclat(this)" onkeypress="handle(this,event)" class="range_style" /></div>';
	              $textout.='</div>';
		   }
		   
		   
	       }else if(intval($row['field_23'])==6){
		
		 $quantity = explode("!!!",$row['field_4']);
		 $suantity = explode("!!!",$row['field_5']);
		 $tity = explode("@@@@",$row['field_40']);
		 $nuantity = explode("!!!",$row['field_1']);
		  
	          $textout.='<input name="qty'.$i.'" id="qty'.$i.'" type="hidden" value="0"><input name="f40f'.$i.'" id="f40f'.$i.'" type="hidden" value="'.$tity[1].'"><input name="f40v'.$i.'" id="f40v'.$i.'" type="hidden" value="'.$tity[0].'">';
		  
		  for($wer=0;$wer<intval($tity[1]); $wer++){
		    
		    $textout.='<div class="css70">'.$nuantity[($wer+1)].'  </div>';
		    
		    $textout.='<div class="tbl5">';
		    $textout.='<div class="tdinboxq"><input name="qtyxx'.$i.'_'.$wer.'" id="qtyxx'.$i.'_'.$wer.'" type="text" value="" class="inboxq" /></div>';
	            $textout.='<div class="tdrange">';
	            $textout.='<input name="qtyx'.$i.'_'.$wer.'" id="qtyx'.$i.'_'.$wer.'" type="range" min="0.0" max="'.$quantity[$wer].'" value="0" step="'.$suantity[$wer].'" onchange="calclat(this)" onkeypress="handle(this,event)" class="range_style" /></div>';
	            
	            $textout.='</div>';
		  }
		   
		  
	       }else{ // Input box - formula #1
	       
	       $textout.='<div class="tbl5">';
	       $textout.='<div class="tdinboxq"><input name="qty'.$i.'" id="qty'.$i.'" type="text" value="" class="inboxq" onchange="calclat2(this)" onkeypress="handle2(this,event)" /></div>';
	       $textout.='<div class="tdrange"><input name="qtyss'.$i.'" id="qtyss'.$i.'" type="range" min="0.0" max="'.$max_qty.'" value="0" step="'.$step.'" onchange="calclat(this)" onkeypress="handle(this,event)" class="range_style" /></div>';
	       $textout.='</div>';
	       }
	    
	       
	   }else if($box_type == 4){ // independent input box ---------------------------------
	    
	       $textout.='<div class="tbl5">';
	       $textout.='<div class="tdinboxq"><input name="qty'.$i.'" id="qty'.$i.'" type="hidden" value="0" />';
	       $textout.='<input name="qtyn'.$i.'" id="qtyn'.$i.'" type="text" value="" class="inboxq" onchange="calclat2(this)" onkeypress= "handle2(this,event)" /></div>';
	       $textout.='<div class="tdrange"><input name="qtyssx'.$i.'" id="qtyssx'.$i.'" type="range" min="0.0" max="'.$max_qty.'" value="0" step="'.$step.'" onchange="calclat(this)" onkeypress="handle(this,event)" class="range_style" /> </div>';
	       $textout.='</div>';
	   
	   }else{
               $textout.=' <input name="qty'.$i.'" type="text" value="" class="css71" onchange="calclat(this)" onkeypress="handle(this,event)"/>';
           }
	    
	   $textout.='</div></td>'; 
	    
	    
           if($nval[13]!='display:none;'){
              $textout.='<td class="css72"><input name="price'.$i.'" type="text" value="'.$row['field_3'].'" class="css73" /></td>';
	   }else{
	      $textout99.='<input name="price'.$i.'" type="hidden" value="'.$row['field_3'].'" />';
	   }
	   
	   
	   if($nval[10]!='display:none;'){
	      $textout.='<td class="css74"><input name="discnt'.$i.'" type="text" value="" class="css75" />';
	      $textout.='<input name="disa'.$i.'" id="disa'.$i.'" type="hidden" value="'.$row['field_7'].'" /> <input name="disb'.$i.'" id="disb'.$i.'" type="hidden" value="'.$row['field_8'].'" /> <input name="disc'.$i.'" id="disc'.$i.'" type="hidden" value="'.$row['field_9'].'" /> <input name="disd'.$i.'" id="disd'.$i.'" type="hidden" value="'.$row['field_10'].'" /> <input name="dise'.$i.'" id="dise'.$i.'" type="hidden" value="'.$row['field_11'].'" /> <input name="disf'.$i.'" id="disf'.$i.'" type="hidden" value="'.$row['field_12'].'" /> <input name="disg'.$i.'" id="disg'.$i.'" type="hidden" value="'.$row['field_13'].'" />  <input name="disj'.$i.'" id="disj'.$i.'" type="hidden" value="'.$row['field_14'].'" /> <input name="dish'.$i.'" id="dish'.$i.'" type="hidden" value="'.$row['field_15'].'" />   <input name="disk'.$i.'" id="disk'.$i.'" type="hidden" value="'.$row['field_16'].'" />  <input name="disl'.$i.'" id="disl'.$i.'" type="hidden" value="'.$row['field_17'].'" />   <input name="dism'.$i.'" id="dism'.$i.'" type="hidden" value="'.$row['field_18'].'" />   <input name="disn'.$i.'" id="disn'.$i.'" type="hidden" value="'.$row['field_19'].'" />   <input name="diso'.$i.'" id="diso'.$i.'" type="hidden" value="'.$row['field_20'].'" />  <input name="disp'.$i.'" id="disp'.$i.'" type="hidden" value="'.$row['field_21'].'" />';
	    
	      $textout.='<input name="disaa'.$i.'" id="disaa'.$i.'" type="hidden" value="'.$row['field_25'].'" /> <input name="disbb'.$i.'" id="disbb'.$i.'" type="hidden" value="'.$row['field_26'].'" /> <input name="discc'.$i.'" id="discc'.$i.'" type="hidden" value="'.$row['field_27'].'" /> <input name="disdd'.$i.'" id="disdd'.$i.'" type="hidden" value="'.$row['field_28'].'" /> <input name="disee'.$i.'" id="disee'.$i.'" type="hidden" value="'.$row['field_29'].'" /> <input name="disff'.$i.'" id="disff'.$i.'" type="hidden" value="'.$row['field_30'].'" /> <input name="disgg'.$i.'" id="disgg'.$i.'" type="hidden" value="'.$row['field_31'].'" />  <input name="disjj'.$i.'" id="disjj'.$i.'" type="hidden" value="'.$row['field_32'].'" /> <input name="dishh'.$i.'" id="dishh'.$i.'" type="hidden" value="'.$row['field_33'].'" />   <input name="diskk'.$i.'" id="diskk'.$i.'" type="hidden" value="'.$row['field_34'].'" />  <input name="disll'.$i.'" id="disll'.$i.'" type="hidden" value="'.$row['field_35'].'" />   <input name="dismm'.$i.'" id="dismm'.$i.'" type="hidden" value="'.$row['field_36'].'" />   <input name="disnn'.$i.'" id="disnn'.$i.'" type="hidden" value="'.$row['field_37'].'" />   <input name="disoo'.$i.'" id="disoo'.$i.'" type="hidden" value="'.$row['field_38'].'" />  <input name="dispp'.$i.'" id="dispp'.$i.'" type="hidden" value="'.$row['field_39'].'" /></td>';
	   }else{
	      $textout99.='<input name="discnt'.$i.'" type="hidden" value="" />';
	      $textout99.='<input name="disa'.$i.'" id="disa'.$i.'" type="hidden" value="'.$row['field_7'].'" /> <input name="disb'.$i.'" id="disb'.$i.'" type="hidden" value="'.$row['field_8'].'" /> <input name="disc'.$i.'" id="disc'.$i.'" type="hidden" value="'.$row['field_9'].'" /> <input name="disd'.$i.'" id="disd'.$i.'" type="hidden" value="'.$row['field_10'].'" /> <input name="dise'.$i.'" id="dise'.$i.'" type="hidden" value="'.$row['field_11'].'" /> <input name="disf'.$i.'" id="disf'.$i.'" type="hidden" value="'.$row['field_12'].'" /> <input name="disg'.$i.'" id="disg'.$i.'" type="hidden" value="'.$row['field_13'].'" />  <input name="disj'.$i.'" id="disj'.$i.'" type="hidden" value="'.$row['field_14'].'" /> <input name="dish'.$i.'" id="dish'.$i.'" type="hidden" value="'.$row['field_15'].'" />   <input name="disk'.$i.'" id="disk'.$i.'" type="hidden" value="'.$row['field_16'].'" />  <input name="disl'.$i.'" id="disl'.$i.'" type="hidden" value="'.$row['field_17'].'" />   <input name="dism'.$i.'" id="dism'.$i.'" type="hidden" value="'.$row['field_18'].'" />   <input name="disn'.$i.'" id="disn'.$i.'" type="hidden" value="'.$row['field_19'].'" />   <input name="diso'.$i.'" id="diso'.$i.'" type="hidden" value="'.$row['field_20'].'" />  <input name="disp'.$i.'" id="disp'.$i.'" type="hidden" value="'.$row['field_21'].'" />';
	    
	      $textout99.='<input name="disaa'.$i.'" id="disaa'.$i.'" type="hidden" value="'.$row['field_25'].'" /> <input name="disbb'.$i.'" id="disbb'.$i.'" type="hidden" value="'.$row['field_26'].'" /> <input name="discc'.$i.'" id="discc'.$i.'" type="hidden" value="'.$row['field_27'].'" /> <input name="disdd'.$i.'" id="disdd'.$i.'" type="hidden" value="'.$row['field_28'].'" /> <input name="disee'.$i.'" id="disee'.$i.'" type="hidden" value="'.$row['field_29'].'" /> <input name="disff'.$i.'" id="disff'.$i.'" type="hidden" value="'.$row['field_30'].'" /> <input name="disgg'.$i.'" id="disgg'.$i.'" type="hidden" value="'.$row['field_31'].'" />  <input name="disjj'.$i.'" id="disjj'.$i.'" type="hidden" value="'.$row['field_32'].'" /> <input name="dishh'.$i.'" id="dishh'.$i.'" type="hidden" value="'.$row['field_33'].'" />   <input name="diskk'.$i.'" id="diskk'.$i.'" type="hidden" value="'.$row['field_34'].'" />  <input name="disll'.$i.'" id="disll'.$i.'" type="hidden" value="'.$row['field_35'].'" />   <input name="dismm'.$i.'" id="dismm'.$i.'" type="hidden" value="'.$row['field_36'].'" />   <input name="disnn'.$i.'" id="disnn'.$i.'" type="hidden" value="'.$row['field_37'].'" />   <input name="disoo'.$i.'" id="disoo'.$i.'" type="hidden" value="'.$row['field_38'].'" />  <input name="dispp'.$i.'" id="dispp'.$i.'" type="hidden" value="'.$row['field_39'].'" />';
	   }
	    
	    
	    if($nval[14]!='display:none;'){
	       $textout.='<td class="css50"><input name="amnt'.$i.'" type="text" value="0" class="css51" /></td>';
	    }else{
		$textout99.='<input name="amnt'.$i.'" type="hidden" value="0" />';
	    }
	    
	    $textout.='</tr>';
	    
	   $i++;
	  }
	  
	  
	}
	
   if($samesel != ''){
		$samesel.='</div>'.$textouts.'</td></tr>';
		$textout.= $samesel;
	        $samesel='';
		$i++;
    }
   
   
   
   
//-------------------- Read Calendar ---------------------------
 $tbname = "qg_calendar";
 $calendar_event ='';
 $sql12 = "SELECT * FROM ".$wpdb->prefix.$tbname." WHERE visible='yes' AND field_1>='$nowyear' ORDER BY id";  
 $moderation3 = $wpdb->get_results($sql12, ARRAY_A); 
 foreach ( (array) $moderation3 as $row ) {
   $calendar_event .= mysql_real_escape_string( $row["field_1"].",".$row["field_2"].",".$row["field_3"].",". $row["field_4"].",".$row["field_5"].html_entity_decode("\r\n"));
  }
  
//----------------------- Time table ---------------------------
   $time_array = '';
   $time_out = '';
   $option_name = 'setting_qg_time';

        if ( get_option($option_name) !== false ) {
             $new_valuet = get_option( $option_name );
        }  else  {
            $deprecated = null;
            $autoload = 'yes';
            add_option( $option_name, $new_valuet, $deprecated, $autoload );
        }
	
    $timesx = explode(";",$new_valuet);
    if(!function_exists('sortFunctions')) {
       function sortFunctions( $a, $b ) { return strtotime($a) - strtotime($b);}
    }
    usort($timesx, "sortFunctions");
    
    for($i4=0;$i4<count($timesx);$i4++) {
          $time_out .= '<option value="'.$timesx[$i4].'"> '.$timesx[$i4].' </option>';
	  $time_array .= '"'.$timesx[$i4].'",';
    }
   
   $time_array = rtrim($time_array,",");
   
//----------------------- Calendar Lang----------------------------------------

      for($xv=1; $xv<=19; $xv++){
          $option_name = 'setting_qgc'.$xv;
    	     if ( get_option($option_name) == false ) {
                  add_option( $option_name, $calvalues[$xv], null, 'yes' );
	     }else{
		$calvalues[$xv] = get_option( $option_name);
	     }
      }
   





if($doshow==0){

      $js_values = 'var css = \'input[type=range]:focus::-webkit-slider-runnable-track { background: '.$nval[6].' !important;} input[type=range]:focus::-moz-range-track {background: '.$nval[6].' !important;} input[type=range]::-webkit-slider-thumb {background-image: linear-gradient('.$nval[9].','.$nval[6].') !important; } input[type=range]::-moz-range-thumb {background-image: linear-gradient('.$nval[9].','.$nval[6].') !important; } input[type=range]::-ms-thumb { background-image: linear-gradient('.$nval[9].','.$nval[6].') !important; } #addcharg{display: none;'.$nval[14].'} .css3{text-align: center;padding: 0px;border-spacing: 0; width:'.$nval[1].';background: '.$nval[2].'; border:'.$nval[3].'; font-size: '.$nval[8].'; color: '.$nval[7].'} .css4{width:10px; font-size: 8px;'.$thstyle.' } .css5{'.$thstyle.'} .css6{ '.$thstyle.$nval[13].' } .css7{ '.$thstyle.$nval[10].' } .css8{ '.$thstyle.$nval[14].' } .css9{text-align: right; background: #dfdfdf; font-size: '.$nval[8].'; width: 100%;border:none;} .css12{'.$nval[14].'}  .css13{'.$nval[11].'} .css14{'.$nval[15].'} .css15{'.$nval[16].'} .css16{'.$nval[16].''.$show_tax2.'} .css17{'.$nval[16].' '.$show_tax3.'} .css18{background-color: transparent !important; border:none !important; padding:4px !important; margin-right:5px !important; width:100px; text-align:right; font-size:'. $nval[8].';color:'.$nval[7].';} .css19{color:'.$nval[4].'; background: '.$nval[6].';} .css20{border:none;text-align: right;padding: 5px;font: bold 16px/30px Georgia;} .css21{background-color: transparent !important; border:none !important; padding:4px !important; margin-right:5px !important; width:100px; text-align:right; font-size:'. $nval[8].';font: bold 16px/30px Georgia; color:'.$nval[4].' !important;} .css22{border:none;padding: 5px;text-align: center;width:100%; background:'.$nval[9].';} #buttn1{background: '.$nval[33].' !important;color : '.$nval[34].' !important;  margin:5px;}  .css23{width:296px;text-align:center;background:'.$nval[2].';border:3px solid '.$nval[6].' !important;font-size:'.$nval[8].'; padding: 5px;border-collapse: collapse;}  .css33{background: '.$nval[33].' !important;color : '.$nval[34].' !important; margin:5px;} .style_qntt2 {width:250px;text-align:left; margin:5px; font-size: '.$nval[8].';color: '.$nval[7].'; background: #f8f1b8 !important;padding:0px 2px 0px 5px; }  .style_qntt3 {width:60px !important; text-align:center; margin:5px; font-size: '. $nval[8].';color: '.$nval[7].'; background: #f8f1b8 !important; padding:3px !important;float:right; }  .css37{font-size: '.$nval[8].' !important; color: '.$nval[7].'; width:90px !important; text-align:center; background: #f8f1b8; padding:0px 2px 0px 5px; margin:3px !important; float:right;} .css40{border-color: '.$nval[9].';border-style: solid;border-width: 1px 1px 1px 0px !important; height:26px;width:100% !important;text-align: right;padding:3px 0px 0px 0px !important;vertical-align: middle !important; background:'.$selectbox_background.';}    .inboxq {float:right; text-align: right;border:none !important;   background:transparent !important; font-weight:bold; width:120px; height:18px; padding:0px 10px 0px 0px !important; font-family: Arial; font-size: 16px;margin:0px !important; z-index:1000 !important; color: '.$nval[6].' !important;}  .check_box { background: -webkit-linear-gradient(top, '.$nval[9].' 0%, '.$nval[6].' 100%) !important;  background: -moz-linear-gradient(top, '.$nval[9].' 0%, '.$nval[6].' 100%) !important;   background: -o-linear-gradient(top, '.$nval[9].'  0%, '.$nval[6].' 100%) !important;   background: -ms-linear-gradient(top, '.$nval[9].' 0%, '.$nval[6].' 100%) !important;    background: linear-gradient(top, '.$nval[9].' 0%, '.$nval[6].' 100%) !important;  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr="'.$nval[9].'", endColorstr="'.$nval[6].'",GradientType=0 ) !important;}  .css50{border: none; background-color: transparent; padding:0px;width: 72px; vertical-align: middle;text-align: center;'.$nval[14].'}  .css51{border: none; background-color: transparent; padding:0px;width: 72px; vertical-align: middle;text-align: center; font-size:'. $nval[8].'; color: '. $nval[7].';}  .css52{display:none;border:none; padding:0px !important;margin:0px;}  .css53{text-align: right;vertical-align: text-top;border-style: solid;border-width: 0px 1px 1px 0px;border-color: '.$nval[9].'; padding:0px;width:100% !important; background:'.$selectbox_background.';}  .css54{width: '.$imagesize.'px; height: auto;}  .css55{font-size:'. $nval[8].';color:'. $nval[7].';'.$select_line.'} .css56{background:'.$nval[9].';border: none !important;}  .thstyle {border:none; color:'. $nval[4].'; font-size: '. $nval[5].'; background: '. $nval[6].'; text-align: center;vertical-align: text-top;  } .css57{cursor: pointer;border:none;padding:0px; margin:0px;width:26px; height:24px;}  .css58{background:'.$nval[9].';border: none !important;padding: 0px !important;} .css59{border:none !important; padding:0px !important;margin:0px;} .css60{text-align: left;  padding:0px !important;margin:0px; width:100% !important; border-style: solid;border-width: 0px 1px 1px 0px;border-color: '.$nval[9].'; background:'.$selectbox_background.';}  .css61{background:'.$nval[9].';} .css62{text-align: center;vertical-align: text-top;border:none;width: 100%;font-weight:bold;padding:5px;} .css63{background:'.$nval[9].';} .css64{text-align: left;vertical-align: text-top;border:none;width: 100%} .css65{'.$name_div_css.' font-size: '. $nval[8].'; color: '. $nval[7].';float:left;} .css66{'.$name_div_css.' font-size: '. $nval[8].'; color: '. $nval[7].';font-weight:bold;}  .css{padding:7px; background: transparent;border:none;'. $nval[12].'} .css68{margin:0px; padding:5px !important;width:100%; text-align: justify;line-height:110%; background: transparent;font-size:'. $nval[8].';border:none;color: '. $nval[7].'} .css69{'.$name_div_css.'  font-size: '. $nval[8].'; color: '. $nval[7].';}  .css70{'.$name_div_css.'  font-size: '. $nval[8].'; color: '. $nval[7].';}  .css71{width: 55px;padding:2px 0px 2px 0px;text-align: center;font-size:'. $nval[8].';color:'. $nval[7].';background: #f8f1b8;}  .css72{border: none; background-color: transparent; padding:0px;width: 55px; vertical-align: middle;text-align: center;'.$nval[13].'} .css73{border: none; background-color: transparent; padding:0px;width: 55px; vertical-align: middle;text-align: center;font-size: '. $nval[8].'; color: '. $nval[7].';}  .css74{border: none; background-color: transparent; padding:0px;width: 55px; vertical-align: middle;text-align: center;'. $nval[10].'} .css75{border: none; background-color: transparent; padding:0px;width: 55px; vertical-align: middle;text-align: center; font-size: '. $nval[8].'; color: '. $nval[7].';}               '.$cssline.'    \',  head = document.head || document.getElementsByTagName("head")[0], style = document.createElement("style"); ';
      
      $js_values .= 'var totalelements = "'.$i.'";var time_array = new Array('.$time_array.');var tax1a = "'.$nval[20].'"; var tax2a = "'.$nval[22].'";var tax3a = "'.$nval[24].'";var nssww = "'.$nval[14].'";var nssww2 = "'.$nval[14].'"; var nwid = parseInt ("'.$calendar_css[5].'");var nhei = parseInt ("'.$calendar_css[6].'");var nfont = "'.$calendar_css[7].'";';
      $js_values .= 'var mn=new Array("'.$calvalues[1].'","'.$calvalues[2].'","'.$calvalues[3].'","'.$calvalues[4].'","'.$calvalues[5].'","'.$calvalues[6].'","'.$calvalues[7].'","'.$calvalues[8].'","'.$calvalues[9].'","'.$calvalues[10].'","'.$calvalues[11].'","'.$calvalues[12].'");var DateList = "'.$calendar_event.'";var Sunday = "'.$calvalues[13].'";var Monday = "'.$calvalues[14].'";var Tuesday = "'.$calvalues[15].'";var Wednesday = "'.$calvalues[16].'";var Thursday = "'.$calvalues[17].'";var Friday = "'.$calvalues[18].'";var Saturday = "'.$calvalues[19].'"; var cssc = new Array("'.$calendar_css[0].'","'.$calendar_css[1].'","'.$calendar_css[2].'","'.$calendar_css[3].'","'.$calendar_css[4].'"); ';
      
      
      wp_register_script('md-script', $md5,array(), null, false);
      wp_enqueue_script('md-script');
      wp_add_inline_script( 'md-script', $js_values );
      wp_register_script('qg-script', $qgquery,array('jquery'), null, false);
      wp_enqueue_script('qg-script');

?>
<form method="post" id="quotegen" name="quotegen" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
 <table class="css3">
    <tr>
           <th class="css4"><?php if(isset($nval[25])){echo $nval[25];} ?></th>
           <th class="css5"><?php echo $nval[26]; ?></th>
           <?php
	      if($nval[13]!='display:none;'){echo '<th class="css6">'.$nval[27].'('.$nval[18].')</th>';}
	      if($nval[10]!='display:none;'){echo '<th class="css7">'.$nval[29].'</th>';}
	      if($nval[14]!='display:none;'){echo '<th class="css8">'.$nval[30].'</th>';}
	    ?>
    </tr>
    <?php echo $textout; ?>
    <tr class="css1">
        <td colspan="<?php echo $colspan; ?>" class="css2"><?php echo $textout99; ?>
        
         <table class="css9">
	    <tr id="addcharg">
             <td class="css11"><?php echo $nval[35]; ?>(<?php echo $nval[18]; ?>)</td>
             <td class="css10"><input name="qgb0" type="text" class="css18" value="0" readonly="readonly" /></td>
            </tr>
	    <tr class="css12">
             <td class="css11"><?php echo $nval[36]; ?>(<?php echo $nval[18]; ?>)</td>
             <td class="css10"><input name="qgb1" type="text" class="css18" value="0" readonly="readonly" /></td>
            </tr>
            <tr class="css13">
             <td class="css11"><?php echo $nval[37]; ?>(<?php echo $nval[18]; ?>)</td>
             <td class="css10"><input name="qgb2" id="qgb2" type="text" class="css18" value="0" readonly="readonly" /></td>
            </tr>        
            <tr class="css14">
             <td class="css11"><?php echo $nval[38]; ?>(<?php echo $nval[18]; ?>)</td>
             <td class="css10"><input name="qgb3" type="text" class="css18" value="0" readonly="readonly" /></td>
            </tr>
            <tr class="css15">
             <td class="css11"><?php echo $nval[19]; ?> (<?php echo $nval[20]; ?>%)</td>
             <td class="css10"><input name="qgb4" type="text" class="css18" value="0" readonly="readonly" /></td>
            </tr>      
            <tr class="css16">
             <td class="css11"><?php if(isset($nval[21])){echo $nval[21];} ?> (<?php echo $nval[22]; ?>%)</td>
             <td class="css10"><input name="qgb5" type="text" class="css18" value="0" readonly="readonly" /></td>
            </tr>
            <tr class="css17">
             <td class="css11"><?php if(isset($nval[23])){echo $nval[23];} ?> (<?php echo $nval[24]; ?>%)</td>
             <td class="css10"><input name="qgb6" type="text" class="css18" value="0" readonly="readonly" /></td>
            </tr>    
    
            <tr class="css19">
             <td class="css20"><?php echo $nval[39]; ?>(<?php echo $nval[18]; ?>)</td>
             <td class="css10">
               <input name="qgb7" type="text" class="css21" value="0" readonly="readonly" />
               <input name="qgb11" type="hidden" value="" />
	       <input name="qgb30" type="hidden" value="0" />
	       <input name="disord" type="hidden" value="<?php echo $new_val[1]; ?>" />
	       <input name="disprs" type="hidden" value="<?php echo $new_val[2]; ?>" />
	       <input name="minord" type="hidden" value="<?php echo $new_val[3]; ?>" />
             </td>
            </tr>
        </table>
            
       </td>
    </tr>
    <tr>
        <td colspan="<?php echo $colspan; ?>" class="css22">
            <input type="button" id="buttn1" onClick="submitf();" value="<?php echo $nval[31]; ?>">
        </td>
    </tr>
       
 </table>
 
 
 
    <div id="subord">
        <table class="css23">
	<?php
	     $order_f ='';   
	     $rend = array(rand(0, 9),rand(0, 9),rand(0, 9));
             $showme = '<span class="css25">'.$rend[0].'&nbsp;<span class="css26">'.$rend[1].'</span>&nbsp;<span class="css27">'.$rend[2].'</span></span>';
             $showme2 = md5($rend[0].$rend[1].$rend[2]);
	     
	     if(get_option('setting_qgform0') == "show"){
	        $order_f .='<tr><th colspan="2" class="css28">'.get_option("setting_qgname0").' #'.get_option("setting_qgname7").' </th></tr>';
	     }
	     
	     for($zx=1;$zx<14;$zx++){ 
		 $node1 = get_option('setting_qgname'.$zx);
		 $node2 = get_option('setting_qgform'.$zx);
		 $astr="";
		 
		 if($node2=='show' || $node2=='show (required field)'){
		   
		   if($node2=='show (required field)'){$astr='<span class="css29">*</span>';} 
		   
		   if($zx==5) {  // date ;
		       $order_f .='<tr><td class="css30">'. $node1.' <input name="oqgb'.$zx.'" type="text" class="css37" value="" onFocus="this.select();lcs(this);lcs2();" onclick="event.cancelBubble=true;this.select();lcs(this);lcs2();" readonly="readonly" /></td> <td class="css31">'.$astr.'</td></tr>';
		 
		   }else if($zx==6){ // time
		       $order_f .='<tr><td class="css30">'. $node1.' <select id="selectime" name="oqgb'.$zx.'" class="css37">'.$time_out.'</select></td><td class="css31">'.$astr.'</td></tr>';
		   
		   }else if($zx==7){//hide the number field
		       $order_f .='<tr class="cnon"><td colspan="2" class="cnon"><input name="oqgb'.$zx.'" type="hidden" value="'.get_option("setting_qgname7").'" /></td></tr>';
		   }else if($zx==12){ // memo
		       $order_f .='<tr><td class="css35">'. $node1.'<br> <textarea name="oqgb'.$zx.'" class="style_qntt2" rows="4"></textarea></td><td class="css31">'.$astr.'</td></tr>';
		  
		   }else if($zx==13){ //recaptcha
		       $order_f .='<tr><td class="css30">'. $node1.' '.$showme.' <input name="oqgb'.$zx.'" type="text" class="style_qntt3" value="" /></td> <td class="css31">'.$astr.'</td></tr>'; 
		   
		   }else{
		       $order_f .='<tr><td class="css30"><input name="oqgb'.$zx.'" type="text" class="style_qntt2" value="" placeholder="'. $node1.'" /></td><td class="css31">'.$astr.'</td></tr>';
		   }
		 
		 }else{
		    if($zx==13){
			$order_f .='<tr class="cnon"><td colspan="2" class="cnon"><input name="oqgb'.$zx.'" type="hidden" value="'.$rend[0].$rend[1].$rend[2].'" /></td></tr>';
		    }else{
		        $order_f .='<tr class="cnon"><td colspan="2" class="cnon"><input name="oqgb'.$zx.'" type="hidden" value="" /></td></tr>';
		    }
		 }

	     }
	     
	     echo $order_f;
	?>        
                    <tr>
                        <td colspan="2" class="css24">
                            <input name="oqgb20" type="hidden" value="<?php echo $showme2; ?>" />
			    <input type="button" class="css33" onClick="submitform();" value="<?php echo $nval[32]; ?>">
                        </td>
                    </tr>
        </table>
    </div>

 
</form>
<?php
}
?>