~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to esale_joomla/connector/tinyerp-synchro.php

  • Committer: Launchpad Translations on behalf of openerp-commiter
  • Date: 2012-11-24 07:05:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5825.
  • Revision ID: launchpad_translations_on_behalf_of_openerp-commiter-20121124070522-2i7pnpw5hq4wuz4g
Launchpad automatic translations update.

Show diffs side-by-side

added added

removed removed

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