function accessDB($cod, $tabla) { //DATABASE work $database = new pdodatabase(); $values = array("*"); $conditions = array("cod" => $cod); $sql = $database->createSelect($tabla, $values, $conditions); $datos = $database->execSelect($sql, $conditions); if ($datos != false) { $row = $datos->fetch(PDO::FETCH_ASSOC); foreach ($row as $key => $value) { $producto[$row['cod']][$key] = $value; } return $producto; } }
function listProduct() { //DATABASE work $database = new pdodatabase(); $values = array("*"); $sql = $database->createSelect("producto", $values, $conditions); $datos = $database->execSelect($sql, null); if ($datos != false) { //list all the products while ($row = $datos->fetch()) { $productos[$row['nombre_corto']][0] = $row['PVP']; if ($row['familia'] === "ORDENA") { $productos[$row['nombre_corto']][1] = $row['cod']; } } return $productos; } }
//Include the smarty lib require_once '../../libs/smarty/libs/Smarty.class.php'; //init an object of the smarty class $smarty = new Smarty(); //init basic attributes $smarty->template_dir = '../templates/'; $smarty->compile_dir = '../templates_c/'; $smarty->config_dir = '../configs/'; $smarty->cache_dir = '../cache/'; $error = ""; $success = ""; unset($_SESSION['username']); unset($_SESSION['cesta']); require_once '../common/class_pdo.php'; if (isset($_POST['send'])) { session_start(); $username = filter_input(INPUT_POST, 'usuario', FILTER_SANITIZE_STRING); $password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING); $bd_pdo = new pdodatabase(); if ($bd_pdo->validateUser("usuarios", $username, $password)) { $_SESSION['username'] = $username; $success = "Usuario correcto, redirigiendo"; header("Refresh: 3; url=product.php"); } else { $error = "Usuario incorrecto. Compruebe que haya introducido bien sus datos"; } } $smarty->assign('success', $success); $smarty->assign('error', $error); //Load the template or html page $smarty->display('login.tpl');