Archive for the ‘Web Development’ Category

Send HTML Newsletter Email to Admin Zencart 1.3.8

Monday, December 1st, 2008

In my last project, I designed new newsletter template and created custom newsletter administration area. When I send newsletter to admin to test the email, it does not send HTML email but plain text mail. Scratching my head, I searched Zencart documentation as well as Google for couple hours to find the answer. Now, I will share the solution here, just in case you go through the same pain as me.

First of all, you need to configure your Zencart to use HTML type email. Login to your administrator area and go to configuration > E-mail options.

  1. Make sure your “E-Mail Transport Method” is set appropriately
  2. Use MIME HTML When Sending Emails = “true”
  3. Send E-Mails = true
  4. Email Admin Format? = HTML

Now try to send a newsletter to the admin, if it still sends plain text mail, do the following. Backup and open in your text editor includes/functions/functions_email.php. In your functions_email.php try to find these codes

120
121
122
if (ADMIN_EXTRA_EMAIL_FORMAT == 'TEXT' && substr($module,-6)=='_extra') {
        $email_html='';  // just blank out the html portion if admin has selected text-only
}

Just below that add the following codes

125
126
127
128
// if no customer email record found, and admin email format is set to HTML, and sending newsletter, and admin is logged in, use HTML:
if ($customers_email_format_read->RecordCount() == 0 && ADMIN_EXTRA_EMAIL_FORMAT == 'HTML' && in_array($module, array('newsletters', 'product_notification')) && isset($_SESSION['admin_id'])) {
     $customers_email_format = 'HTML';
}

Now, you should send email in HTML format. Leave comment if it does not work for you or if this post has helped you and save your time.

Add Start and End Date limit Joomla 1.5 Banners

Monday, October 20th, 2008

On my recent project which uses Joomla v1.5, my client asks for banner management with ability to manage banner based on number of impression or date (period of time). Quick search on Joomla extension repositories show that there are many banner management component and module for Joomla 1.0 but not Joomla 1.5. Most of them which run on 1.5 are module to add animation or customize the display of your banner. At the time I write this blog, I found one component which does this, but it’s fairly plain and does not allow me to limit the banner based on number of impression made, categorize my banners, and keep track of clients.

Fortunately, the default Joomla 1.5 comes with com_banners and mod_banners core component and it has everything I need except start and end date setting to publish banner/ads. So let’s modify this core component to add this feature.

There are two files that you need to edit. First, open up \administrator\components\com_banners\views\banner.php with your favourite editor. Then insert the following codes on line 347 (between </tr> and <tr>).

347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php // BEGIN EDIT - Enable Start and End Date of Banner
	function formatToShortDate($date) {
		$date = substr($date,0,10);
		if ($date == '0000-00-00') return "";
		return $date;
	}
?>					
	<tr>
		<td class="key">
			<?php echo JText::_( 'Start Date' ); ?>
		</td>		
	  <td>
	  <?php echo JHTML::_('calendar', formatToShortDate($row->publish_up) , 'publish_up', 'publish_up', '%Y-%m-%d', array('class'=>'inputbox', 'size'=>'25',  'maxlength'=>'19')); ?></td>		
	</tr>
	<tr>
		<td class="key">
			<?php echo JText::_( 'End Date' ); ?>
		</td>		
	  <td>
	  <?php echo JHTML::_('calendar', formatToShortDate($row->publish_down) , 'publish_down', 'publish_down', '%Y-%m-%d', array('class'=>'inputbox', 'size'=>'25',  'maxlength'=>'19')); ?></td>		
	</tr>
<?php
	// END EDIT - Enable Start and End Date of Banner
?>

Secondly, locate and edit \components\com_banners\models\banner.php.
Try to find this line $wheres[] = ‘(imptotal = 0 OR impmade < imptotal)’;. On my file it’s located on line number 41, and below that add the following code:

42
43
44
45
// BEGIN EDIT - Enable Start and End Date of Banner
$wheres[] = "(publish_up = '0000-00-00 00:00:00' OR publish_up <= CURDATE())";
$wheres[] = "(publish_down = '0000-00-00 00:00:00' OR publish_down >= CURDATE())";
// END EDIT - Enable Start and End Date of Banner

It’s done. Now you will have start and end date field when you create new or edit your banners. The mod_banners will only display ads/banners which sit after the start date (if set) and before the end date (if set). You can leave start and end date field empty to ignore them. Please leave comments if you are satisfied or face any problem. Cheers.

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

Tuesday, October 14th, 2008

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

Saturday, July 26th, 2008

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

Saturday, June 14th, 2008

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 :)