$_SESSION[$sessPrefix . "_order"] = $strOrderBy;
}

//	select all records

 $strSQLbak = $strSQL;

if (is_wr_db()) {
    $strSQL = $rpt_array['sql'] . $rpt_array['where'] . $rpt_array['order_by'];
} elseif (is_wr_project()) {
    $strSQL = $gQuery->gSQLWhere($strWhereClause);
    $strSQL .= " " . trim($strOrderBy);
} elseif (is_wr_custom()) {
    if (GetDatabaseType() != 1) {
	$sqlquery = $rpt_array['sql'];
	if (GetDatabaseType() == 2) { //MSSQLServer
	    $pos = strrpos(strtoupper($sqlquery), "ORDER BY");
	    if ($pos)
		$sqlquery = substr($sqlquery, 0, $pos);
	}
	$strSQL = "select * from (" . $sqlquery . ") as " . AddFieldWrappers("t") . " " . $rpt_array['where'] . $rpt_array['order_by'];
    } else
	$strSQL = "select * from (" . $rpt_array['sql'] . ")" . $rpt_array['where'] . $rpt_array['order_by'];
}
$grid_row = array();
if ($cross_table != "true") {
    $groupno = 0;
    if (!$_SESSION[$sessPrefix . "_pagenumber"]) {
	$_SESSION[$sessPrefix . "_pagenumber"] = 1;
    }
Beispiel #2
0
function GenericStrWhereAdv($strTable, $strField, $SearchFor, $strSearchOption, $SearchFor2, $etype)
{
    global $dal;
    $sfield = $strField;
    $stable = "";
    if (is_wr_db()) {
        WRSplitFieldName($strField, $stable, $sfield);
        $type = WRGetFieldType($strField);
    } else {
        $type = WRCustomGetFieldType($strTable, $strField);
    }
    if (GetDatabaseType() != nDATABASE_MSSQLServer) {
        $ismssql = false;
    } else {
        $ismssql = true;
    }
    $btexttype = IsTextType($type);
    if (GetDatabaseType() == nDATABASE_MySQL) {
        $btexttype = false;
    }
    if (IsBinaryType($type)) {
        return "";
    }
    if (GetDatabaseType() == nDATABASE_MSSQLServer) {
        if ($btexttype && $strSearchOption != "Contains" && $strSearchOption != "Starts with ...") {
            return "";
        }
    }
    if ($strSearchOption == 'Empty') {
        if (IsCharType($type) && (!$ismssql || !$btexttype)) {
            return "(" . WRAddFieldWrappers($strField) . " is null or " . WRAddFieldWrappers($strField) . "='')";
        } elseif ($ismssql && $btexttype) {
            return "(" . WRAddFieldWrappers($strField) . " is null or " . WRAddFieldWrappers($strField) . " LIKE '')";
        } else {
            return WRAddFieldWrappers($strField) . " is null";
        }
    }
    if (GetDatabaseType() == nDATABASE_PostgreSQL) {
        $like = "ilike";
    } else {
        $like = "like";
    }
    if (GetGenericEditFormat($strTable, $sfield) == EDIT_FORMAT_LOOKUP_WIZARD) {
        $pSet = new ProjectSettings($strTable);
        if ($pSet->multiSelect($sfield)) {
            $SearchFor = splitvalues($SearchFor);
        } else {
            $SearchFor = array($SearchFor);
        }
        $ret = "";
        foreach ($SearchFor as $searchItem) {
            $value = $searchItem;
            if (!($value == "null" || $value == "Null" || $value == "")) {
                if (strlen($ret)) {
                    $ret .= " or ";
                }
                if ($strSearchOption == "Equals") {
                    $value = WRmake_db_value($sfield, $value, $strTable);
                    if (!($value == "null" || $value == "Null")) {
                        $ret .= WRAddFieldWrappers($strField) . '=' . $value;
                    }
                } else {
                    $connection = getWebreportConnection();
                    if (strpos($value, ",") !== false || strpos($value, '"') !== false) {
                        $value = '"' . str_replace('"', '""', $value) . '"';
                    }
                    $ret .= WRAddFieldWrappers($strField) . " = " . $connection->prepareString($value);
                    $ret .= " or " . WRAddFieldWrappers($strField) . " " . $like . " " . $connection->prepareString("%," . $value . ",%");
                    $ret .= " or " . WRAddFieldWrappers($strField) . " " . $like . " " . $connection->prepareString("%," . $value);
                    $ret .= " or " . WRAddFieldWrappers($strField) . " " . $like . " " . $connection->prepareString($value . ",%");
                }
            }
        }
        if (strlen($ret)) {
            $ret = "(" . $ret . ")";
        }
        return $ret;
    }
    if (GetGenericEditFormat($strTable, $sfield) == EDIT_FORMAT_CHECKBOX) {
        if ($SearchFor == "none") {
            return "";
        }
        if (NeedQuotes($type)) {
            if ($SearchFor == "on") {
                return "(" . WRAddFieldWrappers($strField) . "<>'0' and " . WRAddFieldWrappers($strField) . "<>'' and " . WRAddFieldWrappers($strField) . " is not null)";
            } else {
                return "(" . WRAddFieldWrappers($strField) . "='0' or " . WRAddFieldWrappers($strField) . "='' or " . WRAddFieldWrappers($strField) . " is null)";
            }
        } else {
            if ($SearchFor == "on") {
                return "(" . WRAddFieldWrappers($strField) . "<>0 and " . WRAddFieldWrappers($strField) . " is not null)";
            } else {
                return "(" . WRAddFieldWrappers($strField) . "=0 or " . WRAddFieldWrappers($strField) . " is null)";
            }
        }
    }
    $value1 = WRmake_db_value($sfield, $SearchFor, $strTable);
    $value2 = false;
    if ($strSearchOption == "Between") {
        $value2 = WRmake_db_value($sfield, $SearchFor2, $strTable);
    }
    if ($strSearchOption != "Contains" && $strSearchOption != "Starts with ..." && ($value1 === "null" || $value2 === "null")) {
        return "";
    }
    $connection = getWebreportConnection();
    if (IsCharType($type) && !$btexttype) {
        $value1 = $connection->upper($value1);
        $value2 = $connection->upper($value2);
        $strField = $connection->upper(WRAddFieldWrappers($strField));
    } elseif ($ismssql && !$btexttype && ($strSearchOption == "Contains" || $strSearchOption == "Starts with ...")) {
        $strField = "convert(varchar," . WRAddFieldWrappers($strField) . ")";
    } elseif (GetDatabaseType() == nDATABASE_PostgreSQL && !$btexttype && ($strSearchOption == "Contains" || $strSearchOption == "Starts with ...")) {
        $strField = "CAST(" . WRAddFieldWrappers($strField) . " AS TEXT)";
    } else {
        $strField = WRAddFieldWrappers($strField);
    }
    $ret = "";
    if ($strSearchOption == "Contains") {
        if (IsCharType($type) && !$btexttype) {
            return $strField . " " . $like . " " . $connection->upper($connection->prepareString("%" . $SearchFor . "%"));
        } else {
            return $strField . " " . $like . " " . $connection->prepareString("%" . $SearchFor . "%");
        }
    } else {
        if ($strSearchOption == "Equals") {
            return $strField . "=" . $value1;
        } else {
            if ($strSearchOption == "Starts with ...") {
                if (IsCharType($type) && !$btexttype) {
                    return $strField . " " . $like . " " . $connection->upper($connection->prepareString($SearchFor . "%"));
                } else {
                    return $strField . " " . $like . " " . $connection->prepareString($SearchFor . "%");
                }
            } else {
                if ($strSearchOption == "More than ...") {
                    return $strField . ">" . $value1;
                } else {
                    if ($strSearchOption == "Less than ...") {
                        return $strField . "<" . $value1;
                    } else {
                        if ($strSearchOption == "Equal or more than ...") {
                            return $strField . ">=" . $value1;
                        } else {
                            if ($strSearchOption == "Equal or less than ...") {
                                return $strField . "<=" . $value1;
                            } else {
                                if ($strSearchOption == "Between") {
                                    $ret = $strField . ">=" . $value1;
                                    $ret .= " and " . $strField . "<=" . $value2;
                                    return $ret;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return "";
}
			{
				$strSQL = AddRowNumber($strSQL, $mypage*$PageSize);
			}
			$rs = db_query($strSQL,$conn);
			db_pageseek($rs,$PageSize,$mypage);
		}
		elseif(GetDatabaseType() == 4)
		{
			if($numrows)
			{
				$maxrecs=$PageSize;
				$strSQL.=" limit ".$PageSize." offset ".(($mypage-1)*$PageSize);
			}
			$rs = db_query($strSQL,$conn);
		}
		elseif(GetDatabaseType() == -1)
		{
			if($numrows)
			{
				$strSQL = AddLimitFirebird($strSQL, (($mypage-1)*$PageSize), $PageSize);
			}
			$rs = db_query($strSQL,$conn);
			db_pageseek($rs,$PageSize,$mypage);
		}
		else
		{
			$rs = db_query($strSQL,$conn);
			db_pageseek($rs,$PageSize,$mypage);
		}
	}
	
Beispiel #4
0
function make_from_clause($type)
{
    global $cman;
    $accessMode = GetDatabaseType() == nDATABASE_Access;
    $root =& $_SESSION[$type];
    $_connection = $cman->getForWebReports();
    if (is_wr_project()) {
        $_connection = $cman->byTable($root['tables'][0]);
    }
    $ret = $_connection->AddTableWrappers($root['tables'][0]);
    $fullouter = "";
    $firstJoin = true;
    if (is_array($root["table_relations"]["relat"])) {
        foreach ($root["table_relations"]["relat"] as $r) {
            if (trim($r["rel_type"]) == "FULL OUTER JOIN") {
                $fullouter .= "\n," . $_connection->AddTableWrappers($r["right_table"]);
                continue;
            }
            if ($accessMode && !$firstJoin) {
                $ret = "(" . $ret . ")";
            }
            $firstJoin = false;
            $ret .= "\n" . $r["rel_type"] . " " . $_connection->AddTableWrappers($r["right_table"]) . " ON ";
            $joinon = "";
            foreach ($r["left_fields"] as $i => $f) {
                if (strlen($joinon)) {
                    $joinon .= " AND ";
                }
                $joinon .= $_connection->AddTableWrappers($r["left_table"]) . "." . $_connection->AddFieldWrappers($r["left_fields"][$i]);
                $joinon .= "=";
                $joinon .= $_connection->AddTableWrappers($r["right_table"]) . "." . $_connection->AddFieldWrappers($r["right_fields"][$i]);
            }
            $ret .= $joinon;
        }
    }
    return "FROM " . $ret . $fullouter;
}
			elseif(is_array($val))
			{
				$res_body .= '<td><span></span></td>';
				continue;
			}
			$s=$val;
			if(strlen($s)>100)
				$s=substr($s,0,100);
			$res_body .= '<td><span>' . runner_htmlspecialchars($s) . '</span></td>';
		}
		$res_body .= '</tr>';
		$flag=false;
	}
	if(!IsStoredProcedure($sql_query_all))
	{
		if(GetDatabaseType()!=1) //Oracle
			$rs=db_query("select count(*) from (".$sql_query_all.") as t",$conn);
		else
			$rs=db_query("select count(*) from (".$sql_query_all.")",$conn);
		$total_rows=0;
		if($data=db_fetch_numarray($rs))
			$total_rows=$data[0];
	}
	if($i>0)
	{
		if(!IsStoredProcedure($sql_query))
		{
			if(postvalue("sql")=="makesql")
			{
				$result="<div><b>".$total_rows."</b> records";
				if($total_rows>50)
	function EditControl($field, $pageObject, $id)
	{
		$this->field = $field;
		$this->goodFieldName = GoodFieldName($field);
		$this->setID($id);

		$this->pageObject = $pageObject;

		$this->is508 = isEnableSection508();
		
		$this->strLabel = $pageObject->pSetEdit->label($field);
		$this->type = $pageObject->pSetEdit->getFieldType($this->field);
		
		if(GetDatabaseType() == 1)
				$this->isOracle = true;
		if(GetDatabaseType() == 2)
				$this->ismssql=true;
		if(GetDatabaseType() == 0)
				$this->isMysql = true;
		if(GetDatabaseType() == 4)
				$this->like = "ilike";

		$this->searchOptions[CONTAINS] = "Contains";
		$this->searchOptions[EQUALS] = "Equals";
		$this->searchOptions[STARTS_WITH] = "Starts with";
		$this->searchOptions[MORE_THAN] = "More than";
		$this->searchOptions[LESS_THAN] = "Less than";
		$this->searchOptions[BETWEEN] = "Between";
		$this->searchOptions[EMPTY_SEARCH] = "Empty";
		$this->searchOptions[NOT_CONTAINS] = "Doesn't contain";
		$this->searchOptions[NOT_EQUALS] = "Doesn't equal";
		$this->searchOptions[NOT_STARTS_WITH] = "Doesn't start with";
		$this->searchOptions[NOT_MORE_THAN] = "Is not more than";
		$this->searchOptions[NOT_LESS_THAN] = "Is not less than";
		$this->searchOptions[NOT_BETWEEN] = "Is not between";
		$this->searchOptions[NOT_EMPTY] = "Is not empty";
		
		$this->init();
	}
Beispiel #7
0
 function getCharTypeInterval($field, $int_type)
 {
     $field = AddFieldWrappers($this->CrossGoodFieldName($field));
     switch (GetDatabaseType()) {
         case 0:
             return array("left(" . $field . "," . $int_type . ")", "left(" . $field . "," . $int_type . ")");
             //MySQL
             break;
         case 1:
             return array("substr(" . $field . ",1," . $int_type . ")", "substr(" . $field . ",1," . $int_type . ")");
             //Oracle
             break;
         case 2:
             return array("left(" . $field . "," . $int_type . ")", "left(" . $field . "," . $int_type . ")");
             //MSSSQL
             break;
         case 3:
             return array("left(" . $field . "," . $int_type . ")", "left(" . $field . "," . $int_type . ")");
             //MS Access
             break;
         case 4:
             return array("substring(" . $field . " from 1 for " . $int_type . ")", "substring(" . $field . " from 1 for " . $int_type . ")");
             //Postgree
             break;
         case 5:
             return array("substring(" . $field . " from 1 for " . $int_type . ")", "substring(" . $field . " from 1 for " . $int_type . ")");
             //Informix
             break;
         case 6:
             return array("substr(" . $field . ",1," . $int_type . ")", "substr(" . $field . ",1," . $int_type . ")");
             //SQLite3
             break;
         case 7:
             return array("substr(" . $field . ",1," . $int_type . ")", "substr(" . $field . ",1," . $int_type . ")");
             //DB2
             break;
     }
 }
function ImportFromCSV($uploadfile, $strOriginalTableName, $ext, $keys, &$keys_present, &$total_records, &$error_message, &$goodlines, $pageObject, $cipherer)
{	
	global $conn, $gSettings;

	$ret = 1;

	$fields = array();
	
	$fields = getImportCVSFields($uploadfile);
	
	// populate field names array
	for ($j=0;$j<count($fields);$j++)
	{
		$fields[$j] = $fields[$j];
		if(substr($fields[$j],0,1)=="\"" && substr($fields[$j],-1)=="\"")
			$fields[$j]=substr($fields[$j],1,-1);
	}
	$fields = getFieldNamesByHeaders($fields, $strOriginalTableName, $ext);

	if($fields == null) // if error happened
		return;
	
	$keys_present=1;
	for($k=0; $k<count($keys); $k++)
	{
		if (!in_array(RemoveFieldWrappers($keys[$k]),$fields))
		{
			$keys_present=0;
			break;
		}
	}
	$autoinc = false;
		if(in_array("id",$fields))
		$autoinc=true;
				
		
	
	
	if(GetDatabaseType() == 2 && $autoinc)
{
	$sql="SET IDENTITY_INSERT ".AddTableWrappers($strOriginalTableName)." ON";
	db_exec($sql,$conn);
}
$total_records = 0;
	$line = "";		
	$row = 0;
	// parse records from file
	if (($handle = OpenCSVFile($uploadfile)) !== FALSE) 
	{
	    while (($data = GetCSVLine($handle, 1000000, ",")) !== FALSE) 
	    {
	    				// first rec contain only fields names	    	
	    	if ($row === 0)
	    	{
	    		$row++;
	    		continue;	    		
	    	}
	    	$arr = array();
			foreach($data as $key=>$val)
			{
				$type = $gSettings->getFieldType($fields[$key]);
				if(IsDateFieldType($type))
				{
					$value = localdatetime2db($val);
					if ( $value !== FALSE && strlen($value) && $value != 'null' )
						$arr[$fields[$key]] = $value;
					else
						$arr[$fields[$key]] = NULL;
				}
				elseif(IsTimeType($type))
				{
					$value = localtime2db($val);
					if ( $value !== FALSE && strlen($value) && !is_null($val) && strlen($val) )
						$arr[$fields[$key]] = $value;
					else
						$arr[$fields[$key]] = NULL;
				}
				else
					$arr[$fields[$key]] = $val;
			}
			
	    	$ret = InsertRecord($arr, $row, $error_message, $goodlines, $keys, $keys_present, 
	    		$strOriginalTableName, $pageObject, $cipherer, $autoinc);
	        $row++;
	    }
	    CloseCSVFile($handle);
	}
	
$total_records = $row-1;
if(GetDatabaseType() == 2 && $autoinc)
{
	$sql="SET IDENTITY_INSERT ".AddTableWrappers($strOriginalTableName)." OFF";
	db_exec($sql,$conn);
}
	
	
	
		
	return $ret;	
} 
Beispiel #9
0
 function Chart(&$ch_array, $param)
 {
     global $field_labels;
     if ($this->webchart) {
         $this->chrt_array = Convert_Old_Chart($ch_array);
     } else {
         $this->chrt_array = $ch_array;
     }
     $this->pSet = new ProjectSettings($this->chrt_array['tables'][0]);
     $this->chrt_array["appearance"]["autoupdate"] = false;
     $this->numRecordsToShow = $this->chrt_array['appearance']['maxbarscroll'];
     if ($this->numRecordsToShow < 1) {
         $this->numRecordsToShow = 1;
     }
     $this->table_type = $this->chrt_array["table_type"];
     if (!$this->table_type) {
         $this->table_type = "project";
     }
     $this->webchart = $param["webchart"];
     $this->cname = $param["cname"];
     $this->sessionPrefix = $this->chrt_array['tables'][0];
     $this->gstrOrderBy = $param["gstrOrderBy"];
     $TableName = GoodFieldName($this->chrt_array['tables'][0]);
     $this->cipherer = new RunnerCipherer($this->chrt_array['tables'][0]);
     $this->header = $this->chrt_array['appearance']['head'];
     $this->footer = $this->chrt_array['appearance']['foot'];
     $this->y_axis_label = $this->chrt_array['appearance']['y_axis_label'];
     for ($i = 0; $i < count($this->chrt_array['parameters']) - 1; $i++) {
         if (isset($this->chrt_array['parameters'][$i]['currencyFormat'])) {
             $this->arrFormatCurrency[] = $this->chrt_array['parameters'][$i]['currencyFormat'];
         } else {
             if ($this->chrt_array['appearance']['scur'] == "false") {
                 $this->arrFormatCurrency[] = "";
             } else {
                 $this->arrFormatCurrency[] = $this->chrt_array['appearance']['scur'];
             }
         }
         if (isset($this->chrt_array['parameters'][$i]['decimalFormat'])) {
             $this->arrFormatDecimal[] = $this->chrt_array['parameters'][$i]['decimalFormat'];
         } else {
             $this->arrFormatDecimal[] = $this->chrt_array['appearance']['dec'];
         }
         $this->arrFormatCustomer[] = $this->chrt_array['parameters'][$i]['customFormat'];
         $this->arrFormatCustomerStr[] = $this->chrt_array['parameters'][$i]['customFormatStr'];
         if ($this->chrt_array["chart_type"]["type"] == "ohlc" || $this->chrt_array["chart_type"]["type"] == "candlestick") {
             $this->arrOHLC_open[] = $this->chrt_array['parameters'][$i]['ohlcOpen'];
             $this->arrOHLC_high[] = $this->chrt_array['parameters'][$i]['ohlcHigh'];
             $this->arrOHLC_low[] = $this->chrt_array['parameters'][$i]['ohlcLow'];
             $this->arrOHLC_close[] = $this->chrt_array['parameters'][$i]['ohlcClose'];
             $this->arrOHLC_color[] = "#" . $this->chrt_array['parameters'][$i]['ohlcColor'];
             if ($this->chrt_array["chart_type"]["type"] == "candlestick") {
                 $this->arrOHLC_candle[] = "#" . $this->chrt_array['parameters'][$i]['ohlcCandleColor'];
             }
         } elseif ($this->chrt_array['parameters'][$i]['name'] != "") {
             if ($this->table_type != "db") {
                 $this->arrDataSeries[] = $this->chrt_array['parameters'][$i]['agr_func'] ? $this->chrt_array['parameters'][$i]['label'] : $this->chrt_array['parameters'][$i]['name'];
             } else {
                 $this->arrDataSeries[] = $this->chrt_array['parameters'][$i]['agr_func'] ? $this->chrt_array['parameters'][$i]['table'] . "_" . $this->chrt_array['parameters'][$i]['label'] : $this->chrt_array['parameters'][$i]['table'] . "_" . $this->chrt_array['parameters'][$i]['name'];
             }
             if (isset($this->chrt_array['appearance']['scolor' . ($i + 1) . '1'])) {
                 $this->arrDataColor[] = $this->chrt_array['appearance']['scolor' . ($i + 1) . '1'];
             } else {
                 $this->arrDataColor[] = $this->chrt_array['parameters'][$i]['series_color'];
             }
             if ($this->chrt_array["chart_type"]["type"] == "bubble") {
                 $this->arrDataSize[] = $this->chrt_array['parameters'][$i]['size'];
             }
             if ($this->chrt_array["chart_type"]["type"] == "gauge") {
                 for ($k = 0; is_array($this->chrt_array["parameters"][$i]["gaugeColorZone"]) && $k < count($this->chrt_array["parameters"][$i]["gaugeColorZone"]); $k++) {
                     $beginColor = (double) @$this->chrt_array["parameters"][$i]["gaugeColorZone"][$k]["gaugeBeginColor"];
                     $endColor = (double) @$this->chrt_array["parameters"][$i]["gaugeColorZone"][$k]["gaugeEndColor"];
                     $gColor = "#" . @$this->chrt_array["parameters"][$i]["gaugeColorZone"][$k]["gaugeColor"];
                     $this->arrGaugeColor[count($this->arrDataSeries) - 1][] = array($beginColor, $endColor, $gColor);
                 }
             }
         }
         if ($this->table_type == "project" && !$this->webchart) {
             $this->arrDataLabels[] = $this->chart_xmlencode(GetFieldLabel(GoodFieldName($TableName), GoodFieldName($this->chrt_array['parameters'][$i]['name'])));
         } else {
             if (!$this->chart_xmlencode($this->chrt_array['parameters'][$i]['label'])) {
                 $this->arrDataLabels[] = $this->chart_xmlencode($this->chrt_array['parameters'][$i]['name']);
             } else {
                 $this->arrDataLabels[] = $this->chart_xmlencode($this->chrt_array['parameters'][$i]['label']);
             }
         }
     }
     if ($this->chrt_array["chart_type"]["type"] != "gauge") {
         if ($this->table_type != "db") {
             $this->strLabel = $this->chrt_array['parameters'][count($this->chrt_array['parameters']) - 1]['name'];
         } else {
             $this->strLabel = $this->chrt_array['parameters'][count($this->chrt_array['parameters']) - 1]['table'] . "_" . $this->chrt_array['parameters'][count($this->chrt_array['parameters']) - 1]['name'];
         }
         for ($j = 0; $j < count($this->chrt_array['fields']); $j++) {
             if ($this->chrt_array['parameters'][count($this->chrt_array['parameters']) - 1]['name'] == $this->chrt_array['fields'][$j]['name']) {
                 if ($this->table_type == "project") {
                     $this->label2 = $this->chart_xmlencode(GetFieldLabel($TableName, GoodFieldName($this->chrt_array['parameters'][count($this->chrt_array['parameters']) - 1]['name'])));
                 } else {
                     $this->label2 = $this->chart_xmlencode($this->chrt_array['parameters'][count($this->chrt_array['parameters']) - 1]['name']);
                 }
             }
         }
     }
     if ($this->chrt_array["chart_type"]["type"] != "ohlc" && $this->chrt_array["chart_type"]["type"] != "candlestick") {
         foreach ($this->arrDataColor as $ind => $val) {
             if ($ind == 0) {
                 $this->arrAxesColor = "#000000";
             } else {
                 $this->arrAxesColor = "#" . $this->arrDataColor[$ind];
             }
         }
     } else {
         foreach ($this->arrOHLC_color as $ind => $val) {
             if ($ind == 0) {
                 $this->arrAxesColor = "#000000";
             } else {
                 $this->arrAxesColor = "#" . $this->arrOHLC_color[$ind];
             }
         }
     }
     // prepare search params
     $gQuery = $this->pSet->getSQLQuery();
     $strWhereClause = "";
     $searchHavingClause = "";
     $strSearchCriteria = "and";
     global $strTableName;
     // search where for basic charts
     if (!$this->webchart) {
         if (isset($_SESSION[$this->sessionPrefix . '_advsearch'])) {
             $searchClauseObj = unserialize($_SESSION[$this->sessionPrefix . '_advsearch']);
             include_once getabspath('classes/controls/EditControlsContainer.php');
             $editControls = new EditControlsContainer(null, $this->pSet, PAGE_REPORT, $this->cipherer);
             $strWhereClause = $searchClauseObj->getWhere($this->pSet->getListOfFieldsByExprType(false), $editControls);
             $searchHavingClause = $searchClauseObj->getWhere($this->pSet->getListOfFieldsByExprType(true), $editControls);
             $strSearchCriteria = @$_SESSION[$strTableName . "_criteria"];
             if ($searchClauseObj->isUsedSearchFor && !$searchClauseObj->isUsedFieldsForSearch) {
                 $strSearchCriteria = "or";
             }
         }
     } else {
         if ($this->table_type != "project") {
             $strTableName = "webchart" . $this->cname;
         }
         $strWhereClause = CalcSearchParam($this->table_type != "project");
     }
     if ($strWhereClause) {
         $this->chrt_array['where'] .= $this->chrt_array['where'] ? " AND (" . $strWhereClause . ")" : " WHERE (" . $strWhereClause . ")";
     }
     if ($this->table_type == "project") {
         if (SecuritySQL("Search")) {
             $strWhereClause = whereAdd($strWhereClause, SecuritySQL("Search"));
         }
         $this->strSQL = $gQuery->gSQLWhere($strWhereClause, $searchHavingClause, $strSearchCriteria);
         $strOrderBy = $this->gstrOrderBy;
         $this->strSQL .= " " . $strOrderBy;
         $strSQLbak = $this->strSQL;
         if (tableEventExists("BeforeQueryChart", $strTableName)) {
             $tstrSQL = $this->strSQL;
             $eventObj = getEventObject($strTableName);
             $eventObj->BeforeQueryChart($tstrSQL, $strWhereClause, $strOrderBy);
             $this->strSQL = $tstrSQL;
         }
         if ($strSQLbak == $this->strSQL) {
             $this->strSQL = $gQuery->gSQLWhere($strWhereClause, $searchHavingClause, $strSearchCriteria);
             $this->strSQL .= " " . $strOrderBy;
         }
     }
     if ($this->cname && $this->table_type == "db") {
         $this->strSQL = $this->chrt_array['sql'] . $this->chrt_array['where'] . $this->chrt_array['group_by'] . $this->chrt_array['order_by'];
     } elseif ($this->cname && $this->table_type == "custom") {
         if (!IsStoredProcedure($this->chrt_array['sql'])) {
             $sql_query = $this->chrt_array['sql'];
             if (GetDatabaseType() == 2) {
                 $pos = strrpos(strtoupper($sql_query), "ORDER BY");
                 if ($pos) {
                     $sql_query = substr($sql_query, 0, $pos);
                 }
             }
             if (GetDatabaseType() != 1) {
                 //Oracle
                 $this->strSQL = "select * from (" . $sql_query . ") as " . AddFieldWrappers("custom_query") . $this->chrt_array['where'];
             } else {
                 $this->strSQL = "select * from (" . $sql_query . ")" . $this->chrt_array['where'];
             }
         } else {
             $this->strSQL = $this->chrt_array['sql'];
         }
     }
     if (tableEventExists("UpdateChartSettings", $strTableName)) {
         $eventObj = getEventObject($strTableName);
         $eventObj->UpdateChartSettings($this);
     }
 }
	function getNextPrevRecordKeys(&$data,$securityMode,&$next,&$prev)
	{
		global $conn;
		$next=array();
		$prev=array();
	
		if(@$_SESSION[$this->sessionPrefix."_noNextPrev"])
			return;
		$prevExpr = "";
		$nextExpr = "";
		$where_next="";
		$where_prev="";
		$order_next="";
		$order_prev="";

		require_once(getabspath('classes/orderclause.php'));
		$orderClause = new OrderClause($this);
		$orderClause->init();

		$query = $this->pSet->getQueryObject();
		
		$where = $_SESSION[$this->sessionPrefix."_where"];
		if(!strlen($where))
			$where = SecuritySQL($securityMode);
		$having = $_SESSION[$this->sessionPrefix."_having"];
		
		$joinFromPart = $_SESSION[$this->sessionPrefix."_joinFromPart"];
		
		$tKeys = $this->pSet->getTableKeys();

		if(!count($orderClause->fieldsList))
		{
			$_SESSION[$this->sessionPrefix."_noNextPrev"] = 1;
			return;
		}
		//	make  next & prev ORDER BY strings
		for($i = 0; $i < count($orderClause->fieldsList); $i++)
		{
			$field = $orderClause->fieldsList[$i];
			if(!$this->pSet->GetFieldByIndex($field->fieldIndex))
				continue;
			if($order_next == "")
			{
				$order_next = " ORDER BY ";
				$order_prev = " ORDER BY ";
			}
			else
			{
				$order_next .= ",";
				$order_prev .= ",";
			}
			$order_next .= $field->fieldIndex." ".$field->orderDirection;
			$order_prev .= $field->fieldIndex." ".($field->orderDirection == "DESC" ? "ASC" : "DESC");
		}

		// make next & prev where expressions
		
		$tail="";
		for($i = 0; $i < count($orderClause->fieldsList); $i++)
		{
			$field = $orderClause->fieldsList[$i];
			$fieldName = $this->pSet->GetFieldByIndex($field->fieldIndex);
			if(!$fieldName)
				continue;
			if(!$query->HasGroupBy())
				$fullName = GetFullFieldName($fieldName, $this->tName, false);
			else
				$fullName = AddFieldWrappers($fieldName);
			$asc = ($field->orderDirection == "ASC");
			if(!is_null($data[$fieldName]))
			{
			//	current field value is not null
				$value = $this->cipherer->MakeDBValue($fieldName, $data[$fieldName], "", "", true);
				$nextop = ($asc ? ">" : "<");
				$prevop = ($asc ? "<" : ">");
				$nextExpr = $fullName.$nextop.$value;
				$prevExpr = $fullName.$prevop.$value;
				if($nextop=="<")
					$nextExpr .= " or ".$fullName." IS NULL";
				else
					$prevExpr .= " or ".$fullName." IS NULL";
				if($i < count($orderClause->fieldsList) - 1)
				{
					$nextExpr .= " or ".$fullName."=".$value;
					$prevExpr .= " or ".$fullName."=".$value;
				}
			}
			else
			{
				$nextExpr = "";
				$prevExpr = "";				
			//	current field value is null
				if($asc)
					$nextExpr = $fullName." IS NOT NULL";
				else
					$prevExpr = $fullName." IS NOT NULL";
				
				if($i < count($orderClause->fieldsList) - 1)
				{
					if($nextExpr != "")
						$nextExpr.=" or ";
					$nextExpr .= $fullName." IS NULL";
					if($prevExpr != "")
						$prevExpr.=" or ";
					$prevExpr .= $fullName." IS NULL";
				}
			}
			if($nextExpr == "")
				$nextExpr = " 1=0 ";
			if($prevExpr == "")
				$prevExpr = " 1=0 ";
			
			// append expression to where clause
			if($i>0)
			{
				$where_next .= " AND ";
				$where_prev .= " AND ";
			}
			$where_next .= "(".$nextExpr;
			$where_prev .= "(".$prevExpr;
			
			$tail .=")";
		}
		$where_next = $where_next.$tail;
		$where_prev = $where_prev.$tail;

		if($where_next=="" or $order_next=="" or $where_prev=="" or $order_prev=="")
		{
			$_SESSION[$this->sessionPrefix."_noNextPrev"] = 1;
			return;
		}
//		make the resulting query
		if($query === null)
			return;
		
		if(!$query->HasGroupBy())
		{
			$oWhere = $query->Where();
			$where = whereAdd($where,$oWhere->toSql($query));
			$where_next = whereAdd($where_next,$where);
			$where_prev = whereAdd($where_prev,$where);
			$query->ReplaceFieldsWithDummies($this->pSet->getBinaryFieldsIndices());
			$sql_next = $query->toSql($where_next, $order_next, null, false, $joinFromPart);
			$sql_prev = $query->toSql($where_prev, $order_prev, null, false, $joinFromPart);
		}
		else
		{
			$oWhere = $query->Where();
			$oHaving = $query->Having();
			$where = whereAdd($where,$oWhere->toSql($query));
			$having = whereAdd($having,$oHaving->toSql($query));
			$query->ReplaceFieldsWithDummies($this->pSet->getBinaryFieldsIndices());
			$sql = "select * from (".$query->toSql($where, "", $having, false, $joinFromPart).") prevnextquery"; 
			$sql_next = $sql." WHERE ".$where_next.$order_next;
			$sql_prev = $sql." WHERE ".$where_prev.$order_prev;
		}
		if(GetGlobalData("returnToActualListPage", false))
		{
			if($prevExpr == " 1=0 ")
				$_SESSION[$this->sessionPrefix."_pagenumber"] = 1;
			else{
				$pageSQL = "select count(*) from (".$sql_prev.") tcount";
				$pageRes = db_query($pageSQL, $conn);
				$pageRow = db_fetch_numarray($pageRes);
				$currentRow = $pageRow[0];
				if($this->pageSize > 0)
					$pageSize = $this->pageSize;
				else
					$pageSize = $this->pSet->getInitialPageSize();
				$this->myPage = floor($currentRow / $pageSize) + 1;
				$_SESSION[$this->sessionPrefix."_pagenumber"] = $this->myPage;
			}
		}

		//	add record count options
		if(GetDatabaseType() == 0 || GetDatabaseType() == 4 || GetDatabaseType() == -1) {
			$sql_next.=" limit 1";
			$sql_prev.=" limit 1";
		}elseif(GetDatabaseType() == 2 || GetDatabaseType() == 3) {
			$sql_next=AddTop($sql_next, 1);
			$sql_prev=AddTop($sql_prev, 1);
		}elseif(GetDatabaseType() == 1) {
			$sql_next=AddRowNumber($sql_next, 1);
			$sql_prev=AddRowNumber($sql_prev, 1);
		}
		$res_next = db_query($sql_next,$conn);
		if($res_next)
		{
			if($row_next = $this->cipherer->DecryptFetchedArray($res_next))
			{
				foreach($tKeys as $i=>$k)
				{
					$next[$i] = $row_next[$k];
				}
			}
			db_closequery($res_next);
		}
		$res_prev = db_query($sql_prev,$conn);
		if($row_prev = $this->cipherer->DecryptFetchedArray($res_prev))
		{
			foreach($tKeys as $i=>$k)
			{
				$prev[$i] = $row_prev[$k];
			}
		}
		db_closequery($res_prev);
	}
	function Chart(&$ch_array, $param)
	{
		global $field_labels;
		
		if($this->webchart)
			$this->chrt_array=Convert_Old_Chart($ch_array);
		else
			$this->chrt_array=$ch_array;
			
		$this->pSet = new ProjectSettings($this->chrt_array['tables'][0]);
		$this->showDetails = $param['showDetails'];
		if( $this->showDetails )
			$this->detailTablesData = $this->pSet->getDetailTablesArr();
		
		$this->hasFlash = $param["hasFlash"];
		$this->chrt_array["appearance"]["autoupdate"] = false;
		
		$this->numRecordsToShow=$this->chrt_array['appearance']['maxbarscroll'];
		if($this->numRecordsToShow<1)
			$this->numRecordsToShow=1;
		$this->table_type=$this->chrt_array["table_type"];
		if(!$this->table_type)
			$this->table_type="project";
		$this->webchart=$param["webchart"];
		$this->cname=$param["cname"];
		$this->chartPreview = $param["chartPreview"];
		$this->sessionPrefix = $this->chrt_array['tables'][0];
		$this->gstrOrderBy=$param["gstrOrderBy"];
		$TableName=GoodFieldName($this->chrt_array['tables'][0]);
		
		$this->cipherer = new RunnerCipherer($this->chrt_array['tables'][0]);

		$this->header = $this->chrt_array['appearance']['head'];
		$this->footer = $this->chrt_array['appearance']['foot'];    
		$this->y_axis_label = $this->chrt_array['appearance']['y_axis_label'];    

		for ( $i=0; $i<count($this->chrt_array['parameters'])-1; $i++) 
		{
			if(isset($this->chrt_array['parameters'][$i]['currencyFormat']))
				$this->arrFormatCurrency[]=$this->chrt_array['parameters'][$i]['currencyFormat'];
			else
			{
				if($this->chrt_array['appearance']['scur']=="false")
					$this->arrFormatCurrency[]="";
				else
					$this->arrFormatCurrency[]=$this->chrt_array['appearance']['scur'];
			}
			
			if(isset($this->chrt_array['parameters'][$i]['decimalFormat']))
				$this->arrFormatDecimal[]=$this->chrt_array['parameters'][$i]['decimalFormat'];
			else
				$this->arrFormatDecimal[]=$this->chrt_array['appearance']['dec'];
			$this->arrFormatCustomer[]=$this->chrt_array['parameters'][$i]['customFormat'];
			$this->arrFormatCustomerStr[]=$this->chrt_array['parameters'][$i]['customFormatStr'];
			
			if($this->chrt_array["chart_type"]["type"]=="ohlc" || $this->chrt_array["chart_type"]["type"]=="candlestick")
			{
				$this->arrOHLC_color[] = "#".$this->chrt_array['parameters'][$i]['ohlcColor'];
				if($this->table_type!="db")
				{
					$this->arrOHLC_open[] = $this->chrt_array['parameters'][$i]['ohlcOpen'];
					$this->arrOHLC_high[] = $this->chrt_array['parameters'][$i]['ohlcHigh'];
					$this->arrOHLC_low[] = $this->chrt_array['parameters'][$i]['ohlcLow'];
					$this->arrOHLC_close[] = $this->chrt_array['parameters'][$i]['ohlcClose'];

				}
				else
				{
					if( $this->chrt_array['parameters'][$i]['agr_func'] )
					{
						$this->arrOHLC_open[] = $this->chrt_array['parameters'][$i]['agr_func']."_".$this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['ohlcOpen'];
						$this->arrOHLC_high[] = $this->chrt_array['parameters'][$i]['agr_func']."_".$this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['ohlcHigh'];
						$this->arrOHLC_low[] = $this->chrt_array['parameters'][$i]['agr_func']."_".$this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['ohlcLow'];
						$this->arrOHLC_close[] = $this->chrt_array['parameters'][$i]['agr_func']."_".$this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['ohlcClose'];
					}
					else
					{
						$this->arrOHLC_open[] = $this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['ohlcOpen'];
						$this->arrOHLC_high[] = $this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['ohlcHigh'];
						$this->arrOHLC_low[] = $this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['ohlcLow'];
						$this->arrOHLC_close[] = $this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['ohlcClose'];
					}

				}
				if($this->chrt_array["chart_type"]["type"]=="candlestick")
					$this->arrOHLC_candle[] = "#".$this->chrt_array['parameters'][$i]['ohlcCandleColor'];
			}
			elseif ( $this->chrt_array['parameters'][$i]['name'] != "" ) 
			{
				if($this->table_type!="db")
					$this->arrDataSeries[] = ($this->chrt_array['parameters'][$i]['agr_func']) ?
					$this->chrt_array['parameters'][$i]['label'] :
					$this->chrt_array['parameters'][$i]['name'];
				else
				{
					$this->arrDataSeries[] = ($this->chrt_array['parameters'][$i]['agr_func']) ?
					$this->chrt_array['parameters'][$i]['agr_func']."_".$this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['name'] :
					$this->chrt_array['parameters'][$i]['table']."_".$this->chrt_array['parameters'][$i]['name'] ;
				}
				
				if(isset($this->chrt_array['appearance']['scolor'.($i+1).'1']))
					$this->arrDataColor[]=$this->chrt_array['appearance']['scolor'.($i+1).'1'];
				else
					$this->arrDataColor[] = $this->chrt_array['parameters'][$i]['series_color'];
					
				if($this->chrt_array["chart_type"]["type"]=="bubble")
					$this->arrDataSize[] = $this->chrt_array['parameters'][$i]['size'];
					
				if($this->chrt_array["chart_type"]["type"]=="gauge")
				{
					for ($k=0;is_array($this->chrt_array["parameters"][$i]["gaugeColorZone"]) && $k<count($this->chrt_array["parameters"][$i]["gaugeColorZone"]);$k++) 
					{
						$beginColor=(float)@$this->chrt_array["parameters"][$i]["gaugeColorZone"][$k]["gaugeBeginColor"];
						$endColor=(float)@$this->chrt_array["parameters"][$i]["gaugeColorZone"][$k]["gaugeEndColor"];
						$gColor="#".@$this->chrt_array["parameters"][$i]["gaugeColorZone"][$k]["gaugeColor"];
						$this->arrGaugeColor[count($this->arrDataSeries)-1][]=array($beginColor,$endColor,$gColor);
					}
				}
			}
			if($this->table_type=="project" && !$this->webchart)
			{
				if($this->chrt_array["chart_type"]["type"] != "candlestick" && $this->chrt_array["chart_type"]["type"] != "ohlc")
					$this->arrDataLabels[]=$this->chart_xmlencode(GetFieldLabel(GoodFieldName($TableName),GoodFieldName($this->chrt_array['parameters'][$i]['name'])));
				else
					$this->arrDataLabels[]=$this->chart_xmlencode(GetFieldLabel(GoodFieldName($TableName),GoodFieldName($this->chrt_array['parameters'][$i]['ohlcOpen'])));
			}
			else
			{
				if(!$this->chart_xmlencode($this->chrt_array['parameters'][$i]['label']))
				{
					if($this->chrt_array["chart_type"]["type"] != "candlestick" && $this->chrt_array["chart_type"]["type"] != "ohlc")
						$this->arrDataLabels[]=$this->chart_xmlencode($this->chrt_array['parameters'][$i]['name']);
					else
						$this->arrDataLabels[]=$this->chart_xmlencode($this->chrt_array['parameters'][$i]['ohlcOpen']);
				}
				else
					$this->arrDataLabels[]=$this->chart_xmlencode($this->chrt_array['parameters'][$i]['label']);
			}
		}
		
		
	
	    if($this->chrt_array["chart_type"]["type"]!="gauge")
	    {
			if($this->table_type!="db")
				$this->strLabel = $this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['name'];
			else
			{
				$this->strLabel = ($this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['agr_func']) ?
				$this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['agr_func']."_".$this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['table']."_".$this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['name']:
				$this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['table']."_".$this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['name'];
			}
			for($j = 0; $j<count($this->chrt_array['fields']); $j++)
			{
				if($this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['name']==$this->chrt_array['fields'][$j]['name'])
				{
					if($this->table_type=="project")
						$this->label2=$this->chart_xmlencode(GetFieldLabel($TableName,GoodFieldName($this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['name'])));
					else
						$this->label2=$this->chart_xmlencode($this->chrt_array['parameters'][count($this->chrt_array['parameters'])-1]['name']);
				}
			}
		}
	    
		if($this->chrt_array["chart_type"]["type"]!="ohlc" && $this->chrt_array["chart_type"]["type"]!="candlestick")
		{
			foreach($this->arrDataColor as $ind=>$val)
			{
				if($ind==0)
					$this->arrAxesColor = "#000000";
				else
					$this->arrAxesColor = "#".$this->arrDataColor[$ind];
			}
		}
		else
		{
			foreach($this->arrOHLC_color as $ind=>$val)
			{
				if($ind==0)
					$this->arrAxesColor = "#000000";
				else
					$this->arrAxesColor = "#".$this->arrOHLC_color[$ind];
			}
		}		
		
		// prepare search params
		$gQuery = $this->pSet->getSQLQuery();

		$masterWhere = "";
		$masterTable = $_SESSION[$this->sessionPrefix."_mastertable"];
		$detailKeysByM = $this->pSet->getDetailKeysByMasterTable($masterTable);
		if(count($detailKeysByM)) 
		{
			for($i=0;$i<count($detailKeysByM);$i++) 
			{
				if($i != 0) 
					$masterWhere.= " and ";
					
				if($this->cipherer && isEncryptionByPHPEnabled())
					$mValue = $this->cipherer->MakeDBValue($detailKeysByM[$i], $_SESSION[$this->sessionPrefix."_masterkey".($i + 1)]);
				else 
					$mValue = make_db_value($detailKeysByM[$i], $_SESSION[$this->sessionPrefix."_masterkey".($i + 1)]);
				if(strlen($mValue) != 0)
					$masterWhere.= GetFullFieldName($detailKeysByM[$i], "", false)."=".$mValue;
				else 
					$masterWhere.= "1=0";
			}
		}
		
		$strWhereClause = "";
		$searchHavingClause = "";
		$strSearchCriteria = "and";
		global $strTableName;
		// search where for basic charts
		if(!$this->webchart)
		{	
			if( !$this->chartPreview && isset($_SESSION[$this->sessionPrefix.'_advsearch']) )
			{
				$searchClauseObj = SearchClause::UnserializeObject($_SESSION[$this->sessionPrefix.'_advsearch']);
				include_once getabspath('classes/controls/EditControlsContainer.php');
				$editControls = new EditControlsContainer(null, $this->pSet, PAGE_REPORT, $this->cipherer);
				
				include_once(getabspath("classes/runnerpage.php"));
				$whereComponents = RunnerPage::sGetWhereComponents( $gQuery, $this->pSet, $searchClauseObj, $editControls );
				$strWhereClause = $whereComponents["searchWhere"];
				foreach($whereComponents["filterWhere"] as $fWhere)
				{
					$strWhereClause = whereAdd($strWhereClause, $fWhere);
				}
		
				$searchHavingClause = $whereComponents["searchHaving"];
				foreach($whereComponents["filterHaving"] as $fHaving)
				{
					$searchHavingClause = whereAdd($searchHavingClause, $fHaving);
				}
				
				$strSearchCriteria = $whereComponents["searchUnionRequired"] ? "or" : "and";
			}
		}
		else 
		{
			if($this->table_type!="project")
				$strTableName="webchart".$this->cname;
			$strWhereClause = CalcSearchParam($this->table_type!="project");
		}
		if ($strWhereClause) 
		{
			$this->chrt_array['where'] .= ($this->chrt_array['where']) ?
				" AND (" . $strWhereClause . ")" :
				" WHERE (" . $strWhereClause . ")";
		}	
		if($this->table_type=="project")
		{
			if(SecuritySQL("Search"))
			{
				$strWhereClause = whereAdd($strWhereClause, SecuritySQL("Search"));
			}
			$this->strSQL = $gQuery->gSQLWhere($strWhereClause,$searchHavingClause, $strSearchCriteria);
		
			$strOrderBy = $this->gstrOrderBy;
			$this->strSQL.= " ".$strOrderBy;

			if( $masterWhere )
				$strWhereClause = whereAdd($strWhereClause, $masterWhere);
			
			$strSQLbak=$this->strSQL;
			if(tableEventExists("BeforeQueryChart",$strTableName)) 
			{
				$tstrSQL = $this->strSQL;
				$eventObj = getEventObject($strTableName);
				$eventObj->BeforeQueryChart($tstrSQL,$strWhereClause,$strOrderBy);
				$this->strSQL = $tstrSQL;
			}
			if($strSQLbak == $this->strSQL)
			{								
				$this->strSQL = $gQuery->gSQLWhere($strWhereClause, $searchHavingClause, $strSearchCriteria);
				$this->strSQL.= " ".$strOrderBy;
			}
		}
		

		if ($this->cname && $this->table_type=="db") 
			$this->strSQL = $this->chrt_array['sql'] . $this->chrt_array['where'] . $this->chrt_array['group_by'] . $this->chrt_array['order_by'];
		elseif ($this->cname && $this->table_type=="custom") 
		{
			if(!IsStoredProcedure($this->chrt_array['sql']))
			{
				$sql_query=$this->chrt_array['sql'];
				if(GetDatabaseType()==2) //MSSQLServer
				{
					$pos=strrpos(strtoupper($sql_query),"ORDER BY");
					if($pos)
						$sql_query=substr($sql_query,0,$pos);
				}
				if(GetDatabaseType()!=1) //Oracle
					$this->strSQL = "select * from (".$sql_query.") as ".AddFieldWrappers("custom_query").$this->chrt_array['where'];
				else
					$this->strSQL = "select * from (".$sql_query.")". $this->chrt_array['where'];
			}
			else
			{
				$this->strSQL = $this->chrt_array['sql'];
			}
		}
			
		if(tableEventExists("UpdateChartSettings",$strTableName))
		{
			$eventObj = getEventObject($strTableName);
			$eventObj->UpdateChartSettings($this);
		}
	}
function make_from_clause($type)
{
	$accessMode=(GetDatabaseType()==3);
	$root=&$_SESSION[$type];
	$ret=AddTableWrappers($root['tables'][0]);
	$fullouter="";
	$firstJoin=true;
	if(is_array($root["table_relations"]["relat"]))
	{
		foreach($root["table_relations"]["relat"] as $r)
		{
			if(trim($r["rel_type"])=="FULL OUTER JOIN")
			{
				$fullouter.="\n,".AddTableWrappers($r["right_table"]);
				continue;
			}
			if($accessMode && !$firstJoin)
			{
				$ret="(".$ret.")";
			}
			$firstJoin=false;
			$ret.="\n".$r["rel_type"]." ".AddTableWrappers($r["right_table"])." ON ";
			$joinon="";
			foreach($r["left_fields"] as $i=>$f)
			{
				if(strlen($joinon))
					$joinon.=" AND ";
				$joinon.=AddTableWrappers($r["left_table"]).".".AddFieldWrappers($r["left_fields"][$i]);
				$joinon.="=";
				$joinon.=AddTableWrappers($r["right_table"]).".".AddFieldWrappers($r["right_fields"][$i]);
			}
			$ret.=$joinon;
		}
	}
	return "FROM ".$ret.$fullouter;
}
Beispiel #13
0
    $strWhereClause = whereAdd($strWhereClause, SecuritySQL("Search"));
    $_SESSION[$sessPrefix . "_sql"] = $strSQL;
    $_SESSION[$sessPrefix . "_where"] = $strWhereClause;
    $_SESSION[$sessPrefix . "_order"] = $strOrderBy;
}
//	select all records
$strSQLbak = $strSQL;
if (is_wr_db()) {
    $strSQL = $rpt_array['sql'] . $rpt_array['where'] . $rpt_array['order_by'];
} elseif (is_wr_project()) {
    $strSQL = $gQuery->gSQLWhere($strWhereClause);
    $strSQL .= " " . trim($strOrderBy);
} elseif (is_wr_custom()) {
    if (GetDatabaseType() != nDATABASE_Oracle) {
        $sqlquery = $rpt_array['sql'];
        if (GetDatabaseType() == nDATABASE_MSSQLServer) {
            $pos = strrpos(strtoupper($sqlquery), "ORDER BY");
            if ($pos) {
                $sqlquery = substr($sqlquery, 0, $pos);
            }
        }
        $strSQL = "select * from (" . $sqlquery . ") as " . $_connection->AddFieldWrappers("t") . " " . $rpt_array['where'] . $rpt_array['order_by'];
    } else {
        $strSQL = "select * from (" . $rpt_array['sql'] . ")" . $rpt_array['where'] . $rpt_array['order_by'];
    }
}
$grid_row = array();
if ($cross_table != "true") {
    $groupno = 0;
    if (!$_SESSION[$sessPrefix . "_pagenumber"]) {
        $_SESSION[$sessPrefix . "_pagenumber"] = 1;
function PrepareString4DB($str)
{
	if(GetDatabaseType()!=nDATABASE_Oracle)
	{
		return db_prepare_string($str);
	}

	if(strlen($str)<4000)
		return db_prepare_string($str);
	$chunklen = 3900;
	$chunks = floor(strlen($str)/$chunklen);
	if(strlen($str) % $chunklen != 0)
		$chunks++;
	$out="";
	for($i=0;$i<$chunks;$i++)
	{
		if(strlen($out))
			$out.="||";
		$out.="to_clob(";
		$out.=db_prepare_string(substr($str,$i*$chunklen,$chunklen));
		$out.=")";
	}
	return $out;
}