<?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>Annotated Timeline Chart - 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="http://yui.yahooapis.com/2.9.0/build/yahoo/yahoo.js"></script> 
 <script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/event/event.js" ></script> 
 <script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/dom/dom.js" ></script> 
 <script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/calendar/calendar.js"></script> 
<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.9.0/build/calendar/assets/skins/sam/calendar.css"> 
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
    var num = 0;
    var retval = "";
    var ttitle = "";
    var ttitle1 = "title1";
    var ttitle2 = "title2";
    var ttext1 = "text1";
    var ttext2 = "text2";
    var ttask1 = "Sold Pencils";
    var ttask2 = "Sold Pens";
	    YAHOO.namespace("example.calendar"); 	 
	    //YAHOO.example.calendar.init = function() { 
	    // YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1SContainer"); 
	    // YAHOO.example.calendar.cal1.render(); 
	    //} 	 
	    //YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init); 	    
<?php 
      $GETtitle = "Sold Pencils and Sold Pens";
      $GETtask = ""; //"Task";
      $GETdesc1 = "Sold Pencils";
      $GETtitle1 = "title1";
      $GETtext1 = "text1";
      $GETdesc2 = "Sold Pencils";
      $GETtitle2 = "title2";
      $GETtext2 = "text2";
      $GETdata = "    [new Date(2008, 1 ,1), 30000, null, null, 40645, null, null],[new Date(2008, 1 ,2), 14045, null, null, 20374, null, null],[new Date(2008, 1 ,3), 55022, null, null, 50766, null, null],[new Date(2008, 1 ,4), 75284, null, null, 14334, 'Out of Stock', 'Ran out of stock on pens at 4pm'],[new Date(2008, 1 ,5), 41476, 'Bought Pens', 'Bought 200k pens', 66467, null, null],[new Date(2008, 1 ,6), 33322, null, null, 39463, null, null] ";
    //[ "Washington", new Date(1789, 3, 29), new Date(1797, 2, 3) ],[ "Adams",      new Date(1797, 2, 3),  new Date(1801, 2, 3) ],[ "Jefferson",  new Date(1801, 2, 3),  new Date(1809, 2, 3) ]';
      if (isset($_POST['data'])) {
       //$GETtitle = str_replace("~~", "##", $_POST['title']);
       $GETtitle = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_POST['title'])))));
       $GETtitle1 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_POST['title1'])))));
       $GETtitle2 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_POST['title2'])))));
       $GETtext1 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_POST['text1'])))));
       $GETtext2 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_POST['text2'])))));
       //$GETtitle = str_replace("##", "'", $GETtitle);
       $GETtask = str_replace("\\'", "'", urldecode($_POST['task'])); //$_POST['task'];
       //$GETdesc = str_replace("~~", "##", $_POST['desc']);
       $GETdesc1 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_POST['desc1'])))));
       $GETdesc2 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_POST['desc2'])))));
       //$GETdesc = str_replace("##", "'", $GETdesc);
       $GETdata = str_replace("~", "'", str_replace("\\'", "'", urldecode($_POST['data'])));
      }
      if (isset($_GET['data'])) {
       //$GETtitle = str_replace("~~", "##", $_GET['title']);
       $GETtitle = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_GET['title'])))));
       $GETtitle1 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_GET['title1'])))));
       $GETtitle2 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_GET['title2'])))));
       $GETtext1 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_GET['text1'])))));
       $GETtext2 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_GET['text2'])))));
       //$GETtitle = str_replace("##", "'", $GETtitle);
       $GETtask = str_replace("\\'", "'", urldecode($_GET['task'])); //$_GET['task'];
       //$GETdesc = str_replace("~~", "##", $_GET['desc']);
       $GETdesc1 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_GET['desc1'])))));
       $GETdesc2 = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode($_GET['desc2'])))));
       //$GETdesc = str_replace("##", "'", $GETdesc);
       $GETdata = str_replace("~", "'", str_replace("\\'", "'", urldecode($_GET['data'])));
      }
      
      echo ' google.load("visualization", "1", {packages:["annotatedtimeline"]}); ' . "\n";
      echo ' function drawChart() { ' . "\n";
      /*
  var data = new google.visualization.DataTable();
  data.addColumn('date', 'Date');
  data.addColumn('number', 'Sold Pencils');
  data.addColumn('string', 'title1');
  data.addColumn('string', 'text1');
  data.addColumn('number', 'Sold Pens');
  data.addColumn('string', 'title2');
  data.addColumn('string', 'text2');
  data.addRows([
    [new Date(2008, 1 ,1), 30000, null, null, 40645, null, null],
    [new Date(2008, 1 ,2), 14045, null, null, 20374, null, null],
    [new Date(2008, 1 ,3), 55022, null, null, 50766, null, null],
    [new Date(2008, 1 ,4), 75284, null, null, 14334, 'Out of Stock', 'Ran out of stock on pens at 4pm'],
    [new Date(2008, 1 ,5), 41476, 'Bought Pens', 'Bought 200k pens', 66467, null, null],
    [new Date(2008, 1 ,6), 33322, null, null, 39463, null, null]
  ]);

  var annotatedtimeline = new google.visualization.AnnotatedTimeLine(
      document.getElementById('visualization'));
  annotatedtimeline.draw(data, {'displayAnnotations': true});
  */
      //echo " var container = document.getElementById('chart_div'); \n";

      //echo " var chart = new google.visualization.AnnotatedTimeline(container); \n";

      echo ' var dataTable = new google.visualization.DataTable(); ' . "\n";
      echo " dataTable.addColumn(  'date', 'Date' ); \n";
      echo " dataTable.addColumn(  'number',  '" . $GETdesc1 . "' ); \n";
      echo " dataTable.addColumn(  'string',  '" . $GETtitle1 . "' ); \n";
      echo " dataTable.addColumn(  'string',  '" . $GETtext1 . "' ); \n";
      echo " dataTable.addColumn(  'number',  '" . $GETdesc2 . "' ); \n";
      echo " dataTable.addColumn(  'string',  '" . $GETtitle2 . "' ); \n";
      echo " dataTable.addColumn(  'string',  '" . $GETtext2 . "' ); \n";

      echo ' dataTable.addRows([' . "\n";
      echo str_replace("~~", "'", str_replace("newDate", "new Date", str_replace("%2c", ",", str_replace("%27", "'", str_replace("%20", " ", str_replace("%28", "(", str_replace("%29", ")", str_replace("%5b", "[", str_replace("`", "'",str_replace("%5d", "]",str_replace('~,', '",', str_replace('[~', '["', str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $GETdata)))))))))))))));
      echo "]);\n";

      echo " var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div')); \n";
      echo " chart.draw(dataTable, {'displayAnnotations': true}); \n } \n";
      
      $ic = 1;
      
      for ($ic=1; $ic<100; $ic++) {
 echo ' function cals' . $ic . '(inhuh,mode) {' . "\n";
 echo ' if (inhuh > ' . $ic . ') { return cals' . ($ic + 1) . '(inhuh,mode); } else if (inhuh < ' . $ic . ') { return cals' . ($ic - 1) . '(inhuh,mode); } else { ' . "\n";
 echo ' if (mode == 0) {YAHOO.example.calendar.cals' . $ic . ' = new YAHOO.widget.Calendar("cals' . $ic . '","cal' . $ic . 'SContainer");  ' . "\n";
 echo ' YAHOO.example.calendar.cals' . $ic . '.render();  ' . "\n";
 echo ' YAHOO.example.calendar.cale' . $ic . ' = new YAHOO.widget.Calendar("cale' . $ic . '","cal' . $ic . 'EContainer");  ' . "\n";
 echo ' YAHOO.example.calendar.cale' . $ic . '.render(); ' . "\n"; 
 echo ' } else { ' . "\n"; 
 echo ' retval = "[";  ' . "\n"; 
 echo ' var soneput = document.getElementById("sone' . $ic . 'put"); ' . "\n"; 
 echo ' var stwoput = document.getElementById("stwo' . $ic . 'put"); ' . "\n"; 
 echo ' var eoneput = document.getElementById("eone' . $ic . 'put"); ' . "\n"; 
 echo ' var etwoput = document.getElementById("etwo' . $ic . 'put"); ' . "\n"; 
 echo ' var ioneput = document.getElementById("ione' . $ic . 'put"); ' . "\n"; 
 echo ' var itwoput = document.getElementById("itwo' . $ic . 'put"); ' . "\n"; 
 echo ' var rest = "," + ioneput.value + ",' . "~" . '" + soneput.value +  "' . "~" . ',' . "~" . '" + eoneput.value +  "' . "~" . '"; ' . "\n"; 
 echo ' rest = rest + "," + itwoput.value + ",' . "~" . '" + stwoput.value +  "' . "~" . ',' . "~" . '" + etwoput.value +  "' . "~" . '"; ' . "\n"; 
//echo " retval = retval + '[" . '"' . "' + iput.value + '" . '"' . ",'; " . "\n"; 
 echo ' var pDates = YAHOO.example.calendar.cals' . $ic . '.getSelectedDates()[0]; ' . "\n"; 
 echo ' var pDatee = YAHOO.example.calendar.cale' . $ic . '.getSelectedDates()[0]; ' . "\n"; 
 echo ' if (pDates) { ' . "\n"; 
 echo ' retval = retval + "newDate(" + eval(1900 + pDates.getYear()) + ","; ' . "\n"; 
 echo ' retval = retval + eval(0 + pDates.getMonth()) + ","; ' . "\n"; 
 echo ' retval = retval + pDates.getDate() + ")" + rest + "]"; ' . "\n"; 
 //echo ' retval = retval + pDates.getDate() + ".";	         ' . "\n"; 
 echo '      } else { ' . "\n"; 
 echo '  pDates = YAHOO.example.calendar.cale' . ($ic - 1) . '.getSelectedDates()[0]; ' . "\n"; 
 echo ' if (pDates) { ' . "\n"; 
 echo ' retval = retval + "newDate(" + eval(1900 + pDates.getYear()) + ","; ' . "\n"; 
 echo ' retval = retval + eval(0 + pDates.getMonth()) + ","; ' . "\n"; 
 echo ' retval = retval + pDates.getDate() + ")" + rest + "]"; ' . "\n"; 
 //echo ' retval = retval + pDates.getDate() + ".";	         ' . "\n"; 
 echo '      }  ' . "\n"; 
 echo '      } ' . "\n"; 
 echo '  return retval;  } ' . "\n"; 
 echo ' } return ""; } ' . "\n";
      }
      
?>
   function cals0(huh,huh2) {
   }
   function cals100(huh,huh2) {
   }

   function goforth() {
   //alert("99 vs " + num);
     var ii=1;
     var dt = "";
     var ci = "";
     while (ii <= num) {
       dt = dt + ci + cals1(ii,1);
       dt = dt.replace("'", "~~").replace('"', '~');
       dt = dt.replace("'", "~~").replace('"', '~');
       dt = dt.replace("'", "~~").replace('"', '~');
       dt = dt.replace("'", "~~").replace('"', '~');
       ttitle = ttitle.replace("'", "~~").replace('"', '~');
       ttitle = ttitle.replace("'", "~~").replace('"', '~');
       ci = ",";
       ii = ii + 1;
       //alert(dt);
     }
     window.location = "./annotatedtimeline_chart.php?title=" + ttitle.replace("'", "~~").replace('"', '~') + "&desc1=" + ttask1.replace("'", "~~").replace('"', '~') + "&title1=" + ttitle1.replace("'", "~~").replace('"', '~') + "&text1=" + ttext1.replace("'", "~~").replace('"', '~') + "&desc2=" + ttask2.replace("'", "~~").replace('"', '~') + "&title2=" + ttitle2.replace("'", "~~").replace('"', '~') + "&text2=" + ttext2.replace("'", "~~").replace('"', '~') + "&data=" + dt.replace("'", "~~").replace('"', '~');
   }
<?php
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";
      echo " </script> \n";
      echo " </head> \n";
      echo " <body class='yui-skin-sam' onload='setTimeout(later, 2 * 1000);'> \n";
      echo " <h1>" . $GETtitle . " Annotated Timeline Chart</h1> \n";
?>
    <div id="chart_div" style="width: 800px; height: 400px; background-color: yellow;"></div>
    <div id="calendar_table"></div>
    <a title="Annotated Timeline Chart" href="./annotatedtimeline_chart.php">Another annotated timeline chart?</a>
    <?php 
      if (!isset($_GET['desc1']) && !isset($_POST['desc1'])) {
      
        echo '<' . 'script' . '>' . "\n " . " function later() { \n" . ' var datalineprefix = " "; ' . "\n";
        echo ' var datalinesuffix = ""; ' . "\n";
        echo ' var extra = ""; ' . "\n";
        echo ' var bits = ""; ' . "\n";
        echo ' var task = ""; ' . "\n";
        echo ' var xtask = ""; ' . "\n";
        echo ' var ict = 0; ' . "\n";
        echo ' var thisline = 1; ' . "\n";
        echo ' var totalleft = 100.0; ' . "\n";
        echo ' var title = prompt("Enter Annotated Timeline Chart Title", "Sold Pencils and Sold Pens"); ' . "\n";
        
        echo ' if (title != null) { ' . "\n";
        echo ' ttitle = title; ' . "\n" . ' task = prompt("Number of Timeline Events for " + title, ""); ' . "\n";
        
        
        echo ' if (task == null) { ' . "\n";
        echo '  title = title; ' . "\n";
        echo ' } else if (task != "0" && task.indexOf("-") == -1 && (task.length == 1 || task.length == 2)) { ' . "\n";
        echo ' xtask = prompt("Task1", ttask1); ttask1 = xtask; ttitle1 = xtask + " " + ttitle1;  ttext1 = xtask + " " + ttext1; ' . "\n";
        echo ' xtask = prompt("Title1", ttitle1); ttitle1 = xtask; ' . "\n";
        echo ' xtask = prompt("Text1", ttext1); ttext1 = xtask; ' . "\n";
        echo ' xtask = prompt("Task2", ttask2); ttask2 = xtask; ttitle2 = xtask + " " + ttitle2;  ttext2 = xtask + " " + ttext2;  ' . "\n";
        echo ' xtask = prompt("Title2", ttitle2); ttitle2 = xtask; ' . "\n";
        echo ' xtask = prompt("Text2", ttext2); ttext2 = xtask; ' . "\n";
        echo '  bits = "<br><a href=# onclick=' . "'" . 'goforth();' . "'" . ' title=' . "'" . 'Show' . "'" . '>Click here to Show Chart when All Filled out Below ...</a><br><table border=1><tr><td>From</td><td>" + ttitle1 + "</td><td>" + ttext1 + "</td><td>" + ttask1 + "</td><td>" + ttask2 + "</td><td>" + ttitle2 + "</td><td>" + ttext2 + "</td><td style=display:none;>To</td></tr>";' . "\n";

        echo '  num = task;' . "\n" . 'while (ict != task) { ' . "\n";
        echo '    bits = bits + "<tr>";' . "\n";
        echo '    ict = ict + 1;' . "\n";
        echo '    bits = bits + "<td><div id=cal" + ict + "SContainer></div></td>";' . "\n";
        echo '    bits = bits + "<td style=' . "'" . 'width:8%' . "'" . '><input id=' . "'" . 'sone" + ict + "put' . "'" . ' type=text></input></td>";' . "\n";
        echo '    bits = bits + "<td style=' . "'" . 'width:8%' . "'" . '><input id=' . "'" . 'eone" + ict + "put' . "'" . ' type=text></input></td>";' . "\n";
        echo '    bits = bits + "<td style=' . "'" . 'background-color:lightgray;width:8%' . "'" . '><input id=' . "'" . 'ione" + ict + "put' . "'" . ' type=text></input></td>";' . "\n";
        echo '    bits = bits + "<td style=' . "'" . 'background-color:lightgray;width:8%' . "'" . '><input id=' . "'" . 'itwo" + ict + "put' . "'" . ' type=text></input></td>";' . "\n";
        echo '    bits = bits + "<td style=' . "'" . 'width:8%' . "'" . '><input id=' . "'" . 'stwo" + ict + "put' . "'" . ' type=text></input></td>";' . "\n";
        echo '    bits = bits + "<td style=' . "'" . 'width:8%' . "'" . '><input id=' . "'" . 'etwo" + ict + "put' . "'" . ' type=text></input></td>";' . "\n";
        echo '    bits = bits + "<td><div style=' . "'" . 'display:none;' . "'" . ' id=cal" + ict + "EContainer></div></td>";' . "\n";
        echo '    bits = bits + "</tr>";' . "\n";
        //echo '  alert(ict + " -- " + bits);' . "\n";
        echo '    } ' . "\n";

        echo '  } else { alert("Can only handle 99 or less."); window.location = "./annotatedtimeline_chart.php"; }' . "\n";
        echo '  bits = bits + "</table>";' . "\n";
        //echo '  alert(bits);' . "\n";
        echo ' var ct = document.getElementById("calendar_table"); ' . "\n";
        echo '  ct.innerHTML = bits;' . "\n";
        //echo '  alert(ct.innerHTML);' . "\n";
        echo '    if (ict != 0) { ict = 0; ' . "\n";
        echo '  while (ict != task) { ' . "\n";
        echo '    ict = ict + 1;' . "\n";
        echo '    cals1(ict,0);' . "\n";
        echo '    } } ' . "\n";
        echo ' } ' . "\n";
        

        echo "} \n" . '</' . 'script' . '>' . "\n";
      } 
    ?>
  </body>
</html>
