<?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 OrderViewOrder extends JView{
var $ctrl= 'order';
var $nameListing = 'ORDERS';
var $nameForm = 'HIKASHOP_ORDER';
var $icon = 'order';
function display($tpl = null){
$this->paramBase = HIKASHOP_COMPONENT.'.'.$this->getName();
$function = $this->getLayout();
if(method_exists($this,$function)) $this->$function();
parent::display($tpl);
}
function listing(){
$app =& JFactory::getApplication();
$fieldsClass = hikashop::get('class.field');
$fields = $fieldsClass->getData('backend_listing','order',false);
$pageInfo = null;
$pageInfo->search = $app->getUserStateFromRequest( $this->paramBase.".search", 'search', '', 'string' );
$pageInfo->filter->order->value = $app->getUserStateFromRequest( $this->paramBase.".filter_order", 'filter_order', 'b.order_id','cmd' );
$pageInfo->filter->order->dir = $app->getUserStateFromRequest( $this->paramBase.".filter_order_Dir", 'filter_order_Dir', 'desc', 'word' );
$pageInfo->limit->value = $app->getUserStateFromRequest( $this->paramBase.'.list_limit', 'limit', $app->getCfg('list_limit'), 'int' );
if(empty($pageInfo->limit->value)) $pageInfo->limit->value = 500;
$pageInfo->limit->start = $app->getUserStateFromRequest( $this->paramBase.'.limitstart', 'limitstart', 0, 'int' );
$pageInfo->filter->filter_status = $app->getUserStateFromRequest( $this->paramBase.".filter_status",'filter_status','','string');
$pageInfo->filter->filter_payment = $app->getUserStateFromRequest( $this->paramBase.".filter_payment",'filter_payment','','string');
$pageInfo->filter->filter_partner = $app->getUserStateFromRequest( $this->paramBase.".filter_partner",'filter_partner','','int');
$database =& JFactory::getDBO();
$filters = array('b.order_type=\'sale\'');
if(!empty($pageInfo->filter->filter_partner)){
if($pageInfo->filter->filter_partner==1){
$filters[]='b.order_partner_id != 0';
}else{
$filters[]='b.order_partner_id = 0';
}
}
switch($pageInfo->filter->filter_status){
case '':
break;
default:
$filters[]='b.order_status = '.$database->Quote($pageInfo->filter->filter_status);
break;
}
switch($pageInfo->filter->filter_payment){
case '':
break;
default:
$filters[]='b.order_payment_method = '.$database->Quote($pageInfo->filter->filter_payment);
break;
}
$searchMap = array('c.id','c.username','c.name','a.user_email','b.order_user_id','b.order_id','b.order_full_price');
foreach($fields as $field){
$searchMap[]='b.'.$field->field_namekey;
}
if(!empty($pageInfo->search)){
$searchVal = '\'%'.$database->getEscaped(JString::strtolower( $pageInfo->search ),true).'%\'';
$id = hikashop::decode($pageInfo->search);
$filter = implode(" LIKE $searchVal OR ",$searchMap)." LIKE $searchVal";
if(!empty($id)){
$filter .= " OR b.order_id LIKE '%".$database->getEscaped($id,true).'%\'';
}
$filters[] = $filter;
}
$order = '';
if(!empty($pageInfo->filter->order->value)){
$order = ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
}
if(!empty($filters)){
$filters = ' WHERE '. implode(' AND ',$filters);
}else{
$filters = '';
}
$query = ' FROM '.hikashop::table('order').' AS b LEFT JOIN '.hikashop::table('user').' AS a ON b.order_user_id=a.user_id LEFT JOIN '.hikashop::table('users',false).' AS c ON a.user_cms_id=c.id '.$filters.$order;
$database->setQuery('SELECT a.*,b.*,c.*'.$query,(int)$pageInfo->limit->start,(int)$pageInfo->limit->value);
$rows = $database->loadObjectList();
if(!empty($pageInfo->search)){
$rows = hikashop::search($pageInfo->search,$rows,'order_id');
}
$database->setQuery('SELECT COUNT(*)'.$query);
$pageInfo->elements->total = $database->loadResult();
$pageInfo->elements->page = count($rows);
jimport('joomla.html.pagination');
if($pageInfo->limit->value == 500) $pageInfo->limit->value = 0;
$pagination = new JPagination( $pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value );
hikashop::setTitle(JText::_($this->nameListing),$this->icon,$this->ctrl);
$bar = & JToolBar::getInstance('toolbar');
JToolBarHelper::editList();
JToolBarHelper::deleteList(JText::_('HIKA_VALIDDELETEITEMS'));
JToolBarHelper::divider();
$bar->appendButton( 'Pophelp',$this->ctrl.'-listing');
$bar->appendButton( 'Link', 'hikashop', JText::_('HIKASHOP_CPANEL'), hikashop::completeLink('dashboard') );
$toggleClass = hikashop::get('helper.toggle');
$this->assignRef('toggleClass',$toggleClass);
$this->assignRef('fields',$fields);
$this->assignRef('fieldsClass',$fieldsClass);
$fieldsClass->handleZoneListing($fields,$rows);
$this->assignRef('rows',$rows);
$this->assignRef('pageInfo',$pageInfo);
$this->assignRef('pagination',$pagination);
$currencyClass = hikashop::get('class.currency');
$this->assignRef('currencyHelper',$currencyClass);
$category = hikashop::get('type.categorysub');
$category->type = 'status';
$this->assignRef('category',$category);
$payment = hikashop::get('type.payment');
$this->assignRef('payment',$payment);
$partner = hikashop::get('type.user_partner');
$this->assignRef('partner',$partner);
$plugin =& JPluginHelper::getPlugin('system', 'hikashop');
if(empty($plugin) || !hikashop::level(2)){
$affiliate_active = false;
}else{
$affiliate_active = true;
}
$this->assignRef('affiliate_active',$affiliate_active);
JHTML::_('behavior.modal');
}
function form(){
$order_id = hikashop::getCID('order_id');
$fieldsClass = hikashop::get('class.field');
$fields = null;
if(!empty($order_id)){
$class = hikashop::get('class.order');
$order = $class->loadFullOrder($order_id,true);
if(hikashop::level(2)){
$fields['order'] = $fieldsClass->getData('backend','order');
$fields['entry'] = $fieldsClass->getData('frontcomp','entry');
}
$task='edit';
}
if(empty($order)){
$app =& JFactory::getApplication();
$app->redirect(hikashop::completeLink('order&task=listing',false,true));
}
$config =& hikashop::config();
$order_status_for_download = $config->get('order_status_for_download','confirmed,shipped');
$download_time_limit = $config->get('download_time_limit',0);
$download_number_limit = $config->get('download_number_limit',0);
$this->assignRef('order_status_for_download',$order_status_for_download);
$this->assignRef('download_time_limit',$download_time_limit);
$this->assignRef('download_number_limit',$download_number_limit);
$category = hikashop::get('type.categorysub');
$category->type = 'status';
$category->load(true);
$this->assignRef('category',$category);
if(!empty($order->order_payment_id)){
$pluginsPayment = hikashop::get('type.plugins');
$pluginsPayment->type='payment';
$this->assignRef('payment',$pluginsPayment);
}
if(!empty($order->order_shipping_id)){
$pluginsShipping = hikashop::get('type.plugins');
$pluginsShipping->type='shipping';
$this->assignRef('shipping',$pluginsShipping);
}
$currencyClass = hikashop::get('class.currency');
$this->assignRef('currencyHelper',$currencyClass);
JPluginHelper::importPlugin( 'hikashop' );
JPluginHelper::importPlugin( 'hikashoppayment' );
JPluginHelper::importPlugin( 'hikashopshipping' );
$dispatcher =& JDispatcher::getInstance();
$dispatcher->trigger( 'onHistoryDisplay', array( & $order->history) );
$this->assignRef('order',$order);
$this->assignRef('fields',$fields);
$this->assignRef('fieldsClass',$fieldsClass);
JHTML::_('behavior.modal');
$bar = & JToolBar::getInstance('toolbar');
if(version_compare(JVERSION,'1.6','<')){
$bar->appendButton( 'Popup','send',JText::_('HIKA_EMAIL'),hikashop::completeLink('order&task=mail&order_id='.$order_id,true),720);
$bar->appendButton( 'Popup','preview',JText::_('INVOICE'),hikashop::completeLink('order&task=invoice&type=full&order_id='.$order_id,true));
$bar->appendButton( 'Popup','preview',JText::_('SHIPPING_INVOICE'),hikashop::completeLink('order&task=invoice&type=shipping&order_id='.$order_id,true));
}else{
$bar->appendButton( 'Popup','send',JText::_('HIKA_EMAIL'),'index.php?option=com_hikashop&ctrl=order&task=mail&tmpl=component&order_id='.$order_id,720);
$bar->appendButton( 'Popup','preview',JText::_('INVOICE'),'index.php?option=com_hikashop&ctrl=order&task=invoice&tmpl=component&type=full&order_id='.$order_id);
$bar->appendButton( 'Popup','preview',JText::_('SHIPPING_INVOICE'),'index.php?option=com_hikashop&ctrl=order&task=invoice&tmpl=component&type=shipping&order_id='.$order_id);
}
$user_id = JRequest::getInt('user_id',0);
if(!empty($user_id)){
$user_info='&user_id='.$user_id;
$url = hikashop::completeLink('user&task=edit&user_id='.$user_id);
}else{
$user_info='';
$url = hikashop::completeLink('order');
}
$bar->appendButton( 'Link', 'cancel', JText::_('HIKA_CANCEL'), $url );
JToolBarHelper::divider();
$bar->appendButton( 'Pophelp',$this->ctrl.'-form');
hikashop::setTitle(JText::_($this->nameForm),$this->icon,$this->ctrl.'&task='.$task.'&order_id='.$order_id.$user_info);
}
function changestatus(){
$order_id = hikashop::getCID('order_id');
$new_status = JRequest::getVar('status','');
if(!empty($order_id)){
$class = hikashop::get('class.order');
$order = $class->get($order_id,$new_status);
$order->order_old_status = $order->order_status;
$order->order_status = $new_status;
$class->loadOrderNotification($order);
}else{
$order = null;
}
$order->order_status = $new_status;
$this->assignRef('element',$order);
$editor = hikashop::get('helper.editor');
$editor->name = 'hikashop_mail_body';
$editor->content = $order->mail->body;
$this->assignRef('editor',$editor);
}
function partner(){
$order_id = hikashop::getCID('order_id');
if(!empty($order_id)){
$class = hikashop::get('class.order');
$order = $class->loadNotification($order_id);
}else{
$order = null;
}
$this->assignRef('element',$order);
$editor = hikashop::get('helper.editor');
$editor->name = 'hikashop_mail_body';
$editor->content = '';
$order->mail->altbody='';
$this->assignRef('editor',$editor);
$partners = hikashop::get('type.partners');
$this->assignRef('partners',$partners);
$currencyType=hikashop::get('type.currency');
$this->assignRef('currencyType',$currencyType);
}
function discount(){
$order_id = hikashop::getCID('order_id');
if(!empty($order_id)){
$class = hikashop::get('class.order');
$order = $class->loadNotification($order_id);
}else{
$order = null;
}
$this->assignRef('element',$order);
$editor = hikashop::get('helper.editor');
$editor->name = 'hikashop_mail_body';
$editor->content = '';
$order->mail->altbody='';
$this->assignRef('editor',$editor);
}
function fields(){
$order_id = hikashop::getCID('order_id');
$fieldsClass = hikashop::get('class.field');
$fields = null;
if(!empty($order_id)){
$class = hikashop::get('class.order');
$order = $class->loadNotification($order_id);
if(hikashop::level(2)){
$fields['order'] = $fieldsClass->getData('backend','order');
}
}else{
$order = null;
}
$this->assignRef('element',$order);
$this->assignRef('fields',$fields);
$this->assignRef('fieldsClass',$fieldsClass);
$editor = hikashop::get('helper.editor');
$editor->name = 'hikashop_mail_body';
$editor->content = '';
$order->mail->altbody='';
$this->assignRef('editor',$editor);
}
function changeplugin(){
$order_id = hikashop::getCID('order_id');
$new_status = JRequest::getVar('status','');
if(!empty($order_id)){
$class = hikashop::get('class.order');
$order = $class->loadNotification($order_id);
}else{
$order = null;
}
$this->assignRef('element',$order);
$editor = hikashop::get('helper.editor');
$editor->name = 'hikashop_mail_body';
$editor->content = '';
$order->mail->altbody='';
$this->assignRef('editor',$editor);
$pluginsPayment = hikashop::get('type.plugins');
$pluginsPayment->type=JRequest::getWord('type');
$this->assignRef($pluginsPayment->type,$pluginsPayment);
$this->assignRef('type',$pluginsPayment->type);
$full_id = JRequest::getCmd('plugin');
$this->assignRef('full_id',$full_id);
$parts = explode('_',$full_id);
$id = array_pop($parts);
$this->assignRef('id',$id);
$method = implode('_',$parts);
$this->assignRef('method',$method);
}
function mail(){
$element = null;
$element->order_id = JRequest::getInt('order_id',0);
if(empty($element->order_id)){
$user_id = JRequest::getInt('user_id',0);
$userClass = hikashop::get('class.user');
$element->customer = $userClass->get($user_id);
$mailClass = hikashop::get('class.mail');
$element->mail = null;
$element->mail->body='';
$element->mail->altbody='';
$element->mail->html=1;
$mailClass->loadInfos($element->mail, 'user_notification');
$element->mail->dst_email =& $element->customer->user_email;
if(!empty($element->customer->name)){
$element->mail->dst_name =& $element->customer->name;
}else{
$element->mail->dst_name = '';
}
}else{
$orderClass = hikashop::get('class.order');
$orderClass->loadMail($element);
}
$editor = hikashop::get('helper.editor');
$editor->name = 'hikashop_mail_body';
$editor->content = $element->mail->body;
$this->assignRef('editor',$editor);
$this->assignRef('element',$element);
}
function invoice(){
$order_id = hikashop::getCID('order_id');
if(!empty($order_id)){
$class = hikashop::get('class.order');
$order = $class->loadFullOrder($order_id);
$task='edit';
}else{
$order = null;
$task='add';
}
$config =& hikashop::config();
$store = str_replace(array("\r\n","\n","\r"),array('<br/>','<br/>','<br/>'),$config->get('store_address',''));
$this->assignRef('store_address',$store);
$this->assignRef('element',$order);
$this->assignRef('order',$order);
if(!empty($order->order_payment_id)){
$pluginsPayment = hikashop::get('type.plugins');
$pluginsPayment->type='payment';
$this->assignRef('payment',$pluginsPayment);
}
if(!empty($order->order_shipping_id)){
$pluginsShipping = hikashop::get('type.plugins');
$pluginsShipping->type='shipping';
$this->assignRef('shipping',$pluginsShipping);
}
$type = JRequest::getWord('type');
$this->assignRef('invoice_type',$type);
$nobutton = true;
$this->assignRef('nobutton',$nobutton);
$display_type = 'frontcomp';
$this->assignRef('display_type',$display_type);
$currencyClass = hikashop::get('class.currency');
$this->assignRef('currencyHelper',$currencyClass);
$fieldsClass = hikashop::get('class.field');
$this->assignRef('fieldsClass',$fieldsClass);
}
function product(){
$product_id = hikashop::getCID('product_id');
$orderClass = hikashop::get('class.order');
if(!empty($product_id)){
$class = hikashop::get('class.order_product');
$product = $class->get($product_id);
}else{
$product = null;
$product->order_id = JRequest::getInt('order_id');
$product->mail->body = '';
}
$orderClass->loadMail($product);
$this->assignRef('element',$product);
$editor = hikashop::get('helper.editor');
$editor->name = 'hikashop_mail_body';
$editor->content = $product->mail->body;
$this->assignRef('editor',$editor);
}
function product_delete(){
$product_id = hikashop::getCID('product_id');
$orderClass = hikashop::get('class.order');
if(!empty($product_id)){
$class = hikashop::get('class.order_product');
$product = $class->get($product_id);
$orderClass->loadMail($product);
$this->assignRef('element',$product);
$editor = hikashop::get('helper.editor');
$editor->name = 'hikashop_mail_body';
$editor->content = $product->mail->body;
$this->assignRef('editor',$editor);
}
}
function address(){
$address_id = hikashop::getCID('address_id');
$address_type = JRequest::getCmd('type');
$fieldsClass = hikashop::get('class.field');
if(!empty($address_id) && !empty($address_type)){
$orderClass = hikashop::get('class.order');
$order = null;
$order->order_id = JRequest::getInt('order_id');
$addressClass=hikashop::get('class.address');
$name = $address_type.'_address';
$order->$name=$addressClass->get($address_id);
$fieldClass = hikashop::get('class.field');
$order->fields = $fieldClass->getData('backend','address');
$orderClass->loadMail($order);
$name = $address_type.'_address';
$fieldsClass->prepareFields($order->fields,$order->$name,'address','field&task=state');
}else{
$order = null;
}
$this->assignRef('fieldsClass',$fieldsClass);
$this->assignRef('element',$order);
$this->assignRef('type',$address_type);
$this->assignRef('id',$address_id);
$editor = hikashop::get('helper.editor');
$editor->name = 'hikashop_mail_body';
$editor->content = $order->mail->body;
$this->assignRef('editor',$editor);
}
}