Example #1
0
 public function onDisplayEbayOrdersPage()
 {
     $this->check_wplister_setup();
     // handle update ALL from eBay action
     if ($this->requestAction() == 'update_orders') {
         // regard update options
         $days = is_numeric($_REQUEST['wpl_number_of_days']) ? $_REQUEST['wpl_number_of_days'] : false;
         $accounts = WPLE_eBayAccount::getAll(false, true);
         // sort by id
         $msg = '';
         // loop each active account
         $processed_accounts = array();
         foreach ($accounts as $account) {
             // make sure we don't process the same account twice
             if (in_array($account->user_name, $processed_accounts)) {
                 WPLE()->logger->info("skipping account {$account->id} - user name {$account->user_name} was already processed");
                 continue;
             }
             $this->initEC($account->id);
             $tm = $this->EC->updateEbayOrders($days);
             $this->EC->updateListings();
             $this->EC->closeEbay();
             $processed_accounts[] = $account->user_name;
             // show ebay_order report
             $msg .= sprintf(__('%s order(s) found on eBay for account %s.', 'wplister'), $tm->count_total, $account->title) . '<br>';
             $msg .= __('Timespan', 'wplister') . ': ' . $tm->getHtmlTimespan() . '&nbsp;&nbsp;';
             $msg .= '<a href="#" onclick="jQuery(\'.ebay_order_report\').toggle();return false;">' . __('show details', 'wplister') . '</a>';
             $msg .= $tm->getHtmlReport();
             $msg .= '<hr>';
         }
         $this->showMessage($msg);
     }
     // handle update from eBay action
     if ($this->requestAction() == 'update') {
         if (isset($_REQUEST['ebay_order'])) {
             // use account_id of first item (todo: group items by account)
             $om = new EbayOrdersModel();
             $order = $om->getItem($_REQUEST['ebay_order'][0]);
             $account_id = $order['account_id'];
             $this->initEC($account_id);
             $tm = $this->EC->updateEbayOrders(false, $_REQUEST['ebay_order']);
             $this->EC->updateListings();
             $this->EC->closeEbay();
             // $this->showMessage( __('Selected orders were updated from eBay.','wplister') );
             // show ebay_order report
             $msg = $tm->count_total . ' ' . __('orders were updated from eBay.', 'wplister') . '<!br>' . '&nbsp;&nbsp;';
             $msg .= '<a href="#" onclick="jQuery(\'.ebay_order_report\').toggle();return false;">' . __('show details', 'wplister') . '</a>';
             $msg .= $tm->getHtmlReport();
             $this->showMessage($msg);
         } else {
             $this->showMessage(__('You need to select at least one item from the list below in order to use bulk actions.', 'wplister'), 1);
         }
     }
     // handle wpl_delete_order action
     if ($this->requestAction() == 'wpl_delete_order') {
         if (isset($_REQUEST['ebay_order'])) {
             $tm = new EbayOrdersModel();
             $ebay_orders = is_array($_REQUEST['ebay_order']) ? $_REQUEST['ebay_order'] : array($_REQUEST['ebay_order']);
             foreach ($ebay_orders as $id) {
                 $tm->deleteItem($id);
             }
             $this->showMessage(__('Selected items were removed.', 'wplister'));
         } else {
             $this->showMessage(__('You need to select at least one item from the list below in order to use bulk actions.', 'wplister'), 1);
         }
     }
     // show warning if duplicate orders found
     $this->checkForDuplicates();
     //Create an instance of our package class...
     $ordersTable = new EbayOrdersTable();
     //Fetch, prepare, sort, and filter our data...
     $ordersTable->prepare_items();
     // load eBay classes to decode details in table
     EbayController::loadEbayClasses();
     $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'ordersTable' => $ordersTable, 'preview_html' => isset($preview_html) ? $preview_html : '', 'form_action' => 'admin.php?page=' . self::ParentMenuId . '-orders');
     $this->display('orders_page', $aData);
 }