websync.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. require_once("util.php");
  3. require_once("NTK/NTK.php");
  4. ?>
  5. <html>
  6. <head>
  7. <title> Index </title>
  8. <?php
  9. echo getHead();
  10. ?>
  11. </head>
  12. <body>
  13. <?php
  14. $action = var_get_post("action", "");
  15. $main_box = new NTKVBox("main_box", 0, 0, False);
  16. // Toolbar
  17. $page = "websync";
  18. $printfile = "";
  19. include("Modules/toolbar.php");
  20. // if($action == "upload_0")
  21. // {
  22. // $main_box->add(new NTKLabel("", "Neue Produkte / Preise online stellen"), 200, 10, "font-style: bold; background-color: #dfe7f3;");
  23. //
  24. // $button_next = new NTKButton("button_next", "Weiter", "location.replace('websync.php?action=upload_1');");
  25. // $main_box->add($button_next);
  26. // }
  27. if($action == "upload_0")
  28. {
  29. require_once("DataBase/Priceset.php");
  30. require_once("DataBase/Customer.php");
  31. require_once("DataBase/Product.php");
  32. require_once("DataBase/Price.php");
  33. require_once("DataBase/Category.php");
  34. $priceset = new Priceset();
  35. $customer = new Customer();
  36. $product = new Product();
  37. $price = new Price();
  38. $category = new Category();
  39. $priceset->export("mysql_export/priceset.csv");
  40. $customer->export("mysql_export/customer.csv");
  41. $product->export("mysql_export/product.csv");
  42. $price->export("mysql_export/price.csv");
  43. $category->export("mysql_export/category.csv");
  44. // upload all db-files "mysql_export"
  45. $handle = popen("/var/www/ursprung/bin/upload.sh", "r");
  46. pclose($handle);
  47. $main_box->add(new NTKLabel("", "Schritt erfolgreich"), 200, -1, "color: #00ff00; background-color: #dfe7f3;");
  48. $button_next = new NTKButton("button_next", "Weiter", "location.replace('websync.php?action=upload_1');");
  49. $main_box->add($button_next, 500);
  50. }
  51. elseif($action == "upload_1")
  52. {
  53. $iframe = new NTKIFrame("upload_frame", "http://www.natuerlich-grobi.de/db_import.php", "width: 300px; height: 200px; background-color: #dfe7f3;");
  54. $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
  55. $main_box->add(new NTKLabel("", "Serverausgabe (dauert etwas):"), False, False, "font-style: bold; background-color: #dfe7f3;");
  56. $main_box->add($iframe, False, False, "background-color: #dfe7f3;");
  57. $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
  58. }
  59. elseif($action == "download_0")
  60. {
  61. $iframe = new NTKIFrame("download_frame", "http://www.natuerlich-grobi.de/db_export.php", "width: 300px; height: 200px; background-color: #dfe7f3;");
  62. // $iframe = new NTKIFrame("download_frame", "http://localhost/ursprung/db_export.php", "width: 300px; height: 200px; background-color: #dfe7f3;");
  63. $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
  64. $main_box->add(new NTKLabel("", "Serverausgabe (dauert etwas):"), False, False, "font-style: bold; background-color: #dfe7f3;");
  65. $main_box->add($iframe, False, False, "background-color: #dfe7f3;");
  66. $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
  67. $main_box->add(new NTKButton("button_next", "Weiter", "ntk_show_splash('bitte warten ...'); location.replace('websync.php?action=download_1');"), 500);
  68. }
  69. elseif($action == "download_1")
  70. {
  71. // download all db-files "mysql_import"
  72. $handle = popen("/var/www/ursprung/bin/download.sh", "r");
  73. pclose($handle);
  74. require_once("DataBase/Bill.php");
  75. require_once("DataBase/Bill_Product.php");
  76. require_once("DataBase/Bill_Import.php");
  77. require_once("DataBase/Bill_Product_Import.php");
  78. require_once("DataBase/Customer.php");
  79. require_once("DataBase/Tour.php");
  80. // import new bills
  81. $bill = new Bill();
  82. $bill_product = new Bill_Product();
  83. $bill_import = new Bill_Import();
  84. $bill_product_import = new Bill_Product_Import();
  85. $customer = new Customer();
  86. $tour = new Tour();
  87. if( $bill_import->import("mysql_import/bill.csv") == 0 &&
  88. $bill_product_import->import("mysql_import/bill_product.csv") == 0)
  89. {
  90. /* import bills from bill_import and products from bill_product_import */
  91. $bills = $bill_import->get();
  92. for($i = 0; $i < count($bills); $i++)
  93. {
  94. if(!$bill->hasTimestamp($bills[$i][6]))
  95. {
  96. $customer_data = $customer->get($bills[$i][1]);
  97. if(count($customer_data) == 0)
  98. {
  99. echo "Fehler: websync.php import bills from bill_import no customer data";
  100. continue;
  101. }
  102. $tour_data = $tour->get($customer_data[0][12]);
  103. $date = getdate(time());
  104. $new_bill_id = $bill->create("", array($bills[$i][1], $customer_data[0][12], $date['year']."-".$date['mon']."-".$date['mday'], $tour_data[0][2], -2, $bills[$i][6]));
  105. $bill_products = $bill_product_import->getByBillId($bills[$i][0]);
  106. for($j = 0; $j < count($bill_products); $j++)
  107. {
  108. $bill_product->create(array($new_bill_id, $bill_products[$j][2], $bill_products[$j][3], $bill_products[$j][4], 0, 0, 0));
  109. }
  110. }
  111. }
  112. $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
  113. $main_box->add(new NTKLabel("", "Fertig"), False, False, "font-style: bold; background-color: #dfe7f3;");
  114. $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
  115. }
  116. else
  117. {
  118. $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
  119. $main_box->add(new NTKLabel("", "neue Bestellungen laden schlug fehl.<br>In ein paar Minuten nochmal versuchen."), False, False, "color: #ff0000; font-style: bold; background-color: #dfe7f3;");
  120. $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
  121. }
  122. }
  123. else
  124. {
  125. // small Toolbar
  126. include("Modules/Websync/toolbar.php");
  127. // main content
  128. $main_box->add(new NTKLabel("", "Internet Synchronisation"), 200, -1, "background-color: #dfe7f3;");
  129. }
  130. // tools
  131. // $tool_box = new NTKVBox("online_box", 5, 0, False);
  132. //
  133. // $online_export_button = new NTKButton("", "online export", "window.open('http://www.natuerlich-grobi.de/db_export.php', 'Online Export', 'width=300,height=200');");
  134. // $tool_box->add($online_export_button, 60, 60, $style);
  135. //
  136. // $download_button = new NTKButton("", "download", "");
  137. // $tool_box->add($download_button, 60, 60, $style);
  138. //
  139. // $local_import_button = new NTKButton("", "Local Import", "location.replace('websync.php?action=local_import');");
  140. // $tool_box->add($local_import_button, 60, 60, $style);
  141. //
  142. // $local_sync_button = new NTKButton("", "Local Sync", "location.replace('websync.php?action=local_sync');");
  143. // $tool_box->add($local_sync_button, 60, 60, $style);
  144. //
  145. // $local_export_button = new NTKButton("", "Local Export", "location.replace('websync.php?action=local_export');");
  146. // $tool_box->add($local_export_button, 60, 60, $style);
  147. //
  148. // $upload_button = new NTKButton("", "upload", "");
  149. // $tool_box->add($upload_button, 60, 60, $style);
  150. //
  151. // $online_import_button = new NTKButton("", "online import", "window.open('http://www.natuerlich-grobi.de/db_import.php', 'Online Import', 'width=300,height=200');");
  152. // $tool_box->add($online_import_button, 60, 60, $style);
  153. //
  154. // // add toolbars
  155. // $main_box->add($tool_box, True, True);
  156. // if($action == "local_import")
  157. // {
  158. // require_once("DataBase_Net/Bill_Net.php");
  159. // require_once("DataBase_Net/Bill_Product_Net.php");
  160. //
  161. // $bill_net = new Bill_Net();
  162. // $bill_product_net = new Bill_Product_Net();
  163. //
  164. // $bill_net->import("mysql_import/bill.csv");
  165. // $bill_product_net->import("mysql_import/bill_product.csv");
  166. //
  167. // $main_box->add(new NTKLabel("", "Local Import erfolgreich"), 200, -1, "background-color: #dfe7f3;");
  168. // }
  169. // elseif($action == "local_sync")
  170. // {
  171. // include("Modules/Websync/PricesetSync.php");
  172. // include("Modules/Websync/CustomerSync.php");
  173. // include("Modules/Websync/ProductSync.php");
  174. // include("Modules/Websync/BillSync.php");
  175. //
  176. // $main_box->add(new NTKLabel("", "Local Sync erfolgreich"), 200, -1, "background-color: #dfe7f3;");
  177. // }
  178. // elseif($action == "local_export")
  179. // {
  180. // require_once("DataBase_Net/Priceset_Net.php");
  181. // require_once("DataBase_Net/Customer_Net.php");
  182. // require_once("DataBase_Net/Product_Net.php");
  183. // require_once("DataBase_Net/Price_Net.php");
  184. // require_once("DataBase_Net/Category_Net.php");
  185. //
  186. //
  187. // $priceset_net = new Priceset_Net();
  188. // $customer_net = new Customer_Net();
  189. // $product_net = new Product_Net();
  190. // $price_net = new Price_Net();
  191. // $category_net = new Category_Net();
  192. //
  193. // $priceset_net->export("mysql_export/priceset.csv");
  194. // $customer_net->export("mysql_export/customer.csv");
  195. // $product_net->export("mysql_export/product.csv");
  196. // $price_net->export("mysql_export/price.csv");
  197. // $category_net->export("mysql_export/category.csv");
  198. //
  199. // $main_box->add(new NTKLabel("", "Local Export erfolgreich"), 200, -1, "background-color: #dfe7f3;");
  200. // }
  201. echo $main_box->getHtml();
  202. ?>
  203. </body>
  204. </html>