Viewing File: /home/cienp/public_html/portal/sql_agnd_gerl.php
<?
$dt_atua = date("Y-m-d H:i:s");
echo ".";
switch ($_POST[opc]){
case "ins":
require "$this->include_dir/conecta.php";
$s_id_tipo = protecao($_POST[id_tipo],'inteiro');
$s_id_colb = protecao($_POST[id_colb],'inteiro');
$s_id_labt = protecao($_POST[id_labt],'inteiro');
$s_dt_inic = protecao($_POST[dt_inic],'data');
$s_dt_finl = protecao($_POST[dt_finl],'data');
$s_hr_inic = protecao($_POST[hr_inic]);
$s_hr_finl = protecao($_POST[hr_finl]);
$s_de_titl = protecao($_POST[de_titl]);
$s_de_agnd = protecao($_POST[de_agnd]);
$s_id_cols = protecao($_POST[id_cols]);
if ($s_dt_inic != '') {
$d1 = explode('/', $s_dt_inic);
$dt_inic = $d1[2]."-".$d1[1]."-".$d1[0];
}
if ($s_dt_finl != '') {
$d2 = explode('/', $s_dt_finl);
$dt_finl = $d2[2]."-".$d2[1]."-".$d2[0];
}
$pass = 0;
if ($s_id_tipo == 3) {
$hh_inic = substr($s_hr_inic,0,2);
$mm_inic = substr($s_hr_inic,2,2);
$tp_inic = substr($s_hr_inic,5,2);
if ($tp_inic == 'PM') {
$hh_inic = $hh_inic + 12;
}
$dt_inic = $dt_inic.' '.$hh_inic.':'.$mm_inic.':00';
$hh_finl = substr($s_hr_finl,0,2);
$mm_finl = substr($s_hr_finl,2,2);
$tp_finl = substr($s_hr_finl,5,2);
if ($tp_finl == 'PM') {
$hh_finl = $hh_finl + 12;
}
$dt_finl = $dt_finl.' '.$hh_finl.':'.$mm_finl.':00';
$sqlj = "SELECT e.id_agnd_gerl ";
$sqlj .= "FROM ".$pref_tabl."agnd_gerl e ";
$sqlj .= "WHERE e.id_tipo = 3 ";
$sqlj .= "AND e.id_labt = $s_id_labt ";
$sqlj .= "AND ((e.dt_inic BETWEEN '$dt_inic' ";
$sqlj .= " AND ('$dt_finl' - INTERVAL 1 SECOND)) ";
$sqlj .= "OR (e.dt_finl BETWEEN ('$dt_inic' + INTERVAL 1 SECOND) ";
$sqlj .= " AND '$dt_finl')";
$sqlj .= "OR (e.dt_inic <= '$dt_inic' ";
$sqlj .= " AND e.dt_finl > '$dt_finl') ";
$sqlj .= "OR (e.dt_inic > '$dt_inic' ";
$sqlj .= " AND e.dt_finl <= '$dt_finl') ";
$sqlj .= "OR (e.dt_inic = '$dt_inic' ";
$sqlj .= " AND e.dt_finl = '$dt_finl')) ";
#echo $sqlj.'....<br>';
$resj = mysqli_query($conn, $sqlj);
if (mysqli_num_rows($resj) > 0) {
$pass++;
}
}
if ($pass == 0) {
$sql = "INSERT INTO ".$pref_tabl."agnd_gerl ";
$sql .= "(id_tipo, id_colb, id_labt, dt_inic, dt_finl, de_titl, de_agnd, dt_cads, id_cads) ";
$sql .= "VALUES ('$s_id_tipo', '$s_id_colb', '$s_id_labt', '$dt_inic', '$dt_finl', '$s_de_titl', '$s_de_agnd', '$dt_atua', $linhau[id_user])";
#echo $sql;
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=ins_agnd_gerl&certo=S";
$sqld = "SELECT MAX(id_agnd_gerl) as id_agnd_gerl ";
$sqld .= "FROM ".$pref_tabl."agnd_gerl ";
#echo $sqld.'<br>';
$resd = mysqli_query($conn, $sqld);
if (mysqli_num_rows($resd) > 0) {
$linhad = mysqli_fetch_array($resd);
$cont = count($s_id_cols);
if ($cont > 0) {
for ($j = 0; $j < $cont; $j++ ) {
$sqlc = "INSERT INTO ".$pref_tabl."agnd_colb ";
$sqlc .= "(id_colb, id_agnd_gerl, dt_cads, id_cads) ";
$sqlc .= "VALUES ('$s_id_cols[$j]', '$linhad[id_agnd_gerl]', '$dt_atua', $linhau[id_user])";
#echo $sqlc;
$resc = mysqli_query($conn, $sqlc);
}
}
}
} else {
$onde = "index1.php?pg=ins_agnd_gerl&certo=N";
}
} else {
$onde = "index1.php?pg=ins_agnd_gerl&certo=J";
}
break;
case "alt":
require "$this->include_dir/conecta.php";
$s_id_agnd_gerl = protecao($_POST[id_agnd_gerl],'inteiro');
$s_id_tipo = protecao($_POST[id_tipo],'inteiro');
$s_id_colb = protecao($_POST[id_colb],'inteiro');
$s_id_labt = protecao($_POST[id_labt],'inteiro');
$s_dt_inic = protecao($_POST[dt_inic],'data');
$s_dt_finl = protecao($_POST[dt_finl],'data');
$s_hr_inic = protecao($_POST[hr_inic]);
$s_hr_finl = protecao($_POST[hr_finl]);
$s_de_titl = protecao($_POST[de_titl]);
$s_de_agnd = protecao($_POST[de_agnd]);
if ($s_dt_inic != '') {
$d1 = explode('/', $s_dt_inic);
$dt_inic = $d1[2]."-".$d1[1]."-".$d1[0];
}
if ($s_dt_finl != '') {
$d2 = explode('/', $s_dt_finl);
$dt_finl = $d2[2]."-".$d2[1]."-".$d2[0];
}
$pass = 0;
if ($s_id_tipo == 3) {
$hh_inic = substr($s_hr_inic,0,2);
$mm_inic = substr($s_hr_inic,2,2);
$tp_inic = substr($s_hr_inic,5,2);
if ($tp_inic == 'PM') {
$hh_inic = $hh_inic + 12;
}
$dt_inic = $dt_inic.' '.$hh_inic.':'.$mm_inic.':00';
$hh_finl = substr($s_hr_finl,0,2);
$mm_finl = substr($s_hr_finl,2,2);
$tp_finl = substr($s_hr_finl,5,2);
if ($tp_finl == 'PM') {
$hh_finl = $hh_finl + 12;
}
$dt_finl = $dt_finl.' '.$hh_finl.':'.$mm_finl.':00';
$sqlj = "SELECT e.id_agnd_gerl ";
$sqlj .= "FROM ".$pref_tabl."agnd_gerl e ";
$sqlj .= "WHERE e.id_tipo = 3 ";
$sqlj .= "AND e.id_agnd_gerl <> '$s_id_agnd_gerl' ";
$sqlj .= "AND e.id_labt = $s_id_labt ";
$sqlj .= "AND ((e.dt_inic BETWEEN '$dt_inic' ";
$sqlj .= " AND ('$dt_finl' - INTERVAL 1 SECOND)) ";
$sqlj .= "OR (e.dt_finl BETWEEN ('$dt_inic' + INTERVAL 1 SECOND) ";
$sqlj .= " AND '$dt_finl')";
$sqlj .= "OR (e.dt_inic <= '$dt_inic' ";
$sqlj .= " AND e.dt_finl > '$dt_finl') ";
$sqlj .= "OR (e.dt_inic > '$dt_inic' ";
$sqlj .= " AND e.dt_finl <= '$dt_finl') ";
$sqlj .= "OR (e.dt_inic = '$dt_inic' ";
$sqlj .= " AND e.dt_finl = '$dt_finl')) ";
#echo $sqlj.'....<br>';
$resj = mysqli_query($conn, $sqlj);
if (mysqli_num_rows($resj) > 0) {
$pass++;
}
}
if ($pass == 0) {
$sql = "UPDATE ".$pref_tabl."agnd_gerl ";
$sql .= "SET id_tipo = '$s_id_tipo', ";
$sql .= "id_colb = '$s_id_colb', ";
$sql .= "id_labt = '$s_id_labt', ";
$sql .= "dt_inic = '$dt_inic', ";
$sql .= "dt_finl = '$dt_finl', ";
$sql .= "de_titl = '$s_de_titl', ";
$sql .= "de_agnd = '$s_de_agnd', ";
$sql .= "id_altr = '$linhau[id_user]', ";
$sql .= "dt_altr = '$dt_atua' ";
$sql .= "WHERE id_agnd_gerl = '$s_id_agnd_gerl' ";
$sql .= "LIMIT 1";
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=alt_agnd_gerl&certo=S";
} else {
$onde = "index1.php?pg=alt_agnd_gerl&certo=N";
}
} else {
$onde = "index1.php?pg=alt_agnd_gerl&certo=J";
}
break;
case "exc":
require "$this->include_dir/conecta.php";
$s_id_agnd_gerl = protecao($_POST[id_agnd_gerl],'inteiro');
if ($s_id_agnd_gerl > 0) {
$sql = "DELETE FROM ".$pref_tabl."agnd_gerl ";
$sql .= "WHERE id_agnd_gerl = '$s_id_agnd_gerl' ";
$sql .= "LIMIT 1";
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=res_agnd_gerl&certo=X";
} else {
$onde = "index1.php?pg=res_agnd_gerl&certo=N";
}
} else {
$onde = "index1.php?pg=res_agnd_gerl&certo=N";
}
break;
case "ins_agnd_colb":
require "$this->include_dir/conecta.php";
$s_id_colb = protecao($_POST[id_colb],'inteiro');
$s_id_agnd_gerl = protecao($_POST[id_agnd_gerl],'inteiro');
$sqld = "SELECT id_colb ";
$sqld .= "FROM ".$pref_tabl."agnd_colb ";
$sqld .= "WHERE id_colb = $s_id_colb ";
$sqld .= "AND id_agnd_gerl = $s_id_agnd_gerl ";
$sqld .= "LIMIT 1 ";
#echo $sqld.'<br>';
$resd = mysqli_query($conn, $sqld);
if (mysqli_num_rows($resd) == 0) {
$sql = "INSERT INTO ".$pref_tabl."agnd_colb ";
$sql .= "(id_colb, id_agnd_gerl, dt_cads, id_cads) ";
$sql .= "VALUES ('$s_id_colb', '$s_id_agnd_gerl', '$dt_atua', $linhau[id_user])";
#echo $sql;
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=alt_agnd_gerl&certo=SC";
// envia e-mail para o colaborador
$sqlcc = "SELECT u.nm_colb, u.de_mail ";
$sqlcc .= "FROM ".$pref_tabl."colb u ";
$sqlcc .= "WHERE u.id_colb = $s_id_colb ";
$sqlcc .= "LIMIT 1 ";
#echo $sqlcc.'<br>';
$rescc = mysqli_query($conn, $sqlcc);
if (mysqli_num_rows($rescc) > 0) {
$linhacc = mysqli_fetch_array($rescc);
if ($linhacc[de_mail] != '') {
$sqlaa = "SELECT a.de_titl, a.de_agnd, b.nm_labt, t.de_tipo, ";
$sqlaa .= "DATE_FORMAT(a.dt_inic, '%d/%m/%Y') as dt_inic, ";
$sqlaa .= "DATE_FORMAT(a.dt_inic, '%H:%i') as hr_inic, ";
$sqlaa .= "DATE_FORMAT(a.dt_finl, '%d/%m/%Y') as dt_finl, ";
$sqlaa .= "DATE_FORMAT(a.dt_finl, '%H:%i') as hr_finl ";
$sqlaa .= "FROM ".$pref_tabl."agnd_gerl a, ".$pref_tabl."labt b, ".$pref_tabl."tipo_agnd t ";
$sqlaa .= "WHERE a.id_labt = b.id_labt ";
$sqlaa .= "AND a.id_tipo = t.id_tipo ";
$sqlaa .= "AND a.id_agnd_gerl = '$s_id_agnd_gerl' ";
$sqlaa .= "LIMIT 1 ";
#echo $sqlaa.'<br>';
$resaa = mysqli_query($conn, $sqlaa);
if (mysqli_num_rows($resaa) > 0) {
$linhaa = mysqli_fetch_array($resaa);
// envia e-mail para o solicitante
$mensagem = "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"pt-BR\" lang=\"pt-BR\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<style TYPE='text/css'>
A {text-decoration: none}
A:link {color:'#89211b';}
A:visited {color:'#89211b';}
A:hover {color:'#000000';}
</style>
</head>
<body>
<p align='left'><font color='#000000' size='2' face='Arial, Helvetica'>
Informamos que você foi adicionado na agenda de $linhaa[de_tipo] abaixo:<br><br>
Laboratório/Sala: $linhaa[nm_labt]<br>
Título: $linhaa[de_titl]<br>
Data de Início: $linhaa[dt_inic] às $linhaa[hr_inic]h<br>
Data Final: $linhaa[dt_finl] às $linhaa[hr_finl]h<br>
Descrição: $linhaa[de_agnd]<br><br>
Atenciosamente,<br><br>
CIEnP<br>
Centro de Inovação e Ensaios Pré-Clínicos<br>
</font><br/></p>
</body>
</html>
";
$snap = "\n";
$from = "compras@cienp.org.br";
$from = "atendimento@commix.com.br";
$boundary = "==Multipart_Boundary_x".md5(time())."x";
$body = stripslashes($mensagem);
// Criamos os cabeçalhos MIME utilizados para separar as partes da mensagem MIME
$html = "--".$boundary.$snap;
$html .= "Content-Transfer-Encoding: 8bits".$snap;
$html .= "Content-Type: text/html; charset=\"ISO-8859-1\"".$snap.$snap;
$html .= $body.$snap;
$html .= "--".$boundary."--";
// Adiciono os cabeçalhos de um arquivo anexado
$head = "MIME-Version: 1.0".$snap;
$head .= "From: $from".$snap;
$head .= "Return-Path: $from".$snap;
$head .= "Reply-to: $from".$snap;
$head .= "Bcc:".$snap;
$head .= "Content-type: multipart/alternative; boundary=\"{$boundary}\"".$snap;
$head .= $boundary.$snap;
$to = $linhacc[de_mail];
$subject = "$linhaa[de_tipo] - CIEnP";
$resmm = mail($to, $subject, $html, $head);
}
}
}
} else {
$onde = "index1.php?pg=alt_agnd_gerl&certo=NC";
}
} else {
$onde = "index1.php?pg=alt_agnd_gerl&certo=JC";
}
break;
case "exc_colb":
require "$this->include_dir/conecta.php";
$s_id_agnd_colb = protecao($_POST[id_agnd_colb],'inteiro');
if ($s_id_agnd_colb > 0) {
$sql = "DELETE FROM ".$pref_tabl."agnd_colb ";
$sql .= "WHERE id_agnd_colb = '$s_id_agnd_colb' ";
$sql .= "LIMIT 1";
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=alt_agnd_gerl&certo=XC";
} else {
$onde = "index1.php?pg=alt_agnd_gerl&certo=N";
}
} else {
$onde = "index1.php?pg=alt_agnd_gerl&certo=N";
}
break;
}
?>
<form name="retorna" method="post" action="">
<input type="hidden" name="id_agnd_gerl" id="id_agnd_gerl" value="<?=$_POST[id_agnd_gerl]?>">
<input type="hidden" name="id_agnd_colb" id="id_agnd_colb" value="<?=$_POST[id_agnd_colb]?>">
<input type="hidden" name="v_id_tipo" id="v_id_tipo" value="<?=$_POST[v_id_tipo]?>">
<input type="hidden" name="v_de_titl" id="v_de_titl" value="<?=$_POST[v_de_titl]?>">
<input type="hidden" name="v_id_colb" id="v_id_colb" value="<?=$_POST[v_id_colb]?>">
<input type="hidden" name="v_id_labt" id="v_id_labt" value="<?=$_POST[v_id_labt]?>">
<input type="hidden" name="v_dt_inic" id="v_dt_inic" value="<?=$_POST[v_dt_inic]?>">
<input type="hidden" name="v_dt_finl" id="v_dt_finl" value="<?=$_POST[v_dt_finl]?>">
<input type="hidden" name="v_de_onde" id="v_de_onde" value="<?=$_POST[v_de_onde]?>">
<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