<?php
  function retval($inv) {
    if (strpos($inv, "E-") !== false) return "0";
    return $inv;
  }
?>

<html>
  <head>
    <title>Motion Chart - RJM Programming - http://www.rjmprogramming.com.au (Copyright &copy; 2013 rjmprogramming.com.au all rights reserved.)</title>
    <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="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
    var num = 0;
    var retval = "";
    var ttitle = "";
    var ttask = "";
    var tsales = "";
    var texpenses = "";
    var tlocation = "";
	    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 = "Fruit Sales and Expenses Trend";
      $GETtask = ""; //"Task";
      $GETdesc = "Fruit";
      $GETsales = "Sales";
      $GETexpenses = "Expenses";
      $GETlocation = "Location";
      $GETdata = "['Apples', new Date(1988,0,1), 1000, 300, 'East'],['Oranges', new Date(1988,0,1), 950, 200, 'West'],['Bananas', new Date(1988,0,1), 300, 250, 'West'],['Apples', new Date(1988,1,1), 1200, 400, 'East'],['Oranges', new Date(1988,1,1), 900, 150, 'West'],['Bananas', new Date(1988,1,1), 788, 617, 'West']";
      if (isset($_GET['data'])) {
       //$GETtitle = str_replace("~~", "##", $_GET['title']);
       $GETtitle = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", $_GET['title'])));
       //$GETtitle = str_replace("##", "'", $GETtitle);
       $GETtask = $_GET['task'];
       //$GETdesc = str_replace("~~", "##", $_GET['desc']);
       $GETdesc = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", $_GET['desc'])));
       //$GETdesc = str_replace("##", "'", $GETdesc);
       $GETsales = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", $_GET['sales'])));
       $GETexpenses = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", $_GET['expenses'])));;
       $GETlocation = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", $_GET['location'])));;
       $GETdata = $_GET['data'];
      }
      
      echo ' google.load("visualization", "1", {packages:["motionchart"]}); ' . "\n";
      echo ' function drawChart() { ' . "\n";
      //echo " var container = document.getElementById('chart_div'); \n";
      //echo " var chart = new google.visualization.Motion(container); \n";

      echo ' var dataTable = new google.visualization.DataTable(); ' . "\n";
      echo " dataTable.addColumn('string', '" . $GETdesc . "'); \n";
      echo " dataTable.addColumn('date', 'Date'); \n";
      echo " dataTable.addColumn('number', '" . $GETsales . "'); \n";
      echo " dataTable.addColumn('number', '" . $GETexpenses . "'); \n";
      echo " dataTable.addColumn('string', '" . $GETlocation . "'); \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(",~", ",'", str_replace("~]", "']", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $GETdata)))))))))))))))));
      echo "]);\n";

      //echo " var chart = new google.visualization.Motion(document.getElementById('chart_div')); \n";
      //echo " chart.draw(dataTable); \n } \n";
      echo " var motionchart = new google.visualization.MotionChart(document.getElementById('chart_div')); \n";
      echo " motionchart.draw(dataTable, {'width': 800, 'height': 400}); \n";
      echo "}\n";
      
      echo ' google.setOnLoadCallback(drawChart); ' . "\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 iput = document.getElementById("i' . $ic . 'put"); ' . "\n"; 
 echo ' var lput = document.getElementById("l' . $ic . 'put"); ' . "\n"; 
 echo ' var soneput = document.getElementById("sone' . $ic . 'put"); ' . "\n"; 
 echo ' var eoneput = document.getElementById("eone' . $ic . 'put"); ' . "\n"; 
 echo ' var stwoput = document.getElementById("stwo' . $ic . 'put"); ' . "\n"; 
 echo ' var etwoput = document.getElementById("etwo' . $ic . 'put"); ' . "\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() + ")," + soneput.value + "," + eoneput.value + ",~" + lput.value + "~],[~" + iput.value + "~,"; ' . "\n"; 
 //echo ' retval = retval + pDates.getDate() + ".";	         ' . "\n"; 
 echo '      } else { ' . "\n"; 
 echo '  pDates = YAHOO.example.calendar.cals1.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() + ")," + soneput.value + "," + eoneput.value + ",~" + lput.value + "~],[~" + iput.value + "~,"; ' . "\n"; 
 //echo ' retval = retval + pDates.getDate() + ".";	         ' . "\n"; 
 echo '      }  ' . "\n"; 
 echo '      } ' . "\n"; 
 echo ' if (pDatee) { ' . "\n"; 
 echo ' retval = retval + "newDate(" + eval(1900 + pDatee.getYear()) + ","; ' . "\n"; 
 echo ' retval = retval + eval(0 + pDatee.getMonth()) + ","; ' . "\n"; 
 echo ' retval = retval + pDatee.getDate() + ")," + stwoput.value + "," + etwoput.value + ",~" + lput.value + "~]"; ' . "\n"; 
 //echo ' retval = retval + pDatee.getDate() + ".";	         ' . "\n"; 
 echo '     } else { ' . "\n"; 
 echo '  pDatee = YAHOO.example.calendar.cale1.getSelectedDates()[0]; ' . "\n"; 
 echo ' if (pDatee) { ' . "\n"; 
 echo ' retval = retval + "newDate(" + eval(1900 + pDatee.getYear()) + ","; ' . "\n"; 
 echo ' retval = retval + eval(0 + pDatee.getMonth()) + ","; ' . "\n"; 
 echo ' retval = retval + pDatee.getDate() + ")," + stwoput.value + "," + etwoput.value + ",~" + lput.value + "~]"; ' . "\n"; 
 //echo ' retval = retval + pDatee.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);
     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 = "./motion_chart.php?title=" + ttitle.replace("'", "~~").replace('"', '~') + "&desc=" + ttitle.replace("'", "~~").replace('"', '~') + "&data=" + dt.replace("'", "~~").replace('"', '~');
   }
<?php
      echo " </script> \n";
      echo " </head> \n";
      echo " <body class='yui-skin-sam' onload='setTimeout(later, 2 * 1000);'> \n";
      echo " <h1>" . $GETtitle . " Motion Chart</h1> \n";
?>
    <div id="chart_div" style="width: 800px; height: 400px; background-color: yellow;"></div>
    <div id="calendar_table"></div>
    <a title="Another Motion Chart" href="./motion_chart.php">Another motion chart?</a>
    <?php 
      if (!isset($_GET['desc'])) {
      
        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 dnone = ""; ' . "\n";
        echo ' var sales = ""; ' . "\n";
        echo ' var expenses = ""; ' . "\n";
        echo ' var location = ""; ' . "\n";
        echo ' var ict = 0; ' . "\n";
        echo ' var thisline = 1; ' . "\n";
        echo ' var totalleft = 100.0; ' . "\n";
        echo ' var title = prompt("Enter Motion Chart Title", "Fruit"); ' . "\n";
        
        echo ' if (title != null) { ' . "\n";
        echo ' ttitle = title; ' . "\n" . ' task = prompt("Enter Number of " + title, "0"); ttask = task; ' . "\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 '  sales = prompt("Enter Motion Chart " + title + " X-Axis Heading", "Sales"); ' . "\n";
        echo '  expenses = prompt("Enter Motion Chart " + title + " Y-Axis Heading", "Expenses"); ' . "\n";
        echo '  location = prompt("Enter Motion Chart " + title + " Location Heading", "Location"); ' . "\n";
        echo '  tsales = sales; ' . "\n";
        echo '  texpenses = expenses; ' . "\n";
        echo '  tlocation = location; ' . "\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 style=' . "'" . 'width:100%' . "'" . '><tr><td>From</td><td>From " + sales + "</td><td>From " + expenses + "</td><td>" + title + "</td><td>" + location + "</td><td>To " + sales + "</td><td>To " + expenses + "</td><td>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 " + dnone + " 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=' . "'" . 'i" + ict + "put' . "'" . ' type=text></input></td>";' . "\n";
        echo '    bits = bits + "<td style=background-color:lightgray;width:8%><input id=' . "'" . 'l" + 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 " + dnone + " id=cal" + ict + "EContainer></div></td>";' . "\n";
        echo '    bits = bits + "</tr>";' . "\n";
        echo '    dnone = " style=display:none; ";' . "\n";
        //echo '  alert(ict + " -- " + bits);' . "\n";
        echo '    } ' . "\n";

        echo '  } else { alert("Can only handle 99 or less."); window.location = "./motion_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>
