Played Around with Drupal, Upcoming Site Update, and more …
I hadn’t write any blog post since last Thursday. The reason is because I had been playing around with Drupal. Drupal is a Content Management System that is similar to WordPress, in my experience, because it can install additional plugins as modules, custom themes, and add pages. However, Drupal has few other features that need to be configured externally if using WordPress, such as the ability to optimize the performance of the site by enabling compression. Perhaps I used WordPress for long time and don’t know how to use Drupal yet, I have not discovered any usefulness of Drupal over WordPress yet. I will continue to learn more about Drupal and improve my Drupal site at diary.robbychen.com. As you can see through the URL, I originally planed to start another diary blog using a CMS app and change the daily post schedule for this blog to irregular post schedule just like my Tumblr-based blog. I decided first to try Drupal because I tried Joomla before and I can’t seem to use it. I think I will try other CMS if Drupal also won’t work for me.
I also plan to update my main site robbychen.com beginning tomorrow since the spring semester is over. I decided to make this site as a portfolio site that include all the programming works that I have done in the past instead of a tutorial site because this domain name is based on my name and it doesn’t suited for a tutorial website or a commercial website. The current layout on the site is based on a commercial website. I will try to create my own site layout and I have decided to apply the color theme of the site based on the new Ubuntu Radiance theme.
The ColdFusion to PHP project that I was promised back in January is not possible anymore because I couldn’t find the CA 278 files and can’t convert to PHP without these files. However, I’m organizing the CA 288 class files which is advanced ColdFusion programming. I will rewrote them with PHP as soon as the maintenance of these files is completed.
Delete part of the URL string using removeChars with ColdFusion
While I was doing the final project for my ColdFusion class today, I got one problem which the URL query keeps adding up when I was using CGI.QUERY_STRING. For example, the query string becomes “projectid=5&clear=yes” when I just added the “&clear=yes” to the end of the CGI.QUERY_STRING variable. After the page have been refreshed, the query would become “projectid=5&clear=yes&clear=yes”. This became a problem to me because not only the URL query was not right, but the result of the page was also not right.
After numerous trail of using cfif, I remembered that I could use a build-in ColdFusion function to remove the last part of URL query and store it to a variable to use it later. The name of the function is removeChars. It needs three parameters, a string, the position number of where to begin removing characters, and the position number of where to end the removing of characters. For example, I used the following statement to remove the “&clear=yes” characters at the end of the CGI.QUERY_STRING variable and stores it to a new variable called variables.QUERY_STRING:
<cfset variables.QUERY_STRING = removeChars("#CGI.QUERY_STRING#",12,11)>
Of course I would add a cfif statement to avoid continue removing the characters if there is no “clear=yes” exists in the string:
<cfif CGI.QUERY_STRING CONTAINS "Clear=yes">
<cfset variables.QUERY_STRING = removeChars("#CGI.QUERY_STRING#",12,11)>
<cfset variables.clear = "#CGI.QUERY_STRING#">
<cfelse>
<cfset variables.QUERY_STRING = "#CGI.QUERY_STRING#">
<cfset variables.clear = "#CGI.QUERY_STRING#&Clear=yes">
</cfif>
<a href="?#variables.QUERY_STRING#" title="Continue Shopping">Continue Shopping</a><br />
<a href="?#variables.clear#" title="Clear Cart">Clear Cart</a>
You can see result of the above code here along with my final project.
Create a DSN-less database connection using ColdFusion 8
For a long time, I had been searching around online to find a solution to switch to MySQL database for my ColdFusion school server from Microsoft Access database. Since I have no control over the ColdFusion Administration settings, I can’t change the DSN connection.
Recently I have been finishing my remaining undone projects. I use Railo open source CF server and MySQL under Ubuntu to do the assignments for the class. The SQL code I was writing is a bunch of aggregate functions:
SELECT Â b.BookId, Â Â Â b.BookTitle, Â s.SalePrice, Â Â Â Â Â Â COUNT(s.SalePrice) AS bcount, Â Â Â Â Â Â SUM(sd.TotalSale) AS ts, Â Â Â Â Â Â SUM(sd.Quantity) AS qt FROM tblBooks AS b, Â Â Â tblSales AS s, Â Â Â Â tblSalesDetail AS sd WHERE b.BookId=s.BookId AND s.SaleId=sd.SaleId AND s.SalePrice IS NOT NULL GROUP BY b.BookTitle ORDER BY #variables.ob# #URL.s#;
When I was testing these code on the localhost which is MySQL-powered, the page was rendered fine without any errors. However, once I uploaded to the school server which is powered by MS Access, the errors began to appear. Noticeably, I can’t use the name such as b.BookId, b.BookTitle, s.SalePrice without using aggregate functions. It struggled me a bit because the final is due tomorrow.
I then remembered my unsolved solution for connecting MySQL database dynamically through CF code because most of the DSN-less code online only works in CF 5. Once again I began to searching for the solution to release my struggle to the MS Access. Finally, I found a CF custom tag to do just that. It is called query, similar to cfquery. Since it’s a custom tag, the use of it is cf_query. This tag is primary used to connect to the MS SQL server by its author. Fortunately he has given a code snippet to dump out the available JDBC drivers on the server.
After I tested this code, I was surprised to see that my school server supports lots of databases that I don’t know about. I chose the MySQL one and copied its JDBC URL to the CF test page. I noticed that I was unable to connect to my own MySQL server on this web server since my hosting provider doesn’t allow remote connection to MySQL. Therefore I googled for “free mysql hosting” and found a website called FreeSQL.org that specifically for hosting free MySQL databases. I connect to this newly created database by using the cf_query code:
<cf_query jdbcURL="jdbc:mysql://www.freesql.org/ColdFusion" username="username" password="password" qName="qGetData">
Note that ColdFusion is the database name. Within the cf_query beginning and ending tag, I wrote the SQL statements to import the data since the phpMyAdmin link does not work on FreeSQL.org. After that, I replaced the above cf_query code with cfquery in the project that I struggled with.
You can download the above code here along with the custom tag and the original code from its author. The project page that I was struggled with can be found here.
Use Samba to Transfer Files between Fedora and Windows XP
Samba is a GNU/Linux network service that provides file sharing between GNU/Linux and Windows. One week ago, I switched my netbook from Ubuntu back to Windows XP thanks to the Google Earth plugin. I need to use Google Earth API for my ColdFusion class and it needs Google Earth plugin to test the API code. However, the Google Earth plugin doesn’t have a Linux version yet despite the popularity of Google Chrome and Google Earth on GNU/Linux. I initially thought that Google Earth plugin could work on virtualized Windows XP through VirtualBox. It failed to display the data due to the low performance of VirtualBox graphics card.
Anyway, to use Samba, you need to first install it by entering the command below to the terminal:
sudo yum install samba samba-client samba-common samba-swat
After the installation, I followed a helpful tutorial on linuxhomenetworking.com to complete the Samba setup. It provided me step-by-step instructions to setup the Samba server using SWAT web interface.
I use Asus Eee PC 1005HA, which means that it has Windows XP Home Edition. The instructions for this tutorial on how to connect Samba server with Windows XP Home confused me. I was never able to connect to the server based on it. Fortunately, I found a post on linuxforums.org that discusses about the same issue. According to the discussion, the firewall must be disabled to allow Samba to accept the connection. This inspired me to enable the Samba and Samba Client ports in Firewall setting without completely disable the Firewall. This prevents any unnecessary security issues. Windows XP successfully connected to the Samba server without any problem.
I have not yet tested with transferring files from Windows XP back to Fedora directly on Fedora, but I think it’s the same technique. Some of the Samba server security concerns would rise if Samba is used on a non-password protected network. According to the article on linuxhomenetworking.com, you need to setup a local HTTPS Certificate for the Samba server if you have any security concerns. I don’t need the certification because I only use the sever on the home network and the network is password-protected.
Google Maps API and ColdFusion
While I was experimenting with Google API for my CA 288 ColdFusion class final project, I discovered that the ColdFusion variables can be used within the script tag. So I tried it out. I put the cfoutput tag outside the script tag in order to use the ColdFusion variables inside the script tag. And then I added cfif statement inside script tag to set the default latitude and longitude values to New York if there is no URL variables. Here is the cfelse part of the code:
var co_lat=#URL.a#;
var co_long=#URL.o#;
initialLocation = new google.maps.LatLng(co_lat,co_long);
var marker = new google.maps.Marker({
position: initialLocation,
map: map
});
contentString = “<br />#URL.d#:” + “<br />” + “Latitude: ” + co_lat + “<br />” + “Longitude: ” + co_long;
map.setCenter(initialLocation);
infowindow.setContent(contentString);
infowindow.setPosition(initialLocation);
infowindow.open(map);
I also used ColdFusion variables to convert them into the JavaScript variables as you can see on the first two lines of code. I also added a marker to the map to show the accurate location for the data provided. This is best used for creating maps from a list of places. For usage example, go to http://160.253.0.40/Students/Students/0111/browserGeo.cfm?d=Addo%20Entrance&a=-33.44431&o=25.73872. To download the source code, visit http://code.google.com/p/ca288-final-spring-2010-mc/downloads/list
The ColdFusion website is now fully data-driven
I learned a way to write code for the menus by using database instead of using cfswich. Now the course website is completely database-driven. I used the CMS approach to redesign the links in each menu. Here is the entire code for the content page that corresponce to the menu items:
<cfquery name=”qGetURL” datasource=”DSN0111″>
SELECT *
FROM tblMenu
WHERE 0=0 AND
<cfif isDefined(“URL.projectid”)>
menuID = #URL.projectid#;
<cfelseif isDefined(“URL.pageid”)>
menuID = #URL.pageid#;
<cfelse>
menuID = 18;
</cfif>
</cfquery><cfoutput>
<cfset filePath = ExpandPath(“#qGetURL.linkLoc#”)>
<cfif fileExists(filePath)>
<cfinclude template=”../#qGetURL.linkLoc#”>
<cfelse>
<div id=”noVal”>Not Found</div>
<cfinclude template=”index.cfm”>
</cfif>
</cfoutput>
As you can see from the above code, the file location and the file names are stored in the database instead of the page content. This way, I can create web pages inside site directories and then include it to the website through database without change the above code.
I also plan to create a ColdFusion web application that can directly update the database without launch MS Access. Right now I’m using CFEclipse to write the ColdFusion code on my Fedora system and virtualized Windows XP through VirtualBox to modify and viewing the database. My goal for this web application is to allow me to modify or view the database with less or no MS Access usage.
For those who don’t know, my ColdFusion course is Microsoft Access based, not MySQL based. I successfully installed ColdFusion 9 on my Fedora system, but I failed to install MS Access driver onto the system. That’s why I plan to create this application in the next few weeks.
Successfully using ColdFusion array for the First Time Without Knowing Anything
I just improved my ColdFusion class website. I used more fileExists functions to automate the detection of the project files in the URL variables. Now I don’t have to worry about adding the projects to the cfswitch statement anymore. Here is the code snippet for one of my cfcase statements:
<cfcase value=”4″>
<cfif fileExists(filePath[4])>
<cfinclude template=”../projects/project4.cfm” />
<cfelse>
<div id=”noVal”>This project is not available yet!</div>
<cfinclude template=”index.cfm” />
</cfif>
</cfcase>
Noted that I used an array in the fileExists function. Here is the cfloop statement for the filePath array:
<cfloop from=”1″ to=”10″ index=”i”>
<cfset filePath[#i#] = ExpandPath(“projects/project#i#.cfm”)>
</cfloop>
As you can see, I used an array inside cfset statement to store 10 ExpandPath functions. This is my first time to use the array in a ColdFusion variable. In fact, I didn’t know anything about how to use ColdFusion array. I just applied the array based on the other programming languages that I have already known. According to course syllabus, we should learn ColdFusion array at later chapter.
At first, I used filePath#i# inside the loop to declare a regular ColdFusion variable. ColdFusion outputted an error stated that “ColdFusion was looking at the following text: #” . Then I tried the traditional method of adding an array by surrounding the loop variable with a pair of brackets. I was very surprised that it actually worked.
I applied the same technique to the title of each webpage so that I no longer forget about adding project title to the title.cfm when completed a project. Here is the code snippet for one of the cfcase statements:
<cfcase value=”7″><cfif fileExists(filePath[7])>#titleName[7]#<cfelse>#defaultTitle#</cfif></cfcase>
The defaultTitle variable is the default title on the site homepage.
The following are the additional updates for the site:
- Projects are now re-organized
- Project 1 has become homepage
- Project 2 has changed to project 1
- New project 2, Advanced SQL, was completed and added to the homepage
ColdFusion site Updated
ColdFusion course website is updated. I inputted all the menu items on the site into the database, as well as all the image locations that associated with the menu items. Here is E-R Diagram for the site:
As you can see, I use one-to-many relationship to design the database. You can view the lager image on the bottom of project 2

