In the previous tutorial, we discussed the code for database connectivity in PHP using functions. That code can be seen in the folder admin with the file name “admin 2008″ and in “process.php” files. We had also discussed about the login and the Signup module designs along with the DB connectivity. In this post, we are going to see about the UI level design for various departments. In addition there is a separate module for composing mails. We will see the coding for the mail composing module.
While defining the fields for attachments and mail body sections, the blob and medium blob data types come into picture. These data types are useful when defining image and other formats or huge block of text. These data types can be defined when creating the database. We are going to see the PHP code snippet for posting a mail along with the attachment in the DB. The following is the code which has been demonstrated along with the use of functions. The UI is very simple an it can be extended according to the user’s needs. The UI level coding for the mail composing module can be seen here: compose mail
function compose ()
{
$attch=””;
$from=$_POST[‘from’] ;
$to=$_POST[‘to’];
$subj=$_POST[‘subj’];
$body=$_POST[‘body’];
$tfname=$_FILES[‘file’][‘tmp_name’];
//$fname=$_FILES[‘file’][‘name’];
//$ftype=$_FILES[‘file’][‘type’];if( !empty($from) && !empty($to) && !empty($subj) && !empty($body) )
{
include_once(“admin/admin2008.php”);
$adb= new admindbase ();
if( !empty($tfname) )
$attch=setattach($tfname);$query=sprintf(“insert into mails (source,dest,subject,attach,body) values(‘%s’,’%s’,’%s’,’%s’,’%s’)”,$from,$to,$subj,$attch,$body);
if( $adb->__write($query) ==1 )
{
$_POST[‘sts’]= “email send to “. $to;
include_once(“status.php”);
}
else
{
$_POST[‘sts’]= “email failed send to “. $to;
include_once(“status.php”);
}
}
else
{
$_POST[‘sts’]= “field missing”;
include_once(“status.php”);
}}
For attaching the file to the mail and retrieving it for the recipient, the following code has been demonstrated using functions. For interconnecting systems, we have to install WAMP server a tool which integrates PHP Apache MySQL for running and deploying the system.
- For deploying it online WAMP server can be launched from system tray.
- Do a left click and from the set of options shown kindly select Put Online option.
- Find out the IP address of the system which runs WAMP along with the complete path where the application is placed.
- Open the browser and type the IP address of the system along with the path of the folder in the client system eg. 192.168.1.32/path to the folder.
- The home page appears and we can start using the website.
function setattach($tfname)
{
if($_FILES[‘file’][‘error’][0]==UPLOAD_ERR_OK)
{
$size=filesize($tfname);
$fp=fopen($tfname,”r”);
$content=addslashes(fread($fp,$size));
fclose($fp);
return $content;
}
else
return “”;
}function retrive()
{include_once(“admin/admin2008.php”);
$adb= new admindbase ();
$user = $_POST[‘user’];
$query =sprintf( “select * from mails where dest=’%s'”,$user);
$rs=$adb->__read($query);
for ( $i=0; $i<count($rs); $i++)
echo $rs [$i][‘source’] . ““.$rs[$i][‘subject’] .”
“;
}?>
The complete UI level coding can be found in this link: Durofy
Do provide your valuable comments after going through these tutorials which can help me in posting further tutorials for building live applications!