<?php
# La. Do Not Call Script, version 1.0, Copyright (C) 2005  Joey Kelly, http://joeykelly.net
#
# Here we're trying to find out if a random telephone number is listed
# in the Louisiana Do-Not-call list.
#
# grep works wonders here, so we're going to call that and display the results
#
# The format of this file (LA_dnc.txt) is one record per line, for example:
#
#   504,5551212
#   ^
#   |
#   |
#   first column of file
#
# At this time, no error checking is provided. If your lusers can't type,
# that's not my problem ;-)

$donotcallfile = '/PATH/TO/LA_dnc.txt';

# here we send our POST variables off to be processed
$number             = getpostvars('number', 12);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<title>La. Do Not Call Script</title>
</head>

<body>


<!--
Here is our GPL license text.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2, as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-->


<h1 align="center">Louisiana Do-Not-Call List</h1>
<p>&nbsp;</p>
Please enter a phone number (must be in the form <b>504-555-1212</b>)<p>
<form action="<?= $PHP_SELF ?>" method="POST" enctype="text">
<input type="text" name="number" value="<?= $number ?>" size=12>
<input type=submit value="Submit">
</form>

<?php
$query = $number;
$query = trim($query);
$query = preg_replace('/-/', ',', $query, 1);
$query = preg_replace('/-/', '', $query, 1);
$returned = `grep $query $donotcallfile`;
$returned = trim($returned);

if ($returned == $query) {
  print "<font color=\"red\">STOP. $number is in the do-not-call list.</font>\n";
} else {
  print "$number is not in the do-not-call list.\n";
}

# functions
function getpostvars($postvar, $maxlength) {
  # this function is taken from another package I wrote, called jkelly-php-utilities 
  $postvar = $_POST[$postvar];
  $postvar = EscapeShellCmd($postvar);
  $postvar = substr($postvar, 0, $maxlength);
  return($postvar);
}

?>

</body>
</html>
