예제 #1
0
 function GetLookupValues($sql, $ds, $df, $dlm)
 {
     global $ReportLanguage;
     $rsarr = array();
     $rowcnt = 0;
     $conn = ewr_Connect();
     if ($rs = $conn->Execute($sql)) {
         $rowcnt = $rs->RecordCount();
         $fldcnt = $rs->FieldCount();
         $rsarr = $rs->GetRows();
         $rs->Close();
     }
     $conn->Close();
     // Clean output buffer
     if (!EWR_DEBUG_ENABLED && ob_get_length()) {
         ob_end_clean();
     }
     // Output
     $key = array();
     $arr = array();
     if (is_array($rsarr) && $rowcnt > 0) {
         for ($i = 0; $i < $rowcnt; $i++) {
             $row = $rsarr[$i];
             if ($dlm != "") {
                 $cnt = 0;
                 for ($j = 0; $j < $fldcnt; $j++) {
                     if (strpos(strval($row[$j]), $dlm) !== FALSE) {
                         $row[$j] = explode($dlm, $row[$j]);
                         if (count($row[$j]) > $cnt) {
                             $cnt = count($row[$j]);
                         }
                     } else {
                         if ($cnt < 1) {
                             $cnt = 1;
                         }
                     }
                 }
             } else {
                 $cnt = 1;
             }
             for ($k = 0; $k < $cnt; $k++) {
                 $val0 = "";
                 $str0 = "";
                 $rec = array();
                 for ($j = 0; $j < $fldcnt; $j++) {
                     if ($dlm != "" && is_array($row[$j])) {
                         if (count($row[$j]) > $k) {
                             $val = $row[$j][$k];
                         } else {
                             $val = $row[$j][0];
                         }
                     } else {
                         $val = $row[$j];
                     }
                     if ($j == 0) {
                         $str = ewr_ConvertValue($ds, $val);
                         $val0 = $val;
                         $str0 = $str;
                     } elseif ($j == 1 && is_null($val0)) {
                         $str = $ReportLanguage->Phrase("NullLabel");
                     } elseif ($j == 1 && strval($val0) == "") {
                         $str = $ReportLanguage->Phrase("EmptyLabel");
                     } elseif ($j == 1) {
                         $str = ewr_DropDownDisplayValue(ewr_ConvertValue($ds, $val), $ds, $df);
                     } else {
                         $str = strval($val);
                     }
                     $str = ewr_ConvertToUtf8($str);
                     $rec[$j] = $str;
                 }
                 if (!in_array($str0, $key)) {
                     $arr[] = $rec;
                     $key[] = $str0;
                 }
             }
         }
     }
     echo ewr_ArrayToJson($arr);
 }
예제 #2
0
function ewr_GetDistinctValues($FldOpr, $sql, $dlm = "")
{
    global $conn;
    $ar = array();
    if (strval($sql) == "") {
        return;
    }
    $wrkrs = $conn->Execute($sql);
    if ($wrkrs) {
        while (!$wrkrs->EOF) {
            $wrkval = ewr_ConvertValue($FldOpr, $wrkrs->fields[0]);
            if ($dlm != "") {
                $arval = explode($dlm, $wrkval);
            } else {
                $arval = array($wrkval);
            }
            $cntar = count($arval);
            for ($i = 0; $i < $cntar; $i++) {
                $val = $arval[$i];
                if (!in_array($val, $ar)) {
                    $ar[] = $val;
                }
            }
            $wrkrs->MoveNext();
        }
    }
    if ($wrkrs) {
        $wrkrs->Close();
    }
    return $ar;
}