ACC SHELL

Path : /srv/www/vhosts/profias/inc/admin/
File Upload :
Current File : /srv/www/vhosts/profias/inc/admin/forms_bak.php

<?php
  
  class Input
  {
    var $type, $name, $value, $reg_check, $id, $class, $spec, $label, $label_id, $label_class, $options;
    
    function Input($type, $name, $value, $reg_check, $id, $class, $spec, $label, $label_id, $label_class, $options)
    {
      $this->type=$type;
      $this->name=$name;
      $this->value=$value;
      $this->id=$id;
      $this->class=$class;
      $this->spec=$spec;
      $this->label=$label;
      $this->label_id=$label_id;
      $this->label_class=$label_class;
      $this->reg_check=$reg_check; 
      $this->options=$options;
    } 
    
    // parametr: DTD vraceneho kodu (html, xhtml), vraci prislusny kod
    function getHTML($dtd, $sent)
    {
      if ('hidden'==$this->type)
      {
        $tmp_class=' class="no_css"';
      }
      else
      {
        $tmp_class=' class="input"';
      }
    
      $result='    <div'.$tmp_class.'>
      ';
    
      // nastaveni docasnych prmennych pro id a class v html kodu
      if (TRUE==$this->id)
      {
        $tmp_id=' id="'.$this->id.'"';
      }
      else
      {
        $tmp_id='';
      }
      if (TRUE==$this->class)
      {
        $tmp_class=' class="'.$this->class.'"';
      }
      else
      {
        $tmp_class='';
      }
      // nastaveni docasnych prmennych pro id a class v html kodu pro label
      if (TRUE==$this->label_id)
      {
        $tmp_label_id=' id="'.$this->label_id.'"';
      }
      else
      {
        $tmp_label_id='';
      }
      if (TRUE==$this->label_class)
      {
        $tmp_label_class=' class="'.$this->label_class.'"';
      }
      else
      {
        $tmp_label_class='';
      }
      
      if (TRUE==$this->name)
      {
        $tmp_name=' name="'.$this->name.'"';
      }
      else
      {
        $tmp_name='';
      }
      if ('xhtml'==$dtd)
      {
      
        if (TRUE==$this->label)
        {
          $result.='        <label'.$tmp_label_id.$tmp_label_class.'>'.$this->label.'</label>
          ';
        }
        if ((TRUE==$this->value) && ('checkbox'==$this->type))
        {
          $this->spec.=' checked'; 
        } 
        if (TRUE==isset($sent[$this->name]))
        {
          if (($this->value==$sent[$this->name]) && ('checkbox'==$this->type))
          {
            $this->spec.=' checked'; 
          } 
        }
        if ('select'==$this->type)
        {
          $result.='<select'.$tmp_id.$tmp_class.' type="'.$this->type.'"'.$tmp_name.$this->spec.' >
          ';
          
          for ($i=0; $i<count($this->options); $i++)
          {
            $tmp_select='';
           // if (TRUE==isset($sent[$this->name]))
            {
              if ( ($sent[$this->name]==$this->options[$i]['text']) || (TRUE==$this->options[$i]['selected']) )
              {
                $tmp_select=' selected="selected"'; 
              }
            }
            if (
              ($this->value==$this->options[$i]['text'])
              ||
              ($this->value==$this->options[$i]['value'])
            )
            {
              $tmp_select=' selected="selected"';
            }
                      
            $result.='  <option'.$tmp_select.' value="'.$this->options[$i]['value'].'">'.$this->options[$i]['text'].'</option>
            ';
          }
          $result.='</select> 
          ';
        }
        else
        if ('checkbox'==$this->type)
        {
          $result.='    <input'.$tmp_id.$tmp_class.' type="'.$this->type.'"'.$tmp_name.$this->spec.' />
          ';
        }
        else
        if ('textarea'==$this->type)
        {
          $result.='    <textarea'.$tmp_id.$tmp_class.$tmp_name.' '.$this->spec.'>'.$this->value.'</textarea>
          ';
        }
        else
        if ('wysiwyg'==$this->type)
        {
  
include_once('fckeditor.php');
//include_once('fckeditor.php');
          if (FALSE==$this->id)
          {
            $this->id=$this->name;
          }
ob_start();
$sBasePath = $_SERVER['PHP_SELF'] ;
$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "../files" ) ) ;
$oFCKeditor = new FCKeditor($this->id) ;
$oFCKeditor->BasePath	= $sBasePath ;
$oFCKeditor->Value=$this->value;
$oFCKeditor->Create() ;
$result.=ob_get_contents();
ob_end_clean(); 
$tmp_class=' class="textarea"';
          $result.='<noscript><textarea'.$tmp_id.$tmp_class.$tmp_name.' '.$this->spec.'>'.$this->value.'</textarea>
            </noscript>
          ';
        }
        else
        if ('label'==$this->type)
        {
          $result.='<div style="clear: both;"><!-- --></div>'.$this->value;
        }
        else
        {
          $result.='    <input'.$tmp_id.$tmp_class.' type="'.$this->type.'"'.$tmp_name.' value="'.$this->value.'"'.$this->spec.' />
          ';
        }
        
        
      }
      
      $result.='  </div>
      ';
      
      return $result;
    }
    
  }
  class Form
  {
    var $action, $method, $id, $class, $inputs, $sent, $default, $bad, $divs, $template;
  
    
    /* konstruktor tridy FORM
     * parametry: action: skript, ktery zpracuje poslana data
     *            method: zpusob poslani dat (GET, POST)
     *            id: id elementu <FORM> v HTML kodu
     *            class: trida elementu <FORM> v HTML kodu
     * vraci true
     */
    function Form($action='', $method='post', $id='', $class='', $sent=array(), $default=array(), $template='')
    {
      $this->action=$action;
      $this->method=$method;
      $this->id=$id;
      $this->class=$class;
      $this->inputs=array();
      $this->sent=$sent;
      $this->default=$default;
      $this->bad=array();
      $this->divs=array(); 
      $this->template=$template;
      
      return true; 
    }
  
    function divStart($id='', $class='')
    {
      array_push($this->divs, array('id'=>$id, 'class'=>$class, 'start'=>count($this->inputs), 'end'=>count($this->inputs)));
    }
  
    function divEnd()
    {
      $this->divs[count($this->divs)-1]['end']=count($this->inputs);
    }
    /* prida do pole inputu novy
     *
     * parametry:
     *
     *   type:        typ (text, select, ...)
     *   name:        jmeno
     *   value:       pocatecni hodnota
     *   reg_check:   regularni vyraz, proti kteremu se bude provadet kontrola obsahu inputu
     *   id:          id inputu v HTML
     *   class:       trida inputu v HTML
     *   spec:        specialni vlastnosti (CHECKED, SELECTED, MAXLENGTH, ROWS, ...)
     *   label:       text k inputu pro <label>
     *   label_id:    id labelu v HTML
     *   label_class: trida labelu v HTML
     *   options:     pole polozek pro <SELECT>
     */
  
    function addInput($type='text', $name='', $value='', $reg_check='', $id='', $class='', $spec='', $label='', $label_id='', $label_class='', $options=array())
    {
      $tmp_value=$value;
      $keys=array_keys($this->sent);
      if (''==$reg_check)
      {
        $reg_check='^.*$'; 
      }
      if ('submit'==$type)
      {
        if ('null'==$value)
        {
          return FALSE;
        }
        $class='button';
        
      }
      
      if ('radio'==$type)
      {
        $class='radio';
      }
      if ('textarea'==$type)
      {
        $class='textarea';
      }
      if ('select'==$type)
      {
        $class='select';
      }
      if ((TRUE==in_array($name, $keys)) && ($type!='submit') && ($type!='button') && ($type!='hidden'))
      {
       if ('null'!=$reg_check)
       { 
        if (TRUE==ereg($reg_check, $this->sent[$name]))
        {
          if ('radio'!=$type)
          {
            $tmp_value=stripslashes($this->sent[$name]);
            // $spec='';
          }
        }
        else
        {
          $this->bad[]=$name; 
          
          $label_class.=' red';
          
        if (TRUE==is_array($this->default))
        {
          $keys=array_keys($this->default);
          if (TRUE==in_array($name, $keys))
          {
            $tmp_value=$this->default[$name];
          }   
        }
  
        }
       }
       else
       {
        if (TRUE==in_array($name, $keys))
        {
          $tmp_value=stripslashes($this->sent[$name]);
        }   
        else
        {
          $tmp_value=$value;
        }
       }
      }
      else
      {
        if (TRUE==is_array($this->default))
        {
          $keys=array_keys($this->default);
          if (TRUE==in_array($name, $keys))
          {
            if ('submit'!=$type)
            {
              if (TRUE==$this->default[$name])
              {
                $tmp_value=$this->default[$name];
              }
            }
          }
        }
      }
      
      $this->inputs[]=new Input($type, $name, $tmp_value, $reg_check, $id, $class, $spec, $label, $label_id, $label_class, $options);
      
      return true;
    }
    
    // parametr: DTD vraceneho kodu (html, xhtml), vraci prislusny kod
    function getHTML($dtd='xhtml')
    {
      $result='';
      // nastaveni docasnych prmennych pro id a class v html kodu
      if (TRUE==$this->id)
      {
        $tmp_id=' id="'.$this->id.'"';
      }
      else
      {
        $tmp_id='';
      }
      if (TRUE==$this->class)
      {
        $tmp_class=' class="'.$this->class.'"';
      }
      else
      {
        $tmp_class='';
      }
    
      
      if ('xhtml'==$dtd)
      {
      
      // bude generovan XHTML kod
        $result.='
        <form'.$tmp_id.$tmp_class.' action="'.$this->action.'" method="'.$this->method.'" enctype="multipart/form-data"> 
          <div>
        ';

        if  (FALSE==$this->template)
        {
        for ($i=0; $i<count($this->inputs); $i++)
        {
          for ($j=0; $j<count($this->divs); $j++)
          {
            if ($this->divs[$j]['start']==$i)
            {
              if (TRUE==$this->divs[$j]['id'])
              {
                $tmp_id=' id="'.$this->divs[$j]['id'].'"';
              }
              else
              {
                $tmp_id='';
              }
              if (TRUE==$this->divs[$j]['class'])
              {
                $tmp_class=' class="'.$this->divs[$j]['class'].'"';
              }
              else
              {
                $tmp_class='';
              }
              $result.='<div'.$tmp_id.$tmp_class.'>
              '; 
            }
          }
        
          $result.=$this->inputs[$i]->getHTML($dtd, $this->sent);
          for ($j=0; $j<count($this->divs); $j++)
          {
            if ($this->divs[$j]['end']==$i+1)
            {
                $result.='</div>
              ';    
            }
          }
        }
        }
        
        
        else
        {
          $f=fopen($this->template, 'r');
          $temp=fread($f, filesize($this->template));
          fclose($f);
          $inc=1;
          for ($i=0; $i<count($this->inputs); $i++)
          {
            if ('hidden'==$this->inputs[$i]->type)
            {
              $result.=$this->inputs[$i]->getHTML($dtd, $this->sent);
            }
            else
            {
              $tmp=$this->inputs[$i]->getHTML($dtd, $this->sent);
              $temp=str_replace('{|'.$inc.'|}', $tmp, $temp);
              $inc++;
            }
            
          }
          $temp=ereg_replace('\{\|.*\|\}', '', $temp);
          $result.=$temp;
        }
        
        $result.='    </div>  
        <div class="clear_both"><!-- --></div>
        </form>
        '; 
      }
      
      return $result; 
    }
  
    
    // vrati pole spatne vyplnenych polozek
    function getErrors()
    {
      return $this->bad;
    }
  
  }
?>

ACC SHELL 2018