From the category archives:

Web Programming

Replace column substring SQL Server columns

by Caroline on June 21, 2007

Replace all instances of FINDTHIS with REPLACEWITHTHIS in columns COLUMN1 and COLUMN2 of table TABLE where those substrings are in fact found

update TABLE set
COLUMN1=REPLACE(COLUMN1,’FINDTHIS’,'REPLACEWITHTHIS’),
COLUMN2=REPLACE(COLUMN2,’FINDTHIS’,'REPLACEWITHTHIS’)
from TABLE
where
COLUMN1 like ‘%SUBSTRINGPIECE%’ or COLUMN2 like ‘%SUBSTRINGPIECE%’

{ 0 comments }

Zen Cart UPS XML does not work with zones

by Caroline on April 2, 2007

You’re here because you want to run UPS XML for Zen Cart with zones. It configures ok if you have no zones set, but as soon as you add a zone it displays the “unconfigured” yellow icon.

The admin and the catalog both use the same code to determine if a UPS rate exists. The problem is, the admin doesn’t care about where that zone is, but the shipping checkout wants it to match the recipient’s zone. So by definition the admin can never be configured because it never matches an empty “order” zone, there’s no concept of an order on the admin end but the admin will not mark the UPS xml as “configured” until it matches this ghost zone.

It might configure ok in your store, but only if it’s set to “no zone,” which means it’ll show up for any destination whether you want it to or not. As soon as you try to add a zone it refuses to configure.

The fact is that whole paragraph of code was off, I wonder if people are using this module successfully. There’s NO WAY you could ever have configured it to do zones!

Change includes/modules/shipping/upsxml.php (upsxml.php,v 1.1.4 2004/12/19) right after the curl code setup to the following:

if (($this->enabled == true) && ((int)MODULE_SHIPPING_UPSXML_RATES_ZONE > 0)) {
$this->enabled=false;
if (empty($order->delivery['country']['id'])) {
$admin=true; }else{$admin=false;
}
/*
$check = $db->Execute(”select zone_id from ” . TABLE_ZONES_TO_GEO_ZONES . ” where geo_zone_id = ‘” . MODULE_SHIPPING_UPSXML_RATES_ZONE . “‘ and zone_country_id = ‘” . $order->delivery['country']['id'] . “‘ order by zone_id”);
*/
if ($admin) {
$sql = “select zone_id from ” . TABLE_ZONES_TO_GEO_ZONES . ” where geo_zone_id = ‘” . MODULE_SHIPPING_UPSXML_RATES_ZONE.”‘”;
} else {
$sql = “select zone_id from ” . TABLE_ZONES_TO_GEO_ZONES . ” where zone_id=’”. $order->delivery['zone_id'] . “‘ and geo_zone_id = ‘” . MODULE_SHIPPING_UPSXML_RATES_ZONE . “‘”;
}

$check = $db->Execute($sql);
if (!$check->EOF) {
$this->enabled = true;
}
}

{ 0 comments }

Programmatically determine Joomla homepage

by Caroline on March 17, 2007

If both mod_rewrite and 301’s are out in full force the home page is not going to be identifiable by a Server query_string containing “frontpage.” To determine if the current code is on the home page:

$s = filter_var($_REQUEST['QUERY_STRING'], FILTER_SANITIZE_SPECIAL_CHARS);
if (empty($s)) {

//you’re on the home page

}

{ 0 comments }

VirtueMart Authorize.net Code Changes

by Caroline on February 26, 2007

VirtueMart does not automate Authorize.net test mode. It doesn’t read classes/payment/ps_authorize.cfg.php AN_TEST_REQUEST to see if it should send test mode to Authorize.Net. A quick fix, alter

FILE CHANGE classes/ps_checkout.php lines 24, 159, 484
line 24:
define (TESTMODE,true);

Lines 159, 484, call validate with TESTMODE rather than hard-coded “false.”
159:
if ( !$this->validate_payment_method( $d, TESTMODE )) {
484:
if (!$this->validate_payment_method($d, TESTMODE)) { //Change false to true to Let the user play with the VISA Testnumber

{ 0 comments }

 ”the physical file name” “may be incorrect”RESTORE DATABASE DBName
FROM DISK = ‘C:\mypath\backedUpDb.bak’
WITH
MOVE
‘backedUpDb_dat’ TO ‘C:\mypath\DBName.mdf’,
MOVE ‘backedUpDb_log’ TO ‘C:\mypath\DBName.ldf’
GO

Where
DBName is the name the db will have on your local machine
backedUpDb.bak is the backup with the wrong physical path
backedUpDb_dat and backedUpDb_log are described below
mdf and ldf are the names and locations you want DBName to have after restoration

 Get backedUpDb_dat from:
SQL Enterprise or Management Studio
Databases
Restore Database
To Database [DBName]
From Device: [click ...]
Backup Media
File
Add
Browse to backedUpDb.bak
OK
Select Restore checkbox
Options
The Original Filename is you backedUpDb_dat and backedUpDb_log
Options
 

 

{ 0 comments }

VirtueMart Product Details Page SEO Title Tags

by Caroline on September 27, 2006

 In administrator/components/com_virtuemart/html/shop.product_details.php, add the category name to the page title

{ 0 comments }

VirtueMart Category Page SEO Title Tags

by Caroline on September 27, 2006

In order to set keyword-rich title tags on a VirtueMart category listing page:

In administrator/components/com_virtuemart/html/shop.index_sdm.php (your mileage may vary on file name), add and initialize a $title variable in the top:

After setting the category name, append the category to the title:


This presumes your shop.index page calls

{ 0 comments }

Answers the question:
How to redirect domains given tools .htaccess, parked domain redirect and Joomla component 404sef.

If you use Joomla and care at all about search engine rankings you’ll have to use a SEF translation of some kind. I chose 404sef and I’m grateful for what it does. Here’s how to get around something it doesn’t do, which is handling non-primary domains.
It will make Search Enging Friendly links for the current domain, but if you redirect a different domain to the 404Sef’d one the component will cough up a hair ball.

Setup:

  1. Joomla 1.0.10
  2. Siteground.com hosting cpanel with parked domains
  3. Global config: SEF on
  4. SEF404 config: SEF on
  5. secondary domains that need to redirect in a search engine friendly way to http://www.bombshelters.com/:

biologicalprotection.com
biologicalshelter.com
biologicalshelter.us
biologicalshelters.com
biologicalshelters.us
blastshelters.com
blastshelters.us
bombshelter.us
chemicalprotection.us
combatshelter.com
disastershelter.com
falloutshelter.us
governmentprotection.com
nbcshelter.com
nbcshelter.us
nuclearprotection.us
nuclearshelter.us
nuclearshelters.com
radiusdefense.com
radiusengineering.us
radiusengineeringinternational.com
radiusengineeringintl.com
radiusshelters.com
saferoomprotection.us
shelterengineering.com
shelterprotection.us
sheltersystems.us
survivalshelter.us
survivalshelters.us
undergroundshelter.us
undergroundshelterengineering.com
undergroundshelters.com
undergroundshelters.us
wmdprotection.us
Setup secondary domains to resolve to primary domain

These domains are all registered on network solutions. I changed the primary and secondary name servers on all of them to the siteground name server for bombshelters.com. Then on cpanel for bombshelters.com I used the “parked domains” tool to point each of the domains to bombshelters.com.

This worked, and then broken suddenly tonight. It actually probably broke when I installed 404SEF I just didn’t realize it.

Symptoms

I guess I had 404SEF off when I redirected the domains to the bombshelters.com name server because m initial tests worked great. You’d type undergroundshelter.us and the browser would display bombshelters.com content under the undergroundshelter.us address bar. When I tried that tonight I got “this page cannot be displayed.”

The pubic_html errorlog pointed to:

[24-Jul-2006 00:58:57] PHP Warning: strpos() []: Empty delimiter. in /home/bombshel/public_html/components/com_sef/sef404.php on line 83

[23-Jul-2006 23:04:24] PHP Fatal error: Call to undefined function: sefreltoabs() in /home/bombshel/public_html/components/com_content/content.html.php on line 584

Things that don’t fix the problem

  1. Turning off 404SEF: it fixes the problem but creates the old problem of unfriendly URLs
  2. Ensuring the strpos delimiter (and target) are not empty on sef404.php:
  3. [24-Jul-2006 00:58:57] PHP Warning: strpos() [function.strpos]: Empty delimiter. in /home/bombshel/public_html/components/com_sef/sef404.php on line 83

    bold line below is line 83

    if (!empty($pathdata) && (!empty($sefconfig->suffix)))

    {
    if (strpos($pathdata,$sefconfig->suffix) !== false)
    $path_array[$x] = str_replace($sefconfig->suffix,”",$pathdata);
    $x++;
    }

    This is fine as far as it goes, it’s good to test inputs before assuming they have content, but it addresses a symptom, not a problem.

  4. Similar to #2, defining sefRelAbs function against its will

]: Empty delimiter. in /home/bombshel/public_html/components/com_sef/sef404.php on line 83]: Empty delimiter. in /home/bombshel/public_html/components/com_sef/sef404.php on line 83content.html.php:
if (!function_exists(’sefRelToAbs’))
{
function sefRelToAbs($string) {}
}
What does work

In .htaccess rewrite any domain that is not http://www.bombshelters.com/ to be http://www.bombshelters.com/. Works for “bombshelters.com” (without www), “falloutshelter.us,” and etc. secondary domains.
RewriteCond %{HTTP_HOST} !bombshelters.com$ [NC]
RewriteRule ^(.*)$ http://bombshelters.com/$1 [L,R=301]

Big thank you to http://enarion.net/web/apache/htaccess/redirect-www-and-no-www/

 

{ 0 comments }

404SEF Joomla Directories-as-Filenames

by Caroline on July 22, 2006

Joomla’s 404SEF component can be tricky if you want to use directory names instead of file extensions, aka

http://www.bombshelters.com/Education/Biological-Bioterror-Weapons-Effects

not

http://www.bombshelters.com/Education/Biological-Bioterror-Weapons-Effects.html

First, lowercase is on by default. Second, default file extension of .html hurls your pages into deep space.

To hae both, go to 404 config, set All Lowercase to No, set File Suffix to a blank textbox.

{ 0 comments }

500 this page cannot be displayed

by Caroline on May 20, 2006

Of the many reasons you’ll see this page while running locally, one is forehead-slapping good.

Check the protocol for SSL (htts://)

{ 0 comments }