<?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/>.

			$currentUser = $sessionHandling->getCurrentUser();
			$resourcesPageLevel = new ResourceCollection(true, 'GRCAD', false, 1, false);

			$GRCAD = $resourcesPageLevel->FindResourceByCode('GRCAD');
			echo '<title>' . Common::GetAppName() . ' - ' . $GRCAD->Value . '</title>';
		?>

		<meta http-equiv="Content-Type" content="text/html;charset=utf8" />

		<link rel="shortcut icon" href="images/GNURC.ico" type="image/x-icon" />
		<link rel="icon" href="images/GNURC.ico" type="image/ico" />

		<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/master.js"></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="main-container">

			<div id="bannerlogocontainer">

				<img id="banner_logo" alt="GNU Remote Control" src="images/logo.png" />

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

			</div>

			<div id="shader">

				<?php
					echo '<span id="header">' . $GRCAD->Value . '</span>';

					$users = new UserCollection(true);
					$groups = new IPThermostatGroupCollection(true);
				?>

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

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

				<?php
					$GRCAD_LBL1 = $resourcesPageLevel->FindResourceByCode('GRCAD$LBL1');
					echo '<div><span class="' . $GRCAD_LBL1->StyleClass . '">' . $GRCAD_LBL1->Value . '</span></div>';
				?>

				<div id="userssection" class="section">

					<div class="sectionheader">

						<?php
							$GRCAD_HDR1 = $resourcesPageLevel->FindResourceByCode('GRCAD$HDR1');
							echo '<span class="' . $GRCAD_HDR1->StyleClass . '">' . $GRCAD_HDR1->Value . '</span>';

							$resourcesGRCAD_HDR1 = new ResourceCollection(true, $GRCAD_HDR1->Code, false, 1, true);
						?>

					</div>

					<div class="sectioninner">

						<table id="profileadmin" class="settings">

							<tr>

								<td colspan="2">

									<?php
										$GRCAD_HDR1_LBL1 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$LBL1');
										echo $GRCAD_HDR1_LBL1->Value . ' <span id="totalusercount">' . $users->count() . '</span>';
									?>

								</td>

								<td colspan="3">

									<?php
										$thermcount = 0;

										foreach ($users as $user)
										{
											$thermcount += $user->MaxTherms;
										}

										$GRCAD_HDR1_LBL2 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$LBL2');
										echo $GRCAD_HDR1_LBL2->Value . ' <span id="totalthermcount">' . number_format($thermcount) . '</span>';
									?>

								</td>

							</tr>

							<tr class="header">

								<th>&nbsp;</th>

									<?php
										$GRCAD_HDR1_CLM1 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$CLM1');
										echo '<th>' . $GRCAD_HDR1_CLM1->Value . '</th>';

										$GRCAD_HDR1_CLM2 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$CLM2');
										echo '<th>' . $GRCAD_HDR1_CLM2->Value . '</th>';

										$GRCAD_HDR1_CLM3 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$CLM3');
										echo '<th>' . $GRCAD_HDR1_CLM3->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_HDR1_HLK2 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$HLK2');
									echo '<a href="javascript:void(0);" id="Users_Edit_' . $user->ID . '" onclick="editUser(' . $user->ID . ');" class="' . $GRCAD_HDR1_HLK2->StyleClass . '">' . $GRCAD_HDR1_HLK2->Value . '</a>';

									$GRCAD_HDR1_HLK3 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$HLK3');
									echo '<a href="javascript:void(0);" id="Users_Update_' . $user->ID . '" onclick="updateUser(' . $user->ID . ');" class="' . $GRCAD_HDR1_HLK3->StyleClass . '">' . $GRCAD_HDR1_HLK3->Value . '</a>';

									$GRCAD_HDR1_HLK4 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$HLK4');
									echo '&nbsp;<a href="javascript:void(0);" id="Users_Cancel_' . $user->ID . '" onclick="cancelEditUser(' . $user->ID . ');" class="' . $GRCAD_HDR1_HLK4->StyleClass . '">' . $GRCAD_HDR1_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">' . number_format($user->MaxTherms) . '</span><input type="text" id="MaxNumTherms_' . $user->ID . '_Input" value="' . $user->MaxTherms . '" class="view" /></td>';
									echo '<td><span id="LangCode_' . $user->ID . '_Span" class="view">' . $user->Language->Description . '</span>';

									echo '<select id="LangCode_' . $user->ID . '_Input" class="view">';

									$languages = new LanguageCollection(true);

									foreach ($languages as $language)
									{
										if ($language->Code == $user->Language->Code)
										{
											echo '<option value="' . $language->Code . '" selected>' . $language->Description . '</option>';
										}
										else
										{
											echo '<option value="' . $language->Code . '">' . $language->Description . '</option>';
										}
									}

									echo '</select></td>';

									echo '<td>';

									$GRCAD_HDR1_HLK5 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$HLK5');
									echo '<a href="javascript:void(0);" id="Users_Delete_' . $user->ID . '" onclick="deleteUser(' . $user->ID . ');" class="' . $GRCAD_HDR1_HLK5->StyleClass . '">' . $GRCAD_HDR1_HLK5->Value . '</a>';

									echo '</td>';
									echo '</tr>';

									$counter++;
								}

								echo '<tr id="addrow">';

								$GRCAD_HDR1_HLK1 = $resourcesGRCAD_HDR1->FindResourceByCode('GRCAD$HDR1$HLK1');
								echo '<td><a href="javascript:void(0);" onclick="addUser();" class="' . $GRCAD_HDR1_HLK1->StyleClass . '">' . $GRCAD_HDR1_HLK1->Value . '</a></td>';

								echo '<td><input type="text" id="UserName_0_Input" class="required" /></td>';
								echo '<td><input type="text" id="MaxNumTherms_0_Input" class="number required" /></td>';
								echo '<td>';

								$resourcesGRCAD_HDR1_CLM3 = new ResourceCollection(true, $GRCAD_HDR1_CLM3->Code, false, 1, true);

								echo '<select id="LangCode_0_Input" class="required">';

								$languages = new LanguageCollection(true);

								$GRCAD_HDR1_CLM3_DDI1 = $resourcesGRCAD_HDR1_CLM3->FindResourceByCode('GRCAD$HDR1$CLM3$DDI1');
								echo '<option value="' . $GRCAD_HDR1_CLM3_DDI1->DropDownItemValue  . '" selected>' . $GRCAD_HDR1_CLM3_DDI1->Value . '</option>';

								foreach ($languages as $language)
								{
									echo '<option value="' . $language->Code . '">' . $language->Description . '</option>';
								}

								echo '</select></td>';

								echo '<td>&nbsp;</td>';

								echo '</tr>';
							?>

						</table>

					</div>

				</div>

				<div id="groupssection" class="section">

					<div class="sectionheader">

						<?php
							$GRCAD_HDR2 = $resourcesPageLevel->FindResourceByCode('GRCAD$HDR2');
							echo '<span class="' . $GRCAD_HDR2->StyleClass . '">' . $GRCAD_HDR2->Value . '</span>';

							$resourcesGRCAD_HDR2 = new ResourceCollection(true, $GRCAD_HDR2->Code, false, 1, true);
						?>

					</div>

					<div class="sectioninner">

						<table id="groupsadmin" class="settings">

							<tr>

								<td colspan="4">

									<?php
										$GRCAD_HDR2_LBL1 = $resourcesGRCAD_HDR2->FindResourceByCode('GRCAD$HDR2$LBL1');
										echo $GRCAD_HDR2_LBL1->Value . ' <span id="totalgroupcount">' . $groups->count() . '</span>';
									?>

								</td>

							</tr>

							<tr class="header">

								<th>&nbsp;</th>

								<?php
									$GRCAD_HDR2_CLM1 = $resourcesGRCAD_HDR2->FindResourceByCode('GRCAD$HDR2$CLM1');
									echo '<th>' . $GRCAD_HDR2_CLM1->Value . '</th>';

									$GRCAD_HDR2_CLM2 = $resourcesGRCAD_HDR2->FindResourceByCode('GRCAD$HDR2$CLM2');
									echo '<th>' . $GRCAD_HDR2_CLM2->Value . '</th>';
								?>

								<th>&nbsp;</th>

							</tr>

							<?php
								$counter = 1;

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

									echo '<td>';
									$GRCAD_HDR2_HLK2 = $resourcesGRCAD_HDR2->FindResourceByCode('GRCAD$HDR2$HLK2');
									echo '<a href="javascript:void(0);" id="Groups_Edit_' . $group->ID . '" onclick="editGroup(' . $group->ID . ');" class="' . $GRCAD_HDR2_HLK2->StyleClass . '">' . $GRCAD_HDR2_HLK2->Value . '</a>';

									$GRCAD_HDR2_HLK3 = $resourcesGRCAD_HDR2->FindResourceByCode('GRCAD$HDR2$HLK3');
									echo '<a href="javascript:void(0);" id="Groups_Update_' . $group->ID . '" onclick="updateGroup(' . $group->ID . ');" class="' . $GRCAD_HDR2_HLK3->StyleClass . '">' . $GRCAD_HDR2_HLK3->Value . '</a>';

									$GRCAD_HDR2_HLK4 = $resourcesGRCAD_HDR2->FindResourceByCode('GRCAD$HDR2$HLK4');
									echo '&nbsp;<a href="javascript:void(0);" id="Groups_Cancel_' . $group->ID . '" onclick="cancelEditGroup(' . $group->ID . ');" class="' . $GRCAD_HDR2_HLK4->StyleClass . '">' . $GRCAD_HDR2_HLK4->Value . '</a>';

									echo '</td>';

									echo '<td><span id="Name_' . $group->ID . '_Span" class="view">' . $group->Name . '</span><input type="text" id="Name_' . $group->ID . '_Input" value="' . $group->Name . '" class="view" /></td>';
									echo '<td><span id="Description_' . $group->ID . '_Span" class="view">' . $group->Description . '</span><input type="text" id="Description_' . $group->ID . '_Input" value="' . $group->Description . '" class="view" /></td>';

									echo '<td>';

									$GRCAD_HDR2_HLK5 = $resourcesGRCAD_HDR2->FindResourceByCode('GRCAD$HDR2$HLK5');
									echo '<a href="javascript:void(0);" id="Groups_Delete_' . $group->ID . '" onclick="deleteGroup(' . $group->ID . ');" class="' . $GRCAD_HDR2_HLK5->StyleClass . '">' . $GRCAD_HDR2_HLK5->Value . '</a>';

									echo '</td>';
									echo '</tr>';

									$counter++;
								}

								echo '<tr id="addrow">';

								$GRCAD_HDR2_HLK1 = $resourcesGRCAD_HDR2->FindResourceByCode('GRCAD$HDR2$HLK1');
								echo '<td><a href="javascript:void(0);" onclick="addGroup();" class="' . $GRCAD_HDR2_HLK1->StyleClass . '">' . $GRCAD_HDR2_HLK1->Value . '</a></td>';

								echo '<td><input type="text" id="Name_0_Input" class="required" /></td>';
								echo '<td><input type="text" id="Description_0_Input" /></td>';

								echo '<td>&nbsp;</td>';

								echo '</tr>';
							?>

						</table>

					</div>

				</div>

			</div>

		</div>

		<input type="hidden" id="messageHidden" />
		<input type="hidden" id="langDDLItems" />

	</body>

</html>
