PageRenderTime 127ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 3ms

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

https://github.com/mcherryleigh/seniordesign
PHP | 5637 lines | 4481 code | 300 blank | 856 comment | 1325 complexity | 6b31140d9bbefb09dbb85ab8e66477e8 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.3 (12.01.2008) #
  6. ## Author & developer: Leumas Naypoka <leumas.a@gmail.com> #
  7. ## Developers: Zewa <http://www.thorax-music.com> #
  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. ## #
  21. ################################################################################
  22. ## +---------------------------------------------------------------------------+
  23. ## | 1. Creating & Calling: |
  24. ## +---------------------------------------------------------------------------+
  25. ## *** define a relative (virtual) path to datagrid.class.php file and "pear"
  26. ## *** directory (relatively to the current file)
  27. ## *** RELATIVE PATH ONLY ***
  28. //
  29. // define ("DATAGRID_DIR", ""); /* Ex.: "datagrid/" */
  30. // define ("PEAR_DIR", "pear/"); /* Ex.: "datagrid/pear/" */
  31. //
  32. // require_once(DATAGRID_DIR.'datagrid.class.php');
  33. // require_once(PEAR_DIR.'PEAR.php');
  34. // require_once(PEAR_DIR.'DB.php');
  35. ##
  36. ## *** creating variables that we need for database connection
  37. // $DB_USER='name'; /* usually like this: prefix_name */
  38. // $DB_PASS=''; /* must be already enscrypted (recommended) */
  39. // $DB_HOST='localhost'; /* usually localhost */
  40. // $DB_NAME='dbName'; /* usually like this: prefix_dbName */
  41. //
  42. // ob_start();
  43. ## *** (example of ODBC connection string)
  44. ## *** $result_conn = $db_conn->connect(DB::parseDSN('odbc://root:12345@test_db'));
  45. ## *** (example of Oracle connection string)
  46. ## *** $result_conn = $db_conn->connect(DB::parseDSN('oci8://root:12345@localhost:1521/mydatabase));
  47. ## *** (example of PostgreSQL connection string)
  48. ## *** $result_conn = $db_conn->connect(DB::parseDSN('pgsql://root:12345@localhost/mydatabase));
  49. ## === (Examples of connections to other db types see in "docs/pear/" folder)
  50. // $db_conn = DB::factory('mysql'); /* don't forget to change on appropriate db type */
  51. // $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
  52. // if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }
  53. ## *** put a primary key on the first place
  54. // $sql = "SELECT primary_key, field_1, field_2 ... FROM tableName ;";
  55. ## *** set needed options and create a new class instance
  56. // $debug_mode = false; /* display SQL statements while processing */
  57. // $messaging = true; /* display system messages on a screen */
  58. // $unique_prefix = "abc_"; /* prevent overlays - must be started with a letter */
  59. // $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
  60. ## *** set data source with needed options
  61. // $default_order_field = "field_name_1 [, field_name_2...]";
  62. // $default_order_type = "ASC|DESC [, ASC|DESC...]";
  63. // $dgrid->dataSource($db_conn, $sql, $default_order_field, $default_order_type);
  64. ##
  65. ##
  66. ## +---------------------------------------------------------------------------+
  67. ## | 2. General Settings: |
  68. ## +---------------------------------------------------------------------------+
  69. ## *** set encoding and collation (default: utf8/utf8_unicode_ci)
  70. /// $dg_encoding = "utf8";
  71. /// $dg_collation = "utf8_unicode_ci";
  72. /// $dgrid->setEncoding($dg_encoding, $dg_collation);
  73. ## *** set interface language (default - English)
  74. ## *** (en) - English (de) - German (se) - Swedish (hr) - Bosnian/Croatian
  75. ## *** (hu) - Hungarian (es) - Espanol (ca) - Catala (fr) - Francais
  76. ## *** (nl) - Netherlands/"Vlaams"(Flemish) (it) - Italiano (pl) - Polish
  77. ## *** (ch) - Chinese (sr) - Serbian (bg) - Bulgarian (pb) - Brazilian Portuguese
  78. ## *** (ar) - Arabic
  79. /// $dg_language = "en";
  80. /// $dgrid->setInterfaceLang($dg_language);
  81. ## *** set direction: "ltr" or "rtr" (default - "ltr")
  82. /// $direction = "ltr";
  83. /// $dgrid->setDirection($direction);
  84. ## *** set layouts: "0" - tabular(horizontal) - default, "1" - columnar(vertical), "2" - customized
  85. /// $layouts = array("view"=>"0", "edit"=>"1", "details"=>"1", "filter"=>"1");
  86. /// $dgrid->setLayouts($layouts);
  87. /// $details_template = "<table><tr><td>{field_name_1}</td><td>{field_name_2}</td></tr>...</table>";
  88. /// $dgrid->setTemplates("","",$details_template);
  89. ## *** set modes for operations ("type" => "link|button|image")
  90. ## *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
  91. /// $modes = array(
  92. /// "add" =>array("view"=>true, "edit"=>false, "type"=>"link"),
  93. /// "edit" =>array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>""),
  94. /// "cancel" =>array("view"=>true, "edit"=>true, "type"=>"link"),
  95. /// "details" =>array("view"=>true, "edit"=>false, "type"=>"link"),
  96. /// "delete" =>array("view"=>true, "edit"=>true, "type"=>"image")
  97. /// );
  98. /// $dgrid->setModes($modes);
  99. ## *** allow scrolling on datagrid
  100. /// $scrolling_option = false;
  101. /// $dgrid->allowScrollingSettings($scrolling_option);
  102. ## *** set scrolling settings (optional)
  103. /// $scrolling_width = "90%";
  104. /// $scrolling_height = "100%";
  105. /// $dgrid->setScrollingSettings($scrolling_width, $scrolling_height);
  106. ## *** allow mulirow operations
  107. // $multirow_option = true;
  108. // $dgrid->allowMultirowOperations($multirow_option);
  109. /// $multirow_operations = array(
  110. /// "delete" => array("view"=>true),
  111. /// "details" => array("view"=>true),
  112. /// "my_operation_name" => array("view"=>true, "flag_name"=>"my_flag_name", "flag_value"=>"my_flag_value", "tooltip"=>"Do something with selected", "image"=>"image.gif")
  113. /// );
  114. /// $dgrid->setMultirowOperations($multirow_operations);
  115. ## *** set CSS class for datagrid
  116. ## *** "default" or "blue" or "gray" or "green" or your own css file
  117. /// $css_class = "default";
  118. /// $dgrid->setCssClass($css_class);
  119. ## *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
  120. /// $http_get_vars = array("act", "id");
  121. /// $dgrid->setHttpGetVars($http_get_vars);
  122. ## *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
  123. ## *** format (in which mode to allow processing of another datagrids)
  124. ## *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
  125. /// $anotherDatagrids = array("abcd_"=>array("view"=>true, "edit"=>true, "details"=>true));
  126. /// $dgrid->setAnotherDatagrids($anotherDatagrids);
  127. ## *** set DataGrid caption
  128. /// $dg_caption = "My Favorite Lovely PHP DataGrid";
  129. /// $dgrid->setCaption($dg_caption);
  130. ##
  131. ##
  132. ## +---------------------------------------------------------------------------+
  133. ## | 3. Printing & Exporting Settings: |
  134. ## +---------------------------------------------------------------------------+
  135. ## *** set printing option: true(default) or false
  136. /// $printing_option = true;
  137. /// $dgrid->allowPrinting($printing_option);
  138. ## *** set exporting option: true(default) or false and relative (virtual) path
  139. ## *** to export directory (relatively to datagrid.class.php file).
  140. ## *** Ex.: "" - if we use current datagrid folder
  141. /// $exporting_option = true;
  142. /// $exporting_directory = "";
  143. /// $dgrid->allowExporting($exporting_option, $exporting_directory);
  144. ##
  145. ##
  146. ## +---------------------------------------------------------------------------+
  147. ## | 4. Sorting & Paging Settings: |
  148. ## +---------------------------------------------------------------------------+
  149. ## *** set sorting option: true(default) or false
  150. /// $sorting_option = true;
  151. /// $dgrid->allowSorting($sorting_option);
  152. ## *** set paging option: true(default) or false
  153. /// $paging_option = true;
  154. /// $rows_numeration = false;
  155. /// $numeration_sign = "N #";
  156. /// $dgrid->allowPaging($paging_option, $rows_numeration, $numeration_sign);
  157. ## *** set paging settings
  158. /// $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  159. /// $top_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  160. // $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  161. /// $default_page_size = 10;
  162. /// $dgrid->setPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
  163. ##
  164. ##
  165. ## +---------------------------------------------------------------------------+
  166. ## | 5. Filter Settings: |
  167. ## +---------------------------------------------------------------------------+
  168. ## *** set filtering option: true or false(default)
  169. /// $filtering_option = true;
  170. /// $show_search_type = true;
  171. /// $dgrid->allowFiltering($filtering_option, $show_search_type);
  172. ## *** set aditional filtering settings
  173. /// $fill_from_array = array("0"=>"No", "1"=>"Yes"); /* as "value"=>"option" */
  174. /// $filtering_fields = array(
  175. /// "Caption_1"=>array("table"=>"tableName_1", "field"=>"fieldName_1|,fieldName_2", "source"=>"self"|$fill_from_array, "show_operator"=>false|true, "default_operator"=>"=|<|>|like|%like|like%|not like", "order"=>"ASC|DESC (optional)", "type"=>"textbox|dropdownlist", "case_sensitive"=>false|true, "comparison_type"=>"string|numeric|binary"),
  176. /// "Caption_2"=>array("table"=>"tableName_2", "field"=>"fieldName_2", "source"=>"self"|$fill_from_array, "show_operator"=>false|true, "default_operator"=>"=|<|>|like|%like|like%|not like", "order"=>"ASC|DESC (optional)", "type"=>"textbox|dropdownlist", "case_sensitive"=>false|true, "comparison_type"=>"string|numeric|binary"),
  177. /// "Caption_3"=>array("table"=>"tableName_3", "field"=>"fieldName_3", "source"=>"self"|$fill_from_array, "show_operator"=>false|true, "default_operator"=>"=|<|>|like|%like|like%|not like", "order"=>"ASC|DESC (optional)", "type"=>"textbox|dropdownlist", "case_sensitive"=>false|true, "comparison_type"=>"string|numeric|binary")
  178. /// );
  179. /// $dgrid->setFieldsFiltering($filtering_fields);
  180. ##
  181. ##
  182. ## +---------------------------------------------------------------------------+
  183. ## | 6. View Mode Settings: |
  184. ## +---------------------------------------------------------------------------+
  185. ## *** set view mode table properties
  186. /// $vm_table_properties = array("width"=>"90%");
  187. /// $dgrid->setViewModeTableProperties($vm_table_properties);
  188. ## *** set columns in view mode
  189. ## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  190. ## *** "barchart" : number format in SELECT SQL must be equal with number format in max_value
  191. /// $vm_colimns = array(
  192. /// "FieldName_1"=>array("header"=>"Name_A", "type"=>"label", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
  193. /// "FieldName_2"=>array("header"=>"Name_B", "type"=>"image", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "default"=>"default_image.ext", "image_width"=>"50px", "image_height"=>"30px"),
  194. /// "FieldName_3"=>array("header"=>"Name_C", "type"=>"linktoview", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
  195. /// "FieldName_3"=>array("header"=>"Name_C", "type"=>"linktoedit", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
  196. /// "FieldName_4"=>array("header"=>"Name_D", "type"=>"link", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "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}"),
  197. /// "FieldName_5"=>array("header"=>"Name_E", "type"=>"link", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "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}"),
  198. /// "FieldName_6"=>array("header"=>"Name_F", "type"=>"link", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "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"),
  199. /// "FieldName_7"=>array("header"=>"Name_G", "type"=>"password", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
  200. /// "FieldName_8"=>array("header"=>"Name_H", "type"=>"barchart", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "field"=>"field_name", "maximum_value"=>"value")
  201. /// );
  202. /// $dgrid->setColumnsInViewMode($vm_colimns);
  203. ## *** set auto-genereted columns in view mode
  204. // $auto_column_in_view_mode = false;
  205. // $dgrid->setAutoColumnsInViewMode($auto_column_in_view_mode);
  206. ##
  207. ##
  208. ## +---------------------------------------------------------------------------+
  209. ## | 7. Add/Edit/Details Mode Settings: |
  210. ## +---------------------------------------------------------------------------+
  211. ## *** set add/edit mode table properties
  212. /// $em_table_properties = array("width"=>"70%");
  213. /// $dgrid->setEditModeTableProperties($em_table_properties);
  214. ## *** set details mode table properties
  215. /// $dm_table_properties = array("width"=>"70%");
  216. /// $dgrid->setDetailsModeTableProperties($dm_table_properties);
  217. ## *** set settings for add/edit/details modes
  218. // $table_name = "table_name";
  219. // $primary_key = "primary_key";
  220. // $condition = "table_name.field = ".$_REQUEST['abc_rid'];
  221. // $dgrid->setTableEdit($table_name, $primary_key, $condition);
  222. ## *** set columns in edit mode
  223. ## *** first letter: r - required, s - simple (not required)
  224. ## *** second letter: t - text(including datetime), n - numeric, a - alphanumeric, e - email, f - float, y - any, l - login name, z - zipcode, p - password, i - integer, v - verified, c - checkbox, u - URL
  225. ## *** third letter (optional):
  226. ## for numbers: s - signed, u - unsigned, p - positive, n - negative
  227. ## for strings: u - upper, l - lower, n - normal, y - any
  228. ## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  229. ## *** 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
  230. ## *** make sure your WYSIWYG dir has 777 permissions
  231. /// $fill_from_array = array("0"=>"No", "1"=>"Yes", "2"=>"Don't know", "3"=>"My be"); /* as "value"=>"option" */
  232. /// $em_columns = array(
  233. /// "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"=>""),
  234. /// "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"),
  235. /// "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"=>""),
  236. /// "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"),
  237. /// "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"),
  238. /// "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"=>""),
  239. /// "FieldName_7" =>array("header"=>"Name_G", "type"=>"image", "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", "image_width"=>"Xpx", "image_height"=>"Ypx", "file_name"=>"Image_Name", "host"=>"local|remote"),
  240. /// "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"=>""),
  241. /// "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"),
  242. /// "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"=>""),
  243. /// "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),
  244. /// "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"),
  245. /// "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"),
  246. /// "FieldName_14" =>array("header"=>"", "type"=>"hidden", "req_type"=>"st", "default"=>"default_value", "visible"=>"true", "unique"=>false|true),
  247. /// "validator" =>array("header"=>"Name_N", "for_field"=>"", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "visible"=>"true", "on_js_event"=>""),
  248. /// "delimiter" =>array("inner_html"=>"<br />")
  249. /// );
  250. /// $dgrid->setColumnsInEditMode($em_columns);
  251. ## *** set auto-genereted columns in edit mode
  252. // $auto_column_in_edit_mode = false;
  253. // $dgrid->setAutoColumnsInEditMode($auto_column_in_edit_mode);
  254. ## *** set foreign keys for add/edit/details modes (if there are linked tables)
  255. ## *** Ex.: "condition"=>"TableName_1.FieldName > 'a' AND TableName_1.FieldName < 'c'"
  256. ## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  257. /// $foreign_keys = array(
  258. /// "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"=>"Field_Name", "order_type"=>"ASC|DESC", "on_js_event"=>""),
  259. /// "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"=>"Field_Name", "order_type"=>"ASC|DESC", "on_js_event"=>"")
  260. /// );
  261. /// $dgrid->setForeignKeysEdit($foreign_keys);
  262. ##
  263. ##
  264. ## +---------------------------------------------------------------------------+
  265. ## | 8. Bind the DataGrid: |
  266. ## +---------------------------------------------------------------------------+
  267. ## *** bind the DataGrid and draw it on the screen
  268. // $dgrid->bind();
  269. // ob_end_flush();
  270. ##
  271. ################################################################################
  272. ////////////////////////////////////////////////////////////////////////////////
  273. //
  274. // Not documented:
  275. // -----------------------------------------------------------------------------
  276. // Property : first_field_focus_allowed = true|false;
  277. // --//-- : hide_grid_before_serach = true|false;
  278. // --//-- : draw_add_button_separately = true|false;
  279. // --//-- : "pre_addition"=>"" and "post_addition"=>"" attributes in view mode for labels and in add/edit/details modes for textboxes
  280. // --//-- : "autocomplete"=>"on|off" attribute for textboxes in add/edit modes
  281. //
  282. // Method : executeSql()
  283. // use it after dataSource() method only (after the using dataSource() need to be recalled)
  284. // $dSet = $dgrid->executeSql("SELECT * FROM tblPresidents WHERE tblPresidents.CountryID = ".$_GET['f_rid']."");
  285. // while($row = $dSet->fetchRow()){
  286. // for($c = 0; ($c < $dSet->numCols()); $c++){ echo $row[$c]." "; }
  287. // echo "<br />";
  288. // }
  289. // --//-- : selectSqlItem()
  290. // $presidents = $dgrid->selectSqlItem("SELECT COUNT(tblPresidents.presidentID) FROM tblPresidents WHERE tblPresidents.CountryID = ".$_GET['f_rid']."");
  291. // --//-- : allowHighlighting(true|false);
  292. // --//-- : setJsErrorsDisplayStyle("all"|"each");
  293. // --//-- : getNextId();
  294. // --//-- : setHeadersInColumnarLayout("Field Name", "Field Value");
  295. // --//-- : setDgMessages("add", "update", "delete");
  296. //
  297. // Feature : onSubmitMyCheck
  298. // <script type='text/javascript'>
  299. // function unique_prefix_onSubmitMyCheck(){
  300. // return true;
  301. // }
  302. // </script>
  303. // --//-- : "on_js_event"=>"onchange='formAction(\"\", \"\", \"".$dgrid->unique_prefix."\", \"".$dgrid->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\")'"
  304. //
  305. ////////////////////////////////////////////////////////////////////////////////
  306. ////////////////////////////////////////////////////////////////////////////////
  307. //
  308. // Tricks:
  309. // -----------------------------------------------------------------------------
  310. // 1. Default value, that disappears on focus:
  311. // "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\";'",
  312. // 2. Uniquie value for uploading image:
  313. // "file_name"=>"img_".((isset($_GET['prfx_mode']) && ($_GET['prfx_mode'] == "add")) ? $dgrid->getNextId() : $dgrid->rid)
  314. //
  315. ////////////////////////////////////////////////////////////////////////////////
  316. class DataGrid
  317. {
  318. //==========================================================================
  319. // Data Members
  320. //==========================================================================
  321. // unique prefixes ---------------------------------------------------------
  322. var $unique_prefix;
  323. var $unique_random_prefix;
  324. // directory ---------------------------------------------------------------
  325. var $directory;
  326. // language ----------------------------------------------------------------
  327. var $lang_name;
  328. var $lang;
  329. // caption -----------------------------------------------------------------
  330. var $caption;
  331. // rows and columns data members -------------------------------------------
  332. var $rows;
  333. var $row_lower;
  334. var $row_upper;
  335. var $columns;
  336. var $col_lower;
  337. var $col_upper;
  338. // http get vars -----------------------------------------------------------
  339. var $http;
  340. var $port;
  341. var $HTTP_URL;
  342. var $http_get_vars;
  343. var $another_datagrids;
  344. // data source -------------------------------------------------------------
  345. var $db_handler;
  346. var $sql;
  347. var $sql_view;
  348. var $sql_group_by;
  349. var $data_set;
  350. // signs -------------------------------------------------------------------
  351. var $amp;
  352. var $nbsp;
  353. // encoding & direction ----------------------------------------------------
  354. var $encoding;
  355. var $collation;
  356. var $direction;
  357. // layout style ------------------------------------------------------------
  358. var $layouts;
  359. var $layout_type;
  360. // templates ---------------------------------------------------------------
  361. var $templates;
  362. // paging variables --------------------------------------------------------
  363. var $pages_total;
  364. var $page_current;
  365. var $req_page_size;
  366. var $paging_allowed;
  367. var $rows_numeration;
  368. var $numeration_sign;
  369. var $lower_paging;
  370. var $upper_paging;
  371. var $pages_array;
  372. var $limit_start;
  373. var $limit_size;
  374. var $rows_total;
  375. // sorting variables -------------------------------------------------------
  376. var $sort_field;
  377. var $sort_type;
  378. var $default_sort_field;
  379. var $default_sort_type;
  380. var $sorting_allowed;
  381. var $sql_sort;
  382. // filtering variables -----------------------------------------------------
  383. var $filtering_allowed;
  384. var $show_search_type;
  385. var $filter_fields;
  386. var $hide_display;
  387. // columns style parameters ------------------------------------------------
  388. var $wrap;
  389. // css style ---------------------------------------------------------------
  390. var $row_highlighting_allowed;
  391. var $css_class;
  392. var $rowColor;
  393. // table style parameters --------------------------------------------------
  394. var $tblAlign;
  395. var $tblWidth;
  396. var $tblBorder;
  397. var $tblBorderColor;
  398. var $tblCellSpacing;
  399. var $tblCellPadding;
  400. // datagrid modes ----------------------------------------------------------
  401. var $modes;
  402. var $mode;
  403. var $rid;
  404. var $rids;
  405. var $tbl_name;
  406. var $primary_key;
  407. var $condition;
  408. var $foreign_keys_array;
  409. var $columns_view_mode;
  410. var $columns_edit_mode;
  411. var $sorted_columns;
  412. var $draw_add_button_separately;
  413. // printing & exporting ----------------------------------------------------
  414. var $printing_allowed;
  415. var $exporting_allowed;
  416. var $exporting_directory;
  417. // debug mode --------------------------------------------------------------
  418. var $debug;
  419. var $start_time;
  420. var $end_time;
  421. // message -----------------------------------------------------------------
  422. var $act_msg;
  423. var $messaging;
  424. var $is_error;
  425. var $errors;
  426. var $is_warning;
  427. var $warnings;
  428. var $dg_messages;
  429. // browser & system types --------------------------------------------------
  430. var $platform;
  431. var $browser_name;
  432. var $browser_version;
  433. // scrolling ---------------------------------------------------------------
  434. var $scrolling_option;
  435. var $scrolling_width;
  436. var $scrolling_height;
  437. // header names ------------------------------------------------------------
  438. var $field_header;
  439. var $field_value_header;
  440. // hide --------------------------------------------------------------------
  441. var $hide_grid_before_serach;
  442. // summarize ---------------------------------------------------------------
  443. var $summarize_columns;
  444. // multirow ----------------------------------------------------------------
  445. var $multirow_allowed;
  446. var $multi_rows;
  447. var $multirow_operations_array;
  448. // first field focus -------------------------------------------------------
  449. var $first_field_focus_allowed;
  450. // javascript errors display style -----------------------------------------
  451. var $js_validation_errors;
  452. //==========================================================================
  453. // Member Functions
  454. //==========================================================================
  455. //--------------------------------------------------------------------------
  456. // default constructor
  457. //--------------------------------------------------------------------------
  458. function DataGrid($debug_mode = false, $messaging = true, $unique_prefix = "", $datagrid_dir = "datagrid/"){
  459. // start calculating running time of a script
  460. $this->start_time = 0;
  461. $this->end_time = 0;
  462. if($debug_mode == true){
  463. $this->start_time = $this->getFormattedMicrotime();
  464. }
  465. // unique prefixes -----------------------------------------------------
  466. $this->setUniquePrefix($unique_prefix);
  467. // directory -----------------------------------------------------------
  468. $this->directory = $datagrid_dir;
  469. // language ------------------------------------------------------------
  470. $this->lang_name = "en";
  471. $this->lang = array();
  472. $this->lang['total'] = "Total";
  473. $this->lang['wrong_parameter_error'] = "Wrong parameter in [<b>_FIELD_</b>]: _VALUE_";
  474. // caption -------------------------------------------------------------
  475. $this->caption = "";
  476. // rows and columns data members ---------------------------------------
  477. $this->http = $this->getProtocol();
  478. $this->port = $this->getPort();
  479. $this->HTTP_URL = $this->http.$_SERVER['HTTP_HOST'].$this->port.$_SERVER['PHP_SELF'];
  480. // http get vars -------------------------------------------------------
  481. $this->http_get_vars = "";
  482. $this->another_datagrids = "";
  483. // css style ----------------------------------------------------------
  484. $this->row_highlighting_allowed = true;
  485. $this->css_class = "default";
  486. $this->rowColor = array();
  487. // signs ---------------------------------------------------------------
  488. $this->amp = "&amp;";
  489. $this->nbsp = ""; //&nbsp;
  490. $this->rows = 0;
  491. $this->row_lower = 0;
  492. $this->row_upper = 0;
  493. $this->columns = 0;
  494. $this->col_lower = 0;
  495. $this->col_upper = 0;
  496. // encoding & direction ------------------------------------------------
  497. $this->encoding = "utf8";
  498. $this->collation = "utf8_unicode_ci";
  499. $this->direction = "ltr";
  500. $this->layouts['view'] = "0";
  501. $this->layouts['edit'] = "1";
  502. $this->layouts['filter'] = "1";
  503. $this->layouts['show'] = "1";
  504. $this->layout_type = "view";
  505. // templates -----------------------------------------------------------
  506. $this->templates['view'] = "";
  507. $this->templates['edit'] = "";
  508. $this->templates['show'] = "";
  509. $this->pages_total = 0;
  510. $this->page_current = 0;
  511. $this->pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  512. $this->req_page_size = 10;
  513. $this->paging_allowed = true;
  514. $this->rows_numeration = false;
  515. $this->numeration_sign = "N #";
  516. $this->lower_paging['results'] = false;
  517. $this->lower_paging['results_align'] = "left";
  518. $this->lower_paging['pages'] = false;
  519. $this->lower_paging['pages_align'] = "center";
  520. $this->lower_paging['page_size'] = false;
  521. $this->lower_paging['page_size_align'] = "right";
  522. $this->upper_paging['results'] = false;
  523. $this->upper_paging['results_align'] = "left";
  524. $this->upper_paging['pages'] = false;
  525. $this->upper_paging['pages_align'] = "center";
  526. $this->upper_paging['page_size'] = false;
  527. $this->upper_paging['page_size_align'] = "right";
  528. $this->limit_start = 0;
  529. $this->limit_size = $this->req_page_size;
  530. $this->rows_total = 0;
  531. $this->sort_field = "";
  532. $this->sort_field_by = "";
  533. $this->sort_type = "";
  534. $this->default_sort_field = array();
  535. $this->default_sort_type = array();
  536. $this->sorting_allowed = true;
  537. $this->sql_view = "";
  538. $this->sql_group_by = "";
  539. $this->sql = "";
  540. $this->sql_sort = "";
  541. $this->filtering_allowed = false;
  542. $this->show_search_type = true;
  543. $this->filter_fields = array();
  544. $this->hide_display = "";
  545. $this->tblAlign['view'] = "center"; $this->tblAlign['edit'] = "center"; $this->tblAlign['details'] = "center";
  546. $this->tblWidth['view'] = "90%"; $this->tblWidth['edit'] = "70%"; $this->tblWidth['details'] = "60%";
  547. $this->tblBorder['view'] = "1"; $this->tblBorder['edit'] = "1"; $this->tblBorder['details'] = "1";
  548. $this->tblBorderColor['view'] = "#000000"; $this->tblBorderColor['edit'] = "#000000"; $this->tblBorderColor['details'] = "#000000";
  549. $this->tblCellSpacing['view'] = "0"; $this->tblCellSpacing['edit'] = "0"; $this->tblCellSpacing['details'] = "0";
  550. $this->tblCellPadding['view'] = "0"; $this->tblCellPadding['edit'] = "0"; $this->tblCellPadding['details'] = "0";
  551. // datagrid modes ------------------------------------------------------
  552. $this->modes["add"] = array("view"=>true, "edit"=>false, "type"=>"link");
  553. $this->modes["edit"] = array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>"");
  554. $this->modes["cancel"] = array("view"=>true, "edit"=>true, "type"=>"link");
  555. $this->modes["details"] = array("view"=>true, "edit"=>false, "type"=>"link");$this->modes["delete"] = array("view"=>true, "edit"=>true, "type"=>"image");
  556. $this->draw_add_button_separately = false;
  557. $this->mode = "view";
  558. $this->rid = "";
  559. $this->rids = "";
  560. $this->tbl_name ="";
  561. $this->primary_key = 0;
  562. $this->condition = "";
  563. $this->foreign_keys_array = array();
  564. $this->columns_view_mode = array();
  565. $this->columns_edit_mode = array();
  566. $this->sorted_columns = array();
  567. $this->printing_allowed = true;
  568. $this->exporting_allowed = false;
  569. $this->exporting_directory = "";
  570. $this->wrap = "wrap";
  571. // scrolling -----------------------------------------------------------
  572. $this->scrolling_option = false;
  573. $this->scrolling_width = "90%";
  574. $this->scrolling_height = "100%";
  575. // header names --------------------------------------------------------
  576. $this->field_header = "";
  577. $this->field_value_header = "";
  578. // hide ----------------------------------------------------------------
  579. $this->hide_grid_before_serach = false;
  580. $this->summarize_columns = array();
  581. $this->multirow_allowed = false;
  582. $this->multi_rows = 0;
  583. $this->multirow_operations_array = array();
  584. $this->multirow_operations_array['delete'] = array("view"=>true);
  585. $this->multirow_operations_array['details'] = array("view"=>true);
  586. $this->first_field_focus_allowed = false;
  587. // message -------------------------------------------------------------
  588. $this->act_msg = "";
  589. $this->debug = (($debug_mode == true) || ($debug_mode == "true")) ? true : false ;
  590. if($this->debug) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
  591. $this->messaging = (($messaging == true) || ($messaging == "true")) ? true : false ;
  592. $this->is_error = false;
  593. $this->errors = array();
  594. $this->is_warning = false;
  595. $this->warnings = array();
  596. $this->dg_messages = array();
  597. $this->dg_messages['add'] = "";
  598. $this->dg_messages['update'] = "";
  599. $this->dg_messages['delete'] = "";
  600. // javascript errors display style -------------------------------------
  601. $this->js_validation_errors = "true";
  602. // set browser definitions
  603. $this->setBrowserDefinitions();
  604. }
  605. //--------------------------------------------------------------------------
  606. // set unique names
  607. //--------------------------------------------------------------------------
  608. function setUniquePrefix($unique_prefix = ""){
  609. $this->unique_prefix = $unique_prefix;
  610. $this->unique_random_prefix = $this->getRandomString("5");
  611. }
  612. //--------------------------------------------------------------------------
  613. // set Http Get Vars
  614. //--------------------------------------------------------------------------
  615. function setHttpGetVars($http_get_vars = ""){
  616. $this->http_get_vars = $http_get_vars;
  617. }
  618. //--------------------------------------------------------------------------
  619. // set Other DataGrids
  620. //--------------------------------------------------------------------------
  621. function setAnotherDatagrids($another_datagrids = ""){
  622. $this->another_datagrids = $another_datagrids;
  623. }
  624. //--------------------------------------------------------------------------
  625. // set Scrolling Settings
  626. //--------------------------------------------------------------------------
  627. function allowScrollingSettings($scrolling_option = false){
  628. $this->scrolling_option = (($scrolling_option == true) || ($scrolling_option == "true")) ? true : false ;
  629. }
  630. //--------------------------------------------------------------------------
  631. // set Scrolling Settings
  632. //--------------------------------------------------------------------------
  633. function setScrollingSettings($width="", $height=""){
  634. if($width != "") $this->scrolling_width = $width;
  635. if($height != "") $this->scrolling_height = $height;
  636. }
  637. //--------------------------------------------------------------------------
  638. // set css class
  639. //--------------------------------------------------------------------------
  640. function setCssClass($class = "default"){
  641. $this->css_class = $class;
  642. }
  643. //--------------------------------------------------------------------------
  644. // write css class
  645. //--------------------------------------------------------------------------
  646. function writeCssClass($class = "default", $type = "embedded"){
  647. $req_print = $this->getVariable('print');
  648. if(strtolower($this->css_class) == "green"){
  649. $this->rowColor[0] = "#ffffff";
  650. $this->rowColor[1] = "#e4f5ef";
  651. $this->rowColor[2] = "#ffffff";
  652. $this->rowColor[3] = "#e4f5ef";
  653. $this->rowColor[4] = "#d4e5df";
  654. $this->rowColor[5] = "#d4e5df";
  655. $this->rowColor[6] = "#c6d7cf"; // header (th main) column
  656. $this->rowColor[7] = "#d4e5df"; // selected row mouse over lighting
  657. echo "\n<style>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>\n";
  658. }else if(strtolower($this->css_class) == "gray") {
  659. $this->rowColor[0] = "#f9f9f9";
  660. $this->rowColor[1] = "#f0f0f0";
  661. $this->rowColor[2] = "#f0f0f0";
  662. $this->rowColor[3] = "#dedede";
  663. $this->rowColor[4] = "#FEFFE8";
  664. $this->rowColor[5] = "#FEFFE8";
  665. $this->rowColor[6] = "#dedede"; // header (th main) column
  666. $this->rowColor[7] = "#FEFFE8"; // selected row mouse over lighting
  667. echo "\n<style>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>\n";
  668. }else if(strtolower($this->css_class) == "blue"){
  669. $this->rowColor[0] = "#f7f9fb";
  670. $this->rowColor[1] = "#ffffff";
  671. $this->rowColor[2] = "#d9e3f1";
  672. $this->rowColor[3] = "#e4ecf7";
  673. $this->rowColor[4] = "#FEFFE8";
  674. $this->rowColor[5] = "#FEFFE8";
  675. $this->rowColor[6] = "#cdd9ea"; // header (th main) column
  676. $this->rowColor[7] = "#FEFFE8"; // selected row mouse over lighting
  677. echo "\n<style>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>\n";
  678. }else{
  679. $this->rowColor[0] = "#fcfaf6";
  680. $this->rowColor[1] = "#ffffff";
  681. $this->rowColor[2] = "#ebeadb"; // dark
  682. $this->rowColor[3] = "#ebeadb"; // light
  683. $this->rowColor[4] = "#e2f3fc"; // row mouse over lighting
  684. $this->rowColor[5] = "#fdfde7"; // on mouse click
  685. $this->rowColor[6] = "#e2e0cb"; // header (th main) column
  686. $this->rowColor[7] = "#f9f9e3"; // selected row mouse over lighting
  687. echo "\n<style>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #eee no-repeat center 2px; }</style>\n";
  688. }
  689. // if we in Print Mode
  690. if($req_print == true){
  691. $this->rowColor[0] = "";
  692. $this->rowColor[1] = "";
  693. $this->rowColor[2] = ""; // dark
  694. $this->rowColor[3] = ""; // light
  695. $this->rowColor[4] = ""; // row mouse over lighting
  696. $this->rowColor[5] = ""; // on mouse click
  697. $this->rowColor[6] = ""; // header (th main) column
  698. $this->rowColor[7] = ""; // selected row mouse over lighting
  699. echo "\n<link rel='stylesheet' type='text/css' href='".$this->directory."css/style_print.css' />\n";
  700. }else{
  701. echo "\n<link rel='stylesheet' type='text/css' href='".$this->directory."css/style_".$this->css_class.".css' />\n";
  702. }
  703. }
  704. //--------------------------------------------------------------------------
  705. // set title for datagrid
  706. //--------------------------------------------------------------------------
  707. function setCaption($dg_title = ""){
  708. $this->caption = $dg_title;
  709. }
  710. //--------------------------------------------------------------------------
  711. // set data source
  712. //--------------------------------------------------------------------------
  713. function dataSource($db_handl, $sql = "", $start_order = "", $start_order_type = ""){
  714. // clear sql statment
  715. $sql = str_replace("\n", " ", $sql); // new row
  716. $sql = str_replace(chr(13), " ", $sql); // CR sign
  717. $sql = str_replace(chr(10), " ", $sql); // LF sign
  718. $sql = str_replace(";", "", $sql);
  719. // get preliminary Primary Key
  720. $p_key = explode(" ", $sql);
  721. $p_key = str_replace(",", "", $p_key[1]);
  722. $p_key = explode(".", $p_key);
  723. $this->primary_key = $p_key[count($p_key)-1];
  724. $req_sort_field = $this->getVariable('sort_field');
  725. $req_sort_field_by = $this->getVariable('sort_field_by');
  726. $sort_field = ($req_sort_field_by != "") ? $req_sort_field_by : $req_sort_field ;
  727. $req_sort_type = $this->getVariable('sort_type');
  728. $this->db_handler = $db_handl;
  729. $this->db_handler->setFetchMode(DB_FETCHMODE_ORDERED);
  730. // handle SELECT SQL statement
  731. $this->sql_view = $sql;
  732. if($this->lastSubStrOccurence($this->sql_view, "from ") < $this->lastSubStrOccurence($this->sql_view, "where ")){
  733. // handle SELECT statment with sub-SELECTs and SELECT without WHERE
  734. $ind = strpos(strtolower($this->sql_view), "group by");
  735. if($ind){
  736. $prefix = substr($sql, 0, $ind);
  737. $suffix = substr($sql, $ind);
  738. $this->sql_view = $prefix." ";
  739. $this->sql_group_by = $suffix;
  740. }else{
  741. $this->sql_view .= " WHERE 1=1 ";
  742. }
  743. }else if($this->lastSubStrOccurence($this->sql_view, "where ") == ""){
  744. $this->sql_view .= " WHERE 1=1 ";
  745. }else{
  746. $ind = strpos(strtolower($this->sql_view), "group by");
  747. if($ind){
  748. $prefix = substr($sql, 0, $ind);
  749. $suffix = substr($sql, $ind);
  750. $this->sql_view = $prefix." ";
  751. $this->sql_group_by = $suffix;
  752. }
  753. }
  754. $this->sql = $this->sql_view.$this->sql_group_by;
  755. // set default order
  756. if($start_order != ""){
  757. $default_sort_field = explode(",", $start_order);
  758. $default_sort_type = explode(",", $start_order_type);
  759. for($ind=0; $ind < count($default_sort_field); $ind++){
  760. $this->default_sort_field[$ind] = trim($default_sort_field[$ind]);
  761. if(isset($default_sort_type[$ind])){
  762. if((strtolower(trim($default_sort_type[$ind])) == "asc") || (strtolower(trim($default_sort_type[$ind])) == "desc")){
  763. $this->default_sort_type[$ind] = trim($default_sort_type[$ind]);
  764. }else{
  765. $this->default_sort_type[$ind] = "ASC";
  766. $this->addWarning('$default_order_type', $start_order_type);
  767. }
  768. }else{
  769. $this->default_sort_type[$ind] = "ASC";
  770. }
  771. }
  772. }else{
  773. $this->default_sort_field[0] = "1";
  774. $this->default_sort_type[0] = "ASC";
  775. }
  776. // create ORDER BY part of sql statment
  777. if($req_sort_field){
  778. if(!substr_count($this->sql, "ORDER BY")){
  779. $this->sql_sort = " ORDER BY ".$sort_field." ".$req_sort_type;
  780. }else{
  781. $this->sql_sort = " , ".$sort_field." ".$req_sort_type;
  782. }
  783. }else if($start_order != ""){
  784. $this->sql_sort = " ORDER BY ".$this->getOrderByList();
  785. }else{
  786. $this->sql_sort = " ORDER BY 1 ASC";

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