Location: PHPKode > projects > Grocery List > start.php
<?php
########################################################################
#
# Project: Grocery List
# URL: http://sourceforge.net/projects/grocery-list/
# E-mail: hide@address.com
#
# Copyright: (C) 2010, Neil McNab
# 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/start.php $
# Last Updated: $Date: 2010-03-06 00:03:07 -0800 (Sat, 06 Mar 2010) $
# Author(s): Neil McNab
#
# Description:
#   Start page, includes logic for smartly suggesting to the user.
#
########################################################################


$title = "Start Page";
$onload = "document.getElementsByName('upc')[0].focus();";
include_once("include/header.php");

$db = dbconnect();

if ($db == NULL) {
    print "<p>ERROR: Could not connect to database, check your include/config.php file.</p>";
    print "<p>Also make sure your database has been created and check the permissions on your database.</p>";
}

if ($db->query("show tables;")->rowCount() <= 1) {
    print "<p>ERROR: Your database hasn't been setup yet, <a href='sqlload.php'>click here</a> to do that now.</p>";    
}

$result = dbexist($db, "SELECT count(*) FROM groceries");

$result2 = dbexist($db, "SELECT count(*) FROM listitems WHERE acctid='$GLIST_ACCT_ID'");

if ($result AND !$result2) {
	print "<p>You appear to have an existing list that hasn't been migrated, <a href='migrate.php'>click here</a> to do that now.</p>";
}

$result1 = dboneshot($db, "SELECT listid FROM lists WHERE acctid='$GLIST_ACCT_ID' LIMIT 1");

if (!$result1) {
	print "<p>You haven't created a list a yet, <a href='editlist.php'>click here to make one</a>.</p>";
} elseif (!$result2) {
	print "<p>You don't have any items in your list yet, <a href='listitems.php?id=$result1'>click here to add one</a>.</p>";
}

$qresult = $db->query("SELECT * FROM lists WHERE acctid='$GLIST_ACCT_ID'");

$result = $qresult->fetchAll();

if ($result1) {
    print '<script type="text/javascript" src="include/cuecat.js"></script>';
    // put quick add form here
    print '<form action="listitems.php" method="post">';
    print 'UPC: <input name="upc" maxlength="255" size="15" value="" />';
    if (sizeof($result) > 1) {
        print " List: <select name='id'>\n";
        foreach ($result as $row) {
            print get_option($row['listid'], $row['listname']);
        }
        print "</select>";
    } else {
        print '<input type="hidden" name="id" value="' . $result[0]['listid'] . '" />';
    }
    print '<input type="submit" name="add" value="Add to Shopping List" />';
    print '</form>';
}


    print "<h2>Your Lists</h2>";

    foreach ($result as $row) {
        $id = $row['listid'];
        print '<p>' . $row['listname'] . ' - ';
print "<a href='listshop.php?id=$id'>Go Shopping</a> | ";
print "<a href='listitems.php?id=$id'>Edit Shopping</a> | ";
print "<a href='listinventory.php?id=$id'>Edit Inventory</a> | ";
print "<a href='listbaselines.php?id=$id'>Edit Baseline</a></p>";

    }

$db = NULL;

if ($DEMO) {
?>

<h2>Features</h2>

<ul>
<li>Compatible with wedge and usb barcode scanners</li>
<li>Add, edit, and delete items from your grocery list</li>
<li>Supports UPC barcodes and gets information from <a href='http://www.upcdatabase.com/'>The Internet UPC Database</a></li>
<li>Manage multiple lists</li>
<li>Group multiple items into a single product category</li>
<li>View your shopping list on your mobile device</li>
<li>Print your shopping list</li>
<li>Optionally integrate your shopping list with the inventory tracker</li>
<li>Optionally set thresholds to buy more when inventory gets too low</li>
<li>Support for amounts and units in addition to quantity</li>
</ul>

<?php
}


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

?>
Return current item: Grocery List