1 | <?php |
---|
2 | /* |
---|
3 | |
---|
4 | benchReceive.php - example way to handle incoming benchmark data, |
---|
5 | or how to use JSON php class to mangle data. No benchmark data |
---|
6 | is stored currently. |
---|
7 | |
---|
8 | -- |
---|
9 | -- Table structure for table `benchmarks` |
---|
10 | -- |
---|
11 | |
---|
12 | CREATE TABLE `benchmarks` ( |
---|
13 | `id` int(11) NOT NULL auto_increment, |
---|
14 | `useragent` varchar(242) NOT NULL default '', |
---|
15 | `dojover` varchar(96) NOT NULL default '', |
---|
16 | `testNum` int(11) NOT NULL default '0', |
---|
17 | `dijit` varchar(64) NOT NULL default '', |
---|
18 | `testCount` int(11) NOT NULL default '0', |
---|
19 | `testAverage` float NOT NULL default '0', |
---|
20 | `testMethod` varchar(10) NOT NULL default '', |
---|
21 | `testTime` bigint(20) NOT NULL default '0', |
---|
22 | `dataSet` varchar(64) NOT NULL default '', |
---|
23 | PRIMARY KEY (`id`), |
---|
24 | KEY `dijit` (`dijit`,`testAverage`), |
---|
25 | KEY `dataSet` (`dataSet`) |
---|
26 | ) TYPE=MyISAM; |
---|
27 | |
---|
28 | -- |
---|
29 | -- [end table struct] -- |
---|
30 | |
---|
31 | */ |
---|
32 | |
---|
33 | if(is_array($_POST)){ |
---|
34 | |
---|
35 | $username = ''; |
---|
36 | $password = ''; |
---|
37 | $dataBase = ''; |
---|
38 | $table = ''; |
---|
39 | |
---|
40 | mysql_connect("localhost",$username,$password); |
---|
41 | mysql_select_db($dataBase); |
---|
42 | |
---|
43 | require("../../dojo/tests/resources/JSON.php"); |
---|
44 | $json = new Services_JSON(); |
---|
45 | |
---|
46 | // see "escape()" call in benchTest.html |
---|
47 | $string = $json->decode(urldecode($_POST['key'])); |
---|
48 | // $string = $json->decode($_POST['key']); |
---|
49 | |
---|
50 | print "<h1>Thank YOU!</h1>"; |
---|
51 | print " |
---|
52 | <p>Your results have been added to our database. No |
---|
53 | personal information outside of what you see here |
---|
54 | has been stored. |
---|
55 | </p> |
---|
56 | |
---|
57 | <p>You can <a href= \"javascript:history.back()\">go back</a> |
---|
58 | and run more tests, or even better, load up another browser |
---|
59 | and the submit your tests again! |
---|
60 | </p> |
---|
61 | |
---|
62 | <p>again ... thanks for your time.</p> |
---|
63 | |
---|
64 | "; |
---|
65 | |
---|
66 | print "<h3>Results Submitted:</h3>"; |
---|
67 | print "<pre style=\"font:6pt Terminal,sans-serif; border:1px solid #cecece; background-color:#ededed; padding:20px; \">"; |
---|
68 | |
---|
69 | $ua = $string->clientNavigator; |
---|
70 | $dojov = $string->dojoVersion; |
---|
71 | |
---|
72 | print "Client: ".$ua."\n"; |
---|
73 | print "Dojo v".$dojov."\n"; |
---|
74 | |
---|
75 | if(is_array($string->dataSet)){ |
---|
76 | print "\nTest Results:"; |
---|
77 | // should client serialize a key, or is this safer? |
---|
78 | $dataSet = md5(serialize($string)); |
---|
79 | foreach ($string->dataSet as $test){ |
---|
80 | $data = array( |
---|
81 | 'dataSet' => $dataSet, |
---|
82 | 'useragent' => $ua, |
---|
83 | 'dojover' => $dojov, |
---|
84 | 'testNum' => $test->testNum, |
---|
85 | 'testMethod' => $test->testMethod, |
---|
86 | 'testTime' => $test->testTime, |
---|
87 | 'testAverage' => $test->testAverage, |
---|
88 | 'testCount' => $test->testCount, |
---|
89 | 'dijit' => $test->dijit |
---|
90 | ); |
---|
91 | print_r($data); |
---|
92 | add_rec($table,$data); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | if(is_array($string->errors)){ |
---|
97 | // not saving errors at this point |
---|
98 | print "\nErrors:"; |
---|
99 | foreach ($string->errors as $error){ |
---|
100 | print_r($error); |
---|
101 | } |
---|
102 | } |
---|
103 | print "</pre>"; |
---|
104 | } |
---|
105 | |
---|
106 | function add_rec($table, $data){ |
---|
107 | |
---|
108 | if(!is_array($data)){ return FALSE; } |
---|
109 | |
---|
110 | $keys = array_keys($data); |
---|
111 | $values = array_values($data); |
---|
112 | $field=0; |
---|
113 | |
---|
114 | for($field;$field<sizeof($data);$field++){ |
---|
115 | if(!ereg("^[0-9].*$",$keys[$field])){ |
---|
116 | $sqlfields = $sqlfields.$keys[$field]."=\"".$values[$field]."\", "; |
---|
117 | } |
---|
118 | } |
---|
119 | $sqlfields = (substr($sqlfields,0,(strlen($sqlfields)-2))); |
---|
120 | |
---|
121 | if($query = mysql_query("insert into $table set $sqlfields")){ |
---|
122 | $id = mysql_insert_id(); |
---|
123 | return ($id); |
---|
124 | }else{ |
---|
125 | return FALSE; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | ?> |
---|