. */ define('PIE', '
GPL v3'. 'Sitio web creado con Apache'. 'Gestor de bases de datos mySQL'. 'PHP Language
'); define('FORMULARIO_ACCESO', '
'. 'Usuario


Clave
'. '

'); define('MENSAJE_DEMO', 'Puede Iniciar sesión con
usuario demo
contraseña demo
'); define('USUARIO_INCORRECTO', '

'); define('CREDITOS_CABECERA', ''); // Esta clase aportará el contenido a la plantilla class AportaContenido { /** * @var bool Aporta información sobre si el usuario está registrado o no. */ private $registrado; /** * @var string Nombre del usuario */ private $usuario = null; /** * @var Menu Menú de la página. */ private $miMenu; /** * @var database Controlador de la base de datos */ private $bdd; /** * @var string Opción elegida por el usuario */ private $opcionActual; /** * @var bool Usuario y clave incorrectos? */ private $usuario_inc = false; /** * @var array Permisos del usuario */ private $perfil; /** * @var array Datos pasados en la URL */ private $datosURL = []; // El constructor necesita saber cuál es la opción actual /** * Constructor de la clase. * * @param BaseDatos $baseDatos Manejador de la base de datos * @param bool $registrado usuario registrado si/no * @param string $usuario Nombre del usuario * @param array $perfil Permisos de acceso del usuario * @param string $opcion Opción elegida por el usuario */ public function __construct($baseDatos, $registrado, $usuario, $perfil, $opcion) { $this->bdd = $baseDatos; $this->miMenu = new Menu('inc/inventario.menu'); $this->registrado = $registrado; $this->usuario = $usuario; $this->perfil = $perfil; $this->opcionActual = $opcion; } /** * Devuelve una tabla HTML con el contenido de las bibliotecas/módulos utilizadas en la aplicación * Si el perfil del usuario es de Configuración devuelve también las versiones de las bibliotecas. * * @return string */ public function creaTablaAcercaDe() { $poner = $this->perfil['Config']; $tabla = ''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''.($poner ? '' : '').''; $tabla .= ''; $tabla .= '
Biblioteca/MóduloVersiónLicencia
jquery2.1.0MIT
Twitter Bootstrap3.1.1MIT
FPDF1.7Libre
PHP QR Code Enconder1.1.4LGPL
Zebra_Image2.2.3LGPL
Jasny Bootstrap3.1.0Apache 2.0
Bootstrap Validator0.2.1MIT
jquery-simplecolorpicker0.3.0MIT
Bootstrap datetimepicker2.1.32MIT
Bootstrap-select1.5.4MIT
X-editable1.5.1MIT
Moment.js2.5.1MIT
'; return $tabla; } /** * Devuelve la fecha actual. * * @param string $formato formato de devolución de la fecha * @param string $idioma idioma para formatear la fecha, p.ej. es_ES * * @return string */ public function fechaActual($formato = '', $idioma = 'es_ES') { if ($formato == '') { $formato = '%d-%b-%y'; } setlocale(LC_TIME, $idioma); return strftime($formato); } /** * @return string Mensaje el usuario debe registrarse. */ private function mensajeRegistro() { return 'Debe registrarse para acceder a este apartado'; } // Procesaremos todas las invocaciones a métodos en // la función __call() /** * Procesa las peticiones de contenido de la plantilla. * * @param string $metodo Método a ejecutar * @param string $parametros Parámetros del método * * @return string Contenido devuelto por el método */ public function __call($metodo, $parametros) { switch ($metodo) { // Dependiendo del método invocado case 'usuario': if ($this->registrado) { return "Usuario=$this->usuario"; } else { return ''; } case 'fecha': $script = '"; $campo = ''; $etiqueta = ''; return $etiqueta.$campo.$script; case 'aplicacion': $nombre = explode(' ', PROGRAMA); $nombre = $nombre[2]; return $nombre.' v'.VERSION; case 'menu': // el menú if ($this->registrado) { return $this->miMenu->insertaMenu(); } else { $salida = FORMULARIO_ACCESO; if ($this->usuario_inc) { $salida .= USUARIO_INCORRECTO; } //$salida.=MENSAJE_DEMO; return $salida; } case 'opcion': if (strstr($this->opcionActual, '&')) { list($opcion, $parametro) = explode('&', $this->opcionActual); } else { $opcion = $this->opcionActual; $parametro = ''; } switch ($opcion) { case 'bienvenido': return 'Menú Principal'; case 'principal': return 'Pantalla Inicial'; case 'articulos': $opcion = 'artículos'; case 'elementos': case 'ubicaciones': case 'usuarios': case 'test': return 'Mantenimiento '.ucfirst($opcion); case 'configuracion': return 'Configuración y Preferencias'; case 'informeInventario':return 'Informe de Inventario'; case 'descuadres':return 'Informe de descuadres'; case 'importacion': return 'Importación de datos'; case 'copiaseg': return 'Copia de seguridad de datos'; } return ''; case 'control': if ($this->registrado) { return 'Cerrar Sesión '; } else { return ''; } // Para incluir el contenido central de la página case 'contenido': // tendremos en cuenta cuál es la opción actual /* echo "opcActual=$this->opcActual
"; echo "Metodo=$Metodo
"; print_r($Parametros); */ // if (!$this->registrado) { // return $this->mensajeRegistro(); // } if (strstr($this->opcionActual, '&')) { list($opcion, $parametro) = explode('&', $this->opcionActual); } else { $opcion = $this->opcionActual; $parametro = ''; } switch ($opcion) { case 'bienvenido': $mensaje = '
'; $mensaje .= 'Bienvenid@ '.$this->usuario.'
'; case 'principal': // contenido inicial $mensaje = ''; $creditos = "$('#creditos').modal({keyboard: false});"; $centro = '
'.CENTRO.'
'; $tabla = $this->creaTablaAcercaDe(); $rama_texto = trim(substr(file_get_contents('.git/HEAD'), 16)); $rama = ($rama_texto != 'master' ? '
' : ''); return $mensaje.'

'.PROGRAMA.''. '

'.$rama.'
'.CREDITOS_CABECERA.$tabla.CREDITOS_PIE; case 'articulos': case 'ubicaciones': case 'test': case 'elementos': $this->cargaDatosURL(); if ($this->datosURL['opc'] == 'informe') { if ($this->perfil['Informe']) { $this->procesaURL(); $fichero = 'xml/informe'.ucfirst($opcion).'.xml'; $salida = TMP.'/informe'.ucfirst($opcion).'.xml'; //Establece los posibles parámetros del listado. $orden = $this->datosURL['orden']; $sentido = $this->datosURL['sentido'] == 'asc' ? ' ' : ' desc '; $filtro = isset($this->datosURL['buscar']) ? $this->bdd->filtra($this->datosURL['buscar']) : ''; $plantilla = file_get_contents($fichero) or die('Fallo en la apertura de la plantilla '.$fichero); $plantilla = str_replace('{filtro}', $filtro, $plantilla); $plantilla = str_replace('{orden}', $orden.$sentido, $plantilla); file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla '.$salida); $informe = new InformePDF($this->bdd, $salida, $this->registrado); $informe->crea($salida); $informe->cierraPDF(); return $this->devuelveInforme($informe); } else { return $this->mensajePermisos('Informes'); } } if ($this->perfil['Consulta']) { $ele = new Mantenimiento($this->bdd, $this->perfil, $opcion); return $ele->ejecuta(); } else { return $this->mensajePermisos(ucfirst($opcion)); } case 'usuarios': if ($this->perfil['Usuarios']) { $this->cargaDatosURL(); if ($this->datosURL['opc'] == 'informe') { if (!$this->pefil['Informe']) { $this->procesaURL(); $fichero = 'xml/informe'.ucfirst($opcion).'.xml'; $salida = TMP.'/informe'.ucfirst($opcion).'.xml'; //Establece los posibles parámetros del listado. $orden = $this->datosURL['orden']; $sentido = $this->datosURL['sentido'] == 'asc' ? ' ' : ' desc '; $filtro = isset($this->datosURL['buscar']) ? $this->bdd->filtra($this->datosURL['buscar']) : ''; $plantilla = file_get_contents($fichero) or die('Fallo en la apertura de la plantilla '.$fichero); $plantilla = str_replace('{filtro}', $filtro, $plantilla); $plantilla = str_replace('{orden}', $orden.$sentido, $plantilla); file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla '.$salida); $informe = new InformePDF($this->bdd, $salida, $this->registrado); $informe->crea($salida); $informe->cierraPDF(); return $this->devuelveInforme($informe); } else { return $this->mensajePermisos('Informes'); } } $ele = new Mantenimiento($this->bdd, $this->perfil, $opcion); return $ele->ejecuta(); } else { return $this->mensajePermisos('Usuarios'); } case 'configuracion': if ($this->perfil['Config']) { $conf = new Configuracion(); return $conf->ejecuta(); } else { return $this->mensajePermisos('Configuración'); } case 'informeInventario': if ($this->perfil['Informe']) { $info = new InformeInventario($this->bdd); return $info->ejecuta(); } else { return $this->mensajePermisos('Informes'); } case 'importacion': if ($this->perfil['Modificacion'] && $this->perfil['Borrado']) { $import = new Importacion($this->bdd, $this->registrado); return $import->ejecuta(); } else { return $this->mensajePermisos('Actualización, creación y borrado de elementos'); } case 'copiaseg': if ($this->perfil['Config']) { $copia = new CopiaSeguridad(); if (isset($_GET['confirmado']) && $_GET['confirmado'] == '1') { if (!$copia->creaCopia()) { $tipo = 'danger'; $cabecera = 'ERROR'; } else { $tipo = 'info'; $cabecera = 'INFORMACIÓN'; } return $this->panel($cabecera, $copia->mensaje(), $tipo); } else { return $copia->dialogo(); } } else { return $this->mensajePermisos('Copias de seguridad'); } } // Fin del contenido case 'usuario_incorrecto': $this->usuario_inc = true; return; case 'registro': // Si está registrado mostrar bienvenida // si no, un enlace if ($this->bEstaRegistrado) { return "Bienvenid@ $this->sUsuario
". 'Cerrar sesión'; } else { return ''; } default: // Si es cualquier otra marca return "Marca {$metodo} queda sin procesar"; } } public function cargaDatosURL() { $this->datosURL['opc'] = isset($_GET['opc']) ? $_GET['opc'] : 'inicial'; $this->datosURL['orden'] = isset($_GET['orden']) ? $_GET['orden'] : 'id'; $this->datosURL['sentido'] = isset($_GET['sentido']) ? $_GET['sentido'] : 'asc'; $this->datosURL['pag'] = isset($_GET['pag']) ? $_GET['pag'] : '0'; $this->datosURL['buscar'] = isset($_GET['buscar']) ? $_GET['buscar'] : null; $this->datosURL['id'] = isset($_GET['id']) ? $_GET['id'] : null; } /** * @param string $tipo * * @return string */ public function mensajePermisos($tipo) { return $this->panel('ERROR', "No tiene permiso para acceder a $tipo", 'danger'); } private function devuelveInforme($informe) { $letras = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; $nombre = TMP.'/informe'.substr(str_shuffle($letras), 0, 10).'.pdf'; $informe->guardaArchivo($nombre); return '
'; } public function panel($cabecera, $mensaje, $tipo) { $panel = '
'; $panel .= '

'.$cabecera.'

'; $panel .= '
'; $panel .= $mensaje; $panel .= '
'; return $panel; } }