public function jobs_load_tasks()
 {
     // quit if no job name provided
     if (!isset($_REQUEST['job'])) {
         return false;
     }
     $jobname = $_REQUEST['job'];
     // check if an array of listing IDs was provided
     $lm = new WPLA_ListingsModel();
     $listing_ids = isset($_REQUEST['item_ids']) && is_array($_REQUEST['item_ids']) ? $_REQUEST['item_ids'] : false;
     if ($listing_ids) {
         $items = $lm->getItemsByIdArray($listing_ids);
     }
     // register shutdown handler
     global $wpla_shutdown_handler_enabled;
     $wpla_shutdown_handler_enabled = true;
     register_shutdown_function(array($this, 'shutdown_handler'));
     // handle job name
     switch ($jobname) {
         case 'updateProductsWithoutASIN':
             // get prepared items
             $sm = new WPLA_ListingsModel();
             $items = $sm->getAllOnlineWithoutASIN();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('updateProduct', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'createAllImportedProducts':
             // get prepared items
             $sm = new WPLA_ListingsModel();
             $items = $sm->getAllImported();
             // DEV: limit to 10 tasks at a time ***
             // $items = array_slice($items, 0, 10, true);
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('createProduct', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'processAmazonReport':
             // get report
             $id = $_REQUEST['item_id'];
             $report = new WPLA_AmazonReport($id);
             $rows = $report->get_data_rows();
             $rows_count = sizeof($rows);
             $page_size = 500;
             $number_of_pages = intval($rows_count / $page_size) + 1;
             $items = array();
             if ($number_of_pages > 0) {
                 for ($page = 0; $page < $number_of_pages; $page++) {
                     $from_row = $page * $page_size + 1;
                     $to_row = ($page + 1) * $page_size;
                     if ($to_row > $rows_count) {
                         $to_row = $rows_count;
                     }
                     $items[] = array('id' => $id, 'page' => $page, 'from_row' => $from_row, 'to_row' => $to_row, 'title' => 'Processing rows ' . $from_row . ' to ' . $to_row);
                 }
             }
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('processReportPage', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'processRowsFromAmazonReport':
             $id = $_REQUEST['report_id'];
             $skus = $_REQUEST['sku_list'];
             foreach ($skus as $sku) {
                 $items[] = array('id' => $id, 'sku' => $sku, 'title' => 'Processing SKU ' . $sku);
             }
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('processSingleSkuFromReport', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'fetchProductDescription':
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('fetchFullProductDescription', $items, $jobname);
             $this->returnJSON($response);
             exit;
         default:
             // echo "unknown job";
             // break;
     }
     // exit();
 }
 public function displayForeignImportPage($import_is_done = false)
 {
     $lm = new WPLA_ListingsModel();
     $listings = $lm->getAllImported('foreign_import');
     // return to step 1 if no products are to be imported
     if (!$import_is_done && count($listings) == 0) {
         return $this->displayMainImportPage();
     }
     // skip step 3 if no products are to be imported
     if ($import_is_done && count($listings) == 0) {
         return $this->displayFinishedImportPage();
     }
     $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'listings' => $listings, 'import_is_done' => $import_is_done, 'form_action' => 'admin.php?page=' . self::ParentMenuId . '-import');
     $this->display('import/foreign_import_page', $aData);
 }