function endpointman_configpageinit($pagename) { global $currentcomponent, $amp_conf, $db; $display = isset($_REQUEST['display']) ? $_REQUEST['display'] : null; $type = ''; $tech = ''; $extdisplay = ''; if ($display == "extensions") { if (isset($_REQUEST['extension'])) { $extdisplay = isset($_REQUEST['extension']) ? $_REQUEST['extension'] : null; } else { $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null; } } elseif ($display == "devices") { if (isset($_REQUEST['deviceid'])) { $extdisplay = isset($_REQUEST['deviceid']) ? $_REQUEST['deviceid'] : null; } else { $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null; } } else { // we only care about extensions or devices, otherwise return return true; } if (isset($extdisplay) && !empty($extdisplay)) { $sql = "SELECT tech FROM devices WHERE id = " . $extdisplay; $tech = $db->getOne($sql); if (!$tech) { $tech = "sip"; $type = 'new'; } elseif ($tech == 'sip') { $type = 'edit'; $tech = 'sip'; } } elseif (isset($_REQUEST['tech_hardware']) or isset($_REQUEST['tech'])) { $tech = isset($_REQUEST['tech_hardware']) ? $_REQUEST['tech_hardware'] : $_REQUEST['tech']; if ($tech == 'sip_generic' or $tech == 'sip') { $tech = "sip"; $type = 'new'; } } if ($tech == 'sip' and !empty($type)) { global $endpoint; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; $delete = isset($_REQUEST['epm_delete']) ? $_REQUEST['epm_delete'] : null; $doc_root = $amp_conf['AMPWEBROOT'] . "/admin/modules/endpointman/"; if (file_exists($doc_root . "includes/functions.inc")) { require $doc_root . "includes/functions.inc"; $endpoint = new endpointmanager(); ini_set('display_errors', 0); if ($action == "del") { $sql = "SELECT mac_id,luid FROM endpointman_line_list WHERE ext = " . $extdisplay; $macid = $endpoint->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); if ($macid) { $endpoint->delete_line($macid['luid'], TRUE); } } if ($action == "edit" or $action == "add") { if (isset($delete)) { $sql = "SELECT mac_id,luid FROM endpointman_line_list WHERE ext = " . $extdisplay; $macid = $endpoint->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); if ($macid) { $endpoint->delete_line($macid['luid'], TRUE); } } $mac = isset($_REQUEST['epm_mac']) ? $_REQUEST['epm_mac'] : null; if (!empty($mac)) { //Mac is set $brand = isset($_REQUEST['epm_brand']) ? $_REQUEST['epm_brand'] : null; $model = isset($_REQUEST['epm_model']) ? $_REQUEST['epm_model'] : null; $line = isset($_REQUEST['epm_line']) ? $_REQUEST['epm_line'] : null; $temp = isset($_REQUEST['epm_temps']) ? $_REQUEST['epm_temps'] : null; if (isset($_REQUEST['name'])) { $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : null; } else { $name = isset($_REQUEST['description']) ? $_REQUEST['description'] : null; } if (isset($_REQUEST['deviceid'])) { if ($_REQUEST['devicetype'] == "fixed") { //SQL to get the Description of the extension from the extension table $sql = "SELECT name FROM users WHERE extension = '" . $_REQUEST['deviceuser'] . "'"; $name_o = $endpoint->eda->sql($sql, 'getOne'); if ($name_o) { $name = $name_o; } } } $reboot = isset($_REQUEST['epm_reboot']) ? $_REQUEST['epm_reboot'] : null; if ($endpoint->mac_check_clean($mac)) { $sql = "SELECT id FROM endpointman_mac_list WHERE mac = '" . $endpoint->mac_check_clean($mac) . "'"; $macid = $endpoint->eda->sql($sql, 'getOne'); if ($macid) { //In Database already $sql = 'SELECT * FROM endpointman_line_list WHERE ext = ' . $extdisplay . ' AND mac_id = ' . $macid; $lines_list =& $endpoint->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); if ($lines_list and isset($model) and isset($line) and !isset($delete) and isset($temp)) { //Modifying line already in the database $endpoint->update_device($macid, $model, $temp, $lines_list['luid'], $name, $lines_list['line']); $row = $endpoint->get_phone_info($macid); if (isset($reboot)) { $endpoint->prepare_configs($row); } else { $endpoint->prepare_configs($row, FALSE); } } elseif (isset($model) and !isset($delete) and isset($line) and isset($temp)) { //Add line to the database if (empty($line)) { $endpoint->add_line($macid, NULL, $extdisplay, $name); } else { $endpoint->add_line($macid, $line, $extdisplay, $name); } $endpoint->update_device($macid, $model, $temp, NULL, NULL, NULL, FALSE); $row = $endpoint->get_phone_info($macid); if (isset($reboot)) { $endpoint->prepare_configs($row); } else { $endpoint->prepare_configs($row, FALSE); } } } elseif (!isset($delete)) { //Add Extension/Phone to database $mac_id = $endpoint->add_device($mac, $model, $extdisplay, $temp, NULL, $name); if ($mac_id) { debug('Write files?'); $row = $endpoint->get_phone_info($mac_id); $endpoint->prepare_configs($row); } } } } } endpointman_applyhooks(); } else { //System can't find the include file. } } }