-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtmlManager.php
executable file
·138 lines (120 loc) · 2.47 KB
/
htmlManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* This file contains the html manager class, this is the class
* responsible for setting up all the values for the page templates
*
* author: Jeffrey Minton <[email protected]>
* version: 1.0
*/
require_once 'Savant3.php';
/**
* htmlManager class, responsible for setting up values for and
* displaying templates
*/
class htmlManager
{
/**
* class member
* the savant3 template object
*/
private $tpl = null;
/**
* Constructor
* sets up the savant object and the path to the templates
*/
function __construct()
{
$this->tpl = new Savant3();
$this->tpl->vals = array();
$this->tpl->addPath('template', '/var/www/diplomacy_online/html/');
}
/**
* show the main template page which contains calls to all
* other templates needed to be displayed
*/
function showPage()//read and display the header.html file
{
$this->tpl->display("html/main.tpl.php");
}
/**
* Put values into the vals dictionary, if maplist or country
* is sent, generate javascript for it
*/
function setVal($key, $value)
{
//array_push($this->tpl->vals, $key=>$value);
if($key == "maplist")
{
$value = $this->genMapJS($value);
}
if($key == "countries")
{
$value = $this->genCountJS($value);
}
if($key == "page")
{
$value = $value . ".tpl.php";
}
$this->tpl->vals[$key] = $value;
}
/**
* Generate the javascript code for the array mapping
* player name to country
*/
function genCountJS($countries)
{
$array = "var countries = {";
$first = true;
foreach($countries as $cid => $country)
{
if($first == true)
{
$first = false;
}
else
{
$array = $array . ", ";
}
//echo $cid . ": " . $country . "<br/>";
$array = $array . "'$cid':'$country'";
}
$array = $array . "};";
//echo $array;
return $array;
}
/**
* generate the js code for the array that represents the
* current map
*/
function genMapJS($map)
{
$array = "var currMap = {";
$first = true;
foreach($map as $cid => $ownedArr)
{
if($first == true)
{
$first = false;
}
else
{
$array = $array . ", ";
}
$array = $array . "'$cid':[";
for($i = 0; $i < count($ownedArr); $i++)
{
$type = $ownedArr[$i]['type'];
$aid = $ownedArr[$i]['aid'];
$array = $array . "{'type':'$type', 'aid':'$aid'}";
if($i < count($ownedArr) - 1)
{
$array = $array . ", ";
}
}
$array = $array . "]";
}
$array = $array . "};";
return $array;
}
}
?>