Issues (1839)

html/inc/countries.inc (2 issues)

1
<?php
2
// This file is part of BOINC.
3
// http://boinc.berkeley.edu
4
// Copyright (C) 2017 University of California
5
//
6
// BOINC is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License
8
// as published by the Free Software Foundation,
9
// either version 3 of the License, or (at your option) any later version.
10
//
11
// BOINC is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
// See the GNU Lesser General Public License for more details.
15
//
16
// You should have received a copy of the GNU Lesser General Public License
17
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
// $Id$
19
20
21
// list of countries taken from http://www.cia.gov
22
23
global $countries;
24
$countries = array(
25
    "None",
26
    "International",
27
    "Afghanistan",
28
    "Albania",
29
    "Algeria",
30
    "American Samoa",
31
    "Andorra",
32
    "Angola",
33
    "Anguilla",
34
    "Antarctica",
35
    "Antigua and Barbuda",
36
    "Argentina",
37
    "Armenia",
38
    "Aruba",
39
    "Australia",
40
    "Austria",
41
    "Azerbaijan",
42
    "Bahamas, The",
43
    "Bahrain",
44
    "Bangladesh",
45
    "Barbados",
46
    "Belarus",
47
    "Belgium",
48
    "Belize",
49
    "Benin",
50
    "Bermuda",
51
    "Bhutan",
52
    "Bolivia",
53
    "Bosnia and Herzegovina",
54
    "Botswana",
55
    "Brazil",
56
    "British Virgin Islands",
57
    "Brunei",
58
    "Bulgaria",
59
    "Burkina Faso",
60
    "Burma",
61
    "Burundi",
62
    "Cambodia",
63
    "Cameroon",
64
    "Canada",
65
    "Cape Verde",
66
    "Cayman Islands",
67
    "Central African Republic",
68
    "Chad",
69
    "Channel Islands",
70
    "Chile",
71
    "China",
72
    "Colombia",
73
    "Comoros",
74
    "Congo, Democratic Republic of the",
75
    "Congo, Republic of the",
76
    "Cook Islands",
77
    "Costa Rica",
78
    "Cote d'Ivoire",
79
    "Croatia",
80
    "Cuba",
81
    "Cyprus",
82
    "Czech Republic",
83
    "Denmark",
84
    "Djibouti",
85
    "Dominica",
86
    "Dominican Republic",
87
    "East Timor",
88
    "Ecuador",
89
    "Egypt",
90
    "El Salvador",
91
    "Equatorial Guinea",
92
    "Eritrea",
93
    "Estonia",
94
    "Ethiopia",
95
    "Falkland Islands",
96
    "Faroe Islands",
97
    "Fiji",
98
    "Finland",
99
    "France",
100
    "French Guiana",
101
    "French Polynesia",
102
    "Gabon",
103
    "Gambia, The",
104
    "Gaza Strip",
105
    "Georgia",
106
    "Germany",
107
    "Ghana",
108
    "Gibraltar",
109
    "Greece",
110
    "Greenland",
111
    "Grenada",
112
    "Guadeloupe",
113
    "Guam",
114
    "Guatemala",
115
    "Guinea",
116
    "Guinea-Bissau",
117
    "Guyana",
118
    "Haiti",
119
    "Holy See (Vatican City)",
120
    "Honduras",
121
    "Hong Kong",
122
    "Hungary",
123
    "Iceland",
124
    "India",
125
    "Indonesia",
126
    "Iran",
127
    "Iraq",
128
    "Ireland",
129
    "Isle of Man",
130
    "Israel",
131
    "Italy",
132
    "Jamaica",
133
    "Japan",
134
    "Jordan",
135
    "Kazakhstan",
136
    "Korea, North",
137
    "Korea, South",
138
    "Kenya",
139
    "Kiribati",
140
    "Kuwait",
141
    "Kyrgyzstan",
142
    "Laos",
143
    "Latvia",
144
    "Lebanon",
145
    "Lesotho",
146
    "Liberia",
147
    "Libya",
148
    "Liechtenstein",
149
    "Lithuania",
150
    "Luxembourg",
151
    "Macau",
152
    "Macedonia",
153
    "Madagascar",
154
    "Malawi",
155
    "Malaysia",
156
    "Maldives",
157
    "Mali",
158
    "Malta",
159
    "Marshall Islands",
160
    "Martinique",
161
    "Mauritania",
162
    "Mauritius",
163
    "Mexico",
164
    "Micronesia",
165
    "Moldova",
166
    "Monaco",
167
    "Mongolia",
168
    "Montenegro",
169
    "Montserrat",
170
    "Morocco",
171
    "Mozambique",
172
    "Namibia",
173
    "Nauru",
174
    "Nepal",
175
    "Netherlands",
176
    "Netherlands Antilles",
177
    "New Caledonia",
178
    "New Zealand",
179
    "Nicaragua",
180
    "Niger",
181
    "Nigeria",
182
    "Niue",
183
    "Northern Mariana Islands",
184
    "Norway",
185
    "Oman",
186
    "Pakistan",
187
    "Palau",
188
    "Panama",
189
    "Papua New Guinea",
190
    "Paraguay",
191
    "Peru",
192
    "Philippines",
193
    "Pitcairn Islands",
194
    "Poland",
195
    "Portugal",
196
    "Puerto Rico",
197
    "Qatar",
198
    "Reunion",
199
    "Romania",
200
    "Russia",
201
    "Rwanda",
202
    "Saint Kitts and Nevis",
203
    "Saint Lucia",
204
    "Saint Pierre and Miquelon",
205
    "Saint Vincent and the Grenadines",
206
    "Samoa",
207
    "San Marino",
208
    "Sao Tome and Principe",
209
    "Saudi Arabia",
210
    "Senegal",
211
    "Serbia",
212
    "Seychelles",
213
    "Sierra Leone",
214
    "Singapore",
215
    "Slovakia",
216
    "Slovenia",
217
    "Solomon Islands",
218
    "Somalia",
219
    "South Africa",
220
    "Spain",
221
    "Sri Lanka",
222
    "Sudan",
223
    "Suriname",
224
    "Swaziland",
225
    "Sweden",
226
    "Switzerland",
227
    "Syria",
228
    "Taiwan",
229
    "Tajikistan",
230
    "Tanzania",
231
    "Thailand",
232
    "Togo",
233
    "Tokelau",
234
    "Tonga",
235
    "Trinidad and Tobago",
236
    "Tunisia",
237
    "Turkey",
238
    "Turkmenistan",
239
    "Turks and Caicos Islands",
240
    "Tuvalu",
241
    "Uganda",
242
    "Ukraine",
243
    "United Arab Emirates",
244
    "United Kingdom",
245
    "United States",
246
    "Uruguay",
247
    "Uzbekistan",
248
    "Vanuatu",
249
    "Venezuela",
250
    "Vietnam",
251
    "Virgin Islands",
252
    "Wallis and Futuna",
253
    "West Bank",
254
    "Western Sahara",
255
    "Yemen",
256
    "Zambia",
257
    "Zimbabwe"
258
);
259
260
$country_to_iso3166_2 = array (
0 ignored issues
show
There must be no space between the "array" keyword and the opening parenthesis
Loading history...
261
    "Afghanistan" => "af",
262
    "Albania" => "al",
263
    "Algeria" => "dz",
264
    "American Samoa" => "as",
265
    "Andorra" => "ad",
266
    "Angola" => "ao",
267
    "Anguilla" => "ai",
268
    "Antarctica" => "aq",
269
    "Antigua and Barbuda" => "ag",
270
    "Argentina" => "ar",
271
    "Armenia" => "am",
272
    "Aruba" => "aw",
273
    "Australia" => "au",
274
    "Austria" => "at",
275
    "Azerbaijan" => "az",
276
    "Bahamas, The" => "bs",
277
    "Bahrain" => "bh",
278
    "Bangladesh" => "bd",
279
    "Barbados" => "bb",
280
    "Belarus" => "by",
281
    "Belgium" => "be",
282
    "Belize" => "bz",
283
    "Benin" => "bj",
284
    "Bermuda" => "bm",
285
    "Bhutan" => "bt",
286
    "Bolivia" => "bo",
287
    "Bosnia and Herzegovina" => "ba",
288
    "Botswana" => "bw",
289
    "Brazil" => "br",
290
    "British Virgin Islands" => "vg",
291
    "Brunei" => "bn",
292
    "Bulgaria" => "bg",
293
    "Burkina Faso" => "bf",
294
    "Burma" => "mm",
295
    "Burundi" => "bi",
296
    "Cambodia" => "kh",
297
    "Cameroon" => "cm",
298
    "Canada" => "ca",
299
    "Cape Verde" => "cv",
300
    "Cayman Islands" => "ky",
301
    "Central African Republic" => "cf",
302
    "Chad" => "td",
303
    "Channel Islands" => "gb",
304
    "Chile" => "cl",
305
    "China" => "cn",
306
    "Colombia" => "co",
307
    "Comoros" => "km",
308
    "Congo, Democratic Republic of the" => "cd",
309
    "Congo, Republic of the" => "cg",
310
    "Cook Islands" => "ck",
311
    "Costa Rica" => "cr",
312
    "Cote d'Ivoire" => "ci",
313
    "Croatia" => "hr",
314
    "Cuba" => "cu",
315
    "Cyprus" => "cy",
316
    "Czech Republic" => "cz",
317
    "Denmark" => "dk",
318
    "Djibouti" => "dj",
319
    "Dominica" => "dm",
320
    "Dominican Republic" => "do",
321
    "East Timor" => "tl",
322
    "Ecuador" => "ec",
323
    "Egypt" => "eg",
324
    "El Salvador" => "sv",
325
    "Equatorial Guinea" => "gq",
326
    "Eritrea" => "er",
327
    "Estonia" => "ee",
328
    "Ethiopia" => "et",
329
    "Falkland Islands" => "fk",
330
    "Faroe Islands" => "fo",
331
    "Fiji" => "fj",
332
    "Finland" => "fi",
333
    "France" => "fr",
334
    "French Guiana" => "gf",
335
    "French Polynesia" => "pf",
336
    "Gabon" => "ga",
337
    "Gambia, The" => "gm",
338
    "Gaza Strip" => "ps",
339
    "Georgia" => "ge",
340
    "Germany" => "de",
341
    "Ghana" => "gh",
342
    "Gibraltar" => "gi",
343
    "Greece" => "gr",
344
    "Greenland" => "gl",
345
    "Grenada" => "gd",
346
    "Guadeloupe" => "gp",
347
    "Guam" => "gu",
348
    "Guatemala" => "gt",
349
    "Guinea" => "gn",
350
    "Guinea-Bissau" => "gw",
351
    "Guyana" => "gy",
352
    "Haiti" => "ht",
353
    "Holy See (Vatican City)" => "va",
354
    "Honduras" => "hn",
355
    "Hong Kong" => "hk",
356
    "Hungary" => "hu",
357
    "Iceland" => "is",
358
    "India" => "in",
359
    "Indonesia" => "id",
360
    "Iran" => "ir",
361
    "Iraq" => "iq",
362
    "Ireland" => "ie",
363
    "Isle of Man" => "im",
364
    "Israel" => "il",
365
    "Italy" => "it",
366
    "Jamaica" => "jm",
367
    "Japan" => "jp",
368
    "Jordan" => "jo",
369
    "Kazakhstan" => "kz",
370
    "Korea, North" => "kp",
371
    "Korea, South" => "kr",
372
    "Kenya" => "ke",
373
    "Kiribati" => "ki",
374
    "Kuwait" => "kw",
375
    "Kyrgyzstan" => "kg",
376
    "Laos" => "la",
377
    "Latvia" => "lv",
378
    "Lebanon" => "lb",
379
    "Lesotho" => "ls",
380
    "Liberia" => "lr",
381
    "Libya" => "ly",
382
    "Liechtenstein" => "li",
383
    "Lithuania" => "lt",
384
    "Luxembourg" => "lu",
385
    "Macau" => "mo",
386
    "Macedonia" => "mk",
387
    "Madagascar" => "mg",
388
    "Malawi" => "mw",
389
    "Malaysia" => "my",
390
    "Maldives" => "mv",
391
    "Mali" => "ml",
392
    "Malta" => "mt",
393
    "Marshall Islands" => "mh",
394
    "Martinique" => "mq",
395
    "Mauritania" => "mr",
396
    "Mauritius" => "mu",
397
    "Mexico" => "mx",
398
    "Micronesia" => "fm",
399
    "Moldova" => "md",
400
    "Monaco" => "mc",
401
    "Mongolia" => "mn",
402
    "Montenegro" => "me",
403
    "Montserrat" => "ms",
404
    "Morocco" => "ma",
405
    "Mozambique" => "mz",
406
    "Namibia" => "na",
407
    "Nauru" => "nr",
408
    "Nepal" => "np",
409
    "Netherlands" => "nl",
410
    "Netherlands Antilles" => "an",
411
    "New Caledonia" => "nc",
412
    "New Zealand" => "nz",
413
    "Nicaragua" => "ni",
414
    "Niger" => "ne",
415
    "Nigeria" => "ng",
416
    "Niue" => "nu",
417
    "Northern Mariana Islands" => "mp",
418
    "Norway" => "no",
419
    "Oman" => "om",
420
    "Pakistan" => "pk",
421
    "Palau" => "pw",
422
    "Panama" => "pa",
423
    "Papua New Guinea" => "pg",
424
    "Paraguay" => "py",
425
    "Peru" => "pe",
426
    "Philippines" => "ph",
427
    "Pitcairn Islands" => "pn",
428
    "Poland" => "pl",
429
    "Portugal" => "pt",
430
    "Puerto Rico" => "pr",
431
    "Qatar" => "qa",
432
    "Reunion" => "re",
433
    "Romania" => "ro",
434
    "Russia" => "ru",
435
    "Rwanda" => "rw",
436
    "Saint Kitts and Nevis" => "kn",
437
    "Saint Lucia" => "lc",
438
    "Saint Pierre and Miquelon" => "pm",
439
    "Saint Vincent and the Grenadines" => "vc",
440
    "Samoa" => "ws",
441
    "San Marino" => "sm",
442
    "Sao Tome and Principe" => "st",
443
    "Saudi Arabia" => "sa",
444
    "Senegal" => "sn",
445
    "Serbia" => "rs",
446
    "Seychelles" => "sc",
447
    "Sierra Leone" => "sl",
448
    "Singapore" => "sg",
449
    "Slovakia" => "sk",
450
    "Slovenia" => "si",
451
    "Solomon Islands" => "sb",
452
    "Somalia" => "so",
453
    "South Africa" => "za",
454
    "Spain" => "es",
455
    "Sri Lanka" => "lk",
456
    "Sudan" => "sd",
457
    "Suriname" => "sr",
458
    "Swaziland" => "sz",
459
    "Sweden" => "se",
460
    "Switzerland" => "ch",
461
    "Syria" => "sy",
462
    "Taiwan" => "tw",
463
    "Tajikistan" => "tj",
464
    "Tanzania" => "tz",
465
    "Thailand" => "th",
466
    "Togo" => "tg",
467
    "Tokelau" => "tk",
468
    "Tonga" => "to",
469
    "Trinidad and Tobago" => "tt",
470
    "Tunisia" => "tn",
471
    "Turkey" => "tr",
472
    "Turkmenistan" => "tm",
473
    "Turks and Caicos Islands" => "tc",
474
    "Tuvalu" => "tv",
475
    "Uganda" => "ug",
476
    "Ukraine" => "ua",
477
    "United Arab Emirates" => "ae",
478
    "United Kingdom" => "gb",
479
    "United States" => "us",
480
    "Uruguay" => "uy",
481
    "Uzbekistan" => "uz",
482
    "Vanuatu" => "vu",
483
    "Venezuela" => "ve",
484
    "Vietnam" => "vn",
485
    "Virgin Islands" => "vg",
486
    "Wallis and Futuna" => "wf",
487
    "West Bank" => "il",
488
    "Western Sahara" => "eh",
489
    "Yemen" => "ye",
490
    "Zambia" => "zm",
491
    "Zimbabwe" => "zw"
492
);
493
494
// return a list of country options for a <select>
495
//
496
function country_select_options($selected_country="None") {
497
    global $countries;
498
499
    require_once("../inc/geoip.inc");
500
501
    // See if we can find the user's country and select it as default:
502
    //
503
    $gi = geoip_open("../inc/GeoIP.dat",GEOIP_STANDARD);
504
    $geoip_country = geoip_country_name_by_addr($gi,$_SERVER["REMOTE_ADDR"]);
505
    geoip_close($gi);
506
507
    if ($selected_country=="") $selected_country="None";
508
    if ($selected_country=="None" and $geoip_country!=""){
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
509
        $selected_country=$geoip_country;
510
    }
511
512
    $x = "";
513
    foreach ($countries as $country) {
514
        $selected = ($selected_country == $country ? "selected":"");
515
        $x .= "<option value=\"$country\" $selected>$country</option>\n";
516
    }
517
    return $x;
518
}
519
520
function is_valid_country($country) {
521
    global $countries;
522
    if ($country == '') return true;
523
    return in_array($country, $countries);
524
}
525
526
?>
527