Fifth pass at adding key files
This commit is contained in:
77
site/stackreach/add_brand.php
Executable file
77
site/stackreach/add_brand.php
Executable file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/Database.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once'./libs/Smarty.class.php';
|
||||
|
||||
|
||||
if ( ! is_logged_in($user) ) {
|
||||
return header("location: $site_url");
|
||||
}
|
||||
|
||||
function DisplayForm($values, $errors)
|
||||
{
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('values', $values);
|
||||
$smarty->assign('errors', $errors);
|
||||
$smarty->display('views/add_brand.tpl');
|
||||
}
|
||||
|
||||
function VerifyForm(&$values, &$errors)
|
||||
{
|
||||
$ret = true;
|
||||
$url = htmlspecialchars($values['website']);
|
||||
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $url))
|
||||
{
|
||||
$errors["website"] = "Please check the website and resubmit";
|
||||
$ret = false;
|
||||
}
|
||||
if (strlen($values['name']) < 4)
|
||||
{
|
||||
$errors["name"] = "Please check the brand name and resubmit";
|
||||
$ret = false;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function ProcessForm($values)
|
||||
{
|
||||
$brand = new Brand($values);
|
||||
$brand->approved = 0;
|
||||
$brand->user_id = get_user_id();
|
||||
|
||||
$brandService = new BrandService();
|
||||
$brandService->createBrand($brand);
|
||||
|
||||
header('location:brands.php');
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
$formValues = $_POST;
|
||||
$formErrors = array();
|
||||
|
||||
try
|
||||
{
|
||||
if (!VerifyForm($formValues, $formErrors))
|
||||
DisplayForm($formValues, $formErrors);
|
||||
else
|
||||
ProcessForm($formValues);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
DisplayForm($formValues, $formErrors);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
DisplayForm(null, null);
|
||||
}
|
||||
|
||||
?>
|
97
site/stackreach/add_frame.php
Executable file
97
site/stackreach/add_frame.php
Executable file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
include_once 'config.php';
|
||||
include_once './models/services/FrameService.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
if ( ! is_logged_in($user) ) {
|
||||
return header("location: $site_url");
|
||||
}
|
||||
|
||||
function DisplayForm($values, $errors)
|
||||
{
|
||||
|
||||
$brandService = new BrandService();
|
||||
$brand = $brandService->getBrandByName($values['brand']);
|
||||
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllGeometriesByBrand($brand->id);
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('values', $values);
|
||||
$smarty->assign('errors', $errors);
|
||||
$smarty->assign('geometries', $geometries);
|
||||
$smarty->assign('brand', $brand);
|
||||
$smarty->display('views/add_frame.tpl');
|
||||
}
|
||||
|
||||
|
||||
function VerifyForm(&$values, &$errors)
|
||||
{
|
||||
return VerifyFrame($values, $errors);
|
||||
}
|
||||
|
||||
function ProcessForm($values)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
$frameService = new FrameService();
|
||||
$frame = new Frame($values);
|
||||
$frame->approved = 0;
|
||||
$frame->user_id = get_user_id();
|
||||
$frameService->createFrame($frame);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
header('location:frames.php');
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
$formValues = $_POST;
|
||||
$formErrors = array();
|
||||
|
||||
if (!isset($_POST['internal_headset']))
|
||||
$formValues['internal_headset'] = 0;
|
||||
else
|
||||
$formValues['internal_headset'] = 1;
|
||||
|
||||
if (!isset($_POST['is_650']))
|
||||
$formValues['is_650'] = 0;
|
||||
else
|
||||
$formValues['is_650'] = 1;
|
||||
|
||||
|
||||
if (!VerifyForm($formValues, $formErrors))
|
||||
DisplayForm($formValues, $formErrors);
|
||||
else
|
||||
ProcessForm($formValues);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (!isset($_SESSION['brand']))
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands();
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brands', $brands);
|
||||
$smarty->assign('action', "add_frame.php");
|
||||
$smarty->display('views/selectbrand.tpl');
|
||||
}
|
||||
else
|
||||
{
|
||||
$formValues['brand'] = $_SESSION['brand'];
|
||||
DisplayForm($formValues, null);
|
||||
}
|
||||
}
|
||||
?>
|
83
site/stackreach/add_geometry.php
Executable file
83
site/stackreach/add_geometry.php
Executable file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
include_once 'config.php';
|
||||
include_once './models/services/FrameService.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
if ( ! is_logged_in($user) ) {
|
||||
return header("location: $site_url");
|
||||
}
|
||||
|
||||
function DisplayForm ($values, $errors)
|
||||
{
|
||||
|
||||
// $brandService = new BrandService();
|
||||
// $brands = $brandService->getAllBrands();
|
||||
// if (count($brands) == 0)
|
||||
// {
|
||||
// header('location:add_brand.php');
|
||||
// return;
|
||||
// }
|
||||
|
||||
$smarty = new Smarty;
|
||||
// $smarty->assign('brands', $brands);
|
||||
$smarty->assign ('values', $values);
|
||||
$smarty->display ('views/add_geometry.tpl');
|
||||
}
|
||||
|
||||
function VerifyForm (&$values, $errors)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
function ProcessForm ($values)
|
||||
{
|
||||
$service = new BrandService();
|
||||
$brand = $service->getBrandByName ($values['brand']);
|
||||
$geometry = new Geometry ($values);
|
||||
$geometry->brand_id = $brand->id;
|
||||
$geometry->approved = 0;
|
||||
$geometry->user_id = get_user_id ();
|
||||
|
||||
$geometryService = new GeometryService();
|
||||
$geometryService->createGeometry ($geometry);
|
||||
header ('location:geometries.php');
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
$formValues = $_POST;
|
||||
$formErrors = array ();
|
||||
|
||||
if (isset ($_POST['is_road']))
|
||||
$formValues['is_road'] = 1;
|
||||
else
|
||||
$formValues['is_road'] = 0;
|
||||
|
||||
if (!VerifyForm ($formValues, $formErrors))
|
||||
DisplayForm ($formValues, $formErrors);
|
||||
else
|
||||
ProcessForm ($formValues);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isset ($_SESSION['brand']))
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands ();
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign ('brands', $brands);
|
||||
$smarty->assign ('action', "add_frame.php");
|
||||
$smarty->display ('views/selectbrand.tpl');
|
||||
}
|
||||
else
|
||||
{
|
||||
$formValues['brand'] = $_SESSION['brand'];
|
||||
DisplayForm ($formValues, null);
|
||||
}
|
||||
}
|
||||
?>
|
76
site/stackreach/add_model.php
Executable file
76
site/stackreach/add_model.php
Executable file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
if ( ! is_logged_in($user) ) {
|
||||
return header("location: $site_url");
|
||||
}
|
||||
|
||||
function DisplayForm($values, $errors)
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brand = $brandService->getBrandByName($values['brand']);
|
||||
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllGeometriesByBrand($brand->id);
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brand', $brand);
|
||||
$smarty->assign('geometries', $geometries);
|
||||
$smarty->display('views/add_model.tpl');
|
||||
}
|
||||
|
||||
function VerifyForm(&$values, $errors)
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function ProcessForm($values)
|
||||
{
|
||||
$modelService = new ModelService();
|
||||
$model = new Model($values);
|
||||
$model->approved = 0;
|
||||
$model->user_id = get_user_id();
|
||||
|
||||
$modelService->createModel($model);
|
||||
header('location:models.php');
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
$formValues = $_POST;
|
||||
$formErrors = array();
|
||||
|
||||
if (!VerifyForm($formValues, $formErrors))
|
||||
DisplayForm($formValues, $formErrors);
|
||||
else
|
||||
ProcessForm($formValues);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! isset($_SESSION['brand']))
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands();
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brands', $brands);
|
||||
$smarty->assign('action', "add_frame.php");
|
||||
$smarty->display('views/selectbrand.tpl');
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$formValues['brand'] = $_SESSION['brand'];
|
||||
DisplayForm($formValues, null);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
30
site/stackreach/approve_brand.php
Executable file
30
site/stackreach/approve_brand.php
Executable file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
|
||||
if ( ! is_updater() )
|
||||
return header('location:http://www.slowtwitch.com');
|
||||
|
||||
if($_SERVER['REQUEST_METHOD']=='POST')
|
||||
{
|
||||
if (is_updater ())
|
||||
{
|
||||
$brand_id = $_POST['brand_id'];
|
||||
$brandService = new BrandService();
|
||||
|
||||
$item = $brandService->getBrandByID($brand_id);
|
||||
$item->approved = 1;
|
||||
|
||||
$brandService->updateBrand($item);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
header('location:brands.php');
|
||||
|
||||
?>
|
31
site/stackreach/approve_frame.php
Executable file
31
site/stackreach/approve_frame.php
Executable file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/FrameService.php';
|
||||
|
||||
if (!is_updater())
|
||||
return header('location:http://www.slowtwitch.com');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
if (is_updater ())
|
||||
{
|
||||
|
||||
$frame_id = $_POST['id'];
|
||||
$frameService = new FrameService();
|
||||
$item = $frameService->getFrameByID($frame_id);
|
||||
$item->approved = 1;
|
||||
|
||||
$frameService->updateFrame($item);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
header('location:frames.php');
|
||||
?>
|
30
site/stackreach/approve_geometry.php
Executable file
30
site/stackreach/approve_geometry.php
Executable file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
|
||||
if ( ! is_updater() )
|
||||
return header('location:http://www.slowtwitch.com');
|
||||
|
||||
if($_SERVER['REQUEST_METHOD']=='POST')
|
||||
{
|
||||
if (is_updater ())
|
||||
{
|
||||
$geometry_id = $_POST['id'];
|
||||
$geometryService = new GeometryService();
|
||||
$item = $geometryService->getGeometryByID($geometry_id);
|
||||
$item->approved = 1;
|
||||
|
||||
$geometryService->updateGeometry($item);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
header('location:geometries.php');
|
||||
|
||||
?>
|
28
site/stackreach/approve_model.php
Executable file
28
site/stackreach/approve_model.php
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
|
||||
if ( ! is_updater() )
|
||||
return header('location:http://www.slowtwitch.com');
|
||||
|
||||
if($_SERVER['REQUEST_METHOD']=='POST')
|
||||
{
|
||||
if (is_updater ())
|
||||
{
|
||||
$model_id = $_POST['model_id'];
|
||||
$modelService = new ModelService();
|
||||
$item = $modelService->getModelByID($model_id);
|
||||
$item->approved = 1;
|
||||
$modelService->updateModel($item);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
header('location:models.php');
|
||||
|
||||
?>
|
18
site/stackreach/brands.php
Executable file
18
site/stackreach/brands.php
Executable file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
include_once 'config.php';
|
||||
include_once 'models/services/BrandService.php';
|
||||
include_once 'libs/Smarty.class.php';
|
||||
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands(is_updater());
|
||||
|
||||
$smarty = new Smarty;
|
||||
//$smarty->caching = 1;
|
||||
//$smarty->force_compile = true;
|
||||
$smarty->assign('brands', $brands);
|
||||
$smarty->assign('user_can_update', is_updater());
|
||||
$smarty->assign('user_logged_in', is_logged_in($user));
|
||||
$smarty->display('views/brands.tpl');
|
||||
|
||||
?>
|
217
site/stackreach/config.php
Executable file
217
site/stackreach/config.php
Executable file
@ -0,0 +1,217 @@
|
||||
<?
|
||||
|
||||
###########################################
|
||||
#-----------Users login system------------#
|
||||
###########################################
|
||||
/* =========================================\
|
||||
Author : Mohammed Ahmed(M@@king) \\
|
||||
Version : 1.0 \\
|
||||
Date Created: Aug 20 2005 \\
|
||||
---------------------------- \\
|
||||
Last Update: August 22 2005 \\
|
||||
---------------------------- \\
|
||||
Country : Palestine \\
|
||||
City : Gaza \\
|
||||
E-mail : m@maaking.com \\
|
||||
MSN : m@maaking.com \\
|
||||
AOL-IM : maa2pal \\
|
||||
WWW : http://www.maaking.com \\
|
||||
Mobile/SMS : 00972-599-622235 \\
|
||||
\\
|
||||
===========================================\
|
||||
------------------------------------------ */
|
||||
//skip the config file if somebody call it from the browser.
|
||||
session_start();
|
||||
|
||||
if (eregi("config.php", $_SERVER['SCRIPT_NAME']))
|
||||
{
|
||||
Header("Location: index.php");
|
||||
die();
|
||||
}
|
||||
|
||||
//your database hostname.
|
||||
$dbhost = "192.168.1.10";
|
||||
//your database username.
|
||||
$dbuname = "slowtwitch";
|
||||
//your db password
|
||||
$dbpass = "k9volqlAcpq";
|
||||
$dbname = "slowtwitch";
|
||||
//don't change unless you change this value in the db.
|
||||
$prefix = "gforum_";
|
||||
|
||||
//change this
|
||||
$site_name = "Slowtwitch.com";
|
||||
$site_email = "aaron@gossamer-threads.com";
|
||||
$site_url = "https://www.slowtwitch.com/stackreach/";
|
||||
|
||||
//09-Nov-2005
|
||||
$phpver = phpversion();
|
||||
if ($phpver < '4.1.0')
|
||||
{
|
||||
$_GET = $HTTP_GET_VARS;
|
||||
$_POST = $HTTP_POST_VARS;
|
||||
$_SERVER = $HTTP_SERVER_VARS;
|
||||
}
|
||||
|
||||
/*
|
||||
if ($phpver >= '4.0.4pl1' && strstr($_SERVER["HTTP_USER_AGENT"], 'compatible'))
|
||||
{
|
||||
if (extension_loaded('zlib'))
|
||||
{
|
||||
ob_end_clean();
|
||||
ob_start('ob_gzhandler');
|
||||
}
|
||||
}
|
||||
else if ($phpver > '4.0')
|
||||
{
|
||||
if (strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip'))
|
||||
{
|
||||
if (extension_loaded('zlib'))
|
||||
{
|
||||
$do_gzip_compress = TRUE;
|
||||
ob_start(array('ob_gzhandler', 5));
|
||||
ob_implicit_flush(0);
|
||||
header('Content-Encoding: gzip');
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$phpver = explode(".", $phpver);
|
||||
$phpver = "$phpver[0]$phpver[1]";
|
||||
if ($phpver >= 41)
|
||||
{
|
||||
$PHP_SELF = $_SERVER['PHP_SELF'];
|
||||
}
|
||||
|
||||
if (!ini_get("register_globals"))
|
||||
{
|
||||
import_request_variables('GPC');
|
||||
}
|
||||
|
||||
|
||||
include_once("mysql.class.php");
|
||||
$db = new sql_db($dbhost, $dbuname, $dbpass, $dbname, false);
|
||||
if (!$db->db_connect_id)
|
||||
{
|
||||
|
||||
echo "<br><font color=red><h3><br><center>Error:</b><br><hr><br>
|
||||
<b>Connection to database failed</b><br>
|
||||
<br><br><br><br><br><br><br><br><br></b></center>";
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
function is_updater()
|
||||
{
|
||||
if (is_logged_in($user))
|
||||
{
|
||||
$username = base64_decode($_SESSION['user']);
|
||||
}
|
||||
|
||||
return (is_admin() === true);
|
||||
}
|
||||
|
||||
function is_admin()
|
||||
{
|
||||
if (is_logged_in($user))
|
||||
{
|
||||
$username = base64_decode($_SESSION['user']);
|
||||
if ($username != "Slowman" && $username != "Rappstar" && $username != "Herbert" && $username != "AWright" )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function get_sid()
|
||||
{
|
||||
if (isset($_SESSION['cookie']) and $_SESSION['cookie'])
|
||||
{
|
||||
return '';
|
||||
}
|
||||
else
|
||||
{
|
||||
return '&' . SID;
|
||||
}
|
||||
}
|
||||
|
||||
function get_user_id()
|
||||
{
|
||||
if (!is_logged_in() AND !isset( $_SESSION['user_id'] ))
|
||||
return null;
|
||||
return base64_decode($_SESSION['user_id']);
|
||||
|
||||
}
|
||||
|
||||
//global function for checking whether user is logged in or not.
|
||||
//you will notice we will use it everwhere in the script.
|
||||
function is_logged_in($user)
|
||||
{
|
||||
global $db; //, $prefix;
|
||||
$prefix = "gforum_";
|
||||
|
||||
// return true if we're already logged in
|
||||
if (isset($_SESSION['user']) && $_SESSION['user'] != '')
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// try and get the session id
|
||||
if (isset($_REQUEST['gforum_1022870964_session']))
|
||||
{
|
||||
$session_id = $_REQUEST['gforum_1022870964_session'];
|
||||
}
|
||||
else if ($_REQUEST['from'] == 'gforum')
|
||||
{
|
||||
foreach ($_COOKIE as $key => $value)
|
||||
{
|
||||
if (preg_match('/gforum.*session/', $key))
|
||||
{
|
||||
$session_id = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isset($session_id))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// return false if we have no login info
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$result = mysql_query("SELECT session_user_id FROM " . $prefix . "Session WHERE session_id='$session_id'") or die(mysql_error());
|
||||
$row = mysql_fetch_array($result);
|
||||
$user_id = $row['session_user_id'];
|
||||
$result = mysql_query("SELECT user_username,user_password,user_last_logon FROM " . $prefix . "User WHERE user_id='$user_id'");
|
||||
$row = mysql_fetch_array($result);
|
||||
|
||||
$_SESSION['user'] = base64_encode($row['user_username']);
|
||||
$_SESSION['password'] = base64_encode($row['user_password']);
|
||||
$_SESSION['user_id'] = base64_encode($user_id);
|
||||
$_SESSION['session_id'] = $session_id;
|
||||
$_SESSION['cookie'] = !(isset($_REQUEST['session']));
|
||||
|
||||
if ($_SESSION['user_id'] == '')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// we're now logged in, so return 1
|
||||
return 1;
|
||||
|
||||
// TODO: SLOWTWITCH CHANGE END
|
||||
}
|
||||
|
||||
?>
|
4
site/stackreach/db_templates/include_breadcrumb.php
Executable file
4
site/stackreach/db_templates/include_breadcrumb.php
Executable file
@ -0,0 +1,4 @@
|
||||
<div class="breadcrumb">
|
||||
<a href="<? echo $main_site_url ?>">Home</a> >
|
||||
<span class="lasttitle">Stack/Reach Database</span>
|
||||
</div>
|
36
site/stackreach/db_templates/include_common_content.php
Executable file
36
site/stackreach/db_templates/include_common_content.php
Executable file
@ -0,0 +1,36 @@
|
||||
<body id="home">
|
||||
<div id="accessibility"><a href="#content">Skip to Content</a></div>
|
||||
<hr class="hide" />
|
||||
<div id="wrapper">
|
||||
<div id="header">
|
||||
<div id="ad_728x90"><!-- BEGIN ADVERTPRO CODE BLOCK -->
|
||||
<? include "/var/home/slowtwitch/slowtwitch.com/www/db_templates/ad_728x90.html"; ?>
|
||||
<!-- END ADVERTPRO CODE BLOCK --></div>
|
||||
<div id="logo"><h1><a href="http://www.slowtwitch.com"><:: Welcome to Slowtwitch.com ::></a></h1></div>
|
||||
</div>
|
||||
|
||||
<? include "/var/home/slowtwitch/slowtwitch.com/www/db_templates/common_nav.html"; ?>
|
||||
|
||||
<hr class="hide" /><div id="ocwrapper" class="clear">
|
||||
<div id="icwrapper" class="clear">
|
||||
|
||||
<div id="leftsidebar">
|
||||
<?php
|
||||
include("include_status.php");
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
include("include_navigation.php");
|
||||
?>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div id="contentwrapper" class="shadowleft">
|
||||
<div class="shadowtop"><div class="shadowtopleft"></div><div class="shadowtopright"></div></div>
|
||||
<div class="shadowright">
|
||||
<div id="content">
|
||||
<div class="clear"></div>
|
14
site/stackreach/db_templates/include_common_footer.php
Executable file
14
site/stackreach/db_templates/include_common_footer.php
Executable file
@ -0,0 +1,14 @@
|
||||
</div><!-- end col-2/3 -->
|
||||
</div><!-- end grid -->
|
||||
</div><!-- end content -->
|
||||
</section>
|
||||
|
||||
</div><!-- end contentwrapper -->
|
||||
</div> <!-- end main -->
|
||||
|
||||
<? include( $common_path . "/templates/include_footer.php") ?>
|
||||
<? //include($common_path . "/templates/include_footer.php") ?>
|
||||
</div> <!-- container -->
|
||||
</body>
|
||||
<? include( $common_path . "/templates/include_global_js.php") ?>
|
||||
</html>
|
29
site/stackreach/db_templates/include_common_head.php
Executable file
29
site/stackreach/db_templates/include_common_head.php
Executable file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html >
|
||||
<html lang="en">
|
||||
<head>
|
||||
<base href="<? echo $site_url ?>/" />
|
||||
<title>Slowtwitch.com Stack & Reach Database: <? echo $pagetitle; ?></title>
|
||||
<? include($common_path . "/templates/include_global_head.php"); ?>
|
||||
<? include($common_path . "/templates/google_analytics.html"); ?>
|
||||
</head>
|
||||
<body class="listings">
|
||||
<? include($common_path . "/ads/ad_wallpaper.html"); ?>
|
||||
|
||||
<div class="container">
|
||||
<? include($common_path . "/templates/include_header.php"); ?>
|
||||
<div class="main">
|
||||
<div class="contentwrapper clearfix">
|
||||
<? include("db_templates/include_breadcrumb.php"); ?>
|
||||
|
||||
<section class="section listings section-has-widgets section-static remove-sidebar">
|
||||
<div class="sidebar-b">
|
||||
<? //include("db_templates/include_sidebar.php");
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="content content-has-widgets">
|
||||
<div class="grid">
|
||||
|
||||
<div class="clearfix">
|
||||
<h1>Stack/Reach Database</h1>
|
||||
<hr class="line" />
|
15
site/stackreach/db_templates/include_navigation.php
Executable file
15
site/stackreach/db_templates/include_navigation.php
Executable file
@ -0,0 +1,15 @@
|
||||
<?PHP ?>
|
||||
|
||||
<div class="widget">
|
||||
<h2>More on Stack/Reach</h2>
|
||||
<div class="region-list">
|
||||
<div class="list-item"><a href="/stackreach/index.php">List All Tri</a></div>
|
||||
<div class="list-item"><a href="/stackreach/road.php">List all Road</a></div>
|
||||
<div class="list-item"><a href="/stackreach/brands.php">Brands</a></div>
|
||||
<div class="list-item"><a href="/stackreach/models.php">Models</a></div>
|
||||
<div class="list-item"><a href="/stackreach/geometries.php">Geometries</a></div>
|
||||
<div class="list-item"><a href="/stackreach/frames.php">Frames</a></div>
|
||||
<div class="list-item"><a href="/stackreach/selectbrand.php">Choose Brand</a></div>
|
||||
<div class="list-item"><a href="/stackreach.html">Archives</a></div>
|
||||
</div>
|
||||
</div>
|
7
site/stackreach/db_templates/include_sidebar.php
Executable file
7
site/stackreach/db_templates/include_sidebar.php
Executable file
@ -0,0 +1,7 @@
|
||||
<? include("include_status.php"); ?>
|
||||
<? include("include_navigation.php"); ?>
|
||||
<div class="widget-divider"></div>
|
||||
|
||||
<div class="advert hide-on-mobile">
|
||||
<? include($common_path . "/ads/ad_300x600.html"); ?>
|
||||
</div>
|
4
site/stackreach/db_templates/include_status.php
Executable file
4
site/stackreach/db_templates/include_status.php
Executable file
@ -0,0 +1,4 @@
|
||||
<?PHP
|
||||
$adplacement = rand(0, 1);
|
||||
?>
|
||||
|
26
site/stackreach/delete_brand.php
Executable file
26
site/stackreach/delete_brand.php
Executable file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
include_once 'config.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './config.php';
|
||||
|
||||
if ( ! is_updater() )
|
||||
return header('location:http://www.slowtwitch.com');
|
||||
|
||||
|
||||
if($_SERVER['REQUEST_METHOD']=='POST')
|
||||
{
|
||||
if (is_updater ())
|
||||
{
|
||||
$brandID = $_POST['brand_id'];
|
||||
$brandService = new BrandService();
|
||||
$brandService->deleteBrand($brandID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
header('location:brands.php');
|
||||
|
||||
?>
|
28
site/stackreach/delete_frame.php
Executable file
28
site/stackreach/delete_frame.php
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
include_once 'config.php';
|
||||
include_once './models/services/FrameService.php';
|
||||
include_once './config.php';
|
||||
|
||||
if ( ! is_updater() )
|
||||
return header('location:http://www.slowtwitch.com');
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
if (is_updater ())
|
||||
{
|
||||
if (isset($_POST['id']))
|
||||
{
|
||||
$frameID = $_POST['id'];
|
||||
$frameService = new FrameService();
|
||||
$frameService->deleteFrame($frameID);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
header('location:frames.php');
|
||||
?>
|
24
site/stackreach/delete_geometry.php
Executable file
24
site/stackreach/delete_geometry.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
include_once './config.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
|
||||
if ( ! is_updater() )
|
||||
return header('location:http://www.slowtwitch.com');
|
||||
|
||||
if($_SERVER['REQUEST_METHOD']=='POST')
|
||||
{
|
||||
if (is_updater ())
|
||||
{
|
||||
$geoID = $_POST['id'];
|
||||
$geometryService = new GeometryService();
|
||||
$geometryService->deleteGeometry($geoID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
header('location:geometries.php');
|
||||
|
||||
?>
|
27
site/stackreach/delete_model.php
Executable file
27
site/stackreach/delete_model.php
Executable file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './config.php';
|
||||
|
||||
if ( ! is_updater() )
|
||||
return header('location:http://www.slowtwitch.com');
|
||||
|
||||
if($_SERVER['REQUEST_METHOD']=='POST')
|
||||
{
|
||||
if (is_updater ())
|
||||
{
|
||||
$modelID = $_POST['id'];
|
||||
$modelService = new ModelService();
|
||||
$modelService->deleteModel($modelID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
|
||||
header('location:models.php');
|
||||
|
||||
?>
|
77
site/stackreach/frames.php
Executable file
77
site/stackreach/frames.php
Executable file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/Database.php';
|
||||
include_once './models/services/FrameService.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'GET')
|
||||
{
|
||||
if (isset($_SESSION['brand']))
|
||||
{
|
||||
$name = $_SESSION['brand'];
|
||||
$brandService = new BrandService();
|
||||
$brand = $brandService->getBrandByName($name);
|
||||
|
||||
$brandMap = array();
|
||||
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllGeometriesByBrand($brand->id, is_updater());
|
||||
|
||||
foreach ($geometries as $geometry)
|
||||
{
|
||||
$modelService = new ModelService();
|
||||
$brandMap[$brand->name][$geometry->name]['models'] = $modelService->getAllModelsByGeometry($geometry->id, is_updater());
|
||||
|
||||
$frameService = new FrameService();
|
||||
$frames = $frameService->getAllFramesByGeometry($geometry->id, is_updater());
|
||||
|
||||
if ($frames === null) { header('location:add_frame.php');}
|
||||
|
||||
foreach ($frames as $frame)
|
||||
{
|
||||
$brandMap[$brand->name][$geometry->name]['geometries'][] = $frame;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brandMap', $brandMap);
|
||||
$smarty->assign('brand', $brand);
|
||||
$smarty->assign('user_can_update', is_updater());
|
||||
$smarty->assign('user_logged_in', is_logged_in($user));
|
||||
$smarty->display('views/frames.tpl');
|
||||
|
||||
// $frameService = new FrameService();
|
||||
// $frames = $frameService->getAllFramesByBrand($brand->id, is_updater());
|
||||
//
|
||||
// if ($frames)
|
||||
// {
|
||||
// $smarty = new Smarty;
|
||||
// $smarty->assign('brand', $brand);
|
||||
// $smarty->assign('frames', $frames);
|
||||
// $smarty->assign('user_can_update', is_updater());
|
||||
// $smarty->display('views/frames.tpl');
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// header("location:add_frame.php?brand=$name");
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands();
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brands', $brands);
|
||||
$smarty->assign('action', "frames.php");
|
||||
$smarty->display('views/selectbrand.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
58
site/stackreach/framesX.php
Executable file
58
site/stackreach/framesX.php
Executable file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
include_once './models/services/FrameService.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
|
||||
include_once 'menu.php';
|
||||
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands ();
|
||||
?>
|
||||
<div id="stackreach">
|
||||
<?php
|
||||
foreach ($brands as $brand)
|
||||
{
|
||||
|
||||
echo '<table border="1"><tr><td colspan="100%">' . $brand->name . '</td></tr>';
|
||||
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllGeometriesByBrand ($brand->id);
|
||||
|
||||
foreach ($geometries as $geometry)
|
||||
{
|
||||
|
||||
$modelService = new ModelService();
|
||||
$models = $modelService->getAllModelsByGeometry ($geometry->id);
|
||||
|
||||
$frameService = new FrameService();
|
||||
$frames = $frameService->getAllFramesByGeometry ($geometry->id);
|
||||
$cnt = count ($frames);
|
||||
|
||||
echo '<tr><td rowspan="' . $cnt . '">';
|
||||
foreach ($models as $model)
|
||||
{
|
||||
echo "$model->name<br/>";
|
||||
}
|
||||
echo "</td>";
|
||||
|
||||
foreach ($frames as $frame)
|
||||
{
|
||||
?><td><?= $frame->size_name ?>
|
||||
</td><td><?= $frame->stack ?>
|
||||
</td><td><?= $frame->reach ?>
|
||||
</td><td><?= $frame->trail ?>
|
||||
</td><td><?= $frame->front_center ?>
|
||||
</td><td><?= $frame->head_tube ?>
|
||||
</td><td><?= $frame->internal_headset ?>
|
||||
</td><td><?= $frame->sta_min ?>
|
||||
</td><td><?= $frame->sta_max ?>
|
||||
</td><td><?= $frame->is_650 ?>
|
||||
</td></tr><tr><?php
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
58
site/stackreach/geometries.php
Executable file
58
site/stackreach/geometries.php
Executable file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'GET')
|
||||
{
|
||||
if (isset($_SESSION['brand']))
|
||||
{
|
||||
$brandName = $_SESSION['brand'];
|
||||
|
||||
$brandService = new BrandService();
|
||||
$brand = $brandService->getBrandByName($brandName);
|
||||
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllGeometriesByBrand($brand->id, is_updater());
|
||||
|
||||
$models = array();
|
||||
foreach ($geometries as $geo)
|
||||
{
|
||||
$modelService = new ModelService();
|
||||
$models[$geo->id] = $modelService->getAllModelsByGeometry($geo->id, is_updater());
|
||||
}
|
||||
|
||||
if ($geometries)
|
||||
{
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brand', $brand);
|
||||
$smarty->assign('geometries', $geometries);
|
||||
if ($models)
|
||||
{
|
||||
$smarty->assign('models', $models);
|
||||
}
|
||||
$smarty->assign('geometries', $geometries);
|
||||
$smarty->assign('user_can_update', is_updater());
|
||||
$smarty->assign('user_logged_in', is_logged_in($user));
|
||||
$smarty->display('views/geometries.tpl');
|
||||
}
|
||||
else
|
||||
{
|
||||
header('location:add_geometry.php?brand=' . $brand->name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands();
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brands', $brands);
|
||||
$smarty->assign('action', "geometries.php");
|
||||
$smarty->display('views/selectbrand.tpl');
|
||||
}
|
||||
}
|
||||
?>
|
52
site/stackreach/index.php
Executable file
52
site/stackreach/index.php
Executable file
@ -0,0 +1,52 @@
|
||||
|
||||
<?php
|
||||
|
||||
include_once './models/services/Database.php';
|
||||
include_once './models/services/FrameService.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
try
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands();
|
||||
|
||||
$brandMap = array();
|
||||
|
||||
foreach ($brands as $brand)
|
||||
{
|
||||
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllTriGeometriesByBrand($brand->id);
|
||||
|
||||
foreach ($geometries as $geometry)
|
||||
{
|
||||
$modelService = new ModelService();
|
||||
$brandMap[$brand->name][$geometry->name]['models'] = $modelService->getAllModelsByGeometry($geometry->id);
|
||||
|
||||
$frameService = new FrameService();
|
||||
$frames = $frameService->getAllFramesByGeometry($geometry->id);
|
||||
|
||||
if ($frames === null) { header('location:add_frame.php');}
|
||||
|
||||
foreach ($frames as $frame)
|
||||
{
|
||||
$brandMap[$brand->name][$geometry->name]['geometries'][] = $frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brandMap', $brandMap);
|
||||
$smarty->display('views/index.tpl');
|
||||
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
17
site/stackreach/info.php
Executable file
17
site/stackreach/info.php
Executable file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
//include_once 'config.php';
|
||||
//include_once 'libs/Smarty.class.php';
|
||||
|
||||
//$smarty = new Smarty;
|
||||
//echo $smarty->cache_dir;
|
||||
//$smarty->clearAllCache();
|
||||
//$smarty->assign('user_can_update', is_updater());
|
||||
|
||||
//if (is_logged_in($user))
|
||||
//{
|
||||
// $username = base64_decode($_SESSION['user']);
|
||||
// echo ($username);
|
||||
//}
|
||||
|
||||
?>
|
7
site/stackreach/logout.php
Executable file
7
site/stackreach/logout.php
Executable file
@ -0,0 +1,7 @@
|
||||
<?PHP
|
||||
include_once("config.php");
|
||||
session_unset();
|
||||
session_destroy();
|
||||
$_SESSION = array();
|
||||
header("Location: http://forum.slowtwitch.com/gforum.cgi?do=logout&from=stackreach");
|
||||
?>
|
46
site/stackreach/models.php
Executable file
46
site/stackreach/models.php
Executable file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'GET')
|
||||
{
|
||||
if (isset($_SESSION['brand']))
|
||||
{
|
||||
$name = $_SESSION['brand'];
|
||||
|
||||
$brandService = new BrandService();
|
||||
$brand = $brandService->getBrandByName($name);
|
||||
|
||||
$modelService = new ModelService();
|
||||
$models = $modelService->getAllModelsByBrand($brand->id, is_updater());
|
||||
|
||||
if ($models)
|
||||
{
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brand', $name);
|
||||
$smarty->assign('models', $models);
|
||||
$smarty->assign('user_can_update', is_updater());
|
||||
$smarty->assign('user_logged_in', is_logged_in($user));
|
||||
$smarty->display('views/models.tpl');
|
||||
}
|
||||
else
|
||||
{
|
||||
header("location:add_model.php?brand=$name");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands();
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brands', $brands);
|
||||
$smarty->assign('action', "models.php");
|
||||
$smarty->display('views/selectbrand.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
226
site/stackreach/models/services/BrandService.php
Normal file
226
site/stackreach/models/services/BrandService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
38
site/stackreach/models/services/Database.php
Normal file
38
site/stackreach/models/services/Database.php
Normal 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";
|
||||
|
||||
}
|
||||
|
||||
?>
|
382
site/stackreach/models/services/FrameService.php
Normal file
382
site/stackreach/models/services/FrameService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
304
site/stackreach/models/services/GeometryService.php
Normal file
304
site/stackreach/models/services/GeometryService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
269
site/stackreach/models/services/ModelService.php
Normal file
269
site/stackreach/models/services/ModelService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
339
site/stackreach/mysql.class.php
Executable file
339
site/stackreach/mysql.class.php
Executable file
@ -0,0 +1,339 @@
|
||||
<?PHP
|
||||
###########################################
|
||||
#-----------Users login system------------#
|
||||
###########################################
|
||||
/*=========================================\
|
||||
Author : Mohammed Ahmed(M@@king) \\
|
||||
Version : 1.0 \\
|
||||
Date Created: Aug 20 2005 \\
|
||||
---------------------------- \\
|
||||
Last Update: August 22 2005 \\
|
||||
---------------------------- \\
|
||||
Country : Palestine \\
|
||||
City : Gaza \\
|
||||
E-mail : m@maaking.com \\
|
||||
MSN : m@maaking.com \\
|
||||
AOL-IM : maa2pal \\
|
||||
WWW : http://www.maaking.com \\
|
||||
Mobile/SMS : 00972-599-622235 \\
|
||||
\\
|
||||
===========================================\
|
||||
------------------------------------------*/
|
||||
if (eregi("mysql.class.php", $_SERVER['SCRIPT_NAME'])) {
|
||||
Header("Location: index.php"); die();
|
||||
}
|
||||
//db class
|
||||
if(!defined("SQL_LAYER"))
|
||||
{
|
||||
|
||||
define("SQL_LAYER","mysql");
|
||||
|
||||
class sql_db
|
||||
{
|
||||
|
||||
var $db_connect_id;
|
||||
var $query_result;
|
||||
var $row = array();
|
||||
var $rowset = array();
|
||||
var $num_queries = 0;
|
||||
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
|
||||
{
|
||||
|
||||
$this->persistency = $persistency;
|
||||
$this->user = $sqluser;
|
||||
$this->password = $sqlpassword;
|
||||
$this->server = $sqlserver;
|
||||
$this->dbname = $database;
|
||||
|
||||
if($this->persistency)
|
||||
{
|
||||
$this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password);
|
||||
}
|
||||
if($this->db_connect_id)
|
||||
{
|
||||
if($database != "")
|
||||
{
|
||||
$this->dbname = $database;
|
||||
$dbselect = @mysql_select_db($this->dbname);
|
||||
if(!$dbselect)
|
||||
{
|
||||
@mysql_close($this->db_connect_id);
|
||||
$this->db_connect_id = $dbselect;
|
||||
}
|
||||
}
|
||||
return $this->db_connect_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Other base methods
|
||||
//
|
||||
function sql_close()
|
||||
{
|
||||
if($this->db_connect_id)
|
||||
{
|
||||
if($this->query_result)
|
||||
{
|
||||
@mysql_free_result($this->query_result);
|
||||
}
|
||||
$result = @mysql_close($this->db_connect_id);
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Base query method
|
||||
//
|
||||
function sql_query($query = "", $transaction = FALSE)
|
||||
{
|
||||
// Remove any pre-existing queries
|
||||
unset($this->query_result);
|
||||
if($query != "")
|
||||
{
|
||||
|
||||
$this->query_result = @mysql_query($query, $this->db_connect_id);
|
||||
|
||||
}
|
||||
if($this->query_result)
|
||||
{
|
||||
unset($this->row[$this->query_result]);
|
||||
unset($this->rowset[$this->query_result]);
|
||||
return $this->query_result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( $transaction == END_TRANSACTION ) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Other query methods
|
||||
//
|
||||
function sql_numrows($query_id = 0)
|
||||
{
|
||||
if(!$query_id)
|
||||
{
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
if($query_id)
|
||||
{
|
||||
$result = @mysql_num_rows($query_id);
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_affectedrows()
|
||||
{
|
||||
if($this->db_connect_id)
|
||||
{
|
||||
$result = @mysql_affected_rows($this->db_connect_id);
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_numfields($query_id = 0)
|
||||
{
|
||||
if(!$query_id)
|
||||
{
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
if($query_id)
|
||||
{
|
||||
$result = @mysql_num_fields($query_id);
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_fieldname($offset, $query_id = 0)
|
||||
{
|
||||
if(!$query_id)
|
||||
{
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
if($query_id)
|
||||
{
|
||||
$result = @mysql_field_name($query_id, $offset);
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_fieldtype($offset, $query_id = 0)
|
||||
{
|
||||
if(!$query_id)
|
||||
{
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
if($query_id)
|
||||
{
|
||||
$result = @mysql_field_type($query_id, $offset);
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_fetchrow($query_id = 0)
|
||||
{
|
||||
if(!$query_id)
|
||||
{
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
if($query_id)
|
||||
{
|
||||
$this->row[$query_id] = @mysql_fetch_array($query_id);
|
||||
return $this->row[$query_id];
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_fetchrowset($query_id = 0)
|
||||
{
|
||||
if(!$query_id)
|
||||
{
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
if($query_id)
|
||||
{
|
||||
unset($this->rowset[$query_id]);
|
||||
unset($this->row[$query_id]);
|
||||
while($this->rowset[$query_id] = @mysql_fetch_array($query_id))
|
||||
{
|
||||
$result[] = $this->rowset[$query_id];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_fetchfield($field, $rownum = -1, $query_id = 0)
|
||||
{
|
||||
if(!$query_id)
|
||||
{
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
if($query_id)
|
||||
{
|
||||
if($rownum > -1)
|
||||
{
|
||||
$result = @mysql_result($query_id, $rownum, $field);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(empty($this->row[$query_id]) && empty($this->rowset[$query_id]))
|
||||
{
|
||||
if($this->sql_fetchrow())
|
||||
{
|
||||
$result = $this->row[$query_id][$field];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->rowset[$query_id])
|
||||
{
|
||||
$result = $this->rowset[$query_id][$field];
|
||||
}
|
||||
else if($this->row[$query_id])
|
||||
{
|
||||
$result = $this->row[$query_id][$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_rowseek($rownum, $query_id = 0){
|
||||
if(!$query_id)
|
||||
{
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
if($query_id)
|
||||
{
|
||||
$result = @mysql_data_seek($query_id, $rownum);
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_nextid(){
|
||||
if($this->db_connect_id)
|
||||
{
|
||||
$result = @mysql_insert_id($this->db_connect_id);
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_freeresult($query_id = 0){
|
||||
if(!$query_id)
|
||||
{
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ( $query_id )
|
||||
{
|
||||
unset($this->row[$query_id]);
|
||||
unset($this->rowset[$query_id]);
|
||||
|
||||
@mysql_free_result($query_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function sql_error($query_id = 0)
|
||||
{
|
||||
$result["message"] = @mysql_error($this->db_connect_id);
|
||||
$result["code"] = @mysql_errno($this->db_connect_id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
} // class sql_db
|
||||
|
||||
} // if ... define
|
||||
|
||||
?>
|
10
site/stackreach/paths.php
Executable file
10
site/stackreach/paths.php
Executable file
@ -0,0 +1,10 @@
|
||||
<?
|
||||
//change this
|
||||
$site_name = "Slowtwitch.com";
|
||||
$site_email = "bao@gt.net";
|
||||
$main_site_url = "https://www.slowtwitch.com";
|
||||
$forum_url = "https://forum.slowtwitch.com";
|
||||
$static_url = "https://www.slowtwitch.com/articles/static";
|
||||
$common_path = "/var/home/slowtwitch/site/common";
|
||||
$mini_version = 0;
|
||||
?>
|
50
site/stackreach/road.php
Executable file
50
site/stackreach/road.php
Executable file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
include_once './models/services/Database.php';
|
||||
include_once './models/services/FrameService.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
try
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands();
|
||||
|
||||
$brandMap = array();
|
||||
|
||||
foreach ($brands as $brand)
|
||||
{
|
||||
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllRoadGeometriesByBrand($brand->id);
|
||||
|
||||
foreach ($geometries as $geometry)
|
||||
{
|
||||
$modelService = new ModelService();
|
||||
$brandMap[$brand->name][$geometry->name]['models'] = $modelService->getAllModelsByGeometry($geometry->id);
|
||||
|
||||
$frameService = new FrameService();
|
||||
$frames = $frameService->getAllFramesByGeometry($geometry->id);
|
||||
|
||||
if ($frames === null) { header('location:add_frame.php');}
|
||||
|
||||
foreach ($frames as $frame)
|
||||
{
|
||||
$brandMap[$brand->name][$geometry->name]['geometries'][] = $frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brandMap', $brandMap);
|
||||
$smarty->display('views/index.tpl');
|
||||
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
|
94
site/stackreach/select_preferred.php
Executable file
94
site/stackreach/select_preferred.php
Executable file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
if (! get_user_id())
|
||||
{
|
||||
echo "you must be logged in to use this feature, redirecting...";
|
||||
sleep(4);
|
||||
header('http://forum.slowtwitch.com/gforum.cgi?do=login&from=stackreach');
|
||||
}
|
||||
|
||||
function save_preferred_brands($ids)
|
||||
{
|
||||
global $host, $dbname, $user, $pass;
|
||||
$dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$sql = "DELETE FROM preferred WHERE user_id=:user_id";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute(array(':user_id' => get_user_id()));
|
||||
|
||||
$user_id = get_user_id();
|
||||
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
$sql = "INSERT INTO preferred (user_id, brand_id) VALUES (:user_id, :brand_id)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute(array(':user_id' => $user_id, ':brand_id' => $id));
|
||||
}
|
||||
}
|
||||
|
||||
function get_preferred_brands()
|
||||
{
|
||||
global $host, $dbname, $user, $pass;
|
||||
$dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
# creating the statement
|
||||
$sql = "SELECT brand_id from preferred where user_id=:user_id";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->setFetchMode(PDO::FETCH_OBJ);
|
||||
$sth->execute(array(':user_id' => get_user_id()));
|
||||
|
||||
$brands = $sth->fetchAll();
|
||||
foreach ($brands as $brand)
|
||||
{
|
||||
$ret[$brand->brand_id] = $brand->brand_id;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
try
|
||||
{
|
||||
save_preferred_brands ($_POST['ids']);
|
||||
header('location:view_preferred.php');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands();
|
||||
$preferred = get_preferred_brands();
|
||||
|
||||
foreach ($brands as $brand)
|
||||
{
|
||||
if (isset($preferred[$brand->id]))
|
||||
{
|
||||
$brand->checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brands', $brands);
|
||||
$smarty->display('views/select_preferred.tpl');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
?>
|
25
site/stackreach/selectbrand.php
Executable file
25
site/stackreach/selectbrand.php
Executable file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset ($_POST['brand']))
|
||||
{
|
||||
$_SESSION['brand'] = $_POST['brand'];
|
||||
|
||||
header ('location:' . $_POST['action']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$brandService = new BrandService();
|
||||
$brands = $brandService->getAllBrands ();
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign ('brands', $brands);
|
||||
$smarty->assign ('action', "selectbrand.php");
|
||||
$smarty->assign ('current_brand', $_SESSION['brand']);
|
||||
$smarty->display ('views/selectbrand.tpl');
|
||||
}
|
||||
?>
|
82
site/stackreach/update_brand.php
Executable file
82
site/stackreach/update_brand.php
Executable file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
include_once './config.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
//if ( ! is_updater() )
|
||||
// return header('location:http://www.slowtwitch.com');
|
||||
|
||||
function DisplayForm($values, $errors)
|
||||
{
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('values', $values);
|
||||
$smarty->assign('errors', $errors);
|
||||
$smarty->display('views/update_brand.tpl');
|
||||
}
|
||||
|
||||
function VerifyForm(&$values, &$errors)
|
||||
{
|
||||
$ret = true;
|
||||
$url = htmlspecialchars($values['website']);
|
||||
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $url))
|
||||
{
|
||||
$errors["website"] = "Please check the website and resubmit";
|
||||
$ret = false;
|
||||
}
|
||||
if (strlen($values['name']) < 2)
|
||||
{
|
||||
$errors["name"] = "Please check the brand name and resubmit";
|
||||
$ret = false;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function ProcessForm($values)
|
||||
{
|
||||
$brand = new Brand($values);
|
||||
$brand->approved = 0;
|
||||
$brand->user_id = get_user_id();
|
||||
|
||||
$brandService = new BrandService();
|
||||
$ret = $brandService->updateBrand($brand);
|
||||
|
||||
header("location:brands.php?brand=$brand->name");
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
$formValues = $_POST;
|
||||
$formErrors = array();
|
||||
|
||||
try
|
||||
{
|
||||
if (!VerifyForm($formValues, $formErrors))
|
||||
DisplayForm($formValues, $formErrors);
|
||||
else
|
||||
ProcessForm($formValues);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
DisplayForm($formValues, $formErrors);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($_GET['brand_id']))
|
||||
{
|
||||
$brand_id = $_GET['brand_id'];
|
||||
|
||||
$brandService = new BrandService();
|
||||
$brand = $brandService->getBrandByID($brand_id);
|
||||
if ($brand !== null)
|
||||
DisplayForm((array) $brand, null);
|
||||
else
|
||||
header('location:brands.php');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
93
site/stackreach/update_frame.php
Executable file
93
site/stackreach/update_frame.php
Executable file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/FrameService.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './models/services/BrandService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
//if ( ! is_updater() )
|
||||
// return header('location:http://www.slowtwitch.com');
|
||||
|
||||
function DisplayForm ($values, $errors)
|
||||
{
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllGeometriesByBrand ($values['brand_id']);
|
||||
|
||||
$brandService = new BrandService();
|
||||
$brand = $brandService->getBrandByID ($values['brand_id']);
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign ('values', $values);
|
||||
$smarty->assign ('errors', $errors);
|
||||
$smarty->assign ('geometries', $geometries);
|
||||
$smarty->assign ('brand', $brand);
|
||||
|
||||
$smarty->display ('views/update_frame.tpl');
|
||||
}
|
||||
|
||||
function VerifyForm (&$values, &$errors)
|
||||
{
|
||||
return VerifyFrame ($values, $errors);
|
||||
}
|
||||
|
||||
function ProcessForm ($values)
|
||||
{
|
||||
|
||||
$frame = new Frame ($values);
|
||||
$frame->approved = 0;
|
||||
$frame->user_id = get_user_id ();
|
||||
|
||||
|
||||
$frameService = new FrameService();
|
||||
$frameService->updateFrame ($frame);
|
||||
|
||||
header ('location:frames.php?brand=' . $values['brand']);
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
$formValues = $_POST;
|
||||
$formErrors = array ();
|
||||
|
||||
if (!isset($_POST['internal_headset']))
|
||||
$formValues['internal_headset'] = 0;
|
||||
else
|
||||
$formValues['internal_headset'] = 1;
|
||||
|
||||
if (!isset($_POST['is_650']))
|
||||
$formValues['is_650'] = 0;
|
||||
else
|
||||
$formValues['is_650'] = 1;
|
||||
|
||||
try
|
||||
{
|
||||
if (!VerifyForm ($formValues, $formErrors))
|
||||
DisplayForm ($formValues, $formErrors);
|
||||
else
|
||||
ProcessForm ($formValues);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage ();
|
||||
DisplayForm ($formValues, $formErrors);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$frame_id = $_GET['id'];
|
||||
|
||||
if ($frame_id !== null)
|
||||
{
|
||||
|
||||
$frameService = new FrameService();
|
||||
$frame = $frameService->getFrameByID ($frame_id);
|
||||
|
||||
if ($frame !== null)
|
||||
DisplayForm ((array) $frame, null);
|
||||
else
|
||||
header ('location:frames.php');
|
||||
}
|
||||
}
|
||||
?>
|
89
site/stackreach/update_geometry.php
Executable file
89
site/stackreach/update_geometry.php
Executable file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
include_once './config.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
//if ( ! is_updater() )
|
||||
// return header('location:http://www.slowtwitch.com');
|
||||
|
||||
function DisplayForm ($values, $errors)
|
||||
{
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign ('values', $values);
|
||||
$smarty->assign ('errors', $errors);
|
||||
|
||||
$smarty->display ('views/update_geometry.tpl');
|
||||
}
|
||||
|
||||
function VerifyForm (&$values, &$errors)
|
||||
{
|
||||
// if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $url))
|
||||
// {
|
||||
// $errors["website"] = "Please check the website and resubmit";
|
||||
// $ret = false;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function ProcessForm ($values)
|
||||
{
|
||||
$geometry = new Geometry ($values);
|
||||
$geometry->approved = 0;
|
||||
$geometry->user_id = get_user_id ();
|
||||
|
||||
try
|
||||
{
|
||||
// echo __LINE__ . "\n";
|
||||
$geometryService = new GeometryService();
|
||||
$geometryService->updateGeometry ($geometry);
|
||||
// echo __LINE__ . "\n";
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// echo 'Caught exception: ', $e->getMessage (), "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
header ('location:geometries.php?brand=' . $values['brand']);
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
$formValues = $_POST;
|
||||
$formErrors = array ();
|
||||
|
||||
if (isset ($_POST['is_road']))
|
||||
$formValues['is_road'] = 1;
|
||||
else
|
||||
$formValues['is_road'] = 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (!VerifyForm ($formValues, $formErrors))
|
||||
DisplayForm ($formValues, $formErrors);
|
||||
else
|
||||
ProcessForm ($formValues);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage ();
|
||||
DisplayForm ($formValues, $formErrors);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$geoID = $_GET['id'];
|
||||
|
||||
if ($geoID !== null)
|
||||
{
|
||||
$geometryService = new GeometryService();
|
||||
$geometry = $geometryService->getGeometryByID ($geoID);
|
||||
if ($geometry !== null)
|
||||
DisplayForm ((array) $geometry, null);
|
||||
else
|
||||
header ('location:geometries.php');
|
||||
}
|
||||
}
|
||||
?>
|
84
site/stackreach/update_model.php
Executable file
84
site/stackreach/update_model.php
Executable file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
include_once 'config.php';
|
||||
include_once './models/services/ModelService.php';
|
||||
include_once './models/services/GeometryService.php';
|
||||
include_once './libs/Smarty.class.php';
|
||||
|
||||
//if ( ! is_updater() )
|
||||
// return header('location:http://www.slowtwitch.com');
|
||||
|
||||
|
||||
function DisplayForm($values, $errors)
|
||||
{
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllGeometriesByBrand($values['brand_id']);
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('values', $values);
|
||||
$smarty->assign('geometries', $geometries);
|
||||
$smarty->assign('errors', $errors);
|
||||
$smarty->display('views/update_model.tpl');
|
||||
}
|
||||
|
||||
function VerifyForm(&$values, &$errors)
|
||||
{
|
||||
// $ret = true;
|
||||
// $url = htmlspecialchars($values['website']);
|
||||
// if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $url))
|
||||
// {
|
||||
// $errors["website"] = "Please check the website and resubmit";
|
||||
// $ret = false;
|
||||
// }
|
||||
// if (strlen($values['name']) < 2)
|
||||
// {
|
||||
// $errors["name"] = "Please check the brand name and resubmit";
|
||||
// $ret = false;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function ProcessForm($values)
|
||||
{
|
||||
$model = new Model($values);
|
||||
$model->approved = 0;
|
||||
$model->user_id = get_user_id();
|
||||
|
||||
$modelService = new ModelService();
|
||||
$modelService->updateModel($model);
|
||||
header('location:models.php');
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
$formValues = $_POST;
|
||||
$formErrors = array();
|
||||
|
||||
try
|
||||
{
|
||||
if (!VerifyForm($formValues, $formErrors))
|
||||
DisplayForm($formValues, $formErrors);
|
||||
else
|
||||
ProcessForm($formValues);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
DisplayForm($formValues, $formErrors);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($_GET['model_id']))
|
||||
{
|
||||
$model_id = $_GET['model_id'];
|
||||
$modelService = new ModelService();
|
||||
$model = $modelService->getModelByID($model_id);
|
||||
if ($model !== null)
|
||||
DisplayForm((array) $model, null);
|
||||
else
|
||||
header('location:models.php');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
81
site/stackreach/view_preferred.php
Executable file
81
site/stackreach/view_preferred.php
Executable file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
include_once './config.php';
|
||||
include './models/services/FrameService.php';
|
||||
include './models/services/ModelService.php';
|
||||
include './models/services/BrandService.php';
|
||||
include './models/services/GeometryService.php';
|
||||
include './libs/Smarty.class.php';
|
||||
|
||||
|
||||
if (! get_user_id())
|
||||
{
|
||||
echo "you must be logged in to use this feature, redirecting...";
|
||||
sleep(3);
|
||||
header('location:http://forum.slowtwitch.com/gforum.cgi?do=login&from=stackreach');
|
||||
}
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
|
||||
|
||||
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
|
||||
# creating the statement
|
||||
$sql = "SELECT brand_id from preferred where user_id=:user_id";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->setFetchMode(PDO::FETCH_OBJ);
|
||||
$sth->execute(array(':user_id' => get_user_id()));
|
||||
$preferred = $sth->fetchAll();
|
||||
|
||||
|
||||
foreach ($preferred as $brand)
|
||||
{
|
||||
$bs = new BrandService();
|
||||
$brands[] = $bs->getBrandByID($brand->brand_id);
|
||||
$bs = null;
|
||||
}
|
||||
|
||||
$brandMap = array();
|
||||
|
||||
foreach ($brands as $brand)
|
||||
{
|
||||
|
||||
$geometryService = new GeometryService();
|
||||
$geometries = $geometryService->getAllGeometriesByBrand($brand->id);
|
||||
|
||||
foreach ($geometries as $geometry)
|
||||
{
|
||||
$modelService = new ModelService();
|
||||
$brandMap[$brand->name][$geometry->name]['models'] = $modelService->getAllModelsByGeometry($geometry->id);
|
||||
|
||||
$frameService = new FrameService();
|
||||
$frames = $frameService->getAllFramesByGeometry($geometry->id);
|
||||
|
||||
|
||||
if ($frames === null) { header('location:add_frame.php');}
|
||||
|
||||
foreach ($frames as $frame)
|
||||
{
|
||||
$brandMap[$brand->name][$geometry->name]['geometries'][] = $frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('brandMap', $brandMap);
|
||||
$smarty->display('views/index.tpl');
|
||||
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user