Fifth pass at adding key files

This commit is contained in:
dsainty
2024-06-17 22:42:14 +10:00
parent 67ccdbcc34
commit 9797a6824a
535 changed files with 95045 additions and 0 deletions

View File

@ -0,0 +1,226 @@
<?php
include_once ('Database.php');
class Brand
{
public function __construct ($item = array ())
{
foreach ($item as $k => $v)
{
$this->{$k} = mysql_real_escape_string ($v);
}
}
}
class BrandService extends Database
{
var $tablename = "brand";
var $connection;
public function __construct ($tablename="")
{
if (! empty($tablename))
$this->tablename = $tablename;
$this->connection = mysqli_connect (
$this->server, $this->username, $this->password, $this->databasename
);
$this->throwExceptionOnError ($this->connection);
}
public function getAllBrands ($updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename";
else
$query = "SELECT * FROM $this->tablename WHERE approved=1 ORDER BY name ASC";
$stmt = mysqli_prepare ($this->connection, $query);
$this->throwExceptionOnError ();
mysqli_stmt_execute ($stmt);
$this->throwExceptionOnError ();
$rows = array ();
mysqli_stmt_bind_result ($stmt, $row->id, $row->name, $row->website, $row->approved, $row->user_id);
while (mysqli_stmt_fetch ($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result ($stmt, $row->id, $row->name, $row->website, $row->approved, $row->user_id);
}
mysqli_stmt_free_result ($stmt);
mysqli_close ($this->connection);
return $rows;
}
public function getBrandByName ($name)
{
$stmt = mysqli_prepare ($this->connection, "SELECT * FROM $this->tablename where name like ?");
$this->throwExceptionOnError ();
mysqli_stmt_bind_param ($stmt, 's', $name);
$this->throwExceptionOnError ();
mysqli_stmt_execute ($stmt);
$this->throwExceptionOnError ();
mysqli_stmt_bind_result ($stmt, $row->id, $row->name, $row->website, $row->approved, $row->user_id);
if (mysqli_stmt_fetch ($stmt))
{
return $row;
}
else
{
return null;
}
}
public function getBrandByID ($itemID)
{
$stmt = mysqli_prepare ($this->connection, "SELECT * FROM $this->tablename where id=?");
$this->throwExceptionOnError ();
mysqli_stmt_bind_param ($stmt, 'i', $itemID);
$this->throwExceptionOnError ();
mysqli_stmt_execute ($stmt);
$this->throwExceptionOnError ();
mysqli_stmt_bind_result ($stmt, $row->id, $row->name, $row->website, $row->approved, $row->user_id);
if (mysqli_stmt_fetch ($stmt))
{
return $row;
}
else
{
return null;
}
}
public function createBrand ($item)
{
$stmt = mysqli_prepare ($this->connection, "INSERT INTO $this->tablename (name, website, approved, user_id) VALUES (?, ?, ?, ?)");
$this->throwExceptionOnError ();
mysqli_stmt_bind_param ($stmt, 'ssii', $item->name, $item->website, $item->approved, $item->user_id);
$this->throwExceptionOnError ();
mysqli_stmt_execute ($stmt);
$this->throwExceptionOnError ();
$autoid = mysqli_stmt_insert_id ($stmt);
mysqli_stmt_free_result ($stmt);
mysqli_close ($this->connection);
return $autoid;
}
public function updateBrand ($item)
{
$stmt = mysqli_prepare ($this->connection, "UPDATE $this->tablename SET name=?, website=?, approved=?, user_id=? WHERE id=?");
$this->throwExceptionOnError ();
mysqli_stmt_bind_param ($stmt, 'ssiii', $item->name, $item->website, $item->approved, $item->user_id, $item->id);
$this->throwExceptionOnError ();
mysqli_stmt_execute ($stmt);
$this->throwExceptionOnError ();
mysqli_stmt_free_result ($stmt);
mysqli_close ($this->connection);
}
public function deleteBrand ($itemID)
{
$stmt = mysqli_prepare ($this->connection, "DELETE FROM $this->tablename WHERE id = ?");
$this->throwExceptionOnError ();
mysqli_stmt_bind_param ($stmt, 'i', $itemID);
mysqli_stmt_execute ($stmt);
$this->throwExceptionOnError ();
mysqli_stmt_free_result ($stmt);
mysqli_close ($this->connection);
}
public function count ()
{
$stmt = mysqli_prepare ($this->connection, "SELECT COUNT(*) AS COUNT FROM $this->tablename");
$this->throwExceptionOnError ();
mysqli_stmt_execute ($stmt);
$this->throwExceptionOnError ();
mysqli_stmt_bind_result ($stmt, $rec_count);
$this->throwExceptionOnError ();
mysqli_stmt_fetch ($stmt);
$this->throwExceptionOnError ();
mysqli_stmt_free_result ($stmt);
mysqli_close ($this->connection);
return $rec_count;
}
public function getBrand_paged ($startIndex, $numItems)
{
$stmt = mysqli_prepare ($this->connection, "SELECT * FROM $this->tablename LIMIT ?, ?");
$this->throwExceptionOnError ();
mysqli_stmt_bind_param ($stmt, 'ii', $startIndex, $numItems);
mysqli_stmt_execute ($stmt);
$this->throwExceptionOnError ();
$rows = array ();
mysqli_stmt_bind_result ($stmt, $row->id, $row->name, $row->website, $row->approved, $row->user_id);
while (mysqli_stmt_fetch ($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result ($stmt, $row->id, $row->name, $row->website, $row->approved, $row->user_id);
}
mysqli_stmt_free_result ($stmt);
mysqli_close ($this->connection);
return $rows;
}
private function throwExceptionOnError ($link = null)
{
if ($link == null)
{
$link = $this->connection;
}
if (mysqli_error ($link))
{
$msg = mysqli_errno ($link) . ": " . mysqli_error ($link);
throw new Exception ('MySQL Error - ' . $msg);
}
}
}
?>

View File

@ -0,0 +1,38 @@
<?php
/*
$user = "stackreach";
$pass = "aephie0uKeeZ";
$host = "localhost";
$port = "";
$dbname = "slowtwitch_stackreach";
abstract class Database
{
protected $username = "stackreach";
protected $password = "aephie0uKeeZ";
protected $server = "localhost";
protected $port = "";
protected $databasename = "slowtwitch_stackreach";
}
*/
$user = "stackreach";
$pass = "aephie0uKeeZ";
$host = "192.168.1.10";
$port = "";
$dbname = "stackreach";
abstract class Database
{
protected $username = "stackreach";
protected $password = "aephie0uKeeZ";
protected $server = "192.168.1.10";
protected $port = "";
protected $databasename = "stackreach";
}
?>

View File

@ -0,0 +1,382 @@
<?php
include_once ('Database.php');
class Frame {
public function __construct($item = array()) {
foreach ($item as $k => $v) {
$this->{$k} = mysql_real_escape_string($v);
}
}
}
function ensure_digits($test, $len, &$values, &$errors)
{
if (strlen($values[$test]) !== $len OR !ctype_digit($values[$test]))
{
$errors[$test] = "$test needs to be a $len digit number";
return false;
}
return true;
}
function ensure_range($test, $max, $min, &$values, &$errors)
{
if (strlen($values[$test]) > $max OR strlen($values[$test]) < $min OR !ctype_digit($values[$test]))
{
$errors[$test] = "$test needs to be a $min to $max digit number";
return false;
}
return true;
}
function VerifyFrame(&$values, &$errors)
{
$ret = true;
if (!ensure_digits('stack', 3, $values, $errors))
$ret = false;
if (!ensure_digits('reach', 3, $values, $errors))
$ret = false;
if (!ensure_digits('trail', 2, $values, $errors))
$ret = false;
if (!ensure_digits('front_center', 3, $values, $errors))
$ret = false;
if (!ensure_range('head_tube', 3, 2, $values, $errors))
$ret = false;
if (!ensure_digits('sta_min', 2, $values, $errors))
$ret = false;
if (isset($values['sta_max']))
{
if (!ensure_digits('sta_max', 2, $values, $errors))
$ret = false;
}
return $ret;
}
class FrameService extends Database
{
var $tablename = "frame";
var $editstablename = "frame_edits";
var $connection;
public function __construct($tablename="")
{
if (! empty($tablename))
$this->tablename = $tablename;
$this->connection = mysqli_connect(
$this->server,
$this->username,
$this->password,
$this->databasename
);
$this->throwExceptionOnError($this->connection);
}
public function getAllFrames($updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename";
else
$query = "SELECT * FROM $this->tablename WHERE approved=1";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getAllFramesOrdered($updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename where approved=1 ORDER BY brand_id, geometry_id, is_650 DESC, reach";
else
$query = "SELECT * FROM $this->tablename ORDER BY brand_id, geometry_id, is_650 DESC, reach";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getAllFramesByBrand($brand, $updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename where brand_id=? ORDER BY geometry_id, is_650 DESC, reach";
else
$query = "SELECT * FROM $this->tablename where brand_id=? and approved=1 ORDER BY geometry_id, is_650 DESC, reach";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $brand);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getAllFramesByGeometry($geo, $updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename where geometry_id=? ORDER BY is_650 DESC, reach";
else
$query = "SELECT * FROM $this->tablename where geometry_id=? AND approved=1 ORDER BY is_650 DESC, reach";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $geo);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getFrameByID($itemID)
{
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where id=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
if (mysqli_stmt_fetch($stmt))
{
return $row;
}
else
{
return null;
}
}
public function createFrame($item)
{
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (brand_id, geometry_id, size_name, stack, reach, trail, front_center, head_tube, internal_headset, sta_min, sta_max, is_650, approved, user_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'iisiiiiiiiiiii',
$item->brand_id,
$item->geometry_id,
$item->size_name,
$item->stack,
$item->reach,
$item->trail,
$item->front_center,
$item->head_tube,
$item->internal_headset,
$item->sta_min,
$item->sta_max,
$item->is_650,
$item->approved,
$item->user_id);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
public function updateFrame($item)
{
$stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET brand_id=?, geometry_id=?, size_name=?, stack=?, reach=?, trail=?, front_center=?, head_tube=?, internal_headset=?, sta_min=?, sta_max=?, is_650=?, approved=?, user_id=? WHERE id=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'iisiiiiiiiiiiii',
$item->brand_id,
$item->geometry_id,
$item->size_name,
$item->stack,
$item->reach,
$item->trail,
$item->front_center,
$item->head_tube,
$item->internal_headset,
$item->sta_min,
$item->sta_max,
$item->is_650,
$item->approved,
$item->user_id,
$item->id);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
public function deleteFrame($itemID)
{
$stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE id = ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
public function count()
{
$stmt = mysqli_prepare($this->connection, "SELECT COUNT(*) AS COUNT FROM $this->tablename");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $rec_count);
$this->throwExceptionOnError();
mysqli_stmt_fetch($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rec_count;
}
public function getFrame_paged($startIndex, $numItems)
{
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename LIMIT ?, ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ii', $startIndex, $numItems);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->size_name, $row->stack, $row->reach, $row->trail, $row->front_center, $row->head_tube, $row->internal_headset, $row->sta_min, $row->sta_max, $row->is_650, $row->approved, $row->user_id);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
private function throwExceptionOnError($link = null)
{
if ($link == null)
{
$link = $this->connection;
}
if (mysqli_error($link))
{
$msg = mysqli_errno($link) . ": " . mysqli_error($link);
throw new Exception('MySQL Error - ' . $msg);
}
}
}
?>

View File

@ -0,0 +1,304 @@
<?php
include_once ('Database.php');
class Geometry {
public function __construct($item = array()) {
foreach ($item as $k => $v) {
$this->{$k} = mysql_real_escape_string($v);
}
}
}
class GeometryService extends Database
{
var $tablename = "geometry";
var $connection;
public function __construct($tablename="")
{
if (! empty($tablename))
$this->tablename = $tablename;
$this->connection = mysqli_connect(
$this->server,
$this->username,
$this->password,
$this->databasename
);
$this->throwExceptionOnError($this->connection);
}
public function getAllGeometries($updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename";
else
$query = "SELECT * FROM $this->tablename WHERE approved=1";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name, $row->approved, $row->user_id, $row->is_road);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name, $row->approved, $row->user_id, $row->is_road);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getAllGeometriesByBrand($brand, $updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename where brand_id=?";
else
$query = "SELECT * FROM $this->tablename where brand_id=? AND approved=1";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $brand);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name, $row->approved, $row->user_id, $row->is_road);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name, $row->approved, $row->user_id, $row->is_road);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getAllTriGeometriesByBrand($brand, $updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename where brand_id=? AND is_road IS NOT TRUE";
else
$query = "SELECT * FROM $this->tablename where brand_id=? AND approved=1 AND is_road IS NOT TRUE";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $brand);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name, $row->approved, $row->user_id, $row->is_road);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name, $row->approved, $row->user_id, $row->is_road);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getAllRoadGeometriesByBrand($brand, $updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename where brand_id=? AND is_road IS NOT FALSE";
else
$query = "SELECT * FROM $this->tablename where brand_id=? AND approved=1 AND is_road IS NOT FALSE";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $brand);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name, $row->approved, $row->user_id, $row->is_road);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name, $row->approved, $row->user_id, $row->is_road);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getGeometryByID($itemID)
{
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where id=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name, $row->approved, $row->user_id, $row->is_road);
if (mysqli_stmt_fetch($stmt))
{
return $row;
}
else
{
return null;
}
}
public function createGeometry($item)
{
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (brand_id, name, approved, user_id, is_road) VALUES (?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'isiii', $item->brand_id, $item->name, $row->approved, $row->user_id, $row->is_road);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
public function updateGeometry($item)
{
$stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET brand_id=?, name=?, approved=?, user_id=?, is_road=? WHERE id=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'isiiii', $item->brand_id, $item->name, $item->approved, $item->user_id, $item->is_road, $item->id);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
public function deleteGeometry($itemID)
{
$stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE id = ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
public function count()
{
$stmt = mysqli_prepare($this->connection, "SELECT COUNT(*) AS COUNT FROM $this->tablename");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $rec_count);
$this->throwExceptionOnError();
mysqli_stmt_fetch($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rec_count;
}
public function getGeometry_paged($startIndex, $numItems)
{
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename LIMIT ?, ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ii', $startIndex, $numItems);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->name);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
private function throwExceptionOnError($link = null)
{
if ($link == null)
{
$link = $this->connection;
}
if (mysqli_error($link))
{
$msg = mysqli_errno($link) . ": " . mysqli_error($link);
throw new Exception('MySQL Error - ' . $msg);
}
}
}
?>

View File

@ -0,0 +1,269 @@
<?php
include_once ('Database.php');
class Model {
public function __construct($item = array()) {
foreach ($item as $k => $v) {
$this->{$k} = mysql_real_escape_string($v);
}
}
}
class ModelService extends Database
{
var $tablename = "model";
var $connection;
public function __construct($tablename="")
{
if (! empty($tablename))
$this->tablename = $tablename;
$this->connection = mysqli_connect(
$this->server,
$this->username,
$this->password,
$this->databasename
);
$this->throwExceptionOnError($this->connection);
}
public function getAllModels($updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename";
else
$query = "SELECT * FROM $this->tablename WHERE approved=1";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->name, $row->notes, $row->approved, $row->user_id);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->name, $row->notes, $row->approved, $row->user_id);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getAllModelsByBrand($brand, $updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename where brand_id=?";
else
$query = "SELECT * FROM $this->tablename where brand_id=? AND approved=1";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $brand);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->name, $row->notes, $row->approved, $row->user_id);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->name, $row->notes, $row->approved, $row->user_id);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getAllModelsByGeometry($geo, $updater = false)
{
if ($updater)
$query = "SELECT * FROM $this->tablename where geometry_id=?";
else
$query = "SELECT * FROM $this->tablename where geometry_id=? and approved=1";
$stmt = mysqli_prepare($this->connection, $query);
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $geo);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->name, $row->notes, $row->approved, $row->user_id);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->name, $row->notes, $row->approved, $row->user_id);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getModelByID($itemID)
{
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where id=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->name, $row->notes, $row->approved, $row->user_id);
if (mysqli_stmt_fetch($stmt))
{
return $row;
}
else
{
return null;
}
}
public function createModel($item)
{
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (brand_id, geometry_id, name, notes, approved, user_id) VALUES (?, ?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'iissii', $item->brand_id, $item->geometry_id, $item->name, $item->notes, $item->approved, $item->user_id);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
public function updateModel($item)
{
$stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET brand_id=?, geometry_id=?, name=?, notes=?, approved=?, user_id=? WHERE id=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'iissiii', $item->brand_id, $item->geometry_id, $item->name, $item->notes, $item->approved, $item->user_id, $item->id);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
public function deleteModel($itemID)
{
$stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE id = ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
public function count()
{
$stmt = mysqli_prepare($this->connection, "SELECT COUNT(*) AS COUNT FROM $this->tablename");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $rec_count);
$this->throwExceptionOnError();
mysqli_stmt_fetch($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rec_count;
}
public function getModel_paged($startIndex, $numItems)
{
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename LIMIT ?, ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ii', $startIndex, $numItems);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->name, $row->notes, $row->approved, $row->user_id);
while (mysqli_stmt_fetch($stmt))
{
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->brand_id, $row->geometry_id, $row->name, $row->notes, $row->approved, $row->user_id);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
private function throwExceptionOnError($link = null)
{
if ($link == null)
{
$link = $this->connection;
}
if (mysqli_error($link))
{
$msg = mysqli_errno($link) . ": " . mysqli_error($link);
throw new Exception('MySQL Error - ' . $msg);
}
}
}
?>