Neue Anmeldung berücksichtigt
authorHolger Lindemann <hli@lx-system.de>
Fri, 29 Feb 2008 13:27:05 +0000 (13:27 +0000)
committerHolger Lindemann <hli@lx-system.de>
Fri, 29 Feb 2008 13:27:05 +0000 (13:27 +0000)
lxo-import/addressB.php
lxo-import/contactB.php
lxo-import/import_lib.php

index dcb5adb..a6a6c19 100644 (file)
@@ -12,17 +12,34 @@ Web: http://lx-system.de
 
 */
 
-if ($_GET["login"]) {
-       $login=$_GET["login"];
-} else {
-       $login=$_POST["login"];
+require ("import_lib.php");
+
+if (!$_SESSION["db"]) {
+       $conffile="../config/authentication.pl";
+       if (!is_file($conffile)) {
+               ende(4);
+       }
+}
+
+if (!anmelden()) ende(5);
+
+if ($_POST["ok"]=="Hilfe") {
+       echo "Importfelder:<br>";
+       echo "Feldname => Bedeutung<br>";
+       foreach($address as $key=>$val) {
+               echo "$key => $val<br>";
+       }
+       exit(0);
 };
+
 if ($_POST["ok"]) {
 
 $nun=time();
 
-require ("import_lib.php");
-$db=new myDB($login);
+
+/* get DB instance */
+$db=$_SESSION["db"]; //new myDB($login);
+
 $crm=checkCRM();
 
 function ende($nr) {
@@ -31,14 +48,6 @@ function ende($nr) {
        exit(1);
 }
 
-if ($_POST["ok"]=="Hilfe") {
-       echo "Importfelder:<br>";
-       echo "Feldname => Bedeutung<br>";
-       foreach($address as $key=>$val) {
-               echo "$key => $val<br>";
-       }
-       exit(0);
-};
 clearstatcache ();
 //print_r($_FILES);
 $test=$_POST["test"];
@@ -57,16 +66,13 @@ if (!empty($_FILES["Datei"]["name"])) {
 if (!$file) ende (2);
 
 $trenner=($_POST["trenner"])?$_POST["trenner"]:",";
-//echo "../users/$login.conf";
-if (!file_exists("../users/$login.conf")) ende(3);
 
 if (!file_exists("$file.csv")) ende(5);
 
-$db=new myDB($login);
 
 if (!$db->chkcol($file)) ende(6);
 
-$employee=chkUsr($login);
+$employee=chkUsr($_SESSION["employee"]);
 if (!$employee) ende(4);
 
 $kunde_fld = array_keys($address);
@@ -184,6 +190,7 @@ echo $j." $file importiert.\n";
 <p class="listtop">Adressimport f&uuml;r die ERP<p>
 <br>
 <form name="import" method="post" enctype="multipart/form-data" action="addressB.php">
+<!--form name="import" method="post"  action="addressB.php"-->
 <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
 <input type="hidden" name="login" value="<?= $login ?>">
 <table>
index 8c8e53a..e07bedb 100644 (file)
@@ -11,18 +11,23 @@ Email: hli@lx-system.de
 Web: http://lx-system.de
 
 */
-if ($_GET["login"]) {
-       $login=$_GET["login"];
-} else {
-       $login=$_POST["login"];
-};
-
+if (!$_SESSION["db"]) {
+       $conffile="../config/authentication.pl";
+       if (!is_file($conffile)) {
+               ende(4);
+       }
+}
 require ("import_lib.php");
-$db=new myDB($login);
+
+if (!anmelden()) ende(5);
+
+/* get DB instance */
+$db=$_SESSION["db"]; //new myDB($login);
+
+
 $crm=checkCRM();
 
 if ($_POST["ok"]) {
-       $login=$_POST["login"];
        $test=$_POST["test"];
 
        if ($crm) {
@@ -36,7 +41,6 @@ if ($_POST["ok"]) {
 
        function ende($nr) {
                echo "Abbruch: $nr\n";
-               echo "Aufruf: addressS.php [login customer|vendor] [test] | [felder]\n";
                exit($nr);
        }
        if ($_POST["ok"]=="Hilfe") {
@@ -68,26 +72,24 @@ if (!$file) ende (2);
 
 if (!file_exists($file."_contact.csv")) ende(5);
 
-if (!file_exists("../users/$login.conf")) ende(3);
-
+$prenumber=$_POST["prenumber"];
 
-$employee=chkUsr($login);
+$employee=chkUsr($_SESSION["employee"]);
 if (!$employee) ende(4);
 
 if (!$db->chkcol($file)) ende(6);
 
 $f=fopen($file."_contact.csv","r");
-$zeile=fgets($f,1200);
-$infld=split($trenner,strtolower($zeile));
-$first=true;
+$zeile=fgetcsv($f,2000,$trenner);
 
+$first=true;
 
-foreach ($infld as $fld) {
-       $fld = trim(strtr($fld,array("\""=>"","'"=>"")));
+foreach ($zeile as $fld) {
+       $fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
        $in_fld[]=$fld;
 }
 $j=0;
-$zeile=fgetcsv($f,1200,$trenner);
+$zeile=fgetcsv($f,2000,$trenner);
 while (!feof($f)){
        $i=-1;
        $firma="";
@@ -98,33 +100,57 @@ while (!feof($f)){
        $vals=" values (";
        foreach($zeile as $data) {
                $i++;
-               if ($in_fld[$i]=="firma") { 
-                       $firma=addslashes(trim($data)); 
-                       continue;
-               };
                if (!in_array($in_fld[$i],$kunde_fld)) {
                        continue;
                }
                $data=addslashes(trim($data));
+               if ($in_fld[$i]=="firma" && $data) { 
+                       $data=suchFirma($file,$data);
+                       if ($data) {
+                               $id=$data["cp_cv_id"];
+                       }
+                       continue;
+               } else if ($in_fld[$i]=="firma") {
+                       continue;
+               } ;
                if ($in_fld[$i]=="cp_cv_id" && $data) {
                        $data=chkKdId($data);
-                       if ($data) $firma="";
-                       if (!$id) $id = $data;
+                       if ($data) {
+                               $id = $data;
+                       };
                        continue;
-               } 
+               } else  if($in_fld[$i]=="cp_cv_id") {
+                       continue;
+               }
                if ($in_fld[$i]==$file."number" && $data) {
-                       $tmp=getFirma($data,$file);
-                       if ($tmp) $firma="";
-                       if ($id<>$tmp) $id=$tmp;
+                       if (!$id) {
+                               $tmp=getFirma($data,$file);
+                               if ($tmp) {
+                                       $id=$tmp;
+                               }
+                       }
+                       continue;
+               } else if  ($in_fld[$i]==$file."number") {
                        continue;
-               } 
+               }
+               if ($in_fld[$i]=="cp_id" && $data) {
+                       $tmp=chkContact($data);
+                       if ($tmp) {
+                               $keys.="cp_id,";
+                               $vals.="$tmp,";
+                       } 
+                       continue;
+               } else if ($in_fld[$i]=="cp_id") {
+                       continue;
+               }
+
                $keys.=$in_fld[$i].",";
                
                if ($data==false or empty($data) or !$data) {
                         $vals.="null,";
                 } else {
                        if (in_array($in_fld[$i],array("cp_fax","cp_phone1","cp_phone2"))) {
-                               $data="0".$data;
+                               $data=$prenumber.$data;
                        } else if ($in_fld[$i]=="cp_country" && $data) {
                                $data=mkland($data);
                        }
@@ -138,13 +164,7 @@ while (!feof($f)){
                $zeile=fgetcsv($f,1200,$trenner);
                continue;
        }
-       if ($firma) {
-               $data=suchFirma($file,$firma);
-               if ($data) {
-                       $vals.=$data["cp_cv_id"].",";
-                       $keys.="cp_cv_id,";
-               }
-       } else if ($id) {
+       if ($id) {
                        $vals.=$id.",";
                        $keys.="cp_cv_id,";
        }
@@ -174,11 +194,11 @@ echo $j." $file importiert.\n";} else {
 <p class="listtop">Kontakt-Adressimport f&uuml;r die ERP</p>
 <form name="import" method="post" enctype="multipart/form-data" action="contactB.php">
 <input type="hidden" name="MAX_FILE_SIZE" value="300000">
-<input type="hidden" name="login" value="<?= $login ?>">
 <table>
 <tr><td></td><td><input type="submit" name="ok" value="Hilfe"></td></tr>
 <tr><td>Zieltabelle</td><td><input type="radio" name="ziel" value="customer" checked>customer <input type="radio" name="ziel" value="vendor">vendor</td></tr>
 <tr><td>Trennzeichen</td><td><input type="text" size="2" maxlength="1" name="trenner" value=";"></td></tr>
+<tr><td>Telefonvorwahl</td><td><input type="text" size="4" maxlength="1" name="prenumber" value=""></td></tr>
 <tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
 <tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
 <tr><td></td><td><input type="submit" name="ok" value="Import"></td></tr>
index a383e0a..9678472 100644 (file)
@@ -123,9 +123,7 @@ $contactscrm = array(
        "cp_privatemail" => "private eMail",
        "cp_notes" => "Bemerkungen",
        "cp_stichwort1" => "Stichwort(e)",
-       "katalog" => "Katalog",
-       "inhaber" => "Inhaber",
-       "contact_id" => "Kontakt ID"
+       "cp_id" => "Kontakt ID"
        );
 
 $contacts = array(
@@ -146,9 +144,7 @@ $contacts = array(
        "cp_privatphone" => "Privattelefon",
        "cp_privatemail" => "private eMail",
        "cp_homepage" => "Homepage",
-       "katalog" => "Katalog",
-       "inhaber" => "Inhaber",
-       "contact_id" => "Kontakt ID"
+       "cp_id" => "Kontakt ID"
        );
 
 function checkCRM() {
@@ -205,7 +201,16 @@ global $db,$file,$test;
                return $data;
        }
 }
-
+function chkContact($id) {
+global $db;
+       $sql="select * from contact where cp_id = $id";
+       $rs=$db->getAll($sql);
+       if ($rs[0]["cp_id"]==$id) {
+               return true;
+       } else {
+               return false;
+       }
+}
 function getKdRefId($data) {
 // gibt es die Nummer schon?
 global $db,$file,$test;