function viewPincho() { $aux = new Establishment(); $name = $_SESSION["name"]; $bool = $aux->select($name); $id = $bool[0]["idEstablishment"]; $p = new Pincho(); $boolean = $p->select($id); if ($boolean == false) { header("Location: ../views/notPinchoEstablishment.php"); } else { $name = $boolean["0"]["name"]; $url = $boolean["0"]["url"]; $description = $boolean["0"]["description"]; $ingredients = $boolean["0"]["ingredients"]; $price = $boolean["0"]["price"]; header("Location: ../views/viewPinchoEstablishment.php?name={$name}&url={$url}&description={$description}&ingredients={$ingredients}&price={$price}"); } }
function codeGeneration($namePopular) { //Buscar el id del popular conociendo el nombre //Buscar el id del establecimiento actual //Buscar el id del pincho del establecimiento actual //Crear un array que contenga la id del establecimiento, la id del popular, la id del pincho y el codigo aleatorio generado, para insertarlo en la tabla codes. $e = new Establishment(); $name = $_SESSION["name"]; $bool = $e->select($name); if ($bool == false) { echo "Error del servidor"; } else { $idEstablishment = $bool[0]["idEstablishment"]; $p = new Pincho(); $boolean = $p->select($idEstablishment); if ($boolean == false) { echo "Error del servidor"; } else { $idPincho = $boolean[0]["code"]; $popular = new Popular(); $comp = $popular->select($namePopular); if ($comp == false) { $msg = "El popular introducido no existe"; header("Location: ../views/generateCode.php?msg={$msg}"); } else { $idPopular = $comp[0]["idPopular"]; $codigoAleatorio = generarCodigo(10); $cod = new Codes(); $tValid = $cod->isValid($codigoAleatorio); if ($tValid == false) { $msg = "Error interno al generar el código.Repita el proceso"; header("Location: ../views/generateCode.php?msg={$msg}"); } else { $array = array(); $array["Pincho_Establishment_idEstablishment"] = $idEstablishment; $array["Pincho_code"] = $idPincho; $array["Popular_idPopular"] = $idPopular; $array["Code"] = $codigoAleatorio; $inserta = $cod->insert($array); if ($inserta == true) { $msg = "El codigo generado es {$codigoAleatorio}"; header("Location: ../views/generateCode.php?msg={$msg}"); } else { echo "Error en la inserción"; } } } } } }