|
ZenCart_Documentation
1.5.0
http://www.collinsharper.com
|
00001 <?php 00010 00011 // The HTML href link wrapper function 00012 function zen_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true) { 00013 global $request_type, $session_started, $http_domain, $https_domain; 00014 if ($page == '') { 00015 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>'); 00016 } 00017 00018 if ($connection == 'NONSSL') { 00019 $link = HTTP_SERVER . DIR_WS_ADMIN; 00020 } elseif ($connection == 'SSL') { 00021 if (ENABLE_SSL_ADMIN == 'true') { 00022 $link = HTTPS_SERVER . DIR_WS_HTTPS_ADMIN; 00023 } else { 00024 $link = HTTP_SERVER . DIR_WS_ADMIN; 00025 } 00026 } else { 00027 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>'); 00028 } 00029 if (!strstr($page, '.php')) $page .= '.php'; 00030 if ($parameters == '') { 00031 $link = $link . $page; 00032 $separator = '?'; 00033 } else { 00034 $link = $link . $page . '?' . $parameters; 00035 $separator = '&'; 00036 } 00037 00038 while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1); 00039 00040 // Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined 00041 if ( ($add_session_id == true) && ($session_started == true) ) { 00042 if (defined('SID') && zen_not_null(SID)) { 00043 $sid = SID; 00044 } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL_ADMIN == 'true') ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) { 00045 //die($connection); 00046 if ($http_domain != $https_domain) { 00047 $sid = zen_session_name() . '=' . zen_session_id(); 00048 } 00049 } 00050 } 00051 00052 if (isset($sid)) { 00053 $link .= $separator . $sid; 00054 } 00055 00056 return $link; 00057 } 00058 00059 function zen_catalog_href_link($page = '', $parameters = '', $connection = 'NONSSL') { 00060 if ($connection == 'NONSSL') { 00061 $link = HTTP_CATALOG_SERVER . DIR_WS_CATALOG; 00062 } elseif ($connection == 'SSL') { 00063 if (ENABLE_SSL_CATALOG == 'true') { 00064 $link = HTTPS_CATALOG_SERVER . DIR_WS_HTTPS_CATALOG; 00065 } else { 00066 $link = HTTP_CATALOG_SERVER . DIR_WS_CATALOG; 00067 } 00068 } else { 00069 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>'); 00070 } 00071 if ($parameters == '') { 00072 $link .= 'index.php?main_page='. $page; 00073 } else { 00074 $link .= 'index.php?main_page='. $page . "&" . zen_output_string($parameters); 00075 } 00076 00077 while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1); 00078 00079 return $link; 00080 } 00081 00083 // The HTML image wrapper function 00084 function zen_image($src, $alt = '', $width = '', $height = '', $params = '') { 00085 $image = '<img src="' . $src . '" border="0" alt="' . $alt . '"'; 00086 if ($alt) { 00087 $image .= ' title=" ' . $alt . ' "'; 00088 } 00089 if ($width) { 00090 $image .= ' width="' . $width . '"'; 00091 } 00092 if ($height) { 00093 $image .= ' height="' . $height . '"'; 00094 } 00095 if ($params) { 00096 $image .= ' ' . $params; 00097 } 00098 $image .= '>'; 00099 00100 return $image; 00101 } 00102 00104 // The HTML form submit button wrapper function 00105 // Outputs a button in the selected language 00106 function zen_image_submit($image, $alt = '', $parameters = '') { 00107 global $language; 00108 00109 $image_submit = '<input type="image" src="' . zen_output_string(DIR_WS_LANGUAGES . $_SESSION['language'] . '/images/buttons/' . $image) . '" border="0" alt="' . zen_output_string($alt) . '"'; 00110 00111 if (zen_not_null($alt)) $image_submit .= ' title=" ' . zen_output_string($alt) . ' "'; 00112 00113 if (zen_not_null($parameters)) $image_submit .= ' ' . $parameters; 00114 00115 $image_submit .= '>'; 00116 00117 return $image_submit; 00118 } 00119 00121 // Draw a 1 pixel black line 00122 function zen_black_line() { 00123 return zen_image(DIR_WS_IMAGES . 'pixel_black.gif', '', '100%', '1'); 00124 } 00125 00127 // Output a separator either through whitespace, or with an image 00128 function zen_draw_separator($image = 'pixel_black.gif', $width = '100%', $height = '1') { 00129 return zen_image(DIR_WS_IMAGES . $image, '', $width, $height); 00130 } 00131 00133 // Output a function button in the selected language 00134 function zen_image_button($image, $alt = '', $params = '') { 00135 global $language; 00136 00137 return zen_image(DIR_WS_LANGUAGES . $_SESSION['language'] . '/images/buttons/' . $image, $alt, '', '', $params); 00138 } 00139 00141 // javascript to dynamically update the states/provinces list when the country is changed 00142 // TABLES: zones 00143 function zen_js_zone_list($country, $form, $field) { 00144 global $db; 00145 $countries = $db->Execute("select distinct zone_country_id 00146 from " . TABLE_ZONES . " 00147 order by zone_country_id"); 00148 00149 $num_country = 1; 00150 $output_string = ''; 00151 while (!$countries->EOF) { 00152 if ($num_country == 1) { 00153 $output_string .= ' if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "\n"; 00154 } else { 00155 $output_string .= ' } else if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "\n"; 00156 } 00157 00158 $states = $db->Execute("select zone_name, zone_id 00159 from " . TABLE_ZONES . " 00160 where zone_country_id = '" . $countries->fields['zone_country_id'] . "' 00161 order by zone_name"); 00162 00163 00164 $num_state = 1; 00165 while (!$states->EOF) { 00166 if ($num_state == '1') $output_string .= ' ' . $form . '.' . $field . '.options[0] = new Option("' . PLEASE_SELECT . '", "");' . "\n"; 00167 $output_string .= ' ' . $form . '.' . $field . '.options[' . $num_state . '] = new Option("' . $states->fields['zone_name'] . '", "' . $states->fields['zone_id'] . '");' . "\n"; 00168 $num_state++; 00169 $states->MoveNext(); 00170 } 00171 $num_country++; 00172 $countries->MoveNext(); 00173 } 00174 $output_string .= ' } else {' . "\n" . 00175 ' ' . $form . '.' . $field . '.options[0] = new Option("' . TYPE_BELOW . '", "");' . "\n" . 00176 ' }' . "\n"; 00177 00178 return $output_string; 00179 } 00180 00182 // Output a form 00183 function zen_draw_form($name, $action, $parameters = '', $method = 'post', $params = '', $usessl = 'false') { 00184 $form = '<form name="' . zen_output_string($name) . '" action="'; 00185 if (zen_not_null($parameters)) { 00186 if ($usessl) { 00187 $form .= zen_href_link($action, $parameters, 'NONSSL'); 00188 } else { 00189 $form .= zen_href_link($action, $parameters, 'NONSSL'); 00190 } 00191 } else { 00192 if ($usessl) { 00193 $form .= zen_href_link($action, '', 'NONSSL'); 00194 } else { 00195 $form .= zen_href_link($action, '', 'NONSSL'); 00196 } 00197 } 00198 $form .= '" method="' . zen_output_string($method) . '"'; 00199 if (zen_not_null($params)) { 00200 $form .= ' ' . $params; 00201 } 00202 $form .= '>'; 00203 if (strtolower($method) == 'post') $form .= '<input type="hidden" name="securityToken" value="' . $_SESSION['securityToken'] . '" />'; 00204 return $form; 00205 } 00206 00208 // Output a form input field 00209 function zen_draw_input_field($name, $value = '~*~*#', $parameters = '', $required = false, $type = 'text', $reinsert_value = true) { 00210 $field = '<input type="' . zen_output_string($type) . '" name="' . zen_output_string($name) . '"'; 00211 00212 if ( $value == '~*~*#' && (isset($GLOBALS[$name]) && is_string($GLOBALS[$name])) && ($reinsert_value == true) ) { 00213 $field .= ' value="' . zen_output_string(stripslashes($GLOBALS[$name])) . '"'; 00214 } elseif ($value != '~*~*#' && zen_not_null($value)) { 00215 $field .= ' value="' . zen_output_string($value) . '"'; 00216 } 00217 00218 if (zen_not_null($parameters)) $field .= ' ' . $parameters; 00219 00220 $field .= ' />'; 00221 00222 return $field; 00223 } 00224 00226 // Output a form password field 00227 function zen_draw_password_field($name, $value = '', $required = false) { 00228 $field = zen_draw_input_field($name, $value, 'maxlength="40"', $required, 'password', false); 00229 00230 return $field; 00231 } 00232 00234 // Output a form filefield 00235 function zen_draw_file_field($name, $required = false) { 00236 $field = zen_draw_input_field($name, '', ' size="50" ', $required, 'file'); 00237 00238 return $field; 00239 } 00240 00242 // Output a selection field - alias function for zen_draw_checkbox_field() and zen_draw_radio_field() 00243 function zen_draw_selection_field($name, $type, $value = '', $checked = false, $compare = '', $parameters = '') { 00244 $selection = '<input type="' . zen_output_string($type) . '" name="' . zen_output_string($name) . '"'; 00245 00246 if (zen_not_null($value)) $selection .= ' value="' . zen_output_string($value) . '"'; 00247 00248 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)) ) { 00249 $selection .= ' checked="checked"'; 00250 } 00251 00252 if (zen_not_null($parameters)) $selection .= ' ' . $parameters; 00253 00254 $selection .= ' />'; 00255 00256 return $selection; 00257 } 00258 00260 // Output a form checkbox field 00261 function zen_draw_checkbox_field($name, $value = '', $checked = false, $compare = '', $parameters = '') { 00262 return zen_draw_selection_field($name, 'checkbox', $value, $checked, $compare, $parameters); 00263 } 00264 00266 // Output a form radio field 00267 function zen_draw_radio_field($name, $value = '', $checked = false, $compare = '', $parameters = '') { 00268 return zen_draw_selection_field($name, 'radio', $value, $checked, $compare, $parameters); 00269 } 00270 00272 // Output a form textarea field 00273 function zen_draw_textarea_field($name, $wrap, $width, $height, $text = '~*~*#', $parameters = '', $reinsert_value = true) { 00274 $field = '<textarea name="' . zen_output_string($name) . '" wrap="' . zen_output_string($wrap) . '" cols="' . zen_output_string($width) . '" rows="' . zen_output_string($height) . '"'; 00275 00276 if (zen_not_null($parameters)) $field .= ' ' . $parameters; 00277 00278 $field .= '>'; 00279 00280 if ($text == '~*~*#' && (isset($GLOBALS[$name]) && is_string($GLOBALS[$name])) && ($reinsert_value == true) ) { 00281 $field .= stripslashes($GLOBALS[$name]); 00282 $field = str_replace('>', '>', $field); 00283 } elseif ($text != '~*~*#' && zen_not_null($text)) { 00284 $field = str_replace('>', '>', $field); 00285 $field .= $text; 00286 } 00287 00288 $field .= '</textarea>'; 00289 00290 return $field; 00291 } 00292 00294 // Output a form hidden field 00295 function zen_draw_hidden_field($name, $value = '', $parameters = '') { 00296 $field = '<input type="hidden" name="' . zen_output_string($name) . '"'; 00297 00298 if (zen_not_null($value)) { 00299 $field .= ' value="' . zen_output_string($value) . '"'; 00300 } elseif (isset($GLOBALS[$name]) && is_string($GLOBALS[$name])) { 00301 $field .= ' value="' . zen_output_string(stripslashes($GLOBALS[$name])) . '"'; 00302 } 00303 00304 if (zen_not_null($parameters)) $field .= ' ' . $parameters; 00305 00306 $field .= ' />'; 00307 00308 return $field; 00309 } 00310 00312 // Output a form pull down menu 00313 function zen_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) { 00314 // $field = '<select name="' . zen_output_string($name) . '"'; 00315 $field = '<select rel="dropdown" name="' . zen_output_string($name) . '"'; 00316 00317 if (zen_not_null($parameters)) $field .= ' ' . $parameters; 00318 00319 $field .= '>' . "\n"; 00320 00321 if (empty($default) && isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) ) $default = stripslashes($GLOBALS[$name]); 00322 00323 for ($i=0, $n=sizeof($values); $i<$n; $i++) { 00324 $field .= '<option value="' . zen_output_string($values[$i]['id']) . '"'; 00325 if ($default == $values[$i]['id']) { 00326 $field .= ' selected="selected"'; 00327 } 00328 00329 $field .= '>' . zen_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>' . "\n"; 00330 } 00331 $field .= '</select>' . "\n"; 00332 00333 if ($required == true) $field .= TEXT_FIELD_REQUIRED; 00334 00335 return $field; 00336 } 00338 // Hide form elements 00339 function zen_hide_session_id() { 00340 global $session_started; 00341 00342 if ( ($session_started == true) && defined('SID') && zen_not_null(SID) ) { 00343 return zen_draw_hidden_field(zen_session_name(), zen_session_id()); 00344 } 00345 } 00346 ?>