hasErrors()) { $_SESSION['errors']['form-edit-'] = $validator->getAllErrors(); } else { require_once CLASS_DIR . 'phpformbuilder/database/db-connect.php'; require_once CLASS_DIR . 'phpformbuilder/database/DB.php'; $db = new DB(DEBUG); $db->setDebugMode('register'); $values = array(); $where = $_SESSION['_editable_primary_keys']; // begin transaction $db->transactionBegin(); try { // update if (DEMO !== true && !$db->update('', $values, $where, DEBUG_DB_QUERIES)) { $error = $db->error(); throw new \Exception($error); } else { // ALL OK if (!DEBUG_DB_QUERIES) { $db->transactionCommit(); $_SESSION['msg'] = Utils::alert(UPDATE_SUCCESS_MESSAGE, 'alert-success has-icon'); // reset form values Form::clear('form-edit-'); // 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(UPDATE_SUCCESS_MESSAGE . '
(' . DEBUG_DB_QUERIES_ENABLED . ')', 'alert-success has-icon'); } } } catch (\Exception $e) { $db->transactionRollback(); $msg_content = DB_ERROR; if (DEBUG) { $msg_content .= '
' . $e->getMessage() . '
' . $db->getLastSql(); } $_SESSION['msg'] = Utils::alert($msg_content, 'alert-danger has-icon'); } } // END else } // END if POST // register editable primary keys, which are NOT posted and will be the query update 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($_SESSION['errors']['form-edit-']) || empty($_SESSION['errors']['form-edit-'])) { // If no error registered $from = ''; $columns = '*'; $where = $_SESSION['_editable_primary_keys']; // if restricted rights if (ADMIN_LOCKED === true && Secure::canUpdateRestricted('')) { $where = array_merge($where, Secure::getRestrictionQuery('')); } $db = new DB(DEBUG); $db->setDebugMode('register'); $db->select($from, $columns, $where, array(), DEBUG_DB_QUERIES); if ($db->rowCount() < 1) { if (DEBUG) { exit($db->getLastSql() . ' : No Record Found'); } else { exit('No Record Found'); } } if (DEBUG_DB_QUERIES) { $debug_content .= $db->getDebugContent(); } $row = $db->fetch(); } // $params come from data-forms.php $pk_url_params = http_build_query($params, '', '/'); $form = new Form('form-edit-', 'horizontal', 'novalidate'); $form->setAction(ADMIN_URL . '/edit/' . $pk_url_params); $form->startFieldset(); $form->setCols(2, ); $form->addBtn('button', 'cancel', 0, '' . CANCEL, 'class=btn btn-warning, data-ladda-button=true, data-style=zoom-in, onclick=history.go(-1)', 'btn-group'); $form->addBtn('submit', 'submit-btn', 1, SUBMIT . '', 'class=btn btn-success, data-ladda-button=true, data-style=zoom-in', 'btn-group'); $form->setCols(0, 12); $form->centerContent(); $form->printBtnGroup('btn-group'); $form->endFieldset(); $form->addPlugin('pretty-checkbox', '#form-edit-'); $form->addPlugin('formvalidation', '#form-edit-', 'default', array('language' => FORMVALIDATION_JAVASCRIPT_LANG));