<?php require_once('lib/Global.php');  ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

	<head>

		<?php
                
//                    # Copyright (C) 2012-2013 GNU remotecontrol authors.
//                    #
//                    # This program is free software: you can redistribute it and/or modify
//                    # it under the terms of the GNU Affero General Public License as
//                    # published by the Free Software Foundation, either version 3 of the
//                    # License, or (at your option) any later version.
//                    #
//                    # This program is distributed in the hope that it will be useful,
//                    # but WITHOUT ANY WARRANTY; without even the implied warranty of
//                    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//                    # GNU Affero General Public License for more details.
//                    #
//                    # You should have received a copy of the GNU Affero General Public License
//                    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
                
                    $resourcesPageLevel = new ResourceCollection(true, 'GRCAD', false, 1, false);
                    
                    $GRCAD = $resourcesPageLevel->FindResourceByCode('GRCAD');
                    echo '<title>'.Common::GetAppName().' - '.$GRCAD->Value.'</title>';

		?>

		<link type="text/css" rel="Stylesheet" href="styles/master.css">
		<link type="text/css" rel="Stylesheet" href="styles/admin.css">
                    
                <script>
                    /*    
                    @licstart  The following is the entire license notice for the 
                    JavaScript code in this page.

                    Copyright (C) 2012-2013 GNU remotecontrol authors

                    The JavaScript code in this page is free software: you can
                    redistribute it and/or modify it under the terms of the GNU
                    General Public License (GNU GPL) as published by the Free Software
                    Foundation, either version 3 of the License, or (at your option)
                    any later version.  The code is distributed WITHOUT ANY WARRANTY;
                    without even the implied warranty of MERCHANTABILITY or FITNESS
                    FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.

                    As additional permission under GNU GPL version 3 section 7, you
                    may distribute non-source (e.g., minimized or compacted) forms of
                    that code without the copy of the GNU GPL normally required by
                    section 4, provided you include this license notice and a URL
                    through which recipients can access the Corresponding Source.   


                    @licend  The above is the entire license notice
                    for the JavaScript code in this page.
                    */
                </script>

		<script type="text/javascript" src="scripts/ajax.js"></script>
		<script type="text/javascript" src="scripts/admin.js"></script>
		<script type="text/javascript">
			var ajax = new Ajax();
			ajax.setHandlerErr(handleError);
		</script>

	</head>

	<body>

		<div id="container">
                    
                    <?php
                                            
                        echo '<span id="header">'.Common::GetAppName().' - '.$GRCAD->Value.'</span>';
        
                        $users = new UserCollection(true);

                    ?>

			<span id="message"></span>

			<img id="loadimage" alt="Working..." title="Working..." src="images/ajax-loader.gif" />

			<table id="profileadmin">
			
				<tr id="totalusersrow">

					<td colspan="4">
					
						<div id="totalscontainer">
						
							<?php
                                                        
                                                            $GRCAD_LBL1 = $resourcesPageLevel->FindResourceByCode('GRCAD$LBL1');
                                                            echo '<span id="totalrows">'.$GRCAD_LBL1->Value.' '.$users->count().'</span>';

                                                            $thermcount = 0;

                                                            foreach($users as $user)
                                                            {
                                                                $thermcount += $user->MaxTherms;
                                                            }
                                                            
                                                            $GRCAD_LBL2 = $resourcesPageLevel->FindResourceByCode('GRCAD$LBL2');
                                                            echo '<span id="totaltstats">'.$GRCAD_LBL2->Value.' '.$thermcount.'</span>';

							?>
						
						</div>						

					</td>
				
				</tr>

				<tr class="header">

					<th>&nbsp;</th>
                                        
                                        <?php
                                        
                                            $GRCAD_CLM1 = $resourcesPageLevel->FindResourceByCode('GRCAD$CLM1');
                                            echo '<th>'.$GRCAD_CLM1->Value.'</th>';
                                            
                                            $GRCAD_CLM2 = $resourcesPageLevel->FindResourceByCode('GRCAD$CLM2');
                                            echo '<th>'.$GRCAD_CLM2->Value.'</th>';
                                        
                                        ?>
                                        
                                        <th>&nbsp;</th>

				</tr>

				<?php

                                    $counter = 1;

                                    foreach($users as $user)
                                    {
                                        if($counter % 2 == 0)
                                        {
                                            echo '<tr id="~'.$user->ID.'~" class="alt">';
                                        }
                                        else
                                        {
                                            echo '<tr id="~'.$user->ID.'~">';
                                        }

                                        echo '<td>';
                                        
                                        $GRCAD_HLK2 = $resourcesPageLevel->FindResourceByCode('GRCAD$HLK2');
                                        echo '<a href="javascript:void(0);" id="Edit_'.$user->ID.'" onclick="editUser('.$user->ID.');" class="'.$GRCAD_HLK2->StyleClass.'">'.$GRCAD_HLK2->Value.'</a>';
                                        
                                        $GRCAD_HLK3 = $resourcesPageLevel->FindResourceByCode('GRCAD$HLK3');
                                        echo '<a href="javascript:void(0);" id="Update_'.$user->ID.'" onclick="updateUser('.$user->ID.');" class="'.$GRCAD_HLK3->StyleClass.'">'.$GRCAD_HLK3->Value.'</a>';
                                        
                                        $GRCAD_HLK4 = $resourcesPageLevel->FindResourceByCode('GRCAD$HLK4');
                                        echo '&nbsp;<a href="javascript:void(0);" id="Cancel_'.$user->ID.'" onclick="cancelEditUser('.$user->ID.');" class="'.$GRCAD_HLK4->StyleClass.'">'.$GRCAD_HLK4->Value.'</a>';
                                        
                                        echo '</td>';
                                        echo '<td><span id="UserName_'.$user->ID.'_Span" class="view">'.$user->UserName.'</span><input type="text" id="UserName_'.$user->ID.'_Input" value="'.$user->UserName.'" class="view" /></td>';
                                        echo '<td><span id="MaxNumTherms_'.$user->ID.'_Span" class="view">'.$user->MaxTherms.'</span><input type="text" id="MaxNumTherms_'.$user->ID.'_Input" value="'.$user->MaxTherms.'" class="view" /></td>';
                                        echo '<td>';
                                        
                                        $GRCAD_HLK5 = $resourcesPageLevel->FindResourceByCode('GRCAD$HLK5');
                                        echo '<a href="javascript:void(0);" id="Delete_'.$user->ID.'" onclick="deleteUser('.$user->ID.');" class="'.$GRCAD_HLK5->StyleClass.'">'.$GRCAD_HLK5->Value.'</a>';
                                        
                                        echo '</td>';
                                        echo '</tr>';

                                        $counter++;
                                    }

                                    echo '<tr id="addrow">';
                                    
                                    $GRCAD_HLK1 = $resourcesPageLevel->FindResourceByCode('GRCAD$HLK1');
                                    echo '<td><a href="javascript:void(0);" onclick="addUser();" class="'.$GRCAD_HLK1->StyleClass.'">'.$GRCAD_HLK1->Value.'</a></td>';
                                    
                                    echo '<td><input type="text" id="UserName_0_Input" /></td>';
                                    echo '<td><input type="text" id="MaxNumTherms_0_Input" class="number" /></td>';                                    
                                    echo '<td>&nbsp;</td>';
                                    
                                    echo '</tr>';
                                
                                ?>

			</table>

		</div>

	</body>

</html>
