-
Notifications
You must be signed in to change notification settings - Fork 0
/
mess_write.php
70 lines (60 loc) · 2.62 KB
/
mess_write.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
RPQ2-Webinterface
Copyright (C) 2012-2013 Innowatt Energiesysteme GmbH
Author: Max Bruckner
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
include_once('meta.php');
include_once('settings.php');
include_once('templates.php');
include_once('page.php');
include_once('file.php');
function write_csv($filename, $comment, $regler, $data, $take_comments, $take_others) {
global $settings;
$first_value = FALSE;
$output = $comment;
$output .= "Regler,$regler\n";
foreach( $data as $line) {
switch($line['type']) {
case 'value':
$first_value = TRUE;
$output .= "{$line['pos']},{$line['skal']},{$line['komma']},{$line['skalproz']},{$line['proz']},{$line['hex']},{$line['bin']},{$line['text']}\n";
break;
case 'comment':
if($take_comments)
$output .= $line['line'] . "\n";
break;
case 'other':
if($take_others && $first_value )
$output .= $line['line'] . "\n";
}
}
$filename = correct_filename($filename, '');
return file_put_contents("{$settings['ordner_einstell-mess']}/$filename", $output);
}
$title = "Messwerttabelle speichern";
$author = "Max Bruckner";
$filename = $_POST['filename'];
$comment = $_POST['comment'];
$regler = $_POST['regler'];
$data = $_POST['data'];
$take_comments = $_POST['take_comments'];
if(write_csv($filename, $comment, $regler, $data, $take_comments, FALSE)) {
$message = http_build_query(array('message' => get_template('success', array('text' => 'Messwerttabelle gespeichert!'))));
$header = get_template('redirect', array('time' => 0, 'destination' => "einstell-mess.php?$message"));
} else {
$message = http_build_query(array('message' => get_template('failure', array('text' => 'Messwerttabelle nicht gespeichert!'))));
$header = get_template('redirect', array('time' => 3, 'destination' => "einstell-mess.php?$message"));
}
draw_page($output, $title, $author, HTML, $header);
?>