<?php
  function retval($inv) {
    if (strpos($inv, "E-") !== false) return "0";
    return $inv;
  }
?>
<!doctype html>
<html>
  <head> <script type="text/javascript" src="http://www.rjmprogramming.com.au/gchartgen.js"></script>
    <title>Intervals - RJM Programming - http://www.rjmprogramming.com.au (Copyright &copy; 2013 rjmprogramming.com.au all rights reserved.)</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=4, user-scalable=yes" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript"
        src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}"></script>
<script type="text/javascript">
<?php 
//var options = {
//        series: [{'color': '#1A8763'}],
//        intervals: { style: 'boxes' },
//        legend: 'none',
//    };

//    var data = new google.visualization.DataTable();
//    data.addColumn('string', 'x');
//    data.addColumn('number', 'values');
//    data.addColumn({id:'i0', type:'number', role:'interval'});
//    data.addColumn({id:'i1', type:'number', role:'interval'});
//    data.addColumn({id:'i2', type:'number', role:'interval'});
//    data.addColumn({id:'i2', type:'number', role:'interval'});
//    data.addColumn({id:'i2', type:'number', role:'interval'});
//    data.addColumn({id:'i2', type:'number', role:'interval'});

//    data.addRows([
//        ['a', 100, 90, 110, 85, 96, 104, 120],
//        ['b', 120, 95, 130, 90, 113, 124, 140],
//        ['c', 130, 105, 140, 100, 117, 133, 139],
//        ['d', 90, 85, 95, 85, 88, 92, 95],
//        ['e', 70, 74, 63, 67, 69, 70, 72],
//        ['f', 30, 39, 22, 21, 28, 34, 40],
//        ['g', 80, 77, 83, 70, 77, 85, 90],
//        ['h', 100, 90, 110, 85, 95, 102, 110]]);

//    // The intervals data as narrow lines (useful for showing raw source
//    // data)
//    var options_lines = {
//        title: 'Line intervals, default',
//        curveType:'function',
//        lineWidth: 2,
//        intervals: { 'style':'line' }, // Use line intervals.
//        legend: 'none',
//    };

//    var chart_lines = new google.visualization.LineChart(document.getElementById('chart_lines'));
//    chart_lines.draw(data, options_lines);


      $GETtitle = "Thick Box Presentation Mode";
      $GETtask = "7";
      $GETdesc = "ThickBox";
      $GETdata = "['a', 100, 90, 110, 85, 96, 104, 120],['b', 120, 95, 130, 90, 113, 124, 140],['c', 130, 105, 140, 100, 117, 133, 139],['d', 90, 85, 95, 85, 88, 92, 95],['e', 70, 74, 63, 67, 69, 70, 72],['f', 30, 39, 22, 21, 28, 34, 40],['g', 80, 77, 83, 70, 77, 85, 90],['h', 100, 90, 110, 85, 95, 102, 110]";
      if (isset($_GET['desc'])) {
       $GETtitle = $_GET['title'];
       $GETtask = $_GET['task'];
       $GETdesc = $_GET['desc'];
       $GETdata = $_GET['data'];
      }
      
      //echo ' google.load("visualization", "1", {packages:["imagesparkline"]}); ' . "\n";
      echo ' function drawChart() { ' . "\n";
      echo ' var data = new google.visualization.DataTable();' . "\n";
      echo " data.addColumn('string', 'x'); \n";
      echo " data.addColumn('number', 'values'); \n";
      for ($ij=0; $ij<($GETtask - 1); $ij++) {
      echo " data.addColumn({id:'i" . $ij . "', type:'number', role:'interval'}); " . "\n";
      }
      //echo " ['" . $GETtask . "','" . $GETdesc . "'] \n";
      echo ' data.addRows([ ' . "\n";
      echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $GETdata)))));
      echo "        ]);\n";
      if (str_replace("bar","",str_replace("bars","",strtolower($GETdesc))) == "") {
      echo " var options = { \n";
      echo "         series: [{'color': '#1A8763'}], \n";
      echo "         intervals: { style: 'boxes' }, \n";
      echo "         legend: 'none', \n";
      echo "     }; \n";
      echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div')).draw(data, options); \n";

      } else if (strpos(strtolower($GETdesc),"no") !== false) {
      echo " var options_lines = { \n";
      echo "   title: '" . $GETtitle . "', \n";
      echo "   curveType:'function', \n";
      echo "   lineWidth: 2, \n";
      echo "   intervals: { 'style':'line' },  \n";
      echo "   legend: 'none', \n";
      echo "     }; \n";
      echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div')).draw(data, options_lines); \n";
      } else if (strpos(strtolower($GETdesc),"area") !== false) {
      echo "   var options = { \n";
      echo "       title:'" . $GETtitle . "', \n";
      echo "       curveType:'function', \n";
      echo "      series: [{'color': '#F1CA3A'}], \n";
      echo "       intervals: { 'style':'area' }, \n";
      echo "       legend: 'none', \n";
      echo "    }; \n";
      echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div')).draw(data, options); \n";
      } else if (strpos(strtolower($GETdesc),"point") !== false) {
      echo "    var options_points = { \n";
      echo "       title:'" . $GETtitle . "', \n";
      echo "       curveType:'function', \n";
      echo "       lineWidth: 4, \n";
      echo "       series: [{'color': '#D3362D'}], \n";
      echo "       intervals: { 'style':'points', pointSize: 2 }, \n";
      echo "       legend: 'none', \n";
      echo "   }; \n";
      echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div')).draw(data, options_points); \n";
      } else if (strpos(strtolower($GETdesc),"stick") !== false) {
      echo "     var options_sticks = { \n";
      echo "      title:'" . $GETtitle . "', \n";
      echo "      curveType:'function', \n";
      echo "      series: [{'color': '#E7711B'}], \n";
      echo "     intervals: { style: 'sticks' }, \n";
      echo "     legend: 'none', \n";
      echo "    }; \n";
      echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div')).draw(data, options_sticks); \n";

      } else if (strpos(strtolower($GETdesc),"box") !== false && strpos(strtolower($GETdesc),"thick") !== false) {
      echo "    var options = { \n";
      echo "   title:'" . $GETtitle . "', \n";
      echo "   curveType:'function', \n";
      echo "   lineWidth: 4, \n";
      echo "   series: [{'color': '#1A8763'}], \n";
      echo "   intervals: { 'lineWidth':2, 'barWidth': 0.5, style: 'boxes' }, \n";
      echo "   legend: 'none', \n";
      echo "   }; \n";
      echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div')).draw(data, options); \n";
      } else if (strpos(strtolower($GETdesc),"box") !== false) {
      echo "   var options = { \n";
      echo "   series: [{'color': '#1A8763'}], \n";
      echo "   intervals: { style: 'boxes' }, \n";
      echo "   legend: 'none', \n";
      echo "   }; \n";

      echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div')).draw(data, options); \n";

      } else if (strpos(strtolower($GETdesc),"line") !== false) {
      echo " var options_lines = { \n";
      echo "   title: '" . $GETtitle . "', \n";
      echo "   curveType:'function', \n";
      echo "   lineWidth: 2, \n";
      echo "   intervals: { 'style':'line' },  \n";
      echo "   legend: 'none', \n";
      echo "     }; \n";
      echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div')).draw(data, options_lines); \n";
      }

    //var chart_lines = new google.visualization.LineChart(document.getElementById('chart_lines'));
    //chart_lines.draw(data, options_lines);
      //}
      echo " \n } \n";
      
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";
      echo " </script> \n";
      echo " </head> \n";
      echo " <body onload='setTimeout(later, 2 * 1000);'> \n";
      echo " <h1>" . $GETtitle . " Intervals</h1> \n";
?>
    <div id="chart_div" style="width: 600px; height: 400px; background-color: yellow;"></div>
    <br><a title="Another Intervals Chart" href="./intervals.php">Another intervals chart?</a>&nbsp;&nbsp;<a target='_blank' title='Google Chart advice' href='https://developers.google.com/chart/interactive/docs/gallery/intervals'>Read more here</a>
    <?php 
      if (!isset($_GET['desc'])) {
      
        echo '<' . 'script' . '>' . "\n " . " function later() { \n" . ' var datalineprefix = " "; ' . "\n";
        echo ' var idata = 97; ' . "\n";
        echo ' var datalinesuffix = ""; ' . "\n";
        echo ' var extra = ""; ' . "\n";
        echo ' var fcomma = ""; ' . "\n";
        echo ' var thisline = 1; ' . "\n";
        echo ' var totalleft = 100.0; ' . "\n";
        if (isset($_GET['title'])) {
        echo ' var title = prompt("Enter Intervals Chart Title " + String.fromCharCode(10) + "(available presentation modes are " + String.fromCharCode(10) + "Bar or Line or Point or Stick or " + String.fromCharCode(10) + "None or Box or ThickBox)", "' . $_GET['title'] . '"); ' . "\n";
        } else {
        echo ' var title = prompt("Enter Intervals Chart Title " + String.fromCharCode(10) + "(available presentation modes are " + String.fromCharCode(10) + "Bar or Line or Point or Stick or " + String.fromCharCode(10) + "None or Box or ThickBox)", "Bars, default"); ' . "\n";
        }
        echo ' if (title != null) { ' . "\n";
        echo ' var desc = prompt("Enter Presentation Mode out of Bar or Line or Point or Stick or None or Box or ThickBox", "Bar"); ' . "\n";
        echo ' var numtaskdesc = prompt("Enter Number of Series to Define (include the series of best fit or primary series, which should be the first data entry for each of your rows)", "2"); ' . "\n";
        echo ' var task = ""; /' . '/ prompt("Enter Measure 1 of 2", "Revenue"); ' . "\n";
        //echo ' var desc = ""; /' . '/ prompt("Enter Measure 2 of 2", "Licenses"); ' . "\n";
        echo ' var datac = ""; ' . "\n";
        echo ' var sq = "~"; /' . '/ "' . "'" . '"; ' . "\n";
        echo ' datalineprefix = prompt("Enter " + numtaskdesc + " Values (separated by comma) ... Row " + thisline + " (please enter Line of Best Fit or Primary Series data first)", ""); ' . "\n";
        echo ' while (datalineprefix.length != 0) { ' . "\n";
        //echo ' if (datalinesuffix.length != 0) datalineprefix = prompt("Enter " + task + " Value " + thisline + " (for no more hit Cancel button)", ""); ' . "\n";
        echo ' if (datalinesuffix.length != 0) datalineprefix = prompt("Enter " + numtaskdesc + " Values (separated by comma) ... Row " + thisline + " (please enter Line of Best Fit or Primary Series data first, for no more hit Cancel button)", ""); ' . "\n";
        echo ' if (datalineprefix == null) { ' . "\n";
        echo '     datalineprefix = ""; ' . "\n";
        echo '     totalleft = 0; ' . "\n";
        echo ' } else if (datalineprefix.length != 0) { ' . "\n";
        echo '     extra = "";  ' . "\n";
        //echo '     if (desc.indexOf("ercent") != (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) extra = " (for " + totalleft + " enter nothing or hit Cancel button)";  ' . "\n";
        echo '     datalinesuffix = String.fromCharCode(idata); /' . '/ prompt("Enter " + desc.replace("  ercent ", "") + " Value " + thisline + extra, "0"); ' . "\n";
        echo '     idata = idata + 1; ' . "\n";
        echo '     /' . '/ datalinesuffix = prompt("Enter " + desc.replace("  ercent ", "") + " Value " + thisline + extra, "0"); ' . "\n";
        //echo '     if (datalinesuffix == null && desc.indexOf("ercent") != (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) datalinesuffix = totalleft; ' . "\n";
        echo '     if (datalinesuffix == null) datalinesuffix = "0"; ' . "\n";
        //echo '     if (datalinesuffix.length == 0) { ' . "\n";
        //echo '       datalinesuffix = eval(totalleft); ' . "\n";
        //echo '       totalleft = 0; ' . "\n";
        //echo '     } else if (eval(totalleft) == eval(datalinesuffix) && desc.indexOf("ercent") != (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        //echo '       totalleft = 0; ' . "\n";
        //echo '     } else if (eval(datalinesuffix) > eval(totalleft) && desc.indexOf("ercent") != (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        //echo '       datalinesuffix = eval(totalleft); ' . "\n";
        //echo '       totalleft = 0; ' . "\n";
        //echo '     } else if (eval(datalinesuffix) > eval(totalleft) && desc.indexOf("ercent") == (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        //echo '       desc = desc + "  ercent "; ' . "\n";
        //echo '     } else { ' . "\n";
        //echo '       totalleft = eval(totalleft) - eval(datalinesuffix); ' . "\n";
        //echo '     } ' . "\n";
        echo '     datac = datac + fcomma + " [" + sq + datalinesuffix + sq + "," + datalineprefix + "] "; ' . "\n";
        echo '     fcomma = ","; ' . "\n";
        echo '     thisline++; ' . "\n";
        echo '   } ' . "\n";
        echo ' } ' . "\n";
        echo ' window.location = "./intervals.php?title=" + title + "&task=" + numtaskdesc + "&desc=" + desc + "&data=" + datac; ' . "\n";
        echo "} \n" . "} \n" . '</' . 'script' . '>' . "\n";
      } 
    ?>
  </body>
</html>
