-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseAll.php
127 lines (119 loc) · 3.13 KB
/
parseAll.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
<?
require_once('db.php');
$db = new db();
// go through each sport
// call parse.php?sport=sport_name
// display results
if(@$_POST['cmd']){
switch($_POST['cmd']){
case 'getSports' :
$sports = $db->fetch_all("SELECT s_id, s_name FROM sports ORDER BY s_name ASC");
echo json_encode(array('sports'=>$sports));
break;
case 'parseSport' :
$s_id = $_POST['s_id'];
$force = $_POST['force'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$_SERVER['HTTP_HOST'].'/parse.php?s_id='.$s_id.'&force='.$force);
//curl_setopt($ch, CURLOPT_POST,1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=getHistory");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
echo $res;
break;
}
exit;
}
?>
<!doctype html>
<html>
<head>
<script src="js/jquery.js"></script>
<style>
#sidebar{
float:left;
width:150px;
}
#results{
border:1px solid black;
margin-left:160px;
padding:5px;
}
</style>
</head>
<body>
<div id="sidebar">
<div id="sports">
</div>
<input type="button" value="Process" id="processB"> <img src="themes/images/ajax-loader.gif" id="spinner" style="display:none"/><br>
Force Update? <input type="checkbox" id="force"/>
</div>
<div id="results">
Select sports and click 'Process'
</div>
<script>
var ESSC = function(){
this.initialize(arguments);
}
$.extend(ESSC.prototype,{
initialize : function(){
this.sports = [];
this.processB = $('#processB');
this.spinner = $('#spinner');
this.force = $('#force')[0];
this.processB.on('click', $.proxy(this.parse,this));
this.getSports();
},
getSports : function(){
var self = this;
$.ajax({
url : location.href,
type : 'POST',
data : { 'cmd' : 'getSports' },
dataType: "json"
}).done($.proxy(self.loadSports,this));
},
loadSports : function(data){
var sports = $('#sports');
for(var i=0; i<data.sports.length;i++){
var s = data.sports[i];
this.sports[s.s_id] = s.s_name;
sports.append("<input type='checkbox' value='"+s.s_id+"'> "+s.s_name+"<BR>");
}
},
parse : function(){
this.processB.prop('disabled',true);
this.spinner.show();
this.chkbxs = $('input[type=checkbox]:checked');
this.index = 0;
this.parseSport(this.chkbxs[0].value);
$('#results').html("Loading...");
},
parseSport : function(s_id){
var self = this;
$.ajax({
url : location.href,
type : 'post',
data : {'cmd' : 'parseSport', 's_id':s_id, 'force':this.force.checked?'1':''},
dataType : 'html'
}).done(function(data){
if(self.index==0) $('#results').html('');
$('#results').append(data);
self.index++;
if(self.chkbxs[self.index]){
self.parseSport(self.chkbxs[self.index].value);
} else {
self.processB.prop('disabled',false);
self.spinner.hide();
}
});
}
});
var essc;
$(document).ready(function(){
essc = new ESSC();
});
</script>
</body>
</html>