<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:import href="user_search.xsl"/>                    
    <xsl:variable name="php_version">php4</xsl:variable>
    
    <xsl:template match="user">
        <xsl:variable name="username">
            <xsl:value-of select="username"/>
        </xsl:variable>
        <xsl:variable name="email">
            <xsl:value-of select="email"/>
        </xsl:variable>
        <tr>
            <td>
            <input type="checkbox" name="usernames[]">
                <xsl:attribute name="value">
                    <xsl:value-of select="$username"/>
                </xsl:attribute>
            </input>
            </td>
            <td>
                <xsl:value-of select="lname"/>
            </td>
            <td>
                <xsl:value-of select="fname"/>
            </td>
            <td>
                <xsl:value-of select="category"/>
            </td>          
            <td>
                <a target="my_dictionary">
                    <xsl:attribute name="href">
                        <xsl:value-of
                            select="concat('../',$php_version,'/mydictionary.',$php_version,'?function=admin_view&amp;view_user=',$username)"
                        />
                    </xsl:attribute>
                    <xsl:value-of select="username"/>
                </a>
            </td>
            <td>
                <a>
                    <xsl:attribute name="href">
                        <xsl:value-of select="concat('mailto:',$email)"/>
                    </xsl:attribute>
                    <xsl:value-of select="email"/>
                </a>
            </td>
            <td>
                <xsl:value-of select="password"/>
            </td>
            <td>
                <xsl:value-of select="date"/>
            </td>
            <td align="center">
                <xsl:value-of select="login_count"/>
            </td>
            <td>
                <xsl:value-of select="last_login"/>
            </td>            
        </tr>
    </xsl:template>
    
    <xsl:template match="defaults">
        <xsl:apply-imports/>
    </xsl:template>
    
    <xsl:template match="/">
        <html>
            <head>
                <title>Account Manager</title>
                <script type="text/javascript">
                    function foo() {
                        var field = document.forms[0].elements['usernames[]'].length;
                        alert(field);
                    }
                </script>
                <script language="javascript" type="text/javascript">
                    var checkflag = "false";
                    function check(field_name) {
                        var field = document.forms[0].elements[field_name];
                        if(checkflag == "false") {
                            for(i=0;i&lt;field.length;i++) {
                                field[i].checked = true; 
                            }
                            checkflag="true";
                        }
                        else {
                            for(i=0;i&lt;field.length;i++) {
                                field[i].checked = false; 
                            }
                            checkflag="false";
                         }
                    }
                </script>
            </head>
            <body>
                <center>
                <form name="user_accounts" method="post">
                    <xsl:attribute name="action"><xsl:value-of select="concat('../',$php_version,'/login.',$php_version)"/></xsl:attribute> 
                    <input type="hidden" name="function" value="delete_accounts"/>
                    <table border="1">
                        <tr>
                            <th>Delete?<input type="button" onclick="check('usernames[]')" value="all"/></th>
                            <th>Last Name</th>
                            <th>First Name</th>
                            <th>Category</th>
                            <th>Username</th>
                            <th>Email</th>
                            <th>Password</th>
                            <th>Date Created</th>
                            <th>Login Count</th>
                            <th>Last Login</th>
                        </tr>
                        <xsl:apply-templates select="//resultset/user"/>
                        <tr>
                            <td colspan="11" align="center">
                                <input type="submit" value="Delete Users"/>
                            </td>
                        </tr>
                    </table>
                </form>  
                </center>
                <xsl:apply-templates select="document('defaults.xml')//defaults"/>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>
