diviner.timeout.class.php 3.86 KB
Newer Older
maryam's avatar
done  
maryam committed
1
2
3
4
5
6
7
8
<?php

class diviner_timeout
{
	private $mode = '';
	
	private $user = '';
	private $diviner = '';
David's avatar
David committed
9
10
	private $devinName='';
	private $oracle = '';
maryam's avatar
done  
maryam committed
11
12
13

	private $previousSGO = 0;
	private $previousSO = 0;
David's avatar
David committed
14

maryam's avatar
done  
maryam committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	
	private $res = '';
	private $reussie ='non';


	public function set_mode($mode)
	{
		$this->mode = $mode;
	}

	public function process()
	{
		if ( $this->init() )
        {
            $this->carte_et_scoreOracle();
            $this->updateparties();
            return $this->display();
        }
        return false;
	}

	private function init()
	{
		//récupération des informations de base : userid
		$this->user = user::getInstance();
		$this->diviner = $this->user->id;	
David's avatar
David committed
41
42
43
44
		$this->devinName = $this->user->username;
		$this->userlvl = userlvl::getInstance();
		$this->points= $this->userlvl->get_points();

maryam's avatar
done  
maryam committed
45
46
47
48
49
50

		return true;
	}

	private function carte_et_scoreOracle()
	{
David's avatar
David committed
51
52
		include('./sys/load_iso.php');
		require_once('./controllers/update_score_coeff.php');
maryam's avatar
done  
maryam committed
53

David's avatar
David committed
54
55
56
57
		if(!isset($_SESSION["timeOutOracle"])){
			// récupération d'enregistrementID pour récupérer l'id de l'Oracle et l'id de la carte
			//connexion à la BD
			$db = db::getInstance();
maryam's avatar
done  
maryam committed
58
			
David's avatar
David committed
59
60
61
62
63
64
65
66
67
68
			//Récupération de enregistrementID
			$sql = 'SELECT enregistrementID FROM parties WHERE idDevin="'.$this->diviner.'" ORDER BY tpsDevin DESC LIMIT 1 ';
	        $res1=$db->query($sql); 
	        $this->res2= mysqli_fetch_assoc($res1);
	        
	       // récupération de l'id de l'oracle et de la carte grâce à enregistrementID
			$sql = 'SELECT idOracle,carteID,OracleLang
	                    FROM enregistrement WHERE enregistrementID='.$this->res2['enregistrementID'].'';	
	        $res1=$db->query($sql); 
	        $res3= mysqli_fetch_assoc($res1);
maryam's avatar
done  
maryam committed
69

David's avatar
David committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	        $this->oracle = $res3['idOracle']; 
	        
			// récupération du contenu de la carte avec carteID
	    	$sql = 'SELECT carteID,niveau,mot,tabou1,tabou2,tabou3,tabou4,tabou5 FROM carte WHERE carteID="'.$res3['carteID'].'"';
	        $res4=$db->query($sql); 
	        $this->res= mysqli_fetch_assoc($res4);
			
		// Requête de modification des scores de l'Oracle qui a fait une description non trouvée par le devin
		
			updateScoreOracleDevinEchec($this->oracle,$iso[$res3["OracleLang"]],$this->res2['enregistrementID']);
			
//~ 			//récupération du score précédent;
//~ 			$sql = 'SELECT `scoreGlobal`,`scoreOracle` FROM `score` WHERE `userid`="'.$this->oracle.'" AND langue="'.$iso[$res3["OracleLang"]].'"';
//~ 			$result=$db->query($sql);
//~ 			$res5= mysqli_fetch_assoc($result);

//~ 			$this->previousSGO= $res5['scoreGlobal'];
//~ 			$this->previousSO= $res5['scoreOracle'];
//~ 			
//~ 			//maj des variables de scores: le score ne doit jamais être négatif.
//~ 			$points = $this->points*0.5;
//~ 			$_SESSION["pointsCoef"] = $points;
//~ 			
//~ 			if($this->previousSO >= $points)
//~ 			{
//~ 				$this->previousSGO = $this->previousSGO - $points;
//~ 				$this->previousSO = $this->previousSO - $points;
//~ 			}

//~ 			//maj du score dans la BD
//~ 			$sql = 'UPDATE score 
//~ 					SET  scoreGlobal='.$db->escape((string) $this->previousSGO) . ', ' .
//~ 					'scoreOracle='.$db->escape((string) $this->previousSO) . '
//~ 					WHERE userid='.$this->oracle.' AND langue="'.$iso[$res3["OracleLang"]].'"';
//~ 					
//~ 			$db->query($sql);
			$_SESSION["timeOutOracle"]=true;

			return false;
		}
		else{
			header('Location: index.php?page.home.html');    
			return false;  
		}
	}
maryam's avatar
done  
maryam committed
115
116
117
118
119
120
121
122
123
124

	private function updateparties()
	{
		// Requête de mise à jour de la table partie
			$db = db::getInstance();
			$sql = 'UPDATE parties 
					SET  reussie='.$db->escape((string) $this->reussie).'
					WHERE idDevin='.$this->diviner.' ORDER BY tpsDevin DESC LIMIT 1 ';
					
			$db->query($sql);
David's avatar
David committed
125
			$_SESSION["notif"]["notification_error"]["Devin"] = 'diviner_timeout';	
maryam's avatar
done  
maryam committed
126
127
128
129
130
131
132
133
134
135
136
		return false;
	}

	private function display()
	{
		include('./views/diviner.timeout.html');
        return true;
	}
}

?>