if ($action == 'borrar') { $idedificio = required_param('edificio', PARAM_INT); // si el eficio tiene salas asociadas a el, se buscan y borran if ($salas = $DB->get_records('reservasalas_salas', array('edificios_id' => $idedificio))) { foreach ($salas as $sala) { $DB->delete_records('reservasalas_reservas', array('salas_id' => $sala->id)); } $DB->delete_records('reservasalas_salas', array('edificios_id' => $idedificio)); } $DB->delete_records('reservasalas_edificios', array('id' => $idedificio)); $action = "ver"; } // Se crea un edificio nuevo if ($action == 'crear') { // Formulario de creción $crearedificio = new createBuildingTwoAdminRoom(); if ($crearedificio->is_cancelled()) { $action = 'ver'; // si el formulario de creacion no se cancelo y tiene los datos validados se crea el edificio } else { if ($fromform = $crearedificio->get_data()) { $record = new stdClass(); $record->nombre = $fromform->edificio; $record->sedes_id = $fromform->sede; $explode = $fromform->modules; // se crea el edificio y su sede asosiada if ($DB->insert_record('reservasalas_edificios', $record)) { $recordtwo = new stdClass(); $buildingid = $DB->get_record('reservasalas_edificios', array('nombre' => $fromform->edificio, 'sedes_id' => $fromform->sede)); $modulesArray = array(); $modulesArray = explode('#', $explode);
if ($action == 'delete') { $idbuilding = required_param('building', PARAM_INT); // If the building is associated with the rooms , are searched and deleted if ($rooms = $DB->get_records('bookingrooms_rooms', array('buildings_id' => $idbuilding))) { foreach ($rooms as $room) { $DB->delete_records('bookingrooms_reserves', array('rooms_id' => $room->id)); } $DB->delete_records('bookingrooms_rooms', array('buildings_id' => $idbuilding)); } $DB->delete_records('bookingrooms_buildings', array('id' => $idbuilding)); $action = "view"; } // A new building was created if ($action == 'create') { // Form creation $createbuilding = new createBuildingTwoAdminRoom(); if ($createbuilding->is_cancelled()) { $action = 'view'; // If the form of creation and has not canceled the building validated data is created } else { if ($fromform = $createbuilding->get_data()) { $record = new stdClass(); $record->name = $fromform->building; $record->campus_id = $fromform->campus; $explode = $fromform->modules; // It creates the building and its campus asociate if ($DB->insert_record('bookingrooms_buildings', $record)) { $recordtwo = new stdClass(); $buildingid = $DB->get_record('bookingrooms_buildings', array('name' => $fromform->building, 'campus_id' => $fromform->campus)); $modulesArray = array(); $modulesArray = explode('#', $explode);