Agregado modulo de gestion de pantallas,
[ecomupi.git] / instalar.php
blobabbc1cd30f007602a5b3156fa1669fd9d7cc1e1c
1 <?php
2 if( !file_exists("include/data.php") ) { if ( !touch ("include/data.php") ) exit ("woops!, include/data.php no existe y no pudo ser creado");}
3 require_once("include/const.php");
4 error_reporting(E_STRICT | E_ALL);
6 function CREAR_TBL($TBL,$QUERY) {
7 global $link;
8 if ( isset($_POST['reiniciar']) ) {
9 @mysql_query("DROP TABLE IF EXISTS $TBL;", $link) or die('!->No se pudo eliminar la tabla "'.$TBL.'".<br /><pre>' . mysql_error() . '</pre>');
11 $QUERY = "CREATE TABLE IF NOT EXISTS ". $TBL . " (" . $QUERY . ");";
12 $x = @mysql_query($QUERY, $link) or die('!->No se pudo crear la tabla "'. $TBL .'".<br /><pre>' . mysql_error() . '</pre>');
13 if ($x) {echo "- Creada: '$TBL'<br />";}
16 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
17 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
18 <head>
19 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
20 <meta http-equiv="Content-Style-type" content="text/css" />
21 <meta http-equiv="Content-Script-type" content="text/javascript" />
22 <meta http-equiv="Content-Language" content="es" />
23 <link rel="StyleSheet" href="estilo.css" type="text/css" />
24 <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
25 <link rel="start" href="/" />
26 <title>Instalador de MUPI</title>
27 </head>
28 <body>
29 <div id="centerwrapper">
30 <div id="content">
33 $DB_motor = isset($DB_motor) ? $DB_motor : "localhost";
34 $DB_usuario = isset($DB_usuario) ? $DB_usuario : "";
35 $DB_base = isset($DB_base) ? $DB_base : "";
36 $MapKey = isset($MapKey) ? $MapKey : "";
37 if (!isset($_POST['instalar'])) {
38 echo '<h1>'._NOMBRE_.' - Instalador</h1><br />
39 <form action="'. $_SERVER['PHP_SELF'] .'" method="post">
40 <table border="0">
41 <tr><td colspan="2"><h2>Configuración MySQL</h2></td></tr>
42 <tr>
43 <td>Dirección del servidor MySQL:</td>
44 <td><input type="text" name="motor" maxlength="100" size="20" value="localhost" /></td>
45 </tr>
46 <tr>
47 <td>Base de datos a utilizar:</td>
48 <td><input type="text" name="base" maxlength="100" size="20" value="'.$DB_base.'" /></td>
49 </tr>
50 <tr>
51 <td>Usuario:</td>
52 <td><input type="text" name="usuario" maxlength="100" size="20" value="'.$DB_usuario.'" /></td>
53 </tr>
54 <tr>
55 <td>Clave:</td>
56 <td><input type="password" name="clave" maxlength="30" size="20" value="" /></td>
57 </tr>
58 <tr><td colspan="2"><h2>Google Maps</h2></td></tr>
59 <tr>
60 <td>Google Map API Key:</td>
61 <td><input type="text" name="MapKey" maxlength="100" size="20" value="'.$MapKey.'" /></td>
62 </tr>
63 <tr><td colspan="2"><h2>Administración</h2></td></tr>
64 <tr>
65 <td>Nombre Administrador:</td>
66 <td><input type="text" name="admin" maxlength="100" size="20" value="" /></td>
67 </tr>
68 <tr>
69 <td>Correo electrónico:</td>
70 <td><input type="text" name="email" maxlength="100" size="20" value="" /></td>
71 </tr>
72 <tr>
73 <td>Clave:</td>
74 <td><input type="password" name="admin_clave" maxlength="20" size="20" value="" /></td>
75 </tr>
76 <tr>
77 <td>Clave (repetir):</td>
78 <td><input type="password" name="admin_clave2" maxlength="20" size="20" value="" /></td>
79 </tr>
80 </table>
81 <br />
82 <input type="checkbox" name="reiniciar" value="" />Destruir tablas si existen
83 <br />
84 <input type="submit" name="instalar" value="Instalar" />
85 </form>
87 } else {
88 echo '<b>'._NOMBRE_.' - Instalador : Instalando</b><br />';
89 if ($_POST['admin_clave'] != $_POST['admin_clave2']) {
90 echo '<h3>+Las contraseñas no coinciden.</h3><br />
91 <a href="javascript:history.back();">Regresar al instalador</a>';
93 echo '<h3>+Creando conexión a la base de datos...</h3><br />';
94 $link = @mysql_connect($_POST['motor'], $_POST['usuario'], $_POST['clave']) or die('Por favor revise sus datos, puesto que se produjo el siguiente error:<br /><pre>' . mysql_error() . '</pre>');
95 mysql_select_db($_POST['base'], $link) or die('!->La base de datos seleccionada "'.$_POST['base'].'" no existe');
96 echo '- Base de datos conectada...<br />';
97 echo '<h3>+Creando Archivo con datos de conexión...</h3><br />';
98 @chmod("include/data.php", 0666);
99 $fh = @fopen("include/data.php", 'w') or die("No se pudo escribir 'data.php'.<br />");
100 if ($fh) {
101 $Datos = "<?php ";
102 fwrite($fh, $Datos);
103 $Datos = '$DB_motor = "'. $_POST['motor'] .'";' . '$DB_usuario = "'. $_POST['usuario'] . '";'. '$DB_clave = "'. $_POST['clave'] .'";' . '$DB_base = "'. $_POST['base'] .'";' . '$MapKey = "'. $_POST['MapKey'] .'";';
104 fwrite($fh, $Datos);
105 $Datos = " ?>\n";
106 fwrite($fh, $Datos);
107 fclose($fh);
109 echo '- Creado<br />';
110 echo '<h3>+Creando Tablas...</h3><br />';
111 if ( isset($_POST['reiniciar']) ) { echo '->Se solicitó destruir y crear tablas<br />'; }
113 Tabla que contiene los datos de los clientes.
114 Esta tabla solo contendrá los datos relaventes a la identificación y contacto de cliente
116 $q="codigo VARCHAR(100) primary key, clave VARCHAR(32) not null, nombre VARCHAR(32) not null, razon VARCHAR(100) not null, email VARCHAR(50), telefono1 VARCHAR(20) not null, telefono2 VARCHAR(20), telefono3 VARCHAR(20), logotipo VARCHAR(200), notas VARCHAR(500), userlevel tinyint(1) unsigned not null, userid VARCHAR(32), timestamp int(11) unsigned not null";
117 CREAR_TBL(TBL_USERS, $q);
120 Tabla que contiene a los USUARIOS activos
121 NOTA: En un futuro se va a unir con TBL_ACTIVE_GUESTS
123 $q="codigo VARCHAR(30) primary key, timestamp int(11) unsigned not null";
124 CREAR_TBL(TBL_ACTIVE_USERS, $q);
127 Tabla que contiene a los VISITANTES activos
128 NOTA: En un futuro se va a unir con TBL_ACTIVE_USERS
130 $q="ip VARCHAR(15) primary key, timestamp int(11) unsigned not null";
131 CREAR_TBL(TBL_ACTIVE_GUESTS, $q);
134 Tabla que contiene la descripción de cada mupi habido y por haber
135 No contiene información sobre quién lo arrenda ni desde cuando, solo lo ubica en el mapa.
136 Ademas contiene la direccion (path) a la imagen/foto generica de este MUPI en particular.
137 NOTA: El campo evento tendrá el código de algún evento ocurrido (si hubiera) a este MUPI.
138 Si el evento le ocurré al MUPI en general (ej. le choca un automovil) entonces deberá
139 asignarle el evento al MUPI.
140 Si el evento llegará a afectar a una sola de las caras, entonces deberá relacionar dicho
141 evento con la cara afectada y no con el MUPI. Ver detalles en tabla TBL_MUPI_FACES.
143 $q="codigo_mupi VARCHAR(100) NOT NULL PRIMARY KEY, direccion VARCHAR(255), foto_generica VARCHAR(255), lon float default NULL, lat float default NULL, codigo_evento VARCHAR(50)";
144 CREAR_TBL(TBL_MUPI, $q);
147 Esta tabla es una tabla relacionada con TBL_MUPI en el sentido de que a travez de ella se determinan las caras alquiladas
148 Ademas de su fecha de alquiler, quien es su "alquilador", que tipo de cara es (peatonal/vehicular) y la foto actual del MUPI.
149 NOTA: Dado que el daño a un MUPI (llamado "evento") puede producirse en una sola cara (ej. el pintando callejero de una cara)
150 entonces también los eventos pueden ser asociados a estas (caras).
152 $q="codigo_cara_mupi VARCHAR(100) NOT NULL PRIMARY KEY, codigo_mupi VARCHAR(100) NOT NULL, codigo VARCHAR(100), alquilado_desde int(11), codigo_evento VARCHAR(50), foto VARCHAR(255)";
153 CREAR_TBL(TBL_MUPI_FACES, $q);
156 La tabla de eventos contiene la fecha cuando sucedió el evento y la descripción del evento.
157 No tiene campo para decir que MUPI afectó porque al contrario es en las tablas TBL_MUPI y
158 TBL_MUPI_FACES en las que se relaciona con una entrada de esta tabla.
161 $q="codigo_evento VARCHAR(50) NOT NULL PRIMARY KEY, descripcion_evento VARCHAR(500)";
162 CREAR_TBL(TBL_MUPI_EVENTS, $q);
165 Esta tabla es un cache de GEOCODES. Requerido por PHPGoogleMapApi para optimizar la búsqueda de los mismos GEOCODES.
166 Ademas puede ser util en un futuro para referenciar los MUPIS por su dirección en lugar de sus coordenadas.
168 $q="address VARCHAR(255) NOT NULL PRIMARY KEY, lon float default NULL, lat float default NULL";
169 CREAR_TBL(TBL_GEOCODE_CACHE, $q);
172 Esta tabla funciona como una versión básica de un registro de pares.
173 Servirá para llevar las estadísticas de todo el sitio:
174 -Numero de visitas
176 $q="clave VARCHAR(255) NOT NULL PRIMARY KEY, valor VARCHAR(255)";
177 CREAR_TBL(TBL_REGISTRY, $q);
179 echo '<h3>+Creando usuario '.$_POST['admin'].'...</h3><br />';
180 $q = "INSERT INTO ".TBL_USERS." VALUES ('".$_POST['admin'] . "', '" . md5($_POST['admin_clave']) . "', 'Administrador Principal', 'Administrador', '" . $_POST['email'] . "', '0','','','','Creado durante de la instalación', 9, 0," . time() . ") ON DUPLICATE KEY UPDATE codigo=VALUES(codigo), clave=VALUES(clave), email=VALUES(email)";
181 @mysql_query($q, $link) or die('!->No se pudo insertar el usuario<br /><pre>' . mysql_error() . '</pre>');;
182 echo '- Creado<br />';
183 mysql_close($link);
184 echo '<br /><b>Instalación completa</b><br />';
187 </div>
188 </div>
189 </body>
190 </html>