Skip to content

Commit

Permalink
Allow setting of both name and number for callerID
Browse files Browse the repository at this point in the history
Fix #5
  • Loading branch information
asiplas committed Feb 23, 2023
1 parent a904451 commit db1d565
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Cidrotation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ public function doConfigPageInit($page) {
$exts_db = $this->db->prepare('INSERT INTO cidrotation_ext(ext) VALUES(:ext)');
$added = array();
foreach($exts as $ext) {
$ext = preg_replace("/[^0-9]/", "", $ext);
$ext = preg_replace("/-/", "", $ext); // '-' is delimiter for dialplan CUT function
if (strlen($ext) < 1 || in_array($ext, $added)) {
continue;
}
$exts_db->execute(array('ext' => $ext));
$added[] = $ext;
}

$cids = explode("\r\n", trim($this->getReq('cid-list')));
$cids = explode("\r\n", trim($_POST['cid-list']));
$cids_db = $this->db->prepare('DELETE FROM cidrotation_cid');
$cids_db->execute();
$cids_db = $this->db->prepare('INSERT INTO cidrotation_cid(cid) VALUES(:cid)');
$added = array();
$id = 0;
foreach($cids as $cid) {
$cid = preg_replace("/[^0-9]/", "", $cid);
$cid = preg_replace("/-/", "", $cid); // '-' is delimiter for dialplan CUT function
if (strlen($cid) < 1 || in_array($cid, $added)) {
continue;
}
Expand Down
7 changes: 4 additions & 3 deletions functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ function cidrotation_hookGet_config($engine) {
$ext->add($context, 's', '', new ext_setvar('cidrotation_cid_list', $cids));
$ext->add($context, 's', '', new ext_setvar('cidrotation_cid', '${CUT(cidrotation_cid_list,-,$[${cidrotation_idx} % '.$cids_len.' + 1])}')); // CUT param is one-indexed

$ext->add($context, 's', '', new ext_setvar('CALLERID(num)', '${cidrotation_cid}'));
$ext->add($context, 's', '', new ext_setvar('CDR(outbound_cnum)', '${cidrotation_cid}'));
$ext->add($context, 's', '', new ext_noop('Set CallerID number ${cidrotation_cid}'));
$ext->add($context, 's', '', new ext_setvar('CALLERID(all)', '${cidrotation_cid}'));
$ext->add($context, 's', '', new ext_setvar('CDR(outbound_cnam)', '${CALLERID(name)}'));
$ext->add($context, 's', '', new ext_setvar('CDR(outbound_cnum)', '${CALLERID(num)}'));
$ext->add($context, 's', '', new ext_noop('Set CallerID to ${CALLERID(all)}'));
$ext->add($context, 's', '', new ext_return());

$ext->splice('macro-dialout-trunk', 's', 'skipoutcid', new ext_gosub('1', 's', $context));
Expand Down
6 changes: 4 additions & 2 deletions module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<rawname>cidrotation</rawname>
<name>CallerID Rotation</name>
<version>16.0.1</version>
<version>16.0.3</version>
<publisher>Andrew Siplas</publisher>
<license>GPLv3</license>
<licenselink>https://www.gnu.org/licenses/gpl-3.0.txt</licenselink>
Expand All @@ -13,6 +13,8 @@
<cidrotation>CallerID Rotation</cidrotation>
</menuitems>
<changelog>*16.0.1* Initial release</changelog>
<changelog>*16.0.2* Fix dialplan splice where allowlist module was skipping cid setting hook</changelog>
<changelog>*16.0.3* Allow for callerid name to be set for pool entries</changelog>
<supported>
<version>16.0</version>
</supported>
Expand All @@ -21,7 +23,7 @@
<field name="ext" type="string" length="15"/>
</table>
<table name="cidrotation_cid">
<field name="cid" type="string" length="15"/>
<field name="cid" type="string" length="64"/>
</table>
</database>
</module>
2 changes: 1 addition & 1 deletion views/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</div>
<div class="row">
<div class="col-md-12">
<span id="cid-list-help" class="help-block fpbx-help-block">Enter CallerID numbers to be rotated for outbound calling, one per line.</span>
<span id="cid-list-help" class="help-block fpbx-help-block">Enter CallerID numbers to be rotated for outbound calling, one per line. May enter using format <strong>"John Smith" &lt;5085550199&gt;</strong> to provide name, otherwise simply provide number.</span>
</div>
</div>
</div>
Expand Down

0 comments on commit db1d565

Please sign in to comment.