Skip to content

Commit

Permalink
Updated ver
Browse files Browse the repository at this point in the history
  • Loading branch information
robbat2 committed May 7, 2003
1 parent bba9d65 commit f93fbcb
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 72 deletions.
4 changes: 2 additions & 2 deletions insert.php → addedit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* $Id: insert.php,v 1.3 2003/04/29 20:47:53 robbat2 Exp $ */
/* $Source: /code/convert/cvsroot/infrastructure/rats/Attic/insert.php,v $ */
/* $Id: addedit.php,v 1.1 2003/05/07 19:57:20 robbat2 Exp $ */
/* $Source: /code/convert/cvsroot/infrastructure/rats/addedit.php,v $ */

include './header.inc.php';

Expand Down
10 changes: 5 additions & 5 deletions gui/array.lib.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
//foo
function
v($n)
v($n,$default=null)
{
$data = getData();
if (isset($data[$n])) {
$v = $data[$n];
} else {
$v = null;
}
if ($v == 'on') {
if ($v == 'on') {
$v = true;
}
} else {
$v = $default;
}
return $v;
}
Expand Down
14 changes: 9 additions & 5 deletions gui/html.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,17 @@ function
}

function
html_simpleselect($name,
$data)
selectinput($name,
$data,$default='')
{
//format is 'value' => 'text'
$activevalue = v($name);
$innerdata = "";
foreach($data as $value => $text) {
if($default == '') {
$activevalue = v($name);
} else {
$activevalue = $default;
}
$innerdata = '';
foreach($data as $value => $text) {
$innerdata .=
htmlElm('option',
array('value' => $value, 'selected' =>($activevalue == $value ? 'selected' : '')),
Expand Down
17 changes: 15 additions & 2 deletions gui/login.inc.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/* $Id: login.inc.php,v 1.3 2003/05/06 21:53:15 robbat2 Exp $ */
/* $Id: login.inc.php,v 1.4 2003/05/07 19:57:20 robbat2 Exp $ */
/* $Source: /code/convert/cvsroot/infrastructure/rats/gui/login.inc.php,v $ */
?>
<form action="main.php" method="POST" class="title">
<form action="validate.php" method="POST" class="title">
<table class="title">
<tr><td>
<label for="username">Username</label>
Expand All @@ -24,13 +24,26 @@
?>
</td>
</tr>

<tr>
<td>
<label for="mode">Mode</label>
</td>
<td>
<?php
echo selectinput('mode',array('normal'=>'Normal','kiosk'=>'Kiosk'),'normal');
?>
</td>
</tr>

<tr>
<td colspan="2">
<?php
echo submitinput('login','Login');
?>
</td>
</tr>

</table>
</form>
<?php
Expand Down
6 changes: 4 additions & 2 deletions header.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* $Id: header.inc.php,v 1.7 2003/04/29 20:47:53 robbat2 Exp $ */
/* $Id: header.inc.php,v 1.8 2003/05/07 19:57:20 robbat2 Exp $ */
error_reporting(E_ALL);
include 'include.php';
include './gui/header.inc.php';
Expand All @@ -13,11 +13,13 @@
$uservalid = admin_validate();
if(!$uservalid) {
//possible hack or invalid password
header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/".'index.php'.'?loginerror=1');
//header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/".'index.php'.'?loginerror=1');
httpredirect('index.php','?loginerror=1');
//echo 'REDIRECT';
exit;
}
$validationskipped = FALSE;

}

?>
3 changes: 1 addition & 2 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
/* $Id: index.php,v 1.8 2003/03/13 11:53:45 robbat2 Exp $ */
/* $Id: index.php,v 1.9 2003/05/07 19:57:20 robbat2 Exp $ */
/* vim: set ft=php expandtab shiftwidth=4 softtabstop=4 tabstop=4: */

$skipvalidate = TRUE;

include 'header.inc.php';
include 'gui/title.inc.php';

include 'gui/login.inc.php';

if(isset($_GET['loginerror']) && $_GET['loginerror']) {
Expand Down
33 changes: 19 additions & 14 deletions kiosk.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php
/* $Id: kiosk.php,v 1.2 2003/03/13 09:38:32 robbat2 Exp $ */
/* $Id: kiosk.php,v 1.3 2003/05/07 19:57:20 robbat2 Exp $ */
/* vim: set ft=php expandtab shiftwidth=4 softtabstop=4 tabstop=4: */
//find -xtype f -name '*php' |grep -v index |grep -v DObj |xargs -l1 echo include

include 'include.php';
include('header.inc.php');

/* $t = new Transactions();
$t->add(100,'Actions','1','1');
$t->add(101,'Users','2','2');
$s = $t->generateSQL();
echo $s;
*/
if(isset($_POST['text'])) {
Expand All @@ -19,21 +18,25 @@
if($m == 'checkin') {
foreach($arr as $line) {
$line = trim($line);
if(isObject($line)) {
$_CheckOuts->checkin($line);
} else {
echo 'Invalid barcode: '.$line.'<br />';
if($line != '') {
if(isObject($line)) {
$_CheckOuts->checkin($line);
} else {
echo 'Invalid barcode: "'.$line.'"<br />';
}
}
}
} else if($m == 'checkout') {
$user = trim(array_shift($arr));
if(isUser($user)) {
foreach($arr as $line) {
$line = trim($line);
if(isObject($line)) {
$_CheckOuts->checkout($user,$line);
} else {
echo 'Invalid barcode: '.$line.'<br />';
if($line != '') {
if(isObject($line)) {
$_CheckOuts->checkout($user,$line);
} else {
echo 'Invalid barcode: "'.$line.'"<br />';
}
}
}
} else {
Expand All @@ -43,9 +46,9 @@

}

echo html_a('logout.php','Logout','leftnavitem','target="_top"')."\n";
?>
<html>
<form action="index.php" method="post">
<form action="kiosk.php" method="POST">
<select name="mode">
<option value="checkout">CheckOut</option>
<option value="checkin">CheckIn</option>
Expand All @@ -54,4 +57,6 @@
</textarea><br />
<input type="submit" name="submit_run" value="Run!" />
</form>
</html>
<?php
include 'footer.inc.php';
?>
18 changes: 11 additions & 7 deletions lib/MySQL.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* $Id: MySQL.php,v 1.10 2003/05/01 22:20:32 robbat2 Exp $ */
/* $Id: MySQL.php,v 1.11 2003/05/07 19:57:20 robbat2 Exp $ */

//var $mysql_conn;

Expand Down Expand Up @@ -82,9 +82,9 @@ function execute() {
}

function checkerror() {
//if(mysql_errno() != 0) {
// die(mysql_error());
//}
if(mysql_errno() != 0) {
die(mysql_error());
}
}

function getNumRows() {
Expand All @@ -94,7 +94,7 @@ function getNumRows() {
return $num;
}
function _getNumRows() {
$num = mysql_num_rows($this->getResult());
$num = @mysql_num_rows($this->getResult());
$this->checkerror();
return $num;
}
Expand Down Expand Up @@ -219,15 +219,19 @@ function MySQL_escape($str) {
return mysql_real_escape_string($str);
}

function MySQL_arrayToSequence($arr,$brackets = TRUE) {
function MySQL_arrayToSequence($arr,$brackets = TRUE, $escape = TRUE) {
$size = count($arr);
$s = '';
if($size > 0) {
if($brackets) {
$s .= '(';
}
for($i = 0; $i < $size; $i++) {
$s .= MySQL_quote($arr[$i]);
if($escape) {
$s .= MySQL_quote($arr[$i]);
} else {
$s .= $arr[$i];
}
if($i+1 < $size) {
$s .= ',';
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Obj/Actions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* $Id: Actions.php,v 1.6 2003/04/29 20:47:53 robbat2 Exp $ */
/* $Id: Actions.php,v 1.7 2003/05/07 19:57:20 robbat2 Exp $ */
/**
* \brief Action handling system
*
Expand All @@ -11,9 +11,9 @@ function Actions() {
function getID_code($str) {
global $MySQL_singleton_abort;
MySQL_buildonemanykey('ActionCode',$str);
$query = 'SELECT ActionID,GenericTable FROM Actions WHERE ActionCode = '.MySQL_quote($str);
$query = 'SELECT ActionID FROM Actions WHERE ActionCode = '.MySQL_quote($str);
$val = MySQL_singleton($query);
if($val == $MySQL_singleton_abort) {
if($val != $MySQL_singleton_abort) {
return $val;
} else {
die ('Unknown Action Code');
Expand Down
42 changes: 21 additions & 21 deletions lib/Obj/CheckOuts.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* $Id: CheckOuts.php,v 1.6 2003/04/24 00:07:52 robbat2 Exp $ */
/* $Id: CheckOuts.php,v 1.7 2003/05/07 19:57:20 robbat2 Exp $ */
/**
* \brief Object CheckOuts
*
Expand All @@ -10,10 +10,11 @@ function CheckOuts() {
}

function checkin($barcode) {
global $MySQL_singleton_abort;
$query = 'SELECT CheckOutID FROM CheckOuts LEFT JOIN Objects USING (ObjectID) WHERE ObjectBarcode = '.MySQL_quote($barcode);
global $_MySQL_trans, $_Transactions;
$coid = MySQL_singleton($query);
if($coid == -1) {
if($coid == $MySQL_singleton_abort) {
echo('Item is not checked out');
} else {
$_MySQL_trans->start();
Expand All @@ -25,43 +26,42 @@ function checkin($barcode) {
}

function checkout($usercode,$barcode) {
global $MySQL_singleton_abort;
global $_MySQL_trans, $_Transactions;
$bad = false;
$oid = MySQL_singleton( 'SELECT ObjectID FROM Objects WHERE ObjectBarcode = '.MySQL_quote($barcode));
if($oid == -1) {
if($oid == $MySQL_singleton_abort) {
echo('Item unknown');
$bad = true;
}
$oid = MySQL_quote($oid);
$uid = MySQL_singleton( 'SELECT UserID FROM Users WHERE UserBarcode = '.MySQL_quote($usercode));
if($uid == -1) {
if($uid == $MySQL_singleton_abort) {
echo('User unknown');
$bad = true;
}
$coid = MySQL_singleton('SELECT CheckOutID FROM CheckOuts WHERE ObjectID='.$oid);
if($coid != 0) {
echo('Item is already out, checkin first');
$coid = MySQL_singleton('SELECT CheckOutID FROM CheckOuts WHERE ObjectID='.MySQL_quote($oid));
if($coid != $MySQL_singleton_abort) {
echo('Item is already out, checkin first ('.$coid.')');
$bad = true;
}
$uid = MySQL_quote($uid);
if(!$bad) {
$_MySQL_trans->start();
//$_MySQL_trans->run("SELECT @duration := ObjectTypeLoanDuration FROM Objects LEFT JOIN ObjectTypes USING (ObjectTypeID) WHERE ObjectID=".$oid);
//$_MySQL_trans->run("SELECT @year:=EXTRACT(YEAR FROM @duration), @month:=EXTRACT(MONTH FROM @duration), @day:=EXTRACT(DAY FROM @duration), @hour:=EXTRACT(HOUR FROM @duration), @minute:=EXTRACT(MINUTE FROM @duration), @second:=EXTRACT(SECOND FROM @duration)");
//$_MySQL_trans->run("SELECT @duration:=CONCAT(@year*365+@month*30+@day,SUBSTRING(@duration,LOCATE(' ',@duration)))");
// $_MySQL_trans->run("SELECT @duedate:=DATE_ADD(NOW(),INTERVAL @duration DAY_SECOND);");
$_MySQL_trans->run('SELECT @duedate:=(((((((NOW() + INTERVAL
EXTRACT(YEAR FROM ObjectTypeLoanDuration) YEAR) + INTERVAL
EXTRACT(MONTH FROM ObjectTypeLoanDuration) MONTH) + INTERVAL
EXTRACT(DAY FROM ObjectTypeLoanDuration) DAY) + INTERVAL
EXTRACT(HOUR FROM ObjectTypeLoanDuration) HOUR) + INTERVAL
EXTRACT(MINUTE FROM ObjectTypeLoanDuration) MINUTE) + INTERVAL
EXTRACT(SECOND FROM ObjectTypeLoanDuration) SECOND)) FROM Objects
LEFT JOIN ObjectTypes USING (ObjectTypeID) WHERE
ObjectID='.MySQL_quote($oid).';');

$_MySQL_trans->run('INSERT CheckOuts (UserID,ObjectID,CheckOutDueDate) VALUES '.MySQL_arrayToSequence(array($uid,$oid,'@duedate')));

$query1 = 'SELECT @duedate:=(((((((NOW() + INTERVAL EXTRACT(YEAR FROM
ObjectTypeLoanDuration) YEAR) + INTERVAL EXTRACT(MONTH FROM
ObjectTypeLoanDuration) MONTH) + INTERVAL EXTRACT(DAY FROM
ObjectTypeLoanDuration) DAY) + INTERVAL EXTRACT(HOUR FROM
ObjectTypeLoanDuration) HOUR) + INTERVAL EXTRACT(MINUTE FROM
ObjectTypeLoanDuration) MINUTE) + INTERVAL EXTRACT(SECOND FROM
ObjectTypeLoanDuration) SECOND)) FROM Objects LEFT JOIN ObjectTypes
USING (ObjectTypeID) WHERE ObjectID='.MySQL_quote($oid).';';
$query2 = 'INSERT CheckOuts (UserID,ObjectID,CheckOutDueDate) VALUES '.MySQL_arrayToSequence(array(MySQL_quote($uid),MySQL_quote($oid),'@duedate'),TRUE,FALSE);
$_MySQL_trans->run($query1);
$_MySQL_trans->run($query2);
$_MySQL_trans->run($_Transactions->singleton(0,'aC','LAST_INSERT_ID()'));
$_MySQL_trans->execute();
echo('Item now checked out');
Expand Down
8 changes: 7 additions & 1 deletion lib/Obj/Objects.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* $Id: Objects.php,v 1.3 2002/12/12 13:39:42 robbat2 Exp $ */
/* $Id: Objects.php,v 1.4 2003/05/07 19:57:20 robbat2 Exp $ */
/**
* \brief Object handling system
*
Expand All @@ -9,6 +9,12 @@ class Objects {
function Objects($newbarcode = -1) {
$this->barcode = $newbarcode;
}
function exists($barcode) {
global $MySQL_singleton_abort;
$query = 'SELECT ObjectID FROM Objects WHERE ObjectBarcode='.MySQL_quote($barcode);
$val = MySQL_singleton($query);
return $val != $MySQL_singleton_abort;
}
}

/* vim: set ft=php expandtab shiftwidth=4 softtabstop=4 tabstop=4: */
Expand Down
Loading

0 comments on commit f93fbcb

Please sign in to comment.