PHP код:
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** 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 == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "test.php"; ?>
<?php require_once('Connections/site.php'); ?>
<?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;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO comments (`data`, iDpr, coment, Nikdob) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['data'], "date"),
GetSQLValueString($_POST['IDpr'], "int"),
GetSQLValueString($_POST['comment'], "text"),
GetSQLValueString($_POST['Nik'], "text"));
mysql_select_db($database_site, $site);
$Result1 = mysql_query($insertSQL, $site) or die(mysql_error());
$insertGoTo = "comments.php?IDpr=".$_GET['IDpr'];
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_Process = "-1";
if (isset($_GET['IDpr'])) {
$colname_Process = $_GET['IDpr'];
}
mysql_select_db($database_site, $site);
$query_Process = sprintf("SELECT * FROM process WHERE id = %s", GetSQLValueString($colname_Process, "int"));
$Process = mysql_query($query_Process, $site) or die(mysql_error());
$row_Process = mysql_fetch_assoc($Process);
$totalRows_Process = mysql_num_rows($Process);
$maxRows_comment = 10;
$pageNum_comment = 0;
if (isset($_GET['pageNum_comment'])) {
$pageNum_comment = $_GET['pageNum_comment'];
}
$startRow_comment = $pageNum_comment * $maxRows_comment;
$colname_comment = "-1";
if (isset($_GET['IDpr'])) {
$colname_comment = $_GET['IDpr'];
}
mysql_select_db($database_site, $site);
$query_comment = sprintf("SELECT * FROM comments WHERE iDpr = %s ORDER BY id ASC", GetSQLValueString($colname_comment, "int"));
$query_limit_comment = sprintf("%s LIMIT %d, %d", $query_comment, $startRow_comment, $maxRows_comment);
$comment = mysql_query($query_limit_comment, $site) or die(mysql_error());
$row_comment = mysql_fetch_assoc($comment);
if (isset($_GET['totalRows_comment'])) {
$totalRows_comment = $_GET['totalRows_comment'];
} else {
$all_comment = mysql_query($query_comment);
$totalRows_comment = mysql_num_rows($all_comment);
}
$totalPages_comment = ceil($totalRows_comment/$maxRows_comment)-1;
$queryString_comment = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_comment") == false &&
stristr($param, "totalRows_comment") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_comment = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_comment = sprintf("&totalRows_comment=%d%s", $totalRows_comment, $queryString_comment);
?>
<?php include "verh.in" ?>
<p class="стиль1" style="font-size: large">Обсуждение Процесса:</p>
<table width="100%" border="1" bordercolor="#000000">
<tr>
<td width="25%" height="27"><div align="right">Дата:</div></td>
<td width="25%"><p><?php echo $row_Process['data']; ?></p>
</td>
<td width="22%"><div align="right">Вес:</div></td>
<td width="28%"><p><?php echo $row_Process['ves']; ?></p>
</td>
</tr>
<tr>
<td height="60" colspan="4"><p>Изменения:</p>
<p><?php echo $row_Process['Izmeneniua']; ?></p></td>
</tr>
</table>
<p> </p>
<hr />
<p> </p>
<p class="стиль1" style="font-size: medium">Комментарии:</p>
<?php do { ?>
<div>
<table width="100%" border="1" bordercolor="#000000">
<tr>
<td width="25%"><div align="right">Ник: </div></td>
<td width="26%"><p><?php echo $row_comment['Nikdob']; ?></p>
</td>
<td width="23%"><div align="right">Дата:</div></td>
<td width="26%"><p><?php echo $row_comment['data']; ?></p>
</td>
</tr>
<tr>
<td colspan="4"><p>Комментарий:</p>
<p><?php echo $row_comment['coment']; ?></p></td>
</tr>
</table>
</div>
<?php } while ($row_comment = mysql_fetch_assoc($comment)); ?><p><a href="<?php printf("%s?pageNum_comment=%d%s", $currentPage, 0, $queryString_comment); ?>">В начало</a>| <a href="<?php printf("%s?pageNum_comment=%d%s", $currentPage, max(0, $pageNum_comment - 1), $queryString_comment); ?>"><< Предыдущая</a> |<a href="<?php printf("%s?pageNum_comment=%d%s", $currentPage, min($totalPages_comment, $pageNum_comment + 1), $queryString_comment); ?>">Следующая >></a> | <a href="<?php printf("%s?pageNum_comment=%d%s", $currentPage, $totalPages_comment, $queryString_comment); ?>">В конец</a> </p>
<p> </p>
<hr />
<p> </p>
<?php if (((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { ?>
<form name="form1" id="form1" method="POST" action="<?php echo $editFormAction; ?>">
Добавить Комментарий:<br />
<input name="data" type="hidden" id="data" value="<?php echo date("Y-m-d")?>" />
<input name="IDpr" type="hidden" id="IDpr" value="<?php echo $_GET['IDpr']?>" />
<input name="Nik" type="hidden" id="Nik" value="<?php echo $_SESSION['MM_Username']?>" />
<br />
<textarea name="comment" id="comment" cols="45" rows="5"></textarea>
<br />
<input type="submit" name="otpravit" id="otpravit" value="Добвить" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
<?php } ?>
<p> </p>
<?php include "niz.in" ?>
<?php
mysql_free_result($Process);
mysql_free_result($comment);
?>