Esempio n. 1
0
function voicemail_configpageload()
{
    global $currentcomponent;
    // Init vars from $_REQUEST[]
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $ext = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    $extn = isset($_REQUEST['extension']) ? $_REQUEST['extension'] : null;
    $display = isset($_REQUEST['display']) ? $_REQUEST['display'] : null;
    if ($ext === '') {
        $extdisplay = $extn;
    } else {
        $extdisplay = $ext;
    }
    if ($action != 'del') {
        $vmbox = voicemail_mailbox_get($extdisplay);
        if ($vmbox == null) {
            $vm = false;
            $incontext = 'default';
            $vmpwd = null;
            $name = null;
            $email = null;
            $pager = null;
            $vmoptions = null;
            $vmx_state = '';
        } else {
            $incontext = isset($vmbox['vmcontext']) ? $vmbox['vmcontext'] : 'default';
            $vmpwd = $vmbox['pwd'];
            $name = $vmbox['name'];
            $email = $vmbox['email'];
            $pager = $vmbox['pager'];
            $vmoptions = $vmbox['options'];
            $vm = true;
            $vmxobj = new vmxObject($extdisplay);
            $vmx_state = $vmxobj->isEnabled() ? 'checked' : '';
            unset($vmxobj);
        }
        //loop through all options
        $options = "";
        if (isset($vmoptions) && is_array($vmoptions)) {
            $alloptions = array_keys($vmoptions);
            if (isset($alloptions)) {
                foreach ($alloptions as $option) {
                    if ($option != "attach" && $option != "envelope" && $option != "saycid" && $option != "delete" && $option != "imapuser" && $option != "imappassword" && $option != '') {
                        $options .= $option . '=' . $vmoptions[$option] . '|';
                    }
                }
                $options = rtrim($options, '|');
                // remove the = sign if there are no options set
                $options = rtrim($options, '=');
            }
            extract($vmoptions, EXTR_PREFIX_ALL, "vmops");
        } else {
            $vmops_attach = 'no';
            $vmops_saycid = 'no';
            $vmops_envelope = 'no';
            $vmops_delete = 'no';
            $vmops_imapuser = null;
            $vmops_imappassword = null;
        }
        if (empty($vmcontext)) {
            $vmcontext = isset($_REQUEST['vmcontext']) ? $_REQUEST['vmcontext'] : $incontext;
        }
        if (empty($vmcontext)) {
            $vmcontext = 'default';
        }
        if ($vm == true) {
            $vmselect = "enabled";
        } else {
            $vmselect = "disabled";
        }
        $fc_vm = featurecodes_getFeatureCode('voicemail', 'dialvoicemail');
        $msgInvalidVmPwd = _("Please enter a valid Voicemail Password, using digits only");
        $msgInvalidEmail = _("Please enter a valid Email Address");
        $msgInvalidPager = _("Please enter a valid Pager Email Address");
        $msgInvalidVMContext = _("VM Context cannot be blank");
        $vmops_imapuser = '';
        $vmops_imappassword = '';
        $section = _("Voicemail & Directory");
        $currentcomponent->addguielem($section, new gui_selectbox('vm', $currentcomponent->getoptlist('vmena'), $vmselect, _('Status'), '', false, "frm_{$display}_voicemailEnabled() && frm_{$display}_vmx_disable_fields()"));
        $disable = $vmselect == 'disabled';
        $currentcomponent->addguielem($section, new gui_textbox('vmpwd', $vmpwd, _('Voicemail Password'), sprintf(_("This is the password used to access the voicemail system.%sThis password can only contain numbers.%sA user can change the password you enter here after logging into the voicemail system (%s) with a phone."), "<br /><br />", "<br /><br />", $fc_vm), "frm_{$display}_isVoiceMailEnabled() && !frm_{$display}_verifyEmptyVoiceMailPassword() && !isInteger()", $msgInvalidVmPwd, false, 0, $disable));
        $currentcomponent->addguielem($section, new gui_textbox('email', $email, _('Email Address'), _("The email address that voicemails are sent to."), "frm_{$display}_isVoiceMailEnabled() && !isEmail()", $msgInvalidEmail, true, 0, $disable));
        $currentcomponent->addguielem($section, new gui_textbox('pager', $pager, _('Pager Email Address'), _("Pager/mobile email address that short voicemail notifications are sent to."), "frm_{$display}_isVoiceMailEnabled() && !isEmail()", $msgInvalidEmail, true, 0, $disable));
        $currentcomponent->addguielem($section, new gui_radio('attach', $currentcomponent->getoptlist('vmyn'), $vmops_attach, _('Email Attachment'), _("Option to attach voicemails to email."), $disable));
        $currentcomponent->addguielem($section, new gui_radio('saycid', $currentcomponent->getoptlist('vmyn'), $vmops_saycid, _('Play CID'), _("Read back caller's telephone number prior to playing the incoming message, and just after announcing the date and time the message was left."), $disable));
        $currentcomponent->addguielem($section, new gui_radio('envelope', $currentcomponent->getoptlist('vmyn'), $vmops_envelope, _('Play Envelope'), _("Envelope controls whether or not the voicemail system will play the message envelope (date/time) before playing the voicemail message. This setting does not affect the operation of the envelope option in the advanced voicemail menu."), $disable));
        $currentcomponent->addguielem($section, new gui_radio('delete', $currentcomponent->getoptlist('vmyn'), $vmops_delete, _('Delete Voicemail'), _("If set to \"yes\" the message will be deleted from the voicemailbox (after having been emailed). Provides functionality that allows a user to receive their voicemail via email alone, rather than having the voicemail able to be retrieved from the Webinterface or the Extension handset.  CAUTION: MUST HAVE attach voicemail to email SET TO YES OTHERWISE YOUR MESSAGES WILL BE LOST FOREVER."), $disable));
        $currentcomponent->addguielem($section, new gui_textbox('imapuser', $vmops_imapuser, _('IMAP Username'), sprintf(_("This is the IMAP username, if using IMAP storage"), "<br /><br />"), '', '', true, 0, $disable));
        $currentcomponent->addguielem($section, new gui_textbox('imappassword', $vmops_imappassword, _('IMAP Password'), sprintf(_("This is the IMAP password, if using IMAP storage"), "<br /><br />"), '', '', true, 0, $disable));
        $currentcomponent->addguielem($section, new gui_textbox('options', $options, _('VM Options'), sprintf(_("Separate options with pipe ( | )%sie: review=yes|maxmessage=60"), "<br /><br />"), '', '', true, 0, $disable));
        $currentcomponent->addguielem($section, new gui_textbox('vmcontext', $vmcontext, _('VM Context'), _("This is the Voicemail Context which is normally set to default. Do not change unless you understand the implications."), "frm_{$display}_isVoiceMailEnabled() && isEmpty()", $msgInvalidVMContext, false, 0, $disable));
        $section = _("VmX Locater");
        $currentcomponent->addguielem($section, new gui_selectbox('vmx_state', $currentcomponent->getoptlist('vmxena'), $vmx_state, _('VmX Locater&trade;'), _("Enable/Disable the VmX Locater feature for this user. When enabled all settings are controlled by the user in the User Portal (ARI). Disabling will not delete any existing user settings but will disable access to the feature"), false, "frm_{$display}_vmx_disable_fields()", $disable), 5, 6);
        $vmxhtml = voicemail_draw_vmxgui($extdisplay, $disable);
        $vmxhtml = '<tr><td colspan="2"><table>' . $vmxhtml . '</table></td></tr>';
        $msgValidNumber = _("Please enter a valid phone number using number digits only");
        $vmxcustom_validate = "\n\t\tdefaultEmptyOK = true;\n\t\tif (!theForm.vmx_option_0_system_default.checked && !isInteger(theForm.vmx_option_0_number.value)) \n\t\t\treturn warnInvalid(theForm.vmx_option_0_number, '{$msgValidNumber}');\n\t\tif (theForm.vmx_option_1_system_default != undefined && !theForm.vmx_option_1_system_default.checked && !isInteger(theForm.vmx_option_1_number.value)) \n\t\t\treturn warnInvalid(theForm.vmx_option_1_number, '{$msgValidNumber}');\n\t\tif (!isInteger(theForm.vmx_option_2_number.value)) \n\t\t\treturn warnInvalid(theForm.vmx_option_2_number, '{$msgValidNumber}');\n\t\t";
        $currentcomponent->addguielem($section, new guielement('vmxcustom', $vmxhtml, "{$vmxcustom_validate}"), 6, 6);
    }
}
function voicemail_configpageload()
{
    global $currentcomponent;
    global $amp_conf;
    global $astman;
    // Init vars from $_REQUEST[]
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $ext = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    $extn = isset($_REQUEST['extension']) ? $_REQUEST['extension'] : null;
    $display = isset($_REQUEST['display']) ? $_REQUEST['display'] : null;
    if ($ext === '') {
        $extdisplay = $extn;
    } else {
        $extdisplay = $ext;
    }
    if ($action != 'del') {
        $vmbox = voicemail_mailbox_get($extdisplay);
        if ($vmbox == null) {
            $vm = false;
            $incontext = 'default';
            $vmpwd = null;
            $name = null;
            $email = null;
            $pager = null;
            $vmoptions = null;
        } else {
            $incontext = isset($vmbox['vmcontext']) ? $vmbox['vmcontext'] : 'default';
            $vmpwd = $vmbox['pwd'];
            $name = $vmbox['name'];
            $email = $vmbox['email'];
            $pager = $vmbox['pager'];
            $vmoptions = $vmbox['options'];
            $vm = true;
        }
        //loop through all options
        $options = "";
        if (isset($vmoptions) && is_array($vmoptions)) {
            $alloptions = array_keys($vmoptions);
            if (isset($alloptions)) {
                foreach ($alloptions as $option) {
                    if ($option != "attach" && $option != "envelope" && $option != "passlogin" && $option != "novmstar" && $option != "saycid" && $option != "delete" && $option != "imapuser" && $option != "imappassword" && $option != '') {
                        $options .= $option . '=' . $vmoptions[$option] . '|';
                    }
                }
                $options = rtrim($options, '|');
                // remove the = sign if there are no options set
                $options = rtrim($options, '=');
            }
            extract($vmoptions, EXTR_PREFIX_ALL, "vmops");
        } else {
            $vmops_novmstar = 'no';
            $vmops_passlogin = '******';
            $vmops_attach = 'no';
            $vmops_saycid = 'no';
            $vmops_envelope = 'no';
            $vmops_delete = 'no';
            $vmops_imapuser = null;
            $vmops_imappassword = null;
        }
        if (empty($vmcontext)) {
            $vmcontext = isset($_REQUEST['vmcontext']) ? $_REQUEST['vmcontext'] : $incontext;
        }
        if (empty($vmcontext)) {
            $vmcontext = 'default';
        }
        if ($vm == true) {
            $vmselect = "enabled";
        } else {
            $vmselect = "disabled";
        }
        $fc_vm = featurecodes_getFeatureCode('voicemail', 'dialvoicemail');
        $msgInvalidVmPwd = _("Please enter a valid Voicemail Password, using digits only");
        $msgInvalidEmail = _("Please enter a valid Email Address");
        $msgInvalidPager = _("Please enter a valid Pager Email Address");
        $msgInvalidVMContext = _("VM Context cannot be blank");
        $vmops_imapuser = isset($vmops_imapuser) ? $vmops_imapuser : '';
        $vmops_imappassword = isset($vmops_imappassword) ? $vmops_imappassword : '';
        $section = _("Voicemail");
        $class = "fpbx-voicemail";
        $category = "voicemail";
        $guidefaults = array("elemname" => "", "prompttext" => "", "helptext" => "", "currentvalue" => "", "valarray" => array(), "jsonclick" => '', "jsvalidation" => "", "failvalidationmsg" => "", "canbeempty" => true, "maxchars" => 0, "disable" => false, "inputgroup" => false, "class" => "");
        $el = array("elemname" => "vm", "prompttext" => _('Enabled'), "currentvalue" => $vmselect, "valarray" => $currentcomponent->getoptlist('vmena'), "jsonclick" => "frm_{$display}_voicemailEnabled() && frm_{$display}_vmxEnabled()", "pairedvalues" => false);
        $currentcomponent->addguielem($section, new gui_radio(array_merge($guidefaults, $el)), $category);
        $disable = $vmselect == 'disabled';
        $el = array("elemname" => "vmpwd", "prompttext" => _('Voicemail Password'), "helptext" => sprintf(_("This is the password used to access the Voicemail system.%sThis password can only contain numbers.%sA user can change the password you enter here after logging into the Voicemail system (%s) with a phone."), "<br /><br />", "<br /><br />", $fc_vm), "currentvalue" => $vmpwd, "jsvalidation" => "frm_{$display}_isVoiceMailEnabled() && !frm_{$display}_isValidVoicemailPass()", "failvalidationmsg" => $msgInvalidVmPwd, "canbeempty" => false, "class" => $class, "disable" => $disable, "passwordToggle" => true);
        $currentcomponent->addguielem($section, new gui_password(array_merge($guidefaults, $el)), $category);
        //for passwordless voicemail we need to check some settings
        //first lets see if there is an entry in the asteriskDB for this device
        //no entry in the db is the same as yes, meaning we need a voicemail password
        $passlogin = !empty($extdisplay) ? $astman->connected() && $astman->database_get("AMPUSER", $extdisplay . "/novmpw") : 'yes';
        $passlogin = !empty($passlogin) ? 'no' : 'yes';
        //now lets get our featurecodes for helptext display niceties
        $mvm = new featurecode('voicemail', 'myvoicemail');
        $dvm = new featurecode('voicemail', 'dialvoicemail');
        $extword = $display == 'extensions' ? _('Extension') : _('Device');
        $display_mode = "advanced";
        $mode = \FreePBX::Config()->get("FPBXOPMODE");
        if (!empty($mode)) {
            $display_mode = $mode;
        }
        if ($display_mode == "basic") {
            $tb = $rb = "gui_hidden";
        } else {
            $tb = "gui_textbox";
            $rb = "gui_radio";
        }
        $el = array("elemname" => "passlogin", "prompttext" => sprintf(_('Require From Same %s'), $extword), "helptext" => sprintf(_("If set to \"no\" then when the user dials %s to access their own voicemail, they will not be asked to enter a password. This does not apply to %s calls, which will always prompt for a password. For security reasons, this should probably be set to \"yes\" in an environment where other users will have physical access to this extension."), $mvm->getCode(), $dvm->getCode()), "currentvalue" => $passlogin, "valarray" => $currentcomponent->getoptlist('vmyn'), "disable" => $disable, "class" => $class);
        $currentcomponent->addguielem($section, new $rb(array_merge($guidefaults, $el)), $category);
        $novmstar = !empty($extdisplay) ? $astman->connected() && $astman->database_get("AMPUSER", $extdisplay . "/novmstar") : 'yes';
        $novmstar = !empty($novmstar) ? 'yes' : 'no';
        $el = array("elemname" => "novmstar", "prompttext" => _("Disable (*) in Voicemail Menu"), "helptext" => sprintf(_("If set to \"yes\" then when someone dials this voicemail box they will not be able to access the voicemail menu by pressing (*). If you have no plans to access your mailbox remotely set this to \"yes\""), $mvm->getCode(), $dvm->getCode()), "currentvalue" => $novmstar, "valarray" => $currentcomponent->getoptlist('vmyn'), "disable" => $disable, "class" => $class);
        $currentcomponent->addguielem($section, new $rb(array_merge($guidefaults, $el)), $category);
        $el = array("elemname" => "email", "prompttext" => _('Email Address'), "helptext" => _("The email address that Voicemails are sent to."), "currentvalue" => $email, "jsvalidation" => "frm_{$display}_isVoiceMailEnabled() && frm_{$display}_isEmailAttachment() && !isEmail()", "failvalidationmsg" => $msgInvalidEmail, "canbeempty" => false, "class" => $class, "disable" => $disable);
        $currentcomponent->addguielem($section, new gui_textbox(array_merge($guidefaults, $el)), $category);
        $el = array("elemname" => "pager", "prompttext" => _('Pager Email Address'), "helptext" => _("Pager/mobile email address that short Voicemail notifications are sent to."), "currentvalue" => $pager, "jsvalidation" => "frm_{$display}_isVoiceMailEnabled() && !isEmpty() && !isEmail()", "failvalidationmsg" => $msgInvalidEmail, "canbeempty" => false, "class" => $class, "disable" => $disable);
        $currentcomponent->addguielem($section, new $tb(array_merge($guidefaults, $el)), $category);
        $el = array("elemname" => "attach", "prompttext" => _('Email Attachment'), "helptext" => _("Option to attach Voicemails to email."), "currentvalue" => $vmops_attach, "valarray" => $currentcomponent->getoptlist('vmyn'), "disable" => $disable, "class" => $class);
        $currentcomponent->addguielem($section, new $rb(array_merge($guidefaults, $el)), $category);
        $el = array("elemname" => "saycid", "prompttext" => _('Play CID'), "helptext" => _("Read back caller's telephone number prior to playing the incoming message, and just after announcing the date and time the message was left."), "currentvalue" => $vmops_saycid, "valarray" => $currentcomponent->getoptlist('vmyn'), "disable" => $disable, "class" => $class);
        $currentcomponent->addguielem($section, new $rb(array_merge($guidefaults, $el)), $category);
        $el = array("elemname" => "envelope", "prompttext" => _('Play Envelope'), "helptext" => _("Envelope controls whether or not the Voicemail system will play the message envelope (date/time) before playing the Voicemail message. This setting does not affect the operation of the envelope option in the advanced Voicemail menu."), "currentvalue" => $vmops_envelope, "valarray" => $currentcomponent->getoptlist('vmyn'), "disable" => $disable, "class" => $class);
        $currentcomponent->addguielem($section, new $rb(array_merge($guidefaults, $el)), $category);
        $el = array("elemname" => "vmdelete", "prompttext" => _('Delete Voicemail'), "helptext" => _("If set to \"yes\" the message will be deleted from the Voicemailbox (after having been emailed). Provides functionality that allows a user to receive their Voicemail via email alone, rather than having the Voicemail able to be retrieved from the Webinterface or the Extension handset.  CAUTION: MUST HAVE attach Voicemail to email SET TO YES OTHERWISE YOUR MESSAGES WILL BE LOST FOREVER."), "currentvalue" => $vmops_delete, "valarray" => $currentcomponent->getoptlist('vmyn'), "disable" => $disable, "class" => $class);
        $currentcomponent->addguielem($section, new $rb(array_merge($guidefaults, $el)), $category);
        if ($amp_conf['VM_SHOW_IMAP'] || $vmops_imapuser || $vmops_imappassword) {
            $el = array("elemname" => "imapuser", "prompttext" => _('IMAP Username'), "helptext" => sprintf(_("This is the IMAP username, if using IMAP storage"), "<br /><br />"), "currentvalue" => $vmops_imapuser, "class" => $class, "disable" => $disable);
            $currentcomponent->addguielem($section, new $tb(array_merge($guidefaults, $el)), $category);
            $el = array("elemname" => "imappassword", "prompttext" => _('IMAP Password'), "helptext" => sprintf(_("This is the IMAP password, if using IMAP storage"), "<br /><br />"), "currentvalue" => $vmops_imapuser, "class" => $class, "disable" => $disable);
            $currentcomponent->addguielem($section, new $tb(array_merge($guidefaults, $el)), $category);
        }
        $el = array("elemname" => "options", "prompttext" => _('VM Options'), "helptext" => sprintf(_("Separate options with pipe ( | )%sie: review=yes|maxmessage=60"), "<br /><br />"), "currentvalue" => $options, "class" => $class, "disable" => $disable);
        $currentcomponent->addguielem($section, new $tb(array_merge($guidefaults, $el)), $category);
        $el = array("elemname" => "vmcontext", "prompttext" => _('VM Context'), "helptext" => _("This is the Voicemail Context which is normally set to default. Do not change unless you understand the implications."), "currentvalue" => $incontext, "class" => $class, "disable" => $disable, "jsvalidation" => "frm_{$display}_isVoiceMailEnabled() && isEmpty()", "failvalidationmsg" => $msgInvalidVMContext);
        $currentcomponent->addguielem($section, new $tb(array_merge($guidefaults, $el)), $category);
        voicemail_draw_vmxgui($extdisplay, $disable);
    }
}
Esempio n. 3
0
function core_devices_configpageload()
{
    global $currentcomponent;
    global $amp_conf;
    $tech_hardware = isset($_REQUEST['tech_hardware']) ? $_REQUEST['tech_hardware'] : null;
    if ($tech_hardware == 'virtual') {
        $currentcomponent->addguielem('_top', new gui_hidden('tech', "virtual"));
        $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Virtual Extension")), 0);
        return true;
    }
    // Init vars from $_REQUEST[]
    $display = isset($_REQUEST['display']) ? $_REQUEST['display'] : null;
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    if ($action == 'del') {
        // Deleted
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_subheading('del', $extdisplay . ' ' . _("deleted"), false));
        }
    } elseif ($extdisplay == '' && $tech_hardware == '') {
        // Adding
    } else {
        $deviceInfo = array();
        if ($extdisplay) {
            // Editing
            $deviceInfo = core_devices_get($extdisplay);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Device") . ": {$extdisplay}", false), 0);
                $delURL = '?' . $_SERVER['QUERY_STRING'] . '&action=del';
                $tlabel = sprintf(_("Delete Device %s"), $extdisplay);
                $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/telephone_delete.png"/>&nbsp;' . $tlabel . '</span>';
                $currentcomponent->addguielem('_top', new gui_link('del', $label, $delURL, true, false), 0);
                if ($deviceInfo['device_user'] != 'none') {
                    $editURL = '?display=users&skip=0&extdisplay=' . urlencode($deviceInfo['user']);
                    $tlabel = $deviceInfo['devicetype'] == 'adhoc' ? sprintf(_("Edit Default User: %s"), $deviceInfo['user']) : sprintf(_("Edit Fixed User: %s"), $deviceInfo['user']);
                    $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/user_edit.png"/>&nbsp;' . $tlabel . '</span>';
                    $currentcomponent->addguielem('_top', new gui_link('edit_user', $label, $editURL, true, false), 0);
                }
            }
        } else {
            $tmparr = explode('_', $tech_hardware);
            $deviceInfo['tech'] = $tmparr[0];
            $deviceInfo['hardware'] = $tmparr[1];
            unset($tmparr);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Device"), strtoupper($deviceInfo['tech']))), 0);
            } else {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Extension"), strtoupper($deviceInfo['tech']))), 0);
            }
        }
        // Ensure they exist before the extract
        $devinfo_description = $devinfo_emergency_cid = null;
        $devinfo_devicetype = $devinfo_user = $devinfo_hardware = null;
        $devinfo_tech = null;
        if (is_array($deviceInfo)) {
            extract($deviceInfo, EXTR_PREFIX_ALL, 'devinfo');
        }
        // Setup vars for use in the gui later on
        $fc_logon = featurecodes_getFeatureCode('core', 'userlogon');
        $fc_logoff = featurecodes_getFeatureCode('core', 'userlogoff');
        $msgInvalidDevID = _("Please enter a device id.");
        $msgInvalidDevDesc = _("Please enter a valid Description for this device");
        $msgInvalidEmergCID = _("Please enter a valid Emergency CID");
        $msgInvalidExtNum = _("Please enter a valid extension number.");
        // Actual gui
        $currentcomponent->addguielem('_top', new gui_hidden('action', isset($extdisplay) && trim($extdisplay) !== '' ? 'edit' : 'add'));
        $currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay));
        if ($display != 'extensions') {
            $section = $extdisplay ? _("Edit User") : _("Add User");
            if ($extdisplay) {
                // Editing
                $currentcomponent->addguielem($section, new gui_hidden('deviceid', $extdisplay), "general");
            } else {
                // Adding
                $currentcomponent->addguielem($section, new gui_textbox('deviceid', $extdisplay, _("Device ID"), _("Give your device a unique integer ID.  The device will use this ID to authenticate to the system."), '!isInteger()', $msgInvalidDevID, false), "general");
            }
            $currentcomponent->addguielem($section, new gui_textbox('description', $devinfo_description, _("Description"), _("The CallerID name for this device will be set to this description until it is logged into."), '!isUnicodeLetter() || isWhitespace()', $msgInvalidDevDesc, false), "general");
            $currentcomponent->addguielem($section, new gui_selectbox('devicetype', $currentcomponent->getoptlist('devicetypelist'), $devinfo_devicetype, _("Device Type"), _("Devices can be fixed or adhoc. Fixed devices are always associated to the same extension/user. Adhoc devices can be logged into and logged out of by users.") . ' ' . $fc_logon . ' ' . _("logs into a device.") . ' ' . $fc_logoff . ' ' . _("logs out of a device."), false), "general");
            $currentcomponent->addguielem($section, new gui_selectbox('deviceuser', $currentcomponent->getoptlist('deviceuserlist'), $devinfo_user, _("Default User"), _("Fixed devices will always mapped to this user.  Adhoc devices will be mapped to this user by default.<br><br>If selecting 'New User', a new User Extension of the same Device ID will be set as the Default User."), false), "general");
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This CallerID will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other CallerID settings."), '!isCallerID()', $msgInvalidEmergCID), "advanced");
        } else {
            $section = _("Extension Options");
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This CallerID will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other CallerID settings."), '!isCallerID()', $msgInvalidEmergCID), "advanced");
        }
        $currentcomponent->addguielem('_top', new gui_hidden('tech', $devinfo_tech));
        $currentcomponent->addguielem('_top', new gui_hidden('hardware', $devinfo_hardware));
        if ($devinfo_tech && $devinfo_tech != "virtual") {
            $section = _("Device Options");
            $msgInvalidChannel = _("Please enter the channel for this device");
            $msgConfirmSecret = _("You have not entered a Secret for this device, although this is possible it is generally bad practice to not assign a Secret to a device. Are you sure you want to leave the Secret empty?");
            $msgInvalidSecret = _("Please enter a Secret for this device");
            $secret_validation = '(isEmpty() && !confirm("' . $msgConfirmSecret . '"))';
            if ($amp_conf['DEVICE_STRONG_SECRETS']) {
                $secret_validation .= ' || (!isEmpty() && weakSecret())';
            }
            if ($display == 'extensions') {
                $section = $extdisplay ? _("Edit Extension") : _("Add Extension");
            } else {
                $section = $extdisplay ? _("Edit User") : _("Add User");
            }
            $drivers = FreePBX::Core()->getAllDrivers();
            if (isset($drivers[$devinfo_tech])) {
                $devopts = $drivers[$devinfo_tech]->getDeviceDisplay($display, $deviceInfo, $currentcomponent, $section);
            } else {
                $devopts = array();
            }
            if (is_array($devopts)) {
                foreach ($devopts as $devopt => $devoptarr) {
                    $devopname = 'devinfo_' . $devopt;
                    $devoptcurrent = isset(${$devopname}) ? ${$devopname} : $devoptarr['value'];
                    $devoptjs = isset($devoptarr['jsvalidation']) ? $devoptarr['jsvalidation'] : '';
                    $devoptfailmsg = isset($devoptarr['failvalidationmsg']) ? $devoptarr['failvalidationmsg'] : '';
                    $devdisable = isset($devoptarr['disable']) ? $devoptarr['disable'] : false;
                    $devonchange = isset($devoptarr['onchange']) ? $devoptarr['onchange'] : '';
                    $prompttext = isset($devoptarr['prompttext']) ? $devoptarr['prompttext'] : $devopt;
                    $hidden = isset($devoptarr['hidden']) ? $devoptarr['hidden'] : false;
                    $type = isset($devoptarr['type']) ? $devoptarr['type'] : (isset($devoptarr['select']) ? 'select' : 'text');
                    $text = isset($devoptarr['text']) ? $devoptarr['text'] : '';
                    $category = isset($devoptarr['category']) ? $devoptarr['category'] : 'advanced';
                    $sec = isset($devoptarr['section']) ? $devoptarr['section'] : $section;
                    $class = isset($devoptarr['class']) ? $devoptarr['class'] : '';
                    $autocomplete = false;
                    // We compare the existing secret against what might be in the put to detect changes when validating
                    if ($devopt == "secret") {
                        $currentcomponent->addguielem($sec, new gui_hidden($devopname . "_origional", $devoptcurrent), 4, null, $category);
                        if ($devoptcurrent == '' && empty($extdisplay)) {
                            $devoptcurrent = \FreePBX::Core()->generateSecret();
                        }
                    }
                    if (!$hidden) {
                        // editing to show advanced as well
                        // Added optional selectbox to enable the unsupported misdn module
                        $tooltip = isset($devoptarr['tt']) ? $devoptarr['tt'] : '';
                        if ($type == 'select') {
                            $currentcomponent->addguielem($sec, new gui_selectbox($devopname, $devoptarr['select'], $devoptcurrent, $prompttext, $tooltip, false, $devonchange, $devdisable, $class), 4, null, $category);
                        } elseif ($type == 'text') {
                            $currentcomponent->addguielem($sec, new gui_textbox($devopname, $devoptcurrent, $prompttext, $tooltip, $devoptjs, $devoptfailmsg, true, 0, $devdisable, false, $class, $autocomplete), 4, null, $category);
                        } elseif ($type == 'button') {
                            $currentcomponent->addguielem($sec, new gui_button($devopname, $devoptcurrent, $prompttext, $tooltip, $text, $devoptjs, $devdisable, $class), 4, null, $category);
                        } elseif ($type == 'radio') {
                            $currentcomponent->addguielem($sec, new gui_radio($devopname, $devoptarr['select'], $devoptcurrent, $prompttext, $tooltip, false, $devonchange, $devdisable, $class, false), 4, null, $category);
                        }
                    } else {
                        // add so only basic
                        $currentcomponent->addguielem($sec, new gui_hidden($devopname, $devoptcurrent), 4, null, $category);
                    }
                }
            }
        }
    }
}
Esempio n. 4
0
function ivr_get_config($engine)
{
    global $ext;
    switch ($engine) {
        case "asterisk":
            $ddial_contexts = array();
            $ivrlist = ivr_list();
            if (is_array($ivrlist)) {
                foreach ($ivrlist as $item) {
                    $id = "ivr-" . $item['ivr_id'];
                    $details = ivr_get_details($item['ivr_id']);
                    $announcement_id = isset($details['announcement_id']) ? $details['announcement_id'] : '';
                    $timeout_id = isset($details['timeout_id']) ? $details['timeout_id'] : '';
                    $invalid_id = isset($details['invalid_id']) ? $details['invalid_id'] : '';
                    $loops = isset($details['loops']) ? $details['loops'] : '2';
                    $retvm = isset($details['retvm']) ? $details['retvm'] : '';
                    if (!empty($details['enable_directdial'])) {
                        if ($details['enable_directdial'] == 'CHECKED') {
                            $ext->addInclude($id, 'from-did-direct-ivr');
                            //generated in core module
                        } else {
                            $ext->addInclude($id, 'from-ivr-directory-' . $details['enable_directdial']);
                            $ddial_contexts[$details['enable_directdial']] = true;
                        }
                    }
                    // I'm not sure I like the ability of people to send voicemail from the IVR.
                    // Make it a config option, possibly?
                    // $ext->addInclude($item[0],'app-messagecenter');
                    if (!empty($details['enable_directory'])) {
                        $ext->addInclude($id, 'app-directory');
                        $dir = featurecodes_getFeatureCode('infoservices', 'directory');
                        $ext->add($id, '#', '', new ext_dbdel('${BLKVM_OVERRIDE}'));
                        $ext->add($id, '#', '', new ext_setvar('__NODEST', ''));
                        $ext->add($id, '#', '', new ext_goto("app-directory,{$dir},1"));
                    }
                    $ext->add($id, 'h', '', new ext_hangup(''));
                    if ($announcement_id) {
                        $announcement_msg = recordings_get_file($announcement_id);
                        $ext->add($id, 's', '', new ext_setvar('MSG', "{$announcement_msg}"));
                    } else {
                        $ext->add($id, 's', '', new ext_setvar('MSG', ""));
                    }
                    $ext->add($id, 's', '', new ext_setvar('LOOPCOUNT', 0));
                    $ext->add($id, 's', '', new ext_setvar('__DIR-CONTEXT', $details['dircontext']));
                    $ext->add($id, 's', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT}'));
                    $ext->add($id, 's', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}'));
                    $ext->add($id, 's', '', new ext_gotoif('$["${CDR(disposition)}" = "ANSWERED"]', 'begin'));
                    $ext->add($id, 's', '', new ext_answer(''));
                    $ext->add($id, 's', '', new ext_wait('1'));
                    $ext->add($id, 's', 'begin', new ext_digittimeout(3));
                    $ext->add($id, 's', '', new ext_responsetimeout($details['timeout']));
                    if ($retvm) {
                        $ext->add($id, 's', '', new ext_setvar('__IVR_RETVM', 'RETURN'));
                    } else {
                        $ext->add($id, 's', '', new ext_setvar('__IVR_RETVM', ''));
                    }
                    $ext->add($id, 's', '', new ext_execif('$["${MSG}" != ""]', 'Background', '${MSG}'));
                    $ext->add($id, 's', '', new ext_waitexten());
                    $ext->add($id, 'hang', '', new ext_playback('vm-goodbye'));
                    $ext->add($id, 'hang', '', new ext_hangup(''));
                    $default_t = true;
                    // Actually add the IVR commands now.
                    $dests = ivr_get_dests($item['ivr_id']);
                    $timeout = false;
                    $invalid = false;
                    $addloop = false;
                    if (!empty($dests)) {
                        foreach ($dests as $dest) {
                            if ($dest['selection'] == 't' && empty($details['alt_timeout'])) {
                                $timeout = true;
                            } elseif ($dest['selection'] == 'i' && empty($details['alt_invalid'])) {
                                $invalid = true;
                            } elseif ($dest['selection'] == 't' && !empty($details['alt_timeout'])) {
                                $timeout = true;
                                if ($timeout_id) {
                                    $timeout_msg = recordings_get_file($timeout_id);
                                    $ext->add($id, $dest['selection'], '', new ext_setvar('MSG', "{$timeout_msg}"));
                                }
                                $ext->add($id, $dest['selection'], '', new ext_setvar('LOOPCOUNT', '$[${LOOPCOUNT} + 1]'));
                                $ext->add($id, $dest['selection'], '', new ext_gotoif('$[${LOOPCOUNT} <= ' . $loops . ']', 's,begin'));
                            } elseif ($dest['selection'] == 'i' && !empty($details['alt_invalid'])) {
                                $invalid = true;
                                $ext->add($id, $dest['selection'], '', new ext_setvar('LOOPCOUNT', '$[${LOOPCOUNT} + 1]'));
                                if ($invalid_id) {
                                    $invalid_msg = recordings_get_file($invalid_id);
                                    $ext->add($id, $dest['selection'], '', new ext_setvar('MSG', "{$invalid_msg}"));
                                } else {
                                    $ext->add($id, $dest['selection'], '', new ext_execif('$[${LOOPCOUNT} <= ' . $loops . ']', 'Playback', 'invalid'));
                                }
                                $ext->add($id, $dest['selection'], '', new ext_gotoif('$[${LOOPCOUNT} <= ' . $loops . ']', 's,begin'));
                            }
                            $ext->add($id, $dest['selection'], '', new ext_dbdel('${BLKVM_OVERRIDE}'));
                            $ext->add($id, $dest['selection'], '', new ext_setvar('__NODEST', ''));
                            // if the goto goes loops back to this ivr, then don't go to the begining or it will break the return to previous ivr info
                            //
                            $dest_context = trim(strtok($dest['dest'], ",|"));
                            if ($dest_context == $id) {
                                $dest['dest'] = $id . ',s,begin';
                            }
                            if ($dest['ivr_ret']) {
                                $ext->add($id, $dest['selection'], '', new ext_gotoif('$["x${IVR_CONTEXT_${CONTEXT}}" = "x"]', $dest['dest'] . ':${IVR_CONTEXT_${CONTEXT}},return,1'));
                            } else {
                                $ext->add($id, $dest['selection'], '', new ext_goto($dest['dest']));
                            }
                        }
                    }
                    // Apply invalid if required
                    if (!$invalid) {
                        if ($invalid_id) {
                            $invalid_msg = recordings_get_file($invalid_id);
                            $ext->add($id, 'i', '', new ext_setvar('MSG', "{$invalid_msg}"));
                        } else {
                            $ext->add($id, 'i', '', new ext_playback('invalid'));
                        }
                        $ext->add($id, 'i', '', new ext_goto('loop,1'));
                        $addloop = true;
                    }
                    if (!$timeout) {
                        if ($timeout_id) {
                            $timeout_msg = recordings_get_file($timeout_id);
                            $ext->add($id, 't', '', new ext_setvar('MSG', "{$timeout_msg}"));
                        }
                        $ext->add($id, 't', '', new ext_goto('loop,1'));
                        $addloop = true;
                    }
                    if ($addloop) {
                        $ext->add($id, 'loop', '', new ext_setvar('LOOPCOUNT', '$[${LOOPCOUNT} + 1]'));
                        $ext->add($id, 'loop', '', new ext_gotoif('$[${LOOPCOUNT} > ' . $loops . ']', 'hang,1'));
                        $ext->add($id, 'loop', '', new ext_goto($id . ',s,begin'));
                        // these need to be reset or inheritance problems makes them go away in some conditions and infinite inheritance creates other problems
                        // reset the message including blanking it if set by a sub-ivr
                        $announcement_msg = $announcement_id ? $announcement_msg : '';
                        $ext->add($id, 'return', '', new ext_setvar('MSG', "{$announcement_msg}"));
                        $ext->add($id, 'return', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}'));
                        $ext->add($id, 'return', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT_${CONTEXT}}'));
                        $ext->add($id, 'return', '', new ext_goto($id . ',s,begin'));
                    }
                }
                if (!empty($ddial_contexts)) {
                    global $version;
                    $ast_lt_14 = version_compare($version, '1.4', 'lt');
                    foreach (array_keys($ddial_contexts) as $dir_id) {
                        $context = 'from-ivr-directory-' . $dir_id;
                        $entries = function_exists('directory_get_dir_entries') ? directory_get_dir_entries($dir_id) : array();
                        foreach ($entries as $dstring) {
                            $exten = $dstring['dial'] == '' ? $dstring['foreign_id'] : $dstring['dial'];
                            if ($exten == '' || $exten == 'custom') {
                                continue;
                            }
                            if ($ast_lt_14) {
                                $ext->add($context, $exten, '', new ext_execif('$["${BLKVM_OVERRIDE}" != ""]', 'dbDel', '${BLKVM_OVERRIDE}'));
                            } else {
                                $ext->add($context, $exten, '', new ext_execif('$["${BLKVM_OVERRIDE}" != ""]', 'Noop', 'Deleting: ${BLKVM_OVERRIDE}: ${DB_DELETE(${BLKVM_OVERRIDE})}'));
                            }
                            $ext->add($context, $exten, '', new ext_setvar('__NODEST', ''));
                            $ext->add($context, $exten, '', new ext_goto('1', $exten, 'from-internal'));
                        }
                    }
                }
            }
            break;
    }
}
Esempio n. 5
0
function core_devices_configpageload()
{
    global $currentcomponent;
    $tech_hardware = isset($_REQUEST['tech_hardware']) ? $_REQUEST['tech_hardware'] : null;
    if ($tech_hardware == 'virtual') {
        return true;
    }
    // Init vars from $_REQUEST[]
    $display = isset($_REQUEST['display']) ? $_REQUEST['display'] : null;
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    if ($action == 'del') {
        // Deleted
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_subheading('del', $extdisplay . ' ' . _("deleted"), false));
        }
    } elseif ($extdisplay == '' && $tech_hardware == '') {
        // Adding
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Device")), 0);
        } else {
            $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add an Extension")), 0);
        }
        $currentcomponent->addguielem('_top', new gui_label('instructions', _("Please select your Device below then click Submit")));
        $currentcomponent->addguielem('Device', new gui_selectbox('tech_hardware', $currentcomponent->getoptlist('devicelist'), '', _("Device"), '', false));
    } else {
        $deviceInfo = array();
        if ($extdisplay) {
            // Editing
            $deviceInfo = core_devices_get($extdisplay);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Device") . ": {$extdisplay}", false), 0);
                $delURL = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '&action=del';
                $tlabel = sprintf(_("Delete Device %s"), $extdisplay);
                $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/telephone_delete.png"/>&nbsp;' . $tlabel . '</span>';
                $currentcomponent->addguielem('_top', new gui_link('del', $label, $delURL, true, false), 0);
                if ($deviceInfo['device_user'] != 'none') {
                    $editURL = $_SERVER['PHP_SELF'] . '?type=setup&display=users&skip=0&extdisplay=' . $deviceInfo['user'];
                    $tlabel = $deviceInfo['devicetype'] == 'adhoc' ? sprintf(_("Edit Default User: %s"), $deviceInfo['user']) : sprintf(_("Edit Fixed User: %s"), $deviceInfo['user']);
                    $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/user_edit.png"/>&nbsp;' . $tlabel . '</span>';
                    $currentcomponent->addguielem('_top', new gui_link('edit_user', $label, $editURL, true, false), 0);
                }
            }
        } else {
            $tmparr = explode('_', $tech_hardware);
            $deviceInfo['tech'] = $tmparr[0];
            $deviceInfo['hardware'] = $tmparr[1];
            unset($tmparr);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Device"), strtoupper($deviceInfo['tech']))), 0);
            } else {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Extension"), strtoupper($deviceInfo['tech']))), 0);
            }
        }
        // Ensure they exist before the extract
        $devinfo_description = $devinfo_emergency_cid = null;
        $devinfo_devicetype = $devinfo_user = $devinfo_hardware = null;
        $devinfo_tech = null;
        if (is_array($deviceInfo)) {
            extract($deviceInfo, EXTR_PREFIX_ALL, 'devinfo');
        }
        // Setup vars for use in the gui later on
        $fc_logon = featurecodes_getFeatureCode('core', 'userlogon');
        $fc_logoff = featurecodes_getFeatureCode('core', 'userlogoff');
        $msgInvalidDevID = _("Please enter a device id.");
        $msgInvalidDevDesc = _("Please enter a valid Description for this device");
        $msgInvalidEmergCID = _("Please enter a valid Emergency CID");
        $msgInvalidExtNum = _("Please enter a valid extension number.");
        // Actual gui
        $currentcomponent->addguielem('_top', new gui_hidden('action', $extdisplay ? 'edit' : 'add'));
        $currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay));
        if ($display != 'extensions') {
            $section = _("Device Info");
            if ($extdisplay) {
                // Editing
                $currentcomponent->addguielem($section, new gui_hidden('deviceid', $extdisplay));
            } else {
                // Adding
                $currentcomponent->addguielem($section, new gui_textbox('deviceid', $extdisplay, _("Device ID"), _("Give your device a unique integer ID.  The device will use this ID to authenticate to the system."), '!isInteger()', $msgInvalidDevID, false));
            }
            $currentcomponent->addguielem($section, new gui_textbox('description', $devinfo_description, _("Description"), _("The caller id name for this device will be set to this description until it is logged into."), '!isAlphanumeric() || isWhitespace()', $msgInvalidDevDesc, false));
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This caller id will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other caller id settings."), '!isCallerID()', $msgInvalidEmergCID));
            $currentcomponent->addguielem($section, new gui_selectbox('devicetype', $currentcomponent->getoptlist('devicetypelist'), $devinfo_devicetype, _("Device Type"), _("Devices can be fixed or adhoc. Fixed devices are always associated to the same extension/user. Adhoc devices can be logged into and logged out of by users.") . ' ' . $fc_logon . ' ' . _("logs into a device.") . ' ' . $fc_logoff . ' ' . _("logs out of a device."), false));
            $currentcomponent->addguielem($section, new gui_selectbox('deviceuser', $currentcomponent->getoptlist('deviceuserlist'), $devinfo_user, _("Default User"), _("Fixed devices will always mapped to this user.  Adhoc devices will be mapped to this user by default.<br><br>If selecting 'New User', a new User Extension of the same Device ID will be set as the Default User."), false));
        } else {
            $section = _("Extension Options");
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This caller id will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other caller id settings."), '!isCallerID()', $msgInvalidEmergCID));
        }
        $currentcomponent->addguielem($section, new gui_hidden('tech', $devinfo_tech));
        $currentcomponent->addguielem($section, new gui_hidden('hardware', $devinfo_hardware));
        if ($devinfo_tech && $devinfo_tech != "virtual") {
            $section = _("Device Options");
            $device_uses = sprintf(_("This device uses %s technology."), $devinfo_tech) . (strtoupper($devinfo_tech) == 'ZAP' && ast_with_dahdi() ? " (" . _("Via DAHDI compatibility mode") . ")" : "");
            $currentcomponent->addguielem($section, new gui_label('techlabel', $device_uses), 4);
            $devopts = $currentcomponent->getgeneralarrayitem('devtechs', $devinfo_tech);
            if (is_array($devopts)) {
                foreach ($devopts as $devopt => $devoptarr) {
                    $devopname = 'devinfo_' . $devopt;
                    $devoptcurrent = isset(${$devopname}) ? ${$devopname} : $devoptarr['value'];
                    $devoptjs = isset($devoptarr['jsvalidation']) ? $devoptarr['jsvalidation'] : '';
                    $devoptfailmsg = isset($devoptarr['failvalidationmsg']) ? $devoptarr['failvalidationmsg'] : '';
                    // We compare the existing secret against what might be in the put to detect changes when validating
                    if ($devopt == "secret") {
                        $currentcomponent->addguielem($section, new gui_hidden($devopname . "_origional", $devoptcurrent), 4);
                    }
                    if ($devoptarr['level'] == 0 || $extdisplay && $devoptarr['level'] == 1) {
                        // editing to show advanced as well
                        $currentcomponent->addguielem($section, new gui_textbox($devopname, $devoptcurrent, $devopt, '', $devoptjs, $devoptfailmsg), 4);
                    } else {
                        // add so only basic
                        $currentcomponent->addguielem($section, new gui_hidden($devopname, $devoptcurrent), 4);
                    }
                }
            }
        }
    }
}
Esempio n. 6
0
function core_devices_configpageload()
{
    global $currentcomponent;
    global $amp_conf;
    $tech_hardware = isset($_REQUEST['tech_hardware']) ? $_REQUEST['tech_hardware'] : null;
    if ($tech_hardware == 'virtual') {
        return true;
    }
    // Init vars from $_REQUEST[]
    $display = isset($_REQUEST['display']) ? $_REQUEST['display'] : null;
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    if ($action == 'del') {
        // Deleted
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_subheading('del', $extdisplay . ' ' . _("deleted"), false));
        }
    } elseif ($extdisplay == '' && $tech_hardware == '') {
        // Adding
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Device")), 0);
        } else {
            $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add an Extension")), 0);
        }
        $currentcomponent->addguielem('_top', new gui_label('instructions', _("Please select your Device below then click Submit")));
        $currentcomponent->addguielem('Device', new gui_selectbox('tech_hardware', $currentcomponent->getoptlist('devicelist'), '', _("Device"), '', false));
    } else {
        $deviceInfo = array();
        if ($extdisplay) {
            // Editing
            $deviceInfo = core_devices_get($extdisplay);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Device") . ": {$extdisplay}", false), 0);
                $delURL = '?' . $_SERVER['QUERY_STRING'] . '&action=del';
                $tlabel = sprintf(_("Delete Device %s"), $extdisplay);
                $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/telephone_delete.png"/>&nbsp;' . $tlabel . '</span>';
                $currentcomponent->addguielem('_top', new gui_link('del', $label, $delURL, true, false), 0);
                if ($deviceInfo['device_user'] != 'none') {
                    $editURL = '?display=users&skip=0&extdisplay=' . $deviceInfo['user'];
                    $tlabel = $deviceInfo['devicetype'] == 'adhoc' ? sprintf(_("Edit Default User: %s"), $deviceInfo['user']) : sprintf(_("Edit Fixed User: %s"), $deviceInfo['user']);
                    $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/user_edit.png"/>&nbsp;' . $tlabel . '</span>';
                    $currentcomponent->addguielem('_top', new gui_link('edit_user', $label, $editURL, true, false), 0);
                }
            }
        } else {
            $tmparr = explode('_', $tech_hardware);
            $deviceInfo['tech'] = $tmparr[0];
            $deviceInfo['hardware'] = $tmparr[1];
            unset($tmparr);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Device"), strtoupper($deviceInfo['tech']))), 0);
            } else {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Extension"), strtoupper($deviceInfo['tech']))), 0);
            }
        }
        // Ensure they exist before the extract
        $devinfo_description = $devinfo_emergency_cid = null;
        $devinfo_devicetype = $devinfo_user = $devinfo_hardware = null;
        $devinfo_tech = null;
        if (is_array($deviceInfo)) {
            extract($deviceInfo, EXTR_PREFIX_ALL, 'devinfo');
        }
        // Setup vars for use in the gui later on
        $fc_logon = featurecodes_getFeatureCode('core', 'userlogon');
        $fc_logoff = featurecodes_getFeatureCode('core', 'userlogoff');
        $msgInvalidDevID = _("Please enter a device id.");
        $msgInvalidDevDesc = _("Please enter a valid Description for this device");
        $msgInvalidEmergCID = _("Please enter a valid Emergency CID");
        $msgInvalidExtNum = _("Please enter a valid extension number.");
        // Actual gui
        $currentcomponent->addguielem('_top', new gui_hidden('action', $extdisplay ? 'edit' : 'add'));
        $currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay));
        if ($display != 'extensions') {
            $section = _("Device Info");
            if ($extdisplay) {
                // Editing
                $currentcomponent->addguielem($section, new gui_hidden('deviceid', $extdisplay));
            } else {
                // Adding
                $currentcomponent->addguielem($section, new gui_textbox('deviceid', $extdisplay, _("Device ID"), _("Give your device a unique integer ID.  The device will use this ID to authenticate to the system."), '!isInteger()', $msgInvalidDevID, false));
            }
            $currentcomponent->addguielem($section, new gui_textbox('description', $devinfo_description, _("Description"), _("The CallerID name for this device will be set to this description until it is logged into."), '!isAlphanumeric() || isWhitespace()', $msgInvalidDevDesc, false));
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This CallerID will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other CallerID settings."), '!isCallerID()', $msgInvalidEmergCID));
            $currentcomponent->addguielem($section, new gui_selectbox('devicetype', $currentcomponent->getoptlist('devicetypelist'), $devinfo_devicetype, _("Device Type"), _("Devices can be fixed or adhoc. Fixed devices are always associated to the same extension/user. Adhoc devices can be logged into and logged out of by users.") . ' ' . $fc_logon . ' ' . _("logs into a device.") . ' ' . $fc_logoff . ' ' . _("logs out of a device."), false));
            $currentcomponent->addguielem($section, new gui_selectbox('deviceuser', $currentcomponent->getoptlist('deviceuserlist'), $devinfo_user, _("Default User"), _("Fixed devices will always mapped to this user.  Adhoc devices will be mapped to this user by default.<br><br>If selecting 'New User', a new User Extension of the same Device ID will be set as the Default User."), false));
        } else {
            $section = _("Extension Options");
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This CallerID will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other CallerID settings."), '!isCallerID()', $msgInvalidEmergCID));
        }
        $currentcomponent->addguielem($section, new gui_hidden('tech', $devinfo_tech));
        $currentcomponent->addguielem($section, new gui_hidden('hardware', $devinfo_hardware));
        if ($devinfo_tech && $devinfo_tech != "virtual") {
            $section = _("Device Options");
            $devinfo_techd = $devinfo_tech == 'sip' ? 'CHAN_SIP' : strtoupper($devinfo_tech);
            if (FreePBX::Modules()->moduleHasMethod("sipsettings", "getBinds")) {
                $out = FreePBX::Sipsettings()->getBinds();
                foreach ($out[$devinfo_tech] as $ip => $data1) {
                    foreach ($data1 as $protocol => $port) {
                        $pport .= $ip . ":" . $port . ', ';
                    }
                }
                $pport = rtrim($pport, ", ");
            } else {
                $pport = '';
            }
            $extrac = !empty($pport) ? sprintf(_('listening on <strong>%s</strong>'), $pport) : '';
            $device_uses = sprintf(_("This device uses %s technology %s"), "<strong>" . $devinfo_techd . "</strong>", $extrac) . (strtoupper($devinfo_tech) == 'ZAP' && ast_with_dahdi() ? " (" . _("Via DAHDi compatibility mode") . ")" : "");
            $currentcomponent->addguielem($section, new gui_label('techlabel', '<div class="alert alert-info" role="alert" style="width:100%">' . $device_uses . '</div>'), 4);
            // We need to scream loudly if this device is using a channel driver that's disabled.
            if ($devinfo_tech == "pjsip" || $devinfo_tech == "sip") {
                $sipdriver = FreePBX::create()->Config->get_conf_setting('ASTSIPDRIVER');
                if ($sipdriver != "both") {
                    // OK, one is disabled.
                    if ($devinfo_tech == "sip") {
                        $iwant = "chan_sip";
                    } else {
                        $iwant = "chan_pjsip";
                    }
                    if ($iwant != $sipdriver) {
                        // Poot.
                        $err = sprintf(_("<strong>CRITICAL ERROR!</strong> Required Service %s is disabled! This device is unusable!"), strtoupper($iwant));
                        $currentcomponent->addguielem($section, new gui_label('techerrlabel', $err), 3);
                    }
                }
            }
            $devopts = $currentcomponent->getgeneralarrayitem('devtechs', $devinfo_tech);
            if (is_array($devopts)) {
                foreach ($devopts as $devopt => $devoptarr) {
                    $devopname = 'devinfo_' . $devopt;
                    $devoptcurrent = isset(${$devopname}) ? ${$devopname} : $devoptarr['value'];
                    $devoptjs = isset($devoptarr['jsvalidation']) ? $devoptarr['jsvalidation'] : '';
                    $devoptfailmsg = isset($devoptarr['failvalidationmsg']) ? $devoptarr['failvalidationmsg'] : '';
                    $devdisable = isset($devoptarr['disable']) ? $devoptarr['disable'] : false;
                    $devonchange = isset($devoptarr['onchange']) ? $devoptarr['onchange'] : '';
                    $prompttext = isset($devoptarr['prompttext']) ? $devoptarr['prompttext'] : $devopt;
                    $hidden = isset($devoptarr['hidden']) ? $devoptarr['hidden'] : false;
                    $type = isset($devoptarr['type']) ? $devoptarr['type'] : (isset($devoptarr['select']) ? 'select' : 'text');
                    $text = isset($devoptarr['text']) ? $devoptarr['text'] : '';
                    // We compare the existing secret against what might be in the put to detect changes when validating
                    if ($devopt == "secret") {
                        $currentcomponent->addguielem($section, new gui_hidden($devopname . "_origional", $devoptcurrent), 4);
                        if ($devoptcurrent == '' && empty($extdisplay)) {
                            $devoptcurrent = md5(uniqid());
                        }
                    }
                    if (!$hidden && ($devoptarr['level'] == 0 || $amp_conf['ALWAYS_SHOW_DEVICE_DETAILS'] && $devoptarr['level'] < 2 || $extdisplay != '')) {
                        // editing to show advanced as well
                        // Added optional selectbox to enable the unsupported misdn module
                        $tooltip = isset($devoptarr['tt']) ? $devoptarr['tt'] : '';
                        if ($type == 'select') {
                            $currentcomponent->addguielem($section, new gui_selectbox($devopname, $devoptarr['select'], $devoptcurrent, $prompttext, $tooltip, false, $devonchange, $devdisable), 4);
                        } elseif ($type == 'text') {
                            $currentcomponent->addguielem($section, new gui_textbox($devopname, $devoptcurrent, $prompttext, $tooltip, $devoptjs, $devoptfailmsg, true, 0, $devdisable), 4);
                        } elseif ($type == 'button') {
                            $currentcomponent->addguielem($section, new gui_button($devopname, $devoptcurrent, $prompttext, $tooltip, $text, $devoptjs, $devdisable), 4);
                        }
                    } else {
                        // add so only basic
                        $currentcomponent->addguielem($section, new gui_hidden($devopname, $devoptcurrent), 4);
                    }
                }
            }
        }
    }
}