<?php
################################################################################
## +---------------------------------------------------------------------------+
## | 1. Creating & Calling: |
## +---------------------------------------------------------------------------+
## *** define a relative (virtual) path to datagrid.class.php file
## *** (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="user";
$DB_PASS="password";
$DB_HOST="host";
$DB_NAME="database";
ob_start();
## *** write down the primary key in the first place (MUST BE AUTO-INCREMENT NUMERIC!)
$sql = "SELECT
id,
model_name,
description,
image_thumb,
image,
price_from,
price_to,
submodels,
model_name as details_link
FROM demo_cars ";
## *** 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 = "cr_"; /* 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("model_name"=>"ASC");
$dgrid->DataSource("PDO", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);
## +---------------------------------------------------------------------------+
## | 2. General Settings: |
## +---------------------------------------------------------------------------+
## +-- Layouts, Templates & CSS -----------------------------------------------+
## *** set layouts: "0" - tabular(horizontal) - default, "1" - columnar(vertical), "2" - customized
## *** use "view"=>"0" and "edit"=>"0" only if you work on the same tables
$layouts = array("view"=>"2", "edit"=>"1", "details"=>"1", "filter"=>"1");
$dgrid->SetLayouts($layouts);
/// *** $mode_template = array("header"=>"", "body"=>"", "footer"=>"");
$view_template = array("header"=>"", "body"=>"", "footer"=>"");
$view_template["header"] = "
<table style="margin-bottom:3px; BORDER-COLLAPSE: collapse; BORDER: #d0d0d0 1px solid; FONT: normal 12px Tahoma;" align="center" width="80%" border="0" cellspacing="2" cellpadding="3" bgcolor="#f3f3f3">
<tr>
<td colspan="4" height="10" nowrap="nowrap" align="left">[ADD]</td>
<td colspan="4" height="10" nowrap="nowrap" align="left">Sort By: @model_name@ | @price_from@</td>
</tr>
</table>";
$view_template["body"] = "
<table style="margin-bottom:3px; BORDER-COLLAPSE:collapse; BORDER:#d0d0d0 1px solid; FONT:normal 12px Tahoma;" align="center" width="80%" border="0" cellspacing="2" cellpadding="3" bgcolor="#f3f3f3">
<tr><td colspan="4" height="10" nowrap="nowrap" align="left"></td></tr>
<tr>
<td width="105px" valign="top" align="center">
<a href="uploads/{image}" rel="lyteshow[cars]" title="">{image_thumb}</a><br />
[MULTIROW_CHECKBOX] [EDIT]
</td>
<td width="5px" nowrap="nowrap"></td>
<td valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="235" height="20" valign="top" style="font-size:12px"><strong>{details_link}</strong></td>
<td width="140" valign="top"><span style="color:#960000;">{price_from} - {price_to}</span></td>
<td width="185" valign="top"><a class="x-gray_dg_a" href='javascript:alert("Blocked in Demo version!");'>EuroAutomobile</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="550">{description}</td>
</tr>
<tr><td height="3" nowrap="nowrap"></td></tr>
<tr>
<td height="20">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="68" valign="top" style="color:#666666">Submodel(s): </td>
<td valign="top" style="color:#008a8a"> {submodels}</td>
</tr>
</table>
</td>
</tr>
<tr><td height="20" style="font-style:italic">Updated: 20-Aug-2009</td></tr>
</table>
</td>
<td valign="top" width="150px" align="center">
N/A <br/>
<a class="x-gray_dg_a" href=\"javascript:alert("Blocked in Demo version!");\">Rate it!</a><br/>
<a class="x-gray_dg_a" href=\"javascript:alert("Blocked in Demo version!");\">EXPERT REVIEW</a>
</td>
</tr>
</table>";
$dgrid->SetTemplates($view_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"=>false, "type"=>"image")
);
$dgrid->SetModes($modes);
## *** set CSS class for datagrid
## *** "default", "blue", "x-blue", "gray", "green" or "pink" or "empty" your own css file
$css_class = "x-gray";
$dgrid->SetCssClass($css_class);
## *** set DataGrid caption
$dg_caption = "New Cars";
$dgrid->SetCaption($dg_caption);
## +-- Multirow Operations ----------------------------------------------------+
## *** allow multirow operations
$multirow_option = true;
$dgrid->AllowMultirowOperations($multirow_option);
$multirow_operations = array(
"edit" => array("view"=>true),
"details" => array("view"=>true),
"delete" => array("view"=>true)
);
$dgrid->SetMultirowOperations($multirow_operations);
## +---------------------------------------------------------------------------+
## | 4. Sorting & Paging Settings: |
## +---------------------------------------------------------------------------+
## *** set paging option: true(default) or false
$paging_option = true;
$rows_numeration = false;
$numeration_sign = "N #";
$dropdown_paging = false;
$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", " "=>true, "page_size_align"=>"right");
$top_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
$pages_array = array("2"=>"2", "5"=>"5", "10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
$default_page_size = 5;
$paging_arrows = array("first"=>"|<<", "previous"=>"<<", "next"=>">>", "last"=>">>|");
$dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);
## +---------------------------------------------------------------------------+
## | 6. View Mode Settings: |
## +---------------------------------------------------------------------------+
## *** set view mode table properties
$vm_table_properties = array("width"=>"80%");
$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
$fill_from_array = array("0"=>"Banned", "1"=>"Active", "2"=>"Closed", "3"=>"Removed"); /* as "value"=>"option" */
$vm_colimns = array(
"details_link"=>array("header"=>"Details view", "type"=>"linktoview", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
"image_thumb" =>array("header"=>"Thumbnail", "type"=>"image", "align"=>"center", "width"=>"120px", "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "default"=>"default_image.ext", "image_width"=>"100px", "image_height"=>"75px", "linkto"=>"", "magnify"=>"false", "magnify_type"=>"lightbox", "magnify_power"=>"2"),
"image" =>array("header"=>"Image", "type"=>"data"),
"submodels" =>array("header"=>"Submodels", "type"=>"data"),
"model_name" =>array("header"=>"Model", "type"=>"label", "align"=>"left", "width"=>"", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
"description" =>array("header"=>"Desciption", "type"=>"label", "align"=>"left", "width"=>"", "wrap"=>"wrap|nowrap", "text_length"=>"255", "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
"price_from" =>array("header"=>"Price From", "type"=>"money", "align"=>"right", "width"=>"", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "sign"=>"$", "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>".", "thousands_separator"=>","),
"price_to" =>array("header"=>"Price to", "type"=>"money", "align"=>"right", "width"=>"", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "sign"=>"$", "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>".", "thousands_separator"=>","),
);
$dgrid->SetColumnsInViewMode($vm_colimns);
## +---------------------------------------------------------------------------+
## | 7. Add/Edit/Details Mode Settings: |
## +---------------------------------------------------------------------------+
## *** set settings for add/edit/details modes
$table_name = "demo_cars";
$primary_key = "id";
$condition = "";
$dgrid->SetTableEdit($table_name, $primary_key, $condition);
## *** set columns in edit mode
$em_columns = array(
"model_name" =>array("header"=>"Model Name", "type"=>"textbox", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
"description" =>array("header"=>"Desciption", "type"=>"textarea", "req_type"=>"ry", "width"=>"430px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "edit_type"=>"simple", "resizable"=>"true", "rows"=>"3", "cols"=>"50"),
"submodels" =>array("header"=>"Submodels", "type"=>"textbox", "req_type"=>"sy", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
"image_thumb" =>array("header"=>"Thumbnail", "type"=>"image", "req_type"=>"st", "width"=>"220px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"100KB", "image_width"=>"100px", "image_height"=>"75px", "resize_image"=>"true", "resize_width"=>"100px", "resize_height"=>"75px", "magnify"=>"false", "magnify_type"=>"popup|magnifier|lightbox", "magnify_power"=>"2", "file_name"=>"car_thumb_".((isset($_GET[$unique_prefix."mode"]) && ($_GET[$unique_prefix."mode"] == "add")) ? $dgrid->GetRandomString("10") : $dgrid->GetRandomString("10")), "host"=>"local|remote"),
"image" =>array("header"=>"Image", "type"=>"image", "req_type"=>"st", "width"=>"220px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"300KB", "image_width"=>"100px", "image_height"=>"75px", "resize_image"=>"false", "resize_width"=>"100px", "resize_height"=>"75px", "magnify"=>"false", "magnify_type"=>"popup|magnifier|lightbox", "magnify_power"=>"2", "file_name"=>"car_".((isset($_GET[$unique_prefix."mode"]) && ($_GET[$unique_prefix."mode"] == "add")) ? $dgrid->GetRandomString("10") : $dgrid->GetRandomString("10")), "host"=>"local|remote"),
"price_from" =>array("header"=>"Price From", "type"=>"money", "req_type"=>"rf", "width"=>"80px", "title"=>"", "readonly"=>"false", "maxlength"=>"9", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "sign"=>"$", "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>".", "thousands_separator"=>","),
"price_to" =>array("header"=>"Price To", "type"=>"money", "req_type"=>"rf", "width"=>"80px", "title"=>"", "readonly"=>"false", "maxlength"=>"9", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "sign"=>"$", "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>".", "thousands_separator"=>","),
);
$dgrid->SetColumnsInEditMode($em_columns);
## +---------------------------------------------------------------------------+
## | 8. Bind the DataGrid: |
## +---------------------------------------------------------------------------+
## *** bind the DataGrid and draw it on the screen
$dgrid->Bind();
ob_end_flush();
################################################################################
?>