Well, I tried to manipulate MySQL to my best.
It is impossible to make date calculation functions inside mysql because
the Expiration Attribute is not stored in date type column.
It is also stupid to get each user to php and manipulate there since that
would be very inefficient. This is what I could do at most.
Please let me know about what you think :)
Evren
<?php
require('../conf/config.php3');
require('../lib/functions.php3');
?>
<html>
<?php

if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
        include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
else{
        echo <<<EOM
<title>Expiring User Accounts</title>
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
<link rel="stylesheet" href="style.css">
</head>
<body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
<center>
<b>Could not include SQL library functions. Aborting</b>
</body>
</html>
EOM;
        exit();
}

$now = time();
$now_str = ($now_str != '') ? "$now_str" : date("M Y",$now + 86400);
$min_str = ($min_str != '') ? "$min_str" : date("j",$now + 86400);
$max_str = ($max_str != '') ? "$max_str" : date("j",$now + 86400);
$num = 0;
$pagesize = ($pagesize) ? $pagesize : all;
$limit = ($pagesize == 'all') ? '' : "LIMIT $pagesize";
$selected[$pagesize] = 'selected';

echo <<<EOM
<head>
<title>Expiring User Accounts</title>
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
<link rel="stylesheet" href="style.css">
</head>
<body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
<center>
<table border=0 width=550 cellpadding=0 cellspacing=0>
<tr valign=top>
<td align=center><img src="images/title2.gif"></td>
</tr>
</table>
EOM;

echo <<<EOM
<br><br>
<table border=0 width=740 cellpadding=1 cellspacing=1>
<tr valign=top>
<td width=55%></td>
<td bgcolor="black" width=45%>
        <table border=0 width=100% cellpadding=2 cellspacing=0>
        <tr bgcolor="#907030" align=right valign=top><th>
        <font color="white">Expiring User Accounts</font>&nbsp;
        </th></tr>
        </table>
</td></tr>
<tr bgcolor="black" valign=top><td colspan=2>
        <table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" 
valign=top>
        <tr><td>
For Date:
<b>$min_str - $max $now_str</b>
EOM;
?>

<p>
        <table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% 
cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
        <tr bgcolor="#d0ddb0">
        <th>#</th><th>user</th><th>date</th>
        </tr>

<?php
$link = @da_sql_pconnect($config);
if ($link){
        $search = @da_sql_query($link,$config,
        "SELECT UserName,Value as Date FROM $config[sql_check_table]
        WHERE Attribute = 'Expiration'
        AND Value LIKE '% $now_str' AND substring(Value,1,2) <= $max_str AND 
substring(Value,1,2) >= $min_str
        ORDER BY substring(Value,1,2)*1 DESC $limit;");
        if ($search){
                while( $row = @da_sql_fetch_array($search,$config) ){
                        $num++;
                        $user = "$row[UserName]";
                        $date = "$row[Date]";
                        echo <<<EOM
                        <tr align=center>
                                <td>$num</td>
                                <td><a href="user_admin.php3?login=$user" title="Edit 
user $user">$user</a></td>
                                <td>$date</td>
                        </tr>
EOM;
                }
        }
        else
                echo "<b>Database query failed: " . da_sql_error($link,$config) . 
"</b><br>\n";
}
else
        echo "<b>Could not connect to SQL database</b><br>\n";
echo <<<EOM
        </table>
<tr><td>
<hr>
<tr><td align="center">
        <form action="expiration.php3" method="get" name="master">
        <table border=0>
                <tr><td colspan=5></td>
                        <td rowspan=3 valign="bottom">
                                <small>
                                the <b>from day</b> matches any login after the 00:00 
that day,
                                and the <b>to day</b> any login before the 23:59 that 
day.
                                the default values shown are the <b>next day</b>.
                        </td>
                </tr>
                <tr valign="bottom">
                        <td><small><b>from day</td><td><small><b>to 
day</td><td><small><b>date</td><td><small><b>pagesize</td><td>
&nbsp;</td>
        <tr valign="middle"><td>
<input type="text" name="min_str" size="11" value="$min_str"></td>
<td><input type="text" name="max_str" size="11" value="$max_str"></td>
<td><input type="text" name="now_str" size="11" value="$now_str"></td>
<td><select name="pagesize">
<option $selected[5] value="5" >05
<option $selected[10] value="10">10
<option $selected[15] value="15">15
<option $selected[20] value="20">20
<option $selected[40] value="40">40
<option $selected[80] value="80">80
<option $selected[all] value="all">all
</select>
</td>
EOM;
?>

<td><input type="submit" class=button value="show"></td></tr>
</table></td></tr></form>
</table>
</tr>
</table>
</body>
</html>

Reply via email to