-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbroadcast_count.php
More file actions
57 lines (48 loc) · 1.44 KB
/
Copy pathbroadcast_count.php
File metadata and controls
57 lines (48 loc) · 1.44 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
<?php
/**
* @file
* Return a count of how many texts will be sent, when supplied with
* a list of tags
*
*/
require_once 'config.php';
db_databaseConnect();
// URL parameters
$include_tags = isset($_REQUEST['include_tags']) ? $_REQUEST['include_tags'] : array();
$tag_names = isset($_REQUEST['tag_names']) ? $_REQUEST['tag_names'] : array();
// Create an array of selected tags from the $tag_names and $include_tags parameters
$tags_selected = array();
foreach ($include_tags as $tag_number => $include_tag) {
if ($include_tag == 'on') {
$tags_selected[] = $tag_names[$tag_number];
}
}
// Are any tags selected?
if (count($tags_selected)) {
// yes, load the active numbers, limited by tags
// create the SQL for the tags
$sql_tags = '';
foreach ($tags_selected as $tag) {
$sql_tags[] = "tag='".addslashes($tag)."'";
}
$sql = "SELECT COUNT(DISTINCT phone) FROM broadcast ".
"LEFT JOIN broadcast_tags ON broadcast.id = broadcast_tags.broadcast_id ".
"WHERE status='active' AND (".implode(' OR ', $sql_tags).")";
if (db_db_getone($sql, $broadcast_count, $error)) {
echo $broadcast_count;
} else {
// an error, but no way to report it
echo 0;
}
} else {
// no tags, get the count of the active numbers
$sql = "SELECT COUNT(*) FROM broadcast WHERE status='active'";
if (db_db_getone($sql, $broadcast_count, $error)) {
echo $broadcast_count;
} else {
// an error, but no way to report it
echo 0;
}
}
db_databaseDisconnect();
?>