Location: PHPKode > projects > SOA For Virtuemart (WebServices) > com_vm_soa/admin/services/VM_CategoriesService.php
<?php
define( '_VALID_MOS', 1 );
define( '_JEXEC', 1 );

/**
 * Virtuemart Category SOA Connector
 *
 * Virtuemart Category SOA Connector (Provide functions GetCategoryFromId, GetCategoryFromId, GetChildsCategory, GetCategorysFromCategory)
 * The return classe is a "Category" classe with attribute : id, name, description, price, quantity, image, fulliamage ,
 * attributes, parent produit, child id)
 *
 * @package    mod_vm_soa
 * @subpackage modules
 * @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');
}

// 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');
}

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.'/';
}

require_once(CLASSPATH.'ps_product_category.php');
require_once(CLASSPATH.'ps_product.php');

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

$ps_product= new ps_product();


/**
 * Class Categorie
 *
 * Class "Categorie" with attribute : id, name, description,  image, fulliamage , parent category
 * attributes, parent produit, child 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 Categorie {
		public $id="Tshirt noir";
		public $name="35.90€";
		public $description="Tshirt noir en bamboo";
		public $image="Tshirt noir en bamboo";
		public $fullimage="Tshirt noir en bamboo";
		public $parentcat="Tshirt noir en bamboo";
		public $numberofproducts="";
		public $category_publish="";
		public $category_browsepage="";
		public $category_flypage="";	
		public $products_per_row="";			
		//constructeur
		function __construct($id, $name, $description, $image, $fullimage,$parentcat,$numberofproducts,$category_publish,$category_browsepage,$category_flypage,$products_per_row) {
			$this->id = $id;
			$this->name = $name;
			$this->description = $description;
			$this->image = $image;
			$this->fullimage = $fullimage;
			$this->parentcat = $parentcat;
			$this->numberofproducts = $numberofproducts;
			$this->category_publish = $category_publish;
			$this->category_browsepage = $category_browsepage;
			$this->category_flypage = $category_flypage;
			$this->products_per_row = $products_per_row;
		}
	}
	
/**
 * Class AvalaibleImage
 *
 * Class "AvalaibleImage" 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 AvalaibleImage {
		public $image_name="";
		public $image_url="";
		public $realpath="";

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $image_name
		 * @param String $image_url
		 */
		function __construct($image_name, $image_url, $realpath) {
			$this->image_name = $image_name;
			$this->image_url = $image_url;	
			$this->realpath = $realpath;				
		}
	}	
	
	/**
    * This function get Childs of a category for a category ID
	* (expose as WS)
    * @param string The id of the category
    * @return array of Categories
   */
	function GetChildsCategories($params) {
	
		include('../vm_soa_conf.php');
		$category_id = $params->categoryId;
		global $sess, $ps_product, $VM_LANG;
		$ps_product_category = new ps_product_category;

		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_cat_getchild']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
		
			
			
			//$ps_vendor_id = $_SESSION["ps_vendor_id"];
			$ps_vendor_id=1;
			$db = new ps_DB;
			$childs = array();
			
			$q = "SELECT category_id, category_thumb_image, category_description,category_parent_id, category_child_id,category_name, category_full_image, category_publish, category_browsepage,category_flypage,products_per_row FROM #__{vm}_category,#__{vm}_category_xref ";
			$q .= "WHERE #__{vm}_category_xref.category_parent_id='$category_id' ";
			$q .= "AND #__{vm}_category.category_id=#__{vm}_category_xref.category_child_id ";
			//$q .= "AND #__{vm}_category.vendor_id='$ps_vendor_id' ";
			if (!empty($params->category_publish)){
				$publish = $params->category_publish;
				$q .= "AND #__{vm}_category.category_publish='$publish' ";
			}
			$q .= "ORDER BY #__{vm}_category.list_order, #__{vm}_category.category_name ASC";
			$db->setQuery($q);
			$db->query();
			
			while( $db->next_record() ) {
			
				$category_id = $db->f("category_id" );
				$category_name = $db->f("category_name" );
				$category_description = $db->f("category_description" );
				$category_thumb_image = $db->f("category_thumb_image" );
				$category_full_image = $db->f("category_full_image" );
				$productcout=$ps_product_category->product_count($category_id);
				$category_publish = $db->f("category_publish" );
				$category_browsepage = $db->f("category_browsepage" );
				$category_flypage = $db->f("category_flypage" );
				$products_per_row = $db->f("products_per_row" );
				$category_parent_id = $db->f("category_parent_id" );
				
				$Categorie = new Categorie($category_id,$category_name,$category_description,$category_thumb_image,$category_full_image,$category_parent_id,$productcout,$category_publish,$category_browsepage,$category_flypage,$products_per_row);
				$catArray[] = $Categorie;
			}
			return $catArray;
			
		}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 the categories
	* (expose as WS)
    * @param string The id of the category
    * @return array of Categories
   */
	function GetAllCategories($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_cat_getall']=="off"){
			$result = "true";
		}

	//	$result=false;
		//Auth OK
		if ($result == "true"){
		
			$ps_product_category = new ps_product_category;
			
			
			$db = new ps_DB;
			
			$q = "SELECT category_id, vendor_id, category_name, category_description, category_thumb_image, category_parent_id, category_full_image, list_order, category_publish, category_browsepage,category_flypage,products_per_row  FROM #__{vm}_category cat ";
			$q .= "JOIN #__{vm}_category_xref ref on ref.category_child_id = cat.category_id  ";
			$q .= "WHERE 1 ";
			if (!empty($params->category_publish)){
				$publish = $params->category_publish;
				$q .= "AND category_publish='$publish' ";
			}
			$db->query( $q );
						
			while ($db->next_record()) {
						
				$category_id = $db->f("category_id" );
				$category_name = $db->f("category_name" );
				$category_description = $db->f("category_description" );
				$category_thumb_image = $db->f("category_thumb_image" );
				$category_full_image = $db->f("category_full_image" );
				$productcout=$ps_product_category->product_count($category_id);
				$category_publish = $db->f("category_publish" );
				$category_browsepage = $db->f("category_browsepage" );
				$category_flypage = $db->f("category_flypage" );
				$products_per_row = $db->f("products_per_row" );
				$category_parent_id = $db->f("category_parent_id" );
				//$parCat =$ps_product_category->get_child_list($categorie);
				
				$Categorie = new Categorie($category_id,$category_name,$category_description,$category_thumb_image,$category_full_image,$category_parent_id,$productcout, $category_publish,$category_browsepage,$category_flypage,$products_per_row );

				$catArray[] = $Categorie;
				
			}
		  //global $catArray;
		  return $catArray;
		
		}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 category
	* (expose as WS)
    * @param string The id of the category
    * @return result
   */
	function AddCategory($params) {
		
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_cat_addcat']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
		
			$updateFullImageName = false;
			$updateImageName = false;
			$imageName="";
			$fullImageName="";
			if (!empty( $params->category->fullimage )) {
			
				if (substr( $params->category->fullimage, 0, 4) != "http") {
				$updateFullImageName = true;
				$fullImageName=$params->category->fullimage;
				$params->category->fullimage="";
				}
			}
			if (!empty( $params->category->image )) {
			
				if (substr( $params->category->image, 0, 4) != "http") {
				$updateImageName = true;
				$imageName=$params->category->image;
				$params->category->image="";
				}
			}
			
			
			$ps_product_category = new ps_product_category;
			$_SESSION["ps_vendor_id"]= "1";
			$_REQUEST["parent_category_id"]=  $params->category->parentcat;
			
			$prod['category_publish']= $params->category->category_publish;
			$prod['category_name']= $params->category->name;
			$prod['category_description']= $params->category->description;
			$prod['category_browsepage']= $params->category->category_browsepage;
			//$prod['products_per_row']= $params->category->products_per_row;
			$_REQUEST["products_per_row"] = $params->category->products_per_row;
			$prod['category_flypage']= $params->category->category_flypage;
			$prod['category_thumb_image_url']= $params->category->image;
			$prod['category_full_image_url']= $params->category->fullimage;
			$prod['parent_category_id'] =  $params->category->parentcat;
			
			$ret = $ps_product_category->add($prod);
			
			if ($updateFullImageName){
			
				$type='UPDATE';
				$db = new ps_DB;
				$values['category_full_image']=$fullImageName;
				$whereClause = " WHERE category_id =".$_REQUEST['category_id']."";
				$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
				$result = $db->query();
				
			}
			if ($updateImageName){
			
				$type='UPDATE';
				$db = new ps_DB;
				$values['category_thumb_image']= $imageName;
				$whereClause = " WHERE category_id =".$_REQUEST['category_id']."";
				$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
				$result = $db->query();
				
			}
			//return $params->category->name;
			if ($ret == false ){
				return new SoapFault("VMCategoryCreationFault", "Cannot create category ".$params->category->name);
			}else{
				return "Category created ".$params->category->name." ID : ".$_REQUEST['category_id'];
			}

		
		}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 Update Category
	* (expose as WS)
    * @param string The id of the category
    * @return result
   */
	function UpdateCategory($params) {
		
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_cat_updatecat']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
		
			//before update, change image file name (because update will delete image) //so when update, image must be URL image 
			/*$type='UPDATE';
			$db = new ps_DB;
			$values['category_thumb_image']="temp";
			$values['category_full_image']="temp";
			$whereClause = " WHERE category_id =".$params->category->id."";
			$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
			$result = $db->query();*/
			$list  = "SELECT category_thumb_image, category_full_image FROM #__{vm}_category WHERE category_id =".$params->category->id."";
			$db = new ps_DB;
			$db->query($list);
			while ($db->next_record()) {
				$original_category_full_image = $db->f("category_full_image");
				$original_category_thumb_image = $db->f("category_thumb_image");
			}
		
			$ps_product_category = new ps_product_category;
			$_SESSION["ps_vendor_id"]= "1";
			$_REQUEST["category_parent_id"]=  $params->category->parentcat;
			$prod['category_id']= $params->category->id;
			$prod['category_publish']= $params->category->category_publish;
			$prod['category_name']= $params->category->name;
			$prod['category_description']= $params->category->description;
			$prod['category_browsepage']= $params->category->category_browsepage;
			//$prod['products_per_row']= $params->category->products_per_row;
			$_REQUEST["products_per_row"] = $params->category->products_per_row;
			$prod['category_flypage']= $params->category->category_flypage;
			$prod['category_thumb_image_url']= $params->category->image;
			$prod['category_full_image_url']= $params->category->fullimage;
			$prod['category_parent_id'] =  $params->category->parentcat;
			
			$canUpdateFullImageFleds = false;
			$canUpdateThumbImageFleds = false;
			$imgMsgerr="";
			
			//// FULL IMG ////
			if (!empty( $params->category->fullimage )) {
			
				if (substr( $params->category->fullimage, 0, 4) != "http") {
					
					$prod['category_full_image'] = "";
					$prod['category_full_image_url'] = "";
					$categoty_full_image = $params->category->fullimage;
					$canUpdateFullImageFleds = true;
					$imgMsgerr="<fullimage> and <image> must be URL or empty";
				}else {
					$prod['category_full_image']= $params->category->fullimage;
					$prod['category_full_image_url']= $params->category->fullimage;
					$categoty_full_image = $params->category->fullimage;
					$canUpdateFullImageFleds = true;
					//protect delete
					$type='UPDATE';
					$db = new ps_DB;
					$values['category_full_image']="temp";
					$whereClause = " WHERE category_id =".$params->category->id."";
					$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
					$result = $db->query();
				}
			} else {
				//if empty copy value// change name befor update to prevent deleting image// and copy after update
				
				$categoty_full_image = $original_category_full_image;
				
				//after getting values change it to prevent delete
				$type='UPDATE';
				$db = new ps_DB;
				$values['category_full_image']="temp";
				$whereClause = " WHERE category_id =".$params->category->id."";
				$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
				$result = $db->query();
			}
			
			//// THUMB IMG ////
			if (!empty( $params->category->image )) {
			
				if (substr( $params->category->image, 0, 4) != "http") {
					
					$prod['category_thumb_image'] = "";
					$prod['category_thumb_image_url'] = "";
					$category_thumb_image = $params->category->image;
					$canUpdateThumbImageFleds = true;
					$imgMsgerr="<fullimage> and <image> must be URL or empty";
				}else {
					$prod['category_thumb_image_url']= $params->category->image;
					$prod['category_thumb_image']= $params->category->image;
					$category_thumb_image = $params->category->image;
					$canUpdateThumbImageFleds = true;
					//protect delete
					$type='UPDATE';
					$db = new ps_DB;
					$values['category_thumb_image']="temp";
					$whereClause = " WHERE category_id =".$params->category->id."";
					$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
					$result = $db->query();
				}
			} else {
				//if empty copy value// change name befor update to prevent deleting image// and copy after update
				
				$category_thumb_image = $original_category_thumb_image;
				
				//after getting values change it to prevent delete
				$type='UPDATE';
				$db = new ps_DB;
				$values['category_thumb_image']="temp";
				$whereClause = " WHERE category_id =".$params->category->id."";
				$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
				$result = $db->query();
			}
			
			//VM update cat
			$ret = $ps_product_category->update($prod);
			
			//update full image
			if ( (empty( $params->category->fullimage ) || $canUpdateFullImageFleds ) && $ret) {
				$type='UPDATE';
				$db = new ps_DB;
				$values['category_full_image']=$categoty_full_image;
				$whereClause = " WHERE category_id =".$params->category->id."";
				$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
				$result = $db->query();
			}else{
				//update to original
				/*$type='UPDATE';
				$db = new ps_DB;
				$values['product_full_image']=$original_product_full_image;
				$whereClause = " WHERE product_id =".$product->id."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();*/
			}
			//update image
			if ( (empty( $params->category->image ) || $canUpdateThumbImageFleds ) && $ret ) {
				$type='UPDATE';
				$db = new ps_DB;
				$values['category_thumb_image']=$category_thumb_image;
				$whereClause = " WHERE category_id =".$params->category->id."";
				$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
				$result = $db->query();
			} else {
				//update to original
				/*$type='UPDATE';
				$db = new ps_DB;
				$values['product_thumb_image']=$original_product_thumb_image;
				$whereClause = " WHERE product_id =".$product->id."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();*/
			}
			
			
			
			if ($ret == false ){
				//update to original img file name			
				$type='UPDATE';
				$db = new ps_DB;
				$values['category_thumb_image']=$original_category_thumb_image;
				$values['category_full_image']=$original_category_full_image;
				$whereClause = " WHERE category_id =".$params->category->id."";
				$db->buildQuery($type,"#__{vm}_category",$values,$whereClause);
				$result = $db->query();
				return new SoapFault("UpdateCategoryFault", "Cannot update category ".$params->category->name);
			}else{
				return "Category updated ".$params->category->name;
			}

		
		}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 DeleteCategory
	* (expose as WS)
    * @param string result
    * @return result
   */
	function DeleteCategory($params) {
		
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_cat_delcat']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
		
			
			$_SESSION["ps_vendor_id"]= "1";
			$prod['ps_vendor_id']= "1";
			$prod['category_id']= $params->category_id;
			
			$ps_product_category = new ps_product_category();
			$ret = $ps_product_category->delete($prod);

			if ($ret == false ){
				return new SoapFault("VMCategoryDeleteFault", "Cannot delete category ".$params->category_id);
			}else{
				return "Category deleted ".$params->category_id;
			}

		
		}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 Get Available Images on server (dir components/com_virtuemart/shop_image/category)
	* (expose as WS)
    * @param string
    * @return array of products
   */
	function GetAvailableImages($params) {
	
		include('../vm_soa_conf.php');
		
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_cat_getimg']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
		
			

			$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');
			}
		
			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.'/';
			}
			
			$INSTALLURL = '';
			if (empty($conf['BASESITE']) && empty($conf['URL'])){
				$INSTALLURL = $URL_BASE;
			} else if (!empty($conf['BASESITE'])){
				$INSTALLURL = 'http://'.$conf['URL'].'/'.$conf['BASESITE'].'/';
			} else {
				$INSTALLURL = 'http://'.$conf['URL'].'/';
			}
			
			if ($params->img_type == "full" || $params->img_type == "all" || $params->img_type == ""){
			
				$dir = realpath( dirname(__FILE__).'/../../../../components/com_virtuemart/shop_image/category' );
				$dirname = $dir;
				//$dir = "/tmp/php5";
				// Ouvre un dossier bien connu, et liste tous les fichiers
				if (is_dir($dir)) {
					if ($dh = opendir($dir)) {
						while (($file = readdir($dh)) !== false) {
							//echo "fichier : $file : type : " . filetype($dir . $file) . "\n";
							$AvalaibleImage = new AvalaibleImage($file,$INSTALLURL.'components/com_virtuemart/shop_image/category/'.$file,$dirname);
							$AvalaibleImageArray[] = $AvalaibleImage;
						}
						closedir($dh);
					}
				}
			}
			if ($params->img_type == "thumb" || $params->img_type == "all" || $params->img_type == ""){
				
				$dir = realpath( dirname(__FILE__).'/../../../../components/com_virtuemart/shop_image/category/resized' );
				$dirname = $dir;
				//$dir = "/tmp/php5";
				// Ouvre un dossier bien connu, et liste tous les fichiers
				if (is_dir($dir)) {
					if ($dh = opendir($dir)) {
						while (($file = readdir($dh)) !== false) {
							//echo "fichier : $file : type : " . filetype($dir . $file) . "\n";
							if ($file =="." || $file ==".." || $file =="index.html"){
								
							} else {
							$AvalaibleImage = new AvalaibleImage($file,$INSTALLURL.'components/com_virtuemart/shop_image/category/resized/'.$file,$dirname);
							$AvalaibleImageArray[] = $AvalaibleImage;
							}
						}
						closedir($dh);
					}
				}
			}
			return $AvalaibleImageArray;

			
		}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);
		}		
	}
	
	/**
    *  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['product_actif']=="on"){
		
		/* SOAP SETTINGS */
		$cache = "0";
		if ($conf['cat_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);
		}

		//$server = new SoapServer($mosConfig_live_site.'/VM_CategoriesWSDL.php');
		if (empty($conf['BASESITE']) && empty($conf['URL'])){
			$server = new SoapServer($URL_BASE.'administrator/components/com_vm_soa/services/VM_CategoriesWSDL.php');
		}else if (!empty($conf['BASESITE'])){
			$server = new SoapServer('http://'.$conf['URL'].'/'.$conf['BASESITE'].'/administrator/components/com_vm_soa/services/VM_CategoriesWSDL.php');
		}else {
			$server = new SoapServer('http://'.$conf['URL'].'/administrator/components/com_vm_soa/services/VM_CategoriesWSDL.php');
		}
		/* Add Functions */
		$server->addFunction("GetAllCategories");
		$server->addFunction("GetChildsCategories");
		$server->addFunction("AddCategory");
		$server->addFunction("DeleteCategory");
		$server->addFunction("GetAvailableImages");
		$server->addFunction("UpdateCategory");
		
		
		$server->handle();
	}else{
		echo "This Web Service (Order) is desactived";
	}
?> 
Return current item: SOA For Virtuemart (WebServices)