PageRenderTime 118ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 2ms

/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
  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]);
  748. }else{
  749. $this->default_sort_type[$ind] = "ASC";
  750. $this->AddWarning('$default_order_type', $start_order_type);
  751. }
  752. }else{
  753. $this->default_sort_type[$ind] = "ASC";
  754. }
  755. }
  756. }else{
  757. $this->default_sort_field[0] = "1";
  758. $this->default_sort_type[0] = "ASC";
  759. }
  760. // create ORDER BY part of sql statment
  761. if($req_sort_field){
  762. if(!substr_count($this->sql, "ORDER BY")){
  763. if($req_sort_field_type == "numeric"){
  764. $this->sql_sort = " ORDER BY ABS(".$sort_field.") ".$req_sort_type;
  765. $numeric_sort = true;
  766. }else{
  767. $this->sql_sort = " ORDER BY ".$sort_field." ".$req_sort_type;
  768. }
  769. }else{
  770. $this->sql_sort = " , ".$sort_field." ".$req_sort_type;
  771. }
  772. }else if($start_order != ""){
  773. $this->sql_sort = " ORDER BY ".$this->GetOrderByList();
  774. }else{
  775. $this->sql_sort = " ORDER BY 1 ASC";
  776. }
  777. $this->GetDataSet($this->sql_sort, "", "", $sort_field, $numeric_sort);
  778. // check if the preliminary key is a Primary Key
  779. if(strtolower($this->GetFieldInfo(0, 'type', 1)) != "int"){
  780. $this->AddWarning($this->primary_key, "Check this field carefully, it may be not a Primary Key!");
  781. }
  782. }
  783. //--------------------------------------------------------------------------
  784. // Set Language
  785. //--------------------------------------------------------------------------
  786. function SetInterfaceLang($lang_name = ""){
  787. $default_language = false;
  788. if(($lang_name != "") && (strlen($lang_name) == 2)){ $this->lang_name = $lang_name; }
  789. if (file_exists($this->directory.'languages/'.$this->lang_name.'.php')) {
  790. include_once($this->directory.'languages/'.$this->lang_name.'.php');
  791. if(function_exists('setLanguage')){
  792. $this->lang = setLanguage();
  793. }else{
  794. if($this->debug){ echo "<label class='".$this->css_class."_class_error_message no_print'>Your language interface option is turned on, but the system was failed to open correctly stream: <b>'".$this->directory."languages/lang.php'</b>. <br>The structure of the file is corrupted or invalid. Please check it or return the language option to default value: <b>'en'</b>!</label><br>"; }
  795. $default_language = true;
  796. }
  797. }else{
  798. if((strtolower($lang_name) != "en") && ($this->debug)){
  799. echo "<label class='".$this->css_class."_class_error_message no_print'>Your language interface option is turned on, but the system was failed to open stream: <b>'".$this->directory."languages/".$lang_name.".php'</b>. <br>No such file or directory. Please check it or return the language option to default value: <b>'en'</b>!</label><br>";
  800. }
  801. $default_language = true;
  802. }
  803. if($default_language){
  804. $this->lang['='] = "="; // "equal";
  805. $this->lang['>'] = ">"; // "bigger";
  806. $this->lang['<'] = "<"; // "smaller";
  807. $this->lang['add'] = "Add";
  808. $this->lang['add_new'] = "+ Add New";
  809. $this->lang['add_new_record'] = "Add new record";
  810. $this->lang['add_new_record_blocked'] = "Security check: attempt of adding a new record! Check your settings, the operation is not allowed!";
  811. $this->lang['adding_operation_completed'] = "The adding operation completed successfully!";
  812. $this->lang['adding_operation_uncompleted'] = "The adding operation uncompleted!";
  813. $this->lang['and'] = "and";
  814. $this->lang['any'] = "any";
  815. $this->lang['ascending'] = "Ascending";
  816. $this->lang['back'] = "Back";
  817. $this->lang['cancel'] = "Cancel";
  818. $this->lang['cancel_creating_new_record'] = "Are you sure you want to cancel creating new record?";
  819. $this->lang['check_all'] = "Check All";
  820. $this->lang['clear'] = "Clear";
  821. $this->lang['create'] = "Create";
  822. $this->lang['create_new_record'] = "Create new record";
  823. $this->lang['current'] = "current";
  824. $this->lang['delete'] = "Delete";
  825. $this->lang['delete_record'] = "Delete record";
  826. $this->lang['delete_record_blocked'] = "Security check: attempt of deleting a record! Check your settings, the operation is not allowed!";
  827. $this->lang['delete_selected'] = "Delete selected";
  828. $this->lang['delete_selected_records'] = "Are you sure you want to delete the selected records?";
  829. $this->lang['delete_this_record'] = "Are you sure you want to delete this record?";
  830. $this->lang['deleting_operation_completed'] = "The deleting operation completed successfully!";
  831. $this->lang['deleting_operation_uncompleted'] = "The deleting operation uncompleted!";
  832. $this->lang['descending'] = "Descending";
  833. $this->lang['details'] = "Details";
  834. $this->lang['details_selected'] = "View selected";
  835. $this->lang['edit'] = "Edit";
  836. $this->lang['edit_selected'] = "Edit selected";
  837. $this->lang['edit_record'] = "Edit record";
  838. $this->lang['edit_selected_records'] = "Are you sure you want to edit the selected records?";
  839. $this->lang['errors'] = "Errors";
  840. $this->lang['export_to_excel'] = "Export to Excel";
  841. $this->lang['export_to_pdf'] = "Export to PDF";
  842. $this->lang['export_to_xml'] = "Export to XML";
  843. $this->lang['field'] = "Field";
  844. $this->lang['field_value'] = "Field Value";
  845. $this->lang['file_find_error'] = "Cannot find file: <b>_FILE_</b>. <br>Check if this file exists and you use a correct path!";
  846. $this->lang['file_opening_error'] = "Cannot open a file. Check your permissions.";
  847. $this->lang['file_writing_error'] = "Cannot write to file. Check writing permissions.";
  848. $this->lang['file_invalid file_size'] = "Invalid file size: ";
  849. $this->lang['file_uploading_error'] = "There was an error while uploading, please try again!";
  850. $this->lang['file_deleting_error'] = "There was an error while deleting!";
  851. $this->lang['first'] = "first";
  852. $this->lang['handle_selected_records'] = "Are you sure you want to handle the selected records?";
  853. $this->lang['hide_search'] = "Hide Search";
  854. $this->lang['last'] = "last";
  855. $this->lang['like'] = "like";
  856. $this->lang['like%'] = "like%"; // "begins with";
  857. $this->lang['%like'] = "%like"; // "ends with";
  858. $this->lang['%like%'] = "%like%"; // "ends with";
  859. $this->lang['loading_data'] = "loading data...";
  860. $this->lang['max'] = "max";
  861. $this->lang['next'] = "next";
  862. $this->lang['no'] = "No";
  863. $this->lang['no_data_found'] = "No data found";
  864. $this->lang['no_data_found_error'] = "No data found! Please, check carefully your code syntax!<br>It may be case sensitive or there are some unexpected symbols.";
  865. $this->lang['no_image'] = "No Image";
  866. $this->lang['not_like'] = "not like";
  867. $this->lang['of'] = "of";
  868. $this->lang['operation_was_already_done'] = "The operation was already completed! You cannot retry it again.";
  869. $this->lang['or'] = "or";
  870. $this->lang['pages'] = "Pages";
  871. $this->lang['page_size'] = "Page size";
  872. $this->lang['previous'] = "previous";
  873. $this->lang['printable_view'] = "Printable View";
  874. $this->lang['print_now'] = "Print Now";
  875. $this->lang['print_now_title'] = "Click here to print this page";
  876. $this->lang['record_n'] = "Record # ";
  877. $this->lang['refresh_page'] = "Refresh Page";
  878. $this->lang['remove'] = "Remove";
  879. $this->lang['reset'] = "Reset";
  880. $this->lang['results'] = "Results";
  881. $this->lang['required_fields_msg'] = "<font color='#cd0000'>*</font> Items marked with an asterisk are required";
  882. $this->lang['search'] = "Search";
  883. $this->lang['search_d'] = "Search"; // (description)
  884. $this->lang['search_type'] = "Search type";
  885. $this->lang['select'] = "select";
  886. $this->lang['set_date'] = "Set date";
  887. $this->lang['sort'] = "Sort";
  888. $this->lang['total'] = "Total";
  889. $this->lang['turn_on_debug_mode'] = "For more information, turn on debug mode.";
  890. $this->lang['uncheck_all'] = "Uncheck All";
  891. $this->lang['unhide_search'] = "Unhide Search";
  892. $this->lang['unique_field_error'] = "The field _FIELD_ allows only unique values - please reenter!";
  893. $this->lang['update'] = "Update";
  894. $this->lang['update_record'] = "Update record";
  895. $this->lang['update_record_blocked'] = "Security check: attempt of updating a record! Check your settings, the operation is not allowed!";
  896. $this->lang['updating_operation_completed'] = "The updating operation completed successfully!";
  897. $this->lang['updating_operation_uncompleted'] = "The updating operation uncompleted!";
  898. $this->lang['upload'] = "Upload";
  899. $this->lang['view'] = "View";
  900. $this->lang['view_details'] = "View details";
  901. $this->lang['warnings'] = "Warnings";
  902. $this->lang['with_selected'] = "With selected";
  903. $this->lang['wrong_field_name'] = "Wrong field name";
  904. $this->lang['wrong_parameter_error'] = "Wrong parameter in [<b>_FIELD_</b>]: _VALUE_";
  905. $this->lang['yes'] = "Yes";
  906. }
  907. }
  908. //--------------------------------------------------------------------------
  909. // Set direction
  910. //--------------------------------------------------------------------------
  911. function SetDirection($direction = "ltr"){
  912. $this->direction = $direction;
  913. }
  914. //--------------------------------------------------------------------------
  915. // Set layouts
  916. //--------------------------------------------------------------------------
  917. function SetLayouts($layouts = ""){
  918. $this->layouts['view'] = (isset($layouts['view'])) ? $layouts['view'] : "0";
  919. $this->layouts['edit'] = (isset($layouts['edit'])) ? $layouts['edit'] : "0";
  920. $this->layouts['show'] = (isset($layouts['details'])) ? $layouts['details'] : "1";
  921. $this->layouts['filter'] = (isset($layouts['filter'])) ? $layouts['filter'] : "0";
  922. }
  923. //--------------------------------------------------------------------------
  924. // Set templates for customized layouts
  925. //--------------------------------------------------------------------------
  926. function SetTemplates($view = "", $add_edit = "", $details = ""){
  927. $this->templates['view'] = $view;
  928. $this->templates['edit'] = $add_edit;
  929. $this->templates['show'] = $details;
  930. }
  931. //--------------------------------------------------------------------------
  932. // Set mode add/edit/cancel/delete
  933. //--------------------------------------------------------------------------
  934. function SetModes($parameters){
  935. $this->modes = array();
  936. if(is_array($parameters)){
  937. foreach($parameters as $modeName => $modeValue){
  938. $this->modes[$modeName] = $modeValue;
  939. }
  940. }
  941. $this->mode = "view";
  942. }
  943. //--------------------------------------------------------------------------
  944. // Allow scrolling settings
  945. //--------------------------------------------------------------------------
  946. function AllowScrollingSettings($scrolling_option = false){
  947. $this->scrolling_option = (($scrolling_option == true) || ($scrolling_option == "true")) ? true : false ;
  948. }
  949. //--------------------------------------------------------------------------
  950. // Set scrolling settings
  951. //--------------------------------------------------------------------------
  952. function setScrollingSettings($width="", $height=""){
  953. if($width != "") $this->scrolling_width = $width;
  954. if($height != "") $this->scrolling_height = $height;
  955. }
  956. //--------------------------------------------------------------------------
  957. // Allow multirow operations
  958. //--------------------------------------------------------------------------
  959. function AllowMultirowOperations($multirow_option = false){
  960. $this->multirow_allowed = (($multirow_option == true) || ($multirow_option == "true")) ? true : false ;
  961. }
  962. //--------------------------------------------------------------------------
  963. // Set multirow operations
  964. //--------------------------------------------------------------------------
  965. function SetMultirowOperations($multirow_operations = ""){
  966. if(is_array($multirow_operations)){
  967. foreach($multirow_operations as $fldName => $fldValue){
  968. $this->multirow_operations_array[$fldName] = $fldValue;
  969. }
  970. }
  971. }
  972. //--------------------------------------------------------------------------
  973. // Set css class
  974. //--------------------------------------------------------------------------
  975. function SetCssClass($class = "default"){
  976. $this->css_class = $class;
  977. }
  978. //--------------------------------------------------------------------------
  979. // Set Http Get Vars
  980. //--------------------------------------------------------------------------
  981. function SetHttpGetVars($http_get_vars = ""){
  982. $this->http_get_vars = $http_get_vars;
  983. }
  984. //--------------------------------------------------------------------------
  985. // Set Other DataGrids
  986. //--------------------------------------------------------------------------
  987. function SetAnotherDatagrids($another_datagrids = ""){
  988. $this->another_datagrids = $another_datagrids;
  989. }
  990. //--------------------------------------------------------------------------
  991. // Set title for datagrid
  992. //--------------------------------------------------------------------------
  993. function SetCaption($dg_caption = ""){
  994. $this->caption = $dg_caption;
  995. }
  996. //--------------------------------------------------------------------------
  997. // Allow exporting functions
  998. //--------------------------------------------------------------------------
  999. function AllowPrinting ($option = true) { $this->printing_allowed = (($option == true) || ($option == "true")) ? true : false ; }
  1000. function AllowExporting ($option = true, $exporting_directory = "") { $this->exporting_allowed = (($option == true) || ($option == "true")) ? true : false ; $this->exporting_directory = $exporting_directory; }
  1001. function AllowExportingTypes($exporting_types = ""){
  1002. if(is_array($exporting_types)){
  1003. $this->exporting_types["excel"] = (isset($exporting_types["excel"]) && (($exporting_types["excel"] == true) || ($exporting_types["excel"] == "true"))) ? true : false;
  1004. $this->exporting_types["pdf"] = (isset($exporting_types["pdf"]) && (($exporting_types["pdf"] == true) || ($exporting_types["pdf"] == "true"))) ? true : false;
  1005. $this->exporting_types["xml"] = (isset($exporting_types["xml"]) && (($exporting_types["xml"] == true) || ($exporting_types["xml"] == "true"))) ? true : false;
  1006. }
  1007. }
  1008. //--------------------------------------------------------------------------
  1009. // Set sorting settings
  1010. //--------------------------------------------------------------------------
  1011. function AllowSorting ($option = true) { $this->sorting_allowed = (($option == true) || ($option == "true")) ? true : false ; }
  1012. //--------------------------------------------------------------------------
  1013. // Set paging settings
  1014. //--------------------------------------------------------------------------
  1015. function AllowPaging($option = true, $rows_numeration = false, $numeration_sign = "N #"){
  1016. $this->paging_allowed = (($option == true) || ($option == "true")) ? true : false ;
  1017. $this->rows_numeration = $rows_numeration;
  1018. $this->numeration_sign = $numeration_sign;
  1019. }
  1020. function SetPagingSettings($lower=false, $upper=false, $pages_array=false, $default_page_size="", $paging_arrows=""){
  1021. if(($lower == true) || ($lower == "true")){
  1022. if($lower['results']) $this->lower_paging['results'] = $lower['results'];
  1023. if($lower['results_align']) $this->lower_paging['results_align'] = $lower['results_align'];
  1024. if($lower['pages']) $this->lower_paging['pages'] = $lower['pages'];
  1025. if($lower['pages_align']) $this->lower_paging['pages_align'] = $lower['pages_align'];
  1026. if($lower['page_size']) $this->lower_paging['page_size'] = $lower['page_size'];
  1027. if($lower['page_size_align']) $this->lower_paging['page_size_align'] = $lower['page_size_align'];
  1028. }
  1029. if(($upper == true) || ($upper == "true")){
  1030. if($upper['results']) $this->upper_paging['results'] = $upper['results'];
  1031. if($upper['results_align']) $this->upper_paging['results_align'] = $upper['results_align'];
  1032. if($upper['pages']) $this->upper_paging['pages'] = $upper['pages'];
  1033. if($upper['pages_align']) $this->upper_paging['pages_align'] = $upper['pages_align'];
  1034. if($upper['page_size']) $this->upper_paging['page_size'] = $upper['page_size'];
  1035. if($upper['page_size_align']) $this->upper_paging['page_size_align'] = $upper['page_size_align'];
  1036. }
  1037. if($pages_array){
  1038. if(is_array($pages_array) && (count($pages_array) > 0)){
  1039. $first_key = "";
  1040. foreach($pages_array as $key => $val){
  1041. if($first_key == "") {$first_key = $key;};
  1042. if (intval($pages_array[$key]) == 0) $pages_array[$key] = 1;
  1043. }
  1044. $this->pages_array = $pages_array;
  1045. $this->req_page_size = ($pages_array[$first_key] > 0) ? $pages_array[$first_key] : $this->req_page_size;
  1046. }
  1047. }
  1048. if(($default_page_size != "") && ($default_page_size > 0)) { $this->default_page_size = $this->req_page_size = $default_page_size; }
  1049. if($paging_arrows != ""){
  1050. if(is_array($paging_arrows) && (count($paging_arrows) > 0)){
  1051. $this->first_arrow = (isset($paging_arrows["first"])) ? $paging_arrows["first"] : $this->first_arrow;
  1052. $this->previous_arrow = (isset($paging_arrows["previous"])) ? $paging_arrows["previous"] : $this->previous_arrow;
  1053. $this->next_arrow = (isset($paging_arrows["next"])) ? $paging_arrows["next"] : $this->next_arrow;
  1054. $this->last_arrow = (isset($paging_arrows["last"])) ? $paging_arrows["last"] : $this->last_arrow;
  1055. }
  1056. }
  1057. }
  1058. //--------------------------------------------------------------------------
  1059. // Set filtering settings
  1060. //--------------------------------------------------------------------------
  1061. function AllowFiltering ($option = false, $show_search_type = "true"){
  1062. $this->filtering_allowed = (($option == true) || ($option == "true")) ? true : false ;
  1063. $this->show_search_type = (($show_search_type == true) || ($show_search_type == "true")) ? true : false ;
  1064. }
  1065. function SetFieldsFiltering($filter_fields_array = ""){
  1066. $req_selSearchType = $this->GetVariable('_ff_selSearchType');
  1067. $req_onSUBMIT_FILTER = $this->GetVariable('_ff_onSUBMIT_FILTER');
  1068. if(is_array($filter_fields_array)){
  1069. foreach($filter_fields_array as $fldName => $fldValue){
  1070. $this->filter_fields[$fldName] = $fldValue;
  1071. }
  1072. if($req_onSUBMIT_FILTER != ""){
  1073. $search_type_start = "AND";
  1074. if($req_selSearchType == "0"){
  1075. $search_type = "AND";
  1076. }else{
  1077. $search_type = "OR";
  1078. }
  1079. if(!substr_count(strtolower($this->sql_view), "where") && !substr_count(strtolower($this->sql_view), "having")) $this->sql_view .= " WHERE 1=1 ";
  1080. foreach($filter_fields_array as $fldName => $fldValue){
  1081. $table_field_name = "";
  1082. $fldValue_fields = str_replace(" ", "", $fldValue['field']);
  1083. $fldValue_fields = explode(",", $fldValue_fields);
  1084. foreach($fldValue_fields as $fldValue_field){
  1085. // ignore filter field if there was empty 'table' or 'field' attribute
  1086. if((trim($fldValue['table']) == "") || (trim($fldValue['field']) == "")) { continue; }
  1087. $table_field_name = $fldValue['table']."_".$fldValue_field;
  1088. if(isset($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name]) && ($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name] !== "")){
  1089. $filter_field_operator = $table_field_name."_operator";
  1090. if(isset($fldValue['case_sensitive']) && ($fldValue['case_sensitive'] != true)){
  1091. $fldTableField = $this->GetLcaseFooByDbType()."(".(($fldValue['table'] != "") ? $fldValue['table']."." : "" ).$fldValue_field.")";
  1092. $fldTableFieldName = $this->StrToLower($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name]);
  1093. }else{
  1094. $fldTableField = (($fldValue['table'] != "") ? $fldValue['table']."." : "" ).$fldValue_field;
  1095. $fldTableFieldName = $_REQUEST[$this->uniquePrefix."_ff_".$table_field_name];
  1096. }
  1097. if(isset($fldValue['comparison_type']) && (strtolower($fldValue['comparison_type']) == "numeric")){
  1098. $left_geresh ="";
  1099. }else{
  1100. $left_geresh ="'";
  1101. }
  1102. // split by separated words if user splitted them by ","
  1103. $splitted_fldTableFieldName = split(",",$fldTableFieldName);
  1104. $separated_word_count = 0;
  1105. if(count($splitted_fldTableFieldName) > 0) $this->sql_view .= " ".$search_type_start." ( ";
  1106. foreach($splitted_fldTableFieldName as $separated_word){
  1107. $separated_word = trim($separated_word);
  1108. if($separated_word_count > 0 ){ $this->sql_view .= " OR "; }
  1109. $requested_filter_field_operator = isset($_REQUEST[$this->uniquePrefix."_ff_".$filter_field_operator]) ? $_REQUEST[$this->uniquePrefix."_ff_".$filter_field_operator] : "";
  1110. if($requested_filter_field_operator != ""){
  1111. if(isset($fldValue['comparison_type']) && (strtolower($fldValue['comparison_type']) == "binary")) $comparison_type = "BINARY";
  1112. else $comparison_type ="";
  1113. // To be sure SQL understands our quotation
  1114. if(substr_count($requested_filter_field_operator, "like") > 0){
  1115. $separated_word = str_replace('\"', mysql_real_escape_string('\\\"'), $separated_word); // double quotation mark
  1116. $separated_word = str_replace("\'", mysql_real_escape_string("\\\'"), $separated_word); // single quotation mark
  1117. }else{
  1118. $separated_word = str_replace('\"', mysql_real_escape_string('\\"'), $separated_word); // double quotation mark
  1119. $separated_word = str_replace("\'", mysql_real_escape_string("\\'"), $separated_word); // single quotation mark
  1120. }
  1121. if($requested_filter_field_operator == "like"){
  1122. $this->sql_view .= " $fldTableField ".$requested_filter_field_operator." ".$comparison_type." '%".$separated_word."%'";
  1123. }else if($requested_filter_field_operator == "like%"){
  1124. $this->sql_view .= " $fldTableField ".substr($requested_filter_field_operator, 0, 4)." ".$comparison_type." '".$separated_word."%'";
  1125. }else if($requested_filter_field_operator == "%like"){
  1126. $this->sql_view .= " $fldTableField ".substr($requested_filter_field_operator, 1, 4)." ".$comparison_type." '%".$separated_word."'";
  1127. }else if($requested_filter_field_operator == "%like%"){
  1128. $this->sql_view .= " $fldTableField ".substr($requested_filter_field_operator, 1, 4)." ".$comparison_type." '%".$separated_word."%'";
  1129. }else{
  1130. $this->sql_view .= " $fldTableField ".$requested_filter_field_operator." $left_geresh".$separated_word."$left_geresh ";
  1131. }
  1132. }else{
  1133. $this->sql_view .= " $fldTableField = $left_geresh".$separated_word."$left_geresh ";
  1134. }
  1135. $separated_word_count++;
  1136. }
  1137. if(count($splitted_fldTableFieldName) > 0) $this->sql_view .= " ) ";
  1138. if($search_type_start !== $search_type){ $search_type_start = $search_type; }
  1139. }
  1140. }
  1141. }
  1142. $this->DataSource($this->db_handler, $this->sql_view);
  1143. }
  1144. }
  1145. }
  1146. //--------------------------------------------------------------------------
  1147. // Set view mode table properties
  1148. //--------------------------------------------------------------------------
  1149. function SetViewModeTableProperties($vmt_properties = ""){
  1150. if(is_array($vmt_properties) && (count($vmt_properties) > 0)){
  1151. if(isset($vmt_properties['width'])) $this->tblWidth['view'] = $vmt_properties['width'];
  1152. }
  1153. }
  1154. //--------------------------------------------------------------------------
  1155. // Set columns in view mode
  1156. //--------------------------------------------------------------------------
  1157. function SetColumnsInViewMode($columns = ""){
  1158. unset($this->columns_view_mode);
  1159. $this->columns_edit_mode = array();
  1160. if(is_array($columns)){
  1161. foreach($columns as $fldName => $fldValue){
  1162. $this->columns_view_mode[$fldName] = $fldValue;
  1163. }
  1164. }
  1165. }
  1166. //--------------------------------------------------------------------------
  1167. // Set auto-generated columns in view mode
  1168. //--------------------------------------------------------------------------
  1169. function SetAutoColumnsInViewMode($auto_columns = ""){
  1170. if(($auto_columns == true) || ($auto_columns == "true")){
  1171. unset($this->columns_view_mode);
  1172. if($this->db_handler->isError($this->data_set) == 1){
  1173. $this->is_error = true;
  1174. $this->AddErrors();
  1175. }else{
  1176. $fields = $this->data_set->tableInfo();
  1177. for($ind=0; $ind < $this->data_set->numCols(); $ind++){
  1178. $this->columns_view_mode[$fields[$ind]['name']] =
  1179. array("header" =>$fields[$ind]['name'],
  1180. "type" =>"label",
  1181. "align" =>"left",
  1182. "width" =>"210px",
  1183. "wrap" =>"wrap",
  1184. "tooltip" =>false,
  1185. "text_length"=>"-1",
  1186. "case" =>"normal",
  1187. "summarize" =>false,
  1188. "visible" =>"true"
  1189. );
  1190. }
  1191. }
  1192. }
  1193. }
  1194. //--------------------------------------------------------------------------
  1195. // Set add/edit/details mode table properties
  1196. //--------------------------------------------------------------------------
  1197. function SetEditModeTableProperties($emt_properties = ""){
  1198. if(is_array($emt_properties) && (count($emt_properties) > 0)){
  1199. if(isset($emt_properties['width'])) $this->tblWidth['edit'] = $emt_properties['width'];
  1200. }
  1201. }
  1202. //--------------------------------------------------------------------------
  1203. // Set details mode table properties
  1204. //--------------------------------------------------------------------------
  1205. function SetDetailsModeTableProperties($dmt_properties = ""){
  1206. if(is_array($dmt_properties) && (count($dmt_properties) > 0)){
  1207. if(isset($dmt_properties['width'])) $this->tblWidth['details'] = $dmt_properties['width'];
  1208. }
  1209. }
  1210. //--------------------------------------------------------------------------
  1211. // Set editing table & primary key id
  1212. //--------------------------------------------------------------------------
  1213. function SetTableEdit($tbl_name, $field_name, $condition = ""){
  1214. $this->tbl_name = $tbl_name;
  1215. $this->primary_key = $field_name;
  1216. $this->condition = $condition;
  1217. }
  1218. //--------------------------------------------------------------------------
  1219. // Set columns in add/edit/details mode
  1220. //--------------------------------------------------------------------------
  1221. function SetColumnsInEditMode($columns = ""){
  1222. unset($this->columns_edit_mode);
  1223. if(is_array($columns)){
  1224. foreach($columns as $fldName => $fldValue){
  1225. $this->columns_edit_mode[$fldName] = $fldValue;
  1226. }
  1227. }
  1228. }
  1229. //--------------------------------------------------------------------------
  1230. // Set auto-generated columns in add/edit/details mode
  1231. //--------------------------------------------------------------------------
  1232. function SetAutoColumnsInEditMode($auto_columns = ""){
  1233. if(($auto_columns == true) || ($auto_columns == "true")){
  1234. unset($this->columns_edit_mode);
  1235. $sql = " SELECT * FROM ".$this->tbl_name." ";
  1236. $dSet = $this->db_handler->query($sql);
  1237. if($this->db_handler->isError($this->data_set) == 1){
  1238. $this->is_error = true;
  1239. $this->AddErrors();
  1240. }else{
  1241. $fields = $dSet->tableInfo();
  1242. for($ind=0; $ind < $dSet->numCols(); $ind++){
  1243. if($fields[$ind]['name'] != $this->primary_key){
  1244. // get required simbol
  1245. $required_simbol = ($this->IsFieldRequired($fields[$ind]['name'])) ? "r" : "s";
  1246. // get field view type & view type
  1247. $type_view = "texbox";
  1248. switch (strtolower($fields[$ind]['type'])){
  1249. case 'int': // int: TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER, BIGINT, TINY, SHORT, LONG, LONGLONG, INT24
  1250. $type_simbol = "i"; break;
  1251. case 'real': // real: FLOAT, DOUBLE, DECIMAL, NUMERIC
  1252. $type_simbol = "f"; break;
  1253. case 'null': // empty: NULL
  1254. $type_simbol = "t"; break;
  1255. case 'string': // string: CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, ENUM, SET, VAR_STRING
  1256. case 'blob': // blob: TINYBLOB, MEDIUMBLOB, LONGBLOB, BLOB, TEXT
  1257. case 'date': // date: DATE
  1258. case 'timestamp': // date: TIMESTAMP
  1259. case 'year': // date: YEAR
  1260. case 'time': // date: TIME
  1261. $type_simbol = "t"; break;
  1262. case 'datetime': // date: DATETIME
  1263. $type_view = "datetime";
  1264. $type_simbol = "t"; break;
  1265. default:
  1266. $type_simbol = "t"; break;
  1267. }
  1268. // get required-type simbols
  1269. $req_type_simbols = $required_simbol."".$type_simbol;
  1270. // get field maxlength
  1271. $field_maxlength = ($fields[$ind]['len'] <= 0) ? "" : $fields[$ind]['len'];
  1272. $this->columns_edit_mode[$fields[$ind]['name']] =
  1273. array("header" =>$fields[$ind]['name'],
  1274. "type" =>"$type_view",
  1275. "req_type" =>"$req_type_simbols",
  1276. "width" =>"210px",
  1277. "maxlength" =>"$field_maxlength",
  1278. "title" =>$fields[$ind]['name'],
  1279. "readonly" =>false,
  1280. "visible" =>"true"
  1281. );
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287. //--------------------------------------------------------------------------
  1288. // Set set foreign keys editing
  1289. //--------------------------------------------------------------------------
  1290. function SetForeignKeysEdit($foreign_keys_array = ""){
  1291. if(is_array($foreign_keys_array)){
  1292. foreach($foreign_keys_array as $fldName => $fldValue){
  1293. $this->foreign_keys_array[$fldName] = $fldValue;
  1294. }
  1295. }
  1296. }
  1297. //--------------------------------------------------------------------------
  1298. // Bind data and draw DG
  1299. //--------------------------------------------------------------------------
  1300. function Bind($show = true){
  1301. $this->SetInterfaceLang();
  1302. $this->SetCommonJavaScript();
  1303. $req_mode = $this->GetVariable('mode');
  1304. $req_rid = $this->GetVariable('rid');
  1305. $req_new = $this->GetVariable('new');
  1306. $req_page_size = $this->GetVariable('page_size');
  1307. $req_sort_field = $this->GetVariable('sort_field');
  1308. $req_sort_field_by = $this->GetVariable('sort_field_by');
  1309. $req_sort_field_type = $this->GetVariable('sort_field_type');
  1310. $sort_field = ($req_sort_field_by != "") ? $req_sort_field_by : $req_sort_field ;
  1311. $req_sort_type = $this->GetVariable('sort_type');
  1312. $req_print = $this->GetVariable('print');
  1313. // protect datagrid from a Hack Attacks
  1314. if($this->SecurityCheck()){
  1315. // VIEW mode processing
  1316. if(($req_mode == "") || (($req_mode == "view") && ($req_sort_field_type == "numeric"))){
  1317. if($req_sort_field_type == "numeric") $numeric_sort = true; else $numeric_sort = false;
  1318. $this->GetDataSet($this->sql_sort, "", "", $req_sort_field_type, $numeric_sort);
  1319. $view_limit = $this->SetSqlLimitByDbType("0", $req_page_size);
  1320. }
  1321. // DELETE mode processing
  1322. if(($req_mode == "delete") && ($req_rid != "")){
  1323. $this->rid = $req_rid;
  1324. if($req_print != true){
  1325. $this->DeleteRow($this->rid);
  1326. }
  1327. $this->sql = $this->sql_view;
  1328. $this->GetDataSet($this->sql_sort);
  1329. $this->mode = "view";
  1330. }
  1331. // UPDATE mode processing
  1332. if($req_mode == "update"){
  1333. $this->rid = $req_rid;
  1334. if($req_print != true){
  1335. if($req_new != 1){
  1336. $this->UpdateRow($this->rid);
  1337. }else{
  1338. $this->AddRow();
  1339. $this->mode_after_update = "";
  1340. }
  1341. }
  1342. if(($req_new != 1) && ($this->mode_after_update == "edit")){
  1343. $req_mode = "edit";
  1344. $this->mode = "edit";
  1345. }else{
  1346. $this->sql = $this->sql_view;
  1347. $this->GetDataSet($this->sql_sort);
  1348. $this->mode = "view";
  1349. }
  1350. }
  1351. // EDIT & DETAILS modes processing
  1352. if((($req_mode == "edit") || ($req_mode == "details")) && ($req_rid != "")){
  1353. if($req_new == 1){
  1354. $this->data_set = $this->db_handler->query($this->sql);
  1355. }
  1356. $this->rid = $req_rid;
  1357. $this->AllowSorting(false);
  1358. $this->AllowPaging(false);
  1359. $this->sql_sort = " ORDER BY " . $this->primary_key . " DESC";
  1360. if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "1") && ($req_mode == "details")){
  1361. $this->rids = explode("-", $this->rid);
  1362. // if we have more that 1 row selected
  1363. if(count($this->rids) > 1){
  1364. $where = "WHERE ".$this->primary_key." IN ('-1' ";
  1365. foreach ($this->rids as $key){ if($key != "") $where .= ", '".$key."' "; }
  1366. $where .= ") ";
  1367. $this->multi_rows = count($this->rids);
  1368. }else{
  1369. $where = "WHERE ".$this->primary_key." = '".$req_rid."' ";
  1370. }
  1371. if($this->condition != ""){ $where .= " AND ". $this->condition; }
  1372. $view_limit = $this->SetSqlLimitByDbType("0", $req_page_size);
  1373. //$this->sql_sort = ""; we need this sorted for multi-rows editing
  1374. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  1375. }else if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "1") && ($req_mode == "edit")){
  1376. $this->rids = explode("-", $this->rid);
  1377. // if we have more that 1 row selected
  1378. // mr_1
  1379. if(count($this->rids) > 1){
  1380. $where = "WHERE ".$this->primary_key." IN ('-1' ";
  1381. foreach ($this->rids as $key){ if($key != "") $where .= ", '".$key."' "; }
  1382. $where .= ") ";
  1383. $this->multi_rows = count($this->rids);
  1384. }else{
  1385. $where = "WHERE ".$this->primary_key." = '".$req_rid."' ";
  1386. }
  1387. if($this->condition != ""){ $where .= " AND ". $this->condition; }
  1388. $view_limit = $this->SetSqlLimitByDbType("0", $req_page_size);
  1389. //$this->sql_sort = ""; we need this sorted for multi-rows editing
  1390. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  1391. }else if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "0") && ($req_mode == "details")){
  1392. // if we have more that 1 row selected
  1393. $this->rids = explode("-", $this->rid);
  1394. if(count($this->rids) > 1){
  1395. $where = "WHERE ".$this->primary_key." IN ('-1' ";
  1396. foreach ($this->rids as $key){ if($key != "") $where .= ", '".$key."' "; }
  1397. $where .= ") ";
  1398. $this->multi_rows = count($this->rids);
  1399. }else{
  1400. $where = "WHERE ".$this->primary_key." = '".$req_rid."' ";
  1401. }
  1402. $view_limit = $this->SetSqlLimitByDbType("0", $req_page_size);
  1403. $this->sql_sort = "";
  1404. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  1405. }else if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "0") && ($req_mode == "edit")){
  1406. $view_limit = "";
  1407. if($this->condition != ""){
  1408. $where = "WHERE ". $this->condition;
  1409. } else {
  1410. $view_limit = $this->SetSqlLimitByDbType("0", $req_page_size);
  1411. $where = "WHERE ".$this->primary_key." >= '".$req_rid."' ";
  1412. }
  1413. if($req_sort_field != "") $this->sql_sort = " ORDER BY ".(($req_sort_field_type == "numeric") ? " ABS (".$sort_field.")" : $sort_field)." ".$req_sort_type;
  1414. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  1415. }else{
  1416. $view_limit = $this->SetSqlLimitByDbType("0", $req_page_size);
  1417. $where = "WHERE ".$this->primary_key." = '".$req_rid."' ";
  1418. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  1419. }
  1420. $this->GetDataSet($this->sql_sort, $view_limit, $this->mode_after_update);
  1421. if($req_mode == "edit") $this->mode = "edit";
  1422. else $this->mode = "details";
  1423. }
  1424. // CANCEL mode processing
  1425. if($req_mode == "cancel"){
  1426. $this->rid = "";
  1427. $this->sql = $this->sql_view;
  1428. $this->GetDataSet($this->sql_sort);
  1429. $this->mode = "view";
  1430. }
  1431. // ADD mode processing
  1432. if($req_mode == "add"){
  1433. $this->mode_after_update = "";
  1434. // we don't need multirow option allowed when we add new record
  1435. $this->multirow_allowed = false;
  1436. if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "0")){
  1437. // we need
  1438. $view_limit = "";
  1439. if($this->condition != "") $where = " WHERE ". $this->condition;
  1440. else $where = "";
  1441. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  1442. }else{
  1443. $view_limit = "";
  1444. $this->sql = "SELECT * FROM $this->tbl_name ";
  1445. }
  1446. $this->sql_sort = " ORDER BY " . $this->primary_key . " DESC";
  1447. $this->GetDataSet($this->sql_sort, $view_limit);
  1448. $this->rid = -1;
  1449. $this->AllowSorting(false);
  1450. $this->AllowPaging(false);
  1451. $this->mode = "edit";
  1452. }
  1453. }else{
  1454. // VIEW mode processing
  1455. if($req_mode == ""){
  1456. if($req_sort_field_type == "numeric") $numeric_sort = true; else $numeric_sort = false;
  1457. $this->GetDataSet($this->sql_sort, "", "", $req_sort_field_type, $numeric_sort);
  1458. $view_limit = $this->SetSqlLimitByDbType("0", $req_page_size);
  1459. }
  1460. if($this->debug){
  1461. echo "<br><center><label class='default_class_error_message'>Wrong parameters were passed! Possible Hack attack!</label></center><br>";
  1462. }else{
  1463. echo "<br><center><label class='default_class_error_message'>Wrong parameters were passed!</label></center><br>";
  1464. }
  1465. }
  1466. $this->DisplayErrors();
  1467. $this->DisplayWarnings();
  1468. $this->DisplayDataSent();
  1469. if($this->data_set){
  1470. if(($this->mode === "edit") || ($this->mode === "add")){
  1471. $this->layout_type = "edit";
  1472. $this->AllowHighlighting(false);
  1473. }else if($this->mode === "details"){
  1474. $this->layout_type = "show";
  1475. $this->AllowHighlighting(false);
  1476. }else {
  1477. $this->layout_type = "view";
  1478. }
  1479. // sort columns by mode order
  1480. $this->SortColumns($this->mode);
  1481. if($show == true){
  1482. $this->WriteCssClass();
  1483. if($this->layouts[$this->layout_type] == "0"){
  1484. $this->DrawTabular();
  1485. }else if($this->layouts[$this->layout_type] == "1"){
  1486. $this->DrawColumnar();
  1487. }else if($this->layouts[$this->layout_type] == "2"){
  1488. $this->DrawCustomized();
  1489. }else{
  1490. $this->DrawTabular();
  1491. }
  1492. }
  1493. }
  1494. $this->SetCommonJavaScriptEnd();
  1495. // finish calculating running time of a script
  1496. if($this->debug){
  1497. $this->end_time = $this->GetFormattedMicrotime();
  1498. echo "<br><center><label class='default_class_label'>Total running time: ".round((float)$this->end_time - (float)$this->start_time, 6)." sec.</label></center>";
  1499. }
  1500. }
  1501. ////////////////////////////////////////////////////////////////////////////
  1502. //
  1503. // Non documented
  1504. //
  1505. ////////////////////////////////////////////////////////////////////////////
  1506. //--------------------------------------------------------------------------
  1507. // ExecuteSQL - returns dataSet after executing custom SQL statement
  1508. //--------------------------------------------------------------------------
  1509. function ExecuteSQL($sql = ""){
  1510. $dataSet = "";
  1511. if($this->db_handler){
  1512. if($sql != ""){
  1513. $this->SetEncodingOnDatabase();
  1514. $dataSet = & $this->db_handler->query($sql);
  1515. }
  1516. if($this->debug){
  1517. if($this->db_handler->isError($dataSet) == 1){ $debugInfo = "<tr><td>".$dataSet->getDebugInfo()."</td></tr>"; } else { $debugInfo = ""; };
  1518. echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left'><label class='".$this->css_class."_class_label'><b>sql: </b>".$sql."</label></td></tr>".$debugInfo."</table><br>";
  1519. }
  1520. }else{
  1521. $this->AddWarning('ExecuteSQL() method', 'This method must be called after DataSource() method only!');
  1522. }
  1523. return $dataSet;
  1524. }
  1525. //--------------------------------------------------------------------------
  1526. // SelectSqlItem - return the first field after executing custom SELECT SQL statement
  1527. //--------------------------------------------------------------------------
  1528. function SelectSqlItem($sql = ""){
  1529. $dataField = "";
  1530. if($this->db_handler){
  1531. if($sql != ""){
  1532. $this->SetEncodingOnDatabase();
  1533. $this->db_handler->setFetchMode(DB_FETCHMODE_ORDERED);
  1534. $dataSet = & $this->db_handler->query($sql);
  1535. if($dataSet->numCols() > 0){
  1536. $row = $dataSet->fetchRow();
  1537. $dataField = $row[0];
  1538. }
  1539. if($this->debug){
  1540. if($this->db_handler->isError($dataSet) == 1){ $debugInfo = "<tr><td>".$dataSet->getDebugInfo()."</td></tr>"; } else { $debugInfo = ""; };
  1541. echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left'><label class='".$this->css_class."_class_label'><b>select sql (".$this->StrToLower($this->lang['total']).": ".$dataSet->numCols().") </b>".$sql."</label></td></tr>".$debugInfo."</table><br>";
  1542. }
  1543. }
  1544. }else{
  1545. $this->AddWarning('SelectSqlItem() method', 'This method must be called after DataSource() method only!');
  1546. }
  1547. return $dataField;
  1548. }
  1549. function AllowHighlighting($option = true){ $this->row_highlighting_allowed = (($option == true) || ($option == "true")) ? true : false ; }
  1550. //--------------------------------------------------------------------------
  1551. // Set javascript errors display style
  1552. //--------------------------------------------------------------------------
  1553. function SetJsErrorsDisplayStyle($display_style = "all"){
  1554. $this->js_validation_errors = ($display_style == "all") ? "true" : "false";
  1555. }
  1556. //--------------------------------------------------------------------------
  1557. // Get current Id
  1558. //--------------------------------------------------------------------------
  1559. protected function GetCurrentId(){
  1560. return ($this->rid != "") ? $this->rid : $this->GetVariable('rid');
  1561. }
  1562. //--------------------------------------------------------------------------
  1563. // Get next Id
  1564. //--------------------------------------------------------------------------
  1565. function GetNextId(){
  1566. if(isset($this->db_handler)){
  1567. // need to be declined if creating new row was cancelied
  1568. // return $this->db_handler->nextId("'".$this->tbl_name."'");
  1569. $sql = " SELECT MAX(".$this->primary_key.") as max_id FROM ".$this->tbl_name." ";
  1570. $dSet = $this->db_handler->query($sql);
  1571. if($row = $dSet->fetchRow()){
  1572. return $row[0]+1;
  1573. }
  1574. }else{
  1575. return "-1";
  1576. }
  1577. }
  1578. //--------------------------------------------------------------------------
  1579. // Set messages
  1580. //--------------------------------------------------------------------------
  1581. function SetDgMessages($add_message = "", $update_message = "", $delete_message = ""){
  1582. $this->dg_messages['add'] = $add_message;
  1583. $this->dg_messages['update'] = $update_message;
  1584. $this->dg_messages['delete'] = $delete_message;
  1585. }
  1586. //--------------------------------------------------------------------------
  1587. // Set header names in columnar layout
  1588. //--------------------------------------------------------------------------
  1589. function SetHeadersInColumnarLayout($field_header = "", $field_value_header = ""){
  1590. $this->field_header = $field_header;
  1591. $this->field_value_header = $field_value_header;
  1592. }
  1593. //--------------------------------------------------------------------------
  1594. // Write css class
  1595. //--------------------------------------------------------------------------
  1596. function WriteCssClass(){
  1597. if(!$this->is_css_class_written){
  1598. $req_print = $this->GetVariable('print');
  1599. echo "\n<!-- DataGrid CSS definitions - START -->";
  1600. $this->SetMediaPrint();
  1601. $this->DefineCssClass();
  1602. // if we in Print Mode
  1603. if($req_print == true){
  1604. $this->rowColor[0] = "";
  1605. $this->rowColor[1] = "";
  1606. $this->rowColor[2] = ""; // dark
  1607. $this->rowColor[3] = ""; // light
  1608. $this->rowColor[4] = ""; // row mouse over lighting
  1609. $this->rowColor[5] = ""; // on mouse click
  1610. $this->rowColor[6] = ""; // header (th main) column
  1611. $this->rowColor[7] = ""; // selected row mouse over lighting
  1612. echo "\n<!--[if IE]><link rel='stylesheet' type='text/css' href='".$this->directory."css/style_print_IE.css'><![endif]-->";
  1613. echo "\n<link rel='stylesheet' type='text/css' href='".$this->directory."css/style_print.css'>";
  1614. }else{
  1615. echo "\n<!--[if IE]><link rel='stylesheet' type='text/css' href='".$this->directory."css/style_".$this->css_class."_IE.css'><![endif]-->";
  1616. echo "\n<link rel='stylesheet' type='text/css' href='".$this->directory."css/style_".$this->css_class.".css'>";
  1617. }
  1618. echo "\n<!-- DataGrid CSS definitions - END -->\n\n";
  1619. $this->is_css_class_written = true;
  1620. }
  1621. }
  1622. //==========================================================================
  1623. // PROTECTED MEMBER FUNCTIONS
  1624. //==========================================================================
  1625. //--------------------------------------------------------------------------
  1626. // Set unique names
  1627. //--------------------------------------------------------------------------
  1628. protected function SetUniquePrefix($unique_prefix = ""){
  1629. $this->uniquePrefix = $unique_prefix;
  1630. $this->unique_random_prefix = $this->GetRandomString("5");
  1631. }
  1632. //--------------------------------------------------------------------------
  1633. // Set css class
  1634. //--------------------------------------------------------------------------
  1635. protected function DefineCssClass(){
  1636. if(strtolower($this->css_class) == "green"){
  1637. $this->rowColor[0] = "#ffffff";
  1638. $this->rowColor[1] = "#e4f5ef";
  1639. $this->rowColor[2] = "#ffffff";
  1640. $this->rowColor[3] = "#e4f5ef";
  1641. $this->rowColor[4] = "#d4e5df";
  1642. $this->rowColor[5] = "#d4e5df";
  1643. $this->rowColor[6] = "#c6d7cf"; // header (th main) column
  1644. $this->rowColor[7] = "#d4e5df"; // selected row mouse over lighting
  1645. echo "\n<style type='text/css'>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>";
  1646. }else if(strtolower($this->css_class) == "gray") {
  1647. $this->rowColor[0] = "#f9f9f9";
  1648. $this->rowColor[1] = "#f0f0f0";
  1649. $this->rowColor[2] = "#f0f0f0";
  1650. $this->rowColor[3] = "#dedede";
  1651. $this->rowColor[4] = "#FEFFE8";
  1652. $this->rowColor[5] = "#FEFFE8";
  1653. $this->rowColor[6] = "#dedede"; // header (th main) column
  1654. $this->rowColor[7] = "#FEFFE8"; // selected row mouse over lighting
  1655. echo "\n<style type='text/css'>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>";
  1656. }else if(strtolower($this->css_class) == "blue"){
  1657. $this->rowColor[0] = "#f7f9fb";
  1658. $this->rowColor[1] = "#ffffff";
  1659. $this->rowColor[2] = "#d9e3f1";
  1660. $this->rowColor[3] = "#e4ecf7";
  1661. $this->rowColor[4] = "#FEFFE8";
  1662. $this->rowColor[5] = "#FEFFE8";
  1663. $this->rowColor[6] = "#cdd9ea"; // header (th main) column
  1664. $this->rowColor[7] = "#FEFFE8"; // selected row mouse over lighting
  1665. echo "\n<style type='text/css'>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>";
  1666. }else if(strtolower($this->css_class) == "pink"){
  1667. $this->rowColor[0] = "#F8F7EF";
  1668. $this->rowColor[1] = "#F8F7EF";
  1669. $this->rowColor[2] = "#333333"; //edit td dark
  1670. $this->rowColor[3] = "#F8F7EF"; //edit td light
  1671. $this->rowColor[4] = "#e4e2d3";
  1672. $this->rowColor[5] = "#E7E3C7";
  1673. $this->rowColor[6] = "#FFCFB4"; // header (th main) column
  1674. $this->rowColor[7] = "#e4e2d3"; // selected row mouse over lighting
  1675. echo "\n<style type='text/css'>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>";
  1676. }else{
  1677. $this->rowColor[0] = "#fcfaf6";
  1678. $this->rowColor[1] = "#ffffff";
  1679. $this->rowColor[2] = "#ebeadb"; // dark
  1680. $this->rowColor[3] = "#ebeadb"; // light
  1681. $this->rowColor[4] = "#e2f3fc"; // row mouse over lighting
  1682. $this->rowColor[5] = "#fdfde7"; // on mouse click
  1683. $this->rowColor[6] = "#e2e0cb"; // header (th main) column
  1684. $this->rowColor[7] = "#f9f9e3"; // selected row mouse over lighting
  1685. echo "\n<style type='text/css'>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #eee no-repeat center 2px; }</style>";
  1686. }
  1687. }
  1688. //--------------------------------------------------------------------------
  1689. // get DataSet
  1690. //--------------------------------------------------------------------------
  1691. protected function GetDataSet($fsort = "", $limit = "", $mode = "", $sort_field = "", $numeric_sort = false){
  1692. $this->SetEncodingOnDatabase();
  1693. // we need this stupid operation to get a total number of rows in our query
  1694. $this->SetTotalNumberRows("", "", $mode);
  1695. // we need this stupid operation to change field's offset on field's name
  1696. if(($numeric_sort == true) && ($sort_field != "")){
  1697. $this->data_set = & $this->db_handler->query($this->SetSqlByDbType($this->sql, $fsort, " LIMIT 0, 1"));
  1698. $this->sql_sort = str_replace("ABS(".$sort_field.")", "ABS(".$this->GetFieldName($sort_field-1).")", $this->sql_sort);
  1699. }
  1700. if($limit == ""){
  1701. $limit = $this->SetSqlLimitByDbType();
  1702. $this->data_set = & $this->db_handler->query($this->SetSqlByDbType($this->sql, $fsort, $limit));
  1703. }
  1704. if($this->db_handler->isError($this->data_set) == 1){
  1705. $this->is_error = true;
  1706. $this->AddErrors();
  1707. }
  1708. $this->rows = $this->NumberRows();
  1709. $this->columns = $this->NumberCols();
  1710. if($this->debug){
  1711. echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left' class='".$this->css_class."_class_error_message no_print' style='COLOR: #333333;'><b>search sql (".$this->StrToLower($this->lang['total']).": ".$this->rows.") </b>". $this->sql.$fsort." ".$limit."</td></tr></table><br>";
  1712. }
  1713. $this->row_lower = 0;
  1714. $this->row_upper = $this->rows;
  1715. $this->col_lower = 0;
  1716. $this->col_upper = $this->columns;
  1717. }
  1718. //--------------------------------------------------------------------------
  1719. // ger ORDER BY fields list
  1720. //--------------------------------------------------------------------------
  1721. protected function GetOrderByList(){
  1722. $orderByList = "";
  1723. for($ind=0; $ind < count($this->default_sort_field); $ind++){
  1724. if($ind != 0) $orderByList .= ",";
  1725. $orderByList .= " ".$this->default_sort_field[$ind]." ".$this->default_sort_type[$ind];
  1726. }
  1727. return $orderByList;
  1728. }
  1729. //--------------------------------------------------------------------------
  1730. // perform security check from a Hack Attacks
  1731. //--------------------------------------------------------------------------
  1732. protected function SecurityCheck(){
  1733. // check rid variable
  1734. $req_rid = $this->GetVariable('rid');
  1735. if(eregi("'", $req_rid) || eregi('"', $req_rid) || eregi("%27", $req_rid) || eregi("%22", $req_rid)){
  1736. return false;
  1737. }
  1738. // check query string
  1739. $query_string = strtolower(rawurldecode($_SERVER['QUERY_STRING']));
  1740. $bad_string = array("%20union%20", "/*", "*/union/*", "+union+", "load_file", "outfile", "document.cookie", "onmouse", "<script", "<iframe", "<applet", "<meta", "<style", "<form", "<img", "<body", "<link", "_GLOBALS", "_REQUEST", "_GET", "_POST", "include_path", "prefix", "http://", "https://", "ftp://", "smb://" );
  1741. foreach ($bad_string as $string_value){
  1742. if (strstr($query_string, $string_value )){
  1743. return false;
  1744. }
  1745. }
  1746. return true;
  1747. }
  1748. //--------------------------------------------------------------------------
  1749. // set encoding and collation on database
  1750. //--------------------------------------------------------------------------
  1751. protected function SetEncodingOnDatabase(){
  1752. $sql_variables = array(
  1753. 'character_set_client' =>$this->encoding,
  1754. 'character_set_server' =>$this->encoding,
  1755. 'character_set_results' =>$this->encoding,
  1756. 'character_set_database'=>$this->encoding,
  1757. 'character_set_connection'=>$this->encoding,
  1758. 'collation_server' =>$this->collation,
  1759. 'collation_database' =>$this->collation,
  1760. 'collation_connection' =>$this->collation
  1761. );
  1762. foreach($sql_variables as $var => $value){
  1763. $sql = "SET $var=$value;";
  1764. $this->db_handler->query($sql);
  1765. }
  1766. }
  1767. //--------------------------------------------------------------------------
  1768. // table drawing functions
  1769. //--------------------------------------------------------------------------
  1770. protected function ShowCaption() {
  1771. echo ($this->caption != "") ? "<div class='".$this->css_class."_class_caption'>". $this->caption ."</div><p></p>".chr(13) : "";
  1772. }
  1773. protected function TblOpen($style=""){
  1774. if($this->scrolling_option == true) {
  1775. $width = ($this->mode == "view") ? "100%" : $this->tblWidth[$this->mode];
  1776. }else{
  1777. $width = $this->tblWidth[$this->mode];
  1778. }
  1779. $horizontal_align = ($this->tblAlign[$this->mode] == "center") ? "margin-left: auto; margin-right: auto;" : "";
  1780. echo "<table dir='".$this->direction."' class='".$this->css_class."_class_table' style='".$horizontal_align."' width='".$width."' ".$style.">".chr(13);
  1781. echo $this->TbodyOpen();
  1782. }
  1783. protected function TblClose(){
  1784. echo $this->TbodyClose();
  1785. echo "</table>".chr(13);
  1786. }
  1787. protected function ScrollDivOpen(){
  1788. if($this->scrolling_option == true){
  1789. echo "<center><div style='TEXT-ALIGN:center; PADDING:0px; WIDTH:".$this->scrolling_width."; HEIGHT:".$this->scrolling_height."; overflow:auto;'>";
  1790. echo chr(13);
  1791. }
  1792. }
  1793. protected function ScrollDivClose(){
  1794. if($this->scrolling_option == true){
  1795. echo "</div></center>"; echo chr(13);
  1796. }
  1797. }
  1798. protected function HideDivOpen(){
  1799. $req_onSUBMIT_FILTER = $this->GetVariable('_ff_onSUBMIT_FILTER');
  1800. if(($this->hide_grid_before_serach == true) && !($req_onSUBMIT_FILTER != "")){
  1801. echo "<div style='display: none;'>"; echo chr(13);
  1802. }
  1803. }
  1804. protected function HideDivClose(){
  1805. $req_onSUBMIT_FILTER = $this->GetVariable('_ff_onSUBMIT_FILTER');
  1806. if(($this->hide_grid_before_serach == true) && !($req_onSUBMIT_FILTER != "")){
  1807. echo "</div>"; echo chr(13);
  1808. }
  1809. }
  1810. protected function TbodyOpen() { echo "<tbody>".chr(13); }
  1811. protected function TbodyClose(){ echo "</tbody>".chr(13); }
  1812. protected function RowOpen($id, $rowColor = "", $height=""){
  1813. $req_print = $this->GetVariable('print');
  1814. $text = "<tr class='class_tr' style='background-color: ".$rowColor.";' id='".$this->uniquePrefix."row_".$id."' ";
  1815. if($height != "") { $text .= "height='".$height."' "; };
  1816. if($req_print != true){
  1817. if($this->row_highlighting_allowed){
  1818. $text .= " onclick=\"onMouseClickRow('".$this->uniquePrefix."','".$id."','".$this->rowColor[5]."', '".$this->rowColor[1]."', '".$this->rowColor[0]."');\" ";
  1819. $text .= " onmouseover=\"onMouseOverRow('".$this->uniquePrefix."','".$id."','".$this->rowColor[4]."', '".$this->rowColor[7]."');\" ";
  1820. $text .= " onmouseout=\"onMouseOutRow('".$this->uniquePrefix."','".$id."','".$rowColor."','".$this->rowColor[5]."');\" ";
  1821. }
  1822. }else{
  1823. $text .= " ";
  1824. }
  1825. $text .= ">".chr(13);
  1826. echo $text;
  1827. }
  1828. protected function RowClose(){
  1829. echo "</tr>".chr(13);
  1830. }
  1831. protected function MainColOpen($align='left', $colSpan=0, $wrap='', $width='', $class='', $style=''){
  1832. if($class == '') $class = $this->css_class."_class_th";
  1833. $class_align = ($align == "") ? "" : " class_".$align;
  1834. $wrap = ($wrap == '') ? $this->wrap : $wrap;
  1835. $text = "<th class='".$class.$class_align." ";
  1836. $text .= ($wrap == 'nowrap') ? " class_nowrap" : "";
  1837. $text .= "' "; // close css class quotation
  1838. $text .= "style=' ";
  1839. $text .= " background-color:".$this->rowColor[6]."; ";
  1840. $text .= ($width !== '')? " width: ".$width.";" : "";
  1841. $text .= "' "; // close css style quotation
  1842. $text .= ($this->mode != "edit") ? " onmouseover=\"bgColor='".$this->rowColor[3]."';\" onmouseout=\"bgColor='".$this->rowColor[6]."';\"" : "";
  1843. $text .= ($colSpan != 0) ? " colspan='$colSpan'" : "";
  1844. $text .= ($style != '') ? " $style" : "";
  1845. $text .= ">";
  1846. echo $text;
  1847. }
  1848. protected function MainColClose(){
  1849. echo "</th>".chr(13);
  1850. }
  1851. protected function ColOpen($align='left', $colSpan=0, $wrap='', $bgcolor='', $class_td='', $width='', $style=''){
  1852. if($class_td == '') $class_td = $this->css_class."_class_td";
  1853. $req_print = $this->GetVariable('print');
  1854. $wrap = ($wrap == '') ? $this->wrap : $wrap;
  1855. $class_align = ($align == "") ? "" : " class_".$align;
  1856. $text = "<td class='".$class_td.$class_align." ";
  1857. $text .= ($wrap == 'nowrap') ? " class_nowrap" : "";
  1858. $text .= "' "; // close css class quotation
  1859. $text .= "style=' ";
  1860. $text .= ($width !== '')? " width: ".$width.";" : "";
  1861. $text .= ($bgcolor !== '')? " background-color: ".$bgcolor.";" : "";
  1862. $text .= "' "; // close css style quotation
  1863. $text .= ($colSpan != 0) ? " colspan='$colSpan'" : "";
  1864. $text .= ($style != '') ? " $style" : "";
  1865. $text .= ">";
  1866. echo $text;
  1867. }
  1868. protected function ColClose(){
  1869. echo "</td>".chr(13);
  1870. }
  1871. protected function EmptyRow(){
  1872. $this->RowOpen("","");
  1873. $this->ColOpen();$this->ColClose();
  1874. $this->RowClose();
  1875. }
  1876. //--------------------------------------------------------------------------
  1877. // draw Control Panel
  1878. //--------------------------------------------------------------------------
  1879. protected function DrawControlPanel(){
  1880. $req_print = $this->GetVariable('print');
  1881. $req_export = $this->GetVariable('export');
  1882. $req_mode = $this->GetVariable('mode');
  1883. $myRef_window = $this->uniquePrefix."myRef";
  1884. if($this->filtering_allowed || $this->exporting_allowed || $this->printing_allowed){
  1885. $margin_bottom = ($this->layout_type == "edit") ? "margin-bottom: 7px;" : "margin-bottom: 5px;";
  1886. echo "<table border='0' id='printTbl' style='margin-left: auto; margin-right: auto; $margin_bottom' width='".$this->tblWidth[$this->mode]."' cellspacing='1' cellpadding='1'>";
  1887. echo "<tr>";
  1888. echo "<td align='left'>";
  1889. if($this->mode == "edit"){
  1890. echo "<label class='".$this->css_class."_class_label'>".$this->lang['required_fields_msg']."</label>";
  1891. }
  1892. echo "</td>";
  1893. if($this->filtering_allowed && (($this->mode != "edit") && ($this->mode != "details"))){
  1894. echo "<td align='right' class='class_nowrap' style='width: 20px;'>";
  1895. $hide_display = "";
  1896. $unhide_display = "display: none; ";
  1897. if(isset($_COOKIE[$this->uniquePrefix.'hide_search'])) {
  1898. if($_COOKIE[$this->uniquePrefix.'hide_search'] == 1){
  1899. $this->hide_display = "display: none;";
  1900. $hide_display = "display: none; ";
  1901. $unhide_display = "";
  1902. }else{
  1903. $this->hide_display = "";
  1904. $hide_display = "";
  1905. $unhide_display = "display: none; ";
  1906. }
  1907. }
  1908. if($req_print != true){
  1909. echo "<a id='".$this->uniquePrefix."a_hide' style='cursor:pointer; ".$hide_display."' onClick=\"return hideUnHideFiltering('hide', '".$this->uniquePrefix."');\"><img src='".$this->directory."images/".$this->css_class."/search_hide_b.gif' onmouseover='this.src=\"".$this->directory."images/".$this->css_class."/search_hide_r.gif\"' onmouseout='this.src=\"".$this->directory."images/".$this->css_class."/search_hide_b.gif\"' alt='".$this->lang['hide_search']."' title='".$this->lang['hide_search']."'></a>";
  1910. echo "<a id='".$this->uniquePrefix."a_unhide' style='cursor:pointer; ".$unhide_display."' onClick=\"return hideUnHideFiltering('unhide', '".$this->uniquePrefix."');\"><img src='".$this->directory."images/".$this->css_class."/search_unhide_b.gif' onmouseover='this.src=\"".$this->directory."images/".$this->css_class."/search_unhide_r.gif\"' onmouseout='this.src=\"".$this->directory."images/".$this->css_class."/search_unhide_b.gif\"' alt='".$this->lang['unhide_search']."' title='".$this->lang['unhide_search']."'></a>";
  1911. }
  1912. echo "</td>";
  1913. }
  1914. if($this->exporting_allowed){
  1915. if((($req_export == "") || ($req_print != true)) && ($req_print == "")){
  1916. if($this->exporting_types["excel"] == true){
  1917. echo "<td align='right' style='width: 20px;'>";
  1918. echo "<a style='cursor:pointer;' onClick=\"".$myRef_window."=window.open(''+self.location+'".(($_SERVER['QUERY_STRING'] == "")?"?":"&amp;").$this->uniquePrefix."export=true&amp;".$this->uniquePrefix."export_type=csv','ExportToExcel','left=100,top=100,width=540,height=360,toolbar=0,resizable=0,location=0,scrollbars=1');".$myRef_window.".focus();\" class='".$this->css_class."_class_a'>";
  1919. echo "<img src='".$this->directory."images/".$this->css_class."/excel_b.gif' onmouseover='this.src=\"".$this->directory."images/".$this->css_class."/excel_r.gif\"' onmouseout='this.src=\"".$this->directory."images/".$this->css_class."/excel_b.gif\"' alt='".$this->lang['export_to_excel']."' title='".$this->lang['export_to_excel']."'></a>";
  1920. echo "</td>";
  1921. }
  1922. if($this->exporting_types["pdf"] == true){
  1923. echo "<td align='right' style='width: 20px;'>";
  1924. echo "<a style='cursor:pointer;' onClick=\"".$myRef_window."=window.open(''+self.location+'".(($_SERVER['QUERY_STRING'] == "")?"?":"&amp;").$this->uniquePrefix."export=true&amp;".$this->uniquePrefix."export_type=pdf','ExportToPdf','left=100,top=100,width=540,height=360,toolbar=0,resizable=0,location=0,scrollbars=1');".$myRef_window.".focus();\" class='".$this->css_class."_class_a'>";
  1925. echo "<img src='".$this->directory."images/".$this->css_class."/pdf.jpg' onmouseover='this.src=\"".$this->directory."images/".$this->css_class."/pdf.jpg\"' onmouseout='this.src=\"".$this->directory."images/".$this->css_class."/pdf.jpg\"' alt='".$this->lang['export_to_pdf']."' title='".$this->lang['export_to_pdf']."'></a>";
  1926. echo "</td>";
  1927. }
  1928. if($this->exporting_types["xml"] == true){
  1929. echo "<td align='right' style='width: 20px;'>";
  1930. echo "<a style='cursor:pointer;' onClick=\"".$myRef_window."=window.open(''+self.location+'".(($_SERVER['QUERY_STRING'] == "")?"?":"&amp;").$this->uniquePrefix."export=true&amp;".$this->uniquePrefix."export_type=xml','ExportToXml','left=100,top=100,width=540,height=360,toolbar=0,resizable=0,location=0,scrollbars=1');".$myRef_window.".focus();\" class='".$this->css_class."_class_a'>";
  1931. echo "<img src='".$this->directory."images/".$this->css_class."/xml_b.png' onmouseover='this.src=\"".$this->directory."images/".$this->css_class."/xml_r.png\"' onmouseout='this.src=\"".$this->directory."images/".$this->css_class."/xml_b.png\"' alt='".$this->lang['export_to_xml']."' title='".$this->lang['export_to_xml']."'></a>";
  1932. echo "</td>";
  1933. }
  1934. }else{
  1935. echo "<td align='right' style='width: 20px;'></td>";
  1936. }
  1937. }
  1938. if($this->printing_allowed){
  1939. if(($req_export == "") && ($req_print != true)){
  1940. echo "<td align='right' style='width: 20px;'><a style='cursor:pointer;' onClick=\"".$myRef_window."=window.open(''+self.location+'".(($_SERVER['QUERY_STRING'] == "")?"?":"&").$this->uniquePrefix."print=true','PrintableView','left=20,top=20,width=840,height=630,toolbar=0,menubar=0,resizable=0,location=0,scrollbars=1');".$myRef_window.".focus()\" class='".$this->css_class."_class_a'><img src='".$this->directory."images/".$this->css_class."/print_b.gif' onmouseover='this.src=\"".$this->directory."images/".$this->css_class."/print_r.gif\"' onmouseout='this.src=\"".$this->directory."images/".$this->css_class."/print_b.gif\"' alt='".$this->lang['printable_view']."' title='".$this->lang['printable_view']."'></a></td>";
  1941. }else{
  1942. echo "<td align='right'><a style='cursor:pointer; ' onClick='window:print();' class='".$this->css_class."_class_a no_print' title='".$this->lang['print_now_title']."'>".$this->lang['print_now']."</a></td>";
  1943. }
  1944. }
  1945. if($this->filtering_allowed && ($this->mode == "view") && ($req_mode != "update") && ($req_mode != "delete")){
  1946. if($req_print != true){
  1947. echo "<td align='right' style='width: 20px;'><a style='cursor:pointer;' onClick='document.location.href=self.location;' class='".$this->css_class."_class_a'><img src='".$this->directory."images/".$this->css_class."/recycle.gif' alt='".$this->lang['refresh_page']."' title='".$this->lang['refresh_page']."'></a>";
  1948. }
  1949. }
  1950. echo "</tr>";
  1951. echo "</table>";
  1952. }
  1953. }
  1954. //--------------------------------------------------------------------------
  1955. // Export Dispatcher
  1956. //--------------------------------------------------------------------------
  1957. protected function ExportTo(){
  1958. $req_export = $this->GetVariable('export');
  1959. $export_type = $this->GetVariable('export_type');
  1960. if($req_export == true){
  1961. if($export_type == "pdf"){
  1962. $this->ExportToPdf();
  1963. }else if($export_type == "xml"){
  1964. $this->ExportToXml();
  1965. }else{ // csv
  1966. $this->ExportToCsv();
  1967. }
  1968. }
  1969. }
  1970. //--------------------------------------------------------------------------
  1971. // Export to CSV (if you change export file name - change file name length in download.php)
  1972. //--------------------------------------------------------------------------
  1973. protected function ExportToCsv(){
  1974. // Let's make sure the we create the file first
  1975. $this->req_page_size = (isset($_REQUEST[$this->uniquePrefix.'page_size']))?$_REQUEST[$this->uniquePrefix.'page_size']:$this->req_page_size;
  1976. $fe = fopen($this->exporting_directory."export.csv", "w+");
  1977. if($fe){
  1978. $somecontent = "";
  1979. if($this->layouts[$this->layout_type] == "0"){
  1980. $type = "tabular";
  1981. }else if($this->layouts[$this->layout_type] == "1"){
  1982. $type = "columnar";
  1983. }
  1984. if($type == "tabular"){
  1985. // fields headers
  1986. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  1987. // get current column's index (offset)
  1988. $c = $this->sorted_columns[$c_sorted];
  1989. $field_name = $this->GetFieldName($c);
  1990. if($this->CanViewField($field_name)){
  1991. $somecontent .= ucfirst($this->GetHeaderName($field_name, true));
  1992. if($c_sorted < count($this->sorted_columns) - 1) $somecontent .= ",";
  1993. }
  1994. }
  1995. $somecontent .= "\n";
  1996. // fields data
  1997. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  1998. $row = $this->data_set->fetchRow();
  1999. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2000. // get current column's index (offset)
  2001. $c = $this->sorted_columns[$c_sorted];
  2002. $field_name = $this->GetFieldName($c);
  2003. if($this->CanViewField($field_name)){
  2004. $somecontent .= str_replace(",", "",$row[$c]);
  2005. if($c_sorted < count($this->sorted_columns) - 1) $somecontent .= ",";
  2006. }
  2007. }
  2008. $somecontent .= "\n";
  2009. }
  2010. }else{
  2011. $row = $this->data_set->fetchRow();
  2012. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2013. // get current column's index (offset)
  2014. $c = $this->sorted_columns[$c_sorted];
  2015. $field_name = $this->GetFieldName($c);
  2016. if($this->CanViewField($field_name)){
  2017. $somecontent .= ucfirst($this->GetHeaderName($field_name, true));
  2018. $somecontent .= ",";
  2019. $somecontent .= str_replace(",", "",$row[$c]);
  2020. if($c_sorted < count($this->sorted_columns) - 1) $somecontent .= "\n";
  2021. }
  2022. }
  2023. $somecontent .= "\n";
  2024. }
  2025. // write some content to the opened file.
  2026. if (fwrite($fe, $somecontent) == FALSE) {
  2027. echo $this->lang['file_writing_error']." (export.csv)";
  2028. exit;
  2029. }
  2030. fclose($fe);
  2031. echo $this->ExportDownloadFile("export.csv");
  2032. }else{
  2033. echo "<label class='".$this->css_class."_class_error_message no_print'>".$this->lang['file_opening_error']."</lable>";
  2034. exit;
  2035. }
  2036. }
  2037. //---------------------------------------------------
  2038. // Export to PDF (if you change export file name - change file name length in download.php)
  2039. //---------------------------------------------------
  2040. protected function ExportToPdf($type = "tabular") {
  2041. // Let's make sure the we create the file first
  2042. $this->req_page_size = (isset($_REQUEST[$this->uniquePrefix.'page_size']))?$_REQUEST[$this->uniquePrefix.'page_size']:$this->req_page_size;
  2043. $newcontent = array();
  2044. $somecontent = "";
  2045. // fields headers
  2046. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2047. // get current column's index (offset)
  2048. $c = $this->sorted_columns[$c_sorted];
  2049. $field_name = $this->GetFieldName($c);
  2050. if($this->CanViewField($field_name)){
  2051. $somecontent .= ucfirst($this->GetHeaderName($field_name, true));
  2052. if($c_sorted < count($this->sorted_columns) - 1) $somecontent .= "\t";
  2053. }
  2054. }
  2055. $newcontent[] = $somecontent;
  2056. $somecontent = "";
  2057. // fields data
  2058. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  2059. $row = $this->data_set->fetchRow();
  2060. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2061. // get current column's index (offset)
  2062. $c = $this->sorted_columns[$c_sorted];
  2063. $field_name = $this->GetFieldName($c);
  2064. if($this->CanViewField($field_name)){
  2065. $somecontent .= str_replace("\t", "",$row[$c]);
  2066. if($c_sorted < count($this->sorted_columns) - 1) $somecontent .= "\t";
  2067. }
  2068. }
  2069. $somecontent .= "\n";
  2070. $newcontent[] = $somecontent;
  2071. $somecontent = "";
  2072. }
  2073. // write some content to the opened file.
  2074. define('FPDF_FONTPATH', $this->directory.'modules/fpdf/font/');
  2075. include_once($this->directory.'modules/fpdf/fpdf.php');
  2076. $pdf=new FPDF();
  2077. $pdf->AddPage();
  2078. $pdf->SetFont('Arial','B',16);
  2079. for($i=0;$i<count($newcontent);$i++) {
  2080. $pdf->Text(10,($i*10)+10,$newcontent[$i]);
  2081. }
  2082. $output_path = ($this->exporting_directory != "") ? $this->exporting_directory : $this->directory;
  2083. $pdf->Output($output_path."export.pdf", "");
  2084. echo $this->ExportDownloadFile("export.pdf");
  2085. }
  2086. //--------------------------------------------------------------------------
  2087. // Export to XML (if you change export file name - change file name length in download.php)
  2088. //--------------------------------------------------------------------------
  2089. protected function ExportToXml(){
  2090. // Let's make sure the we create the file first
  2091. $this->req_page_size = (isset($_REQUEST[$this->uniquePrefix.'page_size']))?$_REQUEST[$this->uniquePrefix.'page_size']:$this->req_page_size;
  2092. $fe = fopen($this->exporting_directory."export.xml", "w+");
  2093. if($fe){
  2094. $somecontent = "<?xml version='1.0' encoding='UTF-8' ?>";
  2095. // fields data
  2096. $somecontent .= "<page>";
  2097. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  2098. $row = $this->data_set->fetchRow();
  2099. $somecontent .= "<row".$r.">";
  2100. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2101. // get current column's index (offset)
  2102. $c = $this->sorted_columns[$c_sorted];
  2103. $field_name = $this->GetFieldName($c);
  2104. if($this->CanViewField($field_name)){
  2105. $header_name = $field_name;
  2106. $somecontent .= "<".$header_name.">";
  2107. $somecontent .= $row[$c];
  2108. $somecontent .= "</".$header_name.">";
  2109. }
  2110. }
  2111. $somecontent .= "</row".$r.">";
  2112. }
  2113. $somecontent .= "</page>";
  2114. // write somecontent to the opened file.
  2115. if (fwrite($fe, $somecontent) == FALSE) {
  2116. echo $this->lang['file_writing_error']." (export.xml)";
  2117. exit;
  2118. }
  2119. fclose($fe);
  2120. echo $this->ExportDownloadFile("export.xml");
  2121. }else{
  2122. echo "<label class='".$this->css_class."_class_error_message no_print'>".$this->lang['file_opening_error']."</lable>";
  2123. exit;
  2124. }
  2125. }
  2126. //--------------------------------------------------------------------------
  2127. // draw filtering
  2128. //--------------------------------------------------------------------------
  2129. protected function DrawFiltering(){
  2130. $req_print = $this->GetVariable('print');
  2131. $selSearchType = $this->GetVariable("_ff_selSearchType");
  2132. $req_onSUBMIT_FILTER = $this->GetVariable('_ff_onSUBMIT_FILTER');
  2133. $cols = 0;
  2134. if($this->filtering_allowed){
  2135. $horizontal_align = ($this->tblAlign[$this->mode] == "center") ? "margin-left: auto; margin-right: auto;" : "";
  2136. echo "<table id='".$this->uniquePrefix."searchset' style='".$horizontal_align." ".$this->hide_display."' width='".(($this->browser_name == "Firefox") ? "98%" : "100%" )."'><tr><td style='text-align: center;'>\n";
  2137. if($req_print != true){
  2138. echo "<fieldset class='".$this->css_class."_class_fieldset' dir='".$this->direction."' style='".$horizontal_align." width: ".$this->tblWidth['view'].";'>\n";
  2139. echo "<legend class='".$this->css_class."_class_legend'>".$this->lang['search_d']."</legend>\n";
  2140. }
  2141. echo "<form name='frmFiltering".$this->uniquePrefix."' id='frmFiltering".$this->uniquePrefix."' action='' method='GET' style='MARGIN: 10px;'>\n";
  2142. $this->SaveHttpGetVars();
  2143. echo "<table class='".$this->css_class."_class_filter_table' border='0' id='filterTbl".$this->uniquePrefix."' style='margin-left: auto; margin-right: auto;' width='".$this->tblWidth[$this->mode]."' cellspacing='1' cellpadding='1'>\n";
  2144. if($this->layouts['filter'] == "0") echo "<tr>\n";
  2145. foreach($this->filter_fields as $fldName => $fldValue){
  2146. $field_property_on_js_event = $this->GetFieldProperty($fldName, "on_js_event", "filter", "normal");
  2147. $field_property_width = $this->GetFieldProperty($fldName, "width", "filter", "normal");
  2148. $field_property_autocomplete = $this->GetFieldProperty($fldName, "autocomplete", "filter", "normal");
  2149. $field_property_handler = $this->GetFieldProperty($fldName, "handler", "filter", "normal");
  2150. $field_property_maxresults = $this->GetFieldProperty($fldName, "maxresults", "filter", "normal");
  2151. $field_property_shownoresults = $this->GetFieldProperty($fldName, "shownoresults", "filter", "normal");
  2152. if($field_property_shownoresults == "") $field_property_shownoresults = "false";
  2153. $field_width = ($field_property_width != "") ? "width: ".$field_property_width.";" : "";
  2154. if($this->layouts['filter'] == "1") echo "<tr valign='middle'>\n";
  2155. $fldValue_fields = explode(",", $fldValue['field']);
  2156. $table_field_name = "".$fldValue['table']."_".$fldValue_fields[0];///del $fldValue['field'];
  2157. if(isset($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name]) AND ($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name] != "")){
  2158. $filter_field_value = stripcslashes($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name]);
  2159. }else{
  2160. $filter_field_value = "";
  2161. }
  2162. $filter_field_value_html = str_replace('"', "&#034;", $filter_field_value); // double quotation mark
  2163. $filter_field_value_html = str_replace("'", "&#039;", $filter_field_value_html); // single quotation mark
  2164. $filter_field_operator = $table_field_name."_operator";
  2165. echo "<td align='";
  2166. if($this->layouts['filter'] == "1"){
  2167. echo ($this->direction == "rtl")?"left":"right"; echo "' style='width:50%;'>".$fldName."";
  2168. echo "</td><td>".$this->nbsp."</td><td>";
  2169. $cols +=3;
  2170. }else if($this->layouts['filter'] == "0"){
  2171. echo ($this->direction == "rtl")?"center":"center"; echo "' >".$fldName."";
  2172. echo " ";
  2173. $cols +=1;
  2174. }else {
  2175. echo ($this->direction == "rtl")?"left":"right"; echo "' style='width:50%;'>".$fldName."";
  2176. echo "</td>";
  2177. echo "<td>".$this->nbsp."</td>";
  2178. echo "<td>";
  2179. $cols +=2;
  2180. }
  2181. if(isset($fldValue['show_operator']) && $fldValue['show_operator'] != false){
  2182. if($req_print != true){
  2183. if(isset($_REQUEST[$this->uniquePrefix."_ff_".$filter_field_operator]) && $_REQUEST[$this->uniquePrefix."_ff_".$filter_field_operator] != ""){
  2184. $filter_operator = $_REQUEST[$this->uniquePrefix."_ff_".$filter_field_operator];
  2185. }else if(isset($fldValue['default_operator']) && $fldValue['default_operator'] != ""){
  2186. $filter_operator = $fldValue['default_operator'];
  2187. }else{
  2188. $filter_operator = "=";
  2189. }
  2190. echo "<select class='".$this->css_class."_class_select' name='".$this->uniquePrefix."_ff_".$filter_field_operator."' id='".$this->uniquePrefix."_ff_".$filter_field_operator."'>";
  2191. echo "<option value='='"; echo ($filter_operator == "=")? "selected" : ""; echo ">".$this->lang['=']."</option>";
  2192. echo "<option value='&gt;'"; echo ($filter_operator == ">")? "selected" : ""; echo ">".$this->lang['>']."</option>";
  2193. echo "<option value='&lt;'"; echo ($filter_operator == "<")? "selected" : ""; echo ">".$this->lang['<']."</option>";
  2194. echo "<option value='like'"; echo ($filter_operator == "like")? "selected" : ""; echo ">".$this->lang['like']."</option>";
  2195. echo "<option value='like%'"; echo ($filter_operator == "like%")? "selected" : ""; echo ">".$this->lang['like%']."</option>";
  2196. echo "<option value='%like'"; echo ($filter_operator == "%like")? "selected" : ""; echo ">".$this->lang['%like']."</option>";
  2197. echo "<option value='%like%'"; echo ($filter_operator == "%like%")? "selected" : ""; echo ">".$this->lang['%like%']."</option>";
  2198. echo "<option value='not like'"; echo ($filter_operator == "not like")? "selected" : ""; echo ">".$this->lang['not_like']."</option>";
  2199. echo "</select>";
  2200. }else{
  2201. echo (isset($_REQUEST[$this->uniquePrefix."_ff_".$filter_field_operator])) ? "[".$_REQUEST[$this->uniquePrefix."_ff_".$filter_field_operator]."]" : "";
  2202. }
  2203. }else{
  2204. // set default operator
  2205. if(isset($fldValue['default_operator']) && $fldValue['default_operator'] != ""){
  2206. echo "<input type='hidden' name='".$this->uniquePrefix."_ff_".$filter_field_operator."' id='".$this->uniquePrefix."_ff_".$filter_field_operator."' value='".$fldValue['default_operator']."'>";
  2207. $filter_operator = $fldValue['default_operator'];
  2208. }else{
  2209. echo "<input type='hidden' name='".$this->uniquePrefix."_ff_".$filter_field_operator."' id='".$this->uniquePrefix."_ff_".$filter_field_operator."' value='='>";
  2210. $filter_operator = "=";
  2211. }
  2212. }
  2213. if($this->layouts['filter'] == "1"){
  2214. echo "</td>\n<td>".$this->nbsp."</td>\n";
  2215. echo "<td style='width:50%;' align='"; echo ($this->direction == "rtl")?"right":"left"; echo "'>";
  2216. $cols +=2;
  2217. }else if($this->layouts['filter'] == "0"){
  2218. echo "<br>";
  2219. }else {
  2220. echo "</td>\n<td>".$this->nbsp."</td>\n";
  2221. echo "<td style='width:50%;' align='"; echo ($this->direction == "rtl")?"right":"left"; echo "'>";
  2222. $cols +=2;
  2223. }
  2224. $filter_field_type = (isset($fldValue['type'])) ? $fldValue['type'] : "" ;
  2225. if($req_print != true){
  2226. switch($filter_field_type){
  2227. case "textbox":
  2228. $fldValue_fields = str_replace(" ", "", $fldValue['field']);
  2229. $fldValue_fields = explode(",", $fldValue_fields);
  2230. $count = 0;
  2231. $onchange_filter_field = "";
  2232. foreach($fldValue_fields as $fldValue_field){
  2233. if($count++ > 0){ $onchange_filter_field .= "document.getElementById(\"".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."\").value="; }
  2234. }
  2235. $count = 0;
  2236. foreach($fldValue_fields as $fldValue_field){
  2237. if($count++ == 0){
  2238. echo "\n<input class='".$this->css_class."_class_textbox' style='".$field_width."' type='text' value='".$filter_field_value_html."' name='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."' id='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."' onchange='".$onchange_filter_field."this.value;' ".$field_property_on_js_event.">";
  2239. if(($field_property_autocomplete == "true") || ($field_property_autocomplete === true)){
  2240. echo "\n<script type='text/javascript'>\n<!--\n";
  2241. echo "var options = {";
  2242. echo " script: '".$this->directory.$field_property_handler."?json=true&limit=".intval($field_property_maxresults)."&',";
  2243. echo " varname: 'input',";
  2244. echo " json: true,";
  2245. echo " shownoresults: ".$field_property_shownoresults.",";
  2246. echo " maxresults: ".intval($field_property_maxresults);
  2247. //callback: function (obj) { document.getElementById('testid').value = obj.id; }
  2248. echo "};";
  2249. echo "var as_json = new bsn.AutoSuggest('".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."', options);";
  2250. echo "\n//-->\n</script>\n";
  2251. }
  2252. }else{
  2253. $filter_field_operator = $fldValue['table']."_".$fldValue_field."_operator";
  2254. echo "\n<input type='hidden' name='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."' id='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."' value='".$filter_field_value_html."'>";
  2255. echo "\n<input type='hidden' name='".$this->uniquePrefix."_ff_".$filter_field_operator."' id='".$this->uniquePrefix."_ff_".$filter_field_operator."' value='".$filter_operator."'>";
  2256. }
  2257. }
  2258. break;
  2259. case "dropdownlist":
  2260. echo "<select class='".$this->css_class."_class_select' style='".$field_width."' name='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue['field']."' id='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue['field']."' ".$field_property_on_js_event.">";
  2261. echo "<option value=''>-- ".$this->lang['any']." --</option>";
  2262. if(is_array($fldValue['source'])){
  2263. foreach($fldValue['source'] as $val => $opt){
  2264. echo "<option value='".$val."' ";
  2265. if($filter_field_value != ""){
  2266. if($filter_field_value == $val) echo "selected";
  2267. }
  2268. echo ">".$opt."</option>";
  2269. }
  2270. }else{
  2271. if (isset($fldValue['condition']) && trim($fldValue['condition']) !== "") {
  2272. $where = $fldValue['condition'];
  2273. }else{
  2274. $where = " 1=1 ";
  2275. }
  2276. if(isset($fldValue['show']) && trim($fldValue['show']) !== ""){
  2277. $sql = "SELECT DISTINCT ".$fldValue['field'].", ".$fldValue['show']." FROM ".$fldValue['table']." WHERE ".$where." ORDER BY ".$fldValue['field']." ".(($this->strToLower((isset($fldValue['order']) ? $fldValue['order'] : "")) == "desc")?"DESC":"ASC")." ";
  2278. $this->db_handler->setFetchMode(DB_FETCHMODE_ASSOC);
  2279. $dSet = $this->db_handler->query($sql);
  2280. while($row = $dSet->fetchRow()){
  2281. $ff_name = $fldValue['show'];
  2282. if (eregi(" as ", strtolower($ff_name))) $ff_name = substr($ff_name, strpos(strtolower($ff_name), " as ")+4);
  2283. if($row[$fldValue['field']] === $filter_field_value){
  2284. if($filter_field_value !=""){
  2285. echo "<option selected value='".$row[$fldValue['field']]."'>".$row[$ff_name]."</option>";
  2286. }else{
  2287. echo "<option value='".$row[$fldValue['field']]."'>".$row[$ff_name]."</option>";
  2288. }
  2289. }else{
  2290. echo "<option value='".$row[$fldValue['field']]."'>".$row[$ff_name]."</option>";
  2291. }
  2292. }
  2293. } else {
  2294. $sql = "SELECT DISTINCT ".$fldValue['field']." FROM ".$fldValue['table']." WHERE ".$where." ORDER BY ".$fldValue['field']." ".(($this->strToLower((isset($fldValue['order']) ? $fldValue['order'] : "")) == "desc")?"DESC":"ASC")." ";
  2295. $this->db_handler->setFetchMode(DB_FETCHMODE_ASSOC);
  2296. $dSet = $this->db_handler->query($sql);
  2297. while($row = $dSet->fetchRow()){
  2298. if($row[$fldValue['field']] === $filter_field_value){
  2299. if($filter_field_value !=""){
  2300. echo "<option selected value='".$row[$fldValue['field']]."'>".$row[$fldValue['field']]."</option>";
  2301. }else{
  2302. echo "<option value='".$row[$fldValue['field']]."'>".$row[$fldValue['field']]."</option>";
  2303. }
  2304. }else{
  2305. echo "<option value='".$row[$fldValue['field']]."'>".$row[$fldValue['field']]."</option>";
  2306. }
  2307. }
  2308. }
  2309. }
  2310. echo "</select>";
  2311. break;
  2312. case "calendar":
  2313. $fldValue_fields = str_replace(" ", "", $fldValue['field']);
  2314. $fldValue_fields = explode(",", $fldValue_fields);
  2315. $count = 0;
  2316. $onchange_filter_field = "";
  2317. foreach($fldValue_fields as $fldValue_field){
  2318. if($count++ > 0){ $onchange_filter_field .= "document.getElementById(\"".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."\").value="; }
  2319. }
  2320. $count = 0;
  2321. foreach($fldValue_fields as $fldValue_field){
  2322. if($count++ == 0){
  2323. echo "\n<input class='".$this->css_class."_class_textbox' style='".$field_width."' type='text' value='".$filter_field_value."' name='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."' id='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."' onchange='".$onchange_filter_field."this.value;' ".$field_property_on_js_event.">";
  2324. }else{
  2325. $filter_field_operator = $fldValue['table']."_".$fldValue_field."_operator";
  2326. echo "\n<input type='hidden' name='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."' id='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."' value='".$filter_field_value."'>";
  2327. echo "\n<input type='hidden' name='".$this->uniquePrefix."_ff_".$filter_field_operator."' id='".$this->uniquePrefix."_ff_".$filter_field_operator."' value='".$filter_operator."'>";
  2328. }
  2329. }
  2330. echo "<a class='".$this->css_class."_class_a2' title='' href=\"javascript: openCalendar('".$this->directory."','', 'frmFiltering".$this->uniquePrefix."', '', '".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue_field."', 'date')\"><img src='".$this->directory."images/".$this->css_class."/cal.gif' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='border:0px; MARGIN:3px;margin-left:6px;margin-right:6px;'></a>".$this->nbsp;
  2331. break;
  2332. default:
  2333. echo "\n<input class='".$this->css_class."_class_textbox' type='text' value='".$filter_field_value_html."' name='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue['field']."' id='".$this->uniquePrefix."_ff_".$fldValue['table']."_".$fldValue['field']."'>";
  2334. break;
  2335. }
  2336. }else{
  2337. echo $filter_field_value;
  2338. }
  2339. echo "</td>\n";
  2340. //value='$_POST[$fldValue]'
  2341. if($this->layouts['filter'] == "1") echo "</tr>\n";
  2342. }
  2343. if($this->layouts['filter'] == "0") echo "</tr>\n";
  2344. echo "<tr><td ".(($cols > 0) ? "colspan='".$cols."'" : "")." style='height:6px;' align='center'></td></tr>\n";
  2345. echo "<tr><td ".(($cols > 0) ? "colspan='".$cols."'" : "")." align='center'>";
  2346. if(count($this->filter_fields) > 1){
  2347. if($this->show_search_type){ echo $this->lang['search_type'].":&nbsp;&nbsp;"; }
  2348. if($req_print != true){
  2349. if($this->show_search_type){
  2350. echo "<select class='".$this->css_class."_class_select' name='".$this->uniquePrefix."_ff_"."selSearchType' id='".$this->uniquePrefix."_ff_"."selSearchType'>";
  2351. echo "<option value='0' "; echo (($selSearchType != "") && ($selSearchType == 0)) ? "selected" : ""; echo ">".$this->lang['and']."</option>";
  2352. echo "<option value='1' "; echo ($selSearchType == 1) ? "selected" : ""; echo ">".$this->lang['or']."</option>";
  2353. echo "</select>&nbsp;&nbsp;&nbsp;";
  2354. }else{
  2355. echo "<input type='hidden' name='".$this->uniquePrefix."_ff_"."selSearchType' id='".$this->uniquePrefix."_ff_"."selSearchType' value='0'>";
  2356. }
  2357. }else{
  2358. if(($selSearchType != "") && ($selSearchType == 0)){
  2359. echo "[and]";
  2360. }else if($selSearchType == 1){
  2361. echo "[or]";
  2362. }else {
  2363. echo "[none]";
  2364. }
  2365. }
  2366. }
  2367. if($req_print != true){
  2368. if($req_onSUBMIT_FILTER != ""){
  2369. $curr_url = $this->CombineUrl("view", "", "&");
  2370. $this->SetUrlString($curr_url, "", "sorting", "paging");
  2371. echo "<input class='".$this->css_class."_class_button' type='button' value='".$this->lang['reset']."' onClick='document.location.href=\"".$this->HTTP_URL.$curr_url."\"'>&nbsp;";
  2372. }
  2373. echo "<input class='".$this->css_class."_class_button' type='submit' name='".$this->uniquePrefix."_ff_"."onSUBMIT_FILTER' id='".$this->uniquePrefix."_ff_"."onSUBMIT_FILTER' value='".$this->lang['search']."'>";
  2374. }
  2375. echo "</td></tr>\n";
  2376. $this->TblClose();
  2377. echo "</form>\n";
  2378. if($req_print != true){
  2379. echo "</fieldset>\n";
  2380. }
  2381. echo "</td></tr></table>\n";
  2382. }
  2383. }
  2384. //--------------------------------------------------------------------------
  2385. // draw in customized layout
  2386. //--------------------------------------------------------------------------
  2387. protected function DrawCustomized(){
  2388. $req_print = $this->GetVariable('print');
  2389. $req_mode = $this->GetVariable('mode');
  2390. $this->ExportTo();
  2391. $this->ShowCaption($this->caption);
  2392. $this->DrawControlPanel();
  2393. if(($this->mode != "edit") && ($this->mode != "details")) $this->DrawFiltering();
  2394. if(($req_mode !== "add") || ($req_mode == "")) $this->PagingFirstPart();
  2395. $this->DisplayMessages();
  2396. if($this->paging_allowed) $this->PagingSecondPart($this->upper_paging, false, true, "Upper");
  2397. if($this->row_lower == $this->row_upper) echo "<br>";
  2398. echo "<div id='".$this->unique_random_prefix."loading_image'><br><table style='margin-left: auto; margin-right: auto;'><tr><td valign='middle'>".$this->lang['loading_data']."</td><td valign='middle'><img src='".$this->directory."images/common/loading.gif' alt='".$this->lang['loading_data']."'></table></div>";
  2399. // draw hide DG open div
  2400. $this->HideDivOpen();
  2401. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  2402. // draw column data
  2403. $row = $this->data_set->fetchRow();
  2404. $template = $this->templates[$this->layout_type];
  2405. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2406. // get current column's index (offset)
  2407. $c = $this->sorted_columns[$c_sorted];
  2408. if($this->IsForeignKey($this->GetFieldName($c))){
  2409. $template = str_replace("{".$this->GetFieldName($c)."}", $this->GetForeignKeyInput($row[$this->GetFieldOffset($this->primary_key)], $this->GetFieldName($c), $row[$c], "view"), $template);
  2410. }else{
  2411. $template = str_replace("{".$this->GetFieldName($c)."}", $this->GetFieldValueByType($row[$c], $c, $row), $template);
  2412. }
  2413. }
  2414. echo $template;
  2415. }
  2416. // draw empty table
  2417. if($r == $this->row_lower){ $this->NoDataFound(); }
  2418. $this->ScrollDivClose();
  2419. if($this->paging_allowed) $this->PagingSecondPart($this->lower_paging, true, true, "Lower");
  2420. // draw hide DG close div
  2421. $this->HideDivClose();
  2422. echo "<script type='text/javascript'>\n<!--\n document.getElementById('".$this->unique_random_prefix."loading_image').style.display='none'; \n//-->\n</script>";
  2423. }
  2424. //--------------------------------------------------------------------------
  2425. // draw in tabular layout
  2426. //--------------------------------------------------------------------------
  2427. protected function DrawTabular(){
  2428. $req_print = $this->GetVariable('print');
  2429. $req_mode = $this->GetVariable('mode');
  2430. $horizontal_align = ($this->tblAlign[$this->mode] == "center") ? "margin-left: auto; margin-right: auto;" : "";
  2431. $this->ExportTo();
  2432. $this->ShowCaption($this->caption);
  2433. $this->DrawControlPanel();
  2434. if($this->mode != "edit") $this->DrawFiltering();
  2435. if(($req_mode !== "add") || ($req_mode == "")) $this->PagingFirstPart();
  2436. $this->DisplayMessages();
  2437. if($this->paging_allowed) $this->PagingSecondPart($this->upper_paging, false, true, "Upper");
  2438. if($this->row_lower == $this->row_upper) echo "<br>";
  2439. //prepare summarize columns array
  2440. foreach ($this->columns_view_mode as $key => $val){
  2441. $field_property_summarize = $this->GetFieldProperty($key, "summarize", "view");
  2442. if(($field_property_summarize == "true") || ($field_property_summarize === true)){
  2443. $this->summarize_columns[$key] = 0;
  2444. }
  2445. }
  2446. echo "<div id='".$this->unique_random_prefix."loading_image'><br><table style='margin-left: auto; margin-right: auto;'><tr><td valign='middle'>".$this->lang['loading_data']."</td><td valign='middle'><img src='".$this->directory."images/common/loading.gif' alt='".$this->lang['loading_data']."'></table></div>";
  2447. // draw hide DG open div
  2448. $this->HideDivOpen();
  2449. // draw add link-button cell
  2450. if(isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode] &&
  2451. isset($this->modes['add']['show_add_button']) && ($this->modes['add']['show_add_button'] == "outside")){
  2452. echo "<table dir='".$this->direction."' border='0' style='".$horizontal_align."' width='".$this->tblWidth[$this->mode]."'>";
  2453. echo "<tr>";
  2454. echo "<td align='".(($this->direction == "ltr") ? "left" : "right")."'><b>";
  2455. $curr_url = $this->CombineUrl("add", "-1");
  2456. $this->SetUrlString($curr_url, "filtering", "sorting", "paging");
  2457. $this->DrawModeButton("add", $curr_url, $this->lang['add_new'], $this->lang['add_new_record'], "add.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$curr_url."';\"", false, "", "");
  2458. echo "</b></td>";
  2459. echo "</tr>";
  2460. echo "</table>";
  2461. $this->modes['add'][$this->mode] = false;
  2462. }
  2463. $this->ScrollDivOpen();
  2464. $this->TblOpen();
  2465. // *** START DRAWING HEADERS -------------------------------------------
  2466. $this->RowOpen("");
  2467. // draw multi-row checkboxes header
  2468. if(($this->multirow_allowed) && ($this->rows_total > 0)){
  2469. $this->ColOpen("center",0,"nowrap",$this->rowColor[0], $this->css_class."_class_td", "26px");
  2470. echo $this->nbsp;
  2471. $this->ColClose();
  2472. }
  2473. // draw add link-button cell
  2474. if(isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode]){
  2475. $curr_url = $this->CombineUrl("add", "-1");
  2476. $this->SetUrlString($curr_url, "filtering", "sorting", "paging");
  2477. $this->MainColOpen("center",0,"nowrap", "1%", $this->css_class."_class_th_normal");
  2478. $this->DrawModeButton("add", $curr_url, $this->lang['add_new'], $this->lang['add_new_record'], "add.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$curr_url."';\"", false, "", "");
  2479. $this->MainColClose();
  2480. }else{
  2481. if(isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]){
  2482. $this->MainColOpen("center",0,"nowrap", "1%", $this->css_class."_class_th_normal"); echo $this->nbsp; $this->MainColClose();
  2483. }
  2484. }
  2485. if(($this->rows_numeration)){
  2486. $this->MainColOpen("center",0,"nowrap", ""); echo $this->numeration_sign; $this->MainColClose();
  2487. }
  2488. // draw column headers in add mode
  2489. if(($this->rid == -1) && ($req_mode == "add")){
  2490. foreach($this->columns_edit_mode as $key => $val){
  2491. if($this->GetFieldProperty($key, "type") != "hidden"){
  2492. $this->MainColOpen("center",0);
  2493. echo "<b>".ucfirst($this->GetHeaderName($key))."</b>";
  2494. $this->MainColClose();
  2495. }
  2496. }
  2497. }else{
  2498. $req_sort_field = $this->GetVariable('sort_field');
  2499. $req_sort_field_by = $this->GetVariable('sort_field_by');
  2500. $req_sort_type = $this->GetVariable('sort_type');
  2501. if($req_sort_field){
  2502. $sort_img = (strtolower($req_sort_type) == "desc") ? $this->directory."images/".$this->css_class."/s_desc.png" : $this->directory."images/".$this->css_class."/s_asc.png" ;
  2503. $sort_img_back = (strtolower($req_sort_type) == "desc") ? $this->directory."images/".$this->css_class."/s_asc.png" : $this->directory."images/".$this->css_class."/s_desc.png" ;
  2504. $sort_alt = (strtolower($req_sort_type) == "desc") ? $this->lang['descending'] : $this->lang['ascending'] ;
  2505. }
  2506. if($this->mode === "view"){
  2507. // draw column headers in view mode
  2508. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2509. // get current column's index (offset)
  2510. $c = $this->sorted_columns[$c_sorted];
  2511. $field_name = $this->GetFieldName($c);
  2512. $field_property_sort_by = $this->GetFieldProperty($field_name, "sort_by", "view");
  2513. $field_property_sort_type = $this->GetFieldProperty($field_name, "sort_type", "view");
  2514. if($field_property_sort_by != ""){
  2515. $sort_field_by = ($this->GetFieldOffset($field_property_sort_by)+1);
  2516. } else {
  2517. $sort_field_by = "";
  2518. };
  2519. if($this->CanViewField($field_name)){
  2520. $field_property_wrap = $this->GetFieldProperty($field_name, "wrap", "view", "lower", $this->wrap);
  2521. $field_property_width = $this->GetFieldProperty($field_name, "width", "view");
  2522. if($this->sorting_allowed && ($req_print != true) && $req_sort_field && ($c == ($req_sort_field -1))){ $th_css_class = $this->css_class."_class_th_selected"; } else { $th_css_class = $this->css_class."_class_th" ;};
  2523. $this->MainColOpen("center", 0, $field_property_wrap, $field_property_width, $th_css_class);
  2524. if($this->sorting_allowed){
  2525. $href_string = $this->CombineUrl("view");
  2526. $this->SetUrlString($href_string, "filtering", "", "paging");
  2527. if(isset($_REQUEST[$this->uniquePrefix.'sort_type']) && $_REQUEST[$this->uniquePrefix.'sort_type'] == "asc") $sort_type="desc";
  2528. else $sort_type="asc";
  2529. if($req_print != true){
  2530. $href_string .= $this->amp.$this->uniquePrefix."sort_field=".($c+1).$this->amp.$this->uniquePrefix."sort_field_by=".$sort_field_by.$this->amp.$this->uniquePrefix."sort_field_type=".$field_property_sort_type.$this->amp.$this->uniquePrefix."sort_type=";
  2531. // prepare sorting order by field's type
  2532. if($req_sort_field && ($c == ($req_sort_field -1))){
  2533. $href_string .= $sort_type;
  2534. }else{
  2535. if($this->IsDate($field_name)){ $href_string .= "desc"; }
  2536. else{ $href_string .= "asc"; }
  2537. }
  2538. // <nobr>
  2539. echo "<b><a class='".$this->css_class."_class_a_header' href='$href_string' title='".$this->lang['sort']."' ";
  2540. if($req_sort_field && ($c == ($req_sort_field -1))){
  2541. echo "onmouseover=\"if(document.getElementById('soimg".$c."')){ document.getElementById('soimg".$c."').src='".$sort_img_back."'; }\" ";
  2542. echo "onmouseout=\"if(document.getElementById('soimg".$c."')){ document.getElementById('soimg".$c."').src='".$sort_img."'; }\" ";
  2543. }
  2544. echo ">".ucfirst($this->GetHeaderName($field_name))." ";
  2545. if($req_sort_field && ($c == ($req_sort_field -1))){
  2546. echo $this->nbsp."<img id='soimg".$c."' src='".$sort_img."' alt='".$sort_alt."' title='".$sort_alt."' style='border:0px;'>".$this->nbsp;
  2547. }
  2548. echo "</a></b>"; // </nobr>
  2549. }else{
  2550. echo "<b>".ucfirst($this->GetHeaderName($field_name))."</b>";
  2551. }
  2552. }else{
  2553. echo "<b>".ucfirst($this->GetHeaderName($field_name))."</b>";
  2554. }
  2555. $this->MainColClose();
  2556. }
  2557. }//for
  2558. }else if($this->mode === "edit"){
  2559. foreach($this->columns_edit_mode as $key => $val){
  2560. if($this->GetFieldProperty($key, "type") != "hidden"){
  2561. if($this->CanViewField($key)){
  2562. $this->MainColOpen("center",0);
  2563. // alow/disable sorting by headers
  2564. echo "<b>".ucfirst($this->GetHeaderName($key))."</b>";
  2565. $this->MainColClose();
  2566. }
  2567. }
  2568. }
  2569. }
  2570. }
  2571. if(isset($this->modes['details'][$this->mode]) && $this->modes['details'][$this->mode]){
  2572. $this->MainColOpen("center",0,"nowrap", "10%", $this->css_class."_class_th_normal");echo $this->lang['view'];$this->MainColClose();
  2573. }
  2574. if(isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode]){
  2575. $this->MainColOpen("center",0,"nowrap", "10%", $this->css_class."_class_th_normal");echo $this->lang['delete'];$this->MainColClose();
  2576. }
  2577. $this->RowClose();
  2578. // *** END HEADERS -----------------------------------------------------
  2579. //if we add a new row on linked tabular view mode table (mode 0 <-> 0)
  2580. $quick_exit = false;
  2581. if((isset($_REQUEST[$this->uniquePrefix.'mode']) && ($_REQUEST[$this->uniquePrefix.'mode'] == "add")) && ($this->row_lower == 0) && ($this->row_upper == 0)){
  2582. $this->row_upper = 1;
  2583. $quick_exit = true;
  2584. }
  2585. // *** START DRAWING ROWS ----------------------------------------------
  2586. $first_field_name = "";
  2587. $curr_url = "";
  2588. $c_curr_url = "";
  2589. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  2590. // add new row (ADD MODE)
  2591. if(($r == $this->row_lower) && ($this->rid == -1) && ($req_mode == "add")){
  2592. if($r % 2 == 0){$this->RowOpen($r, $this->rowColor[0]); $main_td_color=$this->rowColor[2];}
  2593. else {$this->RowOpen($r, $this->rowColor[1]); $main_td_color=$this->rowColor[3];}
  2594. $curr_url = $this->CombineUrl("update", -1, $this->amp);
  2595. $this->SetUrlString($c_curr_url, "filtering", "sorting", "paging", $this->amp);
  2596. $curr_url .= $c_curr_url;
  2597. $curr_url .= $this->amp.$this->uniquePrefix."new=1";
  2598. echo "<form name='".$this->uniquePrefix."frmEditRow' id='".$this->uniquePrefix."frmEditRow' method='post' action='".$curr_url."'>".chr(13);
  2599. echo "<input type='hidden' name='".$this->uniquePrefix."_operation_randomize_code' value='".$this->GetRandomString(20)."'>".chr(13);
  2600. $this->SetEditFieldsFormScript($curr_url);
  2601. // draw multi-row empty cell
  2602. if(($this->multirow_allowed) && (!$this->is_error)){$this->ColOpen("center",0,"nowrap",$this->rowColor[0], $this->css_class."_class_td");echo $this->nbsp;$this->ColClose();}
  2603. $this->ColOpen("center",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2604. $this->DrawModeButton("edit", "#", $this->lang['create'], $this->lang['create_new_record'], "update.gif", "\"".$this->uniquePrefix."sendEditFields(); return false;\"", false, "&nbsp", "");
  2605. $cancel_url = $this->CombineUrl("cancel", -1);
  2606. $this->SetUrlString($cancel_url, "filtering", "sorting", "paging");
  2607. $cancel_url .= $this->amp.$this->uniquePrefix."new=1";
  2608. $this->DrawModeButton("cancel", $cancel_url, $this->lang['cancel'], $this->lang['cancel'], "cancel.gif", "\"return ".$this->uniquePrefix."verifyCancel('".$cancel_url."'); javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, $this->nbsp, "");
  2609. $this->ColClose();
  2610. foreach($this->columns_edit_mode as $key => $val){
  2611. if($this->GetFieldProperty($key, "type") != "hidden"){
  2612. $this->ColOpen("left",0,"nowrap");
  2613. if($this->IsForeignKey($key)){
  2614. echo $this->nbsp.$this->GetForeignKeyInput(-1, $key, '-1', "edit").$this->nbsp;
  2615. }else{
  2616. echo $this->GetFieldValueByType('', 0, '', $key);
  2617. }
  2618. $this->ColClose();
  2619. }else{
  2620. echo $this->GetFieldValueByType('', 0, '', $key);
  2621. }
  2622. }
  2623. if(isset($this->modes['delete']) && $this->modes['delete'][$this->mode]) $this->ColOpen("center",0,"nowrap");echo"";$this->ColClose();
  2624. echo "</form>";
  2625. $this->RowClose();
  2626. }
  2627. //if we add a new row on linked tabular view mode table (mode 0 <-> 0)
  2628. if($quick_exit == true){
  2629. $this->TblClose();
  2630. echo "<script type='text/javascript'>\n<!--\n document.getElementById('".$this->unique_random_prefix."loading_image').style.display='none'; \n//-->\n</script>";
  2631. if(($this->first_field_focus_allowed) && ($first_field_name != "")) echo "<script type='text/javascript'>\n<!--\n document.forms['".$this->uniquePrefix."frmEditRow']".$this->GetFieldRequiredType($first_field_name).$first_field_name.".focus(); \n//-->\n</script>";
  2632. return;
  2633. }
  2634. $row = $this->data_set->fetchRow();
  2635. if($r % 2 == 0){$this->RowOpen($r, $this->rowColor[0]); $main_td_color=$this->rowColor[2];}
  2636. else {$this->RowOpen($r, $this->rowColor[1]); $main_td_color=$this->rowColor[3];}
  2637. // draw multi-row row checkboxes
  2638. if($this->multirow_allowed){
  2639. $this->ColOpen("center",0,"nowrap","","");
  2640. if($req_print == true){
  2641. $disable = "disabled";
  2642. }else{
  2643. $disable = "";
  2644. }
  2645. echo "<input onclick=\"onMouseClickRow('".$this->uniquePrefix."','".$r."', '".$this->rowColor[5]."', '".$this->rowColor[1]."', '".$this->rowColor[0]."')\" type='checkbox' name='".$this->uniquePrefix."checkbox_".$r."' id='".$this->uniquePrefix."checkbox_".$r."' value='";
  2646. echo ($row[$this->GetFieldOffset($this->primary_key)] != -1) ? $row[$this->GetFieldOffset($this->primary_key)] : "0" ;
  2647. echo "' ".$disable.">";
  2648. $this->ColClose();
  2649. }
  2650. // draw mode buttons
  2651. if(isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]){
  2652. if(($this->mode == "edit") && (intval($this->rid) == intval($row[$this->GetFieldOffset($this->primary_key)]))){
  2653. $curr_url = $this->CombineUrl("update", $row[$this->GetFieldOffset($this->primary_key)], $this->amp);
  2654. $cancel_url = $this->CombineUrl("cancel", $row[$this->GetFieldOffset($this->primary_key)]);
  2655. $this->SetUrlString($c_curr_url, "filtering", "sorting", "paging", $this->amp);
  2656. $curr_url .= $c_curr_url;
  2657. $cancel_url .= $c_curr_url;
  2658. if(isset($_REQUEST[$this->uniquePrefix.'mode']) && $_REQUEST[$this->uniquePrefix.'mode'] === "add") { $curr_url .= $this->amp.$this->uniquePrefix."new=1"; $cancel_url .= $this->amp.$this->uniquePrefix."new=1";}
  2659. echo "<form name='".$this->uniquePrefix."frmEditRow' id='".$this->uniquePrefix."frmEditRow' method='post' action='".$curr_url."'>".chr(13);
  2660. echo "<input type='hidden' name='".$this->uniquePrefix."_operation_randomize_code' value='".$this->GetRandomString(20)."'>".chr(13);
  2661. $this->SetEditFieldsFormScript($curr_url);
  2662. $this->ColOpen("center",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2663. $this->DrawModeButton("edit", "#", $this->lang['update'], $this->lang['update_record'], "update.gif", "\"".$this->uniquePrefix."sendEditFields(); return false;\"", false, "&nbsp;", "");
  2664. if(isset($_REQUEST[$this->uniquePrefix.'mode']) && $_REQUEST[$this->uniquePrefix.'mode'] === "add") {
  2665. $cancel_url = $this->CombineUrl("delete", $row[$this->primary_key]);
  2666. $this->SetUrlString($cancel_url, "filtering", "sorting", "paging");
  2667. if(isset($this->modes['cancel'][$this->mode]) && $this->modes['cancel'][$this->mode]){
  2668. $this->DrawModeButton("cancel", $cancel_url, $this->lang['cancel'], $this->lang['cancel'], "cancel.gif", "\"return ".$this->uniquePrefix."verifyCancel('".$cancel_url."'); javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, $this->nbsp, "");
  2669. }
  2670. }else{
  2671. $this->DrawModeButton("cancel", $cancel_url, $this->lang['cancel'], $this->lang['cancel'], "cancel.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, $this->nbsp, "");
  2672. }
  2673. $this->ColClose();
  2674. }else {
  2675. $row_id = ($this->GetFieldOffset($this->primary_key) != "-1") ? $row[$this->GetFieldOffset($this->primary_key)] : $this->GetFieldOffset($this->primary_key);
  2676. $curr_url = $this->CombineUrl("edit", $row_id);
  2677. $this->SetUrlString($curr_url, "filtering", "sorting", "paging");
  2678. if(isset($_REQUEST[$this->uniquePrefix.'new']) && (isset($_REQUEST[$this->uniquePrefix.'new']) == 1)){
  2679. $curr_url .= $this->amp.$this->uniquePrefix."new=1";
  2680. }
  2681. if(isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]){
  2682. // by field Value - link on Edit mode page
  2683. if (isset($this->modes['edit']['byFieldValue']) && ($this->modes['edit']['byFieldValue'] != "")){
  2684. if($this->GetFieldOffset($this->modes['edit']['byFieldValue']) == "-1"){
  2685. if($this->debug){
  2686. $this->ColOpen(($this->direction == "rtl")?"right":"left",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2687. echo $this->nbsp.$this->lang['wrong_field_name']." - ".$this->modes['edit']['byFieldValue'].$this->nbsp;
  2688. }else{
  2689. $this->ColOpen("center",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2690. $this->DrawModeButton("edit", $curr_url, $this->lang['edit'], $this->lang['edit_record'], "edit.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$curr_url."'\"", false, $this->nbsp, "");
  2691. }
  2692. }else{
  2693. $this->ColOpen(($this->direction == "rtl")?"right":"left",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2694. echo $this->nbsp."<a class='".$this->css_class."_class_a_header' href='$curr_url'>".$row[$this->GetFieldOffset($this->modes['edit']['byFieldValue'])]."</a>".$this->nbsp;
  2695. }
  2696. }else{
  2697. $this->ColOpen("center",0,"nowrap",$main_td_color, $this->css_class."_class_td_main", "10%");
  2698. $this->DrawModeButton("edit", $curr_url, $this->lang['edit'], $this->lang['edit_record'], "edit.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$curr_url."'\"", false, $this->nbsp, "");
  2699. }
  2700. $this->ColClose();
  2701. }
  2702. }
  2703. }else{
  2704. if(isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode]){
  2705. $this->ColOpen("center",0,"nowrap",$this->rowColor[2], $this->css_class."_class_td_main");$this->ColClose();
  2706. }
  2707. }
  2708. if($this->rows_numeration){
  2709. $this->ColOpen("center",0,"nowrap"); echo "<label class='".$this->css_class."_class_label'>".($r+1)."</label>"; $this->ColClose();
  2710. }
  2711. // draw column data
  2712. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2713. // get current column's index (offset)
  2714. $c = $this->sorted_columns[$c_sorted];
  2715. $col_align = $this->GetFieldAlign($c, $row);
  2716. $field_property_wrap = $this->GetFieldProperty($this->GetFieldName($c), "wrap", "view", "lower", $this->wrap);
  2717. if(($this->mode === "view") && ($this->CanViewField($this->GetFieldName($c)))){
  2718. if($req_sort_field == $c+1){
  2719. $this->ColOpen($col_align, 0, $field_property_wrap, $this->rowColor[0], $this->css_class."_class_td_selected");
  2720. }else{
  2721. $this->ColOpen($col_align, 0, $field_property_wrap);
  2722. }
  2723. $field_value = $this->GetFieldValueByType($row[$c], $c, $row);
  2724. $field_property_summarize = $this->GetFieldProperty($this->GetFieldName($c), "summarize", "view");
  2725. if(($field_property_summarize == "true") || ($field_property_summarize === true)){
  2726. $this->summarize_columns[$this->GetFieldName($c)] += str_replace(",", "", $row[$c]);
  2727. }
  2728. echo $field_value;
  2729. $this->ColClose();
  2730. }else if($this->mode === "edit"){
  2731. if($this->GetFieldProperty($this->GetFieldName($c), "type") == "hidden"){
  2732. echo $this->GetFieldValueByType('', 0, '', $this->GetFieldName($c));
  2733. }else if($this->CanViewField($this->GetFieldName($c))){
  2734. if($first_field_name == "") $first_field_name = $this->GetFieldName($c);
  2735. if(intval($this->rid) === intval($row[$this->GetFieldOffset($this->primary_key)])){
  2736. $this->ColOpen("left", 0, $field_property_wrap);
  2737. if($this->IsForeignKey($this->GetFieldName($c))){
  2738. echo $this->nbsp.$this->GetForeignKeyInput($row[$this->GetFieldOffset($this->primary_key)], $this->GetFieldName($c), $row[$c], "edit").$this->nbsp;
  2739. }else{
  2740. echo $this->GetFieldValueByType($row[$c], $c, $row);
  2741. }
  2742. $this->ColClose();
  2743. }else{
  2744. $this->ColOpen($col_align, 0, $field_property_wrap);
  2745. if($this->IsForeignKey($this->GetFieldName($c))){
  2746. echo $this->nbsp.$this->GetForeignKeyInput($row[$this->GetFieldOffset($this->primary_key)], $this->GetFieldName($c), $row[$c],"view").$this->nbsp;
  2747. }else{
  2748. echo $this->nbsp.trim($row[$c]).$this->nbsp;
  2749. }
  2750. $this->ColClose();
  2751. }
  2752. }
  2753. }
  2754. }
  2755. $row_id = ($this->GetFieldOffset($this->primary_key) != "-1") ? $row[$this->GetFieldOffset($this->primary_key)] : $this->GetFieldOffset($this->primary_key);
  2756. if(isset($this->modes['details'][$this->mode]) && $this->modes['details'][$this->mode]){
  2757. $curr_url = $this->CombineUrl("details", $row_id);
  2758. $this->SetUrlString($curr_url, "filtering", "sorting", "paging");
  2759. $this->ColOpen("center",0,"nowrap");
  2760. $this->DrawModeButton("details", $curr_url, $this->lang['details'], $this->lang['view_details'], "details.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$curr_url."';\"", false, $this->nbsp, "");
  2761. $this->ColClose();
  2762. }
  2763. if(isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode]){
  2764. $curr_url = $this->CombineUrl("delete", $row_id);
  2765. $this->SetUrlString($curr_url, "filtering", "sorting", "paging");
  2766. $this->ColOpen("center",0,"nowrap");
  2767. $this->DrawModeButton("delete", $curr_url, $this->lang['delete'], $this->lang['delete_record'], "delete.gif", "\"return ".$this->uniquePrefix."verifyDelete('$curr_url');\"", false, "", "");
  2768. $this->ColClose();
  2769. }
  2770. if(($this->mode == "edit") && (intval($this->rid) == intval($row[$this->GetFieldOffset($this->primary_key)]))){ echo "</form>"; }
  2771. $this->RowClose();
  2772. }
  2773. // *** END ROWS --------------------------------------------------------
  2774. // draw summarizing row
  2775. if($r != $this->row_lower){ $this->DrawSummarizeRow($r); }
  2776. $this->TblClose();
  2777. // draw empty table
  2778. if($r == $this->row_lower){ $this->NoDataFound(); }
  2779. $this->ScrollDivClose();
  2780. $this->DrawMultiRowBar($r, $curr_url); // draw multi-row row footer cell
  2781. if($this->paging_allowed) $this->PagingSecondPart($this->lower_paging, true, true, "Lower");
  2782. // draw hide DG close div
  2783. $this->HideDivClose();
  2784. echo "<script type='text/javascript'>\n<!--\n document.getElementById('".$this->unique_random_prefix."loading_image').style.display='none'; \n//-->\n</script>";
  2785. if(($this->first_field_focus_allowed) && ($first_field_name != "")) echo "<script type='text/javascript'>\n<!--\n document.".$this->uniquePrefix."frmEditRow.".$this->GetFieldRequiredType($first_field_name).$first_field_name.".focus(); \n//-->\n</script>";
  2786. }
  2787. //--------------------------------------------------------------------------
  2788. // draw in columnar layout
  2789. //--------------------------------------------------------------------------
  2790. protected function DrawColumnar(){
  2791. $r = ""; //???
  2792. $req_print = $this->GetVariable('print');
  2793. $req_mode = ($this->mode_after_update == "") ? $this->GetVariable('mode') : $this->mode_after_update;
  2794. $this->ExportTo();
  2795. $this->ShowCaption($this->caption);
  2796. $this->DrawControlPanel();
  2797. if((($req_mode !== "add") && ($req_mode !== "details")) || ($req_mode == "")) $this->PagingFirstPart();
  2798. $this->DisplayMessages();
  2799. if(isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode]){
  2800. $this->TblOpen();
  2801. $this->RowOpen($r, $this->rowColor[0]);
  2802. $curr_url = $this->CombineUrl("add", "-1");
  2803. $this->SetUrlString($curr_url, "filtering", "sorting", "paging");
  2804. $this->MainColOpen("center",0,"nowrap", "", $this->css_class."_class_th_normal");
  2805. $this->DrawModeButton("add", $curr_url, $this->lang['add_new'], $this->lang['add_new'], "add.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$curr_url."';\"", true, "", "");
  2806. $this->MainColClose();
  2807. $this->RowClose();
  2808. $this->TblClose();
  2809. }
  2810. if($this->paging_allowed) $this->PagingSecondPart($this->upper_paging, false, true, "Upper");
  2811. //prepare action url for the form
  2812. $curr_url = $this->CombineUrl("update", $this->rid, $this->amp);
  2813. $this->SetUrlString($c_curr_url, "filtering", "sorting", "paging", $this->amp);
  2814. $curr_url .= $c_curr_url;
  2815. if($req_mode === "add") {
  2816. $curr_url .= $this->amp.$this->uniquePrefix."new=1";
  2817. }
  2818. echo "<div id='".$this->unique_random_prefix."loading_image'><br><table align='center'><tr><td valign='middle'>".$this->lang['loading_data']."</td><td valign='middle'><img src='".$this->directory."images/common/loading.gif'></td></tr></table></div>";
  2819. echo "<form name='".$this->uniquePrefix."frmEditRow' id='".$this->uniquePrefix."frmEditRow' method='post' action='".$curr_url."'>".chr(13);
  2820. echo "<input type='hidden' name='".$this->uniquePrefix."_operation_randomize_code' value='".$this->GetRandomString(20)."'>".chr(13);
  2821. $this->TblOpen();
  2822. // draw header
  2823. $this->RowOpen($r);
  2824. $this->MainColOpen("center",0,"nowrap","32%", (($req_print == true) ? $this->css_class."_class_td" : $this->css_class."_class_th")); echo "<b>".(($this->field_header != "") ? $this->field_header : $this->lang['field'])."</b>"; $this->MainColClose();
  2825. $this->MainColOpen("center",0,"nowrap","68%", (($req_print == true) ? $this->css_class."_class_td" : $this->css_class."_class_th")); echo "<b>".(($this->field_value_header != "") ? $this->field_value_header : $this->lang['field_value'])."</b>"; $this->MainColClose();
  2826. $this->RowClose();
  2827. // set number of showing rows on the page
  2828. if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "1") && ($this->mode == "edit")){
  2829. if($this->multi_rows > 0){
  2830. $this->req_page_size = $this->multi_rows;
  2831. }else{
  2832. $this->req_page_size = 1;
  2833. }
  2834. }else if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "1") && ($this->mode == "details")){
  2835. if($this->multi_rows > 0){
  2836. $this->req_page_size = $this->multi_rows;
  2837. }else{
  2838. $this->req_page_size = 1;
  2839. }
  2840. }else if(($this->layouts['view'] == "1") && ($this->layouts['edit'] == "1") && ($this->mode == "edit")){
  2841. $this->req_page_size = 1; // ???
  2842. }else if(($this->layouts['edit'] == "1") && ($this->mode == "details")){
  2843. $this->req_page_size = 1;
  2844. }
  2845. $first_field_name = ""; /* we need it to set a focus on this field */
  2846. // draw rows in ADD MODE
  2847. if($this->rid == -1){
  2848. foreach($this->columns_edit_mode as $key => $val){
  2849. if(($first_field_name == "") && (($this->mode === "edit") || ($this->mode === "add"))) $first_field_name = $key;
  2850. if($r % 2 == 0) $this->RowOpen($r, $this->rowColor[0]);
  2851. else $this->RowOpen($r, $this->rowColor[1]);
  2852. if($key == "delimiter"){
  2853. $this->ColOpen(($this->direction == "rtl")?"right":"left",2,"nowrap");
  2854. echo $this->GetFieldProperty("delimiter", "inner_html");
  2855. $this->ColClose();
  2856. }else if($key == "validator"){
  2857. $field_property_for_field = $this->GetFieldProperty("validator", "for_field");
  2858. $field_property_header = $this->GetFieldProperty("validator", "header");
  2859. $field_property_req_type = $this->GetFieldProperty("validator", "req_type");
  2860. // column's header
  2861. $this->ColOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2862. echo $this->nbsp;echo "<b>".ucfirst($field_property_header)."</b>";
  2863. $this->ColClose();
  2864. // column's data
  2865. $col_align = ($this->direction == "rtl")?"right":"left";
  2866. $this->ColOpen($col_align,0,"nowrap");
  2867. echo $this->GetFieldValueByType('', 0, '', $field_property_for_field, $field_property_req_type);
  2868. $this->ColClose();
  2869. }else if($this->GetFieldProperty($key, "type") == "hidden"){
  2870. echo $this->GetFieldValueByType('', 0, '', $key);
  2871. }else{
  2872. // column's header
  2873. $this->ColOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2874. echo $this->nbsp;echo "<b>".ucfirst($this->GetHeaderName($key))."</b>";
  2875. $this->ColClose();
  2876. // column's data
  2877. $col_align = ($this->direction == "rtl")?"right":"left";
  2878. $this->ColOpen($col_align,0,"nowrap");
  2879. if($this->IsForeignKey($key)){
  2880. echo $this->nbsp.$this->GetForeignKeyInput(-1, $key, '-1', "edit").$this->nbsp;
  2881. }else{
  2882. echo $this->GetFieldValueByType('', 0, '', $key);
  2883. }
  2884. $this->ColClose();
  2885. }
  2886. $this->RowClose();
  2887. }
  2888. }
  2889. // *** START DRAWING ROWS ----------------------------------------------
  2890. for($r = $this->row_lower; (($this->rid != -1) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  2891. $row = $this->data_set->fetchRow();
  2892. // draw column headers
  2893. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2894. // get current column's index (offset)
  2895. $c = $this->sorted_columns[$c_sorted];
  2896. if($r % 2 == 0) $this->RowOpen($r, $this->rowColor[0]);
  2897. else $this->RowOpen($r, $this->rowColor[1]);
  2898. if($this->CanViewField($this->GetFieldName($c))){
  2899. if($this->GetFieldProperty($this->GetFieldName($c), "type") == "hidden"){
  2900. echo $this->GetFieldValueByType('', 0, '', $this->GetFieldName($c));
  2901. }else{
  2902. if(($first_field_name == "") && (($this->mode === "edit") || ($this->mode === "add"))) $first_field_name = $this->GetFieldName($c);
  2903. // column headers
  2904. if(($this->mode === "view") && ($this->CanViewField($this->GetFieldName($c)))){
  2905. $this->ColOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2906. echo $this->nbsp;echo "<b>".ucfirst($this->GetHeaderName($this->GetFieldName($c)))."</b>";
  2907. $this->ColClose();
  2908. }else if(($this->mode === "edit") && ($this->CanViewField($this->GetFieldName($c)))){
  2909. $this->ColOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2910. echo $this->nbsp;echo "<b>".ucfirst($this->GetHeaderName($this->GetFieldName($c)))."</b>";
  2911. $this->ColClose();
  2912. }else if(($this->mode === "details") && ($this->CanViewField($this->GetFieldName($c)))){
  2913. $this->ColOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2914. echo $this->nbsp;echo "<b>".ucfirst($this->GetHeaderName($this->GetFieldName($c)))."</b>";
  2915. $this->ColClose();
  2916. }
  2917. // column data
  2918. $col_align = ($this->direction == "rtl") ? "right" : "left";
  2919. if(($this->mode === "view") && ($this->CanViewField($this->GetFieldName($c)))){
  2920. $field_property_wrap = $this->GetFieldProperty($this->GetFieldName($c), "wrap", "view");
  2921. $this->ColOpen($col_align, 0, $field_property_wrap);
  2922. echo $this->GetFieldValueByType($row[$c], $c, $row);
  2923. $this->ColClose();
  2924. }else if(($this->mode === "details") && ($this->CanViewField($this->GetFieldName($c)))){
  2925. $this->ColOpen($col_align,0);
  2926. if($this->IsForeignKey($this->GetFieldName($c))){
  2927. echo $this->GetForeignKeyInput($row[$this->GetFieldOffset($this->primary_key)], $this->GetFieldName($c), $row[$c],"view");
  2928. }else{
  2929. echo $this->GetFieldValueByType($row[$c], $c, $row);
  2930. }
  2931. $this->ColClose();
  2932. }else if(($this->mode === "edit") && ($this->CanViewField($this->GetFieldName($c)))){
  2933. // if we have multi-rows selected
  2934. // mr_2
  2935. if($this->multi_rows > 0){
  2936. $rid_value = $this->rids[$r];
  2937. }else{
  2938. $rid_value = $this->rid;
  2939. }
  2940. $ind = ($this->GetFieldOffset($this->primary_key) != -1) ? $this->GetFieldOffset($this->primary_key) : 0;
  2941. if(intval($rid_value) === intval($row[$ind])){
  2942. $this->ColOpen($col_align,0,"nowrap");
  2943. if($this->IsForeignKey($this->GetFieldName($c))){
  2944. echo $this->nbsp.$this->GetForeignKeyInput($row[$ind], $this->GetFieldName($c), $row[$c], "edit").$this->nbsp;
  2945. }else{
  2946. echo $this->GetFieldValueByType($row[$c], $c, $row);
  2947. }
  2948. $this->ColClose();
  2949. }else{
  2950. $this->ColOpen($col_align,0,"nowrap");
  2951. if($this->rid == -1){
  2952. // add new row
  2953. if($this->IsForeignKey($this->GetFieldName($c))){
  2954. echo $this->nbsp.$this->GetForeignKeyInput(-1, $this->GetFieldName($c), '-1', "edit").$this->nbsp;
  2955. }else{
  2956. echo $this->GetFieldValueByType('', $c, $row);
  2957. }
  2958. }else{
  2959. if($this->IsForeignKey($this->GetFieldName($c))){
  2960. echo $this->nbsp.$this->GetForeignKeyInput($row[$this->GetFieldOffset($this->primary_key)], $this->GetFieldName($c), $row[$c],"view").$this->nbsp;
  2961. }else{
  2962. echo $this->nbsp.trim($row[$c]).$this->nbsp;
  2963. }
  2964. }
  2965. $this->ColClose();
  2966. }
  2967. }
  2968. }
  2969. }else{
  2970. if($this->mode != "details"){
  2971. $ind = 0;
  2972. foreach($this->columns_edit_mode as $key => $val){
  2973. if($ind == $c_sorted){
  2974. if($key == "validator"){ // customized rows (validator)
  2975. $field_property_for_field = $this->GetFieldProperty($key, "for_field");
  2976. $field_property_header = $this->GetFieldProperty($key, "header");
  2977. $field_property_req_type = $this->GetFieldProperty($key, "req_type");
  2978. $this->ColOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2979. echo $this->nbsp;echo "<b>".ucfirst($field_property_header)."</b>";
  2980. $this->ColClose();
  2981. $field_property_wrap = $this->GetFieldProperty($this->GetFieldName($c), "wrap", "view");
  2982. $this->ColOpen($col_align, 0, $field_property_wrap);
  2983. $field_property_for_field_offset = $this->GetFieldOffset($field_property_for_field);
  2984. if($field_property_for_field_offset != "-1") echo $this->GetFieldValueByType($row[$field_property_for_field_offset], $field_property_for_field_offset, $row, "", $field_property_req_type);
  2985. $this->ColClose();
  2986. }else if($key == "delimiter"){ // customized rows (delimiter)
  2987. $this->ColOpen("",2,"nowrap");
  2988. echo $this->GetFieldProperty("delimiter", "inner_html");
  2989. $this->ColClose();
  2990. }
  2991. }
  2992. $ind++;
  2993. }
  2994. }
  2995. }
  2996. $this->RowClose();
  2997. }// for
  2998. }
  2999. // *** END DRAWING ROWS ------------------------------------------------
  3000. $this->TblClose();
  3001. echo "<br>";
  3002. if(($r == $this->row_lower) && ($this->rid != -1)){
  3003. $this->NoDataFound();
  3004. echo "<br><center>";
  3005. if($req_print != ""){
  3006. echo "<span class='".$this->css_class."_class_a'><b>".$this->lang['back']."</b></span>";
  3007. }else{
  3008. echo "<a class='".$this->css_class."_class_a' href='javascript:history.go(-1);'><b>".$this->lang['back']."</b></a>";
  3009. }
  3010. echo "</center>";
  3011. }else{
  3012. $this->TblOpen();
  3013. $this->RowOpen($r, $this->rowColor[1]);
  3014. $this->MainColOpen('left', 0, '', '', (($req_print == true) ? $this->css_class."_class_td_normal" : $this->css_class."_class_th"), "style='BORDER-RIGHT: #d2d0bb 0px solid;'");
  3015. if($this->mode === "details"){
  3016. $cancel_url = ($this->GetFieldOffset($this->primary_key) != "-1") ? $this->CombineUrl("cancel", $row[$this->GetFieldOffset($this->primary_key)]) : $this->CombineUrl("cancel", "");
  3017. $this->SetUrlString($c_curr_url, "filtering", "sorting", "paging");
  3018. $cancel_url .= $c_curr_url;
  3019. echo "<div style='float:";
  3020. echo ($this->direction == "rtl")?"left":"right";
  3021. if($req_print != ""){
  3022. echo ";'><span class='".$this->css_class."_class_a'><b>".$this->lang['back']."</b></span></div>";
  3023. }else{
  3024. echo ";'>";
  3025. echo $this->DrawModeButton("cancel", $cancel_url, $this->lang['back'], $this->lang['back'], "cancel.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, "", "");
  3026. echo "</div>";
  3027. }
  3028. }else{
  3029. // if not new row
  3030. $ind = ($this->GetFieldOffset($this->primary_key) != -1) ? $this->GetFieldOffset($this->primary_key) : 0;
  3031. if(($this->rid != -1) && isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode]){
  3032. $curr_url = $this->CombineUrl("delete", $row[$ind]);
  3033. $this->SetUrlString($curr_url, "filtering", "sorting", "paging");
  3034. $this->DrawModeButton("delete", $curr_url, $this->lang['delete'], $this->lang['delete_record'], "delete.gif", "\"return ".$this->uniquePrefix."verifyDelete('$curr_url');\"", true, "", "");
  3035. }
  3036. if($this->rid != -1){
  3037. $rid = $row[$ind];
  3038. }else{
  3039. $rid = -1;
  3040. }
  3041. $curr_url = $this->CombineUrl("update", $rid);
  3042. $cancel_url = $this->CombineUrl("cancel", $rid);
  3043. $this->SetUrlString($c_curr_url, "filtering", "sorting", "paging");
  3044. $cancel_url .= $c_curr_url;
  3045. $curr_url .= $c_curr_url;
  3046. if(isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]){
  3047. if($req_mode === "add") { $cancel_url .= $this->amp.$this->uniquePrefix."new=1";}
  3048. $this->SetEditFieldsFormScript();
  3049. echo "<div style='float:"; echo ($this->direction == "rtl")?"left":"right"; echo ";'>";
  3050. if($req_mode === "add") {
  3051. if($this->rid == -1){
  3052. $cancel_url = $this->CombineUrl("cancel", $rid);
  3053. }else{
  3054. $cancel_url = $this->CombineUrl("delete", $rid);
  3055. }
  3056. $this->SetUrlString($cancel_url, "filtering", "sorting", "paging");
  3057. $this->DrawModeButton("cancel", $cancel_url, $this->lang['cancel'], $this->lang['cancel'], "cancel.gif", "\"return ".$this->uniquePrefix."verifyCancel('$cancel_url'); javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, $this->nbsp, "");
  3058. }else{
  3059. $this->DrawModeButton("cancel", $cancel_url, $this->lang['cancel'], $this->lang['cancel'], "cancel.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, $this->nbsp, "");
  3060. }
  3061. echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  3062. if($this->rid == -1){ //aaa new record
  3063. $this->DrawModeButton("edit", "#", $this->lang['create'], $this->lang['create_new_record'], "update.gif", "\"".$this->uniquePrefix."sendEditFields(); return false;\"", false, $this->nbsp, "");
  3064. }else{
  3065. $this->DrawModeButton("edit", "#", $this->lang['update'], $this->lang['update_record'], "update.gif", "\"".$this->uniquePrefix."sendEditFields(); return false;\"", false, $this->nbsp, "");
  3066. }
  3067. echo "</div>";
  3068. }else{
  3069. if(isset($this->modes['cancel'][$this->mode]) && $this->modes['cancel'][$this->mode]){
  3070. echo "<div style='float:"; echo ($this->direction == "rtl")?"left":"right"; echo ";'>";
  3071. $this->DrawModeButton("cancel", $cancel_url, $this->lang['back'], $this->lang['back'], "cancel.gif", "\"\"", false, $this->nbsp, "");
  3072. echo "</div>";
  3073. }
  3074. }
  3075. }
  3076. $this->MainColClose();
  3077. $this->RowClose();
  3078. $this->TblClose();
  3079. }
  3080. echo "</form>";
  3081. echo "<script type='text/javascript'>\n<!--\n document.getElementById('".$this->unique_random_prefix."loading_image').style.display='none'; \n//-->\n</script>";
  3082. if($this->paging_allowed) $this->PagingSecondPart($this->lower_paging, true, true, "Lower");
  3083. if(($this->first_field_focus_allowed) && ($first_field_name != "")) echo "<script type='text/javascript'>\n<!--\n document.".$this->uniquePrefix."frmEditRow.".$this->GetFieldRequiredType($first_field_name).$first_field_name.".focus(); \n//-->\n</script>";
  3084. }
  3085. //--------------------------------------------------------------------------
  3086. // draw Multi-Row Bar
  3087. //--------------------------------------------------------------------------
  3088. protected function DrawMultiRowBar($r, $curr_url){
  3089. $req_print = $this->GetVariable('print');
  3090. $horizontal_align = ($this->tblAlign[$this->mode] == "center") ? "margin-left: auto; margin-right: auto;" : "";
  3091. if(($this->multirow_allowed) && ($r != $this->row_lower)){
  3092. echo "<script type='text/javascript'>\n<!--\n
  3093. function ".$this->uniquePrefix."verifySelected(param, button_type, flag_name, flag_value){
  3094. if(confirm('Are you sure you want to carry out this operation?')){
  3095. selected_rows = '&".$this->uniquePrefix."rid=';
  3096. selected_rows_ids = '';
  3097. found = 0;
  3098. for(i=".$this->row_lower."; i < ".$this->row_upper."; i++){
  3099. if(document.getElementById(\"".$this->uniquePrefix."checkbox_\"+i).checked == true){
  3100. if(found == 1){ selected_rows_ids += '-'; }
  3101. selected_rows_ids += document.getElementById(\"".$this->uniquePrefix."checkbox_\"+i).value;
  3102. found = 1;
  3103. }
  3104. }
  3105. if(found){
  3106. document_location_href = param+selected_rows+selected_rows_ids;
  3107. if(flag_name != ''){
  3108. found = (document_location_href.indexOf(flag_name) != -1);
  3109. if(!found){
  3110. document_location_href += '&'+flag_name+'='+flag_value;
  3111. }
  3112. }
  3113. document.location.href = document_location_href;
  3114. }else{
  3115. alert('You need to select one or more rows to carry out this operation!');
  3116. return false;
  3117. }
  3118. }
  3119. };
  3120. function ".$this->uniquePrefix."setCheckboxes(check){
  3121. if(check){
  3122. for(i=".$this->row_lower."; i < ".$this->row_upper."; i++){
  3123. document.getElementById('".$this->uniquePrefix."checkbox_'+i).checked = true;
  3124. document.getElementById('".$this->uniquePrefix."row_'+i).style.background = '".$this->rowColor[5]."';
  3125. }
  3126. }else{
  3127. for(i=".$this->row_lower."; i < ".$this->row_upper."; i++){
  3128. document.getElementById('".$this->uniquePrefix."checkbox_'+i).checked = false;
  3129. if((i % 2) == 0) row_color_back = '".$this->rowColor[0]."';
  3130. else row_color_back = '".$this->rowColor[1]."';
  3131. document.getElementById('".$this->uniquePrefix."row_'+i).style.background = row_color_back;
  3132. }
  3133. }
  3134. }
  3135. \n//-->\n</script>
  3136. ";
  3137. echo "<table dir='".$this->direction."' border='0' style='".$horizontal_align."' width='".$this->tblWidth[$this->mode]."'>";
  3138. echo "<tr>";
  3139. echo "<td align='left'>";
  3140. echo "<table border='0'>
  3141. <tr>
  3142. <td align='left' valign='middle' class='class_nowrap'>";
  3143. $count = 0;
  3144. foreach($this->multirow_operations_array as $key => $val){
  3145. if($this->multirow_operations_array[$key]['view']) $count++;
  3146. }
  3147. if($count > 0){
  3148. echo "<img style='PADDING:0px; MARGIN:0px; border:0px;' src='".$this->directory."images/".$this->css_class."/arrow_ltr.png' width='38' height='22' alt='".$this->lang['with_selected'].":' title='".$this->lang['with_selected'].":'>";
  3149. if(!$req_print){
  3150. echo "<a class='".$this->css_class."_class_a' href='javascript:void(0);' onClick='".$this->uniquePrefix."setCheckboxes(true); return false;'>".$this->lang['check_all']."</a>
  3151. &nbsp;/&nbsp;
  3152. <a class='".$this->css_class."_class_a' href='javascript:void(0);' onClick='".$this->uniquePrefix."setCheckboxes(false); return false;'>".$this->lang['uncheck_all']."</a>";
  3153. }else{
  3154. echo "<a class='".$this->css_class."_class_label'>".$this->lang['check_all']."</label>
  3155. &nbsp;/&nbsp;
  3156. <a class='".$this->css_class."_class_label'>".$this->lang['uncheck_all']."</label>";
  3157. }
  3158. echo "
  3159. &nbsp;&nbsp;&nbsp;
  3160. <label class='".$this->css_class."_class_label'><i>".$this->lang['with_selected'].":</i></label>&nbsp;&nbsp;
  3161. </td>
  3162. <td align='left' valign='bottom' >";
  3163. foreach($this->multirow_operations_array as $key => $val){
  3164. if($this->multirow_operations_array[$key]['view']){
  3165. echo "&nbsp;";
  3166. $curr_url = $this->CombineUrl($key, "");
  3167. $flag_name = isset($val['flag_name']) ? $val['flag_name'] : "";
  3168. $flag_value = isset($val['flag_value']) ? $val['flag_value'] : "";
  3169. $tooltip = isset($val['tooltip']) ? $val['tooltip'] : $this->lang[$key.'_selected'];
  3170. $image = isset($val['image']) ? $val['image'] : $key.".gif" ;
  3171. $this->SetUrlString($curr_url, "filtering", "sorting", "paging");
  3172. $this->DrawModeButton($key, $curr_url, $tooltip, $tooltip, $image, "\"return ".$this->uniquePrefix."verifySelected('$curr_url', '$key', '$flag_name', '$flag_value');\"", false, "", "image");
  3173. echo "&nbsp;";
  3174. }
  3175. }
  3176. }
  3177. echo "
  3178. </td>
  3179. </tr>
  3180. </table>
  3181. ";
  3182. echo "</td>";
  3183. echo "</tr>";
  3184. echo "</table>";
  3185. }
  3186. }
  3187. //--------------------------------------------------------------------------
  3188. // draw Summarize Row
  3189. //--------------------------------------------------------------------------
  3190. protected function DrawSummarizeRow($r){
  3191. if(count($this->summarize_columns) > 0){
  3192. $this->RowOpen("", $this->rowColor[0]);
  3193. // draw multi-row row footer cell
  3194. if($this->multirow_allowed){
  3195. $this->ColOpen("center",0,"nowrap","","");
  3196. echo $this->nbsp;
  3197. $this->ColClose();
  3198. }
  3199. // draw column headers in view mode
  3200. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  3201. // get current column's index (offset)
  3202. $c = $this->sorted_columns[$c_sorted];
  3203. if($c_sorted == $this->col_lower){
  3204. if((isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode]) ||
  3205. (isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]))
  3206. {
  3207. $this->ColOpen("center",0,"nowrap",$this->rowColor[2], $this->css_class."_class_td_main");
  3208. echo "<a class='".$this->css_class."_class_a'><b>".$this->lang['total'].":</b></a>";
  3209. $this->ColClose();
  3210. }
  3211. if($this->rows_numeration){
  3212. $this->ColOpen("center",0,"nowrap"); echo ""; $this->ColClose();
  3213. }
  3214. }
  3215. if($this->CanViewField($this->GetFieldName($c))){
  3216. $this->ColOpen("right",0,"nowrap");
  3217. $field_property_summarize = $this->GetFieldProperty($this->GetFieldName($c), "summarize", "view");
  3218. if(($field_property_summarize == "true") || ($field_property_summarize === true)){
  3219. echo $this->nbsp."=".$this->nbsp."<a class='".$this->css_class."_class_a'><b>".number_format($this->summarize_columns[$this->GetFieldName($c)], 2)."</b></a>";
  3220. }
  3221. $this->ColClose();
  3222. }
  3223. }
  3224. if((isset($this->modes['details'][$this->mode]) && $this->modes['details'][$this->mode])){
  3225. $this->ColOpen("right",0,"nowrap");$this->ColClose();
  3226. }
  3227. if((isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode])){
  3228. $this->ColOpen("right",0,"nowrap");$this->ColClose();
  3229. }
  3230. $this->RowClose();
  3231. }
  3232. }
  3233. //--------------------------------------------------------------------------
  3234. // sort columns by mode order
  3235. //--------------------------------------------------------------------------
  3236. protected function SortColumns($mode = ""){
  3237. if($mode == "view"){
  3238. foreach($this->columns_view_mode as $fldName => $fldValue){
  3239. $this->sorted_columns[] = $this->GetFieldOffset($fldName);
  3240. }
  3241. }else if(($mode == "edit") || ($mode == "details")){
  3242. if(isset($this->columns_edit_mode) && is_array($this->columns_edit_mode)){
  3243. foreach($this->columns_edit_mode as $fldName => $fldValue){
  3244. $this->sorted_columns[] = $this->GetFieldOffset($fldName);
  3245. }
  3246. }
  3247. }
  3248. }
  3249. //--------------------------------------------------------------------------
  3250. // add error to array of errors
  3251. //--------------------------------------------------------------------------
  3252. protected function AddErrors($dSet = ""){
  3253. if($this->debug){
  3254. if($dSet == "") $dSet = $this->data_set;
  3255. $this->errors[] = $dSet->getDebugInfo();
  3256. }
  3257. }
  3258. //--------------------------------------------------------------------------
  3259. // add warning to array of warnings
  3260. //--------------------------------------------------------------------------
  3261. protected function AddWarning($warning_field = "", $warning_value = "", $str_warning = ""){
  3262. if($this->debug){
  3263. if($str_warning != ""){
  3264. $this->warnings[] = $str_warning;
  3265. }else{
  3266. $warning = str_replace('_FIELD_', $warning_field, $this->lang['wrong_parameter_error']);
  3267. $warning = str_replace('_VALUE_', $warning_value, $warning);
  3268. $this->warnings[] = $warning;
  3269. }
  3270. }
  3271. }
  3272. //--------------------------------------------------------------------------
  3273. // display warnings
  3274. //--------------------------------------------------------------------------
  3275. protected function DisplayWarnings(){
  3276. if($this->debug){
  3277. $count = 0;
  3278. if(count($this->warnings) > 0){
  3279. echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left'>";
  3280. echo "<font class='".$this->css_class."_class_error_message no_print class_underlined'><b>".$this->lang['warnings']."</b>:</font><br><br>";
  3281. foreach($this->warnings as $key){
  3282. echo "<font class='".$this->css_class."_class_error_message no_print'>".(++$count).") $key</font><br>";
  3283. }
  3284. echo "<br>";
  3285. echo "</td></tr></table>";
  3286. }
  3287. }
  3288. }
  3289. //--------------------------------------------------------------------------
  3290. // display errors
  3291. //--------------------------------------------------------------------------
  3292. protected function DisplayErrors(){
  3293. if($this->debug){
  3294. $count = 0;
  3295. if(count($this->errors) > 0){
  3296. echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left'>";
  3297. echo "<font class='".$this->css_class."_class_error_message no_print class_underlined'><b>".$this->lang['errors']."</b>:</font><br><br>";
  3298. foreach($this->errors as $key){
  3299. echo "<font class='".$this->css_class."_class_error_message no_print'>".(++$count).") </font>";
  3300. echo "<font class='".$this->css_class."_class_label'>".substr($key, 0, strpos($key, "["))."</font><br>";
  3301. echo "<font class='".$this->css_class."_class_error_message no_print'>".stristr($key, "[")."</font><br><br>";
  3302. }
  3303. echo "<br>";
  3304. echo "</td></tr></table>";
  3305. }
  3306. }
  3307. }
  3308. //--------------------------------------------------------------------------
  3309. // draw data sent by POST and GET
  3310. //--------------------------------------------------------------------------
  3311. protected function DisplayDataSent(){
  3312. if($this->debug){
  3313. print_r("<font class='".$this->css_class."_class_ok_message no_print'><b>POST</b>: ");
  3314. print_r($_POST);
  3315. print_r("</font><br><br>");
  3316. print_r("<font class='".$this->css_class."_class_ok_message no_print'><b>GET</b>: ");
  3317. print_r($_GET);
  3318. print_r("</font><br><br>");
  3319. }
  3320. }
  3321. //--------------------------------------------------------------------------
  3322. // draw messages
  3323. //--------------------------------------------------------------------------
  3324. protected function DisplayMessages(){
  3325. if($this->messaging && $this->act_msg){
  3326. $css_class = "".$this->css_class."_class_ok_message";
  3327. if($this->is_error) $css_class= "".$this->css_class."_class_error_message no_print";
  3328. if($this->is_warning) $css_class= "".$this->css_class."_class_error_message no_print";
  3329. echo "<div style='margin-top:10px;margin-bottom:10px;'><center><font class='".$css_class."'>".$this->act_msg."</font></center></div>";
  3330. $this->act_msg = "";
  3331. }
  3332. }
  3333. //--------------------------------------------------------------------------
  3334. // save Http Get Vars
  3335. //--------------------------------------------------------------------------
  3336. protected function SaveHttpGetVars(){
  3337. echo "<div style='padding:0px; margin:0px;'>";
  3338. if(is_array($this->http_get_vars) && (count($this->http_get_vars) > 0)){
  3339. foreach($this->http_get_vars as $key){
  3340. echo "<input type='hidden' name='".$key."' id='".$key."' value='".((isset($_REQUEST[$key]))?$_REQUEST[$key]:"")."'>";
  3341. }
  3342. }
  3343. echo "<input type='hidden' name='".$this->uniquePrefix."page_size' id='".$this->uniquePrefix."page_size' value='".((isset($_REQUEST[$this->uniquePrefix.'page_size']))?$_REQUEST[$this->uniquePrefix.'page_size']:$this->req_page_size)."'>\n";
  3344. echo "<input type='hidden' name='".$this->uniquePrefix."sort_field' id='".$this->uniquePrefix."sort_field' value='".((isset($_REQUEST[$this->uniquePrefix.'sort_field']))?$_REQUEST[$this->uniquePrefix.'sort_field']:"")."'>\n";
  3345. echo "<input type='hidden' name='".$this->uniquePrefix."sort_field_by' id='".$this->uniquePrefix."sort_field_by' value='".((isset($_REQUEST[$this->uniquePrefix.'sort_field_by']))?$_REQUEST[$this->uniquePrefix.'sort_field_by']:"")."'>\n";
  3346. echo "<input type='hidden' name='".$this->uniquePrefix."sort_field_type' id='".$this->uniquePrefix."sort_field_type' value='".((isset($_REQUEST[$this->uniquePrefix.'sort_field_type']))?$_REQUEST[$this->uniquePrefix.'sort_field_type']:"")."'>\n";
  3347. echo "<input type='hidden' name='".$this->uniquePrefix."sort_type' id='".$this->uniquePrefix."sort_type' value='".((isset($_REQUEST[$this->uniquePrefix.'sort_type']))?$_REQUEST[$this->uniquePrefix.'sort_type']:"")."'>\n";
  3348. // get URL vars from another DG
  3349. if(is_array($this->another_datagrids) && (count($this->another_datagrids) > 0)){
  3350. foreach($this->another_datagrids as $key => $val){
  3351. if($val[$this->mode] == true){
  3352. foreach($_REQUEST as $r_key => $r_val){
  3353. if(strstr($r_key, $key)){ // ."_ff_"
  3354. echo "<input type='hidden' name='".$r_key."' id='".$r_key."' value='".((isset($_REQUEST[$r_key]))?$_REQUEST[$r_key]:"")."'>\n";
  3355. }
  3356. }
  3357. }
  3358. }
  3359. }
  3360. echo "</div>";
  3361. }
  3362. //--------------------------------------------------------------------------
  3363. // combine url
  3364. //--------------------------------------------------------------------------
  3365. protected function CombineUrl($mode, $rid="", $amp=""){
  3366. $amp = ($amp != "") ? $amp : $this->amp;
  3367. $ind = 0;
  3368. if(is_array($this->http_get_vars) && (count($this->http_get_vars) > 0)){
  3369. foreach($this->http_get_vars as $key){
  3370. if($ind == 0){ $a_url = "?"; $ind = 1; }
  3371. else $a_url .= $amp;
  3372. $a_url .= $key."=".((isset($_REQUEST[$key]))?$_REQUEST[$key]:"");
  3373. }
  3374. }
  3375. if($ind == 0) $a_url = "?".$this->uniquePrefix."mode=".$mode."";
  3376. else $a_url .= $amp.$this->uniquePrefix."mode=".$mode."";
  3377. if($rid !== "") $a_url .= $amp.$this->uniquePrefix."rid=".$rid;
  3378. // get URL vars from another DG
  3379. if(is_array($this->another_datagrids) && (count($this->another_datagrids) > 0)){
  3380. foreach($this->another_datagrids as $key => $val){
  3381. if($val[$this->mode] == true){
  3382. $a_url .= $amp.$key."mode=".((isset($_REQUEST[$key.'mode']))?$_REQUEST[$key.'mode']:"");
  3383. $a_url .= $amp.$key."rid=".((isset($_REQUEST[$key.'rid']))?$_REQUEST[$key.'rid']:"");
  3384. $a_url .= $amp.$key."sort_field=".((isset($_REQUEST[$key.'sort_field']))?$_REQUEST[$key.'sort_field']:"");
  3385. $a_url .= $amp.$key."sort_field_by=".((isset($_REQUEST[$key.'sort_field_by']))?$_REQUEST[$key.'sort_field_by']:"");
  3386. $a_url .= $amp.$key."sort_field_type=".((isset($_REQUEST[$key.'sort_field_type']))?$_REQUEST[$key.'sort_field_type']:"");
  3387. $a_url .= $amp.$key."sort_type=".((isset($_REQUEST[$key.'sort_type']))?$_REQUEST[$key.'sort_type']:"");
  3388. $a_url .= $amp.$key."page_size=".((isset($_REQUEST[$key.'page_size']))?$_REQUEST[$key.'page_size']:"");
  3389. $a_url .= $amp.$key."p=".((isset($_REQUEST[$key.'p']))?$_REQUEST[$key.'p']:"");
  3390. foreach($_REQUEST as $r_key => $r_val){
  3391. if(strstr($r_key, $key."_ff_")){
  3392. //d echo $r_key."=".$_REQUEST[$r_key]."<br>";
  3393. $a_url .= $amp.$r_key."=".((isset($_REQUEST[$r_key]))?$_REQUEST[$r_key]:"");
  3394. }
  3395. }
  3396. }
  3397. }
  3398. }
  3399. return $a_url;
  3400. }
  3401. //--------------------------------------------------------------------------
  3402. // set SQL limit
  3403. //--------------------------------------------------------------------------
  3404. protected function SetSqlLimit(){
  3405. $req_page_num = "";
  3406. $req_page_size = $this->GetVariable('page_size');
  3407. $req_p = $this->GetVariable('p');
  3408. if($req_page_size != "") $this->req_page_size = $req_page_size;
  3409. if($req_p != "") $req_page_num = $req_p;
  3410. if(is_numeric($req_page_num)){
  3411. if($req_page_num > 0) $this->page_current = $req_page_num;
  3412. else $this->page_current = 1;
  3413. }else{
  3414. $this->page_current = 1;
  3415. }
  3416. // if there was deleted a last rows from a last page
  3417. if(intval($this->rows_total) <= intval(($this->page_current - 1) * $this->req_page_size)){
  3418. if($this->page_current > 1){
  3419. $this->page_current--;
  3420. $_REQUEST[$this->uniquePrefix.'p'] = $this->page_current;
  3421. }
  3422. }
  3423. $this->limit_start = ($this->page_current - 1) * $this->req_page_size;
  3424. $this->limit_size = $this->req_page_size;
  3425. }
  3426. //--------------------------------------------------------------------------
  3427. // set SQL limit by DB type
  3428. //--------------------------------------------------------------------------
  3429. protected function SetSqlLimitByDbType($limit_start="", $limit_size=""){
  3430. $this->SetSqlLimit();
  3431. if($limit_start == "") $limit_start = $this->limit_start;
  3432. if($limit_size == "") $limit_size = $this->limit_size;
  3433. $limit_string = "";
  3434. switch($this->db_handler->phptype){
  3435. case "oci8": // oracle
  3436. $limit_string = "AND (rownum > ".$limit_start." AND rownum <= ".intval($limit_start + $limit_size).") ";
  3437. break;
  3438. case "mssql": // mssql
  3439. $limit_string = "AND RowNumber > ".$limit_start." AND RowNumber < ".intval($limit_start + $limit_size).") ";
  3440. break;
  3441. case "pgsql": // Postgresql
  3442. $limit_string = "OFFSET ".$limit_start." LIMIT ".$limit_size." ";
  3443. break;
  3444. case "mysql": // mysql and others
  3445. default:
  3446. $limit_string = "LIMIT ".$limit_start.", ".$limit_size." ";
  3447. break;
  3448. }
  3449. return $limit_string;
  3450. }
  3451. //--------------------------------------------------------------------------
  3452. // set real escape string by DB type
  3453. //--------------------------------------------------------------------------
  3454. protected function SetRealEscapeStringByDbType($field_value = ""){
  3455. switch($this->db_handler->phptype){
  3456. case "mysql": // mysql
  3457. return mysql_real_escape_string($field_value); break;
  3458. default:
  3459. return $field_value; break;
  3460. }
  3461. }
  3462. //--------------------------------------------------------------------------
  3463. // set SQL by DB type
  3464. //--------------------------------------------------------------------------
  3465. protected function SetSqlByDbType($sql="", $order_by="", $limit=""){
  3466. $sql_string = "";
  3467. switch($this->db_handler->phptype){
  3468. case "oci8": // oracle
  3469. if($limit != ""){
  3470. preg_match_all("/\d+/",$limit,$matches);
  3471. $limit_start = $matches[0][0];
  3472. $limit_size = $matches[0][1]-$limit_start;
  3473. $sql_string = $this->db_handler->modifyLimitQuery($sql." ".$order_by, $limit_start, $limit_size);
  3474. if($this->debug) echo "<table><tr><td><b>Oracle sql: </b>".$sql_string."</td></tr></table><br>";
  3475. }else{
  3476. $sql_string = $sql." ".$order_by;
  3477. }
  3478. break;
  3479. case "mssql": // mssql
  3480. //d (10.01.2008) $sql_string = "SELECT ".$limit." ".substr($sql, strpos("select", $this->StrToLower($sql))+7, strlen($sql))." ".$order_by;
  3481. $from_index = strpos($this->StrToLower($sql), "from ");
  3482. $prefix = substr($sql, 0, $from_index);
  3483. $suffix = substr($sql, $from_index);
  3484. $sql_string = $prefix.", Row_Number() over (ORDER BY ".$this->primary_key.") AS RowNumber ".$suffix;
  3485. $sql_string += " ".$limit." ".$order_by;
  3486. break;
  3487. case "mysql": // mysql and others
  3488. default:
  3489. $sql_string = $sql." ".$order_by." ".$limit;
  3490. break;
  3491. }
  3492. return $sql_string;
  3493. }
  3494. //--------------------------------------------------------------------------
  3495. // get LCASE function name by DB type
  3496. //--------------------------------------------------------------------------
  3497. protected function GetLcaseFooByDbType(){
  3498. $lcase_name = "";
  3499. switch($this->db_handler->phptype){
  3500. case "oci8": // oracle
  3501. $lcase_name = "lower"; break;
  3502. case "mssql": // mssql
  3503. $lcase_name = "LCASE"; break;
  3504. case "pgsql": // pgsql
  3505. $lcase_name = "lower"; break;
  3506. case "mysql": // mysql and others
  3507. default:
  3508. $lcase_name = "LCASE"; break;
  3509. }
  3510. return $lcase_name;
  3511. }
  3512. //--------------------------------------------------------------------------
  3513. // paging function - part 1
  3514. //--------------------------------------------------------------------------
  3515. protected function PagingFirstPart(){
  3516. // (1) if we got a wrong number of page -> set page=1
  3517. $req_page_num = "";
  3518. $req_page_size = $this->GetVariable('page_size');
  3519. $req_p = $this->GetVariable('p');
  3520. if(($req_page_size != "") && ($req_page_size != 0)) $this->req_page_size = $req_page_size;
  3521. if($req_p != "") $req_page_num = $req_p;
  3522. if(is_numeric($req_page_num)){
  3523. if($req_page_num > 0) $this->page_current = $req_page_num;
  3524. else $this->page_current = 1;
  3525. }else{
  3526. $this->page_current = 1;
  3527. }
  3528. // (2) set pages_total & page_current vars for paging
  3529. if($this->rows_total > 0){
  3530. if(is_float($this->rows_total / $this->req_page_size))
  3531. $this->pages_total = intval(($this->rows_total / $this->req_page_size) + 1);
  3532. else
  3533. $this->pages_total = intval($this->rows_total / $this->req_page_size);
  3534. }else{
  3535. $this->pages_total = 0;
  3536. }
  3537. if($this->page_current > $this->pages_total) $this->page_current = $this->pages_total;
  3538. }
  3539. //--------------------------------------------------------------------------
  3540. // paging function - part 2
  3541. //--------------------------------------------------------------------------
  3542. protected function PagingSecondPart($lu_paging=false, $upper_br, $lower_br, $type="1"){
  3543. // (4) display paging line
  3544. $req_print = $this->GetVariable('print');
  3545. if($req_print != true) {$a_tag = "a";} else {$a_tag = "span";};
  3546. $text = "";
  3547. $horizontal_align = ($this->tblAlign[$this->mode] == "center") ? "margin-left: auto; margin-right: auto;" : "";
  3548. if($this->pages_total >= 1){
  3549. $href_string = $this->CombineUrl("view", "", "&");
  3550. $this->SetUrlString($href_string, "filtering", "sorting", "");
  3551. $text .= "\n<script type='text/javascript'>\n<!--\n";
  3552. $text .= "function ".$this->uniquePrefix."setPageSize".$type."(){document.location.href = '$href_string&".$this->uniquePrefix."page_size='+document.frmPaging$this->uniquePrefix".$type.".page_size".$type.".value;}";
  3553. $text .= "\n//-->\n</script>\n";
  3554. $href_string .= $this->amp.$this->uniquePrefix."page_size=".$this->req_page_size;
  3555. $text .= "<form name='frmPaging$this->uniquePrefix".$type."' id='frmPaging$this->uniquePrefix".$type."' action='' style='MARGIN:0px; PADDING:5px; '>";
  3556. if($lu_paging['results'] || $lu_paging['pages'] || $lu_paging['page_size']){
  3557. if($upper_br) $text .= ""; //<br>
  3558. }
  3559. $text .= "<table class='".$this->css_class."_class_paging_table' dir='".$this->direction."' style='".$horizontal_align." width: ".$this->tblWidth[$this->mode].";' border='0' >";
  3560. $text .= "<tr><td align='".$lu_paging['results_align']."' class='class_nowrap'>";
  3561. if($lu_paging['results']){
  3562. $text .= "&nbsp;".$this->lang['results'].":&nbsp;";
  3563. if(($this->page_current * $this->req_page_size) <= $this->rows_total) $total = ($this->page_current * $this->req_page_size);
  3564. else $total = $this->rows_total;
  3565. $text .= ($this->page_current * $this->req_page_size - $this->req_page_size + 1)." - ".$total;
  3566. $text .= "&nbsp;".$this->lang['of']."&nbsp;";
  3567. $text .= $this->rows_total;
  3568. $text .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  3569. }
  3570. $text .= "</td><td align='".$lu_paging['pages_align']."' class='class_nowrap'>";
  3571. if($lu_paging['pages']){
  3572. $text .= "&nbsp;".$this->lang['pages'].":&nbsp;";
  3573. $href_prev1 = $href_prev2 = $href_first = "";
  3574. if($this->page_current > 1){
  3575. $href_prev1 = "href='$href_string".$this->amp.$this->uniquePrefix."p=".($this->page_current - 1)."'";
  3576. $href_prev2 = "href='$href_string".$this->amp.$this->uniquePrefix."p=".$this->page_current."'";
  3577. $href_first = "href='$href_string".$this->amp.$this->uniquePrefix."p=1'";
  3578. }
  3579. $text .= "&nbsp;<".$a_tag." title='".$this->lang['first']."' class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' ".$href_first.">".$this->first_arrow."</".$a_tag.">";
  3580. if($this->page_current > 1) $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' title='".$this->lang['previous']."' ".$href_prev1.">".$this->previous_arrow."</".$a_tag.">";
  3581. else $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' title='".$this->lang['previous']."' ".$href_prev2.">".$this->previous_arrow."</".$a_tag.">";
  3582. $text .= "&nbsp;";
  3583. $low_window_ind = $this->page_current - 3;
  3584. $high_window_ind = $this->page_current + 3;
  3585. if($low_window_ind > 1){ $start_index = $low_window_ind; $text .= "..."; }
  3586. else $start_index = 1;
  3587. if($high_window_ind < $this->pages_total) $end_index = $high_window_ind;
  3588. else $end_index = $this->pages_total;
  3589. for($ind=$start_index; $ind <= $end_index; $ind++){
  3590. if($ind == $this->page_current) $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a class_underlined' style='TEXT-DECORATION: underline;' title='".$this->lang['current']."' href='$href_string".$this->amp.$this->uniquePrefix."p=".$ind."'><b>" . $ind . "</b></".$a_tag.">";
  3591. else $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' href='$href_string".$this->amp.$this->uniquePrefix."p=".$ind."'>".$ind."</".$a_tag.">";
  3592. if($ind < $this->pages_total) $text .= ",&nbsp;";
  3593. else $text .= "&nbsp;";
  3594. }
  3595. if($high_window_ind < $this->pages_total) $text .= "...";
  3596. $href_next1 = $href_next2 = $href_last = "";
  3597. if($this->page_current < $this->pages_total){
  3598. $href_next1 = "href='$href_string".$this->amp.$this->uniquePrefix."p=".($this->page_current + 1)."'";
  3599. $href_next2 = "href='$href_string".$this->amp.$this->uniquePrefix."p=".$this->page_current."'";
  3600. $href_last = "href='$href_string".$this->amp.$this->uniquePrefix."p=".$this->pages_total."'";
  3601. }
  3602. if($this->page_current < $this->pages_total) $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' title='".$this->lang['next']."' ".$href_next1.">".$this->next_arrow."</".$a_tag.">";
  3603. else $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' title='".$this->lang['next']."' ".$href_next2.">".$this->next_arrow."</".$a_tag.">";
  3604. $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' title='".$this->lang['last']."' ".$href_last.">".$this->last_arrow."</".$a_tag.">";
  3605. }
  3606. $text .= "</td><td align='".$lu_paging['page_size_align']."' class='class_nowrap'>";
  3607. if($lu_paging['page_size']){
  3608. $text .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  3609. $text .= "&nbsp;".$this->lang['page_size'].":&nbsp;";
  3610. $text .= $this->DrawDropDownList('page_size'.$type, 'setPageSize'.$type.'()', $this->pages_array, $this->req_page_size);
  3611. }
  3612. $text .= "</td></tr>";
  3613. $text .= "</table>";
  3614. $text .= "</form>";
  3615. if($lu_paging['results'] || $lu_paging['pages'] || $lu_paging['page_size']){
  3616. if($lower_br) $text .= ""; //<br>
  3617. }
  3618. echo $text;
  3619. }else{
  3620. echo "<br><br>";
  3621. }
  3622. }
  3623. //--------------------------------------------------------------------------
  3624. // function - set total number of rows in query
  3625. //--------------------------------------------------------------------------
  3626. protected function SetTotalNumberRows($fsort = "", $limit = "", $mode = ""){
  3627. $req_mode = ($mode == "") ? $this->GetVariable('mode') : $mode;
  3628. if(($req_mode == "edit") || ($req_mode == "details")){
  3629. // we need this stupid operation to get a total number of rows in our query
  3630. $this->data_set = & $this->db_handler->query($this->SetSqlByDbType($this->sql, $fsort, $limit));
  3631. $this->rows_total = $this->NumberRows();
  3632. }else{
  3633. $temp_sql = $this->SetSqlByDbType($this->sql, "", "");
  3634. $from_pos = $this->LastSubStrOccurence($temp_sql, "from ");
  3635. $new_sql = "SELECT count(*) as cnt FROM ".substr($temp_sql, (int)(strlen($temp_sql) - $from_pos), (int)$from_pos);
  3636. $this->data_set = & $this->db_handler->query($new_sql);
  3637. if($this->db_handler->isError($this->data_set) == 1){
  3638. $this->rows_total = 0;
  3639. }else{
  3640. $row = $this->data_set->fetchRow();
  3641. $this->rows_total = $row[0];
  3642. }
  3643. }
  3644. }
  3645. //--------------------------------------------------------------------------
  3646. // function - number rows
  3647. //--------------------------------------------------------------------------
  3648. protected function NumberRows(){
  3649. if($this->db_handler->isError($this->data_set)){
  3650. return 0;
  3651. }else{
  3652. return $this->data_set->numRows();
  3653. }
  3654. }
  3655. //--------------------------------------------------------------------------
  3656. // function - number columns
  3657. //--------------------------------------------------------------------------
  3658. protected function NumberCols(){
  3659. if($this->db_handler->isError($this->data_set)){
  3660. return 0;
  3661. }else{
  3662. return $this->data_set->numCols();
  3663. }
  3664. }
  3665. //--------------------------------------------------------------------------
  3666. // function - no data found
  3667. //--------------------------------------------------------------------------
  3668. protected function NoDataFound(){
  3669. $NoDataFoundText = ($this->NoDataFoundText != "") ? $this->NoDataFoundText : $this->lang['no_data_found'];
  3670. $this->TblOpen();
  3671. $this->RowOpen(0, $this->rowColor[0]);
  3672. $add_column = 0;
  3673. if((isset($this->modes['add'][$this->mode]) && ($this->modes['add'][$this->mode])) ||
  3674. (isset($this->modes['edit'][$this->mode]) && ($this->modes['edit'][$this->mode]))
  3675. ) $add_column += 1;
  3676. if(isset($this->mode['delete']) && $this->mode['delete']) $add_column += 1;
  3677. $this->ColOpen("center", (count($this->sorted_columns) + $add_column),"");
  3678. if($this->is_error){
  3679. echo "<br><span class='".$this->css_class."_class_error_message no_print'>".$this->lang['no_data_found_error']."<br>&nbsp;";
  3680. if(!$this->debug){ echo "<br>".$this->lang['turn_on_debug_mode']."<br>&nbsp;"; }
  3681. echo "</span>";
  3682. }else{
  3683. echo "<br>".$NoDataFoundText."<br>&nbsp;";
  3684. }
  3685. $this->ColClose();
  3686. $this->RowClose();
  3687. $this->TblClose();
  3688. }
  3689. //--------------------------------------------------------------------------
  3690. // delete row
  3691. //--------------------------------------------------------------------------
  3692. protected function DeleteRow($rid){
  3693. $req_operation_randomize_code = $this->GetVariable("_operation_randomize_code", true, "post");
  3694. if(!$this->CheckF5CaseValidation($req_operation_randomize_code)) return false;
  3695. if(!$this->CheckSecurityCaseValidation("add", "add_new", "adding")) return false;
  3696. $this->rids = explode("-", $rid);
  3697. $sql = "DELETE FROM $this->tbl_name WHERE $this->primary_key IN ('-1' ";
  3698. foreach ($this->rids as $key){
  3699. $sql .= ", '".$key."' ";
  3700. }
  3701. $sql .= ");";
  3702. $this->db_handler->query($sql);
  3703. $affectedRows = $this->db_handler->affectedRows();
  3704. if($affectedRows > 0){
  3705. $this->act_msg = ($this->dg_messages['delete'] != "") ? $this->dg_messages['delete'] : $this->lang['deleting_operation_completed'];
  3706. if(isset($_SESSION)) { $_SESSION[$this->uniquePrefix.'_operation_randomize_code'] = $req_operation_randomize_code; }
  3707. }else{
  3708. $this->is_warning = true;
  3709. $this->act_msg = $this->lang['deleting_operation_uncompleted'];
  3710. if(isset($_SESSION)) { $_SESSION[$this->uniquePrefix.'_operation_randomize_code'] = ""; }
  3711. }
  3712. if($this->debug) echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left' class='".$this->css_class."_class_error_message no_print' style='COLOR: #333333;'><b>delete sql (".$this->StrToLower($this->lang['total']).": ".$affectedRows.") </b>".$sql."</td></tr></table><br>";
  3713. if($this->debug) $this->act_msg .= " ".$this->lang['record_n']." ".$this->rid;
  3714. }
  3715. //--------------------------------------------------------------------------
  3716. // update row
  3717. //--------------------------------------------------------------------------
  3718. protected function UpdateRow($rid){
  3719. $req_operation_randomize_code = $this->GetVariable("_operation_randomize_code", true, "post");
  3720. if(!$this->CheckF5CaseValidation($req_operation_randomize_code)) return false;
  3721. if(!$this->CheckSecurityCaseValidation("add", "add_new", "adding")) return false;
  3722. $unique_field_found = false;
  3723. $field_header = "";
  3724. $field_count = "0";
  3725. // check for unique fields
  3726. foreach($this->columns_edit_mode as $fldName => $fldValue){
  3727. if(($fldName != "") && ($this->GetFieldProperty($fldName, "unique") == true)){
  3728. $field_prefix = "syy";
  3729. if(isset($fldValue['req_type'])){
  3730. if(strlen(trim($fldValue['req_type'])) == 3){ $field_prefix = $fldValue['req_type']; }
  3731. else if(strlen(trim($fldValue['req_type'])) == 2){ $field_prefix = $fldValue['req_type']."y"; }
  3732. }
  3733. $field_header = (isset($fldValue['header'])) ? $fldValue['header'] : $fldName;
  3734. $unique_condition = (isset($fldValue['unique_condition'])) ? trim($fldValue['unique_condition']) : "" ;
  3735. $field_value = (isset($_POST[$field_prefix.$fldName])) ? $_POST[$field_prefix.$fldName] : "";
  3736. $sql = "SELECT COUNT(*) as count FROM $this->tbl_name WHERE $this->primary_key <> '$rid' AND $fldName = '$field_value'";
  3737. if($unique_condition != "") $sql .= " AND ".$unique_condition." ";
  3738. if(($field_count = $this->SelectSqlItem($sql)) > 0){
  3739. $unique_field_found = true;
  3740. break;
  3741. }
  3742. }
  3743. }
  3744. // create update statment
  3745. if(!$unique_field_found){
  3746. $sql = "UPDATE $this->tbl_name SET ";
  3747. $ind = 0;
  3748. $this->AddCheckBoxesValues();
  3749. $max = count($_POST);
  3750. foreach($_POST as $fldName => $fldValue){
  3751. // update all fields, excepting uploading fields
  3752. if(!strpos($fldName, "file_act") && !strpos($fldName, "_operation_randomize_code")){
  3753. $fldName = substr($fldName, 3, strlen($fldName));
  3754. $fldValue = $this->IsDatePrepare($fldName,$fldValue);
  3755. if(!$this->IsReadonly($fldName) && !$this->IsValidator($fldName)){
  3756. if (intval($ind) >= 1) $sql .= ", ";
  3757. if($this->IsText($fldName)){
  3758. $fldValue_new = $fldValue;
  3759. if(is_array($fldValue)){ // it was a multiple enum
  3760. $count = 0; $fldValue_new = "";
  3761. foreach ($fldValue as $val){ if($count++ > 0) $fldValue_new .= ","; $fldValue_new .= $val; }
  3762. }
  3763. $sql .= "$fldName = '".$this->SetRealEscapeStringByDbType($fldValue_new)."' ";
  3764. }else{
  3765. $sql .= (trim($fldValue) != "") ? "$fldName = $fldValue " : "$fldName = 0 ";
  3766. }
  3767. //if ((intval($ind) === 0) && ($max > 1)) $sql .= ", ";
  3768. $ind++;
  3769. }
  3770. }
  3771. }
  3772. $sql .= " WHERE $this->primary_key = '$rid' ";
  3773. $this->db_handler->query($sql);
  3774. $affectedRows = $this->db_handler->affectedRows();
  3775. if($affectedRows >= 0){
  3776. $this->act_msg = ($this->dg_messages['update'] != "") ? $this->dg_messages['update'] : $this->lang['updating_operation_completed'];
  3777. if(isset($_SESSION)) { $_SESSION[$this->uniquePrefix.'_operation_randomize_code'] = $req_operation_randomize_code; }
  3778. }else{
  3779. $this->is_warning = true;
  3780. $this->act_msg = $this->lang['updating_operation_uncompleted'];
  3781. if(isset($_SESSION)) { $_SESSION[$this->uniquePrefix.'_operation_randomize_code'] = ""; }
  3782. }
  3783. if($this->debug) echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left' class='".$this->css_class."_class_error_message no_print' style='COLOR: #333333;'><b>update sql (".$this->StrToLower($this->lang['total']).": ".$affectedRows.") </b>".$sql."</td></tr></table><br>";
  3784. }else{
  3785. $this->is_warning = true;
  3786. $this->act_msg = str_replace("_FIELD_", $field_header, $this->lang['unique_field_error']);
  3787. if($this->debug) echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left' class='".$this->css_class."_class_error_message no_print' style='COLOR: #333333;'><b>select sql (".$this->StrToLower($this->lang['total']).": ".$field_count.") </b>".$sql."</td></tr></table><br>";
  3788. }
  3789. if($this->debug) $this->act_msg .= " ".$this->lang['record_n']." ".$this->rid;
  3790. }
  3791. //--------------------------------------------------------------------------
  3792. // add row
  3793. //--------------------------------------------------------------------------
  3794. protected function AddRow(){
  3795. $req_operation_randomize_code = $this->GetVariable("_operation_randomize_code", true, "post");
  3796. if(!$this->CheckF5CaseValidation($req_operation_randomize_code)) return false;
  3797. if(!$this->CheckSecurityCaseValidation("add", "add_new", "adding")) return false;
  3798. $unique_field_found = false;
  3799. $field_header = "";
  3800. $field_count = "0";
  3801. // check for unique fields
  3802. foreach($this->columns_edit_mode as $fldName => $fldValue){
  3803. if(($fldName != "") && ($this->GetFieldProperty($fldName, "unique") == true)){
  3804. $field_prefix = "syy";
  3805. if(isset($fldValue['req_type'])){
  3806. if(strlen(trim($fldValue['req_type'])) == 3){ $field_prefix = $fldValue['req_type']; }
  3807. else if(strlen(trim($fldValue['req_type'])) == 2){ $field_prefix = $fldValue['req_type']."y"; }
  3808. }
  3809. $field_header = (isset($fldValue['header'])) ? $fldValue['header'] : $fldName;
  3810. $unique_condition = (isset($fldValue['unique_condition'])) ? trim($fldValue['unique_condition']) : "" ;
  3811. $field_value = (isset($_POST[$field_prefix.$fldName])) ? $_POST[$field_prefix.$fldName] : "";
  3812. $sql = "SELECT COUNT(*) as count FROM $this->tbl_name WHERE $fldName = '$field_value' ";
  3813. if($unique_condition != "") $sql .= " AND ".$unique_condition." ";
  3814. if(($field_count = $this->SelectSqlItem($sql)) > 0){
  3815. $unique_field_found = true;
  3816. break;
  3817. }
  3818. }
  3819. }
  3820. // create insert statment
  3821. if(!$unique_field_found){
  3822. $this->AddCheckBoxesValues();
  3823. $sql = "INSERT INTO $this->tbl_name (";
  3824. $ind = 0;
  3825. $max = count($_POST);
  3826. foreach($_POST as $fldName => $fldValue){
  3827. $ind ++;
  3828. // all fields, excepting uploading fields
  3829. if(!strpos($fldName, "file_act") && !strpos($fldName, "_operation_randomize_code")){
  3830. if(!$this->IsValidator($fldName)){
  3831. $fldName = substr($fldName, 3, strlen($fldName));
  3832. $sql .= "$fldName";
  3833. if (intval($ind) < intval($max) ) $sql .= ", ";
  3834. }
  3835. }
  3836. }
  3837. $sql .= ") VALUES (";
  3838. $ind = 0;
  3839. $max = count($_POST);
  3840. foreach($_POST as $fldName => $fldValue){
  3841. $ind ++;
  3842. // all fields, excepting uploading fields
  3843. if(!strpos($fldName, "file_act") && !strpos($fldName, "_operation_randomize_code")){
  3844. if(!$this->IsValidator($fldName)){
  3845. $fldName = substr($fldName, 3, strlen($fldName));
  3846. $fldValue = $this->IsDatePrepare($fldName,$fldValue);
  3847. if($this->IsText($fldName)) {
  3848. if($fldValue != ""){
  3849. $fldValue_new = $fldValue;
  3850. if(is_array($fldValue)){ // it was a multiple enum
  3851. $count = 0; $fldValue_new = "";
  3852. foreach ($fldValue as $val){ if($count++ > 0) $fldValue_new .= ","; $fldValue_new .= $val; }
  3853. }
  3854. $sql .= "'".$this->SetRealEscapeStringByDbType($fldValue_new)."'";
  3855. }else if($this->IsFieldRequired($fldName)){
  3856. $sql .= "' '";
  3857. }else{
  3858. $sql .= "''";
  3859. }
  3860. }else{
  3861. if(trim($fldValue) != ""){
  3862. $sql .= $fldValue;
  3863. }else if($this->IsFieldRequired($fldName)){
  3864. $sql .= '0';
  3865. }else{
  3866. $sql .= 'NULL';
  3867. }
  3868. }
  3869. if (intval($ind) < intval($max) ) $sql .= ", ";
  3870. }
  3871. }
  3872. }
  3873. $sql .= ") ";
  3874. $dSet = $this->db_handler->query($sql);
  3875. $affectedRows = $this->db_handler->affectedRows();
  3876. if($this->debug) echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left'><b>insert sql (".$this->StrToLower($this->lang['total']).": ".$affectedRows.") </b>".$sql."</td></tr></table><br>";
  3877. if($affectedRows > 0){
  3878. $this->act_msg = ($this->dg_messages['add'] != "") ? $this->dg_messages['add'] : $this->lang['adding_operation_completed'];
  3879. $res = $this->db_handler->query("SELECT MAX(".$this->primary_key.") as maximal_row FROM ".$this->tbl_name." ");
  3880. $row = $res->fetchRow();
  3881. $this->rid = $row[0];
  3882. if($this->debug){
  3883. $this->act_msg .= " ".$this->lang['record_n']." ".$this->rid;
  3884. }
  3885. if(isset($_SESSION)) { $_SESSION[$this->uniquePrefix.'_operation_randomize_code'] = $req_operation_randomize_code; }
  3886. }else{
  3887. $this->is_warning = true;
  3888. $this->act_msg = $this->lang['adding_operation_uncompleted'];
  3889. if($this->db_handler->isError($dSet) == 1){
  3890. $this->is_error = true;
  3891. $this->AddErrors($dSet);
  3892. }
  3893. if(isset($_SESSION)) { $_SESSION[$this->uniquePrefix.'_operation_randomize_code'] = ""; }
  3894. }
  3895. }else{
  3896. $this->is_warning = true;
  3897. $this->act_msg = str_replace("_FIELD_", $field_header, $this->lang['unique_field_error']);
  3898. if($this->debug) echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left'><b>select sql (".$this->StrToLower($this->lang['total']).": ".$field_count.") </b>".$sql."</td></tr></table><br>";
  3899. }
  3900. $this->sql = "SELECT * FROM $this->tbl_name ";
  3901. $fsort = " ORDER BY " . $this->primary_key . " DESC";
  3902. $this->GetDataSet($fsort);
  3903. }
  3904. //--------------------------------------------------------------------------
  3905. // check for F5 refresh case
  3906. //--------------------------------------------------------------------------
  3907. protected function CheckF5CaseValidation($req_operation_randomize_code = ""){
  3908. if(isset($_SESSION[$this->uniquePrefix.'_operation_randomize_code']) && $req_operation_randomize_code != "" && ($_SESSION[$this->uniquePrefix.'_operation_randomize_code'] == $req_operation_randomize_code)){
  3909. $this->is_warning = true;
  3910. $this->act_msg = $this->lang['operation_was_already_done'];
  3911. return false;
  3912. } return true;
  3913. }
  3914. //--------------------------------------------------------------------------
  3915. // check for security case
  3916. //--------------------------------------------------------------------------
  3917. protected function CheckSecurityCaseValidation($mode = "", $operation = "", $gerundy = ""){
  3918. if(($this->modes[$mode]["view"] == false) && ($this->modes[$mode]["edit"] == false)){
  3919. $this->is_warning = true;
  3920. if($this->debug){
  3921. $this->act_msg = $this->lang[$operation.'_record_blocked'];
  3922. }else{
  3923. $this->act_msg = $this->lang[$gerundy.'_operation_uncompleted'];
  3924. }
  3925. return false;
  3926. } return true;
  3927. }
  3928. //--------------------------------------------------------------------------
  3929. // get field offset
  3930. //--------------------------------------------------------------------------
  3931. protected function GetFieldOffset($field_name){
  3932. if(!$this->is_error){
  3933. $fields = $this->data_set->tableInfo();
  3934. for($ind=0; $ind < $this->data_set->numCols(); $ind++){
  3935. if($fields[$ind]['name'] === $field_name) return $ind;
  3936. }
  3937. }
  3938. return -1;
  3939. }
  3940. //--------------------------------------------------------------------------
  3941. // is field required
  3942. //--------------------------------------------------------------------------
  3943. protected function IsFieldRequired($field){
  3944. if(!$this->is_error){
  3945. $fields = $this->data_set->tableInfo();
  3946. if($this->GetFieldOffset($field) != -1){
  3947. $flags = $fields[$this->GetFieldOffset($field)]['flags'];
  3948. //echo $fields[$this->GetFieldOffset($field)]['type']." ".$flags."<br>";
  3949. if(strstr(strtolower($flags), "not_null")){
  3950. return true;
  3951. }
  3952. }
  3953. }
  3954. return false;
  3955. }
  3956. //--------------------------------------------------------------------------
  3957. // get field info
  3958. //--------------------------------------------------------------------------
  3959. protected function GetFieldInfo($field, $parameter='', $type=0){
  3960. if(!$this->is_error){
  3961. $fields = $this->data_set->tableInfo();
  3962. if($type == 0){
  3963. if($this->GetFieldOffset($field) != -1)
  3964. return $fields[$this->GetFieldOffset($field)][$parameter];
  3965. else
  3966. return '';
  3967. }else{
  3968. return $fields[$field][$parameter];
  3969. }
  3970. }
  3971. return -1;
  3972. }
  3973. //--------------------------------------------------------------------------
  3974. // set Datetime field in right format (dd-mm-yyyy)|(yyyy-mm-dd)
  3975. //--------------------------------------------------------------------------
  3976. protected function IsDatePrepare($field_name, $fldValue){
  3977. $field_property_type = $this->GetFieldProperty($field_name, "type");
  3978. switch ($field_property_type){
  3979. case 'date': // date: DATE
  3980. case 'datetime': // date: DATE
  3981. break;
  3982. case 'datetimedmy': // date: DATETIME
  3983. $time1 = substr(trim($fldValue), 10, 9);
  3984. $year1 = substr(trim($fldValue), 6, 4);
  3985. $month1 = substr(trim($fldValue), 3, 2);
  3986. $day1 = substr(trim($fldValue), 0, 2);
  3987. $fldValue = $year1."-".$month1."-".$day1." ".$time1;
  3988. break;
  3989. case 'datedmy': // date: DATE
  3990. $year1 = substr(trim($fldValue), 6, 4);
  3991. $month1 = substr(trim($fldValue), 3, 2);
  3992. $day1 = substr(trim($fldValue), 0, 2);
  3993. $fldValue = $year1."-".$month1."-".$day1;
  3994. break;
  3995. default:
  3996. break;
  3997. }
  3998. return $fldValue;
  3999. }
  4000. //--------------------------------------------------------------------------
  4001. // check if field type needs ''(text) or not (numeric...)
  4002. //--------------------------------------------------------------------------
  4003. protected function IsText($field_name){
  4004. $field_type = $this->GetFieldInfo($field_name, 'type', 0);
  4005. $result = true;
  4006. switch (strtolower($field_type)){
  4007. case 'int': // int: TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER, BIGINT, TINY, SHORT, LONG, LONGLONG, INT24
  4008. case 'real': // real: FLOAT, DOUBLE, DECIMAL, NUMERIC
  4009. case 'null': // empty: NULL
  4010. $result = false; break;
  4011. case 'string': // string: CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, ENUM, SET, VAR_STRING
  4012. case 'blob': // blob: TINYBLOB, MEDIUMBLOB, LONGBLOB, BLOB, TEXT
  4013. case 'date': // date: DATE
  4014. case 'timestamp': // date: TIMESTAMP
  4015. case 'year': // date: YEAR
  4016. case 'time': // date: TIME
  4017. case 'datetime': // date: DATETIME
  4018. $result = true; break;
  4019. default:
  4020. $result = true; break;
  4021. }
  4022. return $result;
  4023. }
  4024. //--------------------------------------------------------------------------
  4025. // check if field type is a date/time type
  4026. //--------------------------------------------------------------------------
  4027. protected function IsDate($field_name){
  4028. $field_type = $this->GetFieldInfo($field_name, 'type', 0);
  4029. $result = false;
  4030. switch (strtolower($field_type)){
  4031. case 'date': // date: DATE
  4032. case 'timestamp': // date: TIMESTAMP
  4033. case 'year': // date: YEAR
  4034. case 'time': // date: TIME
  4035. case 'datetime': // date: DATETIME
  4036. $result = true; break;
  4037. default:
  4038. $result = false; break;
  4039. }
  4040. return $result;
  4041. }
  4042. //--------------------------------------------------------------------------
  4043. // check if a field is readonly
  4044. //--------------------------------------------------------------------------
  4045. protected function IsReadonly($field_name){
  4046. $field_property_readonly = $this->GetFieldProperty($field_name, "readonly");
  4047. if($field_property_readonly == true){
  4048. return true;
  4049. }else{
  4050. return false;
  4051. }
  4052. }
  4053. //--------------------------------------------------------------------------
  4054. // check if a field is validator
  4055. //--------------------------------------------------------------------------
  4056. protected function IsValidator($field_name){
  4057. $validator_letter = substr($field_name, 1, 1);
  4058. $validator_field = substr($field_name, 3, strlen($field_name));
  4059. if($validator_letter == "v"){
  4060. foreach($this->columns_edit_mode as $key){
  4061. if($key['type'] == "validator" && $key['for_field'] == $validator_field){
  4062. return true;
  4063. }
  4064. }
  4065. }
  4066. return false;
  4067. }
  4068. //--------------------------------------------------------------------------
  4069. // check if a field is a foreign key
  4070. //--------------------------------------------------------------------------
  4071. protected function IsForeignKey($field_name){
  4072. if(array_key_exists($field_name, $this->foreign_keys_array)){
  4073. return true;
  4074. }
  4075. return false;
  4076. }
  4077. //--------------------------------------------------------------------------
  4078. // get foreign key input
  4079. //--------------------------------------------------------------------------
  4080. protected function GetForeignKeyInput($keyFieldValue, $fk_field_name, $fk_field_value, $mode="edit"){
  4081. $req_mode = $this->GetVariable('mode');
  4082. // check if foreign key field is readonly or disabled
  4083. $readonly = "";
  4084. $disabled = "";
  4085. $field_property_readonly = $this->GetFieldProperty($fk_field_name, "readonly");
  4086. $field_property_radiobuttons_alignment = "horizontal";
  4087. if(isset($this->foreign_keys_array[$fk_field_name]['radiobuttons_alignment']) && (strtolower($this->foreign_keys_array[$fk_field_name]['radiobuttons_alignment']) == "vertical")){
  4088. $field_property_radiobuttons_alignment = "vertical";
  4089. }
  4090. if($req_mode == "edit"){
  4091. if($field_property_readonly == true){
  4092. $disabled = "disabled"; //$readonly = "readonly='readonly'";
  4093. }
  4094. }
  4095. $sql = " SELECT ".$fk_field_name;
  4096. $sql .= " FROM ".$this->tbl_name;
  4097. $sql .= " WHERE ".$this->primary_key." = '".$keyFieldValue."' ";
  4098. $this->db_handler->setFetchMode(DB_FETCHMODE_ASSOC);
  4099. $dSet = $this->db_handler->query($sql);
  4100. if($dSet->numRows() > 0){
  4101. $row = $dSet->fetchRow();
  4102. $kFieldValue = $row[$fk_field_name];
  4103. }else{
  4104. $kFieldValue = -1;
  4105. }
  4106. // select from outer table
  4107. $sql = " SELECT ".$this->foreign_keys_array[$fk_field_name]['field_key'].",".$this->foreign_keys_array[$fk_field_name]['field_name']." ";
  4108. $sql .= " FROM ".$this->foreign_keys_array[$fk_field_name]['table'] ;
  4109. $sql .= " WHERE 1=1 ";
  4110. if($mode !== "edit"){
  4111. $sql .= " AND " .$this->foreign_keys_array[$fk_field_name]['field_key']."='".$kFieldValue."'";
  4112. }
  4113. if(isset($this->foreign_keys_array[$fk_field_name]['condition']) && ($this->foreign_keys_array[$fk_field_name]['condition'] != "")){
  4114. $sql .= " AND " .$this->foreign_keys_array[$fk_field_name]['condition'];
  4115. }
  4116. // define sorting order
  4117. if(isset($this->foreign_keys_array[$fk_field_name]['order_by_field']) && ($this->foreign_keys_array[$fk_field_name]['order_by_field'] != "")){
  4118. $order_by_field = $this->foreign_keys_array[$fk_field_name]['order_by_field'];
  4119. }else{
  4120. $order_by_field = $this->foreign_keys_array[$fk_field_name]['field_key'];
  4121. }
  4122. // define sorting type
  4123. if(isset($this->foreign_keys_array[$fk_field_name]['order_type']) && ($this->foreign_keys_array[$fk_field_name]['order_type'] != "")){
  4124. $order_type = $this->foreign_keys_array[$fk_field_name]['order_type'];
  4125. }else{
  4126. $order_type = "ASC";
  4127. }
  4128. $sql .= " ORDER BY ".$order_by_field." ".$order_type;
  4129. $dSet = $this->db_handler->query($sql);
  4130. if($this->db_handler->isError($dSet) == 1){
  4131. $this->is_error = true;
  4132. $this->AddErrors($dSet);
  4133. }
  4134. if($this->debug){
  4135. if($this->db_handler->isError($dSet) == 1){
  4136. $num_rows = 0;
  4137. }else{
  4138. $num_rows = $dSet->numRows();
  4139. }
  4140. echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left' wrap><b>search sql (".$this->StrToLower($this->lang['total']).": ".$num_rows.") </b>". $sql."</td></tr></table><br>";
  4141. }
  4142. if($mode === "edit"){
  4143. // save entered values from fields in add/edit modes
  4144. $req_field_value = $this->GetVariable($this->GetFieldRequiredType($fk_field_name).$fk_field_name, false, "post");
  4145. $on_js_event = (isset($this->foreign_keys_array[$fk_field_name]['on_js_event'])) ? $this->foreign_keys_array[$fk_field_name]['on_js_event'] : "";
  4146. $view_type = (isset($this->foreign_keys_array[$fk_field_name]['view_type'])) ? $this->foreign_keys_array[$fk_field_name]['view_type'] : "";
  4147. if($view_type == "textbox"){ //'view_type"=>"textbox"
  4148. while($row = $dSet->fetchRow()){
  4149. $ff_name = $this->foreign_keys_array[$fk_field_name]['field_name'];
  4150. if(eregi(" as ", strtolower($ff_name))) $ff_name = substr($ff_name, strpos(strtolower($ff_name), " as ")+4);
  4151. if($row[$ff_name] === $kFieldValue){
  4152. $kFieldValue = $row[$ff_name];
  4153. $kFieldValue = str_replace('"', "&quot;", $kFieldValue); // double quotation mark
  4154. $kFieldValue = str_replace("'", "&#039;", $kFieldValue); // single quotation mark
  4155. }
  4156. }
  4157. return "<input class='".$this->css_class."_class_textbox' type='text' title='".$this->GetFieldTitle($fk_field_name)."' id='".$this->GetFieldRequiredType($fk_field_name).$fk_field_name."' name='".$this->GetFieldRequiredType($fk_field_name).$fk_field_name."' value='".$kFieldValue."' $disabled ".$on_js_event.">";
  4158. }else if($view_type == "radiobutton"){ //'view_type"=>"radiobutton"
  4159. return $this->DrawRadioButtons($this->GetFieldRequiredType($fk_field_name).$fk_field_name, $fk_field_name, $dSet, $kFieldValue, 'field_key', 'field_name', $disabled, $on_js_event, $field_property_radiobuttons_alignment);
  4160. }else { //'view_type"=>"dropdownlist" - default
  4161. $req_field_name = $this->GetVariable($this->GetFieldRequiredType($fk_field_name).$fk_field_name, false, "post");
  4162. if($req_mode == "add"){
  4163. if($req_field_name != "") $req_field_value = $req_field_value;
  4164. else $req_field_value = $this->GetFieldProperty($fk_field_name, "default");
  4165. }else {
  4166. if($req_field_name != "") $req_field_value = $req_field_value;
  4167. else $req_field_value = $fk_field_value;
  4168. }
  4169. return $this->DrawDropDownList($this->GetFieldRequiredType($fk_field_name).$fk_field_name, '', $dSet, $req_field_value, $fk_field_name, 'field_key', 'field_name', $disabled, $on_js_event);
  4170. }
  4171. }else{
  4172. if(!isset($dSet->message) || $dSet->message == ""){
  4173. $row = $dSet->fetchRow();
  4174. $ff_name = $this->foreign_keys_array[$fk_field_name]['field_name'];
  4175. if (eregi(" as ", strtolower($ff_name))) $ff_name = substr($ff_name, strpos(strtolower($ff_name), " as ")+4);
  4176. return $this->nbsp.$row[$ff_name].$this->nbsp;
  4177. }else{
  4178. if(isset($dSet->message)){ echo $dSet->message; }
  4179. if(isset($dSet->userinfo)){ echo $dSet->userinfo; }
  4180. return "";
  4181. }
  4182. }
  4183. }
  4184. ////////////////////////////////////////////////////////////////////////////
  4185. // URL string creating
  4186. ////////////////////////////////////////////////////////////////////////////
  4187. //--------------------------------------------------------------------------
  4188. // setUrl
  4189. //--------------------------------------------------------------------------
  4190. protected function SetUrlString(&$curr_url, $filtering = "", $sorting = "", $paging ="", $amp=""){
  4191. $amp = ($amp != "") ? $amp : $this->amp;
  4192. if($filtering != "") $this->SetUrlStringFiltering($curr_url, $amp);
  4193. if($sorting != "") $this->SetUrlStringSorting($curr_url, $amp);
  4194. if($paging != "") $this->SetUrlStringPaging($curr_url, $amp);
  4195. }
  4196. //--------------------------------------------------------------------------
  4197. // SetUrlString Filtering
  4198. //--------------------------------------------------------------------------
  4199. protected function SetUrlStringFiltering(&$curr_url, $amp=""){
  4200. $amp = ($amp != "") ? $amp : $this->amp;
  4201. $req_onSUBMIT_FILTER = $this->GetVariable('_ff_onSUBMIT_FILTER');
  4202. if($this->filtering_allowed){
  4203. foreach($this->filter_fields as $fldField){
  4204. $table_field_name = "".$fldField['table']."_".$fldField['field'];
  4205. $filter_field_value = isset($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name]) ? stripcslashes($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name]) : "";
  4206. if($filter_field_value != ""){
  4207. $curr_url .= $amp.$this->uniquePrefix."_ff_".$fldField['table'].'_'.$fldField['field']."=".urlencode($filter_field_value)."";
  4208. }
  4209. $table_field_name_operator = "".$fldField['table']."_".$fldField['field']."_operator";
  4210. if(isset($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name_operator]) AND ($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name_operator] != "")){
  4211. $curr_url .= $amp.$this->uniquePrefix."_ff_".$fldField['table'].'_'.$fldField['field']."_operator=".urlencode($_REQUEST[$this->uniquePrefix."_ff_".$table_field_name_operator])."";
  4212. }
  4213. }
  4214. if(isset($_REQUEST[$this->uniquePrefix."_ff_".'selSearchType']) && (trim($_REQUEST[$this->uniquePrefix."_ff_".'selSearchType']) != ""))
  4215. $curr_url .= $amp.$this->uniquePrefix."_ff_"."selSearchType=".urlencode($_REQUEST[$this->uniquePrefix."_ff_".'selSearchType'])."";
  4216. if($req_onSUBMIT_FILTER != "")
  4217. $curr_url .= $amp.$this->uniquePrefix."_ff_"."onSUBMIT_FILTER=search";
  4218. }
  4219. }
  4220. //--------------------------------------------------------------------------
  4221. // SetUrlString Sorting
  4222. //--------------------------------------------------------------------------
  4223. protected function SetUrlStringSorting(&$curr_url, $amp=""){
  4224. $amp = ($amp != "") ? $amp : $this->amp;
  4225. $sort_field = $this->GetVariable('sort_field');
  4226. $sort_field_by = $this->GetVariable('sort_field_by');
  4227. $sort_field_type = $this->GetVariable('sort_field_type');
  4228. $sort_type = $this->GetVariable('sort_type');
  4229. if($sort_field != "") {
  4230. $this->sort_field = $sort_field;
  4231. $this->sort_field_by = $sort_field_by;
  4232. $this->sort_field_type = $sort_field_type;
  4233. $curr_url .= $amp.$this->uniquePrefix."sort_field=".$this->sort_field.$amp.$this->uniquePrefix."sort_field_by=".$this->sort_field_by.$amp.$this->uniquePrefix."sort_field_type=".$this->sort_field_type;
  4234. }else {
  4235. if(!is_numeric($this->default_sort_field[0])){ $this->default_sort_field[0] = $this->GetFieldOffset($this->default_sort_field[0]) + 1; }
  4236. $curr_url .= $amp.$this->uniquePrefix."sort_field=".$this->default_sort_field[0];
  4237. }; // make pKey
  4238. if($sort_type != "") {
  4239. $this->sort_type = $sort_type;
  4240. $curr_url .= $amp.$this->uniquePrefix."sort_type=".$this->sort_type;
  4241. } else {
  4242. $curr_url .= $amp.$this->uniquePrefix."sort_type=".$this->default_sort_type[0];
  4243. };
  4244. }
  4245. //--------------------------------------------------------------------------
  4246. // SetUrlString Pading
  4247. //--------------------------------------------------------------------------
  4248. protected function SetUrlStringPaging(&$curr_url, $amp=""){
  4249. $amp = ($amp != "") ? $amp : $this->amp;
  4250. $page_size = $this->GetVariable('page_size');
  4251. $p = $this->GetVariable('p');
  4252. if($this->layouts['edit'] == "0"){
  4253. if($page_size != ""){
  4254. $this->req_page_size = $page_size;
  4255. $curr_url .= $amp.$this->uniquePrefix."page_size=".$this->req_page_size;
  4256. }else{
  4257. $curr_url .= $amp.$this->uniquePrefix."page_size=".$this->req_page_size;
  4258. }
  4259. }else{
  4260. if($this->mode === "view"){
  4261. $curr_url .= $amp.$this->uniquePrefix."page_size=".$this->req_page_size;
  4262. }else{
  4263. if($page_size != ""){
  4264. $this->req_page_size = $page_size;
  4265. }else{
  4266. if($this->mode == "edit"){
  4267. $this->req_page_size = $this->default_page_size;
  4268. }
  4269. }
  4270. $curr_url .= $amp.$this->uniquePrefix."page_size=".$this->req_page_size;
  4271. }
  4272. }
  4273. if($p != "") {
  4274. $this->page_current = $p;
  4275. $curr_url .= $amp.$this->uniquePrefix."p=".$this->page_current;
  4276. }else {
  4277. $this->page_current = 1;
  4278. $curr_url .= $amp.$this->uniquePrefix."p=1";
  4279. };
  4280. }
  4281. ////////////////////////////////////////////////////////////////////////////
  4282. // View & Edit mode methods
  4283. ////////////////////////////////////////////////////////////////////////////
  4284. //--------------------------------------------------------------------------
  4285. // get enum values
  4286. //--------------------------------------------------------------------------
  4287. protected function GetEnumValues( $table , $field ){
  4288. $enum_array = "";
  4289. $query = " SHOW COLUMNS FROM $table LIKE '$field' ";
  4290. $this->db_handler->setFetchMode(DB_FETCHMODE_ORDERED);
  4291. $result = $this->db_handler->query($query);
  4292. if($row = $result->fetchRow()){
  4293. // extract the values, the values are enclosed in single quotes and separated by commas
  4294. $regex = "/'(.*?)'/";
  4295. preg_match_all( $regex , $row[1], $enum_array );
  4296. $temp_enum_fields = $enum_array[1];
  4297. $enum_fields = array();
  4298. foreach($temp_enum_fields as $key => $val){
  4299. $enum_fields[$val] = $val;
  4300. }
  4301. return $enum_fields ;
  4302. }else{
  4303. return array();
  4304. }
  4305. }
  4306. //--------------------------------------------------------------------------
  4307. // check if field exists & can be viewed
  4308. //--------------------------------------------------------------------------
  4309. protected function CanViewField($field_name){
  4310. $field_property_visible = $this->GetFieldProperty($field_name, "visible", $this->mode, "lower", "true");
  4311. if($this->mode === "view"){
  4312. if(array_key_exists($field_name, $this->columns_view_mode) && ($field_property_visible == true)) return true;
  4313. }else if($this->mode === "edit"){
  4314. if(array_key_exists($field_name, $this->columns_edit_mode) && ($field_property_visible == true)) return true;
  4315. }else if($this->mode === "details"){
  4316. if(array_key_exists($field_name, $this->columns_edit_mode) && ($field_property_visible == true)) return true;
  4317. }
  4318. return false;
  4319. }
  4320. //--------------------------------------------------------------------------
  4321. // check if field exists & can be viewed
  4322. //--------------------------------------------------------------------------
  4323. protected function GetHeaderName($field_name, $force_simple = false){
  4324. $force_simple = (($force_simple == true) || ($force_simple == "true")) ? true : false ;
  4325. $field_property_header = $this->GetFieldProperty($field_name, "header", $this->mode, "normal");
  4326. if($this->mode === "view"){
  4327. if(array_key_exists($field_name, $this->columns_view_mode) && ($field_property_header != "")){
  4328. return $field_property_header;
  4329. }
  4330. }else if($this->mode === "edit"){
  4331. if(array_key_exists($field_name, $this->columns_edit_mode) && ($field_property_header != "")){
  4332. if((substr($this->GetFieldRequiredType($field_name), 0, 1) == "r") && (!$force_simple)){
  4333. return ucfirst($field_property_header)." <font color='#cd0000'>*</font> ";
  4334. }else{
  4335. return $field_property_header;
  4336. }
  4337. }
  4338. }else if($this->mode === "details"){
  4339. if(array_key_exists($field_name, $this->columns_edit_mode) && ($field_property_header != "")){
  4340. return $field_property_header;
  4341. }
  4342. }
  4343. return $field_name;
  4344. }
  4345. //--------------------------------------------------------------------------
  4346. // Returns field name
  4347. //--------------------------------------------------------------------------
  4348. protected function GetFieldName($field_offset){
  4349. if(!$this->is_error){
  4350. $fields = $this->data_set->tableInfo();
  4351. $field_name = isset($fields[$field_offset]['name']) ? $fields[$field_offset]['name'] : "";
  4352. if($field_name) return $field_name;
  4353. }
  4354. return $field_offset;
  4355. }
  4356. //--------------------------------------------------------------------------
  4357. // get Field Required Type
  4358. //--------------------------------------------------------------------------
  4359. protected function GetFieldRequiredType($field_name, $validator=false){
  4360. $field_prefix = "syy";
  4361. $field_req_type = trim($this->GetFieldProperty($field_name, "req_type"));
  4362. if($field_req_type != ""){
  4363. if(strlen($field_req_type) == 3){ $field_prefix = $field_req_type; }
  4364. else if(strlen($field_req_type) == 2){
  4365. $field_prefix = $field_req_type."y";
  4366. }
  4367. }
  4368. if($validator) $field_prefix[1] = "v";
  4369. return $field_prefix;
  4370. }
  4371. //--------------------------------------------------------------------------
  4372. // get Field Property
  4373. //--------------------------------------------------------------------------
  4374. protected function GetFieldProperty($field_name, $property_name, $mode = "edit", $case = "normal", $return_value = ""){
  4375. switch($mode){
  4376. case "view":
  4377. if(isset($this->columns_view_mode[$field_name][$property_name])){
  4378. if($case === "lower") {
  4379. $return_value = strtolower($this->columns_view_mode[$field_name][$property_name]);
  4380. } else {
  4381. $return_value = $this->columns_view_mode[$field_name][$property_name];
  4382. }
  4383. }
  4384. break;
  4385. case "filter":
  4386. if(isset($this->filter_fields[$field_name][$property_name])){
  4387. if($case === "lower") {
  4388. $return_value = strtolower($this->filter_fields[$field_name][$property_name]);
  4389. } else {
  4390. $return_value = $this->filter_fields[$field_name][$property_name];
  4391. }
  4392. }
  4393. break;
  4394. case "details":
  4395. case "edit":
  4396. default:
  4397. if(isset($this->columns_edit_mode[$field_name][$property_name])){
  4398. if($case === "lower") {
  4399. if(is_array($this->columns_edit_mode[$field_name][$property_name])){
  4400. return $this->columns_edit_mode[$field_name][$property_name];
  4401. }else{
  4402. $return_value = strtolower($this->columns_edit_mode[$field_name][$property_name]);
  4403. }
  4404. } else {
  4405. $return_value = $this->columns_edit_mode[$field_name][$property_name];
  4406. }
  4407. }
  4408. break;
  4409. }
  4410. if($return_value == "true"){
  4411. $return_value = true;
  4412. }else if($return_value == "false"){
  4413. $return_value = false;
  4414. }
  4415. return $return_value;
  4416. }
  4417. //--------------------------------------------------------------------------
  4418. // get Field Title
  4419. //--------------------------------------------------------------------------
  4420. protected function GetFieldTitle($field_name, $mode="edit"){
  4421. $field_title = $this->GetFieldProperty($field_name, "title", $mode, "");
  4422. if($field_title === ""){
  4423. $field_header = $this->GetFieldProperty($field_name, "header", $mode);
  4424. if($field_header === ""){
  4425. return $field_name;
  4426. }else{
  4427. return str_replace("'", "&#039;", $field_header);
  4428. }
  4429. }else{
  4430. return $field_title;
  4431. }
  4432. }
  4433. //--------------------------------------------------------------------------
  4434. // get Field Alignment
  4435. //--------------------------------------------------------------------------
  4436. protected function GetFieldAlign($ind, $row, $mode="view"){
  4437. $field_name = $this->GetFieldName($ind);
  4438. $field_align = $this->GetFieldProperty($field_name, "align", $mode);
  4439. if(($mode == "view") && ($field_align != "")){
  4440. return $field_align;
  4441. }else if(($mode != "view") && ($field_align != "")){
  4442. return $field_align;
  4443. }else{
  4444. if(isset($row[$ind]) && $this->IsText($field_name)){
  4445. return ($this->direction == "ltr")?"left":"right";
  4446. }else{
  4447. return ($this->direction == "ltr")?"right":"left";
  4448. }
  4449. }
  4450. }
  4451. //--------------------------------------------------------------------------
  4452. // get Field Value By Type
  4453. //--------------------------------------------------------------------------
  4454. protected function GetFieldValueByType($field_value, $ind, $row, $field_name="", $m_field_req_type=""){
  4455. // Un-quote string quoted by mysql_real_escape_string()
  4456. if(get_magic_quotes_gpc()) {
  4457. if(ini_get('magic_quotes_sybase')) {
  4458. $field_value = str_replace("''", "'", $field_value);
  4459. } else {
  4460. $field_value = str_replace("''", "'", $field_value);
  4461. $field_value = stripslashes($field_value);
  4462. }
  4463. }
  4464. $req_print = $this->GetVariable('print');
  4465. $req_mode = $this->GetVariable('mode');
  4466. if($field_name == "") $field_name = $this->GetFieldName($ind);
  4467. // -= VIEW MODE =-
  4468. if($this->mode === "view"){
  4469. if(array_key_exists($field_name, $this->columns_view_mode)){
  4470. $fp_tooltip = $this->GetFieldProperty($field_name, "tooltip", "view");
  4471. $fp_tooltip_type = $this->GetFieldProperty($field_name, "tooltip_type", "view");
  4472. $field_property_pre_addition = $this->GetFieldProperty($field_name, "pre_addition", "view");
  4473. $field_property_post_addition = $this->GetFieldProperty($field_name, "post_addition", "view");
  4474. $field_property_on_item_created = $this->GetFieldProperty($field_name, "on_item_created", "view");
  4475. $field_property_text_length = $this->GetFieldProperty($field_name, "text_length", "view");
  4476. $field_property_type = $this->GetFieldProperty($field_name, "type", "view");
  4477. $field_property_case = $this->GetFieldProperty($field_name, "case", "view");
  4478. $field_property_on_js_event = $this->GetFieldProperty($field_name, "on_js_event", "view", "normal");
  4479. // customized working with field value
  4480. if(function_exists($field_property_on_item_created)) $field_value = $field_property_on_item_created($field_value, &$field_property_type);
  4481. $title = "";
  4482. if(($field_property_text_length != "-1") && ($field_property_text_length != "") && ($field_value != "")){
  4483. if((strlen($field_value)) > $field_property_text_length){
  4484. $field_value = str_replace('"', "&quot;", $field_value); // double quotation mark
  4485. $field_value = str_replace("'", "&#039;", $field_value); // single quotation mark
  4486. $field_value = str_replace(chr(13), "", $field_value); // CR sign
  4487. $field_value = str_replace(chr(10), " ", $field_value); // LF sign
  4488. if($req_print != true){
  4489. if(($fp_tooltip == true) || ($fp_tooltip == "true")){
  4490. if($fp_tooltip_type == "floating"){
  4491. $title = " onmouseover=\"return overlib('".$field_value."');\" onmouseout='return nd();' style='cursor: help;'";
  4492. }else{
  4493. $title = "title='".$field_value."' style='cursor: help;'";
  4494. }
  4495. }
  4496. }
  4497. $field_value = substr($field_value, 0, $field_property_text_length)."...";
  4498. }
  4499. }
  4500. $field_type = ($field_property_type == "") ? "label" : $field_property_type;
  4501. // format case of field value
  4502. if(strtolower($field_property_case) == "upper"){
  4503. $field_value = strtoupper($field_value);
  4504. }else if(strtolower($field_property_case) == "lower"){
  4505. $field_value = $this->StrToLower($field_value);
  4506. }else if(strtolower($field_property_case) == "camel"){
  4507. $field_value_splited = split(" ", $field_value);
  4508. $field_value_camel = "";
  4509. foreach ($field_value_splited as $key) {
  4510. $field_value_camel .= ucfirst($key)." ";
  4511. }
  4512. $field_value = trim($field_value_camel);
  4513. }
  4514. if($req_print == true){ $field_type = "label"; }
  4515. $on_js_event = $field_property_on_js_event;
  4516. switch($field_type){
  4517. case "barchart":
  4518. $field_property_field = $this->GetFieldProperty($field_name, "field", "view");
  4519. $field_property_maximum_value = $this->GetFieldProperty($field_name, "maximum_value", "view");
  4520. if(($field_property_field != "") && ($this->GetFieldOffset($field_property_field) != -1)) $field_value = $row[$this->GetFieldOffset($field_property_field)];
  4521. $barchart_result ="
  4522. <table width='110px;' bgcolor='#dddddd' height='10px' align='center' cellpadding='0' cellspacing='0' ".$on_js_event.">
  4523. <tr title='".$field_value."'>
  4524. <td style='FONT-SIZE:9px;' align='center' width='".($field_value/$field_property_maximum_value * 100)."px' bgcolor='#999999' class='class_nowrap'>
  4525. ".(($field_value > 0) ? $field_value : "")."
  4526. </td>
  4527. <td style='FONT-SIZE:9px;' width='".(100 - ($field_value/$field_property_maximum_value * 100))."px' align='center' class='class_nowrap'>
  4528. ".(($field_value == 0) ? $field_value : "")."
  4529. </td>
  4530. </tr>
  4531. </table>";
  4532. return $barchart_result;
  4533. break;
  4534. case "enum":
  4535. if (is_array($this->columns_view_mode[$field_name]["source"])){
  4536. return $this->nbsp.$this->columns_view_mode[$field_name]["source"][$field_value].$this->nbsp;
  4537. }else{
  4538. return $this->nbsp."<label>".trim($field_value)."</label>".$this->nbsp;
  4539. }
  4540. break;
  4541. case "image":
  4542. $field_property_align = $this->GetFieldProperty($field_name, "align", "view", "lower", "center");
  4543. $field_property_target_path = $this->GetFieldProperty($field_name, "target_path", "view");
  4544. $field_property_image_width = $this->GetFieldProperty($field_name, "image_width", "view", "lower", "50px");
  4545. $field_property_image_height = $this->GetFieldProperty($field_name, "image_height", "view", "lower", "30px");
  4546. $field_property_default = $this->GetFieldProperty($field_name, "default", "view", "normal");
  4547. $field_property_magnify = $this->GetFieldProperty($field_name, "magnify", "view", "normal");
  4548. $img_default = "";
  4549. $img_magnify = "";
  4550. $img_src = $field_property_target_path.trim($field_value);
  4551. if($field_property_default != ""){
  4552. if(file_exists(trim($field_property_default))){
  4553. $img_default = "<img src='".$field_property_default."' width='".$field_property_image_width."' height='".$field_property_image_height."' alt='' title='' ".$on_js_event.">";
  4554. }else{
  4555. $img_default = "<span class='".$this->css_class."_class_label' ".$on_js_event.">".$this->lang['no_image']."</span>";
  4556. }
  4557. }
  4558. if(($field_property_magnify == "true") || ($field_property_magnify == true)){
  4559. $img_magnify = "onmouseover='showtrail(\"".$img_src."\",\"\",\"\",\"1\", ".($field_property_image_height*2).", 1, ".($field_property_image_width*2).");' onmouseout='hidetrail();'";
  4560. }
  4561. if((trim($field_value) !== "") && file_exists($field_property_target_path.trim($field_value))){
  4562. return $this->nbsp."<img style='vertical-align: middle; border:1px;' src='".$img_src."' width='".$field_property_image_width."' height='".$field_property_image_height."' ".$on_js_event." ".$img_magnify.">".$this->nbsp;
  4563. }else{
  4564. return "<table align='".$field_property_align."' style='BORDER: solid 0px #000000;' width='".$field_property_image_width."' height='".$field_property_image_height."'><tr><td align='".$field_property_align."'>".$img_default."</td></tr></table>";
  4565. }
  4566. break;
  4567. case "label":
  4568. if((trim($field_value) != "")
  4569. // we need this for right handling wysiwyg editor values
  4570. && (trim($this->StrToLower($field_value)) !== "<pre></pre>")
  4571. && (trim($this->StrToLower($field_value)) !== "<pre>".$this->nbsp."</pre>")
  4572. && (trim($this->StrToLower($field_value)) !== "<p></p>")
  4573. && (trim($this->StrToLower($field_value)) !== "<p>".$this->nbsp."</p>")){
  4574. return $field_property_pre_addition.$this->nbsp."<label class='".$this->css_class."_class_label' ".$title." ".$on_js_event.">".trim($field_value)."</label>".$this->nbsp.$field_property_post_addition;
  4575. }else{
  4576. return "&nbsp;&nbsp;";
  4577. }
  4578. break;
  4579. case "link":
  4580. case "linkbutton":
  4581. $field_property_field_data = $this->GetFieldProperty($field_name, "field_data", "view", "normal");
  4582. $field_property_rel = $this->GetFieldProperty($field_name, "rel", "view");
  4583. $field_property_href = $this->GetFieldProperty($field_name, "href", "view");
  4584. $field_property_target = $this->GetFieldProperty($field_name, "target", "view");
  4585. if($field_property_field_data != ""){
  4586. $rel = ($field_property_rel != "") ? "rel=".$field_property_rel : "";
  4587. $title = $this->GetFieldTitle($field_name, "view");
  4588. $href = $field_property_href;
  4589. foreach ($this->columns_view_mode[$field_name] as $search_field_key => $search_field_value){
  4590. if(substr($search_field_key, 0, 9) == "field_key"){
  4591. $field_number = intval(substr($search_field_key, 10, strlen($search_field_key) - 10));
  4592. $field_inner = ($this->GetFieldOffset($search_field_value) != "-1") ? $row[$this->GetFieldOffset($search_field_value)] : "";
  4593. if(strpos($field_property_href, "{".$field_number."}") >= 0){
  4594. $href = str_replace("{".$field_number."}", $field_inner, $href);
  4595. }
  4596. }
  4597. }
  4598. // remove unexpected 'http://'s
  4599. if(strstr($field_property_href, "http://") != ""){
  4600. $href = str_replace("http://", "", $href);
  4601. $href = "http://".$href;
  4602. }
  4603. return $this->nbsp."<a class='".$this->css_class."_class_a2' href='".$href."' target='".$field_property_target."' ".$rel." title='".$title."' ".$on_js_event.">".trim($row[$this->GetFieldOffset($field_property_field_data)])."</a>".$this->nbsp;
  4604. }else{
  4605. return $this->nbsp;
  4606. }
  4607. break;
  4608. case "linktoview":
  4609. $curr_url = $this->CombineUrl("details", intval($row[(($this->GetFieldOffset($this->primary_key) != -1) ? $this->GetFieldOffset($this->primary_key) : 0)]));
  4610. $this->SetUrlStringPaging($curr_url);
  4611. $this->SetUrlStringSorting($curr_url);
  4612. $this->SetUrlStringFiltering($curr_url);
  4613. return $this->nbsp."<a class='".$this->css_class."_class_a' href='$curr_url' ".$title." ".$on_js_event.">".trim($field_value)."</a>".$this->nbsp;
  4614. break;
  4615. case "linktoedit":
  4616. $curr_url = $this->CombineUrl("edit", $row[(($this->GetFieldOffset($this->primary_key) != -1) ? $this->GetFieldOffset($this->primary_key) : 0)]);
  4617. $this->SetUrlStringPaging($curr_url);
  4618. $this->SetUrlStringSorting($curr_url);
  4619. $this->SetUrlStringFiltering($curr_url);
  4620. return $this->nbsp."<a class='".$this->css_class."_class_a' href='$curr_url' ".$title." ".$on_js_event.">".trim($field_value)."</a>".$this->nbsp;
  4621. break;
  4622. case "linktodelete":
  4623. $curr_url = $this->CombineUrl("delete", $row[(($this->GetFieldOffset($this->primary_key) != -1) ? $this->GetFieldOffset($this->primary_key) : 0)]);
  4624. $this->SetUrlString($curr_url, "filtering", "sorting", "paging");
  4625. $on_js_event = "onclick = \"return ".$this->uniquePrefix."verifyDelete('$curr_url');\"";
  4626. return $this->nbsp."<a class='".$this->css_class."_class_a' style='cursor:pointer;' ".$title." ".$on_js_event.">".trim($field_value)."</a>".$this->nbsp;
  4627. break;
  4628. case "money":
  4629. $field_property_decimal_places = $this->GetFieldProperty($field_name, "decimal_places", "view");
  4630. $field_property_dec_separator = $this->GetFieldProperty($field_name, "dec_separator", "view");
  4631. $field_property_thousands_separator = $this->GetFieldProperty($field_name, "thousands_separator", "view");
  4632. $field_property_money_sign = $this->GetFieldProperty($field_name, "sign", "view");
  4633. if((trim($field_value) != "")
  4634. // we need this for right handling wysiwyg editor values
  4635. && (trim($this->StrToLower($field_value)) !== "<pre></pre>")
  4636. && (trim($this->StrToLower($field_value)) !== "<pre>".$this->nbsp."</pre>")
  4637. && (trim($this->StrToLower($field_value)) !== "<p></p>")
  4638. && (trim($this->StrToLower($field_value)) !== "<p>".$this->nbsp."</p>")){
  4639. return $field_property_pre_addition.$this->nbsp."<label>".trim($field_property_money_sign.number_format($field_value, $field_property_decimal_places, $field_property_dec_separator, $field_property_thousands_separator))."</label>".$this->nbsp.$field_property_post_addition;
  4640. }else{
  4641. return $this->nbsp;
  4642. }
  4643. break;
  4644. case "password":
  4645. return $this->nbsp."<label class='".$this->css_class."_class_label' ".$title." ".$on_js_event.">******</label>".$this->nbsp;
  4646. break;
  4647. default:
  4648. return $this->nbsp."<label class='".$this->css_class."_class_label' ".$title." ".$on_js_event.">".trim($field_value)."</label>".$this->nbsp; break;
  4649. }
  4650. }
  4651. // -= ADD / EDIT / DETAILS MODE =-
  4652. }else if(($this->mode === "edit") || ($this->mode === "details")){
  4653. if(array_key_exists($field_name, $this->columns_edit_mode)){
  4654. $field_property_maxlength = $this->GetFieldProperty($field_name, "maxlength");
  4655. $field_property_type = $this->GetFieldProperty($field_name, "type");
  4656. $field_property_req_type = ($m_field_req_type != "") ? $m_field_req_type : $this->GetFieldProperty($field_name, "req_type");
  4657. $field_property_width = $this->GetFieldProperty($field_name, "width");
  4658. $field_property_readonly = $this->GetFieldProperty($field_name, "readonly");
  4659. $field_property_default = $this->GetFieldProperty($field_name, "default", "edit", "normal");
  4660. $field_property_on_js_event = $this->GetFieldProperty($field_name, "on_js_event", "edit", "normal");
  4661. $field_property_calendar_type = $this->GetFieldProperty($field_name, "calendar_type");
  4662. $field_property_pre_addition = $this->GetFieldProperty($field_name, "pre_addition");
  4663. $field_property_post_addition = $this->GetFieldProperty($field_name, "post_addition");
  4664. $field_property_on_item_created = $this->GetFieldProperty($field_name, "on_item_created", "edit");
  4665. $field_property_autocomplete = $this->GetFieldProperty($field_name, "autocomplete");
  4666. if($field_property_autocomplete == "off") $autocomplete = "autocomplete='off'"; else $autocomplete = "";
  4667. // customized working with field value
  4668. if(function_exists($field_property_on_item_created)) $field_value = $field_property_on_item_created($field_value, &$field_property_type);
  4669. // detect maxlength for the current field
  4670. $field_maxlength = $this->GetFieldInfo($field_name, 'len', 0);
  4671. if($field_maxlength <= 0) $field_maxlength = "";
  4672. else $field_maxlength = "maxlength='".$field_maxlength."'";
  4673. if($field_property_maxlength == ""){
  4674. if(!$this->IsText($field_name)){ $field_maxlength = "maxlength='50'"; }
  4675. }else{
  4676. if(($field_property_maxlength != "-1") && ($field_property_maxlength != "")){
  4677. $field_maxlength = "maxlength='".$field_property_maxlength."'";
  4678. }
  4679. }
  4680. // detect field's type
  4681. if($field_property_type == ""){ $field_type = "label"; } else $field_type = $field_property_type;
  4682. // get required prefix for a field
  4683. $field_req_type = $field_property_req_type;
  4684. if(strlen(trim($field_req_type)) == 3){ $field_req_type = $field_req_type; }
  4685. else if(strlen(trim($field_req_type)) == 2){ $field_req_type = $field_req_type."y"; }
  4686. else { $field_req_type = "syy"; }
  4687. // detect field's width
  4688. if($field_property_width != "") $field_width = "style='width:".$field_property_width.";'"; else $field_width = "";
  4689. // detect field's readonly property
  4690. if($field_property_readonly == true) { $readonly = "readonly='readonly'"; $disabled = "disabled"; }
  4691. else { $readonly = ""; $disabled = ""; }
  4692. if($req_print == true){ $field_type = "print"; }
  4693. // get default value of field
  4694. if(($req_mode == "add") || ($field_type == "hidden")){
  4695. if($field_property_default != "") { $field_value = $field_property_default; }
  4696. ///d 4.02.08 && ($field_property_default != 0)
  4697. }
  4698. $on_js_event = $field_property_on_js_event;
  4699. if ($this->mode === "edit"){
  4700. // save entered values from fields in add/edit modes
  4701. $req_field_value = $this->GetVariable($field_req_type.$field_name, false, "post");
  4702. if($req_field_value != "") $field_value = $req_field_value;
  4703. switch($field_type){
  4704. case "checkbox":
  4705. $checked = "";
  4706. $field_property_true_value = $this->GetFieldProperty($field_name, "true_value");
  4707. $field_property_false_value = $this->GetFieldProperty($field_name, "false_value");
  4708. if(($field_property_true_value != "") && ($field_property_false_value != "")){
  4709. if($field_value == $field_property_true_value){
  4710. $checked = "checked";
  4711. }
  4712. }
  4713. echo $field_property_pre_addition.$this->nbsp."<input class='".$this->css_class."_class_checkbox' type='checkbox' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."' title='".$this->GetFieldTitle($field_name)."' value='".trim($field_value)."' ".$checked." ".$readonly." ".$on_js_event.">".$this->nbsp.$field_property_post_addition;
  4714. break;
  4715. case "date":
  4716. return $this->DrawCalendarButton($field_name, $field_type, "Y-m-d", $field_value, $field_property_pre_addition, $field_property_post_addition, $field_width, $field_maxlength, $on_js_event, $readonly, $field_property_calendar_type);
  4717. break;
  4718. case "datedmy":
  4719. return $this->DrawCalendarButton($field_name, $field_type, "d-m-Y", $field_value, $field_property_pre_addition, $field_property_post_addition, $field_width, $field_maxlength, $on_js_event, $readonly, $field_property_calendar_type);
  4720. break;
  4721. case "datetime":
  4722. return $this->DrawCalendarButton($field_name, $field_type, "Y-m-d H:i:s", $field_value, $field_property_pre_addition, $field_property_post_addition, $field_width, $field_maxlength, $on_js_event, $readonly, $field_property_calendar_type);
  4723. break;
  4724. case "datetimedmy":
  4725. return $this->DrawCalendarButton($field_name, $field_type, "d-m-Y H:i:s", $field_value, $field_property_pre_addition, $field_property_post_addition, $field_width, $field_maxlength, $on_js_event, $readonly, $field_property_calendar_type);
  4726. break;
  4727. case "enum":
  4728. $ret_enum = "";
  4729. $field_property_view_type = $this->GetFieldProperty($field_name, "view_type");
  4730. $field_property_radiobuttons_alignment = $this->GetFieldProperty($field_name, "radiobuttons_alignment");
  4731. if($this->GetFieldProperty($field_name, "multiple") == true){ $enum_multiple = true; } else { $enum_multiple = false; }
  4732. $field_property_multiple_size = $this->GetFieldProperty($field_name, "multiple_size", "edit", "lower", "4");
  4733. switch($field_property_view_type){
  4734. case "radiobutton":
  4735. if(is_array($this->columns_edit_mode[$field_name]["source"])){ // don't remove columns_edit_mode
  4736. $ret_enum .= $this->nbsp.$this->DrawRadioButtons($this->GetFieldRequiredType($field_name).$field_name, $field_name, $this->columns_edit_mode[$field_name]["source"], $field_value, 'source', "", $disabled, $on_js_event, $field_property_radiobuttons_alignment).$this->nbsp;
  4737. }else{
  4738. $ret_enum .= $this->nbsp.$this->DrawRadioButtons($this->GetFieldRequiredType($field_name).$field_name, $field_name, $this->GetEnumValues($this->tbl_name, $field_name), $field_value, 'source', "", $disabled, $on_js_event, $field_property_radiobuttons_alignment).$this->nbsp;
  4739. }
  4740. break;
  4741. case "dropdownlist":
  4742. default:
  4743. if(is_array($this->columns_edit_mode[$field_name]["source"])){ // don't remove columns_edit_mode
  4744. $ret_enum .= $this->nbsp.$this->DrawDropDownList($this->GetFieldRequiredType($field_name).$field_name, '', $this->columns_edit_mode[$field_name]["source"], $field_value, "", "", "", $disabled, $on_js_event, $enum_multiple, $field_property_multiple_size).$this->nbsp;
  4745. }else{
  4746. $ret_enum .= $this->nbsp.$this->DrawDropDownList($this->GetFieldRequiredType($field_name).$field_name, '', $this->GetEnumValues($this->tbl_name, $field_name), trim($field_value), "", "", "", $disabled, $on_js_event, $enum_multiple, $field_property_multiple_size).$this->nbsp;
  4747. }
  4748. break;
  4749. }
  4750. return $ret_enum;
  4751. break;
  4752. case "hidden":
  4753. $ret_hidden ="<input type='hidden' id='".$this->GetFieldRequiredType($field_name).$field_name."' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."' value='".trim($field_value)."'>";
  4754. return $ret_hidden;
  4755. break;
  4756. case "image":
  4757. case "file":
  4758. $ret_file = "";
  4759. $file = false;
  4760. $file_error_msg = "";
  4761. $file_name_view = $field_value;
  4762. $file_act = $this->GetVariable('file_act');
  4763. $file_id = $this->GetVariable('file_id');
  4764. $rid = $this->GetVariable('rid');
  4765. // where the file is going to be placed
  4766. $field_property_target_path = $this->GetFieldProperty($field_name, "target_path");
  4767. $field_property_file_name = $this->GetFieldProperty($field_name, "file_name");
  4768. $field_property_image_width = $this->GetFieldProperty($field_name, "image_width", "edit", "lower", "120px");
  4769. $field_property_image_height = $this->GetFieldProperty($field_name, "image_height", "edit", "lower", "90px");
  4770. $field_property_max_file_size = $this->GetFieldProperty($field_name, "max_file_size", "edit", "lower");
  4771. $field_property_magnify = $this->GetFieldProperty($field_name, "magnify", "edit");
  4772. $img_magnify = "";
  4773. if($this->GetFieldProperty($field_name, "host") == "remote"){
  4774. // *** upload file from url (remote host)
  4775. $ret_file = "";
  4776. if(trim($field_value) == ""){
  4777. if(($file_act == "upload") && ($file_id == $field_name)){
  4778. $file_error_msg = $this->lang['file_uploading_error'];
  4779. $file = false;
  4780. }
  4781. }else{
  4782. if(($file_act == "remove") && ($file_id == $field_name)){
  4783. $sql = "UPDATE $this->tbl_name SET ".$field_name." = '' WHERE $this->primary_key = '".$rid."' ";
  4784. $this->db_handler->query($sql);
  4785. // delete file from target path
  4786. if(file_exists($field_property_target_path.$field_value)){ unlink($field_property_target_path.$field_value); }
  4787. else{ $file_error_msg = $this->lang['file_deleting_error']; }
  4788. $file = false;
  4789. }else if(($file_act == "upload") && ($file_id == $field_name)){
  4790. if($downloaded_file = fopen($field_value, "r")){
  4791. // commented 21.09.2008 $content = fread($downloaded_file, $this->GetRemoteFileSize($field_value));
  4792. $content = $this->HttpGetFile($field_value);
  4793. // get file name from url
  4794. $field_value = strrev($field_value);
  4795. $last_slash = strlen($field_value) - strpos($field_value,'/');
  4796. $field_value = strrev($field_value);
  4797. if($last_slash) { $field_value = substr($field_value,$last_slash); }
  4798. if($field_property_file_name != ""){
  4799. $file_name_view = $field_property_file_name.strchr(basename($field_value),".");
  4800. $field_value = $file_name_view;
  4801. }
  4802. if($uploaded_file = fopen($field_property_target_path.$field_value, "w")){
  4803. if(!fwrite($uploaded_file, $content)){
  4804. $file_error_msg = $this->lang['file_writing_error'];
  4805. $file = false;
  4806. }else{
  4807. //echo "eee";
  4808. $sql = "UPDATE $this->tbl_name SET ".$field_name;
  4809. $sql .= " = '".$field_value."' ";
  4810. $sql .= " WHERE $this->primary_key= '".$rid."' ";
  4811. $this->db_handler->query($sql);
  4812. $file = true;
  4813. fclose($uploaded_file);
  4814. }
  4815. }
  4816. fclose($downloaded_file);
  4817. }else{
  4818. $file_error_msg = $this->lang['file_uploading_error'];
  4819. }
  4820. }else{
  4821. $file = true;
  4822. }
  4823. }
  4824. // if there is a file (uploaded or exists)
  4825. if($file == true){
  4826. //echo $target_path.$field_value;
  4827. if(strlen($field_value) > 40){
  4828. $str_start = strlen($field_value) - 40;
  4829. $str_prefix = "...";
  4830. }else{
  4831. $str_start = 0;
  4832. $str_prefix = "";
  4833. }
  4834. //$ret_file .= "<input type='hidden' name='".$this->uniquePrefix."file_act' id='".$this->uniquePrefix."file_act' value='remove'>";
  4835. $ret_file .= "<table><tr valign='middle'><td align='center'>";
  4836. if($field_type == "image"){
  4837. list($f_width, $f_height, $f_type, $f_attr) = getimagesize($field_property_target_path.$field_value);
  4838. $f_size = number_format((filesize($field_property_target_path.$field_value)/1024),2,".",",")." Kb";
  4839. if(($field_property_magnify == "true") || ($field_property_magnify == true)){
  4840. $img_magnify = "onmouseover='showtrail(\"".$field_property_target_path.$field_value."\",\"\",\"\",\"1\", ".($field_property_image_height*2).", 1, ".($field_property_image_width*2).");' onmouseout='hidetrail();'";
  4841. }
  4842. $ret_file .= $this->nbsp."<img src='".$field_property_target_path.$field_value."' height='".$field_property_image_height."' width='".$field_property_image_width."' title='$field_value ($f_width x $f_height - $f_size)' alt='$field_value' ".$img_magnify.">".$this->nbsp;
  4843. }else{
  4844. $ret_file .= $this->nbsp.$str_prefix.substr($file_name_view, $str_start, 40).$this->nbsp;
  4845. }
  4846. if($field_type == "image") $ret_file .= "<br>";
  4847. else $ret_file .= "&nbsp;&nbsp;";
  4848. if(($field_property_readonly != "true") && ($field_property_readonly != true)){
  4849. $ret_file .= $this->nbsp."[<a class='".$this->css_class."_class_a' href='' onclick='formAction(\"remove\", \"".$field_name."\", \"".$this->uniquePrefix."\", \"".$this->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\"); return false;'><b>".$this->lang['remove']."</b></a>]".$this->nbsp;
  4850. }
  4851. $ret_file .= "</td></tr></table>";
  4852. $ret_file .= "<input type='hidden' value='$field_value' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."'>";
  4853. }else{
  4854. //$ret_file .= "<input type='hidden' name='".$this->uniquePrefix."file_act' id='".$this->uniquePrefix."file_act' value='upload'>";
  4855. if($file_error_msg != "") $ret_file .= $this->nbsp."<label class='".$this->css_class."_class_error_message no_print'>".$file_error_msg."</label><br>";
  4856. $ret_file .= $this->nbsp."<input type='textbox' class='".$this->css_class."_class_textbox' ".$field_width." title='".$this->GetFieldTitle($field_name)."' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."' ".$disabled." ".$on_js_event.">&nbsp;&nbsp;";
  4857. $ret_file .= "[<a class='".$this->css_class."_class_a' ".(($disabled == "disabled") ? "" : "style='cursor: pointer;' onclick='formAction(\"upload\", \"".$field_name."\", \"".$this->uniquePrefix."\", \"".$this->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\"); return false;'")."><b>".$this->lang['upload']."</b></a>]".$this->nbsp;
  4858. }
  4859. return $ret_file;
  4860. }else{
  4861. // *** upload file from local machine
  4862. $ret_file = "";
  4863. if(trim($field_value) == ""){
  4864. $file = true;
  4865. $file_name = $this->GetFieldRequiredType($field_name).$field_name;
  4866. if((count($_FILES) > 0) && ($file_id == $field_name)){
  4867. if (isset($_FILES[$file_name]["error"]) && ($_FILES[$file_name]["error"] > 0)){
  4868. $file_error_msg = $this->lang['file_uploading_error'];
  4869. if($this->debug){ $file_error_msg .= "Error: ".$_FILES[$file_name]["error"]; }
  4870. $file = false;
  4871. }else{
  4872. // check file's max size
  4873. if($field_property_max_file_size != ""){
  4874. $max_file_size = $field_property_max_file_size;
  4875. if (!is_numeric($max_file_size)) {
  4876. if (strpos($max_file_size, 'm') !== false)
  4877. $max_file_size = intval($max_file_size)*1024*1024;
  4878. elseif (strpos($max_file_size, 'k') !== false)
  4879. $max_file_size = intval($max_file_size)*1024;
  4880. elseif (strpos($max_file_size, 'g') !== false)
  4881. $max_file_size = intval($max_file_size)*1024*1024*1024;
  4882. }
  4883. if(isset($_FILES[$file_name]["size"]) && ($_FILES[$file_name]["size"] > $max_file_size)){
  4884. $file = false;
  4885. $file_error_msg = $this->lang['file_invalid file_size'].": ".number_format(($_FILES[$file_name]["size"]/1024),2,".",",")." Kb (".$this->lang['max'].". ".number_format(($max_file_size/1024),2,".",",")." Kb) ";
  4886. }
  4887. }
  4888. }
  4889. if($file == true){
  4890. // create a directory for uploading, if it was not.
  4891. if (!file_exists($field_property_target_path)) { mkdir($field_property_target_path,0744); }
  4892. // add the original filename to our target path. Result is "uploads/filename.extension"
  4893. if($field_property_file_name != ""){
  4894. $target_path_full = $field_property_target_path . $field_property_file_name.strchr(basename($_FILES[$file_name]['name']),".");
  4895. }else{
  4896. $target_path_full = $field_property_target_path . (isset($_FILES[$file_name]['name']) ? basename($_FILES[$file_name]['name']) : "") ;
  4897. }
  4898. if(isset($_FILES[$file_name]['tmp_name'])){
  4899. if(move_uploaded_file($_FILES[$file_name]['tmp_name'], $target_path_full)) {
  4900. chmod($target_path_full, 0644);
  4901. $sql = "UPDATE $this->tbl_name SET ".$field_name;
  4902. if($field_property_file_name != ""){
  4903. $file_name_view = $field_property_file_name.strchr(basename($_FILES[$file_name]['name']),".");
  4904. $field_value = $field_property_file_name.strchr(basename($_FILES[$file_name]['name']),".");
  4905. $sql .= " = '".$field_property_file_name.strchr(basename($_FILES[$file_name]['name']),".")."'";
  4906. }else{
  4907. $file_name_view = $_FILES[$file_name]['name'];
  4908. $field_value = $_FILES[$file_name]['name'];
  4909. $sql .= " = '".$_FILES[$file_name]['name']."' ";
  4910. }
  4911. $sql .= " WHERE $this->primary_key= '".$rid."' ";
  4912. $dSet = $this->db_handler->query($sql);
  4913. if(($this->debug) && ($this->db_handler->isError($dSet) == 1)){
  4914. $this->is_error = true;
  4915. $this->AddErrors($dSet);
  4916. }
  4917. $file = true;
  4918. } else{
  4919. $file_error_msg = $this->lang['file_uploading_error'];
  4920. $file = false;
  4921. }
  4922. }else{
  4923. $file = false;
  4924. }
  4925. }
  4926. }else{
  4927. $file = false;
  4928. }
  4929. }else{
  4930. if(($file_act == "remove") && ($file_id == $field_name)){
  4931. $sql = "UPDATE $this->tbl_name SET ".$field_name." = '' WHERE $this->primary_key = '".$rid."' ";
  4932. $this->db_handler->query($sql);
  4933. // delete file from target path
  4934. if(file_exists($field_property_target_path.$field_value)){
  4935. unlink($field_property_target_path.$field_value);
  4936. }else{
  4937. $file_error_msg = $this->lang['file_deleting_error'];
  4938. }
  4939. $file = false;
  4940. }else{
  4941. $file = true;
  4942. }
  4943. }
  4944. // if there is a file (uploaded or exists)
  4945. if($file == true){
  4946. if(strlen($field_value) > 40){
  4947. $str_start = strlen($field_value) - 40;
  4948. $str_prefix = "...";
  4949. }else{
  4950. $str_start = 0;
  4951. $str_prefix = "";
  4952. }
  4953. //$ret_file .= "<input type='hidden' name='".$this->uniquePrefix."file_act' id='".$this->uniquePrefix."file_act' value='remove'>";
  4954. $ret_file .= "<table><tr valign='middle'><td align='center'>";
  4955. if($field_type == "image"){
  4956. $f_width = $f_height = $f_size = 0;
  4957. if(file_exists($field_property_target_path.$field_value)){
  4958. list($f_width, $f_height, $f_type, $f_attr) = getimagesize($field_property_target_path.$field_value);
  4959. $f_size = number_format((filesize($field_property_target_path.$field_value)/1024),2,".",",")." Kb";
  4960. }else{
  4961. $ret_file .= $this->nbsp."<label class='".$this->css_class."_class_error_message no_print'>".$this->lang['file_uploading_error']."</label><br>";
  4962. }
  4963. if(($field_property_magnify == "true") || ($field_property_magnify == true)){
  4964. $img_magnify = "onmouseover='showtrail(\"".$field_property_target_path.$field_value."\",\"\",\"\",\"1\", ".($field_property_image_height*2).", 1, ".($field_property_image_width*2).");' onmouseout='hidetrail();'";
  4965. }
  4966. $ret_file .= $this->nbsp."<img src='".$field_property_target_path.$field_value."' height='".$field_property_image_height."' width='".$field_property_image_width."' title='$field_value ($f_width x $f_height - $f_size)' alt='$field_value' ".$img_magnify.">".$this->nbsp;
  4967. }else{
  4968. $ret_file .= $this->nbsp.$str_prefix.substr($file_name_view, $str_start, 40).$this->nbsp;
  4969. }
  4970. if($field_type == "image") $ret_file .= "<br>";
  4971. else $ret_file .= "&nbsp;&nbsp;";
  4972. if(($field_property_readonly != "true") && ($field_property_readonly != true)){
  4973. $ret_file .= $this->nbsp."[<a class='".$this->css_class."_class_a' href='javascript:void(0);' onclick='formAction(\"remove\", \"".$field_name."\", \"".$this->uniquePrefix."\", \"".$this->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\"); return false;'><b>".$this->lang['remove']."</b></a>]".$this->nbsp;
  4974. }
  4975. $ret_file .= "</td></tr></table>";
  4976. $ret_file .= "<input type='hidden' value='$field_value' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."'>";
  4977. }else{
  4978. //$ret_file .= "<input type='hidden' name='".$this->uniquePrefix."file_act' id='".$this->uniquePrefix."file_act' value='upload'>";
  4979. if($file_error_msg != "") $ret_file .= $this->nbsp."<label class='".$this->css_class."_class_error_message no_print'>".$file_error_msg."</label><br>";
  4980. $ret_file .= $this->nbsp."<input type='file' class='".$this->css_class."_class_textbox' ".$field_width." title='".$this->GetFieldTitle($field_name)."' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."' ".$disabled." ".$on_js_event.">&nbsp;&nbsp;";
  4981. $ret_file .= "[<a class='".$this->css_class."_class_a' ".(($disabled == "disabled") ? "" : "style='cursor: pointer;' onclick='formAction(\"upload\", \"".$field_name."\", \"".$this->uniquePrefix."\", \"".$this->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\"); return false;'")."><b>".$this->lang['upload']."</b></a>]".$this->nbsp;
  4982. }
  4983. return $ret_file;
  4984. }
  4985. break;
  4986. case "label":
  4987. return $this->nbsp."<label class='".$this->css_class."_class_textbox' ".$field_width." ".$on_js_event.">".trim($field_value)."</label>".$this->nbsp;
  4988. break;
  4989. case "link":
  4990. return $this->nbsp."<input type='text' class='".$this->css_class."_class_textbox' ".$field_width." title='".$this->GetFieldTitle($field_name)."' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."' value='".trim($field_value)."' $field_maxlength $readonly ".$on_js_event.">".$this->nbsp;
  4991. break;
  4992. case "password":
  4993. return $this->nbsp."<input type='password' class='".$this->css_class."_class_textbox' ".$field_width." title='".$this->GetFieldTitle($field_name)."' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."' value='".trim($field_value)."' $field_maxlength $readonly ".$on_js_event.">".$this->nbsp;
  4994. break;
  4995. case "print":
  4996. return $this->nbsp."<label class='".$this->css_class."_class_label' ".$field_width.">".trim($field_value)."</label>".$this->nbsp;
  4997. break;
  4998. case "textarea":
  4999. $field_value = str_replace('"', "&quot;", $field_value); // double quotation mark
  5000. $field_value = str_replace("'", "&#039;", $field_value); // single quotation mark
  5001. $resizable = $field_property_resizable = $this->GetFieldProperty($field_name, "resizable", "edit", "lower", "false");
  5002. $field_rows = $field_property_rows = $this->GetFieldProperty($field_name, "rows", "edit", "lower", "3");
  5003. $field_cols = $field_property_cols = $this->GetFieldProperty($field_name, "cols", "edit", "lower", "23");
  5004. $field_edit_type = $field_property_edit_type = $this->GetFieldProperty($field_name, "edit_type");
  5005. $field_wysiwyg_width = $field_property_width = $this->GetFieldProperty($field_name, "width", "edit", "lower", "0");
  5006. $field_id = $this->GetFieldRequiredType($field_name).$field_name;
  5007. if(strtolower($field_edit_type) == "wysiwyg") $field_maxlength = "";
  5008. if(($resizable == true) || ($resizable == "true")) { $field_class = "class='resizable'"; } else { $field_class = ""; };
  5009. $texarea = $this->nbsp."<textarea ".$field_class." id='".$field_id."' name='".$field_id."' title='".$this->GetFieldTitle($field_name)."' rows='".$field_rows."' cols='".$field_cols."' ".$field_maxlength." ".$field_width." ".$readonly." ".$on_js_event." >".trim($field_value)."</textarea>".$this->nbsp;
  5010. if((strtolower($this->browser_name) != "netscape") && strtolower($field_edit_type) == "wysiwyg"){
  5011. $texarea .= $this->nbsp."\n<script type='text/javascript'>\n";
  5012. $texarea .= "<!--\n";
  5013. $texarea .= "wysiwygWidth = ".((intval($field_wysiwyg_width) > ((9.4)*$field_cols)) ? intval($field_wysiwyg_width) : ((9.4)*$field_cols)).";";
  5014. $texarea .= "wysiwygHeight = ".(21*$field_rows).";";
  5015. $texarea .= "generate_wysiwyg('".$this->GetFieldRequiredType($field_name).$field_name."'); \n";
  5016. $texarea .= "//-->\n";
  5017. $texarea .= "</script>\n";
  5018. }
  5019. return $texarea;
  5020. break;
  5021. case "textbox":
  5022. $field_value = str_replace('"', "&quot;", $field_value); // double quotation mark
  5023. $field_value = str_replace("'", "&#039;", $field_value); // single quotation mark
  5024. return $field_property_pre_addition.$this->nbsp."<input class='".$this->css_class."_class_textbox' ".$field_width." type='text' title='".$this->GetFieldTitle($field_name)."' name='".$field_req_type.$field_name."' id='".$field_req_type.$field_name."' value='".trim($field_value)."' ".$field_maxlength." ".$readonly." ".$on_js_event." ".$autocomplete.">".$this->nbsp.$field_property_post_addition;
  5025. break;
  5026. case "time":
  5027. $ret_date = $this->nbsp."<input class='".$this->css_class."_class_textbox' ".$field_width." readonly type='text' title='".$this->GetFieldTitle($field_name)."' id='".$this->GetFieldRequiredType($field_name).$field_name."' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."' value='".trim($field_value)."' $field_maxlength ".$on_js_event.">";
  5028. if($field_property_calendar_type == "floating"){
  5029. if(!$readonly) $ret_date .= "<img id='img".$this->GetFieldRequiredType($field_name).$field_name."' src='".$this->directory."images/".$this->css_class."/cal.gif' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='cursor:pointer;margin:3px;margin-left:6px;margin-right:6px;border:0px;'></a>\n"."<script type='text/javascript'>Calendar.setup({inputField : '".$this->GetFieldRequiredType($field_name).$field_name."', ifFormat : '%H:%M:%S', showsTime : true, button : 'img".$this->GetFieldRequiredType($field_name).$field_name."'});</script>".$this->nbsp;
  5030. }else{
  5031. if(!$readonly) $ret_date .= "<a class='".$this->css_class."_class_a2' title='".$this->GetFieldTitle($field_name)."' href=\"javascript: openCalendar('".$this->directory."','', '".$this->uniquePrefix."frmEditRow', '$field_req_type', '".$field_name."', '$field_type')\"><img src='".$this->directory."images/".$this->css_class."/cal.gif' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='MARGIN:3px;margin-left:6px;margin-right:6px;border:0px;'></a>".$this->nbsp;
  5032. }
  5033. if(!$readonly) $ret_date .= "<a class='".$this->css_class."_class_a2' style='cursor: pointer;' onClick='document.getElementById(\"".$this->GetFieldRequiredType($field_name).$field_name."\").value=\"".date("H:i:s")."\"'>[".date("H:i:s")."]</a>";
  5034. if((!$readonly) && (substr($this->GetFieldRequiredType($field_name), 0, 1) == "s")) $ret_date .= "&nbsp;<a class='".$this->css_class."_class_a2' style='cursor: pointer;' onClick='document.getElementById(\"".$this->GetFieldRequiredType($field_name).$field_name."\").value=\"\"' title='".$this->lang['clear']."'>[".$this->lang['clear']."]</a>";
  5035. return $ret_date;
  5036. break;
  5037. case "validator":
  5038. $field_property_for_field = $this->GetFieldProperty($field_name, "for_field");
  5039. $field_property_validation_type = $this->GetFieldProperty($field_name, "validation_type");
  5040. $field_req_type = $this->GetFieldRequiredType($field_property_for_field, true);
  5041. if($field_property_validation_type == "password"){ $validator_field_type = "password"; } else { $validator_field_type = "text"; }
  5042. return $this->nbsp."<input type='".$validator_field_type."' class='".$this->css_class."_class_textbox' ".$field_width." title='".$this->GetFieldTitle($field_name)."' name='".$field_req_type.$field_property_for_field."' id='".$field_req_type.$field_property_for_field."' value='' $field_maxlength $readonly ".$on_js_event.">".$this->nbsp;
  5043. break;
  5044. default:
  5045. return $this->nbsp."<input type='text' class='".$this->css_class."_class_textbox' ".$field_width." title='".$this->GetFieldTitle($field_name)."' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."' value='".trim($field_value)."' $field_maxlength $readonly ".$on_js_event.">".$this->nbsp;
  5046. break;
  5047. }
  5048. }else if ($this->mode === "details"){
  5049. switch($field_type){
  5050. case "checkbox":
  5051. return $this->nbsp.(($field_value == 1) ? $this->lang['yes'] : $this->lang['no']).$this->nbsp;
  5052. break;
  5053. case "date":
  5054. $field_value = substr(trim($field_value), 0, 10);
  5055. return $this->nbsp.(($field_value == '0000-00-00') ? '' : $field_value).$this->nbsp;
  5056. break;
  5057. case "datedmy":
  5058. return $this->nbsp.$this->MyDate($field_value, "datedmy").$this->nbsp;
  5059. break;
  5060. case "datetime":
  5061. $field_value = trim($field_value);
  5062. return $this->nbsp.(($field_value == '0000-00-00 00:00:00') ? '' : $field_value).$this->nbsp;
  5063. break;
  5064. case "datetimedmy":
  5065. return $this->nbsp.$this->MyDate($field_value, "datetimedmy").$this->nbsp;
  5066. break;
  5067. case "enum":
  5068. // don't remove columns_edit_mode
  5069. if(isset($this->columns_edit_mode[$field_name]['source']) && is_array($this->columns_edit_mode[$field_name]['source'])){
  5070. foreach($this->columns_edit_mode[$field_name]['source'] as $val => $opt){
  5071. if($field_value == $val) return $this->nbsp.trim($opt).$this->nbsp;
  5072. }
  5073. }
  5074. return $this->nbsp.trim($field_value).$this->nbsp;
  5075. break;
  5076. case "hidden":
  5077. return ""; break;
  5078. case "image":
  5079. $field_property_target_path = $this->GetFieldProperty($field_name, "target_path");
  5080. $field_property_image_width = $this->GetFieldProperty($field_name, "image_width", "edit", "lower", "50px");
  5081. $field_property_image_height = $this->GetFieldProperty($field_name, "image_height", "edit", "lower", "30px");
  5082. $field_property_default = $this->GetFieldProperty($field_name, "default", "edit", "normal");
  5083. $img_default = (($field_property_default != "") && file_exists($field_property_target_path.trim($field_property_default))) ? "<img src='".$field_property_target_path.$field_property_default."' width='".$field_property_image_width."' height='".$field_property_image_height."' alt='' title=''>" : "<span class='".$this->css_class."_class_label'>".$this->lang['no_image']."</span>";
  5084. $field_property_magnify = $this->GetFieldProperty($field_name, "magnify", "edit");
  5085. $img_magnify = "";
  5086. if((trim($field_value) !== "") && file_exists($field_property_target_path.trim($field_value))){
  5087. if(($field_property_magnify == "true") || ($field_property_magnify == true)){
  5088. $img_magnify = "onmouseover='showtrail(\"".$field_property_target_path.trim($field_value)."\",\"\",\"\",\"1\", ".($field_property_image_height*2).", 1, ".($field_property_image_width*2).");' onmouseout='hidetrail();'";
  5089. }
  5090. return $this->nbsp."<img style='vertical-align: middle;border:1px;' src='".$field_property_target_path.trim($field_value)."' width='".$field_property_image_width."' height='".$field_property_image_height."' ".$img_magnify.">".$this->nbsp;
  5091. }else{
  5092. return "<table style='BORDER: solid 1px #000000;' width='".$field_property_image_width."' height='".$field_property_image_height."'><tr><td align='center'>".$img_default."</td></tr></table>";
  5093. }
  5094. break;
  5095. case "label":
  5096. return $this->nbsp.trim($field_value)."";
  5097. break;
  5098. case "link":
  5099. $field_property_field_data = $this->GetFieldProperty($field_name, "field_data", "details", "normal");
  5100. if($field_property_field_data != ""){
  5101. $href_inner = $field_property_href = $this->GetFieldProperty($field_name, "href");
  5102. $field_property_target = $this->GetFieldProperty($field_name, "target");
  5103. $on_js_event = $field_property_on_js_event = $this->GetFieldProperty($field_name, "on_js_event", "details", "normal");
  5104. foreach ($this->columns_edit_mode[$field_name] as $search_field_key => $search_field_value){
  5105. if(substr($search_field_key, 0, 9) == "field_key"){
  5106. $field_number = intval(substr($search_field_key, 10, strlen($search_field_key) - 10));
  5107. $field_inner = $row[$this->GetFieldOffset($search_field_value)];
  5108. if(strpos($href_inner, "{".$field_number."}") >= 0){
  5109. $href = str_replace("{".$field_number."}", $field_inner, $href_inner);
  5110. }
  5111. }
  5112. }
  5113. // remove unexpected 'http://'s
  5114. if(strstr($href_inner, "http://") != ""){
  5115. $href = str_replace("http://", "", $href);
  5116. $href = "http://".$href;
  5117. }
  5118. $link_value = ($this->GetFieldOffset($field_property_field_data) != "-1") ? trim($row[$this->GetFieldOffset($field_property_field_data)]) : "";
  5119. return $this->nbsp."<a class='".$this->css_class."_class_a2' href='".$href."' target='".$field_property_target."' ".$on_js_event.">".$link_value."</a>".$this->nbsp;
  5120. }else{
  5121. return $this->nbsp;
  5122. }
  5123. break;
  5124. case "password":
  5125. return $this->nbsp."<label class='".$this->css_class."_class_label'>******</label>".$this->nbsp;
  5126. break;
  5127. case "print":
  5128. return $this->nbsp."<label class='".$this->css_class."_class_label' ".$field_width.">".trim($field_value)."</label>".$this->nbsp;
  5129. break;
  5130. case "textarea":
  5131. case "textbox":
  5132. return $field_property_pre_addition.$this->nbsp.trim($field_value).$field_property_post_addition;
  5133. break;
  5134. case "validator":
  5135. return ""; break;
  5136. default:
  5137. return $this->nbsp.trim($field_value)."";
  5138. break;
  5139. }
  5140. }
  5141. }
  5142. }
  5143. return false;
  5144. }
  5145. //--------------------------------------------------------------------------
  5146. // add Check Boxes Values
  5147. //--------------------------------------------------------------------------
  5148. protected function AddCheckBoxesValues(){
  5149. foreach($this->columns_edit_mode as $itemName => $itemValue){
  5150. if(isset($itemValue['type']) && $itemValue['type'] == "checkbox"){
  5151. $found = false;
  5152. foreach($_POST as $i => $v){
  5153. if($i == $this->GetFieldRequiredType($itemName).$itemName){
  5154. $found = true;
  5155. }
  5156. }
  5157. if(!$found){
  5158. $_POST[$this->GetFieldRequiredType($itemName).$itemName] = $itemValue['false_value'];
  5159. }else{
  5160. $_POST[$this->GetFieldRequiredType($itemName).$itemName] = $itemValue['true_value'];
  5161. }
  5162. }
  5163. }
  5164. }
  5165. //--------------------------------------------------------------------------
  5166. // get $_REQUEST variable
  5167. //--------------------------------------------------------------------------
  5168. protected function GetVariable($var = "", $prefix = true, $method = "request"){
  5169. $prefix = (($prefix == true) || ($prefix == "true")) ? true : false;
  5170. $unique_prefix = ($prefix) ? $this->uniquePrefix : "" ;
  5171. $unique_prefix_var = (isset($_GET[$unique_prefix.$var])) ? $_GET[$unique_prefix.$var] : "0";
  5172. // check for possible hack attack
  5173. $max_page_size = intval(max($this->pages_array));
  5174. if(($var == "page_size") && (intval($unique_prefix_var) > intval($max_page_size))) {
  5175. return $max_page_size;
  5176. }
  5177. switch($method){
  5178. case "get":
  5179. return isset($_GET[$unique_prefix.$var]) ? $_GET[$unique_prefix.$var] : "";
  5180. break;
  5181. case "post":
  5182. return isset($_POST[$unique_prefix.$var]) ? $_POST[$unique_prefix.$var] : "";
  5183. break;
  5184. default:
  5185. return isset($_REQUEST[$unique_prefix.$var]) ? $_REQUEST[$unique_prefix.$var] : "";
  5186. break;
  5187. }
  5188. }
  5189. //--------------------------------------------------------------------------
  5190. // draw RadioButtons
  5191. //--------------------------------------------------------------------------
  5192. protected function DrawRadioButtons($tag_name, $field_name, &$select_array, $compare = "", $sub_field_value="", $sub_field_name="", $disabled="", $on_js_event="", $radiobuttons_alignment=""){
  5193. $req_print = $this->GetVariable('print');
  5194. $break_by = ($radiobuttons_alignment == "vertical") ? "<br>" : "";
  5195. $text = "";
  5196. if($req_print != true){
  5197. if($on_js_event !="") $text .= "<span ".$on_js_event.">";
  5198. if(is_object($select_array)){
  5199. while($row = $select_array->fetchRow()){
  5200. if(strtolower($row[$this->foreign_keys_array[$field_name][$sub_field_value]]) == strtolower($compare))
  5201. $text .= "<input class='".$this->css_class."_class_radiobutton' type='radio' title='".$this->GetFieldTitle($field_name)."' name='".$tag_name."' id='".$tag_name."' value='".$row[$this->foreign_keys_array[$field_name][$sub_field_value]]."' checked ".$disabled.">".$row[$this->foreign_keys_array[$field_name][$sub_field_name]].$this->nbsp.$break_by;
  5202. else
  5203. $text .= "<input class='".$this->css_class."_class_radiobutton' type='radio' title='".$this->GetFieldTitle($field_name)."' name='".$tag_name."' id='".$tag_name."' value='".$row[$this->foreign_keys_array[$field_name][$sub_field_value]]."' ".$disabled.">".$row[$this->foreign_keys_array[$field_name][$sub_field_name]].$this->nbsp.$break_by;
  5204. }
  5205. }else{
  5206. foreach($select_array as $key => $val){
  5207. if(strtolower($key) == strtolower($compare)){
  5208. $text .= "<input class='".$this->css_class."_class_radiobutton' type='radio' id='".$tag_name."' name='".$tag_name."' value='".$key."' title='".$this->GetFieldTitle($field_name)."' checked ".$disabled.">".$val."&nbsp;".$break_by;
  5209. }else{
  5210. $text .= "<input class='".$this->css_class."_class_radiobutton' type='radio' id='".$tag_name."' name='".$tag_name."' value='".$key."' title='".$this->GetFieldTitle($field_name)."' ".$disabled.">".$val."&nbsp;".$break_by;
  5211. }
  5212. }
  5213. }
  5214. if($on_js_event !="") $text .= "</span>";
  5215. }else{
  5216. if(is_object($select_array)){
  5217. $found = 0;
  5218. while(($row = $select_array->fetchRow()) && (!$found)){
  5219. if(strtolower($row[$this->foreign_keys_array[$field_name][$sub_field_value]]) == strtolower($compare)){
  5220. $text .= "<span ".$on_js_event.">".$row[$this->foreign_keys_array[$field_name][$sub_field_name]]."</span>";
  5221. $found = 1;
  5222. }
  5223. }
  5224. if($found == 0) $text .= "<span ".$on_js_event.">none</span>";
  5225. }else{
  5226. $text = $compare;
  5227. }
  5228. }
  5229. return $text;
  5230. }
  5231. //--------------------------------------------------------------------------
  5232. // draw drop-down list
  5233. //--------------------------------------------------------------------------
  5234. protected function DrawDropDownList($tag_name, $foo_name, &$select_array, $compare = "", $field_name="", $sub_field_value="", $sub_field_name="", $disabled="", $on_js_event="", $multiple=false, $multiple_size="4"){
  5235. $req_print = $this->GetVariable('print');
  5236. $text = "";
  5237. $multiple_parameters = ($multiple) ? $multiple_parameters = "multiple size='".$multiple_size."'" : "";
  5238. $tag_id = $tag_name;
  5239. $tag_name = ($multiple) ? $tag_name = $tag_name."[]" : $tag_name;
  5240. if($req_print != true){
  5241. if(is_object($select_array)){
  5242. $text = "<select class='".$this->css_class."_class_select' name='".$tag_name."' id='".$tag_id."' title='".$this->GetFieldTitle($field_name)."' ".(($foo_name != "") ? "onChange='".$this->uniquePrefix.$foo_name."'" : "")." ".$disabled." ".$on_js_event." ".$multiple_parameters.">";
  5243. $text .= "<option value=''>-- ".$this->lang['select']." --</option>";
  5244. if($this->db_handler->isError($select_array) != 1){
  5245. while($row = $select_array->fetchRow()){
  5246. $ff_name = $this->foreign_keys_array[$field_name][$sub_field_name];
  5247. if(eregi(" as ", strtolower($ff_name))) $ff_name = substr($ff_name, strpos(strtolower($ff_name), " as ")+4);
  5248. if(strtolower($row[$this->foreign_keys_array[$field_name][$sub_field_value]]) == strtolower($compare))
  5249. $text .= "<option selected value='".$row[$this->foreign_keys_array[$field_name][$sub_field_value]]."'>".$row[$ff_name]."</option>";
  5250. else
  5251. $text .= "<option value='".$row[$this->foreign_keys_array[$field_name][$sub_field_value]]."'>".$row[$ff_name]."</option>";
  5252. }
  5253. }
  5254. }else{
  5255. if(!is_array($compare)){ $splitted_compare = split(",",$compare); }else{ $splitted_compare = $compare; }
  5256. $text = "<select class='".$this->css_class."_class_select' name='".$tag_name."' id='".$tag_id."' ".(($foo_name != "") ? "onChange='".$this->uniquePrefix.$foo_name."'" : "")." ".$disabled." ".$on_js_event." ".$multiple_parameters.">";
  5257. foreach($select_array as $key => $val){
  5258. $selected = "";
  5259. if(count($splitted_compare) > 1){
  5260. foreach($splitted_compare as $spl_val){
  5261. if($spl_val == $key) {$selected = "selected"; break; }
  5262. }
  5263. }else{
  5264. $selected = ((strtolower($compare) == strtolower($key)) ? "selected" : "");
  5265. }
  5266. $text .= "<option ".$selected." value='".$key."'>".$val."</option>";
  5267. }
  5268. }
  5269. $text .= "</select>";
  5270. }else{
  5271. if(is_object($select_array)){
  5272. $found = 0;
  5273. while(($row = $select_array->fetchRow()) && (!$found)){
  5274. if(strtolower($row[$this->foreign_keys_array[$field_name][$sub_field_value]]) == strtolower($compare)){
  5275. $text .= "<span>".$row[$this->foreign_keys_array[$field_name][$sub_field_name]]."</span>";
  5276. $found = 1;
  5277. }
  5278. }
  5279. if($found == 0) $text .= "<span>none</span>";
  5280. }else{
  5281. $text = $compare;
  5282. }
  5283. }
  5284. return $text;
  5285. }
  5286. //--------------------------------------------------------------------------
  5287. // draw Mode Button
  5288. //--------------------------------------------------------------------------
  5289. protected function DrawModeButton($mode, $mode_url, $botton_name, $alt_name, $image_file, $onClick, $div_align=false, $nbsp="", $type=""){
  5290. $req_print = $this->GetVariable('print');
  5291. if($type == ""){
  5292. $mode_type = (isset($this->modes[$mode]['type'])) ? $this->modes[$mode]['type'] : "";
  5293. }else{
  5294. $mode_type = $type;
  5295. }
  5296. if(!$this->is_error){
  5297. if($req_print != true){
  5298. switch($mode_type){
  5299. case "button":
  5300. echo $nbsp."<input class='".$this->css_class."_class_button' type='button' ";
  5301. if($div_align){ echo "style='float: "; echo ($this->direction == "rtl")?"right":"left"; echo "' "; }
  5302. echo "onClick=$onClick value='".$botton_name."'>".$nbsp;
  5303. break;
  5304. case "image":
  5305. if($div_align){ echo "<div style='float:"; echo ($this->direction == "rtl")?"right":"left"; echo ";'>"; }
  5306. echo $nbsp."<img style='cursor:pointer; vertical-align: middle;' onClick=".$onClick." src='".$this->directory."images/".$this->css_class."/".$image_file."' alt='$alt_name' title='$alt_name'>".$nbsp;
  5307. if($div_align) echo "</div>";
  5308. break;
  5309. default:
  5310. if($div_align){ echo "<div style='float:"; echo ($this->direction == "rtl")?"right":"left"; echo ";'>"; }
  5311. echo $nbsp."<a class='".$this->css_class."_class_a".(($mode == "add") ? "_header" : "")."' href='$mode_url' onClick=".$onClick." title='$alt_name'>".$botton_name."</a>".$nbsp;
  5312. if($div_align) echo "</div>";
  5313. break;
  5314. }
  5315. }else{
  5316. switch($mode_type){
  5317. case "button":
  5318. echo "<span ";
  5319. if($div_align){ echo "style='float: "; echo ($this->direction == "rtl")?"right":"left"; echo "' "; }
  5320. echo ">".$botton_name."</span>";
  5321. break;
  5322. case "image":
  5323. if($div_align){ echo "<div style='float:"; echo ($this->direction == "rtl")?"right":"left"; echo ";'>"; }
  5324. echo "<img style='vertical-align: middle;' src='".$this->directory."images/".$this->css_class."/".$image_file."' readonly>";
  5325. if($div_align) echo "</div>";
  5326. break;
  5327. default:
  5328. if($div_align){ echo "<div style='float:"; echo ($this->direction == "rtl")?"right":"left"; echo ";'>"; }
  5329. echo $nbsp."<span class='".$this->css_class."_class_a' >".$botton_name."</span>".$nbsp;
  5330. if($div_align) echo "</div>";
  5331. break;
  5332. }
  5333. }
  5334. }
  5335. }
  5336. //--------------------------------------------------------------------------
  5337. // set Common JavaScript
  5338. //--------------------------------------------------------------------------
  5339. protected function SetCommonJavaScript(){
  5340. $req_mode = $this->GetVariable('mode');
  5341. $req_new = $this->GetVariable('new');
  5342. // change mode after update
  5343. if(($req_mode == "update") && ($req_new != 1) && ($this->mode_after_update == "edit")){
  5344. $req_mode = $this->mode_after_update;
  5345. }
  5346. echo "\n<!-- This script was generated by datagrid.class.php v.4.2.8 (http://phpbuilder.blogspot.com) -->";
  5347. // set common JavaScript
  5348. if (!file_exists($this->directory.'scripts/dg.js')) {
  5349. echo "<label class='".$this->css_class."_class_error_message no_print'>Cannot find file: <b>".$this->directory."scripts/dg.js</b>. Check if this file exists and you use a correct path!</label><br><b>";
  5350. }else{
  5351. echo "\n<script type='text/javascript' src='".$this->directory."scripts/dg.js'></script>";
  5352. }
  5353. // include magnify.js file for magnifying images
  5354. if ($this->MagnifyingFieldExists($req_mode)) {
  5355. if (!file_exists($this->directory.'scripts/magnify.js')) {
  5356. echo "<label class='".$this->css_class."_class_error_message no_print'>Cannot find file: <b>".$this->directory."scripts/magnify.js</b>. Check if this file exists and you use a correct path!</label><br><br>";
  5357. }else{
  5358. echo "\n<script type='text/javascript' src='".$this->directory."scripts/magnify.js'></script>";
  5359. echo "\n<STYLE>#trailimageid { DISPLAY: none; FONT-SIZE: 0.75em; Z-INDEX: 200; LEFT: 0px; POSITION: absolute; TOP: 0px; HEIGHT: 0px }</STYLE>";
  5360. }
  5361. }
  5362. if(($req_mode == "add") || ($req_mode == "edit")){
  5363. // include calendar script (floating), if needed
  5364. if ($this->DatetimeFieldExists("floating")) {
  5365. // set calendar JS
  5366. echo "<style type='text/css'>@import url(".$this->directory."modules/jscalendar/skins/aqua/theme.css);</style>\n";
  5367. //<!-- import the calendar script -->
  5368. echo "<script type='text/javascript' src='".$this->directory."modules/jscalendar/calendar.js'></script>"."\n";
  5369. //<!-- import the language module -->
  5370. echo "<script type='text/javascript' src='".$this->directory."modules/jscalendar/lang/calendar-".$this->GetLangAbbrForCalendar().".js'></script>"."\n";
  5371. //<!-- the following script defines the Calendar.setup helper function, which makes
  5372. //adding a calendar a matter of 1 or 2 lines of code. -->
  5373. echo "<script type='text/javascript' src='".$this->directory."modules/jscalendar/calendar-setup.js'></script>\n";
  5374. }
  5375. // include form checking script, if needed
  5376. if (!file_exists($this->directory.'modules/jsafv/form.scripts.js')) {
  5377. echo "<label class='".$this->css_class."_class_error_message no_print'>Cannot find file: <b>".$this->directory."modules/jsafv/form.scripts.js</b>. Check if this file exists and you use a correct path!</label><br><br>";
  5378. }else{
  5379. echo "\n<script type='text/javascript' src='".$this->directory."modules/jsafv/lang/jsafv-".$this->GetLangAbbrForJSAFV().".js'></script>";
  5380. if($this->encoding == "utf8"){
  5381. echo "\n<script type='text/javascript' src='".$this->directory."modules/jsafv/chars/diactric_chars_utf8.js'></script>";
  5382. }else{
  5383. echo "\n<script type='text/javascript' src='".$this->directory."modules/jsafv/chars/diactric_chars.js'></script>";
  5384. }
  5385. echo "\n<script type='text/javascript' src='".$this->directory."modules/jsafv/form.scripts.js'></script>";
  5386. }
  5387. // include resizable textarea script, if needed
  5388. if ($this->ResizableFieldExists()) {
  5389. if (!file_exists($this->directory.'scripts/resize.js')) {
  5390. echo "<label class='".$this->css_class."_class_error_message no_print'>Cannot find file: <b>".$this->directory."scripts/resize.js</b>. Check if this file exists and you use a correct path!</label><br><br>";
  5391. }else{
  5392. echo "\n<script type='text/javascript' src='".$this->directory."scripts/resize.js'></script>";
  5393. }
  5394. }
  5395. // include WYSIWYG script, if needed
  5396. if ($this->WysiwygFieldExists()) {
  5397. // set WYSIWYG
  5398. echo "\n<script type='text/javascript'>\n";
  5399. echo "<!--\n";
  5400. echo "imagesDir = '".$this->directory."modules/wysiwyg/icons/';\n"; // Images Directory
  5401. echo "cssDir = '".$this->directory."modules/wysiwyg/styles/';\n"; // CSS Directory
  5402. echo "popupsDir = '".$this->directory."modules/wysiwyg/popups/';\n"; // Popups Directory
  5403. echo "//-->\n";
  5404. echo "</script>";
  5405. echo "\n<script type='text/javascript' src='".$this->directory."modules/wysiwyg/wysiwyg.js'></script>";
  5406. }
  5407. // set verify JS functions
  5408. if(isset($this->modes['cancel'][$this->mode]) && $this->modes['cancel'][$this->mode]){
  5409. echo "\n<script type='text/javascript'>\n<!--";
  5410. echo "\n function ".$this->uniquePrefix."verifyCancel(param){if(confirm(\"".$this->lang['cancel_creating_new_record']."\")){document.location.href=param;} else { return false;}};";
  5411. echo "//-->\n</script>\n";
  5412. }
  5413. }else{ // view mode
  5414. // include autosuggest.js file and other for AutoSuggestion
  5415. if ($this->AutosuggestFieldExists()){
  5416. echo "\n<script type='text/javascript' src='".$this->directory."modules/autosuggest/js/bsn.AutoSuggest_2.1.3.js'></script>";
  5417. echo "\n<link rel='stylesheet' href='".$this->directory."modules/autosuggest/css/autosuggest_inquisitor.css' type='text/css' media='screen' charset='utf-8'>";
  5418. }
  5419. // include overlib.js file for floating tooltips
  5420. if ($this->FloatingToolTipsFieldExists()) {
  5421. if (!file_exists($this->directory.'modules/overlib/overlib.js')) {
  5422. echo "<label class='".$this->css_class."_class_error_message no_print'>Cannot find file: <b>".$this->directory."modules/overlib/overlib.js</b>. Check if this file exists and you use a correct path!</label><br><br>";
  5423. }else{
  5424. echo "\n<script type='text/javascript' src='".$this->directory."modules/overlib/overlib.js'></script>";
  5425. }
  5426. }
  5427. // include highlight.js file for rows highlighting
  5428. if($this->row_highlighting_allowed){
  5429. if (!file_exists($this->directory.'scripts/highlight.js')) {
  5430. echo "<label class='".$this->css_class."_class_error_message no_print'>Cannot find file: <b>".$this->directory."scripts/highlight.js</b>. Check if this file exists and you use a correct path!</label><br><br>";
  5431. }else{
  5432. echo "\n<script type='text/javascript' src='".$this->directory."scripts/highlight.js'></script>";
  5433. }
  5434. }
  5435. }
  5436. }
  5437. protected function SetCommonJavaScriptEnd(){
  5438. echo "<script type='text/javascript'>\n<!--\n";
  5439. // set verify JS functions
  5440. if(isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode]){
  5441. echo "\nfunction ".$this->uniquePrefix."verifyDelete(param){if(confirm(\"".$this->lang['delete_this_record']."\")){document.location.href=param;} else { window.event.cancelBubble = true; return false;}};";
  5442. }
  5443. echo "\n//-->\n";
  5444. echo "</script>";
  5445. }
  5446. protected function SetMediaPrint(){
  5447. echo "\n<style type='text/css'> @media print { .no_print {DISPLAY: none! important}; }</style>";
  5448. }
  5449. //--------------------------------------------------------------------------
  5450. // set Edit Fields Form Script
  5451. //--------------------------------------------------------------------------
  5452. protected function SetEditFieldsFormScript($url=""){
  5453. echo "<script type='text/javascript'>\n";
  5454. echo "<!--\n";
  5455. //echo $url;
  5456. //document.".$this->uniquePrefix."frmEditRow.action ='".str_replace($this->amp,'&',$url)."';
  5457. echo "function ".$this->uniquePrefix."sendEditFields(){
  5458. if(window.".$this->uniquePrefix."onSubmitMyCheck){ if(!".$this->uniquePrefix."onSubmitMyCheck()){ return false; } }
  5459. ";
  5460. // two different parts of code to find & save wysiwyg editor data
  5461. if($this->browser_name == "Firefox"){
  5462. echo "
  5463. elements = document.getElementsByTagName('*');
  5464. for (var idx = 0; idx < elements.length; idx++) {
  5465. node = elements.item(idx);
  5466. field_name = node.getAttribute('name');
  5467. field_type = node.getAttribute('type');
  5468. // check file or image fields
  5469. if(field_type == 'file'){
  5470. if(document.getElementById(field_name).value != ''){
  5471. alert('You need to upload file or image before update! Click on Upload link.');
  5472. return false;
  5473. }
  5474. }
  5475. field_full_name = 'wysiwyg' + field_name;
  5476. if(document.getElementById(field_full_name)){
  5477. document.getElementById(field_name).value = document.getElementById(field_full_name).contentWindow.document.body.innerHTML;
  5478. if((document.getElementById(field_name).value == '<p>&nbsp;</p>') || (document.getElementById(field_name).value == '<p> </p>') || (document.getElementById(field_name).value == '&lt;p&gt;&nbsp;&lt;/p&gt;')){
  5479. document.getElementById(field_name).value = '';
  5480. }
  5481. }
  5482. }
  5483. ";
  5484. }else{ // "MSIE" or other
  5485. echo "
  5486. for (var idx=0; idx < document.".$this->uniquePrefix."frmEditRow.length; idx++) {
  5487. field_name = ".$this->uniquePrefix."frmEditRow.elements.item(idx).name;
  5488. field_type = ".$this->uniquePrefix."frmEditRow.elements.item(idx).type;
  5489. // check file or image fields
  5490. if(field_type == 'file'){
  5491. if(document.getElementById(field_name).value != ''){
  5492. alert('You need to upload file or image before update! Click on Upload link.');
  5493. return false;
  5494. }
  5495. }
  5496. field_full_name = 'wysiwyg' + field_name;
  5497. if(document.getElementById(field_full_name)){
  5498. document.getElementById(field_name).value = document.getElementById(field_full_name).contentWindow.document.body.innerHTML;
  5499. if((document.getElementById(field_name).value == '<P>&nbsp;</P>') || (document.getElementById(field_name).value == '&lt;P&gt;&nbsp;&lt;/P&gt;')){
  5500. document.getElementById(field_name).value = '';
  5501. }
  5502. }
  5503. };
  5504. ";
  5505. };
  5506. echo "
  5507. if(onSubmitCheck(document.".$this->uniquePrefix."frmEditRow, ".$this->js_validation_errors.")){
  5508. document.".$this->uniquePrefix."frmEditRow.submit();
  5509. }else{
  5510. return false;
  5511. }
  5512. }";
  5513. echo "\n//-->\n";
  5514. echo "</script>\n";
  5515. }
  5516. //--------------------------------------------------------------------------
  5517. // return date format
  5518. //--------------------------------------------------------------------------
  5519. protected function MyDate($field_value, $type="datedmy"){
  5520. $ret_date = "";
  5521. if($type == "datedmy"){
  5522. if (substr(trim($field_value), 4, 1) == "-"){
  5523. $year1 = substr(trim($field_value), 0, 4);
  5524. $month1 = substr(trim($field_value), 5, 2);
  5525. $day1 = substr(trim($field_value), 8, 2);
  5526. if($day1 != ""){ $ret_date = $day1."-".$month1."-".$year1; }
  5527. }else{
  5528. $year1 = substr(trim($field_value), 6, 4);
  5529. $month1 = substr(trim($field_value), 3, 2);
  5530. $day1 = substr(trim($field_value), 0, 2);
  5531. if($day1 != ""){ $ret_date = $day1."-".$month1."-".$year1; }
  5532. }
  5533. }else if($type == "datetimedmy"){
  5534. if (substr(trim($field_value), 4, 1) == "-"){
  5535. $year1 = substr(trim($field_value), 0, 4);
  5536. $month1 = substr(trim($field_value), 5, 2);
  5537. $day1 = substr(trim($field_value), 8, 2);
  5538. $time1 = substr(trim($field_value), 11, 2);
  5539. $time2 = substr(trim($field_value), 14, 2);
  5540. $time3 = substr(trim($field_value), 17, 2);
  5541. if($day1 != ""){ $ret_date = $day1."-".$month1."-".$year1." ".$time1.":".$time2.":".$time3; }
  5542. }else{
  5543. $year1 = substr(trim($field_value), 6, 4);
  5544. $month1 = substr(trim($field_value), 3, 2);
  5545. $day1 = substr(trim($field_value), 0, 2);
  5546. $time1 = substr(trim($field_value), 11, 2);
  5547. $time2 = substr(trim($field_value), 14, 2);
  5548. $time3 = substr(trim($field_value), 17, 2);
  5549. if($day1 != ""){ $ret_date = $day1."-".$month1."-".$year1." ".$time1.":".$time2.":".$time3; }
  5550. }
  5551. }else{
  5552. $ret_date = $field_value;
  5553. }
  5554. return $ret_date;
  5555. }
  5556. ////////////////////////////////////////////////////////////////////////////
  5557. //
  5558. // Auxiliary methods
  5559. // -------------------------------------------------------------------------
  5560. ////////////////////////////////////////////////////////////////////////////
  5561. protected function PrepareFileOperations($key){
  5562. $files = array();
  5563. if(is_array($this->columns_edit_mode)){
  5564. foreach($this->columns_edit_mode as $fldName => $fldParam){
  5565. foreach($fldParam as $key => $val){
  5566. if(($val === "image") || ($val === "file")){
  5567. $file = array();
  5568. $file['file_name'] = $fldParam['file_name'];
  5569. $file['target_path'] = $fldParam['target_path'];
  5570. $files[] = $file;
  5571. break;
  5572. }
  5573. }
  5574. }
  5575. }
  5576. print_r($files);
  5577. }
  5578. protected function DrawCalendarButton($field_name, $field_type, $datetime_format="Y-m-d", $field_value="", $field_property_pre_addition="", $field_property_post_addition="", $field_width="", $field_maxlength="", $on_js_event="", $readonly=false, $field_property_calendar_type = "popup"){
  5579. if($datetime_format == "Y-m-d"){
  5580. $if_format = "%Y-%m-%d"; $show_time = false;
  5581. }else if($datetime_format == "d-m-Y"){
  5582. $if_format = "%d-%m-%Y"; $show_time = false;
  5583. }else if($datetime_format == "Y-m-d H:i:s"){
  5584. $if_format = "%Y-%m-%d %H:%M:%S"; $show_time = true;
  5585. }else if($datetime_format == "d-m-Y H:i:s"){
  5586. $if_format = "%d-%m-%Y %H:%M:%S"; $show_time = true;
  5587. }else{
  5588. $if_format = "%Y-%m-%d"; $show_time = false;
  5589. }
  5590. $ret_date = $this->nbsp."<input class='".$this->css_class."_class_textbox' ".$field_width." readonly type='text' title='".$this->GetFieldTitle($field_name)."' name='".$this->GetFieldRequiredType($field_name).$field_name."' id='".$this->GetFieldRequiredType($field_name).$field_name."' value='".trim($field_value)."' $field_maxlength ".$on_js_event.">";
  5591. if($field_property_calendar_type == "floating"){
  5592. if(!$readonly) $ret_date .= "<img id='img".$this->GetFieldRequiredType($field_name).$field_name."' src='".$this->directory."images/".$this->css_class."/cal.gif' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='cursor:pointer;margin:3px;margin-left:6px;margin-right:6px;border:0px;'></a>".$this->nbsp."<script type='text/javascript'>Calendar.setup({inputField : '".$this->GetFieldRequiredType($field_name).$field_name."', ifFormat : '".$if_format."', showsTime : ".$show_time.", button : 'img".$this->GetFieldRequiredType($field_name).$field_name."'});</script>";
  5593. }else{
  5594. if(!$readonly) $ret_date .= "<a class='".$this->css_class."_class_a2' title='".$this->GetFieldTitle($field_name)."' href=\"javascript: openCalendar('".$this->directory."','', '".$this->uniquePrefix."frmEditRow', '".$this->GetFieldRequiredType($field_name)."', '".$field_name."', '$field_type')\"><img src='".$this->directory."images/".$this->css_class."/cal.gif' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='MARGIN:3px;margin-left:6px;margin-right:6px;border:0px;'></a>".$this->nbsp;
  5595. }
  5596. if(!$readonly) $ret_date .= "<a class='".$this->css_class."_class_a2' style='cursor: pointer;' onClick='document.getElementById(\"".$this->GetFieldRequiredType($field_name).$field_name."\").value=\"".date($datetime_format)."\"'>[".date($datetime_format)."]</a>";
  5597. if((!$readonly) && (substr($this->GetFieldRequiredType($field_name), 0, 1) == "s")) $ret_date .= "&nbsp;<a class='".$this->css_class."_class_a2' style='cursor: pointer;' onClick='document.getElementById(\"".$this->GetFieldRequiredType($field_name).$field_name."\").value=\"\"' title='".$this->lang['clear']."'>[".$this->lang['clear']."]</a>";
  5598. return $field_property_pre_addition.$ret_date.$field_property_post_addition;
  5599. }
  5600. //--------------------------------------------------------------------------
  5601. // get Formatted Microtime
  5602. //--------------------------------------------------------------------------
  5603. protected function GetFormattedMicrotime(){
  5604. list($usec, $sec) = explode(' ', microtime());
  5605. return ((float)$usec + (float)$sec);
  5606. }
  5607. //--------------------------------------------------------------------------
  5608. // download export file
  5609. //--------------------------------------------------------------------------
  5610. protected function ExportDownloadFile($file_name){
  5611. $_SESSION['datagrid_export_dir']= $this->exporting_directory;
  5612. $_SESSION['datagrid_export_file']= $file_name;
  5613. $_SESSION['datagrid_debug']= $this->debug;
  5614. return "<script type='text/javascript'>\n<!--\n ".
  5615. "if(confirm('Do you want to export datagrid content into [".$file_name."] file?')){ ".
  5616. " document.write('".str_replace("_FILE_", $file_name, $this->lang['export_message'])."'); ".
  5617. " document.location.href = '".$this->directory."scripts/download.php'; ".
  5618. "} else {".
  5619. " window.close();".
  5620. "}".
  5621. "\n//-->\n</script>";
  5622. }
  5623. //--------------------------------------------------------------------------
  5624. // overloaded php function strtolower
  5625. //--------------------------------------------------------------------------
  5626. protected function StrToLower($str){
  5627. if($this->lang_name == "en"){
  5628. return strtolower($str);
  5629. }else{
  5630. return mb_StrToLower($str, mb_detect_encoding($str));
  5631. }
  5632. }
  5633. //--------------------------------------------------------------------------
  5634. // check if there is any resizable field
  5635. //--------------------------------------------------------------------------
  5636. protected function ResizableFieldExists(){
  5637. if(is_array($this->columns_edit_mode)){
  5638. foreach($this->columns_edit_mode as $fldName => $fldValue){
  5639. foreach($fldValue as $key => $val){
  5640. if(($key == "resizable") && (($val == true) || ($val == "true"))) return true;
  5641. }
  5642. }
  5643. }
  5644. return false;
  5645. }
  5646. //--------------------------------------------------------------------------
  5647. // check if there is any autosuggest (autocomplete) field exists (in filter)
  5648. //--------------------------------------------------------------------------
  5649. protected function AutosuggestFieldExists(){
  5650. if(is_array($this->filter_fields)){
  5651. foreach($this->filter_fields as $fldName => $fldValue){
  5652. foreach($fldValue as $key => $val){
  5653. if(($key == "autocomplete") && (($val == true) || ($val == "true"))) return true;
  5654. }
  5655. }
  5656. }
  5657. return false;
  5658. }
  5659. //--------------------------------------------------------------------------
  5660. // check if there is any datetime field
  5661. //--------------------------------------------------------------------------
  5662. protected function DatetimeFieldExists($cal_type = ""){
  5663. $found_field_type = false;
  5664. $found_calendar_type = false;
  5665. if(is_array($this->columns_edit_mode)){
  5666. foreach($this->columns_edit_mode as $fldName => $fldValue){
  5667. foreach($fldValue as $key => $val){
  5668. if($key == "type"){
  5669. if(($val == "date") || ($val == "datedmy") || ($val == "datetime") || ($val == "datetimedmy") || ($val == "time")){
  5670. $found_field_type = true;
  5671. }
  5672. }
  5673. if($key == "calendar_type"){
  5674. if(strtolower($val) == $cal_type){
  5675. $found_calendar_type = true;
  5676. }
  5677. }
  5678. if($found_field_type && $found_calendar_type) return true;
  5679. }
  5680. }
  5681. }
  5682. return false;
  5683. }
  5684. //--------------------------------------------------------------------------
  5685. // check if there is any field with magnifying attribute
  5686. //--------------------------------------------------------------------------
  5687. protected function MagnifyingFieldExists($req_mode = ""){
  5688. if(($req_mode == "add") || ($req_mode == "edit")){
  5689. if(isset($this->columns_edit_mode)){
  5690. foreach($this->columns_edit_mode as $fldName => $fldValue){
  5691. foreach($fldValue as $key => $val){
  5692. if(($key == "magnify") && (($val == true) || ($val == "true"))){ return true; }
  5693. }
  5694. }
  5695. }
  5696. }else{
  5697. if(isset($this->columns_view_mode)){
  5698. foreach($this->columns_view_mode as $fldName => $fldValue){
  5699. foreach($fldValue as $key => $val){
  5700. if(($key == "magnify") && (($val == true) || ($val == "true"))){ return true; }
  5701. }
  5702. }
  5703. }
  5704. }
  5705. return false;
  5706. }
  5707. //--------------------------------------------------------------------------
  5708. // check if there is any field with floating tool tips
  5709. //--------------------------------------------------------------------------
  5710. protected function FloatingToolTipsFieldExists(){
  5711. $tooltip_allowed = false;
  5712. if(isset($this->columns_view_mode)){
  5713. foreach($this->columns_view_mode as $fldName => $fldValue){
  5714. foreach($fldValue as $key => $val){
  5715. if(($key == "tooltip") && (($val == true) || ($val == "true"))){ $tooltip_allowed = true; }
  5716. if($tooltip_allowed && ($key == "tooltip_type") && (strtolower($val) == "floating")) { return true; }
  5717. }
  5718. }
  5719. }
  5720. return false;
  5721. }
  5722. //--------------------------------------------------------------------------
  5723. // check if there is any wysiwyg field
  5724. //--------------------------------------------------------------------------
  5725. protected function WysiwygFieldExists(){
  5726. if(is_array($this->columns_edit_mode)){
  5727. foreach($this->columns_edit_mode as $fldName => $fldValue){
  5728. foreach($fldValue as $key => $val){
  5729. if(($key == "edit_type") && (strtolower($val) == "wysiwyg")) return true;
  5730. }
  5731. }
  5732. }
  5733. return false;
  5734. }
  5735. //--------------------------------------------------------------------------
  5736. // get remote file content
  5737. //--------------------------------------------------------------------------
  5738. protected function HttpGetFile($url) {
  5739. $url_stuff = parse_url($url);
  5740. $port = isset($url_stuff['port']) ? $url_stuff['port']:80;
  5741. $fp = fsockopen($url_stuff['host'], $port);
  5742. $query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n";
  5743. $query .= 'Host: ' . $url_stuff['host'];
  5744. $query .= "\n\n";
  5745. fwrite($fp, $query);
  5746. while ($line = fread($fp, 1024)) {
  5747. $buffer .= $line;
  5748. }
  5749. preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts);
  5750. return substr($buffer, - $parts[1]);
  5751. }
  5752. //--------------------------------------------------------------------------
  5753. // get http port
  5754. //--------------------------------------------------------------------------
  5755. protected function GetPort(){
  5756. $port = "";
  5757. if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != "80"){
  5758. $port = ":".$_SERVER['SERVER_PORT'];
  5759. }
  5760. return $port;
  5761. }
  5762. //--------------------------------------------------------------------------
  5763. // get Protocol (http/s)
  5764. //--------------------------------------------------------------------------
  5765. protected function GetProtocol(){
  5766. $protocol = "http://";
  5767. if((isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != "off")) ||
  5768. strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, 5)) == "https"){
  5769. $protocol = "https://";
  5770. }
  5771. return $protocol;
  5772. }
  5773. //--------------------------------------------------------------------------
  5774. // get Server Name
  5775. //--------------------------------------------------------------------------
  5776. protected function GetServerName(){
  5777. $server = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : "";
  5778. $colon = strpos($server,':');
  5779. if ($colon > 0 && $colon < strlen($server)){
  5780. $server = substr($server, 0, $colon);
  5781. }
  5782. return $server;
  5783. }
  5784. //--------------------------------------------------------------------------
  5785. // return last substring occurence
  5786. //--------------------------------------------------------------------------
  5787. protected function LastSubStrOccurence($string, $substring){
  5788. $string = str_replace("\t", " ", $string);
  5789. $string = str_replace("\n", " ", $string);
  5790. $string = strrev(strtolower($string));
  5791. $substring = strrev(strtolower($substring));
  5792. return strpos($string, $substring);
  5793. }
  5794. //--------------------------------------------------------------------------
  5795. // gets random string
  5796. //--------------------------------------------------------------------------
  5797. protected function GetRandomString($length = 20) {
  5798. $template_alpha = "abcdefghijklmnopqrstuvwxyz";
  5799. $template_alphanumeric = "1234567890abcdefghijklmnopqrstuvwxyz";
  5800. settype($template, "string");
  5801. settype($length, "integer");
  5802. settype($rndstring, "string");
  5803. settype($a, "integer");
  5804. settype($b, "integer");
  5805. $b = rand(0, strlen($template_alpha) - 1);
  5806. $rndstring .= $template_alpha[$b];
  5807. for ($a = 0; $a < $length-1; $a++) {
  5808. $b = rand(0, strlen($template_alphanumeric) - 1);
  5809. $rndstring .= $template_alphanumeric[$b];
  5810. }
  5811. return $rndstring;
  5812. }
  5813. //--------------------------------------------------------------------------
  5814. // set browser definitions
  5815. //--------------------------------------------------------------------------
  5816. protected function SetBrowserDefinitions(){
  5817. $bd = array();
  5818. $agent = $_SERVER['HTTP_USER_AGENT'];
  5819. // initialize properties
  5820. $bd['platform'] = "Windows";
  5821. $bd['browser'] = "MSIE";
  5822. $bd['version'] = "6.0";
  5823. // find operating system
  5824. if (eregi("win", $agent)) $bd['platform'] = "Windows";
  5825. elseif (eregi("mac", $agent)) $bd['platform'] = "MacIntosh";
  5826. elseif (eregi("linux", $agent)) $bd['platform'] = "Linux";
  5827. elseif (eregi("OS/2", $agent)) $bd['platform'] = "OS/2";
  5828. elseif (eregi("BeOS", $agent)) $bd['platform'] = "BeOS";
  5829. // test for Opera
  5830. if (eregi("opera",$agent)){
  5831. $val = stristr($agent, "opera");
  5832. if (eregi("/", $val)){
  5833. $val = explode("/",$val); $bd['browser'] = $val[0]; $val = explode(" ",$val[1]); $bd['version'] = $val[0];
  5834. }else{
  5835. $val = explode(" ",stristr($val,"opera")); $bd['browser'] = $val[0]; $bd['version'] = $val[1];
  5836. }
  5837. // test for MS Internet Explorer version 1
  5838. }elseif(eregi("microsoft internet explorer", $agent)){
  5839. $bd['browser'] = "MSIE"; $bd['version'] = "1.0"; $var = stristr($agent, "/");
  5840. if (ereg("308|425|426|474|0b1", $var)) $bd['version'] = "1.5";
  5841. // test for MS Internet Explorer
  5842. }elseif(eregi("msie",$agent) && !eregi("opera",$agent)){
  5843. $val = explode(" ",stristr($agent,"msie")); $bd['browser'] = $val[0]; $bd['version'] = $val[1];
  5844. // test for MS Pocket Internet Explorer
  5845. }elseif(eregi("mspie",$agent) || eregi('pocket', $agent)){
  5846. $val = explode(" ",stristr($agent,"mspie")); $bd['browser'] = "MSPIE"; $bd['platform'] = "WindowsCE";
  5847. if (eregi("mspie", $agent)){
  5848. $bd['version'] = $val[1];
  5849. }else{
  5850. $val = explode("/",$agent); $bd['version'] = $val[1];
  5851. }
  5852. // test for Firebird
  5853. }elseif(eregi("firebird", $agent)){
  5854. $bd['browser']="Firebird"; $val = stristr($agent, "Firebird"); $val = explode("/",$val); $bd['version'] = $val[1];
  5855. // test for Firefox
  5856. }elseif(eregi("Firefox", $agent)){
  5857. $bd['browser']="Firefox"; $val = stristr($agent, "Firefox"); $val = explode("/",$val); $bd['version'] = $val[1];
  5858. // test for Mozilla Alpha/Beta Versions
  5859. }elseif(eregi("mozilla",$agent) && eregi("rv:[0-9].[0-9][a-b]",$agent) && !eregi("netscape",$agent)){
  5860. $bd['browser'] = "Mozilla"; $val = explode(" ",stristr($agent,"rv:")); eregi("rv:[0-9].[0-9][a-b]",$agent,$val); $bd['version'] = str_replace("rv:","",$val[0]);
  5861. // test for Mozilla Stable Versions
  5862. }elseif(eregi("mozilla",$agent) && eregi("rv:[0-9]\.[0-9]",$agent) && !eregi("netscape",$agent)){
  5863. $bd['browser'] = "Mozilla"; $val = explode(" ",stristr($agent,"rv:")); eregi("rv:[0-9]\.[0-9]\.[0-9]",$agent,$val); $bd['version'] = str_replace("rv:","",$val[0]);
  5864. // remaining two tests are for Netscape
  5865. }elseif(eregi("netscape",$agent)){
  5866. $val = explode(" ",stristr($agent,"netscape")); $val = explode("/",$val[0]); $bd['browser'] = $val[0]; $bd['version'] = $val[1];
  5867. }elseif(eregi("mozilla",$agent) && !eregi("rv:[0-9]\.[0-9]\.[0-9]",$agent)){
  5868. $val = explode(" ",stristr($agent,"mozilla")); $val = explode("/",$val[0]); $bd['browser'] = "Netscape"; $bd['version'] = $val[1];
  5869. }
  5870. // clean up extraneous garbage that may be in the name
  5871. $bd['browser'] = ereg_replace("[^a-z,A-Z]", "", $bd['browser']);
  5872. $bd['version'] = ereg_replace("[^0-9,.,a-z,A-Z]", "", $bd['version']);
  5873. $this->browser_name = $bd['browser'];
  5874. $this->browser_version = $bd['version'];
  5875. $this->platform = $bd['platform'];
  5876. }
  5877. //--------------------------------------------------------------------------
  5878. // get Language Abbreviation for JS AFV
  5879. //--------------------------------------------------------------------------
  5880. protected function GetLangAbbrForJSAFV(){
  5881. $return_abbrv = "en";
  5882. switch($this->lang_name){
  5883. case "fr":
  5884. $return_abbrv = "fr"; break;
  5885. case "en":
  5886. default:
  5887. $return_abbrv = "en"; break;
  5888. }
  5889. return $return_abbrv;
  5890. }
  5891. //--------------------------------------------------------------------------
  5892. // get Language Abbreviation for Calendar
  5893. //--------------------------------------------------------------------------
  5894. protected function GetLangAbbrForCalendar(){
  5895. $return_abbrv = "en";
  5896. switch($this->lang_name){
  5897. case "ar": $return_abbrv = "en"; break; // Arabic
  5898. case "hr": $return_abbrv = "hr"; break; // Bosnian/Croatian
  5899. case "bg": $return_abbrv = "bg"; break; // Bulgarian
  5900. case "pb": $return_abbrv = "pt"; break; // Brazilian Portuguese
  5901. case "ca": $return_abbrv = "ca"; break; // Catala
  5902. case "ch": $return_abbrv = "cn"; break; // Chinese
  5903. case "cz": $return_abbrv = "cs"; break; // Czech
  5904. case "de": $return_abbrv = "de"; break; // German
  5905. case "es": $return_abbrv = "es"; break; // Espanol
  5906. case "fr": $return_abbrv = "fr"; break; // Francais
  5907. case "gk": $return_abbrv = "en"; break; // Greek
  5908. case "he": $return_abbrv = "he"; break; // Hebrew
  5909. case "hu": $return_abbrv = "hu"; break; // Hungarian
  5910. case "it": $return_abbrv = "it"; break; // Italiano
  5911. case "nl": $return_abbrv = "nl"; break; // Netherlands/"Vlaams"(Flemish)
  5912. case "pl": $return_abbrv = "pl"; break; // Polish
  5913. case "ro_utf8":
  5914. case "ro": $return_abbrv = "ro"; break; // Romanian
  5915. case "ru": $return_abbrv = "ru"; break; // Russian
  5916. case "sr": $return_abbrv = "en"; break; // Serbian
  5917. case "se": $return_abbrv = "sv"; break; // Swedish
  5918. case "tr": $return_abbrv = "tr"; break; // Turkish
  5919. case "en":
  5920. default:
  5921. $return_abbrv = "en"; break;
  5922. }
  5923. return $return_abbrv;
  5924. }
  5925. }// end class
  5926. ?>