Viewing File: /home/cienp/public_html/portal/sql_patr.php
<?
$dt_atua = date("Y-m-d");
echo ".";
switch ($_POST[opc]){
case "ins":
require "$this->include_dir/conecta.php";
$s_id_marc = protecao($_POST[id_marc],'inteiro');
$s_id_forn = protecao($_POST[id_forn],'inteiro');
$s_id_coli = protecao($_POST[id_colb_inst],'inteiro');
$s_id_colt = protecao($_POST[id_colb_test],'inteiro');
$s_nm_equp = protecao($_POST[nm_equp]);
$s_id_setr = protecao($_POST[id_setr],'inteiro');
$s_id_recs = protecao($_POST[id_recs],'inteiro');
$s_vl_patr = protecao($_POST[vl_patr]);
$s_de_parc = protecao($_POST[de_parc]);
$s_vl_patr = str_replace('.','',$s_vl_patr);
$s_vl_patr = str_replace(',','.',$s_vl_patr);
$sql = "INSERT INTO ".$pref_tabl."patr ";
$sql .= "(id_marc, id_forn, id_colb_inst, id_colb_test, nm_equp, id_setr, id_recs, vl_patr, de_parc, dt_cads, id_cads) ";
$sql .= "VALUES ('$s_id_marc', '$s_id_forn', '$s_id_coli', '$s_id_colt', '$s_nm_equp', '$s_id_setr', '$s_id_recs', '$s_vl_patr', '$s_de_parc', '$dt_atua', $linhau[id_user]) ";
#echo $sql;
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=alt_patr&certo=S";
$sqlj = "SELECT MAX(id_patr) as id_patr ";
$sqlj .= "FROM ".$pref_tabl."patr ";
$resj = mysqli_query($conn, $sqlj);
if (mysqli_num_rows($resj) > 0) {
$linhaj = mysqli_fetch_array($resj);
$_POST[id_patr] = $linhaj[id_patr];
}
} else
$onde = "index1.php?pg=ins_patr&certo=N";
break;
case "alt":
$erros = 0;
require "$this->include_dir/conecta.php";
if ($erros == 0) {
$s_id_marc = protecao($_POST[id_marc],'inteiro');
$s_id_forn = protecao($_POST[id_forn],'inteiro');
$s_id_coli = protecao($_POST[id_colb_inst],'inteiro');
$s_id_colt = protecao($_POST[id_colb_test],'inteiro');
$s_nm_equp = protecao($_POST[nm_equp]);
$s_id_setr = protecao($_POST[id_setr],'inteiro');
$s_id_recs = protecao($_POST[id_recs],'inteiro');
$s_vl_patr = protecao($_POST[vl_patr]);
$s_de_parc = protecao($_POST[de_parc]);
$s_fl_atvo = protecao($_POST[fl_atvo]);
$s_id_patr = protecao($_POST[id_patr],'inteiro');
$s_vl_patr = str_replace('.','',$s_vl_patr);
$s_vl_patr = str_replace(',','.',$s_vl_patr);
$sql = "UPDATE ".$pref_tabl."patr ";
$sql .= "SET id_marc = '$s_id_marc', ";
$sql .= "id_forn = '$s_id_forn', ";
$sql .= "id_colb_inst = '$s_id_coli', ";
$sql .= "id_colb_test = '$s_id_colt', ";
$sql .= "nm_equp = '$s_nm_equp', ";
$sql .= "id_setr = '$s_id_setr', ";
$sql .= "id_recs = '$s_id_recs', ";
$sql .= "vl_patr = '$s_vl_patr', ";
$sql .= "de_parc = '$s_de_parc', ";
$sql .= "id_altr = '$linhau[id_user]', ";
$sql .= "dt_altr = '$dt_atua', ";
$sql .= "fl_atvo = '$s_fl_atvo' ";
$sql .= "WHERE id_patr = $s_id_patr ";
$sql .= "LIMIT 1";
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=alt_patr&certo=S";
} else
$onde = "index1.php?pg=alt_patr&certo=N";
}
break;
case "ins_anex":
$erros = 0;
require "$this->include_dir/conecta.php";
$s_id_patr = protecao($_POST[id_patr],'inteiro');
$s_de_arqv = protecao($_POST[de_arqv],'inteiro');
if (!empty($_FILES['de_arqv']['name'])) {
if (($_FILES['de_arqv']['size'] >= 10000000) || ($_FILES['de_arqv']['size'] == 0)) {
$erros++;
$onde = "index1.php?pg=alt_patr&certo=M";
}
if (strtoupper(substr($_FILES['de_arqv']['type'],-3)) != "PDF") {
$erros++;
$onde = "index1.php?pg=alt_patr&certo=F";
}
if (!is_file($_FILES['de_arqv']['tmp_name'])){
$erros++;
$onde = "index1.php?pg=alt_patr&certo=Y";
}
if (is_dir($_FILES['de_arqv']['name'])){
$erros++;
$onde = "index1.php?pg=alt_patr&certo=D";
}
if ($erros == 0) {
$sql = "INSERT INTO ".$pref_tabl."patr_anex ";
$sql .= "(id_patr, de_arqv, dt_cads, id_cads) ";
$sql .= "VALUES ('$s_id_patr', '$s_de_arqv', '$dt_atua', $linhau[id_user])";
#echo $sql;
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=alt_patr&certo=SA";
$sqln = "SELECT MAX(id_anex) as id_anex ";
$sqln .= "FROM ".$pref_tabl."patr_anex ";
$resn = mysqli_query($conn, $sqln);
if (mysqli_num_rows($resn) > 0) {
$linhan = mysqli_fetch_array($resn);
$s_de_arqv = 'Anexo_do_Patrimonio_'.$linhan[id_anex].'.pdf';
if (move_uploaded_file($_FILES['de_arqv']['tmp_name'], "arqv_patr/$s_de_arqv")) {
$sqlv = "UPDATE ".$pref_tabl."patr_anex ";
$sqlv .= "SET de_arqv = '$s_de_arqv' ";
$sqlv .= "WHERE id_anex = $linhan[id_anex] ";
$sqlv .= "LIMIT 1";
$resv = mysqli_query($conn, $sqlv);
if ($resv) {
$onde = "index1.php?pg=alt_patr&certo=SA";
} else {
$onde = "index1.php?pg=alt_patr&certo=N";
}
} else {
$onde = "index1.php?pg=alt_patr&certo=N";
}
} else {
$onde = "index1.php?pg=alt_patr&certo=N";
}
} else {
$onde = "index1.php?pg=alt_patr&certo=N";
}
}
} else {
$onde = "index1.php?pg=alt_patr&certo=V";
}
break;
case "exc_anex":
$erros = 0;
require "$this->include_dir/conecta.php";
$s_id_patr = protecao($_POST[id_patr],'inteiro');
$s_de_arqv = protecao($_POST[de_arqv],'inteiro');
$s_id_anex = protecao($_POST[id_anex],'inteiro');
$sqlv = "DELETE FROM ".$pref_tabl."patr_anex ";
$sqlv .= "WHERE id_anex = '$s_id_anex' ";
$sqlv .= "AND id_patr = '$s_id_patr' ";
$sqlv .= "LIMIT 1";
$resv = mysqli_query($conn, $sqlv);
if ($resv) {
$onde = "index1.php?pg=alt_patr&certo=X";
$s_de_arqv = 'Anexo_do_Patrimonio_'.$s_id_anex.'.pdf';
@unlink("arqv_patr/$s_de_arqv");
} else {
$onde = "index1.php?pg=alt_patr&certo=N";
}
break;
case "exc_foto":
require "$this->include_dir/conecta.php";
$s_id_foto = protecao($_POST[id_foto],'inteiro');
$s_id_patr = protecao($_POST[id_patr],'inteiro');
if ($s_id_foto > 0) {
$sql = "DELETE FROM " . $pref_tabl . "patr_foto ";
$sql .= "WHERE id_foto = '$s_id_foto' ";
$sql .= "AND id_patr = '$s_id_patr' ";
$sql .= "LIMIT 1 ";
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=alt_patr&certo=XG#dv_foto";
@unlink("img_patr/tb_galr_$s_id_foto.jpg");
@unlink("img_patr/galr_$s_id_foto.jpg");
} else {
$onde = "index1.php?pg=alt_patr&certo=NG#dv_foto";
}
} else {
$onde = "index1.php?pg=alt_patr&certo=NG#dv_foto";
}
break;
case "ins_mant":
require "$this->include_dir/conecta.php";
$s_id_patr = protecao($_POST[id_patr],'inteiro');
$s_dt_mant = protecao($_POST[dt_mant],'data');
$s_dt_recb = protecao($_POST[dt_recb],'data');
$s_nu_os = protecao($_POST[nu_os]);
$s_id_forn = protecao($_POST[id_forn],'inteiro');
$s_de_mant = protecao($_POST[de_mant]);
if ($s_dt_mant != '') {
$d1 = explode('/', $s_dt_mant);
$dt_mant = $d1[2]."-".$d1[1]."-".$d1[0];
}
if ($s_dt_recb != '') {
$d2 = explode('/', $s_dt_recb);
$dt_recb = $d2[2]."-".$d2[1]."-".$d2[0];
}
if ($pass == 0) {
$sql = "INSERT INTO ".$pref_tabl."patr_mant ";
$sql .= "(id_patr, dt_mant, dt_recb, nu_os, id_forn, de_mant, dt_cads, id_cads) ";
$sql .= "VALUES ('$s_id_patr', '$dt_mant', '$dt_recb', '$s_nu_os', '$s_id_forn', '$s_de_mant', '$dt_atua', $linhau[id_user])";
#echo $sql;
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=alt_patr&certo=SM";
} else {
$onde = "index1.php?pg=alt_patr&certo=NM";
}
} else {
$onde = "index1.php?pg=ins_patr_mant&certo=J";
}
break;
}
?>
<form name="retorna" method="post" action="">
<input type="hidden" name="id_patr" id="id_patr" value="<?=$_POST[id_patr]?>">
<input type="hidden" name="id_mant" id="id_mant" value="<?=$_POST[id_mant]?>">
<input type="hidden" name="v_nm_equp" id="v_nm_equp" value="<?=$_POST[v_nm_equp]?>">
<input type="hidden" name="v_fl_atvo" id="v_fl_atvo" value="<?=$_POST[v_fl_atvo]?>">
<input name="passa" type="hidden" id="passa" value="yes">
</form>
<?
echo "<SCRIPT LANGUAGE=javascript> \n";
echo "document.retorna.action = '$onde'; \n";
echo "document.retorna.submit(); \n";
echo "</script>";
?>
Back to Directory
File Manager