[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/ -> batch_print.php (source)

   1  <?php
   2  
   3    require ('includes/application_top.php');
   4    $pageloop = "0";
   5    if ($HTTP_GET_VARS['mkey']) {
   6  
   7      $key = $HTTP_GET_VARS['mkey']; 
   8      $message = $error[$key]; 
   9      $HTTP_GET_VARS['act'] = 0; 
  10  
  11    }
  12  
  13    if ($HTTP_GET_VARS['act'] == '') { $HTTP_GET_VARS['act'] = 0; }
  14  
  15    if (strlen($HTTP_GET_VARS['act']) == 1 && is_numeric($HTTP_GET_VARS['act']))
  16      {
  17  
  18      switch ($HTTP_GET_VARS['act']) {
  19  
  20        case 1:
  21  
  22          // check if invoice number is a empty field .. if its not empty do this ..

  23          // if it is empty skip down to the check date entered code.

  24          if ($invoicenumbers != '') {
  25  
  26            if (!isset($HTTP_POST_VARS['invoicenumbers'])) { message_handler('ERROR_BAD_INVOICENUMBERS');  }
  27            if (!is_writeable(BATCH_PDF_DIR)) { message_handler('SET_PERMISSIONS'); }
  28            $time0   = time();
  29            $invoicenumbers = tep_db_prepare_input($HTTP_POST_VARS['invoicenumbers']);
  30            $arr_no = explode(',',$invoicenumbers);
  31            foreach ($arr_no as $key=>$value) {
  32              $arr_no[$key]=trim($value);
  33              if (substr_count($arr_no[$key],'-')>0) {
  34                $temp_range=explode('-',$arr_no[$key]);
  35                $arr_no[$key]=implode(',',range((int) $temp_range[0], (int) $temp_range[1]));
  36              }
  37            }
  38            $invoicenumbers=implode(',',$arr_no);
  39  
  40          } else {
  41  
  42  
  43    // CHECK DATE ENTERED, GRAB ALL ORDERS FROM THAT DATE, AND CREATE PDF FOR ORDERS

  44            if (!isset($HTTP_POST_VARS['startdate'])) { message_handler(); }
  45            if ((strlen($HTTP_POST_VARS['startdate']) != 10) || verify_start_date($HTTP_POST_VARS['startdate'])) { message_handler('ERROR_BAD_DATE'); }
  46            if (!is_writeable(BATCH_PDF_DIR)) { message_handler('SET_PERMISSIONS'); }
  47            $time0   = time();
  48            $startdate = tep_db_prepare_input($HTTP_POST_VARS['startdate']);
  49  
  50            if (!isset($HTTP_POST_VARS['enddate'])) { message_handler(); }
  51            if ((strlen($HTTP_POST_VARS['enddate']) != 10) || verify_end_date($HTTP_POST_VARS['enddate'])) { message_handler('ERROR_BAD_DATE'); }
  52            if (!is_writeable(BATCH_PDF_DIR)) { message_handler('SET_PERMISSIONS'); }
  53            $time0   = time();
  54            $enddate = tep_db_prepare_input($HTTP_POST_VARS['enddate']);
  55          }
  56  
  57          require (DIR_WS_CLASSES . 'currencies.php');
  58          require(BATCH_PRINT_INC . 'class.ezpdf.php');
  59          require (DIR_WS_CLASSES . 'order.php');
  60  
  61  
  62          //grab only the page size and layout from template

  63          require(BATCH_PRINT_INC . 'templates/' . $HTTP_POST_VARS['file_type']);
  64          $pageloop = "1";
  65          //$pdf = new Cezpdf($HTTP_POST_VARS['page'],$HTTP_POST_VARS['orientation']);

  66  
  67  
  68  
  69          if ($HTTP_POST_VARS['show_comments']) { $get_customer_comments = ' and h.orders_status_id = ' . DEFAULT_ORDERS_STATUS_ID; }
  70          if ($HTTP_POST_VARS['pull_status']){ $pull_w_status = " and o.orders_status = ". $HTTP_POST_VARS['pull_status']; }
  71  
  72  
  73          // if there is a invoice number use first order query otherwise use second date style order query

  74          if ($invoicenumbers != '') {
  75            $orders_query = tep_db_query("select o.orders_id,o.orders_prefix,h.comments,MIN(h.date_added) from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_STATUS_HISTORY . " h where o.orders_id in (" . tep_db_input($invoicenumbers) . ") and h.orders_id = o.orders_id" . $pull_w_status . $get_customer_comments . ' group by o.orders_id');
  76          } else {  
  77            $orders_query = tep_db_query("select o.orders_id,o.orders_prefix,h.comments,MIN(h.date_added) from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_STATUS_HISTORY . " h where o.date_purchased between '" . tep_db_input($startdate) . "' and '" . tep_db_input($enddate) . " 23:59:59'  and h.orders_id = o.orders_id" . $pull_w_status . $get_customer_comments . ' group by o.orders_id');
  78          }
  79   
  80   
  81          if (!tep_db_num_rows($orders_query) > 0) { message_handler('NO_ORDERS'); }
  82          $num = 0;
  83   
  84          while ($orders = tep_db_fetch_array($orders_query)) {
  85  
  86            $order = new order($orders['orders_id']);
  87    
  88            if ($num != 0) { $pdf->EzNewPage(); }
  89  
  90  
  91    // start of pdf layout ..   ################################

  92  
  93            require(BATCH_PRINT_INC . 'templates/' . $HTTP_POST_VARS['file_type']);
  94  
  95    // end pdf layout section     ###############################

  96  
  97            if ($HTTP_POST_VARS['status'] && ($HTTP_POST_VARS['status'] != $order->info['orders_status'])){
  98              $customer_notified = 0; 
  99              $status = tep_db_prepare_input($HTTP_POST_VARS['status']);
 100              $notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, BATCH_COMMENTS) . "\n\n";
 101  
 102              if ($HTTP_POST_VARS['notify']) {
 103                $status_query = tep_db_query("select orders_status_name as name from " . TABLE_ORDERS_STATUS . " where language_id = '" . $languages_id . "' and orders_status_id = " . tep_db_input($status));
 104                $status_name = tep_db_fetch_array($status_query);
 105  
 106                $email = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $orders['orders_id'] . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'], 'SSL') . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($order->info['date_purchased']) . "\n\n" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $status_name['name']);
 107                tep_mail($order->customer['name'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, nl2br($email), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 108                          $customer_notified = '1';
 109              }
 110  
 111              tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . tep_db_input($status) . "', last_modified = now() where orders_id = '" . $orders['orders_id'] . "'");
 112              tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) 
 113              values ('" . $orders['orders_id'] . "', '" . tep_db_input($status) . "', now(), '" . $customer_notified . "', '" . $notify_comments  . "')");
 114            }
 115            $num++;
 116            // Send fake header to avoid timeout, got this trick from phpMyAdmin

 117            $time1  = time();
 118            if ($time1 >= $time0 + 30) {
 119              $time0 = $time1;
 120              header('X-bpPing: Pong');
 121            }
 122          }// EOWHILE

 123  
 124          $pdf_code = $pdf->output();
 125  
 126          $fname = BATCH_PDF_DIR . BATCH_PDF_FILE;
 127          if ($fp = fopen($fname,'w')) {
 128            fwrite($fp,$pdf_code);
 129            fclose($fp);
 130          } else { message_handler('FAILED_TO_OPEN'); }
 131          // changed below to cause pdf to open in a new window 

 132          $message =  'A PDF of ' . $num . ' record(s) was successful! 
 133          <a href="'.$fname.'" target="_blank"><b>Click here</b></a> to download the order file.';
 134  
 135        case 0:
 136  
 137          require(BATCH_PRINT_INC . 'batch_print_header.php');
 138          require(BATCH_PRINT_INC . 'batch_print_body.php');
 139          require(BATCH_PRINT_INC . 'batch_print_footer.php');
 140          break;
 141  
 142        default:
 143  
 144          message_handler();
 145  
 146        }//EOSWITCH

 147  
 148  
 149      } else {
 150  
 151        message_handler('ERROR_INVALID_INPUT');
 152  
 153      }
 154  
 155      // FUNCTION AREA

 156      function message_handler($message=''){
 157  
 158        if ($message) {
 159          header("Location: " . tep_href_link(BATCH_PRINT_FILE, 'mkey=' . $message));
 160        } else {
 161          header("Location: " . tep_href_link(BATCH_PRINT_FILE));
 162        }
 163        exit(0);
 164      }
 165  
 166      function change_color($color) {
 167        global $pdf;
 168  
 169        list($r,$g,$b) = explode(',', $color);
 170        $pdf->setColor($r,$g,$b);
 171      }
 172  
 173      function verify_start_date($startdate) {
 174        $error = 0;
 175        list($year,$month,$day) = explode('-', $startdate);
 176  
 177        if ((strlen($year) != 4) || !is_numeric($year)) {
 178          $error++;
 179        }
 180        if ((strlen($month) != 2) || !is_numeric($month)) {
 181          $error++;
 182        }
 183        if ((strlen($day) != 2) || !is_numeric($day)) {
 184          $error++;
 185        }
 186      return $error;
 187      }
 188  
 189  
 190      function verify_end_date($enddate) {
 191        $error = 0;
 192        list($year,$month,$day) = explode('-', $enddate);
 193  
 194        if ((strlen($year) != 4) || !is_numeric($year)) {
 195          $error++;
 196        }
 197        if ((strlen($month) != 2) || !is_numeric($month)) {
 198          $error++;
 199        }
 200        if ((strlen($day) != 2) || !is_numeric($day)) {
 201          $error++;
 202        }
 203        return $error;
 204      }
 205  
 206  
 207      function print_address($x, $y, $nums){
 208      global $pdf, $num, $billing;
 209      $pos = $y;
 210      global $orders_query;
 211      global $order;
 212      global $orders;
 213      global $languages_id;
 214      global $HTTP_POST_VARS;
 215      if ($order){
 216        if ($billing == true)
 217          $addressparts = explode("\n", tep_address_format($order->billing['format_id'], $order->billing, 1, '', " \n"));
 218        else
 219          $addressparts = explode("\n", tep_address_format($order->delivery['format_id'], $order->delivery, 1, '', " \n"));
 220        foreach($addressparts as $addresspart){
 221          $fontsize = GENERAL_FONT_SIZE;
 222          while ($pdf->getTextWidth($fontsize, $addresspart) > LABEL_WIDTH){
 223            $fontsize--;
 224          }
 225          //$addresspart = preg_replace("%,[[:space:]]*$%", "", $addresspart);

 226          $pdf->addText($x,$pos -=GENERAL_LINE_SPACING,$fontsize,$addresspart);
 227        }
 228        $pdf->addText($x + LABEL_WIDTH - ORDERIDXOFFSET - 22,$y + ORDERIDYOFFSET,ORDERIDFONTSIZE,$orders['orders_id']);
 229  
 230        if ($HTTP_POST_VARS['status'] && ($HTTP_POST_VARS['status'] != $order->info['orders_status'])){
 231          $customer_notified = 0; 
 232          $status = tep_db_prepare_input($HTTP_POST_VARS['status']);
 233          $notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, BATCH_COMMENTS) . "\n\n";
 234  
 235          if ($HTTP_POST_VARS['notify']) {
 236            $status_query = tep_db_query("select orders_status_name as name from " . TABLE_ORDERS_STATUS . " where language_id = " . $languages_id . " and orders_status_id = " . tep_db_input($status));
 237            $status_name = tep_db_fetch_array($status_query);
 238  
 239            $email = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $orders['orders_id'] . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($order->info['date_purchased']) . "\n\n" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $status_name['name']);
 240            tep_mail($order->customer['name'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, nl2br($email), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 241            $customer_notified = '1';
 242          }
 243  
 244          tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . tep_db_input($status) . "', last_modified = now() where orders_id = '" . $orders['orders_id'] . "'");
 245          tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) 
 246          values ('" . $orders['orders_id'] . "', '" . tep_db_input($status) . "', now(), '" . $customer_notified . "', '" . $notify_comments  . "')");
 247        }
 248  
 249        if(($nums % NUM_LABELS_PER_PAGE) == (NUM_LABELS_PER_PAGE-1))
 250        {
 251          $order = false;
 252          return false;
 253        } else {
 254          if($orders = tep_db_fetch_array($orders_query)) {
 255            $order = new order($orders['orders_id']);
 256            return true;
 257          } else {
 258            $order = false;
 259            return false;
 260          }
 261        }
 262  
 263      } else {
 264        return false;
 265      }
 266    }
 267  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7