-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhotline_blocks.php
More file actions
165 lines (143 loc) · 4.12 KB
/
Copy pathhotline_blocks.php
File metadata and controls
165 lines (143 loc) · 4.12 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* @file
* Blocks
*
* Display and edit blocked phone numbers
*
*/
require_once 'config.php';
require_once $LIB_BASE . 'lib_sms.php';
include 'header.php';
// URL parameters
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
// *** ACTIONS ***
// add?
if ($action == 'add') {
addBlockedNumber($phone, $error, $success);
// remove?
} elseif ($action == 'remove') {
removeBlockedNumber($id, $error, $success);
}
// load blocks
$sql = "SELECT * FROM blocked_numbers ORDER by phone";
db_db_query($sql, $blocks, $error);
// any error message?
if (!empty($error)) {
?>
<div class="alert alert-danger" role="alert"><?php echo $error ?></div>
<?php
}
// any success message?
if (!empty($success)) {
?>
<div class="alert alert-success" role="alert"><?php echo $success ?></div>
<?php
}
?>
<h2 class="sub-header">Hotline</h2>
<ul class="nav nav-pills">
<li role="presentation"><a href="hotline_active_calls.php">Active Calls</a></li>
<li role="presentation"><a href="hotline_staff.php">Staff</a></li>
<li role="presentation" class="active"><a href="hotline_blocks.php">Blocks</a></li>
<li role="presentation"><a href="hotline_languages.php">Languages</a></li>
<li role="presentation"><a href="log.php?ph=<?php echo sms_getFirstHotline($hotline_number, $hotline, $error) ? urlencode($hotline_number) : '' ?>">Log</a></li>
</ul>
<br />
<?php
// Add, list and remove blocks
?>
<h3 class="sub-header">Add</h3>
<form id="text-controls" action="hotline_blocks.php" method="POST">
<input type="hidden" name="action" value="add">
<div class="form-group">
<label for="add-phone">Number to block:</label>
<input type="text" class="form-control" name="phone" id="add-phone" size="20" />
</div>
<button class="btn btn-success" id="button-text">Add</button>
</form>
<h3 class="sub-header">Blocks</h3>
<p>
<?php
foreach ($blocks as $block) {
echo '<b>' . $block['phone'] . '</b> (blocked ' . date("m/d/y h:i a", strtotime($block['added'])) . ') '; ?>
<a href="hotline_blocks.php?action=remove&id=<?php echo $block['id'] ?>"
onClick="return confirm('Are you sure you want to remove this block?');">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a><br />
<?php
}
?>
</p>
<?php
include 'footer.php';
/**
* Add a blocked phone number to the database
*
* ...
*
* @param string $phone
* The number to block.
* @param string &$error
* Errors if any occurred.
* @param string &$message
* An informational message if appropriate.
*
* @return bool
* True if added successfully.
*/
function addBlockedNumber($phone, &$error, &$message)
{
$error = '';
$message = '';
if (!trim($phone)) {
$error = "No number provided.";
return false;
}
// make sure the number is in E164 format
if (!sms_normalizePhoneNumber($phone, $error)) {
return false;
}
// is this number in the database already?
$sql = "SELECT COUNT(*) FROM blocked_numbers WHERE phone='".addslashes($phone)."'";
if (!db_db_getone($sql, $number_exists, $error)) {
return false;
}
if ($number_exists > 0) {
$error = "{$number} is already blocked.";
return false;
}
// add the number to the database
$sql = "INSERT INTO blocked_numbers SET phone='".addslashes($phone)."'";
if (!db_db_command($sql, $error)) {
return false;
}
$message = "Added {$phone} to the block list.";
return true;
}
/**
* Remove a phone number block from the database
*
* ...
*
* @param int $id
* Block id to remove.
* @param string &$error
* Errors if any occurred.
* @param string &$message
* An informational message if appropriate.
*
* @return bool
* True unless an error occurred.
*/
function removeBlockedNumber($id, &$error, &$message)
{
$sql = "DELETE FROM blocked_numbers WHERE id='".addslashes($id)."'";
if (!db_db_command($sql, $error)) {
return false;
}
$message = "The record was removed.";
return true;
}
?>