php_track_var; currency_init(); function currency_init() { // This fuction initialize some stuff global $currency_selected, $currency_rate, $currency_menu, $SERVER_NAME, $REQUEST_URI, $HTTP_COOKIE_VARS, $currency_style; // As usuall, the things to edit $host="database.cs.ait.ac.th"; $user="cur_display"; $password="PR&Ig25n"; $database="on"; $currency_menu_font="color=#0000ff style=\"FONT-FAMILY: Verdana, Times New Roman, serif; FONT-SIZE: 10px\""; $currency_style=""; // Send a cookie if we select a new language if ($currency_selected) { setcookie("cookiecurrency", $currency_selected, time()+31536000); } // Some JavaScript to reload with new currency echo " "; if (! $selected_language) $selected_language="en"; // select a language // get the exchange rate from the database $dbh=mysql_connect($host, $user, $password); $res=mysql_db_query($database, "select currency, rate, $selected_language from currency order by currency"); // do we have a selected currency? By reading cookie or by click if (! $currency_selected && $HTTP_COOKIE_VARS["cookiecurrency"]) $currency_selected=$HTTP_COOKIE_VARS["cookiecurrency"]; // my own URL, to call myself back after selecting currency $this_uri="http://$SERVER_NAME$REQUEST_URI"; $this_uri=preg_replace("/(\?|\&)currency_selected=[A-Z]{3}/", "", $this_uri); if (preg_match("/\?/", $this_uri)) { $this_uri.="¤cy_selected="; } else { $this_uri.="?currency_selected="; } $i=0; $currency_menu="\n"; $currency_menu="
\n"; } function currency_menu() { // This function display the menu somewhere on the page global $currency_menu; echo $currency_menu; } function price($string) { // This function display a price and the converted equivalent global $currency_selected, $currency_rate, $currency_style; // find the current currency $cur_currency=preg_replace("/\s*\d+(\.\d*)?\s*/", "", $string); if ((! $cur_currency) || ($cur_currency == "$")) $cur_currency="USD"; preg_match("/\d+(\.\d*)?/", $string, $out); $value= $out[0]; $cur_currency=strtoupper($cur_currency); // do nothing if we have no currency selected if ((! $currency_selected) || ($cur_currency==$currency_selected)) { echo "$value $cur_currency"; return; } // compute the new value $new_value=$value; if ($cur_currency!="USD") { $new_value=$new_value/$currency_rate[$cur_currency]; } if ($currency_selected!="USD") { $new_value=$new_value*$currency_rate[$currency_selected]; } $new_value=round($new_value); echo "$value $cur_currency ($new_value $currency_selected)"; } ?> php_track_var; currency_init(); function currency_init() { // This fuction initialize some stuff global $currency_selected, $currency_rate, $currency_menu, $SERVER_NAME, $REQUEST_URI, $HTTP_COOKIE_VARS, $currency_style; // As usuall, the things to edit $host="database.cs.ait.ac.th"; $user="cur_display"; $password="PR&Ig25n"; $database="on"; $currency_menu_font="color=#0000ff style=\"FONT-FAMILY: Verdana, Times New Roman, serif; FONT-SIZE: 10px\""; $currency_style=""; // Send a cookie if we select a new language if ($currency_selected) { setcookie("cookiecurrency", $currency_selected, time()+31536000); } // Some JavaScript to reload with new currency echo " "; if (! $selected_language) $selected_language="en"; // select a language // get the exchange rate from the database $dbh=mysql_connect($host, $user, $password); $res=mysql_db_query($database, "select currency, rate, $selected_language from currency order by currency"); // do we have a selected currency? By reading cookie or by click if (! $currency_selected && $HTTP_COOKIE_VARS["cookiecurrency"]) $currency_selected=$HTTP_COOKIE_VARS["cookiecurrency"]; // my own URL, to call myself back after selecting currency $this_uri="http://$SERVER_NAME$REQUEST_URI"; $this_uri=preg_replace("/(\?|\&)currency_selected=[A-Z]{3}/", "", $this_uri); if (preg_match("/\?/", $this_uri)) { $this_uri.="¤cy_selected="; } else { $this_uri.="?currency_selected="; } $i=0; $currency_menu="\n"; $currency_menu="\n"; } function currency_menu() { // This function display the menu somewhere on the page global $currency_menu; echo $currency_menu; } function price($string) { // This function display a price and the converted equivalent global $currency_selected, $currency_rate, $currency_style; // find the current currency $cur_currency=preg_replace("/\s*\d+(\.\d*)?\s*/", "", $string); if ((! $cur_currency) || ($cur_currency == "$")) $cur_currency="USD"; preg_match("/\d+(\.\d*)?/", $string, $out); $value= $out[0]; $cur_currency=strtoupper($cur_currency); // do nothing if we have no currency selected if ((! $currency_selected) || ($cur_currency==$currency_selected)) { echo "$value $cur_currency"; return; } // compute the new value $new_value=$value; if ($cur_currency!="USD") { $new_value=$new_value/$currency_rate[$cur_currency]; } if ($currency_selected!="USD") { $new_value=$new_value*$currency_rate[$currency_selected]; } $new_value=round($new_value); echo "$value $cur_currency ($new_value $currency_selected)"; } ?>