Файл: themes/default/form.php
Строк: 218
<?php
if (!defined('CMS')) { die('Access Denied!'); }
class cmsForm {
// атрибуты класса cmsForm
public $uri;
public $action; # <form action="...">
public $method; # <form method="...">
public $version; # WML, HTML, xHTML
public $other; # <form name="..."> OR <form id="...">
public $content = '';
public $contents = '';
public $jscript = '';
function __construct($action = '', $method = 'post', $other = '') {
if (!defined('VERSION')) {
$this->version = cmsDetect::getInstance()->choiceVersion();
}
else $this->version = VERSION;
$this->uri = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'index.' . $this->version;
if ( empty($action) ) {
$action = str_replace('&', '&', $this->uri);
}
$this->method = (strtolower($method) == 'get') ? 'get' : 'post';
if ( strcmp($this->method, 'get') == 0 ) {
$action = explode('?', $action);
$this->action = reset($action);
}
else $this->action = $action;
$this->other = $other;
}
private function __clone() {}
public function __set($name, $value) {
$this->$name = $value;
}
public function debug() {
echo '<pre>', print_r($this, true), '</pre>';
}
public function isEmpty($var = '') {
if ($this->method == 'post') {
return !empty($_POST[$var]) ? check($_POST[$var]) : '';
}
else {
return !empty($_GET[$var]) ? check($_GET[$var]) : '';
}
}
public function addCode($code = '') {
if (strlen($code) > 0) $this->content .= $code;
}
public function addText($title = '', $name, $value = '', $html = '') {
$title = !empty($title) ? $title . '<br />' : '';
$this->content .= $title . '<input class="f_input" type="text" name="' . $name . '" value="' . $value . '"' . $html . '/><br />';
}
public function addHidden($name, $value = '', $html = '') {
$this->content .= '<input type="hidden" name="' . $name . '" value="' . $value . '"' . $html . '/>';
}
public function addPassword($title = '', $name, $value = '', $html = '') {
$title = !empty($title) ? $title . '<br />' : '';
$this->content .= $title . '<input class="f_input" type="password" name="' . $name . '" value="' . $value . '"' . $html . '/><br />';
}
public function addTextarea($title = '', $name, $value = '', $html = '', $cols = 35, $rows = 5) {
$value = !empty($value) ? check($value) : $this->isEmpty($name);
$title = !empty($title) ? $title . '<br />' : '';
$this->content .= $title . '<textarea cols="' . $cols . '" rows="' . $rows . '" ';
$this->content .= 'name="' . $name . '" class="f_textarea"' . $html . '>' . $value . '</textarea><br />';
}
public function addFile($title = '', $name, $html = '') {
$this->other .= ' enctype="multipart/form-data"';
$title = !empty($title) ? $title . '<br />' : '';
$this->content .= $title . '<input type="file" name="' . $name . '" class="f_input"' . $html . '/><br />';
}
function addSelect($title = '', $name, $value = '', $options, $html = '') {
$title = !empty($title) ? $title . '<br />' : '';
$output = $title . '<select name="' . $name . '" class="f_select"' . $html . '>';
foreach( $options as $key => $val ) {
$selected = ( $value == $key ) ? ' selected="selected"' : '';
$output .= '<option value="' . $key . '"' . $selected . '>' . $val . '</option>';
}
$output .= '</select><br />';
$this->content .= $output;
}
public function addRadio($title = '', $name, $value = '', $options, $html = '') {
$title = !empty($title) ? $title . '<br />' : '';
$output = $title;
foreach( $options as $key => $val ) {
$checked = ( $value == $key ) ? ' checked="checked"' : '';
$output .= '<input type="radio" name="' . $name . '" value="' . $key . '"' . $checked . '> ' . $val . '<br />';
}
$this->content .= $output;
}
public function addCheckBox($title = '', $name, $value = '', $true = 1, $html = '') {
$checked = ( $value == $true ) ? ' checked="checked"' : '';
if (is_array($title)) {
$left = !empty($title[0]) ? $title[0] : '';
$right = !empty($title[1]) ? $title[1] : '';
}
else {
$left = !empty($title) ? $title : '';
$right = '';
}
$this->content .= $left . '<input type="checkbox" name="' . $name . '" value="1" ' . $checked . '>' . $right . '<br />';
}
public function addDate( $title = '', $name, $type, $def = 1, $min_year = 1917 ) {
$title = !empty($title) ? $title . '<br />' : '';
$str = '';
$cur_year = date( 'Y' );
if ( $def < 1 ) {
$def = 1;
}
if ( $type == 'y' && $def == 1 ) {
$def = 1970;
}
switch( $type ):
case 'd':
$i = 1;
for ( ; $i <= 31; ++$i) {
$sel = '';
if ( $i == $def ) $sel = ' selected="selected"';
$num = $i;
if ( $i < 10 ) $num = '0'.$i;
$str .= '<option value="' . $num . '"' . $sel . '>' . $i . '</option>';
}
$end = '</select>';
break;
case 'm':
$i = 1;
for ( ; $i <= 12; ++$i) {
$sel = '';
if ( $i == $def ) $sel = ' selected="selected"';
$num = $i;
if ( $i < 10 ) $num = '0'.$i;
$str .= '<option value="' . $num . '"' . $sel . '>' . $i . '</option>';
}
$end = '</select>';
break;
case 'y':
$i = $cur_year;
for ( ; $i >= $min_year; --$i ) {
$sel = '';
if ( $i == $def ) $sel = ' selected="selected"';
$str .= '<option value="' . $i . '"' . $sel . '>' . $i . '</option>';
}
$end = '</select><br />';
break;
endswitch;
$this->content .= $title . '<select name="' . $name . '">' . $str . $end;
}
public function addCaptcha($title = '', $name, $action = '?', $html = '') {
global $config;
$this->content .= $title . '<br /><img name="captcha" src="' . $config['site_url'] . '/captcha.gif" class="ava" alt="Проверочный код" /> ';
$this->content .= '<a class="xxsmall" style="vertical-align:bottom;" href="#" onclick="document.captcha.src = document.captcha.src + '?' + (new Date()).getTime(); return false;">обновить</a><br />';
$this->content .= '<input name="' . $name . '" type="text" /><br />';
}
public function Submit($value = '', $name = '', $class = 'btns', $html = '', $return = false) {
if ( empty($this->content) ) return;
$v[] = '<div class="bl">';
$v[] = '<form action="' . $this->action . '" method="' . $this->method . '"' . $this->other . '>';
$v[] = $this->content;
$v[] = $this->contents;
if (is_array($value) && is_array($name)) {
for($n = 0; $n < count($name); $n++) {
$v[] = '<input type="submit" name="' . $name[$n] . '" class="' . $class . '" value="' . $value[$n] . '" title=" ' . $value[$n] . '"' . $html . '/> ';
}
$v[] = '<br />';
}
else {
$name = !empty($name) ? ' name="' . $name . '"' : '';
$v[] = '<input type="submit"' . $name . ' class="' . $class . '" value="' . $value . '" title=" ' . $value . '"' . $html . '/>';
$v[] = '<br />';
}
$v[] = '</form></div>';
$v[] = $this->jscript;
if (!$return) echo implode('',$v);
else return implode('',$v);
}
public function Show($return = false) {
$v[] = $this->content;
$v[] = $this->contents;
if (!$return) echo implode('',$v);
else return implode('',$v);
}
}
?>