-
Notifications
You must be signed in to change notification settings - Fork 1
/
go_getuserdashboard.php
145 lines (122 loc) · 3.7 KB
/
go_getuserdashboard.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
<?php
ob_start();
include('.gobasicdefines.php');
$include_path=ini_get('include_path');
ini_set('include_path',INI_PATH . ':' . $include_path);
require_once('config.class.php');
require_once('goutility.class.php');
/* Author: Julio Hernandez-Miyares
Date: August 16,2010
Purpose: retrieve the user dashboard given a userid
Simple api because all of the summarized data will be in go_userDashboard and the api's function is solely
to select the normalized row and return in xml (and eventually in json)
Though not implemented for version 1, will require some form of authentication
Total Number of Bets
Total Number of bets initiated
Total Wins/Loses
Total $$$ wins/loses
currently active bets
xml response
<userdashboard>
<statuscode>200</statuscode>
<statusmessage>OK</statusmessage>
<userid>21</userid>
<totalbets>20</totalbets>
<totalbetsinitiated>16</totalbetsinitiated>
<totalwins>5</totalwins>
</userdashboard>
GET query parameters
userid (betsquared id for user)
foursquareid
facebookid
twitterid
*/
//cleanup/build return xml
/* xml returned
<userdashboard>
<statuscode>403</statuscode>
<statusmessage>Forbidden</statusmessage>
<userdashboard>
*/
$LOG=Config::getLogObject();
//parse query parameters , called via HTTP GET
//Filtering
$params = Array();
$params['userid'] = $_GET['userid'];
//open connect to database
$link = mysqli_connect(Config::getDatabaseServer(),Config::getDatabaseUser(), Config::getDatabasePassword(),Config::getDatabase());
if (!$link) {
header('HTTP/1.1 500 Internal Server Error');
mydie("Error connecting to Database");
}
$sql = getQuery($params);
$LOG->log($sql,PEAR_DEBUG);
$cursor = mysqli_query($link,$sql);
if (!$cursor) {
// Server error
header('HTTP/1.1 500 Internal Server Error');
mydie(mysqli_error($link) . " executing $sql",$link);
}
header ("content-type: text/xml");
echo '<?xml version="1.0"?>';
Utility::emitXML("",'userdashboard',0);
Utility::emitXML("200",'statuscode');
Utility::emitXML("OK",'statusmessage');
$recordsEmitted=0;
$totalBets=0;
$totalBets=0;
$totalBetsInitiated=0;
$totalBetsAccepted=0;
$totalWins=0;
$totalLoses=0;
// while records to read/ retrieve and emit xml
if ( $row = mysqli_fetch_assoc($cursor) ) {
$recordsEmitted++;
$userID= $row['userID'];
$totalBets= $row['totalBets'];
$totalBetsInitiated= $row['totalBetsInitiated'];
$totalBetsAccepted= $row['totalBetsAccepted'];
$totalWins= $row['totalWins'];
$totalLoses= $row['totalLoses'];
} //if
$cursor->close();
Utility::emitXML("$userID",'userid');
Utility::emitXML((isset($totalBets) ? $totalBets : 0 ),'totalbets');
Utility::emitXML("$totalBetsInitiated",'totalbetsinitiated');
Utility::emitXML("$totalBetsAccepted",'totalbetsaccepted');
Utility::emitXML("$totalWins",'totalwins');
Utility::emitXML("$totalLoses",'totalloses');
Utility::emitXML("",'userdashboard',0);
$link->close(); /* Close Database */
ob_end_flush();
exit;
/* Functions
*/
function mydie($msg,$link=null) {
global $LOG;
ob_end_clean();
$LOG->log("$msg",PEAR_LOG_ERR);
if (isset($link)) $link->close();
ob_start();
header ("content-type: text/xml");
Utility::emitXML("",'userdashboard',0);
Utility::emitXML("500",'statuscode');
Utility::emitXML("$msg",'statusmessage');
Utility::emitXML("",'userdashboard',0);
ob_end_flush();
die();
}
function getQuery($params) {
$sql = "select * from go_userDashboard ";
if (!empty($params)) {
foreach ($params as $key => $value) {
switch($key) {
case "userid":
$where = " where userID = $value";
} //switch
} //foreach
} //if
$sql .=$where;
return $sql;
}
?>