From 8d8d45d2d96d4b8b90e3fe48d51309d55eaa363f Mon Sep 17 00:00:00 2001 From: PhantomVl Date: Tue, 23 Apr 2019 13:32:52 +0300 Subject: [PATCH] - Create Cisco phone service for user mobility. --- Sccp_manager.class.php | 4 +- Sccp_manager.inc/dbinterface.class.php | 10 +- {!Readme.txt => Technical.note}/ATA.txt | 0 .../Conferencing.txt | 0 .../RedialMenu.txt | 0 .../SEP0000000000.cnf.xml_annotated | 0 {!Readme.txt => Technical.note}/SEPXML.txt | 0 .../backgroundImage.txt | 0 {!Readme.txt => Technical.note}/dialplan.txt | 0 {!Readme.txt => Technical.note}/freppbx.txt | 0 .../help.tftprewrite | 0 {!Readme.txt => Technical.note}/make_sccp.txt | 0 .../sccp.conf.annotated | 0 conf/sccpgeneral.xml.v433 | 2 +- install.php | 190 +++++++++--------- views/form.addruser.php | 2 +- views/hardware.phone.php | 5 +- 17 files changed, 108 insertions(+), 105 deletions(-) rename {!Readme.txt => Technical.note}/ATA.txt (100%) rename {!Readme.txt => Technical.note}/Conferencing.txt (100%) rename {!Readme.txt => Technical.note}/RedialMenu.txt (100%) rename {!Readme.txt => Technical.note}/SEP0000000000.cnf.xml_annotated (100%) rename {!Readme.txt => Technical.note}/SEPXML.txt (100%) rename {!Readme.txt => Technical.note}/backgroundImage.txt (100%) rename {!Readme.txt => Technical.note}/dialplan.txt (100%) rename {!Readme.txt => Technical.note}/freppbx.txt (100%) rename {!Readme.txt => Technical.note}/help.tftprewrite (100%) rename {!Readme.txt => Technical.note}/make_sccp.txt (100%) rename {!Readme.txt => Technical.note}/sccp.conf.annotated (100%) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index bda0ece..be1ac21 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -1319,7 +1319,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { * */ $name_dev = ''; - $db_field = $this->dbinterface->get_db_SccpTableData("get_colums_sccpusers"); + $db_field = $this->dbinterface->get_db_SccpTableData("get_colums_sccpuser"); // $hw_id = (empty($get_settings['sccp_deviceid'])) ? 'new' : $get_settings['sccp_deviceid']; // $update_hw = ($hw_id == 'new') ? 'update' : 'clear'; $hw_prefix = 'SEP'; @@ -1394,7 +1394,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { // return $save_settings; // $update_hw = ($hw_id == 'new') ? 'update' : 'clear'; - $this->dbinterface->sccp_save_db("sccpusers", $save_settings, 'replace', 'name'); + $this->dbinterface->sccp_save_db("sccpuser", $save_settings, 'replace', 'name'); $save_buttons = $this-> get_buttons_phone($get_settings,$name_dev, 'sccpline'); // Sace Buttons config diff --git a/Sccp_manager.inc/dbinterface.class.php b/Sccp_manager.inc/dbinterface.class.php index 9cdcb0b..5be7aa3 100644 --- a/Sccp_manager.inc/dbinterface.class.php +++ b/Sccp_manager.inc/dbinterface.class.php @@ -56,8 +56,8 @@ class dbinterface { $sql = "DESCRIBE sccpdevice"; $raw_settings = sql($sql, "getAll", DB_FETCHMODE_ASSOC); break; - case "get_colums_sccpusers": - $sql = "DESCRIBE sccpusers"; + case "get_colums_sccpuser": + $sql = "DESCRIBE sccpuser"; $raw_settings = sql($sql, "getAll", DB_FETCHMODE_ASSOC); break; case "get_sccpdevice_byid": @@ -67,8 +67,8 @@ class dbinterface { . 'LEFT JOIN sccpdevmodel as addon ON t1.addon=addon.model WHERE name="' . $data['id'] . '";'; $raw_settings = sql($sql, "getRow", DB_FETCHMODE_ASSOC); break; - case "get_sccpdusers": - $sql = "SELECT * FROM `sccpusers` "; + case "get_sccpuser": + $sql = "SELECT * FROM `sccpuser` "; if (!empty($data['id'])) { $sql .= 'WHERE name="' . $data['id'] . '" '; } @@ -173,7 +173,7 @@ class dbinterface { break; case 'sccpdevmodel': case 'sccpdevice': - case 'sccpusers': + case 'sccpuser': $sql_db = $db_name; $sql_key = ""; $sql_var = ""; diff --git a/!Readme.txt/ATA.txt b/Technical.note/ATA.txt similarity index 100% rename from !Readme.txt/ATA.txt rename to Technical.note/ATA.txt diff --git a/!Readme.txt/Conferencing.txt b/Technical.note/Conferencing.txt similarity index 100% rename from !Readme.txt/Conferencing.txt rename to Technical.note/Conferencing.txt diff --git a/!Readme.txt/RedialMenu.txt b/Technical.note/RedialMenu.txt similarity index 100% rename from !Readme.txt/RedialMenu.txt rename to Technical.note/RedialMenu.txt diff --git a/!Readme.txt/SEP0000000000.cnf.xml_annotated b/Technical.note/SEP0000000000.cnf.xml_annotated similarity index 100% rename from !Readme.txt/SEP0000000000.cnf.xml_annotated rename to Technical.note/SEP0000000000.cnf.xml_annotated diff --git a/!Readme.txt/SEPXML.txt b/Technical.note/SEPXML.txt similarity index 100% rename from !Readme.txt/SEPXML.txt rename to Technical.note/SEPXML.txt diff --git a/!Readme.txt/backgroundImage.txt b/Technical.note/backgroundImage.txt similarity index 100% rename from !Readme.txt/backgroundImage.txt rename to Technical.note/backgroundImage.txt diff --git a/!Readme.txt/dialplan.txt b/Technical.note/dialplan.txt similarity index 100% rename from !Readme.txt/dialplan.txt rename to Technical.note/dialplan.txt diff --git a/!Readme.txt/freppbx.txt b/Technical.note/freppbx.txt similarity index 100% rename from !Readme.txt/freppbx.txt rename to Technical.note/freppbx.txt diff --git a/!Readme.txt/help.tftprewrite b/Technical.note/help.tftprewrite similarity index 100% rename from !Readme.txt/help.tftprewrite rename to Technical.note/help.tftprewrite diff --git a/!Readme.txt/make_sccp.txt b/Technical.note/make_sccp.txt similarity index 100% rename from !Readme.txt/make_sccp.txt rename to Technical.note/make_sccp.txt diff --git a/!Readme.txt/sccp.conf.annotated b/Technical.note/sccp.conf.annotated similarity index 100% rename from !Readme.txt/sccp.conf.annotated rename to Technical.note/sccp.conf.annotated diff --git a/conf/sccpgeneral.xml.v433 b/conf/sccpgeneral.xml.v433 index f65b27e..e5df4aa 100644 --- a/conf/sccpgeneral.xml.v433 +++ b/conf/sccpgeneral.xml.v433 @@ -1584,7 +1584,7 @@ and open the template in the editor. Base Version before all crash :-) - pin + password Help! diff --git a/install.php b/install.php index c33f2b2..a9c3c71 100644 --- a/install.php +++ b/install.php @@ -16,7 +16,8 @@ global $amp_conf; global $astman; global $version; global $srvinterface; - +global $mobile_hw; +$mobile_hw = '0'; $class = "\\FreePBX\\Modules\\Sccp_manager\\srvinterface"; if (!class_exists($class, false)) { @@ -27,6 +28,7 @@ if (class_exists($class, false)) { } function Get_DB_config($sccp_compatible) { + global $mobile_hw; $db_config_v0 = array( 'sccpdevmodel' => array( 'enabled' => array('create' => "INT(2) NULL DEFAULT '0'"), @@ -220,6 +222,7 @@ function Get_DB_config($sccp_compatible) { ) ); + // Software mobile $db_config_v4 = array( 'sccpdevmodel' => array( 'enabled' => array('create' => "INT(2) NULL DEFAULT '0'"), @@ -304,10 +307,44 @@ function Get_DB_config($sccp_compatible) { 'echocancel' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"), 'silencesuppression' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"), 'dnd' => array('create' => "enum('off','reject','silent','user') NOT NULL default 'reject'", 'modify' => "enum('off','reject','silent','user')", 'def_modify' => "reject") + ), + 'sccpuser' => array( + 'name' => array('create' => "varchar(20) NOT NULL", 'modify' => "VARCHAR(20)" ), + 'pin' => array('create' => "varchar(7) NOT NULL", 'modify' => "VARCHAR(7)" ), + 'password' => array('create' => "varchar(7) NOT NULL", 'modify' => "VARCHAR(7)" ), + 'description' => array('create' => "varchar(45) NOT NULL", 'modify' => "VARCHAR(45)" ), + 'roaminglogin' => array('create' => "ENUM('on','off','multi') NULL DEFAULT 'off'", 'modify' => "ENUM('on','off','multi')" ), + 'auto_logout' => array('create' => "ENUM('on','off') NULL DEFAULT 'off'", 'modify' => "ENUM('on','off')" ), + 'homedevice' => array('create' => "varchar(20) NOT NULL", 'modify' => "VARCHAR(20)" ), + 'devicegroup' => array('create' => "varchar(7) NOT NULL", 'modify' => "VARCHAR(7)" ), + ) + ); +// Hardware Mobile. Can switch Softwate to Hardware + $db_config_v4M = array( + 'sccpdevmodel' => array( + 'loadinformationid' => array('create' => "VARCHAR(30) NULL DEFAULT NULL") + ), + 'sccpdevice' => array( + 'pickupexten' => array('drop' => "yes"), + 'directed_pickup' => array('drop' => "yes"), + '_description' => array('rename' => "description"), + '_loginname' => array('drop' => "yes"), + '_profileid' => array('drop' => "yes"), + + ), + 'sccpline' => array( + 'directed_pickup' => array('create' => "enum('on','off') NULL default NULL", 'modify' => "enum('on','off')"), + ), + 'sccpuser' => array( + 'id' => array('create' => "varchar(20) NOT NULL", 'modify' => "VARCHAR(20)" ), + 'name' => array('create' => "varchar(45) NOT NULL", 'modify' => "VARCHAR(45)" ), ) ); if ($sccp_compatible >= 433 ) { + if ($mobile_hw == '1') { + return $db_config_v4M; + } return $db_config_v4; } if ($sccp_compatible >= 430) { @@ -417,40 +454,6 @@ function InstallDB_Buttons() { if (db::IsError($check)) { die_freepbx("Can not create sccpbuttonconfig table, error:$check\n"); } -/* - } else { - $db_result = $db->getAll("SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE " - . "WHERE TABLE_SCHEMA = 'asterisk' AND TABLE_NAME = 'buttonconfig' AND REFERENCED_COLUMN_NAME IS NOT NULL;"); - - if (DB::IsError($db_result)) { - die_freepbx("Can not get informations TABLE_SCHEMA\n"); - } - - $sql = ''; - $sql = 'RENAME TABLE `buttonconfig` TO `sccpbuttonconfig`;'; - $sql .= "ALTER TABLE `sccpbuttonconfig` ADD COLUMN `user` VARCHAR(20) NOT NULL DEFAULT '' AFTER `device`;"; - $check = $db->query($sql); - if (db::IsError($check)) { - die_freepbx("Can not create sccpsettings table, error:$check\n"); - } - $sql = ''; - foreach ($db_result as $tabl_data) { - $fld_id = $tabl_data[2]; - if (!empty($fld_id)) { - $sql .= "ALTER TABLE `sccpbuttonconfig` DROP FOREIGN KEY `".$fld_id."`\n"; - } - } - - $sql .= "ALTER TABLE `sccpbuttonconfig` CHANGE COLUMN `device` `device` varchar(15) NULL default NULL"; - $sql .= "ALTER TABLE `sccpbuttonconfig` ADD FOREIGN KEY (device) REFERENCES sccpdevice(name) ON DELETE CASCADE;"; - - $check = $db->query($sql); - if (DB::IsError($db_result)) { - die_freepbx("Can not get drop old FOREIGN KEY \n"); - - } - } - */ return true; } @@ -494,10 +497,10 @@ function InstallDB_sccpdevmodel() { return true; } -function InstallDB_sccpusers() { +function InstallDB_sccpuser() { global $db; - outn("
  • " . _("Creating sccpusers table...") . "
  • "); - $sql = "CREATE TABLE IF NOT EXISTS `sccpusers` ( + outn("
  • " . _("Creating sccpuser table...") . "
  • "); + $sql = "CREATE TABLE IF NOT EXISTS `sccpuser` ( `name` VARCHAR(20) NULL DEFAULT NULL, `pin` VARCHAR(7) NULL DEFAULT NULL, `password` VARCHAR(7) NULL DEFAULT NULL, @@ -671,49 +674,26 @@ function InstallDB_createButtonConfigTrigger() { global $db; outn("
  • " . _("(Re)Create buttonconfig trigger") . "
  • "); $sql = "DROP TRIGGER IF EXISTS sccp_trg_buttonconfig;"; -/* $sql = "DELIMITER $$ -CREATE TRIGGER sccp_trg_buttonconfig BEFORE INSERT ON sccpbuttonconfig -FOR EACH ROW -BEGIN - IF NEW.`reftype` = 'sccpdevice' THEN - IF (SELECT COUNT(*) FROM `sccpdevice` WHERE `sccpdevice`.`name` = NEW.`ref` ) = 0 THEN - UPDATE `Foreign key contraint violated: ref does not exist in sccpdevice` SET x=1; + + $sql .= "CREATE TRIGGER `sccp_trg_buttonconfig` BEFORE INSERT ON `sccpbuttonconfig` FOR EACH ROW BEGIN + IF NEW.`reftype` = 'sccpdevice' THEN + IF (SELECT COUNT(*) FROM `sccpdevice` WHERE `sccpdevice`.`name` = NEW.`ref` ) = 0 THEN + UPDATE `Foreign key contraint violated: ref does not exist in sccpdevice` SET x=1; + END IF; END IF; - END IF; - IF NEW.`reftype` = 'sccpline' THEN - IF (SELECT COUNT(*) FROM `sccpline` WHERE `sccpline`.`name` = NEW.`ref`) = 0 THEN - UPDATE `Foreign key contraint violated: ref does not exist in sccpline` SET x=1; + IF NEW.`reftype` = 'sccpline' THEN + IF (SELECT COUNT(*) FROM `sccpline` WHERE `sccpline`.`name` = NEW.`ref`) = 0 THEN + UPDATE `Foreign key contraint violated: ref does not exist in sccpline` SET x=1; + END IF; END IF; - END IF; - IF NEW.`buttontype` = 'line' THEN - SET @line_x = SUBSTRING_INDEX(NEW.`name`,'!',1); - SET @line_x = SUBSTRING_INDEX(@line_x,'@',1); - IF (SELECT COUNT(*) FROM `sccpline` WHERE `sccpline`.`name` = @line_x ) = 0 THEN - UPDATE `Foreign key contraint violated: line does not exist in sccpline` SET x=1; + IF NEW.`buttontype` = 'line' THEN + SET @line_x = SUBSTRING_INDEX(NEW.`name`,'!',1); + SET @line_x = SUBSTRING_INDEX(@line_x,'@',1); + IF (SELECT COUNT(*) FROM `sccpline` WHERE `sccpline`.`name` = @line_x ) = 0 THEN + UPDATE `Foreign key contraint violated: line does not exist in sccpline` SET x=1; + END IF; END IF; - END IF; -END $$ -DELIMITER ;";*/ - $sql .= " - CREATE TRIGGER `sccp_trg_buttonconfig` BEFORE INSERT ON `sccpbuttonconfig` FOR EACH ROW BEGIN - IF NEW.`reftype` = 'sccpdevice' THEN - IF (SELECT COUNT(*) FROM `sccpdevice` WHERE `sccpdevice`.`name` = NEW.`ref` ) = 0 THEN - UPDATE `Foreign key contraint violated: ref does not exist in sccpdevice` SET x=1; - END IF; - END IF; - IF NEW.`reftype` = 'sccpline' THEN - IF (SELECT COUNT(*) FROM `sccpline` WHERE `sccpline`.`name` = NEW.`ref`) = 0 THEN - UPDATE `Foreign key contraint violated: ref does not exist in sccpline` SET x=1; - END IF; - END IF; - IF NEW.`buttontype` = 'line' THEN - SET @line_x = SUBSTRING_INDEX(NEW.`name`,'!',1); - SET @line_x = SUBSTRING_INDEX(@line_x,'@',1); - IF (SELECT COUNT(*) FROM `sccpline` WHERE `sccpline`.`name` = @line_x ) = 0 THEN - UPDATE `Foreign key contraint violated: line does not exist in sccpline` SET x=1; - END IF; - END IF; - END"; + END;"; $check = $db->query($sql); if (DB::IsError($check)) { die_freepbx("Can not modify sccpdevice table\n"); @@ -775,22 +755,42 @@ function InstallDB_CreateSccpDeviceConfigView($sccp_compatible) { LEFT JOIN sccpbuttonconfig userbutton ON ( userbutton.ref = sccpdevice._loginname ) LEFT JOIN sccpline ON ( sccpline.name = sccpdevice._loginname) GROUP BY sccpdevice.name;"; -*/ - $sql = " - CREATE OR REPLACE - ALGORITHM = MERGE - VIEW sccpdeviceconfig AS - SELECT case sccpdevice._profileid - when 0 then - (select GROUP_CONCAT(CONCAT_WS( ',', defbutton.buttontype, defbutton.name, defbutton.options ) SEPARATOR ';') from `sccpbuttonconfig` as defbutton where defbutton.ref = sccpdevice.name ORDER BY defbutton.instance ) - when 1 then - (select GROUP_CONCAT(CONCAT_WS( ',', userbutton.buttontype, userbutton.name, userbutton.options ) SEPARATOR ';') from `sccpbuttonconfig` as userbutton where userbutton.ref = sccpdevice._loginname ORDER BY userbutton.instance ) - when 2 then - (select GROUP_CONCAT(CONCAT_WS( ',', homebutton.buttontype, homebutton.name, homebutton.options ) SEPARATOR ';') from `sccpbuttonconfig` as homebutton where homebutton.ref = sccpusers.homedevice ORDER BY homebutton.instance ) - end as button, sccpdevice.*, if(sccpdevice._profileid = 0, sccpdevice._description, sccpusers.description) as description - FROM sccpdevice - LEFT JOIN sccpusers sccpusers ON ( sccpusers.name = sccpdevice._loginname ) - GROUP BY sccpdevice.name;"; +*/ + $sql = "DROP VIEW IF EXISTS `sccpdeviceconfig`; + DROP VIEW IF EXISTS `sccpuserconfig`;"; + /// global $hw_mobil; + + global $mobile_hw; + if ($mobile_hw == '1') { + $sql .= "CREATE OR REPLACE ALGORITHM = MERGE VIEW sccpdeviceconfig AS + SELECT GROUP_CONCAT( CONCAT_WS( ',', sccpbuttonconfig.buttontype, sccpbuttonconfig.name, sccpbuttonconfig.options ) + ORDER BY instance ASC SEPARATOR ';' ) AS sccpbutton, sccpdevice.* + FROM sccpdevice + LEFT JOIN sccpbuttonconfig ON (sccpbuttonconfig.reftype = 'sccpdevice' AND sccpbuttonconfig.ref = sccpdevice.name ) + GROUP BY sccpdevice.name; "; + $sql .= "CREATE OR REPLACE ALGORITHM = MERGE VIEW sccpuserconfig AS + SELECT GROUP_CONCAT( CONCAT_WS( ',', sccpbuttonconfig.buttontype, sccpbuttonconfig.name, sccpbuttonconfig.options ) + ORDER BY instance ASC SEPARATOR ';' ) AS button, sccpuser.* + FROM sccpuser + LEFT JOIN sccpbuttonconfig ON ( sccpbuttonconfig.reftype = 'sccpuser' AND sccpbuttonconfig.ref = sccpuser.id) + GROUP BY sccpuser.name; "; + + } else { + $sql .= "CREATE OR REPLACE + ALGORITHM = MERGE + VIEW sccpdeviceconfig AS + SELECT case sccpdevice._profileid + when 0 then + (select GROUP_CONCAT(CONCAT_WS( ',', defbutton.buttontype, defbutton.name, defbutton.options ) SEPARATOR ';') from `sccpbuttonconfig` as defbutton where defbutton.ref = sccpdevice.name ORDER BY defbutton.instance ) + when 1 then + (select GROUP_CONCAT(CONCAT_WS( ',', userbutton.buttontype, userbutton.name, userbutton.options ) SEPARATOR ';') from `sccpbuttonconfig` as userbutton where userbutton.ref = sccpdevice._loginname ORDER BY userbutton.instance ) + when 2 then + (select GROUP_CONCAT(CONCAT_WS( ',', homebutton.buttontype, homebutton.name, homebutton.options ) SEPARATOR ';') from `sccpbuttonconfig` as homebutton where homebutton.ref = sccpuser.homedevice ORDER BY homebutton.instance ) + end as button, if(sccpdevice._profileid = 0, sccpdevice._description, sccpuser.description) as description, sccpdevice.* + FROM sccpdevice + LEFT JOIN sccpuser sccpuser ON ( sccpuser.name = sccpdevice._loginname ) + GROUP BY sccpdevice.name;"; + } } $results = $db->query($sql); if (DB::IsError($check)) { @@ -907,7 +907,7 @@ $sccp_db_ver = CheckSCCPManagerDBVersion(); // BackUp Old config CreateBackUpConfig(); -InstallDB_sccpusers(); +InstallDB_sccpuser(); InstallDB_Buttons(); InstallDB_sccpsettings(); diff --git a/views/form.addruser.php b/views/form.addruser.php index 43cd908..7e57120 100644 --- a/views/form.addruser.php +++ b/views/form.addruser.php @@ -11,7 +11,7 @@ $dev_new = null; if (!empty($_REQUEST['ru_id'])) { $dev_id = $_REQUEST['ru_id']; $def_val['id'] = array("keyword" => 'id', "data" => $dev_id, "seq" => "99"); - $db_res = $this->dbinterface->get_db_SccpTableData('get_sccpdusers', array("id" => $dev_id)); + $db_res = $this->dbinterface->get_db_SccpTableData('get_sccpuser', array("id" => $dev_id)); if (!empty($db_res) ) { foreach ($db_res as $key => $val) { if (!empty($val)) { diff --git a/views/hardware.phone.php b/views/hardware.phone.php index 0e0edcd..38fee97 100644 --- a/views/hardware.phone.php +++ b/views/hardware.phone.php @@ -32,7 +32,7 @@ - + @@ -73,6 +73,9 @@ } function LineFormatter(value, row, index) { + if (value === null) { + return '-- EMPTY --'; + } var data = value.split(";"); result = ''; for (var i = 0; i < data.length; i++) {