%s %s', $class, $colspan, 'Informe os parametros e clique em consultar!', $lkInsertDef); return; } // Formata a clausula where $where = is_array($tableWhere) ? ArWhereToStr($tableWhere, $fieldParamConsulta, $fieldsForm) : $tableWhere; // Formata a query $query = sprintf('select %s from %s where %s', $fildQuery, $tableName, $where); $result = pg_query($dbCon, $query); $class = $fieldsForm['classLinha']; $class = empty($class) ? "" : " class=\"$class\" "; if ($result && pg_num_rows($result)) { $linha = ""; while ($row = pg_fetch_array($result)) { $linha .= sprintf('', $class); foreach ($fieldsSelect as $key => $value) { if ($value) { $vl = $row[$key]; $linha .= sprintf('%s', GetAlignForm($fieldsTypes[$key]), FormataValue($row, $fieldsTypes, $vl, $fieldImg[$key], $fieldImgOper[$key])); } } foreach ($arOperacao as $key => $value) { $linha .= sprintf('%s', GetOperacoes($key, $value, $row[$arKeyDb[0]])); } $linha .= ''; } $fieldsForm['linhas'] = $linha; } else { $colspan = (count($arFieldSelect) + count($arOperacao)); $fieldsForm['linhas'] = sprintf('%s %s', $class, $colspan, 'Nenhum registro encontrado!', $lkInsertDef); } } function GetCabecalioSelect($arSelect, $arDisplay, &$arFieldForm, $arType, $arOperacao) { $class = $arFieldForm['clasHead']; $class = empty($arFieldForm['clasHead']) ? '' : " clas=\"$class\" "; $str = sprintf("", $class); foreach ($arSelect as $key => $value) { if ($value) { $str .= sprintf('%s', GetAlignForm($arType[$key]), $arDisplay[$key]); } } $oper = count($arOperacao); $str .= $oper ? sprintf('Operações', $oper) : ""; $str .= ''; $arFieldForm['headLinhas'] = $str; } function GetAlignForm($type) { $tp = explode(',', $type); switch ($tp[0]) { case 'texto' : case 'alpha' : case 'alphanumerico' : return 'left'; case 'numero': return 'right'; case 'data': case 'dataHora': return 'center'; default : return 'center'; } } function FormataValue($rowDados, $fieldsTypes, $vl, $fieldImg, $fieldImgOper) { if (isset($fieldImg)) { $imgs = explode(';', $fieldImg); foreach ($imgs as $imgValus) { $arImg = explode(':', $imgValus); if ($arImg[1] == $vl) { if (isset($fieldImgOper)) { $arOper = explode(',', $fieldImgOper); $varUrl = sprintf('&%s=%s', $arOper[2], $rowDados[$arOper[2]]); return GetLinkForm($varUrl, $arOper[3], $arOper[0], $arOper[6], $arOper[4], $arOper[5], $arImg[2]); //'jnAtvCampanha,,cmp_id,116,610, 275, Ativação/Destivação Campanha!' } return sprintf('', $arImg[1], $arImg[2]); } } } return $vl; } function ArWhereToStr($arWhere, $arParam, $arForm) { $str = ""; /* * O array $arWhere tem como chave($key) o campo da busca * e o valor($value) operador a ser utilizado utilizado * * O array $arParam sua chave é igual a chave em $arForm que * contém os valores vindos dos formularios */ foreach ($arWhere as $key => $value) { $campoBusca = $key; $operadorBusca = $value; /* * Esta funcao retorna a chave do array passado no primeiro parametro * quando o valor deste array coincidir com o valor passado no segundo * parametro */ $KeyValor = ArKeyFromValue($arParam, $key); $valorBusca = (strtolower($operadorBusca) == 'like') ? QuotedStr(PreparaLike($arForm[$KeyValor])) : QuotedStr($arForm[$KeyValor]); $str .= (empty($str) ? "" : " AND ") . sprintf('%s %s %s', $campoBusca, $operadorBusca, $valorBusca); } return $str; //$tableWhere = array('cmp_descricao' => 'like'); //$fieldParamConsulta = array('txtConsulta' => 'cmp_descricao'); } function ArSelectToStr($arFields) { global $fieldsDefault; $str = ""; foreach ($arFields as $key => $value) { if ($value) { if ($value == 2) $key = QuotedStr($fieldsDefault[$key]) . ' as ' . $key; if (empty($str)) { $str = $key; } else { $str .= ', ' . $key; } } } return " " . $str . " "; } function ArKeyFromValue($ar, $val) { foreach ($ar as $key => $value) { if ($val == $value) { return $key; } } return ""; } function GetVarForm($arSource, &$arDest) { foreach ($arSource as $key => $values) $arDest[$key] = $arSource[$key]; } function GetOperacoes($oper, $param, $key, $paramAux = '') { $prm = explode(',', $param); $idProg = $GLOBALS['idProg']; $nomeJanela = $prm[0]; $imagem = $prm[1]; $campoKey = $prm[2]; $progId = $prm[3]; $wJan = $prm[4]; $hJan = $prm[5]; $title = $prm[6]; if ($oper == 'insert') { $lk = GetLinkFormInsert($nomeJanela, $imagem); } else if ($oper == 'update') { $varUrl = sprintf('&%s=%s', $campoKey, $key); $lk = GetLinkFormUpdate($varUrl, $nomeJanela, $imagem); } else if ($oper == 'delete') { $nomeFuncao = 'DeletaRegistro'; $lk = GetFormDelete($idProg, $key, $paramAux, $nomeFuncao, $imagem); } else { $varUrl = sprintf('&%s=%s', $campoKey, $key); $lk = GetLinkForm($varUrl, $progId, $nomeJanela, $title, $wJan, $hJan, $imagem); } return $lk; } function GetFormDelete($idProg, $id, $param, $nomeFuncao, $imagem = "") { /* * $param: passar parametro de url completo ex.: &nomeVar=valor */ $link = ""; $img = ""; $imgDef = empty($imagem) ? "imgSite/fecha16.png" : $imagem; $atributos = "resizable=NO,scrollbars=NO"; $janW = $GLOBALS["janW"] ? $GLOBALS["janW"] : 500; $janH = $GLOBALS["janH"] ? $GLOBALS["janH"] : 400; $action = FORM_DELETE; $img = ""; $link = "$img"; return $link; } function InsertDefault(&$arForm, $arDefault) { foreach ($arDefault as $key => $value) { if (!$arForm[$key]) { $arForm[$key] = $arDefault[$key]; } } } function GetAcaoForm($arForm) { /* * Retorna o dipo de acao que o usuario esta realizando * com base no parametro formAction */ if (isset($arForm["btGravar"]) && ($arForm["btGravar"] == "Salvar")) return FORM_SAVE; else if ((isset($arForm["btConsulta"]) && ($arForm["btConsulta"] == "Consultar")) || (!isset($arForm["formAction"]))) return FORM_SELECT; if (isset($arForm["formAction"]) && ($arForm["formAction"] == FORM_NEW)) return FORM_NEW; else if (isset($arForm["formAction"]) && ($arForm["formAction"] == FORM_UPDATE)) return FORM_UPDATE; else if (isset($arForm["formAction"]) && ($arForm["formAction"] == FORM_DELETE)) return FORM_DELETE; else return $arForm["formAction"]; } function ModificaAction(&$fieldsForm, $arFuncoes, $arChange) { $modif = 0; foreach ($arFuncoes as $value) { if (isset($fieldsForm[$value])) $modif = 1; } if ($modif) { $fieldsForm['formAction'] = FORM_UNDEF; } else if (!isset($fieldsForm['btGravar'])) { foreach ($arChange as $key => $value) { if (isset($fieldsForm[$key])) $fieldsForm['formAction'] = $value; } } } function fmtMsg($str, $silent = 1) { $arReplace = array("'", "\n"); if (!$silent) $GLOBALS['jsStartup'][] = sprintf("alert('%s');", trim(str_replace($arReplace, "", $str))); return sprintf('%s', $str); } function fmtErro($str, $erroAnexo = '') { if (!empty($erroAnexo) && IsAdmin()) { $arReplace = array("^", "~", "`", "'", "'", "\n"); $GLOBALS['jsStartup'][] = sprintf("alert('%s %s');", $str, trim(str_replace($arReplace, "", RemoveAcentos($erroAnexo)))); $strJs = $str; $str = sprintf('%s Erro: %s %s', $str); } return $str; } function GetLinkForm($varUrl, $idProg, $nomeJanela, $title = "", $wJan = 0, $hJan = 0, $imagem = "", $text = '') { $link = ""; $img = ""; $imgDef = empty($imagem) ? "imgSite/desel12.gif" : $imagem; $atributos = "resizable=NO,scrollbars=NO"; $janW = $wJan ? $wJan : ($GLOBALS["janW"] ? $GLOBALS["janW"] : 500); $janH = $hJan ? $hJan : ($GLOBALS["janH"] ? $GLOBALS["janH"] : 400); $titleImg = !empty($title) ? $title : 'Operações'; $action = FORM_UNDEF; $img = ""; $link = "$img$text"; return $link; } ?>