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

Размер файла: 4.35Kb
<?php
class form  {
	protected $form = ''; 
	protected $method; 
	protected $act; 
	protected $form_names; 
    protected $legend; 
	protected $formid; 
	protected $hidden = array();

	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; 
 	} 

	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; 
	}  

	public function textarea($text = false, $name, $value = '',$bb_code = false,$div) 
	{
	global $text_list;
			$form = ''; 
			$form.= $text ?  $text . '<br/>' : '';
		if($bb_code == true) {
			$form.= SHCMS_core::panelhtml();			
			$form.= '<textarea 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; 
	} 

	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; 
	} 

	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; 
	}		

	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; 

	}
	
    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; 
	}
	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; 
	}	
		
	public function finish() {
		echo   $this->form .  '</form>';
    }
}