<?php

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

function presentaPregsRangoSelect($min_val,$min_text,$max_val,$max_text,$id_q)
{
	//print $id_q;
	print('<select class="form-control" name="question'.$id_q.'" required>');
	print('<option></option>');
	print('<option value="'.$min_val.'">'.$min_val." - ".$min_text.'</option>');
	print("\n");
	for($i=$min_val+1;$i<($max_val);$i++)
	{
		print('<option value="'.$i.'">'.$i.'</option>');
		print($i);
		print("\n");
	}
	print('<option value="'.$max_val.'">'.$max_val." - ".$max_text.'</option>');
	print("\n");
	print("</select>");
	print("\n");
}

function presentaPregsRangoSlider($min_val,$min_text,$max_val,$max_text,$id_q)
{
	//print('<div class="slidecontainer">');
	print('<input type="range" class="form-control-range slider" value="0" min="'.$min_val.'" max="'.$max_val.'" name="question'.$id_q.'" id="question'.$id_q.'" required>');
	print('<div class="row">');
	
    print('<div class="col-4">');
	print("<small>$min_text</small>");
	print('</div>');
    print('<div class="col-4 text-center">');
	print('<span id="val'.$id_q.'"></span>');
	print('</div>');
    print('<div class="col-4 text-right">');
	print("<small>$max_text</small>");
	print('</div>');
	print('</div>');
	
	print('
	<script>
	var slider'.$id_q.' = document.getElementById("question'.$id_q.'");
	var output'.$id_q.' = document.getElementById("val'.$id_q.'");
	output'.$id_q.'.innerHTML = slider'.$id_q.'.value;

	slider'.$id_q.'.onclick = function() {
	  output'.$id_q.'.innerHTML = this.value;
	}
	</script>
	');
	//print('</div>');
}

function presentaPregsRangoRadio($min_val,$min_text,$max_val,$max_text,$id_q)
{
	print('<div class="row-sm">');
	print('<div class="form-check">');
	print('<input class="form-check-input" type="radio" name="question'.$id_q.'" id="radio'.$min_val.'" value="'.$min_val.'" required>');
	print('<label class="form-check-label" for="radio'.$min_val.'">'.$min_val.' - '.$min_text.'</label>');
	print('</div>');

	for($i=$min_val+1;$i<($max_val);$i++)
	{
		print('<div class="form-check">');
		print('<input class="form-check-input" type="radio" name="question'.$id_q.'" id="radio'.$i.'" value="'.$i.'">');
		print('<label class="form-check-label" for="radio'.$i.'">'.$i.'</label>');
		print('</div>');
	}
	print('<div class="form-check">');
	print('<input class="form-check-input" type="radio" name="question'.$id_q.'" id="radio'.$max_val.'" value="'.$max_val.'">');
	print('<label class="form-check-label" for="radio'.$max_val.'">'.$max_val.' - '.$max_text.'</label>');
	print('</div>');
	print('</div>');

}

function presentaPregsRangoRadio2($min_val,$min_text,$max_val,$max_text,$id_q)
{
	print('<div class="row-sm">');
    print('<div class="col">');
	print('<div class="form-check form-check-inline">');
	print('<input class="form-check-input" type="radio" name="question'.$id_q.'" id="radio'.$min_val.'" value="'.$min_val.'">');
	print('</div>');
	print('</div>');

	for($i=$min_val+1;$i<($max_val);$i++)
	{
    print('<div class="col">');
		print('<div class="form-check form-check-inline">');
		print('<input class="form-check-input" type="radio" name="question'.$id_q.'" id="radio'.$i.'" value="'.$i.'">');
		print('</div>');
	print('</div>');
	}

    print('<div class="col">');
	print('<div class="form-check form-check-inline">');
	print('<input class="form-check-input" type="radio" name="question'.$id_q.'" id="radio'.$max_val.'" value="'.$max_val.'">');
	print('</div>');
	print('</div>');

	print('</div>');
	print('<div class="row-sm">');
    print('<div class="col">');
	print('<label class="form-check-label" for="radio'.$min_val.'">'.$min_val.' - '.$min_text.'</label>');
	print('</div>');
	for($i=$min_val+1;$i<($max_val);$i++)
	{
    print('<div class="col">');
		print('<label class="form-check-label" for="radio'.$i.'">'.$i.'</label>');
	print('</div>');
	}
    print('<div class="col">');
	print('<label class="form-check-label" for="radio'.$max_val.'">'.$max_val.' - '.$max_text.'</label>');
	print('</div>');

	print('</div>');

}
?>