<repo_name>PeterRichardsWA/DojoStoreEcommerce<file_sep>/website/application/views/cart.php
<html>
<head>
	<title>Shopping Cart</title>
	<style type="text/css">
		*{
			margin: 0px;
			padding: 0px;
		}
		#header{
			background-color: black;
			color:white;
			width:100%;
			height:50px;
			font-size: 36px;
			margin-bottom: 50px;
		}
		#header a{
			margin-left: 70%;
			color:white;
		}
		table{
			margin: 0 auto;
		}
		#total{
<<<<<<< HEAD
			margin-left:50%;
			margin-top: 10px;
			margin-bottom: 100px;
			font-size: 24px;
=======
			margin-left:80%;
			margin-top: 10px;
			margin-bottom: 100px;
>>>>>>> remotes/origin/master
		}
		th{
			width:50px;
			border-bottom: 1px solid black;
		}
<<<<<<< HEAD
		th, td{
			font-size: 24px;
			text-align: center;
		}
=======
>>>>>>> remotes/origin/master
		form{
			margin-left: 50px;
		}
		p{
			margin: 20px;
		}
	</style>
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
	<script type="text/javascript">
<<<<<<< HEAD
	// when the "same as shipping" box is checked, hide the form for billing info
=======
>>>>>>> remotes/origin/master
	$('document').ready(function(){
		$('#check').click(function(){
			$('.duplicate').toggle('showOrHide');
		});
	});
	</script>
</head>
<body>
	<div id="header">
<<<<<<< HEAD
		Dojo eCommerce
		<a href="/main/cart">View Cart<?php echo "(".$cart['items']."): $".$cart['total']; ?></a>
	</div>
<!-- 	cart displays correctly and allows for deleting items correctly. -->
<!-- need to add ability to update the quantities and have the page update with ajax-->
=======
		<NAME>
		<a href="/main/cart">View Cart</a>
	</div>
>>>>>>> remotes/origin/master
	<table>
		<tr>
			<th>Item</th>
			<th>Price</th>
			<th>Quantity</th>
			<th>Total</th>
			<th>Remove Item</th>
		</tr>
		<?php 
		$total=0;
		foreach ($cartInfo as $item) {
			$subtotal=$item['price']*$item['quantity'];
			$total=$total+$subtotal;
<<<<<<< HEAD
			$id=$item['id'];
			echo "<tr><td>".$item['name']."</td><td>".$item['price']."</td><td>".$item['quantity']."</td><td>".$subtotal."</td><td><a href='/main/remove/".$id."'>X</a></td></tr>";
		}
		?>
	</table>
<!-- 	display the total below the cart -->
	<div id="total">
		<?php echo "<p>Total:$".$total."</p>"; ?>
		<a href="/main/delete"><button>Delete Cart</button></a>
=======
			echo "<tr><td>".$item['name']."</td><td>".$item['price']."</td></td>".$item['quantity']."</td><td>".$subtotal."</td><td><a href='/main/remove'>X</a></td></tr>";
		}
		?>
	</table>
	<div id="total">
		<?php echo "Total:$".$total; ?>
>>>>>>> remotes/origin/master
		<a href="/"><button>Continue Shopping</button></a>
	</div>
	<form action="/main/order" method="post">
		<h2>Shipping Information</h2>
		<p>First Name:<input type="text" name="ship_first"></p>
		<p>Last Name:<input type="text" name="ship_last"></p>
		<p>Address:<input type="text" name="ship_street1"></p>
		<p>Address 2:<input type="text" name="ship_street2"></p>
		<p>City:<input type="text" name="ship_city"></p>
		<p>State:<input type="text" name="ship_state"></p>
		<p>Zip Code:<input type="text" name="ship_zip"></p>
		<h2>Billing Information</h2>
		<input id="check" type="checkbox" name="same_info" value="same_info">Same As Shipping Address
<<<<<<< HEAD
	<!-- 	duplicate class gets hidden by jquery -->
=======
>>>>>>> remotes/origin/master
		<p class="duplicate">First Name:<input type="text" name="bill_first"></p>
		<p class="duplicate">Last Name:<input type="text" name="bill_last"></p>
		<p class="duplicate">Address:<input type="text" name="bill_street1"></p>
		<p class="duplicate">Address 2:<input type="text" name="bill_street2"></p>
		<p class="duplicate">City:<input type="text" name="bill_city"></p>
		<p class="duplicate">State:<input type="text" name="bill_state"></p>
		<p class="duplicate">Zip Code:<input type="text" name="bill_zip"></p>
		<p>Card Number:<input type="text" name="bill_card"></p>
		<p>Security Code:<input type="text" name="bill_security"></p>
		<p>Expiration Date:<input type="month" name="bill_date"></p>
<<<<<<< HEAD
<!-- 	pass the total through the form to display on confirmation. -->
<!-- 	this could instead be calculated when the order is processed -->
		<input type="hidden" name="total" value='<?php echo $total; ?>' />
=======
>>>>>>> remotes/origin/master
		<input type="submit" value="Pay">
	</form>
</body>
</html><file_sep>/new-connection.php
<?php
//define constants for db_host, db_user, db_pass, and db_database
//adjust the values below to match your database settings
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '<PASSWORD>'); //set DB_PASS as '<PASSWORD>' if you're using mac
define('DB_DATABASE', 'store'); //make sure to set your database

//connect to database host
$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);

//make sure connection is good or die
if ($connection->connect_errno) 
{
    die("Failed to connect to MySQL: (" . $connection->connect_errno . ") " . $connection->connect_error);
}

<<<<<<< HEAD
=======

>>>>>>> 4729fe55dece6c1d9356d0ed120b4fd8ead7ec07
//used when expecting multiple results
function fetch_all($query)
{
	$data = array();
	global $connection;
	$result = $connection->query($query);
	 
	//while($row = $result->fetch_assoc())
	while($row = mysqli_fetch_assoc($result)) 
	{
		$data[] = $row;
	}
	return $data;
}

//use when expecting a single result
function fetch_record($query)
{
	global $connection;
	$result = $connection->query($query);
	return mysqli_fetch_assoc($result);
	//return $result->fetch_assoc();
}

//use to run INSERT/DELETE/UPDATE, queries that don't return a value
//notice this function returns a value.  This value will be equal to the ID of the most recent query item 
//ran by your PHP code.
function run_mysql_query($query)
{
	global $connection;
 	$result = $connection->query($query);
 	return $connection->insert_id;
}

//This function will return an escaped string.  IE the string "That's crazy!" Will be returned as:
// "That\'s crazy!...This helps secure your database!
function escape_this_string($string)
{
	global $connection;
	return $connection->real_escape_string($string);
}

?><file_sep>/website/application/models/CartData.php
<?php
//
// MODEL for Cart Data while shopping.  Kristy/Matt/Peter
// this will manage the entries for the cart as users shop through the site.
//
class CartData extends CI_model {

	// model allows for methods to manipulate data: add/update/remove data
	// to view the data is: one record, many records
	//
	// *******************************************************************
	// Get data files towards top of file as they will be used more than
	// write functions
	//
	public function get_all_data($cartid=0) {
		// get all data in the current cart
		return $this->db->query('')->result_array();
	
	}

	public function get_data_id($id=0) {
		// get one item from cart.  Not sure why this is here?
		return $this->db->query('', array($id))->row_array();
	
	}

	// gets number of items in the cart through db
	public function get_cart_total($id=0) {
		$query = "SELECT COUNT(oid) AS numitems FROM orders WHERE oid = ?";
		$values = array($id);
		// numitems is returned in this row_array
		return $this->db->query('', array($id))->row_array();
	}
	
	// functions that change data in the database
	//
	// creates the blank order if it doesn't exist. Later we add items to cart.
	//
	public function create_order($data) {

		// this creates a blank order inserting session id into the database for the cart,
		// so we can tie to this in the future.
		$session_id = $this->session->userdata('session_id');
		
		if($session_id) {
			$myDate = date('Y-m-d H:m'); // make a valid date for create and update

			// create the order, passing back the ID of the newly inserted item, then store in session for
			// shopping.
			$query = 'INSERT INTO orders (sessid,status,created_on,modified_on) VALUES (?,?,now(),now())';
			// # values must match field count above.
			$values = array($session_id,0,$myDate,$myDate);

			$tmp = $this->db->query($query, $values);
		
		} else {
			die('no session!!! cannot create cart.');
		}

		return $this->db->insert_id; // return id of record inserted. more useful.

	}

	public function add_to_cart($cartid=0, $prodid=0, $qty=0) {
		
		// first check to see if item exists in cart already. if so, than just add to qty
		// otherwise create a new entry in cart for this prodid.
		
		$query = "SELECT * FROM pivot_order-products WHERE order_id = ? AND product_id = ?";			
		$values = array($cartid,$prodid);
		$results = $this->db->query($query,$values);

		if($results) {
			$total = $results('quantity') + $qty;
			$query = "UPDATE pivot_order-products SET quantity = ?, SET modified_on = NOW() WHERE order_id = ? AND product_id = ?";
			$values = array($total, $cartid, $prodid);

		} else {
			$query = "INSERT INTO pivot_order-products (order_id,product_id,quantity,created_on,modified_on) VALUES ";
			$query = "(?,?,?,NOW(),NOW())";
			$values = array($cartid, $prodid, $qty);

		}
		return $this->db->query($query, $values);
	}

	// update items in cart. if qty = 0, then remove ALL
	public function remove_from_cart($qty=0, $oid=0, $proid=0) {
		if($qty) {
			$query = "UPDATE pivot_order-products SET quantity = ? WHERE order_id = ? AND product_id = ?";
			$values = array($qty,$oid,$prodid);
		
		} else {
			$query = "DELETE FROM pivot_order-products WHERE order_id = ? AND product_id = ?";
			$values = array($oid,$prodid);

		}
		return $this->db->query($query,$values);
	}

	public function clear_cart($cartid=0) {
		$query = "DELETE FROM pivot_order-products WHERE order_id = ?";
		$values = array($cartid);
		return $this->db->query($query,$values);

	}
}
?><file_sep>/website/application/views/dashboard.php
<?php 		$this->load->view('adminheader');
?>


		<div class="container">
			<div class="row" id="dashheader">
				<div class="col-sm-2"> <!-- search box -->
					<form role="form" action="adminordersearch" method="post">
						<div class="form-group">
							<input type="text" class="form-control" name="adminordersearch" placeholder="search">
						</div>
					</form>
				</div> <!-- search box -->
				<div class="col-sm-2 col-sm-offset-8"> <!-- dropdown -->
					<form role="form" action="adminorderfilter" method="post">
						<div class="form-group">
							  <select class="form-control" name="adminorderfilter">
				   				 <option value="showall">Show All</option>
								 <option value="inprocess">Order In Process</option>
								 <option value="shipped">Shipped</option>
							  </select>
						</div>
					</form>
				</div> <!--dropdown -->
			</div> <!-- dashheader -->
			<div class="row" id="dashbody">
				<table class="table table-striped">
					<thead>
						<tr>
							<th>Order ID</th>
							<th>Name</th>
							<th>Date</th>
							<th>Billing Address</th>
							<th>Total</th>
							<th>Status</th>
						</tr>
					</thead>
					<tbody>
<?php 					foreach($ordersindb as $row) {
	?>						<tr>
								<td><a href="showorder/<?= $row['oid'] ?>"><?= $row['oid'] ?></a></td>
								<td><?= $row['bill_name'] ?></td>
								<td><?= $row['created_at'] ?></td>
								<td><?= $row['bill_street']." ".$row['bill_street2']. ", ".
								$row['bill_city']. " ". $row['bill_state']." ". $row['bill_zip'] ?></td>
								<td><?= $totalarray[$row['oid']] ?></td>
								<TD>
									<!-- default value of order status needs to be set by jquery: .attr("selected","true") -->
									<form role="form" action="changeorderstatus" method="post">
										<div class="form-group">
								  			<select class="form-control" name="adminorderfilter" id="<?= $row['id'] ?>">
								   				 <option value="cancelled">Cancelled</option>
												 <option value="inprocess">Order In Process</option>
												 <option value="shipped">Shipped</option>
											</select>
										</div> 
									</form>
								</TD>
							</tr>
<?php 					} //foreach
?>					</tbody>
				</table>
			</div> <!-- dashbody -->
			<div class="row" id="dashpagination">
				<div class="col-sm-3 col-sm-offset-4">
			<!-- how many pages will be determined by db data -->
				 <ul class="pagination">
				  <li><a href="#">1</a></li>
				  <li><a href="#">2</a></li>
				  <li><a href="#">3</a></li>
				  <li><a href="#">4</a></li>
				  <li><a href="#">5</a></li>
				</ul>
			</div>
			</div> <!-- dashpagination -->
		</div> <!-- container-->
	</body> 
</html><file_sep>/README.md
# DojoStoreEcommerce
The dojo Store with DB and order admin with backend.

Mount MAMP or WAMP at the /website folder for root.

Other directories adjacent or above this directory contain files
for the rest of the site. Database for My SQL, or readme dox, notes. etc.

the ERD is there as well.

--------------------------------------------------------------------
UPDATE: 2/8/2015

created EcomData model for the loading, changing and removal of products in the ecomm store.
created CartData model for adding/editing/removing cart data for shopping.
<file_sep>/website/application/controllers/admins.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admins extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
//		$this->output->enable_profiler();
	}

	public function index() {
		// if admin is logged in, take them to the dash, otherwise, to the login screen
		if (isset($this->session->adminid)) 
			$this->dashboard();
		else
			$this->load->view('admin');
	}

	public function login() {
		$this->load->model('mydb'); 
		$email = $this->input->post('email');
		$password = $this->input->post('password');
		
		//checks info against db
		$check = $this->mydb->get_admin_by_email($email); 
		if($check && ($check['password']==$password)) {
			//good info: log in
			$this->dashboard();
		} else {
			//bad info: bounce back with an error message.
			$this->session->set_flashdata('errors', "Credentials don't match. Try again.");
			$this->load->view('admin'); 
			$this->dashboard();
		}
	}

	public function logoff() {
		//destroy session data
		$this->session->sess_destroy();
		//redirect to login page
		$this->index();
	}

	public function dashboard() {
		$this->load->model('EcomData');
		$adminid = $this->session->userdata('adminid');
		$ordersindb = $this->EcomData->get_all_orders();
		$numresults = count($ordersindb);
		//calculate total of order and add it to the data
		$totalarray = [];
		foreach ($ordersindb as $order) {
			$total = $this->EcomData->get_order_total($order['oid']);
			$totalarray[$order['oid']] = $total;
		}
		$this->load->view('dashboard', array('adminid' => $adminid, "ordersindb" => $ordersindb, 'numresults' => $numresults, 'totalarray' => $totalarray));
	}

	public function showorder($id) {
		$this->load->model('EcomData');
		$order = $this->EcomData->get_order_by_id($id);
		$this->load->view('showorder', array('order' => $order, 'adminid' => $this->session->userdata('adminid')));
	}

	public function products() {
		$this->load->view('adminproductpage', array('adminid' => $this->session->userdata('adminid')));
	}


}

//end of main controller<file_sep>/website/application/controllers/userData.php
<?php
//
// MODEL for userData DB.  Kristy/Matt/Peter
//
class userData extends CI_model {

	// admin functions.  get data to login.
	// set last_login date.
	public function get_admin($uEmail,$uPassword) {
		return $this->db->query('SELECT * FROM admins WHERE email = ? AND password = ?', array($id))->row_array();
	}
	
	public function update_login($id) {
		$this->db->query('UPDATE admins SET last_login = now() WHERE aid = ?');
		return;
	}
}
?><file_sep>/website/application/views/admin.php
<?php 		$this->load->view('adminheader');
?>


		<div class="container">
			<div class="row">
				<div class="col-sm-4" "col-sm-offset-2">
					<h1>Admin Login Page</h1>
				</div>
			</div>
<?php if (null !== ($this->session->flashdata('errors'))) {
?>		<div class="row">
			<div class="col-sm-10">
				<h1 style="color:red"><?= $this->session->flashdata('errors') ?></h1>
			</div>
		</div>
<?php }	
?>			<div class="row">
				<div class="col-sm-4 col-sm-offset-2">
					<form role="form" action="login" method="post">
						<div class="form-group">
							<label for="email">Email:</label>
							<input type="text" class="form-control" name="email">
						</div>
						<div class="form-group">	
							<label for="<PASSWORD>">Password</label>
							<input type="<PASSWORD>" class="form-control" name="<PASSWORD>">
						</div>
						<input class="btn btn-success" type="submit" value="log in">
					</form>
		</div>
		</div>
	</body>
</html><file_sep>/website/application/views/productinfo.php
<html>
<head>
	<title>Product Info</title>
	<style type="text/css">
		*{
			margin: 0px;
			padding: 0px;
		}
		#header{
			background-color: black;
			color:white;
			width:100%;
			height:50px;
			font-size: 36px;
		}
		#header a{
			margin-left: 70%;
			color:white;
		}
		#images,#description{
			margin-top: 20px;
			display: inline-block;
			vertical-align: top;
		}
		#images{
			width:20%;
		}
		.blowup{
			height:200px;
			width:200px;
			display: block;
		}
		.thumbnail{
			height:50px;
			width:50px;
		}
		#description{
			width:70%;
			margin-left: 5%;
		}
		#similar div{
			display: inline-block;
		}
	</style>
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
	<script type="text/javascript">
	$('document').ready(function(){
		$('.thumbnail').hover(function(){
			$src=$(this).attr('src');
			$('.blowup').attr('src',$src);
		});
	});
	</script>
</head>
<body>
	<div id="header">
<<<<<<< HEAD
		Dojo eCommerce
		<a href="/main/cart">View Cart<?php echo "(".$cart['items']."): $".$cart['total']; ?></a>
=======
		Dojo eCommerse
		<a href="/main/cart">View Cart</a>
>>>>>>> remotes/origin/master
	</div>
	<a href="/">Go Back</a>
	<h1>(Product Name Here)</h1>
	<div id="info">
		<div id="images">
			<p>(Pictures Go Here)</p>
			<img class="blowup" src="front.png" alt="product image">
			<img class="thumbnail" src="side.png" alt="product image">
			<img class="thumbnail" src="front.png" alt="product image">
			<img class="thumbnail" src="back.png" alt="product image">
		</div>
		<div id="description">
			description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...description about the product...
			<form action="/main/add" method="post">
<<<<<<< HEAD
				<input type="hidden" name="product_id" value=<?php $product['id'] ?> />
=======
>>>>>>> remotes/origin/master
				<input type="number" name="quantity" min="1">
				<input type="submit" value="Add to Cart">
			</form>
		</div>
	</div>
	<div id="similar">
		<h3>Similar Items</h3>
		<?php 
			foreach ($similar as $row) {
				echo "<div><a href='/main/info/".$row['id']."'><img src=".$row['src']." alt='product image'><p>".$row['name']."</p></a></div>";
			}
		?>
	</div>
</body>
</html><file_sep>/db/store.sql
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 1172.16.31.10
-- Generation Time: Feb 10, 2015 at 11:46 PM
-- Server version: 5.6.17
-- PHP Version: 5.5.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `store`
--

-- --------------------------------------------------------

--
-- Table structure for table `admins`
--

CREATE TABLE IF NOT EXISTS `admins` (
  `aid` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(30) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT 'admin first name',
  `last_name` varchar(45) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT 'admin lastname',
  `email` varchar(120) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'email which is also the admins logon name - cannot be null',
  `password` varchar(15) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '<PASSWORD>',
  `last_login` datetime DEFAULT NULL COMMENT 'date and time of last admin login.  -- should we keep a file log as well?',
  `created_on` datetime DEFAULT NULL,
  `modified_on` datetime DEFAULT NULL,
  PRIMARY KEY (`aid`),
  KEY `prim` (`aid`) USING BTREE,
  KEY `logon` (`email`,`password`) USING BTREE,
  KEY `for logon trace` (`first_name`,`last_name`,`last_login`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `admins`
--

INSERT INTO `admins` (`aid`, `first_name`, `last_name`, `email`, `password`, `last_login`, `created_on`, `modified_on`) VALUES
(1, 'Peter', 'Richards', '<EMAIL>', '', NULL, '2015-02-06 14:02:59', '2015-02-06 14:03:01');

-- --------------------------------------------------------

--
-- Table structure for table `carriers`
--

CREATE TABLE IF NOT EXISTS `carriers` (
  `cid` int(11) NOT NULL AUTO_INCREMENT,
  `Carrier` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'name of the carrier',
  PRIMARY KEY (`cid`),
  KEY `prim` (`cid`,`Carrier`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `carriers`
--

INSERT INTO `carriers` (`cid`, `Carrier`) VALUES
(1, 'UPS'),
(2, 'FedEx'),
(3, 'USPS'),
(4, 'Drone');

-- --------------------------------------------------------

--
-- Table structure for table `categories`
--

CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `active` int(11) DEFAULT '1' COMMENT 'defaults to 1 for active, 0 means we are disabling the active state of this category',
  `category` varchar(80) DEFAULT NULL COMMENT 'name of category (NOT PRODUCTS)',
  `created_on` datetime DEFAULT NULL,
  `modified_on` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `prim` (`id`) USING BTREE,
  KEY `show and where` (`active`,`category`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `categories`
--

INSERT INTO `categories` (`id`, `active`, `category`, `created_on`, `modified_on`) VALUES
(1, 1, 'T-Shirts', '2015-02-06 14:07:25', '2015-02-06 14:07:27'),
(2, 1, 'Shoes', '2015-02-06 14:07:40', '2015-02-06 14:07:42'),
(3, 1, 'Cups', '2015-02-06 14:07:54', '2015-02-06 14:07:56'),
(4, 1, 'Fruits', '2015-02-06 14:08:07', '2015-02-06 14:08:10');

-- --------------------------------------------------------

--
-- Table structure for table `orders`
--

CREATE TABLE IF NOT EXISTS `orders` (
  `oid` int(11) NOT NULL AUTO_INCREMENT,
  `status` int(11) DEFAULT NULL COMMENT 'status of order:  pending, shipping, on carrier, delivered',
  `carrier_id` int(11) DEFAULT NULL COMMENT 'carrier id, table carriers will have fed ex, ups, etc.',
  `ship_name` varchar(50) NOT NULL,
  `ship_street` varchar(100) NOT NULL,
  `ship_street2` varchar(100) DEFAULT NULL,
  `ship_city` varchar(50) NOT NULL,
  `ship_state` varchar(2) DEFAULT NULL,
  `ship_zip` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'shipping zip. must be present',
  `bill_name` varchar(50) NOT NULL,
  `bill_street` varchar(100) NOT NULL,
  `bill_street2` varchar(100) DEFAULT NULL,
  `bill_city` varchar(50) NOT NULL,
  `bill_state` varchar(2) DEFAULT NULL,
  `bill_zip` varchar(10) NOT NULL,
  PRIMARY KEY (`oid`),
  KEY `prim` (`oid`) USING BTREE,
  KEY `statuscar` (`status`,`carrier_id`) USING BTREE,
  KEY `billing` (`bill_zip`) USING BTREE,
  KEY `shipping` (`ship_zip`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `photos`
--

CREATE TABLE IF NOT EXISTS `photos` (
  `phid` int(11) NOT NULL AUTO_INCREMENT,
  `prod_id` int(11) DEFAULT '0' COMMENT 'id of the product this belongs to',
  `sort` int(11) DEFAULT '0' COMMENT 'order the photo should show in, low to high. 0-9 type.',
  `file_path` varchar(300) DEFAULT NULL,
  `caption` varchar(150) DEFAULT NULL COMMENT 'caption or comment on photo',
  `created_on` datetime DEFAULT NULL,
  `modified_on` datetime DEFAULT NULL,
  PRIMARY KEY (`phid`),
  KEY `prim` (`phid`) USING BTREE,
  KEY `for filters` (`sort`,`modified_on`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `photos`
--

INSERT INTO `photos` (`phid`, `prod_id`, `sort`, `file_path`, `caption`, `created_on`, `modified_on`) VALUES
(1, 1, 0, 'sweat-shirt_green.png', 'Green. Shirt. Yes.', '2015-02-09 00:00:00', '2015-02-09 00:00:00'),
(2, 2, 0, 't-shirt_red.png', 'No really, an ice cream scoop.', '2015-02-03 00:00:00', '2015-02-03 00:00:00');

-- --------------------------------------------------------

--
-- Table structure for table `pivot_order-products`
--

CREATE TABLE IF NOT EXISTS `pivot_order-products` (
  `order_id` int(11) NOT NULL DEFAULT '0',
  `product_id` int(11) NOT NULL DEFAULT '0',
  `quantity` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`order_id`,`product_id`,`quantity`),
  KEY `main` (`order_id`,`product_id`,`quantity`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Table structure for table `pivot_related_cats`
--

CREATE TABLE IF NOT EXISTS `pivot_related_cats` (
  `ref_category` int(11) NOT NULL DEFAULT '0',
  `rel_category` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ref_category`,`rel_category`),
  KEY `main` (`ref_category`,`rel_category`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Table structure for table `pivot_related_prods`
--

CREATE TABLE IF NOT EXISTS `pivot_related_prods` (
  `ref_prod_id` int(11) NOT NULL DEFAULT '0',
  `rel_prod_id` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ref_prod_id`,`rel_prod_id`),
  KEY `main` (`ref_prod_id`,`rel_prod_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Table structure for table `products`
--

CREATE TABLE IF NOT EXISTS `products` (
  `pid` int(11) NOT NULL AUTO_INCREMENT,
  `catid` int(11) DEFAULT NULL,
  `inventory` int(11) DEFAULT '0' COMMENT 'simple inventory.  could be in sep table with inventory :: qty, order date, suplier....',
  `added_by` int(11) DEFAULT NULL COMMENT 'the admin who added this product',
  `price` decimal(10,2) DEFAULT '0.00' COMMENT 'price per unit',
  `taxable` int(11) DEFAULT '0' COMMENT 'true or false for taxable item',
  `product` varchar(200) DEFAULT NULL,
  `format` varchar(30) DEFAULT NULL COMMENT 'for comes in packs of 12, or 3 to a pack, or any type of unit',
  `description` text COMMENT 'long description of item.',
  `created_on` datetime DEFAULT NULL,
  `modified_on` datetime DEFAULT NULL,
  PRIMARY KEY (`pid`),
  KEY `main index` (`pid`) USING BTREE,
  KEY `cat` (`catid`) USING BTREE,
  KEY `added_date` (`added_by`,`created_on`) USING BTREE,
  KEY `for filtering` (`inventory`,`price`,`taxable`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `products`
--

INSERT INTO `products` (`pid`, `catid`, `inventory`, `added_by`, `price`, `taxable`, `product`, `format`, `description`, `created_on`, `modified_on`) VALUES
(1, 2, 13, 2, '24.99', 0, 'Upcycled Ninja Mask', NULL, 'Your very own ninja mask upcycled from discarded bike tires!', '2015-02-10 00:00:00', '2015-02-10 00:00:00'),
(2, 3, 5, 2, '3.13', 0, 'Ice Cream Scoop', NULL, 'Cast iron artisanal ice cream scoop. Yum. ', '2015-02-03 00:00:00', '2015-02-03 00:00:00');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
<file_sep>/website/application/controllers/main.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends CI_Controller {

<<<<<<< HEAD
	// ALL MODELS ARE LOADED IN AUTOLOAD during config setup.

	// 	$this->output->enable_profiler();
	// 

	public function __construct() {
		parent::__construct();
	}

	public function index()
	{
		// loads data for landing page - products, categories and cart totals data.
		$productInfo = $this->EcomData->get_all_products();	// return list of all products
		$categories = $this->EcomData->get_category_info(); // return list of all categories
		
		if($this->session->userdata('cartid')) {  // should we just use session_id for the cartid??
			$cartid = $this->session->userdata('cartid');
			$cartTotalItems = $this->CartData->cartTotal($cartid);
		} else {
			$cartid = 0;
			$cartTotalItems = 0;
		}
		 // get current cart info

		// by passing these record sets below, we don't have a way to traverse the list unless we use a associative array with a name for each of these.
		$values = array('productInfo'=>$productInfo,'cartItems' => $CartTotalItems, 'numproducts' => count($productInfo), 'categories' => $categories);
		$this->load->view('landing',$values);

	}

	public function showdetails($pid=0) {

		$results = $this->Ecomdata->get_data_id($pid);
		$this->load->view('product_info',array('data' => $results));

	}

	public function cartTotal($cartid=0)
	{
		// must pass cart id in to this function so that database knows which items to pull, and use
		// for calculation. 
		//this function calculates the cart info to be displayed in the header
		//Fully Functional
		$cartInfo = $this->CartData->get_all_data($cartid);
=======
	// public function __construct()
	// {
	// 	parent::__construct();
	// 	$this->output->enable_profiler();
	// }

	public function index()
	{

		$this->load->model('EcomData');
		$productInfo = $this->EcomData->get_all_product_info();	
		$categories = $this->EcomData->get_category_info();
		$cart=$this->cartTotal();
		$this->load->view('landing',array('productInfo'=>$productInfo,/*'cart'=>$cart ,*/ 'numproducts' => count($productInfo), 'categories' => $categories));

	}

	public function cartTotal()
	{
		//this function calculates the cart info to be displayed in the header
		//Fully Functional
		$this->load->model('CartData');
>>>>>>> 4729fe55dece6c1d9356d0ed120b4fd8ead7ec07
	//	$cartInfo=$this->CartData->get_all_data($cartid=0);
		$items=0;
		$total=0;
		foreach ($cartInfo as $item) {
			$items++;
<<<<<<< HEAD
			$total = $total+$item['price']*$item['quantity'];
		}
		return array('items'=>$items,'total'=>$total);
	}
	public function cart($cartid)
	{
		//load necessary information and display the Cart page
		//Fully Functional
		$cartInfo = $this->CartData->get_all_data($cartid);
		$cart = $this->cartTotal($cartid);
=======
			$total=$total+$item['price']*$item['quantity'];
		}
		return array('items'=>$items,'total'=>$total);
	}
	public function cart()
	{
		//load necessary information and display the Cart page
		//Fully Functional
		$this->load->model('CartData');
		$cartInfo=$this->CartData->get_all_data($cartid=0);
		$cart=$this->cartTotal();
>>>>>>> 4729fe55dece6c1d9356d0ed120b4fd8ead7ec07
		$this->load->view('cart',array('cartInfo'=>$cartInfo,'cart'=>$cart));
	}
	public function info()
	{
		//Load the view for the Product Info page.
<<<<<<< HEAD
		$cart = $this->cartTotal($cartid);
=======
		$cart=$this->cartTotal();
>>>>>>> 4729fe55dece6c1d9356d0ed120b4fd8ead7ec07
		$this->load->view('productinfo',array('cart'=>$cart));
	}
	public function add(){
		//from Product Info page.  This will add an item to the cart, but not currently functional.
<<<<<<< HEAD
		$product = $this->input->post('product_id');
		$quantity = $this->input->post('quantity');
=======
		$product=$this->input->post('product_id');
		$quantity=$this->input->post('quantity');
>>>>>>> 4729fe55dece6c1d9356d0ed120b4fd8ead7ec07
	}
	public function remove($id)
	{
		//deletes a single item from the cart.  
		//Fully functional.
<<<<<<< HEAD
		$this->load->CartData->remove_from_cart($id);
		redirect('/main/cart');
	}
	public function delete($cartid)
	{
		//deletes the entire cart.  
		//Fully Functional.
		$this->load->CartData->clear_cart($cartid);
=======
		$this->load->model('CartData');
		$this->CartData->remove_data($id);
		redirect('/main/cart');
	}
	public function delete()
	{
		//deletes the entire cart.  
		//Fully Functional.
		$this->load->model('CartData');
		$this->CartData->clear_cart();
>>>>>>> 4729fe55dece6c1d9356d0ed120b4fd8ead7ec07
		redirect('/');
	}
	public function order()
	{
		//when an order is placed, load the confirmation page.
		//Need to add form validation, Stripe API, and database interaction.
		$shipping=array('first'=>$this->input->post('ship_first'),
						'last'=>$this->input->post('ship_last'),
						'street1'=>$this->input->post('ship_street1'),
						'street2'=>$this->input->post('ship_street2'),
						'city'=>$this->input->post('ship_city'),
						'state'=>$this->input->post('ship_state'),
						'zip'=>$this->input->post('ship_zip')
						);
		if ($this->input->post('same_info')=='same_info'){
			$billing=$shipping;
		}
		else{
			$billing=array('first'=>$this->input->post('bill_first'),
							'last'=>$this->input->post('bill_last'),
							'street1'=>$this->input->post('bill_street1'),
							'street2'=>$this->input->post('bill_street2'),
							'city'=>$this->input->post('bill_city'),
							'state'=>$this->input->post('bill_state'),
							'zip'=>$this->input->post('bill_zip')
						);
		}
		$card=array('number'=>$this->input->post('bill_card'),
						'ccv'=>$this->input->post('bill_security'),
						'expiration'=>$this->input->post('bill_date')
						);
		$this->session->set_userdata('shipping',$shipping);
		$this->session->set_userdata('billing',$billing);
		$this->session->set_userdata('card',$card);
		$this->session->set_userdata('total',$this->input->post('total'));
		echo $this->input->post('total');
		echo $this->session->userdata('total');
		redirect('/main/confirmation');
	}
	public function confirmation(){
		//Loads the confirmation page and then resets all session data and clears the cart.
		//Fully Functional.
		$shipping=$this->session->userdata('shipping');
		$billing=$this->session->userdata('billing');
		$card=$this->session->userdata('card');
		$total=$this->session->userdata('total');
<<<<<<< HEAD
		unset($this->session->userdata);  // does this work or do we use destroy_session??
		$this->load->CartData->clear_cart($cartid);
=======
		unset($this->session->userdata);
		$this->load->model('CartData');
		$this->CartData->clear_cart();
>>>>>>> 4729fe55dece6c1d9356d0ed120b4fd8ead7ec07
		$this->load->view('confirmation',array('shipping'=>$shipping,'billing'=>$billing,'card'=>$card,'total'=>$total));
	}


	public function admin()
	{
<<<<<<< HEAD
		// show admin login
=======
>>>>>>> 4729fe55dece6c1d9356d0ed120b4fd8ead7ec07
		$this->load->view('login');
	} 
}

//end of main controller
<file_sep>/website/application/controllers/filters.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Filters extends CI_Controller {

	// public function __construct()
	// {
	// 	parent::__construct();
	// 	$this->output->enable_profiler();
	// }
	public function search() {
<<<<<<< HEAD
		
		// all search is partial match (perhaps do soundex search in future)
		//finds every product in the database containing the search term in any field
		
		$searchterm = $this->input->post('product');
		// sanitize the searchterm
		$searchterm = escape_this_string($searchterm);
		
		$results = $this->EcomData->get_from_db_by_keyword($searchterm);

		if($this->session->userdata('cartid')) {  // should we just use session_id for the cartid??
			$cartid = $this->session->userdata('cartid');
			$cartTotalItems = $this->CartData->cartTotal($cartid); // get total number of items based on current cart id
		
		} else {
			$cartid = 0;
			$cartTotalItems = 0;
		
		}
		
		// search term also gets categories that match as well. we can show the matching cats as well.
		$categories = $this->EcomData->get_select_category_info($searchterm);
		
		$values = array('productinfo' => $results, 'carttotal' => $cartTotalItems, 'categories' => $categories);
		// we don't need to pass count of $results as we can calculate on the fly easily during view.
		$this->load->view('landing',$values);
	}

}
=======
		//finds every product in the database containing the search term in any field
		$searchterm = $this->input->post('product');
		$this->load->model('EcomData');
		$results = $this->EcomData->get_from_db_by_keyword($searchterm);

		//reloads the landing page with results as product info
		$categories = $this->EcomData->get_select_category_info($searchterm);
		$this->load->view('landing',array
			('productInfo'=>$results,/*'cart'=>$cart ,*/ 'numproducts' => count($results), 'categories' => $categories));
	}


	
}

>>>>>>> 4729fe55dece6c1d9356d0ed120b4fd8ead7ec07
//end of filters controller
<file_sep>/website/application/views/landing.php
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

	<title>Products</title>
	<style type="text/css">
		*{
			margin: 0px;
			padding: 0px;
		}

		h6 a {
			float:right;
			text-decoration: none;
			color:silver;
			margin:60px;
		}
		#header{
			background-color: black;
			color:white;
			width:100%;
			height:50px;
			font-size: 36px;
			margin-bottom: 50px;
		}
		#header a{
			margin-left: 70%;
			color:white;
		}
		#sidebar, #content{
			display: inline-block;
			vertical-align: top;
			border: 1px solid black;
		}
		#sidebar{
			padding:20px;
		}
		#sidebar li{
			margin: 10px;
			margin-left: 30px;
		}
		#content{
			margin-left: 50px;
			width:70%;
			padding: 20px;
		}
		#nav{
			margin-left: 85%
		}


		.cell {
			border: 1px solid black;
			height:150px;
			width:150px;
			margin:15px;
			display: inline-block;
		}

		.cell img {
			width:150px;
			height:150px;
			margin:0px;
		}

		.infobanner {
			border:1px solid black;
			height:36px;
			margin-top:-36px;
			background-color:#bbbbbb;
			opacity: 0.7;
		}

		.infocell {
			display: inline-block;
			width:45%;
		}
	</style>
</head>
<body>
	<div id="header">
		Dojo eCommerce
		<a href="/main/cart">View Cart<?php echo "(".$cart['items']."): $".$cart['total']; ?></a>
		<a href="/main/cart">View Cart</a>
	</div>
	<div id="sidebar">
		<form id="search" action="search" method="post">
			<input type="text" name="product">
			<input type="submit" value="Search">
		</form>
		<h4>Categories:</h4>
		<ul>
			<li><a href='/'>All Products</a></li>
<?php 		foreach ($categories as $category) {
?> 			<li><a href='#'><?=$category['category']?> (<?= $category['count(*)']?>)</a></li>
<?php 		}
?> 
		</ul>
	</div>
	<div id="content">
		<h2>Products (Page $)</h2>
		<div id="nav">
		<a href="#">Prev</a>
		<a href="#">Next</a>
		<form action="/main/sort" method="post">
			<p>Sort By:<select><option>Price</option><option>Most Popular</option></select></p>
		</form>
		</div>
<?php 	$this->load->view('productdisplay');
?>		
		<?php 
			$pages=floor(count($productInfo)/15)+1;
			for($i=1;$i<=$pages;$i++){
				echo "<a href='/main/page/".$i."'>".$i."</a>";
			}
		?>		

	</div>
</div></div>
	<div id="footer">
		<h6><a href="admin">Admin Login</a></h6>
	</div>
</body>
</html><file_sep>/website/application/views/adminheader.php
<!doctype html>
<html>
<head>
	<title>Admin</title>

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>


		<!-- Latest compiled and minified CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">

	<!-- Optional theme -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">

	<!-- Latest compiled and minified JavaScript -->
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
	<style>

		.navbar-default, nav li{
			background-color: #990000;
			background-image:none;
			color:#ffffff;
		}
		.navbar-default .navbar-nav>li>a, .navbar-default .navbar-brand {
			color:#ffffff;
		}

		.navbar-default a {
			color:#ffffff;
		}
		body {
			padding-top:70px;
		}
		.bordered {
			border:1px solid black;
		}
		.navbar-right {
			padding-top:15px;
		}
		#orderinfotable div {
			padding:10px;
		}
		#statusbox, #totalpricebox  {
			margin-top:20px;
		}
		img {
			height:50px;
		}
	</style>
	<script>
	$(document).on('click', '.modaltrigger', function(){
		if($(this).attr('which')=="add") {
			$('#myModalLabel').html('Add Product');
		} else {
			$('#myModalLabel').html('Edit Product - ID ##ID##');
		}
	});
	</script>

</head>
<body>

<!-- if admin is logged in, show nav bar -->
<?php if(isset($adminid)) {
		echo $adminid; 
?>		<nav id="adminnavbar" class="nav navbar navbar-default navbar-fixed-top">
			<div class="container">
				<div class="nav navbar-header">
					<div class="navbar-brand">Dashboard
					</div>
				</div>
				<div class="nav navbar-nav">
					<ul class="nav navbar-nav">
						<li><a href="/dashboard">Orders</a></li>
						<li><a href="/adminproducts">Products</a></li>
					</ul>
				</div>
				<div class="nav navbar-right navbar-nav"><a href="/logoff">log off</a>
				</div>
			</div>
		</nav>

<?php	}
?><file_sep>/website/application/views/product_info.php
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>The Store: Product Info</title>
	<link rel="stylesheet" type="text/css" href="/assets/css/details.css">
	<script type="text/javascript" src="/assets/scripts/jquery-2.1.3.min.js"></script>
	<script type="text/javascript">

		$(document).ready(function() {

			$('#qty').on('keyup','',function() {
				var x = $('input[id=qty]').val(); 
				var y = $('#qty').attr('valtag');
				var z = x * y;
				$('#total').text('$'+z.toFixed(2));
			});

			$('img[class=picsmall]').hover(function() {
				var tmp = $(this).attr('src');
				$('img[id=pic1]').fadeOut(200);
				$('img[id=pic1]').attr('src',tmp);
				$('img[id=pic1]').fadeIn(200);

			}, function() {


			});

			$('#mainform').on('submit',function() {
				var form = $(this);
				// console.log('here');
				
				$.post(
					form.attr('action'),
					form.serialize(),
					function(output) {
					// 
					}
					,"json");

				return false;
			});
		});
	</script>
</head>
<body>

<?php
	// echo "<pre>";
	// var_dump($data);
	// echo "</pre>";
	// // die();

	$title = $data[0]['product'];
	$main_file = $data[0]['file_path'];
	$caption = $data[0]['caption'];
	// echo "****".$main_file;
	// exit;

?>
<div id="container">

	<div id="nav">
		<a href="/">Go Back</a>
	</div>

	<div id="photos">

		<h3><?= $title ?></h3>
		<div id="main-phot">
			<img id="pic1" class="mainpic" src="/assets/images/<?= $main_file ?>" alt='Main photo' border=0 width=350 height=350>
			<br><span id="subtitle"><?= $caption ?></span>
		</div>

		<div id="smallpix">
		<?php
		// echo "<pre>";
		// var_dump($results);
		// echo "</pre>";
		// exit;
			foreach($data as $row) {
				echo "<div class='divsmall'>";
				echo "<img class='picsmall' src='/assets/images/".$row['file_path']."' border=0 height='50' width='50'>";
				echo "</div>";
			}
		?>
		<div class='clear'></div>
		</div>
	</div>

	<div id="description">
		<p><?= $data[0]['description'] ?></p>
		<div id="buyarea">
			Qty: <input id='qty' valtag='<?=$data[0]['price']?>' type="text" size=3 name="qty" maxlength=3 class="qtyinput"> X <?=$data[0]['price'] ?> :: <label id='total' for='total'>$0.00</label>
		</div>
	</div>
	<div class="clear"></div>



</div>

</body>
</html><file_sep>/website/application/controllers/EcomData.php
<?php
//
// MODEL for Ecommerce Site.  Kristy/Matt/Peter
//
class EcomData extends CI_model {

	//
	// *******************************************************************
	// Get data files towards top of file as they will be used more than
	// write functions
	//
	// 
	public function get_all_products() {
		// gets all products in database with their category and inventory.  order by: category, product title, and category active is true
		$query = 'SELECT products.pid, products.catid, categories.id, categories.active, categories.category, products.inventory, ';
		$query = $query.'products.price, products.taxable, products.product, products.description, photos.sort, photos.file_path, ';
		$query = $query.'photos.caption FROM categories LEFT OUTER JOIN products ON categories.id = products.catid ';
	 	$query = $query.'LEFT OUTER JOIN photos ON products.pid = photos.prod_id WHERE pid IS NOT NULL AND categories.active = 1 ';
	 	$query = $query.'ORDER BY category, product';

		return $this->db->query($query)->result_array(); // return ALL products organized by category, products and all photos.
	}

	public function get_category_info() {
		
		$query = 'SELECT categories.cid, categories.active, categories.category ';
		$query = $query.'FROM categories WHERE active=1 ORDER BY category';
	 
		return $this->db->query($query)->result_array(); // return ALL products organized by category, products and all photos.
	}

	// get an individual row of products from this productid.
	public function get_data_id($pid = 0) {
	
		$query = 'SELECT photos.main, photos.file_path, photos.caption, products.price, ';
		$query = $query.'products.taxable, products.product, products.description, products.inventory, categories.active, ';
		$query = $query.'categories.category, products.pid FROM categories RIGHT OUTER JOIN products ON categories.cid = products.catid ';
		$query = $query.'RIGHT OUTER JOIN photos ON products.pid = photos.prod_id ';
		$query = $query.'WHERE products.pid = ? AND price is not null ORDER BY photos.main DESC';
		// echo $query;
		// exit;
		return $this->db->query($query, array($pid))->result_array();  // array of this row!
	}

	// show all related products to this product id.
	public function get_related_prod($pid=0) {

		$query = 'SELECT products.catid, products.product, products.pid, pivot_related_prods.ref_prod_id ';
		$query = $query.'FROM pivot_related_prods LEFT OUTER JOIN products ON pivot_related_prods.rel_prod_id = products.pid ';
		$query = $query.'WHERE pivot_related_prods.ref_prod_id = ?';
		$values = array($pid);

		return $this->db->query($query, $values)->result_array(); // give us a result array back
	}

	// All related categories based on this products category id.
	public function get_related_cats($cid=0) {

		$query = 'SELECT pivot_related_cats.ref_category, categories.cid, categories.active, categories.category ';
		$query = $query.'FROM pivot_related_cats RIGHT OUTER JOIN categories ON pivot_related_cats.rel_category = categories.cid ';
		$query = $query.'WHERE pivot_related_cats.ref_category = ?';
		$values = array($id);

		return $this->db->query($query, $values)->result_array();  //give a result set back
	}
	//
	// *************************************************************************
	public function add_product($values) {
		// do we need this?  perhaps to update price, taxable product description, etc.
		$query = 'INSERT INTO products (catid, inventory, added_by, price, taxable, product, description, created_on, modified_on) ';
		$query = $query.'VALUES (?,?,?,?,?,?,?,now(),now())';
		$tmp = $this->db->query($query, $values);

		return $this->db->$insert_id; // passback the row id for this insertion
	}

	//
	// *************************************************************************
	public function update_product($id, $values) {
		// do we need this?  perhaps to update price, taxable product description, etc.
		$query = 'UPDATE products SET carid = ?, inventory = ?, add_by = ?, price = ?, taxable = ?, product = ?, description = ?, modified_on = now() WHERE pid = ?';
		
		// ****** we need to add the id onto the values before we execute
		$values = array($id); // push id of this record onto array for update.
		return $this->db->query($query, $values);
	}

	public function remove_data($id) {
		// only put in title and desc since we are doing triggers for auto updates on timestamp and created
		
		$query = 'DELETE FROM products WHERE pid = ?';
		$values = array('id' => $id);

		// doesn't return anything but a value to show it succeeded. if 0 then broke.
		return $this->db->query($query, $values);

	}

}
?><file_sep>/website/application/views/confirmation.php
<html>
<head>
	<title>Order Confirmation</title>
</head>
<body>
<!-- this page simply displays the information that was entered in the order form. -->
<!-- Does not require any further processing or database interaction -->
	<h1>Thank you for your order!</h1>
	<h2>Shipping Address</h2>
	<?php 
		echo "<p>First Name: ".$shipping['first']."</p>
			<p>Last Name: ".$shipping['last']."</p>
			<p>Street Address: ".$shipping['street1']." ".$shipping['street2']."</p>
			<p>City: ".$shipping['city']."</p>
			<p>State: ".$shipping['state']."</p>
			<p>Zip Code: ".$shipping['zip']."</p>";
	?>
	<h2>Billing Address</h2>
	<?php 
		echo "<p>First Name: ".$billing['first']."</p>
			<p>Last Name: ".$billing['last']."</p>
			<p>Street Address: ".$billing['street1']." ".$billing['street2']."</p>
			<p>City: ".$billing['city']."</p>
			<p>State: ".$billing['state']."</p>
			<p>Zip Code: ".$billing['zip']."</p>";
	?>
	<h2>Credit Card Information</h2>
	<?php 
		echo "<p>Card Number: ".$card['number']."</p>
			<p>Expiration Date: ".$card['expiration']."</p>
			<p>Total:".$total."</p>";
	?>
	<a href="/"><button>Back to Home</button></a>
</body>
</html><file_sep>/website/application/views/productdisplay.php
<!-- generate product info area 
	make 5x3 
	from db, pull image, name, price
-->

<?php 	
		for($j = 0;$j<3;$j++){
?>			<div class="row">
<?php 			for($i=0;$i<5;$i++){
					if($i+($j*5) < $numproducts) {
?>						<div class="cell">
<?php 						echo img("assets/images/".$productInfo[$i+($j*5)]['file_path']); 
?>							<div class="infobanner">
								<div class="infocell">
									<h6><?=$productInfo[$i+$j]['product'] ?></h6> 
								</div>
								<div class="infocell">
									<h4><?= $productInfo[$i+$j]['price'] ?></h4>
								</div>
							</div>
						</div>
<?php 				} //if
				} //for-i
			} //for-j
?>
</div><file_sep>/website/application/views/showorder.php
<?php 		$this->load->view('adminheader');
?>

		<div class="container">
			<div class="row">
				<div class="col-sm-3 bordered" id="orderinfotable">
					<div class="row">
						<p>Order ID:<?= $order[0]['oid'] ?></p>
					</div>
					<div class="row">
						<p>Customer Shipping Info:</p>
					</div>
					<div class="row">
						<p>Name:<?= $order[0]['ship_name'] ?></p>
						<p>Address: <?= $order[0]['ship_street']." ".$order[0]['ship_street2'] ?>
						<p>City: <?= $order[0]['ship_city'] ?></p>
						<p>State:<?= $order[0]['ship_state'] ?></p>
						<p>Zip:<?= $order[0]['ship_zip'] ?></p>
					</div>
					<div class="row">
						<p>Customer Billing Info:</p>
					</div>
					<div class="row">
						<p>Name:<?= $order[0]['bill_name'] ?></p>
						<p>Address: <?= $order[0]['bill_street']. " ".$order[0]['bill_street2'] ?></p>
						<p>City: <?= $order[0]['bill_city'] ?></p>
						<p>State:<?= $order[0]['bill_state'] ?></p>
						<p>Zip:<?= $order[0]['bill_zip'] ?></p>
					</div>
				</div>
				<div class="col-sm-8 col-sm-offset-1">
					<div class="row bordered">
						<table class="table table-striped">
							<thead>
								<tr>
									<th>ID</th>
									<th>Item</th>
									<th>Price</th>
									<th>Quantity</th>
									<th>Total</th>
									</tr>
							</thead>
							<tbody>
<?php 							foreach ($order as $item) {
?>								<tr>
									<TD><?= $item['pid'] ?></TD>
	 								<TD><?= $item['product'] ?></TD>
	 								<TD>$<?= $item['price'] ?></TD>
	 								<TD><?= $item['quantity'] ?></TD>
	 								<TD>$<?= $item['price']*$item['quantity'] ?></TD>
	 							</tr>
<?php 							}
?>							</tbody>
						</table>
					</div>
					<div class="row">
						<div class="col-sm-5 bordered" id="statusbox">
							<!-- use jquery to set background color basen on status. -->
							<h2>Status: <?= $order[0]['status'] ?></h2>
						</div>
						<div class="col-sm-2">
						</div>
						<div class="col-sm-5 bordered" id="totalpricebox">
							<h3>Subtotal: $ <?= $subtotal ?></h3>
							<h3>Shipping: $Where do we get this from? <?= $shipping ?></h3>
							<h3>Total Price: $<?= $subtotal + $shipping ?></h3>
						</div>
					</div>
				</div>
			</div>
				
		</div> <!-- container-->
	</body> 
</html><file_sep>/add_admins.php
<?php

require_once('new-connection.php');

// temporary too to create encrypted passwords for the admins
function AddToDatabase($salt,$fname,$lname,$email,$pass) {
	
	$e_password = crypt($salt,$pass);
	$e_email = crypt($salt,$email);

	$query = "INSERT INTO admins (first_name, last_name, email, password, created_on, modified_on) ";
	$query = $query."VALUES ('".$fname."','".$lname."','".$e_email."','".$e_password."',NOW(),NOW() )";
	// echo $query;
	// die('here');

	run_mysql_query($query);
}

echo "STARTING TO ADD....";

$salt = bin2hex(openssl_random_pseudo_bytes(22));

$password = '<PASSWORD>';
$first_name = 'Matt';
$last_name = 'McCullough';
$email = '<EMAIL>';

AddToDatabase($salt, $first_name, $last_name, $email, $password);

$password = '<PASSWORD>';
$first_name = 'Kristy';
$last_name = 'Overton';
$email = '<EMAIL>';

AddToDatabase($salt, $first_name, $last_name, $email, $password);

$password = '<PASSWORD>';
$first_name = 'Peter';
$last_name = 'Richards';
$email = '<EMAIL>';

AddToDatabase($salt, $first_name, $last_name, $email, $password);

echo "<p>DONE!";

?><file_sep>/website/application/views/adminproductpage.php
<?php 		$this->load->view('adminheader');
?>


		<div class="container">
			<div class="row" id="dashheader">
				<div class="col-sm-6"> <!-- search box -->
					<form role="form" action="adminproductsearch" method="post">
						<div class="form-group">
							<input type="text" name="adminproductsearch"  class="form-control" placeholder="search">
						</div>
					</form>
				</div> <!-- search box -->
				<div class="col-sm-2 col-sm-offset-8"> <!-- add new product button -->
					<button type="button" class="btn btn-primary modaltrigger" data-toggle="modal" data-target="#editproduct" which="add">Add New Product</button>
				</div> <!--dropdown -->
			</div> <!-- dashheader -->
			<div class="row" id="dashbody">
				<table class="table table-striped">
					<thead>
						<tr>
							<th>Picture</th>
							<th>Product ID</th>
							<th>Name</th>
							<th>Inventory Count</th>
							<th>Quantity Sold</th>
							<th>Action</th>
						</tr>
					</thead>
					<tbody>
<?php 		//			foreach($productsindb as $row) {
	?>						<tr>
								<TD><img src="#"></TD>
								<td><?= $row['id'] ?></td>
								<td><?= $row['name'] ?></td>
								<td><?= $row['inventory'] ?></td>
								<td><?= $row['totalqtysold'] ?></td>
								<td><a href="addproduct" class="modaltrigger" data-toggle="modal" data-target="#editproduct" which="edit">edit</a> <a href="deleteproduct">delete</a></td>
							</tr>
<?php 	//				} //foreach
?>					</tbody>
				</table>
			</div> <!-- dashbody -->
			<div class="row" id="dashpagination">
				<div class="col-sm-3 col-sm-offset-4">
			<!-- how many pages will be determined by db data -->
				 <ul class="pagination">
				  <li><a href="#">1</a></li>
				  <li><a href="#">2</a></li>
				  <li><a href="#">3</a></li>
				  <li><a href="#">4</a></li>
				  <li><a href="#">5</a></li>
				</ul>
			</div>
			</div> <!-- dashpagination -->
		</div> <!-- container-->

<div class="modal fade" id="editproduct" tabindex="-1" role="dialog">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            					<h4 class="modal-title" id="myModalLabel"><!--supplied by jquery --></h4>
            				</div>
            				<div class="modal-body">
<?php 							$this->load->view('editproduct');
?>            				</div>
            				<div class="modal-footer">
            					  	<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                					<button type="button" class="btn btn-success" id="previewproduct">Preview</button>
                					<button type="submit" class="btn btn-primary">Save changes</button>
                				</form>
								</div>
        					</div>
						</div>
					</div>
				</div>

	</body> 
</html>