loadTemplatefile("page.html", true, true); $tpl->setVariable("TITLE", "Fragrance Calculator"); $tpl->setVariable("TIP", getPageTip()); $tpl->setVariable("ACTIVECALCS", ' class="activelink"'); $tpl->setVariable("MAINCONTENT", getMainContent()); $tpl->setVariable("LEFTNAVBOX", getLeftNavBox()); // $tpl->setVariable("RIGHTCONTENT", getRightContent()); // $tpl->setVariable("LEFTSPECIAL", getLeftSpecial()); $tpl->setVariable("COPYRIGHT", getCopyRightNotice("..")); $tpl->setVariable("OFFICE_INFO", getOfficeInfo("..")); $tpl->parse(); $tpl->show(); function getMainContent() { global $dbHNDL; $content = ''; $currentScreen = isset($_REQUEST["_State"]) ? $_REQUEST["_State"] : 'Default'; $validScreens = array( "Default" => "Choose", "Next" => "Display", "Select New Fragrance" => "Display", "Show Products" => "ShowTargets", "Select New Product" => "ShowTargets", "Calculate" => "CalculateUsageRate" ); if ($dbHNDL == 0) { header("Location: http://www.thesage.com/db_error.html"); exit; } if (!$validScreens[$currentScreen]) $currentScreen = "Default"; if (($currentScreen == "Next") || ($currentScreen == "Select New Fragrance")) return $validScreens[$currentScreen]($_POST['Choice'], $_POST['TargetID'], $_POST['Weight'], $_POST['Measure']); else if (($currentScreen == "Show Products") || ($currentScreen == "Select New Product")) return $validScreens[$currentScreen]($_POST['FragID'], isset($_POST['Weight']) ? $_POST['Weight'] : 1, isset($_POST['Measure']) ? $_POST['Measure'] : 1); else if ($currentScreen == "Calculate") return $validScreens[$currentScreen]($_POST['FragID'], $_POST['TargetID'], $_POST['Weight'], $_POST['Measure']); else return $validScreens[$currentScreen](); } function getLeftNavBox() { $content = << EOT; return $content; } function getLeftSpecial() { global $specials; $featuredProductsList = BuildFeaturedSet($specials, "Specials"); $content = buildContent($featuredProductsList, "Templates"); return $content; } function getRightContent() { global $features; $featuredProductsList = BuildFeaturedSet($features, "Featured"); $content = buildContent($featuredProductsList, "Templates"); return $content; } function GetScents($target) { global $sql1, $sql2; $target = Sanitize($target); $query = "SELECT DISTINCT p.ndex, p.name, c.category FROM products p, productincategory c " . "WHERE p.ndex IN (SELECT DISTINCT frag_id FROM frag_usage $target) AND p.ndex = c.product " . " AND (c.category = 1 OR c.category = 2);"; $sql1->Query($query); while ($sql1->ReadRow()) { $v = $sql1->RowData['name']; $category = $sql1->RowData['category']; if ($category == 1){ $essential_oil[$v] = $sql1->RowData['ndex']; } if ($category == 2){ $fragrance_oil[$v] = $sql1->RowData['ndex']; } } ksort($essential_oil); reset($essential_oil); ksort($fragrance_oil); reset($fragrance_oil); return array ($essential_oil, $fragrance_oil); } // Entry form function Choose(){ global $sql1; $content = "
\n"; $content .= "

Fragrance Calculator

\n"; $content .= "
"; $content .= ""; $fp = fopen("fragcalc_instr.html", "r"); $content .= "\n"; fclose($fp); $content .= "\n"; $content .= ""; $content .= "
" . fread($fp, 1000000) . "
 
Select By Product
"; $content .= ""; $content .= ""; $content .= "
Product TypeWeightMeasure

Select By Fragrance
"; $content .= "

"; $content .= "
"; return $content; } // Display Fragrances function Display($Choice, $TargetID, $Weight, $Measure){ global $sql1, $sql2; $i = $j = 0; $Choice = Sanitize($Choice); $TargetID = Sanitize($TargetID); $Weight = Sanitize($Weight); $Measure = Sanitize($Measure); $content = "
\n"; $content .= "

Fragrance Calculator

\n"; // Entry Point - Target if ($Choice == "target"){ if (is_numeric($Weight) && ($Weight > 0)){ // Retrieving frag_ids of fragrances used in targets with TargetID if ($TargetID == 1) list($essential_oil, $fragrance_oil) = GetScents("where target_ndex = 1 or target_ndex = 2"); else if ($TargetID == 6) list($essential_oil, $fragrance_oil) = GetScents("where target_ndex = 6 or target_ndex = 7" . " or target_ndex = 8 or target_ndex = 9"); else list($essential_oil, $fragrance_oil) = GetScents("where target_ndex = $TargetID"); // Retrieving the names of the resulting fragrances if ((count($essential_oil) > 0) || (count($fragrance_oil) > 0)){ $content .= ""; $content .= "Select a Fragrance

"; $totalScents = count($essential_oil) + count($fragrance_oil); $columnBreak = floor($totalScents / 2); $currentLine = 0; $chunks = array(0 => '', 1 => '', 2 => ''); $chunkCnt = 0; // Essential Oils if (count($essential_oil) == 0) $chunks[$chunkCnt] .= "No Essential Oils for the product selected"; else { $chunks[$chunkCnt] .= ""; while (list($key, $val) = each($essential_oil)) { $chunks[$chunkCnt] .= "\n"; $currentLine++; if ($currentLine == $columnBreak) { $chunks[$chunkCnt] .= "
". "$key
\n"; $chunkCnt++; $chunks[$chunkCnt] .= ""; } } $chunks[$chunkCnt] .= "
"; } $chunkCnt++; // Fragrance Oils if (count($fragrance_oil) == 0) $chunks[$chunkCnt] .= "No Fragrance Oils for the product selected"; else{ $chunks[$chunkCnt] .= ""; while (list($key, $val) = each($fragrance_oil)) { $chunks[$chunkCnt] .= "\n"; $currentLine++; if ($currentLine == $columnBreak) { $chunks[$chunkCnt] .= "
". "$key
\n"; $chunkCnt++; $chunks[$chunkCnt] .= ""; } } $chunks[$chunkCnt] .= "
"; } $content .= ""; if (count($fragrance_oil) > count($essential_oil)) { $content .= "" . "\n"; $content .= "" . "" . "\n" . "\n"; } else { $content .= "" . "\n"; $content .= "" . "" . "\n" . "\n"; } $content .= "
Essential OilsFragrance Oils
" . $chunks[0] . "" . $chunks[2] . "
Fragrance Oils
" . $chunks[1] . "
Essential OilsEssential Oils
" . $chunks[0] . "" . $chunks[1] . "
Fragrance Oils
" . $chunks[1] . "
"; $content .= ""; $content .= ""; $content .= ""; $content .= "
"; } else $content .= "There are no fragrances for the selected product"; } else{ $content .= "Please type a valid number for Weight
"; Choose(); } } // Entry Point - Fragrance else if ($Choice == "fragrance"){ list($essential_oil, $fragrance_oil) = GetScents(""); if ((count($essential_oil) > 0) || (count($fragrance_oil) > 0)) { $content .= ""; $content .= "Select a Fragrance

"; $totalScents = count($essential_oil) + count($fragrance_oil); $columnBreak = floor($totalScents / 2); $currentLine = 0; $chunks = array(0 => '', 1 => '', 2 => ''); $chunkCnt = 0; // Essential Oils if (count($essential_oil) == 0) $chunks[$chunkCnt] .= "No Essential Oils for the product selected"; else { $chunks[$chunkCnt] .= ""; while (list($key, $val) = each($essential_oil)) { $chunks[$chunkCnt] .= "\n"; $currentLine++; if ($currentLine == $columnBreak) { $chunks[$chunkCnt] .= "
". "$key
\n"; $chunkCnt++; $chunks[$chunkCnt] .= ""; } } $chunks[$chunkCnt] .= "
"; } $chunkCnt++; // Fragrance Oils if (count($fragrance_oil) == 0) $chunks[$chunkCnt] .= "No Fragrance Oils for the product selected"; else{ $chunks[$chunkCnt] .= ""; while (list($key, $val) = each($fragrance_oil)) { $chunks[$chunkCnt] .= ""; $currentLine++; if ($currentLine == $columnBreak) { $chunks[$chunkCnt] .= "
". "$key
\n"; $chunkCnt++; $chunks[$chunkCnt] .= ""; } } $chunks[$chunkCnt] .= "
"; } $content .= ""; if (count($fragrance_oil) > count($essential_oil)) { $content .= "" . "\n"; $content .= "" . "" . "\n" . "\n"; } else { $content .= "" . "\n"; $content .= "" . "" . "\n" . "\n"; } $content .= "
Essential OilsFragrance Oils
" . $chunks[0] . "" . $chunks[2] . "
Fragrance Oils
" . $chunks[1] . "
Essential OilsEssential Oils
" . $chunks[0] . "" . $chunks[1] . "
Fragrance Oils
" . $chunks[1] . "
"; $content .= "
"; } else $content .= "No fragrances are listed"; } // No Entry Point Selected else{ $content .= "
Please choose an option to proceed

"; Choose(); } $content .= "
\n"; return $content; } // List Targets that use the selected fragrance function ShowTargets($FragID, $Weight, $Measure){ global $sql1, $sql2; $FragID = Sanitize($FragID); $Weight = Sanitize($Weight); $Measure = Sanitize($Measure); $content = "
\n"; if (isset($FragID)){ $sql1->Query("SELECT u.target_ndex, t.name, t.sort_order" . " FROM frag_usage u, frag_targets t" . " WHERE u.target_ndex = t.ndex" . " AND frag_id = $FragID" . " ORDER BY t.sort_order;"); if ($sql1->RowCount){ $content .= ""; $content .= "Select a product, and the target weight of the product

"; $content .= " "; $MeasureSelect = "\n"; $target = "
\n"; return $content; } function CalculateUsageRate($FragID, $TargetID, $Weight, $Measure) { global $sql1, $sql2; $FragID = Sanitize($FragID); $TargetID = Sanitize($TargetID); $Weight = Sanitize($Weight); $Measure = Sanitize($Measure); $sg = 1; $loColor = "#FFCCCC"; $medColor = "#FFAAAA"; $hiColor = "#FF8888"; $white = "#FFFFFF"; $loStyleOn = ""; $loStyleOff = ""; $medStyleOn = ""; $medStyleOff = ""; $hiStyleOn = ""; $hiStyleOff = ""; $Units = array("1" => "Ounces", "2" => "Pounds", "3" => "Grams" ); $content = "
"; // For target name, minimum usage, maximum usage, and step size $sql1->Query("select * from frag_targets where ndex = $TargetID;"); if ($sql1->RowCount == 1){ $sql1->ReadRow(); $Target_name = $sql1->RowData['name']; $measureNotes = $sql1->RowData['measure_info']; $defaultNotes = $sql1->RowData['default_notes']; $tableStart = $sql1->RowData['min_usage']; $tableEnd = $sql1->RowData['max_usage']; $tableStep = $sql1->RowData['step_size']; } // For Fragrance name $sql2->Query("select name from products where ndex = $FragID;"); if ($sql2->RowCount == 1){ $sql2->ReadRow(); $Frag_name = $sql2->RowData['name']; } // For specific gravity of the selected fragrance $sql2->Query("select sg from frag_sg where frag_id = $FragID;"); $sql2->ReadRow(); $sg = $sql2->RowData['sg']; // For flashpoint of the selected fragrance $sql2->Query("select flashpoint from products where ndex = $FragID;"); $sql2->ReadRow(); $flashpoint = $sql2->RowData['flashpoint']; if (($Measure != 1) && ($Measure != 2) && ($Measure !=3)) $Measure = 1; $content .= "

Fragrance Calculator

\n"; $content .= "

Fragrance Recommendations for
$Frag_name in " . "
$Weight $Units[$Measure] of $Target_name

\n"; $content .= "

$Frag_name
$flashpoint° Flashpoint / $sg Specific Gravity

\n"; // For fragrance recommendations for the selected target $sql2->Query("select * from frag_usage where frag_id = $FragID " . "and target_ndex = $TargetID;"); $sql2->ReadRow(); $lo_rate = $sql2->RowData['lo_rate']; $mid_rate = $sql2->RowData['mid_rate']; $hi_rate = $sql2->RowData['hi_rate']; if (($sg < 170) && (($TargetID == 6) || ($TargetID == 8) || ($TargetID == 9))) { $lo_rate = 0; } $notes = ''; if ($sql2->RowData['notes']) { $notes = "
Notes for $Frag_name
" . $sql2->RowData['notes'] . "

\n"; } if ($defaultNotes) { $notes .= "
General Usage Notes
" . $defaultNotes . "

\n"; } if ($measureNotes) { $notes .= "
Measurement Notes
" . $measureNotes . "

\n"; } // Not Recommended if ($lo_rate == 0) $content .= "$Frag_name is NOT recommended in making $Target_name"; // Print the table of fragrance recommendations else{ // No Recommendation on usage rate if ($lo_rate == -1) { $content .= "There is no recommendation for the usage rate of " . "$Frag_name in $Target_name"; } // Convert from Pounds or grams to Ounces switch($Measure){ case '2': $Weight = $Weight * 16; break; case '3': $Weight = $Weight * (1/28.3495); break; } $content .= "
"; $content .= ""; for ($i= $tableStart; $i<=$tableEnd; $i+=$tableStep){ $percent = $i * 100; $check = round($i, 4); if ($check == round($lo_rate, 4)) { $row_color = $loColor; $rowStyleOn = $loStyleOn; $rowStyleOff = $loStyleOff; } else if ($check == round($mid_rate, 4)) { $row_color = $medColor; $rowStyleOn = $medStyleOn; $rowStyleOff = $medStyleOff; } else if ($check == round($hi_rate, 4)) { $row_color = $hiColor; $rowStyleOn = $hiStyleOn; $rowStyleOff = $hiStyleOff; } else { $row_color = $white; $rowStyleOn = ''; $rowStyleOff = ''; } // Fragrance Recommendations in different units $wtoz = $i * $Weight; $floz = $i * $Weight / $sg; $tsp = $floz * 6; $tbsp = $floz * 2; $ml = $floz * 30; $dram = $floz * 8; $content .= "" . "" . "" . "" . "" . "" . "" . "\n"; } $content .= "
Percent Ounces Wt Teaspoons Tablespoons Milliliters Drams
". $rowStyleOn . sprintf("%01.2f%%", $percent) . $rowStyleOff . "". $rowStyleOn . sprintf("%01.2f", $wtoz) . $rowStyleOff . "". $rowStyleOn . sprintf("%01.2f", $tsp) . $rowStyleOff . "". $rowStyleOn . sprintf("%01.2f", $tbsp) . $rowStyleOff . "". $rowStyleOn . sprintf("%01.1f", $ml) . $rowStyleOff . "". $rowStyleOn . sprintf("%01.2f", $dram) . $rowStyleOff . "
"; // Color Legend $content .= "
"; $content .= "" . "" . "" . "" . "" . "
" . $loStyleOn . "Subtle Scent" . $loStyleOff . "" . $medStyleOn . "Moderate Scent" . $medStyleOff . "" . $hiStyleOn . "Strong Scent" . $hiStyleOff . "
"; $content .= "
"; // Notes $content .= "

$notes"; } $content .= "\n"; $content .= "\n"; $content .= "\n"; $content .= "\n"; $content .= "\n"; $content .= ""; $content .= " "; $content .= "\n"; return $content; } ?>