<?
function display_order($result) {
$myrow = mysql_fetch_array($result);
?>
<table width=400 >
 <tr><td class=section colspan=2>Orders</td></tr>
 <tr><td class=menu>Order Number:</td><td bgcolor=white><? echo $myrow["ordernumber"]; ?></td></tr>
 <tr><td class=menu>Status:</td><td bgcolor=white><? echo $myrow["status"]; ?></td></tr>
 <tr><td class=menu>Stage:</td><td bgcolor=white><? echo $myrow["stage"]; ?></td></tr>
 <tr><td class=menu>Start Date:</td><td bgcolor=white><? echo $myrow["startdate"]; ?></td></tr>
 <tr><td class=menu>End Date:</td><td bgcolor=white><? echo $myrow["enddate"]; ?></td></tr>
 <tr><td class=menu>Comments:</td><td bgcolor=white width="75%" height="20"><? echo $myrow["comments"]; ?></td></tr>
<?php }
?>
<?
function display_orderline_data($result) {
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
?>
<tr onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>">
  <td><? echo $myrow["userid"]; ?></td>
  <td><? echo $myrow["partid"]; ?></td>
  <td><? echo $myrow["quantity"]; ?></td>
  <td><? echo $myrow["status"]; ?></td>
  <td><? echo $myrow["startdate"]; ?></td>
  <td><? echo $myrow["comments"]; ?></td>
  <td>
    <a href="edit.php?op=orderlineedit&line_id=<? echo $myrow["line_id"]; ?>">Edit</a>&nbsp;
    <a href="viewdetail.php?line_id=<? echo $myrow["line_id"]; ?>&orderid=<? echo $myrow["orderid"]; ?>">View</a>&nbsp;
    <a href="delete.php?op=deleteorderline&line_id=<? echo $myrow["line_id"]; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
 </td>
</tr>
<?
	}
}
?>

<?
function display_part_data($result,$start) {
include ("config.php");
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
	$gross_margin = 0;
	$avg_price = 0;
	$costOnHand = 0;
	$units_sold = 0;
	$sales = 0;
	$qty_on_hand = 0;
	$recomended_qty = 0;
	$ARS = 0;
	$qty_remaining = 0;
	$cogs_sold = 0;
	
	$partno = $myrow["partno"];
	$partid2 = $myrow["partid"];
	$units_sold = $myrow["unit_sold"];
	$sales = $myrow["sales"];
	$qty_on_hand = $myrow["qty_on_hand"];
	$qty_available = $myrow["qty_available"];
	
	$user = $_SESSION['s_username'];
$queryOrg = "SELECT * FROM `users` WHERE `username` = '$user' LIMIT 1;";
//echo $query;
$resultOrg = mysql_query($queryOrg,$db);
while($myrowOrg = mysql_fetch_array($resultOrg))
{
$organization = $myrowOrg['organization'];
}
	
$query3 = "SELECT cost, costRMB FROM orderlines WHERE partid = '" . $partid2 . "' ORDER BY `line_id` DESC LIMIT 1;"; 
 $orderResult = mysql_query($query3,$db);
 while ($row = mysql_fetch_array($orderResult, MYSQL_NUM))
 {
 $cost_part = $row[0];
 $costOnHand = $row[0];
 $cost_part_rmb = $row[1];
 }
 
/*$query3 = "SELECT units_sold,sales,qty_on_hand FROM `peachtree` WHERE itemID = '" . $partno . "' ORDER BY `primary` DESC LIMIT 1;"; 
 $orderResult = mysql_query($query3,$db);
 while ($row = mysql_fetch_array($orderResult, MYSQL_NUM))
 {
 $units_sold = $row[0];
	$sales = $row[1];
	$qty_on_hand = $row[2];
 }*/
 
 if ($units_sold > 0)
 		$avg_price = number_format(($sales/$units_sold),2,'.','');
 		else
 		$avg_price = 0;
		
 $query1 = "SELECT quantity,qtyaccepted,qtyReceived FROM `orderlines` WHERE STATUS <> 'Closed' AND STATUS <> 'Cancelled' AND (partid='" . $partid2 . "' or partid= '" . $partno . "');";
	//echo $query1;
    $result3 = mysql_query($query1,$db);
	//$rowOnOrder = mysql_fetch_array($result3, MYSQL_NUM);
	$qty_on_order = 0;
	$qty_accept = 0;
	$qty_received = 0;
	while($rowOnOrder = mysql_fetch_array($result3))
     {
		    if ( $rowOnOrder[0] != NULL )
			{
			$qty_on_order += $rowOnOrder[0];
			$qty_accept += $rowOnOrder[1];
			$qty_received += $rowOnOrder[2];
			}
	  }
	  
	  $qty_remaining = $qty_on_order - $qty_received; //remove the qty received from order
	  
  //******************* INVENTORY DAYS ********************************  
  $days_until_out = 0;
	if ($partno != "")
	{
	$priorDay = "";
	$noCount = 0;
	$countDays = 0;
	$markFirst = "";
	$timeNow = time();
	//$timeSixMonths =  time() - (6 * 4.35 * 7 * 24 * 60 * 60);  //6 months back
	$timeYear =  time() - (52 * 7 * 24 * 60 * 60);  //1 year back
	$queryDays = "SELECT * FROM `parts_timeline` WHERE partno ='" . $partno . "' AND dateChange > $timeYear ORDER BY dateChange ASC;"; //$timeSixMonths
	//echo $queryDays . "<br>";
	$k = 0;
	$resultDays = mysql_query($queryDays);
	$totalRows = mysql_num_rows($resultDays);
	//echo "Total rows: " . $totalRows . "<br>";
	
	 //checking if new product...
				$queryDaysBf = "SELECT * FROM `parts_timeline` WHERE partno ='" . $partno . "' AND dateChange < $timeYear ORDER BY dateChange ASC;";  //$timeSixMonths
				$resultDaysBf = mysql_query($queryDaysBf);
				$totalRowsBf = mysql_num_rows($resultDaysBf);
				
while($rowDays = mysql_fetch_array($resultDays))
	{
	$qty_timeline = $rowDays["qty_on_hand"];
	$dateOnCheck = $rowDays["dateChange"];
	
	//echo "row #: " . $k . "<br>";
	
	$k++;
		if ($markFirst != 1)
		{
			$markFirst = 1; //tag that the first has been recorded
			if ($qty_timeline > 0 && $k >= $totalRows)
			{
				if ($totalRowsBf > 0)  //if not new product then count back...
				{
				$countDays += number_of_days($timeNow,$timeYear); //if poistive then count all the way until now -$timeSixMonths for 6 month change
				//echo "days: " . $countDays . "<br>";
				}
			$priorDay = $dateOnCheck;
			}
			else if ($qty_timeline > 0)
			{
				if ($totalRowsBf > 0)  //if not new product then count back...
				{
				$countDays += number_of_days($dateOnCheck,$timeYear);  //$timeSixMonths for 6 month change
 			//echo "days: " . $countDays . "<br>";
				}
			$priorDay = $dateOnCheck;
			}
			else
			{
			$noCount = 1;
			}
			continue;
		}
		
		if ($k >= $totalRows && $noCount == 0)
		{
			if ($qty_timeline > 0)
			{
			$countDays += number_of_days($timeNow,$priorDay); //if poistive then count all the way until now
		//	echo "days: " . $countDays . "<br>";
			}
			else
			{
			$countDays += number_of_days($dateOnCheck,$priorDay); //if none on hand then count days up to that point
			}
			continue;
		}
		
		if ($qty_timeline > 0 && $noCount == 1) //start counting the days when back to on hand positive
		{
			$priorDay = $dateOnCheck;
			$noCount = 0;
		}
		else if ($qty_timeline <= 0 && $noCount == 0)  //count the days on change to 0
		{
			$countDays += number_of_days($dateOnCheck,$priorDay);
			$noCount = 1;
		}
	}
	
	//echo "total days: " . $countDays . "<br>";
	//$units_sold_6m = $units_sold/2;  //find the average sales in the past 6 months
	//echo $units_sold_6m . "<br>";
	//$ARS = $units_sold_6m/$countDays;
	if($countDays > 0)
	$ARS = $units_sold/$countDays;
	else $ARS = 0;
	//echo $ARS . "<br>";
	if ($ARS > 0 && $qty_on_hand > 0)
	$days_until_out = round($qty_on_hand/$ARS);
	else $days_until_out = 0;
    //echo $days_until_out . "<br>";
 
 		$qty_remaining = $qty_on_order - $qty_received; //remove the qty received from order
		//$qty_on_order = $myrow["qty_on_order"]; //THIS IS UPDATED FROM orderline table
		//$qty_accept = $myrow["qty_accept"]; //THIS IS ADDED FROM orderline table
		
		/**days until the stock will run out including the on order qty**/
		if ($ARS > 0 && $qty_remaining > 0)
		$days_with_on_order = round($qty_remaining/$ARS) + $days_until_out;
		else $days_with_on_order = $days_until_out;
		/**days until the stock will run out including the on order qty**/
	}
  //*********************  INVENTORY DAYS  *************************

 	//******************* EARN & TURN  ********************************/
	if ($costOnHand > 0 && $avg_price > 0)
	{
 	$gross_margin = (($avg_price - $costOnHand)/$avg_price)*100; //GROSS MARGIN
 	$cogs_sold = $costOnHand*$units_sold; //COST OF GOOD SOLD
 	$queryAvg = "SELECT AVG(qty_on_hand) AS avg_on_hand FROM `parts_timeline` WHERE `partno` = '" . $partno . "' AND dateChange > " . $timeYear . ";";
 	$resultAvg = mysql_query($queryAvg);
    $rowAvg = mysql_fetch_array($resultAvg);
 	$on_hand_avg = $rowAvg["avg_on_hand"];
 	
		if($on_hand_avg > 0)
		{	
		//echo "on_hand_avg = " . $on_hand_avg . " * costOnHand = " . $costOnHand;
		$avg_inv_cost = $on_hand_avg * $costOnHand; //Average Inv Costs
		
		$earnNturn = $gross_margin * ($cogs_sold / $avg_inv_cost);
		}
		else
		{
		$onHandMessage = "NO AVERAGE ON HAND";
		}
	
	}
	else
	{
	$costMessage = "NO COST INFORMATION";
	}
 	//echo "<br>" . $partid . " EN= " . $earnNturn . " = " . "GROSSMARGIN(" . $gross_margin . ") * (COGS" . $cogs_sold  . " / " . $avg_inv_cost . " AVG INV)";
 	//******************* END EARN & TURN ******************************/

?>
<tr onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>">
  <td>
  U.S. - <? echo $myrow["partno"] . " <a href=\"javascript:GlobalPopUp('monthly-current-pn.php?partno=" . $myrow["partno"] . "&total=" . $myrow["unit_sold"] . "',800,200);\"><i>view monthly sales &raquo;</i></a>";
  ?>
  <BR> China - <? echo $myrow["pnchina"]; ?> 
  
  <?php
  if($myrow["closeout"] == '1')
		echo "<BR><BR><b style=\"color:#293b74\">CLOSEOUT!</b>";
  if($myrow["active"] == '0')
  {
		echo "<BR><BR><b style=\"color:#ae0011\">DISCONTINUED!</b>";
		  echo '<BR><a href="#" onClick="reAddComm(' . $partid2 . ')" style="color:#293b74; font-size:11px; font-weight:bold;">[remove from discontinued &raquo;]</a>'; 
	}
  else
  {
  echo '<BR><BR><a href="#" onClick="removeComm(' . $partid2 . ')" style="color:#AE0011; font-size:11px; font-weight:bold;">[set as discontinued &raquo;]</a>';
  }
 ?>
 <BR><BR> 
 <?php
 if ($partno != "")
	{
 //recomended qty to order based on 2 motnhs + 35% growth supply time (90 days)
		$recomended_qty = round(($ARS * 1.35) * 90) - (($qty_available + $qty_remaining) - round($ARS * 90));
		if ($recomended_qty > 0)
		{  $flag = "#1c9327; font-weight:bold;"; }
		else { $recomended_qty = 0; $flag = "#000000"; }
 ?>
 <b> Qty on Order:  </b> <?= $qty_on_order;?>&nbsp;&nbsp; <b> Received: </b> <?=$qty_received; ?>&nbsp;&nbsp; <b> Remaining: </b> <?= $qty_remaining; ?><br>
   <b> Days left with on Order: </b> <? echo  $days_with_on_order; ?><br>
  <b>INV. Days: </b> <?= $countDays; ?> &nbsp;&nbsp; <b> ARS: </b><? echo  number_format($ARS,2,'.',','); ?> &nbsp;&nbsp; <b style="color:<?= $flag;?>"> To Order: </b> <? echo  $recomended_qty; 
  }
  ?>
  <br><span style="
  <?php 
		   if ($costOnHand > 0)
			{
			  if($on_hand_avg > 0)
			  {
			   if ($earnNturn >100) echo "color:#293b74;"; 
			   else echo "color:#AE0011;";?>  font-size:10px; font-weight:bold;">Eearn & Turn: <?= number_format($earnNturn,1,'.',','); 
			  }
			  else
			  {
			  echo "font-size:10px; font-weight:bold;\">" . $onHandMessage;
			  }
			   
		   }
		   else
		   {
		   echo "font-size:10px; font-weight:bold;\">" . $costMessage;
		   }
		   ?>
		   </span>
 <BR><BR>
<!-- <a href="javascript:GlobalPopUp('chart/<?= $partid2;?>.png',650,338);"><img src="chartSmall/<?= $partid2;?>.png" border="0" /></a> -->
<a href="javascript:popUpBigWindow('files/<? echo $myrow["artimage"]; ?>');"> 
  <img border="0" src='files/thumb/<? echo $myrow["artimage"]; ?>'></a>
  <BR><BR> 
  <?php
  if ($partno != "")
	{
	?>
  <b>
  Total Qty. Sold: <?php 
  echo "<a href=\"javascript:GlobalPopUp('monthly-current-pn.php?partno=$partno&total=$units_sold',800,200);\">" . $units_sold . "</a>"; ?> - $<? echo  number_format($myrow["sales"],0,'.',','); 
  ?>
  </b>
  <?php
  }
  ?>
 <BR><BR>
<form action="new-onhand.php" method="POST">
<input type="hidden" name="author" value="<?php echo $_SESSION['s_username'];?>">
<input type="hidden" name="partid" value="<?= $myrow["partid"]; ?>">
<input type="hidden" name="partno" value="<?= $myrow["partno"]; ?>">
<b>Qty on Hand:</b>&nbsp;<input name="onhand" value="<?php 
if ($partno != "")
	{
echo $qty_on_hand; 
}
else echo '0';
?>" size="5"> <b>Stock days left: <? echo  $days_until_out; ?></b><br>
<?php echo "<b>Qty Available: " . $qty_available . "</b>"; 
if ($partno != "")
	{
mysql_select_db($dbname2,$db);
		$queryCount = "SELECT SUM(qty) FROM `fullfilment` WHERE `SKU` LIKE '" . $myrow["partno"] . "%' AND `status` = 'Backorder';"; // GROUP BY `SKU`
								$resultCount = mysql_query($queryCount);
								$rowCount = mysql_fetch_array($resultCount);
								//echo $queryCount;
								$countBackorder = $rowCount[0];
								if ($countBackorder > 0)
								echo "&nbsp;&nbsp;<img src=\"images/alert.png\" style=\"float:right;margin:10px;\"><br><a href=\"https://www.overstockart.net/ccm/fullfilment.php?q=" . $partno . "&status=Backorder\" target=\"_blank\" style=\"color:#ae0011;font-weight:bold;float:right;margin:10px;\">" . $countBackorder . " On Backorder!</a>";
								
$now = time();
  
		$queryCount = "SELECT SUM(qty) FROM `eventItems` WHERE `SKU` LIKE '" . $myrow["partno"] . "%' AND `DateEnd` > $now;";
								$resultCount = mysql_query($queryCount);
								$rowCount = mysql_fetch_array($resultCount);
								//echo $queryCount;
								$countEventItems = $rowCount[0];
								if ($countEventItems > 0)
								echo "<div style=\"clear: both\";></div><div style=\"float:right;padding:10px;\"><img src=\"images/clock.svg\" align=\"right\" style=\"margin-top:10px; margin-right:10px; margin-bottom:10px;\"><a href=\"eventItems.php?partnosearch=" . $partno . "\" target=\"_blank\" style=\"color:#293b74;font-weight:bold;\">" . $countEventItems . " On Hold for Events</a></div>";
								
									
		$queryCount = "SELECT SUM(qty) AS sumQty,SUM(qtyReceived) AS sumRec FROM `amazonvOrders` WHERE `SKU` LIKE '" . $partno . "%' AND `qty` > `qtyReceived`";
									$resultCount = mysql_query($queryCount);
									$rowCount = mysql_fetch_array($resultCount);
									//echo $queryCount;
									$countAmazonOrder = $rowCount[0];
									$countAmazonRec = $rowCount[1];
									$countAmazonItems = $countAmazonOrder - $countAmazonRec;
									if ($countAmazonItems > 0)
									echo "<div style=\"clear: both\";></div><div style=\"float:right;padding:10px;\"><img src=\"images/amazon.png\" align=\"right\" style=\"margin-top:10px; margin-right:10px; margin-bottom:10px;\"><a href=\"http://www.overstockart.net/sorter/amazon-sku-list.php?qty_filter=Yes&sortby=date_for_sort&filterPO=all&filterFC=all&filter1=" . $partno . "&submitreport=Run+Items\" target=\"_blank\" style=\"color:#333333;font-weight:bold;\">" . $countAmazonItems . " On Order by Amazon</a></div>";
			
		
		mysql_select_db($dbname,$db);
	}
?>

<br><br>
<b>Add Message:</b><br><input name="message" ><input type="submit" value="Change On Hand"><br>
<input type="checkbox" value="yes" name="sendMail" checked="checked">Send Notification<br>
<input type="checkbox" name="question" value="Yes" />&nbsp;<b>Please check if this is a question.</b><br>

</form>
<br><br>
 <?php
// Here we will get it to show the replies
// This query selects the replies from the database where the thread ID matches the thread $_GET value.
$sql = "SELECT * FROM `replies-parts` WHERE thread = '" . $myrow["partid"] . "' ORDER BY `id` DESC";
$resultM = mysql_query($sql);
if (mysql_num_rows($resultM) > 0)
{
echo "<b>Message Board:</b><br>";
echo "<div id=\"message_column\">";
}
// Now we are getting our results and making them an array
while($r = mysql_fetch_array($resultM)) {
$i == 0 ? $color = "#293b74" : $color = "#AE0011";
$i == 0 ? $i = 1 : $i = 0;

if ($r[question] == "Yes") $color = "#0d9d09"; 

// Everything within the two curly brackets can read from the database using $r[]
// We need to convert the UNIX Timestamp entered into the database for when a thread...
// ... is posted into a readable date, using date().
$posted = date("jS M Y h:i",$r[posted]);
// Now this shows the thread with a horizontal rule after it.
echo "<b style=\"color:$color;\">$r[message]</b><BR>Posted by <b style=\"color:$color;\">$r[author]</b> on $posted";

if ($r[question] == "Yes" && $r[answer] == "" ) echo " <b style=\"color:$color;\">Open Question!!!</b>";
echo "<hr>";

// End of Array
}
if (mysql_num_rows($resultM) > 0)
{
echo "</div>";
}
?>
  </td>
  <td>
  <? echo $myrow["paintingname"]; ?> <br><br> <b>Part Type: <? echo $myrow["ProductType"]; ?></b> <BR><?php if(isset($myrow["CountDays"])) echo '<b>Manuafaturing Days:<br>' . $myrow["CountDays"] . ' Days</b>'; ?><br><br><?php if(isset($myrow["cost"])) echo 'Cost of Painting: <br>$' . $cost_part . ' ' . $cost_part_rmb . 'RMB'; ?><br><br><?php if(isset($myrow["artist"])) echo 'Artist: ' . $myrow["artist"]; ?> 
  <BR /><iframe src="http://www.overstockart.net/sorter/onsite.php?partno=<? echo $myrow["partno"]; ?>"  border="0" scrolling="no" width="180" align="middle" frameborder="0" height="30"></iframe>
  </td>
  <td align="center">  
  <div id="order_column">
 <?php  
 
 if ($organization != "US")
{
 if ($partno != "")
 {
 $query3 = "SELECT `orderlines`.orderid, cost, `orderlines`.status, quantity, `organization` FROM orderlines LEFT JOIN `orders` ON `orderlines`.`orderid` = `orders`.`orderid` WHERE (partid= '" . $partno . "' OR partid = '" . $partid2 . "') AND `organization` = '$organization' ORDER BY `line_id` DESC;"; 
 }
 else
 {
 $query3 = "SELECT `orderlines`.orderid, cost, `orderlines`.status, quantity, `organization` FROM orderlines LEFT JOIN `orders` ON `orderlines`.`orderid` = `orders`.`orderid` WHERE partid = '" . $partid2 . "' AND `organization` = '$organization' ORDER BY `line_id` DESC;"; 
 }
}
else
{
if ($partno != "")
 {
 $query3 = "SELECT `orderlines`.orderid, cost, `orderlines`.status, quantity, `organization` FROM orderlines LEFT JOIN `orders` ON `orderlines`.`orderid` = `orders`.`orderid` WHERE partid= '" . $partno . "' OR partid = '" . $partid2 . "' ORDER BY `line_id` DESC;"; 
 }
 else
 {
 $query3 = "SELECT `orderlines`.orderid, cost, `orderlines`.status, quantity, `organization` FROM orderlines LEFT JOIN `orders` ON `orderlines`.`orderid` = `orders`.`orderid` WHERE partid = '" . $partid2 . "' ORDER BY `line_id` DESC;"; 
 }
}
 
 
 //echo $query3;
 $orderResult = mysql_query($query3,$db);
 while ($row = mysql_fetch_array($orderResult, MYSQL_NUM))
 {
 $orderid = $row[0];
 $cost = $row[1];
  $status = $row[2];
    $qty = $row[3];
	$supplier = $row[4];
 $query4 = "SELECT ordernumber FROM orders WHERE orderid = '" . $orderid . "';";
 $orderResult2 = mysql_query($query4,$db);
 $orderRow = mysql_fetch_array($orderResult2,MYSQL_NUM);
 $orderName = $orderRow[0];
 echo "<a href=\"viewdetail.php?orderid=" . $orderid . "\">" . $orderName . "</a><br />" .  $supplier  . "<br />Qty: " .  $qty  . "<br />Cost: " . $cost . "<br />";
 if ($status != "Closed") $status_color = "#ae0011";
 else $status_color = "#000000";
 echo "Status: <br><b style=\"color:" . $status_color . ";\">" . $status . "</b><br /><br />"; 
 }
 ?>
 </div>
 </td>
  <td align="center">  
   <div id="ship_column">
 <?php  
 if ($organization != "US")
{
 if ($partno != "")
 {
 $query3 = "SELECT `shipment_line`.`shipid`, `qty` FROM `shipment_line` LEFT JOIN `shipment` ON `shipment_line`.`shipid` = `shipment`.`shipid` WHERE (partid= '" . $partno . "' OR partid = '" . $partid2 . "') AND `organization` = '$organization' ORDER BY `lineid` DESC;"; 
 }
 else
 {
 $query3 = "SELECT `shipment_line`.`shipid`, `qty` FROM `shipment_line` LEFT JOIN `shipment` ON `shipment_line`.`shipid` = `shipment`.`shipid` WHERE partid = '" . $partid2 . "' AND `organization` = '$organization' ORDER BY `lineid` DESC;"; 
 }
}
else
{
 if ($partno != "")
 {
 $query3 = "SELECT shipid, qty FROM `shipment_line` WHERE partid= '" . $partno . "' OR partid = '" . $partid2 . "' ORDER BY `lineid` DESC;"; 
 }
 else
 {
 $query3 = "SELECT shipid, qty FROM `shipment_line` WHERE partid = '" . $partid2 . "' ORDER BY `lineid` DESC;"; 
 }
}
// echo $query3;
 
 $orderResult = mysql_query($query3,$db);
 while ($row = mysql_fetch_array($orderResult, MYSQL_NUM))
 {
 $shipid = $row[0];
 $shipqty = $row[1];
 $query4 = "SELECT shipno, completed, organization FROM `shipment` WHERE shipid = '" . $shipid . "';";
 $shipResult2 = mysql_query($query4,$db);
 $shipRow = mysql_fetch_array($shipResult2,MYSQL_NUM);
 $shipName = $shipRow[0];
 $completed = $shipRow[1];
 $supplier = $shipRow[2];
 if ($completed == 'YES') 
 { 
 	$completed = "Complete";
 	$status_color = "#000000";
 }
 else  
 {
 	$completed = "Not Complete";
	$status_color = "#ae0011";
 }
 echo "<a href=\"viewdetail-shipment.php?shipid=" . $shipid . "\">" . $shipName ."</a><br />" . $supplier . "<br />Qty: " . $shipqty . "<br />";
 echo "Status: <b style=\"color:" . $status_color . ";\">" . $completed . "</b><br /><br />"; 
 }
 ?>
 </td>
  <td><? echo $myrow["artsize"]; ?></td>
  <td><a href="javascript:popUpBigWindow('files/<? echo $myrow["artimage"]; ?>');"> 
  <img border="0" src='files/thumb/<? echo $myrow["artimage"]; ?>'></a>
  <br><br>
 <?php 
 if ($myrow["datePhoto"] != "")
 echo "Last updated: <br>" . date("jS M Y",$myrow["datePhoto"]) . "<br> by: <br>" . $myrow["lastUpdateBy"]; 
 ?>
 </div>
  </td>
   <td>
    <a href="edit.php?op=partedit&partid=<? echo $myrow["partid"]; ?>&start=<? echo $start; ?>">Edit</a>&nbsp;
    <a href="viewparts.php?partid=<? echo $myrow["partid"]; ?>">View</a>&nbsp;
    <a href="delete.php?op=deletepart&partid=<? echo $myrow["partid"]; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
 </td>
</tr>
<?php
 }
}
?>
<?
function display_order_data($result) {
include ("config.php");
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
	
    if ($_SESSION["highlightId"] == $myrow["orderid"]) { $color = "#e28080";
	                                         $class = "lastvisited";
											 }
	//Number of paintings in order...
	$result2 = mysql_query("SELECT COUNT(line_id) FROM orderlines WHERE orderid = '" . $myrow["orderid"] ."' GROUP BY orderid",$db);											 
	
		$row2 = mysql_fetch_array($result2, MYSQL_NUM);
		$numPaintings = $row2[0];						
		
$query4 = "SELECT color FROM `status_special` WHERE `status`= '" . $myrow["status"] . "';"; 
		$status1 = mysql_query($query4,$db);
		$row = mysql_fetch_array($status1, MYSQL_NUM);
		//echo $query4;
		$status2 = $row[0];		
		
$query5 = "SELECT color FROM `stage` WHERE `stage`= '" . $myrow["stage"] . "';"; 
		$stage1 = mysql_query($query5,$db);
		$row = mysql_fetch_array($stage1, MYSQL_NUM);
		//echo $query5;
		$stage2 = $row[0];				 
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail.php?orderid=<? echo $myrow["orderid"]; ?>"><? echo $myrow["ordernumber"]; ?></a></td>  <td> <?php echo $numPaintings; ?></TD>

  <TD><? echo $myrow["organization"]; ?></TD>
 <!-- <TD><b style="color:<? echo $status2; ?>;"><? echo $myrow["status"]; ?></b></TD>
  <TD><b style="color:<? echo $stage2; ?>;"><? echo $myrow["stage"]; ?></b></TD>
  <TD><? echo $myrow["startdate"]; ?></TD>
  <TD><? echo $myrow["enddate"]; ?></TD>
  <TD>
    <a href="edit.php?op=orderedit&orderid=<? echo $myrow["orderid"]; ?>">Edit</a>&nbsp;
    <a href="viewdetail.php?orderid=<? echo $myrow["orderid"]; ?>">View</a>&nbsp;
    <a href="orderline.php?orderid=<? echo $myrow["orderid"]; ?>">Summary</a>&nbsp;
    <a href="parts.php?orderid=<? echo $myrow["orderid"]; ?>">Paintings</a>
   <a href="delete.php?op=deleteorder&orderid=<? echo $myrow["orderid"]; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
  </TD>-->
</TR>
<?php
 }
 ?>
<!-- </table>
 </div>-->
 <?php
}
?>
<?
function display_order_data_open_orders($result) {
include ("config.php");
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
	
    if ($_SESSION["highlightId"] == $myrow["orderid"]) { $color = "#e28080";
	                                         $class = "lastvisited";
											 }
	//Number of paintings in order...
	$result2 = mysql_query("SELECT COUNT(line_id) FROM orderlines WHERE orderid = '" . $myrow["orderid"] ."' GROUP BY orderid",$db);											 
	
		$row2 = mysql_fetch_array($result2, MYSQL_NUM);
		$numPaintings = $row2[0];						
		
$query4 = "SELECT color FROM `status_special` WHERE `status`= '" . $myrow["status"] . "';"; 
		$status1 = mysql_query($query4,$db);
		$row = mysql_fetch_array($status1, MYSQL_NUM);
		//echo $query4;
		$status2 = $row[0];		
		
$query5 = "SELECT color FROM `stage` WHERE `stage`= '" . $myrow["stage"] . "';"; 
		$stage1 = mysql_query($query5,$db);
		$row = mysql_fetch_array($stage1, MYSQL_NUM);
		//echo $query5;
		$stage2 = $row[0];				 
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail.php?orderid=<? echo $myrow["orderid"]; ?>"><? echo $myrow["ordernumber"]; ?></a> &nbsp; <span style="font-size:10;">Number of Paintings: &nbsp; <?php echo $numPaintings; ?></span></TD>
 <TD><b style="color:<? echo $status2; ?>;"><? echo $myrow["status"]; ?></b></TD>
  <TD><b style="color:<? echo $stage2; ?>;"><? echo $myrow["stage"]; ?></b></TD>
  <TD><? echo $myrow["startdate"]; ?></TD>
  <TD><? echo $myrow["enddate"]; ?></TD>
    <TD><? echo $myrow["organization"]; ?></TD>
  <TD>
    <a href="edit.php?op=orderedit&orderid=<? echo $myrow["orderid"]; ?>">Edit</a>&nbsp;
    <a href="viewdetail.php?orderid=<? echo $myrow["orderid"]; ?>">View</a>&nbsp;
    <a href="orderline.php?orderid=<? echo $myrow["orderid"]; ?>">Summary</a>&nbsp;
    <a href="parts.php?orderid=<? echo $myrow["orderid"]; ?>">Paintings</a>
   <a href="delete.php?op=deleteorder&orderid=<? echo $myrow["orderid"]; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
  </TD>
</TR>
<?php
 }
 ?>
 </table>
 <?php
}
?>
<?
function display_dev_data($result) {
include ("config.php");
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
	
    if ($_SESSION["highlightDevId"] == $myrow["devid"]) { $color = "#e28080";
	                                         $class = "lastvisited";
											 }
	//Number of paintings in order...
	$result2 = mysql_query("SELECT COUNT(line_id) FROM developmentlines WHERE devid = '" . $myrow["devid"] ."' GROUP BY devid",$db);											 
	
		$row2 = mysql_fetch_array($result2, MYSQL_NUM);
		$numPaintings = $row2[0];						
		
$query4 = "SELECT color FROM `status_special` WHERE `status`= '" . $myrow["status"] . "';"; 
		$status1 = mysql_query($query4,$db);
		$row = mysql_fetch_array($status1, MYSQL_NUM);
		//echo $query4;
		$status2 = $row[0];		
		
$query5 = "SELECT color FROM `stage` WHERE `stage`= '" . $myrow["stage"] . "';"; 
		$stage1 = mysql_query($query5,$db);
		$row = mysql_fetch_array($stage1, MYSQL_NUM);
		//echo $query5;
		$stage2 = $row[0];				 
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail-dev.php?devid=<? echo $myrow["devid"]; ?>"><? echo $myrow["devnumber"]; ?></a> &nbsp; </TD>  <td><span style="font-size:10;"><?php echo $numPaintings; ?></span>  </td>
  
   <TD> <a href="viewdetail-dev.php?devid=<? echo $myrow["devid"]; ?>">View</a></TD>
   
</TR>
<?php
 }
 ?>
<!-- </table>
 </div>-->
 <?php
}
?>
<?
function display_dev_data_full($result) {
include ("config.php");
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
	
    if ($_SESSION["highlightDevId"] == $myrow["devid"]) { $color = "#e28080";
	                                         $class = "lastvisited";
											 }
	//Number of paintings in order...
	$result2 = mysql_query("SELECT COUNT(line_id) FROM developmentlines WHERE devid = '" . $myrow["devid"] ."' GROUP BY devid",$db);											 
	
		$row2 = mysql_fetch_array($result2, MYSQL_NUM);
		$numPaintings = $row2[0];						
		
$query4 = "SELECT color FROM `status_special` WHERE `status`= '" . $myrow["status"] . "';"; 
		$status1 = mysql_query($query4,$db);
		$row = mysql_fetch_array($status1, MYSQL_NUM);
		//echo $query4;
		$status2 = $row[0];		
		
$query5 = "SELECT color FROM `stage` WHERE `stage`= '" . $myrow["stage"] . "';"; 
		$stage1 = mysql_query($query5,$db);
		$row = mysql_fetch_array($stage1, MYSQL_NUM);
		//echo $query5;
		$stage2 = $row[0];				 
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail-dev.php?devid=<? echo $myrow["devid"]; ?>"><? echo $myrow["devnumber"]; ?></a> &nbsp; <span style="font-size:10;">Number of Paintings: &nbsp; <?php echo $numPaintings; ?></span></TD>
   <TD> <? echo $myrow["status"]; ?></TD>
   <TD> <? echo $myrow["startdate"]; ?></TD>
   <TD> <a href="viewdetail-dev.php?devid=<? echo $myrow["devid"]; ?>">View</a></TD>
</TR>
<?php
 }
 ?>
 </table>
 <?php
}
?>
<?
function display_specialorder_quote($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
	
	$query4 = "SELECT color FROM `status_special` WHERE `status`= '" . $myrow["status"] . "';"; 
		$status1 = mysql_query($query4,$db);
		$row = mysql_fetch_array($status1, MYSQL_NUM);
		//echo $query4;
		$status2 = $row[0];
		
	if ($_SESSION["highlightIdQuote"] == $myrow["specialorderid"]) { $color = "#e28080";
	                                         $class = "lastvisited";
											 }
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail-special.php?specialorderid=<? echo $myrow["specialorderid"]; ?>"><? echo $myrow["specialordername"]; ?></a></TD>
  <TD><? echo $myrow["customername"]; ?></TD>
  <!--<TD><? echo $myrow["paintingname"]; ?><br /> <? echo $myrow["artsize"]; ?></TD>
  <TD><?php if(isset($myrow["price"])) echo 'Price: $' . $myrow["price"]; ?><br>
  <?php if(isset($myrow["cost"])) echo 'Cost: $' . $myrow["cost"]; ?>
  </TD>
  <TD><? echo $myrow["partnous"]; ?></TD>
  <TD><? echo $myrow["startdate"]; ?></TD>
  <TD><? echo $myrow["enddate"]; ?></TD>-->
  <TD><b style="color:<? echo $status2; ?>;"><? echo $myrow["status"]; ?></b></TD>
 <!-- <TD>
    <a href="edit.php?op=specialorderedit&specialorderid=<? echo $myrow["specialorderid"]; ?>">Edit</a>&nbsp;
    <a href="viewdetail-special.php?specialorderid=<? echo $myrow["specialorderid"]; ?>">View</a>&nbsp;
    <a href="delete.php?op=deleteorder&orderid=<? echo $myrow["orderid"]; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a> -->
  </TD>
</TR>
<?
 }
 ?>
<!-- </table>
 </div>-->
 
 <?php
}
?>
<?
function display_specialorder_data_open_orders($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
	
	$query4 = "SELECT color FROM `status_special` WHERE `status`= '" . $myrow["status"] . "';"; 
		$status1 = mysql_query($query4,$db);
		$row = mysql_fetch_array($status1, MYSQL_NUM);
		//echo $query4;
		$status2 = $row[0];
		
	if ($_SESSION["highlightIdSpecial"] == $myrow["specialorderid"]) { $color = "#e28080";
	                                         $class = "lastvisited";
											 }
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail-special.php?specialorderid=<? echo $myrow["specialorderid"]; ?>"><? echo $myrow["specialordername"]; ?></a></TD>
  <TD><? echo $myrow["customername"]; ?></TD>
  <TD><? echo $myrow["paintingname"]; ?><br /> <? echo $myrow["artsize"]; ?></TD>
  <TD><?php
//  $vendor_org = $myrow["organization"];
  
$user = $_SESSION['s_username'];
$queryOrg = "SELECT * FROM `users` WHERE `username` = '$user' LIMIT 1;";
echo $query;
$resultOrg = mysql_query($queryOrg,$db);
while($myrowOrg = mysql_fetch_array($resultOrg))
{
$organization = $myrowOrg['organization'];
}

  if($organization == "US")
  {
   if(isset($myrow["price"])) echo 'Price: $' . $myrow["price"] . "<br>"; 
  }
   ?>
  <?php if(isset($myrow["cost"])) echo 'Cost: $' . $myrow["cost"]; ?>
  </TD>
  <TD><? echo $myrow["partnous"]; ?></TD>
  <TD><? echo $myrow["startdate"]; ?></TD>
  <TD>
   <?php
  $today = time();
  list($day, $month, $year) = split('/',$myrow["enddate"]);
  $endDateFormated = $year . "-" . $month . "-" . $day;
  $endDateCompare = strtotime($endDateFormated);
  $endDateSystem = date("M j, Y", $endDateCompare);
  if($today > $endDateCompare)
  $endColor = "#AE0011";
  else $endColor = "#333333";
  echo '<b style="color:' . $endColor . '">' . $endDateSystem . '</b>';
  ?>
  </TD>
   <TD><? echo $myrow["organization"]; ?></TD>
  <TD><b style="color:<? echo $status2; ?>;"><? echo $myrow["status"]; ?></b></TD>
 <!-- <TD>
    <a href="edit.php?op=specialorderedit&specialorderid=<? echo $myrow["specialorderid"]; ?>">Edit</a>&nbsp;
    <a href="viewdetail-special.php?specialorderid=<? echo $myrow["specialorderid"]; ?>">View</a>&nbsp;
    <a href="delete.php?op=deleteorder&orderid=<? echo $myrow["orderid"]; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a> -->
  </TD>
</TR>
<?
 }
 ?>
<!-- </table>-->
 <?php
}
?>
<?
function display_specialorder_data($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
	
	$query4 = "SELECT color FROM `status_special` WHERE `status`= '" . $myrow["status"] . "';"; 
		$status1 = mysql_query($query4,$db);
		$row = mysql_fetch_array($status1, MYSQL_NUM);
		//echo $query4;
		$status2 = $row[0];
		
	if ($_SESSION["highlightIdSpecial"] == $myrow["specialorderid"]) { $color = "#e28080";
	                                         $class = "lastvisited";
											 }
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail-special.php?specialorderid=<? echo $myrow["specialorderid"]; ?>"><? echo $myrow["specialordername"]; ?></a></td>    <td>  <?     echo  $myrow["startdate"];    $d=$myrow["startdate"];
//    echo $d;    list($day, $month, $year) = split('/',$d);//    $endDateFormated = $year . "-" . $month . "-" . $day;//    $endDateCompare = strtotime($endDateFormated);//    $endDateSystem = date("M j, Y", $endDateCompare);//    echo $endDateSystem;//    echo date("M j,Y",mktime(1,1,1,$month,$day,$year));//      echo $day." ".$month." ".$year;  ?></TD>
  <?php  $today = time();  list($day, $month, $year) = split('/',$myrow["enddate"]);  $endDateFormated = $year . "-" . $month . "-" . $day;  $endDateCompare = strtotime($endDateFormated);  $endDateSystem = date("M j, Y", $endDateCompare);  if($today > $endDateCompare)  $endColor = "#AE0011";  else $endColor = "#333333";  ?>  <td>   <?    echo $myrow['enddate']." ";//    echo $endDateSystem;   ?>  </td>  <TD><? echo $myrow["customername"]; ?>

  <!--<TD><? echo $myrow["paintingname"]; ?><br /> <? echo $myrow["artsize"]; ?></TD>
  <TD><?php if(isset($myrow["price"])) echo 'Price: $' . $myrow["price"]; ?><br>
  <?php if(isset($myrow["cost"])) echo 'Cost: $' . $myrow["cost"]; ?>
  </TD>
  <TD><? echo $myrow["partnous"]; ?></TD>
  <TD><? echo $myrow["startdate"]; ?></TD>
  <TD><? echo $myrow["enddate"]; ?></TD>-->
  <TD><? echo $myrow["organization"]; ?></TD>
  <TD><b style="color:<? echo $status2; ?>;"><? echo $myrow["status"]; ?></b></TD>
 <!-- <TD>
    <a href="edit.php?op=specialorderedit&specialorderid=<? echo $myrow["specialorderid"]; ?>">Edit</a>&nbsp;
    <a href="viewdetail-special.php?specialorderid=<? echo $myrow["specialorderid"]; ?>">View</a>&nbsp;
    <a href="delete.php?op=deleteorder&orderid=<? echo $myrow["orderid"]; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a> -->
  </TD>
</TR>
<?
 }
 ?>
<!-- </table>
 </div>-->
 
 <?php
}
?>

 <?php
// Show the Shipping Heading and Data
function ReturnHeader($returnid) {
include ("config.php");
$query = "SELECT * FROM returns WHERE returnid= '" . $returnid . "';";
$result = mysql_query($query,$db);
$myrow = mysql_fetch_array($result);
?>
<table width=100% >
 <tr><td class=section colspan=2><b>Return #<? echo $myrow["returnno"]; ?></b></td></tr>
  <tr><td class=menu>Return #</td><td bgcolor=white><? echo $myrow["returnno"]; ?></td></tr>
 <tr><td class=menu>Status:</td><td bgcolor=white><? echo $myrow["status"]; ?></td></tr>
 <tr><td class=menu>Prepared by:</td><td bgcolor=white><? echo $myrow["user"]; ?></td></tr>
 <?php
 if ($myrow["carrier"] == "DHL")
 {
 ?>
 <tr><td class=menu>Tracking:</td><td bgcolor=white><a href="http://www.dhl-usa.com/content/us/en/express/tracking.shtml?brand=DHL&AWB=<?= $myrow["tracking"]; ?>" target="_blank"><?= $myrow["tracking"]; ?></a></td></tr>
 <?php
 }
 elseif ($myrow["carrier"] == "FEDEX")
 {
 ?>
 <tr><td class=menu>Tracking:</td><td bgcolor=white><a href="http://www.fedex.com/Tracking?action=track&tracknumbers=<?= $myrow["tracking"]; ?>" target="_blank"><?= $myrow["tracking"]; ?></a></td></tr>
 <?php
 }
 elseif ($myrow["carrier"] == "UPS")
 {
 ?>
 <tr><td class=menu>Tracking:</td><td bgcolor=white><a href="http://ups.com?trackingnumber=<?= $myrow["tracking"]; ?>" target="_blank"><?= $myrow["tracking"]; ?></a></td></tr>
 <?php
 }
 ?>
 <tr><td class=menu>Carrier:</td><td bgcolor=white width="75%" height="20"><? echo $myrow["carrier"]; ?></td></tr>
 <tr><td class=menu>Has been Completed?</td><td bgcolor=white width="75%" height="20"><? echo $myrow["completed"]; ?></td></tr>
  <tr><td class=menu>Notes:</td><td bgcolor=white width="75%" height="20"><? echo $myrow["notes"]; ?></td></tr>
</table>
<? }
?>


 <?php
// Show the Shipping Heading and Data
function ShipHeader($shipid) {
include ("config.php");
$query = "SELECT * FROM shipment WHERE shipid= '" . $shipid . "';";
$result = mysql_query($query,$db);
$myrow = mysql_fetch_array($result);
$notes = trim($myrow["notes"]);
?>
<table width=100% >
 <tr><td class=section colspan=2><b>Shipment #<? echo $myrow["shipno"]; ?></b></td></tr>
  <tr><td class=menu>Shipment #</td><td bgcolor=white><? echo $myrow["shipno"]; ?></td></tr>
  <?php if($notes != "") { ?>
  <tr><td class=menu>Notes:</td><td bgcolor=white width="75%" height="20"><? echo $notes; ?></td></tr>
  <?php } ?>
 <tr><td class=menu>Start Date:</td><td bgcolor=white><? echo $myrow["startdate"]; ?></td></tr>
 <tr><td class=menu>Prepared by:</td><td bgcolor=white><? echo $myrow["user"]; ?></td></tr>
 <?php
 if ($myrow["carrier"] == "DHL")
 {
 ?>
 <tr><td class=menu>Tracking:</td><td bgcolor=white><a href="http://www.dhl-usa.com/content/us/en/express/tracking.shtml?brand=DHL&AWB=<?= $myrow["tracking"]; ?>" target="_blank"><?= $myrow["tracking"]; ?></a></td></tr>
 <?php
 }
 elseif ($myrow["carrier"] == "FEDEX")
 {
 ?>
 <tr><td class=menu>Tracking:</td><td bgcolor=white><a href="http://www.fedex.com/Tracking?action=track&tracknumbers=<?= $myrow["tracking"]; ?>" target="_blank"><?= $myrow["tracking"]; ?></a></td></tr>
 <?php
 }
 elseif ($myrow["carrier"] == "UPS")
 {
 ?>
 <tr><td class=menu>Tracking:</td><td bgcolor=white><a href="http://ups.com?trackingnumber=<?= $myrow["tracking"]; ?>" target="_blank"><?= $myrow["tracking"]; ?></a></td></tr>
 <?php
 }
 ?>
 <tr><td class=menu>Carrier:</td><td bgcolor=white width="75%" height="20"><? echo $myrow["carrier"]; ?></td></tr>
 <tr><td class=menu>PO #(US Office):</td><td bgcolor=white width="75%" height="20"><? echo $myrow["pono"]; ?></td></tr>
 <tr><td class=menu>Has been Completed?</td><td bgcolor=white width="75%" height="20"><? echo $myrow["completed"]; ?></td></tr>
 
  <tr> <td class=menu>Message Board:</td><td>
 <?php
// Here we will get it to show the replies
// This query selects the replies from the database where the thread ID matches the thread $_GET value.
$sql = mysql_query("SELECT * FROM `replies-ship` WHERE thread = '$shipid' ORDER BY `id` DESC");
// Now we are getting our results and making them an array
echo "<div id=\"message_column_order\">";
while($r = mysql_fetch_array($sql)) {
$i == 0 ? $color = "#293b74" : $color = "#AE0011";
$i == 0 ? $i = 1 : $i = 0;

if ($r[question] == "Yes") $color = "#0d9d09";

// Everything within the two curly brackets can read from the database using $r[]
// We need to convert the UNIX Timestamp entered into the database for when a thread...
// ... is posted into a readable date, using date().
$posted = date("jS M Y h:i",$r[posted]);
// Now this shows the thread with a horizontal rule after it.
echo "<b style=\"color:$color;\">$r[message]</b><BR>Posted by <b style=\"color:$color;\">$r[author]</b> on $posted"; 
if ($r[question] == "Yes" && $r[answer] == "" ) echo " <b style=\"color:$color;\">Open Question</b>";
echo "<hr>";
// End of Array
}
?>
</div>
 </td></tr>
</table>
<? }
// Show the Shipping Heading and Data
function ShipHeaderPrint($shipid) {
include ("config.php");
$query = "SELECT * FROM shipment WHERE shipid= '" . $shipid . "';";
$result = mysql_query($query,$db);
$myrow = mysql_fetch_array($result);
?>
<img src="images/packing-list.gif">
<table width=100% >
 <tr><td class=section colspan=2>Shipment #<? echo $myrow["shipno"]; ?></td></tr>
 <tr><td class=menu>Start Date:</td><td bgcolor=white><? echo $myrow["startdate"]; ?></td></tr>
 <tr><td class=menu>Prepared by:</td><td bgcolor=white><? echo $myrow["user"]; ?></td></tr>
 <tr><td class=menu>Tracking:</td><td bgcolor=white><? echo $myrow["tracking"]; ?></td></tr>
 <tr><td class=menu>Carrier:</td><td bgcolor=white width="75%" height="20"><? echo $myrow["carrier"]; ?></td></tr>
 <tr><td class=menu>Has been Completed?</td><td bgcolor=white width="75%" height="20"><? echo $myrow["completed"]; ?></td></tr>
  <tr><td class=menu>Notes:</td><td bgcolor=white width="75%" height="20"><? echo $myrow["notes"]; ?></td></tr>
</table>
<? }
// Show the Shipping Heading and Data
function ShipHeaderPrintPhysical($shipid) {
include ("config.php");
$query = "SELECT * FROM shipment WHERE shipid= '" . $shipid . "';";
$result = mysql_query($query,$db);
$myrow = mysql_fetch_array($result);
?>
<table width=100% >
 <tr><td class=section colspan=2>Shipment #<? echo $myrow["shipno"]; ?></td></tr>
 <tr><td class=menu>Start Date:</td><td bgcolor=white><? echo $myrow["startdate"]; ?></td></tr>
 <tr><td class=menu>Prepared by:</td><td bgcolor=white><? echo $myrow["user"]; ?></td></tr>
 <tr><td class=menu>Tracking:</td><td bgcolor=white><? echo $myrow["tracking"]; ?></td></tr>
 <tr><td class=menu>Carrier:</td><td bgcolor=white width="75%" height="20"><? echo $myrow["carrier"]; ?></td></tr>
 <tr><td class=menu>Has been Completed?</td><td bgcolor=white width="75%" height="20"><? echo $myrow["completed"]; ?></td></tr>
  <tr><td class=menu>Notes:</td><td bgcolor=white width="75%" height="20"><? echo $myrow["notes"]; ?></td></tr>
</table>
<? }
?>
<?php
// Show the Order Heading and Data
function OrderHeaderDev($devid) {
include ("config.php");
$query = "SELECT * FROM development WHERE devid= '" . $devid . "';";
$result = mysql_query($query,$db);
$myrow = mysql_fetch_array($result);
$stage = $myrow["stage"];
$status = $myrow["status"];
		$query4 = "SELECT color FROM status WHERE status= '" . $status . "';"; 
		$status1 = mysql_query($query4,$db);
		$row = mysql_fetch_array($status1, MYSQL_NUM);
		$status2 = $row[0];
		$query5 = "SELECT color FROM stage WHERE stage= '" . $stage . "';"; 
		$stage1 = mysql_query($query5,$db);
		$row = mysql_fetch_array($stage1, MYSQL_NUM);
		$stage2 = $row[0];
?>
<table width=100% >
 <tr><td class=section colspan=3>Development</td></tr>
 <tr><td class=menu>Development Number:</td><td bgcolor=white><? echo $myrow["devnumber"]; ?></td><td rowspan="5"><B>Comments:</B><BR><? echo $myrow["comments"]; ?>
 </td></tr>
 <tr><td class=menu>Status:</td><td bgcolor=white style="color:<? echo $status2; ?>;"><b><? echo $myrow["status"]; ?></b></td></tr>
 <tr><td class=menu>Stage:</td><td bgcolor=white style="color:<? echo $stage2; ?>;"><b><? echo $myrow["stage"]; ?></b></td></tr>
 <tr><td class=menu>Start Date:</td><td bgcolor=white><? echo $myrow["startdate"]; ?></td></tr>
 <tr><td class=menu>End Date:</td><td bgcolor=white><? echo $myrow["enddate"]; ?></td></tr>
 <tr><td class=menu>Message Board:</td><td>
 <?php
// Here we will get it to show the replies
// This query selects the replies from the database where the thread ID matches the thread $_GET value.
$sql = mysql_query("SELECT * FROM `replies-dev` WHERE thread = '$devid' ORDER BY `id` DESC");
// Now we are getting our results and making them an array
while($r = mysql_fetch_array($sql)) {
$i == 0 ? $color = "#293b74" : $color = "#AE0011";
$i == 0 ? $i = 1 : $i = 0;

if ($r[question] == "Yes") $color = "#0d9d09"; 

// Everything within the two curly brackets can read from the database using $r[]
// We need to convert the UNIX Timestamp entered into the database for when a thread...
// ... is posted into a readable date, using date().
$posted = date("jS M Y h:i",$r[posted]);
// Now this shows the thread with a horizontal rule after it.
echo "<b style=\"color:$color;\">$r[message]</b><BR>Posted by <b style=\"color:$color;\">$r[author]</b> on $posted";
if ($r[question] == "Yes" && $r[answer] == "" ) echo " <b style=\"color:$color;\">Open Question</b>";
echo "<hr>";
// End of Array
}
?>
 </td><td>
  <form action="newreply-dev.php" method="POST">
<input type="hidden" name="author" value="<?php echo $_SESSION['s_username'];?>">
<input type="hidden" value="<?php echo $devid; ?>" name="thread">
<input type="hidden" value="<?php echo $myrow["status"]; ?>" name="status">
<input type="hidden" value="<?php echo $myrow["devnumber"]; ?>" name="devNum">
<b>Message:</b><br><textarea cols="60" rows="5" name="message"></textarea><br>
<input type="checkbox" name="question" value="Yes" />&nbsp;<b>Please check if this is a question.</b><br>
<input type="submit" value="Post Message">
</form>
  </td></tr>
</table>
<?php
 }
?>
<?php
// Show the Order Heading and Data
function OrderHeader($orderid) {
include ("config.php");
$query = "SELECT * FROM orders WHERE orderid= '" . $orderid . "';";
$result = mysql_query($query,$db);
$myrow = mysql_fetch_array($result);
$stage = $myrow["stage"];
$status = $myrow["status"];
$vendor_org = $myrow["organization"];
		$query4 = "SELECT color FROM status WHERE status= '" . $status . "';"; 
		$status1 = mysql_query($query4,$db);
		$row = mysql_fetch_array($status1, MYSQL_NUM);
		$status2 = $row[0];
		$query5 = "SELECT color FROM stage WHERE stage= '" . $stage . "';"; 
		$stage1 = mysql_query($query5,$db);
		$row = mysql_fetch_array($stage1, MYSQL_NUM);
		$stage2 = $row[0];
?>
<table width=100% >
 <tr><td class=section colspan=5>Order</td></tr>
 <tr><td class=menu>Order Number:</td><td bgcolor=white><? echo $myrow["ordernumber"]; ?></td><td class=menu>Supplier:</td><td bgcolor=white><b><? echo $vendor_org; ?></b></td><td rowspan=3><B>Comments:</B><BR><? echo $myrow["comments"]; ?>
 </td></tr>
 <tr><td class=menu>Status:</td><td bgcolor=white style="color:<? echo $status2; ?>;"><b><? echo $myrow["status"]; ?></b></td><td class=menu>Stage:</td><td bgcolor=white style="color:<? echo $stage2; ?>;"><b><? echo $myrow["stage"]; ?></b></td></tr>
 <tr><td class=menu>Start Date:</td><td bgcolor=white><? echo $myrow["startdate"]; ?></td><td class=menu>End Date:</td><td bgcolor=white><? echo $myrow["enddate"]; ?></td></tr>
 <tr> <td class=menu>Message Board:</td><td colspan=3>
 <?php
// Here we will get it to show the replies
// This query selects the replies from the database where the thread ID matches the thread $_GET value.
$sql = mysql_query("SELECT * FROM `replies-order` WHERE thread = '$orderid' ORDER BY `id` DESC");
// Now we are getting our results and making them an array
echo "<div id=\"message_column_order\">";
while($r = mysql_fetch_array($sql)) {
$i == 0 ? $color = "#293b74" : $color = "#AE0011";
$i == 0 ? $i = 1 : $i = 0;

if ($r[question] == "Yes") $color = "#0d9d09"; 

// Everything within the two curly brackets can read from the database using $r[]
// We need to convert the UNIX Timestamp entered into the database for when a thread...
// ... is posted into a readable date, using date().
$posted = date("jS M Y h:i",$r[posted]);
// Now this shows the thread with a horizontal rule after it.
echo "<b style=\"color:$color;\">$r[message]</b><BR>Posted by <b style=\"color:$color;\">$r[author]</b> on $posted"; 
if ($r[question] == "Yes" && $r[answer] == "" ) echo " <b style=\"color:$color;\">Open Question</b>";
echo "<hr>";
// End of Array
}
?>
</div>
 </td>  <td>
  <form action="newreply-order.php" method="POST">
<input type="hidden" name="author" value="<?php echo $_SESSION['s_username'];?>">
<input type="hidden" value="<?php echo $orderid; ?>" name="thread">
<input type="hidden" value="<?php echo $myrow["status"]; ?>" name="status">
<input type="hidden" value="<?php echo $myrow["ordernumber"]; ?>" name="orderNum">
<input type="hidden" value="<?php echo $vendor_org; ?>" name="vendor">

<b>Message:</b><br><textarea cols="60" rows="5" name="message"></textarea><br>
<input type="checkbox" name="question" value="Yes" />&nbsp;<b>Please check if this is a question.</b><br>
<input type="submit" value="Post Message">
</form>
  </td></tr>
</table>
<? }
//Send Mail for new and changed Orders
function mailsend ($subject,$orderid,$ordernumber,$status,$stage,$startdate,$enddate,$comments) {
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, communicatorosa@gmail.com,info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = "OverstockArt Communicator ".$subject.": ".$ordernumber;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=300>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>Order:</font></td><td bgcolor=white>".$ordernumber."</td></tr>";
$msg.="<tr><td><font color=black>Status:</font></td><td bgcolor=white>".$status."</td></tr>";
$msg.="<tr><td><font color=black>Stage:</font></td><td bgcolor=white>".$stage."</td></tr>";
$msg.="<tr><td><font color=black>Start Date:</font></td><td bgcolor=white>".$startdate."</td></tr>";
$msg.="<tr><td><font color=black>End Date:</font></td><td bgcolor=white>".$enddate."</td></tr>";
$msg.="<tr><td><font color=black>Comments:</font></td><td bgcolor=white>".$comments."</td></tr>";
$msg.="</table><br><br>";
$msg.="<a href='" . HTTP_LOCAL . "viewdetail.php?orderid=$orderid'>View Order # $ordernumber &raquo;</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
//Send Mail for new Shipments
function mailship($subject,$shipid,$shipno,$startdate,$selectuser,$tracking,$carrier)
{
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com, production@overstockart.com";
//communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com,
$mailfrom = "communicator@overstockart.cn";
$subject1 = "OverstockArt Communicator ".$subject.": ".$shipno;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=300>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>Shipment:</font></td><td bgcolor=white>".$shipno."</td></tr>";
$msg.="<tr><td><font color=black>Start Date:</font></td><td bgcolor=white>".$startdate."</td></tr>";
$msg.="<tr><td><font color=black>User:</font></td><td bgcolor=white>".$selectuser."</td></tr>";
$msg.="<tr><td><font color=black>Tracking:</font></td><td bgcolor=white>".$tracking."</td></tr>";
$msg.="<tr><td><font color=black>Carrier:</font></td><td bgcolor=white>".$carrier."</td></tr>";
$msg.="</table><br><br>";
$msg.="<a href='" . HTTP_LOCAL . "viewdetail-shipment.php?shipid=$shipid'>Click to Review the Shippment &raquo;</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}

//Send Mail for Received Shipments
function mailshipreceived($subject,$shipid,$body,$selectuser)
{
$mailto = "asasson@overstockart.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = "overstockArt Communicator ". $subject .": ".$shipno;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=500>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>Shipment:</font></td><td bgcolor=white>".$shipid."</td></tr>";
$msg.="<tr><td><font color=black>User:</font></td><td bgcolor=white>".$selectuser."</td></tr>";
$msg.="<tr><td><font color=black>Tracking:</font></td><td bgcolor=white>".$body."</td></tr>";
$msg.="</table><br><br>";
$msg.="<a href='" . HTTP_LOCAL . "viewdetail-shipment.php?shipid=$shipid'>Click to Review the Shippment &raquo;</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}

//Send Mail for new return
function mailreturn($subject,$returnid,$returnno,$startdate,$selectuser,$tracking,$carrier)
{
$mailto = "asasson@overstockart.com"; // dsasson@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com, production@overstockart.com
$mailfrom = "communicator@overstockart.cn";
$subject1 = "OverstockArt Communicator ".$subject.": ".$returnno;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=300>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>Return:</font></td><td bgcolor=white>".$returnno."</td></tr>";
$msg.="<tr><td><font color=black>Start Date:</font></td><td bgcolor=white>".$startdate."</td></tr>";
$msg.="<tr><td><font color=black>User:</font></td><td bgcolor=white>".$selectuser."</td></tr>";
$msg.="<tr><td><font color=black>Tracking:</font></td><td bgcolor=white>".$tracking."</td></tr>";
$msg.="<tr><td><font color=black>Carrier:</font></td><td bgcolor=white>".$carrier."</td></tr>";
$msg.="</table><br><br>";
$msg.="<a href='" . HTTP_LOCAL . "viewdetail-return.php?returnid=$returnid'>Click to Review the Return &raquo;</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}

?>
<?
//Send Mail for Quote Request
function quotemail ($subject,$name,$npeople,$quality,$size) {
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com,  dkail@overstockart.com, jfrench@overstockart.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = "overstockArt Communicator ".$subject.": ".$ordernumber;
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$mailfrom. "\r\n" .
			"Reply-To: " . $mailfrom . "\r\n" .
			"X-Mailer: PHP/" . phpversion();
$msg ="<body bgcolor=white>";
$msg.="<table width=300>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>Quote Request</td></tr>";
$msg.="<tr><td><font color=black>Painting Name:</font></td><td bgcolor=white>".$name."</td></tr>";
$msg.="<tr><td><font color=black>Number of People in the Painting:</font></td><td bgcolor=white>".$npeople."</td></tr>";
$msg.="<tr><td><font color=black>Quality:</font></td><td bgcolor=white>".$quality."</td></tr>";
$msg.="<tr><td><font color=black>Size:</font></td><td bgcolor=white>".$size."</td></tr>";
$msg.="</table><br><br>";
$msg.="<a href='" . HTTP_LOCAL . "'>overstockArt Communicator</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>
<?php
//Amitai Alert activity
function mailsend2 ($subject,$username,$password) {
$mailto = "asasson@overstockart.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = "Communicator ".$subject.": ".$username;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=300>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>Communicator Someone is in Alert!</td></tr>";
$msg.="<tr><td><font color=black>Username:</font></td><td bgcolor=white>".$username."</td></tr>";
$msg.="</table><br><br>";
$msg.="<a href='" . HTTP_LOCAL . "'>OverstockArt Communicator</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>
<?
//Send Mail for new and changed Special Orders
function mailsend4 ($subject,$specialorderid,$specialordername,$customername,$price,$quantity,$partnous,$paintingname,$artsize,$status,$startdate,$enddate,$comments,$image) {
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com, jfrench@overstockart.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = "overstockArt Communicator ".$subject; //": ".$specialordernamde;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>overstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>Customer Name:</font></td><td bgcolor=white>".$customername."</td>";
$msg.="<td colspan=2 rowspan=5><img src=\"" . $image . "\"></td></tr>";
$msg.="<tr><td><font color=black>Special Order Number:</font></td><td bgcolor=white>".$specialordername."</td></tr>";
$msg.="<tr><td><font color=black>Painting Name:</font></td><td bgcolor=white>".$paintingname."</td></tr>";
$msg.="<tr><td><font color=black>Part Number U.S.:</font></td><td bgcolor=white>".$partnous."</td></tr>";
$msg.="<tr><td><font color=black>Size:</font></td><td bgcolor=white>".$artsize."</td></tr>";
$msg.="<tr><td><font color=black>Qty Requested:</font></td><td bgcolor=white>".$quantity."</td></tr>";
$msg.="<tr><td><font color=black>Start Date:</font></td><td bgcolor=white>".$startdate."</td></tr>";
$msg.="<tr><td><font color=black>End Date:</font></td><td bgcolor=white>".$enddate."</td></tr>";
$msg.="<tr><td><font color=black>Status:</font></td><td bgcolor=white>".$status."</td></tr>";
$msg.="<tr><td><font color=black>Comments:</font></td><td bgcolor=white>".$comments."</td></tr>";
$msg.="</table><br>"; 
$msg.="<a href='" . HTTP_LOCAL . "viewdetail-special.php?specialorderid=" . $specialorderid . "'>View Special Order $specialordername &raquo;</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>
<?
//Send Mail for new and changed Special Orders
function mailsend42 ($subject,$specialorderid,$specialordername,$customername,$price,$quantity,$partnous,$paintingname,$artsize,$status,$startdate,$enddate,$comments) {
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = "OverstockArt Communicator ".$subject;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>Customer Name:</font></td><td bgcolor=white>".$customername."</td></tr>";
$msg.="<tr><td><font color=black>Special Order Number:</font></td><td bgcolor=white>".$specialordername."</td></tr>";
$msg.="<tr><td><font color=black>Painting Name:</font></td><td bgcolor=white>".$paintingname."</td></tr>";
$msg.="<tr><td><font color=black>Part Number U.S.:</font></td><td bgcolor=white>".$partnous."</td></tr>";
$msg.="<tr><td><font color=black>Size:</font></td><td bgcolor=white>".$artsize."</td></tr>";
$msg.="<tr><td><font color=black>Qty Requested:</font></td><td bgcolor=white>".$quantity."</td></tr>";
$msg.="<tr><td><font color=black>Start Date:</font></td><td bgcolor=white>".$startdate."</td></tr>";
$msg.="<tr><td><font color=black>End Date:</font></td><td bgcolor=white>".$enddate."</td></tr>";
$msg.="<tr><td><font color=black>Status:</font></td><td bgcolor=white>".$status."</td></tr>";
$msg.="<tr><td><font color=black>Comments:</font></td><td bgcolor=white>".$comments."</td></tr>";
$msg.="</table><br>"; 
$msg.="<a href='" . HTTP_LOCAL . "viewdetail-special.php?specialorderid=" . $specialorderid . "'>View Special Order #  $specialordername &raquo;</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>
<?
//Send Mail for new quote on Special Orders
function mailmessageQuote($subject,$specialorderid,$specialordername,$author) {
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = $subject;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>Order Number:</font></td><td bgcolor=white>".$specialordername."</td></tr>";
$msg.="<tr><td><font color=black>Status:</font></td><td bgcolor=white>Quote Given</td></tr>";
$msg.="<tr><td colspan=2><font color=black>New Quote Available</font></td></tr>";
$msg.="<tr><td><font color=black>Author:</font></td><td bgcolor=white>".$author."</td></tr>";
$msg.="</table><br>"; 
$msg.="<a href='" . HTTP_LOCAL . "viewdetail-special.php?specialorderid=$specialorderid'>Go to Special Order $specialordername</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>

<?
//Send Mail for new quote on Special Orders
function mailmessageQuoteShip($subject,$shipid,$shipno,$author) {
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = $subject;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>overstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>New Quote for Shipment Number:</font></td><td bgcolor=white>".$shipno."</td></tr>";
$msg.="<tr><td colspan=2><font color=black>New Quote Available</font></td></tr>";
$msg.="<tr><td><font color=black>Author:</font></td><td bgcolor=white>".$author."</td></tr>";
$msg.="</table><br>"; 
$msg.="<a href='" . HTTP_LOCAL . "viewdetail-shipment.php?shipid=$shipid'>Go to Shipment No. $shipno</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>


<?
//Send Mail for new message on Special Orders
function mailmessage ($subject,$specialorderid,$specialordername,$customername,$status,$message,$author) {
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = "OverstockArt Communicator ".$subject;

$Header = "MIME-Version: 1.0\r\n";
$Header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$Header .= "From: Communicator Update <".$mailfrom.">\r\n";
$Header .= "Reply-To: ".$mailfrom."\r\n";
$Header .= "Bcc: asasson@overstockart.com\r\n";
$Header .= "X-Mailer: PHP/" . phpversion();


$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>Customer Name:</font></td><td bgcolor=white>".$customername."</td></tr>";
$msg.="<tr><td><font color=black>Order Number:</font></td><td bgcolor=white>".$specialordername."</td></tr>";
$msg.="<tr><td><font color=black>Status:</font></td><td bgcolor=white>".$status."</td></tr>";
$msg.="<tr><td><font color=black>New Message:</font></td><td bgcolor=white>".$message."</td></tr>";
$msg.="<tr><td><font color=black>Author:</font></td><td bgcolor=white>".$author."</td></tr>";
$msg.="</table><br>"; 
$msg.="<a href='" . HTTP_LOCAL . "viewdetail-special.php?specialorderid=$specialorderid'>Read Message Board on Special Order $specialordername</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $Header))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>

<?
//Send Mail for new message on Special Orders
function mailmessageDevReply ($subject,$partno,$partid,$lineId,$message,$author) {
$mailto = "asasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com,  production@overstockart.com, dkail@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = $subject;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>overstockArt Update <br> Development Status Update!</td></tr>";
$msg.="<tr><td><font color=black>Part Number:</font></td><td bgcolor=white>". $partno . "</td></tr>";
$msg.="<tr><td><font color=black>Message:</font></td><td bgcolor=white>". $message . "</td></tr>";
$msg.="<tr><td><font color=black>Author:</font></td><td bgcolor=white>". $author . "</td></tr>";
$msg.="</table><br>"; 
$msg.="</body>";
mail($mailto, $subject1, $msg, $headers);
}
?>


<?
//Send Mail for new message on Special Orders
function mailmessage5 ($subject,$partno,$partid,$onhand,$message,$customername,$author) {
$mailto = "asasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com,  production@overstockart.com, dkail@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, ahendren@overstockart.com, jdouglas@overstockart.com, jfrench@overstockart.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = $subject;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>overstockArt Update <br> Qty on Hand Alert!</td></tr>";
$msg.="<tr><td><font color=black>&nbsp;</font></td><td bgcolor=white>". $customername . "</td></tr>";
$msg.="<tr><td><font color=black>Part Number:</font></td><td bgcolor=white>". $partno . "</td></tr>";
$msg.="<tr><td><font color=black>Qty Level:</font></td><td bgcolor=white>". $onhand . "</td></tr>";
$msg.="<tr><td><font color=black>Message:</font></td><td bgcolor=white>". $message . "</td></tr>";
$msg.="<tr><td><font color=black>Author:</font></td><td bgcolor=white>". $author . "</td></tr>";
$msg.="</table><br>"; 
$msg.="<a href='" . HTTP_LOCAL . "viewparts.php?partid=$partid'>Read Message on Qty on Hand $partno</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>
<?
//Send Mail for new message on Special Orders
function mailmessage6($subject,$customername,$author) {
$mailto = "asasson@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, dsasson@overstockart.com, ahendren@overstockart.com, jfrench@overstockart.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = $subject;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Update <br> Demand Planning Update!</td></tr>";
$msg.="<tr><td><font color=black>Message from:</font></td><td bgcolor=white>". $author . "</td></tr>";
$msg.="</table><br>"; 
$msg.="<a href='" . HTTP_LOCAL . "demand-current.php'>See Report &raquo;</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>
<?
//Send Mail for new message on Special Orders
function mailmessageGen($subject,$customername,$author) {
$mailto = "asasson@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, dsasson@overstockart.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = $subject;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Update <br>" . $subject . "</td></tr>";
$msg.="<tr><td><font color=black>Message from:</font></td><td bgcolor=white>" . $author . "</td></tr>";
$msg.="<tr><td colspan=2><font color=black>" . $subject . "</font></td></tr>";
$msg.="</table><br>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>
<?
//Send Mail for new message on Special Orders
function mailmessage2 ($subject,$orderid,$ordername,$customername,$status,$message,$author,$vendor_org) {


if ($vendor_org == "China")
{
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com";
}
else
{
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com";
}

$mailfrom = "communicator@overstockart.cn";
$subject1 = "OverstockArt Communicator ".$subject;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>Customer Name:</font></td><td bgcolor=white>".$customername."</td></tr>";
$msg.="<tr><td><font color=black>Order Number:</font></td><td bgcolor=white>".$ordername."</td></tr>";
$msg.="<tr><td><font color=black>Status:</font></td><td bgcolor=white>".$status."</td></tr>";
$msg.="<tr><td><font color=black>New Message:</font></td><td bgcolor=white>".$message."</td></tr>";
$msg.="<tr><td><font color=black>Author:</font></td><td bgcolor=white>".$author."</td></tr>";
$msg.="</table><br>"; 
$msg.="<a href='" . HTTP_LOCAL . "viewdetail.php?orderid=$orderid'>Read Message Board on Order $ordername</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>
<?
//Send Mail for new message on Development
function mailmessage_dev ($subject,$devid,$devname,$author,$status,$message) {
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com";
$mailfrom = "communicator@overstockart.cn";
$subject1 = "OverstockArt Communicator " . $subject;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>overstockArt Communicator Update - Development</td></tr>";
$msg.="<tr><td><font color=black>Development Number:</font></td><td bgcolor=white>".$devname."</td></tr>";
$msg.="<tr><td><font color=black>Status:</font></td><td bgcolor=white>".$status."</td></tr>";
$msg.="<tr><td><font color=black>New Message:</font></td><td bgcolor=white>".$message."</td></tr>";
$msg.="<tr><td><font color=black>Author:</font></td><td bgcolor=white>".$author."</td></tr>";
$msg.="</table><br>"; 
$msg.="<a href='" . HTTP_LOCAL . "viewdetail-dev.php?devid=$devid'>Read Message Board on Development $devname</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>
<?
//Send Mail for new and changed Orders
function mailsend3 ($subject,$userEdit,$orderid,$partid,$ordernumber,$status,$quantity,$dateETA,$imageart,$qtyAccepted,$comments) {
$mailto = "asasson@overstockart.com, dsasson@overstockart.com, communicatorosa@gmail.com, amit@aspaklaria.com, nati@aspaklaria.com, lucy@aspaklaria.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com";
$mailfrom = $userEdit."@communicator.com";
$subject1 = "overstockArt.com Communicator ".$subject; //": ".$ordernumber;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";
$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>OverstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>User:</font></td><td bgcolor=white>".$userEdit."</td>";
$msg.="<td width='250' rowspan='10'><img align='right' src='" . HTTP_LOCAL . "files/thumb/" . $imageart . "' BORDER='1'></td></tr>";
$msg.="<tr><td><font color=black>Order:</font></td><td bgcolor=white>".$ordernumber."</td></tr>";
$msg.="<tr><td><font color=black>Part Number:</font></td><td bgcolor=white>".$partid."</td></tr>";
$msg.="<tr><td><font color=black>Status:</font></td><td bgcolor=white>".$status."</td></tr>";
$msg.="<tr><td><font color=black>ETA Date:</font></td><td bgcolor=white>".$dateETA."</td></tr>";
$msg.="<tr><td><font color=black>Qty Requested:</font></td><td bgcolor=white>".$quantity."</td></tr>";
$msg.="<tr><td><font color=black>Qty Accepted:</font></td><td bgcolor=white>".$qtyAccepted."</td></tr>";
$msg.="<tr><td><font color=black>Comments:</font></td><td bgcolor=white>".$comments."</td></tr>";
$msg.="</table><br><br>";
$msg.="<a href='" . HTTP_LOCAL . "viewdetail.php?orderid=" . $orderid . "'>View Order # $ordernumber &raquo;</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>

<?
//Send Mail for new and changed Orders
function mailsendETA ($subject,$userEdit,$orderid,$partid,$ordernumber,$status,$quantity,$dateETA,$imageart,$qtyAccepted,$comments,$countBackorder) {
$mailto = "asasson@overstockart.com, info@overstockart.com, sthrasher@overstockart.com, fderanzo@overstockart.com, dkail@overstockart.com";
$mailfrom = $userEdit."@communicator.com";
$subject1 = "overstockArt.com Communicator ".$subject; //": ".$ordernumber;
$headers="Content-Type:text/html\r\n";
$headers.="From:".$mailfrom."\r\n";

list($day, $month, $year) = split('/',$dateETA);
$ETADateFormated = $year . "-" . $month . "-" . $day;
$etaDateUS = date("M j, Y",strtotime($ETADateFormated));

$msg ="<body bgcolor=white>";
$msg.="<table width=532>";
$msg.="<tr><td colspan=2 bgcolor=#99B3CC height=1><font size='+1'><b>overstockArt Communicator Update</td></tr>";
$msg.="<tr><td><font color=black>User:</font></td><td bgcolor=white>".$userEdit."</td>";
$msg.="<td width='250' rowspan='10'><img align='right' src='" . HTTP_LOCAL . "files/thumb/" . $imageart . "' BORDER='1'></td></tr>";
$msg.="<tr><td><font color=black>Order:</font></td><td bgcolor=white>".$ordernumber."</td></tr>";
$msg.="<tr><td><font color=black>Part Number:</font></td><td bgcolor=white>".$partid."</td></tr>";
$msg.="<tr><td><font color=black>Status:</font></td><td bgcolor=white>".$status."</td></tr>";
$msg.="<tr><td><font color=black>ETA Date:</font></td><td bgcolor=white>". $etaDateUS ."</td></tr>";
$msg.="<tr><td><font color=black>Qty Requested:</font></td><td bgcolor=white>".$quantity."</td></tr>";
$msg.="<tr><td><font color=black>Qty Accepted:</font></td><td bgcolor=white>".$qtyAccepted."</td></tr>";
$msg.="<tr><td><font color=black>Comments:</font></td><td bgcolor=white>". $comments . "<br>" . $countBackorder . " On Backorder!" . "</td></tr>";
$msg.="</table><br><br>";
$msg.="<a href='" . HTTP_LOCAL . "viewdetail.php?orderid=" . $orderid . "'>View Order # $ordernumber &raquo;</a>";
$msg.="</body>";
if(mail($mailto, $subject1, $msg, $headers))
{
   echo("<p>Message successfully sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
}
?>

<?
function loop_orders ($result) {
	
	// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>">
	<TD> <a href="viewdetail.php?orderid=<? echo $myrow["orderid"]; ?>"><? echo $myrow["ordernumber"]; ?></a></TD>
	<TD><? echo $myrow["status"]; ?></TD>
	<TD><? echo $myrow["stage"]; ?></TD>
	<TD><? echo $myrow["startdate"]; ?></TD>
	<TD><? echo $myrow["enddate"]; ?></TD>
	<TD>
		<a href="edit.php?op=orderedit&orderid=<? echo $myrow["orderid"]; ?>">Edit</a>&nbsp;
		<a href="viewdetail.php?orderid=<? echo $myrow["orderid"]; ?>">View</a>&nbsp;
		<a href="orderline.php?orderid=<? echo $myrow["orderid"]; ?>">Order Lines</a>&nbsp;
		<a href="parts.php?orderid=<? echo $myrow["orderid"]; ?>">Paintings</a>&nbsp;
		<a href="delete.php?op=deleteorders&orderid=<? echo $myrow["orderid"]; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
	</TD>	
</TR>
<?
 }
}
?>	
<?
function table_header($title) {
?>
<div id="main_order_table">
<table border=1>
<tr><td align=center colspan="2" class=order_status>---- <? echo $title; ?> ----</td></tr>
<TR>
	<TD class=menu>Order Number</B></TD>
	<TD class=menu>Supplier</B></TD>
	<!--<TD class=menu>Status</B></TD>
	<TD class=menu>Stage</B></TD>
	<TD class=menu>Start Date</B></TD>
	<TD class=menu>End Date</B></TD>
	<TD class=menu>Options</B></TD>-->
</TR>
<? } ?>
<?
function table_header_open_orders($title) {
?>
<table border=1>
<tr><td align=center colspan="7" class=order_status>---- <? echo $title; ?> ----</td></tr>
<TR>
	<TD class=menu>Order Number</B></TD>
	<TD class=menu>Status</B></TD>
	<TD class=menu>Stage</B></TD>
	<TD class=menu>Start Date</B></TD>
	<TD class=menu>End Date</B></TD>
	<TD class=menu>Supplier</B></TD>
	<TD class=menu>Options</B></TD>
</TR>
<? } ?>
<?
function table_header_dev($title) {
?>
<div id="main_dev_table">
<table border=1>
<tr><td align=center style="background-color:#0e5117;" class=order_status  colspan=2>---- <? echo $title; ?> ----</td></tr>
<TR>
	<TD class=menu>Dev Number</B></TD>
	<!--<TD class=menu>Status</B></TD>
	<TD class=menu>Stage</B></TD>
	<TD class=menu>Start Date</B></TD>
	<TD class=menu>End Date</B></TD>-->
	<TD class=menu>Options</B></TD>
</TR>
<? } ?>
<?
function table_header_dev_full($title) {
?>
<table border=1>
<tr><td align=center class=order_status  colspan=4>---- <? echo $title; ?> ----</td></tr>
<TR>
	<TD class=menu>Dev Number</B></TD>
	<TD class=menu>Status</B></TD>
	<!--<TD class=menu>Stage</B></TD>-->
	<TD class=menu>Start Date</B></TD>
	<!--<TD class=menu>End Date</B></TD>-->
	<TD class=menu>Options</B></TD>
</TR>
<? } ?>
<?
function table_special_header($title,$color) {
?>
<div id="special_order_table">
<table cellpadding="1" cellspacing="2" border="1">
<tr><td colspan=4 align=center class=special_order_status style="background-color:<? echo $color;?>;">---- <? echo $title; ?> ----</td></tr>
<TR>
	<TD class=menu>Special Order Number</B></TD>
	<TD class=menu>Customer Name</B></TD>
	<TD class=menu>Supplier</B></TD>
<!--	<TD class=menu>Painting Name and Size</B></TD>
	<TD class=menu>Price and Cost</B></TD>
	<TD class=menu>Part Number US</B></TD>
	<TD class=menu>Start Date</B></TD>
	<TD class=menu>End Date</B></TD>-->
	<TD class=menu>Status</B></TD>
	<!--<TD class=menu>Options</B></TD>-->
</TR>
<? } ?>
<?
function table_special_header_open_orders($title,$color) {
?>
<table cellpadding="1" cellspacing="2" border="1">
<tr><td colspan=9 align=center class=special_order_status style="background-color:<? echo $color;?>;">---- <? echo $title; ?> ----</td></tr>
<TR>
	<TD class=menu>Special Order Number</B></TD>
	<TD class=menu>Customer Name</B></TD>
	<TD class=menu>Painting Name and Size</B></TD>
	<TD class=menu>Price and Cost</B></TD>
	<TD class=menu>Part Number US</B></TD>
	<TD class=menu>Start Date</B></TD>
	<TD class=menu>End Date</B></TD>
	<TD class=menu>Supplier</B></TD>
	<TD class=menu>Status</B></TD>
	<!--<TD class=menu>Options</B></TD>-->
</TR>
<? } ?>
<?
function table_shipmanager_header($title,$color) {
?>
<table width="100%" cellpadding="1" cellspacing="2" border="1">
<tr><td colspan=9 align=center class=special_order_status style="background-color:<? echo $color;?>;">---- <? echo $title; ?> ----</td></tr>
<tr>
	<td class=menu>Ship No.</td>
	<td class=menu>Ship Date</td>
	<td class=menu>Invoice #</td>
	<td class=menu>Carrier</td>
	<td class=menu>Tracking</td>
	<td class=menu>Options</td>
</tr>
<? } ?>

<?
function table_returnmanager_header($title,$color) {
?>
<table width="100%" cellpadding="1" cellspacing="2" border="1">
<tr><td colspan=9 align=center class=special_order_status style="background-color:<? echo $color;?>;">---- <? echo $title; ?> ----</td></tr>
<TR>
	<TD class=menu>Return No.</B></TD>
	<TD class=menu>Return Date</B></TD>
	<TD class=menu>Carrier</B></TD>
	<TD class=menu>Tracking</B></TD>
	<TD class=menu>Options</B></TD>
</TR>
<? } ?>

<?
function recent_messages($title,$color) {
?>
<!--<div id="reply_table">
<table width="100%" cellpadding="1" cellspacing="2" border="1">
<tr><td colspan=9 align=center class=special_order_status style="background-color:<? echo $color;?>;"><? echo $title; ?></td></tr>
<TR>
	<TD class=menu>Author</B></TD>
	<TD class=menu>Message</B></TD>
</TR>-->
<? } ?>
<?
function recent_messages_full($title,$color) {
?>
<table width="100%" cellpadding="1" cellspacing="2" border="1">
<tr><td colspan=9 align=center class=special_order_status style="background-color:<? echo $color;?>;"><? echo $title; ?></td></tr>
<TR>
	<TD class=menu>Author</B></TD>
	<TD class=menu>Message</B></TD>
	<TD class=menu>Date</TD>
</TR>
<? } ?>
<?
function display_recent_messages_full($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
	
	if ($_SESSION["highlightIdMsgSpecial"] == $myrow["thread"]) { $color = "#e28080";
	                                         $class = "lastvisited";
											 }
		
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD><? echo $myrow["author"]; ?></a></TD>
  <TD><? 
  if (strlen($myrow["message"]) > 50)
	 echo substr($myrow["message"],0,50) . "...";
  else
  echo $myrow["message"]; 
  ?>
  <a href="viewdetail-special.php?specialorderid=<? echo $myrow["thread"]; ?>">&raquo;</a>
  </TD>
  <TD><? echo date('F j, Y', $myrow["posted"]); ?></a></TD>
</TR>
<?php
 }
 ?>
  </table>
 <?php
}
?>

<?
function display_recent_messages_full_order($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;		
	
	if ($_SESSION["highlightIdMsg"] == $myrow["thread"]) { $color = "#e28080";
	                                         $class = "lastvisited";
											 }
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD><? echo $myrow["author"]; ?></a></TD>
  <TD><? 
  if (strlen($myrow["message"]) > 50)
	 echo substr($myrow["message"],0,50) . "...";
  else
  echo $myrow["message"]; 
  ?>
  <a href="viewdetail.php?orderid=<? echo $myrow["thread"]; ?>">&raquo;</a>
  </TD>
  <TD><? echo date('F j, Y', $myrow["posted"]); ?></a></TD>
</TR>
<?php
 }
 ?>
  </table>
 <?php
}
?>

<?
function display_recent_messages($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
		
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD><? echo $myrow["author"]; ?></a></TD>
  <TD><? 
	if ($myrow[question] == "Yes" && $myrow[answer] != "Yes") echo "<b style=\"color:#ae0011\">PLEASE ANSWER OPEN QUESTION!</b><br>"; 

  if (strlen($myrow["message"]) > 50)
	 echo substr($myrow["message"],0,50) . "...";
  else
  echo $myrow["message"]; 
  ?>
  <a href="viewdetail-special.php?specialorderid=<? echo $myrow["thread"]; ?>">&raquo;</a>
  </TD>
</TR>
<?php
 }
 ?>
  </table>
 </div>
 <?php
}
?>
<?
function display_recent_messages_order($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
		
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD><? echo $myrow["author"]; ?></a></TD>
  <TD><? 
	if ($myrow[question] == "Yes" && $myrow[answer] != "Yes") echo "<b style=\"color:#ae0011\">PLEASE ANSWER OPEN QUESTION!</b><br>"; 

  if (strlen($myrow["message"]) > 50)
	 echo substr($myrow["message"],0,50) . "...";
  else
  echo $myrow["message"]; 
  ?>
  <a href="viewdetail.php?orderid=<? echo $myrow["thread"]; ?>">&raquo;</a>
  </TD>
</TR>
<?php
 }
 ?>
<!--  </table>
 </div>-->
 <?php
}
?>
<?
function table_shipmanager_header_index($title,$color) {
?>
<div id="shipment_table">
<table width="100%" cellpadding="1" cellspacing="2" border="1">
<tr><td colspan=9 align=center class=special_order_status style="background-color:<? echo $color;?>;">---- <? echo $title; ?> ----</td></tr>
<TR>
	<TD class=menu>Ship No.</B></TD>
	<TD class=menu>Tracking</B></TD>
	<TD class=menu>Options</B></TD>
</TR>
<? } ?>
<?
function display_shipmanager_data_index($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
		
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail-shipment.php?shipid=<? echo $myrow["shipid"]; ?>"><? echo $myrow["shipno"]; ?></a></TD>
  <TD><? echo $myrow["tracking"]; ?></TD>
  <TD>
    <a href="edit.php?op=shipedit&shipid=<? echo $myrow["shipid"]; ?>">Edit</a>&nbsp;
    <a href="viewdetail-shipment.php?shipid=<? echo $myrow["shipid"]; ?>">View</a>&nbsp;
  </TD>
</TR>
<?php
 }
 ?>
<!--  </table>
 </div>-->
 <?php
}
?>
<?
function display_shipmanager_data($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
		
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail-shipment.php?shipid=<? echo $myrow["shipid"]; ?>"><? echo $myrow["shipno"]; ?></a></TD>
  <TD><? echo $myrow["startdate"]; ?></TD>
    <TD><? echo $myrow["invoiceno"]; ?></TD>
  <TD><? echo $myrow["carrier"]; ?></TD>
  <TD><? echo $myrow["tracking"]; ?></TD>
  <TD>
    <a href="edit.php?op=shipedit&shipid=<? echo $myrow["shipid"]; ?>">Edit</a>&nbsp;
    <a href="viewdetail-shipment.php?shipid=<? echo $myrow["shipid"]; ?>">View</a>&nbsp;
  </TD>
</TR>
<?
 }
}
?>

<?
function display_returnmanager_data($result) {
include ("config.php");
$db = mysql_connect($dbhost, $dbusername,$dbuserpass);
mysql_select_db($dbname,$db);
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
		
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>" >
  <TD> <a href="viewdetail-return.php?returnid=<? echo $myrow["returnid"]; ?>"><? echo $myrow["returnno"]; ?></a></TD>
  <TD><? echo $myrow["startdate"]; ?></TD>
  <TD><? echo $myrow["carrier"]; ?></TD>
  <TD><? echo $myrow["tracking"]; ?></TD>
  <TD>
    <a href="edit.php?op=returnedit&returnid=<? echo $myrow["returnid"]; ?>">Edit</a>&nbsp;
    <a href="viewdetail-return.php?returnid=<? echo $myrow["returnid"]; ?>">View</a>&nbsp;
  </TD>
</TR>
<?
 }
}
?>

<?
function table_special_header_status($title,$color) {
?>
<table width="100%" cellpadding="1" cellspacing="2" border="1">
<tr><td colspan=9 align=center class=special_order_status style="background-color:<? echo $color;?>;">-- <? echo $title; ?> --</td></tr>
<TR>
	<TD class=menu>Special Order Info</B></TD>
	<TD class=menu>Painting Info</B></TD>
	<TD class=menu>Start and End Date</B></TD>
	<TD class=menu>Price and Cost</B></TD>
	<TD class=menu>Comments</B></TD>
	<TD class=menu>Image</B></TD>
</TR>
<? } ?>
<?
function table_special_header_color($title,$color) {
?>
<div id="special_order_table2">
<table width="100%" cellpadding="1" cellspacing="2" border="1">
<tr><td colspan=9 align=center class=special_order_status style="background-color:<? echo $color;?>;"><? echo $title; ?></td></tr>
<TR>
	<TD class=menu>Special Order Number</B></TD>
	<TD class=menu>Customer Name</B></TD>
	<!--<TD class=menu>Painting Name and Size</B></TD>
	<TD class=menu>Price and Cost</B></TD>
	<TD class=menu>Part Number US</B></TD>
	<TD class=menu>Start Date</B></TD>
	<TD class=menu>End Date</B></TD>-->
	<TD class=menu>Status</B></TD>
<!--	<TD class=menu>Options</B></TD>-->
</TR>
<? } ?>
<?
function table_header_monthly_sales($title) 
{
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=17><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Select</b></td>
  <td><b>Item Number</b></td>
   <td><b>Name</b></td>
  <td><b>Units on Hand</b></td>  
  <td><b>Qty Sold Yr.</b></td>  
  <td><b>Jan 01</b></td>
  <td><b>Feb 02</b></td>
<td><b>March 03</b></td>
<td><b>April 04</b></td>
<td><b>May 05</b></td>
<td><b>June 06</b></td>
<td><b>July 07</b></td>
<td><b>Aug 08</b></td>
<td><b>Sep 09</b></td>
<td><b>Oct 10</b></td>
<td><b>Nov 11</b></td>
<td><b>Dec 12</b></td>
</tr>
<? } ?>
<?
function table_header_peachtree_2($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=11><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Select</b></td>
  <td><b>Item Number</b></td>
   <td><b>Name</b></td>
   <td><b>Units Sold</b></td>
  <td><b>Total Sales</b></td>
  <td><b>Qty on Hand</b></td>
  <td><b>Qty on Order</b></td>
  <td><b>Avg Price</b></td>
</tr>
<? } ?>
<?
function table_header_urgent($title) {
?>
<div id="main_urgent_table">
<table border=1 width="100%">
<tr><td align=center class=order_status colspan=3><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
  <td><b>Item Number</b></td>
   <td><b>Units Sold</b></td>
  <td><b>Qty on Hand</b></td>
</tr>
<? } ?>
<?
function table_header_peachtree($title,$factor) {
?>
<style>
#headerset div
{
	float:left;
	font-weight:bold;
	border:solid #FFFFFF 1px;
	height:80px;
}
</style>
<table cellspacing="0" cellpadding="1" border="1" width="920">
 <tr valign="top">
    <td valign="top">
         <table cellspacing="0" cellpadding="1" border="1" width="920">
<tr><td class="subsection" colspan=15><b> <?php echo $title; ?> </td></tr>
<TR bgcolor="lightgrey"><TD colspan="15" style="padding-left: 0px;">
 <div style="width: 920px;" id="headerset">
	<?php	
	$year = date('Y')-1;
	$month = date('m');
	$previous =  date("M, Y",strtotime($year."-".$month."-01 +1 months"));
	$this_month = date("M, Y");
	$in_months = 12/$factor;
	
	if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ){ ?>
	<DIV style="WIDTH: 40px">No.</DIV>
	<DIV style="WIDTH: 69px">Item Number</DIV>
	<DIV style="WIDTH: 180px">Name</DIV>
<!--	<DIV style="WIDTH: 48px">Sales this month <BR><? echo $this_month ?></div>
	<DIV style="WIDTH: 48px">Sales next month <BR><? echo $previous ?></div> -->
	<DIV style="WIDTH: 49px">Units Sold <BR>in <? echo $in_months ?> Mon.</DIV>
	<DIV style="WIDTH: 69px">Total Sales</DIV>
	<DIV style="WIDTH: 56px">Qty on Hand</DIV>
	<DIV style="WIDTH: 53px">Qty on Order</DIV>
	<DIV style="WIDTH: 53px">Inv. Days 6 Mo.</DIV>
	<DIV style="WIDTH: 55px">Qty Sold 6 Mo.</DIV>
	<DIV style="WIDTH: 57px">ARS 6 Mo.</DIV>
	<DIV style="WIDTH: 55px">Days Until Stock Out</DIV>
	<DIV style="WIDTH: 55px">Days Until Rem. Out</DIV>
	<DIV style="WIDTH: 48px">Qty Recomended</DIV>
	<DIV style="WIDTH: 66px">Qty</DIV>	
<?php } 
		else{ ?>
  <div style="width: 40px;">No.</div>
  <div style="width: 66px;">Item Number</div>
  <div style="width: 180px;">Name</div>
<!--  <div style="width: 48px;">Sales this month <br/>
   <? echo $this_month ?></div>
  <div style="width: 47px;">Sales next month <br/>
    <? echo $previous ?></div> -->
  <div style="width: 49px;">Units Sold <br/>
    in <? echo $in_months ?> Months</div>
  <div style="width: 66px;">Total Sales</div>
  <div style="width: 53px;">Qty on Hand</div>
  <div style="width: 49px;">Qty on Order</div>
  <div style="width: 52px;">Inv. Days 6 Mo.</div>
  <div style="width: 54px;">Qty Sold 6 Mo.</div>
  <div style="width: 52px;">ARS 6 Mo.</div>
  <div style="width: 54px;">Days Until Stock Out</div>
  	<div style="width: 55px">Days Until Rem. Out</div>
  <div style="width: 47px;">Rec. Qty</div>
  <div style="width: 62px;">Qty</div>
<?php } ?>
 </div> 
</TD></TR>
</table>  
    </td>
  </tr>
<tr valign="top">
    <td valign="top">
	<div style="width: 920px; height: 400px; overflow:auto">
	<table cellspacing="0" cellpadding="1" border="1" width="900">
<? } ?>

<?
function table_header_peachtree_new($title,$factor) {
?>
<style>
#headerset div
{
	float:left;
	font-weight:bold;
	border:solid #FFFFFF 1px;
	height:80px;
	width: 1080px;
}
</style>
<table cellspacing="0" cellpadding="1" border="1" width="1080">
 <tr valign="top">
    <td valign="top">
         <table cellspacing="0" cellpadding="1" border="1" width="1080">
<tr><td class="subsection" colspan=15><b> <?php echo $title; ?> </td></tr>
<TR bgcolor="lightgrey"><TD colspan="14" style="padding-left: 0px;">
 <div id="headerset">
	<?php	
	$year = date('Y')-1;
	$month = date('m');
	$previous =  date("M, Y",strtotime($year."-".$month."-01 +1 months"));
	$this_month = date("M, Y");
	$in_months = 12/$factor;
	
	if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ){ ?>
	<DIV style="WIDTH: 40px">No.</DIV>
	<DIV style="WIDTH: 160px">Item Number</DIV>
	<DIV style="WIDTH: 160px">Name</DIV>
<!--	<DIV style="WIDTH: 48px">Sales this month <BR><? echo $this_month ?></div>
	<DIV style="WIDTH: 48px">Sales next month <BR><? echo $previous ?></div> -->
	
	<DIV style="WIDTH: 40px">Units Sold <BR>in <? echo $in_months ?> Mon.</DIV>
	<DIV style="WIDTH: 69px">Total Sales</DIV>
	<DIV style="WIDTH: 100px">Qty on Hand</DIV>
	<DIV style="WIDTH: 53px">Qty on Order</DIV>
	<DIV style="WIDTH: 53px">Inv. Days Year</DIV>
	<!--<DIV style="WIDTH: 55px">Qty Sold Year</DIV>-->
	<DIV style="WIDTH: 57px">ARS Year</DIV>
	<DIV style="WIDTH: 55px">Days Until Stock Out</DIV>
	<DIV style="WIDTH: 55px">Days Until Rem. Out</DIV>
	<DIV style="WIDTH: 48px">Qty Recomended</DIV>
	<DIV style="WIDTH: 66px">Qty</DIV>	
<?php } 
		else{ ?>
  <div style="width: 40px;">No.</div>
  <div style="width: 160px;">Item Number</div>
  <div style="width: 180px;">Name</div>
  <div style="width: 60px;">Units Sold <br/>
    in <? echo $in_months ?> Months</div>
  <div style="width: 91px;">Total Sales</div>
  <div style="width: 100px;">Qty on Hand</div>
  <div style="width: 42px;">Qty on Order</div>
  <div style="width: 47px;">Inv. Days Year</div>
  <div style="width: 48px;">Units Sold</div>
  <div style="width: 48px;">ARS Year</div>
  <div style="width: 53px;">Days Until Stock Out</div>
  <div style="width: 52px">Days Until Rem. Out</div>
  <div style="width: 49px;">Rec. Qty</div>
  <div style="width: 64px;">Qty</div>
<?php } ?>
 </div> 
</TD></TR>
</table>  
    </td>
  </tr>
<tr valign="top">
    <td valign="top">
	<div style="width: 1080px; height: 400px; overflow:auto">
	<table cellspacing="0" cellpadding="1" border="1" width="1060">
<? } ?>

<?
function table_header_newproducts2($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Select</b></td>
  <td><b>Part Number</b></td>
  <td><b>Painting Info</b></td>
   <td><b>Size</b></td>
  <td><b>Artist</b></td>
  <td><b>Image</b></td>
  <td><b>Qty</b></td>
</tr>
<? } ?>
<?
function table_header_newproducts($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Select</b></td>
  <td><b>Part Number</b></td>
  <td><b>Painting Info</b></td>
   <td><b>Past Orders</b></td>
  <td><b>Past Shippments</b></td>  
  <td><b>Size</b></td>
  <td><b>Image</b></td>
  <td><b>Qty</b></td>
</tr>
<? } ?>
<?
function table_header_china_us($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Select</b></td>
  <td><b>Item Number</b></td>
   <!--<td><b>Item Number China</b></td>-->
    <td><b>Yahoo ID</b></td>
</tr>
<? } ?>

<?
function table_header_man_days($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Count</b></td>
  <td><b>Item ID</b></td>
  <td><b>P/N US</b></td>
 <td><b>P/N China</b></td>
    <td><b>Manufacturing Days</b></td>
</tr>
<? } ?>

<?
function table_header_shipment($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Select</b></td>
  <td><b>Part Info</b></td>
   <td><b>Order Info</b></td>
  <td><b>Status</b></td>  
  <td><b>Start Date</b></td>
  <td><b>Image</b></td>
  <td><b>Qty Shipped</b></td>
    <td><b>Cost per Unit (RMB)</b></td>
</tr>
<? } ?>
<?
function table_header_view_shipment($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Shipment Line</b></td>
<td><b>Order Info</b></td>
  <td><b>Part Info</b></td>
  <td><b>Qty Shipped</b></td>
    <td><b>Total Cost</b></td>  
  <td><b>Image Requested</b></td>
  <td><b>Image Shipped</b></td>
  <td><b>Options</b></td>
</tr>
<? } ?>
<?
function table_header_view_return($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Return Line</b></td>
<td><b>Shippment to US</b></td>
  <td><b>Part Info</b></td>
  <td><b>Qty on Return</b></td>
    <td><b>Total Cost</b></td>  
  <td><b>Image Returned</b></td>
  <td><b>Options</b></td>
</tr>
<? } ?>
<?
function table_header_view_shipment_print($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Office Notes</b></td>
<td><b>Order Info</b></td>
  <td><b>Part Info</b></td>
  <td><b>Qty Shipped</b></td>
    <td><b>Total Cost</b></td>  
  <td><b>Image</b></td>
</tr>
<? } ?>

<?
function table_header_view_box_special_print($title) {
?>
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
<td><b>Office Notes</b></td>
<td><b>Order Info</b></td>
  <td><b>Part Info</b></td>
  <td><b>Qty Shipped</b></td>
   <!-- <td><b>Total Cost</b></td>  -->
  <td><b>Image</b></td>
</tr>
<? } ?>

<?
function table_header_view_box_print($title) {
?>
<tr><td class="subsection" colspan=7><b> <?php echo $title; ?> </td></tr>
<!--<tr bgcolor=lightgrey>
<td><b>Part Info + Qty</b></td>
  <td><b>Image</b></td>
<td><b>Part Info + Qty</b></td>
  <td><b>Image</b></td>
</tr>-->
<? } ?>
<?
function table_header_status($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
  <td><b>Item Number</b></td>
   <td><b>Name</b></td>
  <td><b>Qty</b></td>  
  <td><b>Date</b></td>
  <td><b>Comments</b></td>
  <td><b>Painting</b></td>
</tr>
<? } ?>

<?
function table_header_status_email($title) {

$header = '<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b>' . $title . ' </td></tr>
<tr bgcolor=lightgrey>  <td><b>Item Number</b></td>   <td><b>Name</b></td>  <td><b>Qty</b></td>   <td><b>Date</b></td>  <td><b>Comments</b></td>  <td><b>Painting</b></td></tr>';

return $header;
}
?>

<?
function table_header_event($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
  <td><b>Item Info</b></td>
   <td><b>Event</b></td>
  <td><b>Qty</b></td>  
  <td><b>Communicator Production Status</b></td>
  <!--<td><b>Production Status</b></td>-->
  <td><b>Painting</b></td>
</tr>
<? } ?>

<?
function table_header_special_status($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
  <td><b>Order Info</b></td>
   <td><b>Name</b></td>
  <td><b>Qty</b></td>  
  <td><b>Date</b></td>
  <td><b>Comments</b></td>
  <td><b>Painting</b></td>
</tr>
<? } ?>
<?
function table_header_orderline($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
  <!-- <td><b>Order Line Name</b></td> -->
  <td><b>Last Modified by</b></td>
   <td><b>Part Number</b></td>
  <td><b>Quantity</b></td>  
  <td><b>Status</b></td>
  <td><b>Start/End Date</b></td>
  <!--<td><b>Description</b></td>-->
  <td><b>Image</b></td>
  <td><b>Options</b></td>
</tr>
<? } ?>

<?
function table_header_parts($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
   <td><b>Part Number</b></td> 
  <td><b>Image</b></td>
  <td><b>Options</b></td>
</tr>
<? } ?>

<?
function table_header_devline($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
 <td><b>Check</b></td> 
  <td><b>Last Modified by</b></td>
   <td><b>Part Number</b></td>
 <!-- <td><b>Quantity</b></td>  -->
  <td><b>Status</b></td>
 <!-- <td><b>Start/End Date</b></td>-->
  <td><b>Image</b></td>
  <td><b>Options</b></td>
 <td><b>Qty</b></td>
</tr>
<? } ?>
<?
/*
function table_header_specialorder($title) {
?>
<table border=1 width="100%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
  <td><b>Special Order Number</b></td>
  <td><b>Customer Name</b></td>
   <td><b>Painting Info</b></td>
  <td><b>Quantity</b></td>  
  <td><b>Status</b></td>
  <td><b>Start Date</b></td>
  <td><b>End Date</b></td>
  <td><b>Image</b></td>
  <td><b>Options</b></td>
</tr>
<? } */?>
<?
function table_header_orderline_print($title) {
?>
<table border=1 width="70%">
<tr><td class="subsection" colspan=9><b> <?php echo $title; ?> </td></tr>
<tr bgcolor=lightgrey>
  <td><b>User</b></td>
   <td><b>Part Number</b></td>
  <td><b>Quantity</b></td>  
  <td><b>Status</b></td>
  <td><b>Start/End Date</b></td>
  <td><b>Image</b></td>
</tr>
<? } ?>
<?
function table_header_part($title) {
?>
<table border=1 width="100%">
<tr><td colspan=7 align=center class=part_status>---- <? echo $title; ?> ----</td></tr>
<TR>
	<TD class=menu><B>Part Number</B></TD>
	<TD class=menu><B>Painting Name</B></TD>
	<TD class=menu><B>Order History</B></TD>
	<TD class=menu><B>Ship History</B></TD>
	<TD class=menu><B>Size</B></TD>
	<TD class=menu><B>Image</B></TD>
	<TD class=menu><B>Options</B></TD>
</TR>
<? } ?>
<?
function display_shipped($result) {
// Loop Thru Records
 while($myrow = mysql_fetch_array($result))
  {
    $i == 0 ? $color = "#FFFFFF" : $color = "#DDDDDD";
	$i == 0 ? $class = "normal" : $class = "normal2";
    $i == 0 ? $i = 1 : $i = 0;
?>
<TR onMouseOver=this.className='highlight' onMouseOut=this.className='<? echo $class; ?>' bgcolor="<? echo $color; ?>">
  <TD> <a href="viewdetail.php?orderid=<? echo $myrow["orderid"]; ?>"><? echo $myrow["ordernumber"]; ?></a></TD>
  <TD><? echo $myrow["startdate"]; ?></TD>
  <TD><? echo $myrow["enddate"]; ?></TD>
</TR>
<?
 }
}
?>
<?
function report_header($title) {
?>
<table border=1 width="100%">
<tr><td colspan=7 align=center><div class=subsection>----<font color=white><b> OverstockArt Communicator: </font><? echo $title; ?> ----</font></center></td></tr>
<TR>
	<TD class=menu>Order Number</B></TD>
	<TD class=menu>Start Date</B></TD>
	<TD class=menu>End Date</B></TD>
</TR>
<? } ?>
<?php
/*function createthumb($name,$filename,$new_w,$new_h){
			$type = getimagesize($name);
			$type1 = $type[2];
			//echo $type1;  //jpeg = 2 gif = 1
			if ($type1 == 1)
            {
                    $src_img=imagecreatefromgif($name);
            }
            else
			{
					$src_img=imagecreatefromjpeg($name);
            }
			$filename = $filename . ".jpg";
 // if (file_exists($filename)) return $filename; //no need to create the thumb...
  			
  $old_x=imagesx($src_img);
  $old_y=imagesy($src_img);
            $thumb_w= $new_w;
            $thumb_h= ($new_w*$old_y)/$old_x;
 
  $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
  imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
  
            imagejpeg($dst_img,$filename); 
            imagedestroy($dst_img); 
            imagedestroy($src_img); 
			
	//return $filename;
}*/
function createthumb($name,$filename,$new_w,$new_h){
    
	$system=explode('.',$name);
	if (preg_match('/png/',$system[1])){
		$src_img=imagecreatefrompng($name);
	}
	if (preg_match('/gif/',$system[1])){
		$src_img=imagecreatefromgif($name);
	}
	else
		$src_img=imagecreatefromjpeg($name);
	 
  $old_x=imageSX($src_img);
  $old_y=imageSY($src_img);
  if ($old_x > $old_y) {
	$thumb_w=$new_w;
	$thumb_h=$old_y*($new_h/$old_x);
  }
  if ($old_x < $old_y) {
	$thumb_w=$old_x*($new_w/$old_y);
	$thumb_h=$new_h;
  }
  if ($old_x == $old_y) {
	$thumb_w=$new_w;
	$thumb_h=$new_h;
  } 
  
  $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
  imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
   if (preg_match("/png/",$system[1]))
   {
	imagepng($dst_img,$filename); 
    } else if (preg_match("/gif/",$system[1])) {
	imagegif($dst_img,$filename); 
    } else {
	imagejpeg($dst_img,$filename); 
   }
   
	imagedestroy($dst_img); 
	imagedestroy($src_img); 
}
function createthumbpng($name,$filename,$new_w,$new_h){
    
		$src_img=imagecreatefrompng($name);
  $old_x=imageSX($src_img);
  $old_y=imageSY($src_img);
  
	$thumb_w=$new_w;
	$thumb_h=$new_h;
  $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
  imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
	imagepng($dst_img,$filename); 
   
	imagedestroy($dst_img); 
	imagedestroy($src_img); 
}
?>
<?php
//This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }
 ?>
<?php
function rand_colorCode(){
$r = dechex(mt_rand(0,255)); // generate the red component
$g = dechex(mt_rand(0,255)); // generate the green component
$b = dechex(mt_rand(0,255)); // generate the blue component
$rgb = $r.$g.$b;
if($r == $g && $g == $b){
$rgb = substr($rgb,0,3); // shorter version
}
return '#'.$rgb;
}
function quotesplit($s, $splitter)
{
//First step is to split it up into the bits that are surrounded by quotes and the bits that aren't. Adding the delimiter to the ends simplifies the logic further down
    $getstrings = split('\"', $splitter.$s.$splitter);
//$instring toggles so we know if we are in a quoted string or not
    $delimlen = strlen($splitter);
    $instring = 0;
    while (list($arg, $val) = each($getstrings))
    {
        if ($instring==1)
        {
//Add the whole string, untouched to the result array.
            $result[] = $val;
            $instring = 0;
        }
        else
        {
//Break up the string according to the delimiter character
//Each string has extraneous delimiters around it (inc the ones we added above), so they need to be stripped off
            $temparray = split($splitter, substr($val, $delimlen, strlen($val)-$delimlen-$delimlen ) );
            while(list($iarg, $ival) = each($temparray))
            {
                $result[] = trim($ival);
            }
            $instring = 1;
        }
    }
    return $result;
}

function number_of_days($dateNow, $datePrevious)
{
$diff = $dateNow - $datePrevious;
$num_days =  $diff / (24 * 60 * 60);  //divide by seconds in a day
return round($num_days);
}

function barcodes($text,$orientation,$size,$codetype)
{
	$text = (isset($text)?$text:"0");
	$image_path = "barcodes/" . $text . ".png";
	$size = (isset($size)?$size:"20");
	$orientation = (isset($orientation)?$orientation:"horizontal");
	$code_type = (isset($codetype)?$codetype:"code128");
	$code_string = "";

	// Translate the $text into barcode the correct $code_type
	if(strtolower($code_type) == "code128")
	{
		$chksum = 104;
		// Must not change order of array elements as the checksum depends on the array's key to validate final code
		$code_array = array(" "=>"212222","!"=>"222122","\""=>"222221","#"=>"121223","$"=>"121322","%"=>"131222","&"=>"122213","'"=>"122312","("=>"132212",")"=>"221213","*"=>"221312","+"=>"231212",","=>"112232","-"=>"122132","."=>"122231","/"=>"113222","0"=>"123122","1"=>"123221","2"=>"223211","3"=>"221132","4"=>"221231","5"=>"213212","6"=>"223112","7"=>"312131","8"=>"311222","9"=>"321122",":"=>"321221",";"=>"312212","<"=>"322112","="=>"322211",">"=>"212123","?"=>"212321","@"=>"232121","A"=>"111323","B"=>"131123","C"=>"131321","D"=>"112313","E"=>"132113","F"=>"132311","G"=>"211313","H"=>"231113","I"=>"231311","J"=>"112133","K"=>"112331","L"=>"132131","M"=>"113123","N"=>"113321","O"=>"133121","P"=>"313121","Q"=>"211331","R"=>"231131","S"=>"213113","T"=>"213311","U"=>"213131","V"=>"311123","W"=>"311321","X"=>"331121","Y"=>"312113","Z"=>"312311","["=>"332111","\\"=>"314111","]"=>"221411","^"=>"431111","_"=>"111224","\`"=>"111422","a"=>"121124","b"=>"121421","c"=>"141122","d"=>"141221","e"=>"112214","f"=>"112412","g"=>"122114","h"=>"122411","i"=>"142112","j"=>"142211","k"=>"241211","l"=>"221114","m"=>"413111","n"=>"241112","o"=>"134111","p"=>"111242","q"=>"121142","r"=>"121241","s"=>"114212","t"=>"124112","u"=>"124211","v"=>"411212","w"=>"421112","x"=>"421211","y"=>"212141","z"=>"214121","{"=>"412121","|"=>"111143","}"=>"111341","~"=>"131141","DEL"=>"114113","FNC 3"=>"114311","FNC 2"=>"411113","SHIFT"=>"411311","CODE C"=>"113141","FNC 4"=>"114131","CODE A"=>"311141","FNC 1"=>"411131","Start A"=>"211412","Start B"=>"211214","Start C"=>"211232","Stop"=>"2331112");
		$code_keys = array_keys($code_array);
		$code_values = array_flip($code_keys);
		for($X = 1; $X <= strlen($text); $X++)
		{
			$activeKey = substr( $text, ($X-1), 1);
			$code_string .= $code_array[$activeKey];
			$chksum=($chksum + ($code_values[$activeKey] * $X));
		}
		$code_string .= $code_array[$code_keys[($chksum - (intval($chksum / 103) * 103))]];

		$code_string = "211214" . $code_string . "2331112";
	}
	elseif(strtolower($code_type) == "code39")
	{
		$code_array = array("0"=>"111221211","1"=>"211211112","2"=>"112211112","3"=>"212211111","4"=>"111221112","5"=>"211221111","6"=>"112221111","7"=>"111211212","8"=>"211211211","9"=>"112211211","A"=>"211112112","B"=>"112112112","C"=>"212112111","D"=>"111122112","E"=>"211122111","F"=>"112122111","G"=>"111112212","H"=>"211112211","I"=>"112112211","J"=>"111122211","K"=>"211111122","L"=>"112111122","M"=>"212111121","N"=>"111121122","O"=>"211121121","P"=>"112121121","Q"=>"111111222","R"=>"211111221","S"=>"112111221","T"=>"111121221","U"=>"221111112","V"=>"122111112","W"=>"222111111","X"=>"121121112","Y"=>"221121111","Z"=>"122121111","-"=>"121111212","."=>"221111211"," "=>"122111211","$"=>"121212111","/"=>"121211121","+"=>"121112121","%"=>"111212121","*"=>"121121211");

		// Convert to uppercase
		$upper_text = strtoupper($text);

		for($X = 1; $X<=strlen($upper_text); $X++)
		{
			$code_string .= $code_array[substr( $upper_text, ($X-1), 1)] . "1";
		}

		$code_string = "1211212111" . $code_string . "121121211";
	}
	elseif(strtolower($code_type) == "code25")
	{
		$code_array1 = array("1","2","3","4","5","6","7","8","9","0");
		$code_array2 = array("3-1-1-1-3","1-3-1-1-3","3-3-1-1-1","1-1-3-1-3","3-1-3-1-1","1-3-3-1-1","1-1-1-3-3","3-1-1-3-1","1-3-1-3-1","1-1-3-3-1");

		for($X = 1; $X <= strlen($text); $X++)
		{
			for($Y = 0; $Y < count($code_array1); $Y++)
			{
				if(substr($text, ($X-1), 1) == $code_array1[$Y])
					$temp[$X] = $code_array2[$Y];
			}
		}

		for($X=1; $X<=strlen($text); $X+=2)
		{
			$temp1 = explode( "-", $temp[$X] );
			$temp2 = explode( "-", $temp[($X + 1)] );
			for($Y = 0; $Y < count($temp1); $Y++)
				$code_string .= $temp1[$Y] . $temp2[$Y];
		}

		$code_string = "1111" . $code_string . "311";
	}
	elseif(strtolower($code_type) == "codabar")
	{
		$code_array1 = array("1","2","3","4","5","6","7","8","9","0","-","$",":","/",".","+","A","B","C","D");
		$code_array2 = array("1111221","1112112","2211111","1121121","2111121","1211112","1211211","1221111","2112111","1111122","1112211","1122111","2111212","2121112","2121211","1121212","1122121","1212112","1112122","1112221");

		// Convert to uppercase
		$upper_text = strtoupper($text);

		for($X = 1; $X<=strlen($upper_text); $X++)
		{
			for($Y = 0; $Y<count($code_array1); $Y++)
			{
				if(substr($upper_text, ($X-1), 1) == $code_array1[$Y] )
					$code_string .= $code_array2[$Y] . "1";
			}
		}
		$code_string = "11221211" . $code_string . "1122121";
	}

	// Pad the edges of the barcode
	$code_length = 20;
	for($i=1; $i <= strlen($code_string); $i++)
		$code_length = $code_length + (integer)(substr($code_string,($i-1),1));

	if(strtolower($orientation) == "horizontal")
	{
		$img_width = $code_length;
		$img_height = $size;
	}
	else
	{
		$img_width = $size;
		$img_height = $code_length;
	}

	$image = imagecreate($img_width, $img_height);
	$black = imagecolorallocate ($image, 0, 0, 0);
	$white = imagecolorallocate ($image, 255, 255, 255);

	imagefill( $image, 0, 0, $white );

	$location = 10;
	for($position = 1 ; $position <= strlen($code_string); $position++)
	{
		$cur_size = $location + ( substr($code_string, ($position-1), 1) );
		if(strtolower($orientation) == "horizontal")
			imagefilledrectangle( $image, $location, 0, $cur_size, $img_height, ($position % 2 == 0 ? $white : $black) );
		else
			imagefilledrectangle( $image, 0, $location, $img_width, $cur_size, ($position % 2 == 0 ? $white : $black) );
		$location = $cur_size;
	}
	// Draw barcode to the screen
	//header ('Content-type: image/png');
	imagepng($image, $image_path); 
	imagedestroy($image);
	
	return $image_path;
}
 ?>