Location: PHPKode > projects > Railway Incident Reporting System > add_staff_involved.php
<?php require_once('Connections/incidentlog.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "1,2";
$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?fail";
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 = "") 
{
  if (PHP_VERSION < 6) {
    $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_insert"])) && ($_POST["MM_insert"] == "addstaff")) {
  $insertSQL = sprintf("INSERT INTO staff (incidentid, name) VALUES (%s, %s)",
                       GetSQLValueString($_POST['incidentid'], "int"),
                       GetSQLValueString($_POST['name'], "text"));

  mysql_select_db($database_incidentlog, $incidentlog);
  $Result1 = mysql_query($insertSQL, $incidentlog) or die(mysql_error());

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

mysql_select_db($database_incidentlog, $incidentlog);
$query_staff = "SELECT * FROM staff";
$staff = mysql_query($query_staff, $incidentlog) or die(mysql_error());
$row_staff = mysql_fetch_assoc($staff);
$totalRows_staff = mysql_num_rows($staff);
?>
<!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>Incident Log - Add involved staff</title>
<link href="css/main.css" rel="stylesheet" type="text/css" /><link href="css/main.css" rel="stylesheet" type="text/css" />

</head>

<body>
<?php
include("inc/header.php");
?>

<?php
include("inc/menu.html");
?>
<h2><?php echo "$IStaff" ?></h2>
<p><?php echo "$AddToRecord" ?> <?php echo $_GET[id]; ?></p>
<form action="<?php echo $editFormAction; ?>" method="POST" name="addstaff"><input name="incidentid" type="hidden" value="<?php echo $_GET[id]; ?>" /><table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td><p><strong>Name<em> (of staff member)</em>:</strong></p></td>
    <td><p>
      <input type="text" name="name" id="name" />
      <em>(Please insert the role of the person in brackets next to the name)</em></p></td>
  </tr>
</table><br /><input name="submit" type="submit" /><br />
<input type="hidden" name="MM_insert" value="addstaff" />
</form>
<?php
include("inc/footer.php");
?>
</body>
</html>
<?php
mysql_free_result($staff);
?>
Return current item: Railway Incident Reporting System