PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/WebsiteFiles/admin/bin/datagrid.class.php

https://github.com/mcherryleigh/seniordesign
PHP | 6309 lines | 5048 code | 314 blank | 947 comment | 1466 complexity | 52112b57467e489dc23be88a2b20fdd6 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. ################################################################################
  3. ## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- #
  4. ## --------------------------------------------------------------------------- #
  5. ## PHP DataGrid version 4.2.8 (01.10.2008) #
  6. ## Author & developer: Leumas Naypoka <leumas.a@gmail.com> #
  7. ## Developers: Zewa <http://www.softic.at> #
  8. ## Fcallez <http://www.innovavirtual.org> #
  9. ## Lisence: GNU GPL #
  10. ## Site: http://phpbuilder.blogspot.com #
  11. ## Copyright: Leumas Naypoka (c) 2006-2008. All rights reserved. #
  12. ## #
  13. ## Additional modules (embedded): #
  14. ## -- openWYSIWYG 1.01 (free cross-browser) http://openWebWare.com #
  15. ## -- PEAR::DB 1.7.11 (PHP Ext. & Application Repository) http://pear.php.net #
  16. ## -- JS AFV 1.0.3 (JS Auto From Validator) http://phpbuilder.blogspot.com #
  17. ## -- overLIB 4.21 (JS library) http://www.bosrup.com/web/overlib/ #
  18. ## -- FPDF v.1.53 (PDF files generator) http://www.fpdf.org #
  19. ## -- JsCalendar v.1.0 (DHTML/JavaScript Calendar) http://www.dynarch.com #
  20. ## -- AutoSuggest v.2.1.3 (AJAX autocomplete) http://www.brandspankingnew.net #
  21. ## #
  22. ################################################################################
  23. ## +---------------------------------------------------------------------------+
  24. ## | 1. Creating & Calling: |
  25. ## +---------------------------------------------------------------------------+
  26. ## *** define a relative (virtual) path to datagrid.class.php file and "pear"
  27. ## *** directory (relatively to the current file)
  28. ## *** RELATIVE PATH ONLY ***
  29. //
  30. // define ("DATAGRID_DIR", ""); /* Ex.: "datagrid/" */
  31. // define ("PEAR_DIR", "pear/"); /* Ex.: "datagrid/pear/" */
  32. //
  33. // require_once(DATAGRID_DIR.'datagrid.class.php');
  34. // require_once(PEAR_DIR.'PEAR.php');
  35. // require_once(PEAR_DIR.'DB.php');
  36. ##
  37. ## *** creating variables that we need for database connection
  38. // $DB_USER='name'; /* usually like this: prefix_name */
  39. // $DB_PASS=''; /* must be already enscrypted (recommended) */
  40. // $DB_HOST='localhost'; /* usually localhost */
  41. // $DB_NAME='dbName'; /* usually like this: prefix_dbName */
  42. //
  43. // ob_start();
  44. ## *** (example of ODBC connection string)
  45. ## *** $result_conn = $db_conn->connect(DB::parseDSN('odbc://root:12345@test_db'));
  46. ## *** (example of Oracle connection string)
  47. ## *** $result_conn = $db_conn->connect(DB::parseDSN('oci8://root:12345@localhost:1521/mydatabase));
  48. ## *** (example of PostgreSQL connection string)
  49. ## *** $result_conn = $db_conn->connect(DB::parseDSN('pgsql://root:12345@localhost/mydatabase));
  50. ## === (Examples of connections to other db types see in "docs/pear/" folder)
  51. // $db_conn = DB::factory('mysql'); /* don't forget to change on appropriate db type */
  52. // $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
  53. // if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }
  54. ## *** put a primary key on the first place
  55. // $sql = "SELECT primary_key, field_1, field_2 ... FROM tableName ;";
  56. ## *** set needed options and create a new class instance
  57. // $debug_mode = false; /* display SQL statements while processing */
  58. // $messaging = true; /* display system messages on a screen */
  59. // $unique_prefix = "abc_"; /* prevent overlays - must be started with a letter */
  60. // $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
  61. ## *** set encoding and collation (default: utf8/utf8_unicode_ci)
  62. /// $dg_encoding = "utf8";
  63. /// $dg_collation = "utf8_unicode_ci";
  64. /// $dgrid->SetEncoding($dg_encoding, $dg_collation);
  65. ## *** set data source with needed options
  66. // $default_order_field = "field_name_1 [, field_name_2...]";
  67. // $default_order_type = "ASC|DESC [, ASC|DESC...]";
  68. // $dgrid->DataSource($db_conn, $sql, $default_order_field, $default_order_type);
  69. ##
  70. ##
  71. ## +---------------------------------------------------------------------------+
  72. ## | 2. General Settings: |
  73. ## +---------------------------------------------------------------------------+
  74. ## *** set interface language (default - English)
  75. ## *** (en) - English (de) - German (se) - Swedish (hr) - Bosnian/Croatian
  76. ## *** (hu) - Hungarian (es) - Espanol (ca) - Catala (fr) - Francais
  77. ## *** (nl) - Netherlands/"Vlaams"(Flemish) (it) - Italiano (pl) - Polish
  78. ## *** (ch) - Chinese (sr) - Serbian (bg) - Bulgarian (pb) - Brazilian Portuguese
  79. ## *** (ar) - Arabic (tr) - Turkish (cz) - Czech (ro/ro_utf8) - Romanian
  80. ## *** (gk) - Greek (he) - Hebrew (ru_utf8) - Russian
  81. /// $dg_language = "en";
  82. /// $dgrid->SetInterfaceLang($dg_language);
  83. ## *** set direction: "ltr" or "rtr" (default - "ltr")
  84. /// $direction = "ltr";
  85. /// $dgrid->SetDirection($direction);
  86. ## *** set layouts: "0" - tabular(horizontal) - default, "1" - columnar(vertical), "2" - customized
  87. /// $layouts = array("view"=>"0", "edit"=>"1", "details"=>"1", "filter"=>"1");
  88. /// $dgrid->SetLayouts($layouts);
  89. /// $details_template = "<table><tr><td>{field_name_1}</td><td>{field_name_2}</td></tr>...</table>";
  90. /// $dgrid->SetTemplates("","",$details_template);
  91. ## *** set modes for operations ("type" => "link|button|image")
  92. ## *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
  93. /// $modes = array(
  94. /// "add" =>array("view"=>true, "edit"=>false, "type"=>"link", "show_add_button"=>"inside|outside"),
  95. /// "edit" =>array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>""),
  96. /// "cancel" =>array("view"=>true, "edit"=>true, "type"=>"link"),
  97. /// "details" =>array("view"=>true, "edit"=>false, "type"=>"link"),
  98. /// "delete" =>array("view"=>true, "edit"=>true, "type"=>"image")
  99. /// );
  100. /// $dgrid->SetModes($modes);
  101. ## *** allow scrolling on datagrid
  102. /// $scrolling_option = false;
  103. /// $dgrid->AllowScrollingSettings($scrolling_option);
  104. ## *** set scrolling settings (optional)
  105. /// $scrolling_width = "90%";
  106. /// $scrolling_height = "100%";
  107. /// $dgrid->setScrollingSettings($scrolling_width, $scrolling_height);
  108. ## *** allow multirow operations
  109. // $multirow_option = true;
  110. // $dgrid->AllowMultirowOperations($multirow_option);
  111. /// $multirow_operations = array(
  112. /// "delete" => array("view"=>true),
  113. /// "details" => array("view"=>true),
  114. /// "my_operation_name" => array("view"=>true, "flag_name"=>"my_flag_name", "flag_value"=>"my_flag_value", "tooltip"=>"Do something with selected", "image"=>"image.gif")
  115. /// );
  116. /// $dgrid->SetMultirowOperations($multirow_operations);
  117. ## *** set CSS class for datagrid
  118. ## *** "default" or "blue" or "gray" or "green" or "pink" or your own css file
  119. /// $css_class = "default";
  120. /// $dgrid->SetCssClass($css_class);
  121. ## *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
  122. /// $http_get_vars = array("act", "id");
  123. /// $dgrid->SetHttpGetVars($http_get_vars);
  124. ## *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
  125. ## *** format (in which mode to allow processing of another datagrids)
  126. ## *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
  127. /// $anotherDatagrids = array("abcd_"=>array("view"=>true, "edit"=>true, "details"=>true));
  128. /// $dgrid->SetAnotherDatagrids($anotherDatagrids);
  129. ## *** set DataGrid caption
  130. /// $dg_caption = "My Favorite Lovely PHP DataGrid";
  131. /// $dgrid->SetCaption($dg_caption);
  132. ##
  133. ##
  134. ## +---------------------------------------------------------------------------+
  135. ## | 3. Printing & Exporting Settings: |
  136. ## +---------------------------------------------------------------------------+
  137. ## *** set printing option: true(default) or false
  138. /// $printing_option = true;
  139. /// $dgrid->AllowPrinting($printing_option);
  140. ## *** set exporting option: true(default) or false and relative (virtual) path
  141. ## *** to export directory (relatively to datagrid.class.php file).
  142. ## *** Ex.: "" - if we use current datagrid folder
  143. /// $exporting_option = true;
  144. /// $exporting_directory = "";
  145. /// $dgrid->AllowExporting($exporting_option, $exporting_directory);
  146. /// $exporting_types = array("excel"=>"true", "pdf"=>"true", "xml"=>"true");
  147. /// $dgrid->AllowExportingTypes($exporting_types);
  148. ##
  149. ##
  150. ## +---------------------------------------------------------------------------+
  151. ## | 4. Sorting & Paging Settings: |
  152. ## +---------------------------------------------------------------------------+
  153. ## *** set sorting option: true(default) or false
  154. /// $sorting_option = true;
  155. /// $dgrid->AllowSorting($sorting_option);
  156. ## *** set paging option: true(default) or false
  157. /// $paging_option = true;
  158. /// $rows_numeration = false;
  159. /// $numeration_sign = "N #";
  160. /// $dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign);
  161. ## *** set paging settings
  162. /// $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  163. /// $top_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  164. // $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  165. /// $default_page_size = 10;
  166. /// $paging_arrows = array("first"=>"|&lt;&lt;", "previous"=>"&lt;&lt;", "next"=>"&gt;&gt;", "last"=>"&gt;&gt;|");
  167. /// $dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);
  168. ##
  169. ##
  170. ## +---------------------------------------------------------------------------+
  171. ## | 5. Filter Settings: |
  172. ## +---------------------------------------------------------------------------+
  173. ## *** set filtering option: true or false(default)
  174. /// $filtering_option = true;
  175. /// $show_search_type = true;
  176. /// $dgrid->AllowFiltering($filtering_option, $show_search_type);
  177. ## *** set aditional filtering settings
  178. ## *** tips: use "," (comma) if you want to make search by some words, for ex.: hello, bye, hi
  179. /// $fill_from_array = array("0"=>"No", "1"=>"Yes"); /* as "value"=>"option" */
  180. /// $filtering_fields = array(
  181. /// "Caption_1"=>array("type"=>"textbox", "table"=>"tableName_1", "field"=>"fieldName_1|,fieldName_2", "show_operator"=>"false", "default_operator"=>"=|<|>|like|%like|like%|%like%|not like", "case_sensitive"=>"false", "comparison_type"=>"string|numeric|binary", "width"=>"", "on_js_event"=>""),
  182. /// "Caption_2"=>array("type"=>"textbox", "autocomplete"=>"false", "handler"=>"modules/autosuggest/test.php", "maxresults"=>"12", "shownoresults"=>"false", "table"=>"tableName_1", "field"=>"fieldName_1|,fieldName_2", "show_operator"=>"false", "default_operator"=>"=|<|>|like|%like|like%|%like%|not like", "case_sensitive"=>"false", "comparison_type"=>"string|numeric|binary", "width"=>"", "on_js_event"=>""),
  183. /// "Caption_3"=>array("type"=>"dropdownlist", "order"=>"ASC|DESC", "table"=>"tableName_2", "field"=>"fieldName_2", "source"=>"self"|$fill_from_array, "show"=>"", "condition"=>"", "show_operator"=>"false", "default_operator"=>"=|<|>|like|%like|like%|%like%|not like", "case_sensitive"=>"false", "comparison_type"=>"string|numeric|binary", "width"=>"", "on_js_event"=>""),
  184. /// "Caption_4"=>array("type"=>"calendar", "table"=>"tableName_3", "field"=>"fieldName_3", "show_operator"=>"false", "default_operator"=>"=|<|>|like|%like|like%|%like%|not like", "case_sensitive"=>"false", "comparison_type"=>"string|numeric|binary", "width"=>"", "on_js_event"=>""),
  185. /// );
  186. /// $dgrid->SetFieldsFiltering($filtering_fields);
  187. ##
  188. ##
  189. ## +---------------------------------------------------------------------------+
  190. ## | 6. View Mode Settings: |
  191. ## +---------------------------------------------------------------------------+
  192. ## *** set view mode table properties
  193. /// $vm_table_properties = array("width"=>"90%");
  194. /// $dgrid->SetViewModeTableProperties($vm_table_properties);
  195. ## *** set columns in view mode
  196. ## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  197. ## *** "barchart" : number format in SELECT SQL must be equal with number format in max_value
  198. /// $fill_from_array = array("0"=>"Banned", "1"=>"Active", "2"=>"Closed", "3"=>"Removed"); /* as "value"=>"option" */
  199. /// $vm_colimns = array(
  200. /// "FieldName_1"=>array("header"=>"Name_A", "type"=>"label", "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"=>""),
  201. /// "FieldName_2"=>array("header"=>"Name_B", "type"=>"image", "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"=>"", "target_path"=>"uploads/", "default"=>"default_image.ext", "image_width"=>"50px", "image_height"=>"30px", "magnify"=>"false"),
  202. /// "FieldName_3"=>array("header"=>"Name_C", "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"=>""),
  203. /// "FieldName_4"=>array("header"=>"Name_D", "type"=>"linktoedit", "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"=>""),
  204. /// "FieldName_5"=>array("header"=>"Name_E", "type"=>"linktodelete", "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"=>""),
  205. /// "FieldName_6"=>array("header"=>"Name_F", "type"=>"link", "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"=>"", "field_key"=>"field_name_0"|"field_key_1"=>"field_name_1"|..., "field_data"=>"field_name_2", "rel"=>"", "title"=>"", "target"=>"_new", "href"=>"{0}"),
  206. /// "FieldName_7"=>array("header"=>"Name_G", "type"=>"link", "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"=>"", "field_key"=>"field_name_0"|"field_key_1"=>"field_name_1"|..., "field_data"=>"field_name_2", "rel"=>"", "title"=>"", "target"=>"_new", "href"=>"mailto:{0}"),
  207. /// "FieldName_8"=>array("header"=>"Name_H", "type"=>"link", "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"=>"", "field_key"=>"field_name_0"|"field_key_1"=>"field_name_1"|..., "field_data"=>"field_name_2", "rel"=>"", "title"=>"", "target"=>"_new", "href"=>"http://mydomain.com?act={0}&act={1}&code=ABC"),
  208. /// "FieldName_9"=>array("header"=>"Name_I", "type"=>"money", "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"=>"", "sign"=>"$", "decimal_places"=>"2", "dec_separator"=>".", "thousands_separator"=>","),
  209. /// "FieldName_10"=>array("header"=>"Name_J", "type"=>"password", "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"=>""),
  210. /// "FieldName_11"=>array("header"=>"Name_K", "type"=>"barchart", "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"=>"", "field"=>"field_name", "maximum_value"=>"value"),
  211. /// "FieldName_12"=>array("header"=>"Name_L", "type"=>"enum", "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"=>"", "source"=>$fill_from_array),
  212. /// );
  213. /// $dgrid->SetColumnsInViewMode($vm_colimns);
  214. ## *** set auto-genereted columns in view mode
  215. // $auto_column_in_view_mode = false;
  216. // $dgrid->SetAutoColumnsInViewMode($auto_column_in_view_mode);
  217. ##
  218. ##
  219. ## +---------------------------------------------------------------------------+
  220. ## | 7. Add/Edit/Details Mode Settings: |
  221. ## +---------------------------------------------------------------------------+
  222. ## *** set add/edit mode table properties
  223. /// $em_table_properties = array("width"=>"70%");
  224. /// $dgrid->SetEditModeTableProperties($em_table_properties);
  225. ## *** set details mode table properties
  226. /// $dm_table_properties = array("width"=>"70%");
  227. /// $dgrid->SetDetailsModeTableProperties($dm_table_properties);
  228. ## *** set settings for add/edit/details modes
  229. // $table_name = "table_name";
  230. // $primary_key = "primary_key";
  231. // $condition = "table_name.field = ".$_REQUEST['abc_rid'];
  232. // $dgrid->SetTableEdit($table_name, $primary_key, $condition);
  233. ## *** set columns in edit mode
  234. ## *** first letter: r - required, s - simple (not required)
  235. ## *** second letter: t - text(including datetime), n - numeric, a - alphanumeric,
  236. ## e - email, f - float, y - any, l - login name, z - zipcode,
  237. ## p - password, i - integer, v - verified, c - checkbox, u - URL
  238. ## *** third letter (optional):
  239. ## for numbers: s - signed, u - unsigned, p - positive, n - negative
  240. ## for strings: u - upper, l - lower, n - normal, y - any
  241. ## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  242. ## *** Ex.: type = textbox|textarea|label|date(yyyy-mm-dd)|datedmy(dd-mm-yyyy)|datetime(yyyy-mm-dd hh:mm:ss)|datetimedmy(dd-mm-yyyy hh:mm:ss)|time(hh:mm:ss)|image|password|enum|print|checkbox
  243. ## *** make sure your WYSIWYG dir has 777 permissions
  244. /// $fill_from_array = array("0"=>"No", "1"=>"Yes", "2"=>"Don't know", "3"=>"My be"); /* as "value"=>"option" */
  245. /// $em_columns = array(
  246. /// "FieldName_1" =>array("header"=>"Name_A", "type"=>"textbox", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  247. /// "FieldName_2" =>array("header"=>"Name_B", "type"=>"textarea", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "edit_type"=>"simple|wysiwyg", "resizable"=>"false", "rows"=>"7", "cols"=>"50"),
  248. /// "FieldName_3" =>array("header"=>"Name_C", "type"=>"label", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  249. /// "FieldName_4" =>array("header"=>"Name_D", "type"=>"date", "req_type"=>"rt", "width"=>"187px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"popup|floating"),
  250. /// "FieldName_5" =>array("header"=>"Name_E", "type"=>"datetime", "req_type"=>"st", "width"=>"187px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"popup|floating"),
  251. /// "FieldName_6" =>array("header"=>"Name_F", "type"=>"time", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  252. /// "FieldName_7" =>array("header"=>"Name_G", "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"=>"100000|100K|10M|1G", "image_width"=>"120px", "image_height"=>"90px", "magnify"=>"false", "file_name"=>"", "host"=>"local|remote"),
  253. /// "FieldName_8" =>array("header"=>"Name_H", "type"=>"password", "req_type"=>"rp", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  254. /// "FieldName_9" =>array("header"=>"Name_I", "type"=>"enum", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>"self"|$fill_from_array, "view_type"=>"dropdownlist(default)|radiobutton", "radiobuttons_alignment"=>"horizontal|vertical", "multiple"=>"false", "multiple_size"=>"4"),
  255. /// "FieldName_10" =>array("header"=>"Name_J", "type"=>"print", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  256. /// "FieldName_11" =>array("header"=>"Name_K", "type"=>"checkbox", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "true_value"=>1, "false_value"=>0),
  257. /// "FieldName_12" =>array("header"=>"Name_L", "type"=>"file", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"100000|100K|10M|1G", "file_name"=>"File_Name", "host"=>"local|remote"),
  258. /// "FieldName_13" =>array("header"=>"Name_M", "type"=>"link", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "field_key"=>"field_name_0"|"field_key_1"=>"field_name_1"|..., "field_data"=>"field_name_2", "target"=>"_new", "href"=>"http://mydomain.com?act={0}&act={1}&code=ABC"),
  259. /// "FieldName_14" =>array("header"=>"Name_N", "type"=>"foreign_key","req_type"=>"ri", "width"=>"210px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
  260. /// "FieldName_15" =>array("header"=>"", "type"=>"hidden", "req_type"=>"st", "default"=>"default_value", "visible"=>"true", "unique"=>"false"),
  261. /// "validator" =>array("header"=>"Name_O", "type"=>"validator", "req_type"=>"rv", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "visible"=>"true", "on_js_event"=>"", "for_field"=>"", "validation_type"=>"password|email"),
  262. /// "delimiter" =>array("inner_html"=>"<br>"),
  263. /// );
  264. /// $dgrid->SetColumnsInEditMode($em_columns);
  265. ## *** set auto-genereted columns in edit mode
  266. // $auto_column_in_edit_mode = false;
  267. // $dgrid->SetAutoColumnsInEditMode($auto_column_in_edit_mode);
  268. ## *** set foreign keys for add/edit/details modes (if there are linked tables)
  269. ## *** Ex.: "field_name"=>"CONCAT(field1,','field2) as field3"
  270. ## *** Ex.: "condition"=>"TableName_1.FieldName > 'a' AND TableName_1.FieldName < 'c'"
  271. ## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  272. /// $foreign_keys = array(
  273. /// "ForeignKey_1"=>array("table"=>"TableName_1", "field_key"=>"FieldKey_1", "field_name"=>"FieldName_1", "view_type"=>"dropdownlist(default)|radiobutton|textbox", "radiobuttons_alignment"=>"horizontal|vertical", "condition"=>"", "order_by_field"=>"", "order_type"=>"ASC|DESC", "on_js_event"=>""),
  274. /// "ForeignKey_2"=>array("table"=>"TableName_2", "field_key"=>"FieldKey_2", "field_name"=>"FieldName_2", "view_type"=>"dropdownlist(default)|radiobutton|textbox", "radiobuttons_alignment"=>"horizontal|vertical", "condition"=>"", "order_by_field"=>"", "order_type"=>"ASC|DESC", "on_js_event"=>"")
  275. /// );
  276. /// $dgrid->SetForeignKeysEdit($foreign_keys);
  277. ##
  278. ##
  279. ## +---------------------------------------------------------------------------+
  280. ## | 8. Bind the DataGrid: |
  281. ## +---------------------------------------------------------------------------+
  282. ## *** bind the DataGrid and draw it on the screen
  283. // $dgrid->WriteCssClass(); /* call of this method between HTML <HEAD> elements */
  284. // $dgrid->Bind();
  285. // ob_end_flush();
  286. ##
  287. ################################################################################
  288. ////////////////////////////////////////////////////////////////////////////////
  289. //
  290. // Not documented:
  291. // -----------------------------------------------------------------------------
  292. // Property : first_field_focus_allowed = true|false;
  293. // --//-- : hide_grid_before_serach = true|false; /* put it before Bind() method */
  294. // --//-- : "pre_addition" => "" and "post_addition"=>"" attributes in view mode for labels and in add/edit/details modes for textboxes, checkboxes
  295. // --//-- : "autocomplete" => "on|off" attribute for textboxes in add/edit modes (default - "on")
  296. // --//-- : mode_after_update = ""|"edit";
  297. // --//-- : "on_item_created" => "function_name" attributes in view/add/edit/details modes for customized work with field value.
  298. // This function must be defined with 1 parameter, that will get fild's data.
  299. // Ex.: function function_name($field_value){ ... return $new_field_value;}
  300. // --//-- : NoDataFoundText = ""; displays a text on empty dataset
  301. //
  302. // Method : ExecuteSQL()
  303. // use it after DataSource() method only (after the using DataSource() need to be recalled)
  304. // $dSet = $dgrid->ExecuteSQL("SELECT * FROM tblPresidents WHERE tblPresidents.CountryID = ".$_GET['f_rid']."");
  305. // while($row = $dSet->fetchRow()){
  306. // for($c = 0; ($c < $dSet->numCols()); $c++){ echo $row[$c]." "; }
  307. // echo "<br>";
  308. // }
  309. // --//-- : SelectSqlItem()
  310. // $presidents = $dgrid->SelectSqlItem("SELECT COUNT(tblPresidents.presidentID) FROM tblPresidents WHERE tblPresidents.CountryID = ".$_GET['f_rid']."");
  311. // --//-- : AllowHighlighting(true|false);
  312. // --//-- : SetJsErrorsDisplayStyle("all"|"each");
  313. // --//-- : GetNextId();
  314. // --//-- : GetCurrentId();
  315. // --//-- : SetHeadersInColumnarLayout("Field Name", "Field Value");
  316. // --//-- : SetDgMessages("add", "update", "delete");
  317. //
  318. // Feature : onSubmitMyCheck
  319. // <script type='text/javascript'>
  320. // function unique_prefix_onSubmitMyCheck(){
  321. // return true;
  322. // }
  323. // </script>
  324. // --//-- : "on_js_event"=>"onchange='formAction(\"\", \"\", \"".$dgrid->uniquePrefix."\", \"".$dgrid->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\")'"
  325. // --//-- : Bind(true|false) - draw DataGrid on the screen on not
  326. //
  327. ////////////////////////////////////////////////////////////////////////////////
  328. ////////////////////////////////////////////////////////////////////////////////
  329. //
  330. // Tricks:
  331. // -----------------------------------------------------------------------------
  332. // 1. Set default value, that disappears on focus:
  333. // "default"=>"http://www.website.com", "on_js_event"=>"onBlur='if(this.value == \"\") this.value = \"http://www.website.com\"; this.style.color=\"#f68d6f\";' onClick='if(this.value==\"http://www.website.com\") this.value=\"\"; this.style.color=\"#000000\";'",
  334. //
  335. // 2. Set uniquie value for uploading image:
  336. // a) "file_name"=>"img_".((isset($_GET['prfx_mode']) && ($_GET['prfx_mode'] == "add")) ? $dgrid->GetNextId() : $dgrid->GetCurrentId())
  337. // b) "file_name"=>"img_".((isset($_GET['prfx_mode']) && ($_GET['prfx_mode'] == "add")) ? $dgrid->GetRandomString("10") : $dgrid->GetCurrentId())
  338. //
  339. // 3. Make auto-submition for filtering fileds:
  340. // "on_js_event"=>"onchange='document.getElementById(\"...prefix..._ff_onSUBMIT_FILTER\").click();'"
  341. //
  342. // 4. Make a field text colored according to condition (in SQL statement):
  343. // if (product='flooring', CONCAT('<SPAN style=\"background-color:yellow\">',product,'</SPAN>'),product) as ProductColored,
  344. //
  345. // 5. Change the field's data on fly (for "on_item_created" field's attribute):
  346. // function setColor($field_value){
  347. // if(strlen($field_value) > 5){
  348. // return "<font color='red'>".$field_value."</font>";
  349. // }else{
  350. // return "<font color='blue'>".$field_value."</font>";
  351. // }
  352. // }
  353. //
  354. // 6. Change the field's type on fly (for "on_item_created" field's attribute):
  355. // function setColor($field_value, $field_property_type){
  356. // if(strlen($field_value) > 5){
  357. // return "<font color='red'>".$field_value."</font>";
  358. // }else{
  359. // $field_property_type = "linktoview";
  360. // return "<font color='blue'>".$field_value."</font>";
  361. // }
  362. // }
  363. //
  364. // 8. Customized filtering: write filter field with empty table name and field: (..."table"=>"", "field"=>"xxx",...)
  365. // Then use $my_field = isset($_GET['prefix__ff__xxx']) ? $_GET['prefix__ff__xxx'] : "";
  366. // Use $my_field in SQL SELECT for your own filtering
  367. //
  368. ////////////////////////////////////////////////////////////////////////////////
  369. Class DataGrid
  370. {
  371. //==========================================================================
  372. // Data Members
  373. //==========================================================================
  374. // unique prefixes ---------------------------------------------------------
  375. public $uniquePrefix;
  376. public $unique_random_prefix;
  377. // directory ---------------------------------------------------------------
  378. public $directory;
  379. // language ----------------------------------------------------------------
  380. public $lang_name;
  381. public $lang;
  382. // caption -----------------------------------------------------------------
  383. public $caption;
  384. // rows and columns data members -------------------------------------------
  385. public $rows;
  386. public $row_lower;
  387. public $row_upper;
  388. public $columns;
  389. public $col_lower;
  390. public $col_upper;
  391. // http get vars -----------------------------------------------------------
  392. public $http;
  393. public $port;
  394. public $server_name;
  395. public $HTTP_URL;
  396. public $http_get_vars;
  397. public $another_datagrids;
  398. // data source -------------------------------------------------------------
  399. public $db_handler;
  400. public $sql;
  401. public $sql_view;
  402. public $sql_group_by;
  403. public $data_set;
  404. // signs -------------------------------------------------------------------
  405. public $amp;
  406. public $nbsp;
  407. // encoding & direction ----------------------------------------------------
  408. public $encoding;
  409. public $collation;
  410. public $direction;
  411. // layout style ------------------------------------------------------------
  412. public $layouts;
  413. public $layout_type;
  414. // templates ---------------------------------------------------------------
  415. public $templates;
  416. // paging variables --------------------------------------------------------
  417. public $pages_total;
  418. public $page_current;
  419. public $default_page_size;
  420. public $req_page_size;
  421. public $paging_allowed;
  422. public $rows_numeration;
  423. public $numeration_sign;
  424. public $lower_paging;
  425. public $upper_paging;
  426. public $pages_array;
  427. public $first_arrow;
  428. public $previous_arrow;
  429. public $next_arrow;
  430. public $last_arrow;
  431. public $limit_start;
  432. public $limit_size;
  433. public $rows_total;
  434. // sorting variables -------------------------------------------------------
  435. public $sort_field;
  436. public $sort_type;
  437. public $default_sort_field;
  438. public $default_sort_type;
  439. public $sorting_allowed;
  440. public $sql_sort;
  441. // filtering variables -----------------------------------------------------
  442. public $filtering_allowed;
  443. public $show_search_type;
  444. public $filter_fields;
  445. public $hide_display;
  446. // columns style parameters ------------------------------------------------
  447. public $wrap;
  448. // css style ---------------------------------------------------------------
  449. public $row_highlighting_allowed;
  450. public $css_class;
  451. public $rowColor;
  452. protected $is_css_class_written;
  453. // table style parameters --------------------------------------------------
  454. public $tblAlign;
  455. public $tblWidth;
  456. public $tblBorder;
  457. public $tblBorderColor;
  458. public $tblCellSpacing;
  459. public $tblCellPadding;
  460. // datagrid modes ----------------------------------------------------------
  461. public $modes;
  462. public $mode_after_update;
  463. public $mode;
  464. protected $rid;
  465. public $rids;
  466. public $tbl_name;
  467. public $primary_key;
  468. public $condition;
  469. public $foreign_keys_array;
  470. public $columns_view_mode;
  471. public $columns_edit_mode;
  472. public $sorted_columns;
  473. // printing & exporting ----------------------------------------------------
  474. public $printing_allowed;
  475. public $exporting_allowed;
  476. public $exporting_directory;
  477. protected $exporting_types;
  478. // debug mode --------------------------------------------------------------
  479. public $debug;
  480. public $start_time;
  481. public $end_time;
  482. // message -----------------------------------------------------------------
  483. public $act_msg;
  484. public $messaging;
  485. public $is_error;
  486. public $errors;
  487. public $is_warning;
  488. public $warnings;
  489. public $dg_messages;
  490. public $NoDataFoundText;
  491. // browser & system types --------------------------------------------------
  492. public $platform;
  493. public $browser_name;
  494. public $browser_version;
  495. // scrolling ---------------------------------------------------------------
  496. public $scrolling_option;
  497. public $scrolling_width;
  498. public $scrolling_height;
  499. // header names ------------------------------------------------------------
  500. public $field_header;
  501. public $field_value_header;
  502. // hide --------------------------------------------------------------------
  503. public $hide_grid_before_serach;
  504. // summarize ---------------------------------------------------------------
  505. public $summarize_columns;
  506. // multirow ----------------------------------------------------------------
  507. public $multirow_allowed;
  508. public $multi_rows;
  509. public $multirow_operations_array;
  510. // first field focus -------------------------------------------------------
  511. public $first_field_focus_allowed;
  512. // javascript errors display style -----------------------------------------
  513. public $js_validation_errors;
  514. //==========================================================================
  515. // PUBLIC MEMBER FUNCTIONS
  516. //==========================================================================
  517. //--------------------------------------------------------------------------
  518. // Default class constructor
  519. //--------------------------------------------------------------------------
  520. function __construct($debug_mode = false, $messaging = true, $unique_prefix = "", $datagrid_dir = "datagrid/"){
  521. $this->debug = (($debug_mode == true) || ($debug_mode == "true")) ? true : false ;
  522. // start calculating running time of a script
  523. $this->start_time = 0;
  524. $this->end_time = 0;
  525. if($this->debug){
  526. $this->start_time = $this->GetFormattedMicrotime();
  527. }
  528. // unique prefixes -----------------------------------------------------
  529. $this->SetUniquePrefix($unique_prefix);
  530. // directory -----------------------------------------------------------
  531. $this->directory = $datagrid_dir;
  532. // language ------------------------------------------------------------
  533. $this->lang_name = "en";
  534. $this->lang = array();
  535. $this->lang['total'] = "Total";
  536. $this->lang['wrong_parameter_error'] = "Wrong parameter in [<b>_FIELD_</b>]: _VALUE_";
  537. // caption -------------------------------------------------------------
  538. $this->caption = "";
  539. // rows and columns data members ---------------------------------------
  540. $this->http = $this->GetProtocol();
  541. $this->port = $this->GetPort();
  542. $this->server_name = $this->GetServerName();
  543. $this->HTTP_URL = str_replace("///", "//", $this->http.$this->server_name.$this->port.$_SERVER['PHP_SELF']);
  544. // http get vars -------------------------------------------------------
  545. $this->http_get_vars = "";
  546. $this->another_datagrids = "";
  547. // css style ----------------------------------------------------------
  548. $this->row_highlighting_allowed = true;
  549. $this->css_class = "default";
  550. $this->rowColor = array();
  551. $this->is_css_class_written = false;
  552. // signs ---------------------------------------------------------------
  553. $this->amp = "&amp;";
  554. $this->nbsp = ""; //&nbsp;
  555. $this->rows = 0;
  556. $this->row_lower = 0;
  557. $this->row_upper = 0;
  558. $this->columns = 0;
  559. $this->col_lower = 0;
  560. $this->col_upper = 0;
  561. // encoding & direction ------------------------------------------------
  562. $this->encoding = "utf8";
  563. $this->collation = "utf8_unicode_ci";
  564. $this->direction = "ltr";
  565. $this->layouts['view'] = "0";
  566. $this->layouts['edit'] = "1";
  567. $this->layouts['filter'] = "1";
  568. $this->layouts['show'] = "1";
  569. $this->layout_type = "view";
  570. // templates -----------------------------------------------------------
  571. $this->templates['view'] = "";
  572. $this->templates['edit'] = "";
  573. $this->templates['show'] = "";
  574. $this->pages_total = 0;
  575. $this->page_current = 0;
  576. $this->pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  577. $this->first_arrow = "|&lt;&lt;";
  578. $this->previous_arrow = "&lt;&lt;";
  579. $this->next_arrow = "&gt;&gt;";
  580. $this->last_arrow = "&gt;&gt;|";
  581. $this->default_page_size = 10;
  582. $this->req_page_size = 10;
  583. $this->paging_allowed = true;
  584. $this->rows_numeration = false;
  585. $this->numeration_sign = "N #";
  586. $this->lower_paging['results'] = false;
  587. $this->lower_paging['results_align'] = "left";
  588. $this->lower_paging['pages'] = false;
  589. $this->lower_paging['pages_align'] = "center";
  590. $this->lower_paging['page_size'] = false;
  591. $this->lower_paging['page_size_align'] = "right";
  592. $this->upper_paging['results'] = false;
  593. $this->upper_paging['results_align'] = "left";
  594. $this->upper_paging['pages'] = false;
  595. $this->upper_paging['pages_align'] = "center";
  596. $this->upper_paging['page_size'] = false;
  597. $this->upper_paging['page_size_align'] = "right";
  598. $this->limit_start = 0;
  599. $this->limit_size = $this->req_page_size;
  600. $this->rows_total = 0;
  601. $this->sort_field = "";
  602. $this->sort_field_by = "";
  603. $this->sort_field_type = "";
  604. $this->sort_type = "";
  605. $this->default_sort_field = array();
  606. $this->default_sort_type = array();
  607. $this->sorting_allowed = true;
  608. $this->sql_view = "";
  609. $this->sql_group_by = "";
  610. $this->sql = "";
  611. $this->sql_sort = "";
  612. $this->filtering_allowed = false;
  613. $this->show_search_type = true;
  614. $this->filter_fields = array();
  615. $this->hide_display = "";
  616. $this->tblAlign['view'] = "center"; $this->tblAlign['edit'] = "center"; $this->tblAlign['details'] = "center";
  617. $this->tblWidth['view'] = "90%"; $this->tblWidth['edit'] = "70%"; $this->tblWidth['details'] = "60%";
  618. $this->tblBorder['view'] = "1"; $this->tblBorder['edit'] = "1"; $this->tblBorder['details'] = "1";
  619. $this->tblBorderColor['view'] = "#000000"; $this->tblBorderColor['edit'] = "#000000"; $this->tblBorderColor['details'] = "#000000";
  620. $this->tblCellSpacing['view'] = "0"; $this->tblCellSpacing['edit'] = "0"; $this->tblCellSpacing['details'] = "0";
  621. $this->tblCellPadding['view'] = "0"; $this->tblCellPadding['edit'] = "0"; $this->tblCellPadding['details'] = "0";
  622. // datagrid modes ------------------------------------------------------
  623. $this->modes["add"] = array("view"=>true, "edit"=>false, "type"=>"link", "show_add_button"=>"inside");
  624. $this->modes["edit"] = array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>"");
  625. $this->modes["cancel"] = array("view"=>true, "edit"=>true, "type"=>"link");
  626. $this->modes["details"] = array("view"=>true, "edit"=>false, "type"=>"link");
  627. $this->modes["delete"] = array("view"=>true, "edit"=>true, "type"=>"image");
  628. $this->mode = "view";
  629. $this->mode_after_update = "";
  630. $this->rid = "";
  631. $this->rids = "";
  632. $this->tbl_name ="";
  633. $this->primary_key = 0;
  634. $this->condition = "";
  635. $this->foreign_keys_array = array();
  636. $this->columns_view_mode = array();
  637. $this->columns_edit_mode = array();
  638. $this->sorted_columns = array();
  639. $this->printing_allowed = true;
  640. $this->exporting_allowed = false;
  641. $this->exporting_directory = "";
  642. $this->exporting_types = array("excel"=>"true", "pdf"=>"true", "xml"=>"true");
  643. $this->wrap = "wrap";
  644. // scrolling -----------------------------------------------------------
  645. $this->scrolling_option = false;
  646. $this->scrolling_width = "90%";
  647. $this->scrolling_height = "100%";
  648. // header names --------------------------------------------------------
  649. $this->field_header = "";
  650. $this->field_value_header = "";
  651. // hide ----------------------------------------------------------------
  652. $this->hide_grid_before_serach = false;
  653. $this->summarize_columns = array();
  654. $this->multirow_allowed = false;
  655. $this->multi_rows = 0;
  656. $this->multirow_operations_array = array();
  657. $this->multirow_operations_array['delete'] = array("view"=>true);
  658. $this->multirow_operations_array['details'] = array("view"=>true);
  659. $this->first_field_focus_allowed = false;
  660. // message -------------------------------------------------------------
  661. $this->act_msg = "";
  662. if($this->debug) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
  663. $this->messaging = (($messaging == true) || ($messaging == "true")) ? true : false ;
  664. $this->is_error = false;
  665. $this->errors = array();
  666. $this->is_warning = false;
  667. $this->warnings = array();
  668. $this->dg_messages = array();
  669. $this->dg_messages['add'] = "";
  670. $this->dg_messages['update'] = "";
  671. $this->dg_messages['delete'] = "";
  672. // javascript errors display style -------------------------------------
  673. $this->js_validation_errors = "true";
  674. // set browser definitions
  675. $this->SetBrowserDefinitions();
  676. }
  677. //--------------------------------------------------------------------------
  678. // Class destructor
  679. //--------------------------------------------------------------------------
  680. function __destruct()
  681. {
  682. // echo 'this object has been destroyed';
  683. }
  684. //--------------------------------------------------------------------------
  685. // Set encoding
  686. //--------------------------------------------------------------------------
  687. function SetEncoding($dg_encoding = "", $dg_collation = ""){
  688. $this->encoding = ($dg_encoding != "") ? $dg_encoding : $this->encoding;
  689. $this->collation = ($dg_collation != "") ? $dg_collation : $this->collation;
  690. }
  691. //--------------------------------------------------------------------------
  692. // Set data source
  693. //--------------------------------------------------------------------------
  694. function DataSource($db_handl, $sql = "", $start_order = "", $start_order_type = ""){
  695. // clear sql statment
  696. $sql = str_replace("\n", " ", $sql); // new row
  697. $sql = str_replace("\t", " ", $sql); // tabulation
  698. $sql = str_replace(chr(13), " ", $sql); // CR sign
  699. $sql = str_replace(chr(10), " ", $sql); // LF sign
  700. $sql = str_replace(";", "", $sql);
  701. // get preliminary Primary Key
  702. $p_key = explode(" ", $sql);
  703. $p_key = str_replace(",", "", $p_key[1]);
  704. $p_key = explode(".", $p_key);
  705. $this->primary_key = $p_key[count($p_key)-1];
  706. $req_sort_field = $this->GetVariable('sort_field');
  707. $req_sort_field_by = $this->GetVariable('sort_field_by');
  708. $req_sort_field_type = $this->GetVariable('sort_field_type');
  709. $sort_field = ($req_sort_field_by != "") ? $req_sort_field_by : $req_sort_field ;
  710. $req_sort_type = $this->GetVariable('sort_type');
  711. $this->db_handler = $db_handl;
  712. $this->db_handler->setFetchMode(DB_FETCHMODE_ORDERED);
  713. $numeric_sort = false;
  714. // handle SELECT SQL statement
  715. $this->sql_view = $sql;
  716. if($this->LastSubStrOccurence($this->sql_view, "from ") < $this->LastSubStrOccurence($this->sql_view, "where ")){
  717. // handle SELECT statment with sub-SELECTs and SELECT without WHERE
  718. $ind = strpos(strtolower($this->sql_view), "group by");
  719. if($ind){
  720. $prefix = substr($sql, 0, $ind);
  721. $suffix = substr($sql, $ind);
  722. $this->sql_view = $prefix." ";
  723. $this->sql_group_by = $suffix;
  724. }else{
  725. $this->sql_view .= " WHERE 1=1 ";
  726. }
  727. }else if($this->LastSubStrOccurence($this->sql_view, "where ") == ""){
  728. $this->sql_view .= " WHERE 1=1 ";
  729. }else{
  730. $ind = strpos(strtolower($this->sql_view), "group by");
  731. if($ind){
  732. $prefix = substr($sql, 0, $ind);
  733. $suffix = substr($sql, $ind);
  734. $this->sql_view = $prefix." ";
  735. $this->sql_group_by = $suffix;
  736. }
  737. }
  738. $this->sql = $this->sql_view.$this->sql_group_by;
  739. // set default order
  740. if($start_order != ""){
  741. $default_sort_field = explode(",", $start_order);
  742. $default_sort_type = explode(",", $start_order_type);
  743. for($ind=0; $ind < count($default_sort_field); $ind++){
  744. $this->default_sort_field[$ind] = trim($default_sort_field[$ind]);
  745. if(isset($default_sort_type[$ind])){
  746. if((strtolower(trim($default_sort_type[$ind])) == "asc") || (strtolower(trim($default_sort_type[$ind])) == "desc")){
  747. $this->default_sort_type[$ind] = trim($default_sort_type[$ind]);

Large files files are truncated, but you can click here to view the full file