-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
129 lines (107 loc) · 3.24 KB
/
functions.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
<?php
session_start();
include("config.php");
/*
CREATE TABLE IF NOT EXISTS `contacts` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(255) DEFAULT NULL,
`contacttype` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
*/
function connect(){
$conn = mysql_connect($GLOBALS['config']['db_host'],$GLOBALS['config']['db_user'],$GLOBALS['config']['db_password']);
mysql_select_db($GLOBALS['config']['db_name']);
return $conn;
}
function getResults()
{
$conn = connect(); // coonect
$result = mysql_query("SELECT * FROM contacts");
$rows = array();
while($row = mysql_fetch_assoc($result)){
array_push($rows,$row);
}
mysql_freeresult($result);
mysql_close($conn);
return $rows;
}
function verifyLogin(){
if(!$_SESSION["loggedin"]){
redirect("login.php");
}
}
function excelHeaders(){
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=contacts.csv");
header("Pragma: no-cache");
header("Expires: 0");
}
function outputCSV($data) {
$outstream = fopen("php://output", "w");
function __outputCSV(&$vals, $key, $filehandler) {
fputcsv($filehandler, $vals); // add parameters if you want
}
array_walk($data, "__outputCSV", $outstream);
fclose($outstream);
}
function sendMail($contact)
{
if($GLOBALS["config"]["disable_mail"])
{
return;
}
$to = $GLOBALS["config"]["report_email"];
$subject = 'New contact recived';
$message = "Email: {$contact['email']} \r\n ContactType = {$contact['contacttype']}";
$headers = 'From: '.$GLOBALS['config']['webmaster_email']. "\r\n" .
'Reply-To: ' .$GLOBALS['config']['webmaster_email']. "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
return;
}
function saveContact($contact){
$conn = connect(); // coonect
$query = "INSERT INTO contacts (email) VALUES ("
.'"'.mysql_real_escape_string($contact["email"]).'"'
.');';
mysql_query($query);
mysql_close($conn);
}
function saveContactDetails($contact){
$conn = connect(); // coonect
$query = 'UPDATE contacts SET contacttype = "'.mysql_real_escape_string($contact["contacttype"]).'"'
.' WHERE email = "'.mysql_real_escape_string($contact["email"]).'";';
mysql_query($query);
mysql_close($conn);
}
function sendSupportMail($contact)
{
if($GLOBALS["config"]["disable_mail"])
{
return;
}
$to = $GLOBALS["config"]["report_email"];
$subject = 'New support request recived';
$message = "Email: {$contact['email']} \r\n" .
"Name = {$contact['name']} \r\n" .
"Message = {$contact['message']} \r\n";
$headers = 'From: '.$GLOBALS['config']['webmaster_email']. "\r\n" .
'Reply-To: ' .$GLOBALS['config']['webmaster_email']. "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
return;
}
function redirect($filename)
{
header( 'Location: '.$GLOBALS["config"]["baseurl"].'/'.$filename);
exit();
}
function login(){
$_SESSION["loggedin"] = true;
}
function logout()
{
$_SESSION["loggedin"] = false;
session_destroy();
}