| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
function directory_configpageload_ivr() { |
|---|
| 4 |
global $currentcomponent, $display; |
|---|
| 5 |
if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'add' || $_REQUEST['action'] == 'edit')) { |
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
$currentcomponent->addgeneralarrayitem('directdial_help', 'directory', |
|---|
| 9 |
_('Tied to a Directory allowing all entries in that directory to be dialed directly, as they appear in the directory')); |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
foreach ((array) directory_list() as $dir) { |
|---|
| 13 |
$name = $dir['dirname'] ? $dir['dirname'] : 'Directory ' . $dir['id']; |
|---|
| 14 |
$currentcomponent->addoptlistitem('directdial', $dir['id'], $name); |
|---|
| 15 |
} |
|---|
| 16 |
} |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
function directory_configpageload() { |
|---|
| 20 |
global $currentcomponent, $display; |
|---|
| 21 |
if ($display == 'directory' && (isset($_REQUEST['action']) && $_REQUEST['action']=='add'|| isset($_REQUEST['id']) && $_REQUEST['id']!='')) { |
|---|
| 22 |
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') { |
|---|
| 23 |
$currentcomponent->addguielem('_top', new gui_pageheading('title', _('Add Directory')), 0); |
|---|
| 24 |
|
|---|
| 25 |
$deet = array('dirname', 'description', 'repeat_loops', 'announcement', |
|---|
| 26 |
'repeat_recording', 'invalid_recording', |
|---|
| 27 |
'callid_prefix', 'alert_info', 'invalid_destination', 'retivr', |
|---|
| 28 |
'say_extension', 'id'); |
|---|
| 29 |
|
|---|
| 30 |
foreach ($deet as $d) { |
|---|
| 31 |
switch ($d){ |
|---|
| 32 |
case 'repeat_loops'; |
|---|
| 33 |
$dir[$d] = 2; |
|---|
| 34 |
break; |
|---|
| 35 |
case 'announcement': |
|---|
| 36 |
case 'repeat_recording': |
|---|
| 37 |
case 'invalid_recording': |
|---|
| 38 |
$dir[$d] = 0; |
|---|
| 39 |
break; |
|---|
| 40 |
default: |
|---|
| 41 |
$dir[$d] = ''; |
|---|
| 42 |
break; |
|---|
| 43 |
} |
|---|
| 44 |
} |
|---|
| 45 |
} else { |
|---|
| 46 |
$dir = directory_get_dir_details($_REQUEST['id']); |
|---|
| 47 |
$label = sprintf(_("Edit Directory: %s"), $dir['dirname'] ? $dir['dirname'] : 'ID '.$dir['id']); |
|---|
| 48 |
$def_dir = directory_get_default_dir(); |
|---|
| 49 |
if ($dir['id'] == $def_dir) { |
|---|
| 50 |
$label .= ' ' . _("[SYSTEM DEFAULT]"); |
|---|
| 51 |
} |
|---|
| 52 |
$currentcomponent->addguielem('_top', new gui_pageheading('title', $label), 0); |
|---|
| 53 |
|
|---|
| 54 |
$usage_list = framework_display_destination_usage(directory_getdest($dir['id'])); |
|---|
| 55 |
$usage_list_text = isset($usage_list['text']) ? $usage_list['text'] : ''; |
|---|
| 56 |
$usage_list_tooltip = isset($usage_list['tooltip']) ? $usage_list['tooltip'] : ''; |
|---|
| 57 |
if (!empty($usage_list)) { |
|---|
| 58 |
$currentcomponent->addguielem('_top', new gui_link_label('usage', $usage_list_text, $usage_list_tooltip), 0); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
$label = sprintf(_("Delete Directory %s"), $dir['dirname'] ? $dir['dirname'] : $dir['id']); |
|---|
| 62 |
$label = '<span><img width="16" height="16" border="0" title="' |
|---|
| 63 |
. $label . '" alt="" src="images/core_delete.png"/> ' . $label . '</span>'; |
|---|
| 64 |
$currentcomponent->addguielem('_top', new gui_link('del', $label, $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '&action=delete', true, false), 0); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
$gen_section = _('Directory General Options'); |
|---|
| 68 |
$currentcomponent->addguielem($gen_section, new gui_textbox('dirname', stripslashes($dir['dirname']), _('Directory Name'), _('Name of this directory.'))); |
|---|
| 69 |
$currentcomponent->addguielem($gen_section, new gui_textbox('description', stripslashes($dir['description']), _('Directory Description'), _('Description of this directory.'))); |
|---|
| 70 |
$currentcomponent->addguielem($gen_section, new gui_textbox('callid_prefix', stripslashes($dir['callid_prefix']), _('CallerID Name Prefix'), _('Prefix to be appended to current CallerID Name.'))); |
|---|
| 71 |
$currentcomponent->addguielem($gen_section, new gui_textbox('alert_info', stripslashes($dir['alert_info']), _('Alert Info'), _('ALERT_INFO to be sent when called from this Directory. Can be used for distinctive ring for SIP devices.'))); |
|---|
| 72 |
|
|---|
| 73 |
$section = _('Directory Options (DTMF)'); |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
$currentcomponent->addoptlistitem('recordings', 0, _('Default')); |
|---|
| 77 |
foreach(recordings_list() as $r){ |
|---|
| 78 |
$currentcomponent->addoptlistitem('recordings', $r['id'], $r['displayname']); |
|---|
| 79 |
} |
|---|
| 80 |
$currentcomponent->setoptlistopts('recordings', 'sort', false); |
|---|
| 81 |
|
|---|
| 82 |
for($i=0; $i <11; $i++){ |
|---|
| 83 |
$currentcomponent->addoptlistitem('repeat_loops', $i, $i); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
$currentcomponent->addguielem($section, new gui_selectbox('announcement', $currentcomponent->getoptlist('recordings'), $dir['announcement'], _('Announcement'), _('Greeting to be played on entry to the directory.'), false)); |
|---|
| 88 |
$currentcomponent->addguielem($section, new gui_selectbox('repeat_loops', $currentcomponent->getoptlist('repeat_loops'), $dir['repeat_loops'], _('Invalid Retries'), _('Number of times to retry when receiving an invalid/unmatched response from the caller'), false)); |
|---|
| 89 |
$currentcomponent->addguielem($section, new gui_selectbox('repeat_recording', $currentcomponent->getoptlist('recordings'), $dir['repeat_recording'], _('Invalid Retry Recording'), _('Prompt to be played when an invalid/unmatched response is received, before prompting the caller to try again'), false)); |
|---|
| 90 |
$currentcomponent->addguielem($section, new gui_selectbox('invalid_recording', $currentcomponent->getoptlist('recordings'), $dir['invalid_recording'], _('Invalid Recording'), _('Prompt to be played before sending the caller to an alternate destination due to the caller pressing 0 or receiving the maximum amount of invalid/unmatched responses (as determined by Invalid Retries)'), false)); |
|---|
| 91 |
$currentcomponent->addguielem($section, new gui_drawselects('invalid_destination', 0, $dir['invalid_destination'], _('Invalid Destination'), _('Destination to send the call to after Invalid Recording is played.'), false)); |
|---|
| 92 |
$currentcomponent->addguielem($section, new gui_checkbox('retivr', $dir['retivr'], _('Return to IVR'), _('When selected, if the call passed through an IVR that had "Return to IVR" selected, the call will be returned there instead of the Invalid destination.'),true)); |
|---|
| 93 |
$currentcomponent->addguielem($section, new gui_checkbox('say_extension', $dir['say_extension'], _('Announce Extension'), _('When checked, the extension number being transferred to will be announced prior to the transfer'),true)); |
|---|
| 94 |
$currentcomponent->addguielem($section, new gui_hidden('id', $dir['id'])); |
|---|
| 95 |
$currentcomponent->addguielem($section, new gui_hidden('action', 'edit')); |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
$section = _('Directory Entries'); |
|---|
| 99 |
|
|---|
| 100 |
$currentcomponent->addguielem($section, new guielement('rawhtml', directory_draw_entries($dir['id']), '')); |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
function directory_configpageinit($pagename) { |
|---|
| 105 |
global $currentcomponent; |
|---|
| 106 |
if($pagename == 'directory'){ |
|---|
| 107 |
$currentcomponent->addprocessfunc('directory_configprocess'); |
|---|
| 108 |
$currentcomponent->addguifunc('directory_configpageload'); |
|---|
| 109 |
return true; |
|---|
| 110 |
} |
|---|
| 111 |
if($pagename == 'ivr'){ |
|---|
| 112 |
$currentcomponent->addguifunc('directory_configpageload_ivr'); |
|---|
| 113 |
return true; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
if ($pagename != 'users' && $pagename != 'extensions') { |
|---|
| 118 |
return true; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; |
|---|
| 122 |
$extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null; |
|---|
| 123 |
$extension = isset($_REQUEST['extension']) ? $_REQUEST['extension'] : null; |
|---|
| 124 |
$tech_hardware = isset($_REQUEST['tech_hardware']) ? $_REQUEST['tech_hardware'] : null; |
|---|
| 125 |
|
|---|
| 126 |
if ($tech_hardware != null || $pagename == 'users') { |
|---|
| 127 |
directory_applyhooks(); |
|---|
| 128 |
$currentcomponent->addprocessfunc('directory_configprocess_exten', 8); |
|---|
| 129 |
} elseif ($action == "add") { |
|---|
| 130 |
|
|---|
| 131 |
$currentcomponent->addprocessfunc('directory_configprocess_exten', 8); |
|---|
| 132 |
} elseif ($extdisplay != '') { |
|---|
| 133 |
|
|---|
| 134 |
directory_applyhooks(); |
|---|
| 135 |
$currentcomponent->addprocessfunc('directory_configprocess_exten', 8); |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
function directory_configprocess(){ |
|---|
| 141 |
if($_REQUEST['display'] == 'directory'){ |
|---|
| 142 |
global $db,$amp_conf; |
|---|
| 143 |
|
|---|
| 144 |
$requestvars = array('id','dirname','description','announcement', |
|---|
| 145 |
'callid_prefix','alert_info','repeat_loops', |
|---|
| 146 |
'repeat_recording','invalid_recording', |
|---|
| 147 |
'invalid_destination','retivr','say_extension'); |
|---|
| 148 |
foreach($requestvars as $var){ |
|---|
| 149 |
$vars[$var] = isset($_REQUEST[$var]) ? $_REQUEST[$var] : ''; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
|---|
| 153 |
$entries = isset($_REQUEST['entries']) ? $_REQUEST['entries'] : ''; |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
switch($action){ |
|---|
| 157 |
case 'edit': |
|---|
| 158 |
|
|---|
| 159 |
$vars['invalid_destination'] = $_REQUEST[$_REQUEST[$_REQUEST['invalid_destination']].str_replace('goto','',$_REQUEST['invalid_destination'])]; |
|---|
| 160 |
$vars['id'] = directory_save_dir_details($vars); |
|---|
| 161 |
directory_save_dir_entries($vars['id'],$entries); |
|---|
| 162 |
needreload(); |
|---|
| 163 |
redirect_standard_continue('id'); |
|---|
| 164 |
break; |
|---|
| 165 |
case 'delete': |
|---|
| 166 |
directory_delete($vars['id']); |
|---|
| 167 |
needreload(); |
|---|
| 168 |
redirect_standard_continue(); |
|---|
| 169 |
break; |
|---|
| 170 |
} |
|---|
| 171 |
} |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
function directory_get_config($engine) { |
|---|
| 175 |
global $ext,$db; |
|---|
| 176 |
switch ($engine) { |
|---|
| 177 |
case 'asterisk': |
|---|
| 178 |
$sql = 'SELECT id,dirname,say_extension FROM directory_details ORDER BY dirname'; |
|---|
| 179 |
$results=sql($sql,'getAll',DB_FETCHMODE_ASSOC); |
|---|
| 180 |
if($results){ |
|---|
| 181 |
$c = 'directory'; |
|---|
| 182 |
|
|---|
| 183 |
// directory basis. (Otherwise we could have consolidated this into a call extension) |
|---|
| 184 |
foreach ($results as $row) { |
|---|
| 185 |
$ext->add($c, $row['id'], '', new ext_answer('')); |
|---|
| 186 |
$ext->add($c, $row['id'], '', new ext_wait('1')); |
|---|
| 187 |
$ext->add($c, $row['id'], '', new ext_agi('directory.agi,dir=' . $row['id'] . ',keypress=${keypress}')); |
|---|
| 188 |
if ($row['say_extension']) { |
|---|
| 189 |
$ext->add($c, $row['id'], '', new ext_playback('pls-hold-while-try&to-extension')); |
|---|
| 190 |
$ext->add($c, $row['id'], '', new ext_saydigits('${DIR_DIAL}')); |
|---|
| 191 |
} |
|---|
| 192 |
$ext->add($c, $row['id'], 'dial-'.$row['id'], new ext_ringing()); |
|---|
| 193 |
$ext->add($c, $row['id'], '', new ext_goto('1','${DIR_DIAL}','from-internal')); |
|---|
| 194 |
} |
|---|
| 195 |
$ext->add($c, 'invalid', 'invalid', new ext_playback('${DIR_INVALID_RECORDING}')); |
|---|
| 196 |
$ext->add($c, 'invalid', '', new ext_ringing()); |
|---|
| 197 |
$ext->add($c, 'invalid', '', new ext_goto('${DIR_INVALID_PRI}','${DIR_INVALID_EXTEN}','${DIR_INVALID_CONTEXT}')); |
|---|
| 198 |
$ext->add($c, 'retivr', 'retivr', new ext_playback('${DIR_INVALID_RECORDING}')); |
|---|
| 199 |
$ext->add($c, 'retivr', '', new ext_goto('1','return','${IVR_CONTEXT}')); |
|---|
| 200 |
$ext->add($c, 'h', '', new ext_macro('hangupcall')); |
|---|
| 201 |
} |
|---|
| 202 |
break; |
|---|
| 203 |
} |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
function directory_list() { |
|---|
| 207 |
$sql='SELECT id,dirname FROM directory_details ORDER BY dirname'; |
|---|
| 208 |
$results=sql($sql, 'getAll', DB_FETCHMODE_ASSOC); |
|---|
| 209 |
return $results; |
|---|
| 210 |
} |
|---|
| 211 |
|
|---|
| 212 |
function directory_get_dir_entries($id){ |
|---|
| 213 |
global $db; |
|---|
| 214 |
if ($id == '') { |
|---|
| 215 |
return array(); |
|---|
| 216 |
} |
|---|
| 217 |
$id = $db->escapeSimple($id); |
|---|
| 218 |
$sql = "SELECT a.name, a.type, a.audio, a.dial, a.foreign_id, a.e_id, b.name foreign_name, IF(a.name != \"\",a.name,b.name) realname |
|---|
| 219 |
FROM directory_entries a LEFT JOIN users b ON a.foreign_id = b.extension WHERE id = $id ORDER BY realname"; |
|---|
| 220 |
$results = sql($sql,'getAll',DB_FETCHMODE_ASSOC); |
|---|
| 221 |
return $results; |
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
function directory_get_dir_details($id){ |
|---|
| 225 |
global $db; |
|---|
| 226 |
$clean_id = $db->escapeSimple($id); |
|---|
| 227 |
$sql = "SELECT * FROM directory_details WHERE ID = $clean_id"; |
|---|
| 228 |
$row = sql($sql,'getRow',DB_FETCHMODE_ASSOC); |
|---|
| 229 |
return $row; |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
function directory_delete($id){ |
|---|
| 233 |
global $db; |
|---|
| 234 |
$id = $db->escapeSimple($id); |
|---|
| 235 |
|
|---|
| 236 |
if (directory_get_default_dir() == $id) { |
|---|
| 237 |
directory_save_default_dir(''); |
|---|
| 238 |
} |
|---|
| 239 |
sql("DELETE FROM directory_entries WHERE id = $id"); |
|---|
| 240 |
sql("DELETE FROM directory_details WHERE id = $id"); |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
function directory_destinations(){ |
|---|
| 244 |
global $db; |
|---|
| 245 |
$sql = 'SELECT id,dirname FROM directory_details ORDER BY dirname'; |
|---|
| 246 |
$results = sql($sql,'getAll',DB_FETCHMODE_ASSOC); |
|---|
| 247 |
|
|---|
| 248 |
foreach($results as $row){ |
|---|
| 249 |
$row['dirname'] = ($row['dirname'])?$row['dirname']:'Directory '.$row['id'] ; |
|---|
| 250 |
$extens[] = array('destination' => 'directory,' . $row['id'] . ',1', 'description' => $row['dirname'], 'category' => _('Directory')); |
|---|
| 251 |
} |
|---|
| 252 |
return isset($extens)?$extens:null; |
|---|
| 253 |
} |
|---|
| 254 |
|
|---|
| 255 |
function directory_draw_entries_table_header_directory() { |
|---|
| 256 |
return array(_('Name'), _('Name Announcement'), _('Dial')); |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
function directory_draw_entries($id){ |
|---|
| 260 |
$sql='SELECT id,name FROM directory_entries ORDER BY name'; |
|---|
| 261 |
$results = sql($sql,'getAll',DB_FETCHMODE_ASSOC); |
|---|
| 262 |
$html = ''; |
|---|
| 263 |
$html .= '<table id="dir_entries_tbl" class="alt_table">'; |
|---|
| 264 |
$headers = mod_func_iterator('draw_entries_table_header_directory'); |
|---|
| 265 |
|
|---|
| 266 |
$html .= '<thead><tr>'; |
|---|
| 267 |
foreach ($headers as $mod => $header) { |
|---|
| 268 |
foreach ($header as $h) { |
|---|
| 269 |
if(is_array($h)) { |
|---|
| 270 |
$html .= '<th ' . $h['attr'] . '/>'; |
|---|
| 271 |
$html .= $h['val']; |
|---|
| 272 |
$html .= '</th>'; |
|---|
| 273 |
} else { |
|---|
| 274 |
$html .= '<th>' . $h . '</th>'; |
|---|
| 275 |
|
|---|
| 276 |
} |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
} |
|---|
| 280 |
$html .= '</tr></thead>'; |
|---|
| 281 |
|
|---|
| 282 |
$newuser = '<select id="addusersel">'; |
|---|
| 283 |
$newuser .= '<option value="none" selected> == '._('Choose One').' == </option>'; |
|---|
| 284 |
$newuser .= '<option value="all">'._('All Users').'</option>'; |
|---|
| 285 |
$newuser .= '<option value="|">'._('Custom').'</option>'; |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
foreach((array) core_users_list() as $user){ |
|---|
| 289 |
$newuser .= '<option value="'.$user[0].'|'.$user[1].'">('.$user[0].') '.$user[1]."</option>\n"; |
|---|
| 290 |
} |
|---|
| 291 |
$newuser .= '</select>'; |
|---|
| 292 |
$html .= '<tfoot><tr><td id="addbut"><a href="#" class="info"><img src="images/core_add.png" name="image" style="border:none;cursor:pointer;" /><span>'._('Add new entry.').'</span></a></td><td colspan="3"id="addrow">'.$newuser.'</td></tr></tfoot>'; |
|---|
| 293 |
$html .= '<tbody>'; |
|---|
| 294 |
$entries = directory_get_dir_entries($id); |
|---|
| 295 |
foreach($entries as $e){ |
|---|
| 296 |
$realid = $e['type'] == 'custom' ? 'custom' : $e['foreign_id']; |
|---|
| 297 |
$foreign_name = $e['foreign_name'] == '' ? 'Custom Entry' : $e['foreign_name']; |
|---|
| 298 |
$html .= directory_draw_entries_tr($id, $realid, $e['name'], $foreign_name, $e['audio'], $e['dial'], $e['e_id']); |
|---|
| 299 |
} |
|---|
| 300 |
$html .= '</tbody></table>'; |
|---|
| 301 |
return $html; |
|---|
| 302 |
} |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
function directory_draw_entries_tr($id, $realid, $name = '',$foreign_name, $audio = '',$num = '',$e_id = '', $reuse_audio = false){ |
|---|
| 306 |
global $amp_conf, $directory_draw_recordings_list, $audio_select; |
|---|
| 307 |
if (!$directory_draw_recordings_list) { |
|---|
| 308 |
$directory_draw_recordings_list = recordings_list(); |
|---|
| 309 |
} |
|---|
| 310 |
$e_id = $e_id ? $e_id : directory_get_next_id($realid); |
|---|
| 311 |
if (!$audio_select || !$reuse_audio) { |
|---|
| 312 |
unset($audio_select); |
|---|
| 313 |
$audio_select = '<select name="entries['.$e_id.'][audio]">'; |
|---|
| 314 |
$audio_select .= '<option value="vm" '.(($audio=='vm')?'SELECTED':'').'>'._('Voicemail Greeting').'</option>'; |
|---|
| 315 |
$audio_select .= '<option value="tts" '.(($audio=='tts')?'SELECTED':'').'>'._('Text to Speech').'</option>'; |
|---|
| 316 |
$audio_select .= '<option value="spell" '.(($audio=='spell')?'SELECTED':'').'>'._('Spell Name').'</option>'; |
|---|
| 317 |
$audio_select .= '<optgroup label="'._('System Recordings:').'">'; |
|---|
| 318 |
foreach($directory_draw_recordings_list as $r){ |
|---|
| 319 |
$audio_select .= '<option value="' . $r['id'] . '" ' . (($audio == $r['id']) ? 'SELECTED' : '') . '>' . $r['displayname'] . '</option>'; |
|---|
| 320 |
} |
|---|
| 321 |
$audio_select .= '</select>'; |
|---|
| 322 |
} |
|---|
| 323 |
|
|---|
| 324 |
if ($realid != 'custom') { |
|---|
| 325 |
$user_type = (isset($amp_conf['AMPEXTENSION']) && $amp_conf['AMPEXTENSION']) == 'deviceanduser' ? 'user' : 'extension'; |
|---|
| 326 |
$tlabel = sprintf(_("Edit %s: %s"), $user_type ,$realid); |
|---|
| 327 |
$label = '<span><img width="16" height="16" border="0" title="'.$tlabel.'" alt="" src="images/user_edit.png"/> </span>'; |
|---|
| 328 |
$user = ' <a href="/admin/config.php?type=setup&display='.$user_type.'s&skip=0&extdisplay='.$realid.'">'.$label.'</a> '; |
|---|
| 329 |
} else { |
|---|
| 330 |
$user = ''; |
|---|
| 331 |
} |
|---|
| 332 |
$delete = '<img src="images/trash.png" style="cursor:pointer;" alt="'._('remove').'" title="'._('Click here to remove this entry').'" class="trash-tr">'; |
|---|
| 333 |
$t1_class = $name == '' ? ' class = "dpt-title" ' : ''; |
|---|
| 334 |
$t2_class = $realid == 'custom' ? ' title="Custom Dialstring" ' : ' title="' . $realid . '" '; |
|---|
| 335 |
if (trim($num) == '') { |
|---|
| 336 |
$t2_class .= '" class = "dpt-title" '; |
|---|
| 337 |
} |
|---|
| 338 |
|
|---|
| 339 |
$td[] = '<input type="hidden" readonly="readonly" name="entries['.$e_id.'][foreign_id]" value="'.$realid.'" /><input type="text" name="entries['.$e_id.'][name]" title="'.$foreign_name.'"'.$t1_class.' value="'.$name.'" />'; |
|---|
| 340 |
$td[] = $audio_select; |
|---|
| 341 |
$td[] = '<input type="text" name="entries['.$e_id.'][num]" '.$t2_class.' value="'.$num.'" />'; |
|---|
| 342 |
$opts = array('id' => $id, 'e_id' => $e_id, 'realid' => $realid, 'name' => $name, 'audio' => $audio, 'num' => $num); |
|---|
| 343 |
|
|---|
| 344 |
$more_td = mod_func_iterator('draw_entries_tr_directory', $opts); |
|---|
| 345 |
foreach ($more_td as $mod) { |
|---|
| 346 |
foreach ($mod as $m){ |
|---|
| 347 |
$td[] = $m; |
|---|
| 348 |
} |
|---|
| 349 |
} |
|---|
| 350 |
|
|---|
| 351 |
$td[] = $delete.$user; |
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
$html = '<tr class="entrie'.$e_id.'">'; |
|---|
| 355 |
foreach ($td as $t) { |
|---|
| 356 |
if (is_array($t)) { |
|---|
| 357 |
$html .= '<td ' . $t['attr'] . '/>'; |
|---|
| 358 |
$html .= $t['val']; |
|---|
| 359 |
$html .= '</td>'; |
|---|
| 360 |
} else { |
|---|
| 361 |
$html .= '<td>' . $t . '</td>'; |
|---|
| 362 |
} |
|---|
| 363 |
} |
|---|
| 364 |
$html .= '</tr>'; |
|---|
| 365 |
return $html; |
|---|
| 366 |
} |
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
function directory_draw_entries_all_users($id){ |
|---|
| 370 |
$html=''; |
|---|
| 371 |
foreach(core_users_list() as $user){ |
|---|
| 372 |
$html .= directory_draw_entries_tr($id, $user[0], '', $user[1], 'vm', '',$id++, true); |
|---|
| 373 |
} |
|---|
| 374 |
return $html; |
|---|
| 375 |
} |
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
function directory_save_default_dir($default_directory) { |
|---|
| 379 |
global $db; |
|---|
| 380 |
|
|---|
| 381 |
if ($default_directory) { |
|---|
| 382 |
sql("REPLACE INTO `admin` (`variable`, value) VALUES ('default_directory', '$default_directory')"); |
|---|
| 383 |
} else { |
|---|
| 384 |
sql("DELETE FROM `admin` WHERE `variable` = 'default_directory'"); |
|---|
| 385 |
} |
|---|
| 386 |
} |
|---|
| 387 |
|
|---|
| 388 |
function directory_get_default_dir() { |
|---|
| 389 |
global $db; |
|---|
| 390 |
|
|---|
| 391 |
$ret = sql("SELECT value FROM `admin` WHERE `variable` = 'default_directory'", 'getOne'); |
|---|
| 392 |
return $ret ? $ret : ''; |
|---|
| 393 |
|
|---|
| 394 |
} |
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
function directory_save_dir_details($vals){ |
|---|
| 399 |
global $db, $amp_conf; |
|---|
| 400 |
|
|---|
| 401 |
foreach($vals as $key => $value) { |
|---|
| 402 |
$vals[$key] = $db->escapeSimple($value); |
|---|
| 403 |
} |
|---|
| 404 |
|
|---|
| 405 |
if ($vals['id']) { |
|---|
| 406 |
$sql = 'REPLACE INTO directory_details (id,dirname,description,announcement, |
|---|
| 407 |
callid_prefix,alert_info,repeat_loops,repeat_recording, |
|---|
| 408 |
invalid_recording,invalid_destination,retivr,say_extension) |
|---|
| 409 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|---|
| 410 |
$foo = $db->query($sql,$vals); |
|---|
| 411 |
if(DB::IsError($foo)) { |
|---|
| 412 |
die_freepbx(print_r($vals,true).' '.$foo->getDebugInfo()); |
|---|
| 413 |
} |
|---|
| 414 |
} else { |
|---|
| 415 |
unset($vals['id']); |
|---|
| 416 |
$sql = 'INSERT INTO directory_details (dirname,description,announcement, |
|---|
| 417 |
callid_prefix,alert_info,repeat_loops,repeat_recording, |
|---|
| 418 |
invalid_recording,invalid_destination,retivr,say_extension) |
|---|
| 419 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
|---|
| 420 |
$foo = $db->query($sql,$vals); |
|---|
| 421 |
if(DB::IsError($foo)) { |
|---|
| 422 |
die_freepbx(print_r($vals,true).' '.$foo->getDebugInfo()); |
|---|
| 423 |
} |
|---|
| 424 |
$sql = ( ($amp_conf["AMPDBENGINE"]=="sqlite3") ? 'SELECT last_insert_rowid()' : 'SELECT LAST_INSERT_ID()'); |
|---|
| 425 |
$vals['id'] = $db->getOne($sql); |
|---|
| 426 |
if (DB::IsError($foo)){ |
|---|
| 427 |
die_freepbx($foo->getDebugInfo()); |
|---|
| 428 |
} |
|---|
| 429 |
} |
|---|
| 430 |
|
|---|
| 431 |
return $vals['id']; |
|---|
| 432 |
} |
|---|
| 433 |
|
|---|
| 434 |
function directory_save_dir_entries($id,$entries){ |
|---|
| 435 |
global $db; |
|---|
| 436 |
$id = $db->escapeSimple($id); |
|---|
| 437 |
sql("DELETE FROM directory_entries WHERE id = $id"); |
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
// if 'dial' is the same as type_id, then delete the 'dial,' leave as default |
|---|
| 441 |
// if 'name' is same as default_name, then delete the 'name,' leave as default |
|---|
| 442 |
if($entries){ |
|---|
| 443 |
$insert=''; |
|---|
| 444 |
|
|---|
| 445 |
foreach($entries as $idx => $row){ |
|---|
| 446 |
if($row['foreign_id'] == 'custom' && trim($row['name']) == '' || $row['foreign_id']==''){ |
|---|
| 447 |
continue; |
|---|
| 448 |
} |
|---|
| 449 |
if ($row['foreign_id'] == 'custom') { |
|---|
| 450 |
$type = 'custom'; |
|---|
| 451 |
$foreign_id = ''; |
|---|
| 452 |
} else { |
|---|
| 453 |
$type = 'user'; |
|---|
| 454 |
$foreign_id = $db->escapeSimple($row['foreign_id']); |
|---|
| 455 |
} |
|---|
| 456 |
$audio = $row['audio'] != '' ? $db->escapeSimple($row['audio']) : ($row['foreign_id'] == 'custom' ? 'tts' : 'vm'); |
|---|
| 457 |
if (!empty($insert)) { |
|---|
| 458 |
$insert .= ','; |
|---|
| 459 |
} |
|---|
| 460 |
$insert.='("'.$id.'","'.$idx.'","'.$db->escapeSimple(trim($row['name'])).'","'.$type.'","'.$foreign_id.'","'.$audio.'","'.$db->escapeSimple(trim($row['num'])).'")'; |
|---|
| 461 |
} |
|---|
| 462 |
sql('INSERT INTO directory_entries (id, e_id, name,type,foreign_id,audio,dial) VALUES '.$insert); |
|---|
| 463 |
} |
|---|
| 464 |
} |
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
function directory_check_default($extension) { |
|---|
| 470 |
$def_dir = directory_get_default_dir(); |
|---|
| 471 |
$sql = "SELECT foreign_id FROM directory_entries WHERE foreign_id = '$extension' AND id = '$def_dir' LIMIT 1"; |
|---|
| 472 |
$results = sql($sql,"getAll"); |
|---|
| 473 |
return count($results); |
|---|
| 474 |
} |
|---|
| 475 |
|
|---|
| 476 |
function directory_set_default($extension, $value) { |
|---|
| 477 |
$default_directory_id = directory_get_default_dir(); |
|---|
| 478 |
if ($default_directory_id == '') { |
|---|
| 479 |
return false; |
|---|
| 480 |
} |
|---|
| 481 |
if ($value) { |
|---|
| 482 |
$entries = sql("SELECT COUNT(*) FROM directory_entries WHERE id = $default_directory_id AND foreign_id = '$extension'","getOne"); |
|---|
| 483 |
if (!$entries) { |
|---|
| 484 |
sql("INSERT INTO directory_entries (id, foreign_id) VALUES ($default_directory_id, '$extension')"); |
|---|
| 485 |
} |
|---|
| 486 |
} else { |
|---|
| 487 |
sql("DELETE FROM directory_entries WHERE id = $default_directory_id AND foreign_id = '$extension'"); |
|---|
| 488 |
} |
|---|
| 489 |
} |
|---|
| 490 |
|
|---|
| 491 |
function directory_applyhooks() { |
|---|
| 492 |
global $currentcomponent; |
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
// displaying stuff on the page. |
|---|
| 496 |
$currentcomponent->addoptlistitem('directory_group', '0', dgettext('directory',_("Exclude"))); |
|---|
| 497 |
$currentcomponent->addoptlistitem('directory_group', '1', dgettext('directory',_("Include"))); |
|---|
| 498 |
$currentcomponent->setoptlistopts('directory_group', 'sort', false); |
|---|
| 499 |
|
|---|
| 500 |
$currentcomponent->addguifunc('directory_configpageload_exten'); |
|---|
| 501 |
} |
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
function directory_configpageload_exten() { |
|---|
| 505 |
global $currentcomponent; |
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
$action = isset($_REQUEST['action']) ? $_REQUEST['action']:null; |
|---|
| 509 |
$extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay']:null; |
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
if ($action != 'del') { |
|---|
| 513 |
|
|---|
| 514 |
$default_directory_id = directory_get_default_dir(); |
|---|
| 515 |
$section = _("Default Group Inclusion"); |
|---|
| 516 |
if ($default_directory_id != "") { |
|---|
| 517 |
$in_default_directory = directory_check_default($extdisplay); |
|---|
| 518 |
$currentcomponent->addguielem($section, new gui_selectbox('in_default_directory', $currentcomponent->getoptlist('directory_group'), $in_default_directory, _('Default Directory'), _('You can include or exclude this extension/user from being part of the default directory when creating or editing.'), false)); |
|---|
| 519 |
} |
|---|
| 520 |
} |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
function directory_configprocess_exten() { |
|---|
| 524 |
global $db; |
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
// |
|---|
| 528 |
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; |
|---|
| 529 |
$ext = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null; |
|---|
| 530 |
$extn = isset($_REQUEST['extension']) ? $_REQUEST['extension'] : null; |
|---|
| 531 |
$in_default_directory = isset($_REQUEST['in_default_directory']) ? $_REQUEST['in_default_directory'] : false; |
|---|
| 532 |
|
|---|
| 533 |
$extdisplay = ($ext === '') ? $extn : $ext; |
|---|
| 534 |
|
|---|
| 535 |
if (($action == "add" || $action == "edit")) { |
|---|
| 536 |
if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true) { |
|---|
| 537 |
if ($in_default_directory !== false) { |
|---|
| 538 |
directory_set_default($extdisplay, $in_default_directory); |
|---|
| 539 |
} |
|---|
| 540 |
} |
|---|
| 541 |
} elseif ($extdisplay != '' && $action == "del") { |
|---|
| 542 |
$sql = "DELETE FROM directory_entries WHERE foreign_id = '$extdisplay'"; |
|---|
| 543 |
sql($sql); |
|---|
| 544 |
} |
|---|
| 545 |
} |
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
function directory_check_destinations($dest=true) { |
|---|
| 551 |
global $active_modules; |
|---|
| 552 |
|
|---|
| 553 |
$destlist = array(); |
|---|
| 554 |
if (is_array($dest) && empty($dest)) { |
|---|
| 555 |
return $destlist; |
|---|
| 556 |
} |
|---|
| 557 |
$sql = "SELECT id, dirname, invalid_destination FROM directory_details "; |
|---|
| 558 |
if ($dest !== true) { |
|---|
| 559 |
$sql .= "WHERE invalid_destination in ('".implode("','",$dest)."')"; |
|---|
| 560 |
} |
|---|
| 561 |
$results = sql($sql, "getAll", DB_FETCHMODE_ASSOC); |
|---|
| 562 |
|
|---|
| 563 |
foreach ($results as $result) { |
|---|
| 564 |
$thisdest = $result['invalid_destination']; |
|---|
| 565 |
$thisid = $result['id']; |
|---|
| 566 |
$destlist[] = array( |
|---|
| 567 |
'dest' => $thisdest, |
|---|
| 568 |
'description' => sprintf(_("Directory: %s "), ($result['dirname'] ? $result['dirname'] : $result['id'])), |
|---|
| 569 |
'edit_url' => 'config.php?display=directory&id=' . urlencode($result['id']), |
|---|
| 570 |
); |
|---|
| 571 |
} |
|---|
| 572 |
return $destlist; |
|---|
| 573 |
} |
|---|
| 574 |
|
|---|
| 575 |
function directory_change_destination($old_dest, $new_dest) { |
|---|
| 576 |
$sql = 'UPDATE directory_details SET invalid_destination = "' . $new_dest . '" WHERE invalid_destination = "' . $old_dest . '"'; |
|---|
| 577 |
sql($sql, "query"); |
|---|
| 578 |
} |
|---|
| 579 |
|
|---|
| 580 |
function directory_getdest($id) { |
|---|
| 581 |
return array("directory,$id,1"); |
|---|
| 582 |
} |
|---|
| 583 |
|
|---|
| 584 |
function directory_getdestinfo($dest) { |
|---|
| 585 |
if (substr(trim($dest),0,10) == 'directory,') { |
|---|
| 586 |
$grp = explode(',',$dest); |
|---|
| 587 |
$id = $grp[1]; |
|---|
| 588 |
$thisdir = directory_get_dir_details($id); |
|---|
| 589 |
|
|---|
| 590 |
if (empty($thisdir)) { |
|---|
| 591 |
return array(); |
|---|
| 592 |
} else { |
|---|
| 593 |
return array('description' => sprintf(_("Directory %s: "), ($thisdir['dirname'] ? $thisdir['dirname'] : $id)), |
|---|
| 594 |
'edit_url' => 'config.php?display=directory&id=' . urlencode($id), |
|---|
| 595 |
); |
|---|
| 596 |
} |
|---|
| 597 |
} else { |
|---|
| 598 |
return false; |
|---|
| 599 |
} |
|---|
| 600 |
} |
|---|
| 601 |
|
|---|
| 602 |
function directory_get_next_id($realid) { |
|---|
| 603 |
global $db; |
|---|
| 604 |
$res = sql('SELECT MAX(e_id) FROM directory_entries WHERE id = "' . $realid . '"', 'getOne'); |
|---|
| 605 |
return $res ? $res : 1; |
|---|
| 606 |
} |
|---|
| 607 |
|
|---|
| 608 |
function directory_recordings_usage($recording_id) { |
|---|
| 609 |
global $active_modules; |
|---|
| 610 |
|
|---|
| 611 |
$results = sql("SELECT `id`, `dirname` FROM `directory_details` |
|---|
| 612 |
WHERE `announcement` = '$recording_id' |
|---|
| 613 |
OR `repeat_recording` = '$recording_id' |
|---|
| 614 |
OR `invalid_recording` = '$recording_id'", |
|---|
| 615 |
"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 616 |
if (empty($results)) { |
|---|
| 617 |
return array(); |
|---|
| 618 |
} else { |
|---|
| 619 |
|
|---|
| 620 |
foreach ($results as $result) { |
|---|
| 621 |
$usage_arr[] = array( |
|---|
| 622 |
'url_query' => 'config.php?display=directory&id=' . urlencode($result['id']), |
|---|
| 623 |
'description' => sprintf(_("Directory: %s"), ($result['dirname'] ? $result['dirname'] : $result['id'])), |
|---|
| 624 |
); |
|---|
| 625 |
} |
|---|
| 626 |
return $usage_arr; |
|---|
| 627 |
} |
|---|
| 628 |
} |
|---|
| 629 |
?> |
|---|
| 630 |
|
|---|