<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if(isset( $_SESSION["sess_artistid"]) and $_SESSION["sess_artistid"]!= ""){
	$artistid = $_SESSION["sess_artistid"];
}else{
	header("Location:login.php");
	exit;
}



if(isset($_POST['submit']))
{


	$select_shipping_settings = "SELECT * FROM ".$tableprefix."shipping_settings ORDER BY nsort_order";
	$result_shipping_settings = mysql_query($select_shipping_settings);	

	while($shipping_settings_row = mysql_fetch_array($result_shipping_settings))
	{
	
		$field_name = "settings_".$shipping_settings_row['nset_id'];
	
		$update_settings = "UPDATE ".$tableprefix."shipping_settings SET vvalue=".GetSQLValueString($_POST[$field_name],"text")."
							WHERE vcode = '".$shipping_settings_row['vcode']."'";
							
		mysql_query($update_settings) or die(mysql_error());		
		$message = "Settings Updated Successfully !!";		
	}

}	



include "../includes/htmltop.php";


$sql = "SELECT * FROM ".$tableprefix."shipping_settings ORDER BY nsort_order";
$rs = mysql_query($sql) or die(mysql_error());

$regular_daily 		= "";
$on_call_air 		= "";
$one_time_pick 		= "";
$letter_center 		= "";
$customer_counter 	= "";
$customer_packing 	= "";
$letter_envelope 	= "";
$ups_tube 			= "";
$express_box 		= "";
$worldwide_25 		= "";
$worldwide_10 		= "";
$residential		= "";
$commercial			= "";
												

?>


<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_seller.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/artisttopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo TEXT_SHIP_SETT;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">	
					<form action="#" method="post" name="frmSettings" onSubmit="return checkSettings();">
						<table cellpadding="0" cellspacing="0" align="center" class="manage_table" width="100%">
																																																																									
<?php
		
												
			$java_script = "<script>
							function checkSettings()
							{";		

			if(mysql_num_rows($rs) > 0)
			{

				while($row = mysql_fetch_array($rs))
				{
				
					$row_id           = $row['nset_id'];
					$row_value        = $row['vvalue'];
					$description 	  = $row["vdescription"];
					$align_flag  	  = ""; 
					$input_text_label = "";
					$colspan          = "";
										
					if($row['vcode'] == 'shipping_origin')
					{
					
					
						$select_country = "SELECT country_name,country_iso_code_2 FROM ".$tableprefix."countries WHERE 1";
						$result_country = mysql_query($select_country);
					
						$input_text = "<select name='settings_$row_id'>";
					
						while($country_row = mysql_fetch_array($result_country))
						{
						
							$country_name = $country_row['country_name'];
							$country_code = $country_row['country_iso_code_2'];
						
							if($country_code == $row['vvalue'])
							{
							
								$country_selected = "selected";
							
							}
							else
							{
							
								$country_selected = "";
							
							}
							
							$input_text .= "<option value='$country_code' $country_selected>$country_name</option>";
							
						
						}
						
										
						$input_text .= "</select>";
						
						$colspan = 2;
					
					
					}
					elseif($row['vcode'] == 'ups_rate')
					{
					
					
						switch($row['vvalue'])
						{
						
							case "Regular+Daily+Pickup":$regular_daily = "selected";
							break;
							case "On+Call+Air":$on_call_air = "selected";
							break;
							case "One+Time+Pickup":$one_time_pick = "selected";
							break;
							case "Letter+Center":$letter_center = "selected";
							break;
							case "Customer+Counter":$customer_counter = "selected";
							break;
						}
						
					
						$input_text = "<select name='settings_$row_id'>
										<option {$regular_daily} value='Regular+Daily+Pickup'>Regular+Daily+Pickup</option>	
										<option {$on_call_air} value='On+Call+Air'>On+Call+Air</option>	
										<option {$one_time_pick} value='One+Time+Pickup'>One+Time+Pickup</option>	
										<option {$letter_center} value='Letter+Center'>Letter+Center</option>
										<option {$customer_counter} value='Customer+Counter'>Customer+Counter</option>
										</select>";
										
					
					}
					elseif($row['vcode'] == 'address_quote')
					{
					
					
						switch($row['vvalue'])
						{
						
							case "0":$residential = "selected";
							break;
							case "1":$commercial = "selected";
							break;
							
						}
						
					
						$input_text = "<select name='settings_$row_id'>
										<option {$residential} value='0'>Residential</option>	
										<option {$commercial} value='1'>Commercial</option>	
										</select>";
										
									
					}
					elseif($row['vcode'] == 'ups_container')
					{
					
					
						switch($row['vvalue'])
						{
						
							case "00":$customer_packing = "selected";
							break;
							case "01":$letter_envelope = "selected";
							break;
							case "03":$ups_tube = "selected";
							break;
							case "21":$express_box = "selected";
							break;
							case "24":$worldwide_25 = "selected";
							break;
							case "25":$worldwide_10 = "selected";
							break;
						}
						
					
						$input_text = "<select name='settings_$row_id'>
										<option {$customer_packing} value='00'>Customer Packaging</option>	
										<option {$letter_envelope} value='01'>UPS Letter Envelope</option>	
										<option {$ups_tube} value='03'>UPS Tube</option>	
										<option {$express_box} value='21'>UPS Express Box</option>
										<option {$worldwide_25} value='24'>UPS Worldwide 25 kilo</option>
										<option {$worldwide_10} value='25'>UPS Worldwide 10 kilo</option>
										</select>";
					
					}
					elseif($row['vcode'] == 'shipping_num_boxes')
					{
					
					
						$input_text = "<select name='settings_$row_id'>";
					
						for($i=1;$i<=5;$i++)
						{
						
							if($i == $row['vvalue'])
							{
							
								$box_selected = "selected";
							
							}
							else
							{
							
								$box_selected = "";
							
							}
							
							$input_text .= "<option value='$i' $box_selected>$i</option>";
							
						
						}
						
										
						$input_text .= "</select>";
					
					
					}
					elseif($row['vcode'] == 'shipping_box_display')
					{
					
					
						$input_text = "<select name='settings_$row_id'>";
					
						for($i=0;$i<=3;$i++)
						{
						
							if($i == $row['vvalue'])
							{
							
								$box_display_selected = "selected";
							
							}
							else
							{
							
								$box_display_selected = "";
							
							}
							
							$input_text .= "<option value='$i' $box_display_selected>$i</option>";
							
						
						}
						
										
						$input_text .= "</select>";
					
					
					}
					else
					{
					
						$input_text = "<input type='text' name='settings_$row_id' id ='settings_$row_id' value='$row_value' class='textbox_shipping' size='21'>";
						$java_script .=" if(trimSpaces(document.frmSettings.settings_$row_id.value) == '')
										 {
											alert('$description is a required field !!');
											document.frmSettings.settings_$row_id.focus();
											return false;
										 }";
										 
										 
					
					}
					if($row['vcode'] == 'shipping_handling' || $row['vcode'] == 'shipping_max')
					{
					
					
						$java_script .=" if(trimSpaces(!check_numeric(document.frmSettings.settings_$row_id.value)))
										 {
											alert('Please enter a numeric value !!');
											document.frmSettings.settings_$row_id.focus();
											return false;
										 }";
					
					
					}
					if($row['vcode'] == 'shipping_box_weight')
					{
					
						$input_text_label = "<td align='left'>
											&nbsp;<b>Package Tare Small to Medium - added percentage:weight</b><br>
											&nbsp;What is the weight of typical packaging of small to medium packages?<br>
											&nbsp;Example: 10% + 1lb 10:1<br>
											&nbsp;10% + 0lbs 10:0<br>
											&nbsp;0% + 5lbs 0:5<br>
											</td>";
																			
					}
					if($row['vcode'] == 'shipping_box_display')
					{
					
						$input_text_label = "<td align='left'>
											&nbsp;<b>Display Number of Boxes and Weight Status</b><br>
											&nbsp;Display Shipping Weight and Number of Boxes?<br>
											&nbsp;0= off<br>
											&nbsp;1= Boxes Only<br>
											&nbsp;2= Weight Only<br>
											&nbsp;3= Both Boxes and Weight<br>
											</td>";
																			
					}
					if($row['vcode'] == 'shipping_box_padding')
					{
					
						$input_text_label = "<td align='left'>
											&nbsp;<b>Larger packages - added packaging percentage:weight</b><br>
											&nbsp;What is the weight of typical packaging for Large packages?<br>
											&nbsp;Example: 10% + 1lb 10:1<br>
											&nbsp;10% + 0lbs 10:0<br>
											&nbsp;0% + 5lbs 0:5<br>
											</td>";
																			
					}
					/*if($row['vcode'] == 'ups_rate')
					{
					
						$align_flag = "valign='top'";
						$input_text_label = "<td width='60%' align='left'>
											&nbsp;<b>RDP - Regular+Daily+Pickup</b><br>
											&nbsp;<b>OCA - On+Call+Air</b><br>
											&nbsp;<b>OTP - One+Time+Pickup</b><br>
											&nbsp;<b>LC - Letter+Center</b><br>
											&nbsp;<b>CC - Customer+Counter</b><br>
											</td>";
																			
					}*/
					
					
									
			
?>				
	
									<tr>
										<td width="23%" align="right" valign="top"><?php echo stripslashes($row["vdescription"])?></td>
										<td width="3%" align="center" valign="top">:</td>
										
<?php

										
	
										if($colspan != "")
										{
										
																				
?>									
										
											<td width="74%" align="left" valign="top" colspan="<?php echo $colspan?>"><?php echo $input_text?></td><?php echo $input_text_label?>
<?php
	
										}
										else
										{	
	
?>									
											<td width="20%" align="left" valign="top"><?php echo $input_text?></td><?php echo $input_text_label?>
										
										
<?php
										}
	
?>									
								  </tr>	
	
	
													
										
									
<?php
	
			
	
			} //end while
			
			
		
		} // end if	
		
		$java_script .= "}</script>";
		
		echo $java_script;			
		
?>																				
																				
																				
						</table>

						</div>
						<div align="center">
							<input type="submit" name="submit" value="Update" class="button">
							<input type="button" name="back" value="Back" class="button" onClick="Javascript:history.go(-1);">
						</div>
						
				<!--content area end-->
								
		  </div>
				
				</form>
				
					<div align="left" class="clear_float"><img src="../images/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
?>