<?

//$shopping_cart_description comes from shopping_cart_button_1.b! (making sample buttons)
if($shopping_cart_description) {
	$display_sample_shopping_cart = "YES";
}

//test("display_sample_shopping_cart",$display_sample_shopping_cart);
/*

$shopping_cart_number = "";
$shopping_cart_description = "";
$shopping_cart_color = "";
$shopping_cart_size = "";
$shopping_cart_weight = "";
$shopping_cart_price_per_item = "";
$shopping_cart_currency_code_iso3 = "";
$shopping_cart_quantity = "";
$shopping_cart_item_subtotal = "";



*/

//$page_row = $page_row + 1;
//$index_row = $index_row + 1;


//logger3("test",$test);



//logger3("_SESSION",$_SESSION);

if(!$display_sample_shopping_cart) {
	$tmp_sql = "SELECT shoppingcartid FROM shopping_cart WHERE cart_number = '" . $shopping_cart_number . "';";
	$shopping_cart_ids = arrayTHECASHIER($tmp_sql);
	//logger3("shopping_cart_ids",$shopping_cart_ids);
	
}
//logger3("tmp_sql",$tmp_sql);

//logger3("shopping_cart_ids",$shopping_cart_ids);
//logger3("shopping_cart_currency_code_iso3",$shopping_cart_currency_code_iso3);


echo "
<style>
.local_cart_menubar {
	color:#999999; 
	font-size:14px; 
	font-family:arial,helvetica; 
	font-weight:bold;
}

.local_cart_row {
	color:#444444;
	font-size:14px;
	font-family:arial,helvetica;
	font-weight:bold;
}
.local_cart_total {
	color:#444444;
	font-size:15px;
	font-family:arial,helvetica;
	font-weight:bold;
}
</style>";


echo "
<tr>
	<td colspan='" . $shopping_cart_colspan . "'>
		<table cellpadding='0' cellspacing='0' border='0' width='100%'>";





if($_SESSION['gallery']['cart']) {
	
	// PHOTO.BANGK!
	
	echo "
	<tr class='local_cart_menubar' style='text-align:left;'>
		<td width='40'>
			Item:
		</td><td style='padding-left:10px; padding-right:10px;'>
			<nobr>File Name:</nobr>
		</td><td style='text-align:center; padding-left:10px; padding-right:10px;'>
			<nobr>Height:</nobr>
		</td><td style='text-align:center; padding-left:10px; padding-right:10px;'>
			<nobr>Width:</nobr>
		</td><td style='text-align:center; padding-left:10px; padding-right:10px;'>
			<nobr>File Size:</nobr>
		</td><td style='text-align:right; padding-left:10px; padding-right:10px;'>";

} else { // DEFAULT
	echo "
	<tr class='local_cart_menubar' style='text-align:left;'>
		<td width='40'>
			Item:
		</td><td>
			Description:
		</td><td style='text-align:center;'>
			Color:
		</td><td style='text-align:center;'>
			Size:
		</td><td style='text-align:center;'>
			Weight:
		</td><td style='text-align:right;'>";	
}








//echo "Price/Item: (" . $tmp_shopping_cart_item['currency_code_iso3'] . ")";
echo "Price/Item:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

echo "
	</td><td style='text-align:right; padding-left:10px; padding-right:10px;'>
		Qnty:
	</td><td style='text-align:right; padding-right:25px;'>";
	
	//echo "Item Sub-Total: (" . $tmp_shopping_cart_item['currency_code_iso3'] . ")";
	echo "<nobr>Item Sub-Total:</nobr>";

echo "	
	</td>
</tr>
<tr>
	<td colspan='8'>
		<hr>
	</td>
</tr>

";

/// live
if(!$display_sample_shopping_cart) {
	
	logger3("_SESSION['gallery']['cart']",$_SESSION['gallery']['cart']);
	
	
	if($_SESSION['gallery']['cart']) {
		
		logger3("2_SESSION['gallery']['cart']",$_SESSION['gallery']['cart']);
		
		foreach($_SESSION['gallery']['cart'] as $key => $value) {
			
		
			logger3("value",$value);
			//exit;
			$shopping_cart_currency_code_iso3 = "USD";
			if(empty($shopping_cart_currency_code_iso3)) $shopping_cart_currency_code_iso3 = "USD";
		
		
			echo "
			<tr class='local_cart_row' style='text-align:left;'>
				<td>";
			
				$page_row = $page_row + 1;
				$index_row = $index_row + 1;
				
				if($special_row_character) {	
					echo $special_row_character;
				} else if($row_special_character) {
					echo $row_special_character;
				
				} else if( ($display_row_numbers != "NO") && ($display_row_numbers != "No") && ($display_row_numbers != "no") ) {
					$numberme = numberme($page_row,$index,$index_row); 
					echo $numberme[1] . $numberme[2];
				}
				
				//logger3("value",$value);
				// $tmp_file_name = $value['filename'];
				// $tmp_file_name = str_ireplace(".jpeg", ".jpg", $tmp_file_name);
				// $tmp_file_name = str_ireplace(".tiff", ".jpg", $tmp_file_name);
				// $tmp_file_name = str_ireplace(".tif", ".jpg", $tmp_file_name);
				// $tmp_file_name = str_ireplace(".raw", ".jpg", $tmp_file_name);
				// $tmp_file_name = str_ireplace(".ong", ".jpg", $tmp_file_name);
				
				$tmp_file_hash = $value['photoBANGK_hash'];
				
				$tmp_preview_url = "https://". $_SESSION['template']['company']['host_gateway'] ."/photoBANGK.gate?action=thumb&hash=". $tmp_file_hash;
				//test("tmp_preview_url",$tmp_preview_url);
				
				
				
				$tmp_item_price = "";
				if(stristr($value['photo_media'],"screen")) {
					$tmp_item_price = $value['price_online'];
					$tmp_image_type = "SOCIAL";
				}
				
				if(stristr($value['photo_media'],"wallpaper")) {
					$tmp_item_price = $value['price_wallpaper'];
					$tmp_image_type = "WALLPAPER";
				}
				
				if(stristr($value['photo_media'],"print")) {
					$tmp_item_price = $value['price_print'];
					$tmp_image_type = "ORIGINAL";
				}
				
				$dimension_details_array = calculate_image_dimension($type=$tmp_image_type,$original_height=$value['height_points'],$original_width=$value['width_points']);
				
				$tmp_image_type = "";
				$value['height_points'] = number_format($dimension_details_array['new_height']);
				$value['width_points'] = number_format($dimension_details_array['new_width']);
				
				
				
				echo "&nbsp;&nbsp;&nbsp;&nbsp;
			</td>
			
			
			
			
			</td><td>
			<!-- <img src='https://s3-us-west-2.amazonaws.com/nsdbphotobangk/thumb_". $tmp_file_name ."' style='height:25px;'> -->
			
			<img src='". $tmp_preview_url."' style='height:25px;'>
			
			
			
			" . $value['filename'] . "
			
			</td><td style='text-align:center;'>
			
			" . $value['height_points'] . " <span style='color:#AAAAAA;'>px</span>
			
			</td><td style='text-align:center;'>
			
			" . $value['width_points'] . " <span style='color:#AAAAAA;'>px</span>
			
			</td><td style='text-align:center;'>
			
			" . number_format($value['filesize_megs']/1000000,"1") . " <span style='color:#AAAAAA;'>mb</span>
			
			</td><td style='text-align:right;'>
			
			<span style='color:#AAAAAA;'>" . $shopping_cart_currency_code_iso3 . "</span>&nbsp;&nbsp;" . number_format($tmp_item_price,"2") . "
			
			</td><td style='text-align:right;'>";
			
	
			echo "1";
			
			echo "
			</td><td style='text-align:right;'>
			
			";
			
			if(number_format($tmp_item_price,"2") == "0.00") { 
				echo "FREE";
			} else {
				echo number_format($tmp_item_price,"2");
			}
			
			echo "
			</td>
		
		</tr>
		<tr>
			<td colspan='8'>
				<hr>
			</td>
		</tr>";
		
		}
	
		
		
		
	} else { // DEFAULT
		
		// bounce back to gallery:
		
		//test("_SESSION",$_SESSION);
		
		//jump("javascript","https://photo.bangk.com/".$_SESSION['payme']['business']['account']['emailaddress']);
		//exit;
		
		//test("shopping_cart_ids",$shopping_cart_ids);
		
		$continue = count($shopping_cart_ids);
		
		//test("continue",$continue);
		if($continue > 0) {
			foreach($shopping_cart_ids as $key => $value) {
				
				$tmp_sql = "SELECT * FROM shopping_cart WHERE shoppingcartid = '" . $value . "';";
				$tmp_shopping_cart_item = object2array(readTHECASHIER($tmp_sql));
				
				//logger3("tmp_shopping_cart_item",$tmp_shopping_cart_item);
				//logger3("tmp_shopping_cart_item['description']",$tmp_shopping_cart_item['description']);
					
				$shopping_cart_description = $tmp_shopping_cart_item['description'];
				
				//logger3("shopping_cart_description",$shopping_cart_description);
				
				
				$shopping_cart_color = str_replace("%2F","/",$tmp_shopping_cart_item['color']);
				$shopping_cart_size = str_replace("%2F","/",$tmp_shopping_cart_item['size']);
				$shopping_cart_weight = str_replace("%2F","/",$tmp_shopping_cart_item['weight']);
				
				
				
				$shopping_cart_currency_code_iso3 = $tmp_shopping_cart_item['currency_code_iso3'];
				$shopping_cart_price_per_item = $tmp_shopping_cart_item['price_per_item'];
				
				$shopping_cart_quantity = $tmp_shopping_cart_item['quantity'];
				$shopping_cart_http_referer = $tmp_shopping_cart_item['http_referer'];
				$shopping_cart_item_subtotal = currency_format($shopping_cart_price_per_item * $shopping_cart_quantity);
				$shopping_cart_grand_total = currency_format($shopping_cart_grand_total + $shopping_cart_item_subtotal);
			
				echo "
				<tr class='local_cart_row' style='text-align:left;'>
					<td>";
				
					$page_row = $page_row + 1;
					$index_row = $index_row + 1;
					
					if($special_row_character) {	
						echo $special_row_character;
					} else if($row_special_character) {
						echo $row_special_character;
					
					} else if( ($display_row_numbers != "NO") && ($display_row_numbers != "No") && ($display_row_numbers != "no") ) {
						$numberme = numberme($page_row,$index,$index_row); 
						echo $numberme[1] . $numberme[2];
					}
					
					//logger3("shopping_cart_description",$shopping_cart_description);
					echo "&nbsp;&nbsp;&nbsp;&nbsp;
				</td>
				
				</td><td>
				
				" . $shopping_cart_description . "
				
				</td><td style='text-align:center;'>
				
				" . $shopping_cart_color . "
				
				</td><td style='text-align:center;'>
				
				" . $shopping_cart_size . "
				
				</td><td style='text-align:center;'>
				
				" . $shopping_cart_weight . "
				
				</td><td style='text-align:right;'>
				
				<span style='color:#AAAAAA;'>" . $shopping_cart_currency_code_iso3 . "</span>&nbsp;&nbsp;" . $shopping_cart_price_per_item . "
				
				</td><td style='text-align:right;'>";
				
				if($shopping_cart_style == "final") {
					
					echo $shopping_cart_quantity;
				
				} else {
				
					echo "<input type='text' size='2' maxlength='3' name='shopping_cart_id_to_update[" . $tmp_shopping_cart_item['shoppingcartid'] . "]' value='" . $shopping_cart_quantity . "'>";
				
				}
				
				echo "
				</td><td style='text-align:right;'>
				
				" . $shopping_cart_item_subtotal . "
				
				</td>
			
			</tr>
			<tr>
				<td colspan='8'>
					<hr>
				</td>
			</tr>";
			
			}
		}
		
		
	}
	
	
//$shopping_cart_description comes from shopping_cart_button_1.b! (making sample buttons)
} else {
	
		//logger3("flag",1);
		echo "
		<tr style='color:#444444; font-size:12px; font-family:arial,helvetica; font-weight:bold; text-align:left;'>
			<td>";
		
			$page_row = $page_row + 1;
			$index_row = $index_row + 1;
			
			if($special_row_character) {	
				echo $special_row_character;
			} else if($row_special_character) {
				echo $row_special_character;
			
			} else if( ($display_row_numbers != "NO") && ($display_row_numbers != "No") && ($display_row_numbers != "no") ) {
				$numberme = numberme($page_row,$index,$index_row); 
				echo $numberme[1] . $numberme[2];
			}
			
			//logger3("shopping_cart_description",$shopping_cart_description);
			echo "&nbsp;&nbsp;&nbsp;&nbsp;
		</td>
		
		</td><td>
		
		" . $shopping_cart_description . "
		
		</td><td style='text-align:center;'>
		
		" . $shopping_cart_color . "
		
		</td><td style='text-align:center;'>
		
		" . $shopping_cart_size . "
		
		</td><td style='text-align:center;'>
		
		" . $shopping_cart_weight . "
		
		</td><td style='text-align:right;'>
		
		<span style='color:#AAAAAA;'>" . $shopping_cart_currency_code_iso3 . "</span>&nbsp;&nbsp;" . $shopping_cart_price_per_item . "
		
		</td><td style='text-align:right;'>";
		
		//if($shopping_cart_style == "final") {
			
			echo $shopping_cart_quantity;
		
		//} else {
		
			//echo "<input type='text' size='2' maxlength='3' name='shopping_cart_id_to_update[" . $tmp_shopping_cart_item['shoppingcartid'] . "]' value='" . $shopping_cart_quantity . "'>";
		
		//}
		
		echo "
		</td><td style='text-align:right;'>
		
		" . $shopping_cart_item_subtotal . "
		
		</td>
	
	</tr>
	<tr>
		<td colspan='8'>
			<hr>
		</td>
	</tr>";

	
	
}

//test("display_sample_shopping_cart",$display_sample_shopping_cart);

if(!$display_sample_shopping_cart) {

	if(
	(strstr($_SERVER['HTTP_HOST'],"shopping"))
	) {
		echo "
	<tr class='local_cart_total'>
		<td colspan='7' style='text-align:right;'>
			GRAND TOTAL (" . $shopping_cart_currency_code_iso3 . "):
		</td>
		<td style='text-align:right;'>
			" . $shopping_cart_grand_total . "
		</td>
	</tr>
	<tr>
		<td colspan='8'>
			<hr>
		</td>
	</tr>";
	} else {
		$_SESSION['shopping']['action'] = "edit";
		
		if($_SESSION['gallery']['cart']) {
			$shopping_cart_grand_total = $_SESSION['payme']['amount'];
		}
		
		$tmp_click_to_edit_shopping_cart_url = "";
		
		if($_SESSION['gallery']['cart']) {
			
			$tmp_click_to_edit_shopping_cart_url = "https://photo." . $_SESSION['template']['company']['domain'] . "/" . $_SESSION['gallery']['account']['emailaddress'] . "?portfolio=all";
			
		} else { // DEFAULT
			
			$tmp_click_to_edit_shopping_cart_url = "https://" . $_SESSION['template']['company']['host_shopping'] . "/" . $_SESSION['gateway']['business']['emailaddress'];
			
		}
		
		//logger3("tmp_click_to_edit_shopping_cart_url",$tmp_click_to_edit_shopping_cart_url);
		if(empty($shopping_cart_currency_code_iso3)) $shopping_cart_currency_code_iso3 = "USD";
		
		echo "
	<tr style='color:#444444; font-size:11px; font-family:arial,helvetica; font-weight:bold;'>
		<td colspan='4' style='text-align:left; font-size:14px; font-weight:bold;'>
			<button class='submit_button_10px' style='color:#770000;' type='button' name='edit_hopping_cart_button' value='Click to Edit your Shopping Cart.' onclick='window.location=\"". $tmp_click_to_edit_shopping_cart_url. "\"'>Click to Edit your Shopping Cart (or Cancel)</button>
		</td>	
		<td colspan='3' style='text-align:right; font-size:14px; font-weight:bold;'>
			GRAND TOTAL (" . $shopping_cart_currency_code_iso3 . "):
		</td>
		<td style='text-align:right; font-size:14px; font-weight:bold;'>
			" . $shopping_cart_grand_total . "
		</td>
	</tr>
	<tr>
		<td colspan='8'>
			<hr>
		</td>
	</tr>";
	}
}

echo "</table>
	</td>
</tr>";


if(!$display_sample_shopping_cart) {

	### UPDATE CURRENCIES:
	/// SET BUSINESS CURRENCIES FIRST:
		//if NON-USD payment request (TRANSLATION REQUIRED)
	### if(
	###     isset($shopping_cart_currency_code_iso3) &&
	###     ($shopping_cart_currency_code_iso3 != $_SESSION['template']['company']['currency1']) 
	###     ) {
	###     
	###     // set special var
	###  	$tmp_business_ratio  = get_fx($shopping_cart_currency_code_iso3,$_SESSION['template']['company']['currency1'], "1.00");
	###     
	###     // business
	###     $include_payme['currency']['business']['code'] = $shopping_cart_currency_code_iso3;
	###     $include_payme['currency']['business']['ratio'] = get_fx($_SESSION['template']['company']['currency1'],$shopping_cart_currency_code_iso3,"1.00");;
	###     $include_payme['currency']['business']['amount'] = $shopping_cart_grand_total;
	###     $include_payme['currency']['business']['fee'] = NULL;
	###     $include_payme['currency']['business']['total'] = NULL;
	###     //base
	###     $include_payme['currency']['base']['code'] = NULL;
	###     $include_payme['currency']['base']['amount'] = currency_format($shopping_cart_grand_total * $tmp_business_ratio);
	###     $include_payme['currency']['base']['fee'] = NULL;
	###     $include_payme['currency']['base']['total'] = NULL;
	### } else {
		//if USD-based payment request (NO TRANSLATION REQUIRED)
	    $include_payme['currency']['business']['code'] = NULL;
	    $include_payme['currency']['business']['ratio'] = NULL;
	    $include_payme['currency']['business']['amount'] = NULL;
	    $include_payme['currency']['business']['fee'] = NULL;
	    $include_payme['currency']['business']['total'] = NULL;
	    
	    $include_payme['currency']['base']['code'] = NULL;
	    $include_payme['currency']['base']['amount'] = $shopping_cart_grand_total;
	    $include_payme['currency']['base']['fee'] = NULL;
	    $include_payme['currency']['base']['total'] = NULL;
	### }
	//customer
	$include_payme['currency']['customer']['code'] = NULL;
	$include_payme['currency']['customer']['ratio'] = NULL;
	$include_payme['currency']['customer']['amount'] = NULL;
	$include_payme['currency']['customer']['fee'] = NULL;
	$include_payme['currency']['customer']['total'] = NULL;
	include($_SESSION['template']['company']['file_path'] . "www/default_gateway_vars_currency.bi");
	logger("SET: payme['currency']: "); logger($payme['currency']);
}


### CLEAR VARS:
unset($display_row_numbers);
unset($row_input_id_1);
unset($row_input_id_2);
unset($special_row_character);
unset($row_special_character);
unset($shopping_cart_description);
unset($shopping_cart_color);
unset($shopping_cart_size);
unset($shopping_cart_weight);
unset($shopping_cart_price_per_item);
unset($shopping_cart_quantity);
unset($shopping_cart_item_subtotal);
unset($shopping_cart_number);
unset($shopping_cart_currency_code_iso3);

?>
