-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathgoEditMOH.php
201 lines (180 loc) · 7.06 KB
/
goEditMOH.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* @file goEditMOH.php
* @brief API for Modifying Music On Hold
* @copyright Copyright (c) 2018 GOautodial Inc.
* @author Demian Lizandro A. Biscocho
* @author Jeremiah Sebastian Samatra
* @author Chris Lomuntad
*
* @par <b>License</b>:
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
include_once ("goAPI.php");
### POST or GET Variables
$moh_id = $astDB->escape($_REQUEST['moh_id']);
$moh_name = $astDB->escape($_REQUEST['moh_name']);
$user_group = $astDB->escape($_REQUEST['user_group']);
$active = strtoupper($astDB->escape($_REQUEST['active']));
$random = strtoupper($astDB->escape($_REQUEST['random']));
$values = $astDB->escape($_REQUEST['item']);
$filename = $astDB->escape($_REQUEST['filename']);
$ranks = $astDB->escape($_REQUEST['rank']);
### Default values
$defActive = array("Y","N");
$defRandom = array("N","Y");
// Error Checking
if (empty($goUser) || is_null($goUser)) {
$apiresults = array(
"result" => "Error: goAPI User Not Defined."
);
} elseif (empty($goPass) || is_null($goPass)) {
$apiresults = array(
"result" => "Error: goAPI Password Not Defined."
);
} elseif (empty($log_user) || is_null($log_user)) {
$apiresults = array(
"result" => "Error: Session User Not Defined."
);
} elseif ($moh_id == null || strlen($moh_id) < 3) {
$apiresults = array(
"result" => "Error: Set a value for MOH ID not less than 3 characters."
);
} elseif (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $moh_name)) {
$apiresults = array(
"result" => "Error: Special characters found in moh_name and must not be empty"
);
} elseif(preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $moh_id)) {
$apiresults = array(
"result" => "Error: Special characters found in moh_id"
);
} elseif (!in_array($active,$defActive)) {
$apiresults = array(
"result" => "Error: Default value for active is Y or N only."
);
} elseif (!in_array($random,$defRandom)) {
$apiresults = array(
"result" => "Error: Default value for random is Y or N only."
);
} else {
// check if goUser and goPass are valid
$fresults = $astDB
->where("user", $goUser)
->where("pass_hash", $goPass)
->getOne("vicidial_users", "user,user_level");
$goapiaccess = $astDB->getRowCount();
$userlevel = $fresults["user_level"];
if ($goapiaccess > 0 && $userlevel > 7) {
// set tenant value to 1 if tenant - saves on calling the checkIfTenantf function
// every time we need to filter out requests
$tenant = (checkIfTenant ($log_group, $goDB)) ? 1 : 0;
if ($tenant) {
$astDB->where("user_group", $log_group);
$astDB->orWhere("user_group", "---ALL---");
} else {
if (strtoupper($log_group) != 'ADMIN') {
if ($userlevel > 8) {
$astDB->where("user_group", $log_group);
$astDB->orWhere("user_group", "---ALL---");
}
}
}
$astDB->where('moh_id', $moh_id);
$rsltvMoh = $astDB->getOne('vicidial_music_on_hold');
if ($rsltvMoh) {
foreach ($rsltvMoh as $fresults) {
$datamoh_id = $fresults['moh_id'];
$datamoh_name = $fresults['moh_name'];
$dataactive = $fresults['active'];
$datarandom = $fresults['random'];
$datauser_group = $fresults['user_group'];
}
if ($filename != null) {
$insertData = array(
'filename' => $filename,
//'rank' => $rank,
'rank' => '1',
'moh_id' => $moh_id
);
$astDB->where('moh_id', $moh_id);
$astDB->update('vicidial_music_on_hold_files', $insertData);
$log_id = log_action($goDB, 'MODIFY', $log_user, $log_ip, "Modified Music On-Hold: $moh_id", $log_group, $astDB->getLastQuery());
}
if ($moh_name == null) {$moh_name = $datamoh_name;}
if ($active == null) {$active = $dataactive;}
if ($user_group == null) {$user_group = $datauser_group;}
if ($random == null) {$random = $datarandom;}
$updateData = array(
'moh_name' => $moh_name,
'active' => $active,
'user_group' => $user_group,
'random' => $random
);
$astDB->where('moh_id', $moh_id);
$rsltv1 = $astDB->update('vicidial_music_on_hold', $updateData);
/*$log_id = log_action($goDB, 'MODIFY', $log_user, $log_ip, "Modified Music On-Hold: $moh_id", $log_group, astDB->getLastQuery());
$updateData = array(
'rebuild_conf_files' => 'Y',
'rebuild_music_on_hold' => 'Y',
'sounds_update' => 'Y'
);
$astDB->where('generate_vicidial_conf', 'Y');
$astDB->where('active_asterisk_server', 'Y');
$astDB->update('servers', $updateData);
$apiresults = array(
"result" => "success"
);*/
if (!$rsltv1) {
$apiresults = array(
"result" => "Error: Try updating Moh Again"
);
} else {
$log_id = log_action($goDB, 'MODIFY', $log_user, $log_ip, "Modified Music On-Hold: $moh_id", $log_group, $astDB->getLastQuery());
$apiresults = array(
"result" => "success"
);
$affected_rows++;
if ($affected_rows) {
//$newQuery2 = "UPDATE servers SET rebuild_conf_files='Y',rebuild_music_on_hold='Y',sounds_update='Y' where generate_vicidial_conf='Y' and active_asterisk_server='Y';";
$updateData = array(
'rebuild_conf_files' => 'Y',
'rebuild_music_on_hold' => 'Y',
'sounds_update' => 'Y'
);
$astDB->where('generate_vicidial_conf', 'Y');
$astDB->where('active_asterisk_server', 'Y');
$astDB->update('servers', $updateData);
$apiresults = array(
"result" => "success"
);
} else {
$apiresults = array(
"result" => "Error: Try updating Moh Again"
);
}
}
} else {
$apiresults = array(
"result" => "Error: MOH doesn't exist"
);
}
} else {
$err_msg = error_handle("10001");
$apiresults = array(
"code" => "10001",
"result" => $err_msg
);
}
}
?>