[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/modules/payment/ -> sofortueberweisung_direct.php (source)

   1  <?php
   2  /*
   3    $Id: sofortueberweisung_direct.php 1782 2008-01-10 01:10:52Z user $
   4  
   5    osCMax Power E-Commerce
   6    http://oscdox.com
   7  
   8    Copyright 2008 osCMax
   9    Copyright (c) 2006 - 2007 Henri Schmidhuber (http://www.in-solution.de)
  10  
  11    Released under the GNU General Public License
  12  */
  13  
  14    class sofortueberweisung_direct {
  15      var $code, $title, $description, $enabled;
  16  
  17  // class constructor
  18      function sofortueberweisung_direct() {
  19        global $order;
  20  
  21        $this->code = 'sofortueberweisung_direct';
  22        $this->title = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_TITLE;
  23        $this->public_title = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_PUBLIC_TITLE;
  24        $this->description = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_DESCRIPTION;
  25        $this->sort_order = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_SORT_ORDER;
  26        $this->enabled = ((MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_STATUS == 'True') ? true : false);
  27  
  28        if ((int)MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PREPARE_ORDER_STATUS_ID > 0) {
  29          $this->order_status = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PREPARE_ORDER_STATUS_ID;
  30        }
  31  
  32        if (is_object($order)) $this->update_status();
  33  
  34        $this->email_footer = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_EMAIL_FOOTER;
  35  
  36        $this->form_action_url = 'https://www.sofort-ueberweisung.de/payment.php';
  37      }
  38  
  39  // class methods
  40      function update_status() {
  41        global $order;
  42  
  43        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ZONE > 0) ) {
  44          $check_flag = false;
  45          $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
  46          while ($check = tep_db_fetch_array($check_query)) {
  47            if ($check['zone_id'] < 1) {
  48              $check_flag = true;
  49              break;
  50            } elseif ($check['zone_id'] == $order->billing['zone_id']) {
  51              $check_flag = true;
  52              break;
  53            }
  54          }
  55  
  56          if ($check_flag == false) {
  57            $this->enabled = false;
  58          }
  59        }
  60      }
  61  
  62      function javascript_validation() {
  63        return false;
  64      }
  65  
  66      function selection() {
  67        global $cart_Sofortueberweisung_Direct_ID;
  68  
  69        if (tep_session_is_registered('cart_Sofortueberweisung_Direct_ID')) {
  70          $order_id = substr($cart_Sofortueberweisung_Direct_ID, strpos($cart_Sofortueberweisung_Direct_ID, '-')+1);
  71  
  72          $check_query = tep_db_query('select orders_id from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '" limit 1');
  73  
  74          if (tep_db_num_rows($check_query) < 1) {
  75            tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . (int)$order_id . '"');
  76            tep_db_query('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = "' . (int)$order_id . '"');
  77            tep_db_query('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '"');
  78            tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS . ' where orders_id = "' . (int)$order_id . '"');
  79            tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' where orders_id = "' . (int)$order_id . '"');
  80            tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_DOWNLOAD . ' where orders_id = "' . (int)$order_id . '"');
  81  
  82            tep_session_unregister('cart_Sofortueberweisung_Direct_ID');
  83          }
  84        }
  85  
  86        return array('id' => $this->code,
  87                     'module' => $this->public_title,
  88                     'fields' => array(array('title' => MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_DESCRIPTION_CHECKOUT_PAYMENT)));
  89      }
  90  
  91      function pre_confirmation_check() {
  92        global $cartID, $cart;
  93  
  94        // We need the cartID
  95        if (empty($cart->cartID)) {
  96          $cartID = $cart->cartID = $cart->generate_cart_id();
  97        }
  98  
  99        if (!tep_session_is_registered('cartID')) {
 100          tep_session_register('cartID');
 101        }
 102      }
 103  
 104      function confirmation() {
 105        global $cartID, $cart_Sofortueberweisung_Direct_ID, $customer_id, $languages_id, $order, $order_total_modules;
 106  
 107        $insert_order = false;
 108  
 109        if (tep_session_is_registered('cart_Sofortueberweisung_Direct_ID')) {
 110          $order_id = substr($cart_Sofortueberweisung_Direct_ID, strpos($cart_Sofortueberweisung_Direct_ID, '-')+1);
 111  
 112          $curr_check = tep_db_query("select currency from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
 113          $curr = tep_db_fetch_array($curr_check);
 114  
 115          if ( ($curr['currency'] != $order->info['currency']) || ($cartID != substr($cart_Sofortueberweisung_Direct_ID, 0, strlen($cartID))) ) {
 116            $check_query = tep_db_query('select orders_id from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '" limit 1');
 117  
 118            if (tep_db_num_rows($check_query) < 1) {
 119              tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . (int)$order_id . '"');
 120              tep_db_query('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = "' . (int)$order_id . '"');
 121              tep_db_query('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '"');
 122              tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS . ' where orders_id = "' . (int)$order_id . '"');
 123              tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' where orders_id = "' . (int)$order_id . '"');
 124              tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_DOWNLOAD . ' where orders_id = "' . (int)$order_id . '"');
 125            }
 126  
 127            $insert_order = true;
 128          }
 129        } else {
 130          $insert_order = true;
 131        }
 132  
 133        if ($insert_order == true) {
 134          $order_totals = array();
 135          if (is_array($order_total_modules->modules)) {
 136            reset($order_total_modules->modules);
 137            while (list(, $value) = each($order_total_modules->modules)) {
 138              $class = substr($value, 0, strrpos($value, '.'));
 139              if ($GLOBALS[$class]->enabled) {
 140                for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
 141                  if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {
 142                    $order_totals[] = array('code' => $GLOBALS[$class]->code,
 143                                            'title' => $GLOBALS[$class]->output[$i]['title'],
 144                                            'text' => $GLOBALS[$class]->output[$i]['text'],
 145                                            'value' => $GLOBALS[$class]->output[$i]['value'],
 146                                            'sort_order' => $GLOBALS[$class]->sort_order);
 147                  }
 148                }
 149              }
 150            }
 151          }
 152  
 153          $sql_data_array = array('customers_id' => $customer_id,
 154                                  'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],
 155                                  'customers_company' => $order->customer['company'],
 156                                  'customers_street_address' => $order->customer['street_address'],
 157                                  'customers_suburb' => $order->customer['suburb'],
 158                                  'customers_city' => $order->customer['city'],
 159                                  'customers_postcode' => $order->customer['postcode'],
 160                                  'customers_state' => $order->customer['state'],
 161                                  'customers_country' => $order->customer['country']['title'],
 162                                  'customers_telephone' => $order->customer['telephone'],
 163                                  'customers_email_address' => $order->customer['email_address'],
 164                                  'customers_address_format_id' => $order->customer['format_id'],
 165                                  'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'],
 166                                  'delivery_company' => $order->delivery['company'],
 167                                  'delivery_street_address' => $order->delivery['street_address'],
 168                                  'delivery_suburb' => $order->delivery['suburb'],
 169                                  'delivery_city' => $order->delivery['city'],
 170                                  'delivery_postcode' => $order->delivery['postcode'],
 171                                  'delivery_state' => $order->delivery['state'],
 172                                  'delivery_country' => $order->delivery['country']['title'],
 173                                  'delivery_address_format_id' => $order->delivery['format_id'],
 174                                  'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'],
 175                                  'billing_company' => $order->billing['company'],
 176                                  'billing_street_address' => $order->billing['street_address'],
 177                                  'billing_suburb' => $order->billing['suburb'],
 178                                  'billing_city' => $order->billing['city'],
 179                                  'billing_postcode' => $order->billing['postcode'],
 180                                  'billing_state' => $order->billing['state'],
 181                                  'billing_country' => $order->billing['country']['title'],
 182                                  'billing_address_format_id' => $order->billing['format_id'],
 183                                  'payment_method' => $order->info['payment_method'],
 184                                  'cc_type' => $order->info['cc_type'],
 185                                  'cc_owner' => $order->info['cc_owner'],
 186                                  'cc_number' => $order->info['cc_number'],
 187                                  'cc_expires' => $order->info['cc_expires'],
 188                                  'date_purchased' => 'now()',
 189                                  'orders_status' => $order->info['order_status'],
 190                                  'currency' => $order->info['currency'],
 191                                  'currency_value' => $order->info['currency_value']);
 192  
 193          tep_db_perform(TABLE_ORDERS, $sql_data_array);
 194  
 195          $insert_id = tep_db_insert_id();
 196  
 197          for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
 198            $sql_data_array = array('orders_id' => $insert_id,
 199                                    'title' => $order_totals[$i]['title'],
 200                                    'text' => $order_totals[$i]['text'],
 201                                    'value' => $order_totals[$i]['value'],
 202                                    'class' => $order_totals[$i]['code'],
 203                                    'sort_order' => $order_totals[$i]['sort_order']);
 204  
 205            tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
 206          }
 207  
 208          for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
 209            $sql_data_array = array('orders_id' => $insert_id,
 210                                    'products_id' => tep_get_prid($order->products[$i]['id']),
 211                                    'products_model' => $order->products[$i]['model'],
 212                                    'products_name' => $order->products[$i]['name'],
 213                                    'products_price' => $order->products[$i]['price'],
 214                                    'final_price' => $order->products[$i]['final_price'],
 215                                    'products_tax' => $order->products[$i]['tax'],
 216                                    'products_quantity' => $order->products[$i]['qty']);
 217  
 218            tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
 219  
 220            $order_products_id = tep_db_insert_id();
 221  
 222            $attributes_exist = '0';
 223            if (isset($order->products[$i]['attributes'])) {
 224              $attributes_exist = '1';
 225              for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
 226                if (DOWNLOAD_ENABLED == 'true') {
 227                  $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename
 228                                       from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 229                                       left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 230                                       on pa.products_attributes_id=pad.products_attributes_id
 231                                       where pa.products_id = '" . $order->products[$i]['id'] . "'
 232                                       and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'
 233                                       and pa.options_id = popt.products_options_id
 234                                       and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'
 235                                       and pa.options_values_id = poval.products_options_values_id
 236                                       and popt.language_id = '" . $languages_id . "'
 237                                       and poval.language_id = '" . $languages_id . "'";
 238                  $attributes = tep_db_query($attributes_query);
 239                } else {
 240                  $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
 241                }
 242                $attributes_values = tep_db_fetch_array($attributes);
 243  
 244                $sql_data_array = array('orders_id' => $insert_id,
 245                                        'orders_products_id' => $order_products_id,
 246                                        'products_options' => $attributes_values['products_options_name'],
 247                                        'products_options_values' => $attributes_values['products_options_values_name'],
 248                                        'options_values_price' => $attributes_values['options_values_price'],
 249                                        'price_prefix' => $attributes_values['price_prefix']);
 250  
 251                tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);
 252  
 253                if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) {
 254                  $sql_data_array = array('orders_id' => $insert_id,
 255                                          'orders_products_id' => $order_products_id,
 256                                          'orders_products_filename' => $attributes_values['products_attributes_filename'],
 257                                          'download_maxdays' => $attributes_values['products_attributes_maxdays'],
 258                                          'download_count' => $attributes_values['products_attributes_maxcount']);
 259  
 260                  tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array);
 261                }
 262              }
 263            }
 264          }
 265  
 266          $cart_Sofortueberweisung_Direct_ID = $cartID . '-' . $insert_id;
 267          tep_session_register('cart_Sofortueberweisung_Direct_ID');
 268        }
 269  
 270        return array('title' => MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_DESCRIPTION_CHECKOUT_CONFIRMATION);
 271      }
 272  
 273      function process_button() {
 274        global $order, $cart, $customer_id, $currencies, $cart_Sofortueberweisung_Direct_ID;
 275  
 276        $order_id = substr($cart_Sofortueberweisung_Direct_ID, strpos($cart_Sofortueberweisung_Direct_ID, '-')+1);
 277  
 278        $parameter= array();
 279        $parameter['kdnr']    = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_KDNR;  // Repräsentiert Ihre Kundennummer bei der Sofortüberweisung
 280        $parameter['projekt'] = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PROJEKT;  // Die verantwortliche Projektnummer bei der Sofortüberweisung, zu der die Zahlung gehört
 281        $parameter['betrag'] = number_format($order->info['total'] * $currencies->get_value('EUR'), 2, '.','');  // Beziffert den Zahlungsbetrag, der an Sie übermittelt werden soll
 282        $vzweck1 = str_replace('{{orderid}}', $order_id, MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_V_ZWECK_1);
 283        $vzweck2 = str_replace('{{orderid}}', $order_id, MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_V_ZWECK_2);
 284  
 285        $vzweck1 = str_replace('{{order_date}}', strftime(DATE_FORMAT_SHORT), $vzweck1);
 286        $vzweck2 = str_replace('{{order_date}}', strftime(DATE_FORMAT_SHORT), $vzweck2);
 287  
 288        $vzweck1 = str_replace('{{customer_id}}', $customer_id, $vzweck1);
 289        $vzweck2 = str_replace('{{customer_id}}', $customer_id, $vzweck2);
 290  
 291        $vzweck1 = str_replace('{{customer_name}}', $order->customer['firstname'] . ' ' . $order->customer['lastname'], $vzweck1);
 292        $vzweck2 = str_replace('{{customer_name}}', $order->customer['firstname'] . ' ' . $order->customer['lastname'], $vzweck2);
 293  
 294        $vzweck1 = str_replace('{{customer_company}}', $order->customer['company'], $vzweck1);
 295        $vzweck2 = str_replace('{{customer_company}}', $order->customer['company'], $vzweck2);
 296  
 297        $vzweck1 = str_replace('{{customer_email}}', $order->customer['email_address'], $vzweck1);
 298        $vzweck2 = str_replace('{{customer_email}}', $order->customer['email_address'], $vzweck2);
 299  
 300        // Kürzen auf 27 Zeichen
 301        $vzweck1 = substr($vzweck1, 0, 27);
 302        $vzweck2 = substr($vzweck2, 0, 27);
 303  
 304        $parameter['v_zweck_1'] = tep_output_string($vzweck1);  // Definieren Sie hier Ihre Verwendungszwecke
 305        $parameter['v_zweck_2'] = tep_output_string($vzweck2);  // Definieren Sie hier Ihre Verwendungszwecke
 306  
 307        $parameter['kunden_var_0'] = tep_output_string($order_id);  // Eindeutige Identifikation der Zahlung, z.B. Session ID oder Auftragsnummer.
 308        $parameter['kunden_var_1'] = tep_output_string($customer_id);
 309        $parameter['kunden_var_2'] = tep_output_string(tep_session_id());
 310        $parameter['kunden_var_3'] = tep_output_string($cart->cartID);
 311        $parameter['kunden_var_4'] = '';
 312        $parameter['kunden_var_5'] = '';
 313        // $parameter['Partner'] = '';
 314  
 315        if (strlen(MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_INPUT_PASSWORT) > 0) {
 316          $tmparray = array(
 317            $parameter['betrag'],
 318            $parameter['v_zweck_1'],
 319            $parameter['v_zweck_2'],
 320            '', // von_konto_inhaber
 321            '', // von_konto_nr
 322            '', // von_konto_blz
 323            $parameter['kunden_var_0'],
 324            $parameter['kunden_var_1'],
 325            $parameter['kunden_var_2'],
 326            $parameter['kunden_var_3'],
 327            $parameter['kunden_var_4'],
 328            $parameter['kunden_var_5'],
 329            MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_INPUT_PASSWORT);
 330          $parameter['key'] = md5(implode("|", $tmparray));
 331        }
 332        $process_button_string = '';
 333        reset($parameter);
 334        while (list($key, $value) = each($parameter)) {
 335          $process_button_string .= tep_draw_hidden_field($key, $value). "\n";
 336        }
 337  
 338        return $process_button_string;
 339      }
 340  
 341      function before_process() {
 342        global $HTTP_GET_VARS, $customer_id, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_Sofortueberweisung_Direct_ID;
 343        global $$payment;
 344  
 345        $md5var4 = md5($HTTP_GET_VARS['sovar3'] . MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_CNT_PASSWORT);
 346        // Statusupdate nur wenn keine Cartänderung vorgenommen
 347        $order_total_integer = number_format($order->info['total'] * $currencies->get_value('EUR'), 2, '.','')*100;
 348        if ($order_total_integer < 1) {
 349          $order_total_integer = '000';
 350        } elseif ($order_total_integer < 10) {
 351          $order_total_integer = '00' . $order_total_integer;
 352        } elseif ($order_total_integer < 100) {
 353          $order_total_integer = '0' . $order_total_integer;
 354        }
 355  
 356        $order_id = substr($cart_Sofortueberweisung_Direct_ID, strpos($cart_Sofortueberweisung_Direct_ID, '-')+1);
 357  
 358        $check_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
 359        if (tep_db_num_rows($check_query)) {
 360          $check = tep_db_fetch_array($check_query);
 361  
 362          if ($check['orders_status'] == MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PREPARE_ORDER_STATUS_ID) {
 363            $sql_data_array = array('orders_id' => $order_id,
 364                                    'orders_status_id' => MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PREPARE_ORDER_STATUS_ID,
 365                                    'date_added' => 'now()',
 366                                    'customer_notified' => '0',
 367                                    'comments' => '');
 368  
 369            if (($md5var4 == $HTTP_GET_VARS['sovar4']) && ((int)$HTTP_GET_VARS['betrag_integer'] == (int)$order_total_integer)) {
 370              $sql_data_array['comments'] = 'Zahlung durch Sofortüberweisung Weiter-Button/Weiterleitung bestätigt!';
 371            } else {
 372              $sql_data_array['comments'] = MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_CHECK_ERROR . '\n' . ($HTTP_GET_VARS['betrag_integer']/100) . '!=' . ($order_total_integer/100);
 373            }
 374  
 375            if (MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_STORE_TRANSACTION_DETAILS == 'True') {
 376              $sql_data_array['comments'] = (!empty($sql_data_array['comments']) ? $sql_data_array['comments'] . "\n\n" : '') . serialize($HTTP_GET_VARS) . "\n" . serialize($HTTP_POST_VARS);
 377            }
 378  
 379            tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 380          }
 381        }
 382  
 383        tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID > 0 ? (int)MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID : (int)DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . (int)$order_id . "'");
 384  
 385        $sql_data_array = array('orders_id' => $order_id,
 386                                'orders_status_id' => (MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID > 0 ? (int)MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID : (int)DEFAULT_ORDERS_STATUS_ID),
 387                                'date_added' => 'now()',
 388                                'customer_notified' => (SEND_EMAILS == 'true') ? '1' : '0',
 389                                'comments' => $order->info['comments']);
 390  
 391        tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 392  
 393  // initialized for the email confirmation
 394        $products_ordered = '';
 395        $subtotal = 0;
 396        $total_tax = 0;
 397  
 398        for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
 399  // Stock Update - Joao Correia
 400          if (STOCK_LIMITED == 'true') {
 401            if (DOWNLOAD_ENABLED == 'true') {
 402              $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename
 403                                  FROM " . TABLE_PRODUCTS . " p
 404                                  LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 405                                  ON p.products_id=pa.products_id
 406                                  LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 407                                  ON pa.products_attributes_id=pad.products_attributes_id
 408                                  WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
 409  // Will work with only one option for downloadable products
 410  // otherwise, we have to build the query dynamically with a loop
 411              $products_attributes = $order->products[$i]['attributes'];
 412              if (is_array($products_attributes)) {
 413                $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
 414              }
 415              $stock_query = tep_db_query($stock_query_raw);
 416            } else {
 417              $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 418            }
 419            if (tep_db_num_rows($stock_query) > 0) {
 420              $stock_values = tep_db_fetch_array($stock_query);
 421  // do not decrement quantities if products_attributes_filename exists
 422              if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
 423                $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
 424              } else {
 425                $stock_left = $stock_values['products_quantity'];
 426              }
 427              tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 428              if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
 429                tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 430              }
 431            }
 432          }
 433  
 434  // Update products_ordered (for bestsellers list)
 435          tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 436  
 437  //------insert customer choosen option to order--------
 438          $attributes_exist = '0';
 439          $products_ordered_attributes = '';
 440          if (isset($order->products[$i]['attributes'])) {
 441            $attributes_exist = '1';
 442            for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
 443              if (DOWNLOAD_ENABLED == 'true') {
 444                $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename
 445                                     from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 446                                     left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 447                                     on pa.products_attributes_id=pad.products_attributes_id
 448                                     where pa.products_id = '" . $order->products[$i]['id'] . "'
 449                                     and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'
 450                                     and pa.options_id = popt.products_options_id
 451                                     and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'
 452                                     and pa.options_values_id = poval.products_options_values_id
 453                                     and popt.language_id = '" . $languages_id . "'
 454                                     and poval.language_id = '" . $languages_id . "'";
 455                $attributes = tep_db_query($attributes_query);
 456              } else {
 457                $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
 458              }
 459              $attributes_values = tep_db_fetch_array($attributes);
 460  
 461              $products_ordered_attributes .= "\n\t" . $attributes_values['products_options_name'] . ' ' . $attributes_values['products_options_values_name'];
 462            }
 463          }
 464  //------insert customer choosen option eof ----
 465          $total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']);
 466          $total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
 467          $total_cost += $total_products_price;
 468  
 469          $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
 470        }
 471  
 472  // lets start with the email confirmation
 473        $email_order = STORE_NAME . "\n" .
 474                       EMAIL_SEPARATOR . "\n" .
 475                       EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" .
 476                       EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n" .
 477                       EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
 478        if ($order->info['comments']) {
 479          $email_order .= tep_db_output($order->info['comments']) . "\n\n";
 480        }
 481        $email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
 482                        EMAIL_SEPARATOR . "\n" .
 483                        $products_ordered .
 484                        EMAIL_SEPARATOR . "\n";
 485  
 486        for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
 487          $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
 488        }
 489  
 490        if ($order->content_type != 'virtual') {
 491          $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" .
 492                          EMAIL_SEPARATOR . "\n" .
 493                          tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
 494        }
 495  
 496        $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
 497                        EMAIL_SEPARATOR . "\n" .
 498                        tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
 499  
 500        if (is_object($$payment)) {
 501          $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" .
 502                          EMAIL_SEPARATOR . "\n";
 503          $payment_class = $$payment;
 504          $email_order .= $payment_class->title . "\n\n";
 505          if ($payment_class->email_footer) {
 506            $email_order .= $payment_class->email_footer . "\n\n";
 507          }
 508        }
 509  
 510        tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 511  
 512  // send emails to other people
 513        if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
 514          tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 515        }
 516  
 517  // load the after_process function from the payment modules
 518        $this->after_process();
 519  
 520        $cart->reset(true);
 521  
 522  // unregister session variables used during checkout
 523        tep_session_unregister('sendto');
 524        tep_session_unregister('billto');
 525        tep_session_unregister('shipping');
 526        tep_session_unregister('payment');
 527        tep_session_unregister('comments');
 528  
 529        tep_session_unregister('cart_Sofortueberweisung_Direct_ID');
 530  
 531        tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
 532      }
 533  
 534      function after_process() {
 535         return false;
 536      }
 537  
 538      function get_error() {
 539        global $HTTP_GET_VARS;
 540  
 541        $error = array('title' => MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_ERROR_HEADING,
 542                       'error' => MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_TEXT_ERROR_MESSAGE);
 543  
 544        return $error;
 545      }
 546  
 547  
 548      function check() {
 549        if (!isset($this->_check)) {
 550          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_STATUS'");
 551          $this->_check = tep_db_num_rows($check_query);
 552        }
 553        return $this->_check;
 554      }
 555  
 556      function install() {
 557        global $HTTP_GET_VARS;
 558  
 559        $kdnr = (isset($HTTP_GET_VARS['kdnr']) && !empty($HTTP_GET_VARS['kdnr'])) ? tep_db_prepare_input($HTTP_GET_VARS['kdnr']) : '10000';
 560        $projekt = (isset($HTTP_GET_VARS['projekt']) && !empty($HTTP_GET_VARS['projekt'])) ? tep_db_prepare_input($HTTP_GET_VARS['projekt']) : '500000';
 561        $input_passwort = (isset($HTTP_GET_VARS['input_passwort']) && !empty($HTTP_GET_VARS['input_passwort'])) ? tep_db_prepare_input($HTTP_GET_VARS['input_passwort']) : '';
 562        $bna_passwort = (isset($HTTP_GET_VARS['bna_passwort']) && !empty($HTTP_GET_VARS['bna_passwort'])) ? tep_db_prepare_input($HTTP_GET_VARS['bna_passwort']) : '';
 563        $cnt_passwort = (isset($HTTP_GET_VARS['cnt_passwort']) && !empty($HTTP_GET_VARS['cnt_passwort'])) ? tep_db_prepare_input($HTTP_GET_VARS['cnt_passwort']) : '';
 564  
 565        $check_query = tep_db_query("select orders_status_id from " . TABLE_ORDERS_STATUS . " where orders_status_name = 'Sofortüberweisung Vorbereitung' limit 1");
 566  
 567        if (tep_db_num_rows($check_query) < 1) {
 568          $status_query = tep_db_query("select max(orders_status_id) as status_id from " . TABLE_ORDERS_STATUS);
 569          $status = tep_db_fetch_array($status_query);
 570  
 571          $status_id = $status['status_id']+1;
 572  
 573          $languages = tep_get_languages();
 574  
 575          for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
 576            tep_db_query("insert into " . TABLE_ORDERS_STATUS . " (orders_status_id, language_id, orders_status_name) values ('" . $status_id . "', '" . $languages[$i]['id'] . "', 'Sofortüberweisung Vorbereitung')");
 577          }
 578  
 579          $flags_query = tep_db_query("describe " . TABLE_ORDERS_STATUS . " public_flag");
 580          if (tep_db_num_rows($flags_query) == 1) {
 581            tep_db_query("update " . TABLE_ORDERS_STATUS . " set public_flag = 0 and downloads_flag = 0 where orders_status_id = '" . $status_id . "'");
 582          }
 583        } else {
 584          $check = tep_db_fetch_array($check_query);
 585  
 586          $status_id = $check['orders_status_id'];
 587        }
 588  
 589        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Sofortüberweisung direkter Modus aktivieren', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_STATUS', 'True', 'Bezahlung per Sofortüberweisung acceptieren?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now());");
 590        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Kundennummer:', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_KDNR', '" . (int)$kdnr . "', 'Ihre Kundennummer bei der Sofortüberweisung', '6', '1', now());");
 591        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Projektnummer:', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PROJEKT', '" . (int)$projekt . "', 'Die verantwortliche Projektnummer bei der Sofortüberweisung, zu der die Zahlung gehört', '6', '1', now());");
 592        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Input-Passwort:', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_INPUT_PASSWORT', '" . tep_db_input($input_passwort) . "', 'Das Input-Passwort (unter Nicht änderbare Parameter / Input-Passwort)', '6', '1', now());");
 593        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Benachrichtigung-Passwort:', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_BNA_PASSWORT', '" . tep_db_input($bna_passwort) . "', 'Das Benachrichtigung-Passwort (unter Benachrichtigungen festlegen)', '6', '1', now());");
 594        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Contentpasswort:', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_CNT_PASSWORT', '" . tep_db_input($cnt_passwort) . "', 'Das Contentpasswort (unter Content-Passwort)', '6', '1', now());");
 595        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
 596        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
 597        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Preparing Order Status', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PREPARE_ORDER_STATUS_ID', '" . (int)$status_id . "', 'Order Status vor Eingang Bestellung', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
 598        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID', '0', 'Order Status nach Eingang Bestellung', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
 599        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Store Transactiondetails', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_STORE_TRANSACTION_DETAILS', 'False', 'Transactionsdetails bei Benachrichtigung in das Kommentarfeld speichern (zum debuggen, ist für Kunden via Konto sichtbar)', '6', '2', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now());");
 600      }
 601  
 602      function remove() {
 603        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 604      }
 605  
 606      function keys() {
 607        return array('MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_STATUS', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_KDNR', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PROJEKT', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_INPUT_PASSWORT', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_BNA_PASSWORT', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_CNT_PASSWORT', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_STORE_TRANSACTION_DETAILS', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ZONE', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_PREPARE_ORDER_STATUS_ID', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_ORDER_STATUS_ID', 'MODULE_PAYMENT_SOFORTUEBERWEISUNG_DIRECT_SORT_ORDER');
 608      }
 609    }
 610  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7