function db_fetch_array($rs, $assoc = 1)
{
    global $mssql_dmy;
    if ($rs->EOF()) {
        return false;
    }
    try {
        $ret = array();
        for ($i = 0; $i < db_numfields($rs); $i++) {
            if (IsBinaryType($rs->Fields[$i]->Type) && $rs->Fields[$i]->Type != 128) {
                $str = "";
                if ($rs->Fields[$i]->ActualSize) {
                    $val = $rs->Fields[$i]->GetChunk($rs->Fields[$i]->ActualSize);
                    $str = str_pad("", count($val));
                    $j = 0;
                    foreach ($val as $byte) {
                        $str[$j++] = chr($byte);
                    }
                }
                if ($assoc) {
                    $ret[$rs->Fields[$i]->Name] = $str;
                } else {
                    $ret[$i] = $str;
                }
            } else {
                $value = $rs->Fields[$i]->Value;
                if (is_null($value)) {
                    $val = NULL;
                } else {
                    if (isdatefieldtype($rs->Fields[$i]->Type)) {
                        $value = localdatetime2db((string) $rs->Fields[$i]->Value, $mssql_dmy);
                    }
                    if (IsNumberType($rs->Fields[$i]->Type)) {
                        $val = floatval($value);
                    } else {
                        $val = strval($value);
                    }
                }
                if ($assoc) {
                    $ret[$rs->Fields[$i]->Name] = $val;
                } else {
                    $ret[$i] = $val;
                }
            }
        }
        $rs->MoveNext();
    } catch (com_exception $e) {
        trigger_error($e->getMessage(), E_USER_ERROR);
    }
    return $ret;
}
Exemplo n.º 2
0
 public function showDBValue(&$data, $keylink = "")
 {
     $value = $data[$this->field];
     if (IsBinaryType($this->fieldType)) {
         $value = "LONG BINARY DATA - CANNOT BE DISPLAYED";
     }
     if ($value === false) {
         $value = "";
     }
     if ($this->editFormat == EDIT_FORMAT_CHECKBOX && $this->viewFormat == FORMAT_NONE) {
         if ($value && $value != 0) {
             $value = "Yes";
         } else {
             $value = "No";
         }
     }
     return $this->checkForEncoding($value, $keylink);
 }
Exemplo n.º 3
0
 /**
  * @param Mixed rs
  * @param Number nPageSize
  */
 protected function WriteTableData($rs, $nPageSize)
 {
     $exportFields = $this->pSet->getExportFields();
     $totalFieldsData = $this->pSet->getTotalsFields();
     if ($this->eventsObject->exists("ListFetchArray")) {
         $row = $this->eventsObject->ListFetchArray($rs, $this);
     } else {
         $row = $this->cipherer->DecryptFetchedArray($this->connection->fetch_array($rs));
     }
     // write header
     echo "<tr>";
     if ($_REQUEST["type"] == "excel") {
         foreach ($exportFields as $field) {
             echo '<td style="width: 100" x:str>' . PrepareForExcel($this->pSet->label($field)) . '</td>';
         }
     } else {
         foreach ($exportFields as $field) {
             echo "<td>" . $this->pSet->label($field) . "</td>";
         }
     }
     echo "</tr>";
     $totals = array();
     $totalsFields = array();
     foreach ($totalFieldsData as $data) {
         if (!in_array($data["fName"], $exportFields)) {
             continue;
         }
         $totals[$data["fName"]] = array("value" => 0, "numRows" => 0);
         $totalsFields[] = array('fName' => $data["fName"], 'totalsType' => $data["totalsType"], 'viewFormat' => $this->pSet->getViewFormat($data["fName"]));
     }
     // write data rows
     $iNumberOfRows = 0;
     $this->viewControls->forExport = "export";
     while ((!$nPageSize || $iNumberOfRows < $nPageSize) && $row) {
         countTotals($totals, $totalsFields, $row);
         $values = array();
         foreach ($exportFields as $field) {
             $fType = $this->pSet->getFieldType($field);
             if (IsBinaryType($fType)) {
                 $values[$field] = "código binario demasiado grande – no puede ser desplegado";
             } else {
                 $values[$field] = $this->getViewControl($field)->getExportValue($row, "");
             }
         }
         $eventRes = true;
         if ($this->eventsObject->exists('BeforeOut')) {
             $eventRes = $this->eventsObject->BeforeOut($row, $values, $this);
         }
         if ($eventRes) {
             $iNumberOfRows++;
             echo "<tr>";
             foreach ($exportFields as $field) {
                 $fType = $this->pSet->getFieldType($field);
                 if (IsCharType($fType)) {
                     if ($_REQUEST["type"] == "excel") {
                         echo '<td x:str>';
                     } else {
                         echo '<td>';
                     }
                 } else {
                     echo '<td>';
                 }
                 $editFormat = $this->pSet->getEditFormat($field);
                 if ($editFormat == EDIT_FORMAT_LOOKUP_WIZARD) {
                     if ($this->pSet->NeedEncode($field)) {
                         if ($_REQUEST["type"] == "excel") {
                             echo PrepareForExcel($values[$field]);
                         } else {
                             echo $values[$field];
                         }
                     } else {
                         echo $values[$field];
                     }
                 } elseif (IsBinaryType($fType)) {
                     echo $values[$field];
                 } else {
                     if ($editFormat == FORMAT_CUSTOM || $this->pSet->isUseRTE($field)) {
                         echo $values[$field];
                     } elseif (NeedQuotes($field)) {
                         if ($_REQUEST["type"] == "excel") {
                             echo PrepareForExcel($values[$field]);
                         } else {
                             echo $values[$field];
                         }
                     } else {
                         echo $values[$field];
                     }
                 }
                 echo '</td>';
             }
             echo "</tr>";
         }
         if ($this->eventsObject->exists("ListFetchArray")) {
             $row = $this->eventsObject->ListFetchArray($rs, $this);
         } else {
             $row = $this->cipherer->DecryptFetchedArray($this->connection->fetch_array($rs));
         }
     }
     if (count($totalFieldsData)) {
         echo "<tr>";
         foreach ($totalFieldsData as $data) {
             if (!in_array($data["fName"], $exportFields)) {
                 continue;
             }
             echo "<td>";
             if (strlen($data["totalsType"])) {
                 if ($data["totalsType"] == "COUNT") {
                     echo "Contar" . ": ";
                 } elseif ($data["totalsType"] == "TOTAL") {
                     echo "Total" . ": ";
                 } elseif ($data["totalsType"] == "AVERAGE") {
                     echo "Promedio" . ": ";
                 }
                 echo runner_htmlspecialchars(GetTotals($data["fName"], $totals[$data["fName"]]["value"], $data["totalsType"], $totals[$data["fName"]]["numRows"], $this->pSet->getViewFormat($data["fName"]), PAGE_EXPORT));
             }
             echo "</td>";
         }
         echo "</tr>";
     }
 }
Exemplo n.º 4
0
					$gKey = $key;
				
				$res_head .= "<th>" . runner_htmlspecialchars($gKey) . "</th>";		
			}
		}
		$res_body .= '<tr>';
		foreach( $data as $fld=>$val ) 
		{
			if(is_wr_project())
			{
				if(IsBinaryType($gSettings->getFieldType($fld)))
					continue;
			}
			elseif(is_wr_custom())
			{
				if(IsBinaryType($fields_type[$fld]))
					continue;
			}
			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;
	}
Exemplo n.º 5
0
function ExportToExcel($rs, $nPageSize, $eventObj, $cipherer, $pageObj)
{
    if ($eventObj->exists("ListFetchArray")) {
        $row = $eventObj->ListFetchArray($rs, $pageObj);
    } else {
        $row = $cipherer->DecryptFetchedArray($pageObj->connection->fetch_array($rs));
    }
    $tmpArr = array();
    $totals = array();
    $arrLabel = array();
    $arrTotal = array();
    $arrFields = array();
    $arrTmpTotal = array();
    $arrColumnWidth = array();
    $arrTotalMessage = array();
    $tmpArr = $pageObj->pSet->getExportFields();
    foreach ($tmpArr as $value) {
        if ($pageObj->pSet->appearOnExportPage($value)) {
            $arrFields[] = $value;
        }
    }
    $arrTmpTotal = $pageObj->pSet->getTotalsFields();
    $pageObj->viewControls->forExport = "excel";
    foreach ($arrFields as $value) {
        $arrLabel[$value] = GetFieldLabel(GoodFieldName($pageObj->tName), GoodFieldName($value));
        $arrColumnWidth[$value] = 10;
        $totals[$value] = array("value" => 0, "numRows" => 0);
        $totalsType = "";
        foreach ($arrTmpTotal as $tvalue) {
            if ($tvalue["fName"] == $value) {
                $totalsType = $tvalue["totalsType"];
                $totalsFields[] = array('fName' => $value, 'totalsType' => $totalsType, 'viewFormat' => $pageObj->pSet->getViewFormat($value));
            }
        }
    }
    // write data rows
    $iNumberOfRows = 0;
    $objPHPExcel = ExportExcelInit($arrLabel, $arrColumnWidth);
    while ((!$nPageSize || $iNumberOfRows < $nPageSize) && $row) {
        countTotals($totals, $totalsFields, $row);
        $values = array();
        $arrData = array();
        $arrDataType = array();
        foreach ($arrFields as $field) {
            if (IsBinaryType($pageObj->pSet->getFieldType($field))) {
                $values[$field] = $row[$field];
            } else {
                $values[$field] = $pageObj->getExportValue($field, $row);
            }
        }
        $eventRes = true;
        if ($eventObj->exists('BeforeOut')) {
            $eventRes = $eventObj->BeforeOut($row, $values, $pageObj);
        }
        if ($eventRes) {
            $iNumberOfRows++;
            $i = 0;
            foreach ($arrFields as $field) {
                if (IsBinaryType($pageObj->pSet->getFieldType($field))) {
                    $arrDataType[$field] = "binary";
                } elseif ($pageObj->pSet->getViewFormat($field) == FORMAT_DATE_SHORT || $pageObj->pSet->getViewFormat($field) == FORMAT_DATE_LONG || $pageObj->pSet->getViewFormat($field) == FORMAT_DATE_TIME) {
                    $arrDataType[$field] = "date";
                } elseif ($pageObj->pSet->getViewFormat($field) == FORMAT_FILE_IMAGE) {
                    $arrDataType[$field] = "file";
                } else {
                    $arrDataType[$field] = "";
                }
                $arrData[$field] = $values[$field];
            }
            ExportExcelRecord($arrData, $arrDataType, $iNumberOfRows, $objPHPExcel, $pageObj);
        }
        if ($eventObj->exists("ListFetchArray")) {
            $row = $eventObj->ListFetchArray($rs, $pageObj);
        } else {
            $row = $cipherer->DecryptFetchedArray($pageObj->connection->fetch_array($rs));
        }
    }
    if (count($arrTmpTotal)) {
        foreach ($arrFields as $fName) {
            $value = array();
            foreach ($arrTmpTotal as $tvalue) {
                if ($tvalue["fName"] == $fName) {
                    $value = $tvalue;
                }
            }
            $total = "";
            $totalMess = "";
            if ($value["totalsType"]) {
                if ($value["totalsType"] == "COUNT") {
                    $totalMess = "Count" . ": ";
                } elseif ($value["totalsType"] == "TOTAL") {
                    $totalMess = "Total" . ": ";
                } elseif ($value["totalsType"] == "AVERAGE") {
                    $totalMess = "Average" . ": ";
                }
                $total = GetTotals($fName, $totals[$fName]["value"], $value["totalsType"], $totals[$fName]["numRows"], $value["viewFormat"], "export");
            }
            $arrTotal[$fName] = $total;
            $arrTotalMessage[$fName] = $totalMess;
        }
    }
    ExportExcelTotals($arrTotal, $arrTotalMessage, ++$iNumberOfRows, $objPHPExcel);
    $extExcel = ".xlsx";
    $formatExcel = "Excel2007";
    if (@$_REQUEST["type"] == "excel5") {
        $formatExcel = "Excel5";
        $extExcel = ".xls";
    }
    ExportExcelSave(GoodFieldName($pageObj->tName) . $extExcel, $formatExcel, $objPHPExcel);
}
Exemplo n.º 6
0
		if ( in_array( $field, $aSelGroupFields ) ) {
			$disabled = "disabled";
			$class = "inactive";
			$blobClass = "";
		}
	}
	
	if (!is_wr_custom()) 
		$field_type=WRGetFieldType( $arr['table'].".".$arr['field']);
	else
		$field_type=$fields_type[$arr['field']];
		
	if(is_wr_custom())
		$arr['table']=$table_name;
	
	if ( IsBinaryType( $field_type ) )  {
		$blobDisabled = "disabled";
		$class = "";
		$blobClass = "inactive";
		$adClass = "inactive";
		$blobCheck = "";
	}

	if ( $class == "active" && $blobClass == "active" ) {
		$blobClass = "";
	}

	$tgFields .='<tr id="'. GoodFieldName($arr['table'].".".$arr['field']) .'" class="tbody">
		<td width="10px" style="border:0px">
				<div style="height:7px">';
	if($disabled=="")
Exemplo n.º 7
0
 /**
  * Add span val for lookup fields, and average|total|count totals
  */
 function addSpanVal($fName, &$data)
 {
     global $strTableName;
     $pSet = new ProjectSettings($strTableName, PAGE_LIST);
     $type = $pSet->getFieldType($fName);
     if ((@$this->arrFieldSpanVal[$fName] == 2 || @$this->arrFieldSpanVal[$fName] == 1) && !IsBinaryType($type)) {
         return "val=\"" . runner_htmlspecialchars($data[$fName]) . "\" ";
     }
 }
Exemplo n.º 8
0
function WRadd_db_quotes($field, $value, $table = "")
{
    $connection = getWebreportConnection();
    $type = WRGetFieldType($table . "." . $field);
    if (IsBinaryType($type)) {
        return $connection->addSlashesBinary($value);
    }
    if (($value === "" || $value === FALSE) && !IsCharType($type)) {
        return "null";
    }
    if (NeedQuotes($type)) {
        if (!IsDateFieldType($type)) {
            $value = $connection->prepareString($value);
        } else {
            $value = $connection->addDateQuotes($value);
        }
    } else {
        $strvalue = (string) $value;
        $strvalue = str_replace(",", ".", $strvalue);
        if (is_numeric($strvalue)) {
            $value = $strvalue;
        } else {
            $value = 0;
        }
    }
    return $value;
}
Exemplo n.º 9
0
	/**
	 * @param String strSearchOption
	 * @return String | Boolean
	 */
	function baseSQLWhere($strSearchOption)
	{
		if(IsBinaryType($this->type))
			return false;
		
	
		if($strSearchOption != 'Empty')
			return "";
		
		$fullFieldName = GetFullFieldName($this->field, $this->pageObject->tName);
		
		if( IsCharType($this->type) && (!$this->ismssql || !$this->btexttype) && !$this->isOracle )
			return "(".$fullFieldName." is null or ".$fullFieldName."='')";
		
		if( $this->ismssql && $this->btexttype )
			return "(".$fullFieldName." is null or ".$fullFieldName." LIKE '')";
		
		return $fullFieldName." is null";
	}
Exemplo n.º 10
0
 /**
  * Update record in the table.
  * @intellisense
  */
 function Update()
 {
     global $dal_info;
     $tableinfo =& $dal_info[$this->m_TableName];
     $updateParam = "";
     $updateValue = "";
     $blobs = array();
     foreach ($tableinfo as $fieldname => $fld) {
         $command = 'if(isset($this->' . $fld['varname'] . ')) { ';
         if ($fld["key"]) {
             $command .= '$this->Param[\'' . escapesq($fieldname) . '\'] = $this->' . $fld['varname'] . ';';
         } else {
             $command .= '$this->Value[\'' . escapesq($fieldname) . '\'] = $this->' . $fld['varname'] . ';';
         }
         $command .= ' }';
         eval($command);
         if (!$fld["key"] && !array_key_exists(strtoupper($fieldname), array_change_key_case($this->Param, CASE_UPPER))) {
             foreach ($this->Value as $field => $value) {
                 if (strtoupper($field) != strtoupper($fieldname)) {
                     continue;
                 }
                 $updateValue .= $this->_connection->addFieldWrappers($fieldname) . "=" . $this->PrepareValue($value, $fld["type"]) . ", ";
                 if ($this->_connection->dbType == nDATABASE_Oracle || $this->_connection->dbType == nDATABASE_DB2 || $this->_connection->dbType == nDATABASE_Informix) {
                     if (IsBinaryType($fld["type"])) {
                         $blobs[$fieldname] = $value;
                     }
                     if ($this->_connection->dbType == nDATABASE_Informix && IsTextType($fld["type"])) {
                         $blobs[$fieldname] = $value;
                     }
                 }
                 break;
             }
         } else {
             foreach ($this->Param as $field => $value) {
                 if (strtoupper($field) != strtoupper($fieldname)) {
                     continue;
                 }
                 $updateParam .= $this->_connection->addFieldWrappers($fieldname) . "=" . $this->PrepareValue($value, $fld["type"]) . " and ";
                 break;
             }
         }
     }
     //	construct SQL and do update
     if ($updateParam) {
         $updateParam = substr($updateParam, 0, -5);
     }
     if ($updateValue) {
         $updateValue = substr($updateValue, 0, -2);
     }
     if ($updateValue && $updateParam) {
         $dalSQL = "update " . $this->_connection->addTableWrappers($this->m_TableName) . " set " . $updateValue . " where " . $updateParam;
         $this->Execute_Query($blobs, $dalSQL, $tableinfo);
     }
     //	cleanup
     $this->Reset();
 }
Exemplo n.º 11
0
 /**
  * Get the field's content
  * @param &Array data
  * @param String keylink
  * @return String	 
  */
 public function showDBValue(&$data, $keylink = "")
 {
     $value = $data[$this->field];
     if (IsBinaryType($this->fieldType)) {
         $value = "LONG BINARY DATA - CANNOT BE DISPLAYED";
         $this->searchHighlight = false;
     }
     if ($value === false) {
         $value = "";
     }
     if ($this->editFormat == EDIT_FORMAT_CHECKBOX && $this->viewFormat == FORMAT_NONE) {
         if ($value && $value != 0) {
             $value = "Yes";
         } else {
             $value = "No";
         }
         $this->searchHighlight = false;
     }
     if ($this->container->forExport == "excel" || $this->container->forExport == "csv") {
         return $value;
     }
     $processedText = $this->processText($value, $keylink);
     return nl2br($processedText);
 }
Exemplo n.º 12
0
 function baseSQLWhere($strSearchOption)
 {
     $this->btexttype = IsTextType($this->type);
     if (IsBinaryType($this->type)) {
         return false;
     }
     if ($strSearchOption == 'Empty') {
         if (IsCharType($this->type) && (!$this->ismssql || !$this->btexttype) && !$this->isOracle) {
             return "(" . GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . " is null or " . GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . "='')";
         } elseif ($this->ismssql && $this->btexttype) {
             return "(" . GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . " is null or " . GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . " LIKE '')";
         } else {
             return GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . " is null";
         }
     }
     return "";
 }
/**
 * @intellisense
 */
function add_db_quotes($field, $value, $table = "", $type = null)
{
	global $strTableName, $locale_info;
	if($table=="")
		$table=$strTableName;
	$pSet = new ProjectSettings($table);
	
	if($type == null)
		$type = $pSet->getFieldType($field);
	if(IsBinaryType($type))
		return db_addslashesbinary($value);
	if(($value==="" || $value===FALSE || is_null($value)) && !IsCharType($type))
		return "null";
	if(NeedQuotes($type))
	{
		if(!IsDateFieldType($type))
			$value=db_prepare_string($value);
		else
		{
			$y = "(\d\d\d\d)";
			$m = "(0?[1-9]|1[0-2])";
			$d = "(0?[1-9]|[1-2][0-9]|3[0-1])";
			$delim = "(-|".preg_quote($locale_info["LOCALE_SDATE"], "/").")";
			$reg = "/".$d.$delim.$m.$delim.$y."|".$m.$delim.$d.$delim.$y."|".$y.$delim.$m.$delim.$d."/";
			if( !preg_match($reg, $value, $matches) )
				return "null";

			$value=db_datequotes($value);
		}
	}
	else
	{
		$strvalue = (string)$value;
		if(is_numeric($strvalue))
			$value = str_replace(",",".",$strvalue);
		else
			$value=0;
	}
	return $value;
}
Exemplo n.º 14
0
 /**
  * Get an array containing the record save status
  * @return Array
  */
 protected function getSaveStatusJSON()
 {
     $returnJSON = array();
     if ($this->action != "edited" || $this->mode == EDIT_SIMPLE) {
         return $returnJSON;
     }
     $returnJSON['success'] = $this->updatedSuccessfully;
     $returnJSON['message'] = $this->message;
     $returnJSON['lockMessage'] = $this->lockingMessageText;
     if (!$this->isCaptchaOk) {
         $returnJSON['captcha'] = false;
     }
     if (!$this->updatedSuccessfully) {
         return $returnJSON;
     }
     //	successful update. Return new keys and field values
     $data = $this->getCurrentRecordInternal();
     if (!$data) {
         $data = $this->newRecordData;
     }
     //	details tables keys
     $returnJSON['detKeys'] = array();
     foreach ($this->pSet->getDetailTablesArr() as $dt) {
         $dkeys = array();
         foreach ($dt["masterKeys"] as $idx => $mk) {
             $dkeys["masterkey" . ($idx + 1)] = $data[$mk];
         }
         $returnJSON['detKeys'][$dt['dDataSourceTable']] = $dkeys;
     }
     //	prepare field values
     //	keys
     $keyParams = array();
     foreach ($this->keyFields as $i => $k) {
         $keyParams[] = "key" . ($i + 1) . "=" . rawurldecode($this->keys[$k]);
     }
     $keylink = "&" . implode("&", $keyParams);
     //	values
     $values = array();
     $rawValues = array();
     $fields = $this->pSet->getFieldsList();
     foreach ($fields as $f) {
         $value = $this->showDBValue($f, $data, $keylink);
         $values[$f] = $value;
         if (IsBinaryType($this->pSet->getFieldType($f))) {
             $rawValues[$f] = "";
         } else {
             $rawValues[$f] = substr($data[$f], 0, 100);
         }
     }
     $returnJSON['keys'] = $this->jsKeys;
     $returnJSON['keyFields'] = $this->keyFields;
     $returnJSON['vals'] = $values;
     $returnJSON['fields'] = $fields;
     $returnJSON['rawVals'] = $rawValues;
     $returnJSON['hrefs'] = $this->buildDetailGridLinks($returnJSON['detKeys']);
     //	the record might become non-editable after updating
     if (!$this->IsRecordEditable(false)) {
         $returnJSON['nonEditable'] = true;
     }
     return $returnJSON;
 }
Exemplo n.º 15
0
 /**	
  * Fetch a result row as an  array
  * @param Mixed qHanle				The query handle
  * @param Number assoc (optional)
  * @return Array
  */
 protected function _fetch_array($qHanle, $assoc = 1)
 {
     $ret = array();
     if ($qHanle->EOF()) {
         return false;
     }
     try {
         for ($i = 0; $i < $this->num_fields($qHanle); $i++) {
             if (IsBinaryType($qHanle->Fields[$i]->Type) && $qHanle->Fields[$i]->Type != 128 || $qHanle->Fields[$i]->Type == 203) {
                 $str = "";
                 if ($qHanle->Fields[$i]->ActualSize > 0) {
                     $size = $qHanle->Fields[$i]->ActualSize;
                     $val = $qHanle->Fields[$i]->GetChunk($size);
                     if (is_array($val) || is_object($val)) {
                         $str = str_pad("", $size);
                         $j = 0;
                         foreach ($val as $byte) {
                             $str[$j++] = chr($byte);
                         }
                     } else {
                         $str = $val;
                     }
                 }
                 if ($assoc) {
                     $ret[$qHanle->Fields[$i]->Name] = $str;
                 } else {
                     $ret[$i] = $str;
                 }
             } else {
                 $value = $qHanle->Fields[$i]->Value;
                 if (is_null($value)) {
                     $val = NULL;
                 } else {
                     if (isdatefieldtype($qHanle->Fields[$i]->Type)) {
                         $value = localdatetime2db((string) $qHanle->Fields[$i]->Value, $this->access_dmy);
                     }
                     if (IsNumberType($qHanle->Fields[$i]->Type)) {
                         $val = floatval($value);
                     } else {
                         $val = strval($value);
                     }
                 }
                 if ($assoc) {
                     $ret[$qHanle->Fields[$i]->Name] = $val;
                 } else {
                     $ret[$i] = $val;
                 }
             }
         }
         $qHanle->MoveNext();
     } catch (com_exception $e) {
         trigger_error($e->getMessage(), E_USER_ERROR);
     }
     return $ret;
 }
Exemplo n.º 16
0
	function IsBinary()
	{
		return IsBinaryType($this->GetType());
	}
Exemplo n.º 17
0
 /**
  * Delete selected records
  */
 function deleteRecords()
 {
     global $globalEvents;
     $this->deleteMessage = "";
     if (@$_REQUEST["mdelete"]) {
         foreach (@$_REQUEST["mdelete"] as $ind) {
             for ($i = 0; $i < count($this->arrKeyFields); $i++) {
                 $keys[$this->arrKeyFields[$i]] = refine($_REQUEST["mdelete" . ($i + 1)][mdeleteIndex($ind)]);
             }
             $this->selectedRecs[] = $keys;
         }
     } elseif (@$_REQUEST["selection"]) {
         foreach (@$_REQUEST["selection"] as $keyblock) {
             $arr = explode("&", refine($keyblock));
             if (count($arr) < count($this->arrKeyFields)) {
                 continue;
             }
             for ($i = 0; $i < count($this->arrKeyFields); $i++) {
                 $keys[$this->arrKeyFields[$i]] = urldecode(@$arr[$i]);
             }
             $this->selectedRecs[] = $keys;
         }
     }
     $this->recordsDeleted = 0;
     $this->lockDelRec = array();
     foreach ($this->selectedRecs as $keys) {
         $where = KeyWhere($keys);
         //	delete only owned records
         if ($this->nSecOptions != ADVSECURITY_ALL && $this->nLoginMethod == SECURITY_TABLE && $this->createLoginPage) {
             $where = whereAdd($where, SecuritySQL("Delete"));
         }
         $strSQl = "delete from " . AddTableWrappers($this->origTName) . " where " . $where;
         $retval = true;
         $deletedrs = db_query(SQLQuery::gSQLWhere_having($this->gsqlHead, $this->gsqlFrom, $this->gsqlWhereExpr, $this->gsqlGroupBy, $this->gsqlHaving, $where), $this->conn);
         $deleted_values = $this->cipherer->DecryptFetchedArray($deletedrs);
         if ($globalEvents->exists("IsRecordEditable", $this->tName)) {
             if (!$globalEvents->IsRecordEditable($deleted_values, true, $this->tName)) {
                 continue;
             }
         }
         if ($this->eventExists("BeforeDelete")) {
             $tdeleteMessage = $this->deleteMessage;
             $retval = $this->eventsObject->BeforeDelete($where, $deleted_values, $tdeleteMessage, $this);
             $this->deleteMessage = $tdeleteMessage;
         }
         $lockRecord = false;
         if ($this->lockingObj) {
             $lockWhere = "";
             foreach ($keys as $keysvalue) {
                 $lockWhere .= rawurlencode($keysvalue) . "&";
             }
             $lockWhere = substr($lockWhere, 0, -1);
             $lockSQL = "select * from " . AddTableWrappers("") . " where " . AddFieldWrappers("keys") . "=" . db_prepare_string($lockWhere) . " and " . AddFieldWrappers("table") . "=" . db_prepare_string($this->origTName) . " and " . AddFieldWrappers("action") . "=1";
             $lockSet = db_query($lockSQL, $this->conn);
             if ($data = db_fetch_array($lockSet)) {
                 $lockRecord = true;
                 $this->lockDelRec[] = $keys;
             }
             if ($this->mode == LIST_SIMPLE) {
                 $_SESSION[$this->sessionPrefix . "_lockDelRec"] = $this->lockDelRec;
             }
         }
         if (!$lockRecord && @$_REQUEST["a"] == "delete" && $retval) {
             $this->recordsDeleted++;
             // delete associated uploaded files if any
             DeleteUploadedFiles($this->pSet, $deleted_values);
             LogInfo($strSQl);
             db_exec($strSQl, $this->conn);
             if ($this->audit && $deleted_values) {
                 $fieldsList = $this->pSet->getFieldsList();
                 $i = 0;
                 foreach ($deleted_values as $key => $value) {
                     if (IsBinaryType($this->pSet->getFieldType($fieldsList[$i]))) {
                         $deleted_audit_values[$fieldsList[$i]] = $value;
                     } else {
                         $deleted_audit_values[$key] = $value;
                     }
                     $i++;
                 }
                 $this->audit->LogDelete($this->tName, $deleted_audit_values, $keys);
             }
             if ($this->eventExists("AfterDelete")) {
                 $tdeleteMessage = $this->deleteMessage;
                 $this->eventsObject->AfterDelete($where, $deleted_values, $tdeleteMessage, $this);
                 $this->deleteMessage = $tdeleteMessage;
             }
         }
         if (strlen($this->deleteMessage)) {
             $this->xt->assignbyref("message", $this->deleteMessage);
             $this->xt->assign("message_block", true);
         }
     }
     if (count($this->selectedRecs) && $this->eventExists("AfterMassDelete")) {
         $this->eventsObject->AfterMassDelete($this->recordsDeleted, $this);
     }
 }
Exemplo n.º 18
0
function add_db_quotes($field, $value, $table = "", $type = null)
{
    global $strTableName;
    if ($table == "") {
        $table = $strTableName;
    }
    $pSet = new ProjectSettings($table);
    if ($type == null) {
        $type = $pSet->getFieldType($field);
    }
    if (IsBinaryType($type)) {
        return db_addslashesbinary($value);
    }
    if (($value === "" || $value === FALSE || is_null($value)) && !IsCharType($type)) {
        return "null";
    }
    if (NeedQuotes($type)) {
        if (!IsDateFieldType($type)) {
            $value = db_prepare_string($value);
        } else {
            $value = db_datequotes($value);
        }
    } else {
        $strvalue = (string) $value;
        $strvalue = str_replace(",", ".", $strvalue);
        if (is_numeric($strvalue)) {
            $value = $strvalue;
        } else {
            $value = 0;
        }
    }
    return $value;
}
Exemplo n.º 19
0
 function LogDelete($str_table, $values, $keys)
 {
     global $globalEvents;
     $retval = true;
     $table = $str_table;
     $pSet = new ProjectSettings($str_table);
     $arr = array();
     if ($globalEvents->exists("OnAuditLog")) {
         $retval = $globalEvents->OnAuditLog($this->strDelete, $this->params, $table, $keys, $values, $arr);
     }
     if ($retval) {
         if (count($keys) > 0) {
             $key = "";
             foreach ($keys as $idx => $val) {
                 if ($key != "") {
                     $key .= ",";
                 }
                 $key .= $val;
             }
         }
         $fp = $this->CreateLogFile();
         $str = format_datetime_custom(db2time(now()), "MMM dd,yyyy") . chr(9) . format_datetime_custom(db2time(now()), "HH:mm:ss") . chr(9) . $this->params[0] . chr(9) . $this->params[1] . chr(9) . $table . chr(9) . $this->strDelete . chr(9) . $key;
         $str_add = "";
         if ($this->logValueEnable($str_table)) {
             foreach ($values as $idx => $val) {
                 $v = "";
                 if (IsBinaryType($pSet->getFieldType($idx))) {
                     $v = "<binary value>";
                 } else {
                     $v = str_replace(array("\r\n", "\n", "\t"), " ", $val);
                     if (strlen($v) > $this->maxFieldLength) {
                         $v = substr($v, 0, $this->maxFieldLength);
                     }
                 }
                 if ($fp) {
                     $str_add .= $str . chr(9) . $idx . chr(9) . $v . "\r\n";
                 }
             }
         } else {
             $str_add = $str . "\r\n";
         }
         if ($fp) {
             fputs($fp, $str_add);
             fclose($fp);
         }
     }
     return $retval;
 }
Exemplo n.º 20
0
 /**
  * Get the field's content
  * @param &Array data
  * @param String keylink
  * @return String	 
  */
 public function showDBValue(&$data, $keylink = "")
 {
     $value = $data[$this->field];
     if (IsBinaryType($this->fieldType)) {
         $value = "código binario demasiado grande – no puede ser desplegado";
         $this->searchHighlight = false;
     }
     if ($value === false) {
         $value = "";
     }
     if ($this->editFormat == EDIT_FORMAT_CHECKBOX && $this->viewFormat == FORMAT_NONE) {
         if ($value && $value != 0) {
             $value = "Sí";
         } else {
             $value = "No";
         }
         $this->searchHighlight = false;
     }
     if ($this->container->forExport == "excel" || $this->container->forExport == "csv") {
         return $value;
     }
     $processedText = $this->processText($value, $keylink);
     return nl2br($processedText);
 }
function WRadd_db_quotes($field,$value,$table="")
{
	$type = WRGetFieldType($table.".".$field);
	if(IsBinaryType($type))
		return db_addslashesbinary($value);
	if(($value==="" || $value===FALSE) && !IsCharType($type))
		return "null";
	if(NeedQuotes($type))
	{
		if(!IsDateFieldType($type))
			$value=db_prepare_string($value);
		else
			$value=db_datequotes($value);
	}
	else
	{
		$strvalue = (string)$value;
		$strvalue = str_replace(",",".",$strvalue);
		if(is_numeric($strvalue))
			$value=$strvalue;
		else
			$value=0;
	}
	return $value;
}
Exemplo n.º 22
0
 /**
  * Get an array containing the record save status
  * @return Array
  */
 protected function getSaveStatusJSON()
 {
     $returnJSON = array();
     if ($this->action != "added" || $this->mode == ADD_SIMPLE) {
         return $returnJSON;
     }
     $returnJSON['success'] = $this->insertedSuccessfully;
     $returnJSON['message'] = $this->message;
     if (!$this->isCaptchaOk) {
         $returnJSON['captcha'] = false;
     } elseif ($this->mode == ADD_POPUP || $this->mode == ADD_MASTER || $this->mode == ADD_MASTER_POPUP) {
         if (isset($_SESSION[$this->tName . "_count_captcha"]) || $_SESSION[$this->tName . "_count_captcha"] > 0 || $_SESSION[$this->tName . "_count_captcha"] < 5) {
             $respJSON['hideCaptcha'] = true;
         }
     }
     if (!$this->insertedSuccessfully) {
         return $returnJSON;
     }
     $jsKeys = array();
     $keyFields = $this->pSet->getTableKeys();
     foreach ($keyFields as $idx => $f) {
         $jsKeys[$idx] = $this->keys[$f];
     }
     if ($this->mode == ADD_ONTHEFLY) {
         $addedData = $this->GetAddedDataLookupQuery(false, $this->mainTable, $this->mainField, $this->mainPageType);
         $data =& $addedData[0];
         if (count($data)) {
             $respData = array($addedData[1]["linkField"] => @$data[$addedData[1]["linkFieldIndex"]], $addedData[1]["displayField"] => @$data[$addedData[1]["displayFieldIndex"]]);
         } else {
             $respData = array($addedData[1]["linkField"] => @$this->newRecordData[$addedData[1]["linkField"]], $addedData[1]["displayField"] => @$this->newRecordData[$addedData[1]["displayField"]]);
         }
         $returnJSON['keys'] = $jsKeys;
         $returnJSON['vals'] = $respData;
         $returnJSON['keyFields'] = $keyFields;
         return $returnJSON;
     }
     //	get current values and show edit controls
     $data = array();
     $haveData = true;
     $linkAndDispVals = array();
     if (count($this->keys)) {
         $where = $this->keysSQLExpression($this->keys);
         //	select only owned records
         if ($this->pSet->getAdvancedSecurityType() != ADVSECURITY_ALL) {
             $where = whereAdd($where, SecuritySQL("Search", $this->tName));
         }
         if ($this->mode == ADD_INLINE && $this->forListPageWithSearch) {
             $addedData = $this->GetAddedDataLookupQuery(true, $this->mainTable, $this->mainField, $this->mainPageType);
             $data =& $addedData[0];
             $linkAndDispVals = array('linkField' => $addedData[0][$addedData[1]["linkField"]], 'displayField' => $addedData[0][$addedData[1]["displayField"]]);
         } else {
             $strSQL = $this->gQuery->gSQLWhere_having_fromQuery('', $where, '');
             $data = $this->cipherer->DecryptFetchedArray($this->connection->query($strSQL)->fetchAssoc());
         }
     }
     if (!$data) {
         $data = $this->newRecordData;
         $haveData = false;
     }
     $showDetailKeys = array();
     foreach ($this->pSet->getDetailTablesArr() as $dt) {
         foreach ($dt["masterKeys"] as $idx => $dk) {
             $showDetailKeys[$dt['dDataSourceTable']]["masterkey" . ($idx + 1)] = $data[$dk];
         }
     }
     $keyParams = array();
     foreach ($this->pSet->getTableKeys() as $i => $kf) {
         $keyParams[] = "key" . ($i + 1) . "=" . runner_htmlspecialchars(rawurlencode(@$data[$kf]));
     }
     $keylink = "&" . implode("&", $keyParams);
     $showValues = array();
     $showFields = array();
     $showRawValues = array();
     $allFields = $this->pSet->getFieldsList();
     foreach ($allFields as $f) {
         if (($this->mode == ADD_MASTER || $this->mode == ADD_MASTER_POPUP) && $this->pSet->appearOnAddPage($f) || $this->pSet->appearOnListPage($f)) {
             $showValues[$f] = $this->showDBValue($f, $data, $keylink);
             $showFields[] = $f;
         }
         if (IsBinaryType($this->pSet->getFieldType($f))) {
             $showRawValues[$f] = "";
         } else {
             $showRawValues[$f] = substr($data[$f], 0, 100);
         }
     }
     if ($this->mode == ADD_INLINE || $this->mode == ADD_POPUP || $this->mode == ADD_DASHBOARD) {
         $returnJSON['keys'] = $jsKeys;
         $returnJSON['vals'] = $showValues;
         $returnJSON['noKeys'] = !$haveData;
         $returnJSON['fields'] = $showFields;
         $returnJSON['keyFields'] = $keyFields;
         $returnJSON['rawVals'] = $showRawValues;
         $returnJSON['detKeys'] = $showDetailKeys;
         $returnJSON['hrefs'] = $this->buildDetailGridLinks($showDetailKeys);
         // add link and display value if list page is lookup with search
         if (count($linkAndDispVals)) {
             $returnJSON['linkValue'] = $linkAndDispVals['linkField'];
             $returnJSON['displayValue'] = $linkAndDispVals['displayField'];
         }
         if ($this->eventsObject->exists("IsRecordEditable", $this->tName)) {
             if (!$this->eventsObject->IsRecordEditable($showRawValues, true, $this->tName)) {
                 $returnJSON['nonEditable'] = true;
             }
         }
         return $returnJSON;
     }
     if ($this->mode == ADD_MASTER || $this->mode == ADD_MASTER_POPUP) {
         $_SESSION["message_add"] = $this->message ? $this->message : "";
         $returnJSON['afterAddId'] = $this->afterAdd_id;
         $returnJSON['fields'] = $showFields;
         $returnJSON['vals'] = $showValues;
         if ($this->mode == ADD_MASTER_POPUP) {
             $returnJSON['keys'] = $jsKeys;
             $returnJSON['noKeys'] = !$haveData;
             $returnJSON['keyFields'] = $keyFields;
             $returnJSON['rawVals'] = $showRawValues;
             $returnJSON['detKeys'] = $showDetailKeys;
             $returnJSON['hrefs'] = $this->buildDetailGridLinks($showDetailKeys);
             if ($this->eventsObject->exists("IsRecordEditable", $this->tName)) {
                 if (!$this->eventsObject->IsRecordEditable($showRawValues, true, $this->tName)) {
                     $returnJSON['nonEditable'] = true;
                 }
             }
         }
         $dpParams = array();
         if ($this->isShowDetailTables && !isMobile()) {
             $dpParams = $this->getDetailsParams($this->id);
         }
         $returnJSON['mKeys'] = array();
         for ($i = 0; $i < count($dpParams['ids']); $i++) {
             $data = 0;
             if (count($this->keys)) {
                 $where = KeyWhere($this->keys);
                 //	select only owned records
                 if ($this->pSet->getAdvancedSecurityType() != ADVSECURITY_ALL) {
                     $where = whereAdd($where, SecuritySQL("Search", $this->tName));
                 }
                 $strSQL = $this->gQuery->gSQLWhere($where);
                 LogInfo($strSQL);
                 $data = $this->cipherer->DecryptFetchedArray($this->connection->query($strSQL)->fetchAssoc());
             }
             if (!$data) {
                 $data = $this->newRecordData;
             }
             $mKeyId = 1;
             $mKeys = $this->pSet->getMasterKeysByDetailTable($dpParams['strTableNames'][$i]);
             foreach ($mKeys as $mk) {
                 if ($data[$mk]) {
                     $returnJSON['mKeys'][$dpParams['strTableNames'][$i]]['masterkey' . $mKeyId++] = $data[$mk];
                 } else {
                     $returnJSON['mKeys'][$dpParams['strTableNames'][$i]]['masterkey' . $mKeyId++] = '';
                 }
             }
         }
         return $returnJSON;
     }
 }
Exemplo n.º 23
0
/**
 * @param String field
 * @param Mixed value
 * @param String table		The datasource table name
 * @param String type
 * @intellisense
 */
function add_db_quotes($field, $value, $table = "", $type = null)
{
    global $strTableName, $locale_info, $cman;
    if ($table == "") {
        $table = $strTableName;
    }
    $pSet = new ProjectSettings($table);
    $connection = $cman->byTable($table);
    if ($type == null) {
        $type = $pSet->getFieldType($field);
    }
    if (IsBinaryType($type)) {
        return $connection->addSlashesBinary($value);
    }
    if (($value === "" || $value === FALSE || is_null($value)) && !IsCharType($type)) {
        return "null";
    }
    if (NeedQuotes($type)) {
        if (!IsDateFieldType($type)) {
            $value = $connection->prepareString($value);
        } else {
            $y = "(\\d\\d\\d\\d)";
            $m = "(0?[1-9]|1[0-2])";
            $d = "(0?[1-9]|[1-2][0-9]|3[0-1])";
            $delim = "(-|" . preg_quote($locale_info["LOCALE_SDATE"], "/") . ")";
            $reg = "/" . $d . $delim . $m . $delim . $y . "|" . $m . $delim . $d . $delim . $y . "|" . $y . $delim . $m . $delim . $d . "/";
            if (!preg_match($reg, $value, $matches)) {
                return "null";
            }
            $value = $connection->addDateQuotes($value);
        }
    } else {
        $strvalue = (string) $value;
        if (is_numeric($strvalue)) {
            $value = str_replace(",", ".", $strvalue);
        } else {
            $value = 0;
        }
        if ($connection->dbType == nDATABASE_PostgreSQL) {
            // if boolean type field, add quotes
            if ($type == 11) {
                $value = strtolower($value);
                if (!strlen($value) || $value == 0 || $value == "0" || $value == "false" || $value == "f" || $value == "n" || $value == "no" || $value == "off") {
                    $value = "f";
                } else {
                    $value = "t";
                }
                $value = $connection->prepareString($value);
            }
        }
    }
    return $value;
}
Exemplo n.º 24
0
 /**
  * @param String strSearchOption
  * @return String | Boolean
  */
 function baseSQLWhere($strSearchOption)
 {
     if (IsBinaryType($this->type)) {
         return false;
     }
     if ($this->connection->dbType != nDATABASE_MySQL) {
         $this->btexttype = IsTextType($this->type);
     }
     if ($this->connection->dbType == nDATABASE_MSSQLServer) {
         if ($this->btexttype && $strSearchOption != "Contains" && $strSearchOption != "Starts with") {
             return false;
         }
     }
     if ($strSearchOption != 'Empty') {
         return "";
     }
     $fullFieldName = $this->getFieldSQLDecrypt();
     if (IsCharType($this->type) && (!$this->ismssql || !$this->btexttype) && !$this->isOracle) {
         return "(" . $fullFieldName . " is null or " . $fullFieldName . "='')";
     }
     if ($this->ismssql && $this->btexttype) {
         return "(" . $fullFieldName . " is null or " . $fullFieldName . " LIKE '')";
     }
     return $fullFieldName . " is null";
 }
Exemplo n.º 25
0
function save_sql($type)
{
    global $cman;
    $sql_query = "";
    $sql_where = "";
    $sql_order_by = "";
    $sql_order_by_preview = "";
    $sql_group_by = "";
    $root =& $_SESSION[$type];
    $_connection = $cman->getForWebReports();
    if (is_wr_project()) {
        $_connection = $cman->byTable($root['tables'][0]);
    }
    switch ($type) {
        case "webreports":
            if (!empty($root['sort_fields'])) {
                $sql_order_by .= " \nORDER BY ";
                foreach ($root['sort_fields'] as $arr) {
                    if (is_wr_project()) {
                        $sql_order_by .= $_connection->AddFieldWrappers($arr['name']);
                    } else {
                        $table = "";
                        $field = "";
                        WRSplitFieldName($arr['name'], $table, $field);
                        if ($table) {
                            $sql_order_by .= $_connection->AddTableWrappers($table) . "." . $_connection->AddFieldWrappers($field);
                        } else {
                            $sql_order_by .= $_connection->AddFieldWrappers($field);
                        }
                    }
                    $sql_order_by .= $arr["desc"] == "true" ? " DESC, " : " ASC, ";
                }
                $sql_order_by = substr($sql_order_by, 0, -2);
            }
            if (is_wr_custom()) {
                $arr = getCustomSQLbyName($root["tables"][0]);
                $sql_query = $arr[2];
                $sql_query_preview = $arr[2];
                $sql_where = "";
                $sql_group_by = "";
                break;
            }
            $arr_fields_all = array();
            if (!empty($root['totals'])) {
                foreach ($root['totals'] as $fld) {
                    if ($fld["show"] == "true") {
                        $alias = " as " . $_connection->AddFieldWrappers(GoodFieldName($fld["table"] . "." . $fld["name"]));
                        $arr_fields_all[] = $_connection->AddTableWrappers($fld["table"]) . "." . $_connection->AddFieldWrappers($fld["name"]) . $alias;
                        if (!IsBinaryType(WRGetFieldType($fld["table"] . "." . $fld["name"]))) {
                            $arr_fields_nb[] = $_connection->AddTableWrappers($fld["table"]) . "." . $_connection->AddFieldWrappers($fld["name"]) . $alias;
                        }
                    }
                }
            } else {
                $table_name = $root['tables'][0];
                $arr_fields = WRGetFieldsList($table_name);
                for ($j = 0; $j < count($arr_fields); $j++) {
                    $arr_fields_all[] = $_connection->AddTableWrappers($table_name) . "." . $_connection->AddFieldWrappers($arr_fields[$j]);
                    if (!IsBinaryType(WRGetFieldType($table_name . "." . $arr_fields[$j]))) {
                        $arr_fields_nb[] = $_connection->AddTableWrappers($table_name) . "." . $_connection->AddFieldWrappers($arr_fields[$j]);
                    }
                }
            }
            $sql_query = "";
            //			$sql_query .= " \nFROM " . AddTableWrappers($root['tables'][0]);
            $sql_query .= " \n" . make_from_clause($type);
            /*		
            			if ( !empty( $root['table_relations'] ) ){
            				$arr_relations = array_slice(explode("@END@", $root['table_relations']["relations"]), 0, -1);
            				foreach ($arr_relations as $rel) {
            					$arr_parts = explode("@SEP@", $rel);
            					$sql_query .= $arr_parts[0];
            				}
            			}
            */
            $sql_query_preview = "SELECT\n" . implode(", \n", $arr_fields_nb) . $sql_query;
            $sql_query = "SELECT\n" . implode(", \n", $arr_fields_all) . $sql_query;
            if (!empty($root['where_condition'])) {
                $sql_where .= " \nWHERE ";
                foreach ($root['where_condition'] as $arr) {
                    WRSplitFieldName($arr['field_opt'], $t, $f);
                    $fld_name = $_connection->AddTableWrappers($t) . "." . $_connection->AddFieldWrappers($f);
                    $sql_where .= "( " . $fld_name . $arr['filter_value'];
                    $sql_where .= $arr['first_or_value'] == "" ? "" : " OR " . $fld_name . $arr['first_or_value'];
                    $sql_where .= $arr['second_or_value'] == "" ? "" : " OR " . $fld_name . $arr['second_or_value'];
                    $sql_where .= $arr['third_or_value'] == "" ? "" : " OR " . $fld_name . $arr['third_or_value'];
                    $sql_where .= " ) AND ";
                }
                $sql_where = substr($sql_where, 0, -5);
            }
            break;
        case "webcharts":
            if (is_wr_custom()) {
                $arr = getCustomSQLbyName($root["tables"][0]);
                $sql_query = $arr[2];
                $sql_query_preview = $arr[2];
                $sql_where = "";
                $sql_order_by = "";
                $sql_order_by_preview = "";
                $sql_group_by = "";
                break;
            }
            $table_name = $root['tables'][0];
            $arr_join_tables = getChartTablesList();
            foreach ($arr_join_tables as $tbl) {
                $arr_fields_join = WRGetFieldsList($tbl);
                for ($j = 0; $j < count($arr_fields_join); $j++) {
                    $arr_fields[] = $arr_fields_join[$j];
                    $arr_fields_all[] = $_connection->AddTableWrappers($tbl) . "." . $_connection->AddFieldWrappers($arr_fields_join[$j]);
                    $arr_label[$_connection->AddTableWrappers($tbl) . "." . $_connection->AddTableWrappers($arr_fields_join[$j])] = $tbl . "_" . $arr_fields_join[$j];
                }
            }
            $sql_query = "SELECT\n";
            $sql_query_preview = "SELECT\n";
            //
            if (!empty($root['parameters'])) {
                if (is_groupby_chart()) {
                    foreach ($root['parameters'] as $idx => $arr) {
                        if ($arr["name"] == "") {
                            continue;
                        }
                        $fld = $_connection->AddTableWrappers($arr["table"]) . "." . $_connection->AddFieldWrappers($arr["name"]);
                        if ($arr["agr_func"] != "") {
                            $fld = $arr["agr_func"] . "(" . $fld . ")";
                            if ($idx < count($arr_fields) - 1 && $arr["label"]) {
                                //	adding alias to Data series field
                                $fld .= " AS " . $_connection->AddFieldWrappers($arr["agr_func"] . "_" . $arr_label[$_connection->AddTableWrappers($arr["table"]) . "." . $_connection->AddFieldWrappers($arr["name"])]);
                            } else {
                                if ($arr["agr_func"] != "GROUP BY") {
                                    //	adding alias to Label field
                                    $fld .= " AS " . $_connection->AddFieldWrappers($arr["agr_func"] . "_" . $arr_label[$_connection->AddTableWrappers($arr["table"]) . "." . $_connection->AddFieldWrappers($arr["name"])]);
                                }
                            }
                        } else {
                            $fld .= " AS " . $_connection->AddFieldWrappers($arr_label[$_connection->AddTableWrappers($arr["table"]) . "." . $_connection->AddFieldWrappers($arr["name"])]);
                        }
                        $sql_query .= $fld . ", \n";
                    }
                    for ($i = 0; $i < count($root['group_by_condition']) - 1; $i++) {
                        $arr = $root['group_by_condition'][$i];
                        if ($arr["field_opt"] == "" || $arr["group_by_value"] == -1) {
                            continue;
                        }
                        $ttable = "";
                        $tfield = "";
                        WRSplitFieldName($arr["field_opt"], $ttable, $tfield);
                        $fld = $_connection->AddTableWrappers($ttable) . "." . $_connection->AddFieldWrappers($tfield);
                        if ($arr["group_by_value"] != -1 && $arr["group_by_value"] != "GROUP BY") {
                            $fld = $arr["group_by_value"] . "(" . $fld . ")" . " AS " . $_connection->AddFieldWrappers($arr["group_by_value"] . "_" . $arr_label[$fld]);
                        } else {
                            if ($arr["group_by_value"] == "GROUP BY") {
                                $fld .= " AS " . $_connection->AddFieldWrappers($arr_label[$arr_fields_all[$i]]);
                            }
                        }
                        $sql_query_preview .= $fld . ", \n";
                    }
                } else {
                    for ($j = 0; $j < count($arr_fields_all); $j++) {
                        if (!IsBinaryType(WRGetFieldType($arr_fields_all[$j]))) {
                            $sql_query .= $arr_fields_all[$j] . " AS " . $_connection->AddFieldWrappers($arr_label[$arr_fields_all[$j]]) . ", \n";
                            $sql_query_preview .= $arr_fields_all[$j] . " AS " . $_connection->AddFieldWrappers($arr_label[$arr_fields_all[$j]]) . ", \n";
                        }
                    }
                }
                $sql_query = substr($sql_query, 0, -3);
                $sql_query_preview = substr($sql_query_preview, 0, -3);
            }
            $sql_query .= " \n" . make_from_clause($type);
            $sql_query_preview .= " \n" . make_from_clause($type);
            //
            $sql_where = "";
            if (!empty($root['group_by_condition'][0])) {
                for ($i = 0; $i < count($root['group_by_condition']) - 1; $i++) {
                    $arr = $root['group_by_condition'][$i];
                    $fld = array(0 => "", 1 => "");
                    WRSplitFieldName($arr['field_opt'], $t, $f);
                    $fld_name = $_connection->AddTableWrappers($t) . "." . $_connection->AddFieldWrappers($f);
                    if ($arr['filter_value'] == "") {
                        continue;
                    }
                    if (strlen($sql_where)) {
                        $sql_where .= " AND ";
                    }
                    $sql_where .= "(" . $fld_name . $arr['filter_value'];
                    $sql_where .= $arr['first_or_value'] == "" ? "" : " OR " . $fld_name . $arr['first_or_value'];
                    $sql_where .= $arr['second_or_value'] == "" ? "" : " OR " . $fld_name . $arr['second_or_value'];
                    $sql_where .= $arr['third_or_value'] == "" ? "" : " OR " . $fld_name . $arr['third_or_value'];
                    $sql_where .= ")";
                }
                if (strlen($sql_where)) {
                    $sql_where = " WHERE " . $sql_where;
                }
                $group_by_clause = "";
                $having_clause = "";
                if (is_groupby_chart()) {
                    for ($i = 0; $i < count($root['group_by_condition']) - 1; $i++) {
                        $arr = $root['group_by_condition'][$i];
                        $table_name = "";
                        $field_name = "";
                        WRSplitFieldName($arr['field_opt'], $table_name, $field_name);
                        $fld_name = $_connection->AddTableWrappers($table_name) . "." . $_connection->AddFieldWrappers($field_name);
                        if ($arr['group_by_value'] != "-1") {
                            if ($arr['group_by_value'] == "GROUP BY") {
                                $group_by_clause .= $fld_name . ", ";
                            }
                            if (!empty($arr['having_value'])) {
                                if ($arr["group_by_value"] != "GROUP BY" && $arr["group_by_value"] != "-1") {
                                    $fld_name = $arr["group_by_value"] . "(" . $fld_name . ")";
                                }
                                $having_clause .= $fld_name . " " . $arr['having_value'] . " AND ";
                            }
                        }
                    }
                    if ($group_by_clause != "") {
                        $group_by_clause = "\nGROUP BY " . substr($group_by_clause, 0, -2);
                    }
                    if ($having_clause != "") {
                        $having_clause = "\nHAVING " . substr($having_clause, 0, -5);
                    }
                    $sql_group_by = $group_by_clause . $having_clause;
                }
                //	calc order by clause
                $arr_order = array();
                for ($i = 0; $i < count($root['group_by_condition']) - 1; $i++) {
                    $arr = $root['group_by_condition'][$i];
                    if ($arr["sort_dir"] == "-1" || is_groupby_chart() && $arr['group_by_value'] == -1) {
                        continue;
                    }
                    WRSplitFieldName($arr['field_opt'], $table_name, $field_name);
                    if (is_groupby_chart() && $arr['group_by_value'] != -1) {
                        $fld_name = $arr["group_by_value"] . "(" . $_connection->AddTableWrappers($table_name) . "." . $_connection->AddFieldWrappers($field_name) . ")";
                        $fld_name_preview = $_connection->AddTableWrappers($table_name) . "." . $_connection->AddFieldWrappers($field_name);
                    } else {
                        $fld_name_preview = $_connection->AddTableWrappers($table_name) . "." . $_connection->AddFieldWrappers($field_name);
                        $fld_name = $_connection->AddTableWrappers($table_name) . "." . $_connection->AddFieldWrappers($field_name);
                    }
                    $arr_order[(int) $arr["sort_order"]] = array("field" => $fld_name, "field_preview" => $fld_name_preview, "dir" => $arr["sort_dir"]);
                }
                if (count($arr_order)) {
                    $arr_sortorders = array_keys($arr_order);
                    sort($arr_sortorders);
                    foreach ($arr_sortorders as $i) {
                        if (strlen($sql_order_by_preview)) {
                            $sql_order_by_preview .= ", ";
                        }
                        if (strlen($sql_order_by)) {
                            $sql_order_by .= ", ";
                        }
                        $sql_order_by_preview .= $arr_order[$i]["field_preview"] . " " . $arr_order[$i]["dir"];
                        $sql_order_by .= $arr_order[$i]["field"] . " " . $arr_order[$i]["dir"];
                    }
                    $sql_order_by_preview = "\nORDER BY " . $sql_order_by_preview;
                    $sql_order_by = "\nORDER BY " . $sql_order_by;
                }
            }
            //$sql_query_preview = $sql_query;
            break;
        default:
            break;
    }
    $_SESSION[$type]['sql'] = $sql_query;
    $_SESSION[$type]['sql_preview'] = $sql_query_preview;
    $_SESSION[$type]['where'] = $sql_where;
    $_SESSION[$type]['order_by'] = $sql_order_by;
    $_SESSION[$type]['order_by_preview'] = $sql_order_by_preview;
    $_SESSION[$type]['group_by'] = $sql_group_by;
    $_SESSION["object_sql"] = $sql_query;
}
Exemplo n.º 26
0
	$aGroupFields[] = $xml_array['tables'][0]."_".$xml_array['group_fields'][$i]['name'];
}


$aTotFields=array();


foreach ( $inspect_fields as $fld ) {
	if(is_wr_db())
		$fld_type=WRGetFieldType($fld['table'].".".$fld['name']);
	elseif(is_wr_custom())
		$fld_type=WRCustomGetFieldType($fld['table'],$fld['name']);
	else
		$fld_type=GetFieldType($fld['name'],$fld['table']);	
	
	if ( !IsBinaryType($fld_type)) {
		$aTotFields[] = $fld['table']."_".$fld['name'];
	}
}

$ngFieldNames = array_diff( $aTotFields, $aGroupFields );


$arr_alias = array();
foreach ( $aGroupFields as $gr_name  ) {
	foreach ( $inspect_fields as $fld ) {
		if ( $gr_name == $fld['table']."_".$fld['name'] && !in_array($fld['table']."_".$fld['name'], $arr_alias)) {
			$arr_alias[] = $fld['table']."_".$fld['name'];
			$arr_page_order_fields["data"][] = $fld;
		}
	}
Exemplo n.º 27
0
 /**
  * Get a headers line for an unprocessed data log
  * @param Array importFields
  * @return String
  */
 protected function getImportFieldsLogCSVLine($importFields)
 {
     $headerFields = array();
     foreach ($importFields as $fName) {
         $fType = $this->pSet->getFieldType($fName);
         if (!IsBinaryType($fType)) {
             $headerFields[] = '"' . str_replace('"', '""', $fName) . '"';
         }
     }
     return implode(",", $headerFields);
 }
	function getNBFieldsList()
	{
		$t = $this->getFieldsList();
		$arr = array();
		foreach($t as $f)
			if(!IsBinaryType($this->getFieldType($f)))
				$arr[] = $f;
		return $arr;
	}
function ExportToExcel()
{
    global $rs, $nPageSize, $strTableName, $conn, $eventObj;
    if ($eventObj->exists("ListFetchArray")) {
        $row = $eventObj->ListFetchArray($rs);
    } else {
        $row = db_fetch_array($rs);
    }
    //	if(!$row)
    //		return;
    $arrLabel = array();
    $arrColumnWidth = array();
    $arrTotal = array();
    $arrTotalMessage = array();
    $totals = array();
    $arrFields = array();
    $arrTmpTotal = array();
    $arrFields = GetFieldsList($strTableName);
    $arrTmpTotal = GetTableData($strTableName, ".totalsFields", array());
    foreach ($arrFields as $value) {
        $arrLabel[$value] = label($value, $strTableName);
        $arrColumnWidth[$value] = 10;
        $totals[$value] = 0;
        $totalsType = "";
        foreach ($arrTmpTotal as $tvalue) {
            if ($tvalue["fName"] == $value) {
                $totalsType = $tvalue["totalsType"];
            }
        }
        $totalsFields[] = array('fName' => $value, 'totalsType' => $totalsType, 'viewFormat' => ViewFormat($value, $strTableName));
    }
    // write data rows
    $iNumberOfRows = 0;
    $objPHPExcel = ExportExcelInit($arrLabel, $arrColumnWidth);
    while ((!$nPageSize || $iNumberOfRows < $nPageSize) && $row) {
        countTotals($totals, $totalsFields, $row);
        $values = array();
        $arrData = array();
        $arrDataType = array();
        foreach ($arrFields as $value) {
            if (GetEditFormat($value, $strTableName) == EDIT_FORMAT_LOOKUP_WIZARD || GetEditFormat($value, $strTableName) == EDIT_FORMAT_RADIO) {
                $values[$value] = "";
                if (strlen($row[$value])) {
                    $values[$value] = DisplayLookupWizard($value, $row[$value], $row, "", MODE_EXPORT);
                }
            } elseif (IsBinaryType(GetFieldType($value, $strTableName))) {
                $values[$value] = $row[$value];
            } else {
                if (ViewFormat($value, $strTableName) != FORMAT_FILE_IMAGE && ViewFormat($value, $strTableName) != FORMAT_FILE && ViewFormat($value, $strTableName) != FORMAT_HYPERLINK && ViewFormat($value, $strTableName) != FORMAT_EMAILHYPERLINK && ViewFormat($value, $strTableName) != FORMAT_CHECKBOX) {
                    $format = ViewFormat($value, $strTableName);
                } else {
                    $format = FORMAT_NONE;
                }
                $values[$value] = GetData($row, $value, $format);
            }
        }
        $eventRes = true;
        if ($eventObj->exists('BeforeOut')) {
            $eventRes = $eventObj->BeforeOut($row, $values, $arrColumnWidth, $iNumberOfRows + 1, $objPHPExcel);
        }
        if ($eventRes) {
            $iNumberOfRows++;
            $i = 0;
            foreach ($arrFields as $value) {
                if (IsBinaryType(GetFieldType($value, $strTableName))) {
                    $arrDataType[$value] = "binary";
                } elseif (ViewFormat($value, $strTableName) == FORMAT_FILE_IMAGE) {
                    $arrDataType[$value] = "file";
                } elseif (ViewFormat($value, $strTableName) == FORMAT_DATE_SHORT || ViewFormat($value, $strTableName) == FORMAT_DATE_LONG || ViewFormat($value, $strTableName) == FORMAT_DATE_TIME) {
                    $arrDataType[$value] = "date";
                } else {
                    $arrDataType[$value] = "";
                }
                $arrData[$value] = $values[$value];
            }
            ExportExcelRecord($arrData, $arrDataType, $iNumberOfRows, $objPHPExcel);
        }
        if ($eventObj->exists("ListFetchArray")) {
            $row = $eventObj->ListFetchArray($rs);
        } else {
            $row = db_fetch_array($rs);
        }
    }
    if (count($arrTmpTotal)) {
        foreach ($arrFields as $fName) {
            $value = array();
            foreach ($arrTmpTotal as $tvalue) {
                if ($tvalue["fName"] == $fName) {
                    $value = $tvalue;
                }
            }
            $total = "";
            $totalMess = "";
            if ($value["totalsType"]) {
                if ($value["totalsType"] == "COUNT") {
                    $totalMess = "Count" . ": ";
                } elseif ($value["totalsType"] == "TOTAL") {
                    $totalMess = "Total" . ": ";
                } elseif ($value["totalsType"] == "AVERAGE") {
                    $totalMess = "Average" . ": ";
                }
                $total = GetTotals($fName, $totals[$fName], $value["totalsType"], $iNumberOfRows, $value["viewFormat"]);
            }
            $arrTotal[$fName] = $total;
            $arrTotalMessage[$fName] = $totalMess;
        }
    }
    ExportExcelTotals($arrTotal, $arrTotalMessage, ++$iNumberOfRows, $objPHPExcel);
    $formatExcel = "Excel2007";
    $extExcel = ".xlsx";
    if (@$_REQUEST["type"] == "excel5") {
        $formatExcel = "Excel5";
        $extExcel = ".xls";
    }
    ExportExcelSave(GoodFieldName($strTableName) . $extExcel, $formatExcel, $objPHPExcel);
}