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; }
function getID_code($str) { global $MySQL_singleton_abort; MySQL_buildonemanykey('ActionCode', $str); $query = 'SELECT ActionID FROM Actions WHERE ActionCode = ' . MySQL_quote($str); $val = MySQL_singleton($query); if ($val != $MySQL_singleton_abort) { return $val; } else { die('Unknown Action Code'); } }
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 == $MySQL_singleton_abort) { echo 'Item unknown'; $bad = true; } $uid = MySQL_singleton('SELECT UserID FROM Users WHERE UserBarcode = ' . MySQL_quote($usercode)); if ($uid == $MySQL_singleton_abort) { echo 'User unknown'; $bad = true; } $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; } 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);"); $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'; } }
<?php /* $Id: delete.php,v 1.2 2003/06/22 23:07:07 robbat2 Exp $ */ /* $Source: /code/convert/cvsroot/infrastructure/rats/delete.php,v $ */ include './header.inc.php'; $perm = v('perm', 'del'); include 'lib/commontable.inc.php'; if ($tablePerm[$perm]) { $idDel = v('id'); $tableDel = v('table'); $query = 'DELETE FROM ' . $tableName . ' WHERE ' . $tableData[$tableName]['_idkey'] . '=' . MySQL_quote($idDel); echo $query; $m = _MySQL_queryhelper($query); $m->checkerror(); $_SESSION['msg'] = 'Item deleted from ' . $tableName; if (!dodbg()) { httpredirect('view.php?table=' . $tableName); } } /* vim: set ft=php expandtab shiftwidth=4 softtabstop=4 tabstop=4: */
if ($wherecol != '' && $wherefunc != '') { if ($wherecurrent != '') { $newwhere = $wherecurrent . ' AND '; } else { $newwhere = ''; } $s = ''; switch ($wherefunc) { case 'substring': $s = $tableName . '.' . $wherecol . ' LIKE ' . MySQL_quote('%' . $wheredata . '%'); break; case 'sqlregex': $s = $tableName . '.' . $wherecol . ' LIKE ' . MySQL_quote($wheredata); break; case 'gnuregex': $s = $tableName . '.' . $wherecol . ' REGEX ' . MySQL_quote($wheredata); break; } $newwhere .= $s; } else { $newwhere = $wherecurrent; } if ($newwhere != '') { $where = ' WHERE ' . $newwhere; } else { $where = ''; } $query = $tableData[$tableName]['_view_sql_final'] . $where . $orderby; if (dodbg(2)) { echo "Query: " . $query; }
function update($GroupID, $GroupName) { $query = 'UPDATE Groups SET GroupName=' . MySQL_quote($GroupName) . ' WHERE GroupID=' . MySQL_quote($GroupID) . ''; }
function MySQL_arrayToSequence($arr, $brackets = TRUE, $escape = TRUE, $order = NULL) { $size = count($arr); $s = ''; if ($size > 0) { if ($brackets) { $s .= '('; } for ($i = 0; $i < $size; $i++) { if ($order !== NULL) { $key = $order[$i]; } else { $key = $i; } if ($escape) { $s .= MySQL_quote($arr[$key]); } else { $s .= $arr[$key]; } if ($i + 1 < $size) { $s .= ','; } } if ($brackets) { $s .= ')'; } } return $s; }
include './header.inc.php'; $perm = v('perm', 'add'); include 'lib/commontable.inc.php'; if ($tablePerm[$perm]) { ?> <form action="submit.php" method="POST" class="dataform"> <?php $editData = NULL; if ($perm == 'edit') { $idEdit = v('id'); $tableEdit = v('table'); $cols = MySQL_arrayToSequence($tableData[$tableName]['_view_cols'], FALSE, FALSE); if (empty($tableData[$tableName]['_idkey'])) { die("Trying to edit a table {$tableName} without any ID key!\n"); } $query = $tableData[$tableName]['_view_sql_all'] . ' WHERE ' . $tableData[$tableName]['_idkey'] . '=' . MySQL_quote($idEdit); if (dodbg()) { echo 'Query: ' . $query . "<br />\n"; } global $MySQL_singleton_abort; $editData = MySQL_singletonassoc($query); if ($editData === $MySQL_singleton_abort) { die("Data abort! Query: {$query}\n"); } echo hiddeninput(fieldName($tableName, $tableData[$tableName]['_idkey']), $idEdit); } echo hiddeninput('table', $tableName); echo hiddeninput('perm', $perm); echo "\n"; ?> <table class="dataform">
} $oldEditData[$dk] = ereg_replace($regexsearch, $regexreplace, $oldEditData[$dk]); $dataEdit[$dk] = ereg_replace($regexsearch, $regexreplace, $dataEdit[$dk]); if (dodbg(4)) { echo 'Fixed ' . $dk . " = " . $oldEditData[$dk] . "<br />\n"; } } unset($datekeys, $dk, $arrkeys); foreach ($dataEdit as $dataKey_key => $dataKey_value) { // skip old data if (dodbg(4)) { echo 'OLD: ' . $oldEditData[$dataKey_key] . "<br />\n"; echo 'NEW: ' . $dataKey_value . "<br />\n"; } if ($oldEditData[$dataKey_key] !== $dataKey_value) { $changequery .= ($first ? '' : ', ') . $dataKey_key . '=' . MySQL_quote($dataKey_value); if ($first) { $first = FALSE; } } } // build query $query = 'UPDATE ' . $tableName . ' SET ' . $changequery . ' WHERE ' . $tableData[$tableName]['_idkey'] . '=' . $idEdit; if (dodbg()) { echo 'Query: ' . $query . "<br />\n"; } if (empty($changequery)) { $_SESSION['msg'] = 'No changes made in data'; } else { $_SESSION['msg'] = 'Changes in ' . $tableName . ' processed.'; $res = _MySQL_queryhelper($query);