2009-11-01 11:00:00 +00:00
< ? php
//Gestion des dépendances
2020-11-15 15:12:32 +00:00
include_once ( " Class/tinyasteroide.php " );
2009-11-01 11:00:00 +00:00
/***************************************************************************
* class . user . php
* ----------------
* begin : Dimanche 7 septembre 2008
* update : Vendredi 27 février 2009
* email : nemunaire @ gmail . com
*
*
***************************************************************************/
class User {
var $id_user ,
$pseudo ,
$auth_level ,
2020-11-15 15:12:32 +00:00
$options ,
2009-11-01 11:00:00 +00:00
$race ,
$alliance ,
$id_alliance ,
$id_grade_alliance ,
2020-11-15 15:12:30 +00:00
$permissions_alliance ,
2009-11-01 11:00:00 +00:00
$mv ,
$mail ,
$envoyerMail ,
$last_visite ,
$points ,
$place_points ,
$technologies = array (),
$credits ,
$politique ,
$politique_lastchange ,
$destinationsFavoris ,
$amis = array (),
$combatAT_tactique ,
$combatDE_tactique ,
$modifUser = array ();
/**
* Constructeur
* @ param int $id id de la planète à importer
*
* @ return void
* @ access public
*/
function User ( $id = 0 ){
if ( ! empty ( $id )) {
2020-11-15 15:12:30 +00:00
global $technologiesVAR , $table_user ;
2009-11-01 11:00:00 +00:00
$bdd = new bdd ();
$bdd -> escape ( $id );
$user = $bdd -> unique_query ( " SELECT * FROM $table_user WHERE id = $id ; " );
$bdd -> deconnexion ();
if ( ! empty ( $user )) {
$this -> id_user = $user [ " id " ];
$this -> pseudo = $user [ " pseudo " ];
$this -> auth_level = $user [ " auth_level " ];
$this -> race = $user [ " race " ];
2020-11-15 15:12:32 +00:00
$this -> options = intval ( $user [ " options " ]);
2009-11-01 11:00:00 +00:00
$this -> mv = $user [ " mv " ];
$this -> id_alliance = $user [ " id_alliance " ];
$this -> id_grade_alliance = $user [ " id_grade_alliance " ];
$this -> mail = $user [ " mail " ];
$this -> envoyerMail = $user [ " envoyerMail " ];
$this -> last_visite = $user [ " last_visite " ];
$this -> points = $user [ " points " ];
$this -> place_points = $user [ " place_points " ];
$this -> credits = $user [ " credits " ];
$this -> politique = $user [ " politique " ];
$this -> politique_lastchange = $user [ " politique_lastchange " ];
if ( ! empty ( $user [ " amis " ])) $this -> amis = unserialize ( $user [ " amis " ]);
else $this -> amis = array ();
if ( ! empty ( $user [ " destinationsFavoris " ])) $this -> destinationsFavoris = unserialize ( $user [ " destinationsFavoris " ]);
else $this -> destinationsFavoris = array ();
$this -> combatAT_tactique = $user [ " combatAT_tactique " ];
$this -> combatDE_tactique = $user [ " combatDE_tactique " ];
foreach ( $technologiesVAR as $tech ){
2020-11-15 15:12:32 +00:00
$this -> technologies [] = intval ( $user [ $tech ]);
2009-11-01 11:00:00 +00:00
}
//Si l'ID d'alliance est défini, on charge l'alliance
if ( ! empty ( $this -> id_alliance ))
$this -> alliance = new TinyAsteroide ( $this -> id_alliance );
}
else die ( 'Erreur #01 : Utilisateur recherché introuvable dans la base de données. Contactez le support technique (' . $config [ 'mail_support' ] . ') au plus vite en précisant le code d\'erreur.' );
}
}
2020-11-15 15:12:30 +00:00
function loadPermissions ( $fondateur = 0 )
2020-11-15 15:12:32 +00:00
{
if ( $fondateur == $this -> id_user )
$this -> permissions_alliance = 1023 ;
else
2020-11-15 15:12:30 +00:00
{
2020-11-15 15:12:32 +00:00
global $table_alliances_grade ;
$bdd = new BDD ();
$grade = $bdd -> unique_query ( " SELECT * FROM $table_alliances_grade WHERE id = " . $this -> id_grade_alliance . " ; " );
$bdd -> deconnexion ();
2020-11-15 15:12:30 +00:00
2020-11-15 15:12:32 +00:00
$this -> permissions_alliance = intval ( $grade [ 'auth' ]);
2020-11-15 15:12:30 +00:00
}
2020-11-15 15:12:32 +00:00
}
2020-11-15 15:12:30 +00:00
2020-11-15 15:12:32 +00:00
function addPoints ( $metal , $cristal , $hydrogene , $credits = 0 , $demolition = false )
{
global $table_bourse_ressources ;
//On charge les 3 valeurs boursières
$bdd = new BDD ();
$bourse = $bdd -> query ( " SELECT dispo FROM $table_bourse_ressources ; " );
$bdd -> deconnexion ();
2009-11-01 11:00:00 +00:00
2020-11-15 15:12:32 +00:00
if ( ! empty ( $credits ))
{
//TODO Equivalence non prouvée entre $credits/bourse_calcPrixBase($bourse[0]["dispo"], 0.7); et $credits/bourse_calcPrixBase($bourse[0]["dispo"], 1) * 0.7; dans le but de ne donner que 70% des points
$metal += $credits / bourse_calcPrixBase ( $bourse [ 0 ][ " dispo " ], 0.7 );
$cristal += $credits / bourse_calcPrixBase ( $bourse [ 1 ][ " dispo " ], 0.7 );
$hydrogene += $credits / bourse_calcPrixBase ( $bourse [ 2 ][ " dispo " ], 0.7 );
2009-11-01 11:00:00 +00:00
}
2020-11-15 15:12:32 +00:00
$points = bourse_calcPrixBase ( $bourse [ 0 ][ " dispo " ], $metal );
$points += bourse_calcPrixBase ( $bourse [ 1 ][ " dispo " ], $cristal );
$points += bourse_calcPrixBase ( $bourse [ 2 ][ " dispo " ], $hydrogene );
if ( $demolition )
$this -> points -= intval ( $points );
else
$this -> points += intval ( $points );
$this -> addModifUser ( " points " );
}
function addCredits ( $credits )
{
$this -> credits += $credits ;
$this -> addModifUser ( " credits " );
return 0 ;
}
2009-11-01 11:00:00 +00:00
function addModifUser ( $modif )
2020-11-15 15:12:32 +00:00
{
if ( ! in_array ( $modif , $this -> modifUser ))
$this -> modifUser [] = $modif ;
}
2009-11-01 11:00:00 +00:00
/**
* Destructeur
*
* @ return void
* @ access public
*/
function __destruct (){
2020-11-15 15:12:32 +00:00
global $table_user ;
2009-11-01 11:00:00 +00:00
$out = array ();
2020-11-15 15:12:32 +00:00
$bdd = new BDD ();
2009-11-01 11:00:00 +00:00
foreach ( $this -> modifUser as $key => $modif )
2020-11-15 15:12:32 +00:00
{
//On gère les champs variables tableaux
if ( is_array ( $modif ))
2009-11-01 11:00:00 +00:00
{
2020-11-15 15:12:32 +00:00
$calc = dDonnees :: nameVAR ( $modif [ 0 ]);
if ( ! isset ( $ { $calc . 'VAR' }))
global $ { $calc . 'VAR' };
if ( empty ( $ { $calc . 'VAR' }))
trigger_error ( 'Impossible de trouver les données pour ' . $modif [ 0 ], E_USER_ERROR );
$out [] = $ { $calc . 'VAR' }[ $modif [ 1 ]] . " = " . $this -> { $modif [ 0 ]}[ $modif [ 1 ]];
}
elseif ( $modif == " force " )
$out [] = " " ;
elseif ( ! is_array ( $this -> { $modif }))
{
$bdd -> escape ( $this -> { $modif });
if ( is_int ( $this -> { $modif }) || is_float ( $this -> { $modif })) $out [] .= $modif . " = " . $this -> { $modif };
else $out [] .= $modif . " = ' " . $this -> { $modif } . " ' " ;
}
else
{
if ( $modif != " coeff_bat " && $modif != " vaisseaux " && $modif != " terrestres " && $modif != " casernes " && $modif != " technologies " && $modif != " batiments " )
{
$prep = serialize ( $this -> { $modif });
$bdd -> escape ( $prep );
$out [] = $modif . " = ' $prep ' " ;
}
2009-11-01 11:00:00 +00:00
else
2020-11-15 15:12:32 +00:00
{
$calc = dDonnees :: nameVAR ( $modif );
if ( ! isset ( $ { $calc . 'VAR' }))
global $ { $calc . 'VAR' };
foreach ( $this -> { $modif } as $j => $value )
$out [] = $ { $calc . 'VAR' }[ $j ] . " = " . $value ;
}
2009-11-01 11:00:00 +00:00
}
2020-11-15 15:12:32 +00:00
}
2009-11-01 11:00:00 +00:00
if ( ! empty ( $out ))
{
$sql = " UPDATE $table_user SET " . implode ( ', ' , $out ) . " WHERE id = " . $this -> id_user . " ; " ;
2020-11-15 15:12:32 +00:00
if ( DEBUG )
echo '<br /><br />' . $sql ;
2009-11-01 11:00:00 +00:00
$bdd -> query ( $sql );
2020-11-15 15:12:32 +00:00
if ( $bdd -> affected () != 1 )
elog ( $bdd -> affected () . " champ(s) affecté(s) par la requête du fichier " . __FILE__ . " à la ligne " . __LINE__ . " , données : out = " . serialize ( $out ) . " avec l'ID " . $this -> id_user , 2 );
2009-11-01 11:00:00 +00:00
}
$bdd -> deconnexion ();
}
}
?>