<?php

$mes = (is_null($this->mes))? date('m'): $this->mes;
$ano = (is_null($this->mes))? date('Y'): $this->ano;
$meses = array('', 'Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez');

/**/
$results = $this->results;
if(is_string($results))
{
  echo "<a class='login' href='$results'>Connect Me!</a>";
}
else
{
if (count($results->getRows()) > 0) {
  $profileName = $results->getProfileInfo()->getProfileName();
  $rows = $results->getRows();
  //var_dump($rows);

  $leDias = array();
  $leData1 = array();
  $leData2 = array();
  $leData3 = array();
  foreach($rows as $rs)
  {
    // se o dia ainda nao foi setado
    if(!in_array($rs[0], $leDias))
    {
      $a = $b = -1;
      $leDias[] = $rs[0];
    }
    if($rs[1] == 'New Visitor')
    {
      $leData1[] = $rs[2];
      $a = $rs[3];
    }
    else
    {
      $leData2[] = $rs[2];
      $b = $rs[3];
    }
    if($a > 0 && $b > 0)
    {
      $leData3[] = ($a+$b);
    }
  }

  echo '
  <script type="text/javascript">
    var leDias =  ['. implode(', ',$leDias) .'];
    var leData1 = ['. implode(', ',$leData1) .'];
    var leData2 = ['. implode(', ',$leData2) .'];
    var leData3 = ['. implode(', ',$leData3) .'];
    var leStitle = "'. $meses[sprintf("%01d", $mes)] .'/'. $ano .'";
  </script>';

} else {
  print '<p>No results found.</p>';
}
/**/
?>

<script type="text/javascript">
//  var leDias =  [1,2,3,4,5,6];
//  var leData1 = [10, 20, 10, 01, 20, 21];
//  var leData2 = [11, 21, 11, 03, 21, 24];
//  var leData3 = [15, 10, 13, 11, 10, 11];
</script>
  <select name="" id="" class="" onchange="location.href='cms_stats/list?year=' + this.options[this.selectedIndex].value;">
    <option value="<?= (date('Y')-1); ?>&month=12"<?= (($ano == (date('Y')-1))? ' selected="selected"': '');?>>Dez/<?= (date('Y')-1); ?></option>

<?php
for ($a=1; $a<13; $a++)
{
  echo '<option value="'. date('Y') .'&month='. sprintf("%02d", $a) .'"'. (($mes == $a && $ano == date('Y'))? ' selected="selected"': '') .'>'. $meses[$a] .'/'. date('Y') .'</option>';
}
?>
  </select>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<?php } //if string ?>