Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. <?php
  2.  
  3. @ob_flush();
  4. @flush();
  5. @ini_set('max_execution_time', 1800); //300 seconds = 5 minutes
  6. set_time_limit(0);
  7.  
  8. //error_reporting(E_ALL);
  9. //ini_set('display_errors', '1');
  10.  
  11. //======Setari
  12. $server_name="localhost";
  13. $db_name = "beauxprod";
  14. $db_user = "root";
  15. $db_pass = "";
  16. mysql_connect($server_name, $db_user, $db_pass);
  17. mysql_select_db($db_name)
  18. or die(mysql_error());
  19. $db2_name="beaux";
  20. $db2_user = "root";
  21. $db2_pass = "mataigay";
  22. //======SF SETARI
  23.  
  24.  
  25. $nrpoza=0;
  26. $result = mysql_query("SELECT * FROM products order by id ASC");
  27. if (!$result)
  28. {
  29. die('Could not query:' . mysql_error());
  30. }
  31. else
  32. while ($row = mysql_fetch_array( $result ))
  33. {
  34. $visible=$row[visible];
  35. //if ($visible==1)
  36. {
  37. $k++;
  38. if($k<=3)
  39. {
  40. $id=$row[id];
  41. $title=$row[title];
  42. $catid=$row[catid];
  43. $subcatid=$row[subcatid];
  44. $tricatid=$row[tricatid];
  45.  
  46. //echo $title.' '.$id.' ';
  47. $desc=$row[desc];
  48. $video=$row[video];
  49. $price=$row[price];
  50. //echo '<script>alert("'.$price.'");</script>';
  51. $stock=$row[stock];
  52. //if (!is_numeric($stock))
  53. //$stock=999;
  54. if($stock>0)
  55. {
  56. }
  57. else
  58. {
  59. $stock=0;
  60. }
  61.  
  62. //if($stock>0)
  63. {
  64.  
  65. mysql_connect($server_name, $db2_user, $db2_pass);
  66. mysql_select_db($db2_name)
  67. or die(mysql_error());
  68.  
  69. if (mysql_num_rows(mysql_query("SELECT * FROM ps_product WHERE id_product='$id'")))
  70.  
  71. {
  72. //updatam stocku`
  73. mysql_query("UPDATE ps_product SET quantity='$stock' WHERE id_product='$id'") or die(mysql_error());
  74. }
  75. else
  76. {
  77. $desc=strip_tags($desc);
  78. $desc=htmlspecialchars_decode($desc);
  79. $video=htmlspecialchars_decode($video);
  80.  
  81. //shortdesc
  82. $o=0;
  83. $dot='';
  84. $shortdesc='';
  85. while(($dot<>'.') && ($o<250))
  86. {
  87. $dot=$desc[$o];
  88. $shortdesc=$shortdesc.$dot;
  89. $o++;
  90. }
  91. //sf shortdesc
  92.  
  93.  
  94. //$title=utf8_encode($title);
  95. $tags='';
  96. $title2=str_replace(',',' ',$title);
  97. $taguri=explode(' ',$title2);
  98. $tags=$taguri[0];
  99. for($o=1;$o<=count($taguri)-1;$o++)
  100. {
  101. if(strlen($taguri[$o])>=2)
  102. $tags=$tags.','.$taguri[$o];
  103. }
  104. //echo $title2.' '.$tags.'<br>';
  105.  
  106.  
  107.  
  108. //$desc='';
  109. $price=trim($price);
  110. $price=str_replace(',','.',$price);
  111.  
  112.  
  113. $sku=strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'),'',$title));
  114.  
  115.  
  116. $iduri=$catid.','.$subcatid.','.$tricatid;
  117. //echo $iduri;
  118.  
  119. $iduri=explode(',',$iduri);
  120. $m=count($iduri)-1;
  121. //echo $m;
  122. $l=0;
  123. for($i=0;$i<=$m;$i++)
  124. {
  125. $ok=1;
  126. for($j=0;$j<=$i-1;$j++)
  127. if ($iduri[$i]==$iduri[$j])
  128. $ok=0;
  129. if ($iduri[$i]=='none')
  130. $ok=0;
  131.  
  132. if ($ok==1)
  133. {
  134. $l++;
  135. $v[$l]=$iduri[$i];
  136. //echo $v[$l];
  137. }
  138. }
  139.  
  140. $m=$l;
  141. $v[1]='1';
  142. $iduri='1';
  143. for($i=2;$i<=$m;$i++)
  144. $iduri=$iduri.','.$v[$i];
  145.  
  146. //$iduri='1,'.$iduri;
  147. //echo $iduri;
  148.  
  149. /*
  150.  
  151. echo $title;
  152. echo '<br>';
  153. echo $desc;
  154. echo '<br>';
  155. echo $price;
  156. echo '<br>';
  157. echo $stock;
  158. echo '<br>';
  159. echo $catid;
  160. echo '<br>';
  161. echo $subcatid;
  162. echo '<br>';
  163. echo $tricatid;
  164. echo '<br>';
  165. echo $iduri;
  166. echo '<br>';
  167. echo '<br>';
  168. echo '<br>';
  169.  
  170. */
  171. //inceput imagine
  172. mysql_connect($server_name, $db_user, $db_pass);
  173. mysql_select_db($db_name)
  174. or die(mysql_error());
  175.  
  176.  
  177.  
  178. $photos='';
  179. $i=0;
  180. $result2 = mysql_query("SELECT * FROM photos WHERE productid='$id' ");
  181. mysql_connect($server_name, $db2_user, $db2_pass);
  182. mysql_select_db($db2_name)
  183. or die(mysql_error());
  184.  
  185. if (!$result2)
  186. {
  187. die('Could not query:' . mysql_error());
  188. }
  189. else
  190. while ($row2 = mysql_fetch_array( $result2 ))
  191. {
  192. $i++;
  193. //$nrpoza++;
  194. $link=$row2[link];
  195. $cover=0;
  196. if($i==1)
  197. $cover=1;
  198. mysql_query("INSERT INTO ps_image (`id_image`,`id_product`,`position`,`cover`) VALUES ('','$id','$i','$cover') ") or die(mysql_error());
  199. $result3=mysql_query("SELECT * FROM ps_image WHERE id_product='$id' and position='$i'");
  200. $row3=mysql_fetch_array($result3);
  201. $nrpoza=$row3[id_image];
  202. $nume=$id.'-'.$nrpoza.'.jpg';
  203. $file=dirname(__FILE__) ."\\"."tmp"."\\".$nume;
  204. $poza=$link;
  205. //echo $file;
  206.  
  207. if (!is_file($file))
  208. {
  209. $fp = fopen ($file, "w+");//This is the file where we save the information
  210.  
  211. $ch = curl_init($poza);
  212. curl_setopt($ch, CURLOPT_URL, $poza);
  213. curl_setopt($ch, CURLOPT_FILE, $fp);
  214. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  215. //curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
  216. curl_exec($ch);
  217. fclose($fp);
  218.  
  219.  
  220. for($j=1;$j<=3;$j++)
  221. {
  222. mysql_query("INSERT INTO ps_image_lang (`id_image`,`id_lang`,`legend`) VALUES ('$nrpoza','$j','$title') ") or die(mysql_error());
  223. }
  224.  
  225. }
  226. }
  227.  
  228. /*echo $photos;
  229. */
  230.  
  231. //$desc='testdesc';
  232. $desc=str_replace(";","",$desc);
  233. $shortdesc=str_replace(";","",$shortdesc);
  234. $title=str_replace(";","",$title);
  235. $metatitle='';
  236. for($i=0;$i<=119;$i++)
  237. $metatitle=$metatitle.$title[$i];
  238. $metadesc='';
  239. for($i=0;$i<=119;$i++)
  240. $metadesc=$metadesc.$desc[$i];
  241. //$metadesc=utf8_encode($metadesc);
  242. //echo $desc;
  243. $price=$price;
  244. //$desc=$desc.'<br>'.$video;
  245. $data=$id.';1;'.$title.';'.$iduri.';'.$price.';1;'.$stock.';'.$shortdesc.';'.$desc.';'.$tags.';'.$metatitle.';'.$tags.';'.$metadesc.';'.$photos.'pulenci';
  246.  
  247.  
  248.  
  249. mysql_query("INSERT INTO ps_product (`id_product`,`id_supplier`,`id_manufacturer`,`id_tax`,`id_category_default`,`id_color_default`,`on_sale`,`ean13`,`ecotax`,`quantity`,`price`,`out_of_stock`,`active`,`indexed`,`date_add`,`date_upd`) VALUES ('$id','0','0','0','1','0','1','','0','$stock','$price','2','1','1',now(),now()) ") or die(mysql_error());
  250.  
  251. //".addslashes($title)."','".addslashes($cat)."','".addslashes($subcat)."','".addslashes($tricat)."','$catid','$subcatid','$tricatid','".addslashes($desc)."','".addslashes($video)."','".$url."','$visible
  252. for($i=1;$i<=$m;$i++)
  253. {
  254. //echo $i.' '.$v[$i].'<br>';
  255. $idcat=$v[$i];
  256. mysql_query("INSERT INTO ps_category_product (`id_category`,`id_product`,`position`) VALUES ('$idcat','$id','') ") or die(mysql_error());
  257.  
  258. }
  259. for($j=1;$j<=3;$j++)
  260. {
  261. mysql_query("INSERT INTO ps_product_lang (`id_product`,`id_lang`,`description`,`description_short`,`link_rewrite`,`meta_description`,`meta_keywords`,`meta_title`,`name`,`available_now`,`available_later`) VALUES ('$id','$j','".mysql_real_escape_string($desc)."','".mysql_real_escape_string($shortdesc)."','','".mysql_real_escape_string($metadesc)."','$tags','".mysql_real_escape_string($title)."','".mysql_real_escape_string($title)."','','') ") or die(mysql_error());
  262.  
  263. }
  264.  
  265.  
  266.  
  267. }
  268.  
  269.  
  270. }
  271. }
  272. }
  273. }
  274.  
  275. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement