Vererbungs-Wildwuchs???

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Vererbungs-Wildwuchs???

    Hallo, ich habe einen anfang für ein Warenkorbsystem geschrieben.
    Nur, ich habe da so meine schwierigkeiten, da ich glaube, dass ich mit meinen Scripten Vererbungs-Wildwuchs betreibe...

    Könnt Ihr mir Tips geben, wie ich mein Vorhaben verbessern kann?
    Ich poste hier einfach mal kompletten Code, damit man sich auch eine Vorstellung machen kann, wie in etwa der Aufbau ist.



    /// WARENKORB

    PHP-Code:
    <?php

    include("./classes/class_sessions.php");
    include(
    "./classes/class_customer.php");
    include(
    "./classes/settings.php");

    $language_error $_SETTINGS['LANGUAGE'].'_err.php';
    //include("./classes/languages/$language_error");

    /************************************************************************
    * Class Name:     cart
    * Extensions:     [CLASS_CUSTOMER]
    * Functions:      add_to_cart, remove_from_cart
    *
    ************************************************************************/


    class cart extends customer{

     var 
    $customer_id;
     var 
    $category;
     var 
    $key;
     var 
    $data;
     var 
    $value;
     var 
    $piece;
     var 
    $_SHOP = array();
     var 
    $temp_value;
     var 
    $_temp_array = array();

    /************************************************************************
    * Function Name:  add_to_cart()
    * Input:          $data ->
    *                 contains: $_GET VALUES
    * Subfunctions:   add_cart_to_db()  [CLASS_CUSTOMER]
    * Output:         -
    ************************************************************************/

    function add_to_cart($data){

        global 
    $_SHOP;
        
    $this->_SHOP $_SHOP;
        
    $this->data  $data;

        if(!
    is_numeric($this->data['amount'])){
          return 
    false;
          }

        
    $counter =  $_SESSION['art_count']+1;

        
    settype ($counter"integer");
        
    $this->_temp_array $_SESSION;
        
    $this->key    $_REQUEST['key'];


        if(
    $this->key != ""){
           
    $this->value $_SESSION['id'][$this->key];
           
    $this->piece explode("=>",$this->value);
           if(
    $this->data['sec'] == "remove"){
             
    $this->temp_value $this->piece[1]-$this->data['amount'];
             
    $_SESSION['id'][$this->key] = $this->piece[0]."=>".$this->temp_value;
             }
             elseif(
    $this->data['sec'] != "remove"){
                   
    $this->temp_value $this->piece[1]+$this->data['amount'];
                   
    $_SESSION['id'][$this->key] = $this->piece[0]."=>".$this->temp_value;
                   }
             
    $search_count 1;
             
    customer::update_cart($this->data['id'],$this->data['amount']);
          }


        if(
    $search_count != 1){

        if(
    $this->_SHOP['DATABASE'] == 1){

           
    customer::add_cart_to_db($this->data);

           
    $_SESSION['art_count']++;

           if(
    count($_SESSION['id']) != $_SESSION['art_count']){
              
    $i = @max(array_keys($_SESSION['id']))+1;
                        if(@
    array_key_exists($i$_SESSION['id'])){
                           
    $i = @max(array_keys($_SESSION['id']))+2;
                          }
             }
             else{
                 
    $i $_SESSION['art_count'];
                 }
                 
    $_SESSION['id'][$i] = $this->data['id']."=>".$this->data['amount'];
                 
    $_SESSION['art_count'] = count($_SESSION['id']);
                 }

            }

      }
    /************************************************************************
    * Function Name:  remove_from_cart()
    * Input:          $key ->
    *                 contains: $_GET VALUES
    * Subfunctions:   remove_cart_from_db()  [CLASS_CUSTOMER]
    * Output:         -
    ************************************************************************/
    function remove_from_cart($key){

           global 
    $_SHOP;
           
    $this->_SHOP  $_SHOP;
           
    $this->key    $key;
           
    $this->temp_value $_SESSION['id'][$this->key];
           
    $this->art_no explode("=>",$this->temp_value);

        if(
    $this->key == "" ||
          !
    array_key_exists($key$_SESSION['id'])){
           return 
    false;
          }

        if(
    $this->_SHOP['DATABASE']     == 1){

           
    customer::remove_cart_from_db($key);

           if(
    $this->key 0){
             unset(
    $_SESSION['id'][$this->key]);
             
    $_SESSION['art_count'] = $_SESSION['art_count']-1;
             return 
    true;
             }
             else{
                 return 
    false;
                 }

           }
        }
    }
    ?>
    /// class_customer.php
    PHP-Code:
    <?php
    include("./classes/class_db.php");
    include(
    "./classes/settings.php");


    class 
    customer extends _database{

    var 
    $id;
    var 
    $amount;
    var 
    $sessid;
    var 
    $_query;
    var 
    $query;
    var 
    $_update = array();
    var 
    $sysmess;

    /************************************************************************
    * Function Name:  add_cart_to_db()
    * Input:          $data ->
    *                 contains: product_id,amount
    * Output:         -
    ************************************************************************/
    function add_cart_to_db($data){
     global 
    $_hostname;
     global 
    $_username;
     global 
    $_password;
     global 
    $_conntype;
     global 
    $_dbname;
     global 
    $_SETTINGS;

     
    $this->id          $data['id'];
     
    $this->amount      $data['amount'];
     
    $this->sessid      session_id();
     
    $this->_update     $_update;
     
    $this->customer_id $_SESSION['customer_id'];

     if(
    $this->customer_id == ""){
       
    $_SESSION['customer'] = "guest";
       }


     
    _database::_connect($_hostname,$_username,$_password,$_conntype,$_dbname);

     if(!
    is_resource($this->connid)){
        return 
    false;
        die;
       }

                
    $this->_query "INSERT INTO pro (id,art_nr,anzahl,sessid)
                                                  VALUES
                                                 ('','
    $this->id','$this->amount','$this->sessid')";
                
    $this->query  _database::query($this->_query,$this->_conntype,$this->connid);

                if(
    $_SETTINGS['CART_INSERT_STAT'] == 1){
                   
    $sysmess .= "INSERT CART STAT";
                  }
    $this->sysmess $sysmess;
    }

    /************************************************************************
    * Function Name:  remove_from_cart()
    * Input:          $key ->
    *                 contains: $_GET VALUES
    * Subfunctions:   remove_cart_from_db()  [CLASS_CUSTOMER]
    *                 remove_cart_from_file()[CLASS_CUSTOMER]
    * Output:         -
    ************************************************************************/

    function remove_cart_from_db($key){


     global 
    $_hostname;
     global 
    $_username;
     global 
    $_password;
     global 
    $_conntype;
     global 
    $_dbname;
     global 
    $_SETTINGS;

     
    $this->sessid    session_id();
     
    $art_no    $this->art_no[0];
     
    $art_count $this->art_no[1];


     
    _database::_connect($_hostname,$_username,$_password,$_conntype,$_dbname);

     if(!
    is_resource($this->connid)){
        return 
    false;
        die;
       }

     
    $this->_query "DELETE FROM pro WHERE  sessid='$this->sessid'
                      AND art_nr='
    $art_no'
                      AND anzahl='
    $art_count'";

     
    $this->query  _database::query($this->_query,$this->_conntype,$this->connid);
     
    $this->_query "OPTIMIZE TABLE pro";
     
    $this->query  _database::query($this->_query,$this->_conntype,$this->connid);

     if(
    $_SETTINGS['CART_DEL_STAT'] == 1){
        
    $sysmess .=  "CART DEL STAT";
       }
    $this->sysmess $sysmess;
    }



    /************************************************************************
    * Function Name:  update_cart()
    * Input:          $key ->
    *                 contains: $_GET VALUES
    * Subfunctions:   remove_cart_from_db()  [CLASS_CUSTOMER]
    *                 remove_cart_from_file()[CLASS_CUSTOMER]
    * Output:         -
    ************************************************************************/

    function update_cart($key,$amount){

     global 
    $_hostname;
     global 
    $_username;
     global 
    $_password;
     global 
    $_conntype;
     global 
    $_dbname;
     global 
    $_SETTINGS;

     
    $this->sessid    session_id();


     
    _database::_connect($_hostname,$_username,$_password,$_conntype,$_dbname);
     if(!
    is_resource($this->connid)){
        return 
    false;
        die;
       }
       if(
    $amount == ""){
         
    $amount 1;
         }

           if(
    $this->data['sec'] == "remove"){
             
    $this->_query "UPDATE pro SET anzahl=anzahl-'$amount' WHERE art_nr='$key' And sessid='$this->sessid'";
             }
             elseif(
    $this->data['sec'] != "remove"){
                    
    $this->_query "UPDATE pro SET anzahl=anzahl+'$amount' WHERE art_nr='$key' And sessid='$this->sessid'";
                    }

                
    $this->query  _database::query($this->_query,$this->_conntype,$this->connid);

                if(
    $_SETTINGS['CART_UPDATE_STAT'] == 1){
                   
    $sysmess .=  "UPDATE CART STAT";
                  }
           
    $this->_query "DELETE FROM pro WHERE anzahl<=0";
           
    $this->query  _database::query($this->_query,$this->_conntype,$this->connid);


    $this->sysmess $sysmess;
    }
    }

    ?>


    Viele Grüsse

    David
    Die meiste Unwissenheit könnte besiegt werden. Wir eignen uns nur deshalb keine Kenntnisse an, weil wir sie nicht wünschen.

  • #2
    http://wai.devmag.net/webprog/php_cl...mplate/wai.tpl

    wäre wohl eine alternative für Dich.

    Dann bräuchtest nur noch eine main klasse und koenntest alle anderen dort relativ leicht on the fly hinzufügen

    Kommentar


    • #3
      Vielen Dank für die Antwort!!!

      Ich werde es gleich mal ausprobieren.
      Die meiste Unwissenheit könnte besiegt werden. Wir eignen uns nur deshalb keine Kenntnisse an, weil wir sie nicht wünschen.

      Kommentar

      Lädt...
      X