-
Notifications
You must be signed in to change notification settings - Fork 0
/
createBusiness.php
executable file
·71 lines (51 loc) · 2.17 KB
/
createBusiness.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
62
63
64
65
66
67
68
69
70
71
<?php
require_once 'Business.php';
require_once 'Connection.php';
require_once 'BusinessTableGateway.php';
require_once 'DealTableGateway.php';
$id = session_id();
if ($id == "") {
session_start();
}
$userId = $_SESSION['user_id'];
require 'ensureUserLoggedIn.php';
$connection = Connection::getInstance();
$gateway = new BusinessTableGateway($connection);
$dealGateway = new DealTableGateway($connection);
//Validates form data, removes harmful input
$businessId = filter_input(INPUT_POST, 'businessId', FILTER_SANITIZE_NUMBER_INT);
$business_name = filter_input(INPUT_POST, 'business_name', FILTER_SANITIZE_STRING);
$business_address = filter_input(INPUT_POST, 'business_address', FILTER_SANITIZE_STRING);
$business_lat = filter_input(INPUT_POST, 'business_lat', FILTER_SANITIZE_NUMBER_FLOAT);
$business_long = filter_input(INPUT_POST, 'business_long', FILTER_SANITIZE_NUMBER_FLOAT);
$business_type = filter_input(INPUT_POST, 'business_type', FILTER_SANITIZE_STRING);
if ($userId == -1) {
$userId = null;
}
//if statements to validate form
$errorMessage = array();
if ($business_name === FALSE || $business_name === '') {
$errorMessage['business_name'] = 'Business Name must not be blank<br/>';
}
if ($business_address === FALSE || $business_address === '') {
$errorMessage['business_address'] = 'Address must not be blank<br/>';
}
if ($business_lat === FALSE || $business_lat === '') {
$errorMessage['business_lat'] = 'Latitude must not be blank<br/>';
}
if ($business_long === FALSE || $business_long === '') {
$errorMessage['business_long'] = 'Longitude must not be blank<br/>';
}
if ($business_type === FALSE || $business_type === '') {
$errorMessage['business_type'] = 'Business type must not be blank<br/>';
}
//$deal = $dealGateway->getDealByUserId($uId);
//$row = $deal->fetch(PDO::FETCH_ASSOC);
if (empty($errorMessage)) {
$businessId = $gateway->insertBusiness($business_name, $business_address, $business_lat, $business_long, $business_type, $userId);
$message = "New Business Created";
header("Location: dealPrompt.php");
}
else {
require 'createBusinessForm.php';
}