define ('DEBUG', TRUE );
// define ('DEBUG', FALSE );
include('verificaPermisos.php');
$perfil[1] = true;
$perfil[2] = true;
$perfil[3] = false;
$perfil[4] = false;
$perfil[5] = false;
if (!verificaPermisos($perfil)) {
header('Location: index.php');
exit;
}
require('include.php');
header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Data del passat
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
function insertaGrup($codi_vehicle, $grups) {
global $objBd;
$ret = true;
$sSQL = 'DELETE FROM GRUP_VEHICLE WHERE CODI_VEHICLE = '.$codi_vehicle;
if (DEBUG)
echo '$sSQL : '.$sSQL.'
';
if (!$objBd->consulta($sSQL))
$ret = false;
if (isset($grups) && !empty($grups)) {
foreach ($grups as $clau => $valor) {
$sSQL = 'INSERT INTO GRUP_VEHICLE (CODI_GRUP, CODI_VEHICLE) VALUES ('.$valor.', '.$codi_vehicle.')';
if (DEBUG)
echo '$sSQL : '.$sSQL.'
';
if (!$objBd->consulta($sSQL))
$ret = false;
}
}
return $ret;
}
$smarty->assign('title', 'Editar vehiculo');
$estil[] = 'css/forms.css';
$smarty->assign('estil', $estil);
$javascript[] = 'js/validacions.js';
$javascript[] = 'js/valida_vehiculo.js';
$smarty->assign('javascript', $javascript);
if (isset($_SESSION['text_titol']))
$smarty->assign('text_titol', $_SESSION['text_titol']);
else
$smarty->assign('text_titol', 'idsGpsWeb');
if (isset($_SESSION['img_fons_titol']))
$smarty->assign('img_fons_titol', $_SESSION['img_fons_titol']);
else
$smarty->assign('img_fons_titol', 'img/fons_roda.gif');
$smarty->assign('usuari', $_SESSION['usuari']);
$smarty->assign('perfil', $_SESSION['perfil']);
$smarty->assign('estil_def', $_SESSION['fulla_estils_def']);
$smarty->assign('fitxer_ajuda', $_SESSION['ayuda']);
$smarty->display('cappag.tpl'); //mostra capalera
include('validacions.php'); //validacions
if (isset($_GET['idVehiculo']) && esNatural($_GET['idVehiculo'])) {
$clean['idVehicle'] = $_GET['idVehiculo'];
//echo 'idVehiculo:'.$clean['idVehicle'].'
';
} else if (isset($_POST['idVehiculo']) && esNatural($_POST['idVehiculo'])) {
$clean['idVehicle'] = $_POST['idVehiculo'];
//echo 'idVehiculo:'.$clean['idVehicle'].'
';
}
// INICI EDICI TERMINAL
//SI PITJEM L'OPCI DE GUARDAR, COMPROBA CAMPS ... ACTUALITZA SI EXISTEIX SINO INSERTA
if (isset($_POST['opcio']) && ($_POST['opcio'] == 'Guarda')) {
// abans de guardar, ELS comproba I ELS PASSA A PHP
include_once('CnxFirebird.php');
$objBd = new CnxFirebird('TRANSDAT'.$_SESSION['grup'].'.gdb');
$error = '';
//inici comprobacions del "GPS"
if (isset($_POST['txtHoraIniPool'])) $clean['txtHoraIniPool']=$_POST['txtHoraIniPool'];
else $clean['txtHoraIniPool']=00;
if (isset($_POST['txtMinIniPool'])) $clean['txtMinIniPool']=$_POST['txtMinIniPool'];
else $clean['txtMinIniPool']=00;
if (isset($_POST['txtHoraFinPool'])) $clean['txtHoraFinPool']=$_POST['txtHoraFinPool'];
else $clean['txtHoraFinPool']=23;
if (isset($_POST['txtMinFinPool'])) $clean['txtMinFinPool']=$_POST['txtMinFinPool'];
else $clean['txtMinFinPool']=59;
if (isset($_POST ['txtKM']) && strlen($_POST['txtKM'])>0) { $clean['distancia']=$_POST['txtKM'];
}
else $clean['distancia']=0;
if (isset($_POST ['txtTiempo']) && strlen($_POST['txtKM'])>0) { $clean['gpstemps']=$_POST['txtTiempo'];
}
else $clean['distancia']=0;
//}ELSE
if (isset($_POST['ddlTipo']) && (strlen($_POST['ddlTipo']) > 0)) {
$clean['tipus_terminal'] = '\''.utf8_decode(escapa_bd($_POST['ddlTipo'])).'\'';
} else
$clean['tipus_terminal'] = 'NULL';
if (isset($_POST['txtTelefono']) && strlen($_POST['txtTelefono']) > 0) {
if (esNatural($_POST['txtTelefono']) && strlen($_POST['txtTelefono']) >= 9)
$clean['telefon'] = '\''.escapa_bd($_POST['txtTelefono']).'\'';
else {
if ($error <> '')
$error .= '
';
$error .= '- El teléfono tiene que estar formado por almenos 9 números.';
}
} else
if (isset($_POST['telefonocult'])) $clean['telefon'] =$_POST['telefonocult'];
else $clean['telefon']= 'NULL';
//fi comprobacions del "GPS"
if (isset($_POST['txtMatricula']) && strlen($_POST['txtMatricula']) > 0) {
$clean['matricula'] = '\''.utf8_decode(escapa_bd($_POST['txtMatricula'])).'\'';
} else
$error .= '- Tiene que entrar la matrícula del vehículo.';
if (isset($_POST['txtNombreVehiculo']) && (strlen($_POST['txtNombreVehiculo']) > 0)) {
$clean['nom_vehicle'] = '\''.utf8_decode(escapa_bd($_POST['txtNombreVehiculo'])).'\'';
} else
$clean['nom_vehicle'] = 'NULL';
if (isset($_POST['txtObservaciones']) && strlen($_POST['txtObservaciones']) > 0) {
$clean['observacions'] = '\''.utf8_decode(escapa_bd($_POST['txtObservaciones'])).'\'';
} else
$clean['observacions'] = 'NULL';
if (isset($_POST['ddlOperario'])) {
if ($_POST['ddlOperario'] == '---') {
$clean['codi_operari'] = 'NULL';
} else if ($_POST['ddlOperario'] == 'NUE') {
$sSQL = 'INSERT INTO OPERARI (NOM) VALUES (\''.escapa_bd($_POST['txtOperario']).'\')';
if ($objBd->consulta($sSQL)) {
$sSQL = 'SELECT CODI FROM OPERARI WHERE NOM = \''.escapa_bd($_POST['txtOperario']).'\'';
if (($objBd->consulta($sSQL)) && ($fila = $objBd->obte_fila(0, 1))) {
$clean['codi_operari'] = $fila['CODI'];
}
}
} else if (esNatural($_POST['ddlOperario'])) {
$clean['codi_operari'] = $_POST['ddlOperario'];
} else
$error .= '- Operario incorrecto.';
}
if (isset($_POST['ddlGrupo']))
$clean['grup'] = $_POST['ddlGrupo'];
else
$clean['grup'] = array();
if (isset($_POST['radIcono']) && esNatural($_POST['radIcono'])) {
$clean['radIcono'] = '\''.$_POST['radIcono'].'\'';
} else
$clean['radIcono'] = '\'1\'';
//acaba de comprobar els camps, si $error no s null, hi ha errors, salta!!
if (!($error == '')) {
$smarty->assign('error', $error);
$smarty->assign('solucio', 'Solucione los valores incorrectos.');
$smarty->assign('email_soport', $_SESSION['email_soport']);
$smarty->display('error.tpl');
exit;
}
//actualitza camps
$sSQLMARC='UPDATE OR INSERT INTO TERMINALS (CODITERMINAL, TIPUS, TELEFON,GPSDISTANCIA,GPSTEMPS) VALUES('.$clean['telefon'].', '.$clean['tipus_terminal'].', '.$clean['telefon'].', '.$clean['distancia'].', '.$clean['gpstemps'].') ';
if (DEBUG){ $fn = "c:\\sqlout.txt";
$fn = fopen($fn, 'w') or die();
fwrite($fn, ">$sSQLMARC<\n");
fclose($fn);
echo $sSQLMARC;
}
//$smarty->assign('sSQL', $sSQLMARC);
if ($objBd->consulta($sSQLMARC)) {
?>