/**
  * recalculate_price_filter_products_prices.
  *
  * @version 2.5.6
  * @since   2.5.6
  */
 function recalculate_price_filter_products_prices()
 {
     if (isset($_GET['recalculate_price_filter_products_prices']) && (wcj_is_user_role('administrator') || is_shop_manager())) {
         wcj_update_products_price_by_country();
         global $wcj_notice;
         $wcj_notice = __('Price filter widget product prices recalculated.', 'woocommerce-jetpack');
     }
 }
 /**
  * generate_report_zip.
  *
  * @version 2.3.10
  * @since   2.3.10
  */
 function generate_report_zip()
 {
     if (isset($_POST['get_invoices_report_zip'])) {
         if (!empty($_POST['report_year']) && !empty($_POST['report_month']) && !empty($_POST['invoice_type'])) {
             if (is_super_admin() || is_shop_manager()) {
                 if (false === $this->get_invoices_report_zip($_POST['report_year'], $_POST['report_month'], $_POST['invoice_type'])) {
                     $this->notice = '<div class="error"><p><strong>' . __('Sorry, but something went wrong...', 'woocommerce-jetpack') . '</strong></p></div>';
                 }
             }
         } else {
             $this->notice = '<div class="error"><p><strong>' . __('Please fill year and month values.', 'woocommerce-jetpack') . '</strong></p></div>';
         }
     }
 }
 /**
  * add_eu_countries_vat_rates.
  *
  * @version 2.3.10
  * @since   2.3.10
  */
 function add_eu_countries_vat_rates()
 {
     if (!isset($_POST['add_eu_countries_vat_rates'])) {
         return;
     }
     if (!is_super_admin() && !is_shop_manager()) {
         return;
     }
     $loop = 0;
     foreach (wcj_get_european_union_countries_with_vat() as $country => $rate) {
         $tax_rate = array('tax_rate_country' => $country, 'tax_rate' => $rate, 'tax_rate_name' => isset($_POST['wcj_tax_name']) ? $_POST['wcj_tax_name'] : __('VAT', 'woocommerce'), 'tax_rate_priority' => 1, 'tax_rate_compound' => 0, 'tax_rate_shipping' => 1, 'tax_rate_order' => $loop++, 'tax_rate_class' => '');
         $tax_rate_id = WC_Tax::_insert_tax_rate($tax_rate);
         WC_Tax::_update_tax_rate_postcodes($tax_rate_id, '');
         WC_Tax::_update_tax_rate_cities($tax_rate_id, '');
     }
 }
 /**
  * handle_downloads.
  *
  * @version 2.2.2
  * @since   2.2.2
  */
 public function handle_downloads()
 {
     if (isset($_GET['wcj_download_file'])) {
         $file_name = $_GET['wcj_download_file'];
         $upload_dir = wcj_get_wcj_uploads_dir('input_fields_uploads');
         $file_path = $upload_dir . '/' . $file_name;
         if (is_super_admin() || is_shop_manager()) {
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: private", false);
             header('Content-disposition: attachment; filename=' . $file_name);
             header("Content-Transfer-Encoding: binary");
             header("Content-Length: " . filesize($file_path));
             readfile($file_path);
             exit;
         }
     }
 }
 /**
  * generate_report_zip.
  *
  * @version 2.5.0
  * @since   2.3.10
  */
 function generate_report_zip()
 {
     if (isset($_POST['get_invoices_report_zip'])) {
         if (wcj_is_module_enabled('general') && 'yes' === get_option('wcj_general_advanced_disable_save_sys_temp_dir', 'no')) {
             $this->notice = '<div class="error"><p><strong>' . __('This option is disabled in WooCommerce > Settings > Booster > Emails & Misc. > General > Advanced Options > Disable Saving PDFs in PHP directory for temporary files', 'woocommerce-jetpack') . '</strong></p></div>';
         } else {
             if (!empty($_POST['report_year']) && !empty($_POST['report_month']) && !empty($_POST['invoice_type'])) {
                 if (wcj_is_user_role('administrator') || is_shop_manager()) {
                     if (false === $this->get_invoices_report_zip($_POST['report_year'], $_POST['report_month'], $_POST['invoice_type'])) {
                         $this->notice = '<div class="error"><p><strong>' . __('Sorry, but something went wrong...', 'woocommerce-jetpack') . '</strong></p></div>';
                     }
                 }
             } else {
                 $this->notice = '<div class="error"><p><strong>' . __('Please fill year and month values.', 'woocommerce-jetpack') . '</strong></p></div>';
             }
         }
     }
 }
 }
 /**
  * generate_pdf_on_init.
  */
 function generate_pdf_on_init()
 {
     // Check if all is OK
     if (true !== $this->get_invoice || 0 == $this->order_id || !is_user_logged_in() || !current_user_can('administrator') && !is_shop_manager() && get_current_user_id() != intval(get_post_meta($this->order_id, '_customer_user', true))) {
         return;
     }
     $the_invoice = wcj_get_pdf_invoice($this->order_id, $this->invoice_type_id);
     //		$invoice = new WCJ_PDF_Invoice();
     $dest = true === $this->save_as_pdf ? 'D' : 'I';
     //		$invoice->get_pdf( $this->order_id, $this->invoice_type_id, '', $dest );//, $this->invoice_type_id );
     $the_invoice->get_pdf($dest);
     //		echo $invoice_html;
 /**
  * process_checkout_files_upload.
  *
  * @version 2.5.0
  * @since   2.4.5
  */
 function process_checkout_files_upload()
 {
     if (!session_id()) {
         session_start();
     }
     // Remove file
     $total_number = apply_filters('booster_get_option', 1, get_option('wcj_checkout_files_upload_total_number', 1));
     for ($i = 1; $i <= $total_number; $i++) {
         if (isset($_POST['wcj_remove_checkout_file_' . $i])) {
             if (isset($_POST['wcj_checkout_files_upload_order_id_' . $i])) {
                 $order_id = $_POST['wcj_checkout_files_upload_order_id_' . $i];
                 $order_file_name = get_post_meta($order_id, '_' . 'wcj_checkout_files_upload_' . $i, true);
                 if ('' != $order_file_name) {
                     $file_path = wcj_get_wcj_uploads_dir('checkout_files_upload') . '/' . $order_file_name;
                     unlink($file_path);
                     $file_name = get_post_meta($order_id, '_' . 'wcj_checkout_files_upload_real_name_' . $i, true);
                     wc_add_notice(sprintf(get_option('wcj_checkout_files_upload_notice_success_remove_' . $i, __('File "%s" was successfully removed.', 'woocommerce-jetpack')), $file_name));
                     delete_post_meta($order_id, '_' . 'wcj_checkout_files_upload_' . $i);
                     delete_post_meta($order_id, '_' . 'wcj_checkout_files_upload_real_name_' . $i);
                 }
             } else {
                 $file_name = 'wcj_checkout_files_upload_' . $i;
                 unlink($_SESSION[$file_name]['tmp_name']);
                 wc_add_notice(sprintf(get_option('wcj_checkout_files_upload_notice_success_remove_' . $i, __('File "%s" was successfully removed.', 'woocommerce-jetpack')), $_SESSION[$file_name]['name']));
                 unset($_SESSION[$file_name]);
             }
         }
     }
     // Upload file
     for ($i = 1; $i <= $total_number; $i++) {
         if (isset($_POST['wcj_upload_checkout_file_' . $i])) {
             $file_name = 'wcj_checkout_files_upload_' . $i;
             if (isset($_FILES[$file_name]) && '' != $_FILES[$file_name]['tmp_name']) {
                 // Validate
                 $is_valid = true;
                 if ('' != ($file_accept = get_option('wcj_checkout_files_upload_file_accept_' . $i, '')) && isset($_FILES[$file_name])) {
                     // Validate file type
                     $file_accept = explode(',', $file_accept);
                     if (is_array($file_accept) && !empty($file_accept)) {
                         $real_file_name = $_FILES[$file_name]['name'];
                         $file_type = '.' . pathinfo($real_file_name, PATHINFO_EXTENSION);
                         if (!in_array($file_type, $file_accept)) {
                             wc_add_notice(sprintf(get_option('wcj_checkout_files_upload_notice_wrong_file_type_' . $i, __('Wrong file type: "%s"!', 'woocommerce-jetpack')), $real_file_name), 'error');
                             $is_valid = false;
                         }
                     }
                 }
                 if ($is_valid) {
                     // To session
                     $_SESSION[$file_name] = $_FILES[$file_name];
                     $tmp_dest_file = tempnam(sys_get_temp_dir(), 'wcj');
                     move_uploaded_file($_SESSION[$file_name]['tmp_name'], $tmp_dest_file);
                     $_SESSION[$file_name]['tmp_name'] = $tmp_dest_file;
                     wc_add_notice(sprintf(get_option('wcj_checkout_files_upload_notice_success_upload_' . $i, __('File "%s" was successfully uploaded.', 'woocommerce-jetpack')), $_SESSION[$file_name]['name']));
                     // To order
                     if (isset($_POST['wcj_checkout_files_upload_order_id_' . $i])) {
                         $this->add_files_to_order($_POST['wcj_checkout_files_upload_order_id_' . $i], null);
                     }
                 }
             } else {
                 wc_add_notice(get_option('wcj_checkout_files_upload_notice_upload_no_file_' . $i, __('Please select file to upload!', 'woocommerce-jetpack')), 'notice');
             }
         }
     }
     // Admin file download
     if (isset($_GET['wcj_download_checkout_file_admin'])) {
         $tmp_file_name = wcj_get_wcj_uploads_dir('checkout_files_upload') . '/' . $_GET['wcj_download_checkout_file_admin'];
         $file_name = get_post_meta($_GET['post'], '_' . 'wcj_checkout_files_upload_real_name_' . $_GET['wcj_checkout_file_number'], true);
         if (wcj_is_user_role('administrator') || is_shop_manager()) {
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: private", false);
             header('Content-disposition: attachment; filename=' . $file_name);
             header("Content-Transfer-Encoding: binary");
             header("Content-Length: " . filesize($tmp_file_name));
             readfile($tmp_file_name);
             exit;
         }
     }
     // User file download
     if (isset($_GET['wcj_download_checkout_file']) && isset($_GET['_wpnonce']) && false !== wp_verify_nonce($_GET['_wpnonce'], 'wcj_download_checkout_file')) {
         $i = $_GET['wcj_download_checkout_file'];
         if (isset($_GET['order-received']) || isset($_GET['view-order'])) {
             $order_id = isset($_GET['order-received']) ? $_GET['order-received'] : $_GET['view-order'];
             $the_order = wc_get_order($order_id);
             if (!$the_order->key_is_valid($_GET['key'])) {
                 return;
             }
             $order_file_name = get_post_meta($order_id, '_' . 'wcj_checkout_files_upload_' . $i, true);
             $tmp_file_name = wcj_get_wcj_uploads_dir('checkout_files_upload') . '/' . $order_file_name;
             $file_name = get_post_meta($order_id, '_' . 'wcj_checkout_files_upload_real_name_' . $i, true);
         } else {
             $tmp_file_name = $_SESSION['wcj_checkout_files_upload_' . $i]['tmp_name'];
             $file_name = $_SESSION['wcj_checkout_files_upload_' . $i]['name'];
         }
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Cache-Control: private", false);
         header('Content-disposition: attachment; filename=' . $file_name);
         header("Content-Transfer-Encoding: binary");
         header("Content-Length: " . filesize($tmp_file_name));
         readfile($tmp_file_name);
         exit;
     }
 }
 /**
  * generate_pdf.
  */
 public function generate_pdf($get_by_order_id = 0)
 {
     if (!isset($_GET['pdf_invoice']) && 0 == $get_by_order_id) {
         return;
     }
     $order_id = 0 == $get_by_order_id ? $_GET['pdf_invoice'] : $get_by_order_id;
     if (!is_user_logged_in() && 0 == $get_by_order_id) {
         return;
     }
     if (!current_user_can('administrator') && !is_shop_manager() && get_current_user_id() != intval(get_post_meta($order_id, '_customer_user', true)) && 0 == $get_by_order_id) {
         return;
     }
     // Include the main TCPDF library (search for installation path).
     //require_once('tcpdf_include.php');
     require_once 'lib/tcpdf_min/tcpdf.php';
     // create new PDF document
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     //$pdf->SetAuthor( 'Algoritmika Ltd.' );
     $pdf->SetTitle('Invoice');
     $pdf->SetSubject('Invoice PDF');
     $pdf->SetKeywords('invoice, PDF');
     // set default header data
     // TODO 2014.09.21
     //		$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
     //$pdf->SetHeaderData( get_option( 'wcj_pdf_invoices_seller_logo_url' ), 30, get_option( 'wcj_pdf_invoices_header_title' ), get_option( 'wcj_pdf_invoices_header_string' ), array(0,64,255), array(0,64,128));
     $pdf->SetPrintHeader(false);
     $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
     //$pdf->SetPrintFooter(false);
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     /*
     // set some language-dependent strings (optional)
     if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
     	require_once(dirname(__FILE__).'/lang/eng.php');
     	$pdf->setLanguageArray($l);
     }
     */
     // ---------------------------------------------------------
     // set default font subsetting mode
     $pdf->setFontSubsetting(true);
     // Set font
     // dejavusans is a UTF-8 Unicode font, if you only need to
     // print standard ASCII chars, you can use core fonts like
     // helvetica or times to reduce file size.
     $pdf->SetFont(apply_filters('wcj_get_option_filter', 'dejavusans', get_option('wcj_pdf_invoices_general_font_family', 'dejavusans')), '', apply_filters('wcj_get_option_filter', 8, get_option('wcj_pdf_invoices_general_font_size')), '', true);
     // Add a page
     // This method has several options, check the source code documentation for more information.
     $pdf->AddPage();
     if ('yes' === get_option('wcj_pdf_invoices_general_font_shadowed', 'yes')) {
         // set text shadow effect
         $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
     }
     $html = $this->get_invoice_html($order_id);
     // Print text using writeHTMLCell()
     $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
     // ---------------------------------------------------------
     // Close and output PDF document
     // This method has several options, check the source code documentation for more information.
     //		$the_order = new WC_Order( $order_id );
     //		$order_number = $the_order->get_order_number();
     /**/
     if ($get_by_order_id > 0) {
         return $pdf->Output('invoice-' . $order_id . '.pdf', 'S');
     } else {
         $file_name = 'invoice-' . $order_id . '.pdf';
         $file_path = sys_get_temp_dir() . '/' . $file_name;
         $result = file_put_contents($file_path, $pdf->Output('', 'S'));
         //echo $pdf->Output( '', 'S' );
         if (isset($_GET['save_pdf_invoice']) && '1' == $_GET['save_pdf_invoice']) {
             //$pdf->Output('invoice-' . $order_id . '.pdf', 'D');
             header("Content-Type: application/octet-stream");
             //$file = $file_name;//$_GET["file"] .".pdf";
             header("Content-Disposition: attachment; filename=" . urlencode($file_name));
             header("Content-Type: application/octet-stream");
             header("Content-Type: application/download");
             header("Content-Description: File Transfer");
         } else {
             //$pdf->Output('invoice-' . $order_id . '.pdf', 'I');
             header("Content-type: application/pdf");
             header("Content-Disposition: inline; filename=" . urlencode($file_name));
         }
         header("Content-Length: " . filesize($file_path));
         flush();
         // this doesn't really matter.
         if (false !== ($fp = fopen($file_path, "r"))) {
             while (!feof($fp)) {
                 echo fread($fp, 65536);
                 flush();
                 // this is essential for large downloads
             }
             fclose($fp);
         } else {
             die(__('Unexpected error', 'woocommerce-jetpack'));
         }
     }
     /**/
     /**
     
     
     		if ( $get_by_order_id > 0 )
     			return $pdf->Output('invoice-' . $order_id . '.pdf', 'S');
     		if ( isset( $_GET['save_pdf_invoice'] ) && '1' == $_GET['save_pdf_invoice'] )
     			$pdf->Output('invoice-' . $order_id . '.pdf', 'D');
     		else
     			$pdf->Output('invoice-' . $order_id . '.pdf', 'I');
     
     			/**/
 }