<?php

/**
 * na zaklade parametru type (text, password, hidden, textarea, submit), name, size, value, rows, cols, checked
 * \param array $params: pole proměnných prevzatých z sablony. Musí obsahovat vyse uvedene promenné
 * \param object &$smarty: objekt smarty 
 * \return false pokud dojde k chybě 
 */
 
  
function smarty_function_insert_form($params,&$smarty)
{
  global $webdoc;
  extract($params); //vytvoreni samostatnych promennych z pole $params
  $params["smarty_include_vars"]=Array(); //definovani novych promennych v $params, bez nich to nebude fungovat

  require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); // osetreni zadavani specialnich znaku (funkce Smarty)
  
  if (!isset($size))
  {
    $size = 20;
  }
  
  if (!isset($rows))
  {
    $rows = 20;
  }
  
  if (!isset($cols))
  {
    $cols = 60;
  }
  
  if (!isset($value) && ($type=="text" OR $type=="password" OR $type=="textarea"))
  {
    $value = '';
  }
  
  if ($type=="submit" && !isset($name))
  {
    $name = 'button';
  }
  
  if (!isset($checked) OR $checked==0)
  {
    $checked = '';
  }
  else
  {
    $checked = 'checked';
  }
  
  if (!isset($type) OR !isset($name) OR !isset($size) OR !isset($value) OR !isset($rows) OR !isset($cols) OR !isset($checked))
  {
    $smarty->trigger_error("insert_form: nebyl zadan nektery z parametru: type, name, size, value"); //Smarty error
    return false;
  }
  else
  {
    if ($type=="text" OR $type=="password")
    {
      $size=(int)$size;
      $output = '';
      $output .=  '<input type="' . smarty_function_escape_special_chars($type) . '" name="' . smarty_function_escape_special_chars($name) . '" size="'. smarty_function_escape_special_chars($size) . '" value="'. smarty_function_escape_special_chars($value) . '" />';
      return $output;
    }
    elseif ($type=="hidden")
    {
      $output = '';
      $output .=  '<input type="' . smarty_function_escape_special_chars($type) . '" name="' . smarty_function_escape_special_chars($name) . '" value="'. smarty_function_escape_special_chars($value) . '" />';
      return $output;
    }
    elseif ($type=="submit")
    {
      $output = '';
      $output .=  '<input type="' . smarty_function_escape_special_chars($type) . '" name="' . smarty_function_escape_special_chars($name) . '" value="'. smarty_function_escape_special_chars($value) . '" />';
      return $output;
    }
    elseif ($type=="textarea")
    {
      $rows=(int)$rows;
      $cols=(int)$cols;
      $output = '';
      $output .=  '<textarea name="' . smarty_function_escape_special_chars($name) . '" rows="' . smarty_function_escape_special_chars($rows) . '" cols="' . smarty_function_escape_special_chars($cols) . '" />'. smarty_function_escape_special_chars($value) . '</textarea>';
      return $output;
    }
    elseif ($type=="checkbox")
    {
      $output = '';
      $output .=  '<input type="' . smarty_function_escape_special_chars($type) . '" name="' . smarty_function_escape_special_chars($name) . '" value="'. smarty_function_escape_special_chars($value) . '" ' . smarty_function_escape_special_chars($checked) . ' />';
      return $output;
    }
    else
    {
    $smarty->trigger_error("insert_form: byl zadan nespravny parametr pro promennou type, pripustne jsou pouze text, password, hidden a textarea"); //Smarty error
    return false;
    }
  }
}

?>
