Location: PHPKode > projects > Grocery List > GL_additem_Form.php
<?php
########################################################################
#
# Project: Grocery List
# URL: http://sourceforge.net/projects/grocery-list/
#
# Copyright: (C) 2007, James Campbell
# License: GNU General Public License Version 3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Filename: $URL: https://grocery-list.svn.sourceforge.net/svnroot/grocery-list/releases/1.0/GL_additem_Form.php $
# Last Updated: $Date: 2010-03-06 00:03:07 -0800 (Sat, 06 Mar 2010) $
# Author(s): James Campbell
#
########################################################################

$title = 'Add Item';
$onload = "list.Quantity.focus();";
include_once("include/header.php");
include_once("include/upcdb.php");

?>

<form name="list" action="checkformatchingGLitem.php">

<?php

$itemnotfound = 1;
$isnumeric = 0;

$Item = isset($_GET["Item"]) ? $_GET["Item"] : "";

//$response = upc_lookup($Item);
$response = upc_lookup_cached($Item);

if($response === FALSE) {
	echo "<B>Errors detected during UPCdatabase lookup<BR>Please confirm results before continuing</B>";
} elseif (is_array($response)) {

	if (array_key_exists('description', $response)) {
		$desc = trim($response['description']);
	}
	
	if (array_key_exists('size', $response)) {
		$pattern = "/^([xX\.0-9\/]*)(.*)/";
		preg_match($pattern, trim($response['size']), $matches);
		$size = trim($matches[1]);
		$units = measure_unit_normalize($matches[2]);
	}	

	$itemnotfound = 0;

	echo "<TABLE BORDER=1 align=\"center\">";
	echo "<TR><TH>Quantity</TH><TH>Name</TH><TH>Size</TH><TH>Units</TH><TH>MFCTR</TH><TH>Notes</TH></TR>";
	echo "<TR><TH><input maxlength=\"10\" name=\"Quantity\" size=\"5\" value=\"1\"></TH><TH><input maxlength=\"100\" name=\"Name\" value=\"$desc\" size=\"30\"></TH><TH><input maxlength=\"10\" name=\"Size\" size=\"5\" value=\"$size\"></TH><TH><input maxlength=\"10\" name=\"units\" size=\"5\" value=\"$units\"></TH><TH><input maxlength=\"100\" name=\"mfctr\" value=\"$mfctr\"></TH><TH><input maxlength=\"200\" name=\"Notes\"></TH></TR>";
	echo "</TABLE>";

	$isnumeric = 1;
}
else
{
	//echo "Item not found";
	if ($response !== TRUE) {
		print $response;
	}

echo "<TABLE BORDER=1 align=\"center\">";
echo "<TR><TH>Quantity</TH><TH>Name</TH><TH>Size</TH><TH>Units</TH><TH>MFCTR</TH><TH>Notes</TH></TR>";
echo "<TR><TH><input maxlength=\"10\" name=\"Quantity\" size=\"5\"></TH><TH><input maxlength=\"100\" name=\"Name\" value=\"$Item\"></TH><TH><input maxlength=\"10\" name=\"Size\" size=\"5\"></TH><TH><input maxlength=\"10\" name=\"units\" size=\"5\"></TH><TH><input maxlength=\"100\" name=\"mfctr\"></TH><TH><input maxlength=\"200\" name=\"Notes\"></TH></TR>";
echo "</TABLE>";

}

?>

<input name="Complete" value="Complete" type="Submit">
<input name="Complete" value="Cancel" type="Submit">

</form>

<p>

<?php
if($itemnotfound == 1 && $isnumeric == 1)
{
	echo "<br><a href=\"http://www.upcdatabase.com/addform.asp?upc=$Item\" target=\"_blank\">Add Item to UPCdatabase</a>";
}
elseif($itemnotfound == 0 && $isnumeric == 1)
{
	echo "<br><a href=\"http://www.upcdatabase.com/editform.asp?upc=$Item\" target=\"_blank\">Edit Item info in UPCdatabase</a>";
}

if($isnumeric == 1 && $itemnotfound != 2)
{
	echo "<br>Please read the <a href=\"http://www.upcdatabase.com/guidelines.asp\" target=\"_blank\">UPCdatabase's Data Entry Guidlines</a> before adding or editing items in their system.";
}

?>
</p>

<?php

include_once($WEBROOT . "/include/footer.php");

?>

Return current item: Grocery List