Current File : /home/users/barii/public_html/finansenl.com.pl/system.fotomagnesy.pl/classes/Form.php
<?php

/*
 * Klasa do tworzenia formularzy
 */
 
class Form{
	
	var $setup = array();
	var $fields = array();
	var $form;
	var $multipart;
	
	function Form($form){
		$this->multipart = false;
		if($form['name'])
			$this->setup['name'] = $form['name'];
		else
			$this->setup['name'] = 'form_'.rand(100,200);
			
		if($form['id'])
			$this->setup['id'] = $form['id'];
		else
			$this->setup['id'] = $this->setup['name'];
			
		switch($form['method']){
			case 'get': $this->setup['method'] = 'Get'; break;
			case 'post': $this->setup['method'] = 'Post'; break;
			default: $this->setup['method'] = 'Post'; break;
		}
		if($form['IdUser'])
			$this->setup['IdUser'] = $form['IdUser'];
		else
			$this->setup['IdUser'] = '';
      
		if($form['action'])
			$this->setup['action'] = $form['action'];
		else
			$this->setup['action'] = '';
		
		if($form['class'])
			$this->setup['class'] = $form['class'];
		else
			$this->setup['class'] = 'cmxform';
		
		if($form['desc'])
			$this->setup['desc'] = $form['desc'];
		else
			$this->setup['desc'] = 'Formularz';
		
		if($form['submit'])
			$this->setup['submit'] = $form['submit'];
		else
			$this->setup['submit'] = 'Wy¶lij formularz';
			
		if($form['submit_position'])
			$this->setup['submit_position'] = $form['submit_position'];
		else
			$this->setup['submit_position'] = 'mrlf120';
		$this->fields = array();
		$this->form = '';
	}
	
	function AddField($name, $label = NULL, $type='text', $values = NULL, $field_options = NULL){
		$field['name']	= $name;
		$field['type']	= $type;
		if($label == NULL)
			$field['label']	= ucfirst($field['name']);
		else
			$field['label']	= $label;
		$field['values']= $values;
		
		if($field['type'] == 'textarea'){
			if($field_options != NULL)
				$field['options'] = $field_options;
			else
				$field['options'] = array(70,6);
		} elseif($field['type'] == 'dropdown'){
			if($field_options != NULL)
				$field['options'] = $field_options;
			else
				$field['options'] = 0;
		} elseif($field['type'] == 'radio'){
			if($field_options != NULL)
				$field['options'] = $field_options;
			else
				$field['options'] = 1;
		} else {
			$field['options'] = $field_options;
		}
		
		array_push($this->fields,$field);
	}
	
	function AddHeader($value){
		$field['type'] = 'header';
		$field['label'] = $value;
		array_push($this->fields,$field);
	}
	
	function AddInfo($value,$id=NULL){
		$field['type'] = 'info';
		$field['label'] = $value;
		if($id!=NULL)
			$field['id'] = $id;
		array_push($this->fields,$field);
	}
  
	function AddOpcje($id){
      $sql = "SELECT * FROM opcja WHERE id_oferta='$id'";
      //echo $sql;
      $res = mysql_query($sql);
      $innych = mysql_num_rows($res);
      $aopcje = '';
      while($row = mysql_fetch_array($res)){
          $aopcje .= '<p><label for="'.$field['name'].'"><span class="form">OPCJA KUPNA</span></label>id: <input name=id[] type=text size=1 value="'.$row['id'].'" class=imp> Opcja: <input name=opcje[] type=text size=30 value="'.$row['opcja'].'" class=imp> Cena: <input name=cena[] type=text size=3 value="'.$row['cena'].'" class=imp> Czas trwania <i>[dni]</i>: <input name=czas[] type=text size=1 value="'.$row['czas'].'" class=imp> Stara cena: <input name=old[] type=text size=3 value="'.$row['old'].'" class=imp> Ile: <input name=ile[] type=text size=3 value="'.$row['ile'].'" class=imp></p>';
      }
      return $aopcje;
  }
	
	
	function AddDiv($value = NULL, $style = NULL){
		$field['type'] = 'div';
		if($value){
			$field['label'] = '<div id="'.$value.'"';
			if($style){
				$field['label'] .= ' style="'.$style.'"';
			}
			$field['label'] .= '>';
		}
		else
			$field['label'] = '</div>';
		array_push($this->fields,$field);
	}
	
	/**
	 * Dodaj pole pliku
	 * @param string $name nazwa pola
	 * @param string $label opis pola
	 * @param string $params parametry pola
	 */
	
	function AddFile($name, $label, $params){
		$this->multipart = true;
		$field['type'] = 'file';
		$field['name'] = $name;
		$field['label'] = $label;
		$field['params'] = $params;
		array_push($this->fields, $field);
	}
	
	/**
	 * Dodaj Obrazek
	 */
	
	function AddImage($name, $url){
		$field['type'] = 'image';
		$field['label'] = $name;
		$field['name'] = $name;
		$field['url'] = $url;
		array_push($this->fields, $field);
	}
	
	function AddCheck($name,$label){
		$field['type'] = 'checkbox';
		$field['label'] = $label;
		$field['name'] = $name;
		array_push($this->fields,$field);
	}
	
	function Create(){
    //$this->multipart =true;
		$this->form .= '<p><b>'.$this->setup['desc'].'</b></p>'.chr(10);
		$this->form .= '<form class="'.$this->setup['class'].'" name="'.$this->setup['name'].'" id="'.$this->setup['id'].'"';
		$this->form .= ' enctype="multipart/form-data"';
		$this->form .= ' method="'.$this->setup['method'].'" action="'.$this->setup['action'].'">'.chr(10);
		
		foreach($this->fields as $field){
			
			if($field['type'] != 'header' && $field['type'] != 'div' && $field['type'] != 'info'){
			  if($field['type'] != 'hidden' and $field['type'] != 'opcje'){
				$this->form .= '<p>'.chr(10).chr(9).'<label for="'.$field['name'].'"><span class="form">'.$field['label'];
				$this->form .= '</span></label>'.chr(10).chr(9);
				}
				switch($field['type']){
					
					case 'text':
					case 'password':
						$this->form .= '<input id="'.$field['name'].'" name="'.$field['name'].'" type="'.$field['type'].'"';
						if($field['options']['size'])
							$this->form .= ' size="'.$field['options']['size'].'"';
						else
							$this->form .= ' size="60"';
						if($field['options']['readonly'])
							$this->form .= ' readonly';
						$this->form .= ' value="'.$field['values'].'" class="imp">'.$field['options']['post'];
                if($field['name']=='WYNIK')$this->form .= '<span onClick="return ObliczCyfreEAN13();" style="cursor:pointer;position:relative;left:-150px;background:red;padding:4px;color:white">Sprawdź kod EAN-13</span>';
						break;
					case 'hidden':
						$this->form .= '<input id="'.$field['name'].'" name="'.$field['name'].'" type="'.$field['type'].'"';
						if($field['options']['size'])
							$this->form .= ' size="'.$field['options']['size'].'"';
						else
							$this->form .= ' size="50"';
						if($field['options']['readonly'])
							$this->form .= ' readonly';
						$this->form .= ' value="'.$field['values'].'" class="imp">'.$field['options']['post'];
						break;
						
					case 'textarea': 
					   $this->form .= '<textarea id="textarea1" name="'.$field['name'].'" cols="'.$field['options'][0].'" rows="'.$field['options'][1].'" class="imp">'.$field['values'].'</textarea>';
						break;
					case 'openarea': 
						$this->form .= '<div align="left"><table>
        <tr><td style="text-align: right" width="80" valign="middle">poniedziałek: <br />wtorek: <br />»roda: <br />czwartek: <br />pi‘tek: <br />sobota: <br />niedziela: <br /></td><td style="text-align: left" width="300" valign="middle">
        <textarea id="'.$field['name'].'" name="'.$field['name'].'" cols="'.$field['options'][0].'" rows="'.$field['options'][1].'" class="imp">'.$field['values'].'</textarea></td></tr>
        </table></div>';
						break;
						
	
					case 'dropdown': 
						$this->form .= '<select name="'.$field['name'].'">';
						if($field['values']=='kat'){
						$IdUser=$this->setup['IdUser'];
            $sql = "SELECT * FROM `massmail_baza_kat`  WHERE userID='$IdUser' ";
            $res = mysql_query($sql);
            while($row = mysql_fetch_array($res)){
            $nazwa_kat=$row["nazwa_kat"];
            $id_kat=$row["id"];
            $this->form .= '<option value="'.$id_kat.'">'.$nazwa_kat.'</option>';
            }
            ?>
            </select>
            <?php
            }
						else{
						$IdUser=$this->setup['IdUser'];
                $sql = "SELECT * FROM `massmail_baza_kat`  WHERE userID='$IdUser'";
                $res = mysql_query($sql);
                while($row = mysql_fetch_array($res)){
                $nazwa=$row["nazwa_kat"];
                $id_kat=$row["id"];
                $this->form .= '<option value="'.$id_kat.'"';
                    if($field['values']==$id_kat){$this->form .=  ' selected ';}
                $this->form .= '>'.$nazwa.'</option>';
                }
						}
						$this->form .= chr(10).'</select>';
						break;
            case 'kategoria':
						$this->form .= '<select name="'.$field['name'].'"><option value="0">wybierz...</option>';
                $sql = "SELECT * FROM `kategorie` WHERE parent!='0'";
                $res = mysql_query($sql);
                while($row = mysql_fetch_array($res)){
                $this->form .= '<option value="'.$row['id'].'"';
                    if($field['values']==$row['id']){$this->form .=  ' selected ';}
                $this->form .= '>'.$row['nazwa'].'</option>';
                }
						$this->form .= chr(10).'</select>';
						break;
            case 'kateg':
						$this->form .= '<select name="'.$field['name'].'"><option value="0">wybierz...</option>';
                $sql = "SELECT * FROM `kategorie`";
                $res = mysql_query($sql);
                while($row = mysql_fetch_array($res)){
                $this->form .= '<option value="'.$row['id'].'"';
                    if($field['values']==$row['id']){$this->form .=  ' selected ';}
                $this->form .= '>'.$row['nazwa'].'</option>';
                }
						$this->form .= chr(10).'</select>';
						break;
													
						case 'typy': 
						$this->form .= '<select name="'.$field['name'].'"><option value="0">wybierz...</option>';
						$kat_id=$field['values'];
            $sql = "SELECT * FROM `prolabel_typy` ORDER BY nazwa";
            
            $res = mysql_query($sql);
            while($row = mysql_fetch_array($res)){
            $nazwa=$row["nazwa"];
            $id_kat=$row["id"];
            $this->form .= '<option value="'.$id_kat.'"';
              if($field['values']==$id_kat){$this->form .=  ' selected ';}
            $this->form .= '>'.$nazwa.'</option>';
            }

						$this->form .= chr(10).'</select>';
						break;
	
						case 'adreswysylki': 
						$this->form .= '<select name="'.$field['name'].'"><option value="0">wybierz...</option>';
						$kat_id=$field['values'];
            $sql = "SELECT * FROM `prolabel_adresy` WHERE user='$_SESSION[iduser]' ORDER BY nazwa";
            
            $res = mysql_query($sql);
            while($row = mysql_fetch_array($res)){
            $nazwa=$row["imie"].' '.$row["nazwisko"].' '.$row["nazwa"].'; '.$row["adres"].' '.$row["kod"].' '.$row["miasto"];
            $id_kat=$row["id"];
            $this->form .= '<option value="'.$id_kat.'"';
              if($field['values']==$id_kat){$this->form .=  ' selected ';}
            $this->form .= '>'.$nazwa.'</option>';
            }

						$this->form .= chr(10).'</select>';
						break;
						    					
						case 'firma': 
						$this->form .= '<select name="'.$field['name'].'">';
						$kat_id=$field['values'];
            $sql = "SELECT * FROM `firma` ORDER BY nazwa ";
            
            $res = mysql_query($sql);
            while($row = mysql_fetch_array($res)){
            $nazwa=$row["nazwa"];                  
            $adres=$row["adres"];
            $id=$row["id"];
            $this->form .= '<option value="'.$id.'"';
              if($field['values']==$id){$this->form .=  ' selected ';}
            $this->form .= '>'.$nazwa.' - '.$adres.'</option>';
            }

						$this->form .= chr(10).'</select>';
						break;
												
						
						
					case 'radio': 
					  if(is_array($field['values'])){
							foreach($field['values'] as $a_key => $value){
								$this->form .= '<input type="radio" name="'.$field['name'].'" value="'.$a_key.'" ';
								if($field['options'] == $a_key) $this->form .= 'checked ';
								$this->form .= 'class="radio" />'.$value.'&nbsp;&nbsp;&nbsp;';
							}
						}
            break;
					case 'file':
						$this->form .= '<input type="file" name="'.$field['name'].'" id="'.$field['name'].'" '.$field['params'].' class="imp"/>';
						break;
					case 'datetime':
						$this->form .= '<input type="text" name="'.$field['name'].'" id="'.$field['name'].'" '.$field['params'].' value="'.$field['values'].'" class="imp"/>
        <img src="images2/cal.gif" onclick="javascript:NewCssCal (\''.$field['name'].'\',\'yyyyMMdd\',\'arrow\',true,\'24\',true)" style="cursor:pointer"/>';
						break;
					case 'image':
						if($field['label']=='Sekwencja')$this->form .= '<img src="'.$field['url'].'" width="500"/>';
						else $this->form .= '<img src="'.$field['url'].'" class="'.$field['name'].'"/>';
						break;
					case 'checkbox':
						$this->form .= '<input type="checkbox" name="'.$field['name'].'" id="'.$field['name'].'" class="imp"/>';
						break;
					case 'opcje':
						$this->form .= '<div id="formularz">'.$this->AddOpcje($field['values']).'</div>';
						break;
					default:
						break;
				}
				$this->form .= chr(10).chr(9).'</p>'.chr(10);
			} else {
				switch($field['type']){
					case 'header' : $this->form .= '<div class="header">'.$field['label'].'</div>'.chr(10); break;
					case 'div' : $this->form .= $field['label'].chr(10); break;
					case 'hidden': $this->form .= '<input type="hidden" name="'.$field['label'].'" id="'.$field['label'].'" value="'.$field['values'].'" class="hidden"/>'.chr(10); break;
					case 'info': $this->form .= '<p class="info" id="'.$field['id'].'">'.$field['label'].'</p>'; break;
				}
			}
		}
		$this->form .= '<p class="'.$this->setup['submit_position'].'"><input class="submit" type="submit" name="submit" value="&nbsp;&nbsp;'.$this->setup['submit'].'&nbsp;&nbsp;"  style="border:1px solid #4f9b2f;margin-top:5px;background:#60bc39;padding:3px 15px;color:white"></p>'.chr(10).'</form>'.chr(10);
		return $this->form;
	}
	
}

?>