All pastes #2127022 Raw Edit

Mine

public text v1 · immutable
#2127022 ·published 2012-03-12 06:18 UTC
rendered paste body
<?php
if (!is_user_logged_in()) {
    echo 'You must be logged in to use this feature.';
    exit;
} 
if (!empty($_POST['submit'])) {

    if (!empty($_FILES['csv'])) {

        if (5 < 4) { // add a check to see if valid csv, had this in before but it was bugged need to fix it, for now put this to force it.
            echo 'The file you uploaded is corrupted or not a valid csv file.';
            exit;
        } else {

            $csv = new parseCSV($_FILES['csv']['tmp_name']);
            $i = 0;


            foreach ($csv->data as $row) {

                if (empty($row['store'])) {
                    $halt = true;
                }

                $dealer = array();
                $dealer['Store'] = $row['store'];
                $dealer['Address'] = $row['address'];
                $dealer['City'] = $row['city'];
                $dealer['Pro'] = $row['pro'];
                $dealer['Pc'] = $row['pc'];
                $dealer['Email'] = $row['email'];
                $dealer['Phone'] = $row['phone'];
                echo '<pre>';
                print_r($dealer);
                echo '</pre>';
                $dealer['ARGS'] = array(
                    'post_author' => 1,
                    'post_title' => $dealer['Store'],
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_type' => 'dealer
                ');
                if ($halt != true) {
                    if ($dealer['ID'] = wp_insert_post($dealer['ARGS'])) {

                        update_post_meta($dealer['ID'], 'wpcf-address', $dealer['Address']);
                        update_post_meta($dealer['ID'], 'wpcf-city', $dealer['City']);
                        update_post_meta($dealer['ID'], 'wpcf-email', $dealer['Email']);
                        update_post_meta($dealer['ID'], 'wpcf-pc', $dealer['Pc']);
                        update_post_meta($dealer['ID'], 'wpcf-phone', $dealer['Phone']);
                        update_post_meta($dealer['ID'], 'wpcf-pro', $dealer['Pro']);
                        update_post_meta($dealer['ID'], 'wpcf-store', $dealer['Store']);

                        $i++;
                    }
                }

                unset($product, $halt);
            }
            echo $i . ' Products added.';
        }
    }
} else {
    ?>
    <html>
        <head>
            <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <?php wp_head(); ?>
        </head>
        <body>
            <div style="margin-bottom:20px;">
                <h1>*COMPANY REMOVED ** Location Importer Tool</h1>
                <p>Please make sure the excel spreadsheet follows the following guidelines:
                <li>The excel file must be a 'csv' file.</li>
                <li>Must include the following columns (all lowercase): store, address, city, pro, pc, email, phone</li>
                <li>Click <a href="<?php echo bloginfo('url'); ?>/wp-import.php?delete=1">here</a> to delete ALL dealer location data in bulk.</li>
            </div>
            <div class="form">

                <form enctype="multipart/form-data" action="" method="post">

                    <input type="file" name="csv" value="" />
                    <input type="submit" name="submit" value="Import" />

                </form>
            </div>
    <?php wp_footer(); ?>
        </body>
    </html>
<?php } ?>