Subversion-Projekte lars-tiefland.content-management

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?php
/**
 * XML_Serializer
 *
 * Creates XML documents from PHP data structures like arrays, objects or scalars.
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category   XML
 * @package    ImmoScout24Export
 * @author     Markus Niewerth <markus@weban.de>
 * @copyright  1997-2007 The PHP Group
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version    CVS: $Id: ImmoScout24Export.php,v 1.0 2007/09/27 9:45:30 markusniewerth Exp $
 * @link       http://pear.php.net/package/XML_Serializer
 * @see        XML_Unserializer
 */
        
require_once 'PEAR.php';

/**
 * XML_DTD_XmlValidator
 * 
 * Usage:
 * 
 * <code>
 * $validator = XML_DTD_XmlValidator;
 * // This will check if the xml is well formed
 * // and will validate it against its DTD
 * if (!$validator->isValid($dtd_file, $xml_file)) {
 *   die($validator->getMessage());
 * }
 * </code>
 * 
 * @package XML_DTD
 * @category XML
 * @author Tomas V.V.Cox <cox@idecnet.com> 
 * @copyright Copyright (c) 2003
 * @version $Id: XmlValidator.php,v 1.5 2004/05/17 19:51:45 schst Exp $
 * @access public 
*/

/**
 * Creates XML documents from PHP data structures like arrays, objects or scalars.
 *
 *
 * @category   XML
 * @package    ImmoScout24Export
 * @author     Markus Niewerth <markus@weban.de>
 * @copyright  1997-2007 The PHP Group
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version    CVS: $Id: ImmoScout24Export.php,v 1.0 2007/09/27 9:45:30 markusniewerth Exp $
 * @link       http://pear.php.net/package/XML_Serializer
 * @see        XML_Unserializer
 */


/**#@+
 * Error constants
 */
/**
 * Close XML parsed tags
 */
define('IMMOSCOUT24EXPORT_CLOSE_TAGS_AFTER', 0);
/**
 * Parameter declared to be numeric but the values are not
 */
define('IMMOSCOUT24EXPORT_CLOSE_TAGS_DIRECT', 1);
/**
 * Communication error
 */
define('IMMOSCOUT24EXPORT_CLOSE_TAGS_INTAG', 2);
/**#@-*/



class ImmoScout24Export extends PEAR {
        
        // the XML String
        var $XMLString;
        
        // To close all elements
        var $closeStack;
        
        // Last file path
        var $tempPath;
        
        // Last path where the file was put into it
        var $dirName;
        
        // enable debbuging in some cases?
        var $debugMode;
        
        var $_ftpConnection;
        
        var $_loginResult;
        
        var $dtdFile;
        
        /**
         * Constructor
         *
         * @param string $database
         * @return ImmoScout24Export
         */
        
        function ImmoScout24Export 
        (
                $database='gwg_gladbeck_de', 
                $debugMode=true, 
                $dtdFile='http://www.gwg-gladbeck.de/XML/xsi/is24immotransfer.xsd'
        ) {
                // Datenbankverbindung initialisieren
                // require_once "/web/apache/content-management/Online-Shop/connect2.php";
                
                // Init properties
                $this->XMLString        =       null;
                $this->closeStack       =       array();
                $this->debugMode        =       $debugMode;
                $this->dtdFile          =       $dtdFile;
        }
        
        /**
         * Returns the current API Version
         *
         * @return string
         */
        
        function apiVersion() {
                return '1.0';
        }
        
   /**
    * Build an xml declaration
    *
    * <code>
    * require_once 'ImmoScout24Export.php';
    *
    * // get an XML declaration:
    * $xmlDecl = ImmoScout24Export::getXMLDeclaration("1.0", "UTF-8", true);
    * </code>
    *
    * @access   public
    * @static
    * @param    string  $version     xml version
    * @param    string  $encoding    character encoding
    * @param    boolean $standAlone  document is standalone (or not)
    * @return   string  $decl xml declaration
    * @uses     ImmoScout24Export::attributesToString() to serialize the attributes of the XML declaration
    */
    function getXMLDeclaration($version = "1.0", $encoding = null, $standalone = null)
    {
        $attributes = array (
                "version" => $version,
        );
        // add encoding
        if ($encoding !== null) {
            $attributes["encoding"] = $encoding;
        }
        // add standalone, if specified
        if ($standalone !== null) {
            $attributes["standalone"] = $standalone ? "yes" : "no";
        }

        return sprintf("<?xml%s?>", ImmoScout24Export::attributesToString($attributes));
    }
        /**
         * Creates elements from attributes array
         *
         * @param array $attributes
         * @return string
         */
    function attributesToString($attributes=array()) {
        if (sizeof($attributes)<1) {
                return "";
        }
        $return = " ";
        foreach (array_keys($attributes) AS $element) {
                $return .= $element . "=\"".$attributes[$element]."\" ";
        }
        return $return;
    }
    
    /**
     * Parse an array with elements and attributes
     * NOTE: Only usable if constructed!
     * 
     * @param array $data
     * @return string
     */
        function parse2XML($data) {
                $string=null;
                $this->XMLString=null;
                foreach (array_keys($data) AS $root) {
                        if (is_array($data[$root])) {
                                
                                $string .= "<".$root." \r\n";
                                foreach (array_keys($data[$root]) AS $child){
                                        if ($child != 'close' && $child != 'Contents') {
                                                $string .= "\t".$child."=\"".utf8_decode($data[$root][$child])."\" \r\n";
                                        }
                                }
                                
                                switch($data[$root]['close'])
                                {
                                        case IMMOSCOUT24EXPORT_CLOSE_TAGS_INTAG:
                                                $string .= "/>\r\n";
                                                break;
                                        case  IMMOSCOUT24EXPORT_CLOSE_TAGS_NESTED:
                                                $this->closeStack[] = $root;
                                                $string .= ">\r\n";
                                                break;
                                        case  IMMOSCOUT24EXPORT_CLOSE_TAGS_NORMAL:
                                                $string .= ">\r\n".$data[$root]['Contents']."\r\n";
                                                $string .= "</$root>\r\n";
                                                break;
                                }                       
                        }
                }
                $this->closeStack = array_reverse($this->closeStack, TRUE);
                foreach ($this->closeStack AS $closer) {
                        $string .= "</$closer>\r\n";
                }
                // reffer to $string
                $this->XMLString = &$string;
                return $this->XMLString;
        }
        
        function XMLSave($fileName='ImmoScout24Export.xml' , $path='./') {
                if ($this->XMLString==null) {
                        return false;
                } else {
                        $XMLDeclaration = ImmoScout24Export::getXMLDeclaration("1.0", 'UTF-8');
                        $this->XMLString = $XMLDeclaration."\r\n".$this->XMLString;
                        // create a tempFile
                        $tmpFileName = tempnam ("/tmp", "XMLTMP");
                        // open it for reading
                        $myHandle        = fopen($tmpFileName, "w+");
                        // write contents to 
                        fwrite($myHandle, $this->XMLString);
                        // then close the handle
                        fclose($myHandle);
                        // define a prefix/suffix
                        $dateTime = date ("Y.M.D.h.s.i_");
                        // log the filename
                        $this->tmpPath = $path . $dateTime . $fileName;
                        
                        // Validate the XML File
                        // This will check if the xml is well formed
                        // and will validate it against its DTD
                        
                        if (!MyValidator::validate($tmpFileName,$this->dtdFile)) {
                                print( $this->debugMode ? '<pre>'.nl2br(htmlentities($validator->getMessage())) . '<br />'. htmlentities(file_get_contents($tmpFileName)). '</pre>' : '');
                                return false;
                        }

                        // and copy it to the given path
                        if (!copy($tmpFileName, $this->tmpPath)) {
                                $copyFalse = true;
                        }
                        // delete the tempFile
                        unlink($tmpFileName); 
                        
                        if ($copyFalse)
                                return false;
                }
                // debug question
                if ($this->debugMode)
                        return $this->XMLString;
                else
                        return true;
        }
        
        function ftp($username=null,$password=null,$hostname=null, $option='open', $destFile=null) {
                
                switch ($option) {
                        case 'open':
                                $this->_ftpConnection = ftp_connect($hostname);
                                // Login with username und password
                                $this->_loginResult = ftp_login($this->_ftpConnection, $username, $password); 
                                break;
                        case 'close':
                                if (is_resource($this->_ftpConnection))
                                        ftp_close($this->_ftpConnection); 
                                return true;
                                break;
                        case 'put':
                                // Datei hochladen
                                $uploadStatus = ftp_put($this->_ftpConnection, $destFile, $this->tmpPath, FTP_BINARY); 
                                // Upload überprüfen
                                if (!$uploadStatus) 
                                return false;
                            return true;
                                break;
                        case 'chdir':
                                // Datei hochladen
                                $chdirStatus = ftp_chdir($this->_ftpConnection, $destFile); 
                                // Upload überprüfen
                                if (!$chdirStatus) 
                                return false;
                            return true;
                                break;
                }

                // check the connection status
                if (!$this->_ftpConnection || !$this->_loginResult) { 
                        return false;
            } else {
                return true;
            }
        }
        
        /**
         * Export Data Array into XML Format
         *
         * @param array $data
         * @return string
         */
        
        function export($config) {
                $this->savePath = dirname($this->tmpPath);
                if 
                (
                        $this->ftp($config['username'],$config['password'],$config['hostname'], 'open') 
                        && 
                        $this->ftp(null,null,null, 'chdir', $config['path'])
                ) 
                {
                        if ($this->ftp(null,null,null, 'put', $config['file'])) {
                                $upload = true;
                        }
                        $this->ftp(null,null,null, 'close');
                        $connection = true;
                }
                
                if ($connection && $upload && $this->debugMode)
                return $this->XMLString;
            else 
                return false;
                
                if (!$connection && $this->debugMode)
                return "connection schlug fehl";
                
            return false;       
        }
                
}   
  
class MyValidator {
        
        function validate($xml,$schema) {
                $dom = new DomDocument(); 
                $dom->load($xml); 
                
                if ($dom->schemaValidate($schema)) { 
                        return true;
                } 
                else { 
                        return false;
                } 
        }
        
} 

/*

// ImmoScout24 Testdaten 
$tags = array(

                "IS24ImmobilienTransfer"                                        => array (
                     "close"                                                            =>      1,
             "xmlns"                                                            =>      "http://www.immobilienscout24.de/immobilientransfer",
             "xmlns:xsi"                                                =>      "http://www.w3.org/2001/XMLSchema-instance",
             "xsi:schemaLocation"                                       =>      "http://gwg.weban.de/XML/xsi/is24immotransfer.xsd",
             "ErstellerSoftware"                                        =>      "ImmoScout24Export",
             "ErstellerSoftwareVersion"                         =>      "1.0",
             "EmailBeiFehler"                                           =>      "markus@weban.de"
                ),
                "Anbieter"                                                                      => array ( 
                         "close"                                                                =>      1,
                         "ScoutKundenID"                                                =>      "30302"
                ),
                "WohnungMiete"                                                          => array (
                        "close"                                                                 =>      1,
                        "AnbieterObjektID"                                              =>      "0815",
                        "Ueberschrift"                                                  =>      "Schöne Wohnung" ,
                        "Importmodus"                                                   =>      "importieren" ,
                        "Wohnflaeche"                                                   =>      "100.00" ,
                        "Zimmer"                                                                =>      "4.00" ,
                        "Adressdruck"                                                   =>      "true" ,
                        "AnzahlBadezimmer"                                              =>      "2" ,
                        "AnzahlSchlafzimmer"                                    =>      "2" ,
                        "Aufzug"                                                                =>      "true" ,
                        "BalkonTerrasse"                                                =>      "true" ,
                        "Baujahr"                                                               =>      "1869" ,
                        "BetreutesWohnen"                                               =>      "true" ,
                        "Einbaukueche"                                                  =>      "true" ,
                        "Etage"                                                                 =>      "2" ,
                        "Etagenzahl"                                                    =>      "6" ,
                        "Foerderung"                                                    =>      "true" ,
                        "FreiAb"                                                                =>      "sofort" ,
                        "GartenBenutzung"                                               =>      "true" ,
                        "GruppierungsID"                                                =>      "1" ,
                        "Haustiere"                                                             =>      "nachVereinbarung" ,
                        "Heizungsart"                                                   =>      "Zentralheizung" ,
                        "Nutzflaeche"                                                   =>      "22" ,
                        "Objektzustand"                                                 =>      "Gepflegt" ,
                        "Parkplatz"                                                             =>      "true" ,
                        "Provision"                                                             =>      "3.8% zzg. 16%MSt" ,
                        "Rollstuhlgerecht"                                              =>      "true" ,
                        "StatusHP"                                                              =>      "aktiv" ,
                        "StatusIS24"                                                    =>      "aktiv" ,
                        "StatusVBM"                                                             =>      "aktiv" ,
                        "Waehrung"                                                              =>      "EUR" ,
                        "WohnungKategorie"                                              =>      "Etagenwohnung"
                ),
                
                "Adresse"                                                                       => array ( 
                         "close"                                                                =>      0,
                         "Strasse"                                                              =>      "Magazin Str.",
                         "Hausnummer"                                                   =>      "15-16",
                         "Ort"                                                                  =>      "Berlin",
                         "Postleitzahl"                                                 =>      "10179",
                         "Laenderkennzeichen"                                   =>      "DEU"
                ),      
                
                "Kontaktperson"                                                         => array ( 
                         "close"                                                                =>      0,
                         "Anrede"                                                               =>      "Herr",
                         "Vorname"                                                              =>      "Martin",
                         "Nachname"                                                             =>      "Mustermann",
                         "Strasse"                                                              =>      "Musterstr.",
                         "Hausnummer"                                                   =>      "22",
                         "Ort"                                                                  =>      "Musterhausen",
                         "Postleitzahl"                                                 =>      "12345",
                         "Laenderkennzeichen"                                   =>      "DEU",
                         "Telefon"                                                              =>      "0123-43627272872",
                         "Mobiltelefon"                                                 =>      "0179-534538729238",
                         "Telefax"                                                              =>      "0123-43276728298",
                         "Homepage"                                                             =>      "www.makler-wer.de",
                         "EMail"                                                                =>      "info@wer.de"
                ),
                
                "SonstigeAngaben"                                                       => array ( 
                         "close"                                                                =>      2,
                         "Contents"                                                             => "Sonstige Angaben"
                ),
                
                "MultimediaAnhang"                                                      => array ( 
                         "close"                                                                =>      0,
                         "AnhangArt"                                                    =>      "video",
                         "Titel"                                                                =>      "Video",
                         "Dateityp"                                                             =>      ".MPG",
                         "Abspieldauer"                                                 =>      "22",
                         "Dateiname"                                                    =>      "video1.mpg"
                ),
                "Mietpreise"                                                            => array ( 
                         "close"                                                                =>      0,
                         "Kaltmiete"                                                    =>      "1234.3",
                         "Heizkosten"                                                   =>      "200.30",
                         "HeizkostenInWarmmieteEnthalten"               =>      "true",
                         "Kaution"                                                              =>      "3 Moanatsmieten",
                         "Nebenkosten"                                                  =>      "250.33",
                         "StellplatzMiete"                                              =>      "160.00",
                         "Warmmiete"                                                    =>      "2223.56"
                )               

);
*/

/* 
        
        www.ImmobilienScout24.de:
        Kunden-Nr: Ihre Scout Kunden-ID.
        Schemadatei: is24immotransfer.xsd
        Übertragung: FTP, als Zip-Archiv, (Teilabgleich)
        Host-Name: ftp.is24.de
        Benutzername: Ihre Scout Kunden-ID
        Kennwort: Ihr Scout Passwort
        
        www.Immonet.de:
        Kunden-Nr: Ihre Immonet Anbieter-Id.
        Schemadatei: openimmo.xsd
        Übertragung: FTP, als Zip-Archiv, Teilabgleich
        Host-Name: ftp.immonet.de
        Benutzername: Ihr spezieller Immonet-igeda username (bekommen Sie über uns)
        Kennwort: Ihr spezielles Immonet-igeda passwd (bekommen Sie über uns)
        
        www.immowelt.de:
        Kunden-Nr: Ihre immowelt Anbieter ID.
        Schemadatei: openimmo.xsd
        Übertragung: FTP, als Zip-Archiv, (Teilabgleich)
        Host-Name: ftp2.immowelt.net
        Benutzername: Ihr immowelt Benutzername
        Kennwort: Ihr immowelt Kennwort
        
        www.immobilien.de:
        Kunden-Nr: Ihre immobilien.de Kunden Nr.
        Schemadatei: openimmo.xsd
        Übertragung: FTP, als Zip-Archiv, (Teilabgleich)
        Host-Name: openimmo.immobilien.de
        Benutzername: Ihre immobilien Benutzername (Kunden Nr)
        Kennwort: Ihr immobilien Passwort
        
        www.immopool.de:
        Kunden-Nr: Ihre immopool Anbieternr.
        Schemadatei: openimmo.xsd
        Übertragung: FTP, als Zip-Archiv, (Teilabgleich)
        Host-Name: 62.225.144.225
        Verzeichnis: /Igeda/ Ihre immopool User-ID
        Benutzername: Ihre immopool User-ID
        Kennwort: Ihr immopool Passwort
        
        www. planethome.de:
        Kunden-Nr: Ihr Planethome Username
        Schemadatei: openimmo.xsd
        Übertragung: EMAIL, als Zip-Archiv
        E-Mail Adresse objekteinstellung@planethome.de
        E-Mail Betreff IMS 2000 Objekteinstellung: Ihr Planethome Username, Ihr Firmenname


$immoCompanys = array
(
        "immobilienscout24",
        "immonet",
        "immowelt",
        "immobilien",
        "immopool",
        "planethome"
);

$ftpServer= array
(
        "immobilienscout24",
        "immonet",
        "immowelt",
        "immobilien",
        "immopool",
        "planethome"
);


// GWG-Konfiguration 
$config = array(
        'username'      => "gwg-gladbeck.de",
        'password'      => "g-w7-a",
        'hostname'      => "gwg-gladbeck.de",
        'path'          => "immoscout",
        'file'          => "ImmoScout24Export_GWG_".date("Y-m-d-h-i-s").".xml"
);

// initiate a ImmoScout24Export object
$ImmoScout24Export      = &new ImmoScout24Export('gwg_gladbeck_de');
$header                         = $ImmoScout24Export->getXMLDeclaration('1.0','UTF-8');
$string                         = $ImmoScout24Export->parse2XML($tags);

// Save Handler
$ImmoScout24Export->XMLSave($content, "ImmoScout24Export.xml","./XML_DATA/");

// show export
if (($return = $ImmoScout24Export->export($config)) !== FALSE) 
{
        echo "UploadServer:     ".$config['hostname']."<br>";
        echo "UploadUser:               ".$config['username']."<br>";
        echo "UploadVerzeichnis: ./".$config['path']."/<br>";
        
        echo "Der Export verlief erfolgreich, die Datei: ".$config['file']." hat folgenden Inhalt: <br />";
        echo "<textarea name=\"textarea\" id=\"textarea\" cols=\"80\" rows=\"20\">$return</textarea>";  
}
*/
?>