summaryrefslogtreecommitdiffstats
path: root/includes/admin/views/giglog_import_gigs.php
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-03-07 20:00:06 +0100
committerHarald Eilertsen <haraldei@anduin.net>2021-03-07 20:00:06 +0100
commitb5622ca47e975370d22912ae1ee6d76d33447a27 (patch)
treea6561325308aa802a88e4c9b7f53620b506543ff /includes/admin/views/giglog_import_gigs.php
parentb2784f4bcb9724786dde19b31304f86918f6fb95 (diff)
downloadgigologadmin-b5622ca47e975370d22912ae1ee6d76d33447a27.tar.gz
gigologadmin-b5622ca47e975370d22912ae1ee6d76d33447a27.tar.bz2
gigologadmin-b5622ca47e975370d22912ae1ee6d76d33447a27.zip
Implement upload of gig data files.
Diffstat (limited to 'includes/admin/views/giglog_import_gigs.php')
-rw-r--r--includes/admin/views/giglog_import_gigs.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php
index 953fa62..e04d0e6 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -19,7 +19,47 @@
if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
class GiglogAdmin_ImportGigsPage {
static function render_html() {
- echo '<div class="wrap"><h1>Let\'s import some gigs!</h1></div>';
+ ?>
+ <div class="wrap">
+ <h1>Import gigs</h1>
+ <p>Import gig data from a tab separated data file.</p>
+ <form action="<?php menu_page_url( 'giglog_import' ) ?>" enctype="multipart/form-data" method="post">
+ <?php wp_nonce_field( plugin_basename( __FILE__ ), 'giglog_import_nonce' ); ?>
+ <label for="giglog_import_file">File: </label>
+ <input type="file" name="giglog_import_file" id="giglog_import_file">
+ <?php submit_button(); ?>
+ </form>
+ </div>
+ <?php
+ echo giglogadmin_getunprocessed();
+ }
+
+ static function submit_form() {
+ if ('POST' === $_SERVER['REQUEST_METHOD'] && current_user_can('upload_files') && !empty($_FILES['giglog_import_file']['tmp_name'])) {
+ $nonce = $_POST['giglog_import_nonce'];
+ $valid_nonce = isset($nonce) && wp_verify_nonce($nonce);
+ GiglogAdmin_ImportGigsPage::process_upload($_FILES['giglog_import_file']);
+ }
+ }
+
+ static function process_upload($file) {
+ global $wpdb;
+
+ $table = 'wpg_files';
+ $fo = new SplFileObject($file['tmp_name']);
+ $r = 0;
+
+ foreach ($fo as $newconcert) {
+ $row = array(
+ 'filename' => $fo,
+ 'rowid' => $r++,
+ 'rowcontent' => $newconcert
+ );
+
+ if ($wpdb->insert($table, $row) === false) {
+ $wpdb->bail();
+ }
+ }
}
}
}