function daynight_toggle() { global $ext; global $amp_conf; global $version; $list = daynight_list(); $passwords = daynight_passwords(); $got_code = false; $day_recording = daynight_recording('day'); $night_recording = daynight_recording('night'); $id = "app-daynight-toggle"; // The context to be included foreach ($list as $item) { $index = $item['ext']; $fcc = new featurecode('daynight', 'toggle-mode-' . $index); $c = $fcc->getCodeActive(); unset($fcc); if (!$c) { continue; } $got_code = true; if ($amp_conf['USEDEVSTATE']) { $ext->addHint($id, $c, 'Custom:DAYNIGHT' . $index); } $ext->add($id, $c, '', new ext_macro('user-callerid')); $ext->add($id, $c, '', new ext_answer('')); $ext->add($id, $c, '', new ext_wait('1')); if (isset($passwords[$index]) && trim($passwords[$index]) != "" && ctype_digit(trim($passwords[$index]))) { $ext->add($id, $c, '', new ext_authenticate($passwords[$index])); } $ext->add($id, $c, '', new ext_setvar('INDEXES', $index)); // Depends on featurecode.sln which is provided in core's sound files // $day_file = "beep&silence/1&featurecode&digits/{$index}&de-activated"; $night_file = "beep&silence/1&featurecode&digits/{$index}&activated"; if (function_exists('recordings_get_file')) { if ($day_recording[$index] != 0) { $day_file = recordings_get_file($day_recording[$index]); } if ($night_recording[$index] != 0) { $night_file = recordings_get_file($night_recording[$index]); } } $ext->add($id, $c, '', new ext_setvar('DAYREC', $day_file)); $ext->add($id, $c, '', new ext_setvar('NIGHTREC', $night_file)); $ext->add($id, $c, '', new ext_goto($id . ',s,1')); } if ($got_code) { $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal $fcc = new featurecode('daynight', 'toggle-mode-all'); $c = $fcc->getCodeActive(); unset($fcc); if ($c) { $ext->add($id, $c, '', new ext_macro('user-callerid')); $ext->add($id, $c, '', new ext_goto($id . ',${EXTEN}*${AMPUSER},1')); } $c = 's'; /* If any are on, all will be turned off. * Otherwise, all will be turned on. */ $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(INDEXES,&)}')); $ext->add($id, $c, '', new ext_setvar('ITER', '1')); $ext->add($id, $c, 'begin1', new ext_setvar('INDEX', '${CUT(INDEXES,&,${ITER})}')); $ext->add($id, $c, '', new ext_setvar('MODE', '${DB(DAYNIGHT/C${INDEX})}')); $ext->add($id, $c, '', new ext_gotoif('$["${MODE}" != "NIGHT"]', 'end1')); $ext->add($id, $c, '', new ext_setvar('DAYNIGHTMODE', 'NIGHT')); $ext->add($id, $c, 'end1', new ext_setvar('ITER', '$[${ITER} + 1]')); $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin1')); $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(INDEXES,&)}')); $ext->add($id, $c, '', new ext_setvar('ITER', '1')); $ext->add($id, $c, 'begin2', new ext_setvar('INDEX', '${CUT(INDEXES,&,${ITER})}')); $ext->add($id, $c, '', new ext_gotoif('$["${DAYNIGHTMODE}" = "NIGHT"]', 'day', 'night')); $ext->add($id, $c, 'day', new ext_setvar('DB(DAYNIGHT/C${INDEX})', 'DAY')); if ($amp_conf['USEDEVSTATE']) { $ext->add($id, $c, '', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'] . '(Custom:DAYNIGHT${INDEX})', 'NOT_INUSE')); } $ext->add($id, $c, 'hook_day', new ext_goto('end2')); $ext->add($id, $c, 'night', new ext_setvar('DB(DAYNIGHT/C${INDEX})', 'NIGHT')); if ($amp_conf['USEDEVSTATE']) { $ext->add($id, $c, '', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'] . '(Custom:DAYNIGHT${INDEX})', 'INUSE')); } $ext->add($id, $c, 'hook_night', new ext_goto('end2')); $ext->add($id, $c, 'end2', new ext_setvar('ITER', '$[${ITER} + 1]')); $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin2')); if ($amp_conf['FCBEEPONLY']) { $ext->add($id, $c, '', new ext_playback('beep')); // $cmd,n,Playback(...) } else { $ext->add($id, $c, '', new ext_execif('$["${DAYNIGHTMODE}" = "NIGHT"]', 'Playback', '${DAYREC}', 'Playback', '${NIGHTREC}')); } $ext->add($id, $c, '', new ext_hangup('')); } }
function daynight_toggle() { global $ext; global $amp_conf; global $version; global $DEVSTATE; $DEVSTATE = version_compare($version, "1.6", "ge") ? "DEVICE_STATE" : "DEVSTATE"; $list = daynight_list(); $passwords = daynight_passwords(); $got_code = false; $day_recording = daynight_recording('day'); $night_recording = daynight_recording('night'); $id = "app-daynight-toggle"; // The context to be included foreach ($list as $item) { $index = $item['ext']; $fcc = new featurecode('daynight', 'toggle-mode-' . $index); $c = $fcc->getCodeActive(); unset($fcc); if (!$c) { continue; } $got_code = true; if ($amp_conf['USEDEVSTATE']) { $ext->addHint($id, $c, 'Custom:DAYNIGHT' . $index); } $ext->add($id, $c, '', new ext_answer('')); $ext->add($id, $c, '', new ext_wait('1')); if (isset($passwords[$index]) && trim($passwords[$index]) != "" && ctype_digit(trim($passwords[$index]))) { $ext->add($id, $c, '', new ext_authenticate($passwords[$index])); } $ext->add($id, $c, '', new ext_setvar('INDEX', $index)); $day_file = "beep&silence/1&day&reception&digits/{$index}&activated"; $night_file = "beep&silence/1&day&reception&digits/{$index}&de-activated"; if (function_exists('recordings_get_file')) { if ($day_recording[$index] != 0) { $day_file = recordings_get_file($day_recording[$index]); } if ($night_recording[$index] != 0) { $night_file = recordings_get_file($night_recording[$index]); } } $ext->add($id, $c, '', new ext_setvar('DAYREC', $day_file)); $ext->add($id, $c, '', new ext_setvar('NIGHTREC', $night_file)); $ext->add($id, $c, '', new ext_goto($id . ',s,1')); } if ($got_code) { $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal $c = 's'; $ext->add($id, $c, '', new ext_setvar('DAYNIGHTMODE', '${DB(DAYNIGHT/C${INDEX})}')); $ext->add($id, $c, '', new ext_gotoif('$["${DAYNIGHTMODE}" = "NIGHT"]', 'day', 'night')); $ext->add($id, $c, 'day', new ext_setvar('DB(DAYNIGHT/C${INDEX})', 'DAY')); if ($amp_conf['USEDEVSTATE']) { $ext->add($id, $c, '', new ext_setvar($DEVSTATE . '(Custom:DAYNIGHT${INDEX})', 'NOT_INUSE')); } if ($amp_conf['FCBEEPONLY']) { $ext->add($id, $c, 'hook_day', new ext_playback('beep')); // $cmd,n,Playback(...) } else { $ext->add($id, $c, 'hook_day', new ext_playback('${DAYREC}')); } $ext->add($id, $c, '', new ext_hangup('')); $ext->add($id, $c, 'night', new ext_setvar('DB(DAYNIGHT/C${INDEX})', 'NIGHT')); if ($amp_conf['USEDEVSTATE']) { $ext->add($id, $c, '', new ext_setvar($DEVSTATE . '(Custom:DAYNIGHT${INDEX})', 'INUSE')); } if ($amp_conf['FCBEEPONLY']) { $ext->add($id, $c, 'hook_night', new ext_playback('beep')); // $cmd,n,Playback(...) } else { $ext->add($id, $c, 'hook_night', new ext_playback('${NIGHTREC}')); } $ext->add($id, $c, '', new ext_hangup('')); } }