<?php
## +---------------------------------------------------------------------------+
## | 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");
## *** creating variables that we need for database connection
$DB_USER="username"; // usually like this: prefix_name
$DB_PASS="password"; // must be already enscrypted
$DB_HOST="localhost"; // often localhost
$DB_NAME="database_name"; // usually like this: prefix_name
ob_start();
## *** put a primary key on the first place
$sql=" SELECT
demo_presidents.id,
demo_presidents.name,
demo_presidents.birth_date,
demo_presidents.status,
demo_presidents.country_id,
demo_presidents.is_active,
demo_presidents.favorite_color,
demo_countries.name as country_name
FROM demo_presidents
INNER JOIN demo_countries ON demo_presidents.country_id=demo_countries.id ";
## *** 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 = "prs_"; /* prevent overlays - must be started with a letter */
$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix);
## *** set data source with needed options
$default_order = array("rating"=>"ASC");
$dgrid->DataSource("PDO", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);
## +---------------------------------------------------------------------------+
## | 2. General Settings: |
## +---------------------------------------------------------------------------+
## +-- PostBack Submission Method ---------------------------------------------+
## *** defines postback submission method for DataGrid: AJAX, POST or GET(default)
$postback_method = "ajax";
$dgrid->SetPostBackMethod($postback_method);
$dg_language = "en";
$dgrid->SetInterfaceLang($dg_language);
## *** set layouts: "0" - tabular(horizontal) - default, "1" - columnar(vertical), "2" - customized
$layouts = array("view"=>"0", "edit"=>"1", "details"=>"1", "filter"=>"2");
$dgrid->SetLayouts($layouts);
## *** allow multirow operations
$multirow_option = true;
$dgrid->AllowMultirowOperations($multirow_option);
$multirow_operations = array(
"edit" => array("view"=>true),
"delete" => array("view"=>true),
"details" => array("view"=>true),
);
$dgrid->SetMultirowOperations($multirow_operations);
## *** set DataGrid caption
$dg_caption = "Presidents";
$dgrid->SetCaption($dg_caption);
## +---------------------------------------------------------------------------+
## | 3. Printing & Exporting Settings: |
## +---------------------------------------------------------------------------+
## *** set printing option: true(default) or false
$printing_option = true;
$dgrid->AllowPrinting($printing_option);
## *** set exporting option: true(default) or false and relative (virtual) path
## *** to export directory (relatively to datagrid.class.php file).
## *** Ex.: "" - if we use current datagrid folder
$exporting_option = false;
$exporting_directory = "";
$dgrid->AllowExporting($exporting_option, $exporting_directory);
$exporting_types = array("excel"=>"true", "pdf"=>"true", "xml"=>"true");
$dgrid->AllowExportingTypes($exporting_types);
## +---------------------------------------------------------------------------+
## | 4. Sorting & Paging Settings: |
## +---------------------------------------------------------------------------+
## *** set sorting option: true(default) or false
$sorting_option = true;
$dgrid->AllowSorting($sorting_option);
## *** set paging option: true(default) or false
$paging_option = true;
$rows_numeration = false;
$numeration_sign = "N #";
$dropdown_paging = true;
$dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign, $dropdown_paging);
## *** set paging settings
$bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
$top_paging = array();
$pages_array = array("2"=>"2", "5"=>"5", "7"=>"7", "10"=>"10", "15"=>"15", "25"=>"25");
$default_page_size = 7;
$paging_arrows = array("first"=>"|<<", "previous"=>"<<", "next"=>">>", "last"=>">>|");
$dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);
## +---------------------------------------------------------------------------+
## | 5. Filter Settings: |
## +---------------------------------------------------------------------------+
## *** set filtering option: true or false(default)
$filtering_option = true;
$show_search_type = true;
$dgrid->AllowFiltering($filtering_option, $show_search_type);
## *** set additional filtering settings
## *** tips: use "," (comma) if you want to make search by some words, for ex.: hello, bye, hi
$filtering_fields = array(
"Name" =>array("type"=>"textbox", "table"=>"demo_presidents", "field"=>"name", "show_operator"=>"false", "default_operator"=>"like%", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"80px", "on_js_event"=>""),
"Birth From" =>array("type"=>"calendar", "field_type"=>"from", "calendar_type"=>"floating", "date_format"=>"date", "table"=>"demo_presidents", "field"=>"birth_date", "show_operator"=>"false", "default_operator"=>">=", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"70px", "on_js_event"=>""),
"To" =>array("type"=>"calendar", "field_type"=>"to", "calendar_type"=>"floating", "date_format"=>"date", "table"=>"demo_presidents", "field"=>"birth_date", "show_operator"=>"false", "default_operator"=>"<=", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"70px", "on_js_event"=>""),
"Status" =>array("type"=>"enum", "table"=>"demo_presidents", "field"=>"status", "field_view"=>"", "filter_condition"=>"", "order"=>"ASC", "source"=>"self", "view_type"=>"radiobutton", "condition"=>"", "show_operator"=>"false", "default_operator"=>"=", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"", "multiple"=>"false", "multiple_size"=>"4", "on_js_event"=>""),
);
$dgrid->SetFieldsFiltering($filtering_fields);
## +---------------------------------------------------------------------------+
## | 6. View Mode Settings: |
## +---------------------------------------------------------------------------+
## *** set view mode table properties
$vm_table_properties = array("width"=>"90%");
$dgrid->SetViewModeTableProperties($vm_table_properties);
## *** set columns in view mode
## *** "barchart" : number format in SELECT SQL must be equal with number format in max_value
$vm_colimns = array(
"name" =>array("header"=>"Name", "type"=>"label", "align"=>"left", "wrap"=>"wrap", "text_length"=>"20", "case"=>"normal"),
"country_name" =>array("header"=>"Country", "type"=>"label", "align"=>"center", "wrap"=>"nowrap", "text_length"=>"30", "case"=>"normal"),
"birth_date" =>array("header"=>"Birth Date", "type"=>"label", "align"=>"center", "header_tooltip"=>"Shows the birth date", "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
"status" =>array("header"=>"Status", "type"=>"label", "align"=>"center", "header_tooltip"=>"Shows the current status", "wrap"=>"nowrap", "text_length"=>"30", "case"=>"normal"),
"favorite_color" =>array("header"=>"Favorite Color", "type"=>"color", "align"=>"center", "width"=>"", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "view_type"=>"image"),
"is_active" =>array("header"=>"Active", "type"=>"checkbox", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "sort_type"=>"numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "true_value"=>1, "false_value"=>0),
"rating" =>array("header"=>"Rating", "type"=>"label", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "sort_type"=>"numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "movable"=>true, ),
);
$dgrid->SetColumnsInViewMode($vm_colimns);
## +---------------------------------------------------------------------------+
## | 7. Add/Edit/Details Mode Settings: |
## +---------------------------------------------------------------------------+
## *** set add/edit mode table properties
$em_table_properties = array("width"=>"75%");
$dgrid->SetEditModeTableProperties($em_table_properties);
## *** set details mode table properties
$dm_table_properties = array("width"=>"60%");
$dgrid->SetDetailsModeTableProperties($dm_table_properties);
## *** set settings for add/edit/details modes
$table_name = "demo_presidents";
$primary_key = "id";
$condition = "";
$dgrid->SetTableEdit($table_name, $primary_key, $condition);
## *** set columns in edit mode
$em_columns = array(
"name" =>array("header"=>"Name", "type"=>"textbox", "width"=>"140px", "req_type"=>"rt", "title"=>"Name"),
"birth_date" =>array("header"=>"Birth Date", "type"=>"date", "req_type"=>"rt", "width"=>"80px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"floating"),
"status" =>array("header"=>"Status", "type"=>"enum", "req_type"=>"st", "width"=>"210px", "title"=>"Status", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "on_js_event"=>"", "source"=>"self", "view_type"=>"dropdownlist"),
"country_id" =>array("header"=>"Country", "type"=>"textbox", "width"=>"160px", "req_type"=>"ri", "title"=>"Country", "readonly"=>true),
"favorite_color" =>array("header"=>"Favorite Color", "type"=>"color", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "view_type"=>"dropdownlist", "save_format"=>"hexcodes"),
"is_active" =>array("header"=>"Active", "type"=>"checkbox", "req_type"=>"si", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "true_value"=>1, "false_value"=>0),
);
$dgrid->SetColumnsInEditMode($em_columns);
## *** set foreign keys for add/edit/details modes (if there are linked tables)
$foreign_keys = array(
"country_id"=>array("table"=>"demo_countries", "field_key"=>"id", "field_name"=>"name", "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal", "condition"=>"", "order_by_field"=>"", "order_type"=>"ASC", "on_js_event"=>""),
);
$dgrid->SetForeignKeysEdit($foreign_keys);
## +---------------------------------------------------------------------------+
## | 8. Bind the DataGrid: |
## +---------------------------------------------------------------------------+
## *** bind the DataGrid and draw it on the screen
## call of this method between HTML ≶HEAD> tags
$dgrid->WriteCssClass();
$dgrid->Bind();
ob_end_flush();
################################################################################
?>