<?php 
require("common_begin.php");

if (!isset($_POST['id']) || !is_numeric($_POST['id']))
  die("no user ID set");

$lst = Listopia::getInstance();

$result = array();
$query = $lst->Database()->select(array(
                      'fields' => 'count(*) as counter, yearweek(t_items.item_created) as dayg, unix_timestamp(t_items.item_created) as unix_date, t_items.item_created',
                      'table' => 't_items',
                      'condition' => 't_items.item_createdby = '.((int)($_POST['id'])),
                      'group' => 'dayg',
                      'order' => 't_items.item_created desc',
                      'limit' => 40
                      ));
// go ahead if we have >1 row
if (!empty($query[0]) && !empty($query[1]))
{
  $result['cols'] = array( 
    array('label' => 'Time', 'type' => 'string'), 
    array('label' => 'Posts', 'type' => 'number') 
    );

  $rowset = array();
  
  $q = array_reverse($query);
  foreach ($q as &$entry)
  {
    $dateString = date("M 'y", $entry[0]['unix_date']);
    
    $trow = array('c' => array(
              array('v' => $dateString, 'f' => null),
              array('v' => intval($entry[0]['counter']), 'f' => null)
              )
            );
  
    array_push($rowset, $trow);
  }
  
  $result['rows'] = $rowset;
}

echo json_encode($result);

require("common_end.php");

