Skip to content

Commit

Permalink
Merge pull request #182 from globaldyne/v11.0
Browse files Browse the repository at this point in the history
V11.0
  • Loading branch information
globaldyne authored Aug 23, 2024
2 parents ee46374 + 5d0754d commit 3c288de
Show file tree
Hide file tree
Showing 42 changed files with 1,602 additions and 1,279 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# CHANGELOG
### Version 11.0
- Making SDS GA
- Added maximum allowed usage for a formula
- Changed datatype for PubChem to json
- Added a button to view ingredient data in PubChem
- Fix PubChemData update button
- Added more error handling for ajax requests
- Added a var (pvSearch) to search ingredients in the local datatabase
- Changed the way the ingredient is handled when exists in a formula but not in the database. Instead of auto creating it when clicked, it presents options to create it, search in PV Online or import via JSON
- Added editability in IFRA Library
- Fix a bug preventing adding new ingredients
- Treat empty IFRA Library values (PROHIBITION, SPECIFICATION) as 0% allowed
- IFRA structure images import improvements

### Version 10.9
- Sys update check improvements
- Dashboard page updates
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ Please note, all DB_ variables are required.
or via docker compose

---
version: '3.8'
services:
pvdb:
image: mariadb:10.5
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.9
11.0
24 changes: 19 additions & 5 deletions core/finished_formula_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,29 @@
$r['cost'] = (float)calcCosts(getPrefSupplier($ing_q['id'],$conn)['price'],$new_quantity, $formula['concentration'], getPrefSupplier($ing_q['id'],$conn)['size']);
}

$u = explode(' - ',searchIFRA($ing_q['cas'],$formula['ingredient'],null,$defCatClass));

if(($u['0'] && $ing_q['byPassIFRA'] == 0)){
$r['usage_limit'] = number_format((float)$u['0']?:100, $settings['qStep']);
$r['usage_restriction'] = (string)$u['1'] ?: 'N/A';
//$u = explode(' - ',searchIFRA($ing_q['cas'],$formula['ingredient'],null,$defCatClass));
$u = searchIFRA($ing_q['cas'],$formula['ingredient'],null,$defCatClass);

//if(($u['0'] && $ing_q['byPassIFRA'] == 0)){
if(($u['val'] || $u['type'] && $ing_q['byPassIFRA'] == 0)){
$r['usage_limit'] = number_format((float)$u['val']?:100, $settings['qStep']);
$r['usage_restriction'] = (string)$u['risk'] ?: 'N/A';
$r['usage_restriction_type'] = (string)$u['type'] ?: 'N/A';
$r['usage_regulator'] = (string)"IFRA";
}else{
$r['usage_limit'] = number_format((float)$ing_q["$defCatClass"], $settings['qStep']) ?: 100;
$r['usage_restriction'] = (int)$ing_q['classification'];
if ($ing_q['classification'] == 1) {
$r['usage_restriction_type'] = 'RECOMMENDATION';
} elseif ($ing_q['classification'] == 2) {
$r['usage_restriction_type'] = 'RESTRICTION';
} elseif ($ing_q['classification'] == 3) {
$r['usage_restriction_type'] = 'SPECIFICATION';
} elseif ($ing_q['classification'] == 4) {
$r['usage_restriction_type'] = 'PROHIBITION';
} else {
$r['usage_restriction_type'] = 'RECOMMENDATION';
}
$r['usage_regulator'] = (string)"PV";
$r['ingredient']['classification'] = (int)$ing_q['classification'] ?: 1;
}
Expand Down
54 changes: 40 additions & 14 deletions core/full_formula_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@
foreach ($form as $formula){

$ing_q = mysqli_fetch_array(mysqli_query($conn, "SELECT id, name, cas, $defCatClass, profile, odor, category, physical_state,usage_type AS classification, type, byPassIFRA FROM ingredients WHERE name = '".$formula['ingredient']."'"));
/*
$reps = mysqli_query($conn,"SELECT ing_rep_name FROM ingReplacements WHERE ing_name = '".$formula['ingredient']."'");
if (mysqli_num_rows($reps)==0) {
$reps = mysqli_query($conn,"SELECT ing_name FROM ingReplacements WHERE ing_rep_name = '".$formula['ingredient']."'");
}
while($replacements = mysqli_fetch_array($reps)){
$replacement[] = $replacements;
}

*/
$totalcontainsOthers = mysqli_num_rows(mysqli_query($conn, "SELECT name,$defPercentage,cas FROM ingredient_compounds WHERE ing = '".$formula['ingredient']."'"));


Expand Down Expand Up @@ -192,15 +193,28 @@

}

$u = explode(' - ',searchIFRA($ing_q['cas'],$formula['ingredient'],null,$defCatClass));
$u = searchIFRA($ing_q['cas'],$formula['ingredient'],null,$defCatClass);

if(($u['0'] && $ing_q['byPassIFRA'] == 0)){
$r['usage_limit'] = number_format((float)$u['0']?:100, $settings['qStep']);
$r['usage_restriction'] = (string)$u['1'] ?: 'N/A';
if(($u['val'] || $u['type'] && $ing_q['byPassIFRA'] == 0)){
$r['usage_limit'] = (float)number_format((float)$u['val'], $settings['qStep']);
$r['usage_restriction'] = (string)$u['risk'] ?: 'N/A';
$r['usage_restriction_type'] = (string)$u['type'] ?: 'N/A';
$r['usage_regulator'] = (string)"IFRA";
}else{
$r['usage_limit'] = number_format((float)$ing_q["$defCatClass"], $settings['qStep']) ?: 100;
$r['usage_restriction'] = (int)$ing_q['classification'];

if ($ing_q['classification'] == 1) {
$r['usage_restriction_type'] = 'RECOMMENDATION';
} elseif ($ing_q['classification'] == 2) {
$r['usage_restriction_type'] = 'RESTRICTION';
} elseif ($ing_q['classification'] == 3) {
$r['usage_restriction_type'] = 'SPECIFICATION';
} elseif ($ing_q['classification'] == 4) {
$r['usage_restriction_type'] = 'PROHIBITION';
} else {
$r['usage_restriction_type'] = 'RECOMMENDATION';
}
$r['usage_regulator'] = (string)"PV";
$r['ingredient']['classification'] = (int)$ing_q['classification'] ?: 1;
}
Expand All @@ -217,7 +231,6 @@
$r['ingredient']['name'] = (string)$ingName ?: $formula['ingredient'];
$r['ingredient']['cas'] = (string)$ing_q['cas'] ?: 'N/A';
$r['ingredient']['physical_state'] = (int)$ing_q['physical_state'];
//$r['ingredient']['classification'] = (int)$ing_q['classification'] ?: 1;
$r['ingredient']['type'] = (string)$ing_q['type'] ?: 'Unknown';

$r['ingredient']['desc'] = (string)$desc ?: '-';
Expand All @@ -229,17 +242,11 @@
$r['ingredient']['inventory']['batch'] = (string)$inventory['batch'] ?: 'N/A';
$r['ingredient']['inventory']['purchased'] = (string)$inventory['purchased'] ?: 'N/A';

//$totalReplacements = 0;
//foreach ($replacement as $rp){
// $totalReplacements++;
// $r['ingredient'][]['replacement']['name'] = (string)$rp['ing_rep_name'] ?: (string)$rp['ing_name'] ?: 'N/A';
//}
//$r['ingredient']['replacement']['total'] = $totalReplacements ?: 0;


$r['ingredient']['containsOthers']['total'] = $totalcontainsOthers ?: 0;

$r['chk_ingredient'] = (string)checkIng($formula['ingredient'],$defCatClass,$conn) ?: null;
$r['chk_ingredient'] = (string)checkIng($formula['ingredient'],$defCatClass,$conn)['text'];
$r['chk_ingredient_code'] = (int)checkIng($formula['ingredient'],$defCatClass,$conn)['code'];
$r['exclude_from_calculation'] = (int)$formula['exclude_from_calculation'] ?: 0;


Expand Down Expand Up @@ -273,6 +280,24 @@
$m['formula_description'] = (string)$meta['notes'];
$m['protected'] = (bool)$meta['isProtected'];

$lastValAccepted = null;

for ($c = 1; $c <= 100; $c++) {
$result = validateFormula($meta['fid'], 100, $c, $mg['total_mg'], $defCatClass, $settings['qStep']);

if ($result === 0) {
$lastValAccepted = $c;
} else {
break;
}
}
if( $lastValAccepted !== null) {

$m['max_usage'] = $lastValAccepted;
} else {
$m['max_usage'] = 'Unable to calculate';
}
/*
$new_conc = $_GET['final_total_ml'] ?: 100/100*$_GET['final_type_conc'] ?: 100;
$carrier = $_GET['final_total_ml'] ?: 100 - $new_conc;
Expand All @@ -292,6 +317,7 @@
$compliance['message'] = (string)$val_msg ?: 'Formula is IFRA compliant';
$response['compliance'] = $compliance;
*/
$response['meta'] = $m;

$s['load_time'] = microtime(true) - $starttime;
Expand Down
36 changes: 18 additions & 18 deletions core/list_IFRA_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@
$r['risk'] = (string)$IFRA['risk']?:'N/A';
$r['contrib_others'] = (string)$IFRA['contrib_others']?:'N/A';
$r['contrib_others_notes'] = (string)$IFRA['contrib_others_notes']?:'N/A';
$r['cat1'] = (float)$IFRA['cat1']?:'N/A';
$r['cat2'] = (float)$IFRA['cat2']?:'N/A';
$r['cat3'] = (float)$IFRA['cat3']?:'N/A';
$r['cat4'] = (float)$IFRA['cat4']?:'N/A';
$r['cat5A'] = (float)$IFRA['cat5A']?:'N/A';
$r['cat5B'] = (float)$IFRA['cat5B']?:'N/A';
$r['cat5C'] = (float)$IFRA['cat5C']?:'N/A';
$r['cat5D'] = (float)$IFRA['cat5D']?:'N/A';
$r['cat6'] = (float)$IFRA['cat6']?:'N/A';
$r['cat7A'] = (float)$IFRA['cat7A']?:'N/A';
$r['cat7B'] = (float)$IFRA['cat7B']?:'N/A';
$r['cat8'] = (float)$IFRA['cat8']?:'N/A';
$r['cat9'] = (float)$IFRA['cat9']?:'N/A';
$r['cat10A'] = (float)$IFRA['cat10A']?:'N/A';
$r['cat10B'] = (float)$IFRA['cat10B']?:'N/A';
$r['cat11A'] = (float)$IFRA['cat11A']?:'N/A';
$r['cat11B'] = (float)$IFRA['cat11B']?:'N/A';
$r['cat12'] = (float)$IFRA['cat12']?:'N/A';
$r['cat1'] = (float)$IFRA['cat1'];
$r['cat2'] = (float)$IFRA['cat2'];
$r['cat3'] = (float)$IFRA['cat3'];
$r['cat4'] = (float)$IFRA['cat4'];
$r['cat5A'] = (float)$IFRA['cat5A'];
$r['cat5B'] = (float)$IFRA['cat5B'];
$r['cat5C'] = (float)$IFRA['cat5C'];
$r['cat5D'] = (float)$IFRA['cat5D'];
$r['cat6'] = (float)$IFRA['cat6'];
$r['cat7A'] = (float)$IFRA['cat7A'];
$r['cat7B'] = (float)$IFRA['cat7B'];
$r['cat8'] = (float)$IFRA['cat8'];
$r['cat9'] = (float)$IFRA['cat9'];
$r['cat10A'] = (float)$IFRA['cat10A'];
$r['cat10B'] = (float)$IFRA['cat10B'];
$r['cat11A'] = (float)$IFRA['cat11A'];
$r['cat11B'] = (float)$IFRA['cat11B'];
$r['cat12'] = (float)$IFRA['cat12'];

$r['defCat']['class'] = (string)$defCatClass?:'N/A';
$r['defCat']['limit'] = (float)$IFRA[$defCatClass]?:'0';
Expand Down
2 changes: 1 addition & 1 deletion core/list_formula_analysis_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
}

$r['contained_percentage'] = $conc_p;
$u = searchIFRA($get_data_ing['cas'], $get_data_ing['name'], null, $defCatClass);

$u = explode(' - ', searchIFRA($get_data_ing['cas'], $get_data_ing['name'], null, $defCatClass));
$r['max_allowed'] = $u[0];

$response['data'][] = $r;
Expand Down
9 changes: 9 additions & 0 deletions css/vault.css
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ a {
font-weight: bold;
}

.custom_profile_notes {
background-size: 30px 30px;
background-repeat:no-repeat;
display: inline-block;
height: 30px;
content:"";
font-weight: bold;
}

.img-formula {
height: 60px;
float: right;
Expand Down
2 changes: 1 addition & 1 deletion db/schema.ver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.9
11.0
1 change: 0 additions & 1 deletion docker-compose/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
version: '3.8'
services:
pvdb:
image: mariadb:10.5
Expand Down
12 changes: 6 additions & 6 deletions func/checkIng.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php if (!defined('pvault_panel')){ die('Not Found');}?>
<?php

function checkIng($ingredient, $defCatClass, $conn){
$chk = mysqli_query($conn, "SELECT id, name, $defCatClass, profile, cas FROM ingredients WHERE name = '$ingredient' OR chemical_name = '$ingredient'");
if(mysqli_num_rows($chk)){
Expand All @@ -11,17 +11,17 @@ function checkIng($ingredient, $defCatClass, $conn){
$chkPrice = mysqli_fetch_array(mysqli_query($conn, "SELECT price FROM suppliers WHERE ingID = '".$qValues['id']."'"));

if(empty($chkIFRA[$defCatClass]) && !isset($qValues[$defCatClass])){
return 'Missing usage data';
return ['text' => 'Missing usage data', 'code' => 1];
}
if(empty($chkPrice['price'])){
return 'Missing pricing data';
return ['text' => 'Missing pricing data', 'code' => 2];
}
if(!($qValues['profile'])){
return 'Missing profile data';
return ['text' => 'Missing profile data', 'code' => 3];
}
}
}else{
return 'Ingredient is missing from the database';
return ['text' => 'Ingredient is missing from the database', 'code' => 4];
}
}
?>

52 changes: 26 additions & 26 deletions func/fixIFRACas.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?php
if (!defined('pvault_panel')){ die('Not Found');}

function fixIFRACas($conn){
$q0 = mysqli_query($conn, "SELECT id,cas FROM IFRALibrary WHERE cas REGEXP '^[a-zA-Z().]'");
while($f = mysqli_fetch_array($q0)){
$r = preg_replace("/^\s/", "",preg_replace("/\s+/", "\n",preg_replace("/[^0-9,\-,\n]/", "", $f['cas'])));
mysqli_query($conn, "UPDATE IFRALibrary SET cas = '$r2' WHERE id = '".$f['id']."'");
}


$q1 = mysqli_query($conn, "SELECT id,ifra_key,cas FROM IFRALibrary WHERE cas REGEXP '\n'");
$fields = 'ifra_key,image,amendment,prev_pub,last_pub,deadline_existing,deadline_new,name,cas,cas_comment,synonyms,formula,flavor_use,prohibited_notes,restricted_photo_notes,restricted_notes,specified_notes,type,risk,contrib_others,contrib_others_notes,cat1,cat2,cat3,cat4,cat5A,cat5B,cat5C,cat5D,cat6,cat7A,cat7B,cat8,cat9,cat10A,cat10B,cat11A,cat11B,cat12';

while($r = mysqli_fetch_array($q1)){
$e = explode("\n",$r['cas']);
foreach($e as $value){

$n = "INSERT INTO IFRALibrary ($fields) SELECT ifra_key,image,amendment,prev_pub,last_pub,deadline_existing,deadline_new,name,'$value',cas_comment,synonyms,formula,flavor_use,prohibited_notes,restricted_photo_notes,restricted_notes,specified_notes,type,risk,contrib_others,contrib_others_notes,cat1,cat2,cat3,cat4,cat5A,cat5B,cat5C,cat5D,cat6,cat7A,cat7B,cat8,cat9,cat10A,cat10B,cat11A,cat11B,cat12 FROM IFRALibrary WHERE id = '".$r['id']."'";
mysqli_query($conn, $n);
}
}
mysqli_query($conn, "DELETE FROM IFRALibrary WHERE cas REGEXP '\n'");
mysqli_query($conn, "DELETE FROM IFRALibrary WHERE name = '' OR ifra_key = 'Key|String'");

}
<?php
if (!defined('pvault_panel')){ die('Not Found');}

function fixIFRACas($conn){
$q0 = mysqli_query($conn, "SELECT id,cas FROM IFRALibrary WHERE cas REGEXP '^[a-zA-Z().]'");
while($f = mysqli_fetch_array($q0)){
$r = preg_replace("/^\s/", "",preg_replace("/\s+/", "\n",preg_replace("/[^0-9,\-,\n]/", "", $f['cas'])));
mysqli_query($conn, "UPDATE IFRALibrary SET cas = '$r2' WHERE id = '".$f['id']."'");
}


$q1 = mysqli_query($conn, "SELECT id,ifra_key,cas FROM IFRALibrary WHERE cas REGEXP '\n'");
$fields = 'ifra_key,image,amendment,prev_pub,last_pub,deadline_existing,deadline_new,name,cas,cas_comment,synonyms,formula,flavor_use,prohibited_notes,restricted_photo_notes,restricted_notes,specified_notes,type,risk,contrib_others,contrib_others_notes,cat1,cat2,cat3,cat4,cat5A,cat5B,cat5C,cat5D,cat6,cat7A,cat7B,cat8,cat9,cat10A,cat10B,cat11A,cat11B,cat12';

while($r = mysqli_fetch_array($q1)){
$e = explode("\n",$r['cas']);
foreach($e as $value){

$n = "INSERT INTO IFRALibrary ($fields) SELECT ifra_key,image,amendment,prev_pub,last_pub,deadline_existing,deadline_new,name,'$value',cas_comment,synonyms,formula,flavor_use,prohibited_notes,restricted_photo_notes,restricted_notes,specified_notes,type,risk,contrib_others,contrib_others_notes,cat1,cat2,cat3,cat4,cat5A,cat5B,cat5C,cat5D,cat6,cat7A,cat7B,cat8,cat9,cat10A,cat10B,cat11A,cat11B,cat12 FROM IFRALibrary WHERE id = '".$r['id']."'";
mysqli_query($conn, $n);
}
}
mysqli_query($conn, "DELETE FROM IFRALibrary WHERE cas REGEXP '\n'");
mysqli_query($conn, "DELETE FROM IFRALibrary WHERE name = '' OR ifra_key = 'Key|String'");

}
?>
Loading

0 comments on commit 3c288de

Please sign in to comment.