Subversion-Projekte lars-tiefland.content-management

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?php

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

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

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

    require_once "../toolbox/common.php";
    require_once
        "../Warenwirtschaft/includes/bestellungen/system/artikelDatabase.php";

    require_once "../Warenwirtschaft/includes/best_manu/system/getShops.php";
    $shop_id = filter_input( INPUT_POST, "shop_id", FILTER_VALIDATE_INT );
    $shops = getShops();
    $shop_ids = array_keys( $shops );
    $default_shop = $shop_ids[0];
    $GLOBALS["ui"]->assign( "default_shop", $default_shop );
    if ( is_null( $shop_id ) )
    {
        $shop_id = 0;
    }

    if ( $_GET["action"] )
    {
        $action = $_GET["action"];
    } elseif ( $_POST["action"] )
    {
        $action = $_POST["action"];
    }
    $preis = $_POST["preis1"];
    if ( stristr( $preis, "%" ) )
    {
        $preis *= -1;
    }
    switch ( $_POST["action"] )
    {
        case "edit":
            if ( $_POST["ID"] )
            {
                $sql = "
                    UPDATE
                        artikel
                    SET
                        status='" . mysql_real_escape_string( $_POST["shop_id"] ) .
                    "',
                        preis1='" . mysql_real_escape_string( $preis ) . "',
                ";
                if ( isset( $user_rechte["marketing"]["gutscheinvorlage"]["mindestbestellwert"] ) )
                {
                    $sql .= "preis2='" . mysql_real_escape_string( $_POST["preis2"] ) .
                        "',";

                }
                $sql .= "
                        kurzbezeichnung='" . mysql_real_escape_string( $_POST["kurzbezeichnung"] ) .
                    "',
                        short_line_1='" . mysql_real_escape_string( $_POST["short_line_1"] ) .
                    "',
                        short_line_2 = " . intval( $_POST["short_line_2"] ) .
                    "
                    WHERE
                        id=" . $_POST["ID"] . "
            ";

            }
            else
            {
                $sql = "
                    INSERT INTO
                        artikel
                    (
                        status,
                ";
                if ( isset( $user_rechte["marketing"]["gutscheinvorlage"]["mindestbestellwert"] ) )
                {
                    $sql .= "
                        preis2,
                    ";
                }
                $sql .= "
                        preis1,
                        kurzbezeichnung,
                        father,
                        short_line_2
                    )
                    VALUES
                    (
                        '" . mysql_real_escape_string( $_POST["shop_id"] ) .
                    "',";
                if ( isset( $user_rechte["marketing"]["gutscheinvorlage"]["mindestbestellwert"] ) )
                {
                    $sql .= "
                        '" . mysql_real_escape_string( $_POST["preis2"] ) .
                        "',
                    ";
                }
                $sql .= "
                        '" . mysql_real_escape_string( $_POST["preis1"] ) .
                    "',
                        '" . mysql_real_escape_string( $_POST["kurzbezeichnung"] ) .
                    "',
                    -5,
                    " . intval( $_POST["short_line_2"] ) .
                    "                    )
                ";
            }
            $res = mysql_query( $sql );
            var_dump(mysql_error());
            $action = "select_edit";
            break;
        case "delete":
            $action = "select_edit";
            break;
    }
    switch ( $action )
    {
        case "edit":
            if ( $_GET["ID"] )
            {
                $vorlage = getVorlage( $_GET["ID"], $_GET["shop_id"] );
            }
            $GLOBALS["ui"]->assign( "vorlage", $vorlage );
            $GLOBALS["ui"]->assign( "file", "vorlage.tpl" );
            break;
        case "delete":
            delVorlage($_GET["ID"]);            
        case "select_edit":
        default:
            $vorlagen = getVorlagen( $shop_id );
            $GLOBALS["ui"]->assign( "vorlagen", $vorlagen );
            $GLOBALS["ui"]->assign( "file", "vorlagen.tpl" );
            break;
    }

    function getVorlagen( $shop_id = 1 )
    {
        $table = "artikel";
        $sql = "SELECT
                *
            FROM
                $table
            WHERE
                Father = -5
            AND
                status=$shop_id
        ";
        $res = mysql_query( $sql );
        while ( $row = mysql_fetch_assoc( $res ) )
        {
            $vorlagen[] = $row;
        }
        return $vorlagen;
    }
    function getVorlage( $v_id, $shop_id = 1 )
    {
        $table = "artikel";
        $sql = "SELECT
                *
            FROM
                $table
            WHERE
                Father = -5
            AND
                ID=$v_id
        ";

        $res = mysql_query( $sql );
        $row = mysql_fetch_assoc( $res );
        return $row;
    }
    
    function delVorlage($v_id)
    {
        $table = "artikel";
        $sql = "DELETE FROM
                $table
            WHERE
                ID=$v_id
        ";

        $res = mysql_query( $sql );
    }
    //$GLOBALS["ui"]->security = true;
    $GLOBALS["ui"]->assign( "shops", $shops );
    $GLOBALS["ui"]->assign( "shop_id", $shop_id );
    $GLOBALS["ui"]->display( "gs_vorlagen.tpl" );
    //var_dump( $GLOBALS["ui"] );

?>