- Add Buton "Update Buton Labels". If you replace User nams, this functon Regenerate device labels

This commit is contained in:
PhantomVl 2019-05-06 18:22:19 +03:00
parent c23a697234
commit fd57b885e6
8 changed files with 173 additions and 24 deletions

View file

@ -106,6 +106,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
public $sccp_conf_init = array();
public $xml_data;
public $class_error; //error construct
public $info_warning;
public function __construct($freepbx = null) {
if ($freepbx == null) {
@ -621,6 +622,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
case 'model_update':
case 'model_add':
case 'model_delete':
case 'update_button_label':
case 'updateSoftKey':
case 'deleteSoftKey':
case 'delete_dialplan':
@ -646,6 +648,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$this->sccp_create_tftp_XML();
$res = $this->srvinterface->sccp_core_commands(array('cmd' => 'sccp_reload'));
// $res = $this->srvinterface->sccp_core_commands(array('cmd' => 'restart_phone'));
$msg = 'Config Saved: ' . $res['Response'] . '. Info :' . $res['data'];
// needreload();
// !TODO!: It is necessary in the future to check, and replace all server responses on correct messages. Use _(msg)
@ -755,6 +758,24 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return array('status' => true, 'message' => 'Reset command send ' . $msg, 'reload' => true);
// }
break;
case 'update_button_label':
$msg = '';
$hw_list = array();
// return array('status' => false, 'message' => 'update_button_label send ' . $msg, 'reload' => false);
if (!empty($request['name'])) {
foreach ($request['name'] as $idv) {
if (!(strpos($idv, 'SEP') === false)) {
$hw_list[] = array('name' => $idv);
}
if ($idv == 'all') {
}
}
}
$res = $this->sccp_db_update_butons($hw_list);
$msg .= $res['Response'] . ' raw: ' . $res['data'] . ' ';
// !TODO!: It is necessary in the future to check, and replace all server responses on correct messages. Use _(msg)
return array('status' => true, 'message' => 'Update Butons Labels Complite ' . $msg, 'reload' => true);
case 'model_add':
$save_settings = array();
$key_name = array('model', 'vendor', 'dns', 'buttons', 'loadimage', 'loadinformationid', 'nametemplate');
@ -1792,6 +1813,52 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return $errors;
}
/*
* Update Butons Labels on mysql DB
*
*/
private function sccp_db_update_butons($hw_list = array()) {
$save_buttons = array();
if (!empty($hw_list)) {
$buton_list = array();
foreach ($hw_list as $value) {
$buton_tmp =$this->dbinterface->get_db_SccpTableData("get_sccpdevice_buttons", array('buttontype'=>'speeddial','id'=>$value['name']));
// die(print_r($buton_tmp,1));
if (!empty($buton_tmp)) {
$buton_list = array_merge($buton_list, $buton_tmp);
}
}
} else {
$buton_list = $this->dbinterface->get_db_SccpTableData("get_sccpdevice_buttons", array('buttontype'=>'speeddial'));
}
// die(print_r($buton_list,1));
if (empty($buton_list)) {
return array('Response'=> ' Found 0 device ', 'data'=> '');
}
$copy_fld = array('ref','reftype','instance','buttontype');
$user_list = $user_list = $this->dbinterface->get_db_SccpTableByID("SccpExtension",Array(),'name');
foreach ($buton_list as $value) {
$btn_opt = explode(',',$value['options']);
$btn_id = $btn_opt[0];
if (!empty($user_list[$btn_id])){
if ($user_list[$btn_id]['label'] != $value['name']) {
$btn_data['name'] = $user_list[$btn_id]['label'];
foreach ($copy_fld as $ckey) {
$btn_data[$ckey] = $value[$ckey];
}
$save_buttons[] = $btn_data;
}
}
}
if (empty($save_buttons)) {
return array('Response'=> 'No update required', 'data'=> ' 0 - records ');
}
$res = $this->dbinterface->sccp_save_db("sccpbuttons", $save_buttons, 'replace', '','');
return array('Response'=> 'Update records :'.count($save_buttons),'data'=>$res);
}
/*
* Save Config Value to mysql DB
* sccp_db_save_setting(empty) - Save All settings from $sccpvalues

View file

@ -26,6 +26,18 @@ class dbinterface {
/*
* Core Access Function
*/
public function get_db_SccpTableByID($dataid, $data = array(), $indexField = '') {
$resut = array();
$raw = $this->get_db_SccpTableData($dataid, $data);
if ( empty($raw) || empty($indexField)) {
return $raw;
}
foreach ($raw as $value) {
$id = $value[$indexField];
$resut[$id] = $value;
}
return $resut;
}
public function get_db_SccpTableData($dataid, $data = array()) {
if ($dataid == '') {
@ -76,8 +88,19 @@ class dbinterface {
$raw_settings = sql($sql, "getRow", DB_FETCHMODE_ASSOC);
break;
case "get_sccpdevice_buttons":
$sql = 'SELECT * FROM sccpbuttonconfig WHERE ref="' . $data['id'] . '" ORDER BY `instance`;';
$sql = '';
if (!empty($data['buttontype'])) {
$sql .= 'buttontype="' . $data['buttontype'] . '" ';
}
if (!empty($data['id'])) {
$sql .= (empty($sql)) ? 'ref="' . $data['id'] . '" ' : 'and ref="' . $data['id'] . '" ';
}
if (!empty($sql)) {
$sql = 'SELECT * FROM sccpbuttonconfig WHERE ' .$sql. 'ORDER BY `instance`;';
$raw_settings = sql($sql, "getAll", DB_FETCHMODE_ASSOC);
} else {
$raw_settings = Array();
}
break;
}
@ -90,6 +113,12 @@ class dbinterface {
return $raw_settings;
}
public function get_db_sysvalues() {
$sql = "SHOW VARIABLES LIKE '%group_concat%'";
$raw_settings = sql($sql, "getRow", DB_FETCHMODE_ASSOC);
return $raw_settings;
}
/*
* Get Sccp Device Model information
*/
@ -213,11 +242,20 @@ class dbinterface {
if ($mode == 'delete') {
break;
}
if (!empty($save_value)) {
if (empty($save_value)) {
break;
}
if ($mode == 'replace') {
$sql = 'UPDATE `sccpbuttonconfig` SET `name`=? WHERE `ref`= ? AND `reftype`=? AND `instance`=? AND `buttontype`=?;';
// $sql = 'INSERT INTO `sccpbuttonconfig` (`ref`, `reftype`,`instance`, `buttontype`, `name`, `options`) VALUES (?,?,?,?,?,?);';
// die(print_r($save_value,1));
$stmt = $db->prepare($sql);
$result= $db->executeMultiple($stmt, $save_value);
} else {
$sql = 'INSERT INTO `sccpbuttonconfig` (`ref`, `reftype`,`instance`, `buttontype`, `name`, `options`) VALUES (?,?,?,?,?,?);';
// die(print_r($save_value,1));
$stmt = $db->prepare($sql);
$res = $db->executeMultiple($stmt, $save_value);
$result = $db->executeMultiple($stmt, $save_value);
}
break;

View file

@ -601,16 +601,26 @@ $(document).ready(function () {
}
}
if ($(this).data('id') === 'reset_dev' || $(this).data('id') === 'reset_token') {
if ($(this).data('id') === 'reset_dev' || $(this).data('id') === 'reset_token' || $(this).data('id') === 'update_button_label' ) {
var dev_cmd = $(this).data('id');
var datas = '';
var i = 0;
var conf_msg = '??????';
if ($(this).data('id') === 'reset_dev') {
conf_msg = 'Reset All device ?';
}
if ($(this).data('id') === 'reset_token') {
conf_msg = 'Reset Token on All device ?';
}
if ($(this).data('id') === 'update_button_label') {
conf_msg = 'Update Butons Labels on All device ?';
}
$('table').bootstrapTable('getSelections').forEach(function (entry) {
datas = datas + 'name[' + i + ']=' + entry['name'] + '&';
i++;
});
if (datas === '') {
if (confirm('Resaet All device')) {
if (confirm(conf_msg)) {
datas = 'name[0]=all';
} else {
dev_cmd = '';

View file

@ -185,8 +185,8 @@ ri ^(ATA030204SCCP090202A.zup)$ firmware/ata186/\1
#ri ^(.+\.sbn)$ firmware/\1
# Keep locales in a separate directory (optional)
ri ^(.+)\/(.+-sccp.jar)$ locales/\1/\2
ri ^(.+)\/(.+-dictionary.xml)$ locales/\1/\2
ri ^(.+)\/(.+-sccp.jar)$ languages/\1/\2
ri ^(.+)\/(.+-dictionary.xml)$ languages/\1/\2
ri ^(.+)\/(.+-dictionary-ext.xml)$ languages/\1/\2
ri ^(.+)\/(.+-tones.xml)$ languages/\1/\2
ri ^(.+)\/(.+-font.xml)$ languages/\1/\2

View file

@ -266,6 +266,7 @@ function Get_DB_config($sccp_compatible) {
'video_tos' => array('def_modify' => "0x88"),
'video_cos' => array('def_modify' => "5"),
'trustphoneip' => array('drop' => "yes"),
'transfer_on_hangup' => array('create' => "enum('on','off') NULL DEFAULT NULL", 'modify' => "enum('on','off')"),
'phonecodepage' => array('create' => 'VARCHAR(50) NULL DEFAULT NULL', 'modify' => "VARCHAR(50)"),
'mwilamp' => array('create' => "enum('on','off','wink','flash','blink') NULL default 'on'", 'modify' => "enum('on','off','wink','flash','blink')"),
'mwioncall' => array('create' => "enum('on','off') NULL default 'on'", 'modify' => "enum('on','off')"),
@ -330,7 +331,7 @@ function Get_DB_config($sccp_compatible) {
'_description' => array('rename' => "description"),
'_loginname' => array('drop' => "yes"),
'_profileid' => array('drop' => "yes"),
'transfer_on_hangup' => array('create' => "enum('on','off') NULL DEFAULT NULL", 'modify' => "enum('on','off')"),
),
'sccpline' => array(
'directed_pickup' => array('create' => "enum('on','off') NULL default NULL", 'modify' => "enum('on','off')"),

View file

@ -254,3 +254,6 @@ if (!empty($_REQUEST['ru_id'])) {
</div>
</form>
<div class="section-butom" data-for="<?php echo $forminfo[0]['name'];?>">
<h3></h3>
</div>

View file

@ -21,6 +21,9 @@
<button name="cr_sccp_phone_xml" class="btn sccp_update btn-default" data-id="create-cnf">
<i class="glyphicon glyphicon-ok"></i> <span><?php echo _('Create CNF') ?></span>
</button>
<button name="update_button_label" class="btn sccp_update btn-default" data-id="update_button_label">
<i class="glyphicon glyphicon-ok"></i> <span><?php echo _('Update Button label') ?></span>
</button>
<button name="reset_sccp_phone" class="btn sccp_update btn-default" data-id="reset_dev">
<i class="glyphicon glyphicon-ok"></i> <span><?php echo _('Reset Device') ?></span>
</button>

View file

@ -30,6 +30,9 @@ $info['dbinterface'] = $this->dbinterface->info();
$info['aminterface'] = $this->aminterface->info();
$db_Schema = $this->dbinterface->validate();
$mysql_info = $this->dbinterface->get_db_sysvalues();
$info['XML'] = $this->xmlinterface->info();
$info['sccp_class'] = $driver['sccp'];
$info['Core_sccp'] = array('Version' => $core['Version'], 'about'=> 'Sccp ver.'. $core['Version'].' r'.$core['vCode']. ' Revision :'. $core['RevisionNum']. ' Hash :'. $core['RevisionHash']);
@ -89,30 +92,27 @@ if (empty($conf_realtime)) {
if (!empty($rt_info)) {
$info['ConfigsRealTime'] = array('Version' => 'Error', 'about'=> $rt_info);
}
}
// $mysql_info
if ($mysql_info['Value'] <= '2000') {
$this->info_warning['MySql'] = Array('Increase Mysql Group Concat Max. Length','Step 1: Go to mysql path <br> nano /etc/my.cnf',
'Step 2: And add the following line below [mysqld] as shown below <br> [mysql] <br>group_concat_max_len = 4096 or more',
'Step 3: Save and restart <br> systemctl restart mariadb.service<br> Or <br> service mysqld restart');
}
//global $amp_conf;
// ************************************************************************************
print_r("<br> Request:<br><pre>");
$json = '';
$buton_list = $this->dbinterface->get_db_SccpTableData("get_sccpdevice_buttons", array('buttontype'=>'speeddial'));
$user_list = $this->dbinterface->get_db_SccpTableByID("SccpExtension",Array(),'name');
print_r("<br> Help Info:<br><pre>");
print_r("<br>");
// print_r($conf_realtime);
//print_r($buton_list);
print_r("<br>");
print_r($user_list);
print_r("<br>");
// print_r("DIRECT START");
// print_r($this->sccpvalues['ccm_address']);
//print_r($this->get_php_classes('\\FreePBX\\modules\\'));
/*
print_r(get_declared_classes());
print_r($this->aminterface->open());
print_r($this->aminterface->_error);
print_r("<br>");
*/
//print_r($this->dbinterface->get_db_SccpTableData('SccpExtension'));
// print_r($this->srvinterface->getеtestChanSCCP_GlablsInfo());
// $test_data = $this->srvinterface-> astman_GetRaw('ExtensionStateList');
@ -134,6 +134,33 @@ print_r("<br> Request:<br><pre>");
//print_r($this->dbinterface->info());
if (!empty($this->info_warning)) {
?>
<div class="fpbx-container container-fluid">
<div class="row">
<div class="container">
<h2 style="border:2px solid Tomato;color:Tomato;" >Sccp Manager Warning</h2>
<div class="table-responsive">
<br> There are Warning in the SCCP Module:<br><pre>
<?php
foreach ($this->info_warning as $key => $value) {
echo '<h3>'.$key.'</h3>';
if (is_array($value)) {
echo '<li>'.implode('</li><li>',$value).'</li>';
} else {
echo '<li>'.$value.'</li>';
}
}
?>
</pre>
<br><h4 style="border:2px solid Tomato;color:Green;" > Check these problems before continuing to work.</h4> <br>
</div>
</div>
</div>
</div>
<br>
<?php }
if (!empty($this->class_error)) {
?>
<div class="fpbx-container container-fluid">