-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave
56 lines (44 loc) · 1.26 KB
/
save
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
<?php
require_once('inc/config.inc');
do {
if ($USER !== 'admin') {
$msg = 'ERROR Only the admin account is allowed to save !!!';
break;
}
if (! isset($_POST['dico'])) {
$msg = 'ERROR the dictionary must be specified !!!';
break;
}
$dico=$_POST['dico'];
$dico_file=$CVDIR.$dico.'/'.$dico.'.'.$EXT;
if (! is_file($dico_file)) {
$msg ='ERROR: '.$dico_file.' does not exist !!!';
break;
}
if (! is_writable($dico_file)) {
$msg ='ERROR: '.$dico_file.' is not writable !!!';
break;
}
if (! isset($_POST['array'])) {
$msg .= 'ERROR the dictionary array must be specified !!!';
break;
}
$arr_dico = json_decode($_POST['array'],true);
//print_r($arr_dico);
$data_txt='';
foreach($arr_dico as $arr) {
$data_txt .= implode("\t",$arr)."\n";
}
//print_r($data_txt);
try {
$string_encoded = iconv( mb_detect_encoding( $data_txt ), 'Windows-1252//TRANSLIT', $data_txt );
$file = fopen($dico_file, "w");
fwrite($file, $string_encoded);
fclose($file);
} catch (Exception $e) {
$msg = 'ERROR: Backup of the '.$dico. ' dictionary failed';
}
$msg = 'Successful saving of the '.$dico. ' dictionary';
} while(0);
echo $msg;
?>