-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_rate.server.php
157 lines (119 loc) · 5.46 KB
/
delete_rate.server.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
<?php
/*******************************************************************************
* delete_rate.server.php
* Function Desc
* 功能描述
* Function Desc
* Date 08 May 2012
* Desc: page created
********************************************************************************/
require_once ("db_connect.php");
require_once ('delete_rate.grid.inc.php');
require_once ('include/xajaxGrid.inc.php');
require_once ('include/common.class.php');
require_once ('include/asterevent.class.php');
require_once ("delete_rate.common.php");
require_once ('include/asterisk.class.php');
/**
* initialize page elements
*
*/
function init(){
global $locate;
$objResponse = new xajaxResponse();
$objResponse->addAssign("divNav","innerHTML",common::generateManageNav($skin));
$objResponse->addAssign("divCopyright","innerHTML",common::generateCopyright($skin));
$objResponse->addAssign("delTable","value","");
$objResponse->addAssign("delType","value","all");
$objResponse->addAssign("delObject","value",'all');
return $objResponse;
}
function changeTable($value){
global $locate;
$objResponse = new xajaxResponse();
if($value == 'resellerrate'){
$delTypeHtml = '<select id="delType" name="delType" onchange="xajax_getObjectData(this.value);"><option value="all">'.$locate->Translate("all").'</option><option value="system">'.$locate->Translate("system").'</option><option value="reseller">'.$locate->Translate("reseller").'</option></select>';
} else {
$delTypeHtml = '<select id="delType" name="delType" onchange="xajax_getObjectData(this.value);"><option value="all">'.$locate->Translate("all").'</option><option value="system">'.$locate->Translate("system").'</option><option value="reseller">'.$locate->Translate("reseller").'</option><option value="group">'.$locate->Translate("group").'</option></select>';
}
$objResponse->addAssign("delTypeBtn","innerHTML",$delTypeHtml);
$objResponse->addAssign("delType","value",'all');
$objResponse->addAssign("delObjectBtn","innerHTML",'<select id="delObject" name="delObject"><option value="all">'.$locate->Translate("all").'</option></select>');
return $objResponse->getXML();
}
function getObjectData($object){
global $locate;
$objResponse = new xajaxResponse();
if($object == 'all'){
$optionHtml = '<select id="delObject" name="delObject"><option value="all">'.$locate->Translate('all').'</option></select>';
} else if($object == 'system'){
$optionHtml = '<select id="delObject" name="delObject"><option value="default">'.$locate->Translate('default').'</option></select>';
} else if($object == 'reseller'){
$optionHtml = & Customer::getObjectHtml('resellergroup');
} else if($object == 'group'){
$optionHtml = & Customer::getObjectHtml('accountgroup');
}
$objResponse->addAssign("delObjectBtn","innerHTML",$optionHtml);
return $objResponse->getXML();
}
function searchRate($f){
global $locate;
$objResponse = new xajaxResponse();
$delTable = $f['delTable'];
$delType = $f['delType'];
$delObject = $f['delObject'];
if(empty($delTable)){
$objResponse->addAlert($locate->Translate("Please select a rate table"));
return $objResponse;
}
$rateHtml = Customer::searchRateHtml($delTable,$delType,$delObject);
$objResponse->addAssign("searchRateList","innerHTML",$rateHtml);
$objResponse->addAssign("delRateBtn","innerHTML","<input type=\"button\" value=\"".$locate->Translate("delete")."\" onclick=\"if (confirm('".$locate->Translate("Are you sure you want to delete this rate")."?')) xajax_deleteRate(document.getElementById('deleteSql').value,document.getElementById('historySql').value);return false;\" />");
return $objResponse->getXML();
}
function deleteRate($deleteSql,$historySql){
global $locate,$db,$config;
$objResponse = new xajaxResponse();
if(empty($deleteSql)){
$objResponse->addAlert($locate->Translate("Can not delete this rate"));
return $objResponse;
}
//if enable the synchronizatioin
if($config['synchronize']['delete_by_use_history']){
Customer::events($historySql);
$insertResult = $db->query($historySql);
if($insertResult <= 0){
$objResponse->addAlert($locate->Translate("delete failed synchronization"));
return $objResponse;
}
}
Customer::events($deleteSql);
$result = $db->query($deleteSql);
if($result){
$objResponse->addAlert($locate->Translate("Delete success").','.$locate->Translate("please remember to restart asterrc"));
$objResponse->addAssign("searchRateList","innerHTML",$locate->Translate("page_rate_tips").' <input type="button" value="'.$locate->Translate("restart asterrc").'" onclick="restartAsterrc();return false;" />');
} else {
$objResponse->addAlert($locate->Translate("Delete failed"));
}
return $objResponse;
}
function restartAsterrc(){
global $locate;
$objResponse = new xajaxResponse();
if($_SESSION['curuser']['usertype'] != 'admin') return $objResponse;
$myAsterisk = new Asterisk();
$pso = exec("ps -ef |grep -v grep |grep -E /asterr[a-z]{0,1\}[.\ ]+-d |awk '{print $2}'");
$rk = exec("sudo /opt/asterisk/scripts/astercc/asterrc -k",$rkd);
$rd = exec("sudo /opt/asterisk/scripts/astercc/asterrc -d",$rdd,$rdv);
$psn = exec("ps -ef |grep -v grep |grep -E /asterr[a-z]{0,1\}[.\ ]+-d |awk '{print $2}'");
if($psn == ''){
$objResponse->addAlert($locate->Translate('start asterrc failed'));
}elseif($psn != $pso){
$objResponse->addAlert($locate->Translate('asterrc have been restart'));
}elseif($psn == $pso ){
$objResponse->addAlert($locate->Translate('asterrc restart failed'));
}
return $objResponse;
}
$xajax->processRequests();
?>