-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactanos.php
259 lines (239 loc) · 14.1 KB
/
contactanos.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php include 'header.php'; ?>
<div class="container">
<div class="row">
<div class="col-md-5 formulario-contacto">
<h3>Contactanos</h3>
<form id="fm" role="form" method="POST">
<div id="nombreGroup" class="form-group has-feedback">
<label class="control-label" for="nombre">Nombre</label>
<input type="text" class="form-control" id="nombre" name="nombre" aria-describedby="nombreStatus" placeholder="Nombre y Apellido" onchange="validar('nombre', 'text')">
<span id="nombreIco" class="glyphicon form-control-feedback" aria-hidden="true"></span>
<span id="nombreStatus" class="sr-only">(success)</span>
</div>
<div id="emailGroup" class="form-group has-feedback">
<label class="control-label" for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" aria-describedby="emailStatus" placeholder="ejemplo@correo.com" onchange="validar('email', 'email')">
<span id="emailIco" class="glyphicon form-control-feedback" aria-hidden="true"></span>
<span id="emailStatus" class="sr-only">(error)</span>
</div>
<div id="telefonoGroup" class="form-group has-feedback">
<label class="control-label" for="telefono">Telefono</label>
<input type="tel" class="form-control" id="telefono" name="telefono" aria-describedby="telefonoStatus" placeholder="Número de red fija o Celular" onchange="validar('telefono', 'tel')">
<span id="telefonoIco" class="glyphicon form-control-feedback" aria-hidden="true"></span>
<span id="telefonoStatus" class="sr-only">(error)</span>
</div>
<div id="asuntoGroup" class="form-group has-feedback">
<label class="control-label" for="asunto">Asunto</label>
<input type="text" class="form-control" id="asunto" name="asunto" aria-describedby="asuntoStatus" placeholder="Asunto" onchange="validar('asunto', 'text')">
<span id="asuntoIco" class="glyphicon form-control-feedback" aria-hidden="true"></span>
<span id="asuntoStatus" class="sr-only">(error)</span>
</div>
<div id="detalleGroup" class="form-group has-feedback">
<label class="control-label" for="detalle">Detalle</label>
<textarea type="text" class="form-control" id="detalle" name="detalle" rows="5" aria-describedby="detalleStatus" placeholder="Que desea consultar" onchange="validar('detalle', 'text')"></textarea>
<span id="detalleIco" class="glyphicon form-control-feedback" aria-hidden="true"></span>
<span id="detalleStatus" class="sr-only">(error)</span>
</div>
<button type="button" class="btn btn-default" onclick="enviarMensaje()">Enviar</button>
</form>
</div>
<div class="col-md-7">
<div id="main" class="mapa">
<div>
<address id="datos-contacto">
<p><h4>Direccion:</h4> Av. Arturo Prat #567, Chillan. Region del Bio Bio</p>
<p><h4>Fono:</h4> 042-256548</p>
</address>
<input type="hidden" value="" id="descripcionUbicacion" name="descripcionUbicacion" >
<input type="hidden" value="" id="latitud" name="latitud">
<input type="hidden" value="" id="longitud" name="longitud">
<input type="hidden" value="" id="zoom" name="zoom" >
</div>
<div id="map-rutas" style="float:left;width:100%;height:100%;"></div>
</div>
</div>
</div>
</div>
<!-- Administracion-->
<script src="Files/js/validarut.js"></script>
<script type="text/javascript">
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var infoWindow = null;
$(document).ready(function () {
cargarDatos();
});
function cargarDatos() {
var url_json = 'Vista/Servlet/administrarEmpresa.php?accion=LISTADO';
$.getJSON(
url_json,
function (datos) {
$('#datos-contacto').html("<p><h4>Direccion:</h4> "+datos.direccion+"</p><p><h4>Fono:</h4> "+datos.telefono+"</p>")
document.getElementById("latitud").value = datos.latitud;
document.getElementById("longitud").value = datos.longitud;
document.getElementById("descripcionUbicacion").value = datos.descripcionUbicacion;
document.getElementById("zoom").value = datos.zoom;
initialize();
}
);
}
function initialize() {
var latitud = document.getElementById("latitud").value;
var longitud = document.getElementById("longitud").value;
var descripcion = document.getElementById("descripcionUbicacion").value;
var zoom = parseInt(document.getElementById("zoom").value);
directionsDisplay = new google.maps.DirectionsRenderer();
var coordenadas = new google.maps.LatLng(latitud, longitud);
//Definimos opciones para crear el mapa
var mapOptions = {
zoom: zoom,
center: coordenadas}
//creamos el mapa con las opciones anteriores y le pasamos el elemento div
map = new google.maps.Map(document.getElementById('map-rutas'), mapOptions);
directionsDisplay.setMap(map);
infoWindow = new google.maps.InfoWindow();
agregarMarker(latitud, longitud, descripcion);
}
function agregarMarker(latitud, longitud, descripcion) {
var position = new google.maps.LatLng(latitud, longitud);//-36.61, -72.0997);
var marker = new google.maps.Marker({
position: position,
map: map,
title: descripcion,
animation: google.maps.Animation.DROP
});
marker.setMap(map);
}
function enviarMensaje() {
if (validarFormulario()) {
$('#fm').form('submit', {
url: "Vista/Servlet/administrarMensaje.php?accion=AGREGAR",
onSubmit: function () {
return $(this).form('validate');
},
success: function (result) {
var result = eval('(' + result + ')');
if (result.success) {
document.getElementById("fm").reset();
mensaje('Exito', result.mensaje);
} else {
mensaje('Error', result.errorMsg);
}
}
});
} else {
mensaje('Error', "Hay casillas vacias o con valores invalidos.");
}
}
function validar(nombre, tipo) {
var contenido;
if (tipo == 'run') {
contenido = eliminarCaracteres(document.getElementById(nombre).value);
document.getElementById(nombre).value = contenido;
if (contenido != null && contenido.length > 6 && Rut(contenido)) {
cambiarEstado(nombre, true);
} else {
cambiarEstado(nombre, false);
}
} else if (tipo == 'text') {
contenido = document.getElementById(nombre).value;
if (contenido != null && contenido.length > 2) {
cambiarEstado(nombre, true);
} else {
cambiarEstado(nombre, false);
}
} else if (tipo == 'radio') {
if ($("#fm input[name='" + nombre + "']:radio").is(':checked')) {
cambiarEstado(nombre, true);
} else {
cambiarEstado(nombre, false);
}
} else if (tipo == 'tel') {
contenido = document.getElementById(nombre).value;
if (contenido != null && contenido.length > 5 && !isNaN(contenido)) {
cambiarEstado(nombre, true);
} else {
cambiarEstado(nombre, false);
}
} else if (tipo == 'date') {
contenido = document.getElementById(nombre).value;
if (contenido != null && contenido.length > 6) {
cambiarEstado(nombre, true);
} else {
cambiarEstado(nombre, false);
}
} else if (tipo == 'email') {
contenido = document.getElementById(nombre).value;
if (validarEmail(contenido)) {
cambiarEstado(nombre, true);
} else {
cambiarEstado(nombre, false);
}
} else if (tipo == 'select') {
contenido = document.getElementById(nombre).value;
if (contenido != null && contenido != "") {
cambiarEstado(nombre, true);
} else {
cambiarEstado(nombre, false);
}
}
}
function validarFormulario() {
var nombre = document.getElementById('nombre').value;
var email = document.getElementById('email').value;
var telefono = document.getElementById('telefono').value;
var asunto = document.getElementById('asunto').value;
var detalle = document.getElementById('detalle').value;
var valido = true;
if (nombre == null || nombre.length < 3) {
valido = false;
cambiarEstado("nombre", false);
}
if (!validarEmail(email)) {
valido = false;
cambiarEstado("email", false);
}
if (telefono == null || telefono.length < 6 || isNaN(telefono)) {
valido = false;
cambiarEstado("telefono", false);
}
if (asunto == null || asunto.length < 3) {
valido = false;
cambiarEstado("asunto", false);
}
if (detalle == null || detalle.length < 3) {
valido = false;
cambiarEstado("detalle", false);
}
return valido;
}
function cambiarEstado(nombre, estado) {
if (estado) {
$('#' + nombre + 'Group').removeClass('has-error');
$('#' + nombre + 'Ico').removeClass('glyphicon-remove');
$('#' + nombre + 'Group').addClass('has-success');
$('#' + nombre + 'Ico').addClass('glyphicon-ok');
} else {
$('#' + nombre + 'Group').removeClass('has-success');
$('#' + nombre + 'Ico').removeClass('glyphicon-ok');
$('#' + nombre + 'Group').addClass('has-error');
$('#' + nombre + 'Ico').addClass('glyphicon-remove');
}
}
function validarEmail(email) {
var expr = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!expr.test(email)) {
return false;
} else {
return true;
}
}
function mensaje(titulo, mensaje) {
document.getElementById('logo-mensaje').src = "Files/img/iconoInformacion.png";
$('#titulo-mensaje').html(titulo);
$('#contenedor-mensaje').html(mensaje);
$('#dg-mensaje').modal(this)//CALL MODAL MENSAJE
}
</script>
<?php include 'footer.php'; ?>