PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/includes/functions/html_output.php

https://github.com/ZenMagick/zc-base
PHP | 346 lines | 233 code | 65 blank | 48 comment | 120 complexity | 48dc332a36f2eb1340526b40b81068ec MD5 | raw file
  1. <?php
  2. /**
  3. * @package admin
  4. * @copyright Copyright 2003-2009 Zen Cart Development Team
  5. * @copyright Portions Copyright 2003 osCommerce
  6. * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  7. * @version $Id: html_output.php 17361 2010-08-25 14:58:56Z wilt $
  8. */
  9. ////
  10. // The HTML href link wrapper function
  11. function zen_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true) {
  12. global $request_type, $session_started, $http_domain, $https_domain;
  13. if ($page == '') {
  14. die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>Function used:<br><br>zen_href_link(\'' . $page . '\', \'' . $parameters . '\', \'' . $connection . '\')</b>');
  15. }
  16. if ($connection == 'NONSSL') {
  17. $link = HTTP_SERVER . DIR_WS_ADMIN;
  18. } elseif ($connection == 'SSL') {
  19. if (ENABLE_SSL_ADMIN == 'true') {
  20. $link = HTTPS_SERVER . DIR_WS_HTTPS_ADMIN;
  21. } else {
  22. $link = HTTP_SERVER . DIR_WS_ADMIN;
  23. }
  24. } else {
  25. die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL<br><br>Function used:<br><br>zen_href_link(\'' . $page . '\', \'' . $parameters . '\', \'' . $connection . '\')</b>');
  26. }
  27. if (!strstr($page, '.php')) $page .= '.php';
  28. if ($parameters == '') {
  29. $link = $link . $page;
  30. $separator = '?';
  31. } else {
  32. $link = $link . $page . '?' . $parameters;
  33. $separator = '&';
  34. }
  35. while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);
  36. // Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
  37. if ( ($add_session_id == true) && ($session_started == true) ) {
  38. if (defined('SID') && zen_not_null(SID)) {
  39. $sid = SID;
  40. } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL_ADMIN == 'true') ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {
  41. //die($connection);
  42. if ($http_domain != $https_domain) {
  43. $sid = zen_session_name() . '=' . zen_session_id();
  44. }
  45. }
  46. }
  47. if (isset($sid)) {
  48. $link .= $separator . $sid;
  49. }
  50. return $link;
  51. }
  52. function zen_catalog_href_link($page = '', $parameters = '', $connection = 'NONSSL') {
  53. if ($connection == 'NONSSL') {
  54. $link = HTTP_CATALOG_SERVER . DIR_WS_CATALOG;
  55. } elseif ($connection == 'SSL') {
  56. if (ENABLE_SSL_CATALOG == 'true') {
  57. $link = HTTPS_CATALOG_SERVER . DIR_WS_HTTPS_CATALOG;
  58. } else {
  59. $link = HTTP_CATALOG_SERVER . DIR_WS_CATALOG;
  60. }
  61. } else {
  62. die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL<br><br>Function used:<br><br>zen_href_link(\'' . $page . '\', \'' . $parameters . '\', \'' . $connection . '\')</b>');
  63. }
  64. if ($parameters == '') {
  65. $link .= 'index.php?main_page='. $page;
  66. } else {
  67. $link .= 'index.php?main_page='. $page . "&" . zen_output_string($parameters);
  68. }
  69. while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);
  70. return $link;
  71. }
  72. ////
  73. // The HTML image wrapper function
  74. function zen_image($src, $alt = '', $width = '', $height = '', $params = '') {
  75. $image = '<img src="' . $src . '" border="0" alt="' . $alt . '"';
  76. if ($alt) {
  77. $image .= ' title=" ' . $alt . ' "';
  78. }
  79. if ($width) {
  80. $image .= ' width="' . $width . '"';
  81. }
  82. if ($height) {
  83. $image .= ' height="' . $height . '"';
  84. }
  85. if ($params) {
  86. $image .= ' ' . $params;
  87. }
  88. $image .= '>';
  89. return $image;
  90. }
  91. ////
  92. // The HTML form submit button wrapper function
  93. // Outputs a button in the selected language
  94. function zen_image_submit($image, $alt = '', $parameters = '') {
  95. global $language;
  96. $image_submit = '<input type="image" src="' . zen_output_string(DIR_WS_LANGUAGES . $_SESSION['language'] . '/images/buttons/' . $image) . '" border="0" alt="' . zen_output_string($alt) . '"';
  97. if (zen_not_null($alt)) $image_submit .= ' title=" ' . zen_output_string($alt) . ' "';
  98. if (zen_not_null($parameters)) $image_submit .= ' ' . $parameters;
  99. $image_submit .= '>';
  100. return $image_submit;
  101. }
  102. ////
  103. // Draw a 1 pixel black line
  104. function zen_black_line() {
  105. return zen_image(DIR_WS_IMAGES . 'pixel_black.gif', '', '100%', '1');
  106. }
  107. ////
  108. // Output a separator either through whitespace, or with an image
  109. function zen_draw_separator($image = 'pixel_black.gif', $width = '100%', $height = '1') {
  110. return zen_image(DIR_WS_IMAGES . $image, '', $width, $height);
  111. }
  112. ////
  113. // Output a function button in the selected language
  114. function zen_image_button($image, $alt = '', $params = '') {
  115. global $language;
  116. return zen_image(DIR_WS_LANGUAGES . $_SESSION['language'] . '/images/buttons/' . $image, $alt, '', '', $params);
  117. }
  118. ////
  119. // javascript to dynamically update the states/provinces list when the country is changed
  120. // TABLES: zones
  121. function zen_js_zone_list($country, $form, $field) {
  122. global $db;
  123. $countries = $db->Execute("select distinct zone_country_id
  124. from " . TABLE_ZONES . "
  125. order by zone_country_id");
  126. $num_country = 1;
  127. $output_string = '';
  128. while (!$countries->EOF) {
  129. if ($num_country == 1) {
  130. $output_string .= ' if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "\n";
  131. } else {
  132. $output_string .= ' } else if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "\n";
  133. }
  134. $states = $db->Execute("select zone_name, zone_id
  135. from " . TABLE_ZONES . "
  136. where zone_country_id = '" . $countries->fields['zone_country_id'] . "'
  137. order by zone_name");
  138. $num_state = 1;
  139. while (!$states->EOF) {
  140. if ($num_state == '1') $output_string .= ' ' . $form . '.' . $field . '.options[0] = new Option("' . PLEASE_SELECT . '", "");' . "\n";
  141. $output_string .= ' ' . $form . '.' . $field . '.options[' . $num_state . '] = new Option("' . $states->fields['zone_name'] . '", "' . $states->fields['zone_id'] . '");' . "\n";
  142. $num_state++;
  143. $states->MoveNext();
  144. }
  145. $num_country++;
  146. $countries->MoveNext();
  147. }
  148. $output_string .= ' } else {' . "\n" .
  149. ' ' . $form . '.' . $field . '.options[0] = new Option("' . TYPE_BELOW . '", "");' . "\n" .
  150. ' }' . "\n";
  151. return $output_string;
  152. }
  153. ////
  154. // Output a form
  155. function zen_draw_form($name, $action, $parameters = '', $method = 'post', $params = '', $usessl = 'false') {
  156. $form = '<form name="' . zen_output_string($name) . '" action="';
  157. if (zen_not_null($parameters)) {
  158. if ($usessl) {
  159. $form .= zen_href_link($action, $parameters, 'NONSSL');
  160. } else {
  161. $form .= zen_href_link($action, $parameters, 'NONSSL');
  162. }
  163. } else {
  164. if ($usessl) {
  165. $form .= zen_href_link($action, '', 'NONSSL');
  166. } else {
  167. $form .= zen_href_link($action, '', 'NONSSL');
  168. }
  169. }
  170. $form .= '" method="' . zen_output_string($method) . '"';
  171. if (zen_not_null($params)) {
  172. $form .= ' ' . $params;
  173. }
  174. $form .= '>';
  175. $form .= '<input type="hidden" name="securityToken" value="' . $_SESSION['securityToken'] . '">';
  176. return $form;
  177. }
  178. ////
  179. // Output a form input field
  180. function zen_draw_input_field($name, $value = '~*~*#', $parameters = '', $required = false, $type = 'text', $reinsert_value = true) {
  181. $field = '<input type="' . zen_output_string($type) . '" name="' . zen_output_string($name) . '"';
  182. if ( $value == '~*~*#' && (isset($GLOBALS[$name]) && is_string($GLOBALS[$name])) && ($reinsert_value == true) ) {
  183. $field .= ' value="' . zen_output_string(stripslashes($GLOBALS[$name])) . '"';
  184. } elseif ($value != '~*~*#' && zen_not_null($value)) {
  185. $field .= ' value="' . zen_output_string($value) . '"';
  186. }
  187. if (zen_not_null($parameters)) $field .= ' ' . $parameters;
  188. $field .= ' />';
  189. return $field;
  190. }
  191. ////
  192. // Output a form password field
  193. function zen_draw_password_field($name, $value = '', $required = false) {
  194. $field = zen_draw_input_field($name, $value, 'maxlength="40"', $required, 'password', false);
  195. return $field;
  196. }
  197. ////
  198. // Output a form filefield
  199. function zen_draw_file_field($name, $required = false) {
  200. $field = zen_draw_input_field($name, '', ' size="50" ', $required, 'file');
  201. return $field;
  202. }
  203. ////
  204. // Output a selection field - alias function for zen_draw_checkbox_field() and zen_draw_radio_field()
  205. function zen_draw_selection_field($name, $type, $value = '', $checked = false, $compare = '', $parameters = '') {
  206. $selection = '<input type="' . zen_output_string($type) . '" name="' . zen_output_string($name) . '"';
  207. if (zen_not_null($value)) $selection .= ' value="' . zen_output_string($value) . '"';
  208. if ( ($checked == true) || (isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) && ($GLOBALS[$name] == 'on')) || (isset($value) && isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) && (stripslashes($GLOBALS[$name]) == $value)) || (zen_not_null($value) && zen_not_null($compare) && ($value == $compare)) ) {
  209. $selection .= ' checked="checked"';
  210. }
  211. if (zen_not_null($parameters)) $selection .= ' ' . $parameters;
  212. $selection .= ' />';
  213. return $selection;
  214. }
  215. ////
  216. // Output a form checkbox field
  217. function zen_draw_checkbox_field($name, $value = '', $checked = false, $compare = '', $parameters = '') {
  218. return zen_draw_selection_field($name, 'checkbox', $value, $checked, $compare, $parameters);
  219. }
  220. ////
  221. // Output a form radio field
  222. function zen_draw_radio_field($name, $value = '', $checked = false, $compare = '', $parameters = '') {
  223. return zen_draw_selection_field($name, 'radio', $value, $checked, $compare, $parameters);
  224. }
  225. ////
  226. // Output a form textarea field
  227. function zen_draw_textarea_field($name, $wrap, $width, $height, $text = '~*~*#', $parameters = '', $reinsert_value = true) {
  228. $field = '<textarea name="' . zen_output_string($name) . '" wrap="' . zen_output_string($wrap) . '" cols="' . zen_output_string($width) . '" rows="' . zen_output_string($height) . '"';
  229. if (zen_not_null($parameters)) $field .= ' ' . $parameters;
  230. $field .= '>';
  231. if ($text == '~*~*#' && (isset($GLOBALS[$name]) && is_string($GLOBALS[$name])) && ($reinsert_value == true) ) {
  232. $field .= stripslashes($GLOBALS[$name]);
  233. $field = str_replace('&gt;', '>', $field);
  234. } elseif ($text != '~*~*#' && zen_not_null($text)) {
  235. $field = str_replace('&gt;', '>', $field);
  236. $field .= $text;
  237. }
  238. $field .= '</textarea>';
  239. return $field;
  240. }
  241. ////
  242. // Output a form hidden field
  243. function zen_draw_hidden_field($name, $value = '', $parameters = '') {
  244. $field = '<input type="hidden" name="' . zen_output_string($name) . '"';
  245. if (zen_not_null($value)) {
  246. $field .= ' value="' . zen_output_string($value) . '"';
  247. } elseif (isset($GLOBALS[$name]) && is_string($GLOBALS[$name])) {
  248. $field .= ' value="' . zen_output_string(stripslashes($GLOBALS[$name])) . '"';
  249. }
  250. if (zen_not_null($parameters)) $field .= ' ' . $parameters;
  251. $field .= ' />';
  252. return $field;
  253. }
  254. ////
  255. // Output a form pull down menu
  256. function zen_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {
  257. // $field = '<select name="' . zen_output_string($name) . '"';
  258. $field = '<select rel="dropdown" name="' . zen_output_string($name) . '"';
  259. if (zen_not_null($parameters)) $field .= ' ' . $parameters;
  260. $field .= '>' . "\n";
  261. if (empty($default) && isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) ) $default = stripslashes($GLOBALS[$name]);
  262. for ($i=0, $n=sizeof($values); $i<$n; $i++) {
  263. $field .= '<option value="' . zen_output_string($values[$i]['id']) . '"';
  264. if ($default == $values[$i]['id']) {
  265. $field .= ' selected="selected"';
  266. }
  267. $field .= '>' . zen_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => '&#039;', '<' => '&lt;', '>' => '&gt;')) . '</option>' . "\n";
  268. }
  269. $field .= '</select>' . "\n";
  270. if ($required == true) $field .= TEXT_FIELD_REQUIRED;
  271. return $field;
  272. }
  273. ////
  274. // Hide form elements
  275. function zen_hide_session_id() {
  276. global $session_started;
  277. if ( ($session_started == true) && defined('SID') && zen_not_null(SID) ) {
  278. return zen_draw_hidden_field(zen_session_name(), zen_session_id());
  279. }
  280. }
  281. ?>