oximex.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxImex extends oxBase
00007 {
00017     public function export( $iStart, $iLines, $sFilepath)
00018     {
00019         if ( !$this->getViewName()) {
00020             return false;
00021         } elseif ( $this->getViewName() == "lexware") {
00022             return $this->exportLexwareArticles( $iStart, $iLines, $sFilepath);
00023         }
00024 
00025         $myConfig = $this->getConfig();
00026         $oDB      = oxDb::getDb();
00027 
00028         $sWhere = "";
00029 
00030         $sSearch = $this->_sCoreTbl . "__oxshopid";
00031         if ( isset( $this->$sSearch)) {
00032             $sWhere = " where oxshopid = '".$myConfig->getShopId()."' ";
00033         }
00034 
00035         $sSelect = "select count(oxid) from ".$this->getViewName().$sWhere;
00036         $iSize = $oDB->getOne( $sSelect);
00037         if ( $iStart < $iSize) {
00038             // if first, delete the file
00039             $fp = fopen( $sFilepath, "a");
00040 
00041             $sSelect = "select * from ".$this->getViewName().$sWhere;
00042             $rs = $oDB->selectLimit( $sSelect, $iLines, $iStart);
00043             // #573 defining decimal separator
00044             $blDecReplace = false;
00045             $sDecimalSeparator = $myConfig->getConfigParam( 'sDecimalSeparator' );
00046             if ( $sDecimalSeparator != ".") {
00047                 $blDecReplace = true;
00048             }
00049 
00050             while (!$rs->EOF) {
00051                 $sLine = "\"".$this->_sCoreTbl."\"";
00052 
00053                 foreach ( $rs->fields as $iNum => $field) {
00054                     $sLine .= $myConfig->getConfigParam( 'sCSVSign' );
00055 
00056                     if ( !is_numeric( $field)) {
00057                         $sLine .= "\"".$this->interFormSimple($field)."\"";
00058                     } else {
00059                         if ( $blDecReplace) {
00060                             $field = str_replace( ".", $sDecimalSeparator, $field );
00061                         }
00062                         $sLine .= $field;
00063                     }
00064                 }
00065                 $sLine .= "\r\n";
00066 
00067                 fputs( $fp, $sLine);
00068 
00069                 $rs->moveNext();
00070             }
00071 
00072             fclose( $fp);
00073 
00074             return true;
00075         }
00076 
00077         return false;
00078     }
00079 
00089     public function exportUsers( $iStart, $iLines, $sFilepath)
00090     {
00091         $myConfig  = $this->getConfig();
00092 
00093         $aGroups = oxSession::getVar("_agroups");
00094 
00095         if ( !$this->getViewName() || !$aGroups) {
00096             return false;
00097         }
00098 
00099         $oDB = oxDb::getDb();
00100 
00101         $sWhere = "";
00102         $sInGroup = "";
00103         $blSep = false;
00104         foreach ($aGroups as $sGroupId => $iAct) {
00105             if ($blSep) {
00106                 $sInGroup .= ", ";
00107             }
00108             $sInGroup .= "'".$sGroupId."'";
00109             $blSep = true;
00110         }
00111 
00112         $sSelect  = "select count(".$this->getViewName().".oxid) from ".$this->getViewName()." ";
00113         $sSelect .= "left join oxobject2group on ".$this->getViewName().".oxid=oxobject2group.oxobjectid ";
00114         $sSelect .= "where oxobject2group.oxgroupsid in ($sInGroup) ";
00115         $sSearch = $this->getViewName() . "__oxshopid";
00116         if ( isset( $this->$sSearch)) {
00117             $sSelect .= $sWhere = "and ".$this->getViewName().".oxshopid = '".$myConfig->getShopId()."' ";
00118         }
00119 
00120         $iSize = $oDB->getOne( $sSelect);
00121         if ( $iStart < $iSize) {   // #387A creating object to fetch field information
00122             $oObj = oxNew( "oxbase" );
00123             $oObj->init($this->getViewName());
00124 
00125             // if first, delete the file
00126             $fp = fopen( $sFilepath, "a");
00127 
00128             $sSelect  = "select * from ".$this->getViewName()." ";
00129             $sSelect .= "left join oxobject2group on ".$this->getViewName().".oxid=oxobject2group.oxobjectid ";
00130             $sSelect .= "where oxobject2group.oxgroupsid in ($sInGroup) ".$sWhere;
00131             $rs = $oDB->selectLimit( $sSelect, $iLines, $iStart);
00132 
00133             // #573 defining decimal separator
00134             $blDecReplace = false;
00135             $sDecimalSeparator = $myConfig->getConfigParam( 'sDecimalSeparator' );
00136             if ( $sDecimalSeparator != "." ) {
00137                 $blDecReplace = true;
00138             }
00139 
00140             while (!$rs->EOF) {
00141                 $sLine = "\"".$this->getViewName()."\"";
00142 
00143                 foreach ( $rs->fields as $iNum => $field) {
00144                     $sLine .= $myConfig->getConfigParam( 'sCSVSign' );
00145 
00146                     if ( !is_numeric( $field)) {   // #387A
00147                         $oFieldObj = null;
00148                         $aIdx2FldName = $oObj->getIdx2FldName();
00149                         if ( isset($aIdx2FldName[$iNum])) {
00150                             $sFieldName = $aIdx2FldName[$iNum];
00151                             //#1096S full copy instead of reference.
00152                             $oFieldObj = clone $oObj->$sFieldName;
00153                         }
00154 
00155                         $sLine .= "\"".$this->interForm($field, $oFieldObj)."\"";
00156                     } else {
00157                         if ( $blDecReplace) {
00158                             $field = str_replace( ".", $sDecimalSeparator, $field );
00159                         }
00160                         $sLine .= $field;
00161                     }
00162                 }
00163                 $sLine .= "\r\n";
00164 
00165                 fputs( $fp, $sLine);
00166 
00167                 $rs->moveNext();
00168             }
00169 
00170             fclose( $fp);
00171 
00172             return true;
00173         }
00174 
00175         return false;
00176     }
00177 
00187     public function exportLexwareArticles( $iStart, $iLines, $sFilepath)
00188     {
00189         $myConfig = $this->getConfig();
00190         $oDB      = oxDb::getDb();
00191 
00192         $sArticleTable = getViewName('oxarticles');
00193 
00194         $sSelect = "select count(oxid) from $sArticleTable ";
00195         $iSize = $oDB->getOne( $sSelect);
00196 
00197         if ( $iStart < $iSize) {
00198             $fp = fopen( $sFilepath, "ab");
00199             if ( !$iStart) {   // first time, write header
00200                 fwrite( $fp, "\"Artikelnummer\";\"Bezeichnung\";\"Einheit\";\"Gewicht\";\"Matchcode\";\"Preis pro Anzahl\";\"Warengruppe\";\"Warengr.-Kurzbez.\";\"Warengr.-Steuersatz\";\"Warengr.-Konto Inland\";\"Warengr.-Konto Ausland\";\"Warengr.-Konto EG\";\"Preis 1\";\"Preis 2\";\"Preis 3\";\"Preis I/1\";\"Preis I/2\";\"Preis I/3\";\"Preis II/1\";\"Preis II/2\";\"Preis II/3\";\"Preis III/1\";\"Preis III/2\";\"Preis III/3\";\"B/N\";\"Lagerartikel\";\"EK 1\";\"Währung EK1\";\"EK 2\";\"Währung EK2\";\"Staffelmenge 1\";\"Staffelmenge 2\";\"Staffelmenge 3\";\"Lieferantennummer 1\";\"Lieferantennummer 2\";\"Bestellmenge Lf.1\";\"Bestellmenge Lf.2\";\"Bestellnr. Lf.1\";\"Bestellnr. Lf.2\";\"Lieferzeit Lf.1\";\"Lieferzeit Lf.2\";\"Lagerbestand\";\"Mindestbestand\";\"Lagerort\";\"Bestellte Menge\";\"Stückliste\";\"Internet\";\"Text\"\r\n");
00201             }
00202             $oldMode = $oDB->setFetchMode( ADODB_FETCH_ASSOC);
00203             $sSelect = "select * from $sArticleTable ";
00204             $rs = $oDB->selectLimit( $sSelect, $iLines, $iStart);
00205             $oDB->setFetchMode( $oldMode);
00206 
00207             while (!$rs->EOF) {
00208                 $oArticle = oxNew( "oxarticle" );
00209                 $blAdmin = $this->isAdmin();
00210                 // TODO: this workaround should be overworked
00211                 $this->setAdminMode( false );
00212                 $oArticle->load( $rs->fields['OXID']);
00213                 $this->setAdminMode( $blAdmin );
00214 
00215                 $sSelect = "select oxtitle from oxarticles where oxid = '".$oArticle->oxarticles__oxparentid->value."'";
00216                 $oTitle = $oDB->getOne( $sSelect);
00217                 if($oTitle != false && strlen ($oTitle)) {
00218                     $nTitle = $this->interForm($oTitle);
00219                 } else {
00220                     $nTitle = $this->interForm($oArticle->oxarticles__oxtitle->value);
00221                 }
00222 
00223 
00224                 $sToFile = $oArticle->oxarticles__oxartnum->value            // Artikelnummer
00225                 //.";".$this->interForm($oArticle->oxarticles__oxshortdesc->value." ".$oArticle->oxarticles__oxvarselect->value) // Bezeichnung
00226                 .";".$nTitle." ".$this->interForm($oArticle->oxarticles__oxvarselect->value) // Bezeichnung
00227                 .";"."Stueck"                        // Einheit
00228                 .";".$oArticle->oxarticles__oxweight->value                  // Gewicht
00229                 .";".$oArticle->oxarticles__oxartnum->value                  // Matchcode
00230                 .";"."1,000"                         // Preis pro Anzahl
00231                 .";"                                  // Warengruppe
00232                 .";"                                  // Warengr.-Kurzbez.
00233                 .";"                                 // Warengr.-Steuersatz
00234                 .";"                                  // Warengr.-Konto Inland
00235                 .";"                                  // Warengr.-Konto Ausland
00236                 .";"                                  // Warengr.-Konto EG
00237                 .";".number_format($oArticle->oxarticles__oxprice->value, 2, '.', '')  // Preis 1
00238                 .";"                                  // Preis 2
00239                 .";"                                 // Preis 3
00240                 .";"                                 // Preis I/1
00241                 .";"                                 // Preis I/2
00242                 .";"                                  // Preis I/3
00243                 .";"                                  // Preis II/1
00244                 .";"                                  // Preis II/2
00245                 .";"                                  // Preis II/3
00246                 .";"                                  // Preis III/1
00247                 .";"                                  // Preis III/2
00248                 .";"                                  // Preis III/3
00249                 .";"                           // B/N
00250                 .";"                           // Lagerartikel
00251                 //.";".number_format($oArticle->oxarticles__oxtprice->value, 2, '.', '')// EK 1
00252                 // #343 fix
00253                 .";".number_format($oArticle->oxarticles__oxbprice->value, 2, '.', '')// EK 1
00254                 .";"                           // Währung EK1
00255                 .";"                           // EK 2
00256                 .";"                           // Währung EK2
00257                 .";"                           // Staffelmenge 1
00258                 .";"                           // Staffelmenge 2
00259                 .";"                           // Staffelmenge 3
00260                 .";"                           // Lieferantennummer 1
00261                 .";"                           // Lieferantennummer 2
00262                 .";"                           // Bestellmenge Lf.1
00263                 .";"                           // Bestellmenge Lf.2
00264                 .";"                           // Bestellnr. Lf.1
00265                 .";"                           // Bestellnr. Lf.2
00266                 .";"                           // Lieferzeit Lf.1
00267                 .";"                           // Lieferzeit Lf.2
00268                 .";".$oArticle->oxarticles__oxstock->value           // Lagerbestand
00269                 .";"                           // Mindestbestand
00270                 .";"                           // Lagerort
00271                 .";"                           // Bestellte Menge
00272                 .";"                           // Stückliste
00273                 .";1"                              // Internet
00274                 .";".$this->interForm( $oArticle->oxarticles__oxshortdesc->value.$oArticle->oxarticles__oxlongdesc->value)// Text
00275                 .";";
00276                 $sToFile .= "\r\n";
00277 
00278                 fwrite( $fp, $sToFile);
00279                 $rs->moveNext();
00280             }
00281 
00282             fclose( $fp);
00283 
00284             return true;
00285         }
00286 
00287         return false;
00288 
00289     }
00290 
00298     function interFormSimple( $nValue)
00299     {
00300         $nValue = str_replace( "\r", "", $nValue);
00301         $nValue = str_replace( "\n", " ", $nValue);
00302         $nValue = str_replace( '"', '""', $nValue);
00303         return $nValue;
00304     }
00305 
00315     function interForm( $nValue, $oObj = null)
00316     {   // thnx to Volker Dörk for this function and his help here
00317 
00318         // #387A skipping conversion for fields where info must be passed in original format
00319         $aFieldTypesToSkip = array("text", "oxshortdesc", "oxlongdesc");
00320         $blSkipStrpTags = false;
00321         if ( $oObj != null) {
00322             // using object field "fldtype", to skip processing because usually
00323             // this type of field is used for HTML text
00324             //
00325             // you may change field to "fldname" and add to $aFieldTypesToSkip
00326             // "oxlongdesc" value to skip only longdesc field
00327             //
00328             if ( in_array($oObj->fldtype, $aFieldTypesToSkip)) {
00329                 $blSkipStripTags = true;
00330             } elseif ( in_array($oObj->fldname, $aFieldTypesToSkip)) {
00331                 $blSkipStripTags = true;
00332             }
00333         }
00334 
00335         //removing simple & (and not  &uuml; chars)
00336         //(not full just a simple check for existing customers for cases like Johnson&Johnson)
00337 
00338         if (strpos($nValue, "&") !== false && strpos($nValue, ";") == false) {
00339             $nValue = str_replace("&", "&amp;", $nValue);
00340         }
00341 
00342         if ( !$blSkipStripTags) {
00343             $nValue = strip_tags( $nValue);
00344         }
00345 
00346 
00347         $nValue = str_replace( "&nbsp;", " ", $nValue);
00348         $nValue = str_replace( "&auml;", "ä", $nValue);
00349         $nValue = str_replace( "&ouml;", "ö", $nValue);
00350         $nValue = str_replace( "&uuml;", "ü", $nValue);
00351         $nValue = str_replace( "&Auml;", "Ä", $nValue);
00352         $nValue = str_replace( "&Ouml;", "Ö", $nValue);
00353         $nValue = str_replace( "&Uuml;", "Ü", $nValue);
00354         $nValue = str_replace( "&szlig;", "ß", $nValue);
00355 
00356         // usually & symbol goes (or should go) like that:
00357         // "& text...", so we predict that this is a rule
00358         // and replace it with special HTML code
00359         $nValue = str_replace( "& ", "&amp; ", $nValue);
00360 
00361         /*
00362         $nValue = str_replace( "&nbsp;", " ", $nValue);
00363         $nValue = str_replace( "&auml;", "ae", $nValue);
00364         $nValue = str_replace( "&ouml;", "oe", $nValue);
00365         $nValue = str_replace( "&uuml;", "ue", $nValue);
00366         $nValue = str_replace( "&Auml;", "Ae", $nValue);
00367         $nValue = str_replace( "&Ouml;", "Oe", $nValue);
00368         $nValue = str_replace( "&Uuml;", "Ue", $nValue);
00369         $nValue = str_replace( "&szlig;", "sz", $nValue);
00370         $nValue = str_replace( "'", "", $nValue);
00371         $nValue = str_replace( "<", "", $nValue);
00372         $nValue = str_replace( ";", ",", $nValue);
00373         $nValue = str_replace( ">", "", $nValue);
00374         $nValue = str_replace( "&", "und", $nValue);
00375 
00376 
00377         $nValue = str_replace( "ü", "ue", $nValue);
00378         $nValue = str_replace( "ä", "ae", $nValue);
00379         $nValue = str_replace( "ö", "oe", $nValue);
00380         $nValue = str_replace( "Ü", "Ue", $nValue);
00381         $nValue = str_replace( "Ä", "Ae", $nValue);
00382         $nValue = str_replace( "Ö", "Oe", $nValue);
00383         */
00384         $nValue = str_replace( "\"", "'", $nValue);
00385         $nValue = str_replace( "(", "'", $nValue);
00386         $nValue = str_replace( ")", "'", $nValue);
00387         $nValue = str_replace( "\r\n", "", $nValue);
00388         $nValue = str_replace( "\n", "", $nValue);
00389 
00390         if ( !$blSkipStripTags) {
00391             $nValue = strip_tags ( $nValue );
00392         }
00393 
00394         return $nValue;
00395     }
00396 
00404     function internPrice( $nPrice)
00405     {  // thnx to Volker Dörk for this function and his help here
00406         $nPrice = $this->interForm($nPrice);
00407         $nPrice = number_format($nPrice, 2, '.', '');
00408         return $nPrice;
00409     }
00410 
00420     function import( $iStart, $iLines, $sFilepath)
00421     {
00422         $myConfig  = $this->getConfig();
00423         $blContinue = true;
00424 
00425         $fp     = fopen( $sFilepath, "r");
00426         $iEnd   = $iStart+$iLines;
00427         $aData  = null;
00428 
00429         //array of tables whitch were updated
00430         $aProcTables = oxSession::getVar("_aProcTables");
00431         if ( !$aProcTables) {
00432             $aProcTables = array();
00433         }
00434 
00435         // #573 defining decimal separator
00436         $blDecReplace = false;
00437         $sDecimalSeparator = $myConfig->getConfigParam( 'sDecimalSeparator' );
00438         if ( $sDecimalSeparator != "." ) {
00439             $blDecReplace = true;
00440         }
00441 
00442         for ( $i = 0; $i<=$iEnd; $i++) {
00443             $aData = $this->_oxFGetCsv( $fp, 40960, $myConfig->getConfigParam( 'sCSVSign' ) );
00444 
00445             if ( $aData && $i >= $iStart) {   // import
00446 
00447                 // read table description if needed
00448                 $sTable = $aData[0];
00449                 $aProcTables[] = $sTable;
00450                 $this->init( $sTable);
00451                 // remove table from line
00452                 $aData = array_splice( $aData, 1, count($aData)-1);
00453                 foreach ($aData as $key => $value) {
00454                     if ( $value == "''" || $value == "" || !$value) {
00455                         $value = null;
00456                     }
00457 
00458                     // #573 - fixing import
00459                     $sKey = $this->_aIdx2FldName[$key];
00460                     if ( $blDecReplace && $this->$sKey->fldtype == "double") {
00461                         $value = str_replace( $sDecimalSeparator, ".", $value );
00462                     }
00463 
00464                     $aData[$key] = trim($value);
00465                 }
00466                 $this->assign($aData);
00467                 $this->save();
00468             }
00469 
00470             if ( feof( $fp)) {
00471                 $blContinue = false;
00472                 if ( $sTable == "oxcategories" || in_array( "oxcategories", $aProcTables)) {
00473                     $oDB = oxDb::getDb();
00474                     $oDB->execute( "update oxcategories set oxhidden = '0' where oxhidden='' ");
00475                 }
00476                 $aProcTables = array();
00477                 break;
00478             }
00479         }
00480         oxSession::setVar( "_aProcTables", $aProcTables);
00481         fclose( $fp);
00482 
00483         return $blContinue;
00484     }
00485 
00494     function exportLexwareOrders( $iFromOrderNr = null, $iToOrderNr = null)
00495     {
00496         // thnx to Volker Dörk for this function and his help here
00497         $myConfig = $this->getConfig();
00498 
00499         $sRet = "";
00500 
00501         $sNewLine = "\r\n";
00502 
00503         $oOrderlist = oxNew( "oxlist" );
00504         $oOrderlist->init( "oxorder" );
00505 
00506         $sSelect = "select * from oxorder where 1 ";
00507 
00508         if ( !empty( $iFromOrderNr)) {
00509             $sSelect .= "and oxordernr >= $iFromOrderNr ";
00510         }
00511         if ( !empty( $iToOrderNr)) {
00512             $sSelect .= "and oxordernr <= $iToOrderNr ";
00513         }
00514 
00515         $oOrderlist->selectString( $sSelect);
00516 
00517         if ( !$oOrderlist->count() ) {
00518             return null;
00519         }
00520 
00521         $sExport  = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>$sNewLine";
00522         $sExport .= "<Bestellliste>$sNewLine";
00523         $sRet .= $sExport;
00524 
00525         //foreach (array_keys( $oOrderlist) as $key) {
00526         foreach ($oOrderlist->arrayKeys() as $key) {
00527             $oOrder = $oOrderlist[$key];
00528 
00529             $oUser = oxNew( "oxuser" );
00530             $oUser->load( $oOrder->oxorder__oxuserid->value);
00531 
00532             $sExport  = "<Bestellung zurückgestellt=\"Nein\" bearbeitet=\"Nein\" übertragen=\"Nein\">$sNewLine";
00533             $sExport .= "<Standardwaehrung>978</Standardwaehrung>$sNewLine";
00534             $sExport .= "<Bestelldatum>$sNewLine";
00535             $sDBDate = $oOrder->oxorder__oxorderdate->value;
00536             $sExport .= "<Datum>".substr($sDBDate, 8, 2).".".substr($sDBDate, 5, 2).".".substr($sDBDate, 0, 4)."</Datum>$sNewLine";
00537             $sExport .= "<Zeit>".substr($oOrder->oxorder__oxorderdate->value, 11, 8)."</Zeit>$sNewLine";
00538             $sExport .= "</Bestelldatum>$sNewLine";
00539             $sExport .= "<Kunde>$sNewLine";
00540 
00541             $sExport .= "<Kundennummer>"./*$this->interForm($oUser->oxuser__oxcustnr->value).*/"</Kundennummer>$sNewLine";
00542             $sExport .= "<Firmenname>".$this->interForm($oOrder->oxorder__oxbillcompany->value)."</Firmenname>$sNewLine";
00543             $sExport .= "<Vorname>".$this->interForm($oOrder->oxorder__oxbillfname->value)."</Vorname>$sNewLine";
00544             $sExport .= "<Name>".$this->interForm($oOrder->oxorder__oxbilllname->value)."</Name>$sNewLine";
00545             $sExport .= "<Strasse>".$this->interForm($oOrder->oxorder__oxbillstreet->value)." ".$this->interForm($oOrder->oxorder__oxbillstreetnr->value)."</Strasse>$sNewLine";
00546             $sExport .= "<PLZ>".$this->interForm($oOrder->oxorder__oxbillzip->value)."</PLZ>$sNewLine";
00547             $sExport .= "<Ort>".$this->interForm($oOrder->oxorder__oxbillcity->value)."</Ort>$sNewLine";
00548             $sExport .= "<Bundesland>".""."</Bundesland>$sNewLine";
00549             $sExport .= "<Land>".$this->interForm($oOrder->oxorder__oxbillcountry->value)."</Land>$sNewLine";
00550             $sExport .= "<Email>".$this->interForm($oUser->oxuser__oxusername->value)."</Email>$sNewLine";
00551             $sExport .= "<Telefon>".$this->interForm($oOrder->oxorder__oxbillfon->value)."</Telefon>$sNewLine";
00552             $sExport .= "<Telefon2>".$this->interForm($oUser->oxuser__oxprivfon->value)."</Telefon2>$sNewLine";
00553             $sExport .= "<Fax>".$this->interForm($oOrder->oxorder__oxbillfax->value)."</Fax>$sNewLine";
00554 
00555             // lieferadresse
00556             if ( $oOrder->oxorder__oxdellname->value) {
00557                 $sDelComp   = $oOrder->oxorder__oxdelcompany->value;
00558                 $sDelfName  = $oOrder->oxorder__oxdelfname->value;
00559                 $sDellName  = $oOrder->oxorder__oxdellname->value;
00560                 $sDelStreet = $oOrder->oxorder__oxdelstreet->value;
00561                 $sDelZip    = $oOrder->oxorder__oxdelzip->value;
00562                 $sDelCity   = $oOrder->oxorder__oxdelcity->value;
00563                 $sDelCountry= $oOrder->oxorder__oxdelcountry->value;
00564             } else {
00565                 $sDelComp   = "";
00566                 $sDelfName  = "";
00567                 $sDellName  = "";
00568                 $sDelStreet = "";
00569                 $sDelZip    = "";
00570                 $sDelCity   = "";
00571                 $sDelCountry= "";
00572             }
00573 
00574             $sExport .= "<Lieferadresse>$sNewLine";
00575             $sExport .= "<Firmenname>".$this->interForm($sDelComp)."</Firmenname>$sNewLine";
00576             $sExport .= "<Vorname>".$this->interForm($sDelfName)."</Vorname>$sNewLine";
00577             $sExport .= "<Name>".$this->interForm($sDellName)."</Name>$sNewLine";
00578             $sExport .= "<Strasse>".$this->interForm($sDelStreet)."</Strasse>$sNewLine";
00579             $sExport .= "<PLZ>".$this->interForm($sDelZip)."</PLZ>$sNewLine";
00580             $sExport .= "<Ort>".$this->interForm($sDelCity)."</Ort>$sNewLine";
00581             $sExport .= "<Bundesland>".""."</Bundesland>$sNewLine";
00582             $sExport .= "<Land>".$this->interForm($sDelCountry)."</Land>$sNewLine";
00583             $sExport .= "</Lieferadresse>$sNewLine";
00584             $sExport .= "<Matchcode>".$this->interForm($oOrder->oxorder__oxbilllname->value).", ".$this->interForm($oOrder->oxorder__oxbillfname->value)."</Matchcode>$sNewLine";
00585 
00586             // ermitteln ob steuerbar oder nicht
00587             $sCountry = strtolower( $oUser->oxuser__oxcountryid->value);
00588             $aHomeCountry = $myConfig->getConfigParam( 'aHomeCountry' );
00589             if ( is_array( $aHomeCountry ) && in_array( $sCountry, $aHomeCountry ) ) {
00590                 $sSteuerbar = "ja";
00591             } else {
00592                 $sSteuerbar = "nein";
00593             }
00594 
00595             $sExport .= "<fSteuerbar>".$this->interForm($sSteuerbar)."</fSteuerbar>$sNewLine";
00596             $sExport .= "</Kunde>$sNewLine";
00597             $sExport .= "<Artikelliste>$sNewLine";
00598             $sRet .= $sExport;
00599 
00600             $dSumNetPrice = 0;
00601             $dSumBrutPrice = 0;
00602 
00603             /*
00604             if( $oOrder->oxorder__oxdelcost->value)
00605             {   // add virtual article for delivery costs
00606                 $oDelCost = oxNew( "oxorderarticle" );
00607                 $oDelCost->oxorderarticles__oxvat->setValue(0);
00608                 $oDelCost->oxorderarticles__oxnetprice->setValue($oOrder->oxorder__oxdelcost->value);
00609                 $oDelCost->oxorderarticles__oxamount->setValue(1);
00610                 $oDelCost->oxorderarticles__oxtitle->setValue("Versandkosten");
00611                 $oDelCost->oxorderarticles__oxbrutprice->setValue($oOrder->oxorder__oxdelcost->value);
00612                 $oOrder->oArticles['oxdelcostid'] = $oDelCost;
00613             }*/
00614 
00615             $oOrderArticles = $oOrder->getOrderArticles();
00616             foreach ($oOrderArticles->arrayKeys() as $key) {
00617                 $oOrderArt = $oOrderArticles->offsetGet($key);
00618 
00619                 $dVATSet = array_search( $oOrderArt->oxorderarticles__oxvat->value, $myConfig->getConfigParam( 'aLexwareVAT' ) );
00620                 $sExport  = "   <Artikel>$sNewLine";
00621                 //$sExport .= "   <Artikelzusatzinfo><Nettostaffelpreis>".$this->InternPrice( $oOrderArt->oxorderarticles__oxnetprice->value)."</Nettostaffelpreis></Artikelzusatzinfo>$sNewLine";
00622                 $sExport .= "   <Artikelzusatzinfo><Nettostaffelpreis></Nettostaffelpreis></Artikelzusatzinfo>$sNewLine";
00623                 $sExport .= "   <SteuersatzID>".$dVATSet."</SteuersatzID>$sNewLine";
00624                 $sExport .= "   <Steuersatz>".$this->internPrice($oOrderArt->oxorderarticles__oxvat->value/100)."</Steuersatz>$sNewLine";
00625                 $sExport .= "   <Artikelnummer>".$oOrderArt->oxorderarticles__oxartnum->value."</Artikelnummer>$sNewLine";
00626                 $sExport .= "   <Anzahl>".$oOrderArt->oxorderarticles__oxamount->value."</Anzahl>$sNewLine";
00627                 $sExport .= "   <Produktname>".$this->interForm( $oOrderArt->oxorderarticles__oxtitle->value);
00628                 if ( $oOrderArt->oxorderarticles__oxselvariant->value) {
00629                     $sExport .= "/".$oOrderArt->oxorderarticles__oxselvariant->value;
00630                 }
00631                 $sExport .= "   </Produktname>$sNewLine";
00632                 $sExport .= "   <Rabatt>0.00</Rabatt>$sNewLine";
00633                 $sExport .= "   <Preis>".$this->internPrice($oOrderArt->oxorderarticles__oxbrutprice->value/$oOrderArt->oxorderarticles__oxamount->value)."</Preis>$sNewLine";
00634                 $sExport .= "   </Artikel>$sNewLine";
00635                 $sRet .= $sExport;
00636 
00637                 $dSumNetPrice   += $oOrderArt->oxorderarticles__oxnetprice->value;
00638                 $dSumBrutPrice  += $oOrderArt->oxorderarticles__oxbrutprice->value;
00639             }
00640 
00641             $dDiscount = $oOrder->oxorder__oxvoucherdiscount->value + $oOrder->oxorder__oxdiscount->value;
00642             $sExport  = "<GesamtRabatt>".$this->internPrice( $dDiscount)."</GesamtRabatt>$sNewLine";
00643             $sExport .= "<GesamtNetto>".$this->internPrice($dSumNetPrice)."</GesamtNetto>$sNewLine";
00644             $sExport .= "<Lieferkosten>".$this->internPrice($oOrder->oxorder__oxdelcost->value)."</Lieferkosten>$sNewLine";
00645             $sExport .= "<Zahlungsartkosten>0.00</Zahlungsartkosten>$sNewLine";
00646             $sExport .= "<GesamtBrutto>".$this->internPrice($dSumBrutPrice)."</GesamtBrutto>$sNewLine";
00647 
00648             $oUserpayment = oxNew( "oxuserpayment" );
00649             $oUserpayment->load( $oOrder->oxorder__oxpaymentid->value);
00650             $sPayment = $oUserpayment->oxuserpayments__oxvalue->value;
00651             $sPayment = str_replace( "__", "", $sPayment);
00652             $sPayment = str_replace( "@@", ",", $sPayment);
00653 
00654             $oPayment = oxNew( "oxpayment" );
00655             $oPayment->load( $oOrder->oxorder__oxpaymenttype->value);
00656 
00657 
00658             $sExport .= "<Bemerkung>".strip_tags( $oOrder->oxorder__oxremark->value)."</Bemerkung>$sNewLine";
00659             $sRet .= $sExport;
00660 
00661             $sExport  = "</Artikelliste>$sNewLine";
00662 
00663             $sExport .= "<Zahlung>$sNewLine";
00664             $oPayment = oxNew( "oxpayment" );
00665             $oPayment->load( $oOrder->oxorder__oxpaymenttype->value);
00666 
00667             //print_r($oPayment);
00668 
00669             $sExport .= "<Art>".$oPayment->oxpayments__oxdesc->value."</Art>$sNewLine";
00670             $sExport .= "</Zahlung>$sNewLine";
00671 
00672             $sExport .= "</Bestellung>$sNewLine";
00673             $sRet .= $sExport;
00674 
00675 
00676             $oOrder->oxorder__oxexport->setValue(1);
00677             $oOrder->save();
00678 
00679         }
00680         $sExport = "</Bestellliste>\r";
00681         $sRet .= $sExport;
00682 
00683         return $sRet;
00684     }
00685 
00695     protected function _oxFGetCsv( $fp, $iMaxLen, $sSep )
00696     {
00697         $aRet = null;
00698 
00699         $iField = 0;
00700         $iQuote = 0;
00701 
00702         for ( $i=0; $i<$iMaxLen; $i++) {
00703             $c = fread( $fp, 1);
00704 
00705             if ( ($c === false || !isset( $c)) || (($c == "\n") && !$iQuote)) {
00706                 break;  // end
00707             } elseif ( $c == $sSep && !$iQuote) {
00708                 $iField++;
00709                 $aRet[$iField] = "";
00710                 continue;
00711             } elseif ( $c == "\"") {
00712                 if ( $iQuote) {
00713                     $iQuote--;
00714                 } else {
00715                     $iQuote++;
00716                 }
00717             }
00718             if ( !isset( $aRet[$iField])) {
00719                 $aRet[$iField] = "";
00720             }
00721             $aRet[$iField] .= $c;
00722         }
00723 
00724         if ( count( $aRet) > 1) {
00725             // remove " or '
00726             foreach ( $aRet as $key => $sField) {
00727                 $sField = trim($sField);
00728                 if ( $sField) {
00729                     if ( $sField[0] == "\"" || $sField[0] == "'") {
00730                         $sField = substr( $sField, 1);
00731                     }
00732 
00733                     $iLen = strlen( $sField) - 1;
00734                     if ( $sField[$iLen] == "\"" || $sField[$iLen] == "'") {
00735                         $sField = substr( $sField, 0, $iLen);
00736                     }
00737 
00738                     $aRet[$key] = $sField;
00739                 }
00740             }
00741             // process "" qoutes
00742             return str_replace('""', '"', $aRet);
00743         }
00744         else {
00745             return null;
00746         }
00747     }
00748 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5