/
market.php
247 lines (226 loc) · 8.56 KB
/
market.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!--
Robert Fink
rwfwcb
CMP_SC 3380
DIANA KANDER DBMS
-->
<?php
/* start the session */
session_start();
if(!isset($_SESSION['user'])) {
header("Location: /kander/login/index.php");
}
if(!isset($_SESSION['id'])) {
header("Location: /kander/login/index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>The Market</title>
<link rel="stylesheet" type="text/css" href="market.css">
<?php include "bootstrap.conf"; ?>
</head>
<body>
<?php include "navbar.html"; ?>
<script>
$(".nav > .active").removeClass('active');
$("#mark").addClass('active');
</script>
<?php
/* start the session */
session_start();
if(!isset($_SESSION['user'])) {
header("Location: /kander/login/index.php");
}
if(!isset($_SESSION['id'])) {
header("Location: /kander/login/index.php");
}
/* require credentials! */
require "db.conf";
/* connect to database */
$link = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
/* check connection */
if (!$link){
printf("Connect failed: %s\n", mysqli_connect_error());
}
/* has the form been submitted? */
if(isset($_POST['submit'])){
/* create a prepared statement */
if ($stmt = mysqli_prepare($link, "INSERT INTO market (id, groups, amount) VALUES (?, ?, ?)")){
/* assign variables */
$id = htmlspecialchars($_SESSION['id']);
$groups = htmlspecialchars($_POST['group']);
$amount = htmlspecialchars($_POST['amount']);
/* bind variables to marker */
mysqli_stmt_bind_param($stmt, 'sss', $id, $groups, $amount);
/* execute the prepared statement */
mysqli_stmt_execute($stmt);
/* close statement */
mysqli_stmt_close($stmt);
} else {
echo "prepare failed";
}
/* create a prepared statement */
if ($stmt = mysqli_prepare($link, "INSERT INTO intellectual_property (id, info) VALUES (?, ?)")){
/* assign variables */
$id = htmlspecialchars($_SESSION['id']);
if ($_POST['info'] != NULL){
$info = htmlspecialchars($_POST['info']);
}
if ($info != NULL){
/* bind variables to marker */
mysqli_stmt_bind_param($stmt, 'ss', $id, $info);
/* execute the prepared statement */
mysqli_stmt_execute($stmt);
}
/* close statement */
mysqli_stmt_close($stmt);
} else {
echo "prepare failed";
}
/* create a prepared statement */
if ($stmt = mysqli_prepare($link, "INSERT INTO competitive_analysis (id, behavior, advantage) VALUES (?, ?, ?)")){
/* assign variables */
$id = htmlspecialchars($_SESSION['id']);
if ($_POST['behavior'] != NULL){
$behavior = htmlspecialchars($_POST['behavior']);
}
if ($_POST['advantage'] != NULL){
$advantage = htmlspecialchars($_POST['advantage']);
}
if ($behavior != NULL && $advantage != NULL){
/* bind variables to marker */
mysqli_stmt_bind_param($stmt, 'sss', $id, $behavior, $advantage);
/* execute the prepared statement */
mysqli_stmt_execute($stmt);
}
/* close statement */
mysqli_stmt_close($stmt);
} else {
echo "prepare failed";
}
}
?>
<form action="market.php" method="POST" id="form1"></form>
<br><br><h1 id='market'>Market Info</h1><br>
<?php
/* run prepared queries to see if any data is already present in market tables */
/* create a prepared statement */
if($stmt = mysqli_prepare($link, "SELECT * FROM market WHERE id=?")){
/* bind variables to marker */
mysqli_stmt_bind_param($stmt, 's', $_SESSION['id']);
/* execute query */
mysqli_stmt_execute($stmt);
/* store result */
mysqli_stmt_store_result($stmt);
printf("%d results<br>", mysqli_stmt_num_rows($stmt));
/* bind result variables */
mysqli_stmt_bind_result($stmt, $id, $groups, $amount);
/* print table headers */
echo "<table><thead><tr><th></th><th>Target Group</th><th>Amount</th></tr></thead>";
while (mysqli_stmt_fetch($stmt)){ /* print output */
?>
<form action="marketUpdate.php" method="POST">
<input type='hidden' name='table' value='market'>
<input type='hidden' name='id' value='<?=$id?>'>
<input type='hidden' name='groups' value='<?=$groups?>'>
<input type='hidden' name='amount' value='<?=$amount?>'>
<tr>
<td><input type='submit' name='update' value='Update'></td>
</form>
<?php
echo "<td><textarea rows='5' cols='60' maxlength='32' class='groupInput' readonly>".$groups."</textarea></td>";
echo "<td><textarea rows='5' cols='60' maxlength='10' class='amountInput' readonly>".$amount."</textarea></td></tr>";
}
echo "<tr><td></td><td><textarea form='form1' rows='5' cols='60' maxlength='32' name='group' class='data' placeholder='Enter target group here...'></textarea></td>";
echo "<td><textarea form='form1' rows='5' cols='60' maxlength='10' name='amount' class='data' placeholder='Enter the amount here...'></textarea></td></tr>";
echo "</table>";
/* close statement */
mysqli_stmt_close($stmt);
} ?>
<br><br><h1 class='blue'>Sustainable Competitive Advantage/Intellectual Property</h2><br>
<?php
/* run prepared queries to see if any data is already present in intellectual_property table */
/* create a prepared statement */
if($stmt = mysqli_prepare($link, "SELECT * FROM intellectual_property WHERE id=?")){
/* bind variables to marker */
mysqli_stmt_bind_param($stmt, 's', $_SESSION['id']);
/* execute query */
mysqli_stmt_execute($stmt);
/* store result */
mysqli_stmt_store_result($stmt);
printf("%d results<br>", mysqli_stmt_num_rows($stmt));
/* bind result variables */
mysqli_stmt_bind_result($stmt, $id, $entry, $info);
/* print table headers */
echo "<table><thead><tr><th></th><th>Information</th></tr></thead>";
while (mysqli_stmt_fetch($stmt)){ /* print output */
?>
<form action="marketUpdate.php" method="POST">
<input type="hidden" name="table" value="intellectualProperty">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="entry" value="<?=$entry?>">
<input type="hidden" name="info" value="<?=$info?>">
<tr>
<td><input type="submit" name="update" value="Update"></td>
</form>
<?php
echo "<td><textarea rows='5' cols='60' maxlength='256' class='data' readonly>".$info."</textarea></td></tr>";
}
echo "<tr><td></td><td><textarea form='form1' rows='5' cols='60' maxlength='256'name='info' class='data' placeholder='Enter information here...'></textarea></td></tr>";
echo "</table>";
/* close statement */
mysqli_stmt_close($stmt);
} ?>
<br><br><h1 class='blue'>Competitive Analysis</h1><br>
<?php
/* run prepared queries to see if any data is already present in intellectual_property table */
/* create a prepared statement */
if($stmt = mysqli_prepare($link, "SELECT * FROM competitive_analysis WHERE id=?")){
/* bind variables to marker */
mysqli_stmt_bind_param($stmt, 's', $_SESSION['id']);
/* execute query */
mysqli_stmt_execute($stmt);
/* store result */
mysqli_stmt_store_result($stmt);
printf("%d results<br>", mysqli_stmt_num_rows($stmt));
/* bind result variables */
mysqli_stmt_bind_result($stmt, $id, $entry, $behavior, $advantage);
/* print table headers */
echo "<table><thead><tr><th></th><th>Current Behavior</th><th>Our Competitive Advantage</tr></thead>";
while (mysqli_stmt_fetch($stmt)){ /* print output */
?>
<form action="marketUpdate.php" method="POST">
<input type="hidden" name="table" value="competitiveAnalysis">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="entry" value="<?=$entry?>">
<input type="hidden" name="behavior" value="<?=$behavior?>">
<input type="hidden" name="advantage" value="<?=$advantage?>">
<tr>
<td><input type="submit" name="update" value="Update"></td>
</form>
<?php
echo "<td><textarea class='data' rows='5' cols='60' maxlength='256' readonly>".$behavior."</textarea></td>";
echo "<td><textarea class='data' rows='5' cols='60' maxlength='256' readonly>".$advantage."</textarea></td></tr>";
}
echo "<tr><td></td><td><textarea form='form1' rows='5' cols='60' maxlength='256' name='behavior' class='data' placeholder='Enter current market behaviors here...'></textarea></td>";
echo "<td><textarea form='form1' rows='5' cols='60' maxlength='256' name='advantage' class='data' placeholder='Enter your competitive advantage here...'></textarea></td></tr>";
echo "</table>";
/* close statement */
mysqli_stmt_close($stmt);
} ?>
<input type="submit" form="form1" name="submit" value="Submit">
<?php
if(isset($_POST['submit'])){
if($error){
echo "<br><br><br><h2 class='red'>Submission Failed</h2>";
}else{
echo "<br><br><br><h2>Submission Successful</h2>";
}
}else{
echo "<br><p>IMPORTANT: Press the submit button to save your progress!</p>";
}
?>
</body>
</html>