changed behaviour
This commit is contained in:
+32
@@ -20,3 +20,35 @@ if ($_GET['controller'] == "Article"){
|
||||
echo "Artikel wurden gespeichert.";
|
||||
}
|
||||
}
|
||||
|
||||
if ($_GET['controller'] == "Inventur"){
|
||||
if ($_GET['action'] == "export") {
|
||||
$json = file_get_contents('php://input');
|
||||
$list = json_decode($json, true);
|
||||
$fp = fopen('data/inventur_'.date('Y-m-d').'.csv', 'w');
|
||||
|
||||
fputcsv($fp,array_keys(flatten($list[0])));
|
||||
foreach ($list as $obj) {
|
||||
$fields = flatten($obj);
|
||||
//array_walk_recursive($obj, function($a)use (&$fields) { $fields[] = $a;});
|
||||
//print_r($fields);
|
||||
fputcsv($fp,$fields);
|
||||
}
|
||||
echo "Inventur wurde gespeichert.";
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function flatten($array, $prefix = '') {
|
||||
$result = array();
|
||||
foreach($array as $key=>$value) {
|
||||
if(is_array($value)) {
|
||||
$result = $result + flatten($value, $prefix . $key . '_');
|
||||
}
|
||||
else {
|
||||
$result[$prefix . $key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
Reference in New Issue
Block a user