| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
global $db; |
|---|
| 4 |
global $amp_conf; |
|---|
| 5 |
|
|---|
| 6 |
$autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT"; |
|---|
| 7 |
$sql = "CREATE TABLE IF NOT EXISTS announcement ( |
|---|
| 8 |
announcement_id integer NOT NULL PRIMARY KEY $autoincrement, |
|---|
| 9 |
description VARCHAR( 50 ), |
|---|
| 10 |
recording VARCHAR( 255 ), |
|---|
| 11 |
allow_skip INT, |
|---|
| 12 |
post_dest VARCHAR( 255 ), |
|---|
| 13 |
return_ivr TINYINT(1) NOT NULL DEFAULT 0, |
|---|
| 14 |
noanswer TINYINT(1) NOT NULL DEFAULT 0, |
|---|
| 15 |
repeat_msg VARCHAR(2) NOT NULL DEFAULT '' |
|---|
| 16 |
)"; |
|---|
| 17 |
$check = $db->query($sql); |
|---|
| 18 |
if(DB::IsError($check)) { |
|---|
| 19 |
die_freepbx("Can not create annoucment table"); |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
$sql = "SELECT return_ivr FROM announcement"; |
|---|
| 24 |
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 25 |
if(DB::IsError($check)) { |
|---|
| 26 |
|
|---|
| 27 |
$sql = "ALTER TABLE announcement ADD return_ivr TINYINT(1) NOT NULL DEFAULT 0;"; |
|---|
| 28 |
$result = $db->query($sql); |
|---|
| 29 |
if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
$sql = "SELECT noanswer FROM announcement"; |
|---|
| 34 |
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 35 |
if(DB::IsError($check)) { |
|---|
| 36 |
|
|---|
| 37 |
$sql = "ALTER TABLE announcement ADD noanswer TINYINT(1) NOT NULL DEFAULT 0;"; |
|---|
| 38 |
$result = $db->query($sql); |
|---|
| 39 |
if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
$repeat = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "repeat":"`repeat`"; |
|---|
| 44 |
$sql = "SELECT $repeat FROM announcement"; |
|---|
| 45 |
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 46 |
if(! DB::IsError($check)) { |
|---|
| 47 |
|
|---|
| 48 |
// |
|---|
| 49 |
$sql = "ALTER TABLE announcement CHANGE $repeat repeat_msg VARCHAR( 2 ) NOT NULL DEFAULT '' ;"; |
|---|
| 50 |
$result = $db->query($sql); |
|---|
| 51 |
if(DB::IsError($result)) { |
|---|
| 52 |
die_freepbx($result->getDebugInfo()); |
|---|
| 53 |
} |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
$sql = "SELECT repeat_msg FROM announcement"; |
|---|
| 58 |
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 59 |
if(DB::IsError($check)) { |
|---|
| 60 |
|
|---|
| 61 |
$sql = "ALTER TABLE announcement ADD repeat_msg VARCHAR(2) NOT NULL DEFAULT '';"; |
|---|
| 62 |
$result = $db->query($sql); |
|---|
| 63 |
if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
$results = array(); |
|---|
| 67 |
$sql = "SELECT announcement_id, post_dest FROM announcement"; |
|---|
| 68 |
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC); |
|---|
| 69 |
if (!DB::IsError($results)) { |
|---|
| 70 |
foreach ($results as $result) { |
|---|
| 71 |
$old_dest = $result['post_dest']; |
|---|
| 72 |
$announcement_id = $result['announcement_id']; |
|---|
| 73 |
|
|---|
| 74 |
$new_dest = merge_ext_followme(trim($old_dest)); |
|---|
| 75 |
if ($new_dest != $old_dest) { |
|---|
| 76 |
$sql = "UPDATE announcement SET post_dest = '$new_dest' WHERE announcement_id = $announcement_id AND post_dest = '$old_dest'"; |
|---|
| 77 |
$results = $db->query($sql); |
|---|
| 78 |
if(DB::IsError($results)) { |
|---|
| 79 |
die_freepbx($results->getMessage()); |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
?> |
|---|
| 86 |
|
|---|