Location: PHPKode > scripts > PHPMass Shopping Cart > phpmass-shopping-cart/user/addressesinfo.php
<?php
/******************************************************************
 * PHPMass Shopping Cart
 * The contents of this file are subject to the PHPMass License. 
 * If you do not agree with PHPMass License Terms and Conditions 
 * than you should not use this software.
 * A copy of the license file is available on www.phpmass.com/license.htm page.
 * 
 * PHPMass.com.
 * All Rights Reserved.
 ******************************************************************/
$SiteSection = 'user';
require('../includes/config.php');
// Cart and top products
$LastProducts = $Carts->getLastProducts();
if (is_array($LastProducts)) {
	$LastProduct = array_shift($LastProducts);
}
$smarty->assign('LastProduct', $LastProduct);
$smarty->assign('LastProducts', $LastProducts);

$TopProducts = $Categories->getTopProducts(0,false,true);
$smarty->assign('TopProducts', $TopProducts);

// END Cart and top products


if (isset($_POST['updateAddress'])) {
	if (!hasLength($_POST['userAddress'],4,255)) $Error['AddressName_NotValid'] = $Lang['AddressName_NotValid'];
	if (!hasLength($_POST['usercity'],4,50)) $Error['City_NotValid'] = $Lang['City_NotValid'];
	if (!isZipcode($_POST['userZipcode'])) $Error['ZipCode_NotValid'] = $Lang['ZipCode_NotValid'];

	if (count($Error) == 0) {
		$Users->updateAddressID($userid,$_POST['addrID'],$_POST['userAddress'],$_POST['usercity'],$_POST['userCountry'],$_POST['userState'],$_POST['userZipcode']);
		$InfoMessage['Address_Updated'] = $Lang['Address_Updated'];
	}
}
elseif (isset($_POST['newAddress'])) {
	if (!hasLength($_POST['userAddress'],4,255)) $Error['AddressName_NotValid'] = $Lang['AddressName_NotValid'];
	if (!hasLength($_POST['usercity'],4,50)) $Error['City_NotValid'] = $Lang['City_NotValid'];
	if (!isZipcode($_POST['userZipcode'])) $Error['ZipCode_NotValid'] = $Lang['ZipCode_NotValid'];
	if (count($Error) == 0) {
		$Users->insertAddress($userid,$_POST['userAddress'],$_POST['usercity'],$_POST['userCountry'],$_POST['userState'],$_POST['userZipcode']);
		$InfoMessage['Address_Inserted'] = $Lang['Address_Inserted'];
	}
}
elseif (isset($_GET['deleteAddress'])) {
	$UserAddresses = $Users->getAddresses($userid);
	if (count($UserAddresses) >= 2){
		$Users->deleteAddress($userid,$_GET['deleteAddress']);
		$InfoMessage['Address_Deleted'] = $Lang['Address_Deleted'];
	}
	else $Error['Atleast_One_Address'] = $Lang['Atleast_One_Address'];

}

if (isset($_GET['modifyAddress'])) {
	$Countries = $Address->getCountries();
	$CurrentAddress = $Users->getAddressById($userid,$_GET['modifyAddress']);
	$SelectedCities = $Address->getStates($CurrentAddress['country']);
	$smarty->assign('CurrentAddress', $CurrentAddress);
}
else {
	$SelectedCities = $Address->getStates();
	$Countries = $Address->getCountries();
}

$UserAddresses = $Users->getAddresses($userid);
if (count($UserAddresses) == 0) $InfoMessage['No_Addresses_Found'] = $Lang['No_Addresses_Found'];
$smarty->assign('Countries', $Countries);
$smarty->assign('Cities', $SelectedCities);
$smarty->assign('UserAddresses', $UserAddresses);

$smarty->assign('PageTitle', $Lang['Addresses']);
$smarty->assign('Error', $Error);
$smarty->assign('InfoMessage', $InfoMessage);

$smarty->display(DOC_ROOT.'/skin/templates/user/'.'addresses.tpl');

?>
Return current item: PHPMass Shopping Cart