<?php
$year = date("Y");
################################################################################
## +---------------------------------------------------------------------------+
## | 1. Creating & Calling: |
## +---------------------------------------------------------------------------+
## *** define a relative (virtual) path to datagrid.class.php file and "pear"
## *** directory (relatively to the current file)
## *** RELATIVE PATH ONLY ***
//
define ("DATAGRID_DIR", "datagrid/"); /* Ex.: "datagrid/" */
require_once(DATAGRID_DIR."datagrid.class.php");
ob_start();
##
## *** creating variables that we need for database connection
$DB_USER="******";
$DB_PASS="******";
$DB_HOST="localhost";
$DB_NAME="******";
################################################################################
## *** put a primary key on the first place
$sql = "SELECT
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-01-01' AND demo_downloads.download_date < '".$year."-02-01') as month1,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-02-01' AND demo_downloads.download_date < '".$year."-03-01') as month2,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-03-01' AND demo_downloads.download_date < '".$year."-04-01') as month3,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-04-01' AND demo_downloads.download_date < '".$year."-05-01') as month4,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-05-01' AND demo_downloads.download_date < '".$year."-06-01') as month5,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-06-01' AND demo_downloads.download_date < '".$year."-07-01') as month6,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-07-01' AND demo_downloads.download_date < '".$year."-08-01') as month7,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-08-01' AND demo_downloads.download_date < '".$year."-09-01') as month8,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-09-01' AND demo_downloads.download_date < '".$year."-10-01') as month9,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-10-01' AND demo_downloads.download_date < '".$year."-11-01') as month10,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-11-01' AND demo_downloads.download_date < '".$year."-12-01') as month11,
(SELECT COUNT(*) FROM demo_downloads WHERE demo_downloads.download_date >= '".$year."-12-01' AND demo_downloads.download_date < '".($year+1)."-01-01') as month12
FROM demo_downloads
GROUP BY month1, month2, month3, month4 ";
## *** set needed options and create a new class instance
$debug_mode = false; /* display SQL statements while processing */
$messaging = true; /* display system messages on a screen */
$unique_prefix = "prd_"; /* prevent overlays - must be started with a letter */
$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix);
$dgrid->SetCssClass("pink");
$dgrid->DisplayLoadingImage("true");
$dgrid->AllowPaging(false, "", "");
## *** set data source with needed options
$default_order = array("download_date"=>"DESC");
$dgrid->DataSource("PDO", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);
## *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
$modes = array(
"add" =>array("view"=>false, "edit"=>false, "type"=>"link"),
"edit" =>array("view"=>false, "edit"=>false, "type"=>"link", "byFieldValue"=>""),
"cancel" =>array("view"=>false, "edit"=>false, "type"=>"link"),
"details" =>array("view"=>false, "edit"=>false, "type"=>"link"),
"delete" =>array("view"=>false, "edit"=>false, "type"=>"image")
);
$dgrid->SetModes($modes);
## *** set DataGrid caption
$dg_caption = "Current Year";
$dgrid->SetCaption($dg_caption);
$dgrid->AllowPrinting(false);
$dgrid->AllowSorting(false);
$dgrid->AllowHighlighting(false);
## +---------------------------------------------------------------------------+
## | 6. View Mode Settings: |
## +---------------------------------------------------------------------------+
## *** set view mode table properties
$vm_table_properties = array("width"=>"444px");
$dgrid->SetViewModeTableProperties($vm_table_properties);
$max_value = "3000";
$vm_colimns = array(
"month1" =>array("header"=>"Jan", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month2" =>array("header"=>"Feb", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month3" =>array("header"=>"Mar", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month4" =>array("header"=>"Apr", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month5" =>array("header"=>"May", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month6" =>array("header"=>"Jun", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month7" =>array("header"=>"Jul", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month8" =>array("header"=>"Aug", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month9" =>array("header"=>"Sep", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month10" =>array("header"=>"Oct", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
"month11" =>array("header"=>"Nov", "type"=>"barchart", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "visible"=>"true", "on_js_event"=>"", "field"=>"", "maximum_value"=>$max_value, "display_type"=>"vertical"),
);
$dgrid->SetColumnsInViewMode($vm_colimns);
## +---------------------------------------------------------------------------+
## | 8. Bind the DataGrid: |
## +---------------------------------------------------------------------------+
## *** bind the DataGrid and draw it on the screen
$dgrid->Bind();
ob_end_flush();
##
################################################################################
}
?>