Location: PHPKode > scripts > HostingBenchmark > hostingbenchmark/includes/view.php
<?php

/***************************************************************
*  (c) 2006-2007 Askywhale (hosting[a]askywhale.com)
*  All rights reserved
*
*  This script is part of HostingBenchmark.com. This project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
***************************************************************/

require_once('tools.php');

function getReleaseVersionTxt($title,$release) {
  global $lang;
  return sprintf($lang['title_release'],$title,$release);
}

function getHeader() {
  global $view,$lang,$error;
  $version = VERSION;
  $langIsoName = $lang['ISO_NAME'];
  $textHeader = $lang['text_header'];
  $textSubHeader = sprintf($lang['text_sub_header'],$view);
  $textFullBack = $lang['full_back'];
  $introText='';
  if($error!='')
    $introText="<strong>$error</strong>";
  else
    if(isset($lang['intro_'.$view]))
      $introText=$lang['intro_'.$view];    
  $res = <<< END1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$langIsoName" lang="$langIsoName">
  <head>
    <title>
END1;
  $res .= getReleaseVersionTxt('HostingBenchmark',$version);
  $res .= <<< END2
</title>
    <meta http-equiv="Content-type" content="text/html; charset=$langIsoName"/>
    <link rel="shortcut icon" type="image/x-icon" href="./images/clock.ico" />
    <link rel="stylesheet" href="./hostingbench.css" type="text/css">
  </head>
  <body>
    <div id='header'><h2>$textHeader</h2><small>$textSubHeader&nbsp;|&nbsp;
    <a href='?action=chooselanguage'>$textFullBack</a></small></div>
    <div id='main'><div id='intro'>$introText</div><form method='post' name='mainform'>
    <input type='hidden' name='action' value='$view' />
END2;
  return $res;
}

function getFooter() {
  global $lang;
  $textFooter = $lang['text_footer'];//.print_r($_SESSION,true);
  return "<br /><input type='submit' value='".$lang['continue']."' /></form><br />".
    "<br /><br /></div><div id='footer'><small>$textFooter</small></div></body></html>";
}

function getViewChooselanguage(){
  global $lang;
  $res =  "<select name='language'>";
  foreach(getAvailableLangs() as $availableLang)
    $res .= "<option value='$availableLang'>$availableLang</option>";
  $res .= "</select>";
  return $res; 
}

function getViewStart(){
  global $lang;
  $lastStringParameters = "";
  if(isset($_SESSION['laststringparameters']))
    $lastStringParameters = $_SESSION['laststringparameters'];
  return "<textarea name='parameters' cols='80' rows='5'>".
    cutString($lastStringParameters,80).
    "</textarea><br />".$lang['use_parameters'].
    "<input type='checkbox' name='use_parameters' />";  
}

function getViewSelecttests(){
  global $availableTest, $lang;
  $res = "<table border='0' cellspacing='10'>";
  foreach($availableTest as $k=>$test) {
    $checked = "";
    if(isset($_SESSION['forms']['selecttests'])) {
      if(isset($_SESSION['forms']['selecttests'][$k]))
        $checked = " checked='checked' ";
    } else
      if($test->getDefaultOn())
        $checked = " checked='checked' ";
    $res .= "<tr title='".$test->getDescription()."'>".
      "<th align='right'>".getReleaseVersionTxt($test->getTitle(),$test->getRelease()).
      "<input type='checkbox' name='$k' $checked /></th><td>";
    if(!$test->isBenchmark())
      $res .= "<strong>".$lang['not_a_benchmark']."</strong>&nbsp;";
    $res .= $test->getDescription()."</td></tr>";
  }
  return $res."</table>";
}

function getViewSetparameters(){
  global $parametersTest;
  return "<strong>".$_SESSION['tests'][$parametersTest]->getTitle()."</strong><br />".
    "<input type='hidden' name='test' value='".$parametersTest."' />".
    $_SESSION['tests'][$parametersTest]->getParametersForm();
}

function getViewSetmainparameters(){
  global $lang;
  $nb = DEFAULT_PASS;
  $ignoreworst = " checked='checked'";
  if(isset($_SESSION['forms']['setmainparameters'])) {
    if(isset($_SESSION['forms']['setmainparameters']['pass']))
      $nb = $_SESSION['forms']['setmainparameters']['pass'];
    if(isset($_SESSION['forms']['setmainparameters']['ignoreworst'])&&
        $_SESSION['forms']['setmainparameters']['ignoreworst']=='off')
      $ignoreworst='';
  }   
  return sprintf($lang['test_nb'],count($_SESSION['tests']))."<br />".
    "<table border='0' cellspacing='5'>".
    "<tr><th>".$lang['how_many_pass']."</td>".
    "<td><input name='pass' value='$nb' size='5' />&nbsp;".
    "<span onclick='document.mainform.pass.value=1' class='clickeable'>[1]</span>&nbsp;".
    "<span onclick='document.mainform.pass.value=10' class='clickeable'>[10]</span>&nbsp;".
    "<span onclick='document.mainform.pass.value=100' class='clickeable'>[100]</span>&nbsp;".
    "</td></tr>".
/*    "<tr><th>".$lang['ignore_worst']."</td>".
    "<td><input type='checkbox' name='ignoreworst' $ignoreworst /></td></tr>".*/
    "</table>";
}

function getViewTest(){
  global $lang;
 
  $test =& $_SESSION['tests'][$_SESSION['currentTest']];
  if($test->setUp()) {
    $totalTime = $test->doBenchmark();    
    $test->tearDown();
  }
  $_SESSION['results'][$_SESSION['currentTest']][] = $totalTime;
  $nbTests = 0;
  $nbBenchs = 0;
  foreach($_SESSION['tests'] as $test2)
    if($test2->isBenchmark()) {
      $nbTests += $_SESSION['forms']['setmainparameters']['pass'];
      $nbBenchs ++;
    } else
      $nbTests += 1;
  if($_SESSION['currentPass']==0)
    $noTest = $_SESSION['currentTest']+1;
  else {
    $noTest = count($_SESSION['tests']) + $nbBenchs*($_SESSION['currentPass']-1) + 1;
    foreach($_SESSION['tests'] as $i => $test2)
      if($i<$_SESSION['currentTest'] && $test2->isBenchmark())
        $noTest++;
  }
  $prc = round(100*$noTest/$nbTests);
  $txtBar = "<table width='100%' cellspacing='0' cellpadding='3' ><tr>".
    "<td width='$prc%' id='bardone'>".sprintf($lang['prc_done'],$prc)."</td>";
  if($prc<100)
    $txtBar .= "<td id='barnotdone'></td>";  
  $txtBar .= "</tr></table>";
  return sprintf($lang['result_dotest'],$totalTime,
    $test->getTitle(),$_SESSION['currentPass']+1)."<br />$txtBar".
    "\n<script type='text/javascript'>\n".
    "function autoSubmit(){ document.forms[0].submit(); }\n".
    "setTimeout('autoSubmit()',500);\n".
    "</script>";
}

function getViewShowresults(){
  global $lang;
  $res = "<table border='0' width='99%'>";
  foreach($_SESSION['tests'] as $k=>$test) {    
    $res .= "<tr><th>".
      getReleaseVersionTxt($test->getTitle(),$test->getRelease())."</th>";
    if($test->isBenchmark()) {
      $avgResult = getAvgResult($test,$_SESSION['results'][$k]);
      if($test->isValid() && $avgResult>-1) {
        $_SESSION['results_avg'][$k] = $avgResult;
        $res .= "<td class='benchresults'>".sprintf($lang['result_avgtest'],$_SESSION['results_avg'][$k])."</td>";
      } else {
        $_SESSION['results_avg'][$k] = -1;
        $res .= "<td class='benchresults'>".$lang['failed_test']."</td>";      
      }          
      $res .="<td class='txtresults'>".$test->getTxtResults()."<td></tr>";
    } else
      $res .="<td class='txtresults' colspan='2'>".$test->getTxtResults()."<td></tr>";
  }
  $_SESSION['laststringparameters'] = getStringParameters();
  return $res."</table>".  
    "<br /><p>".$lang['parameters_string']."<pre class='string'>".
    cutString($_SESSION['laststringparameters'],50)."</pre></p><br /><p>".
    $lang['results_string'].
    "</form><br /><form action='".URL_RESULTS."' method='post'>".
    "<input type='hidden' name='lang' value='".$_SESSION['language']."' />".    
    "<textarea readonly='readonly' cols='60' rows='7' name='results'>".
    cutString(getStringResults(),50)."</textarea><br />".
    "<input type='submit' value='".$lang['click_send_results']."' class='clickeable' />".
    "</p><p><a href='?action=restart'>".
    $lang['click_restart']."</a></p><p>".$lang['end_go_start'].
    "</form><form action=''>";
}

function showView() {
  global $view;
  echo getHeader();
  $f = "getView".ucfirst($view);
  if(function_exists($f))
    echo $f();
  echo getFooter();
}

?>
Return current item: HostingBenchmark