<?php
/***************************************************************************************************************************
****************************************************************************************************************************

InstaMSG.php v1.02
by R.J. Vrijhof
March 13, 2000
Platform: Windows NT

Requirements:
-Windows NT (I use Windows NT Server 4 SP 5)
-Web server (I use Apache v1.3.9)
-PHP3 (I use v3.0.14)
-The Schedule Service must be working!
-And, last but not least, Notepad.exe must be in the same directory as the environment variable WINDIR!

You can reach me at: r@vrijhof.info

View/Download this script: http://www.vrijhof.info/download/InstaMSG%20v1.02.phps

****************************************************************************************************************************

                                                          Description

This is a simple script to send an instant msg to the webmaster. It does this by producing a temporary text file, then
scheduling an AT job, which will launch a batch file, which on its turn launches Notepad that shows the text file. After
closing Notepad, the text file is automatically deleted by the batch file.
This script only works on Windows NT, but I guess with some tweaks it could also be made working on any UNIX/Linux flavor
(with cron and some text editor like Emacs, or hell, if you'd like with VI :-|).

****************************************************************************************************************************

                                                         Installation

To install, take the following steps:

1. Make a directory to hold the batch file (showmsg.cmd, you'll make it in a minute) and (temporary) text files.
2. Make an empty text file and put the following three lines in it:
   @echo off
   %windir%\notepad.exe %1
   del %1
3. Save it as showmsg.cmd in the directory you've just created.
4. Download this PHP file (the one you're reading now) and put it wherever you like on your web site, as long as it is
   reachable from the web (of course) and you can execute PHP files in that directory.
5. Edit the variables below.
6. Done!

****************************************************************************************************************************

                                                            History

1.02  March 13, 2000          Now the msg contains also date & time, just in case you weren't there, so
                              you know what hit you when.
1.01  March 7, 2000           Fixed small (stupid) bug.
1.0   March 7, 2000           First release.

****************************************************************************************************************************
You have to set the following variables to the right values (don't forget the double backslashes in $workdir and
$wd_short and also make sure $workdir and $wd_short end with double backslashes!):
***************************************************************************************************************************/
$self "http://your.site.com/path/InstaMSG.php"# (Relative) URL of this script.
$workdir "C:\\somewhere\\";                      # The directory created for the batch and text files.
$wd_short "C:\\SOMEWH~1\\";                      # The same, but now in 8.3 format.
$delay 5;                                        # Number of seconds the script has to delay before Notepad is opened (if
                                                   # it doesn't work and you see AT jobs being added with an execution date
                                                   # of tomorrow, you have to increase this number).
$text "Message from \"%s\" (on ";                # Leave as-is, or change it to whatever you like, just leave two %s in
$text .= date("F j, Y  G:i:s")."):\r\n\r\n%s";     # here (the first is the e-mail address, the second the message).
/**************************************************************************************************************************
You don't have to change anything beyond this point, but feel free to experiment with whatever you like. It is completely
in the public domain.
****************************************************************************************************************************
****************************************************************************************************************************
***************************************************************************************************************************/



/**************************************************************************************************************************
This function will display the HTML form for sending the message. No error checking is done on the form, neither in
JavaScript, nor in PHP3 after posting (in fact, the mail field can be left empty).
***************************************************************************************************************************/
function displayForm() {
  global 
$self$mail;
  
?>

<form name="form1" id="form1" action="<?php echo $self;?>" method="post">
Type your e-mail address here: <input type="text" name="mail" id="mail" size="20" maxlength="35" value="<?php echo $mail;?>"><br /><br />
Type your message here:<br />

<!-- If you like to push the Send button yourself, comment the following line out and uncomment the line after that: -->
<textarea name="msg" id="msg" rows="10" cols="60" onchange="document.form1.submit();" wrap="hard"></textarea>
<!-- <textarea name="msg" id="msg" rows="10" cols="60" wrap="hard"></textarea> -->

<br /><br />
<input type="submit" value="Send!">
</form>

  <?php
}
/**************************************************************************************************************************
***************************************************************************************************************************
                                                  Start of the HTML output.
***************************************************************************************************************************
**************************************************************************************************************************/


/**************************************************************************************************************************
The HTML code complies with XHTML 1.0 Transitional standard.
**************************************************************************************************************************/
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/TR/xhtml1">

<head>
<title>Send instant msg to webmaster on <?php echo getenv("SERVER_NAME");?></title>
</head>

<body>

<?php
/**************************************************************************************************************************
***************************************************************************************************************************
If the msg field is empty, then it is the first time the script is run, or no msg was typed in (and so, it starts from
scratch). If you don't like that, then you have to put some error checking code in yourself, which can display a nice error
message.
**************************************************************************************************************************/
if (empty($msg)) {
  
?>

<br /><center><h1>Instant MSG</h1></center><br /><br />

  <?php
  displayForm
();

/**************************************************************************************************************************
***************************************************************************************************************************
If the msg field is not empty, do your magic!
**************************************************************************************************************************/
} else {
/**************************************************************************************************************************
Strip possible slashes added by posting:
**************************************************************************************************************************/
  
$mail stripslashes($mail);
  
$msg stripslashes($msg);
  
?>

<br /><center><h1>Message sent!</h1></center><br /><br />

  <?php
  displayForm
();
  
$now time();
/**************************************************************************************************************************
Make the temporary text file:
**************************************************************************************************************************/
  
$fp fopen("$workdir$now.txt""w");
  
fwrite($fpsprintf($text$mail$msg));
  
fclose($fp);
/**************************************************************************************************************************
Schedule the AT job at $delay of seconds (default: 5) from now:
**************************************************************************************************************************/
  
$hr date("G"$now $delay);
  
$min date("i"$now $delay);
  
$sec date("s"$now $delay);
  
exec("at $hr:$min:$sec cmd /c \"" $workdir "showmsg.cmd\" $wd_short$now.txt");
}
/**************************************************************************************************************************
Just for convenience:
**************************************************************************************************************************/
if (empty($mail)) {
  
?>

<script language="JavaScript">
<!--
document.form1.mail.focus();
// -->
</script>

  <?php
} else {
  
?>

<script language="JavaScript">
<!--
document.form1.msg.focus();
// -->
</script>

  <?php
}
?>

</body>

</html>