Storing DID called in CDR userfield

When someone calls into the PBX, the Dst in the CDR record is ‘s’, which is not particularly helpful. Nor can Dst be changed within the extension. However, the CDR userfield can be set at any time, so the number called can be stored here. The best way, for now, would be by adding something in extensions_custom.conf, but I wasn’t able to figure out what to put in there that would then continue with correct processing of the incoming call. Failing that, I made the following modification to admin/modules/core/, to make it add a line to set the CDR userfield:

--- admin/modules/core/   2009-06-30 01:54:24.000000000 -0400
+++ admin/modules/core/    2009-06-30 02:03:11.000000000 -0400
@@ -906,11 +906,13 @@
                    $exten = $exten.(($cidnum == "")?"":"/".$cidnum); //if a CID num is defined, add it

                    if ($cidroute) {
+                       $ext->add($context, $exten, '', new ext_setvar('CDR(userfield)','${EXTEN}'));
                        $ext->add($context, $exten, '', new ext_setvar('__FROM_DID','${EXTEN}'));
                        $ext->add($context, $exten, '', new ext_goto('1','s'));
                        $exten = "s/$cidnum";
                        $ext->add($context, $exten, '', new ext_execif('$["${FROM_DID}" = ""]','Set','__FROM_DID=${EXTEN}'));
                    } else {
+                       $ext->add($context, $exten, '', new ext_setvar('CDR(userfield)','${EXTEN}'));
                        $ext->add($context, $exten, '', new ext_setvar('__FROM_DID','${EXTEN}'));
                    // always set callerID name

Note, when applying this patch, ignore whitespace or replace 4 spaces with tabs.

With this, I also want to be able to see the userfield in the CDR report. That requires another simple modification to admin/cdr/call-log.php:

--- admin/cdr/call-log.php.orig 2009-06-30 02:16:12.000000000 -0400
+++ admin/cdr/call-log.php      2009-06-30 02:28:04.000000000 -0400
@@ -90,6 +90,7 @@
 $FG_TABLE_COL[]=array ("Clid", "clid", "26%", "center", "", "80");
 $FG_TABLE_COL[]=array ("Dst", "dst", "14%", "center", "SORT", "30");
+$FG_TABLE_COL[]=array ("Userfield", "userfield", "8%", "center", "", "20");
 $FG_TABLE_COL[]=array ("Disposition", "disposition", "9%", "center", "", "30");
 if ((!isset($resulttype)) || ($resulttype=="min")) $minute_function= "display_minute";
@@ -101,7 +102,7 @@
 // This Variable store the argument for the SQL query
 //$FG_COL_QUERY='calldate, channel, src, clid, lastapp, lastdata, dst, dst, serverid, disposition, duration';
-$FG_COL_QUERY='calldate, channel, src, clid, dst, disposition, duration';
+$FG_COL_QUERY='calldate, channel, src, clid, dst, userfield, disposition, duration';
 /* --AMP End -- */

I was just solving this, in a new version of Distro and without rewriting the original php files you may try this: