| 1 |
<?php |
|---|
| 2 |
//Copyright (C) 2006 Lenux Inc. (info@lenux.eu) |
|---|
| 3 |
// |
|---|
| 4 |
//This program is free software; you can redistribute it and/or |
|---|
| 5 |
//modify it under the terms of the GNU General Public License |
|---|
| 6 |
//as published by the Free Software Foundation; either version 2 |
|---|
| 7 |
//of the License, or (at your option) any later version. |
|---|
| 8 |
// |
|---|
| 9 |
//This program is distributed in the hope that it will be useful, |
|---|
| 10 |
//but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 |
//GNU General Public License for more details. |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
function configpageinit($mydisplay, $mytype) { |
|---|
| 16 |
global $currentcomponent; |
|---|
| 17 |
if ( $currentcomponent->isequal($mydisplay, $mytype) ) { |
|---|
| 18 |
$currentcomponent->addguifunc('cdrcost_'.$mydisplay.'_configpageload'); |
|---|
| 19 |
$currentcomponent->addprocessfunc('cdrcost_'.$mydisplay.'_configprocess'); |
|---|
| 20 |
return true; |
|---|
| 21 |
} |
|---|
| 22 |
return false; |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
function configpageload($menu) { |
|---|
| 26 |
global $currentcomponent; |
|---|
| 27 |
extract($_REQUEST); |
|---|
| 28 |
|
|---|
| 29 |
if ( $action == 'del' ) { |
|---|
| 30 |
$currentcomponent->addguielem('_top', new gui_subheading('del', $extdisplay.' '._("deleted"), false)); |
|---|
| 31 |
return false; |
|---|
| 32 |
} else { |
|---|
| 33 |
if ( $extdisplay == '' ) { |
|---|
| 34 |
$currentcomponent->addguielem('_top', new gui_pageheading('title', 'Add '.$menu, false), 0); |
|---|
| 35 |
$currentcomponent->addguielem('_top', new gui_hidden('action', 'add')); |
|---|
| 36 |
} elseif ( is_string($extdisplay) ) { |
|---|
| 37 |
$currentcomponent->addguielem('_top', new gui_pageheading('title', "$menu: $extdisplay", false), 0); |
|---|
| 38 |
$currentcomponent->addguielem('_top', new gui_hidden('action', 'edit')); |
|---|
| 39 |
$delURL = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&action=del'; |
|---|
| 40 |
$currentcomponent->addguielem('_top', new gui_link('del', _("Delete ")." $menu $extdisplay", $delURL, true, false), 0); |
|---|
| 41 |
} |
|---|
| 42 |
$currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay)); |
|---|
| 43 |
return true; |
|---|
| 44 |
} |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
function cdrcost_configprocess($addfun, $delfun, $editfun) { |
|---|
| 48 |
extract($_REQUEST); |
|---|
| 49 |
switch ($action) { |
|---|
| 50 |
case "add": |
|---|
| 51 |
$addfun($_REQUEST); |
|---|
| 52 |
|
|---|
| 53 |
break; |
|---|
| 54 |
case "del": |
|---|
| 55 |
$delfun($extdisplay); |
|---|
| 56 |
|
|---|
| 57 |
break; |
|---|
| 58 |
case "edit": |
|---|
| 59 |
$editfun($extdisplay,$_REQUEST); |
|---|
| 60 |
|
|---|
| 61 |
break; |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
function cdrcost_destinations() { |
|---|
| 67 |
return null; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
function cdrcost_get_config($engine) { |
|---|
| 74 |
global $ext; |
|---|
| 75 |
switch($engine) { |
|---|
| 76 |
case "asterisk": |
|---|
| 77 |
break; |
|---|
| 78 |
} |
|---|
| 79 |
sql("SET CHARACTER SET utf8","query"); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
function cdrcost_zonegroup_add($vars) { |
|---|
| 85 |
extract($vars); |
|---|
| 86 |
$sql = "INSERT INTO call_zone_group (name) VALUES ('".$name."');"; |
|---|
| 87 |
sql($sql,"query"); |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
function cdrcost_zonegroup_del($id) { |
|---|
| 91 |
error_log(date("H:i:s").": torol id: ".$id."\n",3,"/tmp/php.log"); |
|---|
| 92 |
$sql = "DELETE FROM call_zone_group WHERE id = '".$id."'"; |
|---|
| 93 |
sql($sql,"query"); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
function cdrcost_zonegroup_edit($id,$vars) { |
|---|
| 97 |
extract($vars); |
|---|
| 98 |
$sql = "UPDATE call_zone_group SET name = '".$name."' WHERE id = '".$id."'"; |
|---|
| 99 |
sql($sql,"query"); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
function cdrcost_zonegroup_get($id) { |
|---|
| 103 |
$sql = "SELECT * FROM call_zone_group WHERE id = '".$id."'"; |
|---|
| 104 |
return sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
function cdrcost_zonegroup_list() { |
|---|
| 108 |
$sql = "SELECT id, name FROM call_zone_group ORDER BY name"; |
|---|
| 109 |
return sql($sql,"getAll"); |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
function cdrcost_zonegroup_configpageinit($dispnum) { |
|---|
| 113 |
configpageinit('zonegroup', 'tool'); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
function cdrcost_zonegroup_configpageload() { |
|---|
| 117 |
global $currentcomponent; |
|---|
| 118 |
extract($_REQUEST); |
|---|
| 119 |
$disppart = 'Zone Group'; |
|---|
| 120 |
if ( configpageload($disppart) ) { |
|---|
| 121 |
$zonegroup = cdrcost_zonegroup_get($extdisplay); |
|---|
| 122 |
if ( is_array($zonegroup) && count($zonegroup) == 1 ) |
|---|
| 123 |
extract($zonegroup[0], EXTR_PREFIX_ALL, 'zonegroup'); |
|---|
| 124 |
$section = $disppart.' Options'; |
|---|
| 125 |
$currentcomponent->addguielem($section, new gui_textbox('name', $zonegroup_name, 'Name', 'The name of this Zone Group.', 'isEmpty()', 'Please enter a valid Name')); |
|---|
| 126 |
} |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
function cdrcost_zonegroup_configprocess() { |
|---|
| 130 |
cdrcost_configprocess(cdrcost_zonegroup_add, cdrcost_zonegroup_del, cdrcost_zonegroup_edit); |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
function cdrcost_zone_add($vars) { |
|---|
| 138 |
extract($vars); |
|---|
| 139 |
$sql = "INSERT INTO call_zone (group_id, name, pattern) VALUES ("; |
|---|
| 140 |
$sql .= "'".$group_id."',"; |
|---|
| 141 |
$sql .= "'".$name."',"; |
|---|
| 142 |
$sql .= "'".$pattern."');"; |
|---|
| 143 |
sql($sql,"query"); |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
function cdrcost_zone_del($id) { |
|---|
| 147 |
$sql = "DELETE FROM call_zone WHERE id = '".$id."'"; |
|---|
| 148 |
sql($sql,"query"); |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
function cdrcost_zone_edit($id,$vars) { |
|---|
| 152 |
extract($vars); |
|---|
| 153 |
$sql = "UPDATE call_zone SET group_id = '".$group_id."', name = '".$name."', pattern = '".$pattern."' WHERE id = '".$id."'"; |
|---|
| 154 |
sql($sql,"query"); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
function cdrcost_zone_get($id) { |
|---|
| 158 |
$sql = "SELECT * FROM call_zone WHERE id = '".$id."'"; |
|---|
| 159 |
return sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
function cdrcost_zone_list() { |
|---|
| 163 |
$sql = "SELECT id, name FROM call_zone ORDER BY name"; |
|---|
| 164 |
return sql($sql,"getAll"); |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
function cdrcost_zone_configpageinit($dispnum) { |
|---|
| 168 |
global $currentcomponent; |
|---|
| 169 |
if ( configpageinit('zone', 'tool') ) { |
|---|
| 170 |
$item = 'grouplist'; |
|---|
| 171 |
$currentcomponent->addoptlist($item, false); |
|---|
| 172 |
$list = cdrcost_zonegroup_list(); |
|---|
| 173 |
if (is_array($list) && count($list) > 0) { |
|---|
| 174 |
foreach ($list as $temp) { |
|---|
| 175 |
$currentcomponent->addoptlistitem($item, $temp[0], $temp[1]); |
|---|
| 176 |
} |
|---|
| 177 |
} |
|---|
| 178 |
} |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
function cdrcost_zone_configpageload() { |
|---|
| 182 |
global $currentcomponent; |
|---|
| 183 |
extract($_REQUEST); |
|---|
| 184 |
$disppart = 'Zone'; |
|---|
| 185 |
if ( configpageload($disppart) ) { |
|---|
| 186 |
$zone = cdrcost_zone_get($extdisplay); |
|---|
| 187 |
if ( is_array($zone) && count($zone) == 1 ) |
|---|
| 188 |
extract($zone[0], EXTR_PREFIX_ALL, 'zone'); |
|---|
| 189 |
$section = $disppart.' Options'; |
|---|
| 190 |
$currentcomponent->addguielem($section, new gui_textbox('name', $zone_name, 'Name', 'The name of this Zone.', 'isEmpty()', 'Please enter a valid Name')); |
|---|
| 191 |
$currentcomponent->addguielem($section, new gui_selectbox('group_id', $currentcomponent->getoptlist('grouplist'), $zone_group_id, 'Group', 'The group of this zone', false)); |
|---|
| 192 |
$currentcomponent->addguielem($section, new gui_textbox('pattern', $zone_pattern, 'Pattern', 'The regex pattern of this Zone.', 'isEmpty()', 'Please enter a valid Pattern')); |
|---|
| 193 |
} |
|---|
| 194 |
} |
|---|
| 195 |
|
|---|
| 196 |
function cdrcost_zone_configprocess() { |
|---|
| 197 |
cdrcost_configprocess(cdrcost_zone_add, cdrcost_zone_del, cdrcost_zone_edit); |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
function cdrcost_schedule_add($vars) { |
|---|
| 205 |
extract($vars); |
|---|
| 206 |
$sql = "INSERT INTO call_schedule (name) VALUES ('".$name."');"; |
|---|
| 207 |
sql($sql,"query"); |
|---|
| 208 |
} |
|---|
| 209 |
|
|---|
| 210 |
function cdrcost_schedule_del($id) { |
|---|
| 211 |
$sql = "DELETE FROM call_schedule WHERE id = '".$id."'"; |
|---|
| 212 |
sql($sql,"query"); |
|---|
| 213 |
} |
|---|
| 214 |
|
|---|
| 215 |
function cdrcost_schedule_edit($id,$vars) { |
|---|
| 216 |
extract($vars); |
|---|
| 217 |
$sql = "UPDATE call_schedule SET name = '".$name."' WHERE id = '".$id."'"; |
|---|
| 218 |
sql($sql,"query"); |
|---|
| 219 |
} |
|---|
| 220 |
|
|---|
| 221 |
function cdrcost_schedule_get($id) { |
|---|
| 222 |
$sql = "SELECT * FROM call_schedule WHERE id = '".$id."'"; |
|---|
| 223 |
return sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
function cdrcost_schedule_list() { |
|---|
| 227 |
$sql = "SELECT id, name FROM call_schedule ORDER BY name"; |
|---|
| 228 |
return sql($sql,"getAll"); |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
function cdrcost_schedule_configpageinit($dispnum) { |
|---|
| 232 |
configpageinit('schedule', 'tool'); |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
function cdrcost_schedule_configpageload() { |
|---|
| 236 |
global $currentcomponent; |
|---|
| 237 |
extract($_REQUEST); |
|---|
| 238 |
$disppart = 'Schedule'; |
|---|
| 239 |
if ( configpageload($disppart) ) { |
|---|
| 240 |
$schedule = cdrcost_schedule_get($extdisplay); |
|---|
| 241 |
if ( is_array($schedule) && count($schedule) == 1 ) |
|---|
| 242 |
extract($schedule[0], EXTR_PREFIX_ALL, 'schedule'); |
|---|
| 243 |
$section = $disppart.' Options'; |
|---|
| 244 |
$currentcomponent->addguielem($section, new gui_textbox('name', $schedule_name, 'Name', 'The name of this Schedule.', 'isEmpty()', 'Please enter a valid Name')); |
|---|
| 245 |
} |
|---|
| 246 |
} |
|---|
| 247 |
|
|---|
| 248 |
function cdrcost_schedule_configprocess() { |
|---|
| 249 |
cdrcost_configprocess(cdrcost_schedule_add, cdrcost_schedule_del, cdrcost_schedule_edit); |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
function cdrcost_schedulepart_add($vars) { |
|---|
| 257 |
extract($vars); |
|---|
| 258 |
$sql = "INSERT INTO call_schedule_part (name, schedule_id, weekday, begin, end) VALUES ("; |
|---|
| 259 |
$sql .= "'".$name."',"; |
|---|
| 260 |
$sql .= "'".$schedule_id."',"; |
|---|
| 261 |
$sql .= "'".$weekday."',"; |
|---|
| 262 |
$sql .= "'".$begin."',"; |
|---|
| 263 |
$sql .= "'".$end."');"; |
|---|
| 264 |
sql($sql,"query"); |
|---|
| 265 |
} |
|---|
| 266 |
|
|---|
| 267 |
function cdrcost_schedulepart_del($id) { |
|---|
| 268 |
$sql = "DELETE FROM call_schedule_part WHERE id = '".$id."'"; |
|---|
| 269 |
sql($sql,"query"); |
|---|
| 270 |
} |
|---|
| 271 |
|
|---|
| 272 |
function cdrcost_schedulepart_edit($id,$vars) { |
|---|
| 273 |
extract($vars); |
|---|
| 274 |
$sql = "UPDATE call_schedule_part SET "; |
|---|
| 275 |
$sql .= "name = '".$name; |
|---|
| 276 |
$sql .= "', schedule_id = '".$schedule_id; |
|---|
| 277 |
$sql .= "', weekday = '".$weekday; |
|---|
| 278 |
$sql .= "', begin = '".$begin; |
|---|
| 279 |
$sql .= "', end = '".$end."' WHERE id = '".$id."'"; |
|---|
| 280 |
sql($sql,"query"); |
|---|
| 281 |
} |
|---|
| 282 |
|
|---|
| 283 |
function cdrcost_schedulepart_get($id) { |
|---|
| 284 |
$sql = "SELECT * FROM call_schedule_part WHERE id = '".$id."'"; |
|---|
| 285 |
return sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 286 |
} |
|---|
| 287 |
|
|---|
| 288 |
function cdrcost_schedulepart_list() { |
|---|
| 289 |
$sql = "SELECT id, name FROM call_schedule_part ORDER BY name"; |
|---|
| 290 |
return sql($sql,"getAll"); |
|---|
| 291 |
} |
|---|
| 292 |
|
|---|
| 293 |
function cdrcost_schedulepart_configpageinit($dispnum) { |
|---|
| 294 |
global $currentcomponent; |
|---|
| 295 |
if ( configpageinit('schedulepart', 'tool') ) { |
|---|
| 296 |
$item = 'schedulelist'; |
|---|
| 297 |
$currentcomponent->addoptlist($item, false); |
|---|
| 298 |
$list = cdrcost_schedule_list(); |
|---|
| 299 |
if (is_array($list) && count($list) > 0) { |
|---|
| 300 |
foreach ($list as $temp) { |
|---|
| 301 |
$currentcomponent->addoptlistitem($item, $temp[0], $temp[1]); |
|---|
| 302 |
} |
|---|
| 303 |
} |
|---|
| 304 |
} |
|---|
| 305 |
} |
|---|
| 306 |
|
|---|
| 307 |
function cdrcost_schedulepart_configpageload() { |
|---|
| 308 |
global $currentcomponent; |
|---|
| 309 |
extract($_REQUEST); |
|---|
| 310 |
$disppart = 'Schedule Part'; |
|---|
| 311 |
if ( configpageload($disppart) ) { |
|---|
| 312 |
$schedulepart_weekday = -1; |
|---|
| 313 |
$schedulepart_begin = '00:00:00'; |
|---|
| 314 |
$schedulepart_end = '23:59:59'; |
|---|
| 315 |
$schedulepart = cdrcost_schedulepart_get($extdisplay); |
|---|
| 316 |
if ( is_array($schedulepart) && count($schedulepart) == 1 ) |
|---|
| 317 |
extract($schedulepart[0], EXTR_PREFIX_ALL, 'schedulepart'); |
|---|
| 318 |
$section = $disppart.' Options'; |
|---|
| 319 |
$currentcomponent->addguielem($section, new gui_textbox('name', $schedulepart_name, 'Name', 'The name of this Schedule part.', 'isEmpty()', 'Please enter a valid Name')); |
|---|
| 320 |
$currentcomponent->addguielem($section, new gui_selectbox('schedule_id', $currentcomponent->getoptlist('schedulelist'), $schedulepart_schedule_id, 'Schedule', 'The schedule for this part belong to.', false)); |
|---|
| 321 |
$currentcomponent->addguielem($section, new gui_textbox('weekday', $schedulepart_weekday, 'Weekday', 'On which weekday this part valid (0 and 7 is sunday, negativ value means always.', '!checkNumber()', 'Please enter a valid value')); |
|---|
| 322 |
$currentcomponent->addguielem($section, new gui_textbox('begin', $schedulepart_begin, 'From', 'From which time this part valid (format is: hh:mm:ss.', 'isEmpty()', 'Please enter a valid from')); |
|---|
| 323 |
$currentcomponent->addguielem($section, new gui_textbox('end', $schedulepart_end, 'To', 'Until which time this part valid (format is: hh:mm:ss.', 'isEmpty()', 'Please enter a valid to')); |
|---|
| 324 |
} |
|---|
| 325 |
} |
|---|
| 326 |
|
|---|
| 327 |
function cdrcost_schedulepart_configprocess() { |
|---|
| 328 |
cdrcost_configprocess(cdrcost_schedulepart_add, cdrcost_schedulepart_del, cdrcost_schedulepart_edit); |
|---|
| 329 |
} |
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
function cdrcost_rate_add($vars) { |
|---|
| 336 |
extract($vars); |
|---|
| 337 |
$sql = "INSERT INTO call_rate ("; |
|---|
| 338 |
$sql .= "accountcode, name, begin, end, trunk, zone_id, rate, min_duration, block_size, connect, disconnect, schedule_id"; |
|---|
| 339 |
$sql .= ") VALUES ("; |
|---|
| 340 |
$sql .= "'".$accountcode."',"; |
|---|
| 341 |
$sql .= "'".$name."',"; |
|---|
| 342 |
$sql .= "'".$begin."',"; |
|---|
| 343 |
$sql .= "'".$end."',"; |
|---|
| 344 |
$sql .= "'".$trunk."',"; |
|---|
| 345 |
$sql .= "'".$zone_id."',"; |
|---|
| 346 |
$sql .= "'".$rate."',"; |
|---|
| 347 |
$sql .= "'".$min_duration."',"; |
|---|
| 348 |
$sql .= "'".$block_size."',"; |
|---|
| 349 |
$sql .= "'".$connect."',"; |
|---|
| 350 |
$sql .= "'".$disconnect."',"; |
|---|
| 351 |
$sql .= "'".$schedule_id."');"; |
|---|
| 352 |
sql($sql,"query"); |
|---|
| 353 |
} |
|---|
| 354 |
|
|---|
| 355 |
function cdrcost_rate_del($id) { |
|---|
| 356 |
$sql = "DELETE FROM call_rate WHERE id = '".$id."'"; |
|---|
| 357 |
sql($sql,"query"); |
|---|
| 358 |
} |
|---|
| 359 |
|
|---|
| 360 |
function cdrcost_rate_edit($id,$vars) { |
|---|
| 361 |
extract($vars); |
|---|
| 362 |
$sql = "UPDATE call_rate SET "; |
|---|
| 363 |
$sql .= "accountcode = '".$accountcode."', "; |
|---|
| 364 |
$sql .= "name = '".$name."', "; |
|---|
| 365 |
$sql .= "begin = '".$begin."', "; |
|---|
| 366 |
$sql .= "end = '".$end."', "; |
|---|
| 367 |
$sql .= "trunk = '".$trunk."', "; |
|---|
| 368 |
$sql .= "zone_id = '".$zone_id."', "; |
|---|
| 369 |
$sql .= "rate = '".$rate."', "; |
|---|
| 370 |
$sql .= "min_duration = '".$min_duration."', "; |
|---|
| 371 |
$sql .= "block_size = '".$block_size."', "; |
|---|
| 372 |
$sql .= "connect = '".$connect."', "; |
|---|
| 373 |
$sql .= "disconnect = '".$disconnect."', "; |
|---|
| 374 |
$sql .= "schedule_id = '".$schedule_id."';"; |
|---|
| 375 |
sql($sql,"query"); |
|---|
| 376 |
} |
|---|
| 377 |
|
|---|
| 378 |
function cdrcost_rate_get($id) { |
|---|
| 379 |
$sql = "SELECT * FROM call_rate WHERE id = '".$id."'"; |
|---|
| 380 |
return sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 381 |
} |
|---|
| 382 |
|
|---|
| 383 |
function cdrcost_rate_list() { |
|---|
| 384 |
$sql = "SELECT id, name FROM call_rate ORDER BY name"; |
|---|
| 385 |
return sql($sql,"getAll"); |
|---|
| 386 |
} |
|---|
| 387 |
|
|---|
| 388 |
function cdrcost_rate_configpageinit($dispnum) { |
|---|
| 389 |
global $currentcomponent; |
|---|
| 390 |
if ( configpageinit('rate', 'tool') ) { |
|---|
| 391 |
$item = 'zonelist'; |
|---|
| 392 |
$currentcomponent->addoptlist($item, false); |
|---|
| 393 |
$list = cdrcost_zone_list(); |
|---|
| 394 |
if (is_array($list) && count($list) > 0) { |
|---|
| 395 |
foreach ($list as $temp) { |
|---|
| 396 |
$currentcomponent->addoptlistitem($item, $temp[0], $temp[1]); |
|---|
| 397 |
} |
|---|
| 398 |
} |
|---|
| 399 |
$item = 'schedulelist'; |
|---|
| 400 |
$currentcomponent->addoptlist($item, false); |
|---|
| 401 |
$list = cdrcost_schedule_list(); |
|---|
| 402 |
if (is_array($list) && count($list) > 0) { |
|---|
| 403 |
foreach ($list as $temp) { |
|---|
| 404 |
$currentcomponent->addoptlistitem($item, $temp[0], $temp[1]); |
|---|
| 405 |
} |
|---|
| 406 |
} |
|---|
| 407 |
} |
|---|
| 408 |
} |
|---|
| 409 |
|
|---|
| 410 |
function cdrcost_rate_configpageload() { |
|---|
| 411 |
global $currentcomponent; |
|---|
| 412 |
extract($_REQUEST); |
|---|
| 413 |
$disppart = 'Rate'; |
|---|
| 414 |
if ( configpageload($disppart) ) { |
|---|
| 415 |
$rate_begin = '1900-01-01 00:00:00'; |
|---|
| 416 |
$rate_end = '2100-01-01 00:00:00'; |
|---|
| 417 |
$rate_rate = 0; |
|---|
| 418 |
$rate_min_duration = 0; |
|---|
| 419 |
$rate_block_size = 1; |
|---|
| 420 |
$rate_connect = 0; |
|---|
| 421 |
$rate_disconnect = 0; |
|---|
| 422 |
$rate = cdrcost_rate_get($extdisplay); |
|---|
| 423 |
if ( is_array($rate) && count($rate) == 1 ) |
|---|
| 424 |
extract($rate[0], EXTR_PREFIX_ALL, 'rate'); |
|---|
| 425 |
$section = $disppart.' Options'; |
|---|
| 426 |
$currentcomponent->addguielem($section, new gui_textbox('name', $rate_name, 'Name', 'The name of this Rate.', 'isEmpty()', 'Please enter a valid Name')); |
|---|
| 427 |
$currentcomponent->addguielem($section, new gui_textbox('accountcode', $rate_accountcode, 'Account Code', 'The accountcode used in the extension config. If empty then this rate is for all accountcode.', '!isAlphanumeric()', 'Please enter a valid account code')); |
|---|
| 428 |
$currentcomponent->addguielem($section, new gui_textbox('begin', $rate_begin, 'Valid from', "This rate is valid from this time. The format is '1979-10-30 01:02:03'.", '', 'Please enter a valid date')); |
|---|
| 429 |
$currentcomponent->addguielem($section, new gui_textbox('end', $rate_end, 'Valid till', "This rate is valid untill this time. The format is '1979-10-30 01:02:03'.", '', 'Please enter a valid date')); |
|---|
| 430 |
$currentcomponent->addguielem($section, new gui_textbox('trunk', $rate_trunk, 'Trunk', 'The name of the Trunk for this rate is applicable.', '!isAlphanumeric()', 'Please enter a valid trunk')); |
|---|
| 431 |
$currentcomponent->addguielem($section, new gui_selectbox('zone_id', $currentcomponent->getoptlist('zonelist'), $rate_zone_id, 'Zone', 'The zone of this rate', false)); |
|---|
| 432 |
$currentcomponent->addguielem($section, new gui_textbox('rate', $rate_rate, 'Rate', 'The cost of this rate per seconds.', '!isFloat()', 'Please enter a valid number')); |
|---|
| 433 |
$currentcomponent->addguielem($section, new gui_textbox('min_duration', $rate_min_duration, 'Minimum duration', 'The minimum duration will be applied in second.', '!isInteger()', 'Please enter a valid duration')); |
|---|
| 434 |
$currentcomponent->addguielem($section, new gui_textbox('block_size', $rate_block_size, 'Block size', 'The increment size which will be applied in second.', '!isInteger()', 'Please enter a valid block size')); |
|---|
| 435 |
$currentcomponent->addguielem($section, new gui_textbox('connect', $rate_connect, 'Connection cost', 'The cost of the estabilished connections.', '!isFloat()', 'Please enter a valid cost')); |
|---|
| 436 |
$currentcomponent->addguielem($section, new gui_textbox('disconnect', $rate_disconnect, 'Disconnection cost', 'The cost of the disconnections.', '!isFloat()', 'Please enter a valid cost')); |
|---|
| 437 |
$currentcomponent->addguielem($section, new gui_selectbox('schedule_id', $currentcomponent->getoptlist('schedulelist'), $rate_schedule_id, 'Schedule', 'In which schedule this rate valid.', false)); |
|---|
| 438 |
} |
|---|
| 439 |
} |
|---|
| 440 |
|
|---|
| 441 |
function cdrcost_rate_configprocess() { |
|---|
| 442 |
cdrcost_configprocess(cdrcost_rate_add, cdrcost_rate_del, cdrcost_rate_edit); |
|---|
| 443 |
} |
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
function get_cost($uniqueid) { |
|---|
| 450 |
$sql = "SELECT * FROM asteriskcdrdb.cdr WHERE uniqueid = '".$uniqueid."'"; |
|---|
| 451 |
$result = sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 452 |
if (is_array($result) && count($result) == 1) { |
|---|
| 453 |
extract($result[0]); |
|---|
| 454 |
} else { |
|---|
| 455 |
die("There can't be two uniqueid cdr!"); |
|---|
| 456 |
} |
|---|
| 457 |
|
|---|
| 458 |
$result = getdate(strtotime($calldate)); |
|---|
| 459 |
$wday = $result["wday"]; |
|---|
| 460 |
$time = $result["hours"].":".$result["minutes"].":".$result["seconds"]; |
|---|
| 461 |
|
|---|
| 462 |
$sql_sch = "SELECT id FROM call_schedule_part WHERE (weekday = -1 OR weekday = ".$wday.") AND begin <= '".$time."' AND '".$time."' <= end"; |
|---|
| 463 |
$sql_zone = "SELECT id FROM call_zone WHERE '".$dst."' REGEXP pattern"; |
|---|
| 464 |
|
|---|
| 465 |
$sql = "SELECT id FROM call_rate WHERE "; |
|---|
| 466 |
$sql .= "accountcode = '".$accountcode."'"; |
|---|
| 467 |
$sql .= " AND begin <= '".$calldate."' AND '".$calldate."' <= end"; |
|---|
| 468 |
$sql .= " AND LOCATE(trunk,'".$dstchannel."') = 1"; |
|---|
| 469 |
$sql .= " AND schedule_id IN (".$sql_sch.")"; |
|---|
| 470 |
$sql .= " AND zone_id IN (".$sql_zone.")"; |
|---|
| 471 |
$result = sql($sql,"getAll"); |
|---|
| 472 |
$costs = array(); |
|---|
| 473 |
if (is_array($result) && count($result) > 0) { |
|---|
| 474 |
foreach ($result as $rid) { |
|---|
| 475 |
$sql = "SELECT * FROM call_rate WHERE id = ".$rid[0]; |
|---|
| 476 |
$tmp = sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 477 |
extract($tmp[0]); |
|---|
| 478 |
$costs[$rid[0]] = max(ceil($billsec / $block_size) * $block_size, $min_duration) * $rate / 60.0 + $connect + $disconnect; |
|---|
| 479 |
} |
|---|
| 480 |
} |
|---|
| 481 |
return $costs; |
|---|
| 482 |
} |
|---|
| 483 |
|
|---|
| 484 |
function last_uniqueid() { |
|---|
| 485 |
$sql = "SELECT MAX(uniqueid) FROM asteriskcdrdb.cdr WHERE disposition = 'ANSWERED'"; |
|---|
| 486 |
$result = sql($sql,"getAll"); |
|---|
| 487 |
return $result[0][0]; |
|---|
| 488 |
} |
|---|
| 489 |
|
|---|
| 490 |
function getnext_uniqueid($last) { |
|---|
| 491 |
if ($last == '') { |
|---|
| 492 |
$sql = "SELECT value FROM globals WHERE variable = 'CDRCOST_MAX'"; |
|---|
| 493 |
$result = sql($sql,"getAll"); |
|---|
| 494 |
if (is_array($result) && count($result) == 1) { |
|---|
| 495 |
$last = $result[0][0]; |
|---|
| 496 |
} |
|---|
| 497 |
} |
|---|
| 498 |
$sql = "SELECT MIN(uniqueid) FROM asteriskcdrdb.cdr WHERE disposition = 'ANSWERED'"; |
|---|
| 499 |
if ($last <> '') { |
|---|
| 500 |
$sql .= " AND uniqueid > '".$last."'"; |
|---|
| 501 |
} |
|---|
| 502 |
$result = sql($sql,"getAll"); |
|---|
| 503 |
if (is_array($result) && count($result) == 1) { |
|---|
| 504 |
return $result[0][0]; |
|---|
| 505 |
} else { |
|---|
| 506 |
return ''; |
|---|
| 507 |
} |
|---|
| 508 |
} |
|---|
| 509 |
|
|---|
| 510 |
function fill_cdrcost() { |
|---|
| 511 |
$next = getnext_uniqueid(''); |
|---|
| 512 |
while ($next <> '') { |
|---|
| 513 |
|
|---|
| 514 |
$costs = get_cost($next); |
|---|
| 515 |
if (count($costs) > 0) { |
|---|
| 516 |
arsort($costs,SORT_NUMERIC); |
|---|
| 517 |
$rid = key($costs); |
|---|
| 518 |
$cost = current($costs); |
|---|
| 519 |
$sql = "INSERT INTO asteriskcdrdb.cdrcost (uniqueid, rate_id, cost) VALUES ('".$next."', ".$rid.", ".$cost.")"; |
|---|
| 520 |
sql($sql,"query"); |
|---|
| 521 |
} |
|---|
| 522 |
$last = $next; |
|---|
| 523 |
$next = getnext_uniqueid($last); |
|---|
| 524 |
} |
|---|
| 525 |
if ($last <> '') { |
|---|
| 526 |
$sql = "INSERT INTO globals (variable, value) VALUES ('CDRCOST_MAX', '".$last."')"; |
|---|
| 527 |
sql($sql,"query"); |
|---|
| 528 |
} |
|---|
| 529 |
} |
|---|
| 530 |
|
|---|
| 531 |
function cdrcost_maint_add($name) { |
|---|
| 532 |
|
|---|
| 533 |
//sql($sql,"query"); |
|---|
| 534 |
} |
|---|
| 535 |
|
|---|
| 536 |
function cdrcost_maint_del($name) { |
|---|
| 537 |
|
|---|
| 538 |
//sql($sql,"query"); |
|---|
| 539 |
} |
|---|
| 540 |
|
|---|
| 541 |
function cdrcost_maint_list() { |
|---|
| 542 |
|
|---|
| 543 |
//return sql($sql,"getAll"); |
|---|
| 544 |
} |
|---|
| 545 |
|
|---|
| 546 |
function cdrcost_maint_configpageinit($dispnum) { |
|---|
| 547 |
} |
|---|
| 548 |
|
|---|
| 549 |
function cdrcost_maint_configpageload() { |
|---|
| 550 |
} |
|---|
| 551 |
|
|---|
| 552 |
function cdrcost_maint_configprocess() { |
|---|
| 553 |
} |
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
?> |
|---|
| 559 |
|
|---|