<?php
/*
* Alliances Manager (Gestionador de Alianzas) - Travian
* Copyright (C) 2008-12 Viva Mayer, Francisco Mesías <hide@address.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Recibe como parámetro la ubicación relativa del documento con respecto
// a la ubicación de la hoja de estilo
function cabecera ($css = "", $titulo = "")
{
$title = "Alliances Manager";
if (!empty($titulo)) $title .= " - ".$titulo;
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
echo "<head>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"/>\n";
echo "<title>".$title."</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$css."libs/estilos.css\">\n";
}
function acceso_restringido( $controlador, $modelo, &$msj)
{
$usuario_cero = array('session', 'registro', 'salir', 'changepass');
$tropas_cero = array('tropas', 'nueva', 'editar', 'borrar');
$aldeas_cero = array('aldeas', 'borrar', 'editar', 'nueva');
$msj = 'EPA02';
// Primero se verifica si ha iniciado sesión
if (!isset($_SESSION['usuario'])) {
if ($controlador=='ControlUsuario' ) {
if ($modelo!='session' or $modelo!='registro') return true;
else {
$msj = 'EPA01';
return false;
}
} else {
$msj = 'EPA02';
return false;
}
} else { // Ahora se verifican los permisos por cada sección y para cada menu
switch ($controlador) {
case 'ControlUsuario':
if (array_search($modelo, $usuario_cero)!==false) return true;
else return false;
break;
case 'ControlTropas':
if (array_search($modelo, $tropas_cero)!==false) return true;
elseif ($_SESSION['ver_tropas']!=0 and ($modelo=='todas' or $modelo=='Buscador') ) return true;
else return false;
break;
case 'ControlAldeas':
if (array_search($modelo, $aldeas_cero)!==false) return true;
elseif ($_SESSION['ver_tropas']!=0 and $modelo=='resumen') return true;
else return false;
break;
case 'ControlAdmin':
if ($_SESSION['gestion']==0) return false;
elseif ( $_SESSION['ver_tropas']==0 and $modelo == 'resumen') return false;
elseif ( $_SESSION['ver_tropas']==0 and $modelo == 'ver_datos') return false;
else return true;
case 'ControlGrupo':
if ($modelo == 'compas') return true;
elseif ($_SESSION['gestion']==0) return false;
else return true;
case 'ControlExtras': return true;
case 'ControlApp': return true;
}
}
}
/* **************************************
* Suma un arreglo lineal numerico
************************************** */
function sum_array ( array $arreglo )
{
$cont_sum_array = 0;
foreach ( $arreglo as $valor )
{
$cont_sum_array += $valor;
}
return $cont_sum_array;
}
function dias_entre($fdia, $fmes, $fanio, $tdia, $tmes, $tanio)
{
$texto = Idioma::singleton();
$F = mktime ( 0, 0, 0, $fmes, $fdia, $fanio);
$T = mktime ( 0, 0, 0, $tmes, $tdia, $tanio);
$aux = abs( ($F - $T) / (60*60*24) );
if ($aux == 0) $dia = $texto->get('hoy');
elseif ($aux == 1) $dia = $texto->get('ayer');
else $dia = $aux;
return $dia;
}
?>