<?php
global $wpdb;
require_once(ABSPATH ."wp-admin/includes/template.php");

	  $imagcss = sprintf("%s/quotegenerator/assets/img/css.png", plugins_url());
	  $imagfrm = sprintf("%s/quotegenerator/assets/img/quote.png", plugins_url());
	  $imagform = sprintf("%s/quotegenerator/assets/img/order.png", plugins_url());
	  $imagord = sprintf("%s/quotegenerator/assets/img/orders.png", plugins_url());
	  $imagitem = sprintf("%s/quotegenerator/assets/img/items.png", plugins_url());
	  $imagcal = sprintf("%s/quotegenerator/assets/img/calendar.png", plugins_url());
	  $web_help = "http://quotegeneratorplus.com/";
	  $imagpayment = sprintf("%s/quotegenerator/assets/img/payment.png", plugins_url());
	  $imageqgno = sprintf("%s/quotegenerator/assets/img/no.png", plugins_url());
          $imageinfo = sprintf("%s/quotegenerator/assets/img/info.png", plugins_url());
	  $imagtime = sprintf("%s/quotegenerator/assets/img/time.png", plugins_url());
	  $imaginv = sprintf("%s/quotegenerator/assets/img/invoices.png", plugins_url());
	  $imaghelp = sprintf("%s/quotegenerator/assets/img/help.png", plugins_url());
	  $imacsset = sprintf("%s/quotegenerator/assets/img/css_settings.jpg", plugins_url());
	  $imaform1 = sprintf("%s/quotegenerator/assets/img/form.jpg", plugins_url());
	  $imaform2 = sprintf("%s/quotegenerator/assets/img/orderform.jpg", plugins_url());
	  $imaorder = sprintf("%s/quotegenerator/assets/img/order.jpg", plugins_url());
	  $imageqg = $web_help."wordpress/images/jpg/";
	  $formula_no='<img src="'. sprintf("%s/quotegenerator/assets/img/no.png", plugins_url()).'" alt="no">';
	  $formula1 = '<img src="'. sprintf("%s/quotegenerator/assets/img/cost_calculations1.jpg", plugins_url()).'" alt="Formula1">';
	  $formula2 = '<img src="'. sprintf("%s/quotegenerator/assets/img/cost_calculations2.jpg", plugins_url()).'" alt="Formula2">';
	  $formula3 = '<img src="'. sprintf("%s/quotegenerator/assets/img/cost_calculations3.jpg", plugins_url()).'" alt="Formula3">';
		  
 $order_name = array("Heading","Name","Email","Address","Phone","Calendar","Time","Order Number","Question #1","Question #2","Question #3","Question #4","Memo","Captcha","Submit order to");
 
 $order_form = array("Online Order","Name","E-mail","Address","Phone","When do You need the service?", "Time of arrival","1","Best time to contact you?","","","","Memo","Captcha",get_option('admin_email'));
 
 $order_value = array("show","show (required field)","show (required field)","hide","hide","hide","hide","show","hide","hide","hide","hide","hide","hide","Automatically send an order to the customer.");

?>


<div class="tbl11">
	     <div class="tiles" onClick="location.href='options-general.php?page=quotegenerator&links=style'"><img src="<?php echo $imagcss; ?>" width="40" height="40" onClick="location.href='options-general.php?page=quotegenerator&links=style'"><br>Form Style</div>
	     
	     <div class="tiles" onClick="location.href='options-general.php?page=quotegenerator&links=form2'"><img src="<?php echo $imagform; ?>" width="40" height="40" onClick="location.href='options-general.php?page=quotegenerator&links=form2'"><br>Order Form</div>
	     <div class="tiles" onClick="location.href='options-general.php?page=quotegenerator&links=items'"><img src="<?php echo $imagitem; ?>" width="40" height="40" onClick="location.href='options-general.php?page=quotegenerator&links=items'"><br>Items</div>
	     <div class="tiles" onClick="location.href='options-general.php?page=quotegenerator&links=calend'"><img src="<?php echo $imagcal; ?>" width="40" height="40" onClick="location.href='options-general.php?page=quotegenerator&links=calend'"><br>Calendar</div>   
	     <div class="tiles" onClick="location.href='options-general.php?page=quotegenerator&links=form3'"><img src="<?php echo $imagtime; ?>" width="40" height="40" onClick="location.href='options-general.php?page=quotegenerator&links=form3'"><br>Time</div>
	     <div class="tiles" onClick="location.href='options-general.php?page=quotegenerator&links=paypal'"><img src="<?php echo $imagpayment; ?>" width="40" height="40" onClick="location.href='options-general.php?page=quotegenerator&links=paypal'"><br>Payment Tools</div>
	     
	     <div class="tiles" onClick="location.href='options-general.php?page=quotegenerator&links=orders'"><img src="<?php echo $imagord ?>" width="40" height="40" onClick="location.href='options-general.php?page=quotegenerator&links=orders'"><br>Orders</div>
             <div class="tiles" onClick="location.href='options-general.php?page=quotegenerator&links=invoices'"><img src="<?php echo $imaginv; ?>" width="40" height="40" onClick="location.href='options-general.php?page=quotegenerator&links=invoices'"><br>Invoices</div>
	     
	     <div class="tiles" onClick="location.href='options-general.php?page=quotegenerator&links=help'"><img src="<?php echo $imaghelp; ?>" width="40" height="40" onClick="location.href='options-general.php?page=quotegenerator&links=help'"><br>User Manual</div>   
</div>

<?php
		  
		  $arrfields = array('','Form width','Form background','Form border','Header text color','Header font size','Header background','Font color','Font size','Font background','Quantity Discounts','Order Total Discount ','Description','Price','Additional Charge, Subtotal and Amount fields','Total before tax','Tax','Currency Symbol','Currency Sign','Tax 1 <span style="font-size:10px;">(the name of a field)</span>','Tax 1 (%)','Tax 2 <span style="font-size:10px;">(the name of a field)</span>','Tax 2 (%)','Tax 3 <span style="font-size:10px;">(the name of a field)</span>','Tax 3 (%)','Header Name 1','Header Name 2','Header Name 3','Header Name 4','Header Name 5','Header Name 6','Button 1','Button 2','Buttons background','Buttons text color','Additional Charge <span style="font-size:10px;">(the name of a field)</span>','Subtotal <span style="font-size:10px;">(the name of a field)</span>','Discount <span style="font-size:10px;">(the name of a field)</span>','Total before Tax <span style="font-size:10px;">(the name of a field)</span>','Total <span style="font-size:10px;">(the name of a field)</span>','Final message');
		  
                  $itemstable='<h3>"Order minimum amount"</h3> - this option allows you to set a minimum amount of money per order.  Open your quote generator <b>Plugin</b> → go to <b>Settings and click on "Items"</b>. You will see order minimum amount option at the top of the page. Enter the minimum amount you want to use, then hit <b>"Save"</b> button and you are done.<br><br>
<h3>"Order total discount"</h3> is an option that allows you to apply discount to your order. Example: if you want to apply a 10% discount to the total amount of the order that is for example greater than $1000, just enter "1000" into "$" field and "10" into "%" field, then hit <b>"Save"</b>.<br><br>
		     
		     <b>Template Options: </b><br><br><span style="font-variant: small-caps;"><b>Option 1</b></span>: You can choose to download already preset template and edit names, formulas, numbers, descriptions to customize the template to your business needs. If you want to use template	please select any template you would like to customize.<br><br>
		     
		     <b>Example:</b>

                     <ul class="c">
			<li>Select "Residential Cleaning". </li>
			<li>Now click on "items" again and template is downloaded. Now you can start to customize any parameter.</li>
			<li>You can apply "order minimum amount", "order total discount", "change items name", "description" in this template. In order to modify these boxes just click on the name and type the new name/description into the box. Don&#39;t forget to click "Save".</li>
			<li>In the table you will see option "Formula #1 #2 #3..." where you can select formula from select box which has a drop down menu of formulas. </li>
			<li>The next row is called "Price" where you can enter the price either in % or $ amount. If you want to enter % please enter price and % symbol. If you just want to enter amount, please enter just the number.</li>
			<li>Price can be entered with  "-" so it will automatically work as a discount.</li>
                     </ul>
		     <br>
		     <span style="font-variant: small-caps;"><b>Option 2</b></span>: To create your own form please click on "Items" and follow these steps:
		     <ul class="c">
			<li>Click on the "Items"- go to "download template option" and select "clear the contents of a table" from the drop down menu. Once you clicked on the following option please click on "Items" again in order to apply the changes.</li>
		     </ul>
		     <b>Here&#39;s an example how to create a new form for residential cleaning</b><br>
		     <ul class="c">
			<li>Click on the "Items"- go to "Download template option" and select "Clear the contents of a table" from the drop down menu. Once you clicked on the following option please click on "Items" again in order to apply the changes.</li>
			<li>Now type in "Order minimum amount". For example, minimum amount for cleaning is $80. Type in "80" and if your company has discount for orders that are $120 or above, type in "120" into "Order total discount" and the amount of discount in %. For example, all orders that are $120 or above in value may receive a 10% discount. Therefore, type in "10" into "%" box. </li>
			<li>Click "Save" in order to apply these changes. </li>
			<li>Now you can click on "Add new item" icon</li>
			<li>The first option is called "New Item line" and it will have "1" already entered. Please leave this line as it is. It is there to provide numbering of the columns and will allow to move around lines  if you will need to change order of items in the future. </li>
			<li>The next line is called "Input Type". Click on Input box and open a drop down menu where you will see 5 options (Input box, input box (independent), check box, select box, header). </li>
			<li>For our example, please select "Header" first.</li>
			<li>The next line is called "Item name". For our example, we will enter the name as "Get a quote instantly and book service online"</li>
			<li>Click on "Save New Item" and you will see a pop out message confirming that the new item has been saved. You will now be able to see a new item in your form. </li>
		     </ul>
		     <b>FYI:</b>
		     <p style="font-style: italic;">There are 2 different ways how clients can be charged for residential cleaning. They can be charged based on hourly rate or they can be charged per entire service. For our example, our clients will be charged per entire service. Your client will see exactly how much they will have to pay for the service. 
In order to create a good estimate for your job I recommend you write out all the <b>items (that you will later be adding to your form)</b> that influence the total price. For example, your list of items may include bedrooms, bathrooms, kitchens, hallways, stairs, living rooms, etc. Other things to consider sq footage, type of cleaning and frequency. Sq footage, weekly cleaning, bi-weekly cleaning, one time cleaning, move out cleaning, windows, fridge, baseboards, etc these are also your <b>items</b>. The number of people as well as presence of pets may also affect the price for a cleaning. Both people and pets are also <b>items</b>. </p>
		     * Now we will add the second item for the same residential cleaning form. You may create as many items as you need. Please follow these steps: <br>
		     <ul class="c">
			<li>Click on “Add new item”</li>
			<li>The first option is called “New Item line” and it will have “2” already entered. Please leave this line as it is. It is there to provide numbering of the columns and will allow to move around lines if you will need to change order of items in the future.</li>
			<li>The next line is called “Input Type”. Click on Input box and open a drop down menu where you will see 5 options (Input box, input box (independent), check box, select box, header). </li>
			<li>For our example, please select “Input box”. *Input box is a box that lets you create a slider. </li>
			<li>For creating a slider you will need to use one of the formulas. In this example we will use formula#1 (Amount=Price*Quantity). </li>
			<li>For our example the slider is for charging client for window cleaning. You will need to enter “Item name”, let&#39;s name this window cleaning slider as “How many windows needs to be washed?”  If you want you can enter additional details in description (for example, you can specify the window size or shape in the description box). For our example we will leave it blank.</li>
			<li>The next line is called “Price”. Please enter the price you would like to charge for one window. For our example, the price for 1 window is $7. Please enter “7”</li>
			<li>Now you&#39;ve moved on to the line called “Maximum Quantity”. For our example, the maximum quantity of windows the client may order per cleaning services is 40.  You can enter here any amount to apply to your maximum limit. For our example, usually 40 is enough for almost any house as there are rarely houses with 40+ windows. </li>
			<li>The next line is called “Step”. “Step” sets how many spaces the client may move the slider from minimum to maximum. With windows example, 1 step would be 1 window, so the slider will slide 1 step per 1 window. You can set “Step” to “2” and it will then slide 2 windows and so on... </li>
			<li>The next line is called “Image (URL)”. This option allows you to place a picture into your quote form that will correspond with your item name. For our example we will leave it blank. </li>
			<li>The final option available in this item set up is “Set a Quantity Discount”. This option allows you apply discount per this specific item, in our example that would be discount for window washing. </li>
			<li>Example: The more windows client orders, the more discount you can provide for that client:<br>From 3 to 5 windows price= $6.30 10% discount<br>From 6 to 10 windows price= $5.95 15% discount<br>From 11 to 20 windows price=$5.60 20% discount</li>
			
		     </ul>
		     You can apply maximum 10 discounts or leave it blank if you don&#39;t want to provide a quantity discount.<br><br>
		     <li>Don&#39;t forget to click “Save New Item” new item and you will see a pop out message confirming that the new item has been saved. You will now be able to see another new item in your form. </li><br>
		     Now we will show you how to create “Check box” for your customized form
		     
		     <ul class="c">
			<li>Click on “Add new item”</li>
			<li>The first option is called “New Item line” and it will have “3” already entered. Please leave this line as it is. It is there to provide numbering of the columns and will allow to move around lines  if you will need to change order of items in the future. </li>
			<li>The next line is called “Input Type”. Click on Input box and open a drop down menu where you will see 5 options (Input box, input box (independent), check box, select box, header). </li>
			<li>For our example, please select “Check box”.</li>
			<li>For creating a check box you will need to use one of the formulas. In this example we will use formula#1 (Amount=Price*Quantity). FYI: For check box the quantity is always equal to 1.</li>
			<li>The next line is called “Item name”. For our example, we want to ask client if they have any pets in the house because you may want to enter additional charge if there are pets in the house. We will enter the name as “Are there any pets in the house?”</li>
			<li>The next line is called “Price”. In our example, we will charge additional $15 if there are any pets that live in the house. If you were to apply this to the formula we are using, the calculation will look like this: $15 x 1(quantity)=$15</li>
			<li>The next line is called “Image (URL)”. This option allows you to place a picture into your quote form that will correspond with your item name. For our example you could paste an url with an image of an animal if you&#39;d like.</li>
			<li>Click on “Save New Item” and you will see a pop out message confirming that the new item has been saved. You will now be able to see another new item in your form. </li>
		     </ul>
		     Now we will show you how to create “Select box”. In our example we will show you how to create “Select box” for different types of cleaning (such as one time cleaning, bi-weekly cleaning, etc). Please follow these steps:<br><br>
		     <ul class="c">
			<li>Click on “Add new item”</li>
			<li>The first option is called “New Item line” and it will have “4” already entered. Please leave this line as it is. It is there to provide numbering of the columns and will allow to move around lines  if you will need to change order of items in the future. </li>
			<li>The next line is called “Input Type”. Click on Input box and open a drop down menu where you will see 5 options (Input box, input box (independent), check box, select box, header). </li>
			<li>For our example, please select “Select box”. </li>
			<li>For creating a “Select box” option you will need to use one of the formulas. In this example we will use formula#2 (Additional Charge=Price%*Subtotal) or (Discount= -Price %* Subtotal).</li>
		     </ul>
		     <br>
			<div style="margin-left:20px;text-align: justify;"><b>FYI:</b>You will notice that in this form there are lines called “Option #1 though #5” but you can create any quantity. For the purpose of our cleaning services example we will create 3 different check boxes of 3 different types of cleaning: move out cleaning, one time cleaning, bi-weekly cleaning. Each Option# represents a different box that will be available for selection. For Option#1 we will create a base price cleaning type, which would be “one time cleaning”</div><br>
			
			<b>Option#1</b>
			<ul class="c">
			    <li>The next line is called “Item name”. For our example, we want to create “Select box” for one time cleaning. We will enter the name as “One Time Cleaning”. In this example, a “One Time Cleaning” option is a base price for all the rest of the cleaning types and therefore it will have 0 %. There won&#39;t be added any extra charge or discount to this base price unlike other cleaning option (for example move out cleaning will have additional charge and bi-weekly cleaning offers a discounted price). </li>
			    <li>The next line is called “Description”. You may choose to add here description of each cleaning type with details. For our example we will leave this option blank. </li>
			    <li>The next line is called “Price” which in our example is represented in %. In our example, we will enter “0%” as it is the base price. Make sure to add “%” sign. </li>
			    <li>The next line is called “Image (URL)”. This option allows you to place a picture into your quote form that will correspond with your item name. For our example you could paste an url with an image of a worker cleaning the house :) → You have now filled out Option#1 for one type of cleaning, now we need to fill out Options#2 and Option#3. </li>
			</ul>
			
			<b>Option#2</b>
			<ul class="c">
			    <li>The next line is called “Item name”. For our example, we want to create “Select box” for move out cleaning. We will enter the name as “Move Out Cleaning”. </li>
			    <li>The next line is called “Description”. You may choose to add here description of each cleaning type with details. For our example we will leave this option blank. </li>
			    <li>The next line is called “Price” which in our example is represented in %. In our example, we will enter “10%” which represents additional charge to the base price. Make sure to add “%” sign. </li>
			    <li>The next line is called “Image (URL)”. This option allows you to place a picture into your quote form that will correspond with your item name. For our example you could paste an url with an image of a worker cleaning the house :)</li>
			</ul>

			
			<b>Option #3</b>
			<ul class="c">
			    <li>The next line is called “Item name”. For our example, we want to create “Select box” for bi-weekly cleaning. We will enter the name as “Bi-Weekly Cleaning”. </li>
			    <li>The next line is called “Description”. You may choose to add here description of each cleaning type with details. For our example we will leave this option blank. </li>
			    <li>The next line is called “Price” which in our example is represented in %. In our example, we will enter “-20%” which represents discount to the base price. Make sure to add “%” sign. </li>
			    <li>The next line is called “Image (URL)”. This option allows you to place a picture into your quote form that will correspond with your item name. For our example you could paste an url with an image of a worker cleaning the house :)</li>
			</ul>
			<b>How to create items as select box options that will not influence the price? </b>
			<div style="margin-left:20px;">By simply entering “0” into price line without “%” sign you will just create different selections without prices. For example, you need to know what type of home that needs to be cleaned? Is it a house, a townhouse or a condo? The prices for all these items will be “0” so the form will only allow you to collect the information.</div>
			<br>
			<b>Input Type “Input box (independent)”</b>
			<div style="margin-left:20px;">Please see “Input box” for instructions. The difference between “Input box” and “Input box (independent)” options is that the second one allows you to enter price that is independent from prices for other items.  This means that all items created as “Input box (independent)” items within the form are constant and are not affected by any surcharges or discounts.  
</div>';

                  $pptexts='The software will redirect customers to PayPal or Stripe (your customers don\'t need to make account on PayPal or Stripe to pay the deposit, all they do is enter their credit card info but you do need to have a PayPal and Stripe account so that the payments go to you specifically) in case if deposit is required before job.<br><br>The window will let you to enter the % of deposit from total amount and currency. Once you enter some % deposit into that box your client once completes entering their order will be right away redirected to PayPal or Stripe to pay the deposit , if you choose not to charge your clients deposit, they will just submit the order and will be waiting for your confirmation.';
		 
		  $pptexts3='An online order form helps you reach customers beyond your local place of business. Build a form that will process payments for you and even send alerts when you get a new order. Start with this order form template and customize it for your business.'; //order fotm text
		  
		  $pptexts4='<p>This option allows you to create your regular business hours.</p>';

		  $calendartext='<h3>How to use "Calendar"? </h3> 
    <br>In order to add any event to your calendar follow these steps:
    <ul class="a">
      <li>First click on <b>"+Add Event"</b>.</li>
      <li>A menu will open.</li>
      <li>Choose the date. </li>
      <li>You will see a tick box called <b>"Block out the day in your calendar"</b>. This option allows you to block your clients from placing orders for that specific day. Use this option when you need to close/block that specific day. Otherwise, leave it blank.</li>
      <li>The next line is called <b>"Event"</b> where you simply enter the name of the event.</li>
      <li>The next two lines are <b>"Start Time"</b> & <b>"End Time"</b>.</li>
      <li>Click on <b>"Create event"</b> in order to save your event into calendar.</li>
    </ul>
    <br>
    <b>How to close specific day only partially?</b><br>
    <ul class="c">
      <li>Click <b>"+Add Event"</b></li>
      <li>Choose any day you want to block. For example, you want to block only morning hours within the specific date. </li>
      <li>Enter event name. </li>
      <li>Lets say your morning is already booked and future appointments are available only after 1 pm. To block out the time from 8AM to 1PM simply select these times and click on <b>"Create event".</b></li>
    </ul>    
    &nbsp; &nbsp;Now you can check your calendar and see that your morning hours on the day you have selected are now blocked out and appointments can be booked by your clients starting from 2 PM.<br><br>
   <span style="color:red;margin-top:10px;">IMPORTANT</span>: For event name please do not use words "<span style="color:red;">Fully booked</span>", "<span style="color:red;">Closed</span>" and "<span style="color:red;">Not available</span>" unless you want to block an entire day as the program already has these names built in and will automatically block the entire day if you enter any of these names. <br><br>
   <b>How to create event in the calendar that only I can see it but not my clients?</b>
   <ul class="a">
      <li>First click on <b>"+Add Event"</b>. </li>
      <li>A menu will open. </li>
      <li>Choose the date. </li>
      <li>You will see a tick box called <b>"Block out the day in your calendar"</b>, leave it blank. </li>
      <li>The next line is called <b>"Event"</b> where you simply enter the name of the event.</li>
      <li>The next two lines are <b>"Start Time"</b> & <b>"End Time"</b>. Do not enter any hours. If you select hours then these hours will be blocked and your client will be able to see that these hours are blocked.</li>
      <li>Click on <b>"Create event"</b>  in order to save your event into calendar.</li>
   </ul>
   <span style="color:red;margin-top:10px;">IMPORTANT</span>: For event name please do not use words "<span style="color:red;">Fully booked</span>", "<span style="color:red;">Closed</span>" and "<span style="color:red;">Not available</span>" unless you want to block an entire day as the program already has these names built in and will automatically block the entire day if you enter any of these names. <br><br>
   <b>How to delete event from my calendar?</b><br>First click on <b>"Event Editor"</b>. When you open your calendar you will see the list of your events. In the left column you will see tick boxes corresponding with each event. Select tick box with event you would like to delete and click on <b>"Delete event"</b>. ';
   
                   $ordertext='<div style="background: #fff !important; padding: 10px;">This options allows you to see all the orders that have been created within your form. Through this option you may not only view all the orders but also <b>edit, email to customer, print and convert your orders to invoices</b>.<br> To edit your order click on a field you want to edit.<br><br><span style="color:red;">IMPORTANT!</span> When you edit your order, including price changes per specific items within that specific order, you <b>must re-calculate</b> the new total manually. <br><br>When you edit an order you will notice that there is no button to save the order. In order to save the new edited version of the order you must click "Convert to Invoice" or "Email to Customer". "Email to customers" option will convert saved order to invoice and email edited order to your customer.</div>';
		   
		   $invoicetext='<div style="background: #fff !important;padding: 10px;">This options allows you to see all the invoices that have been created within your form. Through this option you may not only view all the invoices but also edit save, email to customer and print.<br>To edit your invoice click on a field you want to edit.<br><br><span style="color:red;">IMPORTANT!</span> When you edit your invoice, including price changes per specific items within that specific invoice, you <b>must re-calculate</b> the new total manually.</div>';
		   
		   $shrtcode = "<b>The following shortcode should be added to any page or post: [quotegenerator file='qgcode']</b>";
 
 
 
 
 
 
function showitem(){
   $fields_name = array("","Item name","Description","Price","Maximum Quantity (slider)","Step (per one slider move)","Image (URL)","Quantity Discount #1","Quantity Discount #2","Quantity Discount #3","Quantity Discount #4","Quantity Discount #5","Quantity Discount #6","Quantity Discount #7","Quantity Discount #8","Quantity Discount #9","Quantity Discount #10");

   global $wpdb;
   $tbname = "qg_itemx";
   $arrvalues = array('','0','0','0');
       //1 - Order Total Discount if Total Amount more than
       //2 - % of discount
       //3 Minimum Order
       for($xv=1; $xv<=3; $xv++){
	   $option_name = 'setting_qgx'.$xv;
	     if ( get_option($option_name) == false ) {
                  add_option( $option_name, $arrvalues[$xv], '', 'yes' );
	     }
       }
 //-----------------------------------------------------------
       
       
 if(isset($_GET['itemsnum'])){


    if($_GET['itemsnum']=="add"){
       $idn=1;$ids = '';
       $sql3 = "SELECT * FROM ".$wpdb->prefix.$tbname." WHERE visible='yes'";
       $wpdb->get_results($sql3);
       
          $rowSQL = "SELECT id FROM ".$wpdb->prefix.$tbname." WHERE id = (SELECT max(id) FROM ".$wpdb->prefix.$tbname.")";
          $rows = $wpdb->get_results( $rowSQL );
	  if(isset($rows[0]->id)){
	     $ids = intval($rows[0]->id)+1;
	  }
       
       if($wpdb->num_rows < 1){
	  $idn=1;$ids = 1;
       }else{
	  $rowSQL = "SELECT idn FROM ".$wpdb->prefix.$tbname." WHERE idn = (SELECT max(idn) FROM ".$wpdb->prefix.$tbname." WHERE visible='yes')";
          $rows = $wpdb->get_results( $rowSQL );
	  if(isset($rows[0]->idn)){
	     $idn = intval($rows[0]->idn)+1;
	  }
          //$idn = print_r($rows);
       }
       
      
        $meta = '<style>#buttn1{display:none;}#buttn2{display:none;}#itmtop{display:none;}</style>';
	$closurl="location.href='options-general.php?page=quotegenerator&links=items'";	
	$meta .= '<table class="tbl1"><tr><td colspan="2" style="font-family: Arial;font-size: 14px; background:#ff991d; padding:5px;margin-top:20px; color:#ffffff; text-align:center;width: 100%;">New Item</td>';
	$meta .= '<tr><td colspan="2" style="padding:0px;text-align:right;width: 100%;cursor:pointer;"><img src="'.sprintf("%s/quotegenerator/assets/img/no.png", plugins_url()).'" alt="no" onclick="'.$closurl.'"></td>';
	$meta .= '<tr><td class="tdadd">New Item line</td>';
	$meta .= '<td><input type="text" name="idn" id="idn" value="'.$idn.'" /></td></tr>';
	
	$meta.= '<tr><td class="tdadd">Input Type</td><td><select name="field_22" id="field_22" onchange="selectid0();"><option value="2">Input box </option>	<option value="4">Input box (independent)</option>     <option value="0">Check box </option>     <option value="1">Select box </option>	     <option value="3">Header </option>	    </select>	</td></tr>';
	
	$meta.= '<tr><td class="tdadd">Formula &nbsp; <a href="javascript:showim(1);">#1</a> &nbsp; <a href="javascript:showim(2);">#2</a> &nbsp; <a href="javascript:showim(3);">#3</a> &nbsp; <a href="javascript:showim(4);">#4</a> &nbsp; <a href="javascript:showim(5);">#5</a> &nbsp; <a href="javascript:showim(6);">#6</a>	<br><span>Click number for help.</span>	</td>';
	$meta.= '<td><select name="field_23" id="field_23" onchange="selectid();">   <option value="1">Formula #1 (Amount = Price * Quantity)</option>    <option value="4">Formula #4 (Amount = Price * Quantity1 * Quantity2)</option>    <option value="5">Formula #5 (Amount = Price * Quantity1 * Quantity2 * Quantity3)</option>    <option value="6">Formula #6 (Amount = Your Formula)</option></select>';
	
	$meta.= '<div id="f40" style="width:100%;padding:4px;text-align:center;">Amount = <input type="text" name="field_40" id="field_40" value="" placeholder="For example: (x+y)/2*z" /> <br> <input type="button" id="sbutton3" class="but" style="margin-top:8px;" onClick="scan_item();" value="Scan the Formula"></div>  </td></tr>';
	    
	
	$meta.= '<tr id="opt1"><td colspan="2" style="background:transparent;">Option #1</td></tr>';
	
	$meta.= '<tr><td class="tdadd">'.$fields_name[1].'</td>';
	$meta.= '<td><input type="text" name="field_1" id="field_1" value="" placeholder="Item name" />';
	$meta.= '<div id="add_name1" style="display:none;"><input type="text" name="field_1a" id="field_1a" placeholder="Name of slider #1" value="" /></div>';
	$meta.= '<div id="add_name2" style="display:none;"><input type="text" name="field_1b" id="field_1b" placeholder="Name of slider #2" value="" /></div>';
	$meta.= '<div id="add_name3" style="display:none;"><input type="text" name="field_1c" id="field_1c" placeholder="Name of slider #3" value="" /></div>';
	$meta.= '<input type="hidden" name="field_24" id="field_24" value="'.$ids.'" />';
	$meta.= '</td></tr>';
	
	$meta.= '<tr><td class="tdadd">'.$fields_name[2].'</td><td><textarea name="field_2" id="field_2" value="" rows="2"></textarea></td></tr>';
	
        for($y=3; $y<7; $y++){
	 
	  if($y==4){

	    $nod = "field_".$y;
	    $nod2 = "field_".$y.'b';
	    $nod3 = "field_".$y.'c';
            $meta.= '<tr class="tradd"><td class="tdadd">'.$fields_name[$y].'</td><td><input type="text" name="'.$nod.'" id="'.$nod.'" value="" />';
	    $meta.= '<div id="add_qty2" style="display:none;"><input type="text" name="'.$nod2.'" id="'.$nod2.'" placeholder="Quantity #2" value="" /></div>';
	    $meta.= '<div id="add_qty3" style="display:none;"><input type="text" name="'.$nod3.'" id="'.$nod3.'" placeholder="Quantity #3" value="" /></div>';
	    $meta.= '</td></tr>';
	  
	  }else{
            $nod = "field_".$y;
            $meta.= '<tr class="tradd"><td class="tdadd">'.$fields_name[$y].'</td><td><input type="text" name="'.$nod.'" id="'.$nod.'" value="" /></td></tr>';
	  }
        }
	
	$meta.= '<tr id="tradd3"><td colspan="2"><div id="formtable"></div></td></tr>';
	
	$meta.= '<tr id="sqd" style="background:transparent;"><td colspan="2" style="width:100%;"><a href="javascript:setdisc(1);">Set a Quantity Discount</a><br><table id="setdiscount1" class="tbl1" style="display:none;">';
	
        $fy = 7;
        for($y=7; $y<22; $y=$y+3){
            $nod = "field_".$y;
            $nod2 = "field_".($y+1);
            $nod3 = "field_".($y+2);
            $meta.= '<tr><td>'.$fields_name[$fy].'</td>';
	    $meta.= '<td>from QTY <input type="text" name="'.$nod.'" id="'.$nod.'" value="" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:70px;" /> to QTY <input type="text" name="'.$nod2.'" id="'.$nod2.'" value="" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:70px;" /> discount <input type="text" name="'.$nod3.'" id="'.$nod3.'" value="" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:50px;" />%</td></tr>';
            $fy++;
        }
	$fy = 12;
	for($y=25; $y<40; $y=$y+3){
            $nod = "field_".$y;
            $nod2 = "field_".($y+1);
            $nod3 = "field_".($y+2);
            $meta.= '<tr><td>'.$fields_name[$fy].'</td>';
	    $meta.= '<td>from QTY <input type="text" name="'.$nod.'" id="'.$nod.'" value="" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:70px;" /> to QTY <input type="text" name="'.$nod2.'" id="'.$nod2.'" value="" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:70px;" /> discount <input type="text" name="'.$nod3.'" id="'.$nod3.'" value="" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:50px;" />%</td></tr>';
            $fy++;
        }
	
	    
	    $meta.= '</table></td></tr>';
	    
	    
	  for($zx=2;$zx<=7;$zx++){  
	    
	    $meta.= '<tr style="background:transparent;"><td colspan="2"><div id="opt'.$zx.'" style="display:none;width:100%;"><table class="tbl1">';
	   
	    if($zx==2){$six=2;$eix=5;}
	     else if($zx==3){$six=6;$eix=10;}
	     else if($zx==4){$six=11;$eix=15;}
	     else if($zx==5){$six=16;$eix=20;}
	     else if($zx==6){$six=21;$eix=25;}
	     else if($zx==7){$six=26;$eix=30;}
	    
	    for($ix=$six;$ix<=$eix;$ix++){ //options 2-...
	    
	       $meta.= '<tr><td colspan="2" style="font-weight:bold;background:#e0e0e0;width:100%;">Option #'.$ix.'</td></tr>';
	       $meta.= '<tr><td class="tdadd">'.$fields_name[1].'</td>';
	       $meta.= '<td><input type="text" name="field_'.$ix.'_1" id="field_'.$ix.'_1" value="" />';
	       $meta.= '<input type="hidden" name="field_'.$ix.'_22" id="field_'.$ix.'_22" value="1" />';
	       $meta.= '<input type="hidden" name="field_'.$ix.'_24" id="field_'.$ix.'_24" value="'.$ids.'" /></td></tr>';
	      
	       $meta.= '<tr><td class="tdadd">'.$fields_name[2].'</td>';
	       $meta.= '<td><textarea name="field_'.$ix.'_2" id="field_'.$ix.'_2" value="" rows="2"></textarea></td></tr>';
	       
	       $nod = 'field_'.$ix.'_3';
               $meta.= '<tr id="'.$nod.'q"><td class="tdadd">'.$fields_name[3].'</td><td><input type="text" name="'.$nod.'" id="'.$nod.'" value="" /></td></tr>';
	       
	       $nod = 'field_'.$ix.'_6';
               $meta.= '<tr id="'.$nod.'q"><td class="tdadd">'.$fields_name[6].'</td><td><input type="hidden" name="field_'.$ix.'_4" id="field_'.$ix.'_4" value="0" /><input type="hidden" name="field_'.$ix.'_5" id="field_'.$ix.'_5" value="0" /><input type="text" name="'.$nod.'" id="'.$nod.'" value="" /></td></tr>';
	   
	   }
	    
	    $meta.= '<tr style="background:transparent;"><td colspan="2"><a href="javascript:addopt('.($zx+1).');">Add more options</a></td></tr>';
	    $meta.= '</table></div></td></tr>';
	    
	 }
	    
	    
	    

	    
            $meta .= '<tr style="background:transparent;"><td colspan="2" style="text-align:center;border:none;"><input type="button" id="sbutton1" class="but" onClick="save_item(0);" value="Save New Item"><input type="button" id="sbutton2" class="but" onClick="save_select();" value="Save Select box" style="display:none;"><input type="button" id="sbutton4" class="but" onClick="save_item2(0);" value="Save"></td></tr>';

            $meta .= '</table>';
	      
           return $meta;
	  
	  
	  
     
    }else if('delete'==substr($_GET['itemsnum'],0,6)){
           $delitem = explode("XXX",$_GET['itemsnum']);
           $nitem = intval($delitem[1]);
           $meta = '<style>#buttn1{display:none;}#buttn2{display:none;}</style><table class="tbl1">';
           $meta .= '<tr><td style="text-align:center;border:none;color:red;padding:15px;font-family: Arial;font-size: 14px;">Are you sure you want to delete  the item?</td></tr>';
           $meta .= '<tr><td style="text-align:center;border:none;"><input type="button" class="but" onClick="del_item('.$nitem.');" value="&nbsp; &nbsp; Yes &nbsp; &nbsp;"> &nbsp; &nbsp; <input type="button" class="but" onClick="ret_item();" value="&nbsp; &nbsp; No &nbsp; &nbsp;"></td></tr>';
           $meta .= '</table>';
           
           return $meta;
	  
    }
    
    }else{

        $nhid='';
	$sql21 = "SELECT * FROM ".$wpdb->prefix.$tbname." WHERE visible='yes'";
	$wpdb->get_results($sql21);
        $count_items = $wpdb->num_rows;
	if($count_items==0){
             $nhid='<style>#buttn1{display:none;}  .buttn3{display:none;} .tbl1{display:none;}</style>';
        }else{
             $nhid='<style>#buttn1{display:block;} .buttn3{display:inline;} .tbl1{display:block;}</style>';
        }
	$meta = $nhid.'<table class="tbl1">';
	$meta .= '<tr><th>Line</th><th>Item</th><th>Input Type</th><th>Formula &nbsp; <a href="javascript:showim(1);">#1</a> &nbsp; <a href="javascript:showim(2);">#2</a> &nbsp; <a href="javascript:showim(3);">#3</a> &nbsp; <a href="javascript:showim(4);">#4</a> &nbsp; <a href="javascript:showim(5);">#5</a> &nbsp; <a href="javascript:showim(6);">#6</a><br><span style="font-family: Arial;font-size: 10px;">Click number for help.</span></th> <th>Price</th> <th>Max Quantity<br>(for slider)</th> <th>Step<br>(for slider)</th> <th></th> <th></th></tr>';
	$sql2 = "SELECT * FROM ".$wpdb->prefix.$tbname." WHERE visible='yes' ORDER BY idn";
	$moderation2 = $wpdb->get_results($sql2, ARRAY_A);
	$last_row = '';
      
	foreach ( (array) $moderation2 as $row ) {
	 
	  $new_row = $row['field_24'];
	  if($new_row == $last_row){
	     $samesel='hidden';
	     $samesel2='display:none;';
	  }else{
	    $last_row = $row['field_24'];
	    $samesel='text';
	    $samesel2='';
	  }
	  $meta.= '<tr><td style="background:#ffffff;font-size:4px;height:4px;">&nbsp; &nbsp; </td></tr>';
          $meta.= '<tr><td rowspan="2"><input type="'.$samesel.'" name="idn'.$row['id'].'" id="idn'.$row['id'].'" value="'.$row['idn'].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : center;width:25px;height:100%;" /><input type="hidden" name="field_'.$row['id'].'_24" id="field_'.$row['id'].'_24" value="'.$row['field_24'].'" style="width:25px;height:100%;" /></td>';
	  
	     $quantityn = explode("!!!",$row['field_1']);
	     if($row["field_23"] == 6){
	        $meta.= '<td>';
	        for($fr1=0; $fr1<count($quantityn); $fr1++){
	            $meta.= '<div><input type="text" name="field_'.$row['id'].'_1_'.$fr1.'" id="field_'.$row['id'].'_1_'.$fr1.'" value="'.$quantityn[$fr1].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : left;width:190px;" /></div>';
	        }
	        $meta.= '</td>';
	      }else{
	       $meta.= '<td><input type="text" name="field_'.$row['id'].'_1" id="field_'.$row['id'].'_1" value="'.$quantityn[0].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : left;width:190px;" />';
	     
	       if(isset($quantityn[1])){
	       if($quantityn[1]==''){$ssqq='display:none;'; }else{$ssqq='';}
	          $meta.= '<div><input type="text" name="field_'.$row['id'].'_1a" id="field_'.$row['id'].'_1a" value="'.$quantityn[1].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : left;width:190px;'.$ssqq.'" /></div>';
	       }
	       if(isset($quantityn[2])){
	       if( $quantityn[2]==''){$ssqq='display:none;';}else{$ssqq='';}
	       $meta.= '<div><input type="text" name="field_'.$row['id'].'_1b" id="field_'.$row['id'].'_1b" value="'.$quantityn[2].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : left;width:190px;'.$ssqq.'" /></div>';
	       }
	       if(isset($quantityn[3])){
	       if( $quantityn[3]==''){$ssqq='display:none;';}else{$ssqq='';}
	       $meta.= '<div><input type="text" name="field_'.$row['id'].'_1c" id="field_'.$row['id'].'_1c" value="'.$quantityn[3].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : left;width:190px;'.$ssqq.'" /></div></td>';
	       }
	     }
	  
	  
	  $samesel3='';
	  
	  if($row["field_22"] == 0){
	     $td_option='Check box';
	     $td_option2=0;
	  }else if($row["field_22"] == 1){
	     $td_option='Select box';
	     $td_option2=1;
	  }else if($row["field_22"] == 3){
	     $td_option='Header';
	     $td_option2=3;
	     $samesel3='display:none;';
	  }else if($row["field_22"] == 4){
	     $td_option='Input box (independent)';
	     $td_option2=4;
	  }else{
	     $td_option='Input box';
	     $td_option2=2;
	  }
	  
	  $meta.= '<td style="font-family: Arial;font-size: 11px;margin:0px;text-align : center; width:80px;"><input type="hidden" name="field_'.$row['id'].'_22" id="field_'.$row['id'].'_22" value="'.$td_option2.'" /><input type="hidden" name="field_'.$row['id'].'_40" id="field_'.$row['id'].'_40" value="'.$row["field_40"].'" /><span style="'.$samesel2.'">'.$td_option.'</span></td>';
	  
          if($row["field_23"] == 5){
	     $td_option='Formula #5<br>Amount = Price * Quantity1 * Quantity2 * Quantity3';
	  }else if($row["field_23"] == 4){
	     $td_option='Formula #4<br>Amount = Price * Quantity1 * Quantity2';
	  }else if($row["field_23"] == 3){
	     $td_option='Formula #3<br>Additional Charge = Price% * Total Quantity';
	  }else if($row["field_23"] == 2){
	     $td_option='Formula #2<br>Additional Charge = Price% * Subtotal or Discount = -Price% * Subtotal';
	  }else{
	     $td_option='Formula #1<br>Amount = Price * Quantity';
	  }
	  
	  if($row['field_23']!=6){
	     $meta.= '<td><span style="'.$samesel2.$samesel3.'">'.$td_option.'</span><input type="hidden" name="field_'.$row['id'].'_23" id="field_'.$row['id'].'_23" value="'.$row['field_23'].'" /></td>';
	  }else{
	     $forml=explode("@@@@",$row["field_40"]);
	     $meta.= '<td><span style="'.$samesel2.'">Amount = '.$forml[0].'</span><input type="hidden" name="field_'.$row['id'].'_23" id="field_'.$row['id'].'_23" value="'.$row['field_23'].'" /></td>';
	  }

  
	  
	   if($row['field_23']!=6){
	     $meta.= '<td><input type="text" name="field_'.$row['id'].'_3" id="field_'.$row['id'].'_3" value="'.$row['field_3'].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : center; width:55px;'.$samesel3.'" /></td>';
	     $quantity = explode("!!!",$row['field_4']);
	     $meta.= '<td style="text-align : center;"><input type="text" name="field_'.$row['id'].'_4" id="field_'.$row['id'].'_4" value="'.$quantity[0].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : center; width:55px;'.$samesel2.''.$samesel3.'" />';
	     if(isset($quantity[1])){
	     if($quantity[1]==''){$ssqq='display:none;';}else{$ssqq='';}
	     $meta.= '<div><input type="text" name="field_'.$row['id'].'_4b" id="field_'.$row['id'].'_4b" value="'.$quantity[1].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : center; width:55px;'.$ssqq.' '.$samesel2.''.$samesel3.'" /></div>';
	     }
	     if(isset($quantity[2])){
	     if($quantity[2]==''){$ssqq='display:none;';}else{$ssqq='';}
	     $meta.= '<div><input type="text" name="field_'.$row['id'].'_4c" id="field_'.$row['id'].'_4c" value="'.$quantity[2].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : center; width:55px;'.$ssqq.' '.$samesel2.''.$samesel3.'" /></div>';
	     }
	     $meta.= '</td>';
	     $meta.= '<td><input type="text" name="field_'.$row['id'].'_5" id="field_'.$row['id'].'_5" value="'.$row['field_5'].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : center; width:50px;'.$samesel2.''.$samesel3.'" /></td>';
	   
	   }else{ // Formula #6
	     $quantity = explode("!!!",$row['field_4']);
	     $suantity = explode("!!!",$row['field_5']);
	     $qntt='';
	     $sptt='';
	     for($fr6=0; $fr6<count($quantity); $fr6++){
	         $qntt.= '<div><input type="text" name="field_'.$row['id'].'_4_'.$fr6.'" id="field_'.$row['id'].'_4_'.$fr6.'" value="'.$quantity[$fr6].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : center; width:55px;'.$samesel2.''.$samesel3.'" /></div>';
	         $sptt.= '<div><input type="text" name="field_'.$row['id'].'_5_'.$fr6.'" id="field_'.$row['id'].'_5_'.$fr6.'" value="'.$suantity[$fr6].'" style="font-family: Arial;font-size: 11px;margin:0px;text-align : center; width:50px;'.$samesel2.''.$samesel3.'" /></div>';
	      
	     }
	     $meta.= '<td><input type="hidden" name="field_'.$row['id'].'_3" id="field_'.$row['id'].'_3" value="'.$row['field_3'].'" /></td>';
	     $meta.= '<td style="text-align : center;">'.$qntt.'</td>';
	     $meta.= '<td style="text-align : center;">'.$sptt.'</td>';
	   }
	     
	     $meta.='<td rowspan="2" style="text-align : center;padding:4px;"><input type="button" class="but" onClick="save_itm('.$row['id'].');" value="Save"></td>';
	          
	     $meta.= '<td rowspan="2"><a href="options-general.php?page=quotegenerator&links=items&itemsnum=deleteXXX'.$row['field_24'].'"><img src="'. sprintf("%s/quotegenerator/assets/img/no.png", plugins_url()).'" style="width:26px;height:26px;'.$samesel2.'" alt="Delete"></a></td></tr>';
	  
	     $meta.= '<tr><td colspan="6"><a href="javascript:showdes('.$row['id'].');">Show Description</a>';
	    
	     $meta.= '<span style="margin:0px 0px 0px 150px;padding:0px;'.$samesel3.'">Image URL <input type="text" name="field_'.$row['id'].'_6" id="field_'.$row['id'].'_6" style="font-family: Arial;font-size: 11px;text-align : left; width:420px;padding:0px 0px 0px 5px;" value="'.$row['field_6'].'" /></span>'; // Image
	     
	     $meta.= '<br><div id="destable'.$row['id'].'" style="width:100%;display:none;margin:0px;"><textarea name="field_'.$row['id'].'_2" id="field_'.$row['id'].'_2" rows="3" style="font-family: Arial;font-size: 10px;text-align : justify;width:100%;">'.$row['field_2'].'</textarea> </div>    ';
	  
	  
	  
	  
	  if($row["field_4"] != 0 && $row["field_4"] != 1 ){ //Quantity Discount Table
	  
	    $meta.= '<a href="javascript:showdisc('.$row['id'].');">Open Quantity Discount Table</a> <div id="dtable'.$row['id'].'" style="width:100%;padding:2px; display:none; margin-top:-5px;"><table class="tbl1" style="background:#f9f9f9;"><tr><th>QTY Discount #1</th> <th>QTY Discount #2</th> <th>QTY Discount #3</th> <th>QTY Discount #4</th> <th>QTY Discount #5</th><th>QTY Discount #6</th> <th>QTY Discount #7</th> <th>QTY Discount #8</th> <th>QTY Discount #9</th> <th>QTY Discount #10</th></tr><tr>';
          
	    $fy = 7;
            for($y=7; $y<22; $y=$y+3){
              $nod = "field_".$row['id'].'_'.$y;       $nods = "field_".$y;
              $nod2 = "field_".$row['id'].'_'.($y+1);  $nods2 = "field_".($y+1);
              $nod3 = "field_".$row['id'].'_'.($y+2);  $nods3 = "field_".($y+2);
	    
	      $td_show="text";
	      if($row["field_4"] == 0 || $row["field_4"] == 1 ){$td_show="hidden";}
	    
              $meta.= '<td class="inpdisctd">from <input type="'.$td_show.'" name="'.$nod.'" id="'.$nod.'" value="'.$row[$nods].'" class="inpdisc" /><br>to &nbsp; &nbsp; <input type="'.$td_show.'" name="'.$nod2.'" id="'.$nod2.'" value="'.$row[$nods2].'" class="inpdisc" /><br>discount <input type="'.$td_show.'" name="'.$nod3.'" id="'.$nod3.'" value="'.$row[$nods3].'" class="inpdisc" />%</td>';
              $fy++;
            }
	    $fy = 12;
            for($y=25; $y<40; $y=$y+3){
              $nod = "field_".$row['id'].'_'.$y;       $nods = "field_".$y;
              $nod2 = "field_".$row['id'].'_'.($y+1);  $nods2 = "field_".($y+1);
              $nod3 = "field_".$row['id'].'_'.($y+2);  $nods3 = "field_".($y+2);
	    
	      $td_show="text";
	      if($row["field_4"] == 0 || $row["field_4"] == 1 ){$td_show="hidden";}
	    
              $meta.= '<td class="inpdisctd">from <input type="'.$td_show.'" name="'.$nod.'" id="'.$nod.'" value="'.$row[$nods].'" class="inpdisc" /><br>to &nbsp; &nbsp; <input type="'.$td_show.'" name="'.$nod2.'" id="'.$nod2.'" value="'.$row[$nods2].'" class="inpdisc" /><br>discount <input type="'.$td_show.'" name="'.$nod3.'" id="'.$nod3.'" value="'.$row[$nods3].'" class="inpdisc" />%</td>';
              $fy++;
            }
	    
	    
	    $meta.= '</tr></table></div></td>';
	  } // End of Quantity Discount Table
	    
	  $meta.= '</tr>';
	  
       }
      $meta .= '</table>';
      return $meta;
    }
   
}





function showitem2(){
 global $wpdb;
 $payment_value = array("0","USD","","","Required deposit: $",'<img src="https://www.paypalobjects.com/webstatic/en_US/i/btn/png/gold-rect-paypalcheckout-34px.png" alt="PayPal Checkout" style="width:147px;">');
 for($x=0; $x<count($payment_value); $x++){
        $option_name = 'setting_qgpayment'.$x;
        
        if ( get_option($option_name) !== false ) {
             $payment_value[$x] = get_option($option_name);
        }  else  {
            $deprecated = null;
            $autoload = 'yes';
            add_option( $option_name, $payment_value[$x], $deprecated, $autoload );
        }

 }       
 
    $metaxa = '<table class="tbl2" style="width:100%;">';
    $metaxa .= '<tr style="background: #efefef;"><td style="padding:5px;">&nbsp;The name of a field</td><td style="padding:5px;"><input type="text" name="ppc4"  value="'.$payment_value[4].'" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:260px;" /></td></tr>';
    
    $metaxa .='<tr style="background: #efefef;"><td style="padding:5px;">&nbsp;Deposit (%)</td><td style="padding:5px;">';
    $metaxa .='<select name="ppc0" style="width:100px;"><option value="'.$payment_value[0].'"> '.$payment_value[0].'% </option><option value="0"> 0 </option><option value="5"> 5% </option> <option value="10"> 10% </option> <option value="15"> 15% </option> <option value="20"> 20% </option> <option value="25"> 25% </option> <option value="30"> 30% </option> <option value="35"> 35% </option> <option value="40"> 40% </option> <option value="45"> 45% </option> <option value="50"> 50% </option> <option value="55"> 55% </option><option value="60"> 60% </option> <option value="65"> 65% </option> <option value="70"> 70% </option> <option value="75"> 75% </option> <option value="80"> 80% </option><option value="85"> 85% </option><option value="90"> 90% </option><option value="95"> 95% </option> <option value="100"> 100% </option> </select>';
    $metaxa .='<div style="color:#000000; font-size: 12px;text-align: left;padding: 3px;">What is the minimum deposit you require before you will start.</div></td></tr>';
    
    $metaxa .='<tr style="background: #efefef;"><td style="padding:5px;">&nbsp;Currency</td><td style="padding:5px;">
	<input type="text" name="ppc1" id="ppc1" value="'.$payment_value[1].'" style="font-family: Arial;font-size: 12px;margin:0px;text-align : center;width:100px;" />	<select name="ppc11" id="ppc11" style="width:140px;margin-left:20px;" onchange="set_paypal();"><option value="0"> Choose from list </option>	 <option value="USD"> USD </option>	 <option value="CAD"> CAD </option>	 <option value="GBP"> GBP </option>	 <option value="AUD"> AUD </option>	 <option value="NZD"> NZD </option>	 <option value="EUR"> EUR </option>	 <option value="JPY"> JPY </option>        </select></td></tr>';
    $metaxa .= '<tr><td colspan="2">&nbsp;</td></tr>';
     
    $metaxa .= '<tr><td colspan="2" style="font-family: Arial; font-size: 12px; background:#ff991d; padding:5px; color:#ffffff; text-align:center;"> Pay Pal settings </td></tr>';
    $metaxa .= '<tr style="background: #efefef;"><td style="padding:5px;">&nbsp;PayPal email address</td><td style="padding:5px;"><input type="text" name="ppc2"  value="'.$payment_value[2].'" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:200px;" /></td></tr>';
    $metaxa .= '<tr style="background: #efefef;"><td style="padding:5px;">&nbsp;PayPal image</td><td style="padding:5px;"><textarea name="ppc5" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:260px;">'.stripcslashes($payment_value[5]).'</textarea></td></tr>';
    $metaxa .= '<tr><td colspan="2">&nbsp; </td></tr>';
        
    $metaxa .= '<tr><td colspan="2" style="font-family: Arial; font-size: 12px; background:#ff991d; padding:5px; color:#ffffff; text-align:center;"> Stripe settings </td></tr>';
    $metaxa .= '<tr><td colspan="2">&nbsp;</td></tr>';
    $metaxa .= '<tr style="background: #efefef;"><td style="padding:5px;">&nbsp;Stripe live publishable key</td><td style="padding:5px;"><input type="text" name="ppc3"  value="'.$payment_value[3].'" style="font-family: Arial;font-size: 12px;margin:0px;text-align : left;width:260px;" /></td></tr>';
     
     
    $metaxa .= '</table>';
    return $metaxa;
 
}



function showitem4(){
   global $wpdb;   $option_name = 'setting_qg_time';
   $time_value = '07:00 AM;08:00 AM;09:00 AM;10:00 AM;11:00 AM;12:00 PM;01:00 PM;02:00 PM;03:00 PM;04:00 PM;05:00 PM;06:00 PM;07:00 PM';
        
	if ( get_option($option_name) == false ) {
             add_option( $option_name, $time_value, '', 'yes' );
        }else{
	    $time_value = get_option($option_name);
	}
	
    $time_field = explode(";",$time_value); // create array
    function sortFunction( $a, $b ) { return strtotime($a) - strtotime($b);}
    usort($time_field, "sortFunction");


    $metaxa = '<table class="tbl1"><tr><th colspan="3" style="background:#ff991d; padding:5px; color:#ffffff; text-align:center;"> Time </th></tr>';
    
    for ($i=0; $i<count($time_field); $i++) {
         $metaxa .= '<tr><td style="text-align:center;">'.($i+1).'</td><td style="text-align:center;"><input type="text" name="ppc'.$i.'" value="'.$time_field[$i].'" style="font-family: Arial;font-size: 12px;text-align : left;width:100%;" /></td>';
	 $metaxa .= '<td style="width:36px;padding:2px;text-align:center;"><a href="javascript:save_time('.$i.');"><img src="'. sprintf("%s/quotegenerator/assets/img/no.png", plugins_url()).'" alt="no"></a></td></tr>';
    }
        $metaxa .= '<tr><td colspan="3" style="font-family: Arial;font-size: 14px;font-weight:bold;"> &nbsp; Add New: <input type="text" name="ppc'.$i.'" value="" style="font-family: Arial;font-size: 12px;text-align : left;width:140px;" /><input type="hidden" name="ppct" id="ppct" value="'.($i+1).'" /></td></tr>';
    
  $metaxa .= '</table>';
  return $metaxa;  
}

?>