<?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.region_id,
demo_presidents.country_id,
demo_presidents.name,
demo_presidents.birth_date,
demo_presidents.status,
demo_presidents.rating,
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: |
## +---------------------------------------------------------------------------+
## +-- AJAX -------------------------------------------------------------------+
## *** enable or disable using of AJAX (for sorting and paging ONLY)
$ajax_option = true;
$dgrid->AllowAjax($ajax_option);
## *** set interface language (default - English)
/// $dg_language = "en";
/// $dgrid->SetInterfaceLang($dg_language);
## *** set direction: "ltr" or "rtr" (default - "ltr")
/// $direction = "ltr";
/// $dgrid->SetDirection($direction);
## *** set layouts: "0" - tabular(horizontal) - default, "1" - columnar(vertical), "2" - customized
$layouts = array("view"=>"0", "edit"=>"0", "details"=>"1", "filter"=>"1");
$dgrid->SetLayouts($layouts);
/// $details_template = "<table><tr><td>{field_name_1}</td><td>{field_name_2}</td></tr>...</table>";
/// $dgrid->SetTemplates("","",$details_template);
## *** set modes for operations ("type" => "link|button|image")
## *** "view" - view mode | "edit" - add/edit/details modes
## *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
/// $modes = array(
/// "add" =>array("view"=>true, "edit"=>false, "type"=>"link", "show_add_button"=>"inside|outside"),
/// "edit" =>array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>""),
/// "cancel" =>array("view"=>true, "edit"=>true, "type"=>"link"),
/// "details" =>array("view"=>true, "edit"=>false, "type"=>"link"),
/// "delete" =>array("view"=>true, "edit"=>true, "type"=>"image")
/// );
/// $dgrid->SetModes($modes);
## *** allow scrolling on datagrid
/// $scrolling_option = false;
/// $dgrid->AllowScrollingSettings($scrolling_option);
## *** set scrolling settings (optional)
/// $scrolling_width = "90%";
/// $scrolling_height = "100%";
/// $dgrid->SetScrollingSettings($scrolling_width, $scrolling_height);
## *** allow multirow operations
$multirow_option = true;
$dgrid->AllowMultirowOperations($multirow_option);
$multirow_operations = array(
"delete" => array("view"=>true),
"details" => array("view"=>true),
);
$dgrid->SetMultirowOperations($multirow_operations);
## *** set CSS class for datagrid
## *** "default" or "blue" or "gray" or "green" or "pink" or your own css file
/// $css_class = "default";
/// $dgrid->SetCssClass($css_class);
## *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
/// $http_get_vars = array("act", "id");
/// $dgrid->SetHttpGetVars($http_get_vars);
## *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
## *** format (in which mode to allow processing of another datagrids)
## *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
/// $anotherDatagrids = array("abcd_"=>array("view"=>true, "edit"=>true, "details"=>true));
/// $dgrid->SetAnotherDatagrids($anotherDatagrids);
## *** 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 = true;
/// $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("5"=>"5", "10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
$default_page_size = 10;
$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
/// $fill_from_array = array("0"=>"No", "1"=>"Yes"); /* as "value"=>"option" */
$filtering_fields = array(
"Country"=>array("type"=>"textbox", "autocomplete"=>"true", "handler"=>"autosuggest_countries.php", "maxresults"=>"12", "shownoresults"=>"true", "table"=>"demo_countries", "field"=>"name", "show_operator"=>"false", "default_operator"=>"like%", "case_sensitive"=>"false", "comparison_type"=>"string|numeric|binary", "width"=>"", "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
## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
## *** "barchart" : number format in SELECT SQL must be equal with number format in max_value
/// $fill_from_array = array("0"=>"Banned", "1"=>"Active", "2"=>"Closed", "3"=>"Removed"); /* as "value"=>"option" */
$vm_colimns = array(
"name" =>array("header"=>"Name", "type"=>"label", "align"=>"left", "wrap"=>"wrap", "text_length"=>"20"),
"birth_date" =>array("header"=>"Birth Date", "type"=>"label", "align"=>"center", "wrap"=>"nowrap", "text_length"=>"-1"),
"status" =>array("header"=>"Status", "type"=>"label", "align"=>"center", "wrap"=>"nowrap", "text_length"=>"30"),
"country_name" =>array("header"=>"Country", "type"=>"label", "align"=>"center", "wrap"=>"nowrap", "text_length"=>"30")
);
$dgrid->SetColumnsInViewMode($vm_colimns);
## *** set auto-generated columns in view mode
// $auto_column_in_view_mode = false;
// $dgrid->SetAutoColumnsInViewMode($auto_column_in_view_mode);
## +---------------------------------------------------------------------------+
## | 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),
);
$dgrid->SetColumnsInEditMode($em_columns);
## *** set auto-generated columns in edit mode
// $auto_column_in_edit_mode = false;
// $dgrid->SetAutoColumnsInEditMode($auto_column_in_edit_mode);
## *** 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|vertical", "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();
################################################################################
?>