<?php
global $wpdb;
$tbname = "qg_invoices";
$out2='';
$td_st = ' class="order2"';
$td_st2 = ' class="order3"';
$td_st3 = ' class="order5"';
$th_st = ' class="order6"';
$showid = 1;
$order_num='';
$link = 'options-general.php?page=quotegenerator&links=invoices&rowid=';
$link2 = 'options-general.php?page=quotegenerator&links=invoices&deleteid=';
$imageqg = sprintf("%s/quotegenerator/assets/img/no.png", plugins_url());
$div_st='';$div_st2='';
$emailto="";
$order_id='';$clientn='';$invoice_date='';


if(isset($_REQUEST["rowid"])){
    if(intval($_REQUEST["rowid"])>0){
	$div_st=' class="order7"';
	$div_st2=' class="order8"';
	$showid = $_REQUEST["rowid"]; //invoice id
	
	   $sql2 = "SELECT * FROM ".$wpdb->prefix.$tbname." WHERE id=".$showid;
           $moderation2 = $wpdb->get_results($sql2, ARRAY_A);
       
       foreach ( (array) $moderation2 as $row ) {
	  $out2.= nl2br(stripslashes($row["data_field"]));
	  $clientn = $row["client"];
	  $order_num = $row["order_num"];
	  $order_id = $row["order_id"];
	  $invoice_date = $row["invoice_date"];
       }
    }
}
?>
 
<div id="mainord" <?php echo $div_st2; ?>>
  <table class="tabs2ord"> 
   <tr><td colspan="4" class="td1ord">Invoices</td></tr>
   <tr><th<?php echo $th_st; ?>>#</th>
       <th<?php echo $th_st; ?>> Date </th>
       <th<?php echo $th_st; ?>> Customer </th>
       <th<?php echo $th_st; ?>> Delete </th>
   </tr> 
   <?php
       $sql = "SELECT * FROM ".$wpdb->prefix.$tbname." WHERE visible='yes' ORDER BY id DESC";
       $moderation = $wpdb->get_results($sql, ARRAY_A);
       $out='';
       foreach ( (array) $moderation as $row ) {
	  $out.='<tr>';
	  $out.='<td'.$td_st.'><a href="'.$link.$row["id"].'">'.$row["id"].'</a></td>';
	  $out.='<td'.$td_st.'><a href="'.$link.$row["id"].'">'.$row["invoice_date"].'</a></td>';
	  $out.='<td'.$td_st.'>'.$row["client"].'</td>';
	  $out.='<td'.$td_st.'><a href="'.$link2.$row["id"].'"><img src="'. $imageqg.'" width="20" height="20" alt="Delete"></a></td></tr>';
       }
       echo $out;
   ?>
  </table>
</div>

  <div id="tabs3ord" <?php echo $div_st; ?>>
     <div class="elm1"> <input type="button" class="butord" onClick="printf();" value="Print Invoice">   </div>
     <div class="elm1"> <input type="button" class="butord" onClick="emailf();" value="Email to Customer">   </div>
     <div class="elm1"> <input type="button" class="butord" onClick="save_invoice();" value="Save">   </div>
     <div class="elm1"> <input type="button" class="butord" onClick="cloz(2);" value="Close">   </div>
  </div>

<div id="shwordord" <?php echo $div_st; ?>>
 
   <input name="showid" type="hidden" value="<?php echo $showid; ?>" />
   <input name="order_id" type="hidden" value="<?php echo $order_id; ?>" />
   <input name="ordnum" type="hidden" value="<?php echo $order_num; ?>" />
   <input name="clientn" type="hidden" value="<?php echo $clientn; ?>" />
   <input name="convert" id="convert" type="hidden" value="" />
     
   <div id="emailsord">
     To: <input name="mailto" type="text" value="<?php echo $emailto; ?>" />
     Subject: <input name="subject" type="text" value="Online Order" />
     Message:<br>
     <textarea name="memos0" id="memos0" rows="3"></textarea>
     <div class="order8"><textarea name="memos" id="memos"></textarea></div>
     <input name="sent" id="sent" type="hidden" value="" />
     <input type="button" class="butord" onClick="send_order(2);" value="Submit">
   </div>
   
   <div class="invc1"> Invoice #<?php echo $showid ." (".$invoice_date; ?>)</div>
   <div class="dv1ord"><a href="javascript:cloz(2);"><img src="<?php echo $imageqg; ?>" width="30" height="30" alt="QuoteGeneratorPlus"></a></div>
   <div id="printable" contenteditable="true"><?php echo $out2; ?></div>
   
</div>