Просмотр файла system/inc/classes/form.class.php

Размер файла: 6.28Kb
<?php
/**
 * @name Класс для работы с HTML Формой
 * @copyright Shamsik © 2012-2013
 * Данный код защищен авторскими правами
 * http://shcms.ru
 */

class form  {
	protected $form = ''; 
	protected $method; 
	protected $act; 
	protected $form_names; 
    protected $legend; 
	protected $formid; 
	protected $hidden = array();
    
	/*
	* Заглавное форма 
	* <form action="" method="post">
	*
	* Создаем объект класса form
	* $form = new form('?');
	*/
	public function __construct($act, $method = '', $form_names = '', $formid = '', $hidden = '', $legend = '') {
			$this->act = $act; 
			$this->method = $method ? $method : 'post'; 
			$this->form_names = $form_names ? $form_names : ''; 
			$this->formid = $formid ? $formid : ''; 
			$this->hidden = $hidden ? $hidden : ''; 
			$this->legend = $legend ? $legend : ''; 
			$form = '<form name="form" action="' . $this->act . '" method="' . $this->method . '" '; 
			$form .= $this->formid ?  $this->formid  : '';  
			$form .= $this->form_names ? 'name="' . $this->form_names . '">' : '>'; 
			
		return $this -> form = $form . PHP_EOL; 
 	} 
	/*
	* Форма form input
	* <input type="text" name="name">
	* $form->input('Название','name','type','value',true) Стандартный стиль.
	*/
	public function input($text = '', $name, $type = 'text', $value = '', $br = false, $size = '', $max = '',$name_check = '',$accept = '',$div) { 
			$form = ''; 
			$form.= $text ? $text . '<br/>' : ''; 
			$form.= '<input '.$accept.' type="' . $type . '" name="' . $name . '" value="' . $value . '" size="'.$size.'"'; 
			$form.= $max ? 'maxlength="' . $max . '" />'.($br ? '<br />' : null).'' : '/>  '.$name_check.''.($br ? '<br />' : null).''; 
			$form .= $div;
		return $this->form .= PHP_EOL . $form . PHP_EOL; 
	}  
	/*
	* Форма form texrarea
	* <textarea>$value</textarea>
	* $form->textarea('Название','name','value',true,код css стиля)
	*/
	public function textarea($text = false, $name, $value = '',$bb_code = false,$div,$plans) {
	global $text_list;
			$form = ''; 
			$form.= $text ?  $text . '<br/>' : '';
		if($bb_code == true) {
		//бб коды
			$form.= SHCMS_core::panelhtml();			
			$form.= '<textarea '.$plans.' id="text" name="' . $name . '">'; 
			}else {
			$form.= '<textarea name="' . $name . '">'; 			
			}
			$form.= $value ? $value : ''; 
			$form.= '</textarea><br/>';
			$form .= $div;
		return $this->form .= PHP_EOL . $form . PHP_EOL; 
	} 
	/*
	* Функция ошибки
	* $form->error(text,icon.png)
	*/    
	public function error($text,$icons) {
	        $form = '<div style="color:red"><img src="../template/icon/'.$icons.'">&nbsp;';
	        $form .= $text.'</div>';   
		return $this->form .= $form . PHP_EOL; 
	}
	/*
	* Форма form select
	* <select name="name"><option value="value"></select>
	* $form->select('Название','name','array(1=>2, 3=>4)',$value[form]);
	*/	
	public function select($text, $name, $form_value, $selected = 1,$div) {
			$form = ($text ? $text . '<br/>' : null) . '<select name="' . $name . '">' . PHP_EOL; 
			$for_number = 1; 
			foreach ($form_value as $form_z => $form_num) { 
				$form .= '<option value="' . $form_num . '" ' . ($for_number==$selected ? 'selected="selected"' : '') . '>' . $form_z . '</option>' . PHP_EOL; 
				$for_number ++;
			} 
			$form .= '</select><br/>'; 
			$form .= $div;

		return $this->form .= $form . PHP_EOL; 
	} 
	/*
	* Форма form select (с базы)
	* <select name="name"><option value="value"></select>
	* $form->select('Название','name','*','setting','id','name');
	*/	
	public function select_while($text,$name,$mysql_select,$mysql_from,$value,$name_option) {
	
			$form = ($text ? $text . '<br/>' : null) . '<select name="' . $name . '">' . PHP_EOL; 
            $selecting = mysql_query("SELECT $mysql_select FROM $mysql_from");
                while($while_select = mysql_fetch_array($selecting)) {
                    $form.= '<option value="'.$while_select[$value].'">'.$while_select[$name_option].'</option>';
                }
            $form.= '</select><br/>';
		return $this->form .= $form . PHP_EOL; 
	}		
 	/*
	* Форма form submit
	* <input type="submit" name="submit">
	* $form->submit('Название','value',true);
	*/	
	public function submit ($submitname = false, $submitvalue = '', $br = false) {
        if($submitname == false) {
		    $form = '<input  type="submit"  name="' . $submitvalue . '" value="Отправить" />' .($br ? '<br />' : null); 		
		}else {	
		    $form = '<input  type="submit" name="' . $submitvalue . '" value="' . $submitname . '" />' .($br ? '<br />' : null); 
		}
	return $this->form .= $form . PHP_EOL; 

	}
 	/*
	* Ссылки в форме
	* $form->form_link('shcms.ru','SHCMS_Engine');
	*/	
    public function form_link($link_http = '',$link_title = '') {
	        $form = '<a href="http://'.$_SERVER['HTTP_HOST'].''.$link_http.'">'.$link_title.'</a>';
		return $this->form .= $form . PHP_EOL; 
	}
 	/*
	* Обычный текст в форме
	* $form->text(Я обычный текст);
	*/
	public function text($val) {
	        $form = $val;
	    return $this->form .= $form . PHP_EOL;
	}
 	/*
	* Капча
	* $form->captcha(chat);
	*/
	public function captcha($name_funct) {
		global $settings_shcms;
			if($settings_shcms[$name_funct] == 1){
				$form =  '<script type="text/javascript">
			      	src="/shcms/antibot.php?r=rand(1000,9999)"; 
			      	function reload(){
			      	document.captcha.src="/shcms/antibot.php?r=rand(1000,9999)";
			      	document.captcha.src=src+"?rand="+Math.random(); } </script>
    	   			<img name="captcha" class="midside" alt="Код безопастности" src="'.DIR_SHCMS.'antibot.php?r='.rand(1000, 9999) .'"/><br />
		    		<a href="javascript:void(0)" onclick="reload()">обновить, если не виден код</a><br/>
            		<input type="text" style="width:115px"  size="5" maxlength="5"  name="kod"/><br/>';
	    	}
		return $this->form .= $form . PHP_EOL; 
	}	
 	/*
	* Вывод полной формы
	* $form->finish();
	*/		
	public function finish() {
		echo   $this->form .  '</form>';
    }
}