Location: PHPKode > projects > HikaShop > front/controllers/address.php
<?php
/**
 * @package		HikaShop for Joomla!
 * @version		1.4.3
 * @author		hikashop.com
 * @copyright	(C) 2010 HIKARI SOFTWARE. All rights reserved.
 * @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>
<?php
class addressController extends hikashopController{
	function __construct($config = array()){
		parent::__construct($config);
		$this->modify_views = array('edit');
		$this->add = array('add');
		$this->modify = array('save');
		$this->delete = array('delete');
	}
	function delete(){
		$addressdelete = JRequest::getInt('address_id',0);
		if($addressdelete){
			JRequest::checkToken('request') or jexit( 'Invalid Token' );
			$addressClass = hikashop::get('class.address');
			$oldData = $addressClass->get($addressdelete);
			if(!empty($oldData)){
				$user_id = hikashop::loadUser();
				if($user_id==$oldData->address_user_id){
					$addressClass->delete($addressdelete);
				}
			}
		}
		$this->listing();
	}
	function save(){
		JRequest::checkToken('request') or jexit( 'Invalid Token' );
		$addressClass = hikashop::get('class.address');
		$app =& JFactory::getApplication();
		$oldData = null;
		if(!empty($_REQUEST['address']['address_id'])){
			$oldData = $class->get($_REQUEST['address']['address_id']);
		}
		$fieldClass = hikashop::get('class.field');
		$addressData = $fieldClass->getInput('address',$oldData);
		$ok = true;
		if(empty($addressData)){
			$ok=false;
		}else{
			$user_id = hikashop::loadUser();
			$addressData->address_user_id=$user_id;		
			$address_id = $addressClass->save($addressData);
		}
		if(!$ok || !$address_id){
			if(version_compare(JVERSION,'1.6','<')){
				$app =& JFactory::getApplication();
				$session =& JFactory::getSession();
				$session->set('application.queue', $app->_messageQueue);
			}
			echo '<html><head><script type="text/javascript">javascript: history.go(-1);</script></head><body></body></html>';
			exit;
		}
		$redirect = JRequest::getWord('redirect','');
		global $Itemid;
		$url = '';
		if(!empty($Itemid)){
			$url='&Itemid='.$Itemid;
		}
		if($redirect=='checkout'){
			$app->setUserState( HIKASHOP_COMPONENT.'.shipping_address',0 );
			$app->setUserState( HIKASHOP_COMPONENT.'.billing_address',0 );
			$app->setUserState( HIKASHOP_COMPONENT.'.shipping_method','' );
			$app->setUserState( HIKASHOP_COMPONENT.'.shipping_id',0 );
			$app->setUserState( HIKASHOP_COMPONENT.'.payment_method','' );
			$app->setUserState( HIKASHOP_COMPONENT.'.payment_id',0 );
			$url = hikashop::completeLink('checkout&task=step&step='.JRequest::getInt('step',0).$url,false,true);
		}else{
			$url = hikashop::completeLink('address'.$url,false,true);
		}
		echo '<html><head><script type="text/javascript">parent.window.location.href=\''.$url.'\';</script></head><body></body></html>';
		exit;
	}
}
Return current item: HikaShop