R
E
S
O
U
R
C
E
S
       Home      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: menus, buttons, etc.
_______________________

Send us your questions.
_______________________

site search by freefind
_______________________

HOME
SEO, Google, Privacy
   and Anonymity
Browser Insanity
JavaScript
Popups and Tooltips
Free Website Search
HTML Form Creator
Animation
Buttons and Menus
Counters
Captchas
Image Uploading
CSS and HTML
PHP
AJAX
XPATH
Website Poll
IM and Texting
Databases—MySQL
   or Not MySQL
Personal Status Boards
Content Management
   Systems
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS
Blog CMS
Customer Records
   Management CMS
Address Book CMS
Private Messaging CMS
Chat Room CMS
JavaScript Charts
   and Graphs




Free Personal Status Boards (PSB™)

Free Standard Free PSB

Free PSB Pro Version

Free Social PSB

Free Social PSB Plus (with Email)

Free Business PSB

Free Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

Private Messaging Inbox for Form Creator Form CMS

This script is called message-inbox_.php

The Private Messaging Inbox for Form Creator Form CMS script is one of a group of PHP scripts that handle both the administrative and end-user aspects of a general purpose HTML Form Creator that allows not just input boxes but multiple selection enabled select/option lists as well. In addition to the expectable editing scripts for both administrative and end-user functions, there's also a Search and Match script so that users can use the scripts to find other users with various individual or group commonalities, including proximity searches, i.e., find all the users within various distances. There are even private messaging scripts.

In case you wonder why private messaging is related to a general purpose HTML Form Creator, the answer isn't really that odd. Although there are a zillion possible uses one can put custom, administrator-created forms to, and equally as many form configurations one can create, the two most prominent uses we envisioned when we created our HTML form creator are matching apps for individuals and matching apps for groups. An example of the former is dating site apps like Match.com and an example of the latter is MC (Microcommunity) Search and Match — Search for Compatible Groups. If you don't yet know what MCs are, feel free to go to The Big Answer and find out. It should be obvious that the first thing one does when looking for compatible people—either as individuals or groups—is contact the ones the matching apps find that you are compatible with. So our apps provide a link to a personal messaging script in both our matching script search results and in our Private Messaging Inbox, on this page. In the latter, when a user contacts you, you may use the provided link to reply.

In short, then, whether you want to make a form where clowns, boy scout troups, gays, stamp collectors, bird watchers, swingers, Elvis lovers, conspiracy theory advocates, or others find one another according to various compatibility standards you devise, or simply make a form unrelated to compatibility, matching, or searching, our form creator scripts will allow you to handle both the administrative and end-user aspects of a general purpose HTML Form Creator that allows not just input boxes but multiple selection enabled select/option lists as well. Let your imagination guide you in your usage of our CMS system for form creation and use.

First, we start up a session (in the checkid_.php script) and include the config.php script to ensure that our connection to our database is made correctly. This file has the codes below in it:

$theemailaddress = "yoursite@yoursite.com"; //EDIT ME
$roothostname = "localhost";
$theusername = "yourusername"; //EDIT ME
$thepassword = "yourpassword"; //EDIT ME
$thedatabasename = "yourdb"; //EDIT ME
mysql_connect("".$roothostname."","".$theusername."","".$thepassword."") or die(mysql_error());
mysql_select_db("".$thedatabasename."") or die(mysql_error());

We also use the checkid_.php script to ensure that the session id variable is set, and send the user to register-with-captcha_.php if it is not. Then we put the session variable 'username' into $U—we will be checking that it is set in a second. Then we define a named constant '_NODIRECTACCESS'. We include the config.php file (in the includes folder) which uses the PHP defined() function to check on this constant. If it is not set, we are thrown out of the config.php file like yesterday's trash.

Next we check if the session variables 'groupname', 'username', and 'userid' are set. If not, we are sent to the login script. We make sure $U is still equal to the session variable 'username', that it is not an empty string, and that it's at least 6 characters long or . . . you guessed it . . . the login script. We make sure the session id is set and send them away if not.

The purpose of this script is to display the user's private messaging inbox. The user's groupname will be a link that goes to the HTML Form Creator—Form to Send Private Message script where the user will be able to reply to the message he just received and read. The message form will already contain the sender's groupname in the To Group Name input box, for convenience.

The getgroup() function reads the MySQL table my_members, where member data is stored. It finds the groupname of the user and puts it into the PHP variable $gr.

Next, the $clickedid variable is checked to see if the user has clicked on the Read/Not Read toggle, which is a linked gif image that has Read or Not Read on it. The clicking calls the JavaScript function readit(). This function grabs the id of the message row being clicked and submits it so it gets POSTed to this message inbox script. The MySQL table my_privatemessages then gets updated so that the readit field gets switched from 1 to 0 if it's a 1, or from 0 to 1 if it's a zero. Yes, this field is an on/off switch. It turns out that the MySQL IF() statement was built for just such purposes: SET readit=(IF(readit='0','1','0')).

Next there is a MySQL query using a SELECT statement that gets all data where the touser field contains the user's id and the deleted field has a 0. An inbox must, of course, relate to the touser field since whatever is TO USERS is considered IN. The deleted field is the simplest way for us to deal with deleted messages in the inbox: mark them deleted, in which case they will never be seen again by the user. The administrator can go to his host's phpMyAdmin app at any time and actually delete the message, of course. But keeping an archive of all messages, whether deleted or not, is seen as a wise precaution for a webmaster or host, both legally and logically. Both inbox messages and outbox messages may be deleted this permanent phpMyAdmin way, or impermanently with a mere flag, using HTML Form Creator—Delete Private Message from Inbox and HTML Form Creator—Delete Private Message from Outbox. Anyway, all data where the touser field contains the user's id and the deleted field has a 0 is the definition of what this user should be seeing in his inbox. The query result set ($sql) will be used below, to display inbox data, using while($rows=mysql_fetch_array($sql)).

Note that in the CSS styles, there are three that use properties like: width:150px;max-width:150px;min-width:150px;word-wrap:break-word;. This is what it takes to really control the way the inbox content displays. Simply giving a width for each <td> and hoping for the best is a very forlorn hope indeed—this absolutely works terribly. But our combination of style properties seems to work acceptably cross-browser. It even forces a wrap when there are words or URLs or email addresses that exceed the width of a column and that would normally force the column width to expand.

After the sidebar menu links comes a title: Messages to: <?php $us=$touser;getgroup($us);echo $gr; ?> that has some PHP snuck into it. Note that the getgroup() function is run here. It finds the groupname of the user and puts it into the PHP variable $gr, and this title echoes it to the screen. Users also see "Click "NOT READ/READ" button to toggle indicator." This refers to the gif indicator images in each message row that can either read READ or NOT READ. The switch discussed earlier that switches the readit field in the my_privatemessages table when the user clicks one of the linked images is now seen in action. The image toggles between READ and NOT READ when clicked, and because the MySQL table records the status of the switch, the 0 or 1 in the readit field will always succeed at guiding our script to indicate the correct switch status, and so it does, here.

For security, the PHP functions htmlentities() and stripslashes() are run on the data found in the MySQL table, just in case. This makes data display safe because html entities are the safe form of characters we put on the screen.

Note that we use the date('Y/m/d',$sent) function on the data from the datesent field from the table. This gives a nicely formatted date, and, in case you missed it, the ORDER BY datesent DESC was used in the MySQL query that accessed the inbox data, which gave us the latest messages first. This descending order of messages according to their sent dates is, of course, exactly what our inbox needs.

Finally, notice that there is a form—quite invisible—whose sole purpose is to hold the hidden field whose name is clickedid. The clicked message's id gets POSTed to the $clickedid variable which is used in the MySQL status indicator switch discussed above.

The script below is called: message-inbox_.php


<?php

include_once"checkid_.php";
$U=$_SESSION['username'];
define('_NODIRECTACCESS', TRUE);
include_once"includes/config.php";
if (!isset($_SESSION['groupname']) || !isset($_SESSION['userid']) || !isset($_SESSION['username']) || $_SESSION['username']<>$U || !isset($U) || $U=="" || strlen($U)<6 || !isset($_SESSION['sessionid'])){echo '<script language="javascript">alert("Please login."); window.location = "login_.php";</script>';}

function getgroup($us){
global $us,$gr;
$Q = mysql_query("SELECT groupname FROM my_members WHERE id = '$us' LIMIT 1") or die(mysql_error());
$row=mysql_fetch_assoc($Q);
$gr=$row['groupname'];}

// message-inbox_.php

$touser = $_SESSION['userid'];

$clickedid = $_POST['clickedid'];
if (isset($clickedid)){$sql = mysql_query("UPDATE my_privatemessages SET readit=(IF(readit='0','1','0')) WHERE id='$clickedid'");unset($clickedid);} //uses MySQL "IF()" function

$sql = mysql_query("SELECT * FROM my_privatemessages WHERE touser = '$touser' AND deleted = '0' ORDER BY datesent DESC");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Private Message Inbox</TITLE>
<meta name="description" content="Private Message Inbox">
<meta name="keywords" content="Private Message Inbox,Private Messaging,Private Message,php,javascript, dhtml, DHTML">
<script language="javascript">
mactest=(navigator.userAgent.indexOf("Mac")!=-1) //My browser sniffers
Netscape=(navigator.appName.indexOf("Netscape") != -1)
msafari=(navigator.userAgent.indexOf("Safari")!= -1)
wsafari=0; if(!mactest&&msafari){wsafari=1;msafari=0}
is_opera = 0; if(window.opera){is_opera=1}
is_ie_mac = 0; is_ie=0;if(document.all){is_ie=1}

function fixwidth(){if(Netscape||is_opera){e=document.getElementById('box');e.style.width='822px';e=document.getElementById('menu');e.style.width='116px';e=document.getElementById('table1');e.style.width='820px';}}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit){field.value = field.value.substring(0, maxlimit);}
else{countfield.value = maxlimit - field.value.length;}}

var clicked=0;

function readit(){
document.MyForm.clickedid.value=clicked;
document.MyForm.submit();}
</script>
<STYLE TYPE="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-color:#ccc}
p, li {font:13px Verdana; color:black;text-align:left}
h1 {font:bold 28px Verdana; color:black;text-align:center}
h2 {font:bold 24px Verdana;text-align:center}
h3 {font:bold 15px Verdana;}
#box {background-color:#eee;position:absolute;top:50px;left:150px;width:830px;
padding:10px;border:2px solid blue}
#table1 {width:824px;border:1px solid blue;text-align:center;table-layout:auto}
#menu {background-color:#eee;position:absolute;top:50px;left:0px;width:130px;
padding:5px;border:2px solid blue}
.ie {width:80px;word-wrap:break-word;}
.ie2 {width:150px;max-width:150px;min-width:150px;word-wrap:break-word;}
.ie4 {width:820px;max-width:820px;word-wrap:break-word;}
</style>
</head>
<body onload="fixwidth()">
<h1>Private Message Inbox</h1>
<div id='menu'>
<a HREF="send-message-form_.php">Send Message</a><BR><BR>
<a HREF="message-inbox_.php">Message Inbox</a><BR><BR>
<a HREF="message-outbox_.php">Message Outbox</a><BR><BR>
<a HREF="message-delete-received_.php">Delete Inbox<BR>Message</a><BR><BR>
<a HREF="message-delete-sent_.php">Delete Outbox<BR>Message</a><BR><BR>
<a HREF="login_.php">Login</a><BR><BR>
<a HREF="message-logout_.php">Logout</a><BR><BR>
<a HREF="profile-and-account-management.php">Account Management</a>
</div>
<div id='box'>

<table id='table1' border='1'>
<caption><b>Messages to: <?php $us=$touser;getgroup($us);echo $gr; ?></b> — (Click "NOT READ/READ" button to toggle indicator.)</caption>

<tr><th>From/Reply</th><th>Subject</th><th>Date</th>
<th>Status</th><th>Message</th></tr>

<?php

while($rows=mysql_fetch_array($sql)){

if($rows['readit']=="0"){$read="notread.gif";}else{$read="read.gif";}

$sent=stripslashes($rows['datesent']);

$id=$rows['id'];
$us=htmlentities(stripslashes($rows['fromuser']), ENT_QUOTES);
getgroup($us);
echo "<tr><td class='ie'><a HREF='send-message-form_.php?gr=".$gr."'>".$gr."</a></td>";
echo "<td class='ie2'>".htmlentities(stripslashes($rows['subject']), ENT_QUOTES)."</td>";
echo "<td>".date('Y/m/d',$sent)."</td>";
echo "<td><a href='#' onclick='clicked=".$id.",readit()'><img src='".$read."'></a></td>";
echo "<td class='ie4'>".htmlentities(stripslashes($rows['message']), ENT_QUOTES)."</td></tr>";
}

mysql_close();

?>

</table>

<form name="MyForm" method="POST" action="message-inbox_.php">
<input type="hidden" name="clickedid" value=" ">
</form>

</body>
</html>