diff --git a/Superfecta.class.php b/Superfecta.class.php
new file mode 100644
index 00000000..42e2c367
--- /dev/null
+++ b/Superfecta.class.php
@@ -0,0 +1,230 @@
+freepbx = $freepbx;
+ $this->db = $freepbx->Database;
+ }
+ public function install() {
+
+ }
+ public function uninstall() {
+
+ }
+ public function backup(){
+
+ }
+ public function restore($backup){
+
+ }
+ public function doConfigPageInit($page){
+ return true;
+ }
+
+ public function myDialplanHooks() {
+ return true;
+ }
+
+ public function ajaxRequest($req, &$setting) {
+ switch($req) {
+ case "power":
+ case "delete":
+ case "options":
+ case "save_options":
+ case "update_sources":
+ return true;
+ break;
+ }
+ }
+
+ public function ajaxHandler() {
+ switch($_REQUEST['command']) {
+ case "update_sources":
+ $sources = implode(",", $_REQUEST['data']);
+ $sql = "REPLACE INTO superfectaconfig (value, source, field) VALUES(?, ?, 'sources')";
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array($sources, $_REQUEST['scheme']));
+ return array("success" => true);
+ break;
+ case "power":
+ $data = preg_replace('/^scheme_/i', '', $_REQUEST['scheme']);
+ $sql = "UPDATE superfectaconfig SET value = (value * -1) WHERE field = 'order' AND source = ?";
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array($data));
+ return array("status" => true);
+ break;
+ case "delete":
+ $data = preg_replace('/^scheme_/i', '', $_REQUEST['scheme']);
+ $sql = "DELETE FROM superfectaconfig WHERE source = ?";
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array($data));
+
+ //We now have to reorder the array. Well, we don't -have- to. But it's prettier
+ $sql = "SELECT * FROM superfectaconfig WHERE field LIKE 'order' ORDER BY value ASC";
+ $sth = $this->db->prepare($sql);
+ $sth->execute();
+ $scheme_list = $sth->fetchAll(\PDO::FETCH_ASSOC);
+ $order = 1;
+ foreach($scheme_list as $data) {
+ $sql = "REPLACE INTO superfectaconfig (value, source, field) VALUES(?, ?, 'order')";
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array($order, $data['source']));
+ $order++;
+ }
+ return array("status" => true);
+ break;
+ case "save_options":
+ include(__DIR__."/includes/superfecta_base.php");
+ $path = __DIR__;
+ include $path.'/sources/source-'.$_REQUEST['source'].'.module';
+ if(!class_exists($_REQUEST['source'])) {
+ return array("status" => false);
+ }
+ $module = new $_REQUEST['source'];
+ $params = $module->source_param;
+
+ $scheme = $_REQUEST['scheme'];
+ $source = $_REQUEST['source'];
+
+ foreach($params as $key => $data) {
+ if(isset($_POST[$key]) && $_POST[$key] != "off") {
+ $sql = "REPLACE INTO superfectaconfig (source,field,value) VALUES (?, ?, ?)";
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array($scheme . "_" . $source, $key, $_POST[$key]));
+ } else {
+ $sql = "DELETE FROM superfectaconfig WHERE source = ? AND field = ?";
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array($scheme . "_" . $source, $key));
+ }
+ }
+ return array("status" => true);
+ break;
+ case "options":
+ include(__DIR__."/includes/superfecta_base.php");
+ $scheme = $_REQUEST['scheme'];
+ $source = $_REQUEST['source'];
+
+ $sql = "SELECT field, value FROM superfectaconfig WHERE source = ?";
+ $sth = $this->db->prepare($sql);
+ $sth->execute(array($scheme . "_" . $source));
+ $n_settings = $sth->fetchAll(\PDO::FETCH_KEY_PAIR);
+
+ $path = __DIR__;
+
+ include $path.'/sources/source-'.$_REQUEST['source'].'.module';
+ if(!class_exists($_REQUEST['source'])) {
+ return array("status" => false);
+ }
+ $module = new $_REQUEST['source'];
+ $params = $module->source_param;
+
+ $form_html = '
';
- $form_html .= '';
- foreach($params as $key => $data) {
- $form_html .= '';
- $show = TRUE;
- $default = isset($data['default']) ? $data['default'] : '';
- switch($data['type']) {
- case "text":
- $value = isset($n_settings[$key]) ? $n_settings[$key] : $default;
- $form_html .= ''.str_replace("_", " ", $key).''.$data['description'].' ';
- break;
- case "password":
- $value = isset($n_settings[$key]) ? $n_settings[$key] : $default;
- $form_html .= ''.str_replace("_", " ", $key).''.$data['description'].' ';
- break;
- case "checkbox":
- $checked = isset($n_settings[$key]) && ($n_settings[$key] == 'on') ? 'checked' : $default;
- $form_html .= ''.str_replace("_", " ", $key).''.$data['description'].' ';
- break;
- case "textarea":
- $value = isset($n_settings[$key]) ? $n_settings[$key] : $default;
- $form_html .= ''.str_replace("_", " ", $key).''.$data['description'].' '.$value.' ';
- break;
- case "number":
- $value = isset($n_settings[$key]) ? $n_settings[$key] : $default;
- $form_html .= ''.str_replace("_", " ", $key).''.$data['description'].' ';
- break;
- case "select":
- $value = isset($n_settings[$key]) ? $n_settings[$key] : $default;
- $form_html .= ''.str_replace("_", " ", $key).''.$data['description'].' ';
- foreach($data['option'] as $options_k => $options_l) {
- $selected = ($value == $options_k) ? 'selected' : '';
- $form_html .= "".$options_l." ";
- }
- $form_html .= " ";
- break;
- default:
- $form_html .= 'WARN: Unrecognized option \''.$data['type'].'\' ';
- break;
- }
- $form_html .= ' ';
- }
- $form_html .= '
';
- $form_html .= ' ';
-
- $out = array("success" => true, "show" => $show, "data" => $form_html);
- break;
- case "save_options":
- file_put_contents($amp_conf['AMPWEBROOT'].'/admin/modules/superfecta/log', print_r($_REQUEST,TRUE));
-
- $path = dirname(dirname(__FILE__));
- require_once($path.'/sources/source-'.$_REQUEST['source'].'.module');
- $module = new $_REQUEST['source'];
- $params = $module->source_param;
-
- $scheme = str_replace("base_", "", $_REQUEST['scheme']);
- $source = $_REQUEST['source'];
-
- foreach($params as $key => $data) {
- if(isset($_REQUEST[$key])) {
- $sql = "REPLACE INTO superfectaconfig (source,field,value) VALUES ('".$scheme . "_" . $source."', '".$key."', '".$_REQUEST[$key]."')";
- sql($sql);
- } else {
- $sql = "DELETE FROM superfectaconfig WHERE source = '".$scheme . "_" . $source."' AND field = '".$key."'";
- sql($sql);
- }
- }
- break;
}
echo json_encode($out);
diff --git a/includes/callerid.php b/includes/callerid.php
old mode 100755
new mode 100644
diff --git a/includes/processors/superfecta_multi.php b/includes/processors/superfecta_multi.php
old mode 100755
new mode 100644
diff --git a/includes/processors/superfecta_single.php b/includes/processors/superfecta_single.php
old mode 100755
new mode 100644
diff --git a/includes/rain.tpl.class.php b/includes/rain.tpl.class.php
deleted file mode 100755
index f43c9750..00000000
--- a/includes/rain.tpl.class.php
+++ /dev/null
@@ -1,1013 +0,0 @@
-), stylesheet ( ), script (
-
-
-Caller ID Superfecta
-
-CallerID Superfecta for FreePBX is a utility program which adds incoming CallerID name lookups to your Asterisk system using multiple data sources.
\ No newline at end of file
diff --git a/views/header.php b/views/header.php
new file mode 100644
index 00000000..63348870
--- /dev/null
+++ b/views/header.php
@@ -0,0 +1,24 @@
+
+
+
+
diff --git a/views/sources.html b/views/sources.html
deleted file mode 100755
index 174243c9..00000000
--- a/views/sources.html
+++ /dev/null
@@ -1,387 +0,0 @@
-Add, Remove, Enable, Disable, Sort and Configure data sources as appropriate for your situation.
-Select which data source(s) to use for your lookups, and the order in which you want them used:
-
-
-
-
-
-
-
-
-
- Scheme Name: Duplicate Scheme names not allowed.
-
-
-
- General Options
-
-
-
-
- DID RulesDefine the expected DID Number if your trunk passes DID on incoming calls. Leave this blank to match calls with any or no DID info. This rule trys both absolute and pattern matching (eg "_2[345]X", to match a range of numbers). (The "_" underscore is optional.) :
-
- {$did}
-
-
-
-
- CID RulesIncoming calls with CID matching the patterns specified here will use this CID Scheme. If this is left blank, this scheme will be used for any CID. It can be used to add or remove prefixes.
- Many sources require a specific number of digits in the phone number. It is recommended that you use the patterns to remove excess country code data from incoming CID to increase the effectiveness of this module.
- Note that a pattern without a + or | (to add or remove a prefix) will not make any changes but will create a match. Only the first matched pattern will be executed and the remaining rules will not be acted on.Rules:
- X matches any digit from 0-9
- Z matches any digit from 1-9
- N matches any digit from 2-9
- [1237-9] matches any digit or letter in the brackets (in this example, 1,2,3,7,8,9)
- . wildcard, matches one or more characters (not allowed before a | or +)
- | removes a dialing prefix from the number (for example, 613|NXXXXXX would match when some one dialed "6135551234" but would only pass "5551234" to the Superfecta look up.)+ adds a dialing prefix to the number (for example, 1613+NXXXXXX would match when someone dialed "5551234" and would pass "16135551234" to the Superfecta look up.)
- You can also use both + and |, for example: 01+0|1ZXXXXXXXXX would match "016065551234" and dial it as "0116065551234" Note that the order does not matter, eg. 0|01+1ZXXXXXXXXX does the same thing. :
-
-
- {$cid_rules}
-
-
-
-
-
-
-
- Lookup TimeoutSpecify a timeout in seconds for each source. If the source fails to return a result within the alloted time, the script will move on.
-
-
-
-
- Superfecta Processor
- These are the types of Superfecta Processors:
- {loop="processors_list"}
- {$value.name}: {$value.description}
- {/loop}
-
-
-
-
- {loop="processors_list"}
- {$value.name}
- {/loop}
-
-
-
-
- Multifecta TimeoutSpecify a timeout in seconds defining how long multifecta will obey the source priority. After this timeout, the first source to respond with a CNAM will be taken, until "Lookup Timeout" is reached.
-
-
-
- CID Prefix URLIf you wish to prefix information on the caller id you can specify a url here where that prefix can be retrieved. The data will not be parsed in any way, and will be truncated to the first 10 characters. Example URL: http://www.example.com/GetCID.php?phone_number=[thenumber] [thenumber] will be replaced with the full 10 digit phone number when the URL is called.
-
-
-
-
-
-
-
- SPAM TextThis text will be prepended to Caller ID information to help you identify calls as SPAM calls.
-
-
-
- SPAM Text SubstitutedWhen enabled, the text entered in "SPAM Text" (above) will replace the CID completely rather than pre-pending the CID value.
-
-
-
-
-
- Enable SPAM InterceptionWhen enabled, Spam calls can be diverted or terminated.
-
-
-
-
-
-
- (License Terms)
- (* By clicking on either the "Agree and Save" button, or the "Debug" button on this form you are agreeing to the Caller ID Superfecta Licensing Terms.)
-
-
-
-
- Test a phone number against the selected sources.
- DID Number:The DID to test this scheme against.
- Phone Number:Phone number to test this scheme against.
-
- Test all CID schemesWhen enabled, the debug function will test the number entered against all of the configured CID schemes. When disabled, debug only checks up to the first scheme that provides positive results.
- Debug Level:NONE INFO WARN ALL
-
-
-
-
-
-
\ No newline at end of file
diff --git a/views/sources.php b/views/sources.php
new file mode 100755
index 00000000..f552eead
--- /dev/null
+++ b/views/sources.php
@@ -0,0 +1,128 @@
+Scheme Name:
+
+
+
+
+
+
+
+
diff --git a/views/style.css b/views/style.css
deleted file mode 100755
index dfa93340..00000000
--- a/views/style.css
+++ /dev/null
@@ -1,18 +0,0 @@
-/* CSS Document */
-
-body{ margin:0px; color:#333; font: 13px Helvetica; background:#eee;}
-a{ color: #333; }
-a:hover{ color: #999; }
-img{border:0px;}
-
-#logo{width:100%;height:80px;background:url('img/top.gif') repeat-x #666;}
-#content{ height: 100%;padding:20px; }
-#footer{background: url('img/bottom.gif') repeat-x;color:#ccff00; padding:15px; text-align:center;}
-#footer a{color:#ccff00;}
-
-.layout{background:#fff;border: 1px solid #ccc; padding:20px;margin-bottom:30px;}
-code{ display:block;font:12px monospace; background: #e9ffe9;padding: 15px; border: solid 1px #ccddcc; margin-bottom:10px;}
-tt{ display:block; font:12px monospace; background: #f6fdfd; padding: 15px; border: solid 1px #ccdddd; margin-bottom:0 0 10px 0; }
-
-.color1{background:#eeeeff;}
-.color2{background:#ddddee;}
\ No newline at end of file