if (isset($_POST['action']) && $_POST['action'] == 'edit') {
     $fields = array('fn', 'ln', 'ct', 'sd', 'rt', 'bw');
     $directory = array();
     foreach ($fields as $field) {
         foreach ($_POST[$field] as $key => $value) {
             $key++;
             if ($field == 'sd') {
                 $directory[$key][$field] = $value == '1' ? $key : '';
             } elseif ($field == 'rt' && $value == '') {
                 $directory[$key][$field] = 'default';
             } else {
                 $directory[$key][$field] = $value;
             }
         }
     }
     polycomphones_save_phones_directory($_GET['edit'], $directory);
     // Use SIP notify to reboot phone
     polycomphones_checkconfig(polycomphones_lookup_mac($_GET['edit']));
     redirect('config.php?type=setup&display=polycomphones&polycomphones_form=phones_list');
 }
 $directory = polycomphones_get_phones_directory($_GET['edit']);
 foreach ($directory as $key => $contact) {
     if ($contact['sd'] != '') {
         $directory[$key]['sd'] = '1';
     }
     if ($contact['rt'] == 'default') {
         $directory[$key]['rt'] = '';
     }
 }
 require 'modules/polycomphones/views/polycomphones_phones_directory.php';
 break;
Esempio n. 2
0
    </SIP>
  </voIpProt>
</polycomConfig>');
$id = polycomphones_lookup_mac($_GET['mac']);
$polycom_request = strpos($_SERVER['HTTP_USER_AGENT'], 'Polycom') !== false;
if ($id == null && !$polycom_request) {
    die;
}
if ($polycom_request) {
    $matches = array();
    preg_match('/FileTransport Polycom([^\\/.]*)/', $_SERVER['HTTP_USER_AGENT'], $matches);
    if ($id == null) {
        sql("INSERT INTO polycom_devices (name, mac, model, lastconfig, lastip) \n\t\t\tVALUES ('Auto Added','" . $db->escapeSimple($_GET['mac']) . "','" . $db->escapeSimple($matches[1]) . "',NOW(),'" . $db->escapeSimple($_SERVER['REMOTE_ADDR']) . "')");
        $id = sql("SELECT LAST_INSERT_ID()", 'getOne');
        polycomphones_clear_overrides($_GET['mac']);
        polycomphones_save_phones_directory($_GET['mac'], array());
    } else {
        sql("UPDATE polycom_devices SET lastconfig = NOW(), \n\t\t\tmodel = '" . $db->escapeSimple($matches[1]) . "',\n\t\t\tlastip = '" . $db->escapeSimple($_SERVER['REMOTE_ADDR']) . "'\n\t\t\tWHERE id = '" . $db->escapeSimple($id) . "'");
    }
}
$device = polycomphones_get_phones_edit($id);
$alerts = polycomphones_get_alertinfo_list();
$general = polycomphones_get_general_edit();
$exchange_module = polycomphones_check_module('exchangeum');
$parking_module = polycomphones_check_module('parking');
$features_module = polycomphones_check_module('phonefeatures');
// Lines
$primary = '';
$flexiblekeys = array_reverse(polycomphones_get_flexiblekeys($device, 'line'));
$i = 1;
foreach ($device['lines'] as $line) {
function polycomphones_save_phones_edit($id, $device)
{
    global $db;
    $create = empty($id);
    if (empty($id)) {
        sql("INSERT INTO polycom_devices (name, mac) \n\t\t\tVALUES ('" . $db->escapeSimple($device['name']) . "','" . $db->escapeSimple($device['mac']) . "')");
        $id = sql("SELECT LAST_INSERT_ID()", 'getOne');
    } else {
        sql("UPDATE polycom_devices SET \n\t\t\t\tname = '" . $db->escapeSimple($device['name']) . "',\n\t\t\t\tmac = '" . $db->escapeSimple($device['mac']) . "'\n\t\t\tWHERE id = '" . $db->escapeSimple($id) . "'");
    }
    sql("DELETE FROM polycom_device_lines WHERE id = '" . $db->escapeSimple($id) . "'");
    sql("DELETE FROM polycom_device_line_settings WHERE id = '" . $db->escapeSimple($id) . "'");
    foreach ($device['lines'] as $lineid => $line) {
        sql("INSERT INTO polycom_device_lines (id, lineid, deviceid, externalid) \n\t\t\tVALUES ('" . $db->escapeSimple($id) . "','" . $db->escapeSimple($lineid) . "'," . ($line['deviceid'] != null ? "'" . $db->escapeSimple($line['deviceid']) . "'" : 'NULL') . "," . ($line['externalid'] != null ? "'" . $db->escapeSimple($line['externalid']) . "'" : 'NULL') . ")");
        $entries = array();
        foreach ($line['settings'] as $key => $val) {
            $entries[] = '\'' . $db->escapeSimple($id) . '\',\'' . $db->escapeSimple($lineid) . '\',\'' . $db->escapeSimple($key) . '\',\'' . $db->escapeSimple($val) . '\'';
        }
        if (count($entries) > 0) {
            sql("INSERT INTO polycom_device_line_settings (id, lineid, keyword, value) \n\t\t\t\tVALUES (" . implode('),(', $entries) . ")");
        }
    }
    sql("DELETE FROM polycom_device_attendants WHERE id = '" . $db->escapeSimple($id) . "'");
    foreach ($device['attendants'] as $attendantid => $attendant) {
        sql("INSERT INTO polycom_device_attendants (id, attendantid, keyword, value, label, type) \n\t\t\tVALUES ('" . $db->escapeSimple($id) . "','" . $db->escapeSimple($attendantid) . "','" . $db->escapeSimple($attendant['keyword']) . "','" . $db->escapeSimple($attendant['value']) . "','" . $db->escapeSimple($attendant['label']) . "','" . $db->escapeSimple($attendant['type']) . "')");
    }
    $entries = array();
    foreach ($device['settings'] as $key => $val) {
        $entries[] = '\'' . $db->escapeSimple($id) . '\',\'' . $db->escapeSimple($key) . '\',\'' . $db->escapeSimple($val) . '\'';
    }
    if (count($entries) > 0) {
        sql("REPLACE INTO polycom_device_settings (id, keyword, value) \n\t\t\tVALUES (" . implode('),(', $entries) . ")");
    }
    if ($create) {
        polycomphones_clear_overrides($device['mac']);
        polycomphones_save_phones_directory($device['mac'], array());
    }
}