0)
{
$errs[] = "Sorry, current exchange direction is exists";
}
if ((isset($from_rate) && $from_rate != "" && !is_numeric($from_rate)) || (isset($to_rate) && $to_rate != "" && !is_numeric($to_rate)))
$errs[] = "Please enter correct exchange rate (numbers only)";
if (isset($fee) && $fee != "" && !is_numeric($fee))
$errs[] = "Please enter correct margin value";
/*if (isset($fee) && $fee != "" && !is_numeric($fee) && !strstr($fee, "%"))
$errs[] = "Please enter correct fee value";*/
if (isset($min_amount) && $min_amount != "" && !is_numeric($min_amount))
$errs[] = "Please enter correct minimum exchange value";
if (isset($max_amount) && $max_amount != "" && !is_numeric($max_amount))
$errs[] = "Please enter correct maximum exchange value";
if (isset($min_amount) && is_numeric($min_amount) && isset($max_amount) && is_numeric($max_amount) && $min_amount>$max_amount)
$errs[] = "Max exchange value cant be less than min value";
if ($auto_rate == 1)
{
$fsym = GetCurrencyCode($from_currency);
$tsyms = GetCurrencyCode($to_currency);
$url = "https://min-api.cryptocompare.com/data/price?fsym=".$fsym."&tsyms=".$tsyms;
$json = json_decode(file_get_contents($url), true);
if ($json["Response"] == "Error")
{
$errs[] = "Sorry, auto price update not available for these currencies";
}
}
}
if (count($errs) == 0)
{
$exchange_rate = $to_rate/$from_rate;
if ($auto_rate == 1) $updated_date = ", updated='2018-03-19 16:13:22'"; else $updated_date = ", updated=NOW()";
$insert_sql = "INSERT INTO exchangerix_exdirections SET from_currency='$from_currency', to_currency='$to_currency', from_rate='$from_rate', to_rate='$to_rate', exchange_rate='$exchange_rate', auto_rate='$auto_rate', fee='$fee', min_amount='$min_amount', max_amount='$max_amount', user_instructions='$instructions', description='$description', is_manual='$is_manual', hide_from_visitors='$hide_from_visitors', allow_affiliate='$allow_affiliate', sort_order='$sort_order', status='$status', added=NOW()".$updated_date; //user_id='0'
$result = smart_mysql_query($insert_sql);
$new_coupon_id = mysqli_insert_id($conn);
header("Location: exdirections.php?msg=added");
exit();
}
else
{
$errormsg = "";
foreach ($errs as $errorname)
$errormsg .= $errorname."
";
}
}
//////////////////////////////////////////////////
// delete ////////////////////////////////////////
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['action'] == "delete")
{
$did = (int)$_GET['id'];
//DeleteExDirection($did);
smart_mysql_query("DELETE FROM exchangerix_exdirections WHERE exdirection_id='$did'");
header("Location: exdirections.php?msg=deleted");
exit();
}
// results per page
if (isset($_GET['show']) && is_numeric($_GET['show']) && $_GET['show'] > 0)
$results_per_page = (int)$_GET['show'];
else
$results_per_page = 10;
// Update //
if (isset($_POST['update']) && $_POST['update'] != "")
{
$sorts_arr = array();
$sorts_arr = $_POST['from_rate'];
$from_rate = array();
$from_rate = $_POST['from_rate'];
$to_rate = array();
$to_rate = $_POST['to_rate'];
if (count($sorts_arr) > 0)
{
foreach ($sorts_arr as $k=>$v)
{
$new_from_rate = (float)$from_rate[$k];
$new_to_rate = (float)$to_rate[$k];
$up_query = "";
if ($new_from_rate > 0) $up_query .= "from_rate='".$new_from_rate."',";
if ($new_to_rate > 0) $up_query .= "to_rate='".$new_to_rate."',";
if ($new_to_rate > 0 && $new_to_rate > 0) { $exchange_rate = $new_to_rate/$new_from_rate; $up_query .= "exchange_rate='$exchange_rate',"; }elseif($new_to_rate == 0) { $up_query .= "status='inactive',"; }
smart_mysql_query("UPDATE exchangerix_exdirections SET $up_query sort_order='".(int)$v."' WHERE exdirection_id='".(int)$k."'");
}
}
header("Location: exdirections.php?msg=updated");
exit();
}
// Delete //
if (isset($_POST['delete']))
{
$ids_arr = array();
$ids_arr = $_POST['id_arr'];
if (count($ids_arr) > 0)
{
foreach ($ids_arr as $v)
{
$did = (int)$v;
smart_mysql_query("DELETE FROM exchangerix_exdirections WHERE exdirection_id='$did'");
//DeleteExDirection($did);
}
header("Location: exdirections.php?msg=deleted");
exit();
}
}
$where = "1=1";
////////////////// filter //////////////////////
if (isset($_GET['column']) && $_GET['column'] != "")
{
switch ($_GET['column'])
{
case "title": $rrorder = "title"; break;
case "sort_order": $rrorder = "sort_order"; break;
case "added": $rrorder = "added"; break;
case "last_visit": $rrorder = "last_visit"; break;
case "auto_rate": $rrorder = "auto_rate"; break;
case "total_exchanges": $rrorder = "total_exchanges"; break;
case "today_exchanges": $rrorder = "today_exchanges"; break;
case "visists": $rrorder = "visits"; break;
case "status": $rrorder = "status"; break;
default: $rrorder = "sort_order"; break;
}
}
else
{
$rrorder = "sort_order";
}
if (isset($_GET['order']) && $_GET['order'] != "")
{
switch ($_GET['order'])
{
case "asc": $rorder = "asc"; break;
case "desc": $rorder = "desc"; break;
default: $rorder = "asc"; break;
}
}
else
{
$rorder = "asc";
}
if (isset($_GET['filter']) && $_GET['filter'] != "")
{
$filter = mysqli_real_escape_string($conn, trim(getGetParameter('filter')));
$where .= " AND (title LIKE '%$filter%' OR code LIKE '%$filter%') ";
$totitle = " - Search Results";
}
///////////////////////////////////////////////////////
if (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0) { $page = (int)$_GET['page']; } else { $page = 1; }
$from = ($page-1)*$results_per_page;
/*
if (isset($_GET['store']) && $_GET['store'] != "")
{
$store = substr(trim(getGetParameter('store')), 0, 10);
$store = mysqli_real_escape_string($conn, $store); //dev
//$where .= " AND currency_code='$store' ";
$title2 = $store;
}*/
if (isset($_GET['from_filter']) && is_numeric($_GET['from_filter']))
{
$from_filter = (int)$_GET['from_filter'];
$where .= " AND from_currency='$from_filter' ";
$title2 .= " ".GetCurrencyName($from_filter)." ";
}
if (isset($_GET['to_filter']) && is_numeric($_GET['to_filter']))
{
$to_filter = (int)$_GET['to_filter'];
$where .= " AND to_currency='$to_filter' ";
$title2 .= " ".GetCurrencyName($to_filter);
}
$query = "SELECT *, TIMESTAMPDIFF(MINUTE,updated,NOW()) AS last_update_mins, DATE_FORMAT(added, '".DATE_FORMAT."') AS date_added FROM exchangerix_exdirections WHERE $where ORDER BY $rrorder $rorder, added DESC LIMIT $from, $results_per_page";
$result = smart_mysql_query($query);
$total_on_page = mysqli_num_rows($result);
$query2 = "SELECT * FROM exchangerix_exdirections WHERE ".$where;
$result2 = smart_mysql_query($query2);
$total = mysqli_num_rows($result2);
$cc = 0;
//$title = $title2." Exchange Directions";
$title = "Exchange Directions";
require_once ("inc/header.inc.php");
?>