Skip to content

Commit

Permalink
Merge pull request #188 from globaldyne/v11.5
Browse files Browse the repository at this point in the history
V11.5
  • Loading branch information
globaldyne authored Sep 28, 2024
2 parents 00adf5e + b9e0ea6 commit d8c83aa
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 224 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# CHANGELOG
### Version 11.5
- Fix revisions comparison
- Update logout script
- Check if session already started for user session
- Improved filtering for advanced search in ingredients
- UI updates for ingredients
- Improve PV Online search
- Refactor local ingredients module
- Refactor PV-Online ingredients search

### Version 11.4
- Add shelf life for ingredients
- Add temprature measurement unit
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.4
11.5
5 changes: 4 additions & 1 deletion core/ajax-session.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
session_start();
if (session_status() == PHP_SESSION_NONE) {
session_start(); // Start the session only if not already started
}

if(!isset( $_SESSION['parfumvault']) || $_SESSION['parfumvault'] == false) {
//expired
echo "-1";
Expand Down
8 changes: 7 additions & 1 deletion core/full_revision_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@
}

foreach ($rev as $revision){
$mg['total_mg'] += $revision['quantity'];
$conc = $revision['concentration'] / 100 * $revision['quantity']/$mg['total_mg'] * 100;

$r['id'] = (int)$revision['id'];
$r['fid'] = (string)$revision['fid'];
$r['name'] = (string)$revision['name'];
$r['ingredient']['name'] = (string)$revision['ingredient'];
$r['ingredient']['id'] = (int)$revision['ingredient_id'];
$r['purity'] = (double)$revision['concentration'];
$r['purity'] = (float)$revision['concentration'];

$r['concentration'] = number_format($conc, $settings['qStep']) ?: 0.000;

$r['dilutant'] = (string)$revision['dilutant'];
$r['quantity'] = number_format((float)$revision['quantity'], $settings['qStep'],'.', '') ?: 0;
$r['notes'] = (string)$revision['notes'];
Expand Down
2 changes: 1 addition & 1 deletion db/schema.ver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.4
11.5
2 changes: 1 addition & 1 deletion func/getIngSupplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ function getSupplierByID($sID,$conn){
return $result;
}

?>
?>
2 changes: 1 addition & 1 deletion logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
unset($_SESSION['parfumvault']);
session_unset();
session_destroy();
header('Location: login.php');
header('Location: /login.php');
?>
2 changes: 1 addition & 1 deletion modules/suppliers/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@
echo json_encode($response,JSON_UNESCAPED_UNICODE);
return;

?>
?>
137 changes: 76 additions & 61 deletions modules/suppliers/pvOnline.php
Original file line number Diff line number Diff line change
@@ -1,81 +1,96 @@
<?php
define('__ROOT__', dirname(dirname(__FILE__)));
//define('__ROOT__', dirname(dirname(__FILE__)));

require_once(__ROOT__.'/inc/sec.php');
require_once(__ROOT__.'/inc/opendb.php');
require_once(__ROOT__.'/inc/settings.php');
require_once(__ROOT__.'/func/pvOnline.php');


$row = isset($_POST['start']) ? (int)$_POST['start'] : 0;
$limit = isset($_POST['length']) ? (int)$_POST['length'] : 10;
$order_by = isset($_POST['order_by']) ? $_POST['order_by'] : 'name';
$order = isset($_POST['order_as']) ? $_POST['order_as'] : 'ASC';

$row = $_POST['start']?:0;
$limit = $_POST['length']?:10;
$order_by = $_POST['order_by']?:'name';
$order = $_POST['order_as']?:'ASC';
// Trim and sanitize search input
$s = isset($_POST['search']['value']) ? trim($_POST['search']['value']) : '';

// Prepare data array for API request
$data = [
'request' => 'ingredients',
'start' => $row,
'length' => $limit,
'order_by' => $order_by,
'order_as' => $order,
'src' => 'PV_PRO',
'search[value]' => $s
];

$s = trim($_POST['search']['value']);
$data = [
'request' => 'ingredients',
'start' => $row,
'length' => $limit,
'order_by' => $order_by,
'order_as' => $order,
'src' => 'PV_PRO',
'search[value]=' => $s
];

// Make API request and decode the JSON response
$output = json_decode(pvPost($pvOnlineAPI, $data));

$rx = array();
foreach ($output->ingredients as $ingredient){
$r['id'] = (int)$ingredient->id;
$r['name'] = (string)filter_var ( $ingredient->name, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$r['cas'] = (string)$ingredient->cas ?: 'N/A';
$r['odor'] = (string)$ingredient->odor ?: 'N/A';
$r['profile'] = (string)$ingredient->profile ?: 'Uknown';
$r['physical_state'] = $ingredient->physical_state ?: 1;
$r['category'] = $ingredient->category ?: 0;
$r['type'] = (string)$ingredient->type ?: 'N/A';
$r['IUPAC'] = (string)filter_var ( $ingredient->INCI, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$r['strength'] = (string)$ingredient->strength ?: 'N/A';
$r['purity'] = $ingredient->purity ?: 100;
$r['FEMA'] = (string)$ingredient->FEMA ?: 'N/A';
$r['tenacity'] = (string)$ingredient->tenacity ?: 'N/A';
$r['chemical_name'] = (string)$ingredient->chemical_name ?: 'N/A';
$r['formula'] = (string)$ingredient->formula ?: 'N/A';
$r['flash_point'] = (string)$ingredient->flash_point ?: 'N/A';
$r['appearance'] = (string)$ingredient->appearance ?: 'N/A';
$r['notes'] = (string)$ingredient->notes ?: 'N/A';
$r['allergen'] = $ingredient->allergen ?: 0;
$r['flavor_use'] = $ingredient->flavor_use ?: 0;
$r['einecs'] = (string)$ingredient->einecs ?: 'N/A' ;
$r['usage']['limit'] = $ingredient->cat4 ?: 100;
$r['usage']['reason'] = (string)$ingredient->risk ?: 'N/A';
$r['impact_top'] = $ingredient->impact_top ?: 0;
$r['impact_heart'] = $ingredient->impact_heart ?: 0;
$r['impact_base'] = $ingredient->impact_base ?: 0;


$r['stock'] = (double)0; //Not available in online
$r['info']['byPassIFRA'] = (int)0;//Not available in online

// Initialize response array
$rx = [];
if (isset($output->ingredients) && is_array($output->ingredients)) {
foreach ($output->ingredients as $ingredient) {
if (empty($ingredient->name)) {
continue;
}

$rx[]=$r;
$r = [
'id' => (int) $ingredient->id,
'name' => (string) filter_var($ingredient->name, FILTER_SANITIZE_FULL_SPECIAL_CHARS),
'cas' => (string) ($ingredient->cas ?: 'N/A'),
'odor' => (string) ($ingredient->odor ?: 'N/A'),
'profile' => (string) ($ingredient->profile ?: 'Unknown'),
'physical_state' => (int) ($ingredient->physical_state ?: 1),
'category' => (int) ($ingredient->category ?: 0),
'type' => (string) ($ingredient->type ?: 'N/A'),
'IUPAC' => (string) filter_var($ingredient->INCI, FILTER_SANITIZE_FULL_SPECIAL_CHARS),
'strength' => (string) ($ingredient->strength ?: 'N/A'),
'purity' => (float) ($ingredient->purity ?: 100),
'FEMA' => (string) ($ingredient->FEMA ?: 'N/A'),
'tenacity' => (string) ($ingredient->tenacity ?: 'N/A'),
'chemical_name' => (string) ($ingredient->chemical_name ?: 'N/A'),
'formula' => (string) ($ingredient->formula ?: 'N/A'),
'flash_point' => (string) ($ingredient->flash_point ?: 'N/A'),
'appearance' => (string) ($ingredient->appearance ?: 'N/A'),
'notes' => (string) ($ingredient->notes ?: 'N/A'),
'allergen' => (int) ($ingredient->allergen ?: 0),
'flavor_use' => (int) ($ingredient->flavor_use ?: 0),
'einecs' => (string) ($ingredient->einecs ?: 'N/A'),
'usage' => [
'limit' => (float) ($ingredient->cat4 ?: 100),
'reason' => (string) ($ingredient->risk ?: 'N/A')
],
'impact_top' => (int) ($ingredient->impact_top ?: 0),
'impact_heart' => (int) ($ingredient->impact_heart ?: 0),
'impact_base' => (int) ($ingredient->impact_base ?: 0),
'stock' => 0.0, // Stock not available from online source
'info' => [
'byPassIFRA' => 0 // Not available from online source
]
];

$rx[] = $r;
}
}

$response = array(
"source" => 'PVOnline',
"draw" => (int)$_POST['draw'],
"recordsTotal" => (int)$output->ingredientsTotal,
"recordsFiltered" => (int)$output->ingredientsFiltered,
"data" => $rx
);
// Prepare final response
$response = [
'source' => 'PVOnline',
'draw' => isset($_POST['draw']) ? (int) $_POST['draw'] : 0,
'recordsTotal' => (int) ($output->ingredientsTotal ?? 0),
'recordsFiltered' => (int) ($output->ingredientsFiltered ?? 0),
'data' => $rx
];

if(empty($rx)){
$response['data'] = [];
// If no data found, ensure an empty array is returned
if (empty($rx)) {
$response['data'] = [];
}

// Send the response as JSON
header('Content-Type: application/json; charset=utf-8');
echo json_encode($response,JSON_UNESCAPED_UNICODE);
return;
echo json_encode($response, JSON_UNESCAPED_UNICODE);
return;
17 changes: 14 additions & 3 deletions pages/ingredients.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<div id="advsearchmsg"></div>
<div class="mb-3 row">
<div class="col-sm">
<label for="ing_name" class="col-form-label">Ingredient Name</label>
<label for="ing_name" class="col-form-label">Ingredient name</label>
<input type="text" class="form-control" id="ing_name" placeholder="Any">
</div>
</div>
Expand Down Expand Up @@ -99,14 +99,20 @@
<select name="category" id="ing_category" class="form-control selectpicker" data-live-search="true">
<option value="" selected>Any</option>
<?php while ($row_ingCategory = mysqli_fetch_array($res_ingCategory)){ ?>
<option data-content="<img class='img_ing_sel' src='<?php if($row_ingCategory['image']){ echo $row_ingCategory['image']; }else{ echo '/img/molecule.png';}?>'><?=$row_ingCategory['name']?>" value="<?=$row_ingCategory['id'];?>"></option>
<option data-content="<img class='img_ing_sel' src='<?php if($row_ingCategory['image']){ echo $row_ingCategory['image']; }else{ echo '/img/molecule.png';}?>'><?=$row_ingCategory['name']?>" data-text="<?=$row_ingCategory['name']?>" value="<?=$row_ingCategory['id'];?>"></option>
<?php } ?>
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="retainModal" checked>
<label class="form-check-label" for="retainModal">
Retain window after search
</label>
</div>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<input type="submit" name="button" class="btn btn-primary" id="btnAdvSearch" value="Search">
</div>
Expand Down Expand Up @@ -214,7 +220,8 @@
var profile = $('#ing_profile').val();
var cat = $('#ing_category').val();
var synonym = $('#ing_synonym').val();

var retainModal = $('#retainModal').is(':checked');

$.ajax({
url: '/pages/listIngredients.php',
type: 'GET',
Expand All @@ -231,6 +238,10 @@
dataType: 'html',
success: function (data) {
$('#list_ingredients').html(data);
if (!retainModal) {
$('#adv_search').modal('hide');
}

},
error: function (xhr, status, error) {
$('#advsearchmsg').html('<div class="alert alert-danger"><i class="fa-solid fa-circle-xmark mx-2"></i>An ' + status + ' occurred, check server logs for more info. '+ error +'</div>');
Expand Down
Loading

0 comments on commit d8c83aa

Please sign in to comment.