-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.php
More file actions
executable file
·65 lines (60 loc) · 1.92 KB
/
db.php
File metadata and controls
executable file
·65 lines (60 loc) · 1.92 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
<?php
include("wp-blog-header.php");
function query_db($manufacturer, $model) {
/* This function will take the manufacturer and model number and return the results after querying the database */
global $wpdb;
global $table_prefix;
$query = "SELECT * from " . $table_prefix . "pricesearch where model like '%$model%';";
$result = $wpdb->get_results($query);
return $result;
}
function db_reply($manufacturer, $model) {
/* Gets the manufacturer name and model number from the received message and returns a reply to be sent to the sender */
$result = query_db($manufacturer, $model); //first we query the database
$pricearray = get_price($result, $manufacturer); //and then filter the results to get the price
if ($pricearray != null) {
$model_name = $pricearray["model"];
$off_mah_mp = $pricearray["off_mah_mp"];
$off_roi = $pricearray["off_roi"];
$on_india = $pricearray["on_india"];
$reply = "Price of $manufacturer $model_name";
if ($off_mah_mp!=0) {
$reply_off_mah_mp = " for Maharashtra & MP: $off_mah_mp,";
}
else {
$reply_off_mah_mp = null;
}
if ($off_roi!=0) {
$reply_off_roi = " for Rest of India: $off_roi,";
}
else {
$reply_off_roi = null;
}
if ($on_india!=0) {
$price_on_india = "Online: $on_india";
}
else {
$price_on_india = null;
}
$reply .= $reply_off_mah_mp . $reply_off_roi . $reply_on_india;
}
else {
$reply = "Sorry! The requested device could not be found.";
}
return $reply;
}
function get_price($result, $manufacturer) {
/* go through the results and return the price of nearest or exact match */
if (sizeof($result) > 0) {
foreach ($result as $product) {
if (strtolower($product->brand) == strtolower($manufacturer)) {
$pricearray = array("off_mah_mp" => $product->offline_mh_mp,"off_roi" => $product->offline_roi, "on_india" => $product->online_india, "model" => $product->model);
}
}
}
else {
$pricearray=null;
}
return $pricearray;
}
?>