-
Notifications
You must be signed in to change notification settings - Fork 0
/
createStock.php
executable file
·61 lines (51 loc) · 2.08 KB
/
createStock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
* This file is used to take information from a form and create a branch object
* when the object is created it is added to the database using the BranchTableGateway.php
*/
//files used by this page
require_once 'utils/functions.php';
require_once 'classes/User.php';
require_once 'classes/Stock.php';
require_once 'classes/DB.php';
require_once 'classes/StockTableGateway.php';
//php validation file
require_once 'validateStock.php';
start_session();
//ensures user is logged in else redirect to home page
if (!is_logged_in())
{
header("Location: login_form.php");
}
//calls the validate function passing in the formadata and errors array
//validate prevents the application moving forward untill the validate citria is meet
validate($formdata, $errors);
if (empty($errors))
{
//sets object properties used to set a stock
//formdata array created by the validate stock file
$stockName = $formdata['stockName'];
$stockCode = $formdata['stockCode'];
$qty = $formdata['qty'];
$openPrice = $formdata['openPrice'];
$currentPrice = $formdata['currentPrice'];
$image = $_FILES["filename"]['name'];
//cretaes a new stock object
$stock = new Stock( -1, $stockName, $stockCode, $qty, $openPrice, $currentPrice, $image );
//creates a connection
$connection = Connection::getInstance();
//uses the connection in the StockTableGateway class
$gateway = new StockTableGateway($connection);
//print_r($stock);
//sets the stockId to the return from the new stock created using the stock object above
$stockId = $gateway->newStock($stock);
//returns to the home page
//print_r($stockId);
//redirects to viewAllStock if stock created
header('Location: viewAllStock.php');
}
else
{
//remains on createStockForm is errors are contained in the form
require 'createStockForm.php';
}