Skip to content

Commit

Permalink
Carrier List update
Browse files Browse the repository at this point in the history
Carrier list now pulls all carriers from TrackingHive. Updated CSS.
  • Loading branch information
fireshaper authored Aug 3, 2020
1 parent d7a4d5a commit 393c1c8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 54 deletions.
79 changes: 36 additions & 43 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<div class="package-view">
<div class="package-container">
<?php

/*Get an API Token from my.trackinghive.com and put it here */
$bearerToken = '';

$comment = "No title";

$now = new DateTime();
Expand Down Expand Up @@ -59,16 +59,6 @@ function deleteParcel($_id, $bearerToken){
$carrier = $_POST["carrier"];
$comment = $_POST["comment"];

/*
if (!is_file($file)) {
file_put_contents($file, $trackingNum);
} else {
$parcelFile = fopen($file, 'a');
fwrite($parcelFile, $trackingNum . "," . $carrier . PHP_EOL);
fclose($parcelFile);
}
*/

//----begin trackhive code to add a parcel to your account
try {
$ch = curl_init();
Expand Down Expand Up @@ -111,7 +101,7 @@ function deleteParcel($_id, $bearerToken){
//print_r($json);

if ($json['meta']['code'] == 200) {
echo '<font color="green">Package added!</font><br /><br />';
echo '<font color="red">Package added!</font><br /><br />';
}
}
?>
Expand All @@ -122,13 +112,27 @@ function deleteParcel($_id, $bearerToken){
<input type="text" name="tracking" placeholder="tracking number" class="track-form-input">

<input type="text" name="comment" placeholder="title (optional)" class="track-form-input">

<select name="carrier" id="carrier" class="track-form-input">
<option value="usps">USPS</option>
<option value="ups">UPS</option>
<option value="fedex">FedEx</option>
<option value="dhl">DHL</option>
<option value="aramex">Aramex</option>

<?php
/*Get all carriers*/
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.trackinghive.com/couriers/list");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

$response = curl_exec($ch);
curl_close($ch);

$carrier_json = json_decode($response, false);

foreach ($carrier_json->data as $carriers) {
echo '<option value="' . $carriers->slug . '">' . $carriers->title . '</option>';
}
?>

</select>

<input type="submit" value="Add" class="track-form-input">
Expand Down Expand Up @@ -160,7 +164,6 @@ function deleteParcel($_id, $bearerToken){

//print_r($json);

try {
foreach ($json->data as $mydata) {
$custom_fields = explode(':', $mydata->custom_fields);
$comment = $custom_fields[1];
Expand Down Expand Up @@ -228,22 +231,10 @@ function deleteParcel($_id, $bearerToken){
$infoMore = "N/A";
}

switch ($carrier_slug){
case 'usps':
$carrier = 'USPS';
break;
case 'ups':
$carrier = 'UPS';
break;
case 'fedex':
$carrier = 'FedEx';
break;
case 'dhl':
$carrier = 'DHL';
break;
case 'aramex':
$carrier = 'Aramex';
break;
foreach ($carrier_json->data as $carriers){
if ($carrier_slug == $carriers->slug){
$carrier = $carriers->title;
}
}

$trackingNum = $mydata->tracking_number;
Expand All @@ -252,7 +243,7 @@ function deleteParcel($_id, $bearerToken){
$modTime = strtotime($modTS);
$nowTS = $now->getTimestamp();
$modifiedTime = "About " . date('g', $nowTS - $modTime) . " hours ago";
//echo "About " . date('g', $nowTS - $modTime) . " hours ago";


?>
<div class="parcel-item">
Expand Down Expand Up @@ -302,6 +293,9 @@ function deleteParcel($_id, $bearerToken){
} else if ($infoStatus == "Delivered") {
$statusStyle = 'style="background-color: #3fb00b !important;border-color: #3fb00b !important;"';
$trackStatus = "Delivered";
} else if ($infoStatus == "OutForDelivery") {
$statusStyle = 'style="background-color: #f7d418 !important;border-color: #f7d418 !important;"';
$trackStatus = "Out for Delivery";
} else {
$statusStyle = 'style="background-color: #000 !important;border-color: #000 !important;"';
$trackStatus = "N/A";
Expand All @@ -317,6 +311,8 @@ function deleteParcel($_id, $bearerToken){
$statusStyle = 'style="border-color: #373852 !important;"';
} else if ($infoStatus == "Delivered") {
$statusStyle = 'style="border-color: #3fb00b !important;"';
} else if ($infoStatus == "OutForDelivery") {
$statusStyle = 'style="border-color: #f7d418 !important;"';
} else {
$statusStyle = 'style="border-color: #000 !important;"';
}
Expand Down Expand Up @@ -344,8 +340,7 @@ function deleteParcel($_id, $bearerToken){
<div class="media-right">
<div class="last-update"> <?php echo $modifiedTime; ?> </div>
<div class="delete-button">
<!--<i class="fa fa-trash"></i>
<span>Delete Parcel</span> -->

<form method="post" action="index.php">
<input type="submit" name="action" value="Delete"/>
<input type="hidden" name="id" value="<?php echo $parcelID; ?>"/>
Expand All @@ -356,10 +351,7 @@ function deleteParcel($_id, $bearerToken){
</div>
</div>
</div>
<?php }
} catch (Exception $e) {
echo "Trouble connecting to Trackhive, please try again.";
} ?>
<?php } ?>

</div>
</div>
Expand All @@ -370,3 +362,4 @@ function deleteParcel($_id, $bearerToken){
</div>
</body>
</html>

21 changes: 10 additions & 11 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* For desktop: */
html, body {
height: 100%;
}
body {
margin: 0;
height: 1000px;
background: #94b5eb;
}
h1 {

Expand All @@ -15,12 +18,8 @@ a {

.main {
padding: 20px 0;
border-top: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
background: #94b5eb;
box-sizing: border-box;
position: relative;
height: inherit;
}
.package-inbox-view {
box-sizing: border-box;
Expand All @@ -38,8 +37,7 @@ a {
.content {
margin-left: -15px;
margin-right: -15px;
box-sizing: border-box;

box-sizing: border-box;
}

.package-view {
Expand All @@ -50,15 +48,16 @@ a {
position: relative;
min-height: 1px;
box-sizing: border-box;
background: #f2f2f2;
border-bottom: 10px solid #f2f2f2;
}

.package-container {
position: relative;
height: 100%;
min-height: 365px;
margin-top: 5px;
min-height: 100%;
margin-top: 10px;
padding: 20px;
margin-bottom: 5px;
margin-bottom: 10px;
background: #fff;
box-shadow: 0px 0px 4px 0px rgba(0,0,0,0.2);
border-radius: 2px;
Expand Down

0 comments on commit 393c1c8

Please sign in to comment.