CFDBViewImportCsv.php
6.12 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/*
"Contact Form to Database" Copyright (C) 2013 Michael Simpson (email : michael.d.simpson@gmail.com)
This file is part of Contact Form to Database.
Contact Form to Database 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.
Contact Form to Database 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 Contact Form to Database.
If not, see <http://www.gnu.org/licenses/>.
*/
require_once('CF7DBPlugin.php');
require_once('CFDBView.php');
class CFDBViewImportCsv extends CFDBView
{
/**
* @param $plugin CF7DBPlugin
* @return void
*/
function display(&$plugin)
{
if ($plugin == null) {
$plugin = new CF7DBPlugin;
}
$forms = $plugin->getForms();
$importUrl = admin_url('admin-ajax.php') . '?action=cfdb-importcsv';
$renameUrl = admin_url('admin-ajax.php') . '?action=cfdb-renameform';
$clenaupUrl = admin_url('admin-ajax.php') . '?action=cfdb-cleanup';
?>
<h2><?php echo htmlspecialchars(__('Import CSV File into Form', 'contact-form-7-to-database-extension')); ?></h2>
<form enctype="multipart/form-data" action="<?php echo $importUrl; ?>" method="post">
<table>
<tbody>
<tr>
<td><label for="file"><?php echo htmlspecialchars(__('File', 'contact-form-7-to-database-extension')); ?></label></td>
<td><input type="file" name="file" id="file" size="50"></td>
</tr>
<tr>
<td><input type="radio" name="into" id="new" value="new" checked> <?php echo htmlspecialchars(__('New Form', 'contact-form-7-to-database-extension')); ?></td>
<td><input type="text" name="newformname" id="newformname" size="50"/></td>
</tr>
<tr>
<td><input type="radio" name="into" id="existing" value="into"> <?php echo htmlspecialchars(__('Existing Form', 'contact-form-7-to-database-extension')); ?></td>
<td>
<select name="form" id="form">
<option value=""></option>
<?php
foreach ($forms as $formName) {
echo "<option value=\"$formName\">$formName</option>";
}
?>
</select>
</td>
</tr>
</tbody>
</table>
<input type="submit" name="<?php echo htmlspecialchars(__('Import', 'contact-form-7-to-database-extension')); ?>" id="importsubmit" value="import">
</form>
<script type="text/javascript">
jQuery('#file').change(function () {
var val = jQuery(this).val();
val = val.substring(val.lastIndexOf('/') + 1);
val = val.substring(val.lastIndexOf('\\') + 1);
val = val.replace(/\.([^\.])*$/, "");
jQuery('#newformname').val(val);
});
</script>
<form enctype="multipart/form-data" action="<?php echo $renameUrl; ?>" method="post">
<h2><?php echo htmlspecialchars(__('Rename Form', 'contact-form-7-to-database-extension')); ?></h2>
<select name="form" id="form">
<option value=""></option>
<?php
foreach ($forms as $formName) {
echo "<option value=\"$formName\">$formName</option>";
}
?>
</select>
<td><input type="text" name="newformname" id="renameformname" size="10"/></td>
<input type="submit" name="rename" id="renamesubmit" value="<?php echo htmlspecialchars(__('Rename', 'contact-form-7-to-database-extension')); ?>">
</form>
<h2><?php echo htmlspecialchars(__('Backup Form to CSV File', 'contact-form-7-to-database-extension')); ?></h2>
<ul>
<li><?php echo htmlspecialchars(__('Backup a form into a CSV file that can be re-imported without loss of data.', 'contact-form-7-to-database-extension')); ?></li>
<li><?php echo htmlspecialchars(__('Limitation: this will not export file uploads.', 'contact-form-7-to-database-extension')); ?></li>
<li><?php echo htmlspecialchars(__('Limitation: extremely large numbers of records in your form may cause the export operation on your server to run out of memory, thereby not giving you all the rows.', 'contact-form-7-to-database-extension')); ?></li>
</ul>
<form method="get" action="<?php echo $plugin->getPluginDirUrl() ?>export.php">
<input type="hidden" name="enc" value="CSV"/>
<input type="hidden" name="bak" value="true"/>
<select name="form">
<option value=""></option>
<?php
foreach ($forms as $formName) {
echo "<option value=\"$formName\">$formName</option>";
}
?>
</select>
<input type="submit" name="<?php echo htmlspecialchars(__('Export', 'contact-form-7-to-database-extension')); ?>" value="export">
</form>
<h2><?php echo htmlspecialchars(__('Data Cleanup', 'contact-form-7-to-database-extension')); ?></h2>
<?php echo htmlspecialchars(__('Clean up data that can cause incorrect behavior', 'contact-form-7-to-database-extension')); ?>
<form name="cleanup" action="<?php echo $clenaupUrl; ?>" method="post">
<input type="submit" name="cleanup" id="cleanupsubmit" value="<?php echo htmlspecialchars(__('Clean up data', 'contact-form-7-to-database-extension')); ?>">
</form>
<?php
}
}