I've got a usage file that I have accumulated from various places, pieced it together 
to do basically what I need.  It tallys up a particular dial-up users time online for 
a given month.  The only problem I am having is it shows days, hours and min online.  
I would like to see if I can convert the "days" into hours, so a person does not see 
that they have been online for "3 days, 4 hours and 34 min", I'de like it to say "40 
hours and 34 min".  I've attached the script I am using below.  If anyone has time to 
weed through it and tell me how I can fix this, it would be greatly appriciated.

Thanks,
Scott Miller




<?php 
define("cSelfName", basename($PHP_SELF)); 
require("config.cfg"); 
$dlink = mysql_connect("$sqlserver", "$sqluser", "$sqlpass") or die("Could not connect 
to Mysql Database!!!"); 
mysql_select_db("$database"); 

function datetime2timestamp($sDate) { 
    $iYear = (int)substr($sDate, 0, 4); 
    $iMonth = (int)substr($sDate, 5, 2); 
    $iDay = (int)substr($sDate, 8, 2); 

    $iHour = (int)substr($sDate, 11,2); 
    $iMinutes = (int)substr($sDate, 14,2); 
    $iSeconds = (int)substr($sDate, 17, 2); 

// original line below
//    return mktime($iHour, $iMinutes, $iSeconds, $iMonth, $iDay, $iYear); 
    return mktime($iHour, $iMinutes, $iSeconds, $iMonth, $iYear); 
} 

function format_seconds($iSeconds) { 

        $iDays = floor($iSeconds / 86400); 
        $iRemain = ($iSeconds - $iDays * 86400); 

        $iHours = floor($iRemain / 3600); 
        $iRemain = ($iRemain - $iHours * 3600); 

        $iMinutes = floor($iRemain / 60); 
        $iRemain = ($iRemain - $iMinutes * 60); 

        $iSeconds = round($iRemain); 

      return $iDays.'d '.$iHours.'h '.$iMinutes.'m '.$iSeconds.'s'; 


} 

function formSize($iInput) { 
    // Takes kilobytes as input and returns a formatted string of size. 
    if ($iInput >= 1048576) { 
        $sOutput = round($iInput / 1048576).''; 
    } else if ($iInput >= 1024) { 
        $sOutput = round($iInput / 1024).' KBits'; 
    } else { 
        $sOutput = round($iInput).' Bytes'; 
    } 
    return $sOutput; 
} 

?> 

        <!-- Start Usage File -->
<div id=head1 align="center"><font size=+2 face=arial><B>Dial-up Usage 
Report</B></font></div> 
<div id=text> 
<font face="arial">
<center> 

<form action="<? echo cSelfName; ?>" method="post"> 
<input type="hidden" name="sView" value="dosearch"> 
<table> 
    <tr> 
        <td colspan="2" style="text-align: center;">Enter your Username: <input 
type="text" size="28" name="sNeedle" value="<?= $sNeedle ?>"></td> 
    </tr> 
    <tr> 
        <td style="text-align: right;">Search by: </td> 
        <td> 
            <select name="sHaystack"> 
                    <option value="UserName">Username</option> 
            </select> 
        </td> 
    </tr> 
    <tr> 
        <td style="text-align: right;">Year:</td> 
        <td> 
            <select name="sYear"> 
<? 
$iThisYear = date("Y"); 
for ($i = 2003; $i <= $iThisYear; $i++) { 
    if ($sYear == $i || (!$sYear && $i == $iThisYear)) { 
        echo '<option value="'.$i.'" selected>'.$i.'</option>'; 
    } else { 
        echo '<option value="'.$i.'">'.$i.'</option>'; 
    } 
} 
?> 
            </select> 
        </td> 
    </tr> 
    <tr> 
        <td style="text-align: right;">Month: </td> 
        <td> 
            <select name="iMonth"> 
<? 
$iThisMonth = date('m'); 
$sMonths = array(0, 
    'january', 
    'february', 
    'march', 
    'april', 
    'may', 
    'june', 
    'july', 
    'august', 
    'september', 
    'october', 
    'november', 
    'december' 
); 
for ($i = 1; $i < count($sMonths); $i++) { 
    if ($iMonth == $i || (!$iMonth && $i == $iThisMonth)) { 
        echo '<option value="'.$i.'" selected>'.$sMonths[$i].'</option>'; 
    } else { 
        echo '<option value="'.$i.'">'.$sMonths[$i].'</option>'; 
    } 
} 
?> 
            </select> 
        </td> 
    </tr> 
<? 
if ($bShowAccurate) { 
    $bShowAccurate = " checked"; 
} 
?> 
    <tr> 
        <td>Show Detailed information</td> 
        <td><input type="checkbox" name="bShowAccurate"<?= $bShowAccurate ?>></td> 
    </tr> 
    <tr> 
        <td colspan="2" style="text-align: center;"><input type="submit" 
value="Search"></td> 
    </tr> 
</table> 
</form> 

<? 
switch ($sView) { 
    case "dosearch": 
                ?> 
                <table border="1" cellpadding="2" cellspacing="0"> 
                        <tr> 
                                <td colspan="7" align="center"><b>Search results <font 
color="#FF0000"><?= $sNeedle ?></font></b></td> 
                        </tr> 
                        <tr> 
                                <td><b>Username</b></td> 
                                <td><b>Start Time</b></td> 
                                <td><b>Stop Time</b></td> 
                                <td><b>Total Time</b></td> 
 
                    </tr> 
                <? 
        $sBeginDate = $sYear.'-'.$iMonth.'-01 00:00:00'; 
        $sEndDate = $sYear.'-'.$iMonth.'-'.date('t', mktime(0, 0, 0, $iMonth, 1, 
$sYear)).' 23:59:59'; 
                $sQueryString = " 
                SELECT DISTINCT 
                UserName, 
                AcctStartTime, 
                AcctStopTime, 
                AcctSessionTime, 
                AcctInputOctets, 
                AcctOutputOctets 
                        FROM radacct 
                        WHERE UserName LIKE ('%$sNeedle%') 
            AND AcctStopTime != '0000-00-00 00:00:00' 
            AND AcctStartTime > '$sBeginDate' 
            AND AcctStartTime < '$sEndDate' 
            ORDER BY UserName 
                "; 
        $oQuery = mysql_query($sQueryString); 
        echo mysql_error(); 
                while (list($UserName, $AcctStartTime, $AcctStopTime, 
$AcctSessionTime, $AcctInputOctets, $AcctOutputOctets) = mysql_fetch_row($oQuery)) { 
                        if ($sLastUserName && $UserName != $sLastUserName) { 
                                ?> 
      $sql = "SELECT AcctStartTime, AcctStopTime, FramedIPAddress, AcctSessionTime, 
AcctInputOctets, AcctOutputOctets  FROM radacct WHERE AcctStartTime >= \"$from\" AND 
AcctStopTime <= \"$to\" AND AcctStopTime != 0 AND UserName = 
\"".$query->param('username')."\"";
                                <tr bgcolor="#d0d0d0"> 
                                <td><?= $sLastUserName ?></td> 
                                <td><?= AcctStartTime ?></td> 
                                <td><?= AcctstopTime ?></td> 
                                </tr> 
                                <? 
                $iTotalInput = 0; 
                $iTotalOutput = 0; 
                $iTotalSessionTime = 0; 
                unset($iMinStartStamp); 
                unset($iMaxStopStamp); 
                        } 
                        $iTotalInput += $AcctInputOctets; 
                        $iTotalOutput += $AcctOutputOctets; 
            $iTotalSessionTime += $AcctSessionTime; 
            $sLastUserName = $UserName; 

            $iStartStamp = datetime2timestamp($AcctStartTime); 
            $iStopStamp = datetime2timestamp($AcctStopTime); 

            if (!$iMinStartStamp || $iStartStamp < $iMinStartStamp) { 
                $iMinStartStamp = $iStartStamp; 
            } 
            if ($iStopStamp > $iMaxStopStamp) { 
                $iMaxStopStamp = $iStopStamp; 
            } 

            $sLastAcctStartTime = $AcctStartTime; 

            if ($bShowAccurate) { 
                            ?> 
                            <tr> 
                                <td><? echo $UserName; ?></a></td> 
                                <td><?= $AcctStartTime ?></td> 
                                <td><?= $AcctStopTime ?></td> 
                                <td><? echo format_seconds($AcctSessionTime); ?></td> 
                            </tr> 
                            <? 
            } 
                } 
        if ($sLastUserName && $UserName != $sLastUserName) { 
            ?> 
            <tr bgcolor="#d0d0d0"> 
                <td colspan=2 align=center><b><font face="arial" color="#FF0000">Total 
Time Online</font></b></td> 
                <td colspan=2 align=right><b><font face="arial" color="#FF0000"><?= 
format_seconds($iTotalSessionTime) ?></font></b></td> 
        </tr> 
            <? 
            $iTotalInput = 0; 
            $iTotalOutput = 0; 
            $iTotalSessionTime = 0; 
            unset($iMinStartStamp); 
            unset($iMaxStopStamp); 
        } 

                echo '</table>'; 
                break; 
} 
?> 
        </center> 
    <br> 
    <br> 
    <center><font face="arial" color="#FF0000">d = 24 hours.</font></center> 
    <br> 
    <br> 




        <!-- Stop Usage File -->

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to