throwExceptions = true;
try {
// begin transaction
$db->transactionBegin();
foreach ($_POST['records'] as $record) {
$key_value = explode('=', $record);
$record_pk_value = urldecode($key_value[1]);
// Delete from target table
$where = array('.' => $record_pk_value);
if (!DEMO && !$db->delete('', $where, DEBUG_DB_QUERIES)) {
throw new \Exception(FAILED_TO_DELETE);
}
} // end foreach
// ALL OK
// revert if DEBUG_DB_QUERIES is enabled
$msg_debug = '';
if (DEBUG_DB_QUERIES) {
$db->transactionRollback();
// gives an id to catch it with the Javascript callback
$msg_debug .= '
' . DEBUG_DB_QUERIES_ENABLED . '';
} else {
$db->transactionCommit();
}
$msg = Utils::alert(count($_POST['records']) . BULK_DELETE_SUCCESS_MESSAGE . $msg_debug, 'alert-success has-icon');
} catch (\Exception $e) {
$db->transactionRollback();
if (ENVIRONMENT == 'development' && !$db->show_errors) {
$msg_content = DB_ERROR;
if (ENVIRONMENT == 'development') {
$msg_content .= '
' . $e->getMessage() . '
' . $db->getLastSql();
}
$msg = Utils::alert($msg_content, 'alert-danger has-icon');
}
}
} // END if (isset($_POST['records']))
if (isset($msg)) {
echo $msg;
}
} // END if Secure