function db_GetValues($siteCode, $variableCode, $beginTime, $endTime, $methods)
 {
     $ci =& get_instance();
     $validMethods = array();
     //for every method, query the values
     $retVal = "<values>";
     foreach ($methods as $method) {
         //values shown in output
         $valuesShownForMethod = 0;
         //locate the file
         $methodCode = $method["MethodID"];
         $methodDescription = $method["MethodDescription"];
         //locate start row, end row
         $methodInfo = db_getMethodInfo($methodDescription);
         $beginRow = 0;
         if (isset($beginTime) && $beginTime != "") {
             $queryBeginYear = substr($beginTime, 0, 4);
             $queryBeginMonth = substr($beginTime, 5, 2);
             $beginRow = ($queryBeginYear - $methodInfo["beginYear"]) * 12 + ($queryBeginMonth - $methodInfo["beginMonth"]);
             $queryBeginDay = substr($beginTime, 8, 2);
             if ($queryBeginDay > 14) {
                 $beginRow = $beginRow + 1;
             }
         }
         $endRow = 12 * 300;
         if (isset($endTime) && $endTime != "") {
             $queryEndYear = substr($endTime, 0, 4);
             $queryEndMonth = substr($endTime, 5, 2);
             $endRow = ($queryEndYear - $methodInfo["beginYear"]) * 12 + ($queryEndMonth - $methodInfo["beginMonth"]);
             //check for day (db times are for 14th of the month)
             $queryEndDay = substr($endTime, 8, 2);
             if ($queryEndDay < 14) {
                 $endRow = $endRow - 1;
             }
         }
         //this needs to be changed on the server!
         $filepath = GetFilePath() . $siteCode . '/' . $siteCode . '-' . $methodDescription . '.csv';
         if (file_exists($filepath)) {
             $txt_file = file_get_contents($filepath);
             $rows = explode("\n", $txt_file);
             $rownum = 0;
             foreach ($rows as $row) {
                 if ($rownum >= $beginRow && $rownum <= $endRow) {
                     $row_data = explode(',', $row);
                     if (count($row_data) > 1) {
                         $datetime = substr($row_data[0], 0, -1);
                         $retVal .= '<value censorCode="nc" dateTime="' . $datetime . '"';
                         $retVal .= ' timeOffset="' . '0' . '" dateTimeUTC="' . $datetime . '"';
                         $retVal .= ' methodCode="' . $methodCode . '" ';
                         $retVal .= ' sourceCode="1" qualityControlLevelCode="1" ';
                         $dv = $row_data[1];
                         $retVal .= ">" . $dv . "</value>";
                         $valuesShownForMethod++;
                     }
                 }
                 $rownum++;
             }
         }
         if ($valuesShownForMethod > 0) {
             array_push($validMethods, $method);
         }
     }
     $retVal .= db_GetQualityControlLevelByID(1);
     foreach ($validMethods as $method) {
         $methodID = $method["MethodID"];
         $retVal .= '<method methodID="' . $methodID . '"><methodCode>' . $methodID . "</methodCode>";
         $retVal .= "<methodDescription>" . $method["MethodDescription"] . "</methodDescription>";
         $retVal .= "<methodLink>Unknown</methodLink>";
         $retVal .= "</method>";
     }
     $retVal .= db_GetSourceByID(1);
     $retVal .= "<censorCode><censorCode>nc</censorCode><censorCodeDescription>not censored</censorCodeDescription></censorCode>";
     $retVal .= "</values>";
     return $retVal;
 }
 function db_GetValues_MultipleSeries($siteID, $variableID, $arrMethod, $arrSource, $arrQC, $beginTime, $endTime)
 {
     $ci =& get_instance();
     $samples_table = get_table_name('Samples');
     $ci->db->select("d.LocalDateTime, d.UTCOffset, d.DateTimeUTC, d.MethodID, d.SourceID, d.QualityControlLevelID, d.DataValue, s.LabSampleCode");
     $ci->db->join($samples_table . " s", "d.SampleID = s.SampleID", "LEFT");
     $ci->db->where("d.SiteID", $siteID);
     $ci->db->where("d.VariableID", $variableID);
     $ci->db->order_by("d.LocalDateTime");
     if (isset($beginTime) && $beginTime != "" && (isset($endTime) && $endTime != "")) {
         $ci->db->where("d.LocalDateTime >=", $beginTime);
         $ci->db->where("d.LocalDateTime <=", $endTime);
     }
     $result = $ci->db->get(get_table_name('DataValues') . " d");
     if (!$result) {
         die("<p>Error in executing the SQL query " . $ci->db->last_query() . ": " . $ci->db->_error_message() . "</p>");
     }
     $retVal = "<values>";
     //$metadata = 'methodCode="' . $methodID . '" sourceCode="' . $sourceID . '" qualityControlLevelCode="' . $qcID . '"';
     foreach ($result->result_array() as $row) {
         $retVal .= '<value censorCode="nc" dateTime="' . $row["LocalDateTime"] . '"';
         $retVal .= ' timeOffset="' . $row["UTCOffset"] . '" dateTimeUTC="' . $row["DateTimeUTC"] . '"';
         $retVal .= ' methodCode="' . $row["MethodID"] . '" ';
         $retVal .= ' sourceCode="' . $row["SourceID"] . '" ';
         $retVal .= $row['LabSampleCode'] != '' ? 'labSampleCode="' . $row['LabSampleCode'] . '"' : '';
         $retVal .= ' qualityControlLevelCode="' . $row["QualityControlLevelID"] . '" ';
         $retVal .= ">" . $row["DataValue"] . "</value>";
     }
     foreach ($arrQC as $row) {
         $retVal .= db_GetQualityControlLevelByID($row);
     }
     foreach ($arrMethod as $row) {
         $retVal .= db_GetMethodByID($row);
     }
     foreach ($arrSource as $row) {
         $retVal .= db_GetSourceByID($row);
     }
     $retVal .= "<censorCode><censorCode>nc</censorCode><censorCodeDescription>not censored</censorCodeDescription></censorCode>";
     $retVal .= "</values>";
     return $retVal;
 }