<?php


include_once ("_dirinfo.php");
include_once (PATH_TO_ROOT."init.php");
if ($_POST['action'] == "delete") {
	$sql = "DELETE FROM `".DB_WARPIT_WEBCATI_BASE."`._wwwPoints WHERE pointType = 11 AND dateUsed ='".$_POST['pointsDate']."'";
	$db->SQLexecute($sql);
	
	echo "Ext.getCmp('WEBpointsManagerList').getStore().reload();";
}
elseif ($_POST['action'] == "add-new-points") {
	
	if ($_POST['number'] > 0 && $_POST['groupID']) {
		$sql = "
				INSERT INTO `".DB_WARPIT_WEBCATI_BASE."`._wwwPoints ( id_project, pointType, id_user, webPoints, dateUsed )
					SELECT 10, 11, id, ".$_POST['number'].",NOW() FROM `".DB_WARPIT_USERSPOOL."`._group_link WHERE id_group = ".$_POST['groupID'];		
		//echo $sql;
		$db->SQLexecute($sql);
		echo "Ext.getCmp('AddingNewPoolPointsWindow').close();";
		echo "Ext.getCmp('WEBpointsManagerList').getStore().reload();";
		
	}
} else {

$sql = " SELECT count(*) as n, dateUsed as pointsDate, SUM(webPoints) as points FROM `".DB_WARPIT_WEBCATI_BASE."`._wwwPoints WHERE pointType = 11  GROUP BY dateUsed ORDER BY `dateUsed` ";

//$sql .= " ORDER BY datum DESC";
//echo $sql;
$result = $db->SQLexecute($sql);
while ($dat = $db->fetchAssoc($result)) {
	$data[] = $dat;
}
	
	?>
	
	{
		success: true,
	    results: <?php echo sizeof($data);?>, 
	    rows: <?php echo json_encode($data); ?>        
	    
	}
<?php 
}
?>