2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Separated get_time_zone from number as a function

This commit is contained in:
root
2013-09-11 12:54:35 +10:00
parent da87c070b9
commit e43ce5c8e7

View File

@@ -277,38 +277,14 @@ function import_file($file, $description, $fields, $firstrow = 2)
*
*/
foreach($selected_type as $key => $val)
{
$sql = "SELECT `table`
FROM sample_var_type
WHERE type = '$val'";
$tname = $db->GetRow($sql);
if (!empty($tname))
{
$tz = get_time_zone($data[$key - 1],$val);
if ($tz !== false)
{
$tname = $tname['table'];
if (!empty($tname))
{
$value = $db->Quote($data[$key - 1]);
$sql = "SELECT Time_zone_name as tz
FROM `$tname`
WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) )";
$tz = $db->GetRow($sql);
//print("$sql<br/>");
//if ($db->HasFailedTrans()) { print "FAILED"; exit(); }
if (!empty($tz))
{
$tzone = $tz['tz'];
break;
}
}
}
$tzone = $tz;
break;
}
}
@@ -356,5 +332,41 @@ function import_file($file, $description, $fields, $firstrow = 2)
}
/**
* Get the timezone given the sample value and type
*
* @param string $value A sample value
* @param integer $type The type of sample var (see sample_var_type table)
*
* @return string|bool Return the timezone name or false if not found
*/
function get_time_zone($value,$type)
{
global $db;
$sql = "SELECT `table`
FROM sample_var_type
WHERE type = '$type'";
$tname = $db->GetOne($sql);
if (!empty($tname))
{
$value = $db->Quote($value);
$sql = "SELECT Time_zone_name as tz
FROM `$tname`
WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) )";
$tz = $db->GetOne($sql);
if (!empty($tz))
{
return $tz;
}
}
return false;
}
?>