7f492bc669fc291de7847a9614c84a961fb2e9dd.svn-base 3.1 KB

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