PageRenderTime 61ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/extra addons/extra addons/extra-trunk/esale_joomla/connector/tinyerp-synchro.php

http://hornerp.googlecode.com/
PHP | 673 lines | 501 code | 94 blank | 78 comment | 76 complexity | ad23174d0b3826a2ac2952bd940c0ee4 MD5 | raw file
Possible License(s): MIT, MPL-2.0-no-copyleft-exception, GPL-2.0, GPL-3.0
  1. <?php
  2. define( '_VALID_MOS', 1);
  3. include("xmlrpc.inc");
  4. include("xmlrpcs.inc");
  5. require_once( 'configuration.php' );
  6. require_once( 'administrator/components/com_virtuemart/virtuemart.cfg.php' );
  7. if(empty($mosConfig_host))
  8. {
  9. $conf = new JConfig();
  10. $dbprefix = $conf->dbprefix;
  11. $con = mysql_pconnect($conf->host, $conf->user, $conf->password );
  12. mysql_select_db($conf->db);
  13. }
  14. else
  15. {
  16. $dbprefix = $mosConfig_dbprefix;
  17. $con = mysql_pconnect($mosConfig_host, $mosConfig_user, $mosConfig_password );
  18. mysql_select_db($mosConfig_db);
  19. }
  20. function get_taxes() {
  21. global $dbprefix;
  22. $taxes=array();
  23. $result=mysql_query("select tax_rate_id, tax_rate*100 from ".$dbprefix."vm_tax_rate;");
  24. if ($result) while ($row=mysql_fetch_row($result)) {
  25. $taxes[]=new xmlrpcval(array(new xmlrpcval($row[0], "int"), new xmlrpcval("Tax ".$row[1]."%", "string")), "array");
  26. }
  27. return new xmlrpcresp( new xmlrpcval($taxes, "array"));
  28. }
  29. function delete_products() {
  30. global $dbprefix;
  31. mysql_query("truncate table ".$dbprefix."vm_product_attribute;");
  32. mysql_query("truncate table ".$dbprefix."vm_product_price;");
  33. mysql_query("truncate table ".$dbprefix."vm_product_tax;");
  34. mysql_query("truncate table ".$dbprefix."vm_product_category_xref;");
  35. mysql_query("delete from ".$dbprefix."jf_content where reference_table='vm_product' and reference_field in ('product_s_desc','product_desc') ;");
  36. $result=mysql_query("truncate table ".$dbprefix."vm_product;");
  37. //$result=mysql_query("update ".$dbprefix."vm_product set `product_publish` = 'N';");
  38. //$result=mysql_query("update ".$dbprefix."vm_product set ".
  39. // "product_publish='N' ".
  40. // ";");
  41. return new xmlrpcresp( new xmlrpcval($result, "int"));
  42. }
  43. function unlink_products($product_id) {
  44. global $dbprefix;
  45. //self.debug("Products Ids for Unlink: ".implode(",",$product_ids));
  46. mysql_query("update ".$dbprefix."vm_product set product_publish='N' where product_id in (".implode(",",$product_id).");");
  47. return new xmlrpcresp(new xmlrpcval(1,"int"));
  48. }
  49. function delete_product_categories() {
  50. global $dbprefix;
  51. mysql_query("truncate table ".$dbprefix."vm_category_xref;");
  52. $result = mysql_query("truncate table ".$dbprefix."vm_category;");
  53. return new xmlrpcresp(new xmlrpcval($result, "int"));
  54. }
  55. function get_languages() {
  56. $languages = array();
  57. $languages[] = new xmlrpcval(array(new xmlrpcval(1, "int"), new xmlrpcval("Unique", "string")), "array");
  58. return new xmlrpcresp( new xmlrpcval($languages, "array"));
  59. }
  60. function get_categories() {
  61. global $dbprefix;
  62. $categories=array();
  63. $result=mysql_query("select category_id, category_name from ".$dbprefix."vm_category;");
  64. if ($result) while ($row=mysql_fetch_row($result)) {
  65. $row0 = $row[0];
  66. $row1 = urlencode($row[1]);
  67. $categories[] = new xmlrpcval(array(new xmlrpcval($row[0], "int"), new xmlrpcval(parent_category($row0, $row1), "string")), "array");
  68. }
  69. return new xmlrpcresp( new xmlrpcval($categories, "array"));
  70. }
  71. function parent_category($id, $name) {
  72. global $dbprefix;
  73. $result=mysql_query("select category_parent_id from ".$dbprefix."vm_category_xref where category_child_id=".$id.";");
  74. if ($result && $row=mysql_fetch_row($result)) {
  75. if ($row[0]==0) {
  76. return $name;
  77. } else {
  78. $resultb=mysql_query("select category_name from ".$dbprefix."vm_category where category_id=".$row[0].";");
  79. if ($resultb && $rowb=mysql_fetch_row($resultb)) {
  80. $name=parent_category($row[0], $rowb[0] . " \\ ". $name);
  81. return $name;
  82. }
  83. }
  84. }
  85. return $name;
  86. }
  87. function set_product_stock($tiny_product) {
  88. global $dbprefix;
  89. mysql_query("update ".$dbprefix."vm_product set product_in_stock=".$tiny_product['quantity']." where
  90. product_id=".$tiny_product['esale_joomla_id'].";");
  91. //mysql_query("update products set products_status=".(($tiny_product['quantity']>0)?1:0)." where
  92. //products_id=".$tiny_product['esale_joomla_id'].";");
  93. return new xmlrpcresp(new xmlrpcval(1,"int"));
  94. }
  95. function debug($s) {
  96. $fp = fopen("/tmp/debug.xmlrpc2.txt","a");
  97. fwrite($fp, $s."\n");
  98. fclose($fp);
  99. }
  100. function _update_category_name_by_lang($lang_id, $lang_str, $osc_id, $tiny_category) {
  101. $res = 0;
  102. global $dbprefix;
  103. $original_name = ($tiny_category['name']);
  104. $name_value = ($tiny_category['name:' . $lang_str]);
  105. if($name_value == '' and $original_name != '') {
  106. $name_value = $original_name;
  107. } elseif ($original_name == '' and $name_value != '') {
  108. $original_name = $name_value;
  109. }
  110. if($original_name != '') {
  111. $name_value = str_replace('"', '\"', $name_value);
  112. $result = mysql_query("select id from ".$dbprefix."jf_content where reference_id=".$osc_id." and reference_table='vm_category' and reference_field='category_name';");
  113. $res = -1;
  114. if ($result && $row=mysql_fetch_row($result)) {
  115. $res = mysql_query("update ".$dbprefix."jf_content set reference_id=".$osc_id." ,language_id='".$lang_id."',published=1,value=\"".$name_value."\",modified='".date( "Y-m-d H:i:s" )."',original_value='".md5($original_name)."' where id=".$row[0].";");
  116. } else {
  117. $res = mysql_query("insert into ".$dbprefix."jf_content(language_id,reference_id,reference_table,reference_field,value,original_value,modified_by,modified,published) values (".$lang_id.",".$osc_id.",'vm_category','category_name',\"".$name_value."\",'".md5($original_name)."',70,'".date( "Y-m-d H:i:s" )."',1);");
  118. }
  119. }
  120. }
  121. function set_category($tiny_category){
  122. global $dbprefix;
  123. if($tiny_category['esale_joomla_id'] != 0) {
  124. $result = mysql_query("update ".$dbprefix."vm_category set ".
  125. "category_name='". ($tiny_category['name'])."', ".
  126. "category_description='". ($tiny_category['name'])."'".
  127. "where category_id=".$tiny_category['esale_joomla_id'].";");
  128. $osc_id = $tiny_category['esale_joomla_id'];
  129. } else {
  130. mysql_query("insert into ".$dbprefix."vm_category (category_name,category_description,category_publish,vendor_id) values (\"". ($tiny_category['name'])."\",\"". ($tiny_category['name'])."\",\"Y\",'1');");
  131. $category_child_id = mysql_insert_id();
  132. mysql_query("update ".$dbprefix."vm_category set list_order=".$category_child_id." where category_id=".$category_child_id.";");
  133. $category_parent_id=$tiny_category['parent_id'];
  134. mysql_query("insert into ".$dbprefix."vm_category_xref (category_parent_id,category_child_id) values (".$category_parent_id.",".$category_child_id.");");
  135. $osc_id = $category_child_id;
  136. }
  137. $result = mysql_query("select id from ".$dbprefix."languages where iso='fr';");
  138. $lang_id = -1;
  139. if ($result && $row=mysql_fetch_row($result)) {
  140. $lang_id = $row[0];
  141. }
  142. // Retrieve FRENCH language:
  143. $res = mysql_query("select id from ".$dbprefix."languages where iso='fr';");
  144. $lang_fr_id = -1;
  145. $lang_fr_str = 'fr_FR';
  146. if ($res && $row=mysql_fetch_row($res)) {
  147. $lang_fr_id = $row[0];
  148. }
  149. // Retrieve ENGLISH language:
  150. $res = mysql_query("select id from ".$dbprefix."languages where iso='en';");
  151. $lang_en_id = -1;
  152. $lang_en_str = 'en_US';
  153. if ($res && $row=mysql_fetch_row($res)) {
  154. $lang_en_id = $row[0];
  155. }
  156. _update_category_name_by_lang($lang_fr_id, $lang_fr_str, $osc_id, $tiny_category);
  157. _update_category_name_by_lang($lang_en_id, $lang_en_str, $osc_id, $tiny_category);
  158. return new xmlrpcresp(new xmlrpcval($osc_id, "int"));
  159. }
  160. function set_tax($tiny_tax){
  161. global $dbprefix;
  162. $country_id = '-';
  163. $state_id = '-';
  164. $type = 'fixamount';
  165. if ($tiny_tax['type'] == 'percent')
  166. $type = 'percentage';
  167. if ($tiny_tax['country']) {
  168. $result = mysql_query("select country_3_code from ".$dbprefix."vm_country where country_name='".$tiny_tax['country']."';");
  169. if ($result && $row=mysql_fetch_row($result)) {
  170. $country_id = $row[0];
  171. }
  172. }
  173. if($tiny_tax['esale_joomla_id'] != 0) {
  174. $result=mysql_query("update ".$dbprefix."vm_tax_rate set ".
  175. "tax_name='".$tiny_tax['name']."', ".
  176. "tax_type='".$type."', ".
  177. "tax_rate=".$tiny_tax['rate'].", ".
  178. "inc_base_price=".$tiny_tax['include_base_amount'].", ".
  179. "tax_country='".$country_id."', ".
  180. "tax_state='".$state_id."', ".
  181. "priority=".$tiny_tax['sequence'].
  182. " where tax_rate_id=".$tiny_tax['esale_joomla_id'].";");
  183. $osc_id=$tiny_tax['esale_joomla_id'];
  184. } else {
  185. mysql_query("insert into ".$dbprefix."vm_tax_rate (tax_name,tax_type,tax_rate,inc_base_price,priority,tax_country,tax_state,vendor_id) values (\"".$tiny_tax['name']."\",\"".$type."\",".$tiny_tax['rate'].",".$tiny_tax['include_base_amount'].",".$tiny_tax['sequence'].",'".$country_id."','".$state_id."','1');");
  186. $osc_id = mysql_insert_id();
  187. }
  188. return new xmlrpcresp(new xmlrpcval($osc_id, "int"));
  189. }
  190. function _update_product_name_by_lang($lang_id, $lang_str, $osc_id, $tiny_product) {
  191. $res = 0;
  192. global $dbprefix;
  193. $original_name = ($tiny_product['name']);
  194. $name_value = ($tiny_product['name:' . $lang_str]);
  195. if($name_value=='' and $original_name!='') {
  196. $name_value = $original_name;
  197. } elseif ($original_name=='' and $name_value!='') {
  198. $original_name = $name_value;
  199. }
  200. if($original_name != '') {
  201. $name_value = str_replace('"', '\"', $name_value);
  202. $result = mysql_query("select id from ".$dbprefix."jf_content where reference_id=".$osc_id." and reference_table='vm_product' and reference_field='product_name' and language_id = ".$lang_id.";");
  203. $res = -1;
  204. if ($result && $row=mysql_fetch_row($result)) {
  205. $res = mysql_query("update ".$dbprefix."jf_content set reference_id=".$osc_id." ,language_id='".$lang_id."',published=1,value=\"".$name_value."\",modified='".date( "Y-m-d H:i:s" )."',original_value='".md5($original_name)."' where id=".$row[0].";");
  206. //self.debug("update ".$dbprefix."jf_content set reference_id=".$osc_id." ,language_id='".$lang_id."',published=1,value=\"".$name_value."\",modified='".date( "Y-m-d H:i:s" )."',original_value='".md5($original_name)."' where id=".$row[0].";");
  207. //self.debug("res_update: " . $res);
  208. } else {
  209. $res = mysql_query("insert into ".$dbprefix."jf_content(language_id,reference_id,reference_table,reference_field,value,original_value,modified_by,modified,published) values (".$lang_id.",".$osc_id.",'vm_product','product_name',\"".$name_value."\",'".md5($original_name)."',70,'".date( "Y-m-d H:i:s" )."',1);");
  210. //self.debug("insert into ".$dbprefix."jf_content(language_id,reference_id,reference_table,reference_field,value,original_value,modified_by,modified,published) values (".$lang_id.",".$osc_id.",'vm_product','product_name',\"".$name_value."\",'".md5($original_name)."',70,'".date( "Y-m-d H:i:s" )."',1);");
  211. //self.debug("res_insert: " . $res);
  212. }
  213. }
  214. }
  215. function _update_product_long_desc_by_lang($lang_id, $lang_str, $osc_id, $tiny_product) {
  216. $res = 0;
  217. global $dbprefix;
  218. $original_name = ($tiny_product['description']);
  219. $desc_value = ($tiny_product['description:' . $lang_str]);
  220. if ($desc_value=='' and $original_name!='') {
  221. $desc_value = $original_name;
  222. } elseif ($original_name=='' and $desc_value!='') {
  223. $original_name = $desc_value;
  224. }
  225. if ($original_name!='') {
  226. $desc_value = str_replace('"', '\"', $desc_value);
  227. $result = mysql_query("select id from ".$dbprefix."jf_content where reference_id=".$osc_id." and reference_table='vm_product' and reference_field='product_desc' and language_id = ".$lang_id.";");
  228. $res = -1;
  229. if ($result && $row=mysql_fetch_row($result)) {
  230. $res = mysql_query("update ".$dbprefix."jf_content set reference_id=".$osc_id." ,language_id='".$lang_id."',published=1,value=\"".$desc_value."\",modified='".date( "Y-m-d H:i:s" )."',original_value='".md5($original_name)."' where id=".$row[0].";");
  231. } else {
  232. $res = mysql_query("insert into ".$dbprefix."jf_content(language_id,reference_id,reference_table,reference_field,value,original_value,modified_by,modified,published) values (".$lang_id.",".$osc_id.",'vm_product','product_desc',\"".$desc_value."\",'".md5($original_name)."',70,'".date( "Y-m-d H:i:s" )."',1);");
  233. }
  234. }
  235. }
  236. function _update_product_short_desc_by_lang($lang_id, $lang_str, $osc_id, $tiny_product) {
  237. $res = 0;
  238. global $dbprefix;
  239. $original_name = ($tiny_product['short_description']);
  240. $desc_value = ($tiny_product['short_description:' . $lang_str]);
  241. if($desc_value=='' and $original_name!=''){
  242. $desc_value = $original_name;
  243. } elseif ($original_name=='' and $desc_value!='') {
  244. $original_name = $desc_value;
  245. }
  246. if ($original_name!='') {
  247. $desc_value = str_replace('"','\"',$desc_value);
  248. $result = mysql_query("select id from ".$dbprefix."jf_content where reference_id=".$osc_id." and reference_table='vm_product' and reference_field='product_s_desc' and language_id = ".$lang_id.";");
  249. $temp = -1;
  250. if ($result && $row=mysql_fetch_row($result)) {
  251. $temp = mysql_query("update ".$dbprefix."jf_content set reference_id=".$osc_id.",language_id='".$lang_id."',published=1,value=\"".$desc_value."\",modified='".date( "Y-m-d H:i:s" )."',original_value='".md5($original_name)."' where id=".$row[0].";");
  252. } else {
  253. $temp = mysql_query("insert into ".$dbprefix."jf_content(language_id,reference_id,reference_table,reference_field,value,original_value,modified_by,modified,published) values (".$lang_id.",".$osc_id.",'vm_product','product_s_desc',\"".$desc_value."\",'".md5($original_name)."',70,'".date( "Y-m-d H:i:s" )."',1);");
  254. }
  255. }
  256. }
  257. function set_product($tiny_product){
  258. $rpc_error = 0;
  259. global $dbprefix;
  260. $prod = Array(
  261. 'vendor_id'=>0
  262. );
  263. $result = mysql_query("select vendor_id, vendor_currency from ".$dbprefix."vm_vendor;");
  264. if ($result && $row=mysql_fetch_row($result)) {
  265. $prod['vendor_id']=$row[0];
  266. $prod['vendor_currency']=$row[1];
  267. }
  268. $result=mysql_query("select shopper_group_id from ".$dbprefix."vm_shopper_group where vendor_id=".$vendor_id." and shopper_group_name='-default-';");
  269. if ($result && $row=mysql_fetch_row($result))
  270. $prod['shopper_group']=$row[0];
  271. if ( $tiny_product['esale_joomla_id']) {
  272. $result = mysql_query("select count(*) from ".$dbprefix."vm_product where product_id=". $tiny_product['esale_joomla_id']);
  273. $row = mysql_fetch_row($result);
  274. if (! $row[0] )
  275. $tiny_product['esale_joomla_id'] = 0;
  276. }
  277. if (! $tiny_product['esale_joomla_id']) {
  278. $res = mysql_query("select shopper_group_id,vendor_id from ".$dbprefix."vm_shopper_group where `default` = 1");
  279. $shoperid = mysql_fetch_array($res);
  280. $shopper_group = $shoperid['shopper_group_id'];
  281. $vendorid = $shoperid['vendor_id'];
  282. $res = mysql_query("select vendor_currency from ".$dbprefix."vm_vendor where vendor_id = ".$vendorid);
  283. $vcurrency = mysql_fetch_array($res);
  284. $vendor_currency = $vcurrency['vendor_currency'];
  285. mysql_query("insert into ".$dbprefix."vm_product () values ()");
  286. $osc_id = mysql_insert_id();
  287. mysql_query("insert into ".$dbprefix."vm_product_price (product_id, product_price, product_currency, product_price_vdate, product_price_edate, shopper_group_id) values (".$osc_id.", ".$tiny_product['price'].", '".$vendor_currency."', 0, 0, ".$shopper_group.");");
  288. mysql_query("insert into ".$dbprefix."vm_product_category_xref (product_id, category_id) values (".$osc_id.", ".$tiny_product['category_id'].");");
  289. foreach ($tiny_product['tax_rate_id'] as $taxes=>$values) {
  290. mysql_query("insert into ".$dbprefix."vm_product_tax (product_id, tax_rate_id) values (".$osc_id.", ".$values["id"].");");
  291. }
  292. } else {
  293. $osc_id = $tiny_product['esale_joomla_id'];
  294. }
  295. $query = "update ".$dbprefix."vm_product set ".
  296. "product_in_stock=".$tiny_product['quantity'].",".
  297. "product_weight=".$tiny_product['weight'].",".
  298. "product_sku='".mysql_escape_string($tiny_product['model'])."',".
  299. "product_name='".mysql_escape_string( ($tiny_product['name']))."',".
  300. "vendor_id=".$prod['vendor_id'].",".
  301. "product_desc='".mysql_escape_string( ($tiny_product['description']))."', ".
  302. "product_unit='".mysql_escape_string( ($tiny_product['product_unit']))."', ".
  303. "product_publish='Y',".
  304. "product_packaging=".$tiny_product['product_packaging_qty'].",".
  305. // "product_packaging_type='".$tiny_product['product_packaging_type']."',".
  306. "product_s_desc='".mysql_escape_string( (substr($tiny_product['short_description'],0,200)))."' ".
  307. "where product_id=".$osc_id.";";
  308. $res = mysql_query($query);
  309. if (!$res) {
  310. $rpc_error = 1<<0;
  311. }
  312. // Replace or delete old values
  313. mysql_query("update ".$dbprefix."vm_product_price set product_price='".$tiny_product['price']."' where product_id=".$osc_id.";");
  314. mysql_query("update ".$dbprefix."vm_product_category_xref set category_id='".$tiny_product['category_id']."' where product_id=".$osc_id.";");
  315. mysql_query("delete from ".$dbprefix."vm_product_tax where product_id=".$osc_id.";");
  316. foreach ($tiny_product['tax_rate_id'] as $taxes=>$values) {
  317. mysql_query("insert into ".$dbprefix."vm_product_tax (product_id, tax_rate_id) values (".$osc_id.", ".$values["id"].");");
  318. }
  319. // Retrieve FRENCH language:
  320. $res = mysql_query("select id from ".$dbprefix."languages where iso='fr';");
  321. $lang_fr_id = -1;
  322. $lang_fr_str = 'fr_FR';
  323. if ($res && $row=mysql_fetch_row($res)) {
  324. $lang_fr_id = $row[0];
  325. }
  326. // Retrieve ENGLISH language:
  327. $res = mysql_query("select id from ".$dbprefix."languages where iso='en';");
  328. $lang_en_id = -1;
  329. $lang_en_str = 'en_US';
  330. if ($res && $row=mysql_fetch_row($res)) {
  331. $lang_en_id = $row[0];
  332. }
  333. // Product name:
  334. _update_product_name_by_lang($lang_fr_id, $lang_fr_str, $osc_id, $tiny_product);
  335. _update_product_name_by_lang($lang_en_id, $lang_en_str, $osc_id, $tiny_product);
  336. // Product long description:
  337. _update_product_long_desc_by_lang($lang_fr_id, $lang_fr_str, $osc_id, $tiny_product);
  338. _update_product_long_desc_by_lang($lang_en_id, $lang_en_str, $osc_id, $tiny_product);
  339. // Product short description:
  340. _update_product_short_desc_by_lang($lang_fr_id, $lang_fr_str, $osc_id, $tiny_product);
  341. _update_product_short_desc_by_lang($lang_en_id, $lang_en_str, $osc_id, $tiny_product);
  342. if ($tiny_product['haspic']==1) {
  343. $filename = tempnam('components/com_virtuemart/shop_image/product/', 'tiny_');
  344. $extension = strrchr($tiny_product['code'].'.jpg','.');
  345. $filename.=$extension;
  346. //$filename='components/com_virtuemart/shop_image/product/tiny_'.$tiny_product['code'].'.jpg';
  347. $hd = fopen($filename, "w");
  348. fwrite($hd, base64_decode($tiny_product['picture']));
  349. fclose($hd);
  350. $short = strrchr($filename,'/');
  351. $short = substr($short, 1, strlen($short));
  352. mysql_query("update ".$dbprefix."vm_product set product_full_image='".$short."' where product_id=".$osc_id.";");
  353. mysql_query("update ".$dbprefix."vm_product set product_thumb_image='".$short."' where product_id=".$osc_id.";");
  354. unlink(substr($filename,0,strlen($filename)-4));
  355. /*$newxsize = PSHOP_IMG_WIDTH;
  356. if (!$newxsize) {
  357. $newxsize=90;
  358. }
  359. $newysize = PSHOP_IMG_HEIGHT;
  360. if (!$newysize) {
  361. $newysize=60;
  362. }
  363. $extension=strtolower($extension);
  364. if (in_array($extension, array('.jpeg', '.jpe', '.jpg', '.gif', '.png'))) {
  365. if (in_array($extension, array('.jpeg', '.jpe', '.jpg'))) {
  366. $extension='.jpeg';
  367. }
  368. $thumb=tempnam('components/com_virtuemart/shop_image/product/', 'tiny_').$extension;
  369. $load='imagecreatefrom'.substr($extension,1,strlen($extension)-1);
  370. $save='image'.substr($extension,1,strlen($extension)-1);
  371. $tmp_img=$load($filename);
  372. $imgsize = getimagesize($filename);
  373. if ($imgsize[0] > $newxsize || $imgsize[1] > $newysize) {
  374. if ($imgsize[0]*$newysize > $imgsize[1]*$newxsize) {
  375. $ratio=$imgsize[0]/$newxsize;
  376. } else {
  377. $ratio=$imgsize[1]/$newysize;
  378. }
  379. } else {
  380. $ratio=1;
  381. }
  382. $tn=imagecreatetruecolor (floor($imgsize[0]/$ratio),floor($imgsize[1]/$ratio));
  383. imagecopyresized($tn,$tmp_img,0,0,0,0,floor($imgsize[0]/$ratio),floor($imgsize[1]/$ratio),$imgsize[0],$imgsize[1]);
  384. $short=strrchr($thumb,'/');
  385. $short=substr($short,1,strlen($short));
  386. $save($tn, $thumb);
  387. mysql_query("update ".$dbprefix."vm_product set product_thumb_image='".$short."' where product_id=".$osc_id.";");
  388. }*/
  389. }
  390. $rpc_msg = "";
  391. if ($rpc_error > 0) {
  392. $rpc_msg = "Error in sync script";
  393. };
  394. $resp = new xmlrpcresp(new xmlrpcval($osc_id, "int"), $rpc_error, $rpc_msg);
  395. //$resp = new xmlrpcresp(new xmlrpcval($osc_id, "int"));
  396. return $resp;
  397. }
  398. function get_saleorders($last_so) {
  399. global $dbprefix;
  400. $saleorders=array();
  401. /*$result=mysql_query(
  402. "SELECT
  403. o.`order_id`, c.`last_name`, c.`address_1`, c.`city`, c.`zip`, c.`state`,
  404. c.`country`, c.`phone_1`, c.`user_email`, d.`last_name` , d.`address_1` ,
  405. d.`city`, d.`zip`, d.`state`, d.`country`, o.`cdate`,
  406. c.title, c.first_name, d.title, d.first_name,
  407. d.user_id, c.user_id, o.customer_note
  408. FROM ".
  409. $dbprefix."vm_orders as o,".
  410. $dbprefix."vm_user_info as c, ".
  411. $dbprefix."vm_user_info as d
  412. where
  413. o.order_id>".$last_so." and
  414. o.user_id=c.user_id and
  415. (c.address_type_name is NULL or c.address_type_name='-default-') and
  416. o.user_info_id=d.user_info_id;
  417. ");*/
  418. $result=mysql_query(
  419. "SELECT
  420. o.`order_id`, c.`last_name`, c.`address_1`, c.`city`, c.`zip`, c.`state`,
  421. cn.`country_2_code` as `country`, c.`phone_1`, c.`user_email`, d.`last_name` , d.`address_1` ,
  422. d.`city`, d.`zip`, d.`state`, d.`country`, o.`cdate`,
  423. c.title, c.first_name, d.title, d.first_name,
  424. d.user_id, c.user_id, o.customer_note,
  425. o.order_discount,o.order_shipping,o.order_shipping_tax FROM ".
  426. $dbprefix."vm_orders as o,".
  427. $dbprefix."vm_user_info as c, ".
  428. $dbprefix."vm_country as cn, ".
  429. $dbprefix."vm_user_info as d
  430. where
  431. o.order_id>".$last_so." and
  432. o.user_id=c.user_id and
  433. (c.address_type_name is NULL or c.address_type_name='-default-') and
  434. ( cn.country_3_code = c.country) and
  435. o.user_info_id=d.user_info_id;
  436. ");
  437. if ($result) while ($row=mysql_fetch_row($result)) {
  438. $orderlines = array();
  439. $resultb = mysql_query("select product_id, product_quantity, product_item_price from ".$dbprefix."vm_order_item where order_id=".$row[0].";");
  440. if ($resultb) while ($rowb=mysql_fetch_row($resultb)) {
  441. $orderlines[] = new xmlrpcval( array(
  442. "product_id" => new xmlrpcval($rowb[0], "int"),
  443. "product_qty" => new xmlrpcval($rowb[1], "int"),
  444. "price" => new xmlrpcval($rowb[2], "string")
  445. ), "struct");
  446. }
  447. $fee = $row[23];
  448. $shipping_fee = $row[24];
  449. if ($shipping_fee!=0){
  450. $orderlines[] = new xmlrpcval( array(
  451. "product_is_shipping" => new xmlrpcval(True, "boolean"),
  452. "product_name" => new xmlrpcval("Shipping fees", "string"),
  453. "product_qty" => new xmlrpcval(0, "int"),
  454. "price" => new xmlrpcval($shipping_fee, "string")
  455. ), "struct");
  456. }
  457. $other_fee = (-1 * $fee);
  458. if ($other_fee != 0){
  459. $orderlines[] = new xmlrpcval( array(
  460. "product_name" => new xmlrpcval("Other fees", "string"),
  461. "product_qty" => new xmlrpcval(0, "int"),
  462. "price" => new xmlrpcval($other_fee, "string")
  463. ), "struct");
  464. }
  465. //$orderlines[]=new xmlrpcval( array(
  466. // "product_name" => new xmlrpcval("Shipping tax", "string"),
  467. // "product_qty" => new xmlrpcval(0, "int"),
  468. // "price" => new xmlrpcval($row[25], "string")
  469. // ), "struct");
  470. $saleorders[] = new xmlrpcval( array(
  471. "id" => new xmlrpcval( $row[0], "int"),
  472. "note" => new xmlrpcval( $row[22], "string"),
  473. "lines" => new xmlrpcval( $orderlines, "array"),
  474. "address" => new xmlrpcval( array(
  475. "name" => new xmlrpcval($row[16]." ".$row[1]." ".$row[17], "string"),
  476. "address" => new xmlrpcval($row[2], "string"),
  477. "city" => new xmlrpcval(urlencode($row[3]), "string"),
  478. "zip" => new xmlrpcval($row[4], "string"),
  479. "state" => new xmlrpcval($row[5], "string"),
  480. "country" => new xmlrpcval($row[6], "string"),
  481. "phone" => new xmlrpcval($row[7], "string"),
  482. "email" => new xmlrpcval($row[8], "string"),
  483. "esale_id" => new xmlrpcval($row[20], "string")
  484. ), "struct"),
  485. "delivery" => new xmlrpcval( array(
  486. "name" => new xmlrpcval($row[18]." ".$row[9]." ".$row[19], "string"),
  487. "address" => new xmlrpcval($row[10], "string"),
  488. "city" => new xmlrpcval(urlencode($row[11]), "string"),
  489. "zip" => new xmlrpcval($row[12], "string"),
  490. "state" => new xmlrpcval($row[13], "string"),
  491. "country" => new xmlrpcval($row[14], "string"),
  492. "email" => new xmlrpcval($row[8], "string"),
  493. "esale_id" => new xmlrpcval($row[21], "string")
  494. ), "struct"),
  495. "billing" =>new xmlrpcval( array(
  496. "name" => new xmlrpcval($row[16]." ".$row[1]." ".$row[17], "string"),
  497. "address" => new xmlrpcval($row[2], "string"),
  498. "city" => new xmlrpcval(urlencode($row[3]), "string"),
  499. "zip" => new xmlrpcval($row[4], "string"),
  500. "state" => new xmlrpcval($row[5], "string"),
  501. "country" => new xmlrpcval($row[6], "string"),
  502. "email" => new xmlrpcval($row[8], "string"),
  503. "esale_id" => new xmlrpcval($row[20], "string")
  504. ), "struct"),
  505. "date" => new xmlrpcval( date('YmdHis',$row[15]), "date")
  506. ), "struct");
  507. }
  508. $resp = new xmlrpcresp(new xmlrpcval($saleorders, "array"));
  509. return $resp;
  510. }
  511. function process_order($order_id) {
  512. global $dbprefix;
  513. mysql_query("update ".$dbprefix."vm_orders set order_status='C' where order_id=".$order_id.";");
  514. mysql_query("update ".$dbprefix."vm_order_item set oerder_status='C' where order_id=".$order_id.";");
  515. return new xmlrpcresp(new xmlrpcval(0, "int"));
  516. }
  517. function close_order($order_id) {
  518. global $dbprefix;
  519. mysql_query("update ".$dbprefix."vm_orders set order_status='S' where order_id=".$order_id.";");
  520. mysql_query("update ".$dbprefix."vm_order_item set oerder_status='S' where order_id=".$order_id.";");
  521. return new xmlrpcresp(new xmlrpcval(0, "int"));
  522. }
  523. $server = new xmlrpc_server( array(
  524. "get_taxes" => array(
  525. "function" => "get_taxes",
  526. "signature" => array(array($xmlrpcArray))
  527. ),
  528. "get_languages" => array(
  529. "function" => "get_languages",
  530. "signature" => array(array($xmlrpcArray))
  531. ),
  532. "get_categories" => array(
  533. "function" => "get_categories",
  534. "signature" => array(array($xmlrpcArray))
  535. ),
  536. "get_saleorders" => array(
  537. "function" => "get_saleorders",
  538. "signature" => array(array($xmlrpcArray, $xmlrpcInt))
  539. ),
  540. "set_product" => array(
  541. "function" => "set_product",
  542. "signature" => array(array($xmlrpcInt, $xmlrpcStruct))
  543. ),
  544. "set_category" => array(
  545. "function" => "set_category",
  546. "signature" => array(array($xmlrpcInt, $xmlrpcStruct))
  547. ),
  548. "set_tax" => array(
  549. "function" => "set_tax",
  550. "signature" => array(array($xmlrpcInt, $xmlrpcStruct))
  551. ),
  552. "set_product_stock" => array(
  553. "function" => "set_product_stock",
  554. "signature" => array(array($xmlrpcInt, $xmlrpcStruct))
  555. ),
  556. "process_order" => array(
  557. "function" => "process_order",
  558. "signature" => array(array($xmlrpcInt, $xmlrpcInt))
  559. ),
  560. "delete_products" => array(
  561. "function" => "delete_products",
  562. "signature" => array(array($xmlrpcArray))
  563. ),
  564. "delete_product_categories" => array(
  565. "function" => "delete_product_categories",
  566. "signature" => array(array($xmlrpcArray))
  567. ),
  568. "close_order" => array(
  569. "function" => "close_order",
  570. "signature" => array(array($xmlrpcInt, $xmlrpcInt))
  571. ),
  572. "unlink_products"=>array(
  573. "function" => "unlink_products",
  574. "signature" => array(array($xmlrpcInt, $xmlrpcArray))
  575. )
  576. ), false);
  577. $server->functions_parameters_type= 'phpvals';
  578. $server->service();
  579. ?>