-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart_shop.php
197 lines (174 loc) · 9.54 KB
/
start_shop.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
<?php
require_once('Connections/YBDB.php');
require_once('Connections/database_functions.php');
$page_shop_log = PAGE_SHOP_LOG;
//?shop_id=2
if($_GET['shop_id']>0){
$shop_id = $_GET['shop_id'];
} else {
$shop_id =0;}
switch ($_GET['error']) {
case 'no_shop':
$error_message = 'ERROR: A Shop at this location for today does not exist: Start New Shop';
break;
case 'new_error_message': //this is a sample error message. insert error case here
$error_message = '';
break;
default:
$error_message = 'Start a New Shop OR View and Existing Shop';
break;
}
//shop_date
if($_GET['shop_date']>0){
$shop_date = $_GET['shop_date'];
} else {
$shop_date =current_date();}
//dayname
if($_GET['shop_dayname']=='alldays'){
$shop_dayname = '';
} elseif(isset($_GET['shop_dayname'])) {
$shop_dayname = "AND DAYNAME(date) = '" . $_GET['shop_dayname'] . "'";
} else {
$shop_dayname = '';
}
//record_count
if($_GET['record_count']>0){
$record_count = $_GET['record_count'];
} else {
$record_count = 10;}
$ctrl_shoplocation = "ctrl_shoplocation";
$ctrl_shoptype = "ctrl_shoptype";
$editFormAction = $_SERVER['PHP_SELF'] . "?shop_date=$shop_date&shop_id=$shop_id";
$editFormAction_no_shopid = $_SERVER['PHP_SELF'] . "?shop_date=$shop_date";
mysql_select_db($database_YBDB, $YBDB);
$query_Recordset1 = "SELECT shops.shop_id, date, DAYNAME(date) as day ,shop_location, shop_type, ip_address, IF(date = curdate(),1,0) as CanEdit, COUNT(shop_visit_id) AS num_visitors, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS total_hours FROM shops LEFT JOIN shop_hours ON shops.shop_id = shop_hours.shop_id WHERE date <= '{$shop_date}' {$shop_dayname} GROUP BY shop_id ORDER BY date DESC , shop_id DESC LIMIT 0, $record_count;";
$Recordset1 = mysql_query($query_Recordset1, $YBDB) or die(mysql_error());
//$row_Recordset1 = mysql_fetch_assoc($Recordset1); //Wait to fetch until do loop
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
// action on submit
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_new")) {
$insertSQL = sprintf("INSERT INTO shops (shop_location, shop_type, date, ip_address) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['ctrl_shoplocation'], "text"),
GetSQLValueString($_POST['ctrl_shoptype'], "text"),
GetSQLValueString($_POST['ctrl_date'], "date"),
GetSQLValueString($_SERVER['REMOTE_ADDR'], "text"));
mysql_select_db($database_YBDB, $YBDB);
$Result1 = mysql_query($insertSQL, $YBDB) or die(mysql_error());
//determines the shop_id just added to the database
mysql_select_db($database_YBDB, $YBDB);
$query_Recordset2 = "SELECT MAX(shop_id) AS shop_id FROM shops;";
$Recordset2 = mysql_query($query_Recordset2, $YBDB) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
$shop_id = $row_Recordset2["shop_id"];
//the added shop_id is passed as a variable to the shop page
$insertGoTo = "{$page_shop_log}?shop_id=" . $shop_id;
mysql_free_result($Recordset2);
header(sprintf("Location: %s", $insertGoTo));
//header(sprintf("Location: %s", "index.html"));
}
//Update Record isset($_POST["MM_update"])
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormEdit")) {
$updateSQL = sprintf("UPDATE shops SET date=%s, shop_location=%s, shop_type=%s WHERE shop_id=%s",
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['shop_location'], "text"),
GetSQLValueString($_POST['shop_type'], "text"),
GetSQLValueString($_POST['shop_id'], "int"));
//"2006-10-12 18:15:00"
mysql_select_db($database_YBDB, $YBDB);
$Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error());
header(sprintf("Location: %s",$editFormAction_no_shopid )); //$editFormAction
}
//Change Date isset($_POST["MM_update"])
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) {
$editFormAction = $_SERVER['PHP_SELF'] . "?shop_date={$_POST['shop_date']}&shop_dayname={$_POST['dayname']}&record_count={$_POST['record_count']}";
header(sprintf("Location: %s",$editFormAction )); //$editFormAction
}
?>
<?php include("include_header.html"); ?>
<table>
<tr valign="top">
<td align="left"><span class="yb_heading3red"><?php echo $error_message; ?></span> </td>
</tr>
<tr>
<td><table border="1" cellpadding="1" cellspacing="0">
<tr bgcolor="#99CC33">
<td><strong>ShopID</strong></td>
<td height="35"><strong>Date</strong></td>
<td><strong>Shop Location </strong></td>
<td><strong>Shop Type </strong></td>
<td><strong>Stats</strong></td>
<td><strong>Edit</strong></td>
</tr>
<tr>
<td height="30" colspan="6"><a href="http://www.ybdb.austinyellowbike.org/individual_hours_log.php">Log Non-Shop Hours</a> </td>
</tr>
<form action="<?php echo $editFormAction; ?>" method="post" name="form_new" id="form_new">
<tr>
<td height="30"><span class="yb_heading3red">Start New Shop:</span></td>
<td><input name="ctrl_date" type="text" class="yb_standard" value="<?php echo current_date(); ?>" /></td>
<td><?php list_shop_locations($ctrl_shoplocation,"Treasure City") ?></td>
<td><?php list_shop_types($ctrl_shoptype) ?></td>
<td> </td>
<td><input name="Update" type="submit" id="Update" value="Create Shop" /></td>
</tr>
<input type="hidden" name="MM_insert" value="form_new" />
</form>
<tr bgcolor="#99CC33">
<td height="25" colspan="6" valign="bottom" bgcolor="#99CC33"> View Existing Shops:</td>
</tr>
<form action="<?php echo $editFormAction; ?>" method="post" name="FormUpdate_<?php echo $row_Recordset1['shop_id']; ?>" id="FormUpdate_<?php echo $row_Recordset1['shop_id']; ?>">
<?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { //do {
if($shop_id == $row_Recordset1['shop_id']) {?>
<tr valign="bottom" bgcolor="#CCCC33">
<td>Edit Record:<br />
<?php echo "<a href=\"{$page_shop_log}?shop_id={$row_Recordset1['shop_id']}\">Shop ID: {$row_Recordset1['shop_id']}</a>";?></td>
<td><input name="date" type="text" value="<?php echo $row_Recordset1['date']; ?>" /></td>
<td><?php list_shop_locations('shop_location', $row_Recordset1['shop_location']); ?></td>
<td><?php list_shop_types('shop_type', $row_Recordset1['shop_type']); ?></td>
<td><?php echo $row_Recordset1['num_visitors']; ?> Visitors<br />
~<?php echo $row_Recordset1['total_hours']; ?> Hours</td>
<td><input name="Update" type="submit" id="Update" value="Update" /></td>
</tr>
<input type="hidden" name="MM_insert" value="FormEdit" />
<input type="hidden" name="shop_id" value="<?php echo $row_Recordset1['shop_id']; ?>" />
</form>
<?php } else { // end if EDIT RECORD ?>
<tr>
<td><?php echo "<a href=\"{$page_shop_log}?shop_id={$row_Recordset1['shop_id']}\">Shop ID: {$row_Recordset1['shop_id']}</a>";?></td>
<td><?php echo $row_Recordset1['date'] . ' (' . $row_Recordset1['day'] . ')'; ?></td>
<td><?php echo $row_Recordset1['shop_location']; ?></td>
<td><?php echo $row_Recordset1['shop_type']; ?></td>
<td><?php echo $row_Recordset1['num_visitors']; ?> Visitors<br />
~<?php echo $row_Recordset1['total_hours']; ?> Hours</td>
<td><?php if($row_Recordset1['CanEdit'] == 1) {echo "<a href=\"{$_SERVER['PHP_SELF']}?shop_date={$shop_date}&shop_id={$row_Recordset1['shop_id']}\">edit</a>";} else {echo " ";} ?></td>
</tr>
<?php
} // end if EDIT RECORD
} // end WHILE count of recordset ?>
</table>
<form id="form1" name="form1" method="post" action="">
<br />
Show
<input name="record_count" type="text" value="10" size="3" maxlength="3" />
shops on or before:
<input name="shop_date" type="text" id="shop_date" value="<?php echo $shop_date; ?>" size="10" maxlength="10" />
Day of week:
<select name="dayname">
<option value="alldays" selected="selected">All Days</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select>
<input type="submit" name="Submit" value="Submit" />
(date format YYYY-MM-DD)
<input type="hidden" name="MM_insert" value="ChangeDate" />
</form></td>
</tr>
</table>
<?php include("include_footer.html"); ?>
<?php mysql_free_result($Recordset1);?>