<?php

require_once 'init.php';
if (!$_FILES || empty($_FILES['backlog_file'])) {
    ?>
	<form action="" method="post" enctype="multipart/form-data">
		<label>
			Select CSV File
			<input type="file" name="backlog_file" />
		</label>
		<button type="submit">Upload</button>
	</form><?php 
} else {
    $backlog = csv_to_array($_FILES['backlog_file']['tmp_name']);
    save_array_to_file($backlog, 'uploads/backlog-current.php');
}
        if (!empty($attachments)) {
            $thread->setAttachments($attachments);
        }
        // Create by: required
        $thread->setCreatedBy($customer);
        $conversation->setThreads(array($thread));
        $conversation->setCreatedBy($customer);
        $client->createConversation($conversation);
        echo $key . "+\r\n";
        unset($backlog[$key]);
        save_array_to_file($backlog, 'uploads/backlog-left.php');
    } catch (HelpScout\ApiException $e) {
        $failed[] = $row;
        echo $e->getMessage();
        print_r($e->getErrors());
        save_array_to_file($failed, 'uploads/backlog-failed.php');
    }
}
add_action('wp_footer', 'my_custom_popup_scripts', 500);
function my_custom_popup_scripts()
{
    ?>
	<script type="text/javascript">
		(function ($) {

			$('.pum_sub_form').on('pumNewsletterSuccess', function () {
				$(this).parents('.popmake').popmake('close');
			});


		}(jQuery))