Created
January 31, 2017 13:52
-
-
Save tovask/8389562fa71b25a60226d17bf1dfea77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// kill boolean | |
// dbcolumn keeped | |
if($_SERVER['REQUEST_METHOD']=='POST'){ | |
header('Content-Type: text/plain; charset=utf-8'); | |
$csv = $_POST['csv']; | |
$csv = trim($csv); // cut whitespaces | |
$csv = preg_split("/\r\n|\n|\r/", $csv); // split by line | |
foreach ($csv as &$value) { | |
// prepare for easy split | |
$value = preg_replace('/,,/', ',"",',$value); | |
$value = preg_replace('/,,/', ',"",',$value); | |
$value = preg_replace('/^"/', '',$value); | |
$value = preg_replace('/"$/', '',$value); | |
$value = preg_replace('/,$/', ',"',$value); | |
//var_dump($value); | |
//print $value."\n"; | |
$value = explode('","',$value); | |
} | |
//print_r($csv); | |
print "\$form = array(\n"; | |
foreach($csv as $question){ | |
switch($question[0]){ | |
case 'cimke': | |
print " array('type' => 'section-header','question' => '$question[1]','hint' => '$question[2]'),\n"; | |
break; | |
case 'szoveg': | |
print " array('type' => 'text','question' => '$question[1]','hint' => '$question[2]','formname' => '$question[3]','dbcolumn' => '$question[3]'),\n"; | |
break; | |
case 'torzs': | |
$ertekek = explode(',',$question[4]); | |
$options = "array("; | |
$i = 1; | |
foreach ($ertekek as $value) { | |
$options .= "$i => '$value',"; | |
$i++; | |
} | |
$options .= ")"; | |
print " array('type' => 'radio','question' => '$question[1]','hint' => '$question[2]','formname' => '$question[3]','dbcolumn' => '$question[3]','options' => $options),\n"; | |
break; | |
case 'datum': | |
print " array('type' => 'date','question' => '$question[1]','hint' => '$question[2]','formname' => '$question[3]','dbcolumn' => '$question[3]'),\n"; | |
break; | |
default: | |
print "\n\n\n".'error: unknow type: '.$question[0]."\n\n\n"; | |
//print_r($question); | |
//var_dump($question); | |
break; | |
} | |
} | |
print ");"; | |
exit(); | |
}else{ | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
<style> | |
html,body{ | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
p{ | |
margin: 0; | |
} | |
textarea{ | |
width: 90%; | |
height: 500px; | |
margin-left: 3px; | |
} | |
</style> | |
</head> | |
<body> | |
<p>csv:<br>az oszlopnevek nem kellenek<br>az utolsó sort valamiért nem tudja, azt kézzel kell</p> | |
<form method="POST"> | |
<textarea name="csv" autofocus ></textarea> | |
<br> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment