Location: PHPKode > projects > HikaShop > back/controllers/user.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 UserController extends hikashopController{
	var $type='user';
	function __construct($config = array()){
		parent::__construct($config);
		$this->modify_views[]='editaddress';
		$this->modify[]='deleteaddress';
		$this->modify[]='saveaddress';
		$this->display[]='state';
		$this->display[]='clicks';
		$this->display[]='leads';
		$this->display[]='sales';
		$this->modify_views[]='pay';
		$this->modify[]='pay_confirm';
	}
	function deleteaddress(){
		$addressdelete = JRequest::getInt('address_id',0);
		if($addressdelete){
			$addressClass = hikashop::get('class.address');
			$oldData = $addressClass->get($addressdelete);
			if(!empty($oldData)){
				$addressClass->delete($addressdelete);
				JRequest::setVar('user_id',$oldData->address_user_id);
			}
		}
		$this->edit();
	}
	function cancel(){
		$order_id = JRequest::getInt('order_id');
		if(empty($order_id)){
			$cancel_redirect = JRequest::getString('cancel_redirect');
			if(empty($cancel_redirect)){
				$this->listing();
			}else{
				$this->setRedirect(urldecode($cancel_redirect));
			}
		}else{
			$this->setRedirect(hikashop::completeLink('order&task=edit&order_id='.$order_id,false,true));
		}
	}
	function saveaddress(){
		$addressClass = hikashop::get('class.address');
		$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{
			$address_id = $addressClass->save($addressData);
		}
		if(!$ok || !$address_id){
			$app =& JFactory::getApplication();
			if(version_compare(JVERSION,'1.6','<')){
				$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;
		}
		$url = hikashop::completeLink('user&task=edit&user_id='.$addressData->address_user_id,false,true);
		echo '<html><head><script type="text/javascript">parent.window.location.href=\''.$url.'\';</script></head><body></body></html>';
		exit;
	}
	function editaddress(){
		JRequest::setVar( 'layout', 'editaddress'  );
		return parent::display();
	}
	function state(){
		JRequest::setVar( 'layout', 'state' );
		return parent::display();
	}
	function clicks(){
		JRequest::setVar( 'layout', 'clicks' );
		return parent::display();
	}
	function leads(){
		JRequest::setVar( 'layout', 'leads' );
		return parent::display();
	}
	function sales(){
		JRequest::setVar( 'layout', 'sales' );
		return parent::display();
	}
	function pay(){
		JRequest::setVar( 'layout', 'pay' );
		return parent::display();
	}
	function pay_confirm(){
		$user_id = hikashop::getCID('user_id');
		if(!empty($user_id)){
			$class = hikashop::get('class.user');
			$user = $class->get($user_id);
			if(!empty($user)){
				$class->loadPartnerData($user);
				if(bccomp($user->accumulated['total'],0,5)){
					$method = JRequest::getCmd('pay_method');
					$pay = JRequest::getInt('pay',0);
					$order = null;
					$config =& hikashop::config();
					$order->order_currency_id = $user->user_currency_id;
					$order->order_full_price = $user->accumulated['total'];
					if(!empty($method)){
						$pluginClass = hikashop::get('class.plugins');
						$methods = $pluginClass->getMethods('payment');
						foreach($methods as $methodItem){
							if($methodItem->payment_type==$method){
								$order->order_payment_id = $methodItem->payment_id;
								$order->order_payment_method = $methodItem->payment_type;
								break;
							}
						}
						if(empty($order->order_payment_id)){
							$app =& JFactory::getApplication();
							$app->enqueueMessage('Payment method not found');
							return false;
						}
					}
					$order->order_status = $config->get('order_confirmed_status','confirmed');
					$order->history->history_reason=JText::sprintf('ORDER_CREATED');
					$order->history->history_notified=0;
					$order->history->history_type = 'creation';
					$product=null;
					$product->order_product_name=JText::sprintf('PAYMENT_TO_PARTNER',@$user->name.' ('.$user->user_partner_email.')');
					$product->order_product_code='';
					$product->order_type='partner';
					$product->order_product_price=$user->accumulated['total'];
					$product->order_product_quantity=1;
					$product->order_product_tax=0;
					$product->order_product_options='';
					$product->order_user_id = $user->user_id;
					$product->product_id=0;
					$order->cart = null;
					$order->cart->products = array($product);
					$orderClass = hikashop::get('class.order');
					$order->order_id = $orderClass->save($order);	
					if(!empty($order->order_id)){
						$db =& JFactory::getDBO();
						$query = 'UPDATE '.hikashop::table('click').' SET click_partner_paid=1 WHERE click_partner_id='.$user->user_id;
						$db->setQuery($query);
						$db->query();
						$query = 'UPDATE '.hikashop::table('order').' SET order_partner_paid=1 WHERE order_type=\'sale\' AND order_partner_id='.$user->user_id;
						$db->setQuery($query);
						$db->query();
						$query = 'UPDATE '.hikashop::table('user').' SET user_partner_paid=1 WHERE user_partner_id='.$user->user_id;
						$db->setQuery($query);
						$db->query();
						if(!empty($order->order_payment_id) && $pay){
							$url = hikashop::completeLink('user&task=pay_process&order_id='.$order->order_id,false,true);
							echo '<html><head><script type="text/javascript">parent.window.location.href=\''.$url.'\';</script></head><body></body></html>';
							exit;
						}
					}
				}else{
					$app =& JFactory::getApplication();
					$app->enqueueMessage('No affiliate money accumulated');
					return false;
				}
			} 
		}
		$url=hikashop::completeLink('user&task=edit&user_id='.$user_id,false,true);
		echo '<html><head><script type="text/javascript">parent.window.location.href=\''.$url.'\';</script></head><body></body></html>';
		exit;
	}
	function pay_process(){
		$order_id = hikashop::getCID('order_id');
		if(empty($order_id)){
			return false;
		}
		$user_id = JRequest::getInt('user_id');
		if(empty($user_id)){
			return false;
		}
		$orderClass = hikashop::get('class.order');
		$order = $orderClass->get($order_id);
		$userClass = hikashop::get('class.user');
		$user = $userClass->get($order->order_user_id);
		$orderClass->loadProducts($order);
		$order->cart->products =& $order->products;
		$pluginClass = hikashop::get('class.plugins');
		$methods = $pluginClass->getMethods('payment');
		$methods[$order->order_payment_id]->payment_params->address_type='';
		$methods[$order->order_payment_id]->payment_params->cancel_url=HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=user&task=edit&user_id='.$user->user_id;
		$methods[$order->order_payment_id]->payment_params->return_url=$methods[$order->order_payment_id]->payment_params->cancel_url;
		$methods[$order->order_payment_id]->payment_params->email=$user->user_partner_email;
		$data = hikashop::import('hikashoppayment',$order->order_payment_method);
		$data->onAfterOrderConfirm($order,$methods,$order->order_payment_id);
	}
}
Return current item: HikaShop