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: 3931 $
     * @filesource
     * 
     */

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

    // SVN: $Id: optionen_kopieren.php 3931 2011-09-16 08:17:57Z tiefland $

    require_once "../toolbox/common.php";

    if ( isset( $_POST["dir"] ) )
    {
        $dir = filter_input( INPUT_POST, "dir", FILTER_VALIDATE_INT );
        foreach ( $_POST["Option"] as $opt_id => $active )
        {
            if ( $active )
            {
                $sum[$opt_id] = array_sum( $_POST["Value"][$opt_id] );
            }
            else
            {
                $sum[$opt_id] = 0;
            }
        }
        $sql = "SELECT
                a.ID
            FROM
                artikel a
            WHERE
                Father=$dir
            AND
                Language='" . $_SESSION["language"] . "'
        ";
        $res = mysql_query( $sql );
        while ( $row = mysql_fetch_assoc( $res ) )
        {
            $a_id = $row["ID"];
            $sql_d = "DELETE FROM
                    Feature_to_Ware
                WHERE
                    Ware = $a_id
            ";
            $res_d = mysql_query( $sql_d );
            foreach ( $sum as $option_id => $value )
            {
                if ( $value )
                {
                    $sql_i = "
                        INSERT INTO
                            Feature_to_Ware
                        (
                            Ware,
                            Feature,
                            Feature_options
                        )
                        VALUES
                        (
                            $a_id,
                            $option_id,
                            $value
                        )
                    ";
                    $res_i = mysql_query( $sql_i );
                }
            }
        }
        //exit;
        header( "Location: directory.php?action=edit&ID=" . $dir );
    } elseif ( isset( $_GET["dir"] ) )
    {
        $dir = filter_input( INPUT_GET, "dir", FILTER_VALIDATE_INT );
        $sql = "SELECT
                f.ID,
                f.Name
            FROM
                Features f
            WHERE
                f.Language='" . $_SESSION["language"] . "'
        ";
        $res = mysql_query( $sql );
        while ( $feature = mysql_fetch_assoc( $res ) )
        {
            $sql_fo = "SELECT
                    Value,
                    bit
                FROM
                    Feature_options
                WHERE
                    Feature=" . $feature["ID"] . "
                ORDER BY
                    ID,
                    bit
            ";
            $res_fo = mysql_query( $sql_fo );
            while ( $row_fo = mysql_fetch_assoc( $res_fo ) )
            {
                $row_fo["bit_input"]= 1 << $row_fo["bit"];
                $feature["options"][] = $row_fo;
            }
            $features[] = $feature;
        }
        $GLOBALS["ui"]->assign( "features", $features );
        if ( !is_null( $dir ) )
        {
            $sort = $_SESSION["tree.php"]["output"]["artikel_sort"];
            $sql = "SELECT
                    a.ID,
                    a.kurzbezeichnung
                FROM
                    artikel a
            ";
            if ( stristr( $_SESSION[$self]["output"]["artikel_sort"],
                "hersteller" ) )
            {
                $sql .= ", Herstellerkatalog hk";
            }
            $sql .= "
                WHERE
                    Father=$dir
                AND
                    language='" . $_SESSION["language"] . "'
            ";
            if ( stristr( $_SESSION["tree.php"]["output"]["artikel_sort"],
                "hersteller" ) )
            {
                $sql .= "
                    AND
                    (
                        (hk.ID=a.hersteller) 
                        OR 
                        (a.hersteller=0)
                    )
                ";
                $sort = "hk.Name," . $_SESSION["tree.php"]["output"]["artikel_sort"];
            }
            $sql .= "
                ORDER BY
                    $sort 
                LIMIT 1
            ";
            $res = mysql_query( $sql );
            $row = mysql_fetch_assoc( $res );
            if ( is_array( $row ) )
            {
                foreach ( $features as $f_id => $feature )
                {
                    $i = $feature["ID"];
                    $sql_fw = "SELECT
                            Feature,
                            Feature_options AS bits
                        FROM
                            Feature_to_Ware
                        WHERE
                            Ware=" . $row["ID"] . "
                        AND
                            Feature = $i 
                        ORDER BY
                            Feature
                    ";
                    $res_fw = mysql_query( $sql_fw );
                    $row_fw = mysql_fetch_assoc( $res_fw );
                    foreach ( $feature["options"] as $data )
                    {
                        if ( $row_fw["bits"] & $data["bit_input"] )
                        {
                            $row_fw["values"][] = $data["bit_input"];
                        }
                        else
                        {
                            $row_fw["values"][] = null;
                        }
                    }
                    $row["features"][$row_fw["Feature"]] = $row_fw;
                }
                $GLOBALS["ui"]->assign( "artikel", $row );
                $GLOBALS["ui"]->assign( "dir", $dir );
            }
            else
            {
                $GLOBALS["ui"]->assign( "error", true );
                $GLOBALS["ui"]->assign( "meld", "Keine Artikel in diesem Ordner" );
            }
        }
        $GLOBALS["ui"]->assign( "tpl_f", "optionen_kopieren.tpl" );
        $GLOBALS["ui"]->display( "page.tpl" );
    }
?>