Subversion-Projekte lars-tiefland.ci

Revision

Revision 746 | Revision 1995 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

/**
 * @author Lars Tiefland
 * @copyright 2016
 */

/**
 * Order
 * 
 * Abwicklung des Bestellvorgangs
 * Prüfung der einzelnen Formularfelder
 * 
 * @package WebanOS CI
 * @author Lars Tiefland
 * @copyright 2016
 * @version $Id: Order.php 746 2016-10-06 20:48:09Z lars $
 * @access public
 */
class Order extends CI_Controller
{
        /**
         * Order::__construct()
         * 
         * @return
         */
        public function __construct()
        {
                parent::__construct();
                if (!isset($_SESSION['SHOP']['buy']['Persdata']))
                {
                        $_SESSION['SHOP']['buy']['Persdata'] = array();
                }
                if (!isset($_SESSION['SHOP']['BASKET']))
                {
                        $_SESSION['SHOP']['BASKET'] = array();
                }

                $GLOBALS['order_db'] = $this->load->database('order_db', TRUE);
                $GLOBALS['db_red'] = $this->load->database('db_red', TRUE);
                $anreden = array(
                        $GLOBALS['langstrings']['buy']['mr'] => $GLOBALS['langstrings']['buy']['mr'],
                        $GLOBALS['langstrings']['buy']['mrs'] => $GLOBALS['langstrings']['buy']['mrs'],
                        );
                $this->smarty->assign('anreden', $anreden);
                $this->load->model('Order_model', 'order');
                $this->load->model('artikel_model', 'artikel');
                $versand_laender = getVersandLaender();
                $this->smarty->assign('Laender', $versand_laender);
        }

        /**
         * Order::index()
         * 
         * @return
         */
        public function index($bStep = 1)
        {
                $thirdPartyMethods = array();
                $step = $this->input->post('step');
                if (!$step)
                {
                        $step = $bStep;
                }
                $this->update_versand();
                switch ($this->input->post('action'))
                {
                        case "Persdata":
                                $req_error = true;
                                if ($this->input->post('Persdata'))
                                {
                                        $userData = $this->input->post('Persdata');
                                        if ($this->input->post('Lieferadresse') === "false")
                                        {
                                                $userData['liefer_Anrede'] = $userData['Anrede'];
                                                $userData['liefer_Vorname'] = $userData['Vorname'];
                                                $userData['liefer_Nachname'] = $userData['Nachname'];
                                                $userData['liefer_Firma'] = $userData['Firma'];
                                                $userData['liefer_Strasse'] = $userData['Strasse'];
                                                $userData['liefer_Hausnummer'] = $userData['Hausnummer'];
                                                $userData['liefer_PLZ'] = $userData['PLZ'];
                                                $userData['liefer_Ort'] = $userData['Ort'];
                                                $userData['liefer_email'] = $userData['email'];
                                                $userData['liefer_Telefon'] = $userData['Telefon'];
                                        }
                                        elseif ($this->input->post('Lieferadresse') === "true")
                                        {
                                                if ($this->form_validation->run('liefer') === false)
                                                {
                                                        $errormsg_liefer["liefer_Vorname"] = form_error('Persdata[liefer_Vorname]');
                                                        $errormsg_liefer["liefer_Nachname"] = form_error('Persdata[liefer_Nachname]');
                                                        $errormsg_liefer["liefer_Strasse"] = form_error('Persdata[liefer_Strasse]');
                                                        $errormsg_liefer["liefer_Hausnummer"] = form_error('Persdata[liefer_Hausnummer]');
                                                        $errormsg_liefer["liefer_PLZ"] = form_error('Persdata[liefer_PLZ]');
                                                        $errormsg_liefer["liefer_Ort"] = form_error('Persdata[liefer_Ort]');
                                                        $this->smarty->assign('errormsg_liefer', $errormsg_liefer);
                                                        unset($_GET['subStep']);
                                                }
                                        }
                                        elseif ($this->input->post('Lieferadresse') == "packstation")
                                        {
                                                if ($this->form_validation->run('packstation') === false)
                                                {
                                                        $errormsg_liefer["liefer_Vorname_pst"] = form_error('Persdata[liefer_Vorname_pst]');
                                                        $errormsg_liefer["liefer_Nachname_pst"] = form_error('Persdata[liefer_Nachname_pst]');
                                                        $errormsg_liefer["liefer_Firma_pst"] = form_error('Persdata[liefer_Firma_pst]');
                                                        $errormsg_liefer["liefer_Hausnummer_pst"] = form_error('Persdata[liefer_Hausnummer_pst]');
                                                        $errormsg_liefer["liefer_PLZ_pst"] = form_error('Persdata[liefer_PLZ_pst]');
                                                        $errormsg_liefer["liefer_Ort_pst"] = form_error('Persdata[liefer_Ort_pst]');
                                                        $this->smarty->assign('errormsg_liefer', $errormsg_liefer);
                                                        unset($_GET['subStep']);
                                                }
                                        }
                                        $_SESSION['SHOP']['buy']['Persdata'] = $userData;
                                        $_SESSION['SHOP']['Lieferadresse'] = $this->input->post('Lieferadresse');
                                        $this->update_versand();
                                        $this->form_validation->reset_validation();
                                        if ($this->form_validation->run('guest') === false)
                                        {
                                                $errormsg_rechnung["Vorname"] = form_error('Persdata[Vorname]');
                                                $errormsg_rechnung["Nachname"] = form_error('Persdata[Nachname]');
                                                $errormsg_rechnung["Strasse"] = form_error('Persdata[Strasse]');
                                                $errormsg_rechnung["Hausnummer"] = form_error('Persdata[Hausnummer]');
                                                $errormsg_rechnung["PLZ"] = form_error('Persdata[PLZ]');
                                                $errormsg_rechnung["Ort"] = form_error('Persdata[Ort]');
                                                $errormsg_rechnung["email"] = form_error('Persdata[email]');
                                                $errormsg_rechnung["Telefon"] = form_error('Persdata[Telefon]');
                                                $this->smarty->assign('errormsg_rechnung', $errormsg_rechnung);
                                                unset($_GET['subStep']);
                                        }
                                        else
                                        {
                                                $this->form_validation->reset_validation();
                                                if ($this->input->post('account') == 'new')
                                                {
                                                        if ($this->form_validation('new') === false)
                                                        {
                                                                $req_error = false;
                                                        }
                                                }
                                                else
                                                {
                                                        $req_error = false;
                                                }
                                        }
                                }
                                if (!$req_error)
                                {
                                        $_SESSION["SHOP"]['VERSAND'] = array();

                                        $vItem = $this->artikel->get_artikel($_POST["Versand"], true);
                                        $VersandItem = array(
                                                "Menge" => 1,
                                                "ID" => $_POST['Versand'],
                                                "Versand" => true,
                                                'preis' => $vItem['preis'],
                                                'kurzbezeichnung' => $vItem['kurzbezeichnung'],
                                                );
                                        $_SESSION['SHOP']['VERSAND'] = $VersandItem;
                                        $_SESSION["SHOP"]["buy"]["Versand"] = true;
                                        if ($GLOBALS["INI"]["PayPalPlus"]["aktiv"] == 1)
                                        {
                                                $customMethods = array(
                                                        "vorkasse",
                                                        "selbstabholung",
                                                        "ratenzahlung",
                                                        "nachnahme",
                                                        "sofortueberweisung",
                                                        );
                                                $buy_link_base = 'https://ci.starfleethq.de/';
                                                if ($GLOBALS["INI"]["ssl_buy"] == 1)
                                                {
                                                        $buy_link_base = str_replace("http:", "https:", $buy_link_base);
                                                }
                                                $url = $buy_link_base."/bestellen_seite_2.order";
                                                $versandOptionen = get_versandkosten($_SESSION['SHOP']['buy']['Persdata']['liefer_Land']);
                                                foreach ($versandOptionen as $o_id => $opt)
                                                {
                                                        //admin_debug( $opt["rufname"] );
                                                        $rufname = strtolower($opt["rufname"]);
                                                        if ($GLOBALS["INI"]["dbConnect"]["db_is_utf8"] != 1)
                                                        {
                                                                $opt["kurz"] = utf8_encode($opt["kurz"]);
                                                                $opt["beschr"] = utf8_encode($opt["beschr"]);
                                                        }
                                                        if (in_array($rufname, $customMethods))
                                                        {
                                                                $method = array(
                                                                        "redirectUrl" => $url,
                                                                        "methodName" => $opt["kurz"],
                                                                        "description" => $opt["beschr"],
                                                                        );
                                                                $imgBase = "/images/webelemente/versand_";
                                                                $imgName = $imgBase.$rufname.".jpg";
                                                                $imgUrl = "https://".$_SERVER["SERVER_NAME"].$imgName;
                                                                $imgNameFull = $_SERVER["DOCUMENT_ROOT"].$imgName;
                                                                if ($GLOBALS["INI"]["ssl_buy"] == 1)
                                                                {
                                                                        if (file_exists($imgNameFull))
                                                                        {
                                                                                $method["imageUrl"] = $imgUrl;
                                                                        }
                                                                }
                                                                $thirdPartyMethods[] = $method;
                                                        }
                                                        $payPal3rdParty = json_encode($thirdPartyMethods);
                                                        require_once "module/creditcard/paypalPlus.php";
                                                        $c = new paypalPlus();
                                                        $apporvalUrl = $c->getCreditcardStatus(null);
                                                        $this->smarty->assign("paymentMethods", $payPal3rdParty);
                                                        $this->smarty->assign("approvalUrl", $apporvalUrl);
                                                }
                                                if (strtolower($vItem["short_line_1"]) == "paypal" || strtolower($vItem["short_line_1"]) ==
                                                        "ratenzahlung")
                                                {
                                                        if ($GLOBALS["INI"]["paypal"]["usesApi"] == 1)
                                                        {
                                                                require_once "module/creditcard/paypal.php";
                                                                $c = new paypal();
                                                                $c->getCreditcardStatus(null);
                                                                //
                                                        }
                                                }
                                        }
                                }
                                break;
                        case "Versand":
                                break;
                        case "execute":
                                if ($this->form_validation->run('execute') === false)
                                {
                                        $step = 2;
                                        $errormsg_kontrolle = validation_errors();
                                        $this->smarty->assign('errormsg_kontrolle', $errormsg_kontrolle);
                                }
                                else
                                {
                                        $this->save();
                                }
                                break;
                }
                $_SESSION['SHOP']['buy']['step'] = $step;
                $this->smarty->view('buy.tpl');
        }

        /**
         * Order::save()
         * 
         * @return
         */
        public function save()
        {
                $this->order->create();
        }

        public function update_versand()
        {
                $land = 47;
                if (isset($_SESSION['SHOP']['buy']['Persdata']['liefer_Land']))
                {
                        $land = $_SESSION['SHOP']['buy']['Persdata']['liefer_Land'];
                }
                $versandOptinen = get_versandkosten($land);
                if ($GLOBALS['INI']['PayPalPlus']['aktiv'] == 1)
                {
                        foreach ($versandOptinen as $opt)
                        {
                                if ($opt['rufname'] == 'PayPalPlus')
                                {
                                        $pppVersand = $opt['ID'];
                                        break;
                                }
                        }
                        if ($this->input->get('Land') || $this->input->get('liefer'))
                        {
                                echo $pppVersand;
                        }
                        else
                        {
                                $this->smarty->assign("ppplusVersand", $pppVersand);
                        }
                }
                else
                {
                        foreach ($versandOptinen as $opt)
                        {
                                if ($opt["rufname"] == "amazon" || $opt["rufname"] == "PayPalExpress")
                                {
                                        continue;
                                }
                                elseif ($_GET["packstation"] == 1 && !stristr($opt["kurz"], "DHL"))
                                {
                                        continue;
                                }
                                if ($_GET["kurier"] == 1 && $opt["express"] != 1)
                                {
                                        continue;
                                }
                                if ($GLOBALS['INI']['charset'] == "utf-8" && $GLOBALS['INI']['dbConnect']['db_is_utf8'] !=
                                        1)
                                {
                                        $opt["kurz"] = utf8_encode($opt["kurz"]);
                                        $opt['beschr'] = utf8_encode($opt['beschr']);
                                }
                                $opt['beschr'] = str_replace("\r\n", "<br>", $opt['beschr']);

                                if (($_SESSION["SHOP"]["buy"]["Versand_selected"] == $opt["ID"]) || (!$_SESSION["SHOP"]["buy"]["Versand_selected"] &&
                                        $o_id == 0))
                                {
                                        $opt["checked"] = 'checked="checked"';
                                }
                                $v_opt[] = $opt;
                        }
                        $this->smarty->assign("versandOptionen", $v_opt);
                }
        }
}

?>