From 214509e2c750eeac082b64563e65ba8b3a399767 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Thu, 10 Jun 2021 12:15:18 +0200
Subject: [PATCH 1/4] Use BMO Hooks
Use BMO Hooks
Correct HTML
---
sccpManTraits/bmoFunctions.php | 57 ++++++++++++++++++++++++++++++--
views/advserver.dialtemplate.php | 6 ++--
views/advserver.keyset.php | 22 ++++++------
views/advserver.model.php | 2 +-
views/hardware.extension.php | 12 +++----
views/hardware.phone.php | 4 +--
views/hardware.sphone.php | 18 +++++-----
7 files changed, 86 insertions(+), 35 deletions(-)
diff --git a/sccpManTraits/bmoFunctions.php b/sccpManTraits/bmoFunctions.php
index 9d54576..9bbd35e 100644
--- a/sccpManTraits/bmoFunctions.php
+++ b/sccpManTraits/bmoFunctions.php
@@ -3,12 +3,41 @@
namespace FreePBX\modules\Sccp_manager\sccpManTraits;
trait bmoFunctions {
- /* unused but FPBX API requires it */
+
+ //Need to reload freePBX for modifications below to work
+
+ //need to catch extensions
+ public static function myConfigPageInits() {
+ dbug('have config page inits');
+ return array("extensions");
+ }
public function doConfigPageInit($page) {
+ if ($page == "extensions") {
+ dbug('have extensions in doConfigPageInit');
+ }
$this->doGeneralPost();
}
+ // Try to change extensions which is part of core
+ public static function myGuiHooks() {
+ return array('core');
+ }
+
+ public function doGuiHook(&$cc) {
+ dbug('$_REQUEST', $_REQUEST);
+ //dbug('CC', $cc);
+ if ($_REQUEST['display'] == "extensions" ) {
+ if (isset($_REQUEST['tech_hardware'])) {
+ dbug('Have caught hook in doGuiHook');
+ $this->getActionBar($_REQUEST);
+ }
+ //$cc->addguielem("_top", new \gui_pageheading('', 'I added a header', false));
+ }
+ }
+
+
+
/* unused but FPBX API requires it */
public function install() {
@@ -85,7 +114,6 @@ trait bmoFunctions {
'value' => _("Cancel")
),
);
-
break;
case 'sccpsettings':
$buttons = array(
@@ -101,7 +129,30 @@ trait bmoFunctions {
'value' => _("Cancel")
),
);
-
+ break;
+ case 'extensions':
+ // only called from configpage inits
+ $buttons = array(
+ 'submit' => array(
+ 'name' => 'ajaxsubmit',
+ 'id' => 'ajaxsubmit',
+ 'data-search' => '?display=sccp_custom',
+ 'value' => _("Save")
+ ),
+ 'Save' => array(
+ 'name' => 'ajaxsubmit2',
+ 'id' => 'ajaxsubmit2',
+ 'stayonpage' => 'yes',
+ 'value' => _("Save + Continue")
+ ),
+ 'cancel' => array(
+ 'name' => 'cancel',
+ 'id' => 'ajaxcancel',
+ 'data-search' => '?display=sccp_custom',
+ 'data-hash' => 'sccpdevice',
+ 'value' => _("Cancel")
+ ),
+ );
break;
}
return $buttons;
diff --git a/views/advserver.dialtemplate.php b/views/advserver.dialtemplate.php
index cc37ab7..e7bd7bf 100644
--- a/views/advserver.dialtemplate.php
+++ b/views/advserver.dialtemplate.php
@@ -12,12 +12,12 @@
-
+
@@ -39,4 +39,4 @@
}
return exp_model;
}
-
\ No newline at end of file
+
diff --git a/views/advserver.keyset.php b/views/advserver.keyset.php
index 2dc039c..6228047 100644
--- a/views/advserver.keyset.php
+++ b/views/advserver.keyset.php
@@ -54,7 +54,7 @@ $keynamearray = array('onhook' => array('sname' => 'ONHOOK', 'name' =>'Displa
-
+
@@ -72,7 +72,7 @@ $keynamearray = array('onhook' => array('sname' => 'ONHOOK', 'name' =>'Displa
-
+
@@ -101,9 +101,9 @@ $keynamearray = array('onhook' => array('sname' => 'ONHOOK', 'name' =>'Displa
Help. max len = 15
-
+
-
+
$value) {
@@ -129,7 +129,7 @@ foreach ($keysetarray as $key => $value) {
}
echo '';
$i ++;
}
-?>
-
-
+?>
+
+
+
-
+
\ No newline at end of file
+
diff --git a/views/advserver.model.php b/views/advserver.model.php
index 2b13cf7..3ff44cf 100644
--- a/views/advserver.model.php
+++ b/views/advserver.model.php
@@ -33,7 +33,7 @@
-
+
|
diff --git a/views/hardware.extension.php b/views/hardware.extension.php
index e7eefed..32d1e0a 100644
--- a/views/hardware.extension.php
+++ b/views/hardware.extension.php
@@ -18,9 +18,9 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {
-
+
@@ -39,12 +39,12 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {
function DispayPhoneActionsKeyFormatter(value, row, index) {
var exp_dev = '';
var rmn_dev = '';
- exp_dev += ' ';
- exp_dev += '';
+ exp_dev += " ";
+ exp_dev += "";
if (rmn_dev == 'yes') {
- exp_dev += ' ';
+ exp_dev += " ";
}
return exp_dev;
- return ' ';
+ return " ";
}
diff --git a/views/hardware.phone.php b/views/hardware.phone.php
index cf83ae4..a18f259 100644
--- a/views/hardware.phone.php
+++ b/views/hardware.phone.php
@@ -14,7 +14,7 @@
-
+
|
diff --git a/views/hardware.sphone.php b/views/hardware.sphone.php
index 7ee550d..7d5094a 100644
--- a/views/hardware.sphone.php
+++ b/views/hardware.sphone.php
@@ -14,7 +14,7 @@
-
+
|
- |
+ |
|
|
|
@@ -51,9 +51,9 @@
exp_model += ' \n';
-
+
} else {
exp_model += ' \n';
exp_model += ' ';
@@ -71,13 +71,13 @@
exp_model += ' + ' + row['addon'];
}
}
- return exp_model;
+ return exp_model;
}
function LineFormatterS(value, row, index) {
if (value === null) {
return '-- EMPTY --';
}
- var data = value.split(";");
+ var data = value.split(";");
result = '';
for (var i = 0; i < data.length; i++) {
var val = data[i].split(',');
@@ -87,5 +87,5 @@
}
return result;
}
-
-
\ No newline at end of file
+
+
From cf546961fea8679ad3b70c3cd2682548e8bab676 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Thu, 10 Jun 2021 16:57:19 +0200
Subject: [PATCH 2/4] Add redirect after saving to sccp_line
Add redirect after saving to sccpline
Revert changes in page script formatting
---
conf/Sccp.class.php.v433 | 15 +--------------
sccpManTraits/bmoFunctions.php | 16 +++++-----------
views/hardware.extension.php | 8 ++++----
views/hardware.rnav.php | 2 +-
4 files changed, 11 insertions(+), 30 deletions(-)
diff --git a/conf/Sccp.class.php.v433 b/conf/Sccp.class.php.v433
index 46fbbda..b839999 100644
--- a/conf/Sccp.class.php.v433
+++ b/conf/Sccp.class.php.v433
@@ -31,21 +31,8 @@ class Sccp extends \FreePBX\modules\Core\Driver {
);
}
-/* public function addDevice1($id, $settings) {
- $sql = 'INSERT INTO sccp (id, keyword, data, flags) values (?,?,?,?)';
- $sth = $this->database->prepare($sql);
- $settings = is_array($settings)?$settings:array();
- foreach($settings as $key => $setting) {
- $sth->execute(array($id,$key,$setting['value'],$setting['flag']));
- }
- return true;
- }
-*/
public function addDevice($id, $settings) {
$add_fld = array ("name"=>'label',"outboundcid"=>'cid_num',"langcode"=>'language',"extdisplay"=>'description');
- // print_r($_REQUEST);
- // echo '
';
- // die(print_r($settings));
$settings['cid_num']['value'] = '';
$settings['cid_name']['value'] = $label;
$settings['mailbox']['value']= '';
@@ -84,7 +71,6 @@ class Sccp extends \FreePBX\modules\Core\Driver {
}
}
- // die(print_r($settings));
$tech = Array();
$sql = "DESCRIBE sccpline";
foreach ($this->database->query($sql) as $row) {
@@ -102,6 +88,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
$sth = $this->database->prepare($sql);
$sth->execute();
+ redirect('http://192.168.50.254/admin/config.php?display=sccp_phone', false);
return true;
}
diff --git a/sccpManTraits/bmoFunctions.php b/sccpManTraits/bmoFunctions.php
index 9bbd35e..b75a159 100644
--- a/sccpManTraits/bmoFunctions.php
+++ b/sccpManTraits/bmoFunctions.php
@@ -6,15 +6,13 @@ trait bmoFunctions {
//Need to reload freePBX for modifications below to work
- //need to catch extensions
+ //want to catch extensions
public static function myConfigPageInits() {
- dbug('have config page inits');
return array("extensions");
}
public function doConfigPageInit($page) {
if ($page == "extensions") {
- dbug('have extensions in doConfigPageInit');
}
$this->doGeneralPost();
}
@@ -25,19 +23,13 @@ trait bmoFunctions {
}
public function doGuiHook(&$cc) {
- dbug('$_REQUEST', $_REQUEST);
- //dbug('CC', $cc);
if ($_REQUEST['display'] == "extensions" ) {
if (isset($_REQUEST['tech_hardware'])) {
- dbug('Have caught hook in doGuiHook');
- $this->getActionBar($_REQUEST);
+ //this is the add extensions form
}
- //$cc->addguielem("_top", new \gui_pageheading('', 'I added a header', false));
}
}
-
-
-
+
/* unused but FPBX API requires it */
public function install() {
@@ -64,6 +56,7 @@ trait bmoFunctions {
public function getActionBar($request) {
$buttons = array();
+ dbug('Request in BMO is', $request);
switch ($request['display']) {
case 'sccp_adv':
if (empty($request['tech_hardware'])) {
@@ -132,6 +125,7 @@ trait bmoFunctions {
break;
case 'extensions':
// only called from configpage inits
+ dbug('in case extensions');
$buttons = array(
'submit' => array(
'name' => 'ajaxsubmit',
diff --git a/views/hardware.extension.php b/views/hardware.extension.php
index 32d1e0a..d6cde2a 100644
--- a/views/hardware.extension.php
+++ b/views/hardware.extension.php
@@ -39,12 +39,12 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {
function DispayPhoneActionsKeyFormatter(value, row, index) {
var exp_dev = '';
var rmn_dev = '';
- exp_dev += " ";
- exp_dev += "";
+ exp_dev += ' ';
+ exp_dev += '';
if (rmn_dev == 'yes') {
- exp_dev += " ";
+ exp_dev += ' ';
}
return exp_dev;
- return " ";
+ return ' ';
}
diff --git a/views/hardware.rnav.php b/views/hardware.rnav.php
index 3080456..89914b8 100644
--- a/views/hardware.rnav.php
+++ b/views/hardware.rnav.php
@@ -3,7 +3,7 @@
-
+
From 7427fcabb8623b45b23795ac3c0bfae055a9d2a7 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Thu, 10 Jun 2021 17:41:18 +0200
Subject: [PATCH 3/4] Standardise URL
Standardise URL based on PHP Defaults
---
conf/Sccp.class.php.v433 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/conf/Sccp.class.php.v433 b/conf/Sccp.class.php.v433
index b839999..0c0ee07 100644
--- a/conf/Sccp.class.php.v433
+++ b/conf/Sccp.class.php.v433
@@ -88,7 +88,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
$sth = $this->database->prepare($sql);
$sth->execute();
- redirect('http://192.168.50.254/admin/config.php?display=sccp_phone', false);
+ redirect("http://{$_SERVER['SERVER_ADDR']}/admin/config.php?display=sccp_phone", false);
return true;
}
From 9547cfe92728bb99f4c826358a78e009fef21452 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Fri, 11 Jun 2021 08:54:24 +0200
Subject: [PATCH 4/4] Clean up and document redirect changes
Add comments
Standardise URL's
Remove surplus cases
---
conf/Sccp.class.php.v433 | 6 ++++-
sccpManTraits/bmoFunctions.php | 41 +++++++++-------------------------
2 files changed, 16 insertions(+), 31 deletions(-)
diff --git a/conf/Sccp.class.php.v433 b/conf/Sccp.class.php.v433
index 0c0ee07..253caef 100644
--- a/conf/Sccp.class.php.v433
+++ b/conf/Sccp.class.php.v433
@@ -32,6 +32,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
}
public function addDevice($id, $settings) {
+ global $currentcomponent;
$add_fld = array ("name"=>'label',"outboundcid"=>'cid_num',"langcode"=>'language',"extdisplay"=>'description');
$settings['cid_num']['value'] = '';
$settings['cid_name']['value'] = $label;
@@ -88,7 +89,10 @@ class Sccp extends \FreePBX\modules\Core\Driver {
$sth = $this->database->prepare($sql);
$sth->execute();
- redirect("http://{$_SERVER['SERVER_ADDR']}/admin/config.php?display=sccp_phone", false);
+ // Redirect to SCCP Phone page. This was last function in add so
+ // should be safe. Prefer to add in Hooks, but is not followed
+ // even if set for $currentcomponent
+ redirect("config.php?display=sccp_phone", false);
return true;
}
diff --git a/sccpManTraits/bmoFunctions.php b/sccpManTraits/bmoFunctions.php
index b75a159..1bd6817 100644
--- a/sccpManTraits/bmoFunctions.php
+++ b/sccpManTraits/bmoFunctions.php
@@ -24,12 +24,19 @@ trait bmoFunctions {
public function doGuiHook(&$cc) {
if ($_REQUEST['display'] == "extensions" ) {
- if (isset($_REQUEST['tech_hardware'])) {
- //this is the add extensions form
+ if ($_REQUEST['tech_hardware'] == 'sccp_custom') {
+ /*
+ this is the add extensions form
+ On submit returns to extensions page. Users prefer that it returns
+ To Sccp Phone.
+ Below adds redirect URL, but it is not followed
+ $cc->setRedirectURL("config.php?display=sccp_phone");
+ so force redirect at end of addDevice in SccpClass
+ */
}
}
}
-
+
/* unused but FPBX API requires it */
public function install() {
@@ -56,7 +63,6 @@ trait bmoFunctions {
public function getActionBar($request) {
$buttons = array();
- dbug('Request in BMO is', $request);
switch ($request['display']) {
case 'sccp_adv':
if (empty($request['tech_hardware'])) {
@@ -123,38 +129,13 @@ trait bmoFunctions {
),
);
break;
- case 'extensions':
- // only called from configpage inits
- dbug('in case extensions');
- $buttons = array(
- 'submit' => array(
- 'name' => 'ajaxsubmit',
- 'id' => 'ajaxsubmit',
- 'data-search' => '?display=sccp_custom',
- 'value' => _("Save")
- ),
- 'Save' => array(
- 'name' => 'ajaxsubmit2',
- 'id' => 'ajaxsubmit2',
- 'stayonpage' => 'yes',
- 'value' => _("Save + Continue")
- ),
- 'cancel' => array(
- 'name' => 'cancel',
- 'id' => 'ajaxcancel',
- 'data-search' => '?display=sccp_custom',
- 'data-hash' => 'sccpdevice',
- 'value' => _("Cancel")
- ),
- );
- break;
}
return $buttons;
}
public function getRightNav($request) {
if (isset($request['tech_hardware']) && ($request['tech_hardware'] == 'cisco')) {
- return load_view("/var/www/html/admin/modules/sccp_manager/views/hardware.rnav.php", array('request' => $request));
+ return load_view($_SERVER['DOCUMENT_ROOT'] .'/admin/modules/sccp_manager/views/hardware.rnav.php', array('request' => $request));
}
}