Location: PHPKode > projects > SOA For Virtuemart (WebServices) > com_vm_soa/admin/services/VM_OrdersService.php
<?php

define( '_VALID_MOS', 1 );
define( '_JEXEC', 1 );

/**
 * Virtuemart Order SOA Connector
 *
 * Virtuemart Order SOA Connector (Provide functions getOrdersFromStatus, getOrderStatus, getOrder, getAllOrders)
 *
 * @package    com_vm_soa
 * @subpackage component
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  2010 Mickael Cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    $Id:$
 */
global $mosConfig_absolute_path, $sess;
global $jscook_type, $jscookMenu_style, $jscookTree_style;

$mosConfig_absolute_path= realpath( dirname(__FILE__).'/../../../..' );

// Load the joomla main cfg
if( file_exists(dirname(__FILE__).'/configuration.php' )) {
	require_once( $mosConfig_absolute_path.'/configuration.php' );
	
} else {
	require_once( $mosConfig_absolute_path.'/configuration.php');
}

/** init joomla cfg**/
define('JPATH_BASE', $mosConfig_absolute_path );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');

/**
 * INITIALISE THE APPLICATION
 */
// set the language
$mainframe->initialise();


// Load the virtuemart main parse code
if( file_exists(dirname(__FILE__).'/../../../../components/com_virtuemart/virtuemart_parser.php' )) {
	require_once( dirname(__FILE__).'/../../../../components/com_virtuemart/virtuemart_parser.php' );
	$mosConfig_absolute_path = realpath( dirname(__FILE__).'/../..' );
} else {
	require_once( dirname(__FILE__).'/../../../../components/com_virtuemart/virtuemart_parser.php');
}

// Load the mailer class
$mosConfig_absolute_path= realpath( dirname(__FILE__).'/../../../..' );
$phpmailer_classname='phpmailer';
if( file_exists( $mosConfig_absolute_path . '/libraries/phpmailer/phpmailer.php') ) {
	$phpmailer_path = $mosConfig_absolute_path . '/libraries/phpmailer/phpmailer.php';
}elseif( file_exists( $mosConfig_absolute_path . '/includes/phpmailer/class.phpmailer.php')) {
	$phpmailer_path = $mosConfig_absolute_path . '/includes/phpmailer/class.phpmailer.php';
	$phpmailer_classname = 'mosphpmailer';
}
require_once( $phpmailer_path );
	
require_once(CLASSPATH.'ps_order_status.php');
require_once(CLASSPATH.'ps_order.php');
require_once(CLASSPATH.'ps_checkout.php');
require_once(CLASSPATH.'ps_coupon.php');
require_once(CLASSPATH.'ps_shipping.php');
require_once(CLASSPATH.'ps_payment_method.php');
require_once(CLASSPATH.'ps_creditcard.php');
require_once(CLASSPATH.'ps_product.php');
require_once(CLASSPATH.'ps_order_change.php');

include('../vm_soa_conf.php');

global $mosConfig_live_site;
$URL_BASE ='';
if( $mosConfig_live_site[strlen( $mosConfig_live_site)-1] == '/' ) {
	$URL_BASE = $mosConfig_live_site;
}
else {
	$URL_BASE = $mosConfig_live_site.'/';
}


/**
 * Class OrderStatus
 *
 * Class "OrderStatus" with attribute : id, name, code,
 * 
 *
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class OrderStatus {
	
		public $order_status_id="";
		public $order_status_code="";		
		public $order_status_name="";	
		public $order_status_description="";
		public $list_order="";		
		public $vendor_id="";
		
		function __construct($order_status_id,$order_status_code,$order_status_name,$order_status_description,$list_order,$vendor_id){
		
			$this->order_status_id=$order_status_id;
			$this->order_status_code=$order_status_code;		
			$this->order_status_name=$order_status_name;	
			$this->order_status_description=$order_status_description;
			$this->list_order=$list_order;		
			$this->vendor_id=$vendor_id;	
		
		}
	
	}
	
/**
 * Class Order
 *
 * Class "Order" with attribute : id, user_id, vendor_id,  order_number, user_info_id , order_total order_subtotal
 * order_tax, order_tax_details order_shipping, coupon_discount order_currency ...)
 *
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class Order {
		public $id="";
		public $user_id="";		
		public $vendor_id="";		
		public $order_number="";
		public $user_info_id="";
		public $order_total="";
		public $order_subtotal="";
		public $order_tax="";
		public $order_tax_details="";
		public $order_shipping="";
		public $order_shipping_tax="";
		public $coupon_discount="";
		public $coupon_code="";
		public $order_discount="";
		public $order_currency="";
		public $order_status="";
		public $cdate="";
		public $mdate="";
		public $ship_method_id="";
		public $customer_note="";
		public $ip_address="";
																					
		//constructeur
		function __construct($id,$user_id,$vendor_id,$order_number,$user_info_id,$order_total,$order_subtotal,$order_tax,$order_tax_details,$order_shipping,$order_shipping_tax,
		$coupon_discount,$coupon_code,$order_discount,$order_currency,$order_status,$cdate,$mdate,$ship_method_id,$customer_note,$ip_address) {

			$this->id=$id;
			$this->user_id=$user_id;	
			$this->vendor_id=$vendor_id;			
			$this->order_number=$order_number;
			$this->user_info_id=$user_info_id;
			$this->order_total=$order_total;
			$this->order_subtotal=$order_subtotal;
			$this->order_tax=$order_tax;
			$this->order_tax_details=$order_tax_details;
			$this->order_shipping=$order_shipping;
			$this->order_shipping_tax=$order_shipping_tax;
			$this->coupon_discount=$coupon_discount;
			$this->coupon_code=$coupon_code;
			$this->order_discount=$order_discount;
			$this->order_currency=$order_currency;
			$this->order_status=$order_status;
			$this->cdate=$cdate;
			$this->mdate=$mdate;
			$this->ship_method_id=$ship_method_id;
			$this->customer_note=$customer_note;
			$this->ip_address=$ip_address;
		}
	}
	
  /**
 * Class ShippingRate
 *
 * Class "ShippingRate" with attribute : shipping_rate_id ...,
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class ShippingRate {
		public $shipping_rate_id="";
		public $shipping_rate_name="";		
		public $shipping_rate_carrier_id="";		
		public $shipping_rate_country="";
		public $shipping_rate_zip_start="";
		public $shipping_rate_zip_end="";
		public $shipping_rate_weight_start="";
		public $shipping_rate_weight_end="";
		public $shipping_rate_value="";
		public $shipping_rate_package_fee="";
		public $shipping_rate_currency_id="";
		public $shipping_rate_vat_id="";
		public $shipping_rate_list_order="";
													
		//constructeur
		function __construct($shipping_rate_id,$shipping_rate_name,$shipping_rate_carrier_id,$shipping_rate_country,$shipping_rate_zip_start,
		$shipping_rate_zip_end,$shipping_rate_weight_start,$shipping_rate_weight_end,$shipping_rate_value,$shipping_rate_package_fee,$shipping_rate_currency_id,
		$shipping_rate_vat_id,$shipping_rate_list_order) {

			$this->shipping_rate_id=$shipping_rate_id;
			$this->shipping_rate_name=$shipping_rate_name;	
			$this->shipping_rate_carrier_id=$shipping_rate_carrier_id;			
			$this->shipping_rate_country=$shipping_rate_country;
			$this->shipping_rate_zip_start=$shipping_rate_zip_start;
			$this->shipping_rate_zip_end=$shipping_rate_zip_end;
			$this->shipping_rate_weight_start=$shipping_rate_weight_start;
			$this->shipping_rate_weight_end=$shipping_rate_weight_end;
			$this->shipping_rate_value=$shipping_rate_value;
			$this->shipping_rate_package_fee=$shipping_rate_package_fee;
			$this->shipping_rate_currency_id=$shipping_rate_currency_id;
			$this->shipping_rate_vat_id=$shipping_rate_vat_id;
			$this->shipping_rate_list_order=$shipping_rate_list_order;
			
		}
	}
	
  	/**
	 * Class Coupon
	 *
	 * Class "Coupon" with attribute : coupon_id ...
	 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
	 * @copyright  Mickael cabanas
	 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
	 * @version    Release:
	 */
	class Coupon {
	
		public $coupon_id="";
		public $coupon_code="";
		public $percent_or_total="";		
		public $coupon_type="";	
		public $coupon_value="";
		
		function __construct($coupon_id, $coupon_code,$percent_or_total,$coupon_type,$coupon_value){
		
			$this->coupon_id=$coupon_id;
			$this->coupon_code=$coupon_code;
			$this->percent_or_total=$percent_or_total;		
			$this->coupon_type=$coupon_type;	
			$this->coupon_value=$coupon_value;	
			
		}
	
	}
	
/**
 * Class ShippingCarrier
 *
 * Class "ShippingCarrier" with attribute : shipping_carrier_id ...
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class ShippingCarrier {
	
		public $shipping_carrier_id="";
		public $shipping_carrier_name="";		
		public $shipping_carrier_list_order="";	
		
		function __construct($shipping_carrier_id,$shipping_carrier_name,$shipping_carrier_list_order){
		
			$this->shipping_carrier_id=$shipping_carrier_id;
			$this->shipping_carrier_name=$shipping_carrier_name;		
			$this->shipping_carrier_list_order=$shipping_carrier_list_order;	
		}
	}	
	
	  /**
 * Class PaymentMethod
 *
 * Class "PaymentMethod" with attribute : payment_method_id ...,
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class PaymentMethod {
		public $payment_method_id="";
		public $vendor_id="";		
		public $payment_method_name="";		
		public $payment_class="";
		public $shopper_group_id="";
		public $payment_method_discount="";
		public $payment_method_discount_is_percent="";
		public $payment_method_discount_max_amount="";
		public $payment_method_discount_min_amount="";
		public $list_order="";
		public $payment_method_code="";
		public $enable_processor="";
		public $is_creditcard="";
		public $payment_enabled="";
		public $accepted_creditcards="";
		public $payment_extrainfo="";
		
		//constructeur
		function __construct($payment_method_id,$vendor_id,$payment_method_name,$payment_class,$shopper_group_id,
		$payment_method_discount,$payment_method_discount_is_percent,$payment_method_discount_max_amount,$payment_method_discount_min_amount,$list_order,$payment_method_code,
		$enable_processor,$is_creditcard,$payment_enabled,$accepted_creditcards,$payment_extrainfo) {

			$this->payment_method_id=$payment_method_id;
			$this->vendor_id=$vendor_id;	
			$this->payment_method_name=$payment_method_name;			
			$this->payment_class=$payment_class;
			$this->shopper_group_id=$shopper_group_id;
			$this->payment_method_discount=$payment_method_discount;
			$this->payment_method_discount_is_percent=$payment_method_discount_is_percent;
			$this->payment_method_discount_max_amount=$payment_method_discount_max_amount;
			$this->payment_method_discount_min_amount=$payment_method_discount_min_amount;
			$this->list_order=$list_order;
			$this->payment_method_code=$payment_method_code;
			$this->enable_processor=$enable_processor;
			$this->is_creditcard=$is_creditcard;
			$this->payment_enabled=$payment_enabled;
			$this->accepted_creditcards=$accepted_creditcards;
			$this->payment_extrainfo=$payment_extrainfo;
			
		}
	}
	
/**
 * Class Creditcard
 *
 * Class "Creditcard" with attribute : creditcard_id ...
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class Creditcard {
	
		public $creditcard_id="";
		public $vendor_id="";		
		public $creditcard_name="";	
		public $creditcard_code="";	
		
		function __construct($creditcard_id,$vendor_id,$creditcard_name,$creditcard_code){
		
			$this->creditcard_id=$creditcard_id;
			$this->vendor_id=$vendor_id;		
			$this->creditcard_name=$creditcard_name;	
			$this->creditcard_code=$creditcard_code;
		}
	}
	/**
 * Class returnOutput
 *
 * Class "returnOutput" 
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class returnOutput {
	
		public $returnCode="";
		public $message="";		
		public $outputParam="";	
		
		function __construct($returnCode,$message,$outputParam){
		
			$this->returnCode=$returnCode;
			$this->message=$message;		
			$this->outputParam=$outputParam;	
		}
	}	
	
  	/**
    * This function getOrderStatus return all status avalaible
	* (expose as WS)
    * @param 
    * @return array of Status
    */
	function getOrderStatus($params) {
		
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->login, $params->password);
		if ($conf['auth_order_getstatus']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
	
			$db = new ps_DB;

			$q = "SELECT * FROM #__{vm}_order_status ORDER BY list_order";
			$db->query($q);

			while ($db->next_record()) {
				$OrderStatus = new OrderStatus($db->f("order_status_id"), $db->f("order_status_code"), $db->f("order_status_name"),$db->f("order_status_description"), $db->f("list_order"), $db->f("vendor_id"));
				$arrayStatus[]= $OrderStatus;
			}
			return $arrayStatus;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->login);
		}
	}
	
	/**
    * This function get order details from order id
	* (expose as WS)
    * @param string The id of the order
    * @return order details
    */
	function getOrder($params) {
	
		include('../vm_soa_conf.php');
		
		$id=$params->order_id;
	
		$ps_order_status= new ps_order_status();
		//ps_order_status->
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_getorder']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$db = new ps_DB;

			$list  = "SELECT * FROM #__{vm}_orders WHERE ";
			$list .= "order_id = '$id' ";
			$list .= $q . " LIMIT 0,100 "; 
			
			$db = new ps_DB;
			$db->query($list);
			
			while ($db->next_record()) {
			
				$Order = new Order($db->f("order_id"),$db->f("user_id"),$db->f("vendor_id"), $db->f("order_number"), $db->f("user_info_id"), $db->f("order_total"), $db->f("order_subtotal"),
				$db->f("order_tax"), $db->f("order_tax_details"), $db->f("order_shipping"), $db->f("order_shipping_tax"), $db->f("coupon_discount"), $db->f("coupon_code"), $db->f("order_discount"), $db->f("order_currency"),
				$db->f("order_status"), $db->f("cdate"), $db->f("mdate"), $db->f("ship_method_id"), $db->f("customer_note"), $db->f("ip_address"));
				
			
			}
			return $Order;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function get all orders with specified status P, C, R etc...
	* (expose as WS)
    * @param string params (limiteStart, LimitEnd, Status)
    * @return array of orders
    */
	function getOrdersFromStatus($params) {
	
		include('../vm_soa_conf.php');
		/* Authenticate*/
		
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_getfromstatus']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$db = new ps_DB;

			if (empty($params->limite_start)){
				$params->limite_start="0";
			}
			if (empty($params->limite_end)){
				$params->limite_end="100";
			}
			$list  = "SELECT * FROM #__{vm}_orders WHERE ";
			$list .= "order_status = '$params->status' ";
			$list .= "order by order_id desc ";
			$list .= $q . " LIMIT $params->limite_start, $params->limite_end "; 
			
			$db = new ps_DB;
			$db->query($list);
			
			while ($db->next_record()) {
			
				$Order = new Order($db->f("order_id"),$db->f("user_id"), $db->f("vendor_id"), $db->f("order_number"), $db->f("user_info_id"), $db->f("order_total"), $db->f("order_subtotal"),
				$db->f("order_tax"), $db->f("order_tax_details"), $db->f("order_shipping"), $db->f("order_shipping_tax"), $db->f("coupon_discount"), $db->f("coupon_code"), $db->f("order_discount"), $db->f("order_currency"),
				$db->f("order_status"),$db->f("cdate"), $db->f("mdate") , $db->f("ship_method_id"), $db->f("customer_note"), $db->f("ip_address"));
				$orderArray[]=$Order;
			
			}
			return $orderArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function get all Orders
	* (expose as WS)
    * @param string params (limiteStart, LimitEnd)
    * @return array of Categories
    */
	function getAllOrders($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_getall']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$db = new ps_DB;

			$list  = "SELECT * FROM #__{vm}_orders ";
			$list .= $q . " LIMIT $params->limite_start, $params->limite_end "; 
			
			$db = new ps_DB;
			$db->query($list);
			
			while ($db->next_record()) {
			
				$Order = new Order($db->f("order_id"),$db->f("user_id"), $db->f("vendor_id"), $db->f("order_number"), $db->f("user_info_id"), $db->f("order_total"), $db->f("order_subtotal"),
				$db->f("order_tax"), $db->f("order_tax_details"), $db->f("order_shipping"), $db->f("order_shipping_tax"), $db->f("coupon_discount"), $db->f("coupon_code"), $db->f("order_discount"), $db->f("order_currency"),
				$db->f("order_status"), $db->f("cdate"), $db->f("mdate") , $db->f("ship_method_id"), $db->f("customer_note"), $db->f("ip_address"));
				$orderArray[]=$Order;
			
			}
			return $orderArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}

	/**
    * This function UpdateOrderStatus
	* (expose as WS)
    * @param string params (user, pass, orderid, status, comment)
    * @return string result
    */
	function UpdateOrderStatus($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_updatestatus']=="off"){
			$result = "true";
		}
		
		$mosConfig_absolute_path= realpath( dirname(__FILE__).'/../../../..' );
		
		//Auth OK
		if ($result == "true"){
		
			$cpnIdsStr = "";
			$allOk=true;
			
			if (is_array($params->UpdateOrderStatusParams->UpdateOrderStatusParam)){
				
				$count = count($params->UpdateOrderStatusParams->UpdateOrderStatusParam);
				for ($i = 0; $i < $count; $i++) {
				
					$_SESSION['ps_vendor_id'] = "1";
					$ps_order= new ps_order;
					
					$d['order_id'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam[$i]->order_id;
					//$d['current_order_status'] = "P";
					$d['order_status'] =  $params->UpdateOrderStatusParams->UpdateOrderStatusParam[$i]->status;
					$d['notify_customer'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam[$i]->notify;
					$_REQUEST['notify_customer'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam[$i]->notify;
					if (!empty($params->UpdateOrderStatusParams->UpdateOrderStatusParam[$i]->comment)){
						$d['include_comment'] = "Y";
						$_REQUEST['include_comment'] = "Y";
						
						$d['order_comment'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam[$i]->comment;
						$_REQUEST['order_comment'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam[$i]->comment;
						//$ps_order->notify_customer($d);
					} else {
						$d['include_comment'] = "N";
						$_REQUEST['include_comment'] = "N";
					}
					
					// change status of order
					$result = $ps_order->order_status_update($d);
				
					if ($result){
						$cpnIdsStr .= $params->UpdateOrderStatusParams->UpdateOrderStatusParam[$i]->order_id." ";
					}else{
						$allOk=false;
					}
				}
			
			} else {
				$_SESSION['ps_vendor_id'] = "1";
				$ps_order= new ps_order;
				
				$d['order_id'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam->order_id;
				//$d['current_order_status'] = "P";
				$d['order_status'] =  $params->UpdateOrderStatusParams->UpdateOrderStatusParam->status;
				$d['notify_customer'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam->notify;
				$_REQUEST['notify_customer'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam->notify;
				if (!empty( $params->UpdateOrderStatusParams->UpdateOrderStatusParam->comment)){
					
					$d['include_comment'] = "Y";
					$_REQUEST['include_comment'] = "Y";
					
					$d['order_comment'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam->comment;
					$_REQUEST['order_comment'] = $params->UpdateOrderStatusParams->UpdateOrderStatusParam->comment;
					//$ps_order->notify_customer($d);
				} else {
					$d['include_comment'] = "N";
					$_REQUEST['include_comment'] = "N";
				}
				
				// change status of order
				$result = $ps_order->order_status_update($d);
				
				if ($result){
					return "Order Status updated sucessfully : \n".$d['order_id'] ;
				}else {
					return new SoapFault("UpdateOrderStatusFault", "Cannot update OrderStatus  :".$d['order_id']);
				}
			}

			if ($allOk){
				return "All Order Status updated sucessfully : ".$cpnIdsStr;
			} else {
				return new SoapFault("DeleteStatesFault", "Not all Order Status updated, only orderid  : ".$cpnIdsStr);
			}	
			
		
		
		
		
			
			
			$strResult ="OrderId  ".$params->order_id." status updated to :".$params->status;
			
			return $strResult;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}

	/**
    * This function DeleteOrder
	* (expose as WS)
    * @param string params (user, pass, orderid)
    * @return result
    */
	function DeleteOrder($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_deleteorder']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$d['order_id'] = $params->order_id;
			$ps_order= new ps_order;
			$ps_order->delete($d);
			$strResult ="OrderId deleted : ".$params->order_id;
			
			return $strResult;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	 /**
    * This function get user_info_id (copy ps_chekout.php)
	* (not expose as WS)
    * @param 
    * @return array of Status
    */
	function getUserInfoId($user_id){
	
		$db = new ps_DB();

		/* Select all the ship to information for this user id and
		* order by modification date; most recently changed to oldest
		*/
		$q  = "SELECT user_info_id from `#__{vm}_user_info` WHERE ";
		$q .= "user_id='" . $user_id . "' ";
		$q .= "AND address_type='BT'";
		$db->query($q);
		$db->next_record();
		return $db->f("user_info_id");
	}
	
	 /**
    * This function create an order
	* (expose as WS)
    * @param 
    * @return array of Status
    */
	function CreateOrder($params) {
		
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_createorder']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
	
			global $auth;
			$auth['user_id'] =  $params->user_id;
			$GLOBALS['vmInputFilter'] = $vmInputFilter = new vmInputFilter();
			
			//shpping options
			$shipping = $params->shipping_method;
			$shipping_rate = $params->shipping_carrier_name;
			$shipping_opt = $params->shipping_rate_name;
			$shipping_price = $params->shipping_price;
			$shipping_id = $params->shipping_rate_id;
			$tmpStr ="".$shipping."|".$shipping_rate."|".$shipping_opt."|".$shipping_price."|".$shipping_id;
			$shipping_rate_str = urlencode($tmpStr);
			
			$_REQUEST['shipping_rate_id']=$shipping_rate_str;
			$_SESSION['shipping_rate_id']=$shipping_rate_str;
			$_SESSION['coupon_discount']=$params->coupon_code;
			$_SESSION['auth']["user_id"]= $params->user_id;
			$_SESSION['auth']["show_price_including_tax"] = $params->price_including_tax;
			
			$_SESSION["ps_vendor_id"] = "1" ;
			if (!empty($params->vendor_id)){
				$_SESSION["ps_vendor_id"] = $params->vendor_id;
			}
			
			//add products (check if there is one or more products)
			if (is_array($params->products->product)){
				$count = count($params->products->product);
				$_SESSION['cart']["idx"]=$count;
				for ($i = 0; $i < $count; $i++) {
					$_SESSION['cart'][$i]["product_id"] = $params->products->product[$i]->product_id;
					$_SESSION['cart'][$i]["description"] = $params->products->product[$i]->description;
					$_SESSION['cart'][$i]["quantity"] = $params->products->product[$i]->quantity;
				}
			}else{
				$_SESSION['cart']["idx"]= "1";
				$_SESSION['cart'][0]["product_id"] = $params->products->product->product_id;
				$_SESSION['cart'][0]["description"] = $params->products->product->description;
				$_SESSION['cart'][0]["quantity"] = $params->products->product->quantity;
			}
	
			$_SESSION['coupon_code'] = $params->coupon_code;
			$GLOBALS['product_currency'] = $params->product_currency;
			
			
			$_POST['customer_note'] = $params->customer_note; 
			$order_params['payment_method_id'] = $params->payment_method_id; 
			$order_params['shipping_rate_id'] = $shipping_rate_str;
			$order_params['shipping_tax'] = "2.62";
			$order_params['order_shipping_tax'] = "12.32";
			
			$order_params['agreed'] = "1";			

			$order_params['checkout_this_step'][0] = "CHECK_OUT_GET_FINAL_BASKET";				
			$order_params['checkout_this_step'][1] = "CHECK_OUT_GET_SHIPPING_ADDR";		
			$order_params['checkout_this_step'][2] = "CHECK_OUT_GET_SHIPPING_METHOD";		
			$order_params['checkout_this_step'][3]= "CHECK_OUT_GET_PAYMENT_METHOD";					
			$order_params['checkout_this_step'][4]= "CHECK_OUT_GET_FINAL_CONFIRMATION";			
			//$ret = $ps_checkout->add($order_params);
			
			$_SESSION[$order_params['shipping_rate_id']] = $order_params['shipping_rate_id'];
			
			$_REQUEST['ship_to_info_id'] = getUserInfoId($params->user_id);
			
			$ps_checkout= new ps_checkout();
			
			$order_params['ship_to_info_id'] = $_REQUEST['ship_to_info_id'];
			
			$ret = $ps_checkout->process($order_params);
			
			$_REQUEST['shipping']=$params->shipping_rate_id;
			/*if ($params->force_price=="0"){
			
				$ps_order_change = new ps_order_change($order_params["order_id"]);
				$ps_order_change->change_standard_shipping();
			}*/
			
			//$_REQUEST['TEST'] = "|"."TEST";
			//return new SoapFault("CreateOrderFault", $_REQUEST['TEST']);
			
			if ($ret){
				$returnCode = "OK";
				$message = "Order sucessfully created for user_id : ".$params->user_id;
				$outputParam=$order_params["order_id"];
				$returnOutput = new returnOutput($returnCode,$message,$outputParam);
				return $returnOutput;
			} else{
				return new SoapFault("CreateOrderFault", "Cannot create order for user_id : ".$params->user_id);
			}
					
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function get all coupon code
	* (expose as WS)
    * @param string
    * @return Coupon details
    */
	function GetAllCouponCode($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->login, $params->password);
		if ($conf['auth_order_getcoupon']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$db = new ps_DB;

			$list  = "SELECT * FROM #__{vm}_coupons WHERE 1";
			$db->query($list);
			
			while ($db->next_record()) {
			
				$Coupon = new Coupon($db->f("coupon_id"),$db->f("coupon_code"),$db->f("percent_or_total"), $db->f("coupon_type"), $db->f("coupon_value"));
				$arrayCoupon[]=$Coupon;
			
			}
			return $arrayCoupon;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->login);
		}
	}
	
	/**
    * This function add coupon code
	* (expose as WS)
    * @param string
    * @return result
    */
	function AddCouponCode($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_addcoupon']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$ps_coupon = new ps_coupon;
			$couponCodesStr="";
			$allOk=true;
			
			//chek if there is one or more coupon and add
			if (is_array($params->coupons->coupon)){
			
				$count = count($params->coupons->coupon);

				for ($i = 0; $i < $count; $i++) {
					$d['coupon_code']= $params->coupons->coupon[$i]->coupon_code;
					$d['coupon_value']= $params->coupons->coupon[$i]->coupon_value;
					$d['percent_or_total']= $params->coupons->coupon[$i]->percent_or_total;
					$d['coupon_type']= $params->coupons->coupon[$i]->coupon_type;
					//add coupon
					$ret = $ps_coupon->add_coupon_code($d);
					if ($ret){
						$couponCodesStr .= $d['coupon_code']." ";
					} else {
						$allOk=false;
					}
				}
				
			} else {
				$d['coupon_code']= $params->coupons->coupon->coupon_code;
				$d['coupon_value']= $params->coupons->coupon->coupon_value;
				$d['percent_or_total']= $params->coupons->coupon->percent_or_total;
				$d['coupon_type']= $params->coupons->coupon->coupon_type;
				//add coupon
				$ret = $ps_coupon->add_coupon_code($d);
				if ($ret){
					return "Coupon successfully added : ".$d['coupon_code']." id : ".$_REQUEST['coupon_id'];
				} else {
					return new SoapFault("AddCouponFault", "Cannot add coupon code : ".$d['coupon_code']);
				}
			}
			
			if ($allOk){
				return "All Coupons successfully added : ".$couponCodesStr;
			} else {
				return new SoapFault("AddCouponsFault", "Not all coupons added, only coupons code : ".$couponCodesStr);
			}
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function delete coupon code
	* (expose as WS)
    * @param string
    * @return Coupon details
    */
	function DeleteCouponCode($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_delcoupon']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
		
			$ps_coupon = new ps_coupon;
			$cpnIdsStr="";
			
			if (is_array($params->ids->id)){
			
				$count = count($params->ids->id);
				for ($i = 0; $i < $count; $i++) {
					$d['coupon_id'][$i] = $params->ids->id[$i];
					$cpnIdsStr .= $params->ids->id[$i]." ";
				}
			
			} else {
				$d['coupon_id'] = $params->ids->id;
				$cpnIdsStr .= $params->ids->id." ";
			}
			
			$ps_coupon->remove_coupon_code($d);
			
			return "Coupons successfully deleted : ".$cpnIdsStr;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}

	/**
    * This function get shipping rate
	* (expose as WS)
    * @param string
    * @return shipping rate
    */
	function GetAllShippingRate($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->login, $params->password);
		if ($conf['auth_order_getshiprate']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$db = new ps_DB;

			$list  = "SELECT * FROM #__{vm}_shipping_rate WHERE 1";
			$db->query($list);
			
			while ($db->next_record()) {
			
				$ShippingRate = new ShippingRate($db->f("shipping_rate_id"),$db->f("shipping_rate_name"),$db->f("shipping_rate_carrier_id"), $db->f("shipping_rate_country"),
				$db->f("shipping_rate_zip_start"), $db->f("shipping_rate_zip_end"), $db->f("shipping_rate_weight_start"), $db->f("shipping_rate_weight_end"), $db->f("shipping_rate_value"),
				$db->f("shipping_rate_package_fee"), $db->f("shipping_rate_currency_id"), $db->f("shipping_rate_vat_id"), $db->f("shipping_rate_list_order"));
				$arrayShippingRate[]=$ShippingRate;
			
			}
			return $arrayShippingRate;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->login);
		}
	}
	
	/**
    * This function add shipping rate
	* (expose as WS)
    * @param string
    * @return shipping rate
    */
	function AddShippingRate($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_addshiprate']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$vm_ps_shipping = new vm_ps_shipping;
			$allOk=true;
			$ratesStr;
			//chek if there is one or more shippnig carriers and add
			if (is_array($params->shipping_rates->shippingrate)){
			
				$count = count($params->shipping_rates->shippingrate);

				for ($i = 0; $i < $count; $i++) {
					//$d['shipping_rate_id']= $params->shipping_rates->shipping_rate[$i]->shipping_rate_id;
					$d['shipping_rate_name']= $params->shipping_rates->shippingrate[$i]->shipping_rate_name;
					$d['shipping_rate_carrier_id']= $params->shipping_rates->shippingrate[$i]->shipping_rate_carrier_id;
					$d['shipping_rate_country']= explode(";",$params->shipping_rates->shippingrate[$i]->shipping_rate_country);
					$d['shipping_rate_zip_start']= $params->shipping_rates->shippingrate[$i]->shipping_rate_zip_start;
					$d['shipping_rate_zip_end']= $params->shipping_rates->shippingrate[$i]->shipping_rate_zip_end;
					$d['shipping_rate_weight_start']= $params->shipping_rates->shippingrate[$i]->shipping_rate_weight_start;
					$d['shipping_rate_weight_end']= $params->shipping_rates->shippingrate[$i]->shipping_rate_weight_end;
					$d['shipping_rate_value']= $params->shipping_rates->shippingrate[$i]->shipping_rate_value;
					$d['shipping_rate_package_fee']= $params->shipping_rates->shippingrate[$i]->shipping_rate_package_fee;
					$d['shipping_rate_currency_id']= $params->shipping_rates->shippingrate[$i]->shipping_rate_currency_id;
					$d['shipping_rate_vat_id']= $params->shipping_rates->shippingrate[$i]->shipping_rate_vat_id;
					$d['shipping_rate_list_order']= $params->shipping_rates->shippingrate[$i]->shipping_rate_list_order;
					/*
					$db = new ps_DB;
					$db->buildQuery("INSERT","#__{vm}_shipping_rate",$d);
					$result = $db->query();
					$errMsg=  $db->getErrorMsg();	*/
					$result = $vm_ps_shipping->rate_add($d);

					if ($result){
						$ratesStr .= $params->shipping_rates->shippingrate[$i]->shipping_rate_name." ";
					} else {
						$allOk=false;
					}
				} 
			}else {
					//$d['shipping_rate_id']= $params->shipping_rates->shipping_rate->shipping_rate_id;
					$d['shipping_rate_name']= $params->shipping_rates->shippingrate->shipping_rate_name;
					$d['shipping_rate_carrier_id']= $params->shipping_rates->shippingrate->shipping_rate_carrier_id;
					$d['shipping_rate_country']= explode(";",$params->shipping_rates->shippingrate->shipping_rate_country);
					$d['shipping_rate_zip_start']= $params->shipping_rates->shippingrate->shipping_rate_zip_start;
					$d['shipping_rate_zip_end']= $params->shipping_rates->shippingrate->shipping_rate_zip_end;
					$d['shipping_rate_weight_start']= $params->shipping_rates->shippingrate->shipping_rate_weight_start;
					$d['shipping_rate_weight_end']= $params->shipping_rates->shippingrate->shipping_rate_weight_end;
					$d['shipping_rate_value']= $params->shipping_rates->shippingrate->shipping_rate_value;
					$d['shipping_rate_package_fee']= $params->shipping_rates->shippingrate->shipping_rate_package_fee;
					$d['shipping_rate_currency_id']= $params->shipping_rates->shippingrate->shipping_rate_currency_id;
					$d['shipping_rate_vat_id']= $params->shipping_rates->shippingrate->shipping_rate_vat_id;
					$d['shipping_rate_list_order']= $params->shipping_rates->shippingrate->shipping_rate_list_order;
					
					//add
					/*
					$db = new ps_DB;
					$db->buildQuery("INSERT","#__{vm}_shipping_rate",$d);
					$result = $db->query();
					$errMsg=  $db->getErrorMsg();*/
					$result = $vm_ps_shipping->rate_add($d);
				if ($result){
					return "Shipping Rate successfully added : ".$d['shipping_rate_name'];
				} else {
					return new SoapFault("AddShippingRateFault", "Cannot add rate : ".$d['shipping_rate_name']);
				}
			}
			
			if ($allOk){
				return "All Shipping Rates successfully added : ".$ratesStr;
			} else {
				return new SoapFault("AddShippingRatesFault", "Not all ShiipingRates added, only rates code : ".$ratesStr);
			}
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function Update ShippingRate
	* (expose as WS)
    * @param string
    * @return shipping rate
    */
	function UpdateShippingRate($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_upshiprate']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$vm_ps_shipping = new vm_ps_shipping;
			$allOk=true;
			$ratesStr;
			//chek if there is one or more shippnig carriers and add
			if (is_array($params->shipping_rates->shippingrate)){
			
				$count = count($params->shipping_rates->shippingrate);

				for ($i = 0; $i < $count; $i++) {
					$_REQUEST['shipping_rate_id'] =  $params->shipping_rates->shippingrate[$i]->shipping_rate_id;
					$d['shipping_rate_id']= $params->shipping_rates->shipping_rate[$i]->shipping_rate_id;
					$d['shipping_rate_name']= $params->shipping_rates->shippingrate[$i]->shipping_rate_name;
					$d['shipping_rate_carrier_id']= $params->shipping_rates->shippingrate[$i]->shipping_rate_carrier_id;
					$d['shipping_rate_country']= explode(";",$params->shipping_rates->shippingrate[$i]->shipping_rate_country);
					$d['shipping_rate_zip_start']= $params->shipping_rates->shippingrate[$i]->shipping_rate_zip_start;
					$d['shipping_rate_zip_end']= $params->shipping_rates->shippingrate[$i]->shipping_rate_zip_end;
					$d['shipping_rate_weight_start']= $params->shipping_rates->shippingrate[$i]->shipping_rate_weight_start;
					$d['shipping_rate_weight_end']= $params->shipping_rates->shippingrate[$i]->shipping_rate_weight_end;
					$d['shipping_rate_value']= $params->shipping_rates->shippingrate[$i]->shipping_rate_value;
					$d['shipping_rate_package_fee']= $params->shipping_rates->shippingrate[$i]->shipping_rate_package_fee;
					$d['shipping_rate_currency_id']= $params->shipping_rates->shippingrate[$i]->shipping_rate_currency_id;
					$d['shipping_rate_vat_id']= $params->shipping_rates->shippingrate[$i]->shipping_rate_vat_id;
					$d['shipping_rate_list_order']= $params->shipping_rates->shippingrate[$i]->shipping_rate_list_order;
					/*
					$db = new ps_DB;
					$db->buildQuery("INSERT","#__{vm}_shipping_rate",$d);
					$result = $db->query();
					$errMsg=  $db->getErrorMsg();*/	
					$result = $vm_ps_shipping->rate_update($d);

					if ($result){
						$ratesStr .= $params->shipping_rates->shippingrate[$i]->shipping_rate_name." ";
					} else {
						$allOk=false;
					}
				} 
			}else {
					$d['shipping_rate_id']= $params->shipping_rates->shippingrate->shipping_rate_id;
					$d['shipping_rate_name']= $params->shipping_rates->shippingrate->shipping_rate_name;
					$d['shipping_rate_carrier_id']= $params->shipping_rates->shippingrate->shipping_rate_carrier_id;
					$d['shipping_rate_country']= explode(";",$params->shipping_rates->shippingrate->shipping_rate_country);
					$d['shipping_rate_zip_start']= $params->shipping_rates->shippingrate->shipping_rate_zip_start;
					$d['shipping_rate_zip_end']= $params->shipping_rates->shippingrate->shipping_rate_zip_end;
					$d['shipping_rate_weight_start']= $params->shipping_rates->shippingrate->shipping_rate_weight_start;
					$d['shipping_rate_weight_end']= $params->shipping_rates->shippingrate->shipping_rate_weight_end;
					$d['shipping_rate_value']= $params->shipping_rates->shippingrate->shipping_rate_value;
					$d['shipping_rate_package_fee']= $params->shipping_rates->shippingrate->shipping_rate_package_fee;
					$d['shipping_rate_currency_id']= $params->shipping_rates->shippingrate->shipping_rate_currency_id;
					$d['shipping_rate_vat_id']= $params->shipping_rates->shippingrate->shipping_rate_vat_id;
					$d['shipping_rate_list_order']= $params->shipping_rates->shippingrate->shipping_rate_list_order;
					
					//add
					/*$db = new ps_DB;
					$db->buildQuery("INSERT","#__{vm}_shipping_rate",$d);
					$result = $db->query();
					$errMsg=  $db->getErrorMsg();*/
					$result = $vm_ps_shipping->rate_update($d);
				if ($result){
					return "Shipping Rate successfully updated : ".$d['shipping_rate_id'];
				} else {
					return new SoapFault("UpdateShippingRateFault", "Cannot update rate : ".$d['shipping_rate_id']);
				}
			}
			
			if ($allOk){
				return "All Shipping Rates successfully updated : ".$ratesStr;
			} else {
				return new SoapFault("UpdateShippingRateFault", "Not all ShiipingRates updated , only rates code : ".$ratesStr);
			}
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function Delete Shipping Rate
	* (expose as WS)
    * @param string
    * @return Coupon details
    */
	function DeleteShippingRate($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_delshiprate']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$vm_ps_shipping = new vm_ps_shipping;
			//$db = new ps_DB;
			$allOk=true;
			$cpnIdsStr="";
			
			if (is_array($params->ids->id)){
			
				$count = count($params->ids->id);
				for ($i = 0; $i < $count; $i++) {
					$d['shipping_rate_id'][$i] = $params->ids->id[$i];
					
					/*$q = 'DELETE FROM #__{vm}_shipping_rate WHERE shipping_rate_id  = '.(int)$d['rate_id'][$i];
					$result = $db->query($q);*/
					$result = $vm_ps_shipping->rate_delete($d);
					if ($result){
						$cpnIdsStr .= $params->ids->id[$i]." ";
					}else{
						$allOk=false;
					}
				}
			} else {
				$d['shipping_rate_id'] = $params->ids->id;
				$cpnIdsStr .= $params->ids->id." ";
				/*
				$q = 'DELETE FROM #__{vm}_shipping_rate WHERE shipping_rate_id  = '.(int)$d['rate_id'];
				$result = $db->query($q);*/
				$result = $vm_ps_shipping->rate_delete($d);
				if ($result){
					return "Shipping rate successfully deleted : ".$cpnIdsStr;			
				} else{
					return new SoapFault("DeleteShippingRateFault", "Cannot delete shipping rate : ".$d['rate_id']);
				}
			}
			if ($allOk){
				return "Shipping Rates successfully deleted : ".$cpnIdsStr;
			} else {
				return new SoapFault("DeleteShippingRatesFault", "Not all ShiipingRates deleted, only rates id : ".$cpnIdsStr);
			}

		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function get GetAllShippingCarrier
	* (expose as WS)
    * @param string
    * @return shipping carrier
    */
	function GetAllShippingCarrier($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->login, $params->password);
		if ($conf['auth_order_getshipcarrier']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$db = new ps_DB;

			$list  = "SELECT * FROM #__{vm}_shipping_carrier WHERE 1";
			$db->query($list);
			
			while ($db->next_record()) {
			
				$ShippingCarrier = new ShippingCarrier($db->f("shipping_carrier_id"),$db->f("shipping_carrier_name"),$db->f("shipping_carrier_list_order"));
				$arrayShippingCarrier[]=$ShippingCarrier;
			
			}
			return $arrayShippingCarrier;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->login);
		}
	}
	
		/**
    * This function get AddShippingCarrier
	* (expose as WS)
    * @param string
    * @return result
    */
	function AddShippingCarrier($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_addshipcarrier']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$vm_ps_shipping = new vm_ps_shipping;
			$allOk=true;
			$carriersCodesStr;
			//chek if there is one or more shippnig carriers and add
			if (is_array($params->shipping_carriers->shipping_carrier)){
			
				$count = count($params->shipping_carriers->shipping_carrier);

				for ($i = 0; $i < $count; $i++) {
					$d['shipping_carrier_name']= $params->shipping_carriers->shipping_carrier[$i]->shipping_carrier_name;
					$d['shipping_carrier_list_order']= $params->shipping_carriers->shipping_carrier[$i]->shipping_carrier_list_order;

					//add carrier
					$ret = $vm_ps_shipping->add($d);
					if ($ret){
						$carriersCodesStr .= $d['shipping_carrier_name']." ";
					} else {
						$allOk=false;
					}
				} 
			}else {
				$d['shipping_carrier_name']= $params->shipping_carriers->shipping_carrier->shipping_carrier_name;
				$d['shipping_carrier_list_order']= $params->shipping_carriers->shipping_carrier->shipping_carrier_list_order;

				//add carrier
				$ret = $vm_ps_shipping->add($d);
				if ($ret){
					return "Carrier successfully added : ".$d['shipping_carrier_name']." id : ".$_REQUEST['shipping_carrier_id'];
				} else {
					return new SoapFault("AddCarrierFault", "Cannot add carrier : ".$d['shipping_carrier_name']);
				}
			}
			
			if ($allOk){
				return "All Carriers successfully added : ".$carriersCodesStr;
			} else {
				return new SoapFault("AddCouponsFault", "Not all carriers added, only carriers  : ".$carriersCodesStr);
			}
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function  Update ShippingCarrier
	* (expose as WS)
    * @param string
    * @return result
    */
	function UpdateShippingCarrier($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_upshipcarrier']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$vm_ps_shipping = new vm_ps_shipping;
			$allOk=true;
			$carriersCodesStr;
			//chek if there is one or more shippnig carriers and add
			if (is_array($params->shipping_carriers->shipping_carrier)){
			
				$count = count($params->shipping_carriers->shipping_carrier);

				for ($i = 0; $i < $count; $i++) {
					$d["shipping_carrier_id"] = $params->shipping_carriers->shipping_carrier[$i]->shipping_carrier_id;
					$d['shipping_carrier_name']= $params->shipping_carriers->shipping_carrier[$i]->shipping_carrier_name;
					$d['shipping_carrier_list_order']= $params->shipping_carriers->shipping_carrier[$i]->shipping_carrier_list_order;

					//add carrier
					$ret = $vm_ps_shipping->update($d);
					if ($ret){
						$carriersCodesStr .= $d['shipping_carrier_name']." ";
					} else {
						$allOk=false;
					}
				} 
			}else {
				$d["shipping_carrier_id"] = $params->shipping_carriers->shipping_carrier->shipping_carrier_id;
				$d['shipping_carrier_name']= $params->shipping_carriers->shipping_carrier->shipping_carrier_name;
				$d['shipping_carrier_list_order']= $params->shipping_carriers->shipping_carrier->shipping_carrier_list_order;

				//add carrier
				$ret = $vm_ps_shipping->update($d);
				if ($ret){
					return "Carrier successfully updated : ".$d['shipping_carrier_name']." id : ".$d['shipping_carrier_name'];
				} else {
					return new SoapFault("UpdateShippingCarrierFault", "Cannot update carrier : ".$d['shipping_carrier_name']);
				}
			}
			
			if ($allOk){
				return "All Carriers successfully updated : ".$carriersCodesStr;
			} else {
				return new SoapFault("UpdateShippingCarrierFault", "Not all carriers updated, only carriers code : ".$carriersCodesStr);
			}
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function DeleteShippingCarrier
	* (expose as WS)
    * @param string
    * @return result
    */
	function DeleteShippingCarrier($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_delshipcarrier']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			
			$db = new ps_DB;
			$allOk=true;
			$cpnIdsStr="";
			
			if (is_array($params->ids->id)){
			
				$count = count($params->ids->id);
				for ($i = 0; $i < $count; $i++) {
					$d['id'][$i] = $params->ids->id[$i];
					
					$q = 'DELETE FROM #__{vm}_shipping_carrier WHERE shipping_carrier_id  = '.(int)$d['id'][$i];
					$result = $db->query($q);
					if ($result){
						$cpnIdsStr .= $params->ids->id[$i]." ";
					}else{
						$allOk=false;
					}
				}
			} else {
				$d['id'] = $params->ids->id;
				$cpnIdsStr .= $params->ids->id." ";
				$q = 'DELETE FROM #__{vm}_shipping_carrier WHERE shipping_carrier_id  = '.(int)$d['id'];
				$result = $db->query($q);
				if ($result){
					return "ShippingCarrier successfully deleted : ".$cpnIdsStr;			
				} else{
					return new SoapFault("DeleteShippingCarrierFault", "Cannot delete shipping carrier : ".$d['id']);
				}
			}
			if ($allOk){
				return "All Shipping Carrier successfully deleted : ".$cpnIdsStr;
			} else {
				return new SoapFault("DeleteShippingCarrierFault", "Not all Shipping Carriers deleted, only carrier id : ".$cpnIdsStr);
			}

			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function Get All Payment Method
	* (expose as WS)
    * @param string
    * @return shipping rate
    */
	function GetAllPaymentMethod($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_getpayment']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		

			if ($params->payment_enabled == "Y" || $params->payment_enabled == "N"){
				$list  = "SELECT * FROM #__{vm}_payment_method WHERE payment_enabled ='".$params->payment_enabled."'";
			} else {
				$list  = "SELECT * FROM #__{vm}_payment_method WHERE 1";
			}
			$db = new ps_DB;
			
			$db->query($list);
			
			while ($db->next_record()) {
			
				$PaymentMethod = new PaymentMethod($db->f("payment_method_id"),$db->f("vendor_id"),$db->f("payment_method_name"), $db->f("payment_class"),
				$db->f("shopper_group_id"), $db->f("payment_method_discount"), $db->f("payment_method_discount_is_percent"), $db->f("payment_method_discount_max_amount"), $db->f("payment_method_discount_min_amount"),
				$db->f("list_order"), $db->f("payment_method_code"), $db->f("enable_processor"), $db->f("is_creditcard"), $db->f("payment_enabled"), $db->f("accepted_creditcards"), $db->f("payment_extrainfo"));
				$arrayPaymentMethod[]=$PaymentMethod;
			
			}
			return $arrayPaymentMethod;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	
	/**
    * This function Get All Payment Method
	* (expose as WS)
    * @param string
    * @return shipping rate
    */
	function GetOrderPaymentInfo($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_getpayment']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		

			$order_id = $params->order_id;
			$list  = "SELECT * FROM #__{vm}_payment_method pm join #__{vm}_order_payment op on pm.payment_method_id= op.payment_method_id  ";
			$list  .= "WHERE order_id = '$order_id' ";
			$db = new ps_DB;
			
			$db->query($list);
			
			while ($db->next_record()) {
			
				$PaymentMethod = new PaymentMethod($db->f("payment_method_id"),$db->f("vendor_id"),$db->f("payment_method_name"), $db->f("payment_class"),
				$db->f("shopper_group_id"), $db->f("payment_method_discount"), $db->f("payment_method_discount_is_percent"), $db->f("payment_method_discount_max_amount"), $db->f("payment_method_discount_min_amount"),
				$db->f("list_order"), $db->f("payment_method_code"), $db->f("enable_processor"), $db->f("is_creditcard"), $db->f("payment_enabled"), $db->f("accepted_creditcards"), $db->f("payment_extrainfo"));
				
			
			}
			return $PaymentMethod;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function Add PaymentMethod
	* (expose as WS)
    * @param string
    * @return result
    */
	function AddPaymentMethod($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_addpayment']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$_SESSION["ps_vendor_id"]  = $params->payment_method->vendor_id;
			$_REQUEST['shopper_group_id'] = $params->payment_method->shopper_group_id;
			$_REQUEST['payment_method_discount'] = $params->payment_method->payment_method_discount;
			$_REQUEST['list_order'] = $params->payment_method->list_order;
			
			$d['payment_method_name'] = $params->payment_method->payment_method_name;
			$d['payment_class']= $params->payment_method->payment_class;
			//$d['shopper_group_id']= $params->payment_method->shopper_group_id;
			$d['payment_method_discount']=  $params->payment_method->payment_method_discount;
			$d['payment_method_discount_is_percent']= $params->payment_method->payment_method_discount_is_percent;
			$d['payment_method_discount_max_amount']= $params->payment_method->payment_method_discount_max_amount;
			$d['payment_method_discount_min_amount']= $params->payment_method->payment_method_discount_min_amount;
			$d['list_order']= $params->payment_method->list_order;
			$d['payment_method_code']= $params->payment_method->payment_method_code;
			$d['enable_processor']= $params->payment_method->enable_processor;
			$d['is_creditcard']= $params->payment_method->is_creditcard;
			$d['payment_enabled']= $params->payment_method->payment_enabled;
			$d['accepted_creditcards']= $params->payment_method->accepted_creditcards;
			$_POST['payment_extrainfo']= $params->payment_method->payment_extrainfo;
			
			$ps_payment_method = new ps_payment_method;
			$result = $ps_payment_method->add($d);
			
			if ($result){
				return "PaymentMethod successfully added, ID : ".$_REQUEST['payment_method_id'];
			}else {
				return new SoapFault("AddPaymentMethodFault", "Cannot add PaymentMethod : ".$d['payment_method_name']);
			}

			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function Add UpdatePaymentMethod
	* (expose as WS)
    * @param string
    * @return result
    */
	function UpdatePaymentMethod($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_updatepayment']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$_SESSION["ps_vendor_id"]  = $params->payment_method->vendor_id;
			$_REQUEST['shopper_group_id'] = $params->payment_method->shopper_group_id;
			$_REQUEST['payment_method_discount'] = $params->payment_method->payment_method_discount;
			$_REQUEST['list_order'] = $params->payment_method->list_order;
			
			$d['payment_method_id'] = $params->payment_method->payment_method_id;
			$d['payment_method_name'] = $params->payment_method->payment_method_name;
			$d['payment_class']= $params->payment_method->payment_class;
			//$d['shopper_group_id']= $params->payment_method->shopper_group_id;
			$d['payment_method_discount']=  $params->payment_method->payment_method_discount;
			$d['payment_method_discount_is_percent']= $params->payment_method->payment_method_discount_is_percent;
			$d['payment_method_discount_max_amount']= $params->payment_method->payment_method_discount_max_amount;
			$d['payment_method_discount_min_amount']= $params->payment_method->payment_method_discount_min_amount;
			$d['list_order']= $params->payment_method->list_order;
			$d['payment_method_code']= $params->payment_method->payment_method_code;
			$d['enable_processor']= $params->payment_method->enable_processor;
			$d['is_creditcard']= $params->payment_method->is_creditcard;
			$d['payment_enabled']= $params->payment_method->payment_enabled;
			$d['accepted_creditcards']= $params->payment_method->accepted_creditcards;
			$_POST['payment_extrainfo']= $params->payment_method->payment_extrainfo;
			
			$ps_payment_method = new ps_payment_method;
			$result = $ps_payment_method->update($d);
			
			if ($result){
				return "PaymentMethod successfully Updated : ".$d['payment_method_name'];
			}else {
				return new SoapFault("UpdatePaymentMethoddFault", "Cannot update PaymentMethod : ".$d['payment_method_name']);
			}

			
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function Add DeletePaymentMethod
	* (expose as WS)
    * @param string
    * @return result
    */
	function DeletePaymentMethod($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_delapyment']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$ps_payment_method = new ps_payment_method;

			$cpnIdsStr="";
			
			if (is_array($params->ids->id)){
			
				$count = count($params->ids->id);
				for ($i = 0; $i < $count; $i++) {
					$d['payment_method_id'][$i] = $params->ids->id[$i];
					$cpnIdsStr .= $params->ids->id[$i]." ";
				}
			
			} else {
				$d['payment_method_id'] = $params->ids->id;
				$cpnIdsStr .= $params->ids->id." ";
			}
			
			$result = $ps_payment_method->delete($d);
			if ($result){
				return "Payment Method successfully deleted : ".$cpnIdsStr;
			} else {
				return new SoapFault("DeletePaymentMethodFault", "Cannot delete paymentMethod: ".$cpnIdsStr);
			}
		
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function Get Order between date
	* (expose as WS)
    * @param string 
    * @return array of orders
    */
	function GetOrderFromDate($params) {
	
		include('../vm_soa_conf.php');
		/* Authenticate*/
		
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_getorderfromdate']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			global $mosConfig_offset;
			
			$db = new ps_DB;
			
			// format : 2010-01-30
			 $date_start_Y = substr($params->date_start, 0, 4);
			 $date_start_M = substr($params->date_start, 5, 2);
			 $date_start_D = substr($params->date_start, 8, 2);
			 $date_start = gmmktime(0, 0, 0, (int)$date_start_M, (int)$date_start_D, (int)$date_start_Y);
			 
			 $date_end_Y = substr($params->date_end, 0, 4);
			 $date_end_M = substr($params->date_end, 5, 2);
			 $date_end_D = substr($params->date_end, 8, 2);
			 $date_end = gmmktime(23, 59, 59, (int)$date_end_M, (int)$date_end_D,(int)$date_end_Y);

			$list  = "SELECT * FROM #__{vm}_orders WHERE ";
			if (!empty($params->order_status)){
				$list .= "order_status = '$params->order_status' AND ";
				$list .= "cdate BETWEEN '$date_start' AND '$date_end' ";
				
			}else {
				$list .= "cdate BETWEEN '$date_start' AND '$date_end' ";
			
			}
			$list .= $q . " ORDER BY cdate ASC"; 
			
			
			$db = new ps_DB;
			$db->query($list);
			
			while ($db->next_record()) {
			
				$Order = new Order($db->f("order_id"),$db->f("user_id"), $db->f("vendor_id"), $db->f("order_number"), $db->f("user_info_id"), $db->f("order_total"), $db->f("order_subtotal"),
				$db->f("order_tax"), $db->f("order_tax_details"), $db->f("order_shipping"), $db->f("order_shipping_tax"), $db->f("coupon_discount"), $db->f("coupon_code"), $db->f("order_discount"), $db->f("order_currency"),
				$db->f("order_status"), $db->f("cdate"), $db->f("mdate") , $db->f("ship_method_id"), $db->f("customer_note"), $db->f("ip_address"));
				$orderArray[]=$Order;
			
			}
			return $orderArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
		/**
    * This function get GetAllCreditCard
	* (expose as WS)
    * @param string
    * @return AllCreditCard
    */
	function GetAllCreditCard($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->login, $params->password);
		if ($conf['auth_order_getcreditcard']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$db = new ps_DB;

			$list  = "SELECT * FROM #__{vm}_creditcard WHERE 1";
			$db->query($list);
			
			while ($db->next_record()) {
			
				$Creditcard = new Creditcard($db->f("creditcard_id"),$db->f("vendor_id"),$db->f("creditcard_name"),$db->f("creditcard_code"));
				$arrayCreditcard[]=$Creditcard;
			
			}
			return $arrayCreditcard;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->login);
		}
	}
	
	/**
    * This function  Add CreditCard
	* (expose as WS)
    * @param string
    * @return result
    */
	function AddCreditCard($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_addcreditcard']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$_SESSION["ps_vendor_id"]  = $params->Creditcard->vendor_id;
			$d['creditcard_name'] = $params->Creditcard->creditcard_name;
			$d['creditcard_code']= $params->Creditcard->creditcard_code;
		
			$ps_creditcard = new ps_creditcard;
			$result = $ps_creditcard->add($d);
			
			if ($result==true){
				return "Creditcard successfully added, ID : ".$_REQUEST['creditcard_id'];
			}else {
				return new SoapFault("AddCreditCardFault", "Cannot add Creditcard : ".$d['creditcard_name']);
			}

			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function  Update CreditCard
	* (expose as WS)
    * @param string
    * @return result
    */
	function UpdateCreditCard($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_upcreditcard']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$_SESSION["ps_vendor_id"]  = $params->Creditcard->vendor_id;
			$d['creditcard_id'] = $params->Creditcard->creditcard_id;
			$d['creditcard_name'] = $params->Creditcard->creditcard_name;
			$d['creditcard_code']= $params->Creditcard->creditcard_code;
		
			$ps_creditcard = new ps_creditcard;
			$result = $ps_creditcard->update($d);
			
			if ($result){
				return "Creditcard successfully updated, ID : ".$d['creditcard_name'];
			}else {
				return new SoapFault("UpdateCreditCardFault", "Cannot update Creditcard : ".$d['creditcard_name']);
			}
			
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
		/**
    * This function Delete creditCard
	* (expose as WS)
    * @param string
    * @return result
    */
	function DeleteCreditCard($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_delcreditcard']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
	
			$d['creditcard_id'] = $params->creditcard_id;
		
			$ps_creditcard = new ps_creditcard;
			$result = $ps_creditcard->delete($d);
			
			if ($result){
				return "Creditcard successfully deleted, ID : ".$d['creditcard_id'] ;
			}else {
				return new SoapFault("DeleteCreditCardFault", "Cannot delete Creditcard : ".$d['creditcard_id'] );
			}
			
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
/**
    * This function Add OrderStatus Code
	* (expose as WS)
    * @param string
    * @return result
    */
	function AddOrderStatusCode($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_addstatus']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$_SESSION["ps_vendor_id"]  = $params->OrderStatus->vendor_id;
			$d['order_status_id'] = "0"; //needed but not used
			$d['order_status_code'] = $params->OrderStatus->order_status_code;
			$d['order_status_name']= $params->OrderStatus->order_status_name;
			$d['order_status_description']= $params->OrderStatus->order_status_description;
			$d['list_order']=  $params->OrderStatus->list_order;
			
			
			$ps_order_status = new ps_order_status;
			$result = $ps_order_status->add($d);
			
			if ($result){
				return "OrderStatusCode successfully added, ID : ".$_REQUEST['order_status_id'];
			}else {
				return new SoapFault("AddOrderStatusCodeFault", "Cannot add OrderStatusCode : ".$d['order_status_code']);
			}

			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function Add Update OrderStatus Code
	* (expose as WS)
    * @param string
    * @return result
    */
	function UpdateOrderStatusCode($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_upstatus']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$_SESSION["ps_vendor_id"]  = $params->OrderStatus->vendor_id;
			$d['order_status_id'] = $params->OrderStatus->order_status_id;
			$d['order_status_code'] = $params->OrderStatus->order_status_code;
			$d['order_status_name']= $params->OrderStatus->order_status_name;
			$d['order_status_description']= $params->OrderStatus->order_status_description;
			$d['list_order']=  $params->OrderStatus->list_order;
			
			
			$ps_order_status = new ps_order_status;
			$result = $ps_order_status->update($d);
			
			if ($result){
				return "OrderStatusCode successfully updated, ID : ".$d['order_status_id'];
			}else {
				return new SoapFault("UpdateOrderStatusCodeFault", "Cannot update OrderStatusCode : ".$d['order_status_code']);
			}
			
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function Delete OrderStatus Code
	* (expose as WS)
    * @param string
    * @return result
    */
	function DeleteOrderStatusCode($params) {
	
		include('../vm_soa_conf.php');
				
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_order_delstatus']=="off"){
			$result = "true";
		}	
		
		//Auth OK
		if ($result == "true"){
		
			$db = new ps_DB;

			$list  = "SELECT vendor_id FROM #__{vm}_order_status WHERE order_status_id ='$params->order_status_id' ";
			$db->query($list);
			while ($db->next_record()) {
				$_SESSION["ps_vendor_id"] = $db->f("vendor_id");
			}
			
			$d['order_status_id'] = $params->order_status_id;
			$ps_order_status = new ps_order_status;
			$result = $ps_order_status->delete($d);
			
			if ($result){
				return "OrderStatusCode successfully deleted, ID : ".$d['order_status_id'];
			}else {
				return new SoapFault("DeleteOrderStatusCodeFault", "Cannot delete OrderStatusCode : ".$d['order_status_id']);
			}
		
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}	
	
	
	/**
    *  function onAuthenticate
	* (not expose as WS)
    * @param login/pass
    * @return true/false
   */
	function onAdminAuthenticate($login,$passwd){
	
		jimport('joomla.user.helper');
		$response="false";
		$db = new ps_DB;

		$list  = "SELECT id, username, password, usertype FROM `#__users` ";
		$list .= "WHERE username='".$login."' ";
		
		$response=$list;
		//$list .= $q . " LIMIT 0,100 "; 
		
		$db = new ps_DB;
		$db->query($list);

		/* function inspired by onAuthenticate (joomla.php) | Verify password is good*/
		if($db->next_record())
		{
			$parts	= explode( ':', $db->f("password") );
			$crypt	= $parts[0];
			$salt	= @$parts[1];
			$testcrypt = JUserHelper::getCryptedPassword($passwd, $salt);

			if ($crypt == $testcrypt ) {
				$response= "no_admin";
				if ( $db->f("usertype") == "Super Administrator" || $db->f("usertype") == "Administrator"){
					$response= "true";
				}
			} else {
				$response= "false";
			}
		}
		else
		{
			$response="no_user";
		}
		/////////////////////////////
		return $response;
	}
	
	
	/* SOAP SETTINGS */
	
	if ($conf['order_actif']=="on"){	
	
		
		$cache = "0";
		if ($conf['order_cache'] == "on")$cache = "1";
		ini_set("soap.wsdl_cache_enabled", $cache); // wsdl cache settings
		
		if ($conf['soap_version'] == "SOAP_1_1"){
			$options = array('soap_version' => SOAP_1_1);
		}else {
			$options = array('soap_version' => SOAP_1_2);
		}

		if (empty($conf['BASESITE']) && empty($conf['URL'])){
			$server = new SoapServer($URL_BASE.'administrator/components/com_vm_soa/services/VM_OrderWSDL.php');
		}else if (!empty($conf['BASESITE'])){
			$server = new SoapServer('http://'.$conf['URL'].'/'.$conf['BASESITE'].'/administrator/components/com_vm_soa/services/VM_OrderWSDL.php');
		}else {
			$server = new SoapServer('http://'.$conf['URL'].'/administrator/components/com_vm_soa/services/VM_OrderWSDL.php');
		}
		
		//$server = new SoapServer($mosConfig_live_site.'/VM_OrderWSDL.php');
		/*if (!empty($conf['BASESITE'])){
			$server = new SoapServer('http://'.$conf['URL'].'/'.$conf['BASESITE'].'/administrator/components/com_vm_soa/services/VM_OrderWSDL.php');
		}else {
			$server = new SoapServer('http://'.$conf['URL'].'/administrator/components/com_vm_soa/services/VM_OrderWSDL.php');
		}*/

		/* Add Functions */
		$server->addFunction("getOrdersFromStatus");
		$server->addFunction("getOrder");
		$server->addFunction("getOrderStatus");
		$server->addFunction("getAllOrders");
		$server->addFunction("UpdateOrderStatus");
		$server->addFunction("DeleteOrder");
		$server->addFunction("CreateOrder");
		$server->addFunction("GetAllCouponCode");
		$server->addFunction("AddCouponCode");
		$server->addFunction("DeleteCouponCode");	
		$server->addFunction("GetAllShippingRate");	
		$server->addFunction("GetAllShippingCarrier");	
		$server->addFunction("AddShippingCarrier");	
		$server->addFunction("AddShippingRate");	
		$server->addFunction("DeleteShippingCarrier");
		$server->addFunction("DeleteShippingRate");	
		$server->addFunction("GetAllPaymentMethod");	
		$server->addFunction("AddPaymentMethod");	
		$server->addFunction("DeletePaymentMethod");	
		$server->addFunction("UpdatePaymentMethod");	
		$server->addFunction("GetOrderFromDate");	
		$server->addFunction("GetAllCreditCard");
		$server->addFunction("AddCreditCard");
		$server->addFunction("UpdateCreditCard");
		$server->addFunction("DeleteCreditCard");
		$server->addFunction("DeleteOrderStatusCode");
		$server->addFunction("UpdateOrderStatusCode");
		$server->addFunction("AddOrderStatusCode");
		$server->addFunction("UpdateShippingCarrier");
		$server->addFunction("UpdateShippingRate");
		$server->addFunction("GetOrderPaymentInfo");
		
		$server->handle();
		
	}else{
		echo "This Web Service (Order) is desactived";
	}
?> 
Return current item: SOA For Virtuemart (WebServices)