-
Notifications
You must be signed in to change notification settings - Fork 3
/
default.php
121 lines (102 loc) · 3.09 KB
/
default.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
<?php
//run this to create user database and table
function createDatabase(){
$conn = new mysqli('localhost', 'root', '');
// Create database
$sql = "CREATE DATABASE mydb";
$conn->query($sql);
$conn->close();
}
function createTable(){
$conn = new mysqli('localhost', 'root', '','mydb');
$sql = "CREATE TABLE user (
id FLOAT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
user_type integer NOT NULL,
email VARCHAR(255) NOT NULL,
dept VARCHAR(255) NOT NULL
)";
$conn->query($sql);
$sql = "CREATE TABLE product (
id FLOAT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
item VARCHAR(100) NOT NULL,
storage FLOAT(10),
unitPrice FLOAT(10),
sellPrice FLOAT(10),
date FLOAT(10),
month FLOAT(10),
year FLOAT(10)
)";
$conn->query($sql);
$sql = "CREATE TABLE comment (
id FLOAT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
comment VARCHAR(10000) NOT NULL,
hour VARCHAR(255) NOT NULL,
minute VARCHAR(255) NOT NULL,
date VARCHAR(255) NOT NULL,
month VARCHAR(255) NOT NULL,
year VARCHAR(255) NOT NULL
)";
$conn->query($sql);
$sql = "CREATE TABLE sales (
id FLOAT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
itemId int(11),
item VARCHAR(100) NOT NULL,
quantity int(10),
cost int(10),
revenue int(10),
profit int(10),
date FLOAT(10),
month FLOAT(10),
year FLOAT(10)
)";
$conn->query($sql);
$sql= "CREATE TABLE feedback (
issuepriority varchar(200) NOT NULL,
name varchar(50) NOT NULL,
itemcode int(10) NOT NULL,
issuetitle varchar(100) NOT NULL,
issuedetail varchar(500) NOT NULL,
date date NOT NULL
)";
$conn->close();
}
function createAdmin(){
$conn = new mysqli('localhost', 'root', '','mydb');
$result = mysqli_query($conn,"SELECT * FROM user WHERE id = '1'");
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
// If result matched username, table row must be 1 row
if($count == 0) {
$sql = "INSERT INTO user (username, password, user_type, email)
VALUES ('admin', 'admin',1,'admin@gmail.com')";
$conn->query($sql);
$hour = date('H');
$minute = date('i');
$date = date('d');
$month = date('m');
$year = date('Y');
$wrongYear = $year - 5;
$wrongMonth = ($month-1 > 0)?($month - 1) : $month;
$wrongDate = ($date-10 > 0)?($month - 10) : $date;
$sql = "INSERT INTO comment (comment, hour, minute, date, month, year)
VALUES ('item shipped.', '$hour', '$minute', '$date', '$month', '$wrongYear')";
$conn->query($sql);
$sql = "INSERT INTO comment (comment, hour, minute, date, month, year)
VALUES ('500 apple sells.', '$hour', '$minute', '$date', '$wrongMonth', '$year')";
$conn->query($sql);
$sql = "INSERT INTO comment (comment, hour, minute, date, month, year)
VALUES ('I eat 200 pears.', '$hour', '$minute', '$wrongDate', '$month', '$year')";
$conn->query($sql);
$sql = "INSERT INTO comment (comment, hour, minute, date, month, year)
VALUES ('this is demo.', '$hour', '$minute', '$date', '$month', '$year')";
$conn->query($sql);
}
$conn->close();
$filename = "img/avatar";
if (!file_exists($filename)) {
mkdir($filename, 0700);
}
}
?>