Completed
Pull Request — master (#526)
by Michael
01:57
created

search.php (1 issue)

1
<?php
2
/**************************************************************************
3
**********      English Wikipedia Account Request Interface      **********
4
***************************************************************************
5
** Wikipedia Account Request Graphic Design by Charles Melbye,           **
6
** which is licensed under a Creative Commons                            **
7
** Attribution-Noncommercial-Share Alike 3.0 United States License.      **
8
**                                                                       **
9
** All other code are released under the Public Domain                   **
10
** by the ACC Development Team.                                          **
11
**                                                                       **
12
** See CREDITS for the list of developers.                               **
13
***************************************************************************/
14
15
global $session;
16
17
// load the configuration
18
require_once 'config.inc.php';
19
20
// Get all the classes.
21
require_once 'functions.php';
22
initialiseSession();
23
require_once 'includes/PdoDatabase.php';
24
require_once 'includes/SmartyInit.php';
25
26
// Check to see if the database is unavailable.
27
// Uses the false variable as its the internal interface.
28
if (Offline::isOffline()) {
29
	echo Offline::getOfflineMessage(false);
30
	die();
31
}
32
33
if (isset($_SESSION['user'])) {
34
	$sessionuser = $_SESSION['user'];
35
}
36
else {
37
	$sessionuser = "";
38
}
39
40
// initialise providers
41
global $squidIpList;
42
$locationProvider = new $locationProviderClass(gGetDb('acc'), $locationProviderApiKey);
43
$rdnsProvider = new $rdnsProviderClass(gGetDb('acc'));
44
$antispoofProvider = new $antispoofProviderClass();
45
$xffTrustProvider = new $xffTrustProviderClass($squidIpList);
46
47
BootstrapSkin::displayInternalHeader();
48
49
$session = new session();
50
$session->checksecurity();
0 ignored issues
show
Deprecated Code introduced by
The function session::checksecurity() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

50
/** @scrutinizer ignore-deprecated */ $session->checksecurity();
Loading history...
51
52
// protect against logged out users
53
if (User::getCurrent()->isCommunityUser()) {
54
	showlogin();
55
	BootstrapSkin::displayInternalFooter();
56
	die();
57
}
58
59
///////////////// Page code
60
61
$smarty->display("search/header.tpl");
62
BootstrapSkin::pushTagStack("</div>"); // span12
63
BootstrapSkin::pushTagStack("</div>"); // row
64
    
65
if (isset($_GET['term']) && isset($_GET['type'])) {
66
	$term = $_GET['term'];
67
    
68
	if ($term == "" || $term == "%") {
69
		BootstrapSkin::displayAlertBox("No search term entered.", "alert-error", "", false);
70
		$smarty->display("search/searchform.tpl");
71
		BootstrapSkin::displayInternalFooter();
72
		die();
73
	}
74
75
	if ($_GET['type'] == "email") {
76
		if ($term == "@") {
77
			BootstrapSkin::displayAlertBox("The search term '@' is not valid for email address searches!");
78
			$smarty->display("search/searchform.tpl");
79
			BootstrapSkin::displayInternalFooter();
80
			die();
81
		}			
82
83
		$qterm = '%' . $term . '%';
84
        
85
		$statement = gGetDb()->prepare("SELECT * FROM request WHERE email LIKE :term;");
86
		$statement->bindValue(":term", $qterm);
87
		$statement->execute();
88
		$requests = $statement->fetchAll(PDO::FETCH_CLASS, "Request");
89
		foreach ($requests as $r) {
90
			$r->setDatabase(gGetDb());   
91
		}
92
        
93
		$smarty->assign("term", $term);
94
		$smarty->assign("requests", $requests);
95
		$target = "email address";
96
		$smarty->assign("target", $target);
97
        
98
		$smarty->display("search/searchresult.tpl");
99
	}
100
	elseif ($_GET['type'] == 'IP') {
101
		$qterm = '%' . $term . '%';
102
        
103
		$statement = gGetDb()->prepare("SELECT * FROM request WHERE email <> '[email protected]' and ip <> '127.0.0.1' and ip LIKE :term or forwardedip LIKE :term2;");
104
		$statement->bindValue(":term", $qterm);
105
		$statement->bindValue(":term2", $qterm);
106
		$statement->execute();
107
		$requests = $statement->fetchAll(PDO::FETCH_CLASS, "Request");
108
		foreach ($requests as $r) {
109
			$r->setDatabase(gGetDb());   
110
		}
111
        
112
		$smarty->assign("term", $term);
113
		$smarty->assign("requests", $requests);
114
		$target = "IP address";
115
		$smarty->assign("target", $target);
116
        
117
		$smarty->display("search/searchresult.tpl");
118
	}
119
	elseif ($_GET['type'] == 'Request') {
120
		$qterm = '%' . $term . '%';
121
        
122
		$statement = gGetDb()->prepare("SELECT * FROM request WHERE name LIKE :term;");
123
		$statement->bindValue(":term", $qterm);
124
		$statement->execute();
125
		$requests = $statement->fetchAll(PDO::FETCH_CLASS, "Request");
126
		foreach ($requests as $r) {
127
			$r->setDatabase(gGetDb());   
128
		}
129
        
130
		$smarty->assign("term", $term);
131
		$smarty->assign("requests", $requests);
132
		$target = "requested name";
133
		$smarty->assign("target", $target);
134
        
135
		$smarty->display("search/searchresult.tpl");
136
	}
137
	else {
138
		BootstrapSkin::displayAlertBox("Unknown search type", "alert-error", "Error");
139
		$smarty->display("search/searchform.tpl");
140
		BootstrapSkin::displayInternalFooter();
141
		die();
142
	}
143
}
144
else {
145
	$smarty->display("search/searchform.tpl");
146
}
147
148
BootstrapSkin::displayInternalFooter();
149