Dreamweaver error: while executing onLoad in RecordsetFind.htm, the following JavaScript error(s)

Are you getting the following errors message when using Dreamweaver CS4? (Note that it may happen to Dreamweaver Professional 8 and CS3 as well).

The following translators were not loaded due to errors:
_________.htm: has configuration information that is invalid.
….

In my case it also generate the following error message when you start and close dreamweaver.

while executing onLoad in RecordsetFind.htm, the following JavaScript error(s) occured:
In file “RecordsetFind”:
findRs is not defined

While executing onLoad in TeamAdminTempDelete.html, the following JavaScript error(s) occured:
In file “TeamAdminTempDelete”:
delTempFile is not defined

It turns out that there is something wrong with your Dreamweaver configuration files. It may be caused by file corrupt, or changes in your system.

To solve this you will have to remove the current configuration folders, so that Dreamweaver will generate new one for you. To do that, close your Dreamweaver and go to the following folder:

C:\Documents and Settings\YOUR_WINDOWS_USERNAME\Application Data\Adobe\Dreamweaver CS4\en_US

Rename the “Configuration” folder in to “Configuration-old”, and then fire up your Dreamweaver.

It should generate the new Configuration folder. Now you might loose your last configuration such as the sidebar width, last used view, etc.

Insert into / add element to array at specific position (PHP)

Usually, we can search and identify PHP function just by looking at it’s name which denotes what a function does. For example array_pop(), array_push(), array_search(), array_reverse(), etc. But how about inserting an element into the middle of an array?

array_splice(array &$input, int $offset [, int $length= 0 [, mixed $replacement]] ) is the function that you are looking for. Format to use this function to add new element at certain position in an array is array_splice($array, $insert_position, 0, $element_to_insert);. See below for an example of how this function behaves.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
$input = array("red", "green", "blue", "yellow");
array_splice($input, 2);
// $input is now array("red", "green")
 
$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, -1);
// $input is now array("red", "yellow")
 
$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, count($input), "orange");
// $input is now array("red", "orange")
 
$input = array("red", "green", "blue", "yellow");
array_splice($input, -1, 1, array("black", "maroon"));
// $input is now array("red", "green", "blue", "black", "maroon")
 
$input = array("red", "green", "blue", "yellow");
array_splice($input, 3, 0, "purple");
// $input is now array("red", "green", "blue", "purple", "yellow");
?>

Magento Layout Error after changing Base URL {{base_url}}

When I first login to admin menu on my Magento, I was bothered by this message at the top of my admin interface.

{{base_url}} is not recommended to use in a production environment to declare the Base Unsecure Url / Base Secure Url. It is highly recommended to change this value in your Magento configuration.

Well, most likely you will stumble upon this message on localhost installation. Please do not change this to uncorrect value or else… your Magento site will just break down. If you did it anyway, follow these steps:

  1. Go to your Magento database (you can use phpmyadmin) and open core_config_data table. Then find a row which has path = ‘web/unsecure/base_url’ and change the value back to {{base_url}}.
  2. Finally, to make it works you need to clear out any cache. Go to your magento installation, and open var folder, then delete the session folder (in other word, delete /magento/var/session).

Now, if you still want to update {{base_url}}, read this article http://www.magentocommerce.com/blog/comments/security-update-for-magento-base-url-configuration-value/. Well, in my opinion, Magento is premature product, so it is still fragile. You have to think twice before implement it on your production site.

What’s new in ZenCart 2.0.0

After a long time waiting, Zencart team will release the new Zen Cart v2.0.0. It was originally planned to be released at the end of 2008 but they will most likely to release the upcoming Zencart 2.0 release early this year. The following will cover what you can expect from new Zencart 2.0.0, which is a summary of what I got from Zencart forum (Comming soon Zencart 2.0.0).

Speed
An emphasis has been placed on improving performance by various methods, especially reducing the number of database queries required for processing pages.

Code
For the programmers, you’ll be happy to know that the code has been largely converted to a much more efficient OOP structure, which will ultimately end up making future growth much simpler.

Templating
Templating is much simpler, in that the complicated PHP blocks that used to make them so hard to read or follow or customize have been removed. Stylesheets are leaner. And there are some very easy-to-use admin-side layout controls to make setting your desired layouts *much* simpler.

Overrides
The same override system exists for templates and language files, meaning that those already familiar with that part of the directory structure will find it easy to continue using.

Languages
UTF-8 support is now native, and the more complicated language files have been simplified and split off into their own for easier management.

Written for PHP 5
Zen Cart 2.0 takes advantage of features specific to PHP 5.2 and MySQL 4.1, thus, those are the new minimum requirements for your hosting service to provide in order to run it. CURL is also highly recommended.

And Many More…

It’s time to move our system from Zencart 1.3.8 to Zencart 2.0.0 and for those who are planning to customize Zencart system, I would just recommend you to postpone it. So that you can implement the changes in Zencart 2.0.0 directly to reduce overhead cost.

Add custom Admin configuration field setting for Zencart

Have you created your own module for Zencart? And you would like to add configuration setting for your module, so that your client can configure your module via Admin area? Here is how to do that…

What I do usually is adding new group (with your module name) under Configuration in zencart administrator, then add fields under that group to be setup. Just like if you go to Configuration > My Store, you will find many settings there. All of this fields are declared inside your database, specifically inside zen_configuration_group and zen_configuration table (NB: zen_ is used as table prefix).

So let’s insert new row to your zen_configuration_group to create new group under “Configuration” menu. The following SQL script will add “My New Module” group under “Configuration” menu and position it in the last order. Use this script as template.

1
2
3
4
5
INSERT INTO configuration_group
(configuration_group_id, configuration_group_title, configuration_group_description, sort_order, visible)
VALUES (NULL, 'My New Module', 'My New Module Description....', '1', '1');
 
UPDATE configuration_group SET sort_order = last_insert_id() WHERE configuration_group_id = last_insert_id();

Secondly, to add config items under your new “Configuration > My New Module” use the following SQL

1
2
3
4
5
6
7
8
9
SET @last_id=0;
SELECT (@last_id:=configuration_group_id) AS last_id 
FROM configuration_group
WHERE configuration_group_title= 'My New Module';
 
INSERT INTO configuration 
(configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added)
VALUES 
('', 'Small Image Height', 'IMAGE_VIEWER_SMALL_IMAGE_HEIGHT','75','Description of Small Image Height Setting. Default 75.', @last_id, 1, now());

Note that to run this SQL smoothly without bothering with your zencart database table prefix, execute this script from zencart admin area Tools > Install SQL Patches.

Once you executed those SQL, you will find My New Module category under Configuration menu and Small Image Height setting inside that category. You can then access the value of this configuration from your module straight away by using configuration_key which you have set in your SQL (i.e. echo IMAGE_VIEWER_SMALL_IMAGE_HEIGHT). Please leave comment if you find any difficulties or feel grateful with this blog. Cheers.

Fix Invalid argument supplied for foreach() in cb.core.php on line 240

I come across this bug when I tried to edit user profile on my community builder v1.1 and Joomla 1.5. I found out that many people face the same problem at community builder forum, but unfortunately the forum is hard to navigate and finding the solution is like looking for needle in stack of straws. So here is the solution:

You will need to edit com_comprofiler/plugin/user/plug_cbcore/cb.core.php on around line 528 and 529. Do the following edit:

  1. Change this line “$params =& $juser->getParameters(); to “$params =& $juser->getParameters(true);
  2. Then comment out or remove this line “$params->loadSetupFile(JApplicationHelper::getPath( ‘com_xml’, ‘com_users’ ));”

There you are, now it won’t show any error message when you try to edit user profile in your community builder v1.1 and Joomla v1.5. Looking forward for CB v1.2.

This answer is courtesy of Jinx and can be found at http://forum.joomla.org/viewtopic.php?t=223385.

How to Create Multistep Form in Drupal 6 – Tutorial

CMS system will help us to quickly have the base system but it will limit our development if we are not familiar with the API. Multistep form is a form which has multiple pages of fields and the user should go through each page until at the end of the step. I will touch on how to turn Drupal 6 form into multistep/flowing form.

If you come across Drupal Form API you will realize that by default, the form is declared as associative arrays which are displayed in one page.
$form[‘field_id’] = array (
‘#type’ => ‘textfield’,
‘#title’ => t(‘The label of the input field’),
‘#size’ => 40,
‘#description’ => t(‘Description of the field which appear below input box’),
‘#required’ => TRUE);
);

For complete reference on Drupal 6 Form API visit this site:  http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6

The key to get multistep behavior of the form is by putting $form_state[‘rebuild’] = true; statement inside your form submit function. This statement will call again the function which renders the form when the user clicks submit. By manipulating form function to return different associative arrays we can get multistep form behavior.

The second important step is to store the form state values as we keep redrawing the form so that we do not lost the inputted values from previous step. We can do this inside form submit function and store the value in $form_state[‘storage’] since this is session based variable. $form_state[‘storage’][‘values’] = $form_state[‘values’]; Below is the snippet code example for multistep form in Drupal 6:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function mymodule_myform($form_state) {
   if (empty($form_state['storage']['values'])) {
      $form['firstname'] = array(
         '#type' =&gt; 'textfield',
         '#title' =&gt; t('First Name'),
         '#size' =&gt; 40,
         '#required' =&gt; TRUE
      );
   } else {
      $form['lastname'] = array(
         '#type' =&gt; 'textfield',
         '#title' =&gt; t('Last Name'),
         '#size' =&gt; 40,
         '#required' =&gt; TRUE
      );
   }
}
Function mymodule_myform_submit($form, &amp;$form_state) {
   if (empty($form_state['storage']['values'])) {
      // if there is no previous values redraw for second step
      $form_state['storage']['values'] = $form_state['values'];
      $form_state['rebuild'] = true;
   } else {
      // Form is on the second step, process the data here…
      $firstname = $form_state['storage']['values'][‘firstname’];
      $firstname = $form_state['storage']['values'][‘lastname’];.
   }
}

Above example will create two steps form, to create more steps you can create $form_state[‘storage’][‘step’] which will be assigned with the current step number. You could also use form alter hook mymodule_form_alter(&$form, $form_state, $form_id) to modify existing form.

Integrate Zencart 1.3.8 with phpbb3

These are steps to integrate zencart 1.3.8 with phpBB 3.0.1. These steps will ensure if a user create an account in Zencart, an account for the phpBB will also be created and your phpbb3 display appropriate Total number of user and Newest Member nickname at the board index.

1. Install your phpbb3 and ensure it runs perfectly.

2. Open your configure.php inside /includes folder of your Zen-Cart installation and edit this configuration define(‘DIR_WS_PHPBB’, ‘…..Your  Path to your phpbb3 ….’); with correct physical path to your phpbb installation. It must be your physical path! NOT your relative path. For example of physical path see your ‘DIR_FS_CATALOG’ value inside the same configure.php (ensure you have ‘/’ at the end of the path).

3. Enable link to your phpbb3 from your zencart administrator. Inside your zencart administrator go to “Configuration” -> “My Store” and set “Enable phpBB Linkage?” to TRUE.

4. edit class.phpbb.php inside your …/includes/classes folders. Try to find phpbb_create_account function and replace with the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function phpbb_create_account($nick, $password, $email_address) {
	if ($this-&gt;phpBB['installed'] != true || !zen_not_null($password) || !zen_not_null($email_address) || !zen_not_null($nick)) return false;
	if ($this-&gt;phpbb_check_for_duplicate_email($email_address) == 'already_exists') {
		// $this-&gt;phpbb_change_email($old_email, $email_address);
	} else {
		$sql = "select max(user_id) as total from " . $this-&gt;phpBB['users_table'];
		$phpbb_users = $this-&gt;db_phpbb-&gt;Execute($sql);
 
		$user_id = ($phpbb_users-&gt;fields['total'] + 1);
		$sql = "insert into " . $this-&gt;phpBB['users_table'] . "(user_id, group_id, username, username_clean, user_password, user_email, user_regdate) values ('" . (int)$user_id . "',2, '" . $nick . "', '" . $nick . "', '" . md5($password) . "', '" . $email_address . "', '" . time() ."')";
		$this-&gt;db_phpbb-&gt;Execute($sql);
 
		$sql = "update phpbb_config SET config_value = '{$user_id}' WHERE config_name = 'newest_user_id'";
		$this-&gt;db_phpbb-&gt;Execute($sql);
 
		$sql = "update phpbb_config SET config_value = '{$nick}' WHERE config_name = 'newest_username'";
		$this-&gt;db_phpbb-&gt;Execute($sql);
 
		$sql = "update phpbb_config SET config_value = config_value + 1 WHERE config_name = 'num_users'";
		$this-&gt;db_phpbb-&gt;Execute($sql);
 
		$sql = "INSERT INTO " . $this-&gt;phpBB['user_group_table'] . " (user_id, group_id, user_pending) VALUES ($user_id, 2, 0)";
		$this-&gt;db_phpbb-&gt;Execute($sql);
	}
}

5. Enjoy your nicely integrated phpbb3 forum with zencart. From now on, if a user register an account in Zen-Cart, they will be registered in PHPBB as well.

If you have follow my instruction correctly, now when you create new account in Zen-Cart you will be asked to provide “Forum Nick Name”. You can login in the forum using the Forum Nick Name you have provided and your Zencart password.

Optional: You can manually copy Zen-Cart account that has been setup previously to phpbb user database to integrate them. Next, you can create theme that reflect your store for your phpBB forum. I will not go into detail in here and ZC developers should be able to do these. PS: if you find better solution please let me know 🙂

SEO Friendly URL Using MOD_REWRITE

One aspect in SEO (search engine optimization) is having simple and descriptive URL. For example compare these two url:

  1. http://www.yoursite.com/product.php?id=101
  2. http://www.yoursite.com/product/laptop

The second URL is easier to remember for human / our visitors and it goes the same for Search Engine. Some search engine do not like special characters such as ‘?’,’=’ in URL.

Now Let me introduce you to MOD_REWRITE (rewrite module for Apache web server). This module is able to redirect a URL request to other page/URL. You can achieve the same behavior by using PHP redirect (header(“Location: destination.php”);), however, mod rewrite give you more control and robustness. What’s more, MOD_REWRITE redirect the user seamlessly which means the user will not know if they are redirected. I will go through the simplest steps to create SEO friendly URL using Apache MOD_REWRITE module. This blog is also serve as basic or simple guide on apache mod rewrite module.

Enough for the chitchat let’s go into main business. First of all you have to make sure that your apache server has mod_rewrite module enabled. By default this module is included in apache web server distribution but it is turned off. So go ahead, edit your server httpd.conf, remove ‘#’ in the Load Module section for rewrite_module or mod_rewrite.so, and restart your server.

All URL rewrite rules for mod rewrite should be put inside “.htaccess” file. Please note the behavior of htaccess file in apache which will apply the rule recursively, thus if you put your “.htaccess” in your web root folder it will affect all other folder under this root folder. Create a “.htaccess” file with the following content:

RewriteEngine on
RewriteRule ^(.*)\.html displayPage.php?page=$1

Explanation of above rule:

  • RewriteEngine on will activate any mod rewrite rule that we have specified, you can put “RewriteEngine off” to turn off rewrite rule on certain folders.
  • RewriteRule ^(.*)\.html displayPage.php?page=$1
    This rule will rewrite the url which ended with “.html” so that it will go to displayPage.php. So if you try to go to http://www.mysite.com/our_products.html, you will be redirected to http://www.mysite.com/displayPage.php?page=our_products.

    1. ^(.*)\.html – is a regular expression, any URL that match this expression will be redirected. Please note that we can capture any characters that match regular expression by using brackets “( )”. We can refer to this captured string for redirection purposes by using $n (n = number 1,2,3,4…). For more info on regular expression go to http://www.regular-expressions.info/reference.html
    2. displayPage.php?page=$1 – is the redirection destination. $1 is variable which will contain any character that has been captured before, in our regular expression.

Now create “displaPage.php”, inside this page you can get the page parameter and display the actual page accordingly. For example:

<?php
    $requestedPage = $_GET['page'];
if ($requestedPage == 'our_products') include("page1.php");
else include("index.php");
?>

Now, If you try to access “our_products.html” in your server you will be viewing “page1.php”. You can do many things inside the displayPage.php in this simple example you may find it is not quite useful, but imagine if you rewrite product name in the url (i.e. fender_electric_guitar.html) into their product code / category code (product.php?productId=50541). In order to achieve this, you can query your database and look for the product id for any product name, inside displayPage.php. Hope you find this blog helpful.

Setup Zen-cart for non-English Language

Within the last couple of days, I have been stressfully tried to upgrade Zencart shop with French language. I have backup the same data in the old database exactly, and move it to my workstation. I have installed French language pack for zen-cart, but it does not work. The special characters in French / other languages (i.e. é, à, ç and the like) was rendered differently (become ê, é, etc.).

At first, I thought the problem was on the database. Since I am not allowed to upload any new files to the server and I don’t want to create security risk by uploading phpmyadmin, so I used MySQL Administration tools to process the database. I have tried to use backup function and MySQL Migration tool but the characters on the web page is still faulty. I have also tried to change the collation and database type from “latin” to “utf8”, but again it did not work.

Finally, I just figured out that it has nothing to do with the database. I just have to change the CHARSET of the html page of the zencart, which can be modified from the language file (English.php, French.php, etc.). The strange characters was rendered differently because It was rendered using iso-8859-1 not UTF-8. The solution is to modify the following line “define(‘CHARSET’, ‘iso-8859-1’);” into “define(‘CHARSET’, ‘utf-8’);”.