Subversion-Projekte lars-tiefland.content-management

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?php

    /**
     * @package   Content-management
     * @author    Webagentur Niewerth <tiefland@weban.de>
     * @copyright 2011 Webagentur Niewerth
     * @license   propietary http://www.weban.de
     * @version   $Rev: 3617 $
     * @filesource
     * 
     */

    /**
     * 
     * @package   Content-management
     * @author    Webagentur Niewerth <tiefland@weban.de>
     * @copyright 2011 Webagentur Niewerth
     */

    // SVN: $Id: artikel_export.php 3617 2011-06-29 10:47:00Z tiefland $

    require_once 'Spreadsheet/Excel/Writer.php';
    $date = date( "Y-m-d" );
    $time = date( "H-i" );
    $f_name = "artikel-export_" . $site . "_" . $date . "_" . $time . ".xls";
    exportItems( $f_name );

    function exportItems( $f_name = 'artikel-export.xls' )
    {

        $items = getItems();
        // Creating a workbook
        $workbook = new Spreadsheet_Excel_Writer();
        // change dir for temporary files
        $workbook->setTempDir( $_SERVER["DOCUMENT_ROOT"] );
        // set version to Excel 97/2000
        $workbook->setVersion( 8 );

        // sending HTTP headers
        $workbook->send( $f_name );

        // Creating a worksheet
        $worksheet = &$workbook->addWorksheet( 'Artikel' );

        // The actual data
        $worksheet->write( 0, 0, 'ID' );
        $worksheet->write( 0, 1, 'Produktkategorie' );
        $worksheet->write( 0, 2, 'Produktunterkategorie' );
        $worksheet->write( 0, 3, 'Product Code' );
        $worksheet->write( 0, 4, 'Artikelbezeichnung' );
        $worksheet->write( 0, 5, 'Langbezeichnung' );
        $worksheet->write( 0, 6, 'Beschreibung' );
        $worksheet->write( 0, 7, 'Application' );
        $worksheet->write( 0, 8, 'Protein Name' );
        $worksheet->write( 0, 9, 'Organism' );
        $worksheet->write( 0, 10, 'Indication' );
        $worksheet->write( 0, 11, 'Number of Peptides' );
        $worksheet->write( 0, 12, 'Amount' );
        $worksheet->write( 0, 13, 'Specification' );
        $worksheet->write( 0, 14, 'Current Batch' );
        $worksheet->write( 0, 15, 'Documentation' );
        $worksheet->write( 0, 16, 'Swiss-Prod ID' );
        $worksheet->write( 0, 17, 'NCBI' );
        $worksheet->write( 0, 18, 'Sequence' );
        $worksheet->write( 0, 19, 'Protein Lenghth' );
        $worksheet->write( 0, 20, 'Bild 1' );
        $worksheet->write( 0, 21, 'Icon' );
        $worksheet->write( 0, 22, 'Bild 2' );
        $worksheet->write( 0, 23, 'Bild 3' );
        $worksheet->write( 0, 24, 'Dokument 1' );
        $worksheet->write( 0, 25, 'Dokument 2' );
        $worksheet->write( 0, 26, 'Dokument 3' );
        $worksheet->write( 0, 27, 'Video' );
        $worksheet->write( 0, 28, 'Preis(EUR)' );
        $worksheet->write( 0, 29, 'Staffelung (wenn möglich)' );
        $worksheet->write( 0, 30, 'Preis(USD)' );
        $worksheet->write( 0, 31, 'Staffelung (wenn möglich)' );
        $worksheet->write( 0, 32, 'Status' );
        $worksheet->write( 0, 33, 'Lieferstatus' );
        $worksheet->write( 0, 34, 'LieferstatusText' );
        $worksheet->write( 0, 35, 'Chilled' );
        $worksheet->write( 0, 36, 'Gewicht' );
        $worksheet->write( 0, 37, 'Erstellungsdatum' );
        $worksheet->write( 0, 38, 'Ersteller' );
        $worksheet->write( 0, 39, 'zuletzt geändert am' );
        $worksheet->write( 0, 40, 'letzter Bearbeiter' );
        if ( count( $items ) )
        {
            foreach ( $items as $i => $item )
            {
                $i++;
                $worksheet->write( $i, 0, $item["id"] );
                $worksheet->write( $i, 1, html_entity_decode( $item["Kategorie"] ) );
                $worksheet->write( $i, 2, html_entity_decode( $item["Unterkategorie"] ) );
                $worksheet->write( $i, 3, html_entity_decode( $item["kennung"] ) );
                $worksheet->write( $i, 4, html_entity_decode( $item["kurzbezeichnung"] ) );
                $worksheet->write( $i, 5, html_entity_decode( $item["langbezeichnung"] ) );
                $worksheet->write( $i, 6, html_entity_decode( $item["beschreibung"] ) );
                $worksheet->write( $i, 7, $item['auspraegung_1'] );
                $worksheet->write( $i, 8, $item['auspraegung_2'] );
                $worksheet->write( $i, 9, $item['auspraegung_3'] );
                $worksheet->write( $i, 10, $item['auspraegung_4'] );
                $worksheet->write( $i, 11, $item['auspraegung_5'] );
                $worksheet->write( $i, 12, $item['short_line_1'] );
                $worksheet->write( $i, 13, $item['short_line_2'] );
                $worksheet->write( $i, 14, $item['short_line_3'] );
                $worksheet->write( $i, 15, $item['short_line_4'] );
                $worksheet->write( $i, 16, $item['short_line_5'] );
                $worksheet->write( $i, 17, $item['short_line_6'] );
                $worksheet->write( $i, 18, $item['short_line_7'] );
                $worksheet->write( $i, 19, $item['short_line_8'] );
                $worksheet->write( $i, 20, $item["bild_1_url"] );
                $worksheet->write( $i, 21, $item["bild_2_url"] );
                $worksheet->write( $i, 22, $item["bild_3_url"] );
                $worksheet->write( $i, 23, $item["bild_4_url"] );
                $worksheet->write( $i, 24, $item["bild_5_url"] );
                $worksheet->write( $i, 25, $item["bild_6_url"] );
                $worksheet->write( $i, 26, $item["bild_7_url"] );
                $worksheet->write( $i, 27, $item["bild_8_url"] );
                $worksheet->write( $i, 28, $item["preis1"] );
                $worksheet->write( $i, 29, $item["staffel_1"] );
                $worksheet->write( $i, 30, $item["preis2"] );
                $worksheet->write( $i, 31, $item["staffel_2"] );
                $worksheet->write( $i, 32, $item["status"] );
                $worksheet->write( $i, 33, $item["lieferstatus"] );
                $worksheet->write( $i, 34, $item["lieferstatus_text"] );
                $worksheet->write( $i, 35, $item["chilled"] );
                $worksheet->write( $i, 36, $item["gewicht"] );
                $worksheet->write( $i, 37, $item["erstellt_am"] );
                $worksheet->write( $i, 38, $item["erstellt_von"] );
                $worksheet->write( $i, 39, $item["letzte_aenderung_am"] );
                $worksheet->write( $i, 40, $item["letzte_aenderung_von"] );
                //break;
            }
        } // Let's send the file
        $workbook->close();
    }

    function getItems()
    {
        $items = array();
        if ( is_array( $_POST["kategorien"] ) )
        {
            foreach ( $_POST["kategorien"] as $c_id )
            {
                $sql = "SELECT
                        id
                    FROM
                        artikel
                    WHERE
                        Father=$c_id
                    AND
                        language='" . DEFAULT_LANG . "'
                ";
                $res = mysql_query( $sql );
                while ( $row = mysql_fetch_assoc( $res ) )
                {
                    $items[] = getItem( $row["id"] );
                }
            }
        }
        return $items;
    }
    function getItem( $id )
    {
        global $web_rechte;
        $sql = "SELECT
                id,
                father,
                kurzbezeichnung,
                langbezeichnung,
                beschreibung,
                kennung,
                gewicht,
                erstellt_von,
                erstellt_am,
                letzte_aenderung_am,
                letzte_aenderung_von,
                bild_1_url,
                bild_2_url,
                bild_3_url,
                bild_4_url,
                bild_5_url,
                bild_6_url,
                bild_7_url,
                bild_8_url,
                short_line_1,
                short_line_2,
                short_line_3,
                short_line_4,
                short_line_5,
                short_line_6,
                short_line_7,
                short_line_8,
                IF(status=1,'gesperrt','anzeigen') AS status,
                IF(Eigenschaft_1=1,'ja','nein') AS chilled,
                lieferstatus
            FROM
                artikel
            WHERE
                id=$id
            AND
                language='" . DEFAULT_LANG . "'
        ";
        $res = mysql_query( $sql );
        $row = mysql_fetch_assoc( $res );
        $sql_d = "SELECT
                name,
                father
            FROM
                directory
            WHERE
                id=" . $row["father"] . "
            AND
                language='" . DEFAULT_LANG . "'
        ";
        $res_d = mysql_query( $sql_d );
        $row_d = mysql_fetch_assoc( $res_d );
        $row["Unterkategorie"] = $row_d["name"];
        $sql_d = "SELECT
                name,
                father
            FROM
                directory
            WHERE
                id=" . $row_d["father"] . "
            AND
                language='" . DEFAULT_LANG . "'
        ";
        $res_d = mysql_query( $sql_d );
        $row_d = mysql_fetch_assoc( $res_d );
        $row["Kategorie"] = $row_d["name"];
        $staffeln = getStaffeln( $id );
        foreach ( $staffeln as $s_nr => $staffel )
        {
            foreach ( $staffel["preis"] as $p_ind => $preis )
            {
                if ( $p_ind != 0 )
                {
                    if ( $preis < 0 )
                    {
                        $staffeln_erg[$s_nr][$p_ind] = "Menge: " . $staffel["menge"][$p_ind] .
                            "; Preis: " . $preis * -1 . "%";
                    }
                    else
                    {
                        $staffeln_erg[$s_nr][$p_ind] = "Menge: " . $staffel["menge"][$p_ind] .
                            "; Preis: " . $preis;
                    }
                }
                else
                {
                    $row["preis" . $s_nr] = $preis;
                }
            }
            if ( is_array( $staffeln_erg[$s_nr] ) )
            {
                $row["staffel_" . $s_nr] = implode( ",", $staffeln_erg[$s_nr] );
            }
        }
        $sql_a = "SELECT
                auspraegung,
                wert
            FROM
                artikel_to_auspraegung
            WHERE
                artikel=$id
        ";
        $res_a = mysql_query( $sql_a );
        while ( $row_a = mysql_fetch_assoc( $res_a ) )
        {
            if ( $row_a["auspraegung"] != 5 )
            {
                $wert = unserialize( $row_a["wert"] );
                $row["auspraegung_" . $row_a["auspraegung"]] = implode( ";",
                    $wert );
            }
            else
            {
                $row["auspraegung_" . $row_a["auspraegung"]] = $row_a["wert"];
            }
        }
        $liefer_stati = explode( ";", $web_rechte["online_shop"]["artikel"]["Lieferstatus"] );
        $row["lieferstatus_text"] = $liefer_stati[$row["lieferstatus"]];
        return $row;
    }

    function getStaffeln( $artikel_id )
    {
        $staffeln = array();
        $sql = "SELECT
                preis_index,
                staffel
            FROM
                preise
            WHERE
                artikel_id=" . $artikel_id . "
            AND
                language='" . DEFAULT_LANG . "'
        ";
        $res = mysql_query( $sql );
        while ( $row = mysql_fetcH_assoc( $res ) )
        {
            $staffeln[$row["preis_index"]] = unserialize( $row["staffel"] );
        }
        return $staffeln;
    }
?>