2 /***************************************************************
 
   3 * $Id: shopimport_csv.php,v 1.2 2004/06/30 08:31:35 hli Exp $
 
   4 *Author: Holger Lindemann
 
   5 *Copyright: (c) 2004 Lx-System
 
   7 *eMail: info@lx-system.de
 
  10 ***************************************************************/
 
  11 $login=$_GET["login"];
 
  12 require_once "DB.php";
 
  13 require_once "conf$login.php";
 
  14 $LAND=array("Germany"=>"D");
 
  15 $db=DB::connect($SHOPdns);
 
  16 if (!$db) dbFehler("",$db->getDebugInfo());
 
  17 if (DB::isError($db)) {
 
  18         dbFehler("",$db->getDebugInfo());
 
  19         die ($db->getDebugInfo());
 
  22 function createCategory($name,$maingroup) {
 
  24         $newID=uniqid(rand());
 
  25         $sql="insert into categories (categories_image,parent_id,date_added) values ('$newID',$maingroup,now())";
 
  27         $sql="select * from categories where categories_image = '$newID'";
 
  28         $rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
 
  29         $id=$rs[0]["categories_id"];
 
  30         $sql="update categories set categories_image = null where categories_id=$id";
 
  33         foreach ($langs as $LANG) {
 
  34                 $sql="insert into categories_description (categories_id,language_id,categories_name) values ($id,$LANG,'$name')";
 
  38         return ($rc)?$id:false;
 
  40 function getCategory($name) {
 
  42         if (empty($name)) $name="Default";
 
  43         $tmp=split("!",$name);
 
  48                 $sql="select D.*,C.parent_id from categories C left join categories_description D on C.categories_id=D.categories_id where categories_name like '".$tmp[$i]."' and C.parent_id=$maingroup";
 
  49                 $rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
 
  50                 if ($rs[0]["categories_id"]) {
 
  51                         $maingroup=$rs[0]["categories_id"];
 
  52                         echo $maingroup.":".$rs[0]["categories_name"]." ";
 
  57         } while ($rs and $found and $i<count($tmp));
 
  58         for (;$i<count($tmp); $i++) {
 
  59                 $maingroup=createCategory($tmp[$i],$maingroup);
 
  63 function insartikel($data) {
 
  64 global $db,$header,$tax,$defLang;
 
  65         $newID=uniqid(rand());
 
  66         $sql="insert into products (products_model,products_image) values ('".$data[array_search("products_model")]."','$newID')";
 
  68         $sql="select * from products where products_image='$newID'";
 
  69         $rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
 
  70         $sql="update products set products_image=null,products_status=1 where products_id=".$rs[0]["products_id"];
 
  72         $sql="insert into products_description (products_id,language_id,products_name) values (".$rs[0]["products_id"].",$defLang,' ')";
 
  74         $sql="insert into products_to_categories (products_id,categories_id) values (".$rs[0]["products_id"].",".$data["categories_id"].")";
 
  76         echo " <b>insert</b> ";
 
  77         updartikel($data,$rs[0]["products_id"]);
 
  79 function updartikel($data,$id) {
 
  80 global $db,$header,$tax,$defLang;
 
  81         $sql="update products set products_price=%01.2f,products_weight=%01.2f,products_tax_class_id=%d,products_last_modified=now(),products_quantity=%d   where products_id=%d";
 
  82         $sql=sprintf($sql,$data[array_search("products_price",$header)],$data[array_search("products_weight",$header)],$tax[$data[array_search("products_tax",$header)]],$id,$data[array_search("products_quantity",$header)]);
 
  84         $sql="update products_description set products_name='%s',products_description='%s' where products_id=%d and language_id=$defLang";
 
  85         $sql=sprintf($sql,$data[array_search("products_name",$header)],$data[array_search("products_description",$header)],$id);
 
  87         $sql="update products_to_categories set categories_id=".$data[array_search("categories_id",$header)]." where products_id=$id";
 
  89         echo "(".$id." ".$data[array_search("products_name",$header)].")+++<br>";
 
  91 function chkartikel($data) {
 
  92 global $db,$header,$tax;
 
  93         $sql="select * from products P left join products_description D on P.products_id=D.products_id left join products_to_categories C on P.products_id=C.products_id where  products_model like '".$data[array_search("products_model",$header)]."' and language_id=2";
 
  94         $rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
 
  96                          if ($rs[0]["products_price"]<>$data[array_search("products_price",$header)])   { updartikel($data,$rs[0]["products_id"]); }
 
  97                 else if ($rs[0]["products_weight"]<>$data[array_search("products_weight",$header)])     { updartikel($data,$rs[0]["products_id"]); }
 
  98                 else if ($rs[0]["products_name"]<>$data[array_search("products_name",$header)])         { updartikel($data,$rs[0]["products_id"]); }
 
  99                 else if ($rs[0]["products_description"]<>$data[array_search("products_description",$header)])   { updartikel($data,$rs[0]["products_id"]); }
 
 100                 else if ($rs[0]["products_tax_class_id"]<>$tax[$data[array_search("products_tax",$header)]])    { updartikel($data,$rs[0]["products_id"]); }
 
 101                 else if ($rs[0]["categories_id"]<>$data[array_search("categories_id",$header)])         { updartikel($data,$rs[0]["products_id"]); }
 
 102                 else { echo "(".$rs[0]["products_id"]." ".$rs[0]["products_name"].")...<br>"; };
 
 108 $sql="select languages_id from languages";
 
 109 $rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
 
 111         foreach ($rs as $zeile) {
 
 112                 $langs[]=$zeile["languages_id"];
 
 117 $sql="select * from languages L left join configuration C on L.code=C.configuration_value where  configuration_key = 'DEFAULT_LANGUAGE'";
 
 118 $rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
 
 120         $defLang=$rs[0]["languages_id"];
 
 124 $sql="select * from tax_rates";
 
 125 $rs=$db->getAll($sql,DB_FETCHMODE_ASSOC);
 
 127         foreach ($rs as $zeile) {
 
 128                 $tax[$zeile["tax_rate"]]=$zeile["tax_class_id"];
 
 134 if ($_FILES["csv"]["name"] || ($_POST["nofile"] && file_exists($SHOPdir)) ) {
 
 135         if ($_FILES["csv"]["tmp_name"]) {
 
 136                 move_uploaded_file($_FILES["csv"]["tmp_name"],$SHOPdir);
 
 138         $f=fopen($SHOPdir,"r");
 
 139         $header=fgetcsv($f,1000,";");
 
 140         $header[]="categories_id";
 
 141         $data=fgetcsv($f,1000,";");
 
 143                 $catId=getCategory($data[array_search("categories_name",$header)]);
 
 146                 $data=fgetcsv($f,1000,";");
 
 149         echo "<a href='trans.php'>zurück</a>";
 
 154                 <title>Datenaustausch ERP-osCommerce</title>
 
 159 <h1>Artikelimport aus csv-Datei in osCommerce</h1><br>
 
 160 <form name="csv" action="shopimport_csv.php" enctype="multipart/form-data" method="post">
 
 161         <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="500000">
 
 162         <input type="checkbox" name="nofile" value="1">Auf dem Server vorhandene Daten importieren<br>
 
 163         Datenfile für Import <input type="file" name="csv"><br>
 
 164         <input type="submit" name="ok" value="ok">
 
 167 <a href="trans.php">zurück</a>