. */ include("./include/include.php"); admin_header(); if( !in_array("currencies_view", $_SESSION['sess_functions']) ) { echoln("You are not authorized to see this page."); }else { echoln("

Currencies

"); if( in_array("currencies_edit", $_SESSION['sess_functions']) && isset($_REQUEST['cmd']) ) { $cmd = $_REQUEST['cmd']; }else { $cmd = ""; } if( $cmd=="new" ) { ########### ### New ### ########### $id = 0; $name = ""; $short = ""; $rate = "1"; }elseif( $cmd=="edit" ) { ################# ### Load data ### ################# $query = "SELECT `id`, `name`, `short`, `rate` FROM `currencies` WHERE `ISO_2`='' AND `id`=".get_int("id"); if( @mysql_num_rows( $res=doquery($query) )==1 ) { $row = mysql_fetch_array($res); $id = $row['id']; $name = $row['name']; $short = $row['short']; $rate = $row['rate']; }else { echoln("Failed loading entry, item does not exist.

"); $cmd = ""; } }elseif( $cmd=="save" ) { ################### ### Error check ### ################### $id = get_int("id"); $error = false; $errors = ""; $name = htmlentities(stripslashes($_POST['name']), ENT_NOQUOTES, "UTF-8"); if( strlen($name) < 1 || strlen($name) > 24 ) { $errors .= "

  • Please provide a name of maximum 24 characters.
  • "; $error = true; } $short = htmlentities(stripslashes($_POST['short']), ENT_NOQUOTES, "UTF-8"); if( strlen($short) < 1 || strlen($short) > 12 ) { $errors .= "
  • Please provide a short name of maximum 12 characters.
  • "; $error = true; } $rate = get_float('rate'); if( $rate === false ) { $errors .= "
  • Please provide a rate.
  • "; $error = true; } if( $errors!="" ) { echoln(""); } if( !$error ) { ################# ### Save data ### ################# if( $id>0 ) { // Update $query = "UPDATE `currencies` SET `name`='".addslashes($name)."', `short`='".addslashes($short)."', `rate`=".addslashes($rate); $query.= " WHERE `ISO_2`='' AND `id`=".addslashes($id); }else { // New $query = "INSERT INTO `currencies` (`name`, `short`, `rate`) "; $query.= "VALUES ('".addslashes($name)."', '".addslashes($short)."', ".addslashes($rate).")"; } if( doquery($query) ) { echoln("Entry saved successfully.

    "); }else { echoln("Failed saving entry, please try again.

    "); $cmd = "edit"; } }else { $cmd = "edit"; } }elseif( $cmd=="del" ) { ############## ### Delete ### ############## $query = "SELECT `id`, `name` FROM `currencies` WHERE `ISO_2`='' AND `id`=".addslashes(get_int("id")); if( @mysql_num_rows( $res=doquery($query) )==1 ) { $row = mysql_fetch_array($res); if( isset($_REQUEST['confirm']) ) { if( doquery("DELETE FROM `currencies` WHERE `id`=".addslashes($row['id'])) ) { echoln("Successfully removed '".$row['name']."'.

    "); }else { echoln("Failed removing '".$row['name']."', please try again.

    "); } $cmd = ""; }else { echoln("Are you sure you want to delete '".$row['name']."'?"); echoln("

    Yes   No

    "); } }else { echoln("Cannot delete entry, item does not exist.

    "); } } if( $cmd=="new" || $cmd=="edit" ) { ################# ### Show form ### ################# echoln("

    Back

    "); echoln("
    "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln("
    Name:
    Short name:
    Rate (1 unit = € ??):
    "); echoln("
      "); echoln("
    "); }elseif( $cmd != "del" ) { ################# ### Show list ### ################# echoln("

    Add currency

    "); $query = "SELECT `id`, `ISO_2`, `name`, `short`, `rate` FROM `currencies` ORDER BY `name`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { echoln(""); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); $i = 0; while( $row=mysql_fetch_array($res) ) { $i++; if( ($i%2)==1 ) echoln(" "); else echoln(" "); echoln(" "); echoln(" "); echoln(" "); if( $row['ISO_2'] == '' ) { echoln(" "); }else { echoln(" "); } echoln(" "); } echoln("
    NameShortRate 
    ".$row['name']."".$row['short']."".$row['rate']."edit   delete
    "); echoln("

    Rates that are not editable are automatically updated once per day from the site below.

    "); }else { echoln("There are no currencies to display at this moment."); } echoln("

    Info about exchange rates can be found at the site of the EC: http://ec.europa.eu/budget/contracts_grants/info_contracts/inforeuro/index_en.cfm

    "); } } admin_footer(); ?>