Link Action plugin for slGrid

There was recently a plugin system added to slGrid, which is great because I recently found the need for a plugin that creates a link around specific cell content and decided to write one.

Link Action allows you to create a URL around the contents of a cell using the unique database column ID. It also allows you to pass the target page for the URL and optional URL arguments. If no target page is passed, it defaults to the current page calling the grid.

<?php
/*
 * Example usage:
 * $_SESSION["grid"]->SetPlugin("Full_Name", "link_action", array("target" => "users.php", "extra_args" => "&action=edit"));
 *
 * Assuming the database column ID is 24, and the Full_Name is Raam Dev, here is what the cell would contain:
 * Raam Dev
 */

require_once('class.plugin.php');

class link_action_Plugin extends Grid_Plugin
{

	function introspect()
	{
		return(array(
			"name" 			=> "Link Action",
			"description" 	=> "Creates a URL to call an action using the unique database column ID",
			"author"		=> "Raam Dev ",
			"version"		=> "1.0"
			));
	}

	function generateContent($cell, $args)
	{
		if(empty($args["target"])){
			$args["target"] = $PHP_SELF;
		}
		if(empty($args["extra_args"])){
			$args["extra_args"] = "";
		}
		return("$cell");
	}
}
?>

PHP & MSSQL Difficulties

I managed to finish a couple of small programming tasks this week that have been on my "todo" list for quite some time. I finally got around to updating the Victoria's Garden Registration Request pages so that they now automatically send email notifications to the customers with their login and password, a task which previously had to be done manually. I took a peek at the victoriasgardenonline.com database today and I was surprised to find a total of over 5,000 records across three different tables.

Now I need to figure out how I can write a couple of utilities using PHP to connect to the MSSQL database on the server. This should be simple. Install PHP on the server, which is already running an IIS web server, and when write the PHP to connect to the local MSSQL database. Well, I was unable to successfully install PHP on the Windows 2000 server, and I am limited in how much I can do because it's a production server and I don't want to screw around with it too much. I would much rather run a second web server using Apache on my Linux box, which is running on the same LAN. I would then need to setup a connection between the Linux server and the MSSQL database on the Win2k Server. Again, I tried this but ran into a few problems. I'll hopefully be able to tackle it again this weekend.

HOWTO: Change home directory for a virtual FTP user on a server running pure-ftpd

I run CPanel on my web server and I recently needed to add an FTP account for one of the domains I am hosting. This is easy enough using the FTP Accounts option from the domain's CPanel page. However, I needed to set the home directory for the FTP account to be outside the root web directory (/home/username/public_html). This is not possible from the CPanel interface, most likely because it's a security risk. I checked my server and it shows that I'm running pure-ftpd, so I have no idea why I needed to use the proftpd directory. Heres how I did it:


[email protected]:~# cd /etc/proftpd
[email protected]:~# ls
./ savememo username2 username3
../ username4 username5 username6
[email protected]:~# vi savememo


savememo:RiIR2pPqeBWSM:32023:32024::/home/savememo:/bin/ftpsh
ftp:Ad3Dg04yDsk2dF:14:50:FTP User:/home/savememo/public_ftp:/sbin/nologin
savememo_logs:RiIR2pPqeBWSM:32023:32024:savememo:/usr/local/apache/domlogs:/bin/ftpsh

As you can see, /etc/proftpd contains a file for each of the accounts on your server. Edit the file for the domain in question, in this case savememo.com, and locate the line for the FTP account for which you wish to change the home directory. If I wanted to change the savememo FTP account's home directory to /home/savememo/myfiles, the new file would look like this:


savememo:RiIR2pPqeBWSM:32023:32024::/home/savememo/myfiles:/bin/ftpsh

After editing the file using your favorite console editor, in my case it's vi, save the file and then restart your pure-ftpd service (I'm not sure if this is required).

[email protected]:~# /etc/init.d/pure-ftpd restart
Stopping pure-config.pl:
Stopping pure-authd:
Starting pure-config.pl: [ OK ]
Starting pure-authd:

And that should do it. Now if you go into the FTP Accounts section of the CPanel for the domain you're working with, you should see the new home directory for that FTP user.

HTML_QuickForm – Setting the advcheckbox Checked Value

I must have spent an hour looking for a solution to this problem. Hopefully this post will save someone from the agony I went through. This problem is specific to PEAR HTML_QuickForm, so anyone who doesn't know what that is can enjoy the pretty colors. 🙂

With the standard 'checkbox' element you can simply append the word 'checked' as the last attribute in the addElement method, like this:

$form->addElement('checkbox','remember','Remember me?',
                         '(Check this to remember your login info.)', 'checked');

However, with advcheckbox, which is required if you want to define the checkbox values, setting the checked value from the addElement method is not possible. So how do you do it? First a quick review of the options available with advcheckbox:

  addElement('advcheckbox',
             string element-name,   // name of advcheckbox
             string element-label,  // label output before advcheckbox
             string text,           // label output after advcheckbox
             mixed attributes,      // string or array of attributes
             mixed values);

OK, now here is what I had to do to solve the problem:

$formCheckbox = $form->createElement('advcheckbox',mycheckbox,'',
                                               $row['name'],null,$row['permission_id']);
if(in_array($row['permission_id'], $groups2perms))
	$formCheckbox->setChecked(true); // <-- this is where the magic happens!
else
	$formCheckbox->setChecked(false); // <-- here too!

$form->addElement($formCheckbox);

Thats it! As you can see, you need to use the setChecked() method. However, before you can use it you have to assign the object to a variable ($formCheckbox = $form->createElement(..,..)) and then call the setChecked() method on that variable ($formCheckbox->setChecked(true)). Keep in mind that you can call any number of available methods on the variable before using the addElement() method.

Bugs are in my Stomach!

Some useful things I learned the past few days:

Want to disable the annoying Linux console bell that beeps when you type the wrong command?

setterm -blength 0

Want to disable the graphical login on Ubuntu/Kubuntu?

echo "false" | sudo tee /etc/X11/default-display-manager

Here's an excellent article on getting PHP4 and PHP5 running side by side while using Apache 1.33. I'm recoding the work I've been doing for Aerva using Object-Oriented programming and templates. So to utilize PHP5's OOP features, I needed to have it running on my laptop.

Last night, while taking a crap, I suddenly became extremely dizzy and almost fainted. I literally almost fell off the toilet! I've never almost fainted like that before, ever. When I stood up, I couldn't even walk. Since then I've had a really bad stomach ache, almost threw up twice, and wasn't able to eat very much today. Maybe it's food poisoning (DJT, Vietnam?) or some stomach bug. I was reconsidering completing my Friday workout, but I decided I'd start the workout and stop if I started feeling worse. I actually felt better after I started the workout and I was able to complete it in it's entirety.

The temperature for today, as well as the next two days, is supposed to be in the upper 90's. I'm headed to the beach tomorrow morning, then I'll probably spend the afternoon doing programming work for Aerva. The project I'm working on has a deadline of this Wednesday, and I've got plenty to finish before then.

I had 4 appointments to show the Bowers ST 3 bedroom apartment today. None of them showed up. Anyone looking for a 3bdrm apartment? New stove, new bathroom floor, some new paint, 3rd floor, first month + security deposit, no utilities included, $800 a month.

My truck's transmission really felt as if it was about to crack open while driving to work on Wednesday, so I took the train in on Thursday. I parked my truck at my Lowell office and rode my bike to the train station. I think it was quicker to ride the bike to the train station than it was to drive there; three minutes tops, and I save myself $5 parking. I did some quick calculations and figured out I can save $30 a month taking the train into work three days a week (assuming I don't have to pay for parking and instead ride my bike to the train station, otherwise it's $30 more expensive to take the train in). But the $30 isn't the great part. I actually save my truck from 1000 miles every month! That should extend it's life for awhile (it has 143k miles right now). Taking the train adds an extra 3 hours a week of commuting, but that's 3 hours I can read or use my laptop, so its all good.

I decided not to buy another cell phone. However, by accident I was looking at T-Mobile's website and I glanced at their Blackberry plans. If I switch to T-Mobile's service, I can get the same number of minutes with the unlimited Blackberry Internet service for $40 less than what I'm paying now! And if it costs me $170 to cancel my 2 year contract with Nextel, I still would save $340 by switching to T-Mobile right now ($40 x 12 months = $480 saved, $480 - $170 = $340). Add that $40 to the $30 a month I'm saving by taking the train, and I've just saved myself $840 a year! This finding-ways-to-save stuff is becoming fun!

Urgh, I still feel the stomach bug inside me and my body still feels weird. I've had chills all day today, even though its been 85+ degrees and I still feel a little dizzy when I stand up. I'm sure if I threw up, I'd feel better, but I'm too stubborn to throw up. To give you an idea of how stubborn, I've only thrown up twice in the past 15 years.

Maybe lying in the sun at the beach tomorrow will help.

Must
Remember
To
Wear
Sunblock...

Coding a style changer for WordPress 2.0

I'm sure there are plugin's that take care of this function, however I decided to hardcode this right into my WordPress theme. Why? Because I don't plan to use any other themes. All style changes I make will be done through changing the CSS style sheet. I coded this so that I could work on a new style sheet offline, and when I'm finished, upload the file to my styles directory. It will then automatically show up in the drop down box on the Style Changer page.

So here is what I did. First I created a new WordPress page and called it Style Changer. On this page I put the following PHP code: Continue reading

MyFMO.com Status Update

I have decided to have phpBB, an open-source messaging board, handle the user authentication and registration process for MyFMO. I've already coded my own registration process, and it works flawlessly, but I realized I would eventually want to have a forum on MyFMO for users to discuss fitness related topics. It would be a lot easier to use phpBB's authentication system on my PHP pages, instead of trying to integrate my authentication system with phpBB's.

I added a little progress meter to MyFMO.com to use while it's under construction.

I also added the Before I Die page to the About section of this site.

Modifying the WordPress (more…) link

I found the more feature of WordPress to be very useful, however I wanted to change the link that was displayed. The default is "(more...)", and I wanted it to say something more useful, such as "Continued...". After doing some Googling and finding nothing, I dug through all the PHP files included with WordPress. Finally I found the following in template-functions-post.php, located in the /wp-includes/ directory: Continue reading