Increase Session Timeout

Tired of working in the Admin, taking a break and then having to sign back in. Want to accommodate customers who sign on, put stuff in the cart then go watch a movie before checking out? Well, just increase the session timeout period. You’ll need to do it separately for the catalog and the admin.

For the admin, open admin/includes/functions/sessions.php, find the code below and change the number, which is the seconds before you are timed-out, to something larger:

if (STORE_SESSIONS == 'mysql') {
if (!$SESS_LIFE = get_cfg_var('session.gc_maxlifetime')) {
$SESS_LIFE = 1440;
}

For the catalog do the same thing in includes/functions/sessions.php.

Copied from the OSCommerce forum:
session timeout

Improved Customer Sort

Improve customer sorting in the admin. Stock OSCommerce simply displays a static alphabetical customer list in admin>orders>customers. This old contribution originally posted on the OSCommmerce site in 2002 by Burt and just recently updated 9/20/2011 by D-Woo allows up and down sorting by first and last name and by date the account was created.

It’s really easy to install, just replace admin/customers.php and upload two images.

Secure Your Images file

Protect your images folder with this simple .htaccess file.

Create a blank file, add this code to it, name it .htaccess and upload to your images file:

<FilesMatch "\.(php(&#91;0-9&#93;|s)?|s?p?html|cgi|pl|exe){:content:}quot;>
Order Deny,Allow
Deny from all
</FilesMatch>

This prevents any files with .php or .exe or .cgi to be executed. In other words unauthorized hacker files. For a little bit more read the full thread on the oscommerce site.

Mail Manager for OSCommerce: Description

Mail Manager is a comprehensive mail program for OSCommerce. Designed for 2.2RC2a and OSC 2 CSS.
Purpose:

  1. Send all emails both in html and in text.
  2. Allow editing and templating of all emails, to include order confirmation, create account, password forgotten, status update, and tell a friend emails from the admin
  3. Add a post sales email marketing ability to OSCommerce
  4. Modulate the rate that emails are sent

Emails that can be edited and templated from the admin include the emails that are initiated when a customer create an account, completes an order, requests a password, sends a ‘tell a friend’ email, recieves when an order status is updated, the single emails sent directly from the admin to a customer, and the newsletters.

Mail Manager:

  1. Mail manager allows the shop owner to create and edit all emails from the admin with both an html and a text alternative, to allow professional and readable emails to be produced.
  2. To create a consistent look, templates can be produced in the admin that can be applied to all emails.
  3. A bulkmail module is included that allows the rate that OSCommerce sends email and newsletters to be adjusted. The rate is in seconds per email. This allows shops on shared web-hosting account to send large mailings without exceeding band-width limitations.
  4. The bulkmail module also contains a special feature that allows the sending of marketing emails to customer that have recently made a purchase. This email contains an orders product listing, to include images and links to ‘write a review’, and also contains cross sold items. (if the xsell module is installed).
  5. Mail Manager adds product images to the customer initiated tell_a_friend email.
  6. A search feature is added to the admin email that makes it simple to locate a customer and send them note, etc on a templated email.

Mail Manager Installation

Mail Manager for OSCommerce:
Installation Instructions

Files required for installation can be downloaded from:
The OSCommerce site.

Mail Manager Description

installation:

  • open catalog/includes/languages/english/checkout_process.php, add:define('EMAIL_TEXT_CONFIRM', 'has recommended');
    define('TEXT_FROM', 'from');
  • open/admin/includes/languages/english.php add://mail manager
    define('BOX_HEADING_MAIL_MANAGER', 'Mail Manager');
    define('BOX_MM_BULKMAIL', 'BulkMail Manager');
    define('BOX_MM_TEMPLATES', 'Template Manager');
    define('BOX_MM_EMAIL', 'Send Email');
    define('BOX_MM_RESPONSEMAIL', 'Response Mail');
  • open admin/includes/filenames.php
    add://MAIL MANAGER
    define('FILENAME_MM_RESPONSEMAIL', 'mm_responsemail.php');
    define('FILENAME_MM_TEMPLATES', 'mm_templates.php');
    define('FILENAME_MM_BULKMAIL', 'mm_bulkmail.php');
    define('FILENAME_MM_EMAIL', 'mm_email.php');
  • open admin/includes/database_tables.php
    add:///Mail Manager
    define('TABLE_MM_RESPONSEMAIL', 'mm_responsemail');
    define('TABLE_MM_RESPONSEMAIL_RESTORE', 'mm_responsemail_backup');
    define('TABLE_MM_RESPONSEMAIL_RESET', 'mm_responsemail_reset');
    define('TABLE_MM_TEMPLATES', 'mm_templates');
    define('TABLE_MM_NEWSLETTERS', 'mm_newsletters');
  • open admin/includes/column_left.php add:
    include(DIR_WS_BOXES . 'mail_manager.php');
    just below include(DIR_WS_BOXES . 'modules.php');
  • open admin/includes/classes/email.php, add at the bottom before the closing ?> tag:// eliminate line feeds as <br>
    class emailMailManager extends email {
    function add_html($html, $text = NULL, $images_dir = NULL) {
    $this->html = $html; //tep_convert_linefeeds(array("\r\n", "\n", "\r"), '<br>', $html);
    $this->html_text = tep_convert_linefeeds(array("\r\n", "\n", "\r"), $this->lf, $text);
    if (isset($images_dir)) $this->find_html_images($images_dir);
    }
    }
  • open admin/includes/functions/general.php
    just above the closing ?> tag at the bottom of the page add:///////////////////start mail manager////////////////////////////////////////start mail manager////////////////////////////////////////start mail manager/////////////////////
    function tep_mm_set_mailstatus($mail_id, $status) {
    if ($status == '1') {
    return tep_db_query("update " . TABLE_MM_RESPONSEMAIL . " set status = '1' where mail_id = '" . (int)$mail_id . "'");
    } elseif ($status == '0') {
    return tep_db_query("update " . TABLE_MM_RESPONSEMAIL . " set status = '0' where mail_id = '" . (int)$mail_id . "'");
    } else {
    return -1;
    }
    }

    //mail it
    function tep_mm_sendmail($mail, $email_address, $sender_name, $sender, $output_subject, $output_content_html, $output_content_txt) {
    $mimemessage = new emailMailManager(array('X-Mailer: cat/mail_manager.com'));
    // add html and alternative text version
    $mimemessage->add_html($output_content_html, $output_content_txt);
    $mimemessage->build_message(); // encoding -> 76 character linebreak, replacements must be done before
    $mimemessage->send($mail, $email_address, $sender_name, $sender, $output_subject, $output_content_html, $output_content_txt);
    }///////////////////end mail manager////////////////////////////////////////end mail manager////////////////////////////////////////end mail manager/////////////////////

  • open catalog/includes/classes/email.php, add at the bottom before the closing ?> tag:// eliminate line feeds as <br>
    class emailMailManager extends email {
    function add_html($html, $text = NULL, $images_dir = NULL) {
    $this->html = $html; //tep_convert_linefeeds(array("\r\n", "\n", "\r"), '<br>', $html);
    $this->html_text = tep_convert_linefeeds(array("\r\n", "\n", "\r"), $this->lf, $text);
    if (isset($images_dir)) $this->find_html_images($images_dir);
    }
    }
  • open catalog/includes/database_tables.php
    add:///Mail Manager
    define('TABLE_MM_RESPONSEMAIL', 'mm_responsemail');
    define('TABLE_MM_RESPONSEMAIL_RESTORE', 'mm_responsemail_backup');
    define('TABLE_MM_RESPONSEMAIL_RESET', 'mm_responsemail_reset');
    define('TABLE_MM_TEMPLATES', 'mm_templates');
    define('TABLE_MM_BULKMAIL', 'mm_bulkmail');
  • open admin/includes/column_left.php add:
    include(DIR_WS_BOXES . 'mail_manager.php');
    just below include(DIR_WS_BOXES . 'modules.php');
  • open catalog/includes/functions/general.php
    just above the closing ?> tag at the bottom of the page add:///////////////////start mail manager////////////////////////////////////////start mail manager////////////////////////////////////////start mail manager/////////////////////
    //
    // Sets the status of a mail item
    function tep_mm_set_mailstatus($mail_id, $status) {
    if ($status == '1') {
    return tep_db_query("update " . TABLE_MM_RESPONSEMAIL . " set status = '1' where mail_id = '" . (int)$mail_id . "'");
    } elseif ($status == '0') {
    return tep_db_query("update " . TABLE_MM_RESPONSEMAIL . " set status = '0' where mail_id = '" . (int)$mail_id . "'");
    } else {
    return -1;
    }
    }
    //sends it
    function tep_mm_sendmail($mail, $email_address, $sender_name, $sender, $output_subject, $output_content_html, $output_content_txt) {
    $mimemessage = new emailMailManager(array('X-Mailer: ad/mail_manager.com'));
    // add html and alternative text version
    $mimemessage->add_html($output_content_html, $output_content_txt);
    $mimemessage->build_message(); // encoding -> 76 character linebreak, replacements must be done before
    $mimemessage->send($mail, $email_address, $sender_name, $sender, $output_subject, '');
    }
    ///////////////////end mail manager////////////////////////////////////////end mail manager////////////////////////////////////////end mail manager/////////////////////
  • open catalog/tell_a_friend.php.
    1. About line 35 change:
      $product_info_query = tep_db_query("select pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");

      to:
      $product_info_query = tep_db_query("select p.products_image, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");

      ( or simply add p.products_image to the query)
    2. About line 100 change:
      tep_mail($to_name, $to_email_address, $email_subject, $email_body, $from_name, $from_email_address);

      to//*******start mail manager***************//
      if (file_exists(DIR_WS_MODULES.'mail_manager/tell_a_friend.php')){
      include(DIR_WS_MODULES.'mail_manager/tell_a_friend.php');
      }else{
      tep_mail($to_name, $to_email_address, $email_subject, $email_body, $from_name, $from_email_address);
      }
      //*******end mail manager*****************//
  • open admin/orders.php. About line 85 change:
    tep_mail($check_status['customers_name'], $check_status['customers_email_address'], EMAIL_TEXT_SUBJECT, $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

    to:
    //*******start mail manager****************//
    if (file_exists(DIR_FS_CATALOG_MODULES.'mail_manager/status_update.php')){
    include(DIR_FS_CATALOG_MODULES.'mail_manager/status_update.php');
    }else{
    tep_mail($check_status['customers_name'], $check_status['customers_email_address'], EMAIL_TEXT_SUBJECT, $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
    }
    //********end mail manager****************//
  • open catalog/create_account.php. About line 210 change: tep_mail($name, $email_address, EMAIL_SUBJECT, $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

    to:
    //*******start mail manager**************//
    if (file_exists(DIR_WS_MODULES.'mail_manager/create_account.php')){
    include(DIR_WS_MODULES.'mail_manager/create_account.php');
    }else{
    tep_mail($name, $email_address, EMAIL_SUBJECT, $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
    }
    //*******end mail manager****************//
  • open catalog/checkout_process.php
    1. about line 350 change:
      tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

      to:
      //*******start mail manager****************//
      if (file_exists(DIR_WS_MODULES.'mail_manager/order_confirm.php')){
      include(DIR_WS_MODULES.'mail_manager/order_confirm.php');
      }else{
      tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
      }
      //*******end mail manager*****************//
    2. about line 245 change
      $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";


      to
      $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".'<br />';
      (add a break tag)
  • open catalog/password_forgotten change
    tep_mail($check_customer['customers_firstname'] . ' ' . $check_customer['customers_lastname'], $email_address, EMAIL_PASSWORD_REMINDER_SUBJECT, sprintf(EMAIL_PASSWORD_REMINDER_BODY, $new_password), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

    to //*******start mail manager
    if (file_exists(DIR_WS_MODULES.'mail_manager/password_forgotten.php')){
    include(DIR_WS_MODULES.'mail_manager/password_forgotten.php');
    }else{
    tep_mail($check_customer['customers_firstname'] . ' ' . $check_customer['customers_lastname'], $email_address, EMAIL_PASSWORD_REMINDER_SUBJECT, sprintf(EMAIL_PASSWORD_REMINDER_BODY, $new_password), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
    }
    //*******end mail manager
  • Upload the files and folders in the folder mail_managers folder. All folders and files are new.
  • Import the sql database file. It adds 5 tables to your database, and does not change any existing tables or configuration. It also loads several sample templates.
  • Create a new field, mmstatus, in the Database in the customers table. The mmstatus.sql file contains command to use in phpmyadmin to create this. This command is posted below:ALTER TABLE `customers` ADD `mmstatus` CHAR( 2 ) NOT NULL AFTER `customers_newsletter`

Recently Viewed Products Infobox for OSCommerce

for: OSC 2 CSS.

The following code yields a new infobox that displays the last four items viewed. Adapted from this OSCommerce Contribution to fit OSC 2 CSS. Caveat: I have had mixed success with rendering product urls but you can see a successful demo at www.niora.com. View some products and they start showing up in a box in the right hand column. What is unique about this code is that does not use database queries to display the products.

Installation:

2) Add the following command to the left or right column where you want the box to appear.

require(DIR_WS_BOXES . 'recently_viewed.php');

1) create a new file, recently_viewed.php. Paste the following code into this file and upload the file to the includes/boxes folder.

<?php
// Lets set the number of history items to display
$display_count = 4;
$action = (isset($_GET&#91;'action'&#93;) ? $_GET&#91;'action'&#93; : '');
if ($action == 'clear_history') {
unset($_SESSION&#91;'last_product_views'&#93;);
}
// Build history string
$last_product_views = $_SESSION&#91;'last_product_views'&#93;;
if ($last_product_views != "") {
$visited_array = explode('|', $_SESSION&#91;'last_product_views'&#93;);
$output_count = 1; 
foreach ($visited_array as $visited_array_item) {
$visited_item = trim($visited_array_item);
if ( ($visited_item != "") && ($output_count <= $display_count) ) {
$item_pieces = explode("^", $visited_item);
$item_image = trim($item_pieces&#91;0&#93;);
$item_name = trim($item_pieces&#91;1&#93;);
$item_url = trim($item_pieces&#91;2&#93;);
$visited_output .= '';
$last_visited_thumb = tep_image(DIR_WS_IMAGES . $item_image, $item_name, '75', '75');
$visited_output .= '<div class="pl-image"><a href="http://' . $item_url . '">' . $last_visited_thumb . '</a></div><div class="pl-name"><a href="http://' . $item_url . '">' . $item_name.'</a><br></div>';
$visited_output .= '';
$output_count++;
}
}
}
// Now look at the current page
if (basename($_SERVER['SCRIPT_NAME']) == "product_info.php") {
// First remove the action=clear_history from the url
$current_product_path = str_replace('&action=clear_history', '', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
//$pieces = explode("?osCsid", $current_product_path);
//$current_product_path = $pieces[0];
$new_array_item = $product_info['products_image'] . '^' . $product_info['products_name']. '^' . $current_product_path;
// and add it to the $_SESSION variable
$last_product_views = $_SESSION['last_product_views'];
if ($last_product_views == "") {
$_SESSION['last_product_views'] = trim($new_array_item);
} else {
$items_array = explode('|', $_SESSION['last_product_views']); 
$count = 1;
$new_array_string = '';
foreach ($items_array as $array_item) {
if ($count <= $display_count) {
$array_item = trim($array_item);
if ($array_item != "") {
if ($array_item != $new_array_item) {
$new_array_string .= "|" . $array_item;
$count++;
} 
}
}
}
$_SESSION&#91;'last_product_views'&#93; = $new_array_item . '|' . $new_array_string;
}
}
// Display history string to browser
if ($last_product_views != "") {
$info_box_contents = array();
$info_box_contents&#91;&#93; = array('text' => '<hr><div class="align_left"><strong>Last Viewed</strong></div>');
new cssinfoBoxHeading($info_box_contents, 'true', 'true', tep_href_link($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], tep_get_all_get_params(array('action')) . 'action=clear_history'));

$info_box_contents = array();
$info_box_contents[] = array('text' => $visited_output);
// new plcontentBox($info_box_contents);
new cssinfoBox($info_box_contents);
} // end if ($last_product_views != "")
?>

Account Tabs for OSC to CSSv2

On OCS to CSS this combines the files address_book.php, account_edit.php, account_history.php and account_password.php into one file, account.php. The information is accessed with JQuery tabs for really intuitive and easy navigation. Download this file, account.php and the required CSS file from google.code

Requires the main JQuery file and the JQuery UI file. You will need to be prepared to make adjustments to the html.

Screenshots:

Address Book Tab
Click to enlarge


Address Book Tab
Edit Account Tab
Click to enlarge


Edit Account Tab
Password Tab
Click to enlarge


Password Tab
Order History Tab
Click to enlarge


Order History Tab

Download the Files

OSCommerce: 3.0 vs 2.3 vs OSC to CSS

What version to use?

  • V3.0

    OSCommerce 3.0 represents an entirely new modular structure. It has updated security features, and a nicer admin and much more. However, it is virtually featureless, a bare bones core, that is not ready for non-developers to use. Many people will find that their web hosts do not have the latest version of php, which 3.0 requires. The thousands of great contributions available for 2.2RC2a will not work on 3.0

  • V2.3

    OSCommerce 2.3 is the first version to get rid of the outmoded OSCommerce table structure, and it incorporates important security features. It has an improved admin. It is different enough from 2.2RC2a that many of the contributions available for 2.2RC2a will not work. Plus the incorporation of the tableless CSS structure is not complete, and awkwardly implemented. For example, it is difficult to add javascript or unique stylesheets to individual pages.

  • OSC to CSS

    OSC to CSS has all the advantages of 2.2RC2a, has the table structure replaced with a superior incorporation of CSS. It some nice JQuery features installed to include a horizontal category menu, pretty photo, and a Json coded ‘add to cart’ feature. The admin and database structure are unchanged from 2.2RC2a so nearly all the contributions available for 2.2RC2a work on OSC to CSS. It just takes a bit of creative html work on the catalog side. An it is not difficult to install the 2.3 security features. This link explains how: update 2.2RC2a security

In summary, OSC to CSS is fast and simple with thousands of contributions available, uses a great tableless structure, has an updated modern look as downloaded, and the security features for 2.3 can easily be incorporated.

Parsing a URL

    • Parsing a url

    • Echo a url. Here is an example of a webpage with a query string attached:
      $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'];
      echo $url;

      example result: http://www.mywebsite.com/mail.php?f2fc1b9ecc1986f34588fd=listAudience&modulemail

    • Echo just the query string of the url:
      echo $_SERVER['QUERY_STRING'];

      example result: f2fc1b9ecc1986f34588fd=listAudience&modulemail

    • Echo just some portion of the query string of the url, in this case everything after the ‘=’
      echo preg_match('/listAudience&modulemail$/i', $_SERVER['QUERY_STRING'];

      example result: listAudience&modulemail

      courtesy of: http://www.daniweb.com/forums/thread16687.html

Registering, or Setting, a Value in OSCommerce.

Set a value on one page that is available for another page, or anywhere on the site:

  1. For example, to set the value of $myvar as ‘delorum ipsum’:
    <?php
      $myvar = 'delorum ipsum'; // give it a value here
      if ( ! tep_session_is_registered('myvar') ) {
        tep_session_register('myvar');
      }
    ?>
    

    In plain english this says:
    Make $myvar equal delorum ipsum, and if $myvar is not already registered or been set to equal delorum ipsum in the website, make it equal to delorum ipsum everywhere in the website.

  2. One the page you wish to carry that value to, simply echo the variable, ‘$myvar’ . In other words, below will print ‘delorum ipsum’.
    echo $myvar;
    
  3. When you no longer need the value, unregister it like so:
    tep_session_unregister('myvar');

This is done to allow information, that can come from the database or a form, to follow a customer as they navigate unpredictably through the shop. Here are some examples from OSCommerce:

  • Open login.php
    near the top you see these lines:

    tep_session_register('customer_id');
            tep_session_register('customer_default_address_id');
            tep_session_register('customer_first_name');
            tep_session_register('customer_country_id');
            tep_session_register('customer_zone_id');</code>
    </li>These are all values pulled from the database. 
    <li>Later on in catalog/checkout_shipping.php if the customer makes some comments on the form on that page, the comments get registered, and becomes the value of the variable  '$comments'.</li>
    tep_session_register('comments');
  • Open catalog/logoff.php: When the customer signs out, all this happens.
     tep_session_unregister('customer_id');
      tep_session_unregister('customer_default_address_id');
      tep_session_unregister('customer_first_name');
      tep_session_unregister('customer_country_id');
      tep_session_unregister('customer_zone_id');
      tep_session_unregister('comments');
  • This unregisters all the values that have been attached to those variables, because they are no longer needed.