html_output.php

来自「this the oscommerce 3.0 aplha 4」· PHP 代码 · 共 695 行 · 第 1/2 页

PHP
695
字号
    $field = '';    $counter = 0;    foreach ($values as $key => $value) {      $counter++;      if (is_array($value)) {        $selection_value = $value['id'];        $selection_text = '&nbsp;' . $value['text'];      } else {        $selection_value = $value;        $selection_text = '';      }      $field .= '<input type="' . osc_output_string($type) . '" name="' . osc_output_string($name) . '"';      if (strpos($parameters, 'id=') === false) {        $field .= ' id="' . osc_output_string($name) . (sizeof($values) > 1 ? $counter : '') . '"';      }      if (trim($selection_value) != '') {        $field .= ' value="' . osc_output_string($selection_value) . '"';      }      if ((is_bool($default) && $default === true) || ((is_string($default) && (trim($default) == trim($selection_value))) || (is_array($default) && in_array(trim($selection_value), $default)))) {        $field .= ' checked="checked"';      }      if (!empty($parameters)) {        $field .= ' ' . $parameters;      }      $field .= ' />';      if (!empty($selection_text)) {        $field .= '<label for="' . osc_output_string($name) . (sizeof($values) > 1 ? $counter : '') . '" class="fieldLabel">' . $selection_text . '</label>';      }      $field .= $separator;    }    if (!empty($field)) {      $field = substr($field, 0, strlen($field)-strlen($separator));    }    return $field;  }/** * Outputs a form checkbox field * * @param string $name The name and indexed ID of the checkbox field * @param mixed $values The value of, or an array of values for, the checkbox field * @param string $default The default value for the checkbox field * @param string $parameters Additional parameters for the checkbox field * @param string $separator The separator to use between multiple options for the checkbox field * @access public */  function osc_draw_checkbox_field($name, $values = null, $default = null, $parameters = null, $separator = '&nbsp;&nbsp;') {    return osc_draw_selection_field($name, 'checkbox', $values, $default, $parameters, $separator);  }/** * Outputs a form radio field * * @param string $name The name and indexed ID of the radio field * @param mixed $values The value of, or an array of values for, the radio field * @param string $default The default value for the radio field * @param string $parameters Additional parameters for the radio field * @param string $separator The separator to use between multiple options for the radio field * @access public */  function osc_draw_radio_field($name, $values, $default = null, $parameters = null, $separator = '&nbsp;&nbsp;') {    return osc_draw_selection_field($name, 'radio', $values, $default, $parameters, $separator);  }/** * Outputs a form textarea field * * @param string $name The name and ID of the textarea field * @param string $value The default value for the textarea field * @param int $width The width of the textarea field * @param int $height The height of the textarea field * @param string $parameters Additional parameters for the textarea field * @param boolean $override Override the default value with the value found in the GET or POST scope * @access public */  function osc_draw_textarea_field($name, $value = null, $width = 60, $height = 5, $parameters = null, $override = true) {    if (!is_bool($override)) {      $override = true;    }    if ($override === true) {      if (isset($_GET[$name])) {        $value = $_GET[$name];      } elseif (isset($_POST[$name])) {        $value = $_POST[$name];      }    }    if (!is_numeric($width)) {      $width = 60;    }    if (!is_numeric($height)) {      $width = 5;    }    $field = '<textarea name="' . osc_output_string($name) . '" cols="' . (int)$width . '" rows="' . (int)$height . '"';    if (strpos($parameters, 'id=') === false) {      $field .= ' id="' . osc_output_string($name) . '"';    }    if (!empty($parameters)) {      $field .= ' ' . $parameters;    }    $field .= '>' . osc_output_string_protected($value) . '</textarea>';    return $field;  }/** * Outputs a form hidden field * * @param string $name The name of the hidden field * @param string $value The value for the hidden field * @param string $parameters Additional parameters for the hidden field * @access public */  function osc_draw_hidden_field($name, $value = null, $parameters = null) {    $field = '<input type="hidden" name="' . osc_output_string($name) . '"';    if (trim($value) != '') {      $field .= ' value="' . osc_output_string($value) . '"';    }    if (!empty($parameters)) {      $field .= ' ' . $parameters;    }    $field .= ' />';    return $field;  }/** * Outputs a form hidden field containing the session name and ID if SID is not empty * * @access public */  function osc_draw_hidden_session_id_field() {    global $osC_Session;    if ($osC_Session->hasStarted() && !osc_empty(SID)) {      return osc_draw_hidden_field($osC_Session->getName(), $osC_Session->getID());    }  }/** * Outputs a form pull down menu field * * @param string $name The name of the pull down menu field * @param array $values Defined values for the pull down menu field * @param string $default The default value for the pull down menu field * @param string $parameters Additional parameters for the pull down menu field * @access public */  function osc_draw_pull_down_menu($name, $values, $default = null, $parameters = null) {    $group = false;    if (isset($_GET[$name])) {      $default = $_GET[$name];    } elseif (isset($_POST[$name])) {      $default = $_POST[$name];    }    $field = '<select name="' . osc_output_string($name) . '"';    if (strpos($parameters, 'id=') === false) {      $field .= ' id="' . osc_output_string($name) . '"';    }    if (!empty($parameters)) {      $field .= ' ' . $parameters;    }    $field .= '>';    for ($i=0, $n=sizeof($values); $i<$n; $i++) {      if (isset($values[$i]['group'])) {        if ($group != $values[$i]['group']) {          $group = $values[$i]['group'];          $field .= '<optgroup label="' . osc_output_string($values[$i]['group']) . '">';        }      }      $field .= '<option value="' . osc_output_string($values[$i]['id']) . '"';      if ( (!is_null($default) && ($default == $values[$i]['id'])) || (is_array($default) && in_array($values[$i]['id'], $default)) ) {        $field .= ' selected="selected"';      }      $field .= '>' . osc_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => '&#039;', '<' => '&lt;', '>' => '&gt;')) . '</option>';      if ( ($group !== false) && (($group != $values[$i]['group']) || !isset($values[$i+1])) ) {        $group = false;        $field .= '</optgroup>';      }    }    $field .= '</select>';    return $field;  }/** * Outputs a label for form field elements * * @param string $text The text to use as the form field label * @param string $for The ID of the form field element to assign the label to * @param string $access_key The access key to use for the form field element * @param bool $required A flag to show if the form field element requires input or not * @access public */  function osc_draw_label($text, $for, $access_key = null, $required = false) {    if (!is_bool($required)) {      $required = false;    }    return '<label for="' . osc_output_string($for) . '"' . (!empty($access_key) ? ' accesskey="' . osc_output_string($access_key) . '"' : '') . '>' . osc_output_string($text) . ($required === true ? '<em>*</em>' : '') . '</label>';  }/** * Outputs a form pull down menu for a date selection * * @param string $name The base name of the date pull down menu fields * @param array $value An array containing the year, month, and date values for the default date (year, month, date) * @param boolean $default_today Default to todays date if no default value is used * @param boolean $show_days Show the days in a pull down menu * @param boolean $use_month_names Show the month names in the month pull down menu * @param int $year_range_start The start of the years range to use for the year pull down menu * @param int $year_range_end The end of the years range to use for the year pull down menu * @access public */  function osc_draw_date_pull_down_menu($name, $value = null, $default_today = true, $show_days = true, $use_month_names = true, $year_range_start = 0, $year_range_end = 1) {    $year = date('Y');    if (!is_bool($default_today)) {      $default_today = true;    }    if (!is_bool($show_days)) {      $show_days = true;    }    if (!is_bool($use_month_names)) {      $use_month_names = true;    }    if (!is_numeric($year_range_start)) {      $year_range_start = 0;    }    if (!is_numeric($year_range_end)) {      $year_range_end = 1;    }    if (!is_array($value)) {      $value = array();    }    if (!isset($value['year']) || !is_numeric($value['year']) || ($value['year'] < ($year - $year_range_start)) || ($value['year'] > ($year + $year_range_end))) {      if ($default_today === true) {        $value['year'] = $year;      } else {        $value['year'] = $year - $year_range_start;      }    }    if (!isset($value['month']) || !is_numeric($value['month']) || ($value['month'] < 1) || ($value['month'] > 12)) {      if ($default_today === true) {        $value['month'] = date('n');      } else {        $value['month'] = 1;      }    }    if (!isset($value['date']) || !is_numeric($value['date']) || ($value['date'] < 1) || ($value['date'] > 31)) {      if ($default_today === true) {        $value['date'] = date('j');      } else {        $value['date'] = 1;      }    }    $params = '';    $days_select_string = '';    if ($show_days === true) {      $params = 'onchange="updateDatePullDownMenu(this.form, \'' . $name . '\');"';      $days_in_month = ($default_today === true) ? date('t') : 31;      $days_array = array();      for ($i=1; $i<=$days_in_month; $i++) {        $days_array[] = array('id' => $i,                              'text' => $i);      }      $days_select_string = osc_draw_pull_down_menu($name . '_days', $days_array, $value['date']);    }    $months_array = array();    for ($i=1; $i<=12; $i++) {      $months_array[] = array('id' => $i,                              'text' => (($use_month_names === true) ? strftime('%B', mktime(0, 0, 0, $i, 1)) : $i));    }    $months_select_string = osc_draw_pull_down_menu($name . '_months', $months_array, $value['month'], $params);    $years_array = array();    for ($i = ($year - $year_range_start); $i <= ($year + $year_range_end); $i++) {      $years_array[] = array('id' => $i,                             'text' => $i);    }    $years_select_string = osc_draw_pull_down_menu($name . '_years', $years_array, $value['year'], $params);    return $days_select_string . $months_select_string . $years_select_string;  }?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?