wootook-reloaded/admin/statbuilder.php
Gregory PLANCHAT d7619777af Initial commit
2011-06-07 09:23:48 +02:00

270 lines
12 KiB
PHP

<?php
/**
* This file is part of XNova:Legacies
*
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @see http://www.xnova-ng.org/
*
* Copyright (c) 2009-Present, XNova Support Team <http://www.xnova-ng.org>
* All rights reserved.
*
* 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/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing XNova.
*
*/
define('INSIDE' , true);
define('INSTALL' , false);
define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/common.php';
include(ROOT_PATH . 'admin/statfunctions.' . PHPEXT);
if (strtolower(substr(PHP_SAPI, 0, 3)) == 'cli' || in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {
includeLang('admin');
$StatDate = time();
// Rotation des statistiques
doquery ( "DELETE FROM {{table}} WHERE `stat_code` = '2';" , 'statpoints');
doquery ( "UPDATE {{table}} SET `stat_code` = `stat_code` + '1';" , 'statpoints');
$GameUsers = doquery("SELECT * FROM {{table}} WHERE authlevel<3", 'users');
while ($CurUser = mysql_fetch_assoc($GameUsers)) {
// Recuperation des anciennes statistiques
$OldStatRecord = doquery ("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `id_owner` = '".$CurUser['id']."';",'statpoints');
if ($OldStatRecord) {
$OldTotalRank = $OldStatRecord['total_rank'];
$OldTechRank = $OldStatRecord['tech_rank'];
$OldBuildRank = $OldStatRecord['build_rank'];
$OldDefsRank = $OldStatRecord['defs_rank'];
$OldFleetRank = $OldStatRecord['fleet_rank'];
// Suppression de l'ancien enregistrement
doquery ("DELETE FROM {{table}} WHERE `stat_type` = '1' AND `id_owner` = '".$CurUser['id']."';",'statpoints');
} else {
$OldTotalRank = 0;
$OldTechRank = 0;
$OldBuildRank = 0;
$OldDefsRank = 0;
$OldFleetRank = 0;
}
// Total des unitées consommée pour la recherche
$Points = GetTechnoPoints ( $CurUser );
$TTechCount = $Points['TechCount'];
$TTechPoints = ($Points['TechPoint'] / $gameConfig['stat_settings']);
// Totalisation des points accumulés par planete
$TBuildCount = 0;
$TBuildPoints = 0;
$TDefsCount = 0;
$TDefsPoints = 0;
$TFleetCount = 0;
$TFleetPoints = 0;
$GCount = $TTechCount;
$GPoints = $TTechPoints;
$UsrPlanets = doquery("SELECT * FROM {{table}} WHERE `id_owner` = '". $CurUser['id'] ."';", 'planets');
while ($CurPlanet = mysql_fetch_assoc($UsrPlanets) ) {
$Points = GetBuildPoints ( $CurPlanet );
$TBuildCount += $Points['BuildCount'];
$GCount += $Points['BuildCount'];
$PlanetPoints = ($Points['BuildPoint'] / $gameConfig['stat_settings']);
$TBuildPoints += ($Points['BuildPoint'] / $gameConfig['stat_settings']);
$Points = GetDefensePoints ( $CurPlanet );
$TDefsCount += $Points['DefenseCount'];;
$GCount += $Points['DefenseCount'];
$PlanetPoints += ($Points['DefensePoint'] / $gameConfig['stat_settings']);
$TDefsPoints += ($Points['DefensePoint'] / $gameConfig['stat_settings']);
$Points = GetFleetPoints ( $CurPlanet );
$TFleetCount += $Points['FleetCount'];
$GCount += $Points['FleetCount'];
$PlanetPoints += ($Points['FleetPoint'] / $gameConfig['stat_settings']);
$TFleetPoints += ($Points['FleetPoint'] / $gameConfig['stat_settings']);
$GPoints += $PlanetPoints;
$QryUpdatePlanet = "UPDATE {{table}} SET ";
$QryUpdatePlanet .= "`points` = '". $PlanetPoints ."' ";
$QryUpdatePlanet .= "WHERE ";
$QryUpdatePlanet .= "`id` = '". $CurPlanet['id'] ."';";
doquery ( $QryUpdatePlanet , 'planets');
}
$QryInsertStats = "INSERT INTO {{table}} SET ";
$QryInsertStats .= "`id_owner` = '". $CurUser['id'] ."', ";
$QryInsertStats .= "`id_ally` = '". $CurUser['ally_id'] ."', ";
$QryInsertStats .= "`stat_type` = '1', "; // 1 pour joueur , 2 pour alliance
$QryInsertStats .= "`stat_code` = '1', "; // de 1 a 2 mis a jour de maniere automatique
$QryInsertStats .= "`tech_points` = '". $TTechPoints ."', ";
$QryInsertStats .= "`tech_count` = '". $TTechCount ."', ";
$QryInsertStats .= "`tech_old_rank` = '". $OldTechRank ."', ";
$QryInsertStats .= "`build_points` = '". $TBuildPoints ."', ";
$QryInsertStats .= "`build_count` = '". $TBuildCount ."', ";
$QryInsertStats .= "`build_old_rank` = '". $OldBuildRank ."', ";
$QryInsertStats .= "`defs_points` = '". $TDefsPoints ."', ";
$QryInsertStats .= "`defs_count` = '". $TDefsCount ."', ";
$QryInsertStats .= "`defs_old_rank` = '". $OldDefsRank ."', ";
$QryInsertStats .= "`fleet_points` = '". $TFleetPoints ."', ";
$QryInsertStats .= "`fleet_count` = '". $TFleetCount ."', ";
$QryInsertStats .= "`fleet_old_rank` = '". $OldFleetRank ."', ";
$QryInsertStats .= "`total_points` = '". $GPoints ."', ";
$QryInsertStats .= "`total_count` = '". $GCount ."', ";
$QryInsertStats .= "`total_old_rank` = '". $OldTotalRank ."', ";
$QryInsertStats .= "`stat_date` = '". $StatDate ."';";
doquery ( $QryInsertStats , 'statpoints');
}
$Rank = 1;
$RankQry = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' ORDER BY `tech_points` DESC;", 'statpoints');
while ($TheRank = mysql_fetch_assoc($RankQry) ) {
$QryUpdateStats = "UPDATE {{table}} SET ";
$QryUpdateStats .= "`tech_rank` = '". $Rank ."' ";
$QryUpdateStats .= "WHERE ";
$QryUpdateStats .= " `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $TheRank['id_owner'] ."';";
doquery ( $QryUpdateStats , 'statpoints');
$Rank++;
}
$Rank = 1;
$RankQry = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' ORDER BY `build_points` DESC;", 'statpoints');
while ($TheRank = mysql_fetch_assoc($RankQry) ) {
$QryUpdateStats = "UPDATE {{table}} SET ";
$QryUpdateStats .= "`build_rank` = '". $Rank ."' ";
$QryUpdateStats .= "WHERE ";
$QryUpdateStats .= " `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $TheRank['id_owner'] ."';";
doquery ( $QryUpdateStats , 'statpoints');
$Rank++;
}
$Rank = 1;
$RankQry = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' ORDER BY `defs_points` DESC;", 'statpoints');
while ($TheRank = mysql_fetch_assoc($RankQry) ) {
$QryUpdateStats = "UPDATE {{table}} SET ";
$QryUpdateStats .= "`defs_rank` = '". $Rank ."' ";
$QryUpdateStats .= "WHERE ";
$QryUpdateStats .= " `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $TheRank['id_owner'] ."';";
doquery ( $QryUpdateStats , 'statpoints');
$Rank++;
}
$Rank = 1;
$RankQry = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' ORDER BY `fleet_points` DESC;", 'statpoints');
while ($TheRank = mysql_fetch_assoc($RankQry) ) {
$QryUpdateStats = "UPDATE {{table}} SET ";
$QryUpdateStats .= "`fleet_rank` = '". $Rank ."' ";
$QryUpdateStats .= "WHERE ";
$QryUpdateStats .= " `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $TheRank['id_owner'] ."';";
doquery ( $QryUpdateStats , 'statpoints');
$Rank++;
}
$Rank = 1;
$RankQry = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' ORDER BY `total_points` DESC;", 'statpoints');
while ($TheRank = mysql_fetch_assoc($RankQry) ) {
$QryUpdateStats = "UPDATE {{table}} SET ";
$QryUpdateStats .= "`total_rank` = '". $Rank ."' ";
$QryUpdateStats .= "WHERE ";
$QryUpdateStats .= " `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $TheRank['id_owner'] ."';";
doquery ( $QryUpdateStats , 'statpoints');
$Rank++;
}
// Statistiques des alliances ...
$GameAllys = doquery("SELECT * FROM {{table}}", 'alliance');
while ($CurAlly = mysql_fetch_assoc($GameAllys)) {
// Recuperation des anciennes statistiques
$OldStatRecord = doquery ("SELECT * FROM {{table}} WHERE `stat_type` = '2' AND `id_owner` = '".$CurAlly['id']."';",'statpoints');
if ($OldStatRecord) {
$OldTotalRank = $OldStatRecord['total_rank'];
$OldTechRank = $OldStatRecord['tech_rank'];
$OldBuildRank = $OldStatRecord['build_rank'];
$OldDefsRank = $OldStatRecord['defs_rank'];
$OldFleetRank = $OldStatRecord['fleet_rank'];
// Suppression de l'ancien enregistrement
doquery ("DELETE FROM {{table}} WHERE `stat_type` = '2' AND `id_owner` = '".$CurAlly['id']."';",'statpoints');
} else {
$OldTotalRank = 0;
$OldTechRank = 0;
$OldBuildRank = 0;
$OldDefsRank = 0;
$OldFleetRank = 0;
}
// Total des unitées consommée pour la recherche
$QrySumSelect = "SELECT ";
$QrySumSelect .= "SUM(`tech_points`) as `TechPoint`, ";
$QrySumSelect .= "SUM(`tech_count`) as `TechCount`, ";
$QrySumSelect .= "SUM(`build_points`) as `BuildPoint`, ";
$QrySumSelect .= "SUM(`build_count`) as `BuildCount`, ";
$QrySumSelect .= "SUM(`defs_points`) as `DefsPoint`, ";
$QrySumSelect .= "SUM(`defs_count`) as `DefsCount`, ";
$QrySumSelect .= "SUM(`fleet_points`) as `FleetPoint`, ";
$QrySumSelect .= "SUM(`fleet_count`) as `FleetCount`, ";
$QrySumSelect .= "SUM(`total_points`) as `TotalPoint`, ";
$QrySumSelect .= "SUM(`total_count`) as `TotalCount` ";
$QrySumSelect .= "FROM {{table}} ";
$QrySumSelect .= "WHERE ";
$QrySumSelect .= "`stat_type` = '1' AND ";
$QrySumSelect .= "`id_ally` = '". $CurAlly['id'] ."';";
$Points = doquery( $QrySumSelect, 'statpoints', true);
$TTechCount = $Points['TechCount'];
$TTechPoints = $Points['TechPoint'];
$TBuildCount = $Points['BuildCount'];
$TBuildPoints = $Points['BuildPoint'];
$TDefsCount = $Points['DefsCount'];
$TDefsPoints = $Points['DefsPoint'];
$TFleetCount = $Points['FleetCount'];
$TFleetPoints = $Points['FleetPoint'];
$GCount = $Points['TotalCount'];
$GPoints = $Points['TotalPoint'];
$QryInsertStats = "INSERT INTO {{table}} SET ";
$QryInsertStats .= "`id_owner` = '". $CurAlly['id'] ."', ";
$QryInsertStats .= "`id_ally` = '0', ";
$QryInsertStats .= "`stat_type` = '2', "; // 1 pour joueur , 2 pour alliance
$QryInsertStats .= "`stat_code` = '1', "; // de 1 a 5 mis a jour de maniere automatique
$QryInsertStats .= "`tech_points` = '". $TTechPoints ."', ";
$QryInsertStats .= "`tech_count` = '". $TTechCount ."', ";
$QryInsertStats .= "`tech_old_rank` = '". $OldTechRank ."', ";
$QryInsertStats .= "`build_points` = '". $TBuildPoints ."', ";
$QryInsertStats .= "`build_count` = '". $TBuildCount ."', ";
$QryInsertStats .= "`build_old_rank` = '". $OldBuildRank ."', ";
$QryInsertStats .= "`defs_points` = '". $TDefsPoints ."', ";
$QryInsertStats .= "`defs_count` = '". $TDefsCount ."', ";
$QryInsertStats .= "`defs_old_rank` = '". $OldDefsRank ."', ";
$QryInsertStats .= "`fleet_points` = '". $TFleetPoints ."', ";
$QryInsertStats .= "`fleet_count` = '". $TFleetCount ."', ";
$QryInsertStats .= "`fleet_old_rank` = '". $OldFleetRank ."', ";
$QryInsertStats .= "`total_points` = '". $GPoints ."', ";
$QryInsertStats .= "`total_count` = '". $GCount ."', ";
$QryInsertStats .= "`total_old_rank` = '". $OldTotalRank ."', ";
$QryInsertStats .= "`stat_date` = '". $StatDate ."';";
doquery ( $QryInsertStats , 'statpoints');
}
AdminMessage ( $lang['adm_done'], $lang['adm_stat_title'] );
} else {
AdminMessage ( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
}