Example #1
0
}
?>

<h2>Date/Time</h2>

<div id="form-wrapper">

	<div id="form-inside">

		<form action="dateTime.php" method="post" name="DateTimeSettings" id="DateTimeSettings">
			<input type="hidden" name="userAction" value="DateTime">

			<span class="label">Current Time</span>
			<span class="description">Current time on the NetBoot/SUS/LDAP Proxy server</span>
			<span><?php 
print getLocalTime();
?>
</span>
			<br>
			<br>

			<span class="label">Current Time Zone</span>
			<span class="description">Current time zone on the NetBoot/SUS/LDAP Proxy server</span>
			<span><?php 
echo getSystemTimeZoneMenu();
?>
</span>
			<br>

			<span class="label">Network Time Server</span>
			<span class="description">Server to use to synchronize the date/time (e.g. "pool.ntp.org")</span>
Example #2
0
    function showAcceptTab() {
        $chapter=sprintf(_("Do Not Disturb"));
        $this->showChapter($chapter);

        $this->getAcceptRules();

        $this->getVoicemail();
        $this->getDivertTargets();
        $this->getDiversions();

        print "
        <form method=post class=form-horizontal name=sipsettings onSubmit=\"return checkForm(this)\">
        ";

        print "
        <div class=row-fluid>
            <div class=span12>
                <p>";
        print _("You can reject calls depending on the time of day and Caller-ID. ");
        print _("You can create custom groups in the Contacts page like Family or Coworkers. ");
        print  "</p>
            <p>";
        print _("Rejected calls are diverted based on the Unavailable condition in the Call Forwarding page. ");
        print "<p>";
        print "<p class=desc>";
        printf (_("Your current time is: %s"),$this->timezone);
        $timestamp=time();
        $LocalTime=getLocalTime($this->timezone,$timestamp);
        print " $LocalTime";

        print "
        </div>
        </div>
        ";

       // $chapter=sprintf(_("Rules"));
       // $this->showChapter($chapter);

/*  print "
        <div class=row-fluid>
        <div class=span12>";
        print _("This will override the permanent rules for the chosen duration. ");
        print "
        </div>
        </div>
        ";
 */
        if ($this->acceptRules['temporary']['duration']) {
            $class_e='error';
        } else {
            $class_e='';
        }

       // print "<div class='control-group $class_e'>
         //   <label for=duration class=control-label>";

      //  print _("Duration");
       // print "</label>
            //";

         // print "<span class=help-inline>";
       // print _("minute(s)");
       // print "</span>";


        //print "</span></div>
        //</div>

        //";

        $chapter=sprintf(_("Rules"));
        $this->showChapter($chapter);

        print "
        <div class=row-fluid>
        ";

        print "<table class='table table-condensed table-striped middle' border=0 width=100%>";
        print "<thead><tr>
            <tr>
            <th colspan=6>
            ";
        print _("Temporary");
        print "</th></tr></thead>";
        print "<tr><td style='vertical-align: middle'><span>";
        print _("Duration");
        print "</span></td><td colspan='2' style='vertical-align: middle'>";
        if ($this->acceptRules['temporary']['duration']) {
                printf ('
                <script LANGUAGE="JavaScript">
                    var minutes = %s;
                    ID=window.setTimeout("update();", 1000*60);
                    function update() {
                            minutes--;
                            document.sipsettings.minutes.value = minutes;
                            ID=window.setTimeout("update();",1000*60);
                    }

                </script>
                ',$this->acceptRules['temporary']['duration']);

                    print " <input type=text name=minutes size=3 maxsize=3 value=\"";
                    print $this->acceptRules['temporary']['duration'];
                    print "\" disabled=true>";
                    print " <input type=hidden name=accept_temporary_remain value=\"";
                    print $this->acceptRules['temporary']['duration'];
                    print "\"> ";
            } else {
                print "<select id=testselect rel='popover' class=input-medium name=duration data-original-title='";
                print _("Temporary Rules");
                print "' data-content='";
                    print _("This will override the permanent rules for the chosen duration.");
                    print "'> ";
                    print "<option>";
                    print "<option value=1  >  1";
                    print "<option value=5  >  5";
                    print "<option value=10 > 10";
                    print "<option value=20 > 20";
                    print "<option value=30 > 30";
                    print "<option value=45 > 45";
                    print "<option value=60 > 60";
                    print "<option value=90 > 90";
                    print "<option value=120>120";
                    print "<option value=150>150";
                    print "<option value=180>180";
                    print "<option value=240>240";
                    print "<option value=480>480";
                    print "</select><span> ";
                    print _("Minute(s)");
                    print "</span>";
            }
        print "</td>";

        $_name="radio_temporary";

        $_checked_everybody="";
        $_checked_nobody="";
        $_checked_groups="";

        if (is_array($this->acceptRules['temporary']['groups']) &&in_array("everybody",$this->acceptRules['temporary']['groups'])) {
            $_checked_everybody="checked";
        } else if (is_array($this->acceptRules['temporary']['groups']) && in_array("nobody",$this->acceptRules['temporary']['groups'])) {
            $_checked_nobody="checked";
        } else if (!in_array('everybody',$this->acceptRules['temporary']['groups']) &&
                   !in_array('nobody',$this->acceptRules['temporary']['groups']) &&
                   count($this->acceptRules['temporary']['groups'])) {
            $_checked_groups="checked";
        }

        if ($_checked_nobody) {
            $class_nobody="checked_groups";
        } else {
            $class_nobody="note";
        }

        printf ("<td style='vertical-align:middle' class='note'><input type=radio name=%s value=0 %s> %s</td> ",$_name,$_checked_everybody,_("Everybody"));
        printf ("<td style='vertical-align:middle' class='$class_nobody'><input type=radio name=%s value=1 %s> %s </td>",$_name,$_checked_nobody,_("Nobody"));

        $c=count($this->acceptRules['groups']);

        if ($_checked_groups) {
            $class_groups="checked_groups";
        } else {
            $class_groups="note";
        }

        print "<td style='vertical-align:middle' class='$class_groups'>";

        if (count($this->acceptRules['groups'])>2) {

            printf ("<input type=radio name=%s value=2 %s class=hidden>",$_name,$_checked_groups);
            $i=0;

            foreach(array_keys($this->acceptRules['groups']) as $_group) {
                $i++;

                if (preg_match("/(everybody|nobody)/",$this->acceptRules['groups'][$_group])) continue;

                if (in_array($this->acceptRules['groups'][$_group],$this->acceptRules['temporary']['groups'])) {
                    $_checked="checked";
                } else {
                    $_checked="";
                }

                $_name="groups_temporary[]";
                printf ("<span><input style='vertical-align:top' type=checkbox name=%s value=%s onClick=\"document.sipsettings.radio_temporary[2].checked=true\" %s> %s</span>\n",
                $_name,
                $this->acceptRules['groups'][$_group],
                $_checked,
                $this->PhonebookGroups[$this->acceptRules['groups'][$_group]]
                );
            }
        }

        print "</td></tr>";
        print "<thead>
            <th colspan=6>
            ";
        print _("Permanent");
        print "</th></tr><tr>
            <th>";
        print _("Days");
        print "</th>
        <th colspan=2>";
        print _("Time Interval");
        print "</th>
        <th colspan=3>";
        print _("Groups");
        print "</th>
        </tr></thead>
        ";

        foreach (array_keys($this->acceptDailyProfiles) as $profile) {

            if ($this->acceptRules['persistent'][$profile]['start'] || $this->acceptRules['persistent'][$profile]['stop']) {
                $class="checked_groups";
                $class2="label label-info";
            } else {
                $class="mhj";
                $class2='';
            }
            if ($profile==1) {
                print "<tr><td colspan=6 style='height:3px; padding:0px' bgcolor=lightgrey></td></tr>";
            }

            print "
            <tr>
            <td style='vertical-align: middle;'><span class='$class2'>";

            printf ("%s",$this->acceptDailyProfiles[$profile]);
            print "</span></td>";
            unset($selected_StartTime);
            $selected_StartTime[$this->acceptRules['persistent'][$profile]['start']]="selected";
            printf ("<td><select class=span10 name=start_%s>",$profile);

            $t=0;
            $j=0;

            print "<option>";

            while ($t<24) {
                if (!$j) {
                    if (strlen($t)==1) {
                        $t1="0".$t.":00";
                    } else {
                        $t1=$t.":00";
                    }
                    $j++;
                } else {
                    if (strlen($t)==1) {
                        $t1="0".$t.":30";
                    } else {
                        $t1=$t.":30";
                    }
                    $j=0;
                    $t++;
                }
                print "<option $selected_StartTime[$t1]>$t1";
            }

            printf ("<option %s>23:59",$selected_StartTime['23:59']);
            print "</select>";

            unset($selected_StopTime);

            $selected_StopTime[$this->acceptRules['persistent'][$profile]['stop']]="selected";
            printf ("<td><select class=span10 name=stop_%s>",$profile);
            $t=0;
            $j=0;
            print "<option>";
            while ($t<24) {
                if (!$j) {
                    if (strlen($t)==1) {
                        $t1="0".$t.":00";
                    } else {
                        $t1=$t.":00";
                    }
                    $j++;
                } else {
                    if (strlen($t)==1) {
                        $t1="0".$t.":30";
                    } else {
                        $t1=$t.":30";
                    }
                    $j=0;
                    $t++;
                }
                print "<option $selected_StopTime[$t1]> $t1";
            }
            printf ("<option %s>23:59",$selected_StopTime['23:59']);
            print "</select>";

            $_name="radio_persistent_".$profile;

            $_checked_everybody="";
            $_checked_nobody="";
            $_checked_groups="";

            if (is_array($this->acceptRules['persistent'][$profile]['groups']) && in_array("everybody",$this->acceptRules['persistent'][$profile]['groups'])) {
                $_checked_everybody="checked";
            } else if (is_array($this->acceptRules['persistent'][$profile]['groups']) && in_array("nobody",$this->acceptRules['persistent'][$profile]['groups'])) {
                $_checked_nobody="checked";
            } else if (!in_array('everybody',$this->acceptRules['persistent'][$profile]['groups']) &&
                       !in_array('nobody',$this->acceptRules['persistent'][$profile]['groups']) &&
                       count($this->acceptRules['persistent'][$profile]['groups'])) {
                $_checked_groups="checked";
            } else {
                $_checked_everybody="checked";
            }

            if ($_checked_nobody) {
                $class_nobody="checked_groups";
            } else {
                $class_nobody="note";
            }

            printf ("<td style='vertical-align: middle;' class='note'><input style='vertical-align: top;' type=radio name=%s value=0 %s> %s</td>",$_name,$_checked_everybody,_("Everybody"));
            printf ("<td style='vertical-align: middle;' class='$class_nobody'><input style='vertical-align: top;' type=radio name=%s value=1 %s> %s</td>",$_name,$_checked_nobody,_("Nobody"));

            $c=count($this->acceptRules['groups']);

            if ($_checked_groups) {
                $class_groups="checked_groups";
            } else {
                $class_groups="note";
            }

            print "<td style='vertical-align: middle' class='controls $class_groups'>";
            if (count($this->acceptRules['groups'])>2) {
                printf ("<input style='vertical-align: top;' type=radio name=%s value=2 %s class=hidden>",$_name,$_checked_groups);
                $i=0;

                foreach(array_keys($this->acceptRules['groups']) as $_group) {
                    $i++;
                    if (preg_match("/(everybody|nobody)/",$this->acceptRules['groups'][$_group])) continue;

                    if (in_array($this->acceptRules['groups'][$_group],$this->acceptRules['persistent'][$profile]['groups'])) {
                        $_checked="checked";
                    } else {
                        $_checked="";
                    }

                    $_name="groups_".$profile."[]";
                    printf ("<input style='vertical-align: top;' type=checkbox name=%s value=%s onClick=\"document.sipsettings.radio_persistent_%s[2].checked=true\" %s> %s ",
                    $_name,
                    $this->acceptRules['groups'][$_group],
                    $profile,
                    $_checked,
                    $this->PhonebookGroups[$this->acceptRules['groups'][$_group]]
                    );
                }
            }

            print "</td>
            </tr>
            ";
        }

        print "</table></div>";

        print "
        <div class='form-actions'>
            <input type=hidden name=action value=\"set accept rules\">
        ";

        print "
        <input class='btn' type=submit value=\"";
        print _("Save");
        print "\"
               onClick=saveHandler(this)>
        ";

        print "
          </div>
        ";

        print $this->hiddenElements;
        print "
        </form>
        ";

        $chapter=sprintf(_("Rejected Callers"));
        $this->showChapter($chapter);

        print "
        <form class=form-horizontal method=post name=reject_form onSubmit=\"return checkForm(this)\">
        ";
        print "
        <div class=row-fluid>
        <div class=span12>";
        print _("Use %Number@% to match PSTN numbers and user@domain to match SIP Addresses");
        print "
        </div>
        </div>
        ";

        if ($this->getRejectMembers()) {
            foreach ($this->rejectMembers as $_member) {
                $j++;

                $rr=floor($j/2);
                $mod=$j-$rr*2;

                if ($mod ==0) {
                    $_class='odd';
                } else {
                    $_class='even';
                }

                print "
                <div class='control-group $_class'>";

                print "<label class=control-label>";
                print _("SIP Address");
                print "</label>";
                print "<div class=controls>
                <input type=text size=35 name=rejectMembers[] value=\"$_member\">
                </div>";
                print "</div>";
            }
        }

        print "<div class=control-group>";
        print "<label class=control-label>";
        print _("SIP Address");
        print "</label>";
        print "<div class=controls>
            <input type=text size=35 name=rejectMembers[]>";
        print "</div></div>";
        print "<div class='form-actions'>";
        print "<input class=btn type=submit value=\"";
        print _("Save");
        print "\"
               onClick=saveHandler(this)>
            ";
        print "</div></div>";

        print "
            <input type=hidden name=action value=\"set reject\">
        ";


        print $this->hiddenElements;

        print "
        </form>
        ";


    }
Example #3
0
    function MaxSessionTime($dictionary) {
        // Used for prepaid application to return maximum session time based on a prepaid balance

        $this->rateValuesCache=array();

        $this->MaxSessionTimeSpans=0;

        $durationRate           = 0;

        /////////////////////////////////////////////////////
        // required fields passed from the CDR structure
        //
        $this->timestamp         = time();
        $this->callId            = $dictionary['callId'];
        $this->DestinationId     = $dictionary['DestinationId'];
        $this->BillingPartyId    = $dictionary['BillingPartyId'];
        $this->domain            = $dictionary['domain'];
        $this->duration          = $dictionary['duration'];
        $this->aNumber           = $dictionary['aNumber'];
        $this->cNumber           = $dictionary['cNumber'];
        $this->gateway           = $dictionary['gateway'];
        $this->RatingTables      = $dictionary['RatingTables'];
        $this->application       = $dictionary['application'];
        $this->ResellerId        = $dictionary['ResellerId'];
        $Balance                 = $dictionary['Balance'];

        if (!$this->application) $this->application='audio';

        if (!$this->DestinationId) {
            $log=sprintf("Error: no DestinationId supplied in MaxSessionTime()");
            syslog(LOG_NOTICE, $log);
            return false;
        }

        if (!$this->lookupDestinationDetails()) {
            return false;
        }

        if (!$this->lookupProfiles()) {
            return false;
        }

        $this->startTimeBilling   = getLocalTime($this->billingTimezone,$this->timestamp);
        list($dateText,$timeText) = explode(" ",trim($this->startTimeBilling));

        $Bdate = explode("-",$dateText);
        $Btime = explode(":",$timeText);

        $this->timestampBilling   = mktime($Btime[0], $Btime[1], $Btime[2], $Bdate[1], $Bdate[2], $Bdate[0]);
        $this->startTimeBilling   = Date("Y-m-d H:i:s",$this->timestampBilling);

        $i=0;
        $durationRatedTotal=0;

        while ($Balance > 0 ) {
            $span++;
            $this->MaxSessionTimeSpans++;

            if ($i == "0") {
                $dayofweek       = date("w",$this->timestampBilling);
                $hourofday       = date("G",$this->timestampBilling);
                $dayofyear       = date("Y-m-d",$this->timestampBilling);
            } else {
                $dayofweek       = date("w",$this->timestampBilling+$durationRatedTotal);
                $hourofday       = $foundRate['nextHourOfDay'];
                $dayofyear       = date("Y-m-d",$this->timestampBilling+$durationRatedTotal);
            }

            $foundRate            = $this->lookupRateAudio($dayofyear,$dayofweek,$hourofday,$durationRatedTotal);

            if ($this->rateNotFound) {
                // break here to avoid loops
                break;
            }

            $thisRate=$foundRate;

            if ($j > 0) {
                $payConnect=0;
                $durationForRating = $thisRate['duration'];
            } else {
                $payConnect=1;
                if ($this->min_duration && $this->duration < $this->min_duration) {
                    $durationForRating=$this->min_duration;
                } else {
                    $durationForRating=$thisRate['duration'];
                }
            }

            $j++;

            $connectCost     = $thisRate['values']['connectCost'];
            $durationRate    = $thisRate['values']['durationRate'];

            if ($span=="1" && !$dictionary['skipConnectCost']) {
                $this->connectCost=number_format($connectCost/$this->priceDenominator,$this->priceDecimalDigits);

                $connectCostSpan=$connectCost;
                $setupBalanceRequired=$connectCost/$this->priceDenominator;

                if ($connectCost && $Balance <= $setupBalanceRequired) {
                    syslog(LOG_NOTICE,"Balance too small: $Balance <= $setupBalanceRequired");
                    return false;
                }

                $Balance = $Balance-$setupBalanceRequired;

            } else {
                $connectCostSpan=0;
                $setupBalanceRequired=0;
            }

            $connectCostPrint     = number_format($connectCostSpan/$this->priceDenominator,$this->priceDecimalDigits);
            $durationRatePrint    = number_format($durationRate/$this->priceDenominator,$this->priceDecimalDigits);

            $spanPrice            = $this->price+$setupBalanceRequired*$payConnect+
                                    $durationRate*$durationForRating/$this->durationPeriodRated/$this->priceDenominator;

            if ($Balance > $spanPrice) {
                $Balance = $Balance-$spanPrice;
                $durationRatedTotal   = $durationRatedTotal+ $foundRate['duration'];

            } else {

                $durationAllowedinThisSpan = $Balance /
                                             $durationRate * $this->durationPeriodRated * $this->priceDenominator;
                $rateOfThisSpan=$durationRate/$this->priceDenominator;

                $durationRatedTotal=$durationRatedTotal + $durationAllowedinThisSpan;

                $Balance=$Balance-$spanPrice;
                return $durationRatedTotal;
            }

            if ($durationRatedTotal >= $this->duration) {
                return sprintf("%f",$durationRatedTotal);
            }

            $i++;

            if ($i>10) {
                return sprintf("%f",$durationRatedTotal);
                break;
            }
        }

        return false;
    }
        $tz = $_POST['timezone'];
        setTimeZone($tz);
    }
    if (isset($_POST['timeserver'])) {
        $ts = $_POST['timeserver'];
        setTimeServer($ts);
    }
}
?>

<form action="admin.php" method="post" name="DateTimeSettings" id="DateTimeSettings">
<input type="hidden" name="userAction" value="DateTime">
<table style="border: 0px;" class="formLabel">
        <tr>
		<td style="text-align: right;">Current Time: </td>
		<td><?print getLocalTime();?></td>
	</tr>
	<tr>
                <td style="text-align: right;"><label for="timezone">Current Time Zone: </label></td>
		<td><?getSystemTimeZoneMenu();?></td>
	</tr>
	<tr>
		<td style="text-align: right;"><label for="timeserver">Network Time Server:</label></td>
		<td><input type="text" name="timeserver" id="timeserver" value="<?php 
echo getCurrentTimeServer();
?>
" /></td>
	</tr>
</table>
<br>
<input type="submit" value="Save Date/Time Configuration" name="SaveDateTime"/>
Example #5
0
    function import($file,$timezone) {
        $b=time();
        $this->radiusAttributes=array(
            "Acct-Session-Id"            => "AcctSessionId",
            "Calling-Station-Id"         => "CallingStationId",
            "Called-Station-Id"          => "CalledStationId",
            "Acct-Status-Type"           => "",
            "Realm"                      => "",
            "Acct-Authentic"             => "AcctAuthentic",
            "Acct-Terminate-Cause"       => "AcctTerminateCause",
            "User-Name"                  => "UserName",
            "Service-Type"               => "ServiceType",
            "NAS-IP-Address"             => "NASIPAddress",
            "Acct-Delay-Time"            => "AcctDelayTime",
            "Client-IP-Address"          => "ClientIPAddress",
            "Acct-Unique-Session-Id"     => "AcctUniqueId",
            "Timestamp"                  => "Timestamp",
            "NAS-Port-Id"                => "NASPortId",
            "Cisco-NAS-Port"             => "CiscoNASPort",
            "NAS-Port-Type"              => "NASPortType",
            "NAS-Port"                   => "NASPort",
            "Framed-Protocol"            => "FramedProtocol",
            "Framed-IP-Address"          => "FramedIPAddress",
            "Connect-Info"               => "ConnectInfo_stop",
            "h323-setup-time"            => "H323SetupTime",
            "h323-connect-time"          => "H323ConnectTime",
            "h323-disconnect-time"       => "H323DisconnectTime",
            "h323-disconnect-cause"      => "H323DisconnectCause",
            "h323-remote-address"        => "H323RemoteAddress",
            "h323-voice-quality"         => "H323VoiceQuality",
            "h323-gw-id"                 => "H323GWID",
            "h323-conf-id"	             => "H323ConfID",
            "h323-call-origin"           => "H323CallOrigin",
            "h323-call-type"             => "H323CallType",
            "Acct-Input-Octets"          => "AcctInputOctets",
            "Acct-Output-Octets"         => "AcctOutputOctets",
            "Acct-Input-Packets"         => "AcctInputPackets",
            "Acct-Output-Packets"        => "AcctOutputPackets",
            "Acct-Session-Time"          => "AcctSessionTime"
            );

        if (!$fp=fopen("$file","r")) {
            print "Error: cannot open file $file\n";
            return 0;
        } else {
            $filesize=filesize($file);
            print "File $file (size=$filesize) succesfully opened.\n";
        }

        $success=0;
        $failed =0;

        if ($filesize > 100000) {
            print "Import progress: ";
            flush();
        }

        while (!feof($fp)) {
            $record       = $this->RadiusRecordRead($fp);
            $radiusParsed = $this->RadiusRecordParse($record);
            $currentFilePointer=ftell($fp);
            if ($filesize > 100000) {
                if ($currentFilePointer> $progress*$filesize/100) {
                    $progress++;
                    if ($progress%10==0) {
                        print "$progress% ";
                        if ($progress==100) {
                            print "\n";
                        }
                    }
                    flush();
                }
            }
            dprint_r($radiusParsed);
            $packetType   = $radiusParsed["Acct-Status-Type"];
            $radiusTable  = $this->table;
            unset($query);

            if ($packetType=="Start") {
                $results[$file][$packetType]++;
                $accounting_start_query= "INSERT into $this->table (RadAcctId, AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, NASPortId, NASPortType, AcctStartTime, AcctStopTime, AcctSessionTime, AcctAuthentic, ConnectInfo_start, ConnectInfo_stop, AcctInputOctets, AcctOutputOctets, CalledStationId, CallingStationId, AcctTerminateCause, ServiceType, FramedProtocol, FramedIPAddress, AcctStartDelay, AcctStopDelay) values('', '%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port-Id}', '%{NAS-Port-Type}', '%S', '0', '0', '%{Acct-Authentic}', '%{Connect-Info}', '', '0', '0', '%{Called-Station-Id}', '%{Calling-Station-Id}', '', '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', '%{Acct-Delay-Time}', '0')";
                $query=$accounting_start_query;
				$query=preg_replace("/%{/","",$query);
                $query=preg_replace("/}'/","'",$query);
                $query=preg_replace("/}\)/",")",$query);
                $Timestamp=getLocalTime($timezone,$radiusParsed[Timestamp]);

                $query=preg_replace("/'%S'/","'$Timestamp'",$query);
                $query=preg_replace("/SQL-User-Name/","User-Name",$query);
                foreach (array_keys($this->radiusAttributes) as $attribute) {
                	$value=$radiusParsed[$attribute];
                    $query=preg_replace("/'$attribute'/","'$value'",$query);
                }
            } else if ($packetType=="Stop") {
				$accounting_stop_query = "INSERT into $this->table (RadAcctId, AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, CiscoNASPort, NASPortId, NASPortType, AcctStartTime, AcctStopTime, AcctSessionTime, AcctAuthentic, ConnectInfo_start, ConnectInfo_stop, AcctInputOctets, AcctOutputOctets, CalledStationId, CallingStationId, AcctTerminateCause, ServiceType, FramedProtocol, FramedIPAddress, AcctStartDelay, AcctStopDelay, H323GWId, H323CallOrigin, H323CallType, H323Setuptime,H323ConnectTime, H323DisconnectTime,H323DisconnectCause,H323RemoteAddress,H323VoiceQuality, H323ConfId, Timestamp ) values  ('', '%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', '%{Cisco-NAS-Port}','%{NAS-Port-Id}', '%{NAS-Port-Type}', from_unixtime(unix_timestamp('%S')-%{Acct-Session-Time}), '%S', '%{Acct-Session-Time}', '%{Acct-Authentic}', '', '%{Connect-Info}', '%{Acct-Input-Octets}', '%{Acct-Output-Octets}', '%{Called-Station-Id}', '%{Calling-Station-Id}', '%{Acct-Terminate-Cause}', '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', '0', '%{Acct-Delay-Time}', SUBSTRING('%{h323-remote-address}',21), SUBSTRING('%{h323-call-origin}',18), SUBSTRING('%{h323-call-type}',16), SUBSTRING('%{h323-setup-time}',18), SUBSTRING('%{h323-connect-time}',20), SUBSTRING('%{h323-disconnect-time}',23), SUBSTRING('%{h323-disconnect-cause}',23), SUBSTRING('%{h323-remote-address}',21),SUBSTRING('%{h323-voice-quality}',20), SUBSTRING('%{h323-conf-id}',14) , '%{Timestamp}')";
                $query=$accounting_stop_query;
				$query=preg_replace("/%{/","",$query);
                $query=preg_replace("/}'/","'",$query);
                $query=preg_replace("/}\)/",")",$query);
                $Timestamp=getLocalTime($timezone,$radiusParsed[Timestamp]);

                $query=preg_replace("/'%S'/","'$Timestamp'",$query);
                $query=preg_replace("/SQL-User-Name/","User-Name",$query);
                foreach (array_keys($this->radiusAttributes) as $attribute) {
                	$value=$radiusParsed[$attribute];
                    $query=preg_replace("/'$attribute'/","'$value'",$query);
                    $value=$radiusParsed['Acct-Session-Time'];
                    $query=preg_replace("/Acct-Session-Time/","$value",$query);
                }
            }

            if ($query) {
            	$results[$file][packetTypes][$packetType]++;
            	$AcctSessionId=$radiusParsed["Acct-Session-Id"];
            	dprint ("$packetType Radius packet $AcctSessionId\n");
                $this->CDRdb->Halt_On_Error="no";
                dprint("$query\n");

                if ($this->CDRdb->query($query)) {
                    if ($packetType=="Start" || $packetType=="Failed" ) {
                        if ($this->CDRdb->affected_rows()) {
                            $results[$file][database][insert]++;
                        } else {
                            $results[$file][database][insertExists]++;
                        }
                    } else if ($packetType=="Stop") {
                        if ($this->CDRdb->affected_rows()) {
                            $results[$file][database][update]++;
                        } else {
                            $results[$file][database][updateExists]++;
                        }

                    }
                } else {
                    $results[$file][database][errorType][$packetType]++;
                    $results[$file][database][error]++;
                    $results[$file][database][errors][$this->CDRdb->Errno]++;
                    $results[$file][database][errorDict][$this->CDRdb->Errno]=$this->CDRdb->Error;
                }
                $results[$file][database][queries]++;
            }
        }

        $e=time();
        $d=$e-$b;

        print "Import results (script runtime $d s)\n";
        foreach (array_keys($results[$file][packetTypes]) as $ptype) {
        	$howmany=$results[$file][packetTypes][$ptype];
            print "$ptype: $howmany packets ";
            $totalPackets=$totalPackets+$howmany;
        }

        print "\nDatabase import statistics: ";
        if ($results[$file][database][insert]) {
            $howmany=$results[$file][database][insert];
            print "$howmany records inserted ";
        }

        if ($results[$file][database][update]) {
            $howmany=$results[$file][database][update];
            print "$howmany records updated";
        }

        if ($results[$file][database][error]) {
            $howmany=$results[$file][database][error];
            $queries=$results[$file][database][queries];
            print "\n$queries queries from which $howmany queries failed\n";
        	foreach (array_keys($results[$file][database][errors]) as $error) {
        		$howmany=$results[$file][database][errors][$error];
                $errorDescription=$results[$file][database][errorDict][$error];
                print "MySQL Error $error ($errorDescription): $howmany errors\n";
            }
            print "Error were generated by the folowing RADIUS packet types:\n";
        	foreach (array_keys($results[$file][database][errorType]) as $errorType) {
        		$howmany=$results[$file][database][errorType][$errorType];
                print "$errorType packet: $howmany errors\n";
            }
        }

        if ($d) {
        	$importSpeed=number_format($totalPackets/$d,0,"","");
            print "Import speed: $importSpeed packets / second\n";
        }
    }