<?php 

  $mysqli = mysqli_connect("127.0.0.1","root","","thepeople")
            or die (" 
                    <p>Spatne zadane udaje v db.php</p>
                "); 
  mysqli_set_charset($mysqli,"utf8");
  
  function Select($table_name, $column_name, $select_one)
        {   
           global $mysqli;
           $selectDropdown = "<label class=\"field select\"><select name=\"$column_name\" id=\"$column_name\">";
           if ($select_one == "whatever"){$selectDropdown .= "<option value=\"\">Whatever...</option>";}
           else {$selectDropdown .= "<option value=\"\">Select"; 
           if ($select_one != ""){$selectDropdown .=" $select_one";};
           $selectDropdown .= "...</option>";}
           $result = $mysqli->query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
               WHERE TABLE_NAME = '$table_name' AND COLUMN_NAME = '$column_name'")
           or die ($mysqli->error());
        
            $row = mysqli_fetch_array($result);
            $enumList = explode(",", str_replace("'", "", substr($row['COLUMN_TYPE'], 5, (strlen($row['COLUMN_TYPE'])-6))));
        
            foreach ($enumList as $value) {
                $selectDropdown .= "<option value=\"$value\">$value</option>";
            }
        
            $selectDropdown .= "</select><i class=\"arrow\"></i></label>";
            return $selectDropdown;
    } 
    
    
    function RadioButton($table_name, $column_name, $dont = 0)
        {   
           global $mysqli;
           $radioButton = "<div class=\"option-group field\">"; 
           $result = $mysqli->query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
               WHERE TABLE_NAME = '$table_name' AND COLUMN_NAME = '$column_name'")
           or die ($mysqli->error());
        
            $row = mysqli_fetch_array($result);
            $enumList = explode(",", str_replace("'", "", substr($row['COLUMN_TYPE'], 5, (strlen($row['COLUMN_TYPE'])-6))));
        
            foreach ($enumList as $value) {
                $radioButton .= "<label class=\"option\">
                                  <input type=\"radio\" value=\"$value\" name=\"$column_name\">
                                  <span class=\"radio\"></span>
                                  $value
                                 </label>";
            }
            if ($dont) {
            $radioButton .= "<label class=\"option\">
                                  <input type=\"radio\" value=\"\" name=\"$column_name\" checked>
                                  <span class=\"radio\"></span>
                                  Don't know
                                 </label>";  }
            $radioButton .= "</div>";
            return $radioButton;
    }
    
    function YesNo($column_name)
        {   
           global $mysqli;
           $radioButton = "<label class=\"field-label\" for=\"$column_name\">$column_name</label>
                           <div class=\"option-group field\">"; 
           $radioButton .= "<label class=\"option\">
                                  <input type=\"radio\" value=\"1\" name=\"$column_name\">
                                  <span class=\"radio\"></span>
                                  Yes
                                 </label>";
            $radioButton .= "<label class=\"option\">
                                  <input type=\"radio\" value=\"0\" name=\"$column_name\">
                                  <span class=\"radio\"></span>
                                  No
                                 </label>";
            $radioButton .= "<label class=\"option\">
                                  <input type=\"radio\" value=\"-1\" name=\"$column_name\" checked>
                                  <span class=\"radio\"></span>
                                  Don't know
                                 </label>";
            $radioButton .= "</div>";
            return $radioButton;
    }
    
    function CheckBox($table_name, $column_name, $i)
        {   
           global $mysqli;
           $checkBox = "<div class=\"option-group field marg\">";
           $result = $mysqli->query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
               WHERE TABLE_NAME = '$table_name' AND COLUMN_NAME = '$column_name'")
           or die ($mysqli->error());
        
            $row = mysqli_fetch_array($result);
            $enumList = explode(",", str_replace("'", "", substr($row['COLUMN_TYPE'], 5, (strlen($row['COLUMN_TYPE'])-6))));
        
            foreach ($enumList as $value) {
                $checkBox .= "<label class=\"option color\" title=\"$value\">
                                <input type=\"checkbox\" name=\"$column_name"."[]\" id=\"$value$i\" value=\"$value\">
                                <span class=\"checkbox\"></span>
                              </label>";
            }
            $checkBox .= "</div>";
            return $checkBox;
    }
   
   
   function iso2ascii($text)
            {
                return Str_Replace(
                        Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú","ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž") ,
                        Array("a","c","d","e","e","i","l","n","o","r","s","t","u","u","y","z","A","C","D","E","E","I","L","N","O","R","S","T","U","U","Y","Z") ,
                        $text);
            } 
   
?>
