multisite('admin.php')); $form->setAttributes($attributes); // Hidden inputs $hidden_inputs = array('area' => $area, 'room' => $room); $form->addHiddenInputs($hidden_inputs); // The button $element = new ElementInputSubmit(); $element->setAttribute('value', get_vocab("NO")); $form->addElement($element); $form->render(); } function generate_yes_form(int $room, int $area) : void { $form = new Form(Form::METHOD_POST); $attributes = array('action' => multisite('del.php')); $form->setAttributes($attributes); // Hidden inputs $hidden_inputs = array('type' => 'room', 'area' => $area, 'room' => $room, 'confirm' => '1'); $form->addHiddenInputs($hidden_inputs); // The button $element = new ElementInputSubmit(); $element->setAttribute('value', get_vocab("YES")); $form->addElement($element); $form->render(); } // Check the CSRF token Form::checkToken(); // Check the user is authorised for this page checkAuthorised(this_page()); // Get non-standard form variables $type = get_form_var('type', 'string'); $confirm = get_form_var('confirm', 'string', null, INPUT_POST); $context = array( 'view' => $view, 'view_all' => $view_all, 'year' => $year, 'month' => $month, 'day' => $day, 'area' => $area, 'room' => $room ?? null ); // This is gonna blast away something. We want them to be really // really sure that this is what they want to do. if ($type == "room") { // We are supposed to delete a room if (!empty($confirm)) { // They have confirmed it already, so go blast! db()->begin(); try { // First take out all appointments for this room $sql = "DELETE FROM " . _tbl('entry') . " WHERE room_id=?"; db()->command($sql, array($room)); $sql = "DELETE FROM " . _tbl('repeat') . " WHERE room_id=?"; db()->command($sql, array($room)); // Now take out the room itself $sql = "DELETE FROM " . _tbl('room') . " WHERE id=?"; db()->command($sql, array($room)); } catch (DBException $e) { db()->rollback(); throw $e; } db()->commit(); // Go back to the admin page location_header("admin.php?area=$area"); } else { print_header($context); // We tell them how bad what they're about to do is // Find out how many appointments would be deleted // Do a quick count of the number of entries $n_entries = get_n_entries_by_room($room); if ($n_entries > 0) { $limit = 20; // Order in descending order because the latest bookings are probably the most important. $entries = get_entries_by_room($room, null, null, true, $limit); // We can't rely on ($n_entries > 0) because there's a very small chance the number of entries // may have changed between the two queries if (count($entries) > 0) { echo "
\n"; echo get_vocab("deletefollowing") . ":\n"; echo "
\n"; echo ""; $formatter = new \NumberFormatter(Language::getInstance()->getWebLocale(), \NumberFormatter::DEFAULT_STYLE); echo get_vocab("and_n_more", $formatter->format($n_entries - $limit)) . '.'; echo "
"; } } echo "" . get_vocab("sure") . "
\n"; generate_yes_form($room, $area); generate_no_form($room, $area); echo "\n"; echo get_vocab("delarea"); $query_vars = array('area' => $area); $query = http_build_query($query_vars, '', '&'); echo '' . get_vocab('back') . ''; echo "
\n"; print_footer(); exit; } } throw new \Exception ("Unknown type");