예제 #1
0
파일: wpi_ui.php 프로젝트: JSpier/smacamp
 /**
  * Does our preprocessing for the manage invoice page, adds our meta boxes, and checks invoice data
  *
  * @since 3.0
  */
 static function page_manage_invoice_preprocess($screen_id)
 {
     global $wpi_settings, $this_invoice, $wpdb;
     // Check if invoice_id already exists
     $invoice_id_exists = false;
     if (!empty($_REQUEST['wpi'])) {
         if (!empty($_REQUEST['wpi']['new_invoice'])) {
             if (wpi_check_invoice($_REQUEST['wpi']['new_invoice']['invoice_id'])) {
                 $invoice_id_exists = true;
             }
         }
         if (!empty($_REQUEST['wpi']['existing_invoice'])) {
             if (wpi_check_invoice($_REQUEST['wpi']['existing_invoice']['invoice_id'])) {
                 $invoice_id_exists = true;
             }
         }
     }
     if ($invoice_id_exists) {
         // Select status of invoice from DB
         $status = $wpdb->get_var("SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = '{$_REQUEST['wpi']['existing_invoice']['invoice_id']}' AND meta_key = 'status'");
     }
     // New Invoice
     if (isset($_REQUEST['wpi']['new_invoice']) && empty($invoice_id_exists)) {
         $this_invoice = new WPI_Invoice();
         $this_invoice->create_new_invoice("invoice_id={$_REQUEST['wpi']['new_invoice']['invoice_id']}");
         // If we are copying from a template
         if (!empty($_REQUEST['wpi']['new_invoice']['template_copy'])) {
             $this_invoice->load_template("id={$_REQUEST['wpi']['new_invoice']['template_copy']}");
         }
         // Set user and determine type
         $this_invoice->load_user("email={$_REQUEST['wpi']['new_invoice']['user_email']}");
         // Add custom data if user doesn't exist.
         if (empty($this_invoice->data['user_data'])) {
             $this_invoice->data['user_data'] = array('user_email' => $_REQUEST['wpi']['new_invoice']['user_email']);
         }
         $new_invoice = true;
         // Enter in GET values
         if (isset($_GET['prefill']['subject'])) {
             $this_invoice->data['subject'] = $_GET['prefill']['subject'];
         }
         if (!empty($_GET['prefill']['is_quote']) && $_GET['prefill']['is_quote'] == 'true') {
             $this_invoice->data['is_quote'] = true;
             $this_invoice->data['status'] = "quote";
         }
     } else {
         if (!empty($invoice_id_exists)) {
             // Existing Invoice
             $this_invoice = new WPI_Invoice();
             if (isset($_REQUEST['wpi']['existing_invoice']['invoice_id'])) {
                 $ID = $_REQUEST['wpi']['existing_invoice']['invoice_id'];
             } else {
                 if (isset($_REQUEST['wpi']['new_invoice']['invoice_id'])) {
                     $ID = $_REQUEST['wpi']['new_invoice']['invoice_id'];
                 }
             }
             $this_invoice->load_invoice("id={$ID}");
         }
     }
     add_meta_box('postbox_payment_methods', __('Payment Settings', WPI), 'postbox_payment_methods', $screen_id, 'normal', 'high');
     if (is_object($this_invoice) && isset($this_invoice->data['type']) && $this_invoice->data['type'] == 'single_payment') {
         add_meta_box('postbox_overview', __('Overview', WPI), 'postbox_overview', $screen_id, 'side', 'high');
     } else {
         add_meta_box('postbox_publish', __('Publish', WPI), 'postbox_publish', $screen_id, 'side', 'high');
     }
     add_meta_box('postbox_user_existing', __('User Information', WPI), 'postbox_user_existing', $screen_id, 'side', 'low');
 }