PageRenderTime 89ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/mcherryleigh/seniordesign
PHP | 5637 lines | 4481 code | 300 blank | 856 comment | 1325 complexity | 6b31140d9bbefb09dbb85ab8e66477e8 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. ################################################################################
  3. ## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- #
  4. ## --------------------------------------------------------------------------- #
  5. ## PHP DataGrid version 4.2.3 (12.01.2008) #
  6. ## Author & developer: Leumas Naypoka <leumas.a@gmail.com> #
  7. ## Developers: Zewa <http://www.thorax-music.com> #
  8. ## Fcallez <http://www.innovavirtual.org> #
  9. ## Lisence: GNU GPL #
  10. ## Site: http://phpbuilder.blogspot.com #
  11. ## Copyright: Leumas Naypoka (c) 2006-2008. All rights reserved. #
  12. ## #
  13. ## Additional modules (embedded): #
  14. ## -- openWYSIWYG 1.01 (free cross-browser) http://openWebWare.com #
  15. ## -- PEAR::DB 1.7.11 (PHP Ext. & Application Repository) http://pear.php.net #
  16. ## -- JS AFV 1.0.3 (JS Auto From Validator) http://phpbuilder.blogspot.com #
  17. ## -- overLIB 4.21 (JS library) http://www.bosrup.com/web/overlib/ #
  18. ## -- FPDF v.1.53 (PDF files generator) http://www.fpdf.org #
  19. ## -- JsCalendar v.1.0 (DHTML/JavaScript Calendar) http://www.dynarch.com #
  20. ## #
  21. ################################################################################
  22. ## +---------------------------------------------------------------------------+
  23. ## | 1. Creating & Calling: |
  24. ## +---------------------------------------------------------------------------+
  25. ## *** define a relative (virtual) path to datagrid.class.php file and "pear"
  26. ## *** directory (relatively to the current file)
  27. ## *** RELATIVE PATH ONLY ***
  28. //
  29. // define ("DATAGRID_DIR", ""); /* Ex.: "datagrid/" */
  30. // define ("PEAR_DIR", "pear/"); /* Ex.: "datagrid/pear/" */
  31. //
  32. // require_once(DATAGRID_DIR.'datagrid.class.php');
  33. // require_once(PEAR_DIR.'PEAR.php');
  34. // require_once(PEAR_DIR.'DB.php');
  35. ##
  36. ## *** creating variables that we need for database connection
  37. // $DB_USER='name'; /* usually like this: prefix_name */
  38. // $DB_PASS=''; /* must be already enscrypted (recommended) */
  39. // $DB_HOST='localhost'; /* usually localhost */
  40. // $DB_NAME='dbName'; /* usually like this: prefix_dbName */
  41. //
  42. // ob_start();
  43. ## *** (example of ODBC connection string)
  44. ## *** $result_conn = $db_conn->connect(DB::parseDSN('odbc://root:12345@test_db'));
  45. ## *** (example of Oracle connection string)
  46. ## *** $result_conn = $db_conn->connect(DB::parseDSN('oci8://root:12345@localhost:1521/mydatabase));
  47. ## *** (example of PostgreSQL connection string)
  48. ## *** $result_conn = $db_conn->connect(DB::parseDSN('pgsql://root:12345@localhost/mydatabase));
  49. ## === (Examples of connections to other db types see in "docs/pear/" folder)
  50. // $db_conn = DB::factory('mysql'); /* don't forget to change on appropriate db type */
  51. // $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
  52. // if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }
  53. ## *** put a primary key on the first place
  54. // $sql = "SELECT primary_key, field_1, field_2 ... FROM tableName ;";
  55. ## *** set needed options and create a new class instance
  56. // $debug_mode = false; /* display SQL statements while processing */
  57. // $messaging = true; /* display system messages on a screen */
  58. // $unique_prefix = "abc_"; /* prevent overlays - must be started with a letter */
  59. // $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
  60. ## *** set data source with needed options
  61. // $default_order_field = "field_name_1 [, field_name_2...]";
  62. // $default_order_type = "ASC|DESC [, ASC|DESC...]";
  63. // $dgrid->dataSource($db_conn, $sql, $default_order_field, $default_order_type);
  64. ##
  65. ##
  66. ## +---------------------------------------------------------------------------+
  67. ## | 2. General Settings: |
  68. ## +---------------------------------------------------------------------------+
  69. ## *** set encoding and collation (default: utf8/utf8_unicode_ci)
  70. /// $dg_encoding = "utf8";
  71. /// $dg_collation = "utf8_unicode_ci";
  72. /// $dgrid->setEncoding($dg_encoding, $dg_collation);
  73. ## *** set interface language (default - English)
  74. ## *** (en) - English (de) - German (se) - Swedish (hr) - Bosnian/Croatian
  75. ## *** (hu) - Hungarian (es) - Espanol (ca) - Catala (fr) - Francais
  76. ## *** (nl) - Netherlands/"Vlaams"(Flemish) (it) - Italiano (pl) - Polish
  77. ## *** (ch) - Chinese (sr) - Serbian (bg) - Bulgarian (pb) - Brazilian Portuguese
  78. ## *** (ar) - Arabic
  79. /// $dg_language = "en";
  80. /// $dgrid->setInterfaceLang($dg_language);
  81. ## *** set direction: "ltr" or "rtr" (default - "ltr")
  82. /// $direction = "ltr";
  83. /// $dgrid->setDirection($direction);
  84. ## *** set layouts: "0" - tabular(horizontal) - default, "1" - columnar(vertical), "2" - customized
  85. /// $layouts = array("view"=>"0", "edit"=>"1", "details"=>"1", "filter"=>"1");
  86. /// $dgrid->setLayouts($layouts);
  87. /// $details_template = "<table><tr><td>{field_name_1}</td><td>{field_name_2}</td></tr>...</table>";
  88. /// $dgrid->setTemplates("","",$details_template);
  89. ## *** set modes for operations ("type" => "link|button|image")
  90. ## *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
  91. /// $modes = array(
  92. /// "add" =>array("view"=>true, "edit"=>false, "type"=>"link"),
  93. /// "edit" =>array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>""),
  94. /// "cancel" =>array("view"=>true, "edit"=>true, "type"=>"link"),
  95. /// "details" =>array("view"=>true, "edit"=>false, "type"=>"link"),
  96. /// "delete" =>array("view"=>true, "edit"=>true, "type"=>"image")
  97. /// );
  98. /// $dgrid->setModes($modes);
  99. ## *** allow scrolling on datagrid
  100. /// $scrolling_option = false;
  101. /// $dgrid->allowScrollingSettings($scrolling_option);
  102. ## *** set scrolling settings (optional)
  103. /// $scrolling_width = "90%";
  104. /// $scrolling_height = "100%";
  105. /// $dgrid->setScrollingSettings($scrolling_width, $scrolling_height);
  106. ## *** allow mulirow operations
  107. // $multirow_option = true;
  108. // $dgrid->allowMultirowOperations($multirow_option);
  109. /// $multirow_operations = array(
  110. /// "delete" => array("view"=>true),
  111. /// "details" => array("view"=>true),
  112. /// "my_operation_name" => array("view"=>true, "flag_name"=>"my_flag_name", "flag_value"=>"my_flag_value", "tooltip"=>"Do something with selected", "image"=>"image.gif")
  113. /// );
  114. /// $dgrid->setMultirowOperations($multirow_operations);
  115. ## *** set CSS class for datagrid
  116. ## *** "default" or "blue" or "gray" or "green" or your own css file
  117. /// $css_class = "default";
  118. /// $dgrid->setCssClass($css_class);
  119. ## *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
  120. /// $http_get_vars = array("act", "id");
  121. /// $dgrid->setHttpGetVars($http_get_vars);
  122. ## *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
  123. ## *** format (in which mode to allow processing of another datagrids)
  124. ## *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
  125. /// $anotherDatagrids = array("abcd_"=>array("view"=>true, "edit"=>true, "details"=>true));
  126. /// $dgrid->setAnotherDatagrids($anotherDatagrids);
  127. ## *** set DataGrid caption
  128. /// $dg_caption = "My Favorite Lovely PHP DataGrid";
  129. /// $dgrid->setCaption($dg_caption);
  130. ##
  131. ##
  132. ## +---------------------------------------------------------------------------+
  133. ## | 3. Printing & Exporting Settings: |
  134. ## +---------------------------------------------------------------------------+
  135. ## *** set printing option: true(default) or false
  136. /// $printing_option = true;
  137. /// $dgrid->allowPrinting($printing_option);
  138. ## *** set exporting option: true(default) or false and relative (virtual) path
  139. ## *** to export directory (relatively to datagrid.class.php file).
  140. ## *** Ex.: "" - if we use current datagrid folder
  141. /// $exporting_option = true;
  142. /// $exporting_directory = "";
  143. /// $dgrid->allowExporting($exporting_option, $exporting_directory);
  144. ##
  145. ##
  146. ## +---------------------------------------------------------------------------+
  147. ## | 4. Sorting & Paging Settings: |
  148. ## +---------------------------------------------------------------------------+
  149. ## *** set sorting option: true(default) or false
  150. /// $sorting_option = true;
  151. /// $dgrid->allowSorting($sorting_option);
  152. ## *** set paging option: true(default) or false
  153. /// $paging_option = true;
  154. /// $rows_numeration = false;
  155. /// $numeration_sign = "N #";
  156. /// $dgrid->allowPaging($paging_option, $rows_numeration, $numeration_sign);
  157. ## *** set paging settings
  158. /// $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  159. /// $top_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  160. // $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  161. /// $default_page_size = 10;
  162. /// $dgrid->setPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
  163. ##
  164. ##
  165. ## +---------------------------------------------------------------------------+
  166. ## | 5. Filter Settings: |
  167. ## +---------------------------------------------------------------------------+
  168. ## *** set filtering option: true or false(default)
  169. /// $filtering_option = true;
  170. /// $show_search_type = true;
  171. /// $dgrid->allowFiltering($filtering_option, $show_search_type);
  172. ## *** set aditional filtering settings
  173. /// $fill_from_array = array("0"=>"No", "1"=>"Yes"); /* as "value"=>"option" */
  174. /// $filtering_fields = array(
  175. /// "Caption_1"=>array("table"=>"tableName_1", "field"=>"fieldName_1|,fieldName_2", "source"=>"self"|$fill_from_array, "show_operator"=>false|true, "default_operator"=>"=|<|>|like|%like|like%|not like", "order"=>"ASC|DESC (optional)", "type"=>"textbox|dropdownlist", "case_sensitive"=>false|true, "comparison_type"=>"string|numeric|binary"),
  176. /// "Caption_2"=>array("table"=>"tableName_2", "field"=>"fieldName_2", "source"=>"self"|$fill_from_array, "show_operator"=>false|true, "default_operator"=>"=|<|>|like|%like|like%|not like", "order"=>"ASC|DESC (optional)", "type"=>"textbox|dropdownlist", "case_sensitive"=>false|true, "comparison_type"=>"string|numeric|binary"),
  177. /// "Caption_3"=>array("table"=>"tableName_3", "field"=>"fieldName_3", "source"=>"self"|$fill_from_array, "show_operator"=>false|true, "default_operator"=>"=|<|>|like|%like|like%|not like", "order"=>"ASC|DESC (optional)", "type"=>"textbox|dropdownlist", "case_sensitive"=>false|true, "comparison_type"=>"string|numeric|binary")
  178. /// );
  179. /// $dgrid->setFieldsFiltering($filtering_fields);
  180. ##
  181. ##
  182. ## +---------------------------------------------------------------------------+
  183. ## | 6. View Mode Settings: |
  184. ## +---------------------------------------------------------------------------+
  185. ## *** set view mode table properties
  186. /// $vm_table_properties = array("width"=>"90%");
  187. /// $dgrid->setViewModeTableProperties($vm_table_properties);
  188. ## *** set columns in view mode
  189. ## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  190. ## *** "barchart" : number format in SELECT SQL must be equal with number format in max_value
  191. /// $vm_colimns = array(
  192. /// "FieldName_1"=>array("header"=>"Name_A", "type"=>"label", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
  193. /// "FieldName_2"=>array("header"=>"Name_B", "type"=>"image", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "default"=>"default_image.ext", "image_width"=>"50px", "image_height"=>"30px"),
  194. /// "FieldName_3"=>array("header"=>"Name_C", "type"=>"linktoview", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
  195. /// "FieldName_3"=>array("header"=>"Name_C", "type"=>"linktoedit", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
  196. /// "FieldName_4"=>array("header"=>"Name_D", "type"=>"link", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "field_key"=>"field_name_0"|"field_key_1"=>"field_name_1"|..., "field_data"=>"field_name_2", "rel"=>"", "title"=>"", "target"=>"_new", "href"=>"{0}"),
  197. /// "FieldName_5"=>array("header"=>"Name_E", "type"=>"link", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "field_key"=>"field_name_0"|"field_key_1"=>"field_name_1"|..., "field_data"=>"field_name_2", "rel"=>"", "title"=>"", "target"=>"_new", "href"=>"mailto:{0}"),
  198. /// "FieldName_6"=>array("header"=>"Name_F", "type"=>"link", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "field_key"=>"field_name_0"|"field_key_1"=>"field_name_1"|..., "field_data"=>"field_name_2", "rel"=>"", "title"=>"", "target"=>"_new", "href"=>"http://mydomain.com?act={0}&act={1}&code=ABC"),
  199. /// "FieldName_7"=>array("header"=>"Name_G", "type"=>"password", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
  200. /// "FieldName_8"=>array("header"=>"Name_H", "type"=>"barchart", "align"=>"left", "width"=>"X%|Xpx", "wrap"=>"wrap|nowrap", "text_length"=>"-1", "tooltip"=>true|false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "field"=>"field_name", "maximum_value"=>"value")
  201. /// );
  202. /// $dgrid->setColumnsInViewMode($vm_colimns);
  203. ## *** set auto-genereted columns in view mode
  204. // $auto_column_in_view_mode = false;
  205. // $dgrid->setAutoColumnsInViewMode($auto_column_in_view_mode);
  206. ##
  207. ##
  208. ## +---------------------------------------------------------------------------+
  209. ## | 7. Add/Edit/Details Mode Settings: |
  210. ## +---------------------------------------------------------------------------+
  211. ## *** set add/edit mode table properties
  212. /// $em_table_properties = array("width"=>"70%");
  213. /// $dgrid->setEditModeTableProperties($em_table_properties);
  214. ## *** set details mode table properties
  215. /// $dm_table_properties = array("width"=>"70%");
  216. /// $dgrid->setDetailsModeTableProperties($dm_table_properties);
  217. ## *** set settings for add/edit/details modes
  218. // $table_name = "table_name";
  219. // $primary_key = "primary_key";
  220. // $condition = "table_name.field = ".$_REQUEST['abc_rid'];
  221. // $dgrid->setTableEdit($table_name, $primary_key, $condition);
  222. ## *** set columns in edit mode
  223. ## *** first letter: r - required, s - simple (not required)
  224. ## *** second letter: t - text(including datetime), n - numeric, a - alphanumeric, e - email, f - float, y - any, l - login name, z - zipcode, p - password, i - integer, v - verified, c - checkbox, u - URL
  225. ## *** third letter (optional):
  226. ## for numbers: s - signed, u - unsigned, p - positive, n - negative
  227. ## for strings: u - upper, l - lower, n - normal, y - any
  228. ## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  229. ## *** Ex.: type = textbox|textarea|label|date(yyyy-mm-dd)|datedmy(dd-mm-yyyy)|datetime(yyyy-mm-dd hh:mm:ss)|datetimedmy(dd-mm-yyyy hh:mm:ss)|time(hh:mm:ss)|image|password|enum|print|checkbox
  230. ## *** make sure your WYSIWYG dir has 777 permissions
  231. /// $fill_from_array = array("0"=>"No", "1"=>"Yes", "2"=>"Don't know", "3"=>"My be"); /* as "value"=>"option" */
  232. /// $em_columns = array(
  233. /// "FieldName_1" =>array("header"=>"Name_A", "type"=>"textbox", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  234. /// "FieldName_2" =>array("header"=>"Name_B", "type"=>"textarea", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "edit_type"=>"simple|wysiwyg", "resizable"=>"false", "rows"=>"7", "cols"=>"50"),
  235. /// "FieldName_3" =>array("header"=>"Name_C", "type"=>"label", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  236. /// "FieldName_4" =>array("header"=>"Name_D", "type"=>"date", "req_type"=>"rt", "width"=>"187px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"popup|floating"),
  237. /// "FieldName_5" =>array("header"=>"Name_E", "type"=>"datetime", "req_type"=>"st", "width"=>"187px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"popup|floating"),
  238. /// "FieldName_6" =>array("header"=>"Name_F", "type"=>"time", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  239. /// "FieldName_7" =>array("header"=>"Name_G", "type"=>"image", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"100000|100K|10M|1G", "image_width"=>"Xpx", "image_height"=>"Ypx", "file_name"=>"Image_Name", "host"=>"local|remote"),
  240. /// "FieldName_8" =>array("header"=>"Name_H", "type"=>"password", "req_type"=>"rp", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  241. /// "FieldName_9" =>array("header"=>"Name_I", "type"=>"enum", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>"self"|$fill_from_array, "view_type"=>"dropdownlist(default)|radiobutton", "radiobuttons_alignment"=>"horizontal|vertical", "multiple"=>false, "multiple_size"=>"4"),
  242. /// "FieldName_10" =>array("header"=>"Name_J", "type"=>"print", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  243. /// "FieldName_11" =>array("header"=>"Name_K", "type"=>"checkbox", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "true_value"=>1, "false_value"=>0),
  244. /// "FieldName_12" =>array("header"=>"Name_L", "type"=>"file", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"100000|100K|10M|1G", "file_name"=>"File_Name", "host"=>"local|remote"),
  245. /// "FieldName_13" =>array("header"=>"Name_M", "type"=>"link", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "field_key"=>"field_name_0"|"field_key_1"=>"field_name_1"|..., "field_data"=>"field_name_2", "target"=>"_new", "href"=>"http://mydomain.com?act={0}&act={1}&code=ABC"),
  246. /// "FieldName_14" =>array("header"=>"", "type"=>"hidden", "req_type"=>"st", "default"=>"default_value", "visible"=>"true", "unique"=>false|true),
  247. /// "validator" =>array("header"=>"Name_N", "for_field"=>"", "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "visible"=>"true", "on_js_event"=>""),
  248. /// "delimiter" =>array("inner_html"=>"<br />")
  249. /// );
  250. /// $dgrid->setColumnsInEditMode($em_columns);
  251. ## *** set auto-genereted columns in edit mode
  252. // $auto_column_in_edit_mode = false;
  253. // $dgrid->setAutoColumnsInEditMode($auto_column_in_edit_mode);
  254. ## *** set foreign keys for add/edit/details modes (if there are linked tables)
  255. ## *** Ex.: "condition"=>"TableName_1.FieldName > 'a' AND TableName_1.FieldName < 'c'"
  256. ## *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  257. /// $foreign_keys = array(
  258. /// "ForeignKey_1"=>array("table"=>"TableName_1", "field_key"=>"FieldKey_1", "field_name"=>"FieldName_1", "view_type"=>"dropdownlist(default)|radiobutton|textbox", "radiobuttons_alignment"=>"horizontal|vertical", "condition"=>"", "order_by_field"=>"Field_Name", "order_type"=>"ASC|DESC", "on_js_event"=>""),
  259. /// "ForeignKey_2"=>array("table"=>"TableName_2", "field_key"=>"FieldKey_2", "field_name"=>"FieldName_2", "view_type"=>"dropdownlist(default)|radiobutton|textbox", "radiobuttons_alignment"=>"horizontal|vertical", "condition"=>"", "order_by_field"=>"Field_Name", "order_type"=>"ASC|DESC", "on_js_event"=>"")
  260. /// );
  261. /// $dgrid->setForeignKeysEdit($foreign_keys);
  262. ##
  263. ##
  264. ## +---------------------------------------------------------------------------+
  265. ## | 8. Bind the DataGrid: |
  266. ## +---------------------------------------------------------------------------+
  267. ## *** bind the DataGrid and draw it on the screen
  268. // $dgrid->bind();
  269. // ob_end_flush();
  270. ##
  271. ################################################################################
  272. ////////////////////////////////////////////////////////////////////////////////
  273. //
  274. // Not documented:
  275. // -----------------------------------------------------------------------------
  276. // Property : first_field_focus_allowed = true|false;
  277. // --//-- : hide_grid_before_serach = true|false;
  278. // --//-- : draw_add_button_separately = true|false;
  279. // --//-- : "pre_addition"=>"" and "post_addition"=>"" attributes in view mode for labels and in add/edit/details modes for textboxes
  280. // --//-- : "autocomplete"=>"on|off" attribute for textboxes in add/edit modes
  281. //
  282. // Method : executeSql()
  283. // use it after dataSource() method only (after the using dataSource() need to be recalled)
  284. // $dSet = $dgrid->executeSql("SELECT * FROM tblPresidents WHERE tblPresidents.CountryID = ".$_GET['f_rid']."");
  285. // while($row = $dSet->fetchRow()){
  286. // for($c = 0; ($c < $dSet->numCols()); $c++){ echo $row[$c]." "; }
  287. // echo "<br />";
  288. // }
  289. // --//-- : selectSqlItem()
  290. // $presidents = $dgrid->selectSqlItem("SELECT COUNT(tblPresidents.presidentID) FROM tblPresidents WHERE tblPresidents.CountryID = ".$_GET['f_rid']."");
  291. // --//-- : allowHighlighting(true|false);
  292. // --//-- : setJsErrorsDisplayStyle("all"|"each");
  293. // --//-- : getNextId();
  294. // --//-- : setHeadersInColumnarLayout("Field Name", "Field Value");
  295. // --//-- : setDgMessages("add", "update", "delete");
  296. //
  297. // Feature : onSubmitMyCheck
  298. // <script type='text/javascript'>
  299. // function unique_prefix_onSubmitMyCheck(){
  300. // return true;
  301. // }
  302. // </script>
  303. // --//-- : "on_js_event"=>"onchange='formAction(\"\", \"\", \"".$dgrid->unique_prefix."\", \"".$dgrid->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\")'"
  304. //
  305. ////////////////////////////////////////////////////////////////////////////////
  306. ////////////////////////////////////////////////////////////////////////////////
  307. //
  308. // Tricks:
  309. // -----------------------------------------------------------------------------
  310. // 1. Default value, that disappears on focus:
  311. // "default"=>"http://www.website.com", "on_js_event"=>"onBlur='if(this.value == \"\") this.value = \"http://www.website.com\"; this.style.color=\"#f68d6f\";' onClick='if(this.value==\"http://www.website.com\") this.value=\"\"; this.style.color=\"#000000\";'",
  312. // 2. Uniquie value for uploading image:
  313. // "file_name"=>"img_".((isset($_GET['prfx_mode']) && ($_GET['prfx_mode'] == "add")) ? $dgrid->getNextId() : $dgrid->rid)
  314. //
  315. ////////////////////////////////////////////////////////////////////////////////
  316. class DataGrid
  317. {
  318. //==========================================================================
  319. // Data Members
  320. //==========================================================================
  321. // unique prefixes ---------------------------------------------------------
  322. var $unique_prefix;
  323. var $unique_random_prefix;
  324. // directory ---------------------------------------------------------------
  325. var $directory;
  326. // language ----------------------------------------------------------------
  327. var $lang_name;
  328. var $lang;
  329. // caption -----------------------------------------------------------------
  330. var $caption;
  331. // rows and columns data members -------------------------------------------
  332. var $rows;
  333. var $row_lower;
  334. var $row_upper;
  335. var $columns;
  336. var $col_lower;
  337. var $col_upper;
  338. // http get vars -----------------------------------------------------------
  339. var $http;
  340. var $port;
  341. var $HTTP_URL;
  342. var $http_get_vars;
  343. var $another_datagrids;
  344. // data source -------------------------------------------------------------
  345. var $db_handler;
  346. var $sql;
  347. var $sql_view;
  348. var $sql_group_by;
  349. var $data_set;
  350. // signs -------------------------------------------------------------------
  351. var $amp;
  352. var $nbsp;
  353. // encoding & direction ----------------------------------------------------
  354. var $encoding;
  355. var $collation;
  356. var $direction;
  357. // layout style ------------------------------------------------------------
  358. var $layouts;
  359. var $layout_type;
  360. // templates ---------------------------------------------------------------
  361. var $templates;
  362. // paging variables --------------------------------------------------------
  363. var $pages_total;
  364. var $page_current;
  365. var $req_page_size;
  366. var $paging_allowed;
  367. var $rows_numeration;
  368. var $numeration_sign;
  369. var $lower_paging;
  370. var $upper_paging;
  371. var $pages_array;
  372. var $limit_start;
  373. var $limit_size;
  374. var $rows_total;
  375. // sorting variables -------------------------------------------------------
  376. var $sort_field;
  377. var $sort_type;
  378. var $default_sort_field;
  379. var $default_sort_type;
  380. var $sorting_allowed;
  381. var $sql_sort;
  382. // filtering variables -----------------------------------------------------
  383. var $filtering_allowed;
  384. var $show_search_type;
  385. var $filter_fields;
  386. var $hide_display;
  387. // columns style parameters ------------------------------------------------
  388. var $wrap;
  389. // css style ---------------------------------------------------------------
  390. var $row_highlighting_allowed;
  391. var $css_class;
  392. var $rowColor;
  393. // table style parameters --------------------------------------------------
  394. var $tblAlign;
  395. var $tblWidth;
  396. var $tblBorder;
  397. var $tblBorderColor;
  398. var $tblCellSpacing;
  399. var $tblCellPadding;
  400. // datagrid modes ----------------------------------------------------------
  401. var $modes;
  402. var $mode;
  403. var $rid;
  404. var $rids;
  405. var $tbl_name;
  406. var $primary_key;
  407. var $condition;
  408. var $foreign_keys_array;
  409. var $columns_view_mode;
  410. var $columns_edit_mode;
  411. var $sorted_columns;
  412. var $draw_add_button_separately;
  413. // printing & exporting ----------------------------------------------------
  414. var $printing_allowed;
  415. var $exporting_allowed;
  416. var $exporting_directory;
  417. // debug mode --------------------------------------------------------------
  418. var $debug;
  419. var $start_time;
  420. var $end_time;
  421. // message -----------------------------------------------------------------
  422. var $act_msg;
  423. var $messaging;
  424. var $is_error;
  425. var $errors;
  426. var $is_warning;
  427. var $warnings;
  428. var $dg_messages;
  429. // browser & system types --------------------------------------------------
  430. var $platform;
  431. var $browser_name;
  432. var $browser_version;
  433. // scrolling ---------------------------------------------------------------
  434. var $scrolling_option;
  435. var $scrolling_width;
  436. var $scrolling_height;
  437. // header names ------------------------------------------------------------
  438. var $field_header;
  439. var $field_value_header;
  440. // hide --------------------------------------------------------------------
  441. var $hide_grid_before_serach;
  442. // summarize ---------------------------------------------------------------
  443. var $summarize_columns;
  444. // multirow ----------------------------------------------------------------
  445. var $multirow_allowed;
  446. var $multi_rows;
  447. var $multirow_operations_array;
  448. // first field focus -------------------------------------------------------
  449. var $first_field_focus_allowed;
  450. // javascript errors display style -----------------------------------------
  451. var $js_validation_errors;
  452. //==========================================================================
  453. // Member Functions
  454. //==========================================================================
  455. //--------------------------------------------------------------------------
  456. // default constructor
  457. //--------------------------------------------------------------------------
  458. function DataGrid($debug_mode = false, $messaging = true, $unique_prefix = "", $datagrid_dir = "datagrid/"){
  459. // start calculating running time of a script
  460. $this->start_time = 0;
  461. $this->end_time = 0;
  462. if($debug_mode == true){
  463. $this->start_time = $this->getFormattedMicrotime();
  464. }
  465. // unique prefixes -----------------------------------------------------
  466. $this->setUniquePrefix($unique_prefix);
  467. // directory -----------------------------------------------------------
  468. $this->directory = $datagrid_dir;
  469. // language ------------------------------------------------------------
  470. $this->lang_name = "en";
  471. $this->lang = array();
  472. $this->lang['total'] = "Total";
  473. $this->lang['wrong_parameter_error'] = "Wrong parameter in [<b>_FIELD_</b>]: _VALUE_";
  474. // caption -------------------------------------------------------------
  475. $this->caption = "";
  476. // rows and columns data members ---------------------------------------
  477. $this->http = $this->getProtocol();
  478. $this->port = $this->getPort();
  479. $this->HTTP_URL = $this->http.$_SERVER['HTTP_HOST'].$this->port.$_SERVER['PHP_SELF'];
  480. // http get vars -------------------------------------------------------
  481. $this->http_get_vars = "";
  482. $this->another_datagrids = "";
  483. // css style ----------------------------------------------------------
  484. $this->row_highlighting_allowed = true;
  485. $this->css_class = "default";
  486. $this->rowColor = array();
  487. // signs ---------------------------------------------------------------
  488. $this->amp = "&amp;";
  489. $this->nbsp = ""; //&nbsp;
  490. $this->rows = 0;
  491. $this->row_lower = 0;
  492. $this->row_upper = 0;
  493. $this->columns = 0;
  494. $this->col_lower = 0;
  495. $this->col_upper = 0;
  496. // encoding & direction ------------------------------------------------
  497. $this->encoding = "utf8";
  498. $this->collation = "utf8_unicode_ci";
  499. $this->direction = "ltr";
  500. $this->layouts['view'] = "0";
  501. $this->layouts['edit'] = "1";
  502. $this->layouts['filter'] = "1";
  503. $this->layouts['show'] = "1";
  504. $this->layout_type = "view";
  505. // templates -----------------------------------------------------------
  506. $this->templates['view'] = "";
  507. $this->templates['edit'] = "";
  508. $this->templates['show'] = "";
  509. $this->pages_total = 0;
  510. $this->page_current = 0;
  511. $this->pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  512. $this->req_page_size = 10;
  513. $this->paging_allowed = true;
  514. $this->rows_numeration = false;
  515. $this->numeration_sign = "N #";
  516. $this->lower_paging['results'] = false;
  517. $this->lower_paging['results_align'] = "left";
  518. $this->lower_paging['pages'] = false;
  519. $this->lower_paging['pages_align'] = "center";
  520. $this->lower_paging['page_size'] = false;
  521. $this->lower_paging['page_size_align'] = "right";
  522. $this->upper_paging['results'] = false;
  523. $this->upper_paging['results_align'] = "left";
  524. $this->upper_paging['pages'] = false;
  525. $this->upper_paging['pages_align'] = "center";
  526. $this->upper_paging['page_size'] = false;
  527. $this->upper_paging['page_size_align'] = "right";
  528. $this->limit_start = 0;
  529. $this->limit_size = $this->req_page_size;
  530. $this->rows_total = 0;
  531. $this->sort_field = "";
  532. $this->sort_field_by = "";
  533. $this->sort_type = "";
  534. $this->default_sort_field = array();
  535. $this->default_sort_type = array();
  536. $this->sorting_allowed = true;
  537. $this->sql_view = "";
  538. $this->sql_group_by = "";
  539. $this->sql = "";
  540. $this->sql_sort = "";
  541. $this->filtering_allowed = false;
  542. $this->show_search_type = true;
  543. $this->filter_fields = array();
  544. $this->hide_display = "";
  545. $this->tblAlign['view'] = "center"; $this->tblAlign['edit'] = "center"; $this->tblAlign['details'] = "center";
  546. $this->tblWidth['view'] = "90%"; $this->tblWidth['edit'] = "70%"; $this->tblWidth['details'] = "60%";
  547. $this->tblBorder['view'] = "1"; $this->tblBorder['edit'] = "1"; $this->tblBorder['details'] = "1";
  548. $this->tblBorderColor['view'] = "#000000"; $this->tblBorderColor['edit'] = "#000000"; $this->tblBorderColor['details'] = "#000000";
  549. $this->tblCellSpacing['view'] = "0"; $this->tblCellSpacing['edit'] = "0"; $this->tblCellSpacing['details'] = "0";
  550. $this->tblCellPadding['view'] = "0"; $this->tblCellPadding['edit'] = "0"; $this->tblCellPadding['details'] = "0";
  551. // datagrid modes ------------------------------------------------------
  552. $this->modes["add"] = array("view"=>true, "edit"=>false, "type"=>"link");
  553. $this->modes["edit"] = array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>"");
  554. $this->modes["cancel"] = array("view"=>true, "edit"=>true, "type"=>"link");
  555. $this->modes["details"] = array("view"=>true, "edit"=>false, "type"=>"link");$this->modes["delete"] = array("view"=>true, "edit"=>true, "type"=>"image");
  556. $this->draw_add_button_separately = false;
  557. $this->mode = "view";
  558. $this->rid = "";
  559. $this->rids = "";
  560. $this->tbl_name ="";
  561. $this->primary_key = 0;
  562. $this->condition = "";
  563. $this->foreign_keys_array = array();
  564. $this->columns_view_mode = array();
  565. $this->columns_edit_mode = array();
  566. $this->sorted_columns = array();
  567. $this->printing_allowed = true;
  568. $this->exporting_allowed = false;
  569. $this->exporting_directory = "";
  570. $this->wrap = "wrap";
  571. // scrolling -----------------------------------------------------------
  572. $this->scrolling_option = false;
  573. $this->scrolling_width = "90%";
  574. $this->scrolling_height = "100%";
  575. // header names --------------------------------------------------------
  576. $this->field_header = "";
  577. $this->field_value_header = "";
  578. // hide ----------------------------------------------------------------
  579. $this->hide_grid_before_serach = false;
  580. $this->summarize_columns = array();
  581. $this->multirow_allowed = false;
  582. $this->multi_rows = 0;
  583. $this->multirow_operations_array = array();
  584. $this->multirow_operations_array['delete'] = array("view"=>true);
  585. $this->multirow_operations_array['details'] = array("view"=>true);
  586. $this->first_field_focus_allowed = false;
  587. // message -------------------------------------------------------------
  588. $this->act_msg = "";
  589. $this->debug = (($debug_mode == true) || ($debug_mode == "true")) ? true : false ;
  590. if($this->debug) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
  591. $this->messaging = (($messaging == true) || ($messaging == "true")) ? true : false ;
  592. $this->is_error = false;
  593. $this->errors = array();
  594. $this->is_warning = false;
  595. $this->warnings = array();
  596. $this->dg_messages = array();
  597. $this->dg_messages['add'] = "";
  598. $this->dg_messages['update'] = "";
  599. $this->dg_messages['delete'] = "";
  600. // javascript errors display style -------------------------------------
  601. $this->js_validation_errors = "true";
  602. // set browser definitions
  603. $this->setBrowserDefinitions();
  604. }
  605. //--------------------------------------------------------------------------
  606. // set unique names
  607. //--------------------------------------------------------------------------
  608. function setUniquePrefix($unique_prefix = ""){
  609. $this->unique_prefix = $unique_prefix;
  610. $this->unique_random_prefix = $this->getRandomString("5");
  611. }
  612. //--------------------------------------------------------------------------
  613. // set Http Get Vars
  614. //--------------------------------------------------------------------------
  615. function setHttpGetVars($http_get_vars = ""){
  616. $this->http_get_vars = $http_get_vars;
  617. }
  618. //--------------------------------------------------------------------------
  619. // set Other DataGrids
  620. //--------------------------------------------------------------------------
  621. function setAnotherDatagrids($another_datagrids = ""){
  622. $this->another_datagrids = $another_datagrids;
  623. }
  624. //--------------------------------------------------------------------------
  625. // set Scrolling Settings
  626. //--------------------------------------------------------------------------
  627. function allowScrollingSettings($scrolling_option = false){
  628. $this->scrolling_option = (($scrolling_option == true) || ($scrolling_option == "true")) ? true : false ;
  629. }
  630. //--------------------------------------------------------------------------
  631. // set Scrolling Settings
  632. //--------------------------------------------------------------------------
  633. function setScrollingSettings($width="", $height=""){
  634. if($width != "") $this->scrolling_width = $width;
  635. if($height != "") $this->scrolling_height = $height;
  636. }
  637. //--------------------------------------------------------------------------
  638. // set css class
  639. //--------------------------------------------------------------------------
  640. function setCssClass($class = "default"){
  641. $this->css_class = $class;
  642. }
  643. //--------------------------------------------------------------------------
  644. // write css class
  645. //--------------------------------------------------------------------------
  646. function writeCssClass($class = "default", $type = "embedded"){
  647. $req_print = $this->getVariable('print');
  648. if(strtolower($this->css_class) == "green"){
  649. $this->rowColor[0] = "#ffffff";
  650. $this->rowColor[1] = "#e4f5ef";
  651. $this->rowColor[2] = "#ffffff";
  652. $this->rowColor[3] = "#e4f5ef";
  653. $this->rowColor[4] = "#d4e5df";
  654. $this->rowColor[5] = "#d4e5df";
  655. $this->rowColor[6] = "#c6d7cf"; // header (th main) column
  656. $this->rowColor[7] = "#d4e5df"; // selected row mouse over lighting
  657. echo "\n<style>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>\n";
  658. }else if(strtolower($this->css_class) == "gray") {
  659. $this->rowColor[0] = "#f9f9f9";
  660. $this->rowColor[1] = "#f0f0f0";
  661. $this->rowColor[2] = "#f0f0f0";
  662. $this->rowColor[3] = "#dedede";
  663. $this->rowColor[4] = "#FEFFE8";
  664. $this->rowColor[5] = "#FEFFE8";
  665. $this->rowColor[6] = "#dedede"; // header (th main) column
  666. $this->rowColor[7] = "#FEFFE8"; // selected row mouse over lighting
  667. echo "\n<style>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>\n";
  668. }else if(strtolower($this->css_class) == "blue"){
  669. $this->rowColor[0] = "#f7f9fb";
  670. $this->rowColor[1] = "#ffffff";
  671. $this->rowColor[2] = "#d9e3f1";
  672. $this->rowColor[3] = "#e4ecf7";
  673. $this->rowColor[4] = "#FEFFE8";
  674. $this->rowColor[5] = "#FEFFE8";
  675. $this->rowColor[6] = "#cdd9ea"; // header (th main) column
  676. $this->rowColor[7] = "#FEFFE8"; // selected row mouse over lighting
  677. echo "\n<style>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #ddd no-repeat center 2px; }</style>\n";
  678. }else{
  679. $this->rowColor[0] = "#fcfaf6";
  680. $this->rowColor[1] = "#ffffff";
  681. $this->rowColor[2] = "#ebeadb"; // dark
  682. $this->rowColor[3] = "#ebeadb"; // light
  683. $this->rowColor[4] = "#e2f3fc"; // row mouse over lighting
  684. $this->rowColor[5] = "#fdfde7"; // on mouse click
  685. $this->rowColor[6] = "#e2e0cb"; // header (th main) column
  686. $this->rowColor[7] = "#f9f9e3"; // selected row mouse over lighting
  687. echo "\n<style>.resizable-textarea .grippie { BACKGROUND: url(".$this->directory."images/common/grippie.png) #eee no-repeat center 2px; }</style>\n";
  688. }
  689. // if we in Print Mode
  690. if($req_print == true){
  691. $this->rowColor[0] = "";
  692. $this->rowColor[1] = "";
  693. $this->rowColor[2] = ""; // dark
  694. $this->rowColor[3] = ""; // light
  695. $this->rowColor[4] = ""; // row mouse over lighting
  696. $this->rowColor[5] = ""; // on mouse click
  697. $this->rowColor[6] = ""; // header (th main) column
  698. $this->rowColor[7] = ""; // selected row mouse over lighting
  699. echo "\n<link rel='stylesheet' type='text/css' href='".$this->directory."css/style_print.css' />\n";
  700. }else{
  701. echo "\n<link rel='stylesheet' type='text/css' href='".$this->directory."css/style_".$this->css_class.".css' />\n";
  702. }
  703. }
  704. //--------------------------------------------------------------------------
  705. // set title for datagrid
  706. //--------------------------------------------------------------------------
  707. function setCaption($dg_title = ""){
  708. $this->caption = $dg_title;
  709. }
  710. //--------------------------------------------------------------------------
  711. // set data source
  712. //--------------------------------------------------------------------------
  713. function dataSource($db_handl, $sql = "", $start_order = "", $start_order_type = ""){
  714. // clear sql statment
  715. $sql = str_replace("\n", " ", $sql); // new row
  716. $sql = str_replace(chr(13), " ", $sql); // CR sign
  717. $sql = str_replace(chr(10), " ", $sql); // LF sign
  718. $sql = str_replace(";", "", $sql);
  719. // get preliminary Primary Key
  720. $p_key = explode(" ", $sql);
  721. $p_key = str_replace(",", "", $p_key[1]);
  722. $p_key = explode(".", $p_key);
  723. $this->primary_key = $p_key[count($p_key)-1];
  724. $req_sort_field = $this->getVariable('sort_field');
  725. $req_sort_field_by = $this->getVariable('sort_field_by');
  726. $sort_field = ($req_sort_field_by != "") ? $req_sort_field_by : $req_sort_field ;
  727. $req_sort_type = $this->getVariable('sort_type');
  728. $this->db_handler = $db_handl;
  729. $this->db_handler->setFetchMode(DB_FETCHMODE_ORDERED);
  730. // handle SELECT SQL statement
  731. $this->sql_view = $sql;
  732. if($this->lastSubStrOccurence($this->sql_view, "from ") < $this->lastSubStrOccurence($this->sql_view, "where ")){
  733. // handle SELECT statment with sub-SELECTs and SELECT without WHERE
  734. $ind = strpos(strtolower($this->sql_view), "group by");
  735. if($ind){
  736. $prefix = substr($sql, 0, $ind);
  737. $suffix = substr($sql, $ind);
  738. $this->sql_view = $prefix." ";
  739. $this->sql_group_by = $suffix;
  740. }else{
  741. $this->sql_view .= " WHERE 1=1 ";
  742. }
  743. }else if($this->lastSubStrOccurence($this->sql_view, "where ") == ""){
  744. $this->sql_view .= " WHERE 1=1 ";
  745. }else{
  746. $ind = strpos(strtolower($this->sql_view), "group by");
  747. if($ind){
  748. $prefix = substr($sql, 0, $ind);
  749. $suffix = substr($sql, $ind);
  750. $this->sql_view = $prefix." ";
  751. $this->sql_group_by = $suffix;
  752. }
  753. }
  754. $this->sql = $this->sql_view.$this->sql_group_by;
  755. // set default order
  756. if($start_order != ""){
  757. $default_sort_field = explode(",", $start_order);
  758. $default_sort_type = explode(",", $start_order_type);
  759. for($ind=0; $ind < count($default_sort_field); $ind++){
  760. $this->default_sort_field[$ind] = trim($default_sort_field[$ind]);
  761. if(isset($default_sort_type[$ind])){
  762. if((strtolower(trim($default_sort_type[$ind])) == "asc") || (strtolower(trim($default_sort_type[$ind])) == "desc")){
  763. $this->default_sort_type[$ind] = trim($default_sort_type[$ind]);
  764. }else{
  765. $this->default_sort_type[$ind] = "ASC";
  766. $this->addWarning('$default_order_type', $start_order_type);
  767. }
  768. }else{
  769. $this->default_sort_type[$ind] = "ASC";
  770. }
  771. }
  772. }else{
  773. $this->default_sort_field[0] = "1";
  774. $this->default_sort_type[0] = "ASC";
  775. }
  776. // create ORDER BY part of sql statment
  777. if($req_sort_field){
  778. if(!substr_count($this->sql, "ORDER BY")){
  779. $this->sql_sort = " ORDER BY ".$sort_field." ".$req_sort_type;
  780. }else{
  781. $this->sql_sort = " , ".$sort_field." ".$req_sort_type;
  782. }
  783. }else if($start_order != ""){
  784. $this->sql_sort = " ORDER BY ".$this->getOrderByList();
  785. }else{
  786. $this->sql_sort = " ORDER BY 1 ASC";
  787. }
  788. $this->getDataSet($this->sql_sort);
  789. // check if the preliminary key is a Primary Key
  790. if(strtolower($this->getFieldInfo(0, 'type', 1)) != "int"){
  791. $this->addWarning($this->primary_key, "Check this field carefully, it may be not a Primary Key!");
  792. }
  793. }
  794. //--------------------------------------------------------------------------
  795. // get DataSet
  796. //--------------------------------------------------------------------------
  797. function getDataSet($fsort = "", $limit = ""){
  798. $this->setEncodingOnDatabase();
  799. // we need this stupid operation to get a total number of rows in our query
  800. $this->setTotalNumberRows();
  801. if($limit == ""){
  802. $limit = $this->setSqlLimitByDbType();
  803. $this->data_set = & $this->db_handler->query($this->setSqlByDbType($this->sql, $fsort, $limit));
  804. }
  805. if($this->db_handler->isError($this->data_set) == 1){
  806. $this->is_error = true;
  807. $this->addErrors();
  808. }
  809. $this->rows = $this->numberRows();
  810. $this->columns = $this->numberCols();
  811. if($this->debug){
  812. 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 />";
  813. }
  814. $this->row_lower = 0;
  815. $this->row_upper = $this->rows;
  816. $this->col_lower = 0;
  817. $this->col_upper = $this->columns;
  818. }
  819. //--------------------------------------------------------------------------
  820. // ger ORDER BY fields list
  821. //--------------------------------------------------------------------------
  822. function getOrderByList(){
  823. $orderByList = "";
  824. for($ind=0; $ind < count($this->default_sort_field); $ind++){
  825. if($ind != 0) $orderByList .= ",";
  826. $orderByList .= " ".$this->default_sort_field[$ind]." ".$this->default_sort_type[$ind];
  827. }
  828. return $orderByList;
  829. }
  830. //--------------------------------------------------------------------------
  831. // perform security check from a Hack Attacks
  832. //--------------------------------------------------------------------------
  833. function securityCheck(){
  834. $req_rid = $this->getVariable('rid');
  835. if(eregi("'", $req_rid) || eregi('"', $req_rid) ||
  836. eregi("%27", $req_rid) || eregi("%22", $req_rid)){
  837. return false;
  838. }
  839. return true;
  840. }
  841. //--------------------------------------------------------------------------
  842. // bind data and draw
  843. //--------------------------------------------------------------------------
  844. function bind(){
  845. $this->setInterfaceLang();
  846. $this->setMediaPrint();
  847. $this->setCommonJavaScript();
  848. $req_mode = $this->getVariable('mode');
  849. $req_rid = $this->getVariable('rid');
  850. $req_new = $this->getVariable('new');
  851. $req_page_size = $this->getVariable('page_size');
  852. $req_sort_field = $this->getVariable('sort_field');
  853. $req_sort_field_by = $this->getVariable('sort_field_by');
  854. $sort_field = ($req_sort_field_by != "") ? $req_sort_field_by : $req_sort_field ;
  855. $req_sort_type = $this->getVariable('sort_type');
  856. $req_print = $this->getVariable('print');
  857. // protect datagrid from a Hack Attacks
  858. if($this->securityCheck()){
  859. // VIEW mode processing
  860. if($req_mode == ""){
  861. $this->getDataSet($this->sql_sort);
  862. $view_limit = $this->setSqlLimitByDbType("0", $req_page_size);
  863. }
  864. // DELETE mode processing
  865. if(($req_mode == "delete") && ($req_rid != "")){
  866. $this->rid = $req_rid;
  867. if($req_print != true){
  868. $this->deleteRow($this->rid);
  869. }
  870. $this->sql = $this->sql_view;
  871. $this->getDataSet($this->sql_sort);
  872. $this->mode = "view";
  873. }
  874. // EDIT & DETAILS modes processing
  875. if((($req_mode == "edit") || ($req_mode == "details")) && ($req_rid != "")){
  876. if($req_new == 1){
  877. $this->data_set = $this->db_handler->query($this->sql);
  878. }
  879. $this->rid = $req_rid;
  880. $this->allowSorting(false);
  881. $this->allowPaging(false);
  882. $this->sql_sort = " ORDER BY " . $this->primary_key . " DESC";
  883. if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "1") && ($req_mode == "details")){
  884. $this->rids = explode("-", $this->rid);
  885. // if we have more that 1 row selected
  886. if(count($this->rids) > 1){
  887. $where = "WHERE ".$this->primary_key." IN ('-1' ";
  888. foreach ($this->rids as $key){ if($key != "") $where .= ", '".$key."' "; }
  889. $where .= ") ";
  890. $this->multi_rows = count($this->rids);
  891. }else{
  892. $where = "WHERE ".$this->primary_key." = '".$req_rid."' ";
  893. }
  894. $view_limit = $this->setSqlLimitByDbType("0", $req_page_size);
  895. //$this->sql_sort = ""; we need this sorted for multi-rows editing
  896. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  897. }else if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "1") && ($req_mode == "edit")){
  898. $this->rids = explode("-", $this->rid);
  899. // if we have more that 1 row selected
  900. // mr_1
  901. if(count($this->rids) > 1){
  902. $where = "WHERE ".$this->primary_key." IN ('-1' ";
  903. foreach ($this->rids as $key){ if($key != "") $where .= ", '".$key."' "; }
  904. $where .= ") ";
  905. $this->multi_rows = count($this->rids);
  906. }else{
  907. $where = "WHERE ".$this->primary_key." = '".$req_rid."' ";
  908. }
  909. $view_limit = $this->setSqlLimitByDbType("0", $req_page_size);
  910. //$this->sql_sort = ""; we need this sorted for multi-rows editing
  911. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  912. }else if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "0") && ($req_mode == "details")){
  913. // if we have more that 1 row selected
  914. $this->rids = explode("-", $this->rid);
  915. if(count($this->rids) > 1){
  916. $where = "WHERE ".$this->primary_key." IN ('-1' ";
  917. foreach ($this->rids as $key){ if($key != "") $where .= ", '".$key."' "; }
  918. $where .= ") ";
  919. $this->multi_rows = count($this->rids);
  920. }else{
  921. $where = "WHERE ".$this->primary_key." = '".$req_rid."' ";
  922. }
  923. $view_limit = $this->setSqlLimitByDbType("0", $req_page_size);
  924. $this->sql_sort = "";
  925. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  926. }else if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "0") && ($req_mode == "edit")){
  927. $view_limit = "";
  928. if($this->condition != "") $where = " WHERE ". $this->condition;
  929. else $where = "";
  930. if($req_sort_field != "") $this->sql_sort = " ORDER BY " . $sort_field . " " . $req_sort_type;
  931. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  932. }else{
  933. $view_limit = $this->setSqlLimitByDbType("0", $req_page_size);
  934. $where = "WHERE ".$this->primary_key." = '".$req_rid."' ";
  935. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  936. }
  937. $this->getDataSet($this->sql_sort, $view_limit);
  938. if($req_mode == "edit") $this->mode = "edit";
  939. else $this->mode = "details";
  940. }
  941. // CANCEL mode processing
  942. if($req_mode == "cancel"){
  943. $this->rid = "";
  944. $this->sql = $this->sql_view;
  945. $this->getDataSet($this->sql_sort);
  946. $this->mode = "view";
  947. }
  948. // UPDATE mode processing
  949. if($req_mode == "update"){
  950. $this->rid = $req_rid;
  951. if($req_print != true){
  952. if($req_new != 1){
  953. $this->updateRow($this->rid);
  954. }else{
  955. $this->addRow();
  956. }
  957. }
  958. $this->sql = $this->sql_view;
  959. $this->getDataSet($this->sql_sort);
  960. $this->mode = "view";
  961. }
  962. // ADD mode processing
  963. if($req_mode == "add"){
  964. // we don't need multirow option allowed when we add new record
  965. $this->multirow_allowed = false;
  966. if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "0")){
  967. // we need
  968. $view_limit = "";
  969. if($this->condition != "") $where = " WHERE ". $this->condition;
  970. else $where = "";
  971. $this->sql = "SELECT * FROM $this->tbl_name ".$where;
  972. }else{
  973. $view_limit = "";
  974. $this->sql = "SELECT * FROM $this->tbl_name ";
  975. }
  976. $this->sql_sort = " ORDER BY " . $this->primary_key . " DESC";
  977. $this->getDataSet($this->sql_sort, $view_limit);
  978. $this->rid = -1;
  979. $this->allowSorting(false);
  980. $this->allowPaging(false);
  981. $this->mode = "edit";
  982. }
  983. }else{
  984. // VIEW mode processing
  985. if($req_mode == ""){
  986. $this->getDataSet($this->sql_sort);
  987. $view_limit = $this->setSqlLimitByDbType("0", $req_page_size);
  988. }
  989. if($this->debug == true){
  990. echo "<br /><center><label class='default_class_error_message'>Wrong parameters were passed! Possible Hack attack!</label></center><br />";
  991. }else{
  992. echo "<br /><center><label class='default_class_error_message'>Wrong parameters were passed!</label></center><br />";
  993. }
  994. }
  995. $this->displayErrors();
  996. $this->displayWarnings();
  997. $this->displayDataSent();
  998. if($this->data_set){
  999. if(($this->mode === "edit") || ($this->mode === "add")){
  1000. $this->layout_type = "edit";
  1001. $this->allowHighlighting(false);
  1002. }else if($this->mode === "details"){
  1003. $this->layout_type = "show";
  1004. $this->allowHighlighting(false);
  1005. }else {
  1006. $this->layout_type = "view";
  1007. }
  1008. // sort columns by mode order
  1009. $this->sortColums($this->mode);
  1010. if($this->layouts[$this->layout_type] == "0"){
  1011. $this->drawTabular();
  1012. }else if($this->layouts[$this->layout_type] == "1"){
  1013. $this->drawColumnar();
  1014. }else if($this->layouts[$this->layout_type] == "2"){
  1015. $this->drawCustomized();
  1016. }else{
  1017. $this->drawTabular();
  1018. }
  1019. }
  1020. $this->setCommonJavaScriptEnd();
  1021. // finish calculating running time of a script
  1022. if($this->debug == true){
  1023. $this->end_time = $this->getFormattedMicrotime();
  1024. echo "<br><center><label class='default_class_label'>Total running time: ".round((float)$this->end_time - (float)$this->start_time, 6)." sec.</label></center>";
  1025. }
  1026. }
  1027. //--------------------------------------------------------------------------
  1028. // set encoding
  1029. //--------------------------------------------------------------------------
  1030. function setEncoding($dg_encoding = "", $dg_collation = ""){
  1031. $this->encoding = ($dg_encoding != "") ? $dg_encoding : $this->encoding;
  1032. $this->collation = ($dg_collation != "") ? $dg_collation : $this->collation;
  1033. }
  1034. //--------------------------------------------------------------------------
  1035. // set encoding and collation on database
  1036. //--------------------------------------------------------------------------
  1037. function setEncodingOnDatabase(){
  1038. $sql_variables = array(
  1039. 'character_set_client' =>$this->encoding,
  1040. 'character_set_server' =>$this->encoding,
  1041. 'character_set_results' =>$this->encoding,
  1042. 'character_set_database'=>$this->encoding,
  1043. 'character_set_connection'=>$this->encoding,
  1044. 'collation_server' =>$this->collation,
  1045. 'collation_database' =>$this->collation,
  1046. 'collation_connection' =>$this->collation
  1047. );
  1048. foreach($sql_variables as $var => $value){
  1049. $sql = "SET $var=$value;";
  1050. $this->db_handler->query($sql);
  1051. }
  1052. }
  1053. //--------------------------------------------------------------------------
  1054. // set direction
  1055. //--------------------------------------------------------------------------
  1056. function setDirection($direction = "ltr"){
  1057. $this->direction = $direction;
  1058. }
  1059. //--------------------------------------------------------------------------
  1060. // set layouts
  1061. //--------------------------------------------------------------------------
  1062. function setLayouts($layouts = ""){
  1063. $this->layouts['view'] = (isset($layouts['view'])) ? $layouts['view'] : "0";
  1064. $this->layouts['edit'] = (isset($layouts['edit'])) ? $layouts['edit'] : "0";
  1065. $this->layouts['show'] = (isset($layouts['details'])) ? $layouts['details'] : "1";
  1066. $this->layouts['filter'] = (isset($layouts['filter'])) ? $layouts['filter'] : "0";
  1067. }
  1068. //--------------------------------------------------------------------------
  1069. // set templates for customized layouts
  1070. //--------------------------------------------------------------------------
  1071. function setTemplates($view = "", $add_edit = "", $details = ""){
  1072. $this->templates['view'] = $view;
  1073. $this->templates['edit'] = $add_edit;
  1074. $this->templates['show'] = $details;
  1075. }
  1076. function setPagingSettings($lower=false, $upper=false, $pages_array=false, $default_page_size=""){
  1077. if(($lower == true) || ($lower == "true")){
  1078. if($lower['results']) $this->lower_paging['results'] = $lower['results'];
  1079. if($lower['results_align']) $this->lower_paging['results_align'] = $lower['results_align'];
  1080. if($lower['pages']) $this->lower_paging['pages'] = $lower['pages'];
  1081. if($lower['pages_align']) $this->lower_paging['pages_align'] = $lower['pages_align'];
  1082. if($lower['page_size']) $this->lower_paging['page_size'] = $lower['page_size'];
  1083. if($lower['page_size_align']) $this->lower_paging['page_size_align'] = $lower['page_size_align'];
  1084. }
  1085. if(($upper == true) || ($upper == "true")){
  1086. if($upper['results']) $this->upper_paging['results'] = $upper['results'];
  1087. if($upper['results_align']) $this->upper_paging['results_align'] = $upper['results_align'];
  1088. if($upper['pages']) $this->upper_paging['pages'] = $upper['pages'];
  1089. if($upper['pages_align']) $this->upper_paging['pages_align'] = $upper['pages_align'];
  1090. if($upper['page_size']) $this->upper_paging['page_size'] = $upper['page_size'];
  1091. if($upper['page_size_align']) $this->upper_paging['page_size_align'] = $upper['page_size_align'];
  1092. }
  1093. if($pages_array){
  1094. if(is_array($pages_array) && (count($pages_array) > 0)){
  1095. $first_key = "";
  1096. foreach($pages_array as $key => $val){
  1097. if($first_key == "") {$first_key = $key;};
  1098. if (intval($pages_array[$key]) == 0) $pages_array[$key] = 1;
  1099. }
  1100. $this->pages_array = $pages_array;
  1101. $this->req_page_size = ($pages_array[$first_key] > 0) ? $pages_array[$first_key] : $this->req_page_size;
  1102. }
  1103. }
  1104. if(($default_page_size != "") && ($default_page_size > 0)) { $this->req_page_size = $default_page_size; }
  1105. }
  1106. function allowPrinting ($option = true) { $this->printing_allowed = (($option == true) || ($option == "true")) ? true : false ; }
  1107. function allowExporting ($option = true, $exporting_directory = "") { $this->exporting_allowed = (($option == true) || ($option == "true")) ? true : false ; $this->exporting_directory = $exporting_directory; }
  1108. function allowSorting ($option = true) { $this->sorting_allowed = (($option == true) || ($option == "true")) ? true : false ; }
  1109. function allowFiltering ($option = false, $show_search_type = "true"){
  1110. $this->filtering_allowed = (($option == true) || ($option == "true")) ? true : false ;
  1111. $this->show_search_type = (($show_search_type == true) || ($show_search_type == "true")) ? true : false ;
  1112. }
  1113. function allowPaging($option = true, $rows_numeration = false, $numeration_sign = "N #"){
  1114. $this->paging_allowed = (($option == true) || ($option == "true")) ? true : false ;
  1115. $this->rows_numeration = $rows_numeration;
  1116. $this->numeration_sign = $numeration_sign;
  1117. }
  1118. function allowMultirowOperations($multirow_option = false){
  1119. $this->multirow_allowed = (($multirow_option == true) || ($multirow_option == "true")) ? true : false ;
  1120. }
  1121. //--------------------------------------------------------------------------
  1122. // set multirow operations
  1123. //--------------------------------------------------------------------------
  1124. function setMultirowOperations($multirow_operations = ""){
  1125. if(is_array($multirow_operations)){
  1126. foreach($multirow_operations as $fldName => $fldValue){
  1127. $this->multirow_operations_array[$fldName] = $fldValue;
  1128. }
  1129. }
  1130. }
  1131. //--------------------------------------------------------------------------
  1132. // set fields for filtering
  1133. //--------------------------------------------------------------------------
  1134. function setFieldsFiltering($filter_fields_array = ""){
  1135. $req_selSearchType = $this->getVariable('_ff_selSearchType');
  1136. $req_onSUBMIT_FILTER = $this->getVariable('_ff_onSUBMIT_FILTER');
  1137. if(is_array($filter_fields_array)){
  1138. foreach($filter_fields_array as $fldName => $fldValue){
  1139. $this->filter_fields[$fldName] = $fldValue;
  1140. }
  1141. if($req_onSUBMIT_FILTER != ""){
  1142. $search_type_start = "AND";
  1143. if($req_selSearchType == "0"){
  1144. $search_type = "AND";
  1145. }else{
  1146. $search_type = "OR";
  1147. }
  1148. if(!substr_count(strtolower($this->sql_view), "where") && !substr_count(strtolower($this->sql_view), "having")) $this->sql_view .= " WHERE 1=1 ";
  1149. foreach($filter_fields_array as $fldName => $fldValue){
  1150. $table_field_name = "";
  1151. $fldValue_fields = str_replace(" ", "", $fldValue['field']);
  1152. $fldValue_fields = explode(",", $fldValue_fields);
  1153. foreach($fldValue_fields as $fldValue_field){
  1154. $table_field_name = $fldValue['table']."_".$fldValue_field;
  1155. if(isset($_REQUEST[$this->unique_prefix."_ff_".$table_field_name]) && trim($_REQUEST[$this->unique_prefix."_ff_".$table_field_name]) !== ""){
  1156. $filter_field_operator = $table_field_name."_operator";
  1157. if(isset($fldValue['case_sensitive']) && ($fldValue['case_sensitive'] != true)){
  1158. $fldTableField = $this->getLcaseFooByDbType()."(".(($fldValue['table'] != "") ? $fldValue['table']."." : "" ).$fldValue_field.")";
  1159. $fldTableFieldName = $this->strToLower($_REQUEST[$this->unique_prefix."_ff_".$table_field_name]);
  1160. }else{
  1161. $fldTableField = (($fldValue['table'] != "") ? $fldValue['table']."." : "" ).$fldValue_field;
  1162. $fldTableFieldName = $_REQUEST[$this->unique_prefix."_ff_".$table_field_name];
  1163. }
  1164. if(isset($fldValue['comparison_type']) && (strtolower($fldValue['comparison_type']) == "numeric")){
  1165. $left_geresh ="";
  1166. }else{
  1167. $left_geresh ="'";
  1168. }
  1169. if(isset($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator])){
  1170. if(isset($fldValue['comparison_type']) && (strtolower($fldValue['comparison_type']) == "binary")) $comparison_type = "BINARY";
  1171. else $comparison_type ="";
  1172. if($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator] == "like"){
  1173. $this->sql_view .= " $search_type_start $fldTableField ".$_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator]." ".$comparison_type." '%".$fldTableFieldName."%'";
  1174. }else if($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator] == "like%"){
  1175. $this->sql_view .= " $search_type_start $fldTableField ".substr($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator], 0, 4)." ".$comparison_type." '".$fldTableFieldName."%'";
  1176. }else if($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator] == "%like"){
  1177. $this->sql_view .= " $search_type_start $fldTableField ".substr($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator], 1, 4)." ".$comparison_type." '%".$fldTableFieldName."'";
  1178. }else{
  1179. $this->sql_view .= " $search_type_start $fldTableField ".$_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator]." $left_geresh".$fldTableFieldName."$left_geresh ";
  1180. }
  1181. }else{
  1182. $this->sql_view .= " $search_type_start $fldTableField = $left_geresh".$fldTableFieldName."$left_geresh ";
  1183. }
  1184. if($search_type_start !== $search_type){ $search_type_start = $search_type; }
  1185. }
  1186. }
  1187. }
  1188. $this->dataSource($this->db_handler, $this->sql_view);
  1189. }
  1190. }
  1191. }
  1192. //--------------------------------------------------------------------------
  1193. // set mode add/edit/cancel/delete
  1194. //--------------------------------------------------------------------------
  1195. function setModes($parameters){
  1196. $this->modes = array();
  1197. if(is_array($parameters)){
  1198. foreach($parameters as $modeName => $modeValue){
  1199. $this->modes[$modeName] = $modeValue;
  1200. }
  1201. }
  1202. $this->mode = "view";
  1203. }
  1204. //--------------------------------------------------------------------------
  1205. // set editing table & primary key Id
  1206. //--------------------------------------------------------------------------
  1207. function setTableEdit($tbl_name, $field_name, $condition = ""){
  1208. $this->tbl_name = $tbl_name;
  1209. $this->primary_key = $field_name;
  1210. $this->condition = $condition;
  1211. }
  1212. //--------------------------------------------------------------------------
  1213. // set set Foreign Keys Editing
  1214. //--------------------------------------------------------------------------
  1215. function setForeignKeysEdit($foreign_keys_array = ""){
  1216. if(is_array($foreign_keys_array)){
  1217. foreach($foreign_keys_array as $fldName => $fldValue){
  1218. $this->foreign_keys_array[$fldName] = $fldValue;
  1219. }
  1220. }
  1221. }
  1222. //--------------------------------------------------------------------------
  1223. // set View Mode Table Properties
  1224. //--------------------------------------------------------------------------
  1225. function setViewModeTableProperties($vmt_properties = ""){
  1226. if(is_array($vmt_properties) && (count($vmt_properties) > 0)){
  1227. if(isset($vmt_properties['width'])) $this->tblWidth['view'] = $vmt_properties['width'];
  1228. }
  1229. }
  1230. //--------------------------------------------------------------------------
  1231. // set Add/Edit/Details Mode Table Properties
  1232. //--------------------------------------------------------------------------
  1233. function setEditModeTableProperties($emt_properties = ""){
  1234. if(is_array($emt_properties) && (count($emt_properties) > 0)){
  1235. if(isset($emt_properties['width'])) $this->tblWidth['edit'] = $emt_properties['width'];
  1236. }
  1237. }
  1238. //--------------------------------------------------------------------------
  1239. // set Details Mode Table Properties
  1240. //--------------------------------------------------------------------------
  1241. function setDetailsModeTableProperties($dmt_properties = ""){
  1242. if(is_array($dmt_properties) && (count($dmt_properties) > 0)){
  1243. if(isset($dmt_properties['width'])) $this->tblWidth['details'] = $dmt_properties['width'];
  1244. }
  1245. }
  1246. //--------------------------------------------------------------------------
  1247. // set Columns in View Mode
  1248. //--------------------------------------------------------------------------
  1249. function setColumnsInViewMode($columns = ""){
  1250. unset($this->columns_view_mode);
  1251. if(is_array($columns)){
  1252. foreach($columns as $fldName => $fldValue){
  1253. $this->columns_view_mode[$fldName] = $fldValue;
  1254. }
  1255. }
  1256. }
  1257. //--------------------------------------------------------------------------
  1258. // set Auto-Generated Columns in View Mode
  1259. //--------------------------------------------------------------------------
  1260. function setAutoColumnsInViewMode($auto_columns = ""){
  1261. if(($auto_columns == true) || ($auto_columns == "true")){
  1262. unset($this->columns_view_mode);
  1263. if($this->db_handler->isError($this->data_set) == 1){
  1264. $this->is_error = true;
  1265. $this->addErrors();
  1266. }else{
  1267. $fields = $this->data_set->tableInfo();
  1268. for($ind=0; $ind < $this->data_set->numCols(); $ind++){
  1269. $this->columns_view_mode[$fields[$ind]['name']] =
  1270. array("header" =>$fields[$ind]['name'],
  1271. "type" =>"label",
  1272. "align" =>"left",
  1273. "width" =>"210px",
  1274. "wrap" =>"wrap",
  1275. "tooltip" =>false,
  1276. "text_length"=>"-1",
  1277. "case" =>"normal",
  1278. "summarize" =>false,
  1279. "visible" =>"true"
  1280. );
  1281. }
  1282. }
  1283. }
  1284. }
  1285. //--------------------------------------------------------------------------
  1286. // set Columns in Add/Edit/Details Mode
  1287. //--------------------------------------------------------------------------
  1288. function setColumnsInEditMode($columns = ""){
  1289. unset($this->columns_edit_mode);
  1290. if(is_array($columns)){
  1291. foreach($columns as $fldName => $fldValue){
  1292. $this->columns_edit_mode[$fldName] = $fldValue;
  1293. }
  1294. }
  1295. }
  1296. //--------------------------------------------------------------------------
  1297. // set Auto-Generated Columns in Add/Edit/Details Mode
  1298. //--------------------------------------------------------------------------
  1299. function setAutoColumnsInEditMode($auto_columns = ""){
  1300. if(($auto_columns == true) || ($auto_columns == "true")){
  1301. unset($this->columns_edit_mode);
  1302. $sql = " SELECT * FROM ".$this->tbl_name." ";
  1303. $dSet = $this->db_handler->query($sql);
  1304. if($this->db_handler->isError($this->data_set) == 1){
  1305. $this->is_error = true;
  1306. $this->addErrors();
  1307. }else{
  1308. $fields = $dSet->tableInfo();
  1309. for($ind=0; $ind < $dSet->numCols(); $ind++){
  1310. if($fields[$ind]['name'] != $this->primary_key){
  1311. // get required simbol
  1312. $required_simbol = ($this->isFieldRequired($fields[$ind]['name'])) ? "r" : "s";
  1313. // get field view type & view type
  1314. $type_view = "texbox";
  1315. switch (strtolower($fields[$ind]['type'])){
  1316. case 'int': // int: TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER, BIGINT, TINY, SHORT, LONG, LONGLONG, INT24
  1317. $type_simbol = "i"; break;
  1318. case 'real': // real: FLOAT, DOUBLE, DECIMAL, NUMERIC
  1319. $type_simbol = "f"; break;
  1320. case 'null': // empty: NULL
  1321. $type_simbol = "t"; break;
  1322. case 'string': // string: CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, ENUM, SET, VAR_STRING
  1323. case 'blob': // blob: TINYBLOB, MEDIUMBLOB, LONGBLOB, BLOB, TEXT
  1324. case 'date': // date: DATE
  1325. case 'timestamp': // date: TIMESTAMP
  1326. case 'year': // date: YEAR
  1327. case 'time': // date: TIME
  1328. $type_simbol = "t"; break;
  1329. case 'datetime': // date: DATETIME
  1330. $type_view = "datetime";
  1331. $type_simbol = "t"; break;
  1332. default:
  1333. $type_simbol = "t"; break;
  1334. }
  1335. // get required-type simbols
  1336. $req_type_simbols = $required_simbol."".$type_simbol;
  1337. // get field maxlength
  1338. $field_maxlength = ($fields[$ind]['len'] <= 0) ? "" : $fields[$ind]['len'];
  1339. $this->columns_edit_mode[$fields[$ind]['name']] =
  1340. array("header" =>$fields[$ind]['name'],
  1341. "type" =>"$type_view",
  1342. "req_type" =>"$req_type_simbols",
  1343. "width" =>"210px",
  1344. "maxlength" =>"$field_maxlength",
  1345. "title" =>$fields[$ind]['name'],
  1346. "readonly" =>false,
  1347. "visible" =>"true"
  1348. );
  1349. };
  1350. }
  1351. }
  1352. }
  1353. }
  1354. //--------------------------------------------------------------------------
  1355. // table drawing functions
  1356. //--------------------------------------------------------------------------
  1357. function showCaption() {
  1358. echo ($this->caption != "") ? "<div class='".$this->css_class."_class_caption'>". $this->caption ."</div><br />".chr(13) : "";
  1359. }
  1360. function tblOpen(){
  1361. if($this->scrolling_option == true) {
  1362. $width = ($this->mode == "view") ? "100%" : $this->tblWidth[$this->mode];
  1363. }else{
  1364. $width = $this->tblWidth[$this->mode];
  1365. }
  1366. echo "<table dir='".$this->direction."' class='".$this->css_class."_class_table' align='".$this->tblAlign[$this->mode]."' width='".$width."'>".chr(13);
  1367. echo $this->tbodyOpen();
  1368. }
  1369. function tblClose(){
  1370. echo $this->tbodyClose();
  1371. echo "</table>".chr(13);
  1372. }
  1373. function scrollDivOpen(){
  1374. if($this->scrolling_option == true){
  1375. echo "<center><div style='TEXT-ALIGN:center; PADDING:0px; WIDTH:".$this->scrolling_width."; HEIGHT:".$this->scrolling_height."; overflow:auto;'>";
  1376. echo chr(13);
  1377. }
  1378. }
  1379. function scrollDivClose(){
  1380. if($this->scrolling_option == true){
  1381. echo "</div></center>"; echo chr(13);
  1382. }
  1383. }
  1384. function hideDivOpen(){
  1385. $req_onSUBMIT_FILTER = $this->getVariable('_ff_onSUBMIT_FILTER');
  1386. if(($this->hide_grid_before_serach == true) && !($req_onSUBMIT_FILTER != "")){
  1387. echo "<div style='display: none;'>"; echo chr(13);
  1388. }
  1389. }
  1390. function hideDivClose(){
  1391. $req_onSUBMIT_FILTER = $this->getVariable('_ff_onSUBMIT_FILTER');
  1392. if(($this->hide_grid_before_serach == true) && !($req_onSUBMIT_FILTER != "")){
  1393. echo "</div>"; echo chr(13);
  1394. }
  1395. }
  1396. function theadOpen() { echo "<thead>".chr(13); }
  1397. function theadClose(){ echo "</thead>".chr(13); }
  1398. function tbodyOpen() { echo "<tbody>".chr(13); }
  1399. function tbodyClose(){ echo "</tbody>".chr(13); }
  1400. function tfootOpen() { echo "<tfoot>".chr(13); }
  1401. function tfootClose(){ echo "</tfoot>".chr(13); }
  1402. function rowOpen($id, $rowColor = "", $height=""){
  1403. $req_print = $this->getVariable('print');
  1404. $text = "<tr class='class_tr' bgcolor='$rowColor' id='".$this->unique_prefix."row_".$id."' ";
  1405. if($height != "") { $text .= "height='".$height."' "; };
  1406. if($req_print != true){
  1407. if($this->row_highlighting_allowed){
  1408. $text .= " onclick=\"onMouseClickRow('".$this->unique_prefix."','".$id."','".$this->rowColor[5]."', '".$this->rowColor[1]."', '".$this->rowColor[0]."');\" ";
  1409. $text .= " onmouseover=\"onMouseOverRow('".$this->unique_prefix."','".$id."','".$this->rowColor[4]."', '".$this->rowColor[7]."');\" ";
  1410. $text .= " onmouseout=\"onMouseOutRow('".$this->unique_prefix."','".$id."','".$rowColor."','".$this->rowColor[5]."');\" ";
  1411. }
  1412. }else{
  1413. $text .= " ";
  1414. }
  1415. $text .= ">".chr(13);
  1416. echo $text;
  1417. }
  1418. function rowClose(){
  1419. echo "</tr>".chr(13);
  1420. }
  1421. function mainColOpen($align='left', $colSpan=0, $wrap='', $width='', $class='', $style=''){
  1422. if($class == '') $class = $this->css_class."_class_th";
  1423. $class_align = ($align == "") ? "" : " class_".$align;
  1424. $wrap = ($wrap == '') ? $this->wrap : $wrap;
  1425. $text = "<th class='".$class.$class_align."' ";
  1426. $text .= " bgColor='".$this->rowColor[6]."'";
  1427. $text .= ($this->mode != "edit") ? " onmouseover=\"bgColor='".$this->rowColor[3]."';\" onmouseout=\"bgColor='".$this->rowColor[6]."';\"" : "";
  1428. $text .= ($width !=='')? " width='$width'" : "";
  1429. $text .= ($colSpan != 0) ? " colspan='$colSpan'" : "";
  1430. $text .= ($wrap != '') ? " $wrap" : "";
  1431. $text .= ($style != '') ? " $style" : "";;
  1432. $text .= ">";
  1433. echo $text;
  1434. }
  1435. function mainColClose(){
  1436. echo "</th>".chr(13);
  1437. }
  1438. function colOpen($align='left', $colSpan=0, $wrap='', $bgcolor='', $class_td='', $width=''){
  1439. if($class_td == '') $class_td = $this->css_class."_class_td";
  1440. $req_print = $this->getVariable('print');
  1441. $wrap = ($wrap == '') ? $this->wrap : $wrap;
  1442. $class_align = ($align == "") ? "" : " class_".$align;
  1443. $text = "<td class='".$class_td.$class_align."' ";
  1444. $text .= ($bgcolor !== '')? " bgcolor='$bgcolor'" : "";
  1445. $text .= ($colSpan != 0) ? " colspan='$colSpan'" : "";
  1446. $text .= ($width !=='')? " width='$width'" : "";
  1447. $text .= ($wrap != '') ? " $wrap" : "";
  1448. $text .= ">";
  1449. echo $text;
  1450. }
  1451. function colClose(){
  1452. echo "</td>".chr(13);
  1453. }
  1454. function emptyRow(){
  1455. $this->rowOpen("","");
  1456. $this->colOpen();$this->colClose();
  1457. $this->rowClose();
  1458. }
  1459. //--------------------------------------------------------------------------
  1460. // draw Control Panel
  1461. //--------------------------------------------------------------------------
  1462. function drawControlPanel(){
  1463. $req_print = $this->getVariable('print');
  1464. $req_export = $this->getVariable('export');
  1465. $req_mode = $this->getVariable('mode');
  1466. if($this->filtering_allowed || $this->exporting_allowed || $this->printing_allowed){
  1467. $margin_bottom = ($this->layout_type == "edit") ? "margin-bottom: 7px;" : "margin-bottom: 5px;";
  1468. echo "<table border='0' align='center' id='printTbl' style='margin-left: auto; margin-right: auto; $margin_bottom' width='".$this->tblWidth[$this->mode]."' cellspacing='1' cellpadding='1'>";
  1469. echo "<tr>";
  1470. echo "<td align='left'>";
  1471. if($this->mode == "edit"){
  1472. echo "<label class='".$this->css_class."_class_label'>".$this->lang['required_fields_msg']."</label>";
  1473. }
  1474. echo "</td>";
  1475. if($this->filtering_allowed && (($this->mode != "edit") && ($this->mode != "details"))){
  1476. echo "<td align='right' class='class_nowrap' width='20px'>";
  1477. $hide_display = "";
  1478. $unhide_display = "display: none; ";
  1479. if(isset($_COOKIE[$this->unique_prefix.'hide_search'])) {
  1480. if($_COOKIE[$this->unique_prefix.'hide_search'] == 1){
  1481. $this->hide_display = "display: none;";
  1482. $hide_display = "display: none; ";
  1483. $unhide_display = "";
  1484. }else{
  1485. $this->hide_display = "";
  1486. $hide_display = "";
  1487. $unhide_display = "display: none; ";
  1488. }
  1489. }
  1490. if($req_print != true){
  1491. echo "<a id='".$this->unique_prefix."a_hide' style='cursor:pointer; ".$hide_display."' onClick=\"return hideUnHideFiltering('hide', '".$this->unique_prefix."');\"><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>";
  1492. echo "<a id='".$this->unique_prefix."a_unhide' style='cursor:pointer; ".$unhide_display."' onClick=\"return hideUnHideFiltering('unhide', '".$this->unique_prefix."');\"><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>";
  1493. }
  1494. echo "</td>";
  1495. }
  1496. if($this->exporting_allowed){
  1497. echo "<td align='right' width='20px'>";
  1498. if((($req_export == "") || ($req_print != true)) && ($req_print == "")){
  1499. echo "<a style='cursor:pointer;' onClick=\"myRef=window.open(''+self.location+'".(($_SERVER['QUERY_STRING'] == "")?"?":"&").$this->unique_prefix."export=true&".$this->unique_prefix."export_type=csv','ExportToExcel','left=100,top=100,width=540,height=360,toolbar=0,resizable=0,location=0,scrollbars=1');myRef.focus();\" class='".$this->css_class."_class_a'>";
  1500. 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>";
  1501. echo "</td>";
  1502. echo "<td align='right' width='20px'>";
  1503. echo "<a style='cursor:pointer;' onClick=\"myRef=window.open(''+self.location+'".(($_SERVER['QUERY_STRING'] == "")?"?":"&").$this->unique_prefix."export=true&".$this->unique_prefix."export_type=pdf','ExportToPdf','left=100,top=100,width=540,height=360,toolbar=0,resizable=0,location=0,scrollbars=1');myRef.focus();\" class='".$this->css_class."_class_a'>";
  1504. 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>";
  1505. echo "</td>";
  1506. echo "<td align='right' width='20px'>";
  1507. echo "<a style='cursor:pointer;' onClick=\"myRef=window.open(''+self.location+'".(($_SERVER['QUERY_STRING'] == "")?"?":"&").$this->unique_prefix."export=true&".$this->unique_prefix."export_type=xml','ExportToExcel','left=100,top=100,width=540,height=360,toolbar=0,resizable=0,location=0,scrollbars=1');myRef.focus();\" class='".$this->css_class."_class_a'>";
  1508. 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>";
  1509. }
  1510. echo "</td>";
  1511. }
  1512. if($this->printing_allowed){
  1513. if(($req_export == "") && ($req_print != true)){
  1514. echo "<td align='right' width='20px'><a style='cursor:pointer;' onClick=\"myRef=window.open(''+self.location+'".(($_SERVER['QUERY_STRING'] == "")?"?":"&").$this->unique_prefix."print=true','PrintableView','left=20,top=20,width=840,height=630,toolbar=0,menubar=0,resizable=0,location=0,scrollbars=1');myRef.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>";
  1515. }else{
  1516. 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>";
  1517. }
  1518. }
  1519. if($this->filtering_allowed && ($this->mode == "view") && ($req_mode != "update") && ($req_mode != "delete")){
  1520. echo "<td align='right' 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>";
  1521. }
  1522. echo "</tr>";
  1523. echo "</table>";
  1524. }
  1525. }
  1526. //--------------------------------------------------------------------------
  1527. // Export Dispatcher
  1528. //--------------------------------------------------------------------------
  1529. function exportTo(){
  1530. $req_export = $this->getVariable('export');
  1531. $export_type = $this->getVariable('export_type');
  1532. if($req_export == true){
  1533. if($export_type == "pdf"){
  1534. $this->exportToPdf();
  1535. }else if($export_type == "xml"){
  1536. $this->exportToXml();
  1537. }else{ // csv
  1538. $this->exportToCsv();
  1539. }
  1540. }
  1541. }
  1542. //--------------------------------------------------------------------------
  1543. // Export to CSV (if you change export file name - change file name length in download.php)
  1544. //--------------------------------------------------------------------------
  1545. function exportToCsv(){
  1546. // Let's make sure the we create the file first
  1547. $this->req_page_size = (isset($_REQUEST[$this->unique_prefix.'page_size']))?$_REQUEST[$this->unique_prefix.'page_size']:$this->req_page_size;
  1548. $fe = fopen($this->exporting_directory."export.csv", "w+");
  1549. if($fe){
  1550. $somecontent = "";
  1551. // fields headers
  1552. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  1553. // get current column's index (offset)
  1554. $c = $this->sorted_columns[$c_sorted];
  1555. $field_name = $this->getFieldName($c);
  1556. if($this->canViewField($field_name)){
  1557. $somecontent .= ucfirst($this->getHeaderName($field_name, true));
  1558. if($c_sorted < count($this->sorted_columns) - 1) $somecontent .= ",";
  1559. }
  1560. }
  1561. $somecontent .= "\n";
  1562. // fields data
  1563. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  1564. $row = $this->data_set->fetchRow();
  1565. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  1566. // get current column's index (offset)
  1567. $c = $this->sorted_columns[$c_sorted];
  1568. $field_name = $this->getFieldName($c);
  1569. if($this->canViewField($field_name)){
  1570. $somecontent .= str_replace(",", "",$row[$c]);
  1571. if($c_sorted < count($this->sorted_columns) - 1) $somecontent .= ",";
  1572. }
  1573. }
  1574. $somecontent .= "\n";
  1575. }
  1576. // write some content to the opened file.
  1577. if (fwrite($fe, $somecontent) == FALSE) {
  1578. echo $this->lang['file_writing_error']." (export.csv)";
  1579. exit;
  1580. }
  1581. fclose($fe);
  1582. echo $this->exportDownloadFile("export.csv");
  1583. }else{
  1584. echo "<label class='".$this->css_class."_class_error_message no_print'>".$this->lang['file_opening_error']."</lable>";
  1585. exit;
  1586. }
  1587. }
  1588. //---------------------------------------------------
  1589. // Export to PDF (if you change export file name - change file name length in download.php)
  1590. //---------------------------------------------------
  1591. function exportToPdf($type = "tabular") {
  1592. // Let's make sure the we create the file first
  1593. $this->req_page_size = (isset($_REQUEST[$this->unique_prefix.'page_size']))?$_REQUEST[$this->unique_prefix.'page_size']:$this->req_page_size;
  1594. $newcontent = array();
  1595. $somecontent = "";
  1596. // fields headers
  1597. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  1598. // get current column's index (offset)
  1599. $c = $this->sorted_columns[$c_sorted];
  1600. $field_name = $this->getFieldName($c);
  1601. if($this->canViewField($field_name)){
  1602. $somecontent .= ucfirst($this->getHeaderName($field_name, true));
  1603. if($c_sorted < count($this->sorted_columns) - 1) $somecontent .= "\t";
  1604. }
  1605. }
  1606. $newcontent[] = $somecontent;
  1607. $somecontent = "";
  1608. // fields data
  1609. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  1610. $row = $this->data_set->fetchRow();
  1611. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  1612. // get current column's index (offset)
  1613. $c = $this->sorted_columns[$c_sorted];
  1614. $field_name = $this->getFieldName($c);
  1615. if($this->canViewField($field_name)){
  1616. $somecontent .= str_replace("\t", "",$row[$c]);
  1617. if($c_sorted < count($this->sorted_columns) - 1) $somecontent .= "\t";
  1618. }
  1619. }
  1620. $somecontent .= "\n";
  1621. $newcontent[] = $somecontent;
  1622. $somecontent = "";
  1623. }
  1624. // write some content to the opened file.
  1625. define('FPDF_FONTPATH', $this->directory.'modules/fpdf/font/');
  1626. include_once($this->directory.'modules/fpdf/fpdf.php');
  1627. $pdf=new FPDF();
  1628. $pdf->AddPage();
  1629. $pdf->SetFont('Arial','B',16);
  1630. for($i=0;$i<=count($newcontent);$i++) {
  1631. $pdf->Text(10,($i*10)+10,$newcontent[$i]);
  1632. }
  1633. $output_path = ($this->exporting_directory != "") ? $this->exporting_directory : $this->directory;
  1634. $pdf->Output($output_path."export.pdf", "");
  1635. echo $this->exportDownloadFile("export.pdf");
  1636. }
  1637. //--------------------------------------------------------------------------
  1638. // Export to XML (if you change export file name - change file name length in download.php)
  1639. //--------------------------------------------------------------------------
  1640. function exportToXml(){
  1641. // Let's make sure the we create the file first
  1642. $this->req_page_size = (isset($_REQUEST[$this->unique_prefix.'page_size']))?$_REQUEST[$this->unique_prefix.'page_size']:$this->req_page_size;
  1643. $fe = fopen($this->exporting_directory."export.xml", "w+");
  1644. if($fe){
  1645. $somecontent = "<?xml version='1.0' encoding='UTF-8' ?>";
  1646. // fields data
  1647. $somecontent .= "<page>";
  1648. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  1649. $row = $this->data_set->fetchRow();
  1650. $somecontent .= "<row".$r.">";
  1651. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  1652. // get current column's index (offset)
  1653. $c = $this->sorted_columns[$c_sorted];
  1654. $field_name = $this->getFieldName($c);
  1655. if($this->canViewField($field_name)){
  1656. $header_name = $field_name;
  1657. $somecontent .= "<".$header_name.">";
  1658. $somecontent .= $row[$c];
  1659. $somecontent .= "</".$header_name.">";
  1660. }
  1661. }
  1662. $somecontent .= "</row".$r.">";
  1663. }
  1664. $somecontent .= "</page>";
  1665. // write somecontent to the opened file.
  1666. if (fwrite($fe, $somecontent) == FALSE) {
  1667. echo $this->lang['file_writing_error']." (export.xml)";
  1668. exit;
  1669. }
  1670. fclose($fe);
  1671. echo $this->exportDownloadFile("export.xml");
  1672. }else{
  1673. echo "<label class='".$this->css_class."_class_error_message no_print'>".$this->lang['file_opening_error']."</lable>";
  1674. exit;
  1675. }
  1676. }
  1677. //--------------------------------------------------------------------------
  1678. // draw filtering
  1679. //--------------------------------------------------------------------------
  1680. function drawFiltering(){
  1681. $req_print = $this->getVariable('print');
  1682. $selSearchType = $this->getVariable("_ff_selSearchType");
  1683. $req_onSUBMIT_FILTER = $this->getVariable('_ff_onSUBMIT_FILTER');
  1684. $cols = 0;
  1685. if($this->filtering_allowed){
  1686. echo "<table id='".$this->unique_prefix."searchset' style='".$this->hide_display."' width='".(($this->browser_name == "Firefox") ? "98%" : "100%" )."' align='center'><tr><td align='center'>\n";
  1687. if($req_print != true){
  1688. echo "<fieldset class='".$this->css_class."_class_fieldset' dir='".$this->direction."' align='".$this->tblAlign[$this->mode]."' style='WIDTH: ".$this->tblWidth['view']."'>\n";
  1689. echo "<legend class='".$this->css_class."_class_legend'>".$this->lang['search_d']."</legend>\n";
  1690. }
  1691. echo "<form name='frmFiltering".$this->unique_prefix."' id='frmFiltering".$this->unique_prefix."' action='' method='get' style='MARGIN: 10px;'>\n";
  1692. $this->saveHttpGetVars();
  1693. echo "<table class='".$this->css_class."_class_filter_table' border='0' id='filterTbl".$this->unique_prefix."' style='margin-left: auto; margin-right: auto;' width='".$this->tblWidth[$this->mode]."' cellspacing='1' cellpadding='1'>\n";
  1694. if($this->layouts['filter'] == "0") echo "<tr>\n";
  1695. foreach($this->filter_fields as $fldName => $fldValue){
  1696. $cols = 0;
  1697. if($this->layouts['filter'] == "1") echo "<tr valign='middle'>\n";
  1698. $fldValue_fields = explode(",", $fldValue['field']);
  1699. $table_field_name = "".$fldValue['table']."_".$fldValue_fields[0];///del $fldValue['field'];
  1700. if(isset($_REQUEST[$this->unique_prefix."_ff_".$table_field_name]) AND ($_REQUEST[$this->unique_prefix."_ff_".$table_field_name] != "")){
  1701. $filter_field_value = $_REQUEST[$this->unique_prefix."_ff_".$table_field_name];
  1702. }else{
  1703. $filter_field_value = "";
  1704. }
  1705. $filter_field_operator = $table_field_name."_operator";
  1706. echo "<td align='";
  1707. if($this->layouts['filter'] == "1"){
  1708. echo ($this->direction == "rtl")?"left":"right"; echo "' width='50%'>".$fldName."";
  1709. echo "</td><td>".$this->nbsp."</td><td>";
  1710. $cols +=3;
  1711. }else if($this->layouts['filter'] == "0"){
  1712. echo ($this->direction == "rtl")?"center":"center"; echo "' >".$fldName."";
  1713. echo " ";
  1714. }else {
  1715. echo ($this->direction == "rtl")?"left":"right"; echo "' width='50%'>".$fldName."";
  1716. echo "</td>";
  1717. echo "<td>".$this->nbsp."</td>";
  1718. echo "<td>";
  1719. $cols +=2;
  1720. }
  1721. if(isset($fldValue['show_operator']) && $fldValue['show_operator'] != false){
  1722. if($req_print != true){
  1723. if(isset($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator]) && $_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator] != ""){
  1724. $filter_operator = $_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator];
  1725. }else if(isset($fldValue['default_operator']) && $fldValue['default_operator'] != ""){
  1726. $filter_operator = $fldValue['default_operator'];
  1727. }else{
  1728. $filter_operator = "=";
  1729. }
  1730. echo "<select class='".$this->css_class."_class_select' name='".$this->unique_prefix."_ff_".$filter_field_operator."' id='".$this->unique_prefix."_ff_".$filter_field_operator."'>";
  1731. echo "<option value='='"; echo ($filter_operator == "=")? "selected" : ""; echo ">".$this->lang['=']."</option>";
  1732. echo "<option value='&gt;'"; echo ($filter_operator == ">")? "selected" : ""; echo ">".$this->lang['>']."</option>";
  1733. echo "<option value='&lt;'"; echo ($filter_operator == "<")? "selected" : ""; echo ">".$this->lang['<']."</option>";
  1734. echo "<option value='like'"; echo ($filter_operator == "like")? "selected" : ""; echo ">".$this->lang['like']."</option>";
  1735. echo "<option value='like%'"; echo ($filter_operator == "like%")? "selected" : ""; echo ">".$this->lang['like%']."</option>";
  1736. echo "<option value='%like'"; echo ($filter_operator == "%like")? "selected" : ""; echo ">".$this->lang['%like']."</option>";
  1737. echo "<option value='not like'"; echo ($filter_operator == "not like")? "selected" : ""; echo ">".$this->lang['not_like']."</option>";
  1738. echo "</select>";
  1739. }else{
  1740. echo (isset($_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator])) ? "[".$_REQUEST[$this->unique_prefix."_ff_".$filter_field_operator]."]" : "";
  1741. }
  1742. }else{
  1743. // set default operator
  1744. if(isset($fldValue['default_operator']) && $fldValue['default_operator'] != ""){
  1745. echo "<input type='hidden' name='".$this->unique_prefix."_ff_".$filter_field_operator."' id='".$this->unique_prefix."_ff_".$filter_field_operator."' value='".$fldValue['default_operator']."'>";
  1746. $filter_operator = $fldValue['default_operator'];
  1747. }else{
  1748. echo "<input type='hidden' name='".$this->unique_prefix."_ff_".$filter_field_operator."' id='".$this->unique_prefix."_ff_".$filter_field_operator."' value='='>";
  1749. $filter_operator = "=";
  1750. }
  1751. }
  1752. if($this->layouts['filter'] == "1"){
  1753. echo "</td>\n<td>".$this->nbsp."</td>\n";
  1754. echo "<td width='50%' align='"; echo ($this->direction == "rtl")?"right":"left"; echo "'>";
  1755. $cols +=2;
  1756. }else if($this->layouts['filter'] == "0"){
  1757. echo "<br />";
  1758. }else {
  1759. echo "</td>\n<td>".$this->nbsp."</td>\n";
  1760. echo "<td width='50%' align='"; echo ($this->direction == "rtl")?"right":"left"; echo "'>";
  1761. $cols +=2;
  1762. }
  1763. $filter_field_type = (isset($fldValue['type'])) ? $fldValue['type'] : "" ;
  1764. if($req_print != true){
  1765. switch($filter_field_type){
  1766. case "textbox":
  1767. $fldValue_fields = str_replace(" ", "", $fldValue['field']);
  1768. $fldValue_fields = explode(",", $fldValue_fields);
  1769. $count = 0;
  1770. $onchange_filter_field = "";
  1771. foreach($fldValue_fields as $fldValue_field){
  1772. if($count++ > 0){ $onchange_filter_field .= "document.getElementById(\"".$this->unique_prefix."_ff_".$fldValue['table']."_".$fldValue_field."\").value="; }
  1773. }
  1774. $count = 0;
  1775. foreach($fldValue_fields as $fldValue_field){
  1776. if($count++ == 0){
  1777. echo "\n<input class='".$this->css_class."_class_textbox' type='text' value='".$filter_field_value."' name='".$this->unique_prefix."_ff_".$fldValue['table']."_".$fldValue_field."' id='".$this->unique_prefix."_ff_".$fldValue['table']."_".$fldValue_field."' onchange='".$onchange_filter_field."this.value;' />";
  1778. }else{
  1779. $filter_field_operator = $fldValue['table']."_".$fldValue_field."_operator";
  1780. echo "\n<input type='hidden' name='".$this->unique_prefix."_ff_".$fldValue['table']."_".$fldValue_field."' id='".$this->unique_prefix."_ff_".$fldValue['table']."_".$fldValue_field."' value='".$filter_field_value."' />";
  1781. echo "\n<input type='hidden' name='".$this->unique_prefix."_ff_".$filter_field_operator."' id='".$this->unique_prefix."_ff_".$filter_field_operator."' value='".$filter_operator."'>";
  1782. }
  1783. }
  1784. break;
  1785. case "dropdownlist":
  1786. echo "<select class='".$this->css_class."_class_select' name='".$this->unique_prefix."_ff_".$fldValue['table']."_".$fldValue['field']."' id='".$this->unique_prefix."_ff_".$fldValue['table']."_".$fldValue['field']."'>";
  1787. echo "<option value=''>-- ".$this->lang['any']." --</option>";
  1788. if(is_array($fldValue['source'])){
  1789. foreach($fldValue['source'] as $val => $opt){
  1790. echo "<option value='".$val."' ";
  1791. if($filter_field_value == $val) echo "selected";
  1792. echo ">".$opt."</option>";
  1793. }
  1794. }else{
  1795. $sql = "SELECT DISTINCT ".$fldValue['field']." FROM ".$fldValue['table']." ORDER BY ".$fldValue['field']." ".(($this->strToLower((isset($fldValue['order']) ? $fldValue['order'] : "")) == "desc")?"DESC":"ASC")." ;";
  1796. $this->db_handler->setFetchMode(DB_FETCHMODE_ASSOC);
  1797. $dSet = $this->db_handler->query($sql);
  1798. while($row = $dSet->fetchRow()){
  1799. if($row[$fldValue['field']] === $filter_field_value)
  1800. echo "<option selected value='".$row[$fldValue['field']]."'>".$row[$fldValue['field']]."</option>";
  1801. else
  1802. echo "<option value='".$row[$fldValue['field']]."'>".$row[$fldValue['field']]."</option>";
  1803. }
  1804. }
  1805. echo "</select>";
  1806. break;
  1807. default:
  1808. echo "\n<input class='".$this->css_class."_class_textbox' type='text' value='".$filter_field_value."' name='".$this->unique_prefix."_ff_".$fldValue['table']."_".$fldValue['field']."' id='".$this->unique_prefix."_ff_".$fldValue['table']."_".$fldValue['field']."' />";
  1809. break;
  1810. }
  1811. }else{
  1812. echo $filter_field_value;
  1813. }
  1814. echo "</td>\n";
  1815. //value='$_POST[$fldValue]'
  1816. if($this->layouts['filter'] == "1") echo "</tr>\n";
  1817. }
  1818. if($this->layouts['filter'] == "0") echo "</tr>\n";
  1819. echo "<tr><td ".(($cols > 0) ? "colspan='".$cols."'" : "")." height='6px' align='center'></td></tr>\n";
  1820. echo "<tr><td ".(($cols > 0) ? "colspan='".$cols."'" : "")." align='center'>";
  1821. if(count($this->filter_fields) > 1){
  1822. if($this->show_search_type){ echo $this->lang['search_type'].":&nbsp;&nbsp;"; }
  1823. if($req_print != true){
  1824. if($this->show_search_type){
  1825. echo "<select class='".$this->css_class."_class_select' name='".$this->unique_prefix."_ff_"."selSearchType' id='".$this->unique_prefix."_ff_"."selSearchType'>";
  1826. echo "<option value='0' "; echo (($selSearchType != "") && ($selSearchType == 0)) ? "selected" : ""; echo ">".$this->lang['and']."</option>";
  1827. echo "<option value='1' "; echo ($selSearchType == 1) ? "selected" : ""; echo ">".$this->lang['or']."</option>";
  1828. echo "</select>&nbsp;&nbsp;&nbsp;";
  1829. }else{
  1830. echo "<input type='hidden' name='".$this->unique_prefix."_ff_"."selSearchType' id='".$this->unique_prefix."_ff_"."selSearchType' value='0' />";
  1831. }
  1832. }else{
  1833. if(($selSearchType != "") && ($selSearchType == 0)){
  1834. echo "[and]";
  1835. }else if($selSearchType == 1){
  1836. echo "[or]";
  1837. }else {
  1838. echo "[none]";
  1839. }
  1840. }
  1841. }
  1842. if($req_print != true){
  1843. if($req_onSUBMIT_FILTER != ""){
  1844. $curr_url = $this->combineUrl("view", "", "&");
  1845. $this->setUrlString($curr_url, "", "sorting", "paging");
  1846. echo "<input class='".$this->css_class."_class_button' type='button' value='".$this->lang['reset']."' onClick='document.location.href=\"".$this->HTTP_URL.$curr_url."\"'>&nbsp;";
  1847. }
  1848. echo "<input class='".$this->css_class."_class_button' type='submit' name='".$this->unique_prefix."_ff_"."onSUBMIT_FILTER' id='".$this->unique_prefix."_ff_"."onSUBMIT_FILTER' value='".$this->lang['search']."'>";
  1849. }
  1850. echo "</td></tr>\n";
  1851. $this->tblClose();
  1852. echo "</form>\n";
  1853. if($req_print != true){
  1854. echo "</fieldset>\n";
  1855. }
  1856. echo "</td></tr></table>\n";
  1857. }
  1858. }
  1859. //--------------------------------------------------------------------------
  1860. // draw in customized layout
  1861. //--------------------------------------------------------------------------
  1862. function drawCustomized(){
  1863. $req_print = $this->getVariable('print');
  1864. $req_mode = $this->getVariable('mode');
  1865. $this->writeCssClass();
  1866. $this->exportTo();
  1867. $this->showCaption($this->caption);
  1868. $this->drawControlPanel();
  1869. if(($this->mode != "edit") && ($this->mode != "details")) $this->drawFiltering();
  1870. if(($req_mode !== "add") || ($req_mode == "")) $this->pagingFirstPart();
  1871. $this->displayMessages();
  1872. if($this->paging_allowed) $this->pagingSecondPart($this->upper_paging, false, true, "Upper");
  1873. if($this->row_lower == $this->row_upper) echo "<br />";
  1874. 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' /></table></div>";
  1875. // draw hide DG open div
  1876. $this->hideDivOpen();
  1877. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  1878. // draw column data
  1879. $row = $this->data_set->fetchRow();
  1880. $template = $this->templates[$this->layout_type];
  1881. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  1882. // get current column's index (offset)
  1883. $c = $this->sorted_columns[$c_sorted];
  1884. if($this->isForeignKey($this->getFieldName($c))){
  1885. $template = str_replace("{".$this->getFieldName($c)."}", $this->getForeignKeyInput($row[$this->getFieldOffset($this->primary_key)], $this->getFieldName($c), $row[$c], "view"), $template);
  1886. }else{
  1887. $template = str_replace("{".$this->getFieldName($c)."}", $this->getFieldValueByType($row[$c], $c, $row), $template);
  1888. }
  1889. }
  1890. echo $template;
  1891. }
  1892. // draw empty table
  1893. if($r == $this->row_lower){ $this->noDataFound(); }
  1894. $this->scrollDivClose();
  1895. if($this->paging_allowed) $this->pagingSecondPart($this->lower_paging, true, true, "Lower");
  1896. // draw hide DG close div
  1897. $this->hideDivClose();
  1898. echo "<script>document.getElementById('".$this->unique_random_prefix."loading_image').style.display='none';</script>";
  1899. }
  1900. //--------------------------------------------------------------------------
  1901. // draw in tabular layout
  1902. //--------------------------------------------------------------------------
  1903. function drawTabular(){
  1904. $req_print = $this->getVariable('print');
  1905. $req_mode = $this->getVariable('mode');
  1906. $this->writeCssClass();
  1907. $this->exportTo();
  1908. $this->showCaption($this->caption);
  1909. $this->drawControlPanel();
  1910. if($this->mode != "edit") $this->drawFiltering();
  1911. if(($req_mode !== "add") || ($req_mode == "")) $this->pagingFirstPart();
  1912. $this->displayMessages();
  1913. if($this->paging_allowed) $this->pagingSecondPart($this->upper_paging, false, true, "Upper");
  1914. if($this->row_lower == $this->row_upper) echo "<br />";
  1915. //prepare summarize columns array
  1916. foreach ($this->columns_view_mode as $key => $val){
  1917. if(isset($val['summarize']) && ($val['summarize'] === true)){
  1918. $this->summarize_columns[$key] = 0;
  1919. }
  1920. }
  1921. 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' /></table></div>";
  1922. // draw hide DG open div
  1923. $this->hideDivOpen();
  1924. // draw add link-button cell
  1925. if(isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode] && $this->draw_add_button_separately){
  1926. echo "<table dir='".$this->direction."' border='0' align='".$this->tblAlign[$this->mode]."' width='".$this->tblWidth[$this->mode]."'>";
  1927. echo "<tr>";
  1928. echo "<td align='".(($this->direction == "ltr") ? "left" : "right")."'><b>";
  1929. $curr_url = $this->combineUrl("add", "-1");
  1930. $this->setUrlString($curr_url, "filtering", "sorting", "paging");
  1931. $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, "", "");
  1932. echo "</b></td>";
  1933. echo "</tr>";
  1934. echo "</table>";
  1935. $this->modes['add'][$this->mode] = false;
  1936. }
  1937. $this->scrollDivOpen();
  1938. $this->tblOpen();
  1939. // *** START DRAWING HEADERS -------------------------------------------
  1940. $this->rowOpen("");
  1941. // draw multi-row checkboxes header
  1942. if(($this->multirow_allowed) && ($this->rows_total > 0)){
  1943. $this->colOpen("center",0,"nowrap",$this->rowColor[0], $this->css_class."_class_td", "26px");
  1944. echo $this->nbsp;
  1945. $this->colClose();
  1946. }
  1947. // draw add link-button cell
  1948. if(isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode]){
  1949. $curr_url = $this->combineUrl("add", "-1");
  1950. $this->setUrlString($curr_url, "filtering", "sorting", "paging");
  1951. $this->mainColOpen("center",0,"nowrap", "1%", $this->css_class."_class_th_normal");
  1952. $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, "", "");
  1953. $this->mainColClose();
  1954. }else{
  1955. if(isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]){
  1956. $this->mainColOpen("center",0,"nowrap", "1%", $this->css_class."_class_th_normal"); echo $this->nbsp; $this->mainColClose();
  1957. }
  1958. }
  1959. if(($this->rows_numeration)){
  1960. $this->mainColOpen("center",0,"nowrap", ""); echo $this->numeration_sign; $this->mainColClose();
  1961. }
  1962. // draw column headers in add mode
  1963. if(($this->rid == -1) && ($req_mode == "add")){
  1964. foreach($this->columns_edit_mode as $key => $val){
  1965. if($this->getFieldProperty($key, "type") != "hidden"){
  1966. $this->mainColOpen("center",0);
  1967. echo "<b>".ucfirst($this->getHeaderName($key))."</b>";
  1968. $this->mainColClose();
  1969. }
  1970. }
  1971. }else{
  1972. $req_sort_field = $this->getVariable('sort_field');
  1973. $req_sort_field_by = $this->getVariable('sort_field_by');
  1974. $req_sort_type = $this->getVariable('sort_type');
  1975. if($req_sort_field){
  1976. $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" ;
  1977. $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" ;
  1978. $sort_alt = (strtolower($req_sort_type) == "desc") ? $this->lang['descending'] : $this->lang['ascending'] ;
  1979. }
  1980. if($this->mode === "view"){
  1981. // draw column headers in view mode
  1982. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  1983. // get current column's index (offset)
  1984. $c = $this->sorted_columns[$c_sorted];
  1985. $field_name = $this->getFieldName($c);
  1986. $field_property_sort_by = $this->getFieldProperty($field_name, "sort_by", "view");
  1987. if($field_property_sort_by != ""){
  1988. $sort_field_by = ($this->getFieldOffset($field_property_sort_by)+1);
  1989. } else {
  1990. $sort_field_by = "";
  1991. };
  1992. if($this->canViewField($field_name)){
  1993. $field_property_wrap = $this->getFieldProperty($field_name, "wrap", "view", "lower", $this->wrap);
  1994. $field_property_width = $this->getFieldProperty($field_name, "width", "view");
  1995. 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" ;};
  1996. $this->mainColOpen("center", 0, $field_property_wrap, $field_property_width, $th_css_class);
  1997. if($this->sorting_allowed){
  1998. $href_string = $this->combineUrl("view");
  1999. $this->setUrlString($href_string, "filtering", "", "paging");
  2000. if(isset($_REQUEST[$this->unique_prefix.'sort_type']) && $_REQUEST[$this->unique_prefix.'sort_type'] == "asc") $sort_type="desc";
  2001. else $sort_type="asc";
  2002. if($req_print != true){
  2003. $href_string .= $this->amp.$this->unique_prefix."sort_field=".($c+1).$this->amp.$this->unique_prefix."sort_field_by=".$sort_field_by.$this->amp.$this->unique_prefix."sort_type=";
  2004. // prepare sorting order by field's type
  2005. if($req_sort_field && ($c == ($req_sort_field -1))){
  2006. $href_string .= $sort_type;
  2007. }else{
  2008. if($this->isDate($field_name)){ $href_string .= "desc"; }
  2009. else{ $href_string .= "asc"; }
  2010. }
  2011. echo "<nobr><b><a class='".$this->css_class."_class_a' href='$href_string' title='".$this->lang['sort']."' ";
  2012. if($req_sort_field && ($c == ($req_sort_field -1))){
  2013. echo "onmouseover=\"if(document.getElementById('soimg".$c."')){ document.getElementById('soimg".$c."').src='".$sort_img_back."'; }\" ";
  2014. echo "onmouseout=\"if(document.getElementById('soimg".$c."')){ document.getElementById('soimg".$c."').src='".$sort_img."'; }\" ";
  2015. }
  2016. echo ">".ucfirst($this->getHeaderName($field_name))." ";
  2017. if($req_sort_field && ($c == ($req_sort_field -1))){
  2018. echo $this->nbsp."<img id='soimg".$c."' src='".$sort_img."' alt='".$sort_alt."' title='".$sort_alt."' border='0'>".$this->nbsp;
  2019. }
  2020. echo "</a></b></nobr>";
  2021. }else{
  2022. echo "<b>".ucfirst($this->getHeaderName($field_name))."</b>";
  2023. }
  2024. }else{
  2025. echo "<b>".ucfirst($this->getHeaderName($field_name))."</b>";
  2026. }
  2027. $this->mainColClose();
  2028. }
  2029. }//for
  2030. }else if($this->mode === "edit"){
  2031. foreach($this->columns_edit_mode as $key => $val){
  2032. if($this->getFieldProperty($key, "type") != "hidden"){
  2033. $this->mainColOpen("center",0);
  2034. // alow/disable sorting by headers
  2035. echo "<b>".ucfirst($this->getHeaderName($key))."</b>";
  2036. $this->mainColClose();
  2037. }
  2038. }
  2039. }
  2040. }
  2041. if(isset($this->modes['details'][$this->mode]) && $this->modes['details'][$this->mode]){
  2042. $this->mainColOpen("center",0,"nowrap", "10%", $this->css_class."_class_th_normal");echo $this->lang['view'];$this->mainColClose();
  2043. }
  2044. if(isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode]){
  2045. $this->mainColOpen("center",0,"nowrap", "10%", $this->css_class."_class_th_normal");echo $this->lang['delete'];$this->mainColClose();
  2046. }
  2047. $this->rowClose();
  2048. // *** END HEADERS -----------------------------------------------------
  2049. //if we add a new row on linked tabular view mode table (mode 0 <-> 0)
  2050. $quick_exit = false;
  2051. if((isset($_REQUEST[$this->unique_prefix.'mode']) && ($_REQUEST[$this->unique_prefix.'mode'] == "add")) && ($this->row_lower == 0) && ($this->row_upper == 0)){
  2052. $this->row_upper = 1;
  2053. $quick_exit = true;
  2054. }
  2055. // *** START DRAWING ROWS ----------------------------------------------
  2056. $first_field_name = "";
  2057. $curr_url = "";
  2058. $c_curr_url = "";
  2059. for($r = $this->row_lower; (($r >=0 && $this->row_upper >=0) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  2060. // add new row (ADD MODE)
  2061. if(($r == $this->row_lower) && ($this->rid == -1) && ($req_mode == "add")){
  2062. if($r % 2 == 0){$this->rowOpen($r, $this->rowColor[0]); $main_td_color=$this->rowColor[2];}
  2063. else {$this->rowOpen($r, $this->rowColor[1]); $main_td_color=$this->rowColor[3];}
  2064. $curr_url = $this->combineUrl("update", -1, $this->amp);
  2065. $this->setUrlString($c_curr_url, "filtering", "sorting", "paging", $this->amp);
  2066. $curr_url .= $c_curr_url;
  2067. $curr_url .= $this->amp.$this->unique_prefix."new=1";
  2068. echo "<form name='".$this->unique_prefix."frmEditRow' id='".$this->unique_prefix."frmEditRow' method='post' action='".$curr_url."'>\n";
  2069. $this->setEditFieldsFormScript($curr_url);
  2070. // draw multi-row empty cell
  2071. 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();}
  2072. $this->colOpen("center",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2073. $this->drawModeButton("edit", "#", $this->lang['create'], $this->lang['create_new_record'], "update.gif", "\"".$this->unique_prefix."sendEditFields(); return false;\"", false, "&nbsp", "");
  2074. $cancel_url = $this->combineUrl("cancel", -1);
  2075. $this->setUrlString($cancel_url, "filtering", "sorting", "paging");
  2076. $cancel_url .= $this->amp.$this->unique_prefix."new=1";
  2077. $this->drawModeButton("cancel", $cancel_url, $this->lang['cancel'], $this->lang['cancel'], "cancel.gif", "\"return ".$this->unique_prefix."verifyCancel('".$cancel_url."'); javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, $this->nbsp, "");
  2078. $this->colClose();
  2079. foreach($this->columns_edit_mode as $key => $val){
  2080. if($this->getFieldProperty($key, "type") != "hidden"){
  2081. $this->colOpen("left",0,"nowrap");
  2082. if($this->isForeignKey($key)){
  2083. echo $this->nbsp.$this->getForeignKeyInput(-1, $key, '-1', "edit").$this->nbsp;
  2084. }else{
  2085. echo $this->getFieldValueByType('', 0, '', $key);
  2086. }
  2087. $this->colClose();
  2088. }else{
  2089. echo $this->getFieldValueByType('', 0, '', $key);
  2090. }
  2091. }
  2092. if(isset($this->modes['delete']) && $this->modes['delete'][$this->mode]) $this->colOpen("center",0,"nowrap");echo"";$this->colClose();
  2093. echo "</form>";
  2094. $this->rowClose();
  2095. }
  2096. //if we add a new row on linked tabular view mode table (mode 0 <-> 0)
  2097. if($quick_exit == true){
  2098. $this->tblClose();
  2099. echo "<script>document.getElementById('".$this->unique_random_prefix."loading_image').style.display='none';</script>";
  2100. if(($this->first_field_focus_allowed) && ($first_field_name != "")) echo "<script type='text/javascript'>\n<!--\n document.".$this->unique_prefix."frmEditRow.".$this->getFieldRequiredType($first_field_name).$first_field_name.".focus(); \n//-->\n</script>";
  2101. return;
  2102. }
  2103. $row = $this->data_set->fetchRow();
  2104. if($r % 2 == 0){$this->rowOpen($r, $this->rowColor[0]); $main_td_color=$this->rowColor[2];}
  2105. else {$this->rowOpen($r, $this->rowColor[1]); $main_td_color=$this->rowColor[3];}
  2106. // draw multi-row row checkboxes
  2107. if($this->multirow_allowed){
  2108. $this->colOpen("center",0,"nowrap","","");
  2109. if($req_print == true){
  2110. $disable = "disabled";
  2111. }else{
  2112. $disable = "";
  2113. }
  2114. echo "<input onclick=\"onMouseClickRow('".$this->unique_prefix."','".$r."', '".$this->rowColor[5]."', '".$this->rowColor[1]."', '".$this->rowColor[0]."')\" type='checkbox' name='".$this->unique_prefix."checkbox_".$r."' id='".$this->unique_prefix."checkbox_".$r."' value='";
  2115. echo ($row[$this->getFieldOffset($this->primary_key)] != -1) ? $row[$this->getFieldOffset($this->primary_key)] : "0" ;
  2116. echo "' ".$disable."/>";
  2117. $this->colClose();
  2118. }
  2119. // draw mode buttons
  2120. if(isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]){
  2121. if(($this->mode == "edit") && (intval($this->rid) == intval($row[$this->getFieldOffset($this->primary_key)]))){
  2122. $curr_url = $this->combineUrl("update", $row[$this->getFieldOffset($this->primary_key)], $this->amp);
  2123. $cancel_url = $this->combineUrl("cancel", $row[$this->getFieldOffset($this->primary_key)]);
  2124. $this->setUrlString($c_curr_url, "filtering", "sorting", "paging", $this->amp);
  2125. $curr_url .= $c_curr_url;
  2126. $cancel_url .= $c_curr_url;
  2127. if(isset($_REQUEST[$this->unique_prefix.'mode']) && $_REQUEST[$this->unique_prefix.'mode'] === "add") { $curr_url .= $this->amp.$this->unique_prefix."new=1"; $cancel_url .= $this->amp.$this->unique_prefix."new=1";}
  2128. echo "<form name='".$this->unique_prefix."frmEditRow' id='".$this->unique_prefix."frmEditRow' method='post' action='".$curr_url."'>";
  2129. $this->setEditFieldsFormScript($curr_url);
  2130. $this->colOpen("center",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2131. $this->drawModeButton("edit", "#", $this->lang['update'], $this->lang['update_record'], "update.gif", "\"".$this->unique_prefix."sendEditFields(); return false;\"", false, "&nbsp;", "");
  2132. if(isset($_REQUEST[$this->unique_prefix.'mode']) && $_REQUEST[$this->unique_prefix.'mode'] === "add") {
  2133. $cancel_url = $this->combineUrl("delete", $row[$this->primary_key]);
  2134. $this->setUrlString($cancel_url, "filtering", "sorting", "paging");
  2135. if(isset($this->modes['cancel'][$this->mode]) && $this->modes['cancel'][$this->mode]){
  2136. $this->drawModeButton("cancel", $cancel_url, $this->lang['cancel'], $this->lang['cancel'], "cancel.gif", "\"return ".$this->unique_prefix."verifyCancel('".$cancel_url."'); javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, $this->nbsp, "");
  2137. }
  2138. }else{
  2139. $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, "");
  2140. }
  2141. $this->colClose();
  2142. }else {
  2143. $row_id = ($this->getFieldOffset($this->primary_key) != "-1") ? $row[$this->getFieldOffset($this->primary_key)] : $this->getFieldOffset($this->primary_key);
  2144. $curr_url = $this->combineUrl("edit", $row_id);
  2145. $this->setUrlString($curr_url, "filtering", "sorting", "paging");
  2146. if(isset($_REQUEST[$this->unique_prefix.'new']) && (isset($_REQUEST[$this->unique_prefix.'new']) == 1)){
  2147. $curr_url .= $this->amp.$this->unique_prefix."new=1";
  2148. }
  2149. if(isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]){
  2150. // by field Value - link on Edit mode page
  2151. if (isset($this->modes['edit']['byFieldValue']) && ($this->modes['edit']['byFieldValue'] != "")){
  2152. if($this->getFieldOffset($this->modes['edit']['byFieldValue']) == "-1"){
  2153. if($this->debug == true){
  2154. $this->colOpen(($this->direction == "rtl")?"right":"left",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2155. echo $this->nbsp.$this->lang['wrong_field_name']." - ".$this->modes['edit']['byFieldValue'].$this->nbsp;
  2156. }else{
  2157. $this->colOpen("center",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2158. $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, "");
  2159. }
  2160. }else{
  2161. $this->colOpen(($this->direction == "rtl")?"right":"left",0,"nowrap",$main_td_color, $this->css_class."_class_td_main");
  2162. echo $this->nbsp."<a class='".$this->css_class."_class_a' href='$curr_url'>".$row[$this->getFieldOffset($this->modes['edit']['byFieldValue'])]."</a>".$this->nbsp;
  2163. }
  2164. }else{
  2165. $this->colOpen("center",0,"nowrap",$main_td_color, $this->css_class."_class_td_main", "10%");
  2166. $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, "");
  2167. }
  2168. $this->colClose();
  2169. }
  2170. }
  2171. }else{
  2172. if(isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode]){
  2173. $this->colOpen("center",0,"nowrap",$this->rowColor[2], $this->css_class."_class_td_main");$this->colClose();
  2174. }
  2175. }
  2176. if($this->rows_numeration){
  2177. $this->colOpen("center",0,"nowrap"); echo "<label class='".$this->css_class."_class_label'>".($r+1)."</label>"; $this->colClose();
  2178. }
  2179. // draw column data
  2180. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2181. // get current column's index (offset)
  2182. $c = $this->sorted_columns[$c_sorted];
  2183. $col_align = $this->getFieldAlign($c, $row);
  2184. $field_property_wrap = $this->getFieldProperty($this->getFieldName($c), "wrap", "view", "lower", $this->wrap);
  2185. if(($this->mode === "view") && ($this->canViewField($this->getFieldName($c)))){
  2186. if($req_sort_field == $c+1){
  2187. $this->colOpen($col_align, 0, $field_property_wrap, $this->rowColor[0], $this->css_class."_class_td_selected");
  2188. }else{
  2189. $this->colOpen($col_align, 0, $field_property_wrap);
  2190. }
  2191. $field_value = $this->getFieldValueByType($row[$c], $c, $row);
  2192. $field_property_summarize = $this->getFieldProperty($this->getFieldName($c), "summarize", "view");
  2193. if(($field_property_summarize == "true") || ($field_property_summarize == true)){
  2194. $this->summarize_columns[$this->getFieldName($c)] += str_replace(",", "", $row[$c]);
  2195. }
  2196. echo $field_value;
  2197. $this->colClose();
  2198. }else if($this->mode === "edit"){
  2199. if($this->getFieldProperty($this->getFieldName($c), "type") == "hidden"){
  2200. echo $this->getFieldValueByType('', 0, '', $this->getFieldName($c));
  2201. }else if($this->canViewField($this->getFieldName($c))){
  2202. if($first_field_name == "") $first_field_name = $this->getFieldName($c);
  2203. if(intval($this->rid) === intval($row[$this->getFieldOffset($this->primary_key)])){
  2204. $this->colOpen("left", 0, $field_property_wrap);
  2205. if($this->isForeignKey($this->getFieldName($c))){
  2206. echo $this->nbsp.$this->getForeignKeyInput($row[$this->getFieldOffset($this->primary_key)], $this->getFieldName($c), $row[$c], "edit").$this->nbsp;
  2207. }else{
  2208. echo $this->getFieldValueByType($row[$c], $c, $row);
  2209. }
  2210. $this->colClose();
  2211. }else{
  2212. $this->colOpen($col_align, 0, $field_property_wrap);
  2213. if($this->isForeignKey($this->getFieldName($c))){
  2214. echo $this->nbsp.$this->getForeignKeyInput($row[$this->getFieldOffset($this->primary_key)], $this->getFieldName($c), $row[$c],"view").$this->nbsp;
  2215. }else{
  2216. echo $this->nbsp.trim($row[$c]).$this->nbsp;
  2217. }
  2218. $this->colClose();
  2219. }
  2220. }
  2221. }
  2222. }
  2223. $row_id = ($this->getFieldOffset($this->primary_key) != "-1") ? $row[$this->getFieldOffset($this->primary_key)] : $this->getFieldOffset($this->primary_key);
  2224. if(isset($this->modes['details'][$this->mode]) && $this->modes['details'][$this->mode]){
  2225. $curr_url = $this->combineUrl("details", $row_id);
  2226. $this->setUrlString($curr_url, "filtering", "sorting", "paging");
  2227. $this->colOpen("center",0,"nowrap");
  2228. $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, "");
  2229. $this->colClose();
  2230. }
  2231. if(isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode]){
  2232. $curr_url = $this->combineUrl("delete", $row_id);
  2233. $this->setUrlString($curr_url, "filtering", "sorting", "paging");
  2234. $this->colOpen("center",0,"nowrap");
  2235. $this->drawModeButton("delete", $curr_url, $this->lang['delete'], $this->lang['delete_record'], "delete.gif", "\"return ".$this->unique_prefix."verifyDelete('$curr_url');\"", false, "", "");
  2236. $this->colClose();
  2237. }
  2238. if(($this->mode == "edit") && (intval($this->rid) == intval($row[$this->getFieldOffset($this->primary_key)]))){ echo "</form>"; }
  2239. $this->rowClose();
  2240. }
  2241. // *** END ROWS --------------------------------------------------------
  2242. // draw summarizing row
  2243. if($r != $this->row_lower){ $this->drawSummarizeRow($r); }
  2244. $this->tblClose();
  2245. // draw empty table
  2246. if($r == $this->row_lower){ $this->noDataFound(); }
  2247. $this->scrollDivClose();
  2248. $this->drawMultiRowBar($r, $curr_url); // draw multi-row row footer cell
  2249. if($this->paging_allowed) $this->pagingSecondPart($this->lower_paging, true, true, "Lower");
  2250. // draw hide DG close div
  2251. $this->hideDivClose();
  2252. echo "<script>document.getElementById('".$this->unique_random_prefix."loading_image').style.display='none';</script>";
  2253. if(($this->first_field_focus_allowed) && ($first_field_name != "")) echo "<script type='text/javascript'>\n<!--\n document.".$this->unique_prefix."frmEditRow.".$this->getFieldRequiredType($first_field_name).$first_field_name.".focus(); \n//-->\n</script>";
  2254. }
  2255. //--------------------------------------------------------------------------
  2256. // draw in columnar layout
  2257. //--------------------------------------------------------------------------
  2258. function drawColumnar(){
  2259. $r = ""; //???
  2260. $req_print = $this->getVariable('print');
  2261. $req_mode = $this->getVariable('mode');
  2262. $this->writeCssClass();
  2263. $this->exportTo();
  2264. $this->showCaption($this->caption);
  2265. $this->drawControlPanel();
  2266. if((isset($_REQUEST[$this->unique_prefix.'mode']) && ($_REQUEST[$this->unique_prefix.'mode'] !== "add") && ($_REQUEST[$this->unique_prefix.'mode'] !== "details")) || (!isset($_REQUEST[$this->unique_prefix.'mode']))) $this->pagingFirstPart();
  2267. $this->displayMessages();
  2268. if(isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode]){
  2269. $this->tblOpen();
  2270. $this->rowOpen($r, $this->rowColor[0]);
  2271. $curr_url = $this->combineUrl("add", "-1");
  2272. $this->setUrlString($curr_url, "filtering", "sorting", "paging");
  2273. $this->mainColOpen("center",0,"nowrap", "", $this->css_class."_class_th_normal");
  2274. $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, "", "");
  2275. $this->mainColClose();
  2276. $this->rowClose();
  2277. $this->tblClose();
  2278. }
  2279. if($this->paging_allowed) $this->pagingSecondPart($this->upper_paging, false, true, "Upper");
  2280. //prepare action url for the form
  2281. $curr_url = $this->combineUrl("update", $this->rid, $this->amp);
  2282. $this->setUrlString($c_curr_url, "filtering", "sorting", "paging", $this->amp);
  2283. $curr_url .= $c_curr_url;
  2284. if($req_mode === "add") {
  2285. $curr_url .= $this->amp.$this->unique_prefix."new=1";
  2286. }
  2287. 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>";
  2288. echo "<form name='".$this->unique_prefix."frmEditRow' id='".$this->unique_prefix."frmEditRow' method='post' action='".$curr_url."'>".chr(13);
  2289. $this->tblOpen();
  2290. // draw header
  2291. $this->rowOpen($r);
  2292. $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();
  2293. $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();
  2294. $this->rowClose();
  2295. // set number of showing rows on the page
  2296. if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "1") && ($this->mode == "edit")){
  2297. if($this->multi_rows > 0){
  2298. $this->req_page_size = $this->multi_rows;
  2299. }else{
  2300. $this->req_page_size = 1;
  2301. }
  2302. }else if(($this->layouts['view'] == "0") && ($this->layouts['edit'] == "1") && ($this->mode == "details")){
  2303. if($this->multi_rows > 0){
  2304. $this->req_page_size = $this->multi_rows;
  2305. }else{
  2306. $this->req_page_size = 1;
  2307. }
  2308. }else if(($this->layouts['view'] == "1") && ($this->layouts['edit'] == "1") && ($this->mode == "edit")){
  2309. $this->req_page_size = 1; // ???
  2310. }else if(($this->layouts['edit'] == "1") && ($this->mode == "details")){
  2311. $this->req_page_size = 1;
  2312. }
  2313. $first_field_name = ""; /* we need it to set a focus on this field */
  2314. // draw rows in ADD MODE
  2315. if($this->rid == -1){
  2316. foreach($this->columns_edit_mode as $key => $val){
  2317. if(($first_field_name == "") && (($this->mode === "edit") || ($this->mode === "add"))) $first_field_name = $key;
  2318. if($r % 2 == 0) $this->rowOpen($r, $this->rowColor[0]);
  2319. else $this->rowOpen($r, $this->rowColor[1]);
  2320. if($key == "delimiter"){
  2321. $this->colOpen(($this->direction == "rtl")?"right":"left",2,"nowrap");
  2322. echo $this->getFieldProperty("delimiter", "inner_html");
  2323. $this->colClose();
  2324. }else if($key == "validator"){
  2325. $field_property_for_field = $this->getFieldProperty("validator", "for_field");
  2326. $field_property_header = $this->getFieldProperty("validator", "for_field");
  2327. // column's header
  2328. $this->colOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2329. echo $this->nbsp;echo "<b>".ucfirst($field_property_header)."</b>";
  2330. $this->colClose();
  2331. // column's data
  2332. $col_align = ($this->direction == "rtl")?"right":"left";
  2333. $this->colOpen($col_align,0,"nowrap");
  2334. echo $this->getFieldValueByType('', 0, '', $field_property_for_field);
  2335. $this->colClose();
  2336. }else if($this->getFieldProperty($key, "type") == "hidden"){
  2337. echo $this->getFieldValueByType('', 0, '', $key);
  2338. }else{
  2339. // column's header
  2340. $this->colOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2341. echo $this->nbsp;echo "<b>".ucfirst($this->getHeaderName($key))."</b>";
  2342. $this->colClose();
  2343. // column's data
  2344. $col_align = ($this->direction == "rtl")?"right":"left";
  2345. $this->colOpen($col_align,0,"nowrap");
  2346. if($this->isForeignKey($key)){
  2347. echo $this->nbsp.$this->getForeignKeyInput(-1, $key, '-1', "edit").$this->nbsp;
  2348. }else{
  2349. echo $this->getFieldValueByType('', 0, '', $key);
  2350. }
  2351. $this->colClose();
  2352. }
  2353. $this->rowClose();
  2354. }
  2355. }
  2356. // *** START DRAWING ROWS ----------------------------------------------
  2357. for($r = $this->row_lower; (($this->rid != -1) && ($r < $this->row_upper) && ($r < ($this->row_lower + $this->req_page_size))); $r++){
  2358. $row = $this->data_set->fetchRow();
  2359. // draw column headers
  2360. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2361. // get current column's index (offset)
  2362. $c = $this->sorted_columns[$c_sorted];
  2363. if($r % 2 == 0) $this->rowOpen($r, $this->rowColor[0]);
  2364. else $this->rowOpen($r, $this->rowColor[1]);
  2365. if($this->canViewField($this->getFieldName($c))){
  2366. if($this->getFieldProperty($this->getFieldName($c), "type") == "hidden"){
  2367. echo $this->getFieldValueByType('', 0, '', $this->getFieldName($c));
  2368. }else{
  2369. if(($first_field_name == "") && (($this->mode === "edit") || ($this->mode === "add"))) $first_field_name = $this->getFieldName($c);
  2370. // column headers
  2371. if(($this->mode === "view") && ($this->canViewField($this->getFieldName($c)))){
  2372. $this->colOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2373. echo $this->nbsp;echo "<b>".ucfirst($this->getHeaderName($this->getFieldName($c)))."</b>";
  2374. $this->colClose();
  2375. }else if(($this->mode === "edit") && ($this->canViewField($this->getFieldName($c)))){
  2376. $this->colOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2377. echo $this->nbsp;echo "<b>".ucfirst($this->getHeaderName($this->getFieldName($c)))."</b>";
  2378. $this->colClose();
  2379. }else if(($this->mode === "details") && ($this->canViewField($this->getFieldName($c)))){
  2380. $this->colOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2381. echo $this->nbsp;echo "<b>".ucfirst($this->getHeaderName($this->getFieldName($c)))."</b>";
  2382. $this->colClose();
  2383. }
  2384. // column data
  2385. $col_align = ($this->direction == "rtl") ? "right" : "left";
  2386. if(($this->mode === "view") && ($this->canViewField($this->getFieldName($c)))){
  2387. $this->colOpen($col_align,0,$this->columns_view_mode[$this->getFieldName($c)]['wrap']);
  2388. echo $this->getFieldValueByType($row[$c], $c, $row);
  2389. $this->colClose();
  2390. }else if(($this->mode === "details") && ($this->canViewField($this->getFieldName($c)))){
  2391. $this->colOpen($col_align,0);
  2392. if($this->isForeignKey($this->getFieldName($c))){
  2393. echo $this->getForeignKeyInput($row[$this->getFieldOffset($this->primary_key)], $this->getFieldName($c), $row[$c],"view");
  2394. }else{
  2395. echo $this->getFieldValueByType($row[$c], $c, $row);
  2396. }
  2397. $this->colClose();
  2398. }else if(($this->mode === "edit") && ($this->canViewField($this->getFieldName($c)))){
  2399. // if we have multi-rows selected
  2400. // mr_2
  2401. if($this->multi_rows > 0){
  2402. $rid_value = $this->rids[$r];
  2403. }else{
  2404. $rid_value = $this->rid;
  2405. }
  2406. $ind = ($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0;
  2407. if(intval($rid_value) === intval($row[$ind])){
  2408. $this->colOpen($col_align,0,"nowrap");
  2409. if($this->isForeignKey($this->getFieldName($c))){
  2410. echo $this->nbsp.$this->getForeignKeyInput($row[$ind], $this->getFieldName($c), $row[$c], "edit").$this->nbsp;
  2411. }else{
  2412. echo $this->getFieldValueByType($row[$c], $c, $row);
  2413. }
  2414. $this->colClose();
  2415. }else{
  2416. $this->colOpen($col_align,0,"nowrap");
  2417. if($this->rid == -1){
  2418. // add new row
  2419. if($this->isForeignKey($this->getFieldName($c))){
  2420. echo $this->nbsp.$this->getForeignKeyInput(-1, $this->getFieldName($c), '-1', "edit").$this->nbsp;
  2421. }else{
  2422. echo $this->getFieldValueByType('', $c, $row);
  2423. }
  2424. }else{
  2425. if($this->isForeignKey($this->getFieldName($c))){
  2426. echo $this->nbsp.$this->getForeignKeyInput($row[$this->getFieldOffset($this->primary_key)], $this->getFieldName($c), $row[$c],"view").$this->nbsp;
  2427. }else{
  2428. echo $this->nbsp.trim($row[$c]).$this->nbsp;
  2429. }
  2430. }
  2431. $this->colClose();
  2432. }
  2433. }
  2434. }
  2435. }else{
  2436. $ind = 0;
  2437. foreach($this->columns_edit_mode as $key => $val){
  2438. if($ind == $c_sorted){
  2439. if($key == "validator"){ // customized rows (validator)
  2440. $field_property_for_field = $this->getFieldProperty($key, "for_field");
  2441. $field_property_header = $this->getFieldProperty($key, "for_field");
  2442. $this->colOpen(($this->direction == "rtl")?"right":"left",0,"nowrap");
  2443. echo $this->nbsp;echo "<b>".ucfirst($field_property_header)."</b>";
  2444. $this->colClose();
  2445. $this->colOpen($col_align,0,$this->columns_view_mode[$this->getFieldName($c)]['wrap']);
  2446. echo $this->getFieldValueByType('', $this->getFieldOffset($field_property_for_field), $row);
  2447. $this->colClose();
  2448. }else if($key == "delimiter"){ // customized rows (delimiter)
  2449. $this->colOpen("",2,"nowrap");
  2450. echo $this->getFieldProperty("delimiter", "inner_html");
  2451. $this->colClose();
  2452. }
  2453. }
  2454. $ind++;
  2455. }
  2456. }
  2457. $this->rowClose();
  2458. }// for
  2459. }
  2460. // *** END DRAWING ROWS ------------------------------------------------
  2461. $this->tblClose();
  2462. echo "<br />";
  2463. if(($r == $this->row_lower) && ($this->rid != -1)){
  2464. $this->noDataFound();
  2465. echo "<br /><center>";
  2466. if($req_print != ""){
  2467. echo "<span class='".$this->css_class."_class_a'><b>".$this->lang['back']."</b></span>";
  2468. }else{
  2469. echo "<a class='".$this->css_class."_class_a' href='javascript:history.go(-1);'><b>".$this->lang['back']."</b></a>";
  2470. }
  2471. echo "</center>";
  2472. }else{
  2473. $this->tblOpen();
  2474. $this->rowOpen($r, $this->rowColor[1]);
  2475. $this->mainColOpen('left', 0, '', '', (($req_print == true) ? $this->css_class."_class_td_normal" : $this->css_class."_class_th"), "style='BORDER-RIGHT: #d2d0bb 0px solid;'");
  2476. if($this->mode === "details"){
  2477. $cancel_url = $this->combineUrl("cancel", $row[$this->getFieldOffset($this->primary_key)]);
  2478. $this->setUrlString($c_curr_url, "filtering", "sorting", "paging");
  2479. $cancel_url .= $c_curr_url;
  2480. echo "<div style='float:";
  2481. echo ($this->direction == "rtl")?"left":"right";
  2482. if($req_print != ""){
  2483. echo ";'><span class='".$this->css_class."_class_a'><b>".$this->lang['back']."</b></span></div>";
  2484. }else{
  2485. echo ";'>";
  2486. echo $this->drawModeButton("cancel", $cancel_url, $this->lang['back'], $this->lang['back'], "cancel.gif", "\"javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, "", "");
  2487. echo "</div>";
  2488. }
  2489. }else{
  2490. // if not new row
  2491. $ind = ($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0;
  2492. if(($this->rid != -1) && isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode]){
  2493. $curr_url = $this->combineUrl("delete", $row[$ind]);
  2494. $this->setUrlString($curr_url, "filtering", "sorting", "paging");
  2495. $this->drawModeButton("delete", $curr_url, $this->lang['delete'], $this->lang['delete_record'], "delete.gif", "\"return ".$this->unique_prefix."verifyDelete('$curr_url');\"", true, "", "");
  2496. }
  2497. if($this->rid != -1){
  2498. $rid = $row[$ind];
  2499. }else{
  2500. $rid = -1;
  2501. }
  2502. $curr_url = $this->combineUrl("update", $rid);
  2503. $cancel_url = $this->combineUrl("cancel", $rid);
  2504. $this->setUrlString($c_curr_url, "filtering", "sorting", "paging");
  2505. $cancel_url .= $c_curr_url;
  2506. $curr_url .= $c_curr_url;
  2507. if(isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]){
  2508. if($req_mode === "add") { $cancel_url .= $this->amp.$this->unique_prefix."new=1";}
  2509. $this->setEditFieldsFormScript();
  2510. echo "<div style='float:"; echo ($this->direction == "rtl")?"left":"right"; echo ";'>";
  2511. if($req_mode === "add") {
  2512. if($this->rid == -1){
  2513. $cancel_url = $this->combineUrl("cancel", $rid);
  2514. }else{
  2515. $cancel_url = $this->combineUrl("delete", $rid);
  2516. }
  2517. $this->setUrlString($cancel_url, "filtering", "sorting", "paging");
  2518. $this->drawModeButton("cancel", $cancel_url, $this->lang['cancel'], $this->lang['cancel'], "cancel.gif", "\"return ".$this->unique_prefix."verifyCancel('$cancel_url'); javascript:document.location.href='".$this->HTTP_URL.$cancel_url."'\"", false, $this->nbsp, "");
  2519. }else{
  2520. $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, "");
  2521. }
  2522. echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  2523. if($this->rid == -1){ //aaa new record
  2524. $this->drawModeButton("edit", "#", $this->lang['create'], $this->lang['create_new_record'], "update.gif", "\"".$this->unique_prefix."sendEditFields(); return false;\"", false, $this->nbsp, "");
  2525. }else{
  2526. $this->drawModeButton("edit", "#", $this->lang['update'], $this->lang['update_record'], "update.gif", "\"".$this->unique_prefix."sendEditFields(); return false;\"", false, $this->nbsp, "");
  2527. }
  2528. echo "</div>";
  2529. }else{
  2530. echo "<div style='float:"; echo ($this->direction == "rtl")?"left":"right"; echo ";'>";
  2531. $this->drawModeButton("cancel", $cancel_url, $this->lang['back'], $this->lang['back'], "cancel.gif", "\"\"", false, $this->nbsp, "");
  2532. echo "</div>";
  2533. }
  2534. }
  2535. $this->mainColClose();
  2536. $this->rowClose();
  2537. $this->tblClose();
  2538. }
  2539. echo "</form>";
  2540. echo "<script>document.getElementById('".$this->unique_random_prefix."loading_image').style.display='none';</script>";
  2541. if($this->paging_allowed) $this->pagingSecondPart($this->lower_paging, true, true, "Lower");
  2542. if(($this->first_field_focus_allowed) && ($first_field_name != "")) echo "<script type='text/javascript'>\n<!--\n document.".$this->unique_prefix."frmEditRow.".$this->getFieldRequiredType($first_field_name).$first_field_name.".focus(); \n//-->\n</script>";
  2543. }
  2544. //--------------------------------------------------------------------------
  2545. // draw Multi-Row Bar
  2546. //--------------------------------------------------------------------------
  2547. function drawMultiRowBar($r, $curr_url){
  2548. $req_print = $this->getVariable('print');
  2549. if(($this->multirow_allowed) && ($r != $this->row_lower)){
  2550. echo "<script type='text/javascript'>
  2551. function ".$this->unique_prefix."verifySelected(param, button_type, flag_name, flag_value){
  2552. if(confirm('Are you sure you want to carry out this operation?')){
  2553. selected_rows = '&".$this->unique_prefix."rid=';
  2554. selected_rows_ids = '';
  2555. found = 0;
  2556. for(i=".$this->row_lower."; i < ".$this->row_upper."; i++){
  2557. if(document.getElementById(\"".$this->unique_prefix."checkbox_\"+i).checked == true){
  2558. if(found == 1){ selected_rows_ids += '-'; }
  2559. selected_rows_ids += document.getElementById(\"".$this->unique_prefix."checkbox_\"+i).value;
  2560. found = 1;
  2561. }
  2562. }
  2563. if(found){
  2564. document_location_href = param+selected_rows+selected_rows_ids;
  2565. if(flag_name != ''){
  2566. found = (document_location_href.indexOf(flag_name) != -1);
  2567. if(!found){
  2568. document_location_href += '&'+flag_name+'='+flag_value;
  2569. }
  2570. }
  2571. document.location.href = document_location_href;
  2572. }else{
  2573. alert('You need to select one or more rows to carry out this operation!');
  2574. return false;
  2575. }
  2576. }
  2577. };
  2578. function ".$this->unique_prefix."setCheckboxes(check){
  2579. if(check){
  2580. for(i=".$this->row_lower."; i < ".$this->row_upper."; i++){
  2581. document.getElementById('".$this->unique_prefix."checkbox_'+i).checked = true;
  2582. document.getElementById('".$this->unique_prefix."row_'+i).style.background = '".$this->rowColor[5]."';
  2583. }
  2584. }else{
  2585. for(i=".$this->row_lower."; i < ".$this->row_upper."; i++){
  2586. document.getElementById('".$this->unique_prefix."checkbox_'+i).checked = false;
  2587. if((i % 2) == 0) row_color_back = '".$this->rowColor[0]."';
  2588. else row_color_back = '".$this->rowColor[1]."';
  2589. document.getElementById('".$this->unique_prefix."row_'+i).style.background = row_color_back;
  2590. }
  2591. }
  2592. }
  2593. </script>
  2594. ";
  2595. echo "<table dir='".$this->direction."' border='0' align='".$this->tblAlign[$this->mode]."' width='".$this->tblWidth[$this->mode]."'>";
  2596. echo "<tr>";
  2597. echo "<td align='left'>";
  2598. echo "<table border='0' align='left'>
  2599. <tr>
  2600. <td align='left' valign='center' class='class_nowrap'>";
  2601. $count = 0;
  2602. foreach($this->multirow_operations_array as $key => $val){
  2603. if($this->multirow_operations_array[$key]['view']) $count++;
  2604. }
  2605. if($count > 0){
  2606. echo "<img style='PADDING:0px; MARGIN:0px;' src='".$this->directory."images/".$this->css_class."/arrow_ltr.png' border='0' width='38' height='22' alt='".$this->lang['with_selected'].":' title='".$this->lang['with_selected'].":' />";
  2607. if(!$req_print){
  2608. echo "<a class='".$this->css_class."_class_a' href='#' onClick='".$this->unique_prefix."setCheckboxes(true); return false;'>".$this->lang['check_all']."</a>
  2609. &nbsp;/&nbsp;
  2610. <a class='".$this->css_class."_class_a' href='#' onClick='".$this->unique_prefix."setCheckboxes(false); return false;'>".$this->lang['uncheck_all']."</a>";
  2611. }else{
  2612. echo "<a class='".$this->css_class."_class_label'>".$this->lang['check_all']."</label>
  2613. &nbsp;/&nbsp;
  2614. <a class='".$this->css_class."_class_label'>".$this->lang['uncheck_all']."</label>";
  2615. }
  2616. echo "
  2617. &nbsp;&nbsp;&nbsp;
  2618. <label class='".$this->css_class."_class_label'><i>".$this->lang['with_selected'].":</i></label>&nbsp;&nbsp;
  2619. </td>
  2620. <td align='left' valign='bottom' >";
  2621. foreach($this->multirow_operations_array as $key => $val){
  2622. if($this->multirow_operations_array[$key]['view']){
  2623. echo "&nbsp;";
  2624. $curr_url = $this->combineUrl($key, "");
  2625. $flag_name = isset($val['flag_name']) ? $val['flag_name'] : "";
  2626. $flag_value = isset($val['flag_value']) ? $val['flag_value'] : "";
  2627. $tooltip = isset($val['tooltip']) ? $val['tooltip'] : $this->lang[$key.'_selected'];
  2628. $image = isset($val['image']) ? $val['image'] : $key.".gif" ;
  2629. $this->setUrlString($curr_url, "filtering", "sorting", "paging");
  2630. $this->drawModeButton($key, $curr_url, $tooltip, $tooltip, $image, "\"return ".$this->unique_prefix."verifySelected('$curr_url', '$key', '$flag_name', '$flag_value');\"", false, "", "image");
  2631. echo "&nbsp;";
  2632. }
  2633. }
  2634. }
  2635. echo "
  2636. </td>
  2637. </tr>
  2638. </table>
  2639. ";
  2640. echo "</td>";
  2641. echo "</tr>";
  2642. echo "</table>";
  2643. }
  2644. }
  2645. //--------------------------------------------------------------------------
  2646. // draw Summarize Row
  2647. //--------------------------------------------------------------------------
  2648. function drawSummarizeRow($r){
  2649. if(count($this->summarize_columns) > 0){
  2650. $this->rowOpen("", $this->rowColor[0]);
  2651. // draw multi-row row footer cell
  2652. if($this->multirow_allowed){
  2653. $this->colOpen("center",0,"nowrap","","");
  2654. echo $this->nbsp;
  2655. $this->colClose();
  2656. }
  2657. // draw column headers in view mode
  2658. for($c_sorted = $this->col_lower; $c_sorted < count($this->sorted_columns); $c_sorted++){
  2659. // get current column's index (offset)
  2660. $c = $this->sorted_columns[$c_sorted];
  2661. if($c_sorted == $this->col_lower){
  2662. if((isset($this->modes['add'][$this->mode]) && $this->modes['add'][$this->mode]) ||
  2663. (isset($this->modes['edit'][$this->mode]) && $this->modes['edit'][$this->mode]))
  2664. {
  2665. $this->colOpen("center",0,"nowrap",$this->rowColor[2], $this->css_class."_class_td_main");
  2666. echo "<a class='".$this->css_class."_class_a'><b>".$this->lang['total'].":</b></a>";
  2667. $this->colClose();
  2668. }
  2669. if($this->rows_numeration){
  2670. $this->colOpen("center",0,"nowrap"); echo ""; $this->colClose();
  2671. }
  2672. }
  2673. if($this->canViewField($this->getFieldName($c))){
  2674. $this->colOpen("right",0,"nowrap");
  2675. if(isset($this->columns_view_mode[$this->getFieldName($c)]['summarize']) && ($this->columns_view_mode[$this->getFieldName($c)]['summarize'] === true))
  2676. echo $this->nbsp."=".$this->nbsp."<a class='".$this->css_class."_class_a'><b>".number_format($this->summarize_columns[$this->getFieldName($c)], 2)."</b></a>";
  2677. $this->colClose();
  2678. }
  2679. }
  2680. if((isset($this->modes['details'][$this->mode]) && $this->modes['details'][$this->mode])){
  2681. $this->colOpen("right",0,"nowrap");$this->colClose();
  2682. }
  2683. if((isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode])){
  2684. $this->colOpen("right",0,"nowrap");$this->colClose();
  2685. }
  2686. $this->rowClose();
  2687. }
  2688. }
  2689. //--------------------------------------------------------------------------
  2690. // sort columns by mode order
  2691. //--------------------------------------------------------------------------
  2692. function sortColums($mode = ""){
  2693. if($mode == "view"){
  2694. foreach($this->columns_view_mode as $fldName => $fldValue){
  2695. $this->sorted_columns[] = $this->getFieldOffset($fldName);
  2696. }
  2697. }else if(($mode == "edit") || ($mode == "details")){
  2698. foreach($this->columns_edit_mode as $fldName => $fldValue){
  2699. $this->sorted_columns[] = $this->getFieldOffset($fldName);
  2700. }
  2701. }
  2702. }
  2703. //--------------------------------------------------------------------------
  2704. // add error to array of errors
  2705. //--------------------------------------------------------------------------
  2706. function addErrors($dSet = ""){
  2707. if($this->debug){
  2708. if($dSet == "") $dSet = $this->data_set;
  2709. $this->errors[] = $dSet->getDebugInfo();
  2710. }
  2711. }
  2712. //--------------------------------------------------------------------------
  2713. // add warning to array of warnings
  2714. //--------------------------------------------------------------------------
  2715. function addWarning($warning_field, $warning_value){
  2716. if($this->debug){
  2717. $warning = str_replace('_FIELD_', $warning_field, $this->lang['wrong_parameter_error']);
  2718. $warning = str_replace('_VALUE_', $warning_value, $warning);
  2719. $this->warnings[] = $warning;
  2720. }
  2721. }
  2722. //--------------------------------------------------------------------------
  2723. // display warnings
  2724. //--------------------------------------------------------------------------
  2725. function displayWarnings(){
  2726. if($this->debug){
  2727. $count = 0;
  2728. if(count($this->warnings) > 0){
  2729. echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left'>";
  2730. echo "<font class='".$this->css_class."_class_error_message no_print'><u><b>".$this->lang['warnings']."</b></u>:</font><br /><br />";
  2731. foreach($this->warnings as $key){
  2732. echo "<font class='".$this->css_class."_class_error_message no_print'>".(++$count).") $key</font><br />";
  2733. }
  2734. echo "<br />";
  2735. echo "</td></tr></table>";
  2736. }
  2737. }
  2738. }
  2739. //--------------------------------------------------------------------------
  2740. // display errors
  2741. //--------------------------------------------------------------------------
  2742. function displayErrors(){
  2743. if($this->debug){
  2744. $count = 0;
  2745. if(count($this->errors) > 0){
  2746. echo "<table width='".$this->tblWidth[$this->mode]."'><tr><td align='left'>";
  2747. echo "<font class='".$this->css_class."_class_error_message no_print'><u><b>".$this->lang['errors']."</b></u>:</font><br /><br />";
  2748. foreach($this->errors as $key){
  2749. echo "<font class='".$this->css_class."_class_error_message no_print'>".(++$count).") </font>";
  2750. echo "<font class='".$this->css_class."_class_label'>".substr($key, 0, strpos($key, "["))."</font><br />";
  2751. echo "<font class='".$this->css_class."_class_error_message no_print'>".stristr($key, "[")."</font><br /><br />";
  2752. }
  2753. echo "<br />";
  2754. echo "</td></tr></table>";
  2755. }
  2756. }
  2757. }
  2758. //--------------------------------------------------------------------------
  2759. // draw data sent by POST and GET
  2760. //--------------------------------------------------------------------------
  2761. function displayDataSent(){
  2762. if($this->debug){
  2763. print_r("<font class='".$this->css_class."_class_ok_message no_print'><b>POST</b>: ");
  2764. print_r($_POST);
  2765. print_r("</font><br /><br />");
  2766. print_r("<font class='".$this->css_class."_class_ok_message no_print'><b>GET</b>: ");
  2767. print_r($_GET);
  2768. print_r("</font><br /><br />");
  2769. }
  2770. }
  2771. //--------------------------------------------------------------------------
  2772. // draw messages
  2773. //--------------------------------------------------------------------------
  2774. function displayMessages(){
  2775. if($this->messaging && $this->act_msg){
  2776. $css_class = "".$this->css_class."_class_ok_message";
  2777. if($this->is_error) $css_class= "".$this->css_class."_class_error_message no_print";
  2778. if($this->is_warning) $css_class= "".$this->css_class."_class_error_message no_print";
  2779. echo "<div style='margin-top:10px;margin-bottom:10px;'><center><font class='".$css_class."'>$this->act_msg</font></center></div>";
  2780. $this->act_msg = "";
  2781. }
  2782. }
  2783. //--------------------------------------------------------------------------
  2784. // save Http Get Vars
  2785. //--------------------------------------------------------------------------
  2786. function saveHttpGetVars(){
  2787. if(is_array($this->http_get_vars) && (count($this->http_get_vars) > 0)){
  2788. foreach($this->http_get_vars as $key){
  2789. echo "<input type='hidden' name='".$key."' id='".$key."' value='".((isset($_REQUEST[$key]))?$_REQUEST[$key]:"")."'>";
  2790. }
  2791. }
  2792. echo "<input type='hidden' name='".$this->unique_prefix."page_size' id='".$this->unique_prefix."page_size' value='".((isset($_REQUEST[$this->unique_prefix.'page_size']))?$_REQUEST[$this->unique_prefix.'page_size']:$this->req_page_size)."'>\n";
  2793. echo "<input type='hidden' name='".$this->unique_prefix."sort_field' id='".$this->unique_prefix."sort_field' value='".((isset($_REQUEST[$this->unique_prefix.'sort_field']))?$_REQUEST[$this->unique_prefix.'sort_field']:"")."'>\n";
  2794. echo "<input type='hidden' name='".$this->unique_prefix."sort_field_by' id='".$this->unique_prefix."sort_field_by' value='".((isset($_REQUEST[$this->unique_prefix.'sort_field_by']))?$_REQUEST[$this->unique_prefix.'sort_field_by']:"")."'>\n";
  2795. echo "<input type='hidden' name='".$this->unique_prefix."sort_type' id='".$this->unique_prefix."sort_type' value='".((isset($_REQUEST[$this->unique_prefix.'sort_type']))?$_REQUEST[$this->unique_prefix.'sort_type']:"")."'>\n";
  2796. // get URL vars from another DG
  2797. if(is_array($this->another_datagrids) && (count($this->another_datagrids) > 0)){
  2798. foreach($this->another_datagrids as $key => $val){
  2799. if($val[$this->mode] == true){
  2800. foreach($_REQUEST as $r_key => $r_val){
  2801. if(strstr($r_key, $key)){ // ."_ff_"
  2802. echo "<input type='hidden' name='".$r_key."' id='".$r_key."' value='".((isset($_REQUEST[$r_key]))?$_REQUEST[$r_key]:"")."'>\n";
  2803. }
  2804. }
  2805. }
  2806. }
  2807. }
  2808. }
  2809. //--------------------------------------------------------------------------
  2810. // combine url
  2811. //--------------------------------------------------------------------------
  2812. function combineUrl($mode, $rid="", $amp=""){
  2813. $amp = ($amp != "") ? $amp : $this->amp;
  2814. $ind = 0;
  2815. if(is_array($this->http_get_vars) && (count($this->http_get_vars) > 0)){
  2816. foreach($this->http_get_vars as $key){
  2817. if($ind == 0){ $a_url = "?"; $ind = 1; }
  2818. else $a_url .= $amp;
  2819. $a_url .= $key."=".((isset($_REQUEST[$key]))?$_REQUEST[$key]:"");
  2820. }
  2821. }
  2822. if($ind == 0) $a_url = "?".$this->unique_prefix."mode=".$mode."";
  2823. else $a_url .= $amp.$this->unique_prefix."mode=".$mode."";
  2824. if($rid !== "") $a_url .= $amp.$this->unique_prefix."rid=".$rid;
  2825. // get URL vars from another DG
  2826. if(is_array($this->another_datagrids) && (count($this->another_datagrids) > 0)){
  2827. foreach($this->another_datagrids as $key => $val){
  2828. if($val[$this->mode] == true){
  2829. $a_url .= $amp.$key."mode=".((isset($_REQUEST[$key.'mode']))?$_REQUEST[$key.'mode']:"");
  2830. $a_url .= $amp.$key."rid=".((isset($_REQUEST[$key.'rid']))?$_REQUEST[$key.'rid']:"");
  2831. $a_url .= $amp.$key."sort_field=".((isset($_REQUEST[$key.'sort_field']))?$_REQUEST[$key.'sort_field']:"");
  2832. $a_url .= $amp.$key."sort_field_by=".((isset($_REQUEST[$key.'sort_field_by']))?$_REQUEST[$key.'sort_field_by']:"");
  2833. $a_url .= $amp.$key."sort_type=".((isset($_REQUEST[$key.'sort_type']))?$_REQUEST[$key.'sort_type']:"");
  2834. $a_url .= $amp.$key."page_size=".((isset($_REQUEST[$key.'page_size']))?$_REQUEST[$key.'page_size']:"");
  2835. $a_url .= $amp.$key."p=".((isset($_REQUEST[$key.'p']))?$_REQUEST[$key.'p']:"");
  2836. foreach($_REQUEST as $r_key => $r_val){
  2837. if(strstr($r_key, $key."_ff_")){
  2838. //d echo $r_key."=".$_REQUEST[$r_key]."<br />";
  2839. $a_url .= $amp.$r_key."=".((isset($_REQUEST[$r_key]))?$_REQUEST[$r_key]:"");
  2840. }
  2841. }
  2842. }
  2843. }
  2844. }
  2845. return $a_url;
  2846. }
  2847. //--------------------------------------------------------------------------
  2848. // set SQL limit
  2849. //--------------------------------------------------------------------------
  2850. function setSqlLimit(){
  2851. $req_page_num = "";
  2852. $req_page_size = $this->getVariable('page_size');
  2853. $req_p = $this->getVariable('p');
  2854. if($req_page_size != "") $this->req_page_size = $req_page_size;
  2855. if($req_p != "") $req_page_num = $req_p;
  2856. if(is_numeric($req_page_num)){
  2857. if($req_page_num > 0) $this->page_current = $req_page_num;
  2858. else $this->page_current = 1;
  2859. }else{
  2860. $this->page_current = 1;
  2861. }
  2862. // if there was deleted a last rows from a last page
  2863. if(intval($this->rows_total) <= intval(($this->page_current - 1) * $this->req_page_size)){
  2864. if($this->page_current > 1){
  2865. $this->page_current--;
  2866. $_REQUEST[$this->unique_prefix.'p'] = $this->page_current;
  2867. }
  2868. }
  2869. $this->limit_start = ($this->page_current - 1) * $this->req_page_size;
  2870. $this->limit_size = $this->req_page_size;
  2871. }
  2872. //--------------------------------------------------------------------------
  2873. // set SQL limit by DB type
  2874. //--------------------------------------------------------------------------
  2875. function setSqlLimitByDbType($limit_start="", $limit_size=""){
  2876. $this->setSqlLimit();
  2877. if($limit_start == "") $limit_start = $this->limit_start;
  2878. if($limit_size == "") $limit_size = $this->limit_size;
  2879. $limit_string = "";
  2880. switch($this->db_handler->phptype){
  2881. case "oci8": // oracle
  2882. $limit_string = "AND (rownum > ".$limit_start." AND rownum <= ".intval($limit_start + $limit_size).") ";
  2883. break;
  2884. case "mssql": // mssql
  2885. $limit_string = "AND RowNumber > ".$limit_start." AND RowNumber < ".intval($limit_start + $limit_size).") ";
  2886. break;
  2887. case "pgsql": // Postgresql
  2888. $limit_string = "OFFSET ".$limit_start." LIMIT ".$limit_size." ";
  2889. break;
  2890. case "mysql": // mysql and others
  2891. default:
  2892. $limit_string = "LIMIT ".$limit_start.", ".$limit_size." ";
  2893. break;
  2894. }
  2895. return $limit_string;
  2896. }
  2897. //--------------------------------------------------------------------------
  2898. // set real escape string by DB type
  2899. //--------------------------------------------------------------------------
  2900. function setRealEscapeStringByDbType($field_value = ""){
  2901. switch($this->db_handler->phptype){
  2902. case "mysql": // mysql
  2903. return mysql_real_escape_string($field_value); break;
  2904. default:
  2905. return $field_value; break;
  2906. }
  2907. }
  2908. //--------------------------------------------------------------------------
  2909. // set SQL by DB type
  2910. //--------------------------------------------------------------------------
  2911. function setSqlByDbType($sql="", $order_by="", $limit=""){
  2912. $sql_string = "";
  2913. switch($this->db_handler->phptype){
  2914. case "oci8": // oracle
  2915. if($limit != ""){
  2916. preg_match_all("/\d+/",$limit,$matches);
  2917. $limit_start = $matches[0][0];
  2918. $limit_size = $matches[0][1]-$limit_start;
  2919. $sql_string = $this->db_handler->modifyLimitQuery($sql." ".$order_by, $limit_start, $limit_size);
  2920. if($this->debug) echo "<table><tr><td><b>Oracle sql: </b>".$sql_string."</td></tr></table><br>";
  2921. }else{
  2922. $sql_string = $sql." ".$order_by;
  2923. }
  2924. break;
  2925. case "mssql": // mssql
  2926. //d (10.01.2008) $sql_string = "SELECT ".$limit." ".substr($sql, strpos("select", $this->strToLower($sql))+7, strlen($sql))." ".$order_by;
  2927. $from_index = strpos($this->strToLower($sql), "from ");
  2928. $prefix = substr($sql, 0, $from_index);
  2929. $suffix = substr($sql, $from_index);
  2930. $sql_string = $prefix.", Row_Number() over (ORDER BY ".$this->primary_key.") AS RowNumber ".$suffix;
  2931. $sql_string += " ".$limit." ".$order_by;
  2932. break;
  2933. case "mysql": // mysql and others
  2934. default:
  2935. $sql_string = $sql." ".$order_by." ".$limit;
  2936. break;
  2937. }
  2938. return $sql_string;
  2939. }
  2940. //--------------------------------------------------------------------------
  2941. // get LCASE function name by DB type
  2942. //--------------------------------------------------------------------------
  2943. function getLcaseFooByDbType(){
  2944. $lcase_name = "";
  2945. switch($this->db_handler->phptype){
  2946. case "oci8": // oracle
  2947. $lcase_name = "lower"; break;
  2948. case "mssql": // mssql
  2949. $lcase_name = "LCASE"; break;
  2950. case "pgsql": // pgsql
  2951. $lcase_name = "lower"; break;
  2952. case "mysql": // mysql and others
  2953. default:
  2954. $lcase_name = "LCASE"; break;
  2955. }
  2956. return $lcase_name;
  2957. }
  2958. //--------------------------------------------------------------------------
  2959. // paging function - part 1
  2960. //--------------------------------------------------------------------------
  2961. function pagingFirstPart(){
  2962. // (1) if we got a wrong number of page -> set page=1
  2963. $req_page_num = "";
  2964. $req_page_size = $this->getVariable('page_size');
  2965. $req_p = $this->getVariable('p');
  2966. if(($req_page_size != "") && ($req_page_size != 0)) $this->req_page_size = $req_page_size;
  2967. if($req_p != "") $req_page_num = $req_p;
  2968. if(is_numeric($req_page_num)){
  2969. if($req_page_num > 0) $this->page_current = $req_page_num;
  2970. else $this->page_current = 1;
  2971. }else{
  2972. $this->page_current = 1;
  2973. }
  2974. // (2) set pages_total & page_current vars for paging
  2975. if($this->rows_total > 0){
  2976. if(is_float($this->rows_total / $this->req_page_size))
  2977. $this->pages_total = intval(($this->rows_total / $this->req_page_size) + 1);
  2978. else
  2979. $this->pages_total = intval($this->rows_total / $this->req_page_size);
  2980. }else{
  2981. $this->pages_total = 0;
  2982. }
  2983. if($this->page_current > $this->pages_total) $this->page_current = $this->pages_total;
  2984. }
  2985. //--------------------------------------------------------------------------
  2986. // paging function - part 2
  2987. //--------------------------------------------------------------------------
  2988. function pagingSecondPart($lu_paging=false, $upper_br, $lower_br, $type="1"){
  2989. // (4) display paging line
  2990. $req_print = $this->getVariable('print');
  2991. if($req_print != true) {$a_tag = "a";} else {$a_tag = "span";};
  2992. $text = "";
  2993. if($this->pages_total >= 1){
  2994. $href_string = $this->combineUrl("view", "", "&");
  2995. $this->setUrlString($href_string, "filtering", "sorting", "");
  2996. $text .= "\n<script type='text/javascript'>\n<!--\n";
  2997. $text .= "function ".$this->unique_prefix."setPageSize".$type."(){document.location.href = '$href_string&".$this->unique_prefix."page_size='+document.frmPaging$this->unique_prefix".$type.".page_size".$type.".value;}";
  2998. $text .= "\n//-->\n</script>\n";
  2999. $href_string .= $this->amp.$this->unique_prefix."page_size=".$this->req_page_size;
  3000. $text .= "<form name='frmPaging$this->unique_prefix".$type."' id='frmPaging$this->unique_prefix".$type."' action='' style='MARGIN:0px; PADDING:5px; '>";
  3001. if($lu_paging['results'] || $lu_paging['pages'] || $lu_paging['page_size']){
  3002. if($upper_br) $text .= ""; //<br />
  3003. }
  3004. $text .= "<table class='".$this->css_class."_class_paging_table' dir='".$this->direction."' align='".$this->tblAlign[$this->mode]."' width='".$this->tblWidth[$this->mode]."' border='0' >";
  3005. $text .= "<tr><td align='".$lu_paging['results_align']."' class='class_nowrap'>";
  3006. if($lu_paging['results']){
  3007. $text .= "&nbsp;".$this->lang['results'].":&nbsp;";
  3008. if(($this->page_current * $this->req_page_size) <= $this->rows_total) $total = ($this->page_current * $this->req_page_size);
  3009. else $total = $this->rows_total;
  3010. $text .= ($this->page_current * $this->req_page_size - $this->req_page_size + 1)." - ".$total;
  3011. $text .= "&nbsp;".$this->lang['of']."&nbsp;";
  3012. $text .= $this->rows_total;
  3013. $text .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  3014. }
  3015. $text .= "</td><td align='".$lu_paging['pages_align']."' class='class_nowrap'>";
  3016. if($lu_paging['pages']){
  3017. $text .= "&nbsp;".$this->lang['pages'].":&nbsp;";
  3018. $href_prev1 = $href_prev2 = $href_first = "";
  3019. if($this->page_current > 1){
  3020. $href_prev1 = "href='$href_string".$this->amp.$this->unique_prefix."p=".($this->page_current - 1)."'";
  3021. $href_prev2 = "href='$href_string".$this->amp.$this->unique_prefix."p=".$this->page_current."'";
  3022. $href_first = "href='$href_string".$this->amp.$this->unique_prefix."p=1'";
  3023. }
  3024. $text .= "&nbsp;<".$a_tag." title='".$this->lang['first']."' class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' ".$href_first.">|<&lt;</".$a_tag.">";
  3025. 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.">&lt;&lt;</".$a_tag.">";
  3026. else $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' title='".$this->lang['previous']."' ".$href_prev2.">&lt;&lt;</".$a_tag.">";
  3027. $text .= "&nbsp;";
  3028. $low_window_ind = $this->page_current - 3;
  3029. $high_window_ind = $this->page_current + 3;
  3030. if($low_window_ind > 1){ $start_index = $low_window_ind; $text .= "..."; }
  3031. else $start_index = 1;
  3032. if($high_window_ind < $this->pages_total) $end_index = $high_window_ind;
  3033. else $end_index = $this->pages_total;
  3034. for($ind=$start_index; $ind <= $end_index; $ind++){
  3035. if($ind == $this->page_current) $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: underline;' title='".$this->lang['current']."' href='$href_string".$this->amp.$this->unique_prefix."p=".$ind."'><b><u>" . $ind . "</u></b></".$a_tag.">";
  3036. else $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' href='$href_string".$this->amp.$this->unique_prefix."p=".$ind."'>".$ind."</".$a_tag.">";
  3037. if($ind < $this->pages_total) $text .= ",&nbsp;";
  3038. else $text .= "&nbsp;";
  3039. }
  3040. if($high_window_ind < $this->pages_total) $text .= "...";
  3041. $href_next1 = $href_next2 = $href_last = "";
  3042. if($this->page_current < $this->pages_total){
  3043. $href_next1 = "href='$href_string".$this->amp.$this->unique_prefix."p=".($this->page_current + 1)."'";
  3044. $href_next2 = "href='$href_string".$this->amp.$this->unique_prefix."p=".$this->page_current."'";
  3045. $href_last = "href='$href_string".$this->amp.$this->unique_prefix."p=".$this->pages_total."'";
  3046. }
  3047. 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.">&gt;&gt;</".$a_tag.">";
  3048. else $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' title='".$this->lang['next']."' ".$href_next2.">&gt;&gt;</".$a_tag.">";
  3049. $text .= "&nbsp;<".$a_tag." class='".$this->css_class."_class_a' style='TEXT-DECORATION: none;' title='".$this->lang['last']."' ".$href_last.">&gt;>|</".$a_tag.">";
  3050. }
  3051. $text .= "</td><td align='".$lu_paging['page_size_align']."' class='class_nowrap'>";
  3052. if($lu_paging['page_size']){
  3053. $text .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  3054. $text .= "&nbsp;".$this->lang['page_size'].":&nbsp;";
  3055. $text .= $this->drawDropDownList('page_size'.$type, 'setPageSize'.$type.'()', $this->pages_array, $this->req_page_size);
  3056. }
  3057. $text .= "</td></tr>";
  3058. $text .= "</table>";
  3059. $text .= "</form>";
  3060. if($lu_paging['results'] || $lu_paging['pages'] || $lu_paging['page_size']){
  3061. if($lower_br) $text .= ""; //<br />
  3062. }
  3063. echo $text;
  3064. }else{
  3065. echo "<br /><br />";
  3066. }
  3067. }
  3068. //--------------------------------------------------------------------------
  3069. // function - set total number of rows in query
  3070. //--------------------------------------------------------------------------
  3071. function setTotalNumberRows($fsort = "", $limit = ""){
  3072. $req_mode = $this->getVariable('mode');
  3073. if(($req_mode == "edit") || ($req_mode == "details")){
  3074. // we need this stupid operation to get a total number of rows in our query
  3075. $this->data_set = & $this->db_handler->query($this->setSqlByDbType($this->sql, $fsort, $limit));
  3076. $this->rows_total = $this->numberRows();
  3077. }else{
  3078. $temp_sql = $this->setSqlByDbType($this->sql, "", "");
  3079. $from_pos = $this->lastSubStrOccurence($temp_sql, "from ");
  3080. $new_sql = "SELECT count(*) as cnt FROM ".substr($temp_sql, (int)(strlen($temp_sql) - $from_pos), (int)$from_pos);
  3081. $this->data_set = & $this->db_handler->query($new_sql);
  3082. if($this->db_handler->isError($this->data_set) == 1){
  3083. $this->rows_total = 0;
  3084. }else{
  3085. $row = $this->data_set->fetchRow();
  3086. $this->rows_total = $row[0];
  3087. }
  3088. }
  3089. }
  3090. //--------------------------------------------------------------------------
  3091. // function - number rows
  3092. //--------------------------------------------------------------------------
  3093. function numberRows(){
  3094. if($this->db_handler->isError($this->data_set)){
  3095. return 0;
  3096. }else{
  3097. return $this->data_set->numRows();
  3098. }
  3099. }
  3100. //--------------------------------------------------------------------------
  3101. // function - number columns
  3102. //--------------------------------------------------------------------------
  3103. function numberCols(){
  3104. if($this->db_handler->isError($this->data_set)){
  3105. return 0;
  3106. }else{
  3107. return $this->data_set->numCols();
  3108. }
  3109. }
  3110. //--------------------------------------------------------------------------
  3111. // function - no data found
  3112. //--------------------------------------------------------------------------
  3113. function noDataFound(){
  3114. $this->tblOpen();
  3115. $this->rowOpen(0, $this->rowColor[0]);
  3116. $add_column = 0;
  3117. if((isset($this->modes['add'][$this->mode]) && ($this->modes['add'][$this->mode])) ||
  3118. (isset($this->modes['edit'][$this->mode]) && ($this->modes['edit'][$this->mode]))
  3119. ) $add_column += 1;
  3120. if(isset($this->mode['delete']) && $this->mode['delete']) $add_column += 1;
  3121. $this->colOpen("center", (count($this->sorted_columns) + $add_column),"");
  3122. if($this->is_error){
  3123. echo "<br /><span class='".$this->css_class."_class_error_message no_print'>".$this->lang['no_data_found_error']."<br />&nbsp;";
  3124. if(!$this->debug){ echo "<br />".$this->lang['turn_on_debug_mode']."<br />&nbsp;"; }
  3125. echo "</span>";
  3126. }else{
  3127. echo "<br />".$this->lang['no_data_found']."<br />&nbsp;";
  3128. }
  3129. $this->colClose();
  3130. $this->rowClose();
  3131. $this->tblClose();
  3132. }
  3133. //--------------------------------------------------------------------------
  3134. // delete row
  3135. //--------------------------------------------------------------------------
  3136. function deleteRow($rid){
  3137. $this->rids = explode("-", $rid);
  3138. $sql = "DELETE FROM $this->tbl_name WHERE $this->primary_key IN ('-1' ";
  3139. foreach ($this->rids as $key){
  3140. $sql .= ", '".$key."' ";
  3141. }
  3142. $sql .= ");";
  3143. $this->db_handler->query($sql);
  3144. $affectedRows = $this->db_handler->affectedRows();
  3145. if($affectedRows > 0){
  3146. $this->act_msg = ($this->dg_messages['delete'] != "") ? $this->dg_messages['delete'] : $this->lang['deleting_operation_completed'];
  3147. }else{
  3148. $this->is_warning = true;
  3149. $this->act_msg = $this->lang['deleting_operation_uncompleted'];
  3150. }
  3151. 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 />";
  3152. if($this->debug) $this->act_msg .= " ".$this->lang['record_n']." ".$this->rid;
  3153. }
  3154. //--------------------------------------------------------------------------
  3155. // update row
  3156. //--------------------------------------------------------------------------
  3157. function updateRow($rid){
  3158. $unique_field_found = false;
  3159. $field_header = "";
  3160. $field_count = "0";
  3161. // check for unique fields
  3162. foreach($this->columns_edit_mode as $fldName => $fldValue){
  3163. if(($fldName != "") && ($this->getFieldProperty($fldName, "unique") == true)){
  3164. $field_prefix = "syy";
  3165. if(isset($fldValue['req_type'])){
  3166. if(strlen(trim($fldValue['req_type'])) == 3){ $field_prefix = $fldValue['req_type']; }
  3167. else if(strlen(trim($fldValue['req_type'])) == 2){ $field_prefix = $fldValue['req_type']."y"; }
  3168. }
  3169. $field_header = (isset($fldValue['header'])) ? $fldValue['header'] : $fldName;
  3170. $unique_condition = (isset($fldValue['unique_condition'])) ? trim($fldValue['unique_condition']) : "" ;
  3171. $field_value = (isset($_POST[$field_prefix.$fldName])) ? $_POST[$field_prefix.$fldName] : "";
  3172. $sql = "SELECT COUNT(*) as count FROM $this->tbl_name WHERE $this->primary_key <> '$rid' AND $fldName = '$field_value'";
  3173. if($unique_condition != "") $sql .= " AND ".$unique_condition." ";
  3174. if(($field_count = $this->selectSqlItem($sql)) > 0){
  3175. $unique_field_found = true;
  3176. break;
  3177. }
  3178. }
  3179. }
  3180. // create update statment
  3181. if(!$unique_field_found){
  3182. $sql = "UPDATE $this->tbl_name SET ";
  3183. $ind = 0;
  3184. $this->addCheckBoxesValues();
  3185. $max = count($_POST);
  3186. foreach($_POST as $fldName => $fldValue){
  3187. // update all fields, excepting uploading fields
  3188. if(!strpos($fldName, "file_act")){
  3189. $fldName = substr($fldName, 3, strlen($fldName));
  3190. $fldValue = $this->isDatePrepare($fldName,$fldValue);
  3191. if(!$this->isReadonly($fldName) && !$this->isValidator($fldName)){
  3192. if (intval($ind) >= 1) $sql .= ", ";
  3193. if($this->isText($fldName)){
  3194. $fldValue_new = $fldValue;
  3195. if(is_array($fldValue)){ // it was a multiple enum
  3196. $count = 0; $fldValue_new = "";
  3197. foreach ($fldValue as $val){ if($count++ > 0) $fldValue_new .= ","; $fldValue_new .= $val; }
  3198. }
  3199. $sql .= "$fldName = '".$this->setRealEscapeStringByDbType($fldValue_new)."' ";
  3200. }else{
  3201. $sql .= (trim($fldValue) != "") ? "$fldName = $fldValue " : "$fldName = 0 ";
  3202. }
  3203. //if ((intval($ind) === 0) && ($max > 1)) $sql .= ", ";
  3204. $ind++;
  3205. }
  3206. }
  3207. }
  3208. $sql .= " WHERE $this->primary_key = '$rid' ";
  3209. $this->db_handler->query($sql);
  3210. $affectedRows = $this->db_handler->affectedRows();
  3211. if($affectedRows >= 0){
  3212. $this->act_msg = ($this->dg_messages['update'] != "") ? $this->dg_messages['update'] : $this->lang['updating_operation_completed'];
  3213. }else{
  3214. $this->is_warning = true;
  3215. $this->act_msg = $this->lang['updating_operation_uncompleted'];
  3216. }
  3217. 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 />";
  3218. }else{
  3219. $this->is_warning = true;
  3220. $this->act_msg = str_replace("_FIELD_", $field_header, $this->lang['unique_field_error']);
  3221. 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 />";
  3222. }
  3223. if($this->debug) $this->act_msg .= " ".$this->lang['record_n']." ".$this->rid;
  3224. }
  3225. //--------------------------------------------------------------------------
  3226. // add row
  3227. //--------------------------------------------------------------------------
  3228. function addRow(){
  3229. $unique_field_found = false;
  3230. $field_header = "";
  3231. $field_count = "0";
  3232. // check for unique fields
  3233. foreach($this->columns_edit_mode as $fldName => $fldValue){
  3234. if(($fldName != "") && ($this->getFieldProperty($fldName, "unique") == true)){
  3235. $field_prefix = "syy";
  3236. if(isset($fldValue['req_type'])){
  3237. if(strlen(trim($fldValue['req_type'])) == 3){ $field_prefix = $fldValue['req_type']; }
  3238. else if(strlen(trim($fldValue['req_type'])) == 2){ $field_prefix = $fldValue['req_type']."y"; }
  3239. }
  3240. $field_header = (isset($fldValue['header'])) ? $fldValue['header'] : $fldName;
  3241. $unique_condition = (isset($fldValue['unique_condition'])) ? trim($fldValue['unique_condition']) : "" ;
  3242. $field_value = (isset($_POST[$field_prefix.$fldName])) ? $_POST[$field_prefix.$fldName] : "";
  3243. $sql = "SELECT COUNT(*) as count FROM $this->tbl_name WHERE $fldName = '$field_value' ";
  3244. if($unique_condition != "") $sql .= " AND ".$unique_condition." ";
  3245. if(($field_count = $this->selectSqlItem($sql)) > 0){
  3246. $unique_field_found = true;
  3247. break;
  3248. }
  3249. }
  3250. }
  3251. // create insert statment
  3252. if(!$unique_field_found){
  3253. $this->addCheckBoxesValues();
  3254. $sql = "INSERT INTO $this->tbl_name (";
  3255. $ind = 0;
  3256. $max = count($_POST);
  3257. foreach($_POST as $fldName => $fldValue){
  3258. $ind ++;
  3259. // all fields, excepting uploading fields
  3260. if(!strpos($fldName, "file_act")){
  3261. if(!$this->isValidator($fldName)){
  3262. $fldName = substr($fldName, 3, strlen($fldName));
  3263. $sql .= "$fldName";
  3264. if (intval($ind) < intval($max) ) $sql .= ", ";
  3265. }
  3266. }
  3267. }
  3268. $sql .= ") VALUES (";
  3269. $ind = 0;
  3270. $max = count($_POST);
  3271. foreach($_POST as $fldName => $fldValue){
  3272. $ind ++;
  3273. // all fields, excepting uploading fields
  3274. if(!strpos($fldName, "file_act")){
  3275. $fldName = substr($fldName, 3, strlen($fldName));
  3276. $fldValue = $this->isDatePrepare($fldName,$fldValue);
  3277. if(!$this->isValidator($fldName)){
  3278. if($this->isText($fldName)) {
  3279. if($fldValue != ""){
  3280. $fldValue_new = $fldValue;
  3281. if(is_array($fldValue)){ // it was a multiple enum
  3282. $count = 0; $fldValue_new = "";
  3283. foreach ($fldValue as $val){ if($count++ > 0) $fldValue_new .= ","; $fldValue_new .= $val; }
  3284. }
  3285. $sql .= "'".$this->setRealEscapeStringByDbType($fldValue_new)."'";
  3286. }else if($this->isFieldRequired($fldName)){
  3287. $sql .= "' '";
  3288. }else{
  3289. $sql .= "''";
  3290. }
  3291. }else{
  3292. if(trim($fldValue) != ""){
  3293. $sql .= $fldValue;
  3294. }else if($this->isFieldRequired($fldName)){
  3295. $sql .= '0';
  3296. }else{
  3297. $sql .= 'NULL';
  3298. }
  3299. }
  3300. if (intval($ind) < intval($max) ) $sql .= ", ";
  3301. }
  3302. }
  3303. }
  3304. $sql .= ") ";
  3305. $dSet = $this->db_handler->query($sql);
  3306. $affectedRows = $this->db_handler->affectedRows();
  3307. 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 />";
  3308. if($affectedRows > 0){
  3309. $this->act_msg = ($this->dg_messages['add'] != "") ? $this->dg_messages['add'] : $this->lang['adding_operation_completed'];
  3310. if($this->debug){
  3311. $res = $this->db_handler->query("SELECT MAX(".$this->primary_key.") as maximal_row FROM ".$this->tbl_name." ");
  3312. $row = $res->fetchRow();
  3313. $this->rid = $row[0];
  3314. $this->act_msg .= " ".$this->lang['record_n']." ".$this->rid;
  3315. }
  3316. }else{
  3317. $this->is_warning = true;
  3318. $this->act_msg = $this->lang['adding_operation_uncompleted'];
  3319. if($this->db_handler->isError($dSet) == 1){
  3320. $this->is_error = true;
  3321. $this->addErrors($dSet);
  3322. }
  3323. }
  3324. }else{
  3325. $this->is_warning = true;
  3326. $this->act_msg = str_replace("_FIELD_", $field_header, $this->lang['unique_field_error']);
  3327. 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 />";
  3328. }
  3329. $this->sql = "SELECT * FROM $this->tbl_name ";
  3330. $fsort = " ORDER BY " . $this->primary_key . " DESC";
  3331. $this->getDataSet($fsort);
  3332. }
  3333. //--------------------------------------------------------------------------
  3334. // get field offset
  3335. //--------------------------------------------------------------------------
  3336. function getFieldOffset($field_name){
  3337. if(!$this->is_error){
  3338. $fields = $this->data_set->tableInfo();
  3339. for($ind=0; $ind < $this->data_set->numCols(); $ind++){
  3340. if($fields[$ind]['name'] === $field_name) return $ind;
  3341. }
  3342. }
  3343. return -1;
  3344. }
  3345. //--------------------------------------------------------------------------
  3346. // is field required
  3347. //--------------------------------------------------------------------------
  3348. function isFieldRequired($field){
  3349. if(!$this->is_error){
  3350. $fields = $this->data_set->tableInfo();
  3351. if($this->getFieldOffset($field) != -1){
  3352. $flags = $fields[$this->getFieldOffset($field)]['flags'];
  3353. //echo $fields[$this->getFieldOffset($field)]['type']." ".$flags."<br />";
  3354. if(strstr(strtolower($flags), "not_null")){
  3355. return true;
  3356. }
  3357. }
  3358. }
  3359. return false;
  3360. }
  3361. //--------------------------------------------------------------------------
  3362. // get field info
  3363. //--------------------------------------------------------------------------
  3364. function getFieldInfo($field, $parameter='', $type=0){
  3365. if(!$this->is_error){
  3366. $fields = $this->data_set->tableInfo();
  3367. if($type == 0){
  3368. if($this->getFieldOffset($field) != -1)
  3369. return $fields[$this->getFieldOffset($field)][$parameter];
  3370. else
  3371. return '';
  3372. }else{
  3373. return $fields[$field][$parameter];
  3374. }
  3375. }
  3376. return -1;
  3377. }
  3378. //--------------------------------------------------------------------------
  3379. // set Datetime field in right format (dd-mm-yyyy)|(yyyy-mm-dd)
  3380. //--------------------------------------------------------------------------
  3381. function isDatePrepare($field_name, $fldValue){
  3382. $field_property_type = $this->getFieldProperty($field_name, "type");
  3383. switch ($field_property_type){
  3384. case 'date': // date: DATE
  3385. case 'datetime': // date: DATE
  3386. break;
  3387. case 'datetimedmy': // date: DATETIME
  3388. $time1 = substr(trim($fldValue), 10, 9);
  3389. $year1 = substr(trim($fldValue), 6, 4);
  3390. $month1 = substr(trim($fldValue), 3, 2);
  3391. $day1 = substr(trim($fldValue), 0, 2);
  3392. $fldValue = $year1."-".$month1."-".$day1." ".$time1;
  3393. break;
  3394. case 'datedmy': // date: DATE
  3395. $year1 = substr(trim($fldValue), 6, 4);
  3396. $month1 = substr(trim($fldValue), 3, 2);
  3397. $day1 = substr(trim($fldValue), 0, 2);
  3398. $fldValue = $year1."-".$month1."-".$day1;
  3399. break;
  3400. default:
  3401. break;
  3402. }
  3403. return $fldValue;
  3404. }
  3405. //--------------------------------------------------------------------------
  3406. // check if field type needs ''(text) or not (numeric...)
  3407. //--------------------------------------------------------------------------
  3408. function isText($field_name){
  3409. $field_type = $this->getFieldInfo($field_name, 'type', 0);
  3410. $result = true;
  3411. switch (strtolower($field_type)){
  3412. case 'int': // int: TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER, BIGINT, TINY, SHORT, LONG, LONGLONG, INT24
  3413. case 'real': // real: FLOAT, DOUBLE, DECIMAL, NUMERIC
  3414. case 'null': // empty: NULL
  3415. $result = false; break;
  3416. case 'string': // string: CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, ENUM, SET, VAR_STRING
  3417. case 'blob': // blob: TINYBLOB, MEDIUMBLOB, LONGBLOB, BLOB, TEXT
  3418. case 'date': // date: DATE
  3419. case 'timestamp': // date: TIMESTAMP
  3420. case 'year': // date: YEAR
  3421. case 'time': // date: TIME
  3422. case 'datetime': // date: DATETIME
  3423. $result = true; break;
  3424. default:
  3425. $result = true; break;
  3426. }
  3427. return $result;
  3428. }
  3429. //--------------------------------------------------------------------------
  3430. // check if field type is a date/time type
  3431. //--------------------------------------------------------------------------
  3432. function isDate($field_name){
  3433. $field_type = $this->getFieldInfo($field_name, 'type', 0);
  3434. $result = false;
  3435. switch (strtolower($field_type)){
  3436. case 'date': // date: DATE
  3437. case 'timestamp': // date: TIMESTAMP
  3438. case 'year': // date: YEAR
  3439. case 'time': // date: TIME
  3440. case 'datetime': // date: DATETIME
  3441. $result = true; break;
  3442. default:
  3443. $result = false; break;
  3444. }
  3445. return $result;
  3446. }
  3447. //--------------------------------------------------------------------------
  3448. // check if a field is readonly
  3449. //--------------------------------------------------------------------------
  3450. function isReadonly($field_name){
  3451. $field_property_readonly = $this->getFieldProperty($field_name, "readonly");
  3452. if($field_property_readonly == true){
  3453. return true;
  3454. }else{
  3455. return false;
  3456. }
  3457. }
  3458. //--------------------------------------------------------------------------
  3459. // check if a field is validator
  3460. //--------------------------------------------------------------------------
  3461. function isValidator($field_name){
  3462. $field_property_type = $this->getFieldProperty($field_name, "type");
  3463. if($field_property_type == "validator"){
  3464. return true;
  3465. }else{
  3466. return false;
  3467. }
  3468. }
  3469. //--------------------------------------------------------------------------
  3470. // check if a field is a foreign key
  3471. //--------------------------------------------------------------------------
  3472. function isForeignKey($field_name){
  3473. if(array_key_exists($field_name, $this->foreign_keys_array)){
  3474. return true;
  3475. }
  3476. return false;
  3477. }
  3478. //--------------------------------------------------------------------------
  3479. // get foreign key input
  3480. //--------------------------------------------------------------------------
  3481. function getForeignKeyInput($keyFieldValue, $fk_field_name, $fk_field_value, $mode="edit"){
  3482. $req_mode = $this->getVariable('mode');
  3483. // check if foreign key field is readonly or disabled
  3484. $readonly = "";
  3485. $disabled = "";
  3486. $field_property_readonly = $this->getFieldProperty($fk_field_name, "readonly");
  3487. $field_property_radiobuttons_alignment = $this->getFieldProperty($fk_field_name, "radiobuttons_alignment");
  3488. if($req_mode == "edit"){
  3489. if($field_property_readonly == true){
  3490. $disabled = "disabled"; //$readonly = "readonly='readonly'";
  3491. }
  3492. }
  3493. $sql = " SELECT ".$fk_field_name;
  3494. $sql .= " FROM ".$this->tbl_name;
  3495. $sql .= " WHERE ".$this->primary_key." = '".$keyFieldValue."' ";
  3496. $this->db_handler->setFetchMode(DB_FETCHMODE_ASSOC);
  3497. $dSet = $this->db_handler->query($sql);
  3498. if($dSet->numRows() > 0){
  3499. $row = $dSet->fetchRow();
  3500. $kFieldValue = $row[$fk_field_name];
  3501. }else{
  3502. $kFieldValue = -1;
  3503. }
  3504. // select from outer table
  3505. $sql = " SELECT ".$this->foreign_keys_array[$fk_field_name]['field_key'].",".$this->foreign_keys_array[$fk_field_name]['field_name'].", ".$this->foreign_keys_array[$fk_field_name]['table'].".* ";
  3506. $sql .= " FROM ".$this->foreign_keys_array[$fk_field_name]['table'] ;
  3507. $sql .= " WHERE 1=1 ";
  3508. if($mode !== "edit"){
  3509. $sql .= " AND " .$this->foreign_keys_array[$fk_field_name]['field_key']."='".$kFieldValue."'";
  3510. }
  3511. if(isset($this->foreign_keys_array[$fk_field_name]['condition']) && ($this->foreign_keys_array[$fk_field_name]['condition'] != "")){
  3512. $sql .= " AND " .$this->foreign_keys_array[$fk_field_name]['condition'];
  3513. }
  3514. // define sorting order
  3515. if(isset($this->foreign_keys_array[$fk_field_name]['order_by_field']) && ($this->foreign_keys_array[$fk_field_name]['order_by_field'] != "")){
  3516. $order_by_field = $this->foreign_keys_array[$fk_field_name]['order_by_field'];
  3517. }else{
  3518. $order_by_field = $this->foreign_keys_array[$fk_field_name]['field_key'];
  3519. }
  3520. // define sorting type
  3521. if(isset($this->foreign_keys_array[$fk_field_name]['order_type']) && ($this->foreign_keys_array[$fk_field_name]['order_type'] != "")){
  3522. $order_type = $this->foreign_keys_array[$fk_field_name]['order_type'];
  3523. }else{
  3524. $order_type = "ASC";
  3525. }
  3526. $sql .= " ORDER BY ".$order_by_field." ".$order_type;
  3527. $dSet = $this->db_handler->query($sql);
  3528. if($this->db_handler->isError($dSet) == 1){
  3529. $this->is_error = true;
  3530. $this->addErrors($dSet);
  3531. }
  3532. if($this->debug){
  3533. if($this->db_handler->isError($dSet) == 1){
  3534. $num_rows = 0;
  3535. }else{
  3536. $num_rows = $dSet->numRows();
  3537. }
  3538. 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 />";
  3539. }
  3540. if($mode === "edit"){
  3541. // save entered values from fields in add/edit modes
  3542. $req_field_value = $this->getVariable($this->getFieldRequiredType($fk_field_name).$fk_field_name, false, "post");
  3543. $on_js_event = (isset($this->foreign_keys_array[$fk_field_name]['on_js_event'])) ? $this->foreign_keys_array[$fk_field_name]['on_js_event'] : "";
  3544. $view_type = (isset($this->foreign_keys_array[$fk_field_name]['view_type'])) ? $this->foreign_keys_array[$fk_field_name]['view_type'] : "";
  3545. if($view_type == "textbox"){ //'view_type"=>"textbox"
  3546. while($row = $dSet->fetchRow()){
  3547. if($row[$this->foreign_keys_array[$fk_field_name]['field_key']] === $kFieldValue){
  3548. $kFieldValue = $row[$this->foreign_keys_array[$fk_field_name]['field_name']];
  3549. $kFieldValue = str_replace('"', "&quot;", $kFieldValue); // double quotation mark
  3550. $kFieldValue = str_replace("'", "&#039;", $kFieldValue); // single quotation mark
  3551. }
  3552. }
  3553. 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.">";
  3554. }else if($view_type == "radiobutton"){ //'view_type"=>"radiobutton"
  3555. 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);
  3556. }else { //'view_type"=>"dropdownlist" - default
  3557. $req_field_name = $this->getVariable($this->getFieldRequiredType($fk_field_name).$fk_field_name, false, "post");
  3558. if($req_mode == "add"){
  3559. if($req_field_name != "") $req_field_value = $req_field_value;
  3560. else $req_field_value = $this->getFieldProperty($fk_field_name, "default");
  3561. }else {
  3562. if($req_field_name != "") $req_field_value = $req_field_value;
  3563. else $req_field_value = $fk_field_value;
  3564. }
  3565. 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);
  3566. }
  3567. }else{
  3568. $row = $dSet->fetchRow();
  3569. $ff_name = $this->foreign_keys_array[$fk_field_name]['field_name'];
  3570. if (eregi(" as ", strtolower($ff_name))) $ff_name = substr($ff_name, strpos(strtolower($ff_name), " as ")+4);
  3571. return $this->nbsp.$row[$ff_name].$this->nbsp;
  3572. }
  3573. }
  3574. ////////////////////////////////////////////////////////////////////////////
  3575. // URL string creating
  3576. ////////////////////////////////////////////////////////////////////////////
  3577. //--------------------------------------------------------------------------
  3578. // setUrl
  3579. //--------------------------------------------------------------------------
  3580. function setUrlString(&$curr_url, $filtering = "", $sorting = "", $paging ="", $amp=""){
  3581. $amp = ($amp != "") ? $amp : $this->amp;
  3582. if($filtering != "") $this->setUrlStringFiltering($curr_url, $amp);
  3583. if($sorting != "") $this->setUrlStringSorting($curr_url, $amp);
  3584. if($paging != "") $this->setUrlStringPaging($curr_url, $amp);
  3585. }
  3586. //--------------------------------------------------------------------------
  3587. // setUrlString Filtering
  3588. //--------------------------------------------------------------------------
  3589. function setUrlStringFiltering(&$curr_url, $amp=""){
  3590. $amp = ($amp != "") ? $amp : $this->amp;
  3591. $req_onSUBMIT_FILTER = $this->getVariable('_ff_onSUBMIT_FILTER');
  3592. if($this->filtering_allowed){
  3593. foreach($this->filter_fields as $fldField){
  3594. $table_field_name = "".$fldField['table']."_".$fldField['field'];
  3595. if(isset($_REQUEST[$this->unique_prefix."_ff_".$table_field_name]) AND ($_REQUEST[$this->unique_prefix."_ff_".$table_field_name] != "")){
  3596. $curr_url .= $amp.$this->unique_prefix."_ff_".$fldField['table'].'_'.$fldField['field']."=".urlencode($_REQUEST[$this->unique_prefix."_ff_".$table_field_name])."";
  3597. }
  3598. $table_field_name_operator = "".$fldField['table']."_".$fldField['field']."_operator";
  3599. if(isset($_REQUEST[$this->unique_prefix."_ff_".$table_field_name_operator]) AND ($_REQUEST[$this->unique_prefix."_ff_".$table_field_name_operator] != "")){
  3600. $curr_url .= $amp.$this->unique_prefix."_ff_".$fldField['table'].'_'.$fldField['field']."_operator=".urlencode($_REQUEST[$this->unique_prefix."_ff_".$table_field_name_operator])."";
  3601. }
  3602. }
  3603. if(isset($_REQUEST[$this->unique_prefix."_ff_".'selSearchType']) && (trim($_REQUEST[$this->unique_prefix."_ff_".'selSearchType']) != ""))
  3604. $curr_url .= $amp.$this->unique_prefix."_ff_"."selSearchType=".urlencode($_REQUEST[$this->unique_prefix."_ff_".'selSearchType'])."";
  3605. if($req_onSUBMIT_FILTER != "")
  3606. $curr_url .= $amp.$this->unique_prefix."_ff_"."onSUBMIT_FILTER=search";
  3607. }
  3608. }
  3609. //--------------------------------------------------------------------------
  3610. // setUrlString Sorting
  3611. //--------------------------------------------------------------------------
  3612. function setUrlStringSorting(&$curr_url, $amp=""){
  3613. $amp = ($amp != "") ? $amp : $this->amp;
  3614. $sort_field = $this->getVariable('sort_field');
  3615. $sort_field_by = $this->getVariable('sort_field_by');
  3616. $sort_type = $this->getVariable('sort_type');
  3617. if($sort_field != "") {
  3618. $this->sort_field = $sort_field;
  3619. $this->sort_field_by = $sort_field_by;
  3620. $curr_url .= $amp.$this->unique_prefix."sort_field=".$this->sort_field.$amp.$this->unique_prefix."sort_field_by=".$this->sort_field_by;
  3621. }else {
  3622. if(!is_numeric($this->default_sort_field[0])){ $this->default_sort_field[0] = $this->getFieldOffset($this->default_sort_field[0]) + 1; }
  3623. $curr_url .= $amp.$this->unique_prefix."sort_field=".$this->default_sort_field[0];
  3624. }; // make pKey
  3625. if($sort_type != "") {
  3626. $this->sort_type = $sort_type;
  3627. $curr_url .= $amp.$this->unique_prefix."sort_type=".$this->sort_type;
  3628. } else {
  3629. $curr_url .= $amp.$this->unique_prefix."sort_type=".$this->default_sort_type[0];
  3630. };
  3631. }
  3632. //--------------------------------------------------------------------------
  3633. // setUrlString Pading
  3634. //--------------------------------------------------------------------------
  3635. function setUrlStringPaging(&$curr_url, $amp=""){
  3636. $amp = ($amp != "") ? $amp : $this->amp;
  3637. $page_size = $this->getVariable('page_size');
  3638. $p = $this->getVariable('p');
  3639. if($this->layouts['edit'] == "0"){
  3640. if($page_size != ""){
  3641. $this->req_page_size = $_REQUEST[$this->unique_prefix.'page_size'];
  3642. $curr_url .= $amp.$this->unique_prefix."page_size=".$this->req_page_size;
  3643. }else{
  3644. $curr_url .= $amp.$this->unique_prefix."page_size=".$this->req_page_size;
  3645. }
  3646. }else{
  3647. if($this->mode === "view"){
  3648. $curr_url .= $amp.$this->unique_prefix."page_size=".$this->req_page_size;
  3649. }else{
  3650. if(isset($_REQUEST[$this->unique_prefix.'page_size'])) $this->req_page_size = $_REQUEST[$this->unique_prefix.'page_size'];
  3651. $curr_url .= $amp.$this->unique_prefix."page_size=".$this->req_page_size;
  3652. }
  3653. }
  3654. if($p != "") {
  3655. $this->page_current = $_REQUEST[$this->unique_prefix.'p'];
  3656. $curr_url .= $amp.$this->unique_prefix."p=".$this->page_current;
  3657. }else {
  3658. $this->page_current = 1;
  3659. $curr_url .= $amp.$this->unique_prefix."p=1";
  3660. };
  3661. }
  3662. ////////////////////////////////////////////////////////////////////////////
  3663. // View & Edit mode methods
  3664. ////////////////////////////////////////////////////////////////////////////
  3665. //--------------------------------------------------------------------------
  3666. // get enum values
  3667. //--------------------------------------------------------------------------
  3668. function getEnumValues( $table , $field ){
  3669. $enum_array = "";
  3670. $query = " SHOW COLUMNS FROM $table LIKE '$field' ";
  3671. $this->db_handler->setFetchMode(DB_FETCHMODE_ORDERED);
  3672. $result = $this->db_handler->query($query);
  3673. if($row = $result->fetchRow()){
  3674. // extract the values, the values are enclosed in single quotes and separated by commas
  3675. $regex = "/'(.*?)'/";
  3676. preg_match_all( $regex , $row[1], $enum_array );
  3677. $temp_enum_fields = $enum_array[1];
  3678. $enum_fields = array();
  3679. foreach($temp_enum_fields as $key => $val){
  3680. $enum_fields[$val] = $val;
  3681. }
  3682. return $enum_fields ;
  3683. }else{
  3684. return array();
  3685. }
  3686. }
  3687. //--------------------------------------------------------------------------
  3688. // check if field exists & can be viewed
  3689. //--------------------------------------------------------------------------
  3690. function canViewField($field_name){
  3691. $field_property_visible = $this->getFieldProperty($field_name, "visible", $this->mode, "lower", "true");
  3692. if($this->mode === "view"){
  3693. if(array_key_exists($field_name, $this->columns_view_mode) && ($field_property_visible == true)) return true;
  3694. }else if($this->mode === "edit"){
  3695. if(array_key_exists($field_name, $this->columns_edit_mode) && ($field_property_visible == true)) return true;
  3696. }else if($this->mode === "details"){
  3697. if(array_key_exists($field_name, $this->columns_edit_mode) && ($field_property_visible == true)) return true;
  3698. }
  3699. return false;
  3700. }
  3701. //--------------------------------------------------------------------------
  3702. // check if field exists & can be viewed
  3703. //--------------------------------------------------------------------------
  3704. function getHeaderName($field_name, $force_simple = false){
  3705. $force_simple = (($force_simple == true) || ($force_simple == "true")) ? true : false ;
  3706. if($this->mode === "view"){
  3707. if(array_key_exists($field_name, $this->columns_view_mode) && isset($this->columns_view_mode[$field_name]['header']))
  3708. return $this->columns_view_mode[$field_name]['header'];
  3709. }else if($this->mode === "edit"){
  3710. $field_property_header = $this->getFieldProperty($field_name, "header");
  3711. if(array_key_exists($field_name, $this->columns_edit_mode) && ($field_property_header != "")){
  3712. if((substr($this->getFieldRequiredType($field_name), 0, 1) == "r") && (!$force_simple)){
  3713. return "<font color='#cd0000'>*</font> ".ucfirst($field_property_header);
  3714. }else{
  3715. return $field_property_header;
  3716. }
  3717. }
  3718. }else if($this->mode === "details"){
  3719. $field_property_header = $this->getFieldProperty($field_name, "header");
  3720. if(array_key_exists($field_name, $this->columns_edit_mode) && ($field_property_header != "")){
  3721. return $field_property_header;
  3722. }
  3723. }
  3724. return $field_name;
  3725. }
  3726. //--------------------------------------------------------------------------
  3727. // Returns field name
  3728. //--------------------------------------------------------------------------
  3729. function getFieldName($field_offset){
  3730. if(!$this->is_error){
  3731. $fields = $this->data_set->tableInfo();
  3732. $field_name = isset($fields[$field_offset]['name']) ? $fields[$field_offset]['name'] : "";
  3733. if($field_name) return $field_name;
  3734. }
  3735. return $field_offset;
  3736. }
  3737. //--------------------------------------------------------------------------
  3738. // get Field Required Type
  3739. //--------------------------------------------------------------------------
  3740. function getFieldRequiredType($field_name){
  3741. $field_prefix = "syy";
  3742. $field_req_type = trim($this->getFieldProperty($field_name, "req_type"));
  3743. if($field_req_type != ""){
  3744. if(strlen($field_req_type) == 3){ $field_prefix = $field_req_type; }
  3745. else if(strlen($field_req_type) == 2){
  3746. $field_prefix = $field_req_type."y";
  3747. }
  3748. }
  3749. return $field_prefix;
  3750. }
  3751. //--------------------------------------------------------------------------
  3752. // get Field Property
  3753. //--------------------------------------------------------------------------
  3754. function getFieldProperty($field_name, $property_name, $mode = "edit", $case = "lower", $return_value = ""){
  3755. switch($mode){
  3756. case "view":
  3757. if(isset($this->columns_view_mode[$field_name][$property_name])){
  3758. if($case === "lower") {
  3759. $return_value = strtolower($this->columns_view_mode[$field_name][$property_name]);
  3760. } else {
  3761. $return_value = $this->columns_view_mode[$field_name][$property_name];
  3762. }
  3763. }
  3764. break;
  3765. case "edit":
  3766. default:
  3767. if(isset($this->columns_edit_mode[$field_name][$property_name])){
  3768. if($case === "lower") {
  3769. if(is_array($this->columns_edit_mode[$field_name][$property_name])){
  3770. return $this->columns_edit_mode[$field_name][$property_name];
  3771. }else{
  3772. $return_value = strtolower($this->columns_edit_mode[$field_name][$property_name]);
  3773. }
  3774. } else {
  3775. $return_value = $this->columns_edit_mode[$field_name][$property_name];
  3776. }
  3777. }
  3778. break;
  3779. }
  3780. if($return_value == "true"){
  3781. $return_value = true;
  3782. }else if($return_value == "false"){
  3783. $return_value = false;
  3784. }
  3785. return $return_value;
  3786. }
  3787. //--------------------------------------------------------------------------
  3788. // get Field Title
  3789. //--------------------------------------------------------------------------
  3790. function getFieldTitle($field_name, $mode="edit"){
  3791. $field_title = $this->getFieldProperty($field_name, "title", $mode, "");
  3792. if($field_title === ""){
  3793. $field_header = $this->getFieldProperty($field_name, "header", $mode);
  3794. if($field_header === ""){
  3795. return $field_name;
  3796. }else{
  3797. return str_replace("'", "&#039;", $field_header);
  3798. }
  3799. }else{
  3800. return $field_title;
  3801. }
  3802. }
  3803. //--------------------------------------------------------------------------
  3804. // get Field Alignment
  3805. //--------------------------------------------------------------------------
  3806. function getFieldAlign($ind, $row, $mode="view"){
  3807. $field_name = $this->getFieldName($ind);
  3808. $field_align = $this->getFieldProperty($field_name, "align", $mode);
  3809. if(($mode == "view") && isset($this->columns_view_mode[$field_name]['align'])){
  3810. return $this->columns_view_mode[$field_name]['align'];
  3811. }else if(($mode != "view") && ($field_align != "")){
  3812. return $field_align;
  3813. }else{
  3814. if(isset($row[$ind]) && $this->isText($field_name)){
  3815. return ($this->direction == "ltr")?"left":"right";
  3816. }else{
  3817. return ($this->direction == "ltr")?"right":"left";
  3818. }
  3819. }
  3820. }
  3821. //--------------------------------------------------------------------------
  3822. // get Field Value By Type
  3823. //--------------------------------------------------------------------------
  3824. function getFieldValueByType($field_value, $ind, $row, $field_name=""){
  3825. // Un-quote string quoted by mysql_real_escape_string()
  3826. if(get_magic_quotes_gpc()) {
  3827. if(ini_get('magic_quotes_sybase')) {
  3828. $field_value = str_replace("''", "'", $field_value);
  3829. } else {
  3830. $field_value = stripslashes($field_value);
  3831. }
  3832. }
  3833. $req_print = $this->getVariable('print');
  3834. $req_mode = $this->getVariable('mode');
  3835. if($field_name == "") $field_name = $this->getFieldName($ind);
  3836. // -= VIEW MODE =-
  3837. if($this->mode === "view"){
  3838. $fp_tooltip = $this->getFieldProperty($field_name, "tooltip", "view");
  3839. $fp_tooltip_type = $this->getFieldProperty($field_name, "tooltip_type", "view");
  3840. $field_property_pre_addition = $this->getFieldProperty($field_name, "pre_addition", "view");
  3841. $field_property_post_addition = $this->getFieldProperty($field_name, "post_addition", "view");
  3842. $title = "";
  3843. if(isset($this->columns_view_mode[$field_name]['text_length']) && ($this->columns_view_mode[$field_name]['text_length'] != "-1") && ($field_value != "")){
  3844. if((strlen($field_value)) > $this->columns_view_mode[$field_name]['text_length']){
  3845. $field_value = str_replace('"', "&quot;", $field_value); // double quotation mark
  3846. $field_value = str_replace("'", "&#039;", $field_value); // single quotation mark
  3847. $field_value = str_replace(chr(13), "", $field_value); // CR sign
  3848. $field_value = str_replace(chr(10), " ", $field_value); // LF sign
  3849. if($req_print != true){
  3850. if(($fp_tooltip == true) || ($fp_tooltip == "true")){
  3851. if($fp_tooltip_type == "floating"){
  3852. $title = " onmouseover=\"return overlib('".$field_value."');\" onmouseout='return nd();' style='cursor: help;'";
  3853. }else{
  3854. $title = "title='".$field_value."' style='cursor: help;'";
  3855. }
  3856. }
  3857. }
  3858. $field_value = substr($field_value, 0, $this->columns_view_mode[$field_name]['text_length'])."...";
  3859. }
  3860. }
  3861. if(array_key_exists($field_name, $this->columns_view_mode)){
  3862. if(!isset($this->columns_view_mode[$field_name]['type'])) $field_type = "label";
  3863. else $field_type = $this->columns_view_mode[$field_name]['type'];
  3864. // format case of field value
  3865. if(!isset($this->columns_view_mode[$field_name]['case'])){
  3866. $field_value = $field_value;
  3867. }else if(strtolower($this->columns_view_mode[$field_name]['case']) == "upper"){
  3868. $field_value = strtoupper($field_value);
  3869. }else if(strtolower($this->columns_view_mode[$field_name]['case']) == "lower") {
  3870. $field_value = $this->strToLower($field_value);
  3871. }
  3872. if($req_print == true){ $field_type = "label"; }
  3873. $on_js_event = (isset($this->columns_view_mode[$field_name]['on_js_event']))?$this->columns_view_mode[$field_name]['on_js_event']:"";
  3874. switch($field_type){
  3875. case "barchart":
  3876. $field = (isset($this->columns_view_mode[$field_name]['field']) ? $this->columns_view_mode[$field_name]['field'] : "");
  3877. if(($field != "") && ($this->getFieldOffset($field) != -1)) $field_value = $row[$this->getFieldOffset($field)];
  3878. $maximum_value = (isset($this->columns_view_mode[$field_name]['maximum_value']) ? $this->columns_view_mode[$field_name]['maximum_value'] : "");
  3879. $barchart_result ="
  3880. <table width='110px;' bgcolor='##0000ff' height='10px' align='center' cellpadding='0' cellspacing='0' ".$on_js_event.">
  3881. <tr title='".$field_value."'>
  3882. <td style='FONT-SIZE:9px;' align='center' width='".($field_value/$maximum_value * 100)."px' bgcolor='#ff0000' class='class_nowrap'>
  3883. ".(($field_value > 0) ? $field_value : "")."
  3884. </td>
  3885. <td style='FONT-SIZE:9px;' width='".(100 - ($field_value/$maximum_value * 100))."px' align='center' class='class_nowrap'>
  3886. ".(($field_value == 0) ? $field_value : "")."
  3887. </td>
  3888. </tr>
  3889. </table>
  3890. ";
  3891. return $barchart_result;
  3892. break;
  3893. case "image":
  3894. $img_align = (isset($this->columns_view_mode[$field_name]['align']) ? $this->columns_view_mode[$field_name]['align'] : "center");
  3895. $img_target_path = (isset($this->columns_view_mode[$field_name]['target_path']) ? $this->columns_view_mode[$field_name]['target_path'] : "");
  3896. $img_width = (isset($this->columns_view_mode[$field_name]['image_width']) ? $this->columns_view_mode[$field_name]['image_width'] : "50px");
  3897. $img_height = (isset($this->columns_view_mode[$field_name]['image_height']) ? $this->columns_view_mode[$field_name]['image_height'] : "30px");
  3898. if(isset($this->columns_view_mode[$field_name]['default']) && ($this->columns_view_mode[$field_name]['default'] != "")){
  3899. if(file_exists($img_target_path.trim($this->columns_view_mode[$field_name]['default']))){
  3900. $img_default = "<img src='".$img_target_path.$this->columns_view_mode[$field_name]['default']."' width='".$img_width."' height='".$img_height."' alt='' title='' ".$on_js_event." />";
  3901. }else{
  3902. $img_default = "<span class='".$this->css_class."_class_label' ".$on_js_event.">".$this->lang['no_image']."</span>";
  3903. }
  3904. }else{
  3905. $img_default = "";
  3906. }
  3907. if((trim($field_value) !== "") && file_exists($img_target_path.trim($field_value))){
  3908. return $this->nbsp."<img src='".$img_target_path.trim($field_value)."' border='1' width='".$img_width."' height='".$img_height."' align='middle' ".$on_js_event." />".$this->nbsp;
  3909. }else{
  3910. return "<table align='".$img_align."' style='BORDER: solid 0px #000000;' width='".$img_width."' height='".$img_height."'><tr><td align='".$img_align."'>".$img_default."</td></tr></table>";
  3911. }
  3912. break;
  3913. case "label":
  3914. if((trim($field_value) != "")
  3915. // we need this for right handling wysiwyg editor values
  3916. && (trim($this->strToLower($field_value)) !== "<pre></pre>")
  3917. && (trim($this->strToLower($field_value)) !== "<pre>".$this->nbsp."</pre>")
  3918. && (trim($this->strToLower($field_value)) !== "<p></p>")
  3919. && (trim($this->strToLower($field_value)) !== "<p>".$this->nbsp."</p>")){
  3920. 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;
  3921. }else{
  3922. return "&nbsp;&nbsp;";
  3923. }
  3924. break;
  3925. case "link":
  3926. case "linkbutton":
  3927. if(isset($this->columns_view_mode[$field_name]['field_data']) && (trim($this->columns_view_mode[$field_name]['field_data']) != "")){
  3928. $rel = (isset($this->columns_view_mode[$field_name]['rel'])) ? "rel=".$this->columns_view_mode[$field_name]['rel'] : "";
  3929. $title = $this->getFieldTitle($field_name, "view");
  3930. $href_inner = (isset($this->columns_view_mode[$field_name]['href']))?$this->columns_view_mode[$field_name]['href']:"";
  3931. $target_inner = (isset($this->columns_view_mode[$field_name]['target']))?$this->columns_view_mode[$field_name]['target']:"";
  3932. $href = $href_inner;
  3933. foreach ($this->columns_view_mode[$field_name] as $search_field_key => $search_field_value){
  3934. if(substr($search_field_key, 0, 9) == "field_key"){
  3935. $field_number = intval(substr($search_field_key, 10, strlen($search_field_key) - 10));
  3936. $field_inner = $row[$this->getFieldOffset($search_field_value)];
  3937. if(strpos($href_inner, "{".$field_number."}") >= 0){
  3938. $href = str_replace("{".$field_number."}", $field_inner, $href);
  3939. }
  3940. }
  3941. }
  3942. // remove unexpected 'http://'s
  3943. if(strstr($href_inner, "http://") != ""){
  3944. $href = str_replace("http://", "", $href);
  3945. $href = "http://".$href;
  3946. }
  3947. return $this->nbsp."<a class='".$this->css_class."_class_a2' href='".$href."' target='".$target_inner."' ".$rel." title='".$title."' ".$on_js_event.">".trim($row[$this->getFieldOffset($this->columns_view_mode[$field_name]['field_data'])])."</a>".$this->nbsp;
  3948. }else{
  3949. return $this->nbsp;
  3950. }
  3951. break;
  3952. case "linktoview";
  3953. $curr_url = $this->combineUrl("details", intval($row[(($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0)]));
  3954. $this->setUrlStringPaging($curr_url);
  3955. $this->setUrlStringSorting($curr_url);
  3956. $this->setUrlStringFiltering($curr_url);
  3957. return $this->nbsp."<a class='".$this->css_class."_class_a' href='$curr_url' ".$title." ".$on_js_event.">".trim($field_value)."</a>".$this->nbsp;
  3958. break;
  3959. case "linktoedit";
  3960. $curr_url = $this->combineUrl("edit", intval($row[(($this->getFieldOffset($this->primary_key) != -1) ? $this->getFieldOffset($this->primary_key) : 0)]));
  3961. $this->setUrlStringPaging($curr_url);
  3962. $this->setUrlStringSorting($curr_url);
  3963. $this->setUrlStringFiltering($curr_url);
  3964. return $this->nbsp."<a class='".$this->css_class."_class_a' href='$curr_url' ".$title." ".$on_js_event.">".trim($field_value)."</a>".$this->nbsp;
  3965. break;
  3966. case "password":
  3967. return $this->nbsp."<label class='".$this->css_class."_class_label' ".$title." ".$on_js_event.">******</label>".$this->nbsp;
  3968. break;
  3969. default:
  3970. return $this->nbsp."<label class='".$this->css_class."_class_label' ".$title." ".$on_js_event.">".trim($field_value)."</label>".$this->nbsp; break;
  3971. }
  3972. }
  3973. // -= ADD / EDIT / DETAILS MODE =-
  3974. }else if(($this->mode === "edit") || ($this->mode === "details")){
  3975. if(array_key_exists($field_name, $this->columns_edit_mode)){
  3976. $field_property_maxlength = $this->getFieldProperty($field_name, "maxlength");
  3977. $field_property_type = $this->getFieldProperty($field_name, "type");
  3978. $field_property_req_type = $this->getFieldProperty($field_name, "req_type");
  3979. $field_property_width = $this->getFieldProperty($field_name, "width");
  3980. $field_property_readonly = $this->getFieldProperty($field_name, "readonly");
  3981. $field_property_default = $this->getFieldProperty($field_name, "default");
  3982. $field_property_on_js_event = $this->getFieldProperty($field_name, "on_js_event");
  3983. $field_property_calendar_type = $this->getFieldProperty($field_name, "calendar_type");
  3984. $field_property_pre_addition = $this->getFieldProperty($field_name, "pre_addition");
  3985. $field_property_post_addition = $this->getFieldProperty($field_name, "post_addition");
  3986. $field_property_autocomplete = $this->getFieldProperty($field_name, "autocomplete");
  3987. if($field_property_autocomplete == "off") $autocomplete = "autocomplete='off'"; else $autocomplete = "";
  3988. // detect maxlength for the current field
  3989. $field_maxlength = $this->getFieldInfo($field_name, 'len', 0);
  3990. if($field_maxlength <= 0) $field_maxlength = "";
  3991. else $field_maxlength = "maxlength='".$field_maxlength."'";
  3992. if($field_property_maxlength == ""){
  3993. if(!$this->isText($field_name)){ $field_maxlength = "maxlength='50'"; }
  3994. }else{
  3995. if(($field_property_maxlength != "-1") && ($field_property_maxlength != "")){
  3996. $field_maxlength = "maxlength='".$field_property_maxlength."'";
  3997. }
  3998. }
  3999. // detect field's type
  4000. if($field_property_type == ""){ $field_type = "label"; } else $field_type = $field_property_type;
  4001. // get required prefix for a field
  4002. $field_req_type = $field_property_req_type;
  4003. if(strlen(trim($field_req_type)) == 3){ $field_req_type = $field_req_type; }
  4004. else if(strlen(trim($field_req_type)) == 2){ $field_req_type = $field_req_type."y"; }
  4005. else { $field_req_type = "syy"; }
  4006. // detect field's width
  4007. if($field_property_width != "") $field_width = "style='width:".$field_property_width.";'"; else $field_width = "";
  4008. // detect field's readonly property
  4009. if($field_property_readonly == true) { $readonly = "readonly='readonly'"; $disabled = "disabled"; }
  4010. else { $readonly = ""; $disabled = ""; }
  4011. if($req_print == true){ $field_type = "print"; }
  4012. // get default value of field
  4013. if(($req_mode == "add") || ($field_type == "hidden")){
  4014. if($field_property_default != "") $field_value = $field_property_default;
  4015. }
  4016. $on_js_event = $field_property_on_js_event;
  4017. if ($this->mode === "edit"){
  4018. // save entered values from fields in add/edit modes
  4019. $req_field_value = $this->getVariable($field_req_type.$field_name, false, "post");
  4020. if($req_field_value != "") $field_value = $req_field_value;
  4021. switch($field_type){
  4022. case "checkbox":
  4023. $checked = "";
  4024. $field_property_true_value = $this->getFieldProperty($field_name, "true_value");
  4025. $field_property_false_value = $this->getFieldProperty($field_name, "false_value");
  4026. if(($field_property_true_value != "") && ($field_property_false_value != "")){
  4027. if($field_value == $field_property_true_value){
  4028. $checked = "checked";
  4029. }
  4030. }
  4031. echo "<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;
  4032. break;
  4033. case "date":
  4034. $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.">";
  4035. if($field_property_calendar_type == "floating"){
  4036. if(!$readonly) $ret_date .= "<img id='img".$this->getFieldRequiredType($field_name).$field_name."' src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='cursor:pointer;margin:3px;margin-left:6px;margin-right:6px;' /></a>\n"."<script type='text/javascript'>Calendar.setup({inputField : '".$this->getFieldRequiredType($field_name).$field_name."', ifFormat : '%Y-%m-%d', showsTime : false, button : 'img".$this->getFieldRequiredType($field_name).$field_name."'});</script>".$this->nbsp;
  4037. }else{
  4038. if(!$readonly) $ret_date .= "<a class='".$this->css_class."_class_a2' title='".$this->getFieldTitle($field_name)."' href=\"javascript: openCalendar('".$this->directory."','', '".$this->unique_prefix."frmEditRow', '$field_req_type', '".$field_name."', '$field_type')\"><img src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='MARGIN:3px;margin-left:6px;margin-right:6px;' /></a>".$this->nbsp;
  4039. }
  4040. 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("Y-m-d")."\"'>[".date("Y-m-d")."]</a>";
  4041. 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>";
  4042. return $ret_date;
  4043. break;
  4044. case "datedmy":
  4045. $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='".$this->myDate($field_value, "datedmy")."' $field_maxlength ".$on_js_event.">";
  4046. if($field_property_calendar_type == "floating"){
  4047. if(!$readonly) $ret_date .= "<img id='img".$this->getFieldRequiredType($field_name).$field_name."' src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='cursor:pointer;margin:3px;margin-left:6px;margin-right:6px;' /></a>\n"."<script type='text/javascript'>Calendar.setup({inputField : '".$this->getFieldRequiredType($field_name).$field_name."', ifFormat : '%d-%m-%Y', showsTime : false, button : 'img".$this->getFieldRequiredType($field_name).$field_name."'});</script>".$this->nbsp;
  4048. }else{
  4049. if(!$readonly) $ret_date .= "<a class='".$this->css_class."_class_a2' title='".$this->getFieldTitle($field_name)."' href=\"javascript: openCalendar('".$this->directory."','', '".$this->unique_prefix."frmEditRow', '$field_req_type', '".$field_name."', '$field_type')\"><img src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='MARGIN:3px;margin-left:6px;margin-right:6px;' /></a>".$this->nbsp;
  4050. }
  4051. 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("d-m-Y")."\"'>[".date("d-m-Y")."]</a>";
  4052. 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>";
  4053. return $ret_date;
  4054. break;
  4055. case "datetime":
  4056. $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.">";
  4057. if($field_property_calendar_type == "floating"){
  4058. if(!$readonly) $ret_date .= "<img id='img".$this->getFieldRequiredType($field_name).$field_name."' src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='cursor:pointer;margin:3px;margin-left:6px;margin-right:6px;' /></a>\n"."<script type='text/javascript'>Calendar.setup({inputField : '".$this->getFieldRequiredType($field_name).$field_name."', ifFormat : '%Y-%m-%d %H:%M:%S', showsTime : true, button : 'img".$this->getFieldRequiredType($field_name).$field_name."'});</script>".$this->nbsp;
  4059. }else{
  4060. if(!$readonly) $ret_date .= "<a class='".$this->css_class."_class_a2' title='".$this->getFieldTitle($field_name)."' href=\"javascript: openCalendar('".$this->directory."','', '".$this->unique_prefix."frmEditRow', '$field_req_type', '".$field_name."', '$field_type')\"><img src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='MARGIN:3px;margin-left:6px;margin-right:6px;' /></a>".$this->nbsp;
  4061. }
  4062. 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("Y-m-d H:i:s")."\"'>[".date("Y-m-d H:i:s")."]</a>";
  4063. 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>";
  4064. return $ret_date;
  4065. break;
  4066. case "datetimedmy":
  4067. $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='".$this->myDate($field_value, "datetimedmy")."' $field_maxlength ".$on_js_event.">";
  4068. if($field_property_calendar_type == "floating"){
  4069. if(!$readonly) $ret_date .= "<img id='img".$this->getFieldRequiredType($field_name).$field_name."' src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='cursor:pointer;margin:3px;margin-left:6px;margin-right:6px;' /></a>\n"."<script type='text/javascript'>Calendar.setup({inputField : '".$this->getFieldRequiredType($field_name).$field_name."', ifFormat : '%d-%m-%Y %H:%M:%S', showsTime : true, button : 'img".$this->getFieldRequiredType($field_name).$field_name."'});</script>".$this->nbsp;
  4070. }else{
  4071. if(!$readonly) $ret_date .= "<a class='".$this->css_class."_class_a2' title='".$this->getFieldTitle($field_name)."' href=\"javascript: openCalendar('".$this->directory."','', '".$this->unique_prefix."frmEditRow', '$field_req_type', '".$field_name."', '$field_type')\"><img src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='MARGIN:3px;margin-left:6px;margin-right:6px;' /></a>".$this->nbsp;
  4072. }
  4073. 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("d-m-Y H:i:s")."\"'>[".date("d-m-Y H:i:s")."]</a>";
  4074. 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>";
  4075. return $ret_date;
  4076. break;
  4077. case "enum":
  4078. $ret_enum = "";
  4079. $field_property_view_type = $this->getFieldProperty($field_name, "view_type");
  4080. $field_property_radiobuttons_alignment = $this->getFieldProperty($field_name, "radiobuttons_alignment");
  4081. if($this->getFieldProperty($field_name, "multiple") == true){ $enum_multiple = true; } else { $enum_multiple = false; }
  4082. $field_property_multiple_size = $this->getFieldProperty($field_name, "multiple_size", "edit", "lower", "4");
  4083. switch($field_property_view_type){
  4084. case "radiobutton":
  4085. if(is_array($this->columns_edit_mode[$field_name]["source"])){ // don't remove columns_edit_mode
  4086. $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;
  4087. }else{
  4088. $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;
  4089. }
  4090. break;
  4091. case "dropdownlist":
  4092. default:
  4093. if(is_array($this->columns_edit_mode[$field_name]["source"])){ // don't remove columns_edit_mode
  4094. $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;
  4095. }else{
  4096. $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;
  4097. }
  4098. break;
  4099. }
  4100. return $ret_enum;
  4101. break;
  4102. case "hidden":
  4103. $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)."' />";
  4104. return $ret_hidden;
  4105. break;
  4106. case "image":
  4107. case "file":
  4108. $ret_file = "";
  4109. $file = false;
  4110. $file_error_msg = "";
  4111. $file_name_view = $field_value;
  4112. $file_act = $this->getVariable('file_act');
  4113. $file_id = $this->getVariable('file_id');
  4114. $rid = $this->getVariable('rid');
  4115. // where the file is going to be placed
  4116. $field_property_target_path = $this->getFieldProperty($field_name, "target_path");
  4117. $field_property_file_name = $this->getFieldProperty($field_name, "file_name");
  4118. $field_property_image_width = $this->getFieldProperty($field_name, "image_width", "edit", "lower", "120px");
  4119. $field_property_image_height = $this->getFieldProperty($field_name, "image_height", "edit", "lower", "90px");
  4120. $field_property_max_file_size = $this->getFieldProperty($field_name, "max_file_size");
  4121. if($this->getFieldProperty($field_name, "host") == "remote"){
  4122. // *** upload file from url (remote host)
  4123. $ret_file = "";
  4124. if(trim($field_value) == ""){
  4125. if(($file_act == "upload") && ($file_id == $field_name)){
  4126. $file_error_msg = $this->lang['file_uploading_error'];
  4127. $file = false;
  4128. }
  4129. }else{
  4130. if(($file_act == "remove") && ($file_id == $field_name)){
  4131. $sql = "UPDATE $this->tbl_name SET ".$field_name." = '' WHERE $this->primary_key = '".$rid."' ";
  4132. $this->db_handler->query($sql);
  4133. // delete file from target path
  4134. if(file_exists($field_property_target_path.$field_value)){ unlink($field_property_target_path.$field_value); }
  4135. else{ $file_error_msg = $this->lang['file_deleting_error']; }
  4136. $file = false;
  4137. }else if(($file_act == "upload") && ($file_id == $field_name)){
  4138. if($downloaded_file = fopen($field_value, "r")){
  4139. $content = fread($downloaded_file, $this->getRemoteFileSize($field_value));
  4140. // get file name from url
  4141. $field_value = strrev($field_value);
  4142. $last_slash = strlen($field_value) - strpos($field_value,'/');
  4143. $field_value = strrev($field_value);
  4144. if($last_slash) { $field_value = substr($field_value,$last_slash); }
  4145. if($field_property_file_name != ""){
  4146. $file_name_view = $field_property_file_name.strchr(basename($field_value),".");
  4147. $field_value = $file_name_view;
  4148. }
  4149. if($uploaded_file = fopen($field_property_target_path.$field_value, "w")){
  4150. if(!fwrite($uploaded_file, $content)){
  4151. $file_error_msg = $this->lang['file_writing_error'];
  4152. $file = false;
  4153. }else{
  4154. //echo "eee";
  4155. $sql = "UPDATE $this->tbl_name SET ".$field_name;
  4156. $sql .= " = '".$field_value."' ";
  4157. $sql .= " WHERE $this->primary_key= '".$rid."' ";
  4158. $this->db_handler->query($sql);
  4159. $file = true;
  4160. fclose($uploaded_file);
  4161. }
  4162. }
  4163. fclose($downloaded_file);
  4164. }else{
  4165. $file_error_msg = $this->lang['file_uploading_error'];
  4166. }
  4167. }else{
  4168. $file = true;
  4169. }
  4170. }
  4171. // if there is a file (uploaded or exists)
  4172. if($file == true){
  4173. //echo $target_path.$field_value;
  4174. if(strlen($field_value) > 40){
  4175. $str_start = strlen($field_value) - 40;
  4176. $str_prefix = "...";
  4177. }else{
  4178. $str_start = 0;
  4179. $str_prefix = "";
  4180. }
  4181. //$ret_file .= "<input type='hidden' name='".$this->unique_prefix."file_act' id='".$this->unique_prefix."file_act' value='remove' />";
  4182. $ret_file .= "<table><tr valign='middle'><td align='center'>";
  4183. if($field_type == "image"){
  4184. list($f_width, $f_height, $f_type, $f_attr) = getimagesize($field_property_target_path.$field_value);
  4185. $f_size = number_format((filesize($field_property_target_path.$field_value)/1024),2,".",",")." Kb";
  4186. $img_width = $field_property_image_width;
  4187. $img_height = $field_property_image_height;
  4188. $ret_file .= $this->nbsp."<img src='".$field_property_target_path.$field_value."' height='".$img_height."' width='".$img_width."' title='$field_value ($f_width x $f_height - $f_size)' alt='$field_value'/>".$this->nbsp;
  4189. }else{
  4190. $ret_file .= $this->nbsp.$str_prefix.substr($file_name_view, $str_start, 40).$this->nbsp;
  4191. }
  4192. if($field_type == "image") $ret_file .= "<br />";
  4193. else $ret_file .= "&nbsp;&nbsp;";
  4194. $ret_file .= $this->nbsp."[<a class='".$this->css_class."_class_a' href='' onclick='formAction(\"remove\", \"".$field_name."\", \"".$this->unique_prefix."\", \"".$this->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\"); return false;'><b>".$this->lang['remove']."</b></a>]".$this->nbsp;
  4195. $ret_file .= "</td></tr></table>";
  4196. $ret_file .= "<input type='hidden' value='$field_value' name='".$this->getFieldRequiredType($field_name).$field_name."' id='".$this->getFieldRequiredType($field_name).$field_name."' />";
  4197. }else{
  4198. //$ret_file .= "<input type='hidden' name='".$this->unique_prefix."file_act' id='".$this->unique_prefix."file_act' value='upload' />";
  4199. if($file_error_msg != "") $ret_file .= $this->nbsp."<label class='".$this->css_class."_class_error_message no_print'>".$file_error_msg."</label><br />";
  4200. $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;";
  4201. $ret_file .= "[<a class='".$this->css_class."_class_a' ".(($disabled == "disabled") ? "" : "style='cursor: pointer;' onclick='formAction(\"upload\", \"".$field_name."\", \"".$this->unique_prefix."\", \"".$this->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\"); return false;'")."><b>".$this->lang['upload']."</b></a>]".$this->nbsp;
  4202. }
  4203. return $ret_file;
  4204. }else{
  4205. // *** upload file from local machine
  4206. $ret_file = "";
  4207. if(trim($field_value) == ""){
  4208. $file = true;
  4209. $file_name = $this->getFieldRequiredType($field_name).$field_name;
  4210. if((count($_FILES) > 0) && ($file_id == $field_name)){
  4211. if (isset($_FILES[$file_name]["error"]) && ($_FILES[$file_name]["error"] > 0)){
  4212. //debug? $file_error_msg = "Error: ".$_FILES[$file_name]["error"]."";
  4213. $file_error_msg = $this->lang['file_uploading_error'];
  4214. $file = false;
  4215. }else{
  4216. // check file's max size
  4217. if($field_property_max_file_size != ""){
  4218. $max_file_size = $field_property_max_file_size;
  4219. if (!is_numeric($max_file_size)) {
  4220. if (strpos($max_file_size, 'm') !== false)
  4221. $max_file_size = intval($max_file_size)*1024*1024;
  4222. elseif (strpos($max_file_size, 'k') !== false)
  4223. $max_file_size = intval($max_file_size)*1024;
  4224. elseif (strpos($max_file_size, 'g') !== false)
  4225. $max_file_size = intval($max_file_size)*1024*1024*1024;
  4226. }
  4227. if(isset($_FILES[$file_name]["size"]) && ($_FILES[$file_name]["size"] > $max_file_size)){
  4228. $file = false;
  4229. $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) ";
  4230. }
  4231. }
  4232. }
  4233. if($file == true){
  4234. // create a directory for uploading, if it was not.
  4235. if (!file_exists($field_property_target_path)) { mkdir($field_property_target_path,0744); }
  4236. // add the original filename to our target path. Result is "uploads/filename.extension"
  4237. if($field_property_file_name != ""){
  4238. $target_path_full = $field_property_target_path . $field_property_file_name.strchr(basename($_FILES[$file_name]['name']),".");
  4239. }else{
  4240. $target_path_full = $field_property_target_path . (isset($_FILES[$file_name]['name']) ? basename($_FILES[$file_name]['name']) : "") ;
  4241. }
  4242. if(isset($_FILES[$file_name]['tmp_name'])){
  4243. if(move_uploaded_file($_FILES[$file_name]['tmp_name'], $target_path_full)) {
  4244. chmod($target_path_full, 0644);
  4245. $sql = "UPDATE $this->tbl_name SET ".$field_name;
  4246. if($field_property_file_name != ""){
  4247. $file_name_view = $field_property_file_name.strchr(basename($_FILES[$file_name]['name']),".");
  4248. $field_value = $field_property_file_name.strchr(basename($_FILES[$file_name]['name']),".");
  4249. $sql .= " = '".$field_property_file_name.strchr(basename($_FILES[$file_name]['name']),".")."'";
  4250. }else{
  4251. $file_name_view = $_FILES[$file_name]['name'];
  4252. $field_value = $_FILES[$file_name]['name'];
  4253. $sql .= " = '".$_FILES[$file_name]['name']."' ";
  4254. }
  4255. $sql .= " WHERE $this->primary_key= '".$rid."' ";
  4256. $this->db_handler->query($sql);
  4257. //debug? mysql_error();
  4258. $file = true;
  4259. } else{
  4260. $file_error_msg = $this->lang['file_uploading_error'];
  4261. //print_r($_FILES);
  4262. $file = false;
  4263. }
  4264. }else{
  4265. $file = false;
  4266. }
  4267. }
  4268. }else{
  4269. $file = false;
  4270. }
  4271. }else{
  4272. if(($file_act == "remove") && ($file_id == $field_name)){
  4273. $sql = "UPDATE $this->tbl_name SET ".$field_name." = '' WHERE $this->primary_key = '".$rid."' ";
  4274. $this->db_handler->query($sql);
  4275. // delete file from target path
  4276. if(file_exists($field_property_target_path.$field_value)){
  4277. unlink($field_property_target_path.$field_value);
  4278. }else{
  4279. $file_error_msg = $this->lang['file_deleting_error'];
  4280. }
  4281. $file = false;
  4282. }else{
  4283. $file = true;
  4284. }
  4285. }
  4286. // if there is a file (uploaded or exists)
  4287. if($file == true){
  4288. if(strlen($field_value) > 40){
  4289. $str_start = strlen($field_value) - 40;
  4290. $str_prefix = "...";
  4291. }else{
  4292. $str_start = 0;
  4293. $str_prefix = "";
  4294. }
  4295. //$ret_file .= "<input type='hidden' name='".$this->unique_prefix."file_act' id='".$this->unique_prefix."file_act' value='remove' />";
  4296. $ret_file .= "<table><tr valign='middle'><td align='center'>";
  4297. if($field_type == "image"){
  4298. $f_width = $f_height = $f_size = 0;
  4299. if(file_exists($field_property_target_path.$field_value)){
  4300. list($f_width, $f_height, $f_type, $f_attr) = getimagesize($field_property_target_path.$field_value);
  4301. $f_size = number_format((filesize($field_property_target_path.$field_value)/1024),2,".",",")." Kb";
  4302. }else{
  4303. $ret_file .= $this->nbsp."<label class='".$this->css_class."_class_error_message no_print'>".$this->lang['file_uploading_error']."</label><br />";
  4304. }
  4305. $img_width = $field_property_image_width;
  4306. $img_height = $field_property_image_height;
  4307. $ret_file .= $this->nbsp."<img src='".$field_property_target_path.$field_value."' height='".$img_height."' width='".$img_width."' title='$field_value ($f_width x $f_height - $f_size)' alt='$field_value'/>".$this->nbsp;
  4308. }else{
  4309. $ret_file .= $this->nbsp.$str_prefix.substr($file_name_view, $str_start, 40).$this->nbsp;
  4310. }
  4311. if($field_type == "image") $ret_file .= "<br />";
  4312. else $ret_file .= "&nbsp;&nbsp;";
  4313. $ret_file .= $this->nbsp."[<a class='".$this->css_class."_class_a' href='#' onclick='formAction(\"remove\", \"".$field_name."\", \"".$this->unique_prefix."\", \"".$this->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\"); return false;'><b>".$this->lang['remove']."</b></a>]".$this->nbsp;
  4314. $ret_file .= "</td></tr></table>";
  4315. $ret_file .= "<input type='hidden' value='$field_value' name='".$this->getFieldRequiredType($field_name).$field_name."' id='".$this->getFieldRequiredType($field_name).$field_name."' />";
  4316. }else{
  4317. //$ret_file .= "<input type='hidden' name='".$this->unique_prefix."file_act' id='".$this->unique_prefix."file_act' value='upload' />";
  4318. if($file_error_msg != "") $ret_file .= $this->nbsp."<label class='".$this->css_class."_class_error_message no_print'>".$file_error_msg."</label><br />";
  4319. $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;";
  4320. $ret_file .= "[<a class='".$this->css_class."_class_a' ".(($disabled == "disabled") ? "" : "style='cursor: pointer;' onclick='formAction(\"upload\", \"".$field_name."\", \"".$this->unique_prefix."\", \"".$this->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\"); return false;'")."><b>".$this->lang['upload']."</b></a>]".$this->nbsp;
  4321. }
  4322. return $ret_file;
  4323. }
  4324. break;
  4325. case "label":
  4326. return $this->nbsp."<label class='".$this->css_class."_class_textbox' ".$field_width." ".$on_js_event.">".trim($field_value)."</label>".$this->nbsp;
  4327. break;
  4328. case "link":
  4329. 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;
  4330. break;
  4331. case "password":
  4332. 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;
  4333. break;
  4334. case "print":
  4335. return $this->nbsp."<label class='".$this->css_class."_class_label' ".$field_width.">".trim($field_value)."</label>".$this->nbsp;
  4336. break;
  4337. case "textarea":
  4338. $field_value = str_replace('"', "&quot;", $field_value); // double quotation mark
  4339. $field_value = str_replace("'", "&#039;", $field_value); // single quotation mark
  4340. $resizable = $field_property_resizable = $this->getFieldProperty($field_name, "resizable", "edit", "lower", "false");
  4341. $field_rows = $field_property_rows = $this->getFieldProperty($field_name, "rows", "edit", "lower", "3");
  4342. $field_cols = $field_property_cols = $this->getFieldProperty($field_name, "cols", "edit", "lower", "23");
  4343. $field_edit_type = $field_property_edit_type = $this->getFieldProperty($field_name, "edit_type");
  4344. $field_wysiwyg_width = $field_property_width = $this->getFieldProperty($field_name, "width", "edit", "lower", "0");
  4345. $field_id = $this->getFieldRequiredType($field_name).$field_name;
  4346. if(strtolower($field_edit_type) == "wysiwyg") $field_maxlength = "";
  4347. if(($resizable == true) || ($resizable == "true")) { $field_class = "class='resizable'"; } else { $field_class = ""; };
  4348. $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;
  4349. if((strtolower($this->browser_name) != "netscape") && strtolower($field_edit_type) == "wysiwyg"){
  4350. $texarea .= $this->nbsp."\n<script type='text/javascript'>\n";
  4351. $texarea .= "<!--\n";
  4352. $texarea .= "wysiwygWidth = ".((intval($field_wysiwyg_width) > ((9.4)*$field_cols)) ? intval($field_wysiwyg_width) : ((9.4)*$field_cols)).";";
  4353. $texarea .= "wysiwygHeight = ".(21*$field_rows).";";
  4354. $texarea .= "generate_wysiwyg('".$this->getFieldRequiredType($field_name).$field_name."'); \n";
  4355. $texarea .= "//-->\n";
  4356. $texarea .= "</script>\n";
  4357. }
  4358. return $texarea;
  4359. break;
  4360. case "textbox":
  4361. $field_value = str_replace('"', "&quot;", $field_value); // double quotation mark
  4362. $field_value = str_replace("'", "&#039;", $field_value); // single quotation mark
  4363. return $field_property_pre_addition.$this->nbsp."<input class='".$this->css_class."_class_textbox' ".$field_width." 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." ".$readonly." ".$on_js_event." ".$autocomplete.">".$this->nbsp.$field_property_post_addition;
  4364. break;
  4365. case "time":
  4366. $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.">";
  4367. if($field_property_calendar_type == "floating"){
  4368. if(!$readonly) $ret_date .= "<img id='img".$this->getFieldRequiredType($field_name).$field_name."' src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='cursor:pointer;margin:3px;margin-left:6px;margin-right:6px;' /></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;
  4369. }else{
  4370. if(!$readonly) $ret_date .= "<a class='".$this->css_class."_class_a2' title='".$this->getFieldTitle($field_name)."' href=\"javascript: openCalendar('".$this->directory."','', '".$this->unique_prefix."frmEditRow', '$field_req_type', '".$field_name."', '$field_type')\"><img src='".$this->directory."images/".$this->css_class."/cal.gif' border='0' alt='".$this->lang['set_date']."' title='".$this->lang['set_date']."' align='top' style='MARGIN:3px;margin-left:6px;margin-right:6px;' /></a>".$this->nbsp;
  4371. }
  4372. 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>";
  4373. 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>";
  4374. return $ret_date;
  4375. break;
  4376. case "validator":
  4377. $field_property_for = $this->getFieldProperty($field_name, "for");
  4378. if($field_property_for == "password"){
  4379. 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='' $field_maxlength $readonly ".$on_js_event.">".$this->nbsp;
  4380. }else{
  4381. return $this->nbsp."<input class='".$this->css_class."_class_textbox' ".$field_width." type='text' title='".$this->getFieldTitle($field_name)."' name='".$this->getFieldRequiredType($field_name).$field_name."' id='".$this->getFieldRequiredType($field_name).$field_name."' value='' $field_maxlength $readonly ".$on_js_event.">".$this->nbsp;
  4382. }
  4383. break;
  4384. default:
  4385. 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;
  4386. break;
  4387. }
  4388. }else if ($this->mode === "details"){
  4389. switch($field_type){
  4390. case "checkbox":
  4391. return $this->nbsp.(($field_value == 1) ? $this->lang['yes'] : $this->lang['no']).$this->nbsp;
  4392. break;
  4393. case "date":
  4394. return $this->nbsp.substr(trim($field_value), 0, 10).$this->nbsp;
  4395. break;
  4396. case "datedmy":
  4397. return $this->nbsp.$this->myDate($field_value, "datedmy").$this->nbsp;
  4398. break;
  4399. case "datetime":
  4400. return $this->nbsp.trim($field_value).$this->nbsp;
  4401. break;
  4402. case "datetimedmy":
  4403. return $this->nbsp.$this->myDate($field_value, "datetimedmy").$this->nbsp;
  4404. break;
  4405. case "enum":
  4406. // don't remove columns_edit_mode
  4407. if(isset($this->columns_edit_mode[$field_name]['source']) && is_array($this->columns_edit_mode[$field_name]['source'])){
  4408. foreach($this->columns_edit_mode[$field_name]['source'] as $val => $opt){
  4409. if($field_value == $val) return $this->nbsp.trim($opt).$this->nbsp;
  4410. }
  4411. }
  4412. return $this->nbsp.trim($field_value).$this->nbsp;
  4413. break;
  4414. case "hidden":
  4415. return ""; break;
  4416. case "image":
  4417. $img_target_path = $field_property_target_path = $this->getFieldProperty($field_name, "target_path");
  4418. $img_width = $field_property_image_width = $this->getFieldProperty($field_name, "image_width", "edit", "lower", "50px");
  4419. $img_height = $field_property_image_height = $this->getFieldProperty($field_name, "image_height", "edit", "lower", "30px");
  4420. $field_property_default = $this->getFieldProperty($field_name, "default");
  4421. $img_default = (($field_property_default != "") && file_exists($img_target_path.trim($field_property_default))) ? "<img src='".$img_target_path.$field_property_default."' width='".$img_width."' height='".$img_height."' alt='' title='' />" : "<span class='".$this->css_class."_class_label'>".$this->lang['no_image']."</span>";
  4422. if((trim($field_value) !== "") && file_exists($img_target_path.trim($field_value))){
  4423. return $this->nbsp."<img src='".$img_target_path.trim($field_value)."' border='1' width='".$img_width."' height='".$img_height."' align='middle' />".$this->nbsp;
  4424. }else{
  4425. return "<table style='BORDER: solid 1px #000000;' width='".$img_width."' height='".$img_height."'><tr><td align='center'>".$img_default."</td></tr></table>";
  4426. }
  4427. break;
  4428. case "label":
  4429. return $this->nbsp.trim($field_value)."";
  4430. break;
  4431. case "link":
  4432. $field_property_field_data = $this->getFieldProperty($field_name, "field_data");
  4433. if($field_property_field_data != ""){
  4434. $href_inner = $field_property_href = $this->getFieldProperty($field_name, "href");
  4435. $target_inner = $field_property_target = $this->getFieldProperty($field_name, "target");
  4436. $on_js_event = $field_property_on_js_event = $this->getFieldProperty($field_name, "on_js_event");
  4437. foreach ($this->columns_edit_mode[$field_name] as $search_field_key => $search_field_value){
  4438. if(substr($search_field_key, 0, 9) == "field_key"){
  4439. $field_number = intval(substr($search_field_key, 10, strlen($search_field_key) - 10));
  4440. $field_inner = $row[$this->getFieldOffset($search_field_value)];
  4441. if(strpos($href_inner, "{".$field_number."}") >= 0){
  4442. $href = str_replace("{".$field_number."}", $field_inner, $href_inner);
  4443. }
  4444. }
  4445. }
  4446. // remove unexpected 'http://'s
  4447. if(strstr($href_inner, "http://") != ""){
  4448. $href = str_replace("http://", "", $href);
  4449. $href = "http://".$href;
  4450. }
  4451. return $this->nbsp."<a class='".$this->css_class."_class_a2' href='".$href."' target='".$target_inner."' ".$on_js_event.">".trim($row[$this->getFieldOffset($field_property_field_data)])."</a>".$this->nbsp;
  4452. }else{
  4453. return $this->nbsp;
  4454. }
  4455. break;
  4456. case "password":
  4457. return $this->nbsp."<label class='".$this->css_class."_class_label'>******</label>".$this->nbsp;
  4458. break;
  4459. case "print":
  4460. return $this->nbsp."<label class='".$this->css_class."_class_label' ".$field_width.">".trim($field_value)."</label>".$this->nbsp;
  4461. break;
  4462. case "textarea":
  4463. case "textbox":
  4464. return $field_property_pre_addition.$this->nbsp.trim($field_value).$field_property_post_addition;
  4465. break;
  4466. case "validator":
  4467. return ""; break;
  4468. default:
  4469. return $this->nbsp.trim($field_value)."";
  4470. break;
  4471. }
  4472. }
  4473. }
  4474. }
  4475. return false;
  4476. }
  4477. //--------------------------------------------------------------------------
  4478. // add Check Boxes Values
  4479. //--------------------------------------------------------------------------
  4480. function addCheckBoxesValues(){
  4481. foreach($this->columns_edit_mode as $itemName => $itemValue){
  4482. if(isset($itemValue['type']) && $itemValue['type'] == "checkbox"){
  4483. $found = false;
  4484. foreach($_POST as $i => $v){
  4485. if($i == $this->getFieldRequiredType($itemName).$itemName){
  4486. $found = true;
  4487. }
  4488. }
  4489. if(!$found){
  4490. $_POST[$this->getFieldRequiredType($itemName).$itemName] = $itemValue['false_value'];
  4491. }else{
  4492. $_POST[$this->getFieldRequiredType($itemName).$itemName] = $itemValue['true_value'];
  4493. }
  4494. }
  4495. }
  4496. }
  4497. //--------------------------------------------------------------------------
  4498. // get $_REQUEST variable
  4499. //--------------------------------------------------------------------------
  4500. function getVariable($var = "", $prefix = true, $method = "request"){
  4501. $prefix = (($prefix == true) || ($prefix == "true")) ? true : false;
  4502. $unique_prefix = ($prefix) ? $this->unique_prefix : "" ;
  4503. switch($method){
  4504. case "get":
  4505. return isset($_GET[$unique_prefix.$var]) ? $_GET[$unique_prefix.$var] : "";
  4506. break;
  4507. case "post":
  4508. return isset($_POST[$unique_prefix.$var]) ? $_POST[$unique_prefix.$var] : "";
  4509. break;
  4510. default:
  4511. return isset($_REQUEST[$unique_prefix.$var]) ? $_REQUEST[$unique_prefix.$var] : "";
  4512. break;
  4513. }
  4514. }
  4515. //--------------------------------------------------------------------------
  4516. // draw RadioButtons
  4517. //--------------------------------------------------------------------------
  4518. function drawRadioButtons($tag_name, $field_name, &$select_array, $compare = "", $sub_field_value="", $sub_field_name="", $disabled="", $on_js_event="", $radiobuttons_alignment=""){
  4519. $req_print = $this->getVariable('print');
  4520. $break_by = ($radiobuttons_alignment == "vertical") ? "<br />" : "";
  4521. $text = "";
  4522. if($req_print != true){
  4523. if($on_js_event !="") $text .= "<span ".$on_js_event.">";
  4524. if(is_object($select_array)){
  4525. while($row = $select_array->fetchRow()){
  4526. if(strtolower($row[$this->foreign_keys_array[$field_name][$sub_field_value]]) == strtolower($compare))
  4527. $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;
  4528. else
  4529. $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;
  4530. }
  4531. }else{
  4532. foreach($select_array as $key => $val){
  4533. if(strtolower($key) == strtolower($compare)){
  4534. $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;
  4535. }else{
  4536. $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;
  4537. }
  4538. }
  4539. }
  4540. if($on_js_event !="") $text .= "</span>";
  4541. }else{
  4542. if(is_object($select_array)){
  4543. $found = 0;
  4544. while(($row = $select_array->fetchRow()) && (!$found)){
  4545. if(strtolower($row[$this->foreign_keys_array[$field_name][$sub_field_value]]) == strtolower($compare)){
  4546. $text .= "<span ".$on_js_event.">".$row[$this->foreign_keys_array[$field_name][$sub_field_name]]."</span>";
  4547. $found = 1;
  4548. }
  4549. }
  4550. if($found == 0) $text .= "<span ".$on_js_event.">none</span>";
  4551. }else{
  4552. $text = $compare;
  4553. }
  4554. }
  4555. return $text;
  4556. }
  4557. //--------------------------------------------------------------------------
  4558. // draw drop-down list
  4559. //--------------------------------------------------------------------------
  4560. 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"){
  4561. $req_print = $this->getVariable('print');
  4562. $text = "";
  4563. $multiple_parameters = ($multiple) ? $multiple_parameters = "multiple size='".$multiple_size."'" : "";
  4564. $tag_id = $tag_name;
  4565. $tag_name = ($multiple) ? $tag_name = $tag_name."[]" : $tag_name;
  4566. if($req_print != true){
  4567. if(is_object($select_array)){
  4568. $text = "<select class='".$this->css_class."_class_select' name='".$tag_name."' id='".$tag_id."' title='".$this->getFieldTitle($field_name)."' ".(($foo_name != "") ? "onChange='".$this->unique_prefix.$foo_name."'" : "")." ".$disabled." ".$on_js_event." ".$multiple_parameters.">";
  4569. $text .= "<option value=''>-- ".$this->lang['select']." --</option>";
  4570. if($this->db_handler->isError($select_array) != 1){
  4571. while($row = $select_array->fetchRow()){
  4572. $ff_name = $this->foreign_keys_array[$field_name][$sub_field_name];
  4573. if(eregi(" as ", strtolower($ff_name))) $ff_name = substr($ff_name, strpos(strtolower($ff_name), " as ")+4);
  4574. if(strtolower($row[$this->foreign_keys_array[$field_name][$sub_field_value]]) == strtolower($compare))
  4575. $text .= "<option selected value='".$row[$this->foreign_keys_array[$field_name][$sub_field_value]]."'>".$row[$ff_name]."</option>";
  4576. else
  4577. $text .= "<option value='".$row[$this->foreign_keys_array[$field_name][$sub_field_value]]."'>".$row[$ff_name]."</option>";
  4578. }
  4579. }
  4580. }else{
  4581. if(!is_array($compare)){ $splitted_compare = split(",",$compare); }else{ $splitted_compare = $compare; }
  4582. $text = "<select class='".$this->css_class."_class_select' name='".$tag_name."' id='".$tag_id."' ".(($foo_name != "") ? "onChange='".$this->unique_prefix.$foo_name."'" : "")." ".$disabled." ".$on_js_event." ".$multiple_parameters.">";
  4583. foreach($select_array as $key => $val){
  4584. $selected = "";
  4585. if(count($splitted_compare) > 1){
  4586. foreach($splitted_compare as $spl_val){
  4587. if($spl_val == $key) {$selected = "selected"; break; }
  4588. }
  4589. }else{
  4590. $selected = ((strtolower($compare) == strtolower($key)) ? "selected" : "");
  4591. }
  4592. $text .= "<option ".$selected." value='".$key."'>".$val."</option>";
  4593. }
  4594. }
  4595. $text .= "</select>";
  4596. }else{
  4597. if(is_object($select_array)){
  4598. $found = 0;
  4599. while(($row = $select_array->fetchRow()) && (!$found)){
  4600. if(strtolower($row[$this->foreign_keys_array[$field_name][$sub_field_value]]) == strtolower($compare)){
  4601. $text .= "<span>".$row[$this->foreign_keys_array[$field_name][$sub_field_name]]."</span>";
  4602. $found = 1;
  4603. }
  4604. }
  4605. if($found == 0) $text .= "<span>none</span>";
  4606. }else{
  4607. $text = $compare;
  4608. }
  4609. }
  4610. return $text;
  4611. }
  4612. //--------------------------------------------------------------------------
  4613. // draw Mode Button
  4614. //--------------------------------------------------------------------------
  4615. function drawModeButton($mode, $mode_url, $botton_name, $alt_name, $image_file, $onClick, $div_align=false, $nbsp="", $type=""){
  4616. $req_print = $this->getVariable('print');
  4617. if($type == ""){
  4618. $mode_type = (isset($this->modes[$mode]['type'])) ? $this->modes[$mode]['type'] : "";
  4619. }else{
  4620. $mode_type = $type;
  4621. }
  4622. if(!$this->is_error){
  4623. if($req_print != true){
  4624. switch($mode_type){
  4625. case "button":
  4626. echo $nbsp."<input class='".$this->css_class."_class_button' type='button' ";
  4627. if($div_align){ echo "style='float: "; echo ($this->direction == "rtl")?"right":"left"; echo "' "; }
  4628. echo "onClick=$onClick value='".$botton_name."' />".$nbsp;
  4629. break;
  4630. case "image":
  4631. if($div_align){ echo "<div style='float:"; echo ($this->direction == "rtl")?"right":"left"; echo ";'>"; }
  4632. echo $nbsp."<img style='cursor:pointer;' align='middle' onClick=$onClick src='".$this->directory."images/".$this->css_class."/".$image_file."' alt='$alt_name' title='$alt_name' />".$nbsp;
  4633. if($div_align) echo "</div>";
  4634. break;
  4635. default:
  4636. if($div_align){ echo "<div style='float:"; echo ($this->direction == "rtl")?"right":"left"; echo ";'>"; }
  4637. echo $nbsp."<a class='".$this->css_class."_class_a' href='$mode_url' onClick=$onClick title='$alt_name'>".$botton_name."</a>".$nbsp;
  4638. if($div_align) echo "</div>";
  4639. break;
  4640. }
  4641. }else{
  4642. switch($mode_type){
  4643. case "button":
  4644. echo "<span ";
  4645. if($div_align){ echo "style='float: "; echo ($this->direction == "rtl")?"right":"left"; echo "' "; }
  4646. echo ">".$botton_name."</span>";
  4647. break;
  4648. case "image":
  4649. if($div_align){ echo "<div style='float:"; echo ($this->direction == "rtl")?"right":"left"; echo ";'>"; }
  4650. echo "<img align='middle' src='".$this->directory."images/".$this->css_class."/".$image_file."' readonly />";
  4651. if($div_align) echo "</div>";
  4652. break;
  4653. default:
  4654. if($div_align){ echo "<div style='float:"; echo ($this->direction == "rtl")?"right":"left"; echo ";'>"; }
  4655. echo $nbsp."<span class='".$this->css_class."_class_a' >".$botton_name."</span>".$nbsp;
  4656. if($div_align) echo "</div>";
  4657. break;
  4658. }
  4659. }
  4660. }
  4661. }
  4662. //--------------------------------------------------------------------------
  4663. // set Common JavaScript
  4664. //--------------------------------------------------------------------------
  4665. function setCommonJavaScript(){
  4666. $req_mode = $this->getVariable('mode');
  4667. echo "\n<!-- This script was generated by datagrid.class.php v.4.2.3 (http://phpbuilder.blogspot.com) -->";
  4668. // set common JavaScript
  4669. if (!file_exists($this->directory.'scripts/dg.js')) {
  4670. 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 /><br />";
  4671. }else{
  4672. echo "\n<script type='text/javascript' src='".$this->directory."scripts/dg.js'></script>";
  4673. }
  4674. if(($req_mode == "add") || ($req_mode == "edit")){
  4675. // include calendar script (floating), if needed
  4676. if ($this->datetimeFieldExists("floating")) {
  4677. // set calendar JS
  4678. echo "<style type='text/css'>@import url(".$this->directory."modules/jscalendar/skins/aqua/theme.css);</style>";
  4679. //<!-- import the calendar script -->
  4680. echo "<script type='text/javascript' src='".$this->directory."modules/jscalendar/calendar.js'></script>"."\n";
  4681. //<!-- import the language module -->
  4682. echo "<script type='text/javascript' src='".$this->directory."modules/jscalendar/lang/calendar-".$this->getLangAbbrForCalendar().".js'></script>"."\n";
  4683. //<!-- the following script defines the Calendar.setup helper function, which makes
  4684. //adding a calendar a matter of 1 or 2 lines of code. -->
  4685. echo "<script type='text/javascript' src='".$this->directory."modules/jscalendar/calendar-setup.js'></script>";
  4686. }
  4687. // include form checking script, if needed
  4688. if (!file_exists($this->directory.'modules/jsafv/form.scripts.js')) {
  4689. 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 />";
  4690. }else{
  4691. echo "\n<script type='text/javascript' src='".$this->directory."modules/jsafv/form.scripts.js'></script>";
  4692. }
  4693. // include resizable textarea script, if needed
  4694. if ($this->resizableFieldExists()) {
  4695. if (!file_exists($this->directory.'scripts/resize.js')) {
  4696. 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 />";
  4697. }else{
  4698. echo "\n<script type='text/javascript' src='".$this->directory."scripts/resize.js'></script>";
  4699. }
  4700. }
  4701. // include WYSIWYG script, if needed
  4702. if ($this->wysiwygFieldExists()) {
  4703. // set WYSIWYG
  4704. echo "\n<script type='text/javascript'>\n";
  4705. echo "<!--\n";
  4706. echo "imagesDir = '".$this->directory."modules/wysiwyg/icons/';\n"; // Images Directory
  4707. echo "cssDir = '".$this->directory."modules/wysiwyg/styles/';\n"; // CSS Directory
  4708. echo "popupsDir = '".$this->directory."modules/wysiwyg/popups/';\n"; // Popups Directory
  4709. echo "//-->\n";
  4710. echo "</script>";
  4711. echo "\n<script type='text/javascript' src='".$this->directory."modules/wysiwyg/wysiwyg.js'></script>";
  4712. }
  4713. }
  4714. // include overlib.js file for floating tooltips
  4715. if ($this->floatingToolTipsFieldExists()) {
  4716. if (!file_exists($this->directory.'modules/overlib/overlib.js')) {
  4717. 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 />";
  4718. }else{
  4719. echo "\n<script type='text/javascript' src='".$this->directory."modules/overlib/overlib.js'></script>";
  4720. }
  4721. }
  4722. // include highlight.js file for rows highlighting
  4723. if($this->row_highlighting_allowed){
  4724. if (!file_exists($this->directory.'scripts/highlight.js')) {
  4725. 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 />";
  4726. }else{
  4727. echo "\n<script type='text/javascript' src='".$this->directory."scripts/highlight.js'></script>";
  4728. }
  4729. }
  4730. // set verify JS functions
  4731. echo "\n<script type='text/javascript'>\n<!--";
  4732. if(isset($this->modes['cancel'][$this->mode]) && $this->modes['cancel'][$this->mode]){
  4733. echo "\nfunction ".$this->unique_prefix."verifyCancel(param){if(confirm(\"".$this->lang['cancel_creating_new_record']."\")){document.location.href=param;} else { return false;}};";
  4734. }
  4735. echo "//-->\n</script>\n";
  4736. }
  4737. function setCommonJavaScriptEnd(){
  4738. echo "<script type='text/javascript'>\n<!--\n";
  4739. // set verify JS functions
  4740. if(isset($this->modes['delete'][$this->mode]) && $this->modes['delete'][$this->mode]){
  4741. echo "\nfunction ".$this->unique_prefix."verifyDelete(param){if(confirm(\"".$this->lang['delete_this_record']."\")){document.location.href=param;} else { window.event.cancelBubble = true; return false;}};";
  4742. }
  4743. echo "\n//-->\n";
  4744. echo "</script>";
  4745. }
  4746. function setMediaPrint(){
  4747. echo "\n<style type='text\css'> @media print { .no_print {DISPLAY: none! important}; }</style>";
  4748. }
  4749. //--------------------------------------------------------------------------
  4750. // set Edit Fields Form Script
  4751. //--------------------------------------------------------------------------
  4752. function setEditFieldsFormScript($url=""){
  4753. echo "<script type='text/javascript'>\n";
  4754. echo "<!--\n";
  4755. //echo $url;
  4756. //document.".$this->unique_prefix."frmEditRow.action ='".str_replace($this->amp,'&',$url)."';
  4757. echo "function ".$this->unique_prefix."sendEditFields(){
  4758. if(window.".$this->unique_prefix."onSubmitMyCheck){ if(!".$this->unique_prefix."onSubmitMyCheck()){ return false; } }
  4759. if(onSubmitCheck(document.".$this->unique_prefix."frmEditRow, ".$this->js_validation_errors.")){
  4760. ";
  4761. // two different parts of code to find & save wysiwyg editor data
  4762. if($this->browser_name == "Firefox"){
  4763. echo "
  4764. elements = document.getElementsByTagName('*');
  4765. for (var idx = 0; idx < elements.length; idx++) {
  4766. node = elements.item(idx);
  4767. field_name = node.getAttribute('name');
  4768. field_full_name = 'wysiwyg' + field_name;
  4769. if(document.getElementById(field_full_name)){
  4770. document.getElementById(field_name).value = document.getElementById(field_full_name).contentWindow.document.body.innerHTML;
  4771. }
  4772. }
  4773. ";
  4774. }else{ // "MSIE" or other
  4775. echo "
  4776. for (var idx=0; idx < document.".$this->unique_prefix."frmEditRow.length; idx++) {
  4777. field_name = ".$this->unique_prefix."frmEditRow.elements.item(idx).name;
  4778. field_full_name = 'wysiwyg' + field_name;
  4779. if(document.getElementById(field_full_name)){
  4780. document.getElementById(field_name).value = document.getElementById(field_full_name).contentWindow.document.body.innerHTML;
  4781. }
  4782. };
  4783. ";
  4784. };
  4785. echo "
  4786. document.".$this->unique_prefix."frmEditRow.submit();
  4787. }else{
  4788. return false;
  4789. }
  4790. }";
  4791. echo "\n//-->\n";
  4792. echo "</script>\n";
  4793. }
  4794. //--------------------------------------------------------------------------
  4795. // return date format
  4796. //--------------------------------------------------------------------------
  4797. function myDate($field_value, $type="datedmy"){
  4798. $ret_date = "";
  4799. if($type == "datedmy"){
  4800. if (substr(trim($field_value), 4, 1) == "-"){
  4801. $year1 = substr(trim($field_value), 0, 4);
  4802. $month1 = substr(trim($field_value), 5, 2);
  4803. $day1 = substr(trim($field_value), 8, 2);
  4804. if($day1 != ""){ $ret_date = $day1."-".$month1."-".$year1; }
  4805. }else{
  4806. $year1 = substr(trim($field_value), 6, 4);
  4807. $month1 = substr(trim($field_value), 3, 2);
  4808. $day1 = substr(trim($field_value), 0, 2);
  4809. if($day1 != ""){ $ret_date = $day1."-".$month1."-".$year1; }
  4810. }
  4811. }else if($type == "datetimedmy"){
  4812. if (substr(trim($field_value), 4, 1) == "-"){
  4813. $year1 = substr(trim($field_value), 0, 4);
  4814. $month1 = substr(trim($field_value), 5, 2);
  4815. $day1 = substr(trim($field_value), 8, 2);
  4816. $time1 = substr(trim($field_value), 11, 2);
  4817. $time2 = substr(trim($field_value), 14, 2);
  4818. $time3 = substr(trim($field_value), 17, 2);
  4819. if($day1 != ""){ $ret_date = $day1."-".$month1."-".$year1." ".$time1.":".$time2.":".$time3; }
  4820. }else{
  4821. $year1 = substr(trim($field_value), 6, 4);
  4822. $month1 = substr(trim($field_value), 3, 2);
  4823. $day1 = substr(trim($field_value), 0, 2);
  4824. $time1 = substr(trim($field_value), 11, 2);
  4825. $time2 = substr(trim($field_value), 14, 2);
  4826. $time3 = substr(trim($field_value), 17, 2);
  4827. if($day1 != ""){ $ret_date = $day1."-".$month1."-".$year1." ".$time1.":".$time2.":".$time3; }
  4828. }
  4829. }else{
  4830. $ret_date = $field_value;
  4831. }
  4832. return $ret_date;
  4833. }
  4834. ////////////////////////////////////////////////////////////////////////////
  4835. //
  4836. // Non documented
  4837. //
  4838. ////////////////////////////////////////////////////////////////////////////
  4839. function allowHighlighting($option = true){ $this->row_highlighting_allowed = (($option == true) || ($option == "true")) ? true : false ; }
  4840. //--------------------------------------------------------------------------
  4841. // get Next Id
  4842. //--------------------------------------------------------------------------
  4843. function getNextId(){
  4844. if(isset($this->db_handler)){
  4845. return $this->db_handler->nextId();
  4846. }else{
  4847. return "-1";
  4848. }
  4849. #$sql = " SELECT MAX(".$this->primary_key.") as max_id FROM ".$this->tbl_name." ";
  4850. #$dSet = $this->db_handler->query($sql);
  4851. #if($row = $dSet->fetchRow()){
  4852. # return $row[0]+1;
  4853. #}
  4854. }
  4855. //--------------------------------------------------------------------------
  4856. // set messages
  4857. //--------------------------------------------------------------------------
  4858. function setDgMessages($add_message = "", $update_message = "", $delete_message = ""){
  4859. $this->dg_messages['add'] = $add_message;
  4860. $this->dg_messages['update'] = $update_message;
  4861. $this->dg_messages['delete'] = $delete_message;
  4862. }
  4863. //--------------------------------------------------------------------------
  4864. // set header names in columnar layout
  4865. //--------------------------------------------------------------------------
  4866. function setHeadersInColumnarLayout($field_header = "", $field_value_header = ""){
  4867. $this->field_header = $field_header;
  4868. $this->field_value_header = $field_value_header;
  4869. }
  4870. //--------------------------------------------------------------------------
  4871. // set javascript errors display style
  4872. //--------------------------------------------------------------------------
  4873. function setJsErrorsDisplayStyle($display_style = "all"){
  4874. $this->js_validation_errors = ($display_style == "all") ? "true" : "false";
  4875. }
  4876. //--------------------------------------------------------------------------
  4877. // selectSqlItem - return the first field after executing custom SELECT SQL statement
  4878. //--------------------------------------------------------------------------
  4879. function selectSqlItem($sql = ""){
  4880. $dataField = "";
  4881. if($sql != ""){
  4882. $this->setEncodingOnDatabase();
  4883. $this->db_handler->setFetchMode(DB_FETCHMODE_ORDERED);
  4884. $dataSet = & $this->db_handler->query($sql);
  4885. if($dataSet->numCols() > 0){
  4886. $row = $dataSet->fetchRow();
  4887. $dataField = $row[0];
  4888. }
  4889. if($this->debug){
  4890. if($this->db_handler->isError($dataSet) == 1){ $debugInfo = "<tr><td>".$dataSet->getDebugInfo()."</td></tr>"; } else { $debugInfo = ""; };
  4891. 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 />";
  4892. }
  4893. }
  4894. return $dataField;
  4895. }
  4896. //--------------------------------------------------------------------------
  4897. // executeSql - return dataSet after executing custom SQL statement
  4898. //--------------------------------------------------------------------------
  4899. function executeSQL($sql = ""){
  4900. $dataSet = "";
  4901. if($sql != ""){
  4902. $this->setEncodingOnDatabase();
  4903. $dataSet = & $this->db_handler->query($sql);
  4904. }
  4905. if($this->debug){
  4906. if($this->db_handler->isError($dataSet) == 1){ $debugInfo = "<tr><td>".$dataSet->getDebugInfo()."</td></tr>"; } else { $debugInfo = ""; };
  4907. 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 />";
  4908. }
  4909. return $dataSet;
  4910. }
  4911. ////////////////////////////////////////////////////////////////////////////
  4912. //
  4913. // Auxiliary methods
  4914. // -------------------------------------------------------------------------
  4915. ////////////////////////////////////////////////////////////////////////////
  4916. //--------------------------------------------------------------------------
  4917. // get Formatted Microtime
  4918. //--------------------------------------------------------------------------
  4919. function getFormattedMicrotime(){
  4920. list($usec, $sec) = explode(' ', microtime());
  4921. return ((float)$usec + (float)$sec);
  4922. }
  4923. //--------------------------------------------------------------------------
  4924. // download export file
  4925. //--------------------------------------------------------------------------
  4926. function exportDownloadFile($file_name){
  4927. return "<script type='text/javascript'>\n<!--\n ".
  4928. "if(confirm('Do you want to export datagrid content into [".$file_name."] file?')){ ".
  4929. " document.write('".str_replace("_FILE_", $file_name, $this->lang['export_message'])."'); ".
  4930. " document.location = '".$this->directory."scripts/download.php?dir=".$this->exporting_directory."&file=".$file_name."'; ".
  4931. "} else {".
  4932. " window.close();".
  4933. "}".
  4934. "\n//-->\n</script>";
  4935. }
  4936. //--------------------------------------------------------------------------
  4937. // overloaded php function strtolower
  4938. //--------------------------------------------------------------------------
  4939. function strToLower($str){
  4940. if($this->lang_name == "en"){
  4941. return strtolower($str);
  4942. }else{
  4943. return mb_strtolower($str, mb_detect_encoding($str));
  4944. }
  4945. }
  4946. //--------------------------------------------------------------------------
  4947. // check if there is any resizable field
  4948. //--------------------------------------------------------------------------
  4949. function resizableFieldExists(){
  4950. foreach($this->columns_edit_mode as $fldName => $fldValue){
  4951. foreach($fldValue as $key => $val){
  4952. if(($key == "resizable") && (($val == true) || ($val == "true"))) return true;
  4953. }
  4954. }
  4955. return false;
  4956. }
  4957. //--------------------------------------------------------------------------
  4958. // check if there is any datetime field
  4959. //--------------------------------------------------------------------------
  4960. function datetimeFieldExists($cal_type = ""){
  4961. $found_field_type = false;
  4962. $found_calendar_type = false;
  4963. foreach($this->columns_edit_mode as $fldName => $fldValue){
  4964. foreach($fldValue as $key => $val){
  4965. if($key == "type"){
  4966. if(($val == "date") || ($val == "datedmy") || ($val == "datetime") || ($val == "datetimedmy") || ($val == "time")){
  4967. $found_field_type = true;
  4968. }
  4969. }
  4970. if($key == "calendar_type"){
  4971. if(strtolower($val) == $cal_type){
  4972. $found_calendar_type = true;
  4973. }
  4974. }
  4975. if($found_field_type && $found_calendar_type) return true;
  4976. }
  4977. }
  4978. return false;
  4979. }
  4980. //--------------------------------------------------------------------------
  4981. // check if there is any field with floating tool tips
  4982. //--------------------------------------------------------------------------
  4983. function floatingToolTipsFieldExists(){
  4984. $tooltip_allowed = false;
  4985. foreach($this->columns_view_mode as $fldName => $fldValue){
  4986. foreach($fldValue as $key => $val){
  4987. if(($key == "tooltip") && (($val == true) || ($val == "true"))){ $tooltip_allowed = true; }
  4988. if($tooltip_allowed && ($key == "tooltip_type") && (strtolower($val) == "floating")) { return true; }
  4989. }
  4990. }
  4991. return false;
  4992. }
  4993. //--------------------------------------------------------------------------
  4994. // check if there is any wysiwyg field
  4995. //--------------------------------------------------------------------------
  4996. function wysiwygFieldExists(){
  4997. foreach($this->columns_edit_mode as $fldName => $fldValue){
  4998. foreach($fldValue as $key => $val){
  4999. if(($key == "edit_type") && (strtolower($val) == "wysiwyg")) return true;
  5000. }
  5001. }
  5002. return false;
  5003. }
  5004. //--------------------------------------------------------------------------
  5005. // get size of the remote file
  5006. //--------------------------------------------------------------------------
  5007. function getRemoteFileSize($url, $user = "", $pw = ""){
  5008. ob_start();
  5009. $ch = curl_init($url);
  5010. curl_setopt($ch, CURLOPT_HEADER, 1);
  5011. curl_setopt($ch, CURLOPT_NOBODY, 1);
  5012. if(!empty($user) && !empty($pw)) {
  5013. $headers = array('Authorization: Basic ' . base64_encode("$user:$pw"));
  5014. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  5015. }
  5016. $ok = curl_exec($ch);
  5017. curl_close($ch);
  5018. $head = ob_get_contents();
  5019. ob_end_clean();
  5020. $regex = '/Content-Length:\s([0-9].+?)\s/';
  5021. $count = preg_match($regex, $head, $matches);
  5022. return isset($matches[1]) ? $matches[1] : "unknown";
  5023. }
  5024. //--------------------------------------------------------------------------
  5025. // get http port
  5026. //--------------------------------------------------------------------------
  5027. function getPort(){
  5028. $port = "";
  5029. if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != "80"){
  5030. $port = ":".$_SERVER['SERVER_PORT'];
  5031. }
  5032. return $port;
  5033. }
  5034. //--------------------------------------------------------------------------
  5035. // get Protocol (http/s)
  5036. //--------------------------------------------------------------------------
  5037. function getProtocol(){
  5038. $protocol = "http://";
  5039. if((isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != "off")) ||
  5040. strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, 5)) == "https"){
  5041. $protocol = "https://";
  5042. }
  5043. return $protocol;
  5044. }
  5045. //--------------------------------------------------------------------------
  5046. // return last substring occurence
  5047. //--------------------------------------------------------------------------
  5048. function lastSubStrOccurence($string, $substring){
  5049. $string = str_replace("\t", " ", $string);
  5050. $string = str_replace("\n", " ", $string);
  5051. $string = strrev(strtolower($string));
  5052. $substring = strrev(strtolower($substring));
  5053. return strpos($string, $substring);
  5054. }
  5055. //--------------------------------------------------------------------------
  5056. // gets random string
  5057. //--------------------------------------------------------------------------
  5058. function getRandomString($length = 20) {
  5059. $template = "1234567890abcdefghijklmnopqrstuvwxyz";
  5060. settype($template, "string");
  5061. settype($length, "integer");
  5062. settype($rndstring, "string");
  5063. settype($a, "integer");
  5064. settype($b, "integer");
  5065. for ($a = 0; $a <= $length; $a++) {
  5066. $b = rand(0, strlen($template) - 1);
  5067. $rndstring .= $template[$b];
  5068. }
  5069. return $rndstring;
  5070. }
  5071. //--------------------------------------------------------------------------
  5072. // set browser definitions
  5073. //--------------------------------------------------------------------------
  5074. function setBrowserDefinitions(){
  5075. $bd = array();
  5076. $agent = $_SERVER['HTTP_USER_AGENT'];
  5077. // initialize properties
  5078. $bd['platform'] = "Windows";
  5079. $bd['browser'] = "MSIE";
  5080. $bd['version'] = "6.0";
  5081. // find operating system
  5082. if (eregi("win", $agent)) $bd['platform'] = "Windows";
  5083. elseif (eregi("mac", $agent)) $bd['platform'] = "MacIntosh";
  5084. elseif (eregi("linux", $agent)) $bd['platform'] = "Linux";
  5085. elseif (eregi("OS/2", $agent)) $bd['platform'] = "OS/2";
  5086. elseif (eregi("BeOS", $agent)) $bd['platform'] = "BeOS";
  5087. // test for Opera
  5088. if (eregi("opera",$agent)){
  5089. $val = stristr($agent, "opera");
  5090. if (eregi("/", $val)){
  5091. $val = explode("/",$val); $bd['browser'] = $val[0]; $val = explode(" ",$val[1]); $bd['version'] = $val[0];
  5092. }else{
  5093. $val = explode(" ",stristr($val,"opera")); $bd['browser'] = $val[0]; $bd['version'] = $val[1];
  5094. }
  5095. // test for MS Internet Explorer version 1
  5096. }elseif(eregi("microsoft internet explorer", $agent)){
  5097. $bd['browser'] = "MSIE"; $bd['version'] = "1.0"; $var = stristr($agent, "/");
  5098. if (ereg("308|425|426|474|0b1", $var)) $bd['version'] = "1.5";
  5099. // test for MS Internet Explorer
  5100. }elseif(eregi("msie",$agent) && !eregi("opera",$agent)){
  5101. $val = explode(" ",stristr($agent,"msie")); $bd['browser'] = $val[0]; $bd['version'] = $val[1];
  5102. // test for MS Pocket Internet Explorer
  5103. }elseif(eregi("mspie",$agent) || eregi('pocket', $agent)){
  5104. $val = explode(" ",stristr($agent,"mspie")); $bd['browser'] = "MSPIE"; $bd['platform'] = "WindowsCE";
  5105. if (eregi("mspie", $agent))
  5106. $bd['version'] = $val[1];
  5107. else {
  5108. $val = explode("/",$agent); $bd['version'] = $val[1];
  5109. }
  5110. // test for Firebird
  5111. }elseif(eregi("firebird", $agent)){
  5112. $bd['browser']="Firebird"; $val = stristr($agent, "Firebird"); $val = explode("/",$val); $bd['version'] = $val[1];
  5113. // test for Firefox
  5114. }elseif(eregi("Firefox", $agent)){
  5115. $bd['browser']="Firefox"; $val = stristr($agent, "Firefox"); $val = explode("/",$val); $bd['version'] = $val[1];
  5116. // test for Mozilla Alpha/Beta Versions
  5117. }elseif(eregi("mozilla",$agent) && eregi("rv:[0-9].[0-9][a-b]",$agent) && !eregi("netscape",$agent)){
  5118. $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]);
  5119. // test for Mozilla Stable Versions
  5120. }elseif(eregi("mozilla",$agent) && eregi("rv:[0-9]\.[0-9]",$agent) && !eregi("netscape",$agent)){
  5121. $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]);
  5122. // remaining two tests are for Netscape
  5123. }elseif(eregi("netscape",$agent)){
  5124. $val = explode(" ",stristr($agent,"netscape")); $val = explode("/",$val[0]); $bd['browser'] = $val[0]; $bd['version'] = $val[1];
  5125. }elseif(eregi("mozilla",$agent) && !eregi("rv:[0-9]\.[0-9]\.[0-9]",$agent)){
  5126. $val = explode(" ",stristr($agent,"mozilla")); $val = explode("/",$val[0]); $bd['browser'] = "Netscape"; $bd['version'] = $val[1];
  5127. }
  5128. // clean up extraneous garbage that may be in the name
  5129. $bd['browser'] = ereg_replace("[^a-z,A-Z]", "", $bd['browser']);
  5130. $bd['version'] = ereg_replace("[^0-9,.,a-z,A-Z]", "", $bd['version']);
  5131. $this->browser_name = $bd['browser'];
  5132. $this->browser_version = $bd['version'];
  5133. $this->platform = $bd['platform'];
  5134. }
  5135. //--------------------------------------------------------------------------
  5136. // get Language Abbreviation for Calendar
  5137. //--------------------------------------------------------------------------
  5138. function getLangAbbrForCalendar(){
  5139. $return_abbrv = "en";
  5140. switch($this->lang_name){
  5141. case "ar": $return_abbrv = "en"; break; // Arabic
  5142. case "hr": $return_abbrv = "hr"; break; // Bosnian/Croatian
  5143. case "bg": $return_abbrv = "bg"; break; // Bulgarian
  5144. case "pb": $return_abbrv = "pt"; break; // Brazilian Portuguese
  5145. case "ca": $return_abbrv = "ca"; break; // Catala
  5146. case "ch": $return_abbrv = "cn"; break; // Chinese
  5147. case "es": $return_abbrv = "es"; break; // Espanol
  5148. case "fr": $return_abbrv = "fr"; break; // Francais
  5149. case "de": $return_abbrv = "de"; break; // German
  5150. case "hu": $return_abbrv = "hu"; break; // Hungarian
  5151. case "it": $return_abbrv = "it"; break; // Italiano
  5152. case "nl": $return_abbrv = "nl"; break; // Netherlands/"Vlaams"(Flemish)
  5153. case "pl": $return_abbrv = "pl"; break; // Polish
  5154. case "sr": $return_abbrv = "en"; break; // Serbian
  5155. case "se": $return_abbrv = "sv"; break; // Swedish
  5156. case "en":
  5157. default:
  5158. $return_abbrv = "en"; break;
  5159. }
  5160. return $return_abbrv;
  5161. }
  5162. //--------------------------------------------------------------------------
  5163. // set Language
  5164. //--------------------------------------------------------------------------
  5165. function setInterfaceLang($lang_name = ""){
  5166. $default_language = false;
  5167. if(($lang_name != "") && (strlen($lang_name) == 2)){ $this->lang_name = $lang_name; }
  5168. if (file_exists($this->directory.'languages/'.$this->lang_name.'.php')) {
  5169. include_once($this->directory.'languages/'.$this->lang_name.'.php');
  5170. if (function_exists('setLanguage')){
  5171. $this->lang = setLanguage();
  5172. }else{
  5173. 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 />"; }
  5174. $default_language = true;
  5175. }
  5176. }else{
  5177. if((strtolower($lang_name) != "en") && ($this->debug)){
  5178. 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 />";
  5179. }
  5180. $default_language = true;
  5181. }
  5182. if($default_language){
  5183. $this->lang['='] = "="; // "equal";
  5184. $this->lang['>'] = ">"; // "bigger";
  5185. $this->lang['<'] = "<"; // "smaller";
  5186. $this->lang['add'] = "Add";
  5187. $this->lang['add_new'] = "+ Add New";
  5188. $this->lang['add_new_record'] = "Add new record";
  5189. $this->lang['adding_operation_completed'] = "The adding operation completed successfully!";
  5190. $this->lang['adding_operation_uncompleted'] = "The adding operation uncompleted!";
  5191. $this->lang['and'] = "and";
  5192. $this->lang['any'] = "any";
  5193. $this->lang['ascending'] = "Ascending";
  5194. $this->lang['back'] = "Back";
  5195. $this->lang['cancel'] = "Cancel";
  5196. $this->lang['cancel_creating_new_record'] = "Are you sure you want to cancel creating new record?";
  5197. $this->lang['check_all'] = "Check All";
  5198. $this->lang['clear'] = "Clear";
  5199. $this->lang['create'] = "Create";
  5200. $this->lang['create_new_record'] = "Create new record";
  5201. $this->lang['current'] = "current";
  5202. $this->lang['delete'] = "Delete";
  5203. $this->lang['delete_record'] = "Delete record";
  5204. $this->lang['delete_selected'] = "Delete selected";
  5205. $this->lang['delete_selected_records'] = "Are you sure you want to delete the selected records?";
  5206. $this->lang['delete_this_record'] = "Are you sure you want to delete this record?";
  5207. $this->lang['deleting_operation_completed'] = "The deleting operation completed successfully!";
  5208. $this->lang['deleting_operation_uncompleted'] = "The deleting operation uncompleted!";
  5209. $this->lang['descending'] = "Descending";
  5210. $this->lang['details'] = "Details";
  5211. $this->lang['details_selected'] = "View selected";
  5212. $this->lang['edit'] = "Edit";
  5213. $this->lang['edit_selected'] = "Edit selected";
  5214. $this->lang['edit_record'] = "Edit record";
  5215. $this->lang['edit_selected_records'] = "Are you sure you want to edit the selected records?";
  5216. $this->lang['errors'] = "Errors";
  5217. $this->lang['export_to_excel'] = "Export to Excel";
  5218. $this->lang['export_to_pdf'] = "Export to PDF";
  5219. $this->lang['export_to_xml'] = "Export to XML";
  5220. $this->lang['export_message'] = "<label class='".$this->css_class."_class_label'>The file _FILE_ is ready. After you finish downloading,</label> <a class='".$this->css_class."_class_error_message no_print' href='javascript: window.close();'>close this window</a>.";
  5221. $this->lang['field'] = "Field";
  5222. $this->lang['field_value'] = "Field Value";
  5223. $this->lang['file_find_error'] = "Cannot find file: <b>_FILE_</b>. <br />Check if this file exists and you use a correct path!";
  5224. $this->lang['file_opening_error'] = "Cannot open a file. Check your permissions.";
  5225. $this->lang['file_writing_error'] = "Cannot write to file. Check writing permissions.";
  5226. $this->lang['file_invalid file_size'] = "Invalid file size: ";
  5227. $this->lang['file_uploading_error'] = "There was an error while uploading, please try again!";
  5228. $this->lang['file_deleting_error'] = "There was an error while deleting!";
  5229. $this->lang['first'] = "first";
  5230. $this->lang['handle_selected_records'] = "Are you sure you want to handle the selected records?";
  5231. $this->lang['hide_search'] = "Hide Search";
  5232. $this->lang['last'] = "last";
  5233. $this->lang['like'] = "like";
  5234. $this->lang['like%'] = "like%"; // "begins with";
  5235. $this->lang['%like'] = "%like"; // "ends with";
  5236. $this->lang['loading_data'] = "loading data...";
  5237. $this->lang['max'] = "max";
  5238. $this->lang['next'] = "next";
  5239. $this->lang['no'] = "No";
  5240. $this->lang['no_data_found'] = "No data found";
  5241. $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.";
  5242. $this->lang['no_image'] = "No Image";
  5243. $this->lang['not_like'] = "not like";
  5244. $this->lang['of'] = "of";
  5245. $this->lang['or'] = "or";
  5246. $this->lang['pages'] = "Pages";
  5247. $this->lang['page_size'] = "Page size";
  5248. $this->lang['previous'] = "previous";
  5249. $this->lang['printable_view'] = "Printable View";
  5250. $this->lang['print_now'] = "Print Now";
  5251. $this->lang['print_now_title'] = "Click here to print this page";
  5252. $this->lang['record_n'] = "Record # ";
  5253. $this->lang['refresh_page'] = "Refresh Page";
  5254. $this->lang['remove'] = "Remove";
  5255. $this->lang['reset'] = "Reset";
  5256. $this->lang['results'] = "Results";
  5257. $this->lang['required_fields_msg'] = "<font color='#cd0000'>*</font> Items marked with an asterisk are required";
  5258. $this->lang['search'] = "Search";
  5259. $this->lang['search_d'] = "Search"; // (description)
  5260. $this->lang['search_type'] = "Search type";
  5261. $this->lang['select'] = "select";
  5262. $this->lang['set_date'] = "Set date";
  5263. $this->lang['sort'] = "Sort";
  5264. $this->lang['total'] = "Total";
  5265. $this->lang['turn_on_debug_mode'] = "For more information, turn on debug mode.";
  5266. $this->lang['uncheck_all'] = "Uncheck All";
  5267. $this->lang['unhide_search'] = "Unhide Search";
  5268. $this->lang['unique_field_error'] = "The field _FIELD_ allows only unique values - please reenter!";
  5269. $this->lang['update'] = "Update";
  5270. $this->lang['update_record'] = "Update record";
  5271. $this->lang['updating_operation_completed'] = "The updating operation completed successfully!";
  5272. $this->lang['updating_operation_uncompleted'] = "The updating operation uncompleted!";
  5273. $this->lang['upload'] = "Upload";
  5274. $this->lang['view'] = "View";
  5275. $this->lang['view_details'] = "View details";
  5276. $this->lang['warnings'] = "Warnings";
  5277. $this->lang['with_selected'] = "With selected";
  5278. $this->lang['wrong_field_name'] = "Wrong field name";
  5279. $this->lang['wrong_parameter_error'] = "Wrong parameter in [<b>_FIELD_</b>]: _VALUE_";
  5280. $this->lang['yes'] = "Yes";
  5281. }
  5282. }
  5283. }// end class
  5284. ?>