forked from Xinyi-Lai/CS411_Geniuses
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathop_approve.php
More file actions
executable file
·87 lines (71 loc) · 2.81 KB
/
op_approve.php
File metadata and controls
executable file
·87 lines (71 loc) · 2.81 KB
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
<?php
include_once "db_functions.php";
//get the parameter from URL
$id = $_GET["id"];
//connect db
if ($id) {
$conn = connectDB();
// get info
$sql = "SELECT * FROM Sales WHERE SaleId=$id";
$result = $conn->query($sql);
if (!$result) {
$msg = "Error search in sale: " . $sql . "<br>" . $conn->error;
$conn->close();
exit;
}
$row = mysqli_fetch_assoc($result);
$sellerid = $row['SellerId'];
$buyerid = $row['IntendedBuyerId'];
$product_name = $row['ProductName'];
$tag = $row['Tag'];
$description = $row['Description'];
$price = $row['IntendedPrice'];
// delete image for products in Sales
$original_filepath = $row['Image'];
if(is_file($original_filepath)) {
unlink($original_filepath);
}
// remove from Sales
$sql = "DELETE FROM Sales WHERE SaleId=$id";
if (!$conn->query($sql)) {
$msg = "Error remove from sale: " . $sql . "<br>" . $conn->error;
$conn->close();
exit;
}
// insert into Transactions
$sql = "INSERT INTO Transactions (SellerId, BuyerId, ProductName, Price, Tag, Description)
VALUES ('$sellerid', '$buyerid', '$product_name', '$price', '$tag', '$description')";
if (!$conn->query($sql)) {
$msg = "Error insert into transaction: " . $sql . "<br>" . $conn->error;
}
// refresh recommendation system
$myfile = fopen("py/tagset.txt", "w") or die("Unable to open file!");
$sql = "SELECT BuyerId, GROUP_CONCAT(DISTINCT Tag) AS Tagset FROM Transactions GROUP BY BuyerId";
$result = $conn->query($sql);
if ($result) {
while ( $row = mysqli_fetch_assoc($result) ) {
fwrite($myfile, $row['Tagset'] . "\n" );
}
} else {
$msg = "Error grouping Transactions by BuyerId" . $sql . "<br>" . $conn->error;
}
fclose($myfile);
$myfile = fopen("py/recommend.txt", "w") or die("Unable to open file!");
fwrite($myfile, "top: ");
$sql = "SELECT Tag, COUNT(*) AS cntTag FROM Transactions GROUP BY Tag ORDER BY cntTag DESC LIMIT 3";
$result = $conn->query($sql);
if ($result) {
while ( $row = mysqli_fetch_assoc($result) ) {
fwrite($myfile, $row['Tag'] . ", " );
}
} else {
$msg = "Error sorting cnt(Tag) in Transactions" . $sql . "<br>" . $conn->error;
}
fwrite($myfile, "\n");
fclose($myfile);
//$result = system("python3 py/apriori.py");
$result = exec("python3 py/apriori.py");
$conn->close();
}
//echo "<script>console.log('$msg')</script>";
?>