$tmp3 = $ami->GetVar($tmp2[7], "CALLERID(name)");
         $leg2cid = $tmp3['Value'] . ' ';
         $connections[$leg1]["Connected"] = $leg2;
         $connections[$leg1]["Duration"] = @date("i:s", $tmp2[$iDurationIndex]);
         $connections[$leg1]["Application"] = $tmp2[5];
         $connections[$leg1]["CallerID"] = $leg2cid;
         $connections[$leg1]["Channel"] = $tmp2[0];
         $connections[$leg2]["Connected"] = $leg1;
         $connections[$leg2]["Duration"] = @date("i:s", $tmp2[$iDurationIndex]);
         $connections[$leg2]["Application"] = $tmp2[5];
         $connections[$leg2]["CallerID"] = $leg1cid;
         $connections[$leg2]["Channel"] = $tmp2[7];
     }
 } elseif ($tmp2[4] == "Up" and $tmp2[$iSecondLegIndex] == "(None)") {
     $i++;
     $leg1 = ExtrId($tmp2[0], $cDialplanSeparator);
     $leg2 = $tmp2[2];
     if ($leg1 != $leg2) {
         $tmp3 = $ami->ExtensionState($leg1, $dialplan_context, $i * 1023);
         $connections[$leg1]["Status"] = $tmp3['Status'];
         $tmp3 = $ami->ExtensionState($leg2, $dialplan_context, $i * 1023);
         $connections[$leg2]["Status"] = $tmp3['Status'];
         $tmp3 = $ami->GetVar($tmp2[0], "CALLERID(name)");
         $leg1cid = $tmp3['Value'] . ' ';
         $tmp3 = $ami->GetVar($tmp2[2], "CALLERID(name)");
         $leg2cid = $tmp3['Value'] . ' ';
         $connections[$leg1]["Connected"] = $leg2;
         $connections[$leg1]["Duration"] = @date("i:s", $tmp2[$iDurationIndex]);
         $connections[$leg1]["Application"] = $tmp2[5];
         $connections[$leg1]["CallerID"] = $tmp2[5];
         $connections[$leg1]["Channel"] = $tmp2[0];
         $tmp3 = $ami->GetVar($tmp2[7], "CALLERID(name)");
         $leg2cid = $tmp3['Value'] . ' ';
         $connections[$leg1]["Connected"] = $leg2;
         $connections[$leg1]["Duration"] = @date("i:s", $tmp2[10]);
         $connections[$leg1]["Application"] = $tmp2[5];
         $connections[$leg1]["CallerID"] = $leg2cid;
         $connections[$leg1]["Channel"] = $tmp2[0];
         $connections[$leg2]["Connected"] = $leg1;
         $connections[$leg2]["Duration"] = @date("i:s", $tmp2[10]);
         $connections[$leg2]["Application"] = $tmp2[5];
         $connections[$leg2]["CallerID"] = $leg1cid;
         $connections[$leg2]["Channel"] = $tmp2[7];
     }
 } elseif ($tmp2[4] == "Up" and $tmp2[11] == "(None)") {
     $i++;
     $leg1 = ExtrId($tmp2[0]);
     $leg2 = $tmp2[2];
     if ($leg1 != $leg2) {
         $tmp3 = $ami->ExtensionState($leg1, "from-internal", $i * 1023);
         $connections[$leg1]["Status"] = $tmp3['Status'];
         $tmp3 = $ami->ExtensionState($leg2, "from-internal", $i * 1023);
         $connections[$leg2]["Status"] = $tmp3['Status'];
         $tmp3 = $ami->GetVar($tmp2[0], "CALLERID(name)");
         $leg1cid = $tmp3['Value'] . ' ';
         $tmp3 = $ami->GetVar($tmp2[2], "CALLERID(name)");
         $leg2cid = $tmp3['Value'] . ' ';
         $connections[$leg1]["Connected"] = $leg2;
         $connections[$leg1]["Duration"] = @date("i:s", $tmp2[10]);
         $connections[$leg1]["Application"] = $tmp2[5];
         $connections[$leg1]["CallerID"] = $tmp2[5];
         $connections[$leg1]["Channel"] = $tmp2[0];