1:<?
2:session_start();
3:
4:/*
5:if (!$_SERVER['HTTPS']) {
6: header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']);
7: die();
8:}
9:*/
10:
11:include('class.rFastTemplate.php');
12:include("./php/config.php");
13:include("./php/common.php");
14:
15:$tpl = new rFastTemplate("templates");
16:
17://inicialitzem plantilles
18:ini_tpls($tpl);
19:
20:
21:if ($_SESSION['idreg'] == '') { // comprova que estem enregistrats
22: $tpl->assign ('TITOL', "Error");
23: $tpl->assign ('AUX', "En primer lloc ha d'iniciar sessió com usuari <b>registrat</b>.");
24: $tpl->parse(COS, "aux");
25:} else { // menu de navegacio
26: if ($_GET['nav']=='noucr') { // registrar nou complex rural
27: $tpl->parse(COS, "noucr");
28: } elseif ($_GET['nav']=='cr') { // menu de complexos rurals d'empresari hostaler
29: // determinem els complexos rurals de l'empresari hostaler
30: $query = mysql_query("SELECT CR_Codi, CR_Nom from Complex_rural where CR_Empresari_hostaler='".$_SESSION['idreg']."' and CR_Actiu = 1", $link);
31: if (mysql_num_rows($query) == 0) {
32: $tpl->assign ('TITOL', "Empresari hostaler");
33: $tpl->assign ('AUX', "No té registrat cap complex rural <b>actiu</b>");
34: $tpl->parse(COS, "aux");
35: } else {
36: while ($f = mysql_fetch_array($query)) {
37: // determinem els allotjaments
38: $consul = mysql_query("SELECT count(*) AS NumAll from Complex_rural c, Allotjament a where c.CR_Codi='".$f['CR_Codi']."' and c.CR_Codi=a.A_Complex_rural", $link);
39: $f2 = mysql_fetch_array($consul);
40: // determinem les reserves realitzades
41: $consul = mysql_query("SELECT count(*) AS NumRes from Complex_rural c, Allotjament a, Reserva r where c.CR_Codi='".$f['CR_Codi']."' and c.CR_Codi=a.A_Complex_rural and a.A_Codi=r.R_Allotjament", $link);
42: $f3 = mysql_fetch_array($consul);
43: $tpl->assign (array (CRNOM => $f['CR_Nom'], CRRESERVES => $f3['NumRes'], CRALLOTJAMENTS => $f2['NumAll'], LINKNALL => 'eh.php?nav=credit&id='.$f['CR_Codi'].'', LINKEDITCR => 'eh.php?nav=modcr&id='.$f['CR_Codi'].'', LINKRES => 'eh.php?nav=reservacr&id='.$f['CR_Codi'].''));
44: $tpl->parse(ROWCR, ".rowcr");
45: }
46: $tpl->parse(COS, "cr");
47: } // fi menu de complexos rurals d'empresari hostaler
48:
49: } elseif ($_GET['nav'] == 'credit') { //afegim nous allotjaments
50: $query = mysql_query("SELECT CR_Nom, CR_Tipus_allotjament from Complex_rural where CR_Codi = '".$_GET['id']."'", $link);
51: $f = mysql_fetch_array($query);
52: $_SESSION['editcr'] = $_GET['id'];
53: $tpl->assign('CRNOM', $f['CR_Nom']);
54: $tpl->assign('ALLTIPUS', ucfirst(strtolower($f['CR_Tipus_allotjament'])));
55: $tpl->parse(COS, "nouall");
56:
57: } elseif ($_GET['nav'] == 'modcr') { // modifiquem dades complex rural
58: $query = mysql_query("SELECT * from Complex_rural where CR_Codi = '".$_GET['id']."'", $link);
59: $f = mysql_fetch_array($query);
60: $tpl->assign (array (IDCR => $f['CR_Codi'], CRNOM => $f['CR_Nom'], CRADRECA => $f['CR_Adreca'], CRCP => $f['CR_Codi_postal'], CRPOBLACIO => $f['CR_Poblacio'], CRPROVINCIA => ucwords(strtolower(substr($f['CR_Provincia'], 3, (strlen($f['CR_Provincia'])-3)))), CRTIPUS => ucfirst(strtolower($f['CR_Tipus_allotjament'])), CRTEL => $f['CR_Telefon'], CREMAIL => $f['CR_Email'], CRDESCRIPCIO => $f['CR_Descripcio']));
61: // mostra els allotjaments
62: $query = mysql_query("SELECT * from Complex_rural c, Allotjament a where c.CR_Codi = '".$_GET['id']."' and c.CR_Codi=a.A_Complex_rural", $link);
63: if (mysql_num_rows($query) != 0) {
64: while ($f = mysql_fetch_array($query)) {
65: $tpl->assign (array (IDALL => $f['A_Codi'], ALLCAP => $f['A_Capacitat'], ALLPREUALTA => $f['A_Preu_talta'], ALLPREUBAIXA => $f['A_Preu_tbaixa'], ALLNUMERO => $f['A_Quantitat'], ALLDESCR => $f['A_Descripcio']));
66: $tpl->parse(ROWALL, ".rowall");
67: }
68: } else {
69: $tpl->parse(ROWALL, "blank");
70: }
71: $tpl->parse(COS, "modcr");
72:
73: } elseif ($_GET['nav'] == 'reservacr') { // consultem les reserves pendents per allotjament
74: $query = mysql_query("SELECT * from Complex_rural c, Allotjament a, Reserva r, Usuari u where c.CR_Codi = '".$_GET['id']."' and c.CR_Codi=a.A_Complex_rural and a.A_Codi=r.R_Allotjament and u.U_Codi=r.R_Usuari", $link);
75: if (mysql_num_rows($query) == 0) { // si no hi han reserves
76: $tpl->assign ('TITOL', "Reserves actuals");
77: $tpl->assign ('AUX', "En aquest moment no té cap <b>reserva</b> en aquest <b>complex rural</b>.<br><br><a href='javascript:history.back()'>Tornar a la pàgina anterior</a>");
78: $tpl->parse(COS, "aux");
79: } else { // si hi han reserves, mostrem informacio reduida
80: while ($f = mysql_fetch_array($query)) {
81: $tpl->assign (array (IDRES => $f['R_Codi'], NOMCR => $f['CR_Nom'], NOMUS => $f['U_Nom']." ".$f['U_Cognom1']." ".$f['U_Cognom2'], DATARES => date_to_esp($f['R_Data_reserva']), DATAINI => date_to_esp($f['R_Data_inici']), DATAFI => date_to_esp($f['R_Data_fi'])));
82: $tpl->parse(ROWRESERVA, ".rowreserva");
83: }
84: $tpl->parse(COS, "reservacr");
85: }
86: } else {
87: $tpl->parse(COS, "cos");
88: } // fi de navs
89:
90:
91:// inici esborrar empresari hostaler
92:if ($_POST['idehdrop']) {
93: if ($_SESSION['idreg'] == '') { // comprova que estem enregistrats
94: $tpl->assign ('TITOL', "Error");
95: $tpl->assign ('AUX', "En primer lloc ha d'iniciar sessió com usuari <b>registrat</b>");
96: $tpl->parse(COS, "aux");
97: } else {
98: $now=date("Y") ."-". date("m") ."-". date("d");
99: $query=mysql_query("SELECT EH_Codi from Empresari_hostaler e, Complex_rural c, Allotjament a, Reserva r where e.EH_Codi='".$_POST['idehdrop']."' and e.EH_Codi=c.CR_Empresari_hostaler and c.CR_Codi=a.A_Complex_rural and a.A_Codi=r.R_Allotjament and r.R_Data_fi >= ".$now."", $link);
100: if (mysql_num_rows($query) == 0) {
101: $query=mysql_query("UPDATE Empresari_hostaler SET EH_Actiu='0' where EH_Codi='".$_POST['idehdrop']."'", $link);
102: session_destroy();
103: header("Location: index.php");
104:// $tpl->assign ('TITOL', "Empresari hostaler esborrat");
105: // $tpl-> assign ('AUX', "L'<b>empresari hostaler</b> ha sigut esborrat correctament.");
106: //$tpl->parse(COS, "aux");
107: } else {
108: $tpl->assign ('TITOL', "Error al esborrar empresari hostaler");
109: $tpl-> assign ('AUX', "L'<b>empresari hostaler</b> seleccionat té algun <b>complex rural</b> amb alguna <b>reserva activa</b>, i no es pot esborrar.");
110: $tpl->parse(COS, "aux");
111: }
112: }
113:}
114:// fi esborrar empresari hostaler
115:
116:
117:// inici nou/modificar complex rural
118:if ($_POST['crnom'] || $_POST['crtel'] || $_POST['cremail'] || $_POST['cradreca'] || $_POST['crcodipostal'] || $_POST['crpoblacio'] || $_POST['crprovincia'] || $_POST['crtipus'] || $_POST['crnumall'] || $_POST['crfoto'] || $_POST['crdescripcio']) {
119: $crerrors='';
120: // comprova que no hi han complexos rurals del mateix EH amb el mateix nom
121: $consulta2 = mysql_query("SELECT CR_Nom from Empresari_hostaler e, Complex_rural c where e.EH_Codi=c.CR_Empresari_hostaler and e.EH_Email='".$_SESSION['emailreg']."' and c.CR_Nom='".$_POST['crnom']."'", $link);
122: if ($f = mysql_fetch_array($consulta2) && ($_POST['esmodcr'] != '1')) {
123: $crerrors.="<li>Ja ha registrat un <b>complex rural</b> amb aquest <b>nom</b></li>";
124: }
125: // comprova errors en dades a introduir
126: if ((!ereg("^.{2,100}$", $_POST['crnom'])) && ($_POST['esmodcr'] != '1')) {
127: $crerrors.="<li>El <b>nom del complex rural</b> és incorrecte</li>";
128: }
129: if (!ereg("^[0-9]{9,9}$", $_POST['crtel'])) {
130: $crerrors.="<li>El <b>telèfon</b> és incorrecte</li>";
131: }
132: if ((!ereg("^[a-zA-Z0-9-]([\._a-zA-Z0-9-]+)*@[a-zA-Z0-9]+\.([a-zA-Z0-9-]+[\.]?)*$", $_POST['cremail'])) && ($_POST['cremail']) != '') {
133: $crerrors.="<li>L'<b>e-mail</b> és incorrecte</li>";
134: }
135: if ((!ereg("^.{3,100}$", $_POST['cradreca'])) && ($_POST['esmodcr'] != '1')) {
136: $crerrors.="<li>L'<b>adreça</b> és incorrecta</li>";
137: }
138: if ((!ereg("^[0-9]{5}$", $_POST['crcodipostal'])) && ($_POST['esmodcr'] != '1')) {
139: $crerrors.="<li>El <b>codi postal</b> és incorrecte</li>";
140: }
141: if ((!ereg("^.{2,50}$", $_POST['crpoblacio'])) && ($_POST['esmodcr'] != '1')) {
142: $crerrors.="<li>La <b>població</b> és incorrecta</li>";
143: }
144: if (($_POST['crprovincia'] == 0) && ($_POST['esmodcr'] != '1')) {
145: $crerrors.="<li>La <b>provincia</b> és incorrecta</li>";
146: }
147: if (($_POST['crprovincia']{0} != $_POST['crcodipostal']{0}) || ($_POST['crprovincia']{1} != $_POST['crcodipostal']{1})){
148: $crerrors.="<li>La <b>provincia</b> no es correspon al <b>codi postal</b></li>";
149: }
150: if (($_POST['crtipus'] == '') && ($_POST['esmodcr'] != '1')) {
151: $crerrors.="<li>El <b>tipus de complex rural</b> és incorrecte</li>";
152: }
153: // gestionem els errors
154: if ($_SESSION['emailreg'] == '') {
155: $tpl->assign ('TITOL', "Error");
156: $tpl->assign ('AUX', "En primer lloc ha d'iniciar sessio com usuari registrat");
157: $tpl->parse(COS, "aux");
158: } elseif (!empty($crerrors)) {
159: $crerrors="<ul>".$crerrors;
160: $crerrors.="</ul><a href='javascript:history.back()'>Tornar a la pàgina anterior</a>";
161: $tpl->assign ('TITOL', "Errors en les dades de complex rural");
162: $tpl->assign ('AUX', $crerrors);
163: $tpl->parse(COS, "aux");
164: } else {
165: //gestionem la foto
166: if ($HTTP_POST_FILES['crfoto']['name']) { // comprovem si hi ha foto...
167: $ferrors="";
168: $nomfoto = $HTTP_POST_FILES['crfoto']['name'];
169: $tipofoto = $HTTP_POST_FILES['crfoto']['type'];
170: $tamanyfoto = $HTTP_POST_FILES['crfoto']['size'];
171: $tmpfoto = $HTTP_POST_FILES['crfoto']['tmp_name'];
172: if (!(strpos($tipofoto, "jpeg") && ($tamanyfoto < 1048577))) {
173: $ferrors.="<li>La <b>imatge</b> ha de ser <b>.jpg o .jpeg</b> i ha de tindre un tamany <b>menor d'1 Mb</b></li>";
174: } else {
175: $foto=file_get_contents($tmpfoto);
176: }
177: }
178: if (!empty($ferrors)) { // comprovem si hi han errors en la foto
179: $ferrors="<ul>".$ferrors;
180: $ferrors.="</ul><a href='javascript:history.back()'>Tornar a la pàgina anterior</a>";
181: $tpl->assign ('TITOL', "Errors en les dades de nou complex rural");
182: $tpl->assign ('AUX', $ferrors);
183: $tpl->parse(COS, "aux");
184: } else { // si no hi han errors, insertem les dades
185: if ($_POST['esmodcr'] == '1') { // si estem modificant, fem update
186: mysql_query("UPDATE Complex_rural SET CR_Telefon='".$_POST['crtel']."', CR_Email='".$_POST['cremail']."', CR_Descripcio='".$_POST['crdescripcio']."' where CR_Codi='".$_POST['idcrmod']."'", $link);
187: if ($HTTP_POST_FILES['crfoto']['name']) { // si estem modificant la foto...
188: mysql_query("UPDATE Complex_rural SET CR_Imatge='".mysql_escape_string($foto)."', CR_Tipus_imatge='".$tipofoto."' where CR_Codi='".$_POST['idcrmod']."'", $link);
189: }
190: } else { // si es nou cr, insertem les dades
191: // el nou complex rural s'inserta com a inactiu, quan l'EH envie la documentacio acreditant la propietat, l'administrador l'activara
192: mysql_query("INSERT INTO Complex_rural (CR_Codi , CR_Nom, CR_Telefon, CR_Email, CR_Adreca, CR_Codi_postal, CR_Poblacio, CR_Provincia, CR_Tipus_allotjament, CR_Empresari_hostaler, CR_Foto, CR_Actiu, CR_Descripcio, CR_Imatge, CR_Tipus_imatge) VALUES ('', '{$_POST['crnom']}', '{$_POST['crtel']}', '{$_POST['cremail']}' , '{$_POST['cradreca']}', '{$_POST['crcodipostal']}', '{$_POST['crpoblacio']}', '{$_POST['crprovincia']}', '{$_POST['crtipus']}', '{$_SESSION['idreg']}', '{$_POST['crfoto']}', '0', '{$_POST['crdescripcio']}', '".mysql_escape_string($foto)."', '".$tipofoto."')", $link);
193: $my_error = mysql_error($link);
194: }
195: if(!empty($my_error)) {
196: $tpl->assign ('TITOL', "Errors");
197: $tpl-> assign ('AUX', $my_error);
198: $tpl->parse(COS, "aux");
199: } else {
200: if ($_POST['esmodcr'] == '1') {
201: $tpl->assign ('TITOL', "Modificació correcta");
202: $tpl->assign ('AUX', "Les dades del complex rural s'han modificat correctament");
203: $tpl->parse(COS, "aux");
204: } else {
205: $tpl->assign ('TITOL', "Registre de nou complex rural correcte");
206: $tpl->assign ('AUX', "Per a activar el complex rural haurà de remetre'ns per fax o per correu una còpia de l'escriptura que demostre la veracitat de la propietat al número de fax 966374658 o a l'adreça C.de la piga Nº33, 48012, València.<br><br>Per a enregistrar nous <b>allotjaments</b> podeu anar al menú de gestió de <b>Complexos Rurals</b>.<br><br>Gràcies per utilitzar aquest servei.<br><br>");
207: $tpl->parse(COS, "aux");
208: }
209: }
210: }
211: }
212:}
213:// fi nou/modificar complex rural
214:
215:
216:// inici nou/editar allotjament
217:if ($_POST['allcapacitat'] || $_POST['allpreutalta'] || $_POST['allpreutbaixa'] || $_POST['allquantitat'] || $_POST['alldescripcio']) {
218: $allerrors='';
219:
220: // comprova que segueix existint CR i la sessio d'EH
221: $cerca=mysql_query("SELECT * from Complex_rural c, Empresari_hostaler e where e.EH_Email='".$_SESSION['emailreg']."' and e.EH_Codi = c.CR_Empresari_hostaler", $link);
222: if (mysql_num_rows($cerca) == 0) {
223: $allerrors.="<li>Error en les dades de nou allotjament. Torna a realizar una cerca</li>";
224: }
225:
226: // comprova que no hi han mes allotjaments en aquest cr amb aquestes caracteristiques; nomes si es nou allotjament
227: if ($_POST['iseditall'] != '1') {
228: $cerca=mysql_query("SELECT * from Complex_rural c, Empresari_hostaler e, Allotjament a where e.EH_Email='".$_SESSION['emailreg']."' and e.EH_Codi = c.CR_Empresari_hostaler and c.CR_Codi='".$_SESSION['editcr']."' and c.CR_Codi=a.A_Complex_rural and a.A_Preu_talta='".$_POST['allpreutalta']."' and a.A_Preu_tbaixa='".$_POST['allpreutbaixa']."' and a.A_Capacitat='".$_POST['allcapacitat']."'", $link);
229: if (mysql_num_rows($cerca) != 0) {
230: $allerrors.="<li>Ja existeix un <b>allotjament</b> en aquest <b>complex rural</b> amb aquestes caracteristiques. Per a ampliar el nombre d'aquestos allotjaments ha d'editar el registrat anteriorment</li>";
231: }
232: }
233:
234: // comprova errors en dades a introduir
235: if (!ereg("^[0-9]{1,11}$", $_POST['allcapacitat'])) {
236: $allerrors.="<li>La <b>capacitat</b> és incorrecta</li>";
237: }
238: if (!ereg("^[0-9]{1,11}$", $_POST['allpreutalta'])) {
239: $allerrors.="<li>El <b>preu de temporada alta</b> és incorrecte</li>";
240: }
241: if (!ereg("^[0-9]{1,11}$", $_POST['allpreutbaixa'])) {
242: $allerrors.="<li>El <b>preu de temporada baixa</b> és incorrecte</li>";
243: }
244: if (!ereg("^[0-9]{1,11}$", $_POST['allquantitat'])) {
245: $allerrors.="<li>La <b>quantitat d'allotjaments</b> és incorrecta</li>";
246: }
247: // gestiona els errors
248: if ($_SESSION['emailreg'] == '') {
249: $tpl->assign ('TITOL', "Error");
250: $tpl->assign ('AUX', "En primer lloc ha d'iniciar sessio com usuari registrat");
251: $tpl->parse(COS, "aux");
252: } elseif (!empty($allerrors)) {
253: $allerrors="<ul>".$allerrors;
254: $allerrors.="</ul><a href='javascript:history.back()'>Tornar a la pàgina anterior</a>";
255: $tpl->assign ('TITOL', "Errors en les dades de nou allotjament");
256: $tpl->assign ('AUX', $allerrors);
257: $tpl->parse(COS, "aux");
258: } else {
259: if ($_POST['iseditall'] == '1') { // si estem editant, fem update
260: mysql_query("UPDATE Allotjament SET A_Capacitat='".$_POST['allcapacitat']."', A_Preu_talta='".$_POST['allpreutalta']."', A_Preu_tbaixa='".$_POST['allpreutbaixa']."', A_Quantitat='".$_POST['allquantitat']."', A_Descripcio='".$_POST['alldescripcio']."' where A_Codi='".$_POST['idallmod']."'", $link);
261: } else { // si es nou allotjament, fem insert
262: mysql_query("INSERT INTO Allotjament (A_Codi, A_Capacitat, A_Preu_talta, A_Preu_tbaixa, A_Complex_rural, A_Quantitat, A_Descripcio) VALUES ('', '{$_POST['allcapacitat']}', '{$_POST['allpreutalta']}', '{$_POST['allpreutbaixa']}' , '{$_SESSION['editcr']}', '{$_POST['allquantitat']}', '{$_POST['alldescripcio']}')", $link);
263: }
264: $my_error = mysql_error($link);
265: if(!empty($my_error)) {
266: $tpl->assign ('TITOL', "Errors");
267: $tpl-> assign ('AUX', $my_error);
268: $tpl->parse(COS, "aux");
269: } else {
270: if ($_POST['iseditall'] == '1') {
271: $tpl->assign ('TITOL', "Modificació d'allotjament correcta");
272: $tpl->assign ('AUX', "L'allotjament s'ha modificat correctament");
273: $tpl->parse(COS, "aux");
274: } else {
275: $tpl->assign ('TITOL', "Registre de nou allotjament correcte");
276: $tpl->assign ('AUX', "S'ha registrat correctament l'allotjament");
277: $tpl->parse(COS, "aux");
278: }
279: }
280: }
281:}
282:// fi nou/editar allotjament
283:
284:// inici esborrar allotjament
285:if ($_POST['iddropall']) {
286: if ($_SESSION['idreg'] == '') { // comprova que estem enregistrats
287: $tpl->assign ('TITOL', "Error");
288: $tpl->assign ('AUX', "En primer lloc ha d'iniciar sessió com usuari <b>registrat</b>");
289: $tpl->parse(COS, "aux");
290: } else {
291: $now=date("Y") ."-". date("m") ."-". date("d");
292: $query=mysql_query("SELECT * from Allotjament a, Reserva r where a.A_Codi='".$_POST['iddropall']."' and a.A_Codi=r.R_Allotjament and r.R_Data_fi >= ".$now."", $link);
293: if (mysql_num_rows($query) == 0) {
294: $query=mysql_query("DELETE from Allotjament where A_Codi='".$_POST['iddropall']."'", $link);
295: $tpl->assign ('TITOL', "Allotjament esborrat");
296: $tpl-> assign ('AUX', "L'<b>allotjament</b> ha sigut esborrat correctament.");
297: $tpl->parse(COS, "aux");
298: } else {
299: $tpl->assign ('TITOL', "Error al esborrar allotjament");
300: $tpl-> assign ('AUX', "L'<b>allotjament</b> seleccionat té alguna <b>reserva activa</b>, i no es pot esborrar.");
301: $tpl->parse(COS, "aux");
302: }
303: }
304:}
305:// fi esborrar allotjament
306:
307:// inici esborrar complex rural
308:if ($_POST['idcrdrop']) {
309: if ($_SESSION['idreg'] == '') { // comprova que estem enregistrats
310: $tpl->assign ('TITOL', "Error");
311: $tpl->assign ('AUX', "En primer lloc ha d'iniciar sessió com usuari <b>registrat</b>");
312: $tpl->parse(COS, "aux");
313: } else {
314: $now=date("Y") ."-". date("m") ."-". date("d");
315: $query=mysql_query("SELECT * from Complex_rural c, Allotjament a, Reserva r where c.CR_Codi='".$_POST['idcrdrop']."' and c.CR_Codi=a.A_Complex_rural and a.A_Codi=r.R_Allotjament and r.R_Data_fi >= ".$now."", $link);
316: if (mysql_num_rows($query) == 0) {
317: $query=mysql_query("UPDATE Complex_rural SET CR_Actiu='0' where CR_Codi='".$_POST['idcrdrop']."'", $link);
318: $tpl->assign ('TITOL', "Complex rural esborrat");
319: $tpl-> assign ('AUX', "El <b>complex rural</b> ha sigut esborrat correctament.");
320: $tpl->parse(COS, "aux");
321: } else {
322: $tpl->assign ('TITOL', "Error al esborrar complex rural");
323: $tpl-> assign ('AUX', "El <b>complex rural</b> seleccionat té alguna <b>reserva activa</b>, i no es pot esborrar.");
324: $tpl->parse(COS, "aux");
325: }
326: }
327:}
328:// fi esborrar complex rural
329:
330:
331:
332:
333:
334:}
335:
336:$tpl->parse(MAIN, "main");
337:
338:$tpl->FastPrint();
339:exit;
340:?>