hasErrors()) {
$_SESSION['errors']['form-delete-'] = $validator->getAllErrors();
} else {
if ($_POST['delete-'] > 0) {
$db = new DB(DEBUG);
$db->setDebugMode('register');
try {
// begin transaction
$db->transactionBegin();
// Delete from target table
$where = $_SESSION['_editable_primary_keys'];
if (DEMO === true || $db->delete('', $where, DEBUG_DB_QUERIES)) {
// ALL OK
if (!DEBUG_DB_QUERIES) {
$db->transactionCommit();
$_SESSION['msg'] = Utils::alert(DELETE_SUCCESS_MESSAGE, 'alert-success has-icon');
// reset form values
Form::clear('form-delete-');
// unset the search string
if (isset($_SESSION['rp_search_string'][''])) {
unset($_SESSION['rp_search_string']['']);
}
// redirect to list page
if (isset($_SESSION['active_list_url'])) {
header('Location:' . $_SESSION['active_list_url']);
} else {
header('Location:' . ADMIN_URL . '');
}
// if we don't exit here, $_SESSION['msg'] will be unset
exit();
} else {
$debug_content = $db->getDebugContent();
$db->transactionRollback();
$_SESSION['msg'] = Utils::alert(DELETE_SUCCESS_MESSAGE . '
(' . DEBUG_DB_QUERIES_ENABLED . ')', 'alert-success has-icon');
}
} else {
throw new \Exception($db->error());
}
} catch (\Exception $e) {
if (DEBUG_DB_QUERIES) {
$debug_content = $db->getDebugContent();
}
$msg_content = DB_ERROR;
if (ENVIRONMENT == 'development') {
$msg_content .= '
' . $e->getMessage() . '
' . $db->getLastSql();
}
$_SESSION['msg'] = Utils::alert($msg_content, 'alert-danger has-icon');
}
}
}
} // END if POST
// register editable primary keys, which are NOT posted and will be the query delete filter
// $params come from data-forms.php
// replace 'fieldname' with 'table.fieldname' to avoid ambigous query
$where_params = array_combine(
array_map(function ($k) {
return '.' . $k;
}, array_keys($params)),
$params
);
$_SESSION['_editable_primary_keys'] = $where_params;
if (!isset($db)) {
$db = new DB(DEBUG);
$db->setDebugMode('register');
}
// select name to display for confirmation
$from = '';
$columns = array('');
$where = $_SESSION['_editable_primary_keys'];
$extras = array('limit' => 1);
$db->select($from, $columns, $where, $extras, DEBUG_DB_QUERIES);
if (DEBUG_DB_QUERIES) {
$debug_content = $db->getDebugContent();
}
$count = $db->rowCount();
if ($count > 0) {
$row = $db->fetch();
$display_value = $row->;
} else {
// this should never happen
// echo $db->getLastSql();
header("X-Robots-Tag: noindex", true);
exit('QRY ERROR');
}
$form = new Form('form-delete-', 'vertical', 'novalidate');
// $params come from data-forms.php
$pk_url_params = http_build_query($params, '', '/');
$form->setAction(ADMIN_URL . '/delete/' . $pk_url_params);
$form->startFieldset();
$form->addHtml('