Ejemplo n.º 1
0
 /**
  * Process actions from Main Page (List of invoices)
  *
  * @since 3.0
  */
 static function process_invoice_actions($action, $ids)
 {
     global $wpi_settings;
     //** Set status */
     switch ($action) {
         case 'trash':
             $status = 'trashed';
             break;
         case 'delete':
             $status = 'deleted';
             break;
         case 'untrash':
             $status = 'untrashed';
             break;
         case 'unarchive':
             $status = 'un-archived';
             break;
         case 'archive':
             $status = 'archived';
             break;
     }
     if (!is_array($ids)) {
         $ids = explode(',', $ids);
     }
     //** Process action */
     $invoice_ids = array();
     foreach ((array) $ids as $ID) {
         //** Perfom action */
         $this_invoice = new WPI_Invoice();
         $this_invoice->load_invoice("id={$ID}");
         $invoice_id = $this_invoice->data['invoice_id'];
         switch ($action) {
             case 'trash':
                 if ($this_invoice->trash()) {
                     $invoice_ids[] = $invoice_id;
                 }
                 break;
             case 'delete':
                 if ($this_invoice->delete()) {
                     $invoice_ids[] = $invoice_id;
                 }
                 break;
             case 'untrash':
                 if ($this_invoice->untrash()) {
                     $invoice_ids[] = $invoice_id;
                 }
                 break;
             case 'unarchive':
                 if ($this_invoice->unarchive()) {
                     $invoice_ids[] = $invoice_id;
                 }
                 break;
             case 'archive':
                 if ($this_invoice->archive()) {
                     $invoice_ids[] = $invoice_id;
                 }
                 break;
         }
     }
     if (!empty($status) && $status) {
         //** Get Referer and clean it up */
         $sendback = wp_get_referer();
         $sendback = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'invoice_id, unarchived, archived'), $sendback);
         //** Determine if reffer is not main page, we set it ( anyway, will do redirect to main page ) */
         if (!strpos($sendback, $wpi_settings['links']['overview_page'])) {
             $sendback = $wpi_settings['links']['overview_page'];
         }
         wp_redirect(add_query_arg(array($status => 1, 'invoice_id' => implode(',', $invoice_ids)), $sendback));
         die;
     }
 }
Ejemplo n.º 2
0
 /**
  * Handle Bulk Action's request
  *
  */
 public function process_bulk_action()
 {
     $action = $this->current_action();
     $status = false;
     //** Set status */
     switch ($action) {
         case 'trash':
             $status = 'trashed';
             break;
         case 'delete':
             $status = 'deleted';
             break;
         case 'untrash':
             $status = 'restored';
             break;
         case 'unarchive':
             $status = 'un-archived';
             break;
         case 'archive':
             $status = 'archived';
             break;
     }
     $invoice_ids = array();
     if (!empty($_REQUEST['post_ids'])) {
         foreach ((array) $_REQUEST['post_ids'] as $ID) {
             $this_invoice = new WPI_Invoice();
             $this_invoice->load_invoice("id={$ID}");
             $invoice_id = $this_invoice->data['invoice_id'];
             switch ($action) {
                 case 'trash':
                     if ($this_invoice->trash()) {
                         $invoice_ids[] = $invoice_id;
                     }
                     break;
                 case 'delete':
                     if ($this_invoice->delete()) {
                         $invoice_ids[] = $invoice_id;
                     }
                     break;
                 case 'untrash':
                     if ($this_invoice->untrash()) {
                         $invoice_ids[] = $invoice_id;
                     }
                     break;
                 case 'unarchive':
                     if ($this_invoice->unarchive()) {
                         $invoice_ids[] = $invoice_id;
                     }
                     break;
                 case 'archive':
                     if ($this_invoice->archive()) {
                         $invoice_ids[] = $invoice_id;
                     }
                     break;
             }
         }
     }
     if ($status) {
         $this->message = 'Successfully ' . $status;
     }
 }