| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
function dictate_get_config($engine) { |
|---|
| 4 |
$modulename = 'dictate'; |
|---|
| 5 |
|
|---|
| 6 |
// This generates the dialplan |
|---|
| 7 |
global $ext; |
|---|
| 8 |
global $asterisk_conf; |
|---|
| 9 |
switch($engine) { |
|---|
| 10 |
case "asterisk": |
|---|
| 11 |
if (is_array($featurelist = featurecodes_getModuleFeatures($modulename))) { |
|---|
| 12 |
foreach($featurelist as $item) { |
|---|
| 13 |
$featurename = $item['featurename']; |
|---|
| 14 |
$fname = $modulename.'_'.$featurename; |
|---|
| 15 |
if (function_exists($fname)) { |
|---|
| 16 |
$fcc = new featurecode($modulename, $featurename); |
|---|
| 17 |
$fc = $fcc->getCodeActive(); |
|---|
| 18 |
unset($fcc); |
|---|
| 19 |
|
|---|
| 20 |
if ($fc != '') |
|---|
| 21 |
$fname($fc); |
|---|
| 22 |
} else { |
|---|
| 23 |
$ext->add('from-internal-additional', 'debug', '', new ext_noop($modulename.": No func $fname")); |
|---|
| 24 |
} |
|---|
| 25 |
} |
|---|
| 26 |
} |
|---|
| 27 |
break; |
|---|
| 28 |
} |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
function dictate_dodictate($c) { |
|---|
| 32 |
global $ext; |
|---|
| 33 |
global $asterisk_conf; |
|---|
| 34 |
|
|---|
| 35 |
$id = "app-dictate-record"; // The context to be included |
|---|
| 36 |
|
|---|
| 37 |
$ext->addInclude('from-internal-additional', $id); // Add the include from from-internal |
|---|
| 38 |
$ext->add($id, $c, '', new ext_answer('')); |
|---|
| 39 |
$ext->add($id, $c, '', new ext_macro('user-callerid')); |
|---|
| 40 |
$ext->add($id, $c, '', new ext_NoOp('CallerID is ${AMPUSER}')); |
|---|
| 41 |
$ext->add($id, $c, '', new ext_setvar('DICTENABLED','${DB(AMPUSER/${AMPUSER}/dictate/enabled)}')); |
|---|
| 42 |
$ext->add($id, $c, '', new ext_gotoif('$[$["x${DICTENABLED}"="x"]|$["x${DICTENABLED}"="xdisabled"]]','nodict', 'dictok')); |
|---|
| 43 |
$ext->add($id, $c, 'nodict', new ext_playback('feature-not-avail-line')); |
|---|
| 44 |
$ext->add($id, $c, '', new ext_hangup('')); |
|---|
| 45 |
$ext->add($id, $c, 'dictok', new ext_dictate($asterisk_conf['astvarlibdir'].'/sounds/dictate/${AMPUSER}')); |
|---|
| 46 |
$ext->add($id, $c, '', new ext_macro('hangupcall')); |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
function dictate_senddictate($c) { |
|---|
| 50 |
global $ext; |
|---|
| 51 |
global $asterisk_conf; |
|---|
| 52 |
|
|---|
| 53 |
$id = "app-dictate-send"; // The context to be included |
|---|
| 54 |
$ext->addInclude('from-internal-additional', $id); // Add the include from from-internal |
|---|
| 55 |
$ext->add($id, $c, '', new ext_answer('')); |
|---|
| 56 |
$ext->add($id, $c, '', new ext_macro('user-callerid')); |
|---|
| 57 |
$ext->add($id, $c, '', new ext_NoOp('CallerID is ${AMPUSER}')); |
|---|
| 58 |
$ext->add($id, $c, '', new ext_setvar('DICTENABLED','${DB(AMPUSER/${AMPUSER}/dictate/enabled)}')); |
|---|
| 59 |
$ext->add($id, $c, '', new ext_gotoif('$[$["x${DICTENABLED}"="x"]|$["x${DICTENABLED}"="xdisabled"]]','nodict', 'dictok')); |
|---|
| 60 |
$ext->add($id, $c, 'nodict', new ext_playback('feature-not-avail-line')); |
|---|
| 61 |
$ext->add($id, $c, '', new ext_hangup('')); |
|---|
| 62 |
$ext->add($id, $c, 'dictok', new ext_read('DICTFILE','enter-filename-short')); |
|---|
| 63 |
$ext->add($id, $c, '', new ext_setvar('DICTEMAIL','${DB(AMPUSER/${AMPUSER}/dictate/email)}')); |
|---|
| 64 |
$ext->add($id, $c, '', new ext_setvar('DICTFMT','${DB(AMPUSER/${AMPUSER}/dictate/format)}')); |
|---|
| 65 |
$ext->add($id, $c, '', new ext_setvar('NAME','${DB(AMPUSER/${AMPUSER}/cidname)}')); |
|---|
| 66 |
$ext->add($id, $c, '', new ext_playback('dictation-being-processed')); |
|---|
| 67 |
$ext->add($id, $c, '', new ext_system($asterisk_conf['astvarlibdir'].'/bin/audio-email.pl --file '.$asterisk_conf['astvarlibdir'].'/sounds/dictate/${AMPUSER}/${DICTFILE}.raw --attachment dict-${DICTFILE} --format ${DICTFMT} --to ${DICTEMAIL} --subject "Dictation from ${NAME} Attached"')); |
|---|
| 68 |
$ext->add($id, $c, '', new ext_playback('dictation-sent')); |
|---|
| 69 |
$ext->add($id, $c, '', new ext_macro('hangupcall')); |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
function dictate_configpageinit($pagename) { |
|---|
| 73 |
global $currentcomponent; |
|---|
| 74 |
|
|---|
| 75 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| 76 |
$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| 77 |
$extension = isset($_REQUEST['extension'])?$_REQUEST['extension']:null; |
|---|
| 78 |
$tech_hardware = isset($_REQUEST['tech_hardware'])?$_REQUEST['tech_hardware']:null; |
|---|
| 79 |
|
|---|
| 80 |
// We only want to hook 'users' or 'extensions' pages. |
|---|
| 81 |
if ($pagename != 'users' && $pagename != 'extensions') |
|---|
| 82 |
return true; |
|---|
| 83 |
// On a 'new' user, 'tech_hardware' is set, and there's no extension. Hook into the page. |
|---|
| 84 |
if ($tech_hardware != null || $pagename == 'users') { |
|---|
| 85 |
dictation_applyhooks(); |
|---|
| 86 |
$currentcomponent->addprocessfunc('dictate_configprocess', 8); |
|---|
| 87 |
} elseif ($action=="add") { |
|---|
| 88 |
// We don't need to display anything on an 'add', but we do need to handle returned data. |
|---|
| 89 |
$currentcomponent->addprocessfunc('dictate_configprocess', 8); |
|---|
| 90 |
} elseif ($extdisplay != '') { |
|---|
| 91 |
// We're now viewing an extension, so we need to display _and_ process. |
|---|
| 92 |
dictation_applyhooks(); |
|---|
| 93 |
$currentcomponent->addprocessfunc('dictate_configprocess', 8); |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
function dictation_applyhooks() { |
|---|
| 99 |
global $currentcomponent; |
|---|
| 100 |
|
|---|
| 101 |
$currentcomponent->addoptlistitem('dictena', 'enabled', _('Enabled')); |
|---|
| 102 |
$currentcomponent->addoptlistitem('dictena', 'disabled',_('Disabled')); |
|---|
| 103 |
$currentcomponent->setoptlistopts('dictena', 'sort', false); |
|---|
| 104 |
|
|---|
| 105 |
$currentcomponent->addoptlistitem('dictfmt', 'ogg', 'Ogg Vorbis'); |
|---|
| 106 |
$currentcomponent->addoptlistitem('dictfmt', 'gsm', 'GSM'); |
|---|
| 107 |
$currentcomponent->addoptlistitem('dictfmt', 'wav', 'WAV'); |
|---|
| 108 |
$currentcomponent->setoptlistopts('dictfmt', 'sort', false); |
|---|
| 109 |
// Add the 'process' function - this gets called when the page is loaded, to hook into |
|---|
| 110 |
// displaying stuff on the page. |
|---|
| 111 |
$currentcomponent->addguifunc('dictate_configpageload'); |
|---|
| 112 |
|
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
// This is called before the page is actually displayed, so we can use addguielem(). |
|---|
| 116 |
function dictate_configpageload() { |
|---|
| 117 |
global $currentcomponent; |
|---|
| 118 |
|
|---|
| 119 |
// Init vars from $_REQUEST[] |
|---|
| 120 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| 121 |
$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| 122 |
|
|---|
| 123 |
// Don't display this stuff it it's on a 'This xtn has been deleted' page. |
|---|
| 124 |
if ($action != 'del') { |
|---|
| 125 |
$dibox = dictate_get($extdisplay); |
|---|
| 126 |
// Defaults are in dictate_get, if they're not set. |
|---|
| 127 |
$dodict = $dibox['enabled']; |
|---|
| 128 |
$email = $dibox['email']; |
|---|
| 129 |
$format = $dibox['format']; |
|---|
| 130 |
|
|---|
| 131 |
$section = _('Dictation Services'); |
|---|
| 132 |
$msgInvalidEmail = _('Please enter a valid Email Address'); |
|---|
| 133 |
$currentcomponent->addguielem($section, new gui_selectbox('dictenabled', $currentcomponent->getoptlist('dictena'), $dodict, _('Dictation Service'), '', false)); |
|---|
| 134 |
$currentcomponent->addguielem($section, new gui_selectbox('dictformat', $currentcomponent->getoptlist('dictfmt'), $format, _('Dictation Format'), '', false)); |
|---|
| 135 |
$currentcomponent->addguielem($section, new gui_textbox('dictemail', $email, _('Email Address'), _('The email address that completed dictations are sent to.'), "!isEmail()", $msgInvalidEmail, true)); |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
function dictate_configprocess() { |
|---|
| 140 |
//create vars from the request |
|---|
| 141 |
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| 142 |
$ext = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| 143 |
$extn = isset($_REQUEST['extension'])?$_REQUEST['extension']:null; |
|---|
| 144 |
$dictenabled = isset($_REQUEST['dictenabled'])?$_REQUEST['dictenabled']:null; |
|---|
| 145 |
$dictemail = isset($_REQUEST['dictemail'])?$_REQUEST['dictemail']:null; |
|---|
| 146 |
$dictformat = isset($_REQUEST['dictformat'])?$_REQUEST['dictformat']:null; |
|---|
| 147 |
|
|---|
| 148 |
if ($ext==='') { |
|---|
| 149 |
$extdisplay = $extn; |
|---|
| 150 |
} else { |
|---|
| 151 |
$extdisplay = $ext; |
|---|
| 152 |
} |
|---|
| 153 |
if ($action == "add" || $action == "edit") { |
|---|
| 154 |
if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true) { |
|---|
| 155 |
dictate_update($extdisplay, $dictenabled, $dictformat, $dictemail); |
|---|
| 156 |
} |
|---|
| 157 |
} elseif ($action == "del") { |
|---|
| 158 |
dictate_del($extdisplay); |
|---|
| 159 |
} |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
function dictate_get($xtn) { |
|---|
| 163 |
global $astman; |
|---|
| 164 |
|
|---|
| 165 |
// Retrieve the dictation configuraiton from this user from ASTDB |
|---|
| 166 |
$ena = $astman->database_get("AMPUSER",$xtn."/dictate/enabled"); |
|---|
| 167 |
$format = $astman->database_get("AMPUSER",$xtn."/dictate/format"); |
|---|
| 168 |
$email = $astman->database_get("AMPUSER",$xtn."/dictate/email"); |
|---|
| 169 |
// If it's blank, set it to disabled |
|---|
| 170 |
if (!$ena) { $ena = "disabled"; } |
|---|
| 171 |
// Default format is ogg |
|---|
| 172 |
if (!$format) { $format = "ogg"; } |
|---|
| 173 |
|
|---|
| 174 |
return array('enabled' => $ena, 'format' => $format, 'email' => $email); |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
function dictate_update($ext, $ena, $fmt, $email) { |
|---|
| 178 |
global $astman; |
|---|
| 179 |
|
|---|
| 180 |
if ($ena === 'disabled') { |
|---|
| 181 |
dictate_del($ext); |
|---|
| 182 |
} else { |
|---|
| 183 |
// Update the settings in ASTDB |
|---|
| 184 |
$astman->database_put("AMPUSER",$ext."/dictate/enabled",$ena); |
|---|
| 185 |
$astman->database_put("AMPUSER",$ext."/dictate/format",$fmt); |
|---|
| 186 |
$astman->database_put("AMPUSER",$ext."/dictate/email",$email); |
|---|
| 187 |
} |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
function dictate_del($ext) { |
|---|
| 191 |
global $astman; |
|---|
| 192 |
|
|---|
| 193 |
// Clean up the tree when the user is deleted |
|---|
| 194 |
$astman->database_deltree("AMPUSER/$ext/dictate"); |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
?> |
|---|