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.

CSS: Float in Firefox and IE

Today I come across basic problem that most web designer face. If only there was one Internet browser in the world, life would be much easier. When you float an element in IE, it does not really float, instead the margin is still affecting other element as you can see in the following illustrations:

<style type="text/css">
	body {
		width:400px;
	}
	div {
		width:200px;
		height:50px;
		background-color:#0099FF;
	}
	div#a {
		float:right;
		margin-left:10px;
		background-color:#FF9900;
	}
</style>
<body>
<div id="a">
 
</div>
 
<div id="b">
 
</div>
</body>

CSS Float experiment result in Internet Explorer 7

Now Here is what it looks like under Firefox 3.0:

CSS Float experiment result with FireFox

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’);”.

Sony Ericsson K800i Sudden Death

I wonder how many people have gone through the same experience as I had. Last month, I was still using my Sony Ericsson K800i which I had bought 2 years ago. It is a decent mobile phone with leading camera feature when it was launched and as IT geek I am satisfied with all the features of the phone. I have stored crucial data in my phone including important contact numbers, and suddenly I could not turn on the phone after I change the SIM card.

I was on my trip in Singapore and I used local SIM card, since my Australian SIM card does not work there. Just before I board the plane to go back to Melbourne I replace the SIM card quickly. I turned off the phone, took out the battery, took out the SIM and put my Australian SIM card. Voila, I could not turn on the phone anymore although I have just charged the battery to its full capacity. When I tried, it just showed blinking red light near the infrared port of the phone.

As IT geek and ex-mobile phone expert (I used to flash and modify the software of my mobile phone), I didn’t give up. I tried to look through the internet for a solution. I found out many people get the same situations, and some of them successfully revive the phone by rewriting the EROM (equivalent of BIOS in PC). No luck, I could not recover my K800i. Next thing, I tried to bring it to customer service centre, but again they refused my phone because it was purchased outside Australia (They are not allowed to put Australian software/flash into my phone).

Well, this is an expensive experience. I have learnt two things. Firstly, always backup your mobile phone regularly. There is lots of hand phone backup software out there or if you used smart phone you can just connect it to your PC and copy your organizer data to your Outlook. Secondly, do not cut out the power abruptly when turning off your Sony Ericsson mobile phone. It looks like Sony Ericsson mobile phone writes some data into the EROM when turning on and off and if we cut out the power the EROM will be corrupt. When you break your EROM, your phone won’t be recognized by your PC, you cannot charge the battery, and etc. It just death.

CSS: Gap between two DIV elements

When I wrote stylesheet for my website (www.ferolen.com) couple weeks ago, I encountered some errors. One of the CSS problems is a gap that mysteriously appears between DIV elements. Most of the time we would like to has two div elements to stick together smoothly especially if we use it to contain background image. You have set the padding and margin to 0, but it does not help. However, if you apply border around the DIV, magically the gap disappear. These symptoms usually occur when you have element with margin inside the DIV. How could we get rid of the gap but without the border? The answer is by applying 1px padding to the DIV element or set the margin of the child element of the DIV to 0.

For Example, the following case could be solved by adding “padding:1px” to #div2 or set the margin of “p” in div2 to 0;

.css: gap between DIVs css gap source code

XP Vs Scrum

Two of the most well known agile methodologies are XP (extreme programming) and scrum. Both of these practices have similarities and differences. As agile software development techniques, they have same characteristics which are relatively short development time and consist of several iterations. In this blog, the explanation of both practices will be discussed as well as the strengths and weaknesses of each method.

XP which is also known as extreme programming is an agile software development approach which consists of several practices and values. Many articles stressed the values of communication, simplicity, feedback, and courage in XP. Communication value is where team member uses verbal communication to other team member over formal written document. The team members in XP project includes developers and customer representatives who should understand the domain and know what is needed. XP also emphasize simple design and solution to fulfill customer requirements. In development process, feedback from customer, system testing, and other team members are important. XP also encourage the developers to write code only for current requirements in pair and do code refactoring if needed in the future.

People often think that scrum is same with XP. Scrum is a subset of agile software development techniques. It is an iterative process to develop or manage certain project and it will produce shippable product which can be presented to the customer at the end of iteration. Unlike XP, scrum emphasizes the management side of a project and does not define a detail engineering practice. Iteration in scrum is called sprint which will deal with certain features defined by customer in a backlog. After the team chooses the most risky feature in backlog they will develop it. A sprint usually takes thirty days and can be decreased to one week if the system is simple and easy to develop. During a sprint, team will have a meeting each day to discuss what has been done, what the obstacles are, and what will be done.

XP specify the software engineering practices such as test-driven development, refactoring, pair programming, simple design, etc. On the other hand, scrum focuses on the management side which quite general so that it can be implemented on other project beyond software development project. For example, scrum does not specify pair programming or test driven development, but it specify how we manage the requirements or requested features. Scrum can be seen as a wrapper for existing engineering practices. Scrum requires self organizing team which cannot be disturbed by requirement changes once they started the sprint. If the customer wants to change the feature, they have to wait until the iteration finished and then introduce the change. In contrast, extreme programming is more acceptable to change during iteration which usually only last for two weeks.

XP and scrum has subtle different. They emphasize on different side of a software development project. It will be great if we can combine both of them to manage our agile software project.

Is pair programming painful?

Pair programming has become popular word among software developers recently. As the name suggests, pair programming is a software development activity (writing code) which is done by two programmers. There will be only one of them writes the code and the other programmer thinks whether the code written satisfy their goals. The idea is similar with rallying where in one car there are two people. They are the driver and co-driver. The driver will drive the car and the co-driver will guide the driver to drive accurately.

Pair programming is a programming technique adopted by extreme programming or any agile software development methodologies. Some people argue that this method is a good practice. On the other hand, there are many people say that it is sorrowful. In this blog, the benefits and drawbacks of pair programming will be analyzed, to understand whether pair programming is painful or not.

Some benefits of pair programming are efficiency and increase in performance. In term of efficiency, we can cut the number of workstations as well as software licenses since we need only one workstation every two developers. However, the main advantage that people looking for in this programming approach is an improvement in developer performance. This includes an increase on the number of line of codes and reduced number of bugs or defects in the written code. This can be achieved, because one of the programmers can concentrate to write the code and another one analyzes the code which is written on the screen. If there is something wrong with the code, there is a big chance that it will be spotted during the development phase.

Although pair programming promises wonderful benefits for developers, it has some drawbacks. I believe most people will feel awkward, if they are watched by someone else when they are working. That is why we can find cubicles in many working places. Some people find that it is hard to work under tight supervision. The other problem is every human has their own style and way of thinking. This is also applied in coding style and logical flow within our source code. In my opinion, it is difficult to understand other programmer’s code or adopt their styles, especially if there is a big different in the experience and programming skills.

All of the drawbacks of pair programming are most likely caused by unmatched programmer being paired. I believe this can be solved if both programmer can get a long together and have the same level of programming skills. It will be better if both programmers come from the same programming language background since there is a big probability they will have same programming styles. It is not an easy task to pair up developers in a project.

Is pair programming painful? This issue is debatable since there are advantages and disadvantages. However personally, I would say that pair programming is not painful. There are some precautions that we can do to minimize or eliminate the pains in this programming approach.