PageRenderTime 59ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/org.dojotoolkit.dojo.1.3/docs/_static/dojo/dijit/bench/benchReceive.php

https://github.com/victor-homyakov/frameworks
PHP | 129 lines | 75 code | 20 blank | 34 comment | 8 complexity | 60101e64fdf8e737c123f5c34196ef9e MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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);
  100. }else{
  101. return FALSE;
  102. }
  103. }
  104. ?>