$params['sender_address'] = array('first_name' => $line[5], 'last_name' => $line[6], 'post_code' => $line[7], 'town' => $line[8], 'street' => $line[9]);
     }
     if ($num >= 11) {
         $params['sender_address']['company_name'] = $line[10];
     }
     if ($num >= 12) {
         $params['sender_address']['building_number'] = $line[11];
     }
     if ($num == 13) {
         $params['sender_address']['flat_number'] = $line[12];
     }
     //echo print_r($params) . '<br>';
     $ret = new RestApi($params);
     $info_arr = $ret->getInfo();
     if ($info_arr['http_code'] != 201) {
         $err = $ret->getResponse();
         $message[] = "Parcel Create failed for line {$row} <br>Error Code: " . $info_arr["http_code"] . " " . $err;
         $error_rows++;
         $row++;
         continue;
     }
     $response = json_decode($ret->getResponse());
     $parcel_id = $response->id;
     // Add the parcel to the log table.
     $params['parcel_id'] = $parcel_id;
     add_parcel($params, $num);
     $processed_rows++;
     $row++;
 }
 fclose($file);
 // Set up the message to tell the user various statistics.
function print_many_labels(&$params, &$parcels, $username)
{
    require "config.php";
    $return = array();
    $zipname = "test_" . $username . '_' . session_id() . ".zip";
    $zip = new ZipArchive();
    $res = $zip->open($zipname, ZipArchive::CREATE);
    if ($res === TRUE) {
        $timestamp = date('dmy_His', time());
        foreach ($parcels as $key => $parcel) {
            $params['url'] = $base_url . 'reverselogistics/' . $parcel . '/label.json';
            //echo json_encode($params);
            $restApi2 = new RestApi($params);
            $file_name = "InPost_Return_Label" . $timestamp . $key . ".pdf";
            $pdf = $restApi2->getResponse();
            $info = $restApi2->getInfo();
            if ($info['http_code'] != 200) {
                $_SESSION['error_message'] = 'Failed to create your labels ' . $info["http_code"];
                continue;
            }
            $binary = base64_decode($pdf);
            // Add to the list of parcels that need their status
            // updated.
            $return[] = $parcel;
            // Add the PDF to the main ZIP file.
            $zip->addFromString($file_name, $binary);
        }
        $zip->close();
    } else {
        $_SESSION['error_message'] = 'Failed to create ZIP file for your labels.';
        header("Location: r_orders.php");
        return $return;
    }
    return $return;
}
$params['params']['date_before'] = date('Y-m-d');
$params['params']['date_after'] = date('Y-m-d');
$rest_api = new RestApi($params);
$reply = $rest_api->getResponse();
$returns_today = json_decode($reply);
// Get the count for the previous month
$params['params']['date_after'] = date('Y-m-d', mktime(0, 0, 0, date('m') - 1, date('d'), date('Y')));
$params['params']['date_before'] = date('Y-m-d');
$rest_api = new RestApi($params);
$reply = $rest_api->getResponse();
$returns_month = json_decode($reply);
// Get the count for the previous year
$params['params']['date_after'] = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y') - 1));
$params['params']['date_before'] = date('Y-m-d');
$rest_api = new RestApi($params);
$reply = $rest_api->getResponse();
$returns_year = json_decode($reply);
?>
<!DOCTYPE HTML>
<html>
<head profile="http://www.w3.org/2005/10/profile">
<link rel="icon" type="image/png" href="images/favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="author" content="InPost UK Ltd">
<meta name="dcterms.rightsHolder" content="InPost UK Ltd">
<meta name="dcterms.dateCopyrighted" content="2014">
<title>InPost 24/7 - User Portal</title>
<link rel="stylesheet" type="text/css" href="css/main_ss.css">
   
</head>
<body>
// Get the ID of the latest inserted row.
$new_id = tep_db_insert_id();
// create the parcel
$params = array('url' => $base_url . 'parcels', 'token' => $api_key, 'methodType' => 'POST', 'params' => array('description' => $refe, 'receiver' => array('phone' => $mobile, 'email' => $email), 'size' => $size, 'tmp_id' => $temp_parcel_id, 'target_machine' => $locker));
$restApi1 = new RestApi($params);
//echo '<pre>';
//print_r($restApi1->getInfo());
//echo '</pre><br>';
//echo '<pre>';
//print_r($restApi1->getResponse());
//echo '</pre>';
//returned header info
$info_arr1 = $restApi1->getInfo();
//if parcel creation successful
if ($info_arr1["http_code"] == 201) {
    $response = json_decode($restApi1->getResponse());
    $parcel_id = $response->id;
    //pay for the parcel
    $restApi2 = new RestApi(array('url' => $base_url . 'parcels/' . $parcel_id . '/pay', 'token' => $api_key, 'methodType' => 'POST', 'params' => array()));
    //returned header info
    $info_arr2 = $restApi2->getInfo();
    // if payment successful
    if ($info_arr2["http_code"] == 204) {
        //update payment status in db
        $creation_date = date('Y-m-d H:i:s');
        $query = tep_db_query("UPDATE " . $table_prefix . $parcel_table . " SET status='PAID', rl_code='{$rl_code}', parcel_id='{$parcel_id}', creation_date='{$creation_date}' WHERE id={$new_id}");
        echo "<td><div style='text-align: center'>CREATED & PAID</div></td>";
        echo "<td><div style='text-align: center'>NONE</div></td>";
        //header("Location: u_orders.php");
    } else {
        //if not, display the error code, error description
 if ($num >= 15) {
     $params['params']['additional_description_2'] = $line[14];
 }
 if ($num >= 16) {
     $params['params']['additional_description_3'] = $line[15];
 }
 if ($num == 17) {
     $params['params']['company_name'] = $line[16];
 }
 if ($num == 18) {
     $params['params']['address']['flat_number'] = $line[17];
 }
 //echo print_r($params) . '<br>';
 $ret = new RestApi($params);
 $info_arr = $ret->getInfo();
 $response = $ret->getResponse();
 if ($info_arr['http_code'] != 200) {
     $message[] = "Parcel Create failed for line {$row} <br>Error Code: " . $info_arr["http_code"] . " " . $response;
     $error_rows++;
     $row++;
     continue;
 }
 $response = json_decode($response, true);
 //echo "Response = " . print_r($response) . '<br>';
 //echo "<br>info = " . print_r($info_arr) . '<br>';
 $ex_date = $response['expire_at'];
 $exp_date = substr($ex_date, 0, 10);
 //extract expiry date
 if (array_key_exists("is_active", $response)) {
     $return_code = $response['code'];
     if ($response['is_active'] == '1') {
}
//echo $count;
if (count($to_print_array) == 0) {
    // Simply return. We have no labels to print
    header('Location: c_orders.php');
    return;
}
$parcels_st = implode(";", $to_print_array);
//echo $parcels_st;
// Get the user's label format
$ret = tep_db_query("SELECT label_format from " . $table_prefix . "users where username='******'");
$result = tep_db_fetch_array($ret);
$label_format = $result['label_format'];
$dispatch_date = date('Y-m-d H:i:s');
foreach ($parcels as $pid) {
    $query = tep_db_query("UPDATE imported_orders SET status='DISPATCHED', dispatch_date='{$dispatch_date}' WHERE parcel_id='{$pid}' AND perm_token='{$api_key}'");
}
//retrieve stickers
$restApi = new RestApi(array('url' => $base_url . 'stickers/' . $parcels_st, 'token' => $api_key, 'methodType' => 'GET', 'params' => array('format' => $label_format, 'type' => 'normal')));
date_default_timezone_set('Europe/London');
$timestamp = date('dmy_His', time());
if ($label_format == 'Pdf') {
    $file_name = "InPost_Labels_" . $timestamp . ".pdf";
} else {
    $file_name = "InPost_Labels_" . $timestamp . ".epl";
}
$pdf = $restApi->getResponse();
$binary = base64_decode($pdf);
header('Content-type: application/pdf');
header("Content-Disposition:attachment; filename={$file_name}");
echo $binary;
<div class="wrapper">
<?php 
include_once 'includes/menu.php';
?>

<div align="center" style="position: relative; top:75px; margin-left:auto; margin-right:auto;">

<?php 
//Generate an active return code
$params = array('url' => $base_url . 'reverselogistics.json', 'token' => $api_key, 'methodType' => 'POST', 'params' => array('rma' => $rma_code, 'parcel_size' => $size, 'expire_at' => $expiry_date, 'sender_phone' => $mobile, 'sender_email' => $email, 'with_label' => 'TRUE', 'additional_description_1' => $add_desc1, 'additional_description_2' => $add_desc2, 'additional_description_3' => $add_desc3, 'address' => array('first_name' => $fname, 'last_name' => $lname, 'company_name' => $cname, 'post_code' => $postcode, 'town' => $town, 'street' => $street, 'building_number' => $building, 'flat_number' => '', 'province' => $county, 'phone' => $rmobile)));
//echo 'sent paramsters ' . json_encode($params) . '<br>';
$restApi = new RestApi($params);
$request = $restApi->getInfo();
//echo 'request ' . print_r($request) . '<br>';
$response = json_decode($restApi->getResponse(), true);
$info_arr = $restApi->getInfo();
//echo '<pre>';
//echo '<br>response ' . print_r($response);
//echo '</pre>';
//echo '<pre>';
//echo '<br>info_arr ' . print_r($info_arr);
//echo '</pre>';
//echo 'getErrno ' . $restApi->getErrno() . '<br>';
//echo 'getError ' . $restApi->getError() . '<br>';
if ($info_arr["http_code"] == 200) {
    $ex_date = $response['expire_at'];
    $exp_date = substr($ex_date, 0, 10);
    //extract expiry date
    //a new return code's been created?
    if (array_key_exists("is_active", $response)) {