<?php require_once('Connections/conn_newland.php'); ?><?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "administrator";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "frm_updateUser")) {
  $updateSQL = sprintf("UPDATE tbl_users SET userGroup=%s WHERE userID=%s",
                       GetSQLValueString($_POST['userGroup'], "text"),
                       GetSQLValueString($_POST['userID'], "int"));

  mysql_select_db($database_conn_newland, $conn_newland);
  $Result1 = mysql_query($updateSQL, $conn_newland) or die(mysql_error());

  $updateGoTo = "admin_addUser_master.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$maxRows_rs_registeredUsers = 20;
$pageNum_rs_registeredUsers = 0;
if (isset($_GET['pageNum_rs_registeredUsers'])) {
  $pageNum_rs_registeredUsers = $_GET['pageNum_rs_registeredUsers'];
}
$startRow_rs_registeredUsers = $pageNum_rs_registeredUsers * $maxRows_rs_registeredUsers;

$colname_rs_registeredUsers = "-1";
if (isset($_GET['recordID'])) {
  $colname_rs_registeredUsers = $_GET['recordID'];
}
mysql_select_db($database_conn_newland, $conn_newland);
$query_rs_registeredUsers = sprintf("SELECT userID, firstName, lastName, username, userGroup FROM tbl_users WHERE userID = %s ORDER BY lastName ASC", GetSQLValueString($colname_rs_registeredUsers, "int"));
$query_limit_rs_registeredUsers = sprintf("%s LIMIT %d, %d", $query_rs_registeredUsers, $startRow_rs_registeredUsers, $maxRows_rs_registeredUsers);
$rs_registeredUsers = mysql_query($query_limit_rs_registeredUsers, $conn_newland) or die(mysql_error());
$row_rs_registeredUsers = mysql_fetch_assoc($rs_registeredUsers);

if (isset($_GET['totalRows_rs_registeredUsers'])) {
  $totalRows_rs_registeredUsers = $_GET['totalRows_rs_registeredUsers'];
} else {
  $all_rs_registeredUsers = mysql_query($query_rs_registeredUsers);
  $totalRows_rs_registeredUsers = mysql_num_rows($all_rs_registeredUsers);
}
$totalPages_rs_registeredUsers = ceil($totalRows_rs_registeredUsers/$maxRows_rs_registeredUsers)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Newland Tours: Dodaj użytkownika do grupy administratorów</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>

<body class="oneColFixCtrHdr">
<a href="#top"><img src="images/spacer.gif" alt="Przejdź do głównej treści strony" border="0" /></a>
<div id="container">
  <div id="header">
    <img src="images/banner_left.gif" width="451" height="68" alt="Banner Newland Tours, strona lewa." /><img src="images/banner_right.jpg" width="276" height="68" id="bannerRight" alt="Banner Newland Tours, strona prawa" />
  <!-- end #header --></div>
  <div id="navigation">
  	<ul>
        <li><a href="index.php">Główna</a></li>
        <li><span class=""><span class=""><a href="about.cfm">O firmie</a></span></span></li>
<li><a href="tours.php">Znajdź wyjazd</a></li>
        <li><a href="profiles.php">Opisy krajów</a></li>
        <li><a href="contact.php">Kontakt z nami</a></li>
    </ul>
    </div>
  <div id="mainContent">
    <h1><a name="top" id="top"></a>Dodaj  użytkownika do&nbsp;grupy administratorów</h1>
    <p>Użyj  poniższego menu, aby zmienić grupę praw dostępu użytkownika.  Kliknij&nbsp;przycisk Wyślij, aby zmiany przyniosły skutek.</p>
    <form id="frm_updateUser" name="frm_updateUser" method="POST" action="<?php echo $editFormAction; ?>">
      <table border="1" align="center">
        <tr>
          <td><strong>Imię</strong></td>
          <td><?php echo $row_rs_registeredUsers['firstName']; ?> </td>
        </tr>
        <tr>
          <td><strong>Nazwisko</strong></td>
          <td><?php echo $row_rs_registeredUsers['lastName']; ?> </td>
        </tr>
        <tr>
          <td><strong>Bieżąca grupa praw dostępu</strong></td>
          <td><?php echo $row_rs_registeredUsers['userGroup']; ?> </td>
        </tr>
        <tr>
          <td><strong>Nowa grupa praw dostępu</strong></td>
          <td><select name="userGroup" id="userGroup">
              <option value="gość" selected="selected">Gość</option>
              <option value="administrator">Administrator</option>
          </select></td>
        </tr>
        <tr>
          <td><input name="userID" type="hidden" id="userID" value="<?php echo $_GET['recordID']; ?>" /></td>
          <td><input type="submit" name="button" id="button" value="Wyślij" /></td>
        </tr>
      </table>
      <br clear="all" />
      <!-- end #mainContent -->
      <input type="hidden" name="MM_update" value="frm_updateUser" />
    </form>
  </div>
  <div id="footer">
    <p>&copy; 2007 Newland Tours</p>
  <!-- end #footer --></div>
<!-- end #container --></div>



</body>
</html><?php
mysql_free_result($rs_registeredUsers);
?>
