Fifth pass at adding key files
This commit is contained in:
		
							
								
								
									
										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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
		Reference in New Issue
	
	Block a user