<?php 
if ($_SESSION['cust_id']=='') {
?>
<script language="javascript" type="text/javascript">
          needToConfirm = false;
          window.location="orders_no_return.php";
</script>
<?php
}
else {
$preset=$_GET['preset'];
$preset_list_name=$_GET['preset_list_name'];

if ($preset==1) {
	 $table_name = $_SESSION['db_prefix']."_preset_list";
	 $preset_query = "SELECT * FROM $table_name WHERE preset_list_name = '".$preset_list_name."'  ";
	 $preset_result = mySQL_query($preset_query);
     $preset_num = mysql_num_rows($preset_result);
    // $preset = mysql_result($preset_result, $i, " ");<br>
	
	$table_name1 = $_SESSION['db_prefix']."_preset_list";
		$table_name2 = $_SESSION['db_prefix']."_order_job_lines_temp";
    	$copy_query = "INSERT INTO $table_name2 (store_item_id, quantity, user_name ) SELECT store_item_id, preset_quantity, '".$_SESSION['username']."'  FROM $table_name1 WHERE preset_list_name = '".$preset_list_name."' ";
   		execsql($copy_query);
}


$table_name = $_SESSION['db_prefix']."_order_job_lines_temp WHERE user_name = '".$_SESSION['username']."' AND store_item_id>0";
$line_query = "SELECT * FROM $table_name ";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

$table_name = $_SESSION['db_prefix']."_order_job_lines_temp WHERE user_name = '".$_SESSION['username']."' AND store_item_id='0'";
$line2_query = "SELECT * FROM $table_name ";
$line2_result = mySQL_query($line2_query);
$line2_num = mysql_num_rows($line2_result);


$table_name = $_SESSION['db_prefix']."_preset_list";
$store_item_query = "SELECT preset_list_name  FROM $table_name WHERE list_type = 'Orders' GROUP BY preset_list_name ORDER BY preset_list_name ASC";
	$store_item_result = execsql($store_item_query);
	$store_item_num = mysql_num_rows($store_item_result);
	$w = 0;
	$arrId31 = array ();
	$arrName31 = array ();
	while ($w < $store_item_num) {
		$arrId31[$w] = mysql_result($store_item_result, $w, "preset_list_name");
		$arrName31[$w] = mysql_result($store_item_result, $w, "preset_list_name");
		$w++;
	}

$special_orders='yes';
include('../include/store_item_select_header_no_price.php');
?>

 
<script language="javascript">
function addRow2(dataTable2) {
 
            var table2 = document.getElementById(dataTable2);
 
            var rowCount = table2.rows.length;
            var row = table2.insertRow(rowCount);
			var line_no = rowCount-1;
 
            var cell1 = row.insertCell(0);
            var element21 = document.createElement("input");
            element21.type = "checkbox";
            element21.name="line_checkbox7"+line_no;
			element21.id="line_checkbox7"+line_no;
			/*element21.checked="checked";*/
            cell1.appendChild(element21);
			 
            var cell2 = row.insertCell(1);
            var element22 = document.createElement("input");
            element22.type = "text";
            element22.name = "item_text7"+line_no;
			element22.className = "text300";
			element22.value = "";
			element22.onchange = function(){document.getElementById("line_checkbox7"+line_no).checked = "checked";}
			cell2.appendChild(element22);
			
			   
            var cell4 = row.insertCell(2);
			cell4.align="right";
            var element23 = document.createElement("input");
            element23.type = "text";
            element23.name = "quantity_text7"+line_no;
			element23.className = "text60";
			element23.value = "";
			element23.style = "text-align:right";
			element23.onkeypress = function isNumberKey(evt)
       								{
          							var charCode = (evt.which) ? evt.which : event.keyCode
          							if (charCode != 46 && charCode > 31 
            						&& (charCode < 48 || charCode > 57))
             						return false;
 
          							return true;
       								}
									;
			element23.onkeyup = function() {this.value = this.value.replace (/(\...).*/, '$1')};
			cell4.appendChild(element23);
			
					
			var cell5 = row.insertCell(3);
			cell5.align="right";
			var element26 = document.createElement("input");
            element26.type = "text";
            element26.name = "amount_text7"+line_no;
			element26.className = "text60";
			element26.onkeypress = function isNumberKey(evt)
       								{
          							var charCode = (evt.which) ? evt.which : event.keyCode
          							if (charCode != 46 && charCode > 31 
            						&& (charCode < 48 || charCode > 57))
             						return false;
 
          							return true;
       								}
									;
			element26.onkeyup = function() {this.value = this.value.replace (/(\...).*/, '$1')};
			element26.style = "text-align:right";		

            var element24 = document.createElement("input");
            element24.type = "hidden";
            element24.name = "line_num2";
			element24.value = rowCount;
            						
			cell5.appendChild(element26);
            cell5.appendChild(element24);
			
			var element28 = document.createElement("script");
			element28.setAttribute('type', 'text/javascript');
			element28.innerHTML="var frmvalidator  = new Validator('form1');frmvalidator.EnableMsgsTogether();for (i = 0; i < 50; i++) {frmvalidator.addValidation('item_text7'+i,'req','-  item on special order line '+(i+1)+'.');frmvalidator.addValidation('quantity_text7'+i,'req','- quantity on special order line '+(i+1)+'.');frmvalidator.addValidation('amount_text7'+i,'req','- price on special order line '+(i+1)+'.');}"; 
			document.getElementsByTagName('head').item(0).appendChild(element28);
	
			element21.onmouseup = function() {
				 if (document.getElementById('line_checkbox7'+line_no).checked) {
                         element22.style.background = '#F0F0F0';
						 element23.style.background = '#F0F0F0';
						 element26.style.background = '#F0F0F0';
						 element22.value = '.';
						 element23.value = '.';
						 element26.value = '.';
						 element22.disabled = true;
						 element23.disabled = true;
						 element26.disabled = true;
						 
                } else {
                        element22.style.background = '#FFF';
						element23.style.background = '#FFF';
						element26.style.background = '#FFF';
						element22.value = '';
						element23.value = '';
						element26.value = '';
						element22.disabled = false;
						element23.disabled = false;
						element26.disabled = false;
						 
                }
				};
			
}
</script> 

</head>

<?php include('../include/wait.php') ?>

<body onLoad=" MM_showHideLayers('wait','','hide'); initCS(); " onFocus="MM_showHideLayers('wait','','hide');" >


<form id="form1" name="form1" method="POST" action="compileJobWizbase.php?p=4&s=3">
<div class="wizard_page_middle_frame">
<div id="preset_list_div" <?php if ($preset==2) { ?> hidden="true" <?php } ?> >
Load preset list: 
  <select name="preset_select" class="select160" onChange="needToConfirm = false; window.location.href= this.form.preset_select.options[this.form.preset_select.selectedIndex].value" >
    <option value=""></option>
    <?php
        	for ($i = 0; $i < count($arrId31); $i++) {
    		echo "<option value=compileJobWizbase.php?p=3&s=&preset=1&preset_list_name=".$arrId31[$i].">".$arrName31[$i]."</option>";
	}
?>
  </select>
&nbsp;&nbsp;<img src="../images/exclamation_mark_red_small.png" width="10" height="16">Selecting a preset list will clear the store item list below.</div>  

<?php
$temp_table_name = 'man_order_job_lines_temp';
include('../include/store_item_select_table_no_price.php'); 
?> 
					
<div class="wizard_frame"><br>
    <table id="dataTable2" width="630" border="1" style="border-collapse:collapse;">
    <?php
	
	   if ($line2_num==0) {
	       
		   $a71='.';
		   $a72='.';
		   $a73='0';
		   	   }
	   else {
		   
		   $a71 = mysql_result($line2_result, 0, "item_name");
		   $a72 = mysql_result($line2_result, 0, "quantity");
		   $a73 = mysql_result($line2_result, 0, "price");
		   
	   }
		?>
    <thead> 
        <tr>
          <td>&nbsp;</td>
          <td>Special order</td>
          <td align="center">Quantity</td>
          <td align="center">Unit price</td>
        </tr>
        </thead>
        <script>
			 function check_it7() {
				 if (document.getElementById('line_checkbox70').checked) {
                         document.getElementById('item_text70').style.background = '#F0F0F0';
						 document.getElementById('quantity_text70').style.background = '#F0F0F0';
						 document.getElementById('amount_text70').style.background = '#F0F0F0';
						 document.getElementById('item_text70').value = '.';
						 document.getElementById('quantity_text70').value = '.';
						 document.getElementById('amount_text70').value = '.';
						 document.getElementById('item_text70').disabled = true;
						 document.getElementById('quantity_text70').disabled = true;
						 document.getElementById('amount_text70').disabled = true;
						 
                } else {
                        document.getElementById('item_text70').style.background = '#FFF';
						document.getElementById('quantity_text70').style.background = '#FFF';
						document.getElementById('amount_text70').style.background = '#FFF';
						document.getElementById('item_text70').value = '';
						document.getElementById('quantity_text70').value = '';
						document.getElementById('amount_text70').value = '';
						document.getElementById('item_text70').disabled = false;
						document.getElementById('quantity_text70').disabled = false;
						document.getElementById('amount_text70').disabled = false;
                }
				}
		     </script>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox70" id="line_checkbox70"  onMouseUp="check_it7()" <?php if ($a71!='.') { ?> checked="checked"  <?php } ?> /></td>
          <td width="294"><input  name="item_text70" type="text" class="text300" id="item_text70" value="<?php echo $a71 ?>" onChange="document.getElementById('line_checkbox70').checked=true;" onFocus="document.getElementById('item_text70').value=''; document.getElementById('quantity_text70').value=''; document.getElementById('amount_text70').value='';"/></td>
          <td width="100" align="right"><input  name="quantity_text70" type="text" class="text60" id="quantity_text70" value="<?php echo $a72 ?>" style="text-align:right" onKeyPress="return isNumberKey(event)"/></td>
            <td width="100" align="right"><input  name="amount_text70" type="text" class="text60" id="amount_text70" value="<?php echo number_format($a73, 2, '.', ','); ?>" onKeyPress="return isNumberKey(event)" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1')" style="text-align:right"/><input type="hidden" name="line_num2" id="line_num2" value="1" >
         </td>    
            <!--<input name="textfield0" type="text" id="textfield0" size="5" value="1"></td>-->
        </tr>
        <?php
		$i=1;
		while ($i<$line2_num) {
		   $a71 = mysql_result($line2_result, $i, "item_name");
		   $a72 = mysql_result($line2_result, $i, "quantity");
		   $a73 = mysql_result($line2_result, $i, "price");
		   //$a74 = mysql_result($line2_result, $i, "order_no");
		?>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox7<?php echo $i ?>" id="line_checkbox7<?php echo $i ?>" checked="checked" <?php if ($a71!='') { ?>  <?php } ?> onMouseUp="{
				 if (document.getElementById('line_checkbox7<?php echo $i ?>').checked) {
                         document.getElementById('item_text7<?php echo $i ?>').style.background = '#F0F0F0';
                         document.getElementById('quantity_text7<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('amount_text7<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('item_text7<?php echo $i ?>').value = '.';
                         document.getElementById('quantity_text7<?php echo $i ?>').value = '.';
						 document.getElementById('amount_text7<?php echo $i ?>').value = '.';
						 document.getElementById('item_text7<?php echo $i ?>').disabled = true;
                         document.getElementById('quantity_text7<?php echo $i ?>').disabled = true;
						 document.getElementById('amount_text7<?php echo $i ?>').disabled = true;
						 
                } else {
                         document.getElementById('item_text7<?php echo $i ?>').style.background = '#FFF';
                         document.getElementById('quantity_text7<?php echo $i ?>').style.background = '#FFF';
						 document.getElementById('amount_text7<?php echo $i ?>').style.background = '#FFF';
                         document.getElementById('item_text7<?php echo $i ?>').value = '';
                         document.getElementById('quantity_text7<?php echo $i ?>').value = '';
						 document.getElementById('amount_text7<?php echo $i ?>').value = '';
						 document.getElementById('item_text7<?php echo $i ?>').disabled = false;
                         document.getElementById('quantity_text7<?php echo $i ?>').disabled = false;
						 document.getElementById('amount_text7<?php echo $i ?>').disabled = false;
                }
				}
                "/></td>
          <td width="294"><input  name="item_text7<?php echo $i ?>" type="text" class="text300" id="item_text7<?php echo $i ?>" value="<?php echo $a71 ?>"  onChange="document.getElementById('line_checkbox7<?php echo $i ?>').checked=true;"/></td>
          <td width="144" align="right"><input  name="quantity_text7<?php echo $i ?>" type="text" class="text60" id="quantity_text7<?php echo $i ?>" value="<?php echo $a72 ?>" onKeyPress="return isNumberKey(event)" style="text-align:right"/></td>
            <td width="144" align="right"><input  name="amount_text7<?php echo $i ?>" type="text" class="text60" id="amount_text7<?php echo $i ?>" value="<?php echo number_format($a73, 2, '.', ',') ?>" onKeyPress="return isNumberKey(event)" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1')" style="text-align:right"/>              <input type="hidden" name="line_num2" id="line_num2" value="<?php echo $line2_num?>"></td>
        </tr>
        <?php
		$i++;
		}
		?>
        
  </table>
  
    <input type="button" class="imagebutton" onClick="addRow2('dataTable2')" value="Add line" />
    <div align="right">
      <label class="label_small">To delete a line: uncheck line box.</label></div>
  
					
				
  </div>

  
<div class="wizard_frame">
  <table width="590" height="50" align="center" id="table_button_bar">
          <tr>
            <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','compileJobWizbase.php?s=&p=2'); return document.MM_returnValue; ;return document.MM_returnValue"/></td>
            <td width="115">&nbsp;</td>
            <td width="99"><span class="wizard">
              <input name="error" type="hidden" id="error" value="0" />
              <input name="p" type="hidden" id="p" value="3" />
              <input name="s" type="hidden" id="s" value="3" />
            </span></td>
            <td width="125" align="left"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false;  cancel_confirmation(1, '../orders/orders_main.php');" value="Cancel" /></td>
            <td width="110" align="left"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
          </tr>
      </table>
    </div>
  </div>
</form>
</div>

<!--form validation-->
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
     
  for (i = 0; i < 50; i++) {
	frmvalidator.addValidation("store_item_text"+i,"req","- store item on store line "+(i+1)+".");
	frmvalidator.addValidation("quantity_text"+i,"req","- quantity  on store line "+(i+1)+".");
  	
	/*frmvalidator.addValidation("item_text7"+i,"req","- store item on special order line "+(i+1)+".");
	frmvalidator.addValidation("quantity_text7"+i,"req","- quantity  on special order line"+(i+1)+".");
  	frmvalidator.addValidation("amount_text7"+i,"req","- price on special store order "+(i+1)+".");*/
	
}	
  </script>
</body>

<?php
}
?>