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
     $listing_ids = isset($_REQUEST['listing_ids']) && is_array($_REQUEST['listing_ids']) ? $_REQUEST['listing_ids'] : false;
     if ($listing_ids) {
         $items = WPLE_ListingQueryHelper::getItemsByIdArray($listing_ids);
     }
     // handle job name
     switch ($jobname) {
         case 'updateEbayData':
             // call EbayController
             $site_id = isset($_REQUEST['site_id']) ? $_REQUEST['site_id'] : get_option('wplister_ebay_site_id');
             $account_id = isset($_REQUEST['account_id']) ? $_REQUEST['account_id'] : get_option('wplister_default_account_id');
             $this->initEC($account_id);
             $tasks = $this->EC->initCategoriesUpdate($site_id);
             $this->EC->closeEbay();
             // update store categories for each account using this site_id
             $accounts = WPLE_eBayAccount::getAll();
             foreach ($accounts as $account) {
                 if ($site_id != $account->site_id) {
                     continue;
                 }
                 // add task - load user specific details
                 $tasks[] = array('task' => 'loadUserAccountDetails', 'displayName' => 'update eBay account details for ' . $account->title, 'account_id' => $account->id);
                 // add task - load store categories
                 $tasks[] = array('task' => 'loadStoreCategories', 'displayName' => 'update custom store categories for ' . $account->title, 'account_id' => $account->id);
             }
             // for each account
             // build response
             $response = new stdClass();
             $response->tasklist = $tasks;
             $response->total_tasks = count($tasks);
             $response->error = '';
             $response->success = true;
             // create new job
             $newJob = new stdClass();
             $newJob->jobname = $jobname;
             $newJob->tasklist = $tasks;
             $job = new JobsModel($newJob);
             $response->job_key = $job->key;
             $this->returnJSON($response);
             exit;
         case 'verifyItems':
             $response = $this->_create_bulk_listing_job('verifyItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'publishItems':
             $response = $this->_create_bulk_listing_job('publishItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'reviseItems':
             $response = $this->_create_bulk_listing_job('reviseItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'updateItems':
             $response = $this->_create_bulk_listing_job('updateItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'endItems':
             $response = $this->_create_bulk_listing_job('endItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'relistItems':
             $response = $this->_create_bulk_listing_job('relistItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'verifyAllPreparedItems':
             // get prepared items
             $items = WPLE_ListingQueryHelper::getAllPrepared();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('verifyItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'publishAllVerifiedItems':
             // get verified items
             $items = WPLE_ListingQueryHelper::getAllVerified();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('publishItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'publishAllPreparedItems':
             // get prepared items
             $items = WPLE_ListingQueryHelper::getAllPrepared();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('publishItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'reviseAllChangedItems':
             // get changed items
             $items = WPLE_ListingQueryHelper::getAllChangedItemsToRevise();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('reviseItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'relistAllRestockedItems':
             // get restocked items
             $items = WPLE_ListingQueryHelper::getAllEndedItemsToRelist();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('relistItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'updateAllPublishedItems':
             // get published items
             $items = WPLE_ListingQueryHelper::getAllPublished();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('updateItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'updateAllRelistedItems':
             // get published items
             $items = WPLE_ListingQueryHelper::getAllRelisted();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('updateItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'runDelayedProfileApplication':
             // get items using given profile
             $profile_id = get_option('wple_job_reapply_profile_id');
             if (!$profile_id) {
                 return;
             }
             $items1 = WPLE_ListingQueryHelper::getAllPreparedWithProfile($profile_id);
             $items2 = WPLE_ListingQueryHelper::getAllVerifiedWithProfile($profile_id);
             $items3 = WPLE_ListingQueryHelper::getAllPublishedWithProfile($profile_id);
             $items = array_merge($items1, $items2, $items3);
             $total_items = sizeof($items);
             $batch_size = get_option('wplister_apply_profile_batch_size', 1000);
             $tasks = array();
             // echo "<pre>profile_id: ";echo $profile_id;echo"</pre>";
             // echo "<pre>total: ";echo $total_items;echo"</pre>";die();
             for ($page = 0; $page < $total_items / $batch_size; $page++) {
                 $from = $page * $batch_size + 1;
                 $to = $page * $batch_size + $batch_size;
                 $to = min($to, $total_items);
                 // add task - load user specific details
                 $tasks[] = array('task' => 'applyProfileDelayed', 'displayName' => 'Apply profile to items ' . $from . ' to ' . $to, 'profile_id' => $profile_id, 'offset' => $page * $batch_size, 'limit' => $batch_size);
             }
             // build response
             $response = new stdClass();
             $response->tasklist = $tasks;
             $response->total_tasks = count($tasks);
             $response->error = '';
             $response->success = true;
             // create new job
             $newJob = new stdClass();
             $newJob->jobname = $jobname;
             $newJob->tasklist = $tasks;
             $job = new JobsModel($newJob);
             $response->job_key = $job->key;
             $this->returnJSON($response);
             exit;
         default:
             // echo "unknown job";
             // break;
     }
     // exit();
 }