<?//Copyright David Byrne 2007
//This file is part of eCanteen.
// eCanteen is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// eCanteen 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with eCanteen. If not, see <http://www.gnu.org/licenses/>.?>
<?session_start();
if ($_SESSION['userlevel']>=3)
{
include("../include/constants.php"); mysql_free_result($res);
$filter = "";
$filterfield = "";
$wholeonly = "";
$order = "";
$ordtype = "";
?>
<html>
<head>
<title>ecanteen -- break</title>
<meta name="generator" content="text/html">
<LINK REL="stylesheet" TYPE="text/css" HREF="maintain.css">
</head>
<body>
<table class="bd" width="50%"><tr><td class="hr"><h2>Breaks</h2></td><td class="bd" width="50%"><button id="Return2Cal" onclick="window.location.href='../index.php';return true;" style="width: 190px">Return to Main Menu</button></td></tr></table>
<?
$conn = connect();
$showrecs = 20;
$pagerange = 10;
$a = @$_GET["a"];
$recid = @$_GET["recid"];
if (isset($_GET["order"])) $order = @$_GET["order"];
if (isset($_GET["type"])) $ordtype = @$_GET["type"];
if (isset($_POST["order"])) $order = @$_POST["order"];
if (isset($_POST["type"])) $ordtype = @$_POST["type"];
if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
$page = @$_GET["page"];
if (!isset($page)) $page = 1;
$sql = @$_POST["sql"];
switch ($sql) {
case "insert":
sql_insert();
break;
case "update":
sql_update();
break;
}
switch ($a) {
case "add":
addrec();
break;
case "edit":
editrec($recid);
break;
default:
select();
break;
}
if (isset($order)) $_SESSION["order"] = $order;
if (isset($ordtype)) $_SESSION["type"] = $ordtype;
mysql_close($conn);
?>
<table class="bd" width="100%"><tr><td class="hr"></td></tr></table>
</body>
</html>
<?
}
?>
<? function select()
{
global $a;
global $showrecs;
global $page;
global $order;
global $ordtype;
if ($a == "reset") {
$order = "";
$ordtype = "";
}
if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }
$res = sql_select();
$count = mysql_numrows($res);
if ($count % $showrecs != 0) {
$pagecount = intval($count / $showrecs) + 1;
}
else {
$pagecount = intval($count / $showrecs);
}
$startrec = $showrecs * ($page - 1);
if ($startrec < $count) {mysql_data_seek($res, $startrec);}
$reccount = min($showrecs * $page, $count);
$fields = array(
"BreakID" => "ID",
"Break" => "Break",
"BreakShortName" => "Short Name",
"SortOrder" => "Sort Order",
"OrderCloseTime" => "Order Close-off Time",
"Minutes" => "Duration");
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Records shown <? echo $startrec + 1 ?> - <? echo $reccount ?> of <? echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<? showpagenav($page, $pagecount,$order,$ordtype); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<?
reset($fields);
foreach($fields as $val => $caption) {
?>
<td class="hr"><a class="hr" href="break.php?order=<? echo $val ?>&type=<? echo $ordtypestr ?>"><? echo htmlspecialchars($caption) ?></a></td>
<? } ?>
<td class="hr"> </td>
</tr>
<?
for ($i = $startrec; $i < $reccount; $i++)
{
$row = mysql_fetch_assoc($res);
$style = "dr";
if ($i % 2 != 0) {
$style = "sr";
}
?>
<tr>
<?
reset($fields);
foreach($fields as $val => $caption) {
?>
<td class="<? echo $style; ?>"><?
if ($caption=="Order Close-off Time")
{
list($CloseDate,$CloseTime)=explode(" ",$row["OrderCloseTime"]);
echo htmlspecialchars($CloseTime);
}else{
echo htmlspecialchars($row[$val]);
}
echo "</td>";
}
?>
<td class="<? echo $style ?>"><a href="break.php?a=edit&recid=<? echo $i ?>&order=<? echo $order ?>&type=<? echo $ordtype ?>">Edit</a></td>
</tr>
<?
}
mysql_free_result($res);
?>
</table>
<br>
<? } ?>
<? function showroweditor($row)
{
global $conn;
list($CloseDate,$CloseTime)=explode(" ",$row["OrderCloseTime"]);
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><? echo htmlspecialchars("ID")." " ?></td>
<td class="dr"><input type="text" name="BreakID" value="<? echo str_replace('"', '"', trim($row["BreakID"])) ?>"></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("Break")." " ?></td>
<td class="dr"><input type="text" name="Break" maxlength="50" value="<? echo str_replace('"', '"', trim($row["Break"])) ?>"></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("Short Name")." " ?></td>
<td class="dr"><input type="text" name="BreakShortName" maxlength="5" value="<? echo str_replace('"', '"', trim($row["BreakShortName"])) ?>"></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("Sort Order")." " ?></td>
<td class="dr"><input type="text" name="SortOrder" value="<? echo str_replace('"', '"', trim($row["SortOrder"])) ?>"></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("Order Close-off Time")." " ?></td>
<td class="dr"><input type="text" name="OrderCloseTime" value="<? echo str_replace('"', '"', trim($CloseTime)) ?>"></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("Duration")." " ?></td>
<td class="dr"><input type="text" name="Minutes" value="<? echo str_replace('"', '"', trim($row["Minutes"])) ?>"></td>
</tr>
</table>
<input type="hidden" name="order" value="<? echo $_GET["order"] ?>">
<input type="hidden" name="type" value="<? echo $_GET["type"] ?>">
<? } ?>
<? function showpagenav($page, $pagecount,$order,$ordtype)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="break.php?a=add&order=<? echo $order ?>&type=<? echo $ordtype ?>">Add Record</a> </td>
<? if ($page > 1) { ?>
<td><a href="break.php?page=<? echo $page - 1 ?>&order=<? echo $order ?>&type=<? echo $ordtype ?>"><< Prev</a> </td>
<? } ?>
<?
global $pagerange;
if ($pagecount > 1) {
if ($pagecount % $pagerange != 0) {
$rangecount = intval($pagecount / $pagerange) + 1;
}
else {
$rangecount = intval($pagecount / $pagerange);
}
for ($i = 1; $i < $rangecount + 1; $i++) {
$startpage = (($i - 1) * $pagerange) + 1;
$count = min($i * $pagerange, $pagecount);
if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
for ($j = $startpage; $j < $count + 1; $j++) {
if ($j == $page) {
?>
<td><b><? echo $j ?></b></td>
<? } else { ?>
<td><a href="break.php?page=<? echo $j ?>&order=<? echo $order ?>&type=<? echo $ordtype ?>"><? echo $j ?></a></td>
<? } } } else { ?>
<td><a href="break.php?page=<? echo $startpage ?>&order=<? echo $order ?>&type=<? echo $ordtype ?>"><? echo $startpage ."..." .$count ?></a></td>
<? } } } ?>
<? if ($page < $pagecount) { ?>
<td> <a href="break.php?page=<? echo $page + 1 ?>&order=<? echo $order ?>&type=<? echo $ordtype ?>">Next >></a> </td>
<? } ?>
</tr>
</table>
<? } ?>
<? function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="break.php?order=<? echo $_GET["order"] ?>&type=<? echo $_GET["type"] ?>">Index Page</a></td>
<? if ($recid > 0) { ?>
<td><a href="break.php?a=<? echo $a ?>&recid=<? echo $recid - 1 ?>&order=<? echo $_GET["order"] ?>&type=<? echo $_GET["type"] ?>">Prior Record</a></td>
<? } if ($recid < $count) { ?>
<td><a href="break.php?a=<? echo $a ?>&recid=<? echo $recid + 1 ?>&order=<? echo $_GET["order"] ?>&type=<? echo $_GET["type"] ?>">Next Record</a></td>
<? } ?>
</tr>
</table>
<hr size="1" noshade>
<? } ?>
<? function addrec()
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="break.php">Index Page</a></td>
</tr>
</table>
<hr size="1" noshade>
<form action="break.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?
$row = array(
"BreakID" => "",
"Break" => "",
"BreakShortName" => "",
"SortOrder" => "",
"OrderCloseTime" => "",
"Minutes" => "");
showroweditor($row)
?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<? } ?>
<? function editrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("edit", $recid, $count);
?>
<br>
<form action="break.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xBreakID" value="<? echo $row["BreakID"] ?>">
<? showroweditor($row) ?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?
session_start();mysql_free_result($res);
include("../include/constants.php");
} ?>
<? function connect()
{
$conn = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
mysql_select_db(DB_NAME);
return $conn;
}
function sqlvalue($val, $quote)
{
if ($quote)
$tmp = sqlstr($val);
else
$tmp = $val;
if ($tmp == "")
$tmp = "NULL";
elseif ($quote)
$tmp = "'".$tmp."'";
return $tmp;
}
function sqlstr($val)
{
return str_replace("'", "''", $val);
}
function sql_select()
{
global $conn;
global $order;
global $ordtype;
$sql = "select `BreakID`, `Break`, `BreakShortName`, `SortOrder`, `OrderCloseTime`, `Minutes`, `~SiteID\$` from `break` where `~SiteID\$`=".$_SESSION['SiteID'];
if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
$res = mysql_query($sql, $conn) or die(mysql_error());
return $res;
}
function sql_getrecordcount()
{
global $conn;
global $order;
global $ordtype;
$sql = "select count(*) from `break` where `~SiteID\$`=".$_SESSION['SiteID'];
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res);
reset($row);
return current($row);
}
function sql_insert()
{
global $conn;
global $_POST;
$sql = "insert into `break` (`Break`, `BreakShortName`, `SortOrder`, `OrderCloseTime`, `Minutes`, `~SiteID\$`) values (".sqlvalue(@$_POST["Break"], true) .", " .sqlvalue(@$_POST["BreakShortName"], true) .", " .sqlvalue(@$_POST["SortOrder"], false) .", " .sqlvalue("1899-12-30 ".@$_POST["OrderCloseTime"], true) .", " .sqlvalue(@$_POST["Minutes"], false) .", " .sqlvalue($_SESSION['SiteID'], false) .")";
mysql_query($sql, $conn) or die(mysql_error());
}
function sql_update()
{
global $conn;
global $_POST;
$sql = "update `break` set `Break`=" .sqlvalue(@$_POST["Break"], true) .", `BreakShortName`=" .sqlvalue(@$_POST["BreakShortName"], true) .", `SortOrder`=" .sqlvalue(@$_POST["SortOrder"], false) .", `OrderCloseTime`=" .sqlvalue("1899-12-30 ".@$_POST["OrderCloseTime"], true) .", `Minutes`=" .sqlvalue(@$_POST["Minutes"], false) .", `~SiteID\$`=" .sqlvalue($_SESSION['SiteID'], false) ." where " ."(`BreakID`=" .sqlvalue(@$_POST["xBreakID"], false) .")";
mysql_query($sql, $conn) or die(mysql_error());
}
?>