Archive for the ‘programming’ Category

Custom 403 module on Drupal.org

editDrupal / Open source development / php / programmingcommentsNo Comments »
June 22nd 2009

custom_403_screen_shotThis is a module I have worked on a while back. I have recently had the time to finish it and it is now released and hosted on drupal.org, which is very exciting.

You can view the module project page here, to see a demo page, please visit here

The module was made with one thing specifically in mind, giving the users more information when they encounter a 403 on a website. Since drupal uses various role based node access privileges, I thought a module that provides custom information based on the roles allowed or disallowed on any specific node will be more helpful.

The module works with the content access module to give the visitors information on what roles are allowed to access the nodes and maybe the admins can also give more information on how to obtain these roles. Anyways, please enjoy the module, if you have questions and comments, please let me know

Cheers!

Add a Database

editprogramming / Visual BasiccommentsNo Comments »
June 30th 2008

Chapter3_Prog1_001
The first step in adding a database to visual basic project is going to Project -> Add New Item…

Select SQL Database

Right Click Tables -> Add New Table
Chapter3_Prog1_002
Add the colums and their data types

Primary key – foreign key relationship can be found under the menu-relationship
Chapter3_Prog1_003

After adding the database connection to the data source, you can now drag tables or do other manipulation with the data

Chapter3_Prog1_004
To download the source code for this program, click here

Lessons learned: code optmization

editphp / programmingcommentsNo Comments »
June 25th 2008

Have you ever written a piece of code that works, but the amount of redundancy and inefficiency drove you nuts? Always had the itch to go back and pretty it up? Well, that’s exactly what I did. I recently wrote a script for a people directory, it contained 3 parts

  1. An database storing the information of the people (i.e. name, states, country, etc etc.)
  2. the html input file (see example below)
  3. The data processor using PHP

input file (input.html)

The idea is that you will be able to select a last name or a state and find the corresponding results. For example, finding someone in the state of Virginia, finding someone with last name start with W, or a combination of both.

This was the first attempt for selecting the matching last name:

HERE

HERE

By using arrays, here are the code for selecting the matching last name and state and generate the SQL query

HERE

HERE

Joomla content backup using php

editphp / programmingcommentsNo Comments »
May 3rd 2008

A while back one of my project was to create a joomla based content management website. Afterwards I was asked to make a backup mechanism that would back up all of the content on the website. There were plenty of third party plugins available on joomla’s extension directory but I found them either too complicated for normal users to operate or costed money. Another option was to use PhpMyAdmin to backup the entire joomla database, however that was too
complicated for the user in this situation as well. Therefore I decided to write a custom php script made just to handle the content backup.

Some file you need download: (PHP ZIP library: PHP zip library, contains: Zip.php and PEAR.php)

1st: I had to find where the content was stored, luckily for joomla based CMS all contents are stored in the database under the table “jos_content” or whatever the pre-fix: “xx_content” in the joomla database you created.

2nd: I had to create the basic MySQL connection script: here are the following:

openning the database:

//********************************************************************************
//opendb
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

mysql_select_db($dbname);
//********************************************************************************

configure the database information: Simple enter the MySQL database information

//*******************************************************************************
//configuration file
$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'db_name';
//end of configuration file
//*******************************************************************************

Close connection:

//*******************************************************************************
//close connection
mysql_close($conn);
//*******************************************************************************

Here are the basic scripts for openning and closing a mySQL database connection in php, for more information on them, visit w3schools to learn more

Now comes the meat of the script:

//************************************************
//include the php library for zip file compression
//************************************************
include ('Zip.php');

//*************************************************************************************
//Querying the database table containing the contents of the website, notice we used a
//concat function to combine the introtext and fulltext together
//*************************************************************************************
$query  = "SELECT id, title, concat(introtext, concat('\n', `fulltext`)) content FROM jos_content";
$result = mysql_query($query);

//*****************************************************************
//Displaying the SQL querying result in html using a form text area
//*****************************************************************
echo "";
echo " 

$number files created under /help/backup

"; //providing download link echo "Click here to download the backup package";

As some of you can tell, this script is still in very immature stage, future updates could include SQL injection prevention measures, validation of the backup directory and also deletion of the html files once they have been packaged. Anyways I hope this have been useful.

A simple internet Browser

editprogramming / Visual Basiccomments1 Comment »
March 19th 2008

It’s very exciting isn’t it, in the second program, We are attempting to create a customized simple internet browser. My program consist of the following controls:

1 WebBrowser (the web content area)
Name: BrowseWindow

3 buttons (HomeButton, BackButton, Button_1)

Some thoughts: The browser is very simple, address does not address content of the web. Maximize, content area does not, future considerations.

Code

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

BrowseWindow.Navigate(TextBox1.Text)

End Sub

Private Sub BackButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackButton.Click

BrowseWindow.GoBack()

End Sub

Private Sub HomeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HomeButton.Click

BrowseWindow.GoHome()

End Sub
End Class

Screen shot (click to enlarge)

Chapter 1 Program 2 Screen shot

download Chapter 1 Program 2 Code download