function saveJSONRecord($table, $parentKeyName) { if (!sesWriteAccess()) { header('HTTP/1.1 403 Forbidden'); exit; } $data = json_decode(file_get_contents('php://input'), true); if (!$data) { header('HTTP/1.1 400 Bad Request'); return; } $strForm = $table; $strFunc = ''; $strList = ''; $id = isset($data['id']) ? $data['id'] : false; require 'form_switch.php'; $new = $id ? false : true; unset($data['id']); $warnings = ''; $res = saveFormData($strTable, $id, $astrFormElements, $data, $warnings, $parentKeyName, $parentKeyName ? $data[$parentKeyName] : FALSE); if ($res !== true) { if ($warnings) { header('HTTP/1.1 409 Conflict'); } header('Content-Type: application/json'); echo json_encode(['missing_fields' => $res, 'warnings' => $warnings]); return; } if ($new) { header('HTTP/1.1 201 Created'); } printJSONRecord($strTable, $id, $warnings); }
<?php require 'config.php'; //Main function if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($firstnameErr == "" && $lastnameErr == "" && $emailErr == "" && $mobileErr == "") { while (1) { if (file_get_contents("lock.txt") == "unlocked") { // no lock present, so place one file_put_contents("lock.txt", "locked"); $agentID = findNextAvailableAgent(); if ($agentID == 0) { //No active agents available saveBacklog($firstname, $lastname, $email, $mobile, $message); echo "<br><p>Thank you for submitting this form.</p><p>There are no agents available at the moment but we will get in touch with you shortly.</p>"; } else { $leadID = saveFormData($firstname, $lastname, $email, $mobile, $message); assignAgent($leadID, $agentID); echo "<br><p>Thank you for submitting this form.</p><p>An agent will be attending to your request shortly.</p>"; sendEmail($leadID, $agentID); } // remove the lock file_put_contents("lock.txt", "unlocked", LOCK_EX); break; } else { //lock present so must wait usleep(mt_rand(1, 500000)); } } } } //Save in backlog because no agents are available
// e.g. Employee, Pay Record etc $url = $crud_page['url'] . "?page_id=" . $_GET['page_id']; // $url = isset( $_SERVER['HTTP_REFERER'] )? $_SERVER['HTTP_REFERER'] : $crud_page['url']."?page_id=".$crud_page['id']; // check deleting: if (isset($_GET['record_id']) && isset($_GET['delete']) && $_GET['delete'] == 'true') { $logmsg = $recordTitle . " Deleted: Record Id = " . $_GET['record_id']; deleteRecord($crud_page['table_name'], "id=" . $_GET['record_id'], $logmsg, $url); } // handle posted data if (isset($_POST['submit'])) { // prpost(); validatefft($crud_page['table_name']); if ($form->isValid()) { $condition = isset($_GET['record_id']) ? "id=" . $_GET['record_id'] : NULL; $logmsg = isset($_GET['record_id']) ? $recordTitle . " Edited: " . $recordTitle . " ID: " . $_POST['id'] : "New " . $recordTitle . " Saved"; saveFormData($crud_page['table_name'], $_POST, $condition, $logmsg, $url); } } ?> <h2><?php echo $recordTitle; ?> Form</h2> <?php $record_id = isset($_GET['record_id']) ? $_GET['record_id'] : null; showfft($crud_page, $record_id); ?> <?php