header("location: ../index.php"); } connect(); $type = $_POST["type"]; $id = $_POST["id"]; $id2 = $_POST["id2"]; $name = $_POST["name"]; $rank = $_POST["rank"]; if ($type) { switch ($type) { case 'createRecord': $rank = StructuredField::createRecord($id, $name, $rank); $result = "Record for unit with id {$id} at rank={$rank} with name={$name} has been created"; break; case 'updateRecord': $rank = StructuredField::updateRecord($id, $name, $rank); $result = "Record {$id} has been updated with rank={$rank}, and name={$name}"; break; case 'moveRankUp': StructuredField::moveRankUp($id, $rank); $result = "rank #{$rank} has been freed"; break; case 'readRecord': $record = StructuredField::readRecord($id); if ($record) { $result = implode(",", $record); } else { $result = "no record found"; } break; case 'getSortedRecords':
//move rank down $moveRankDown = $_GET['movedown']; if ($moveRankDown) { StructuredField::switchRank($records[$moveRankDown][0], $records[1 + $moveRankDown][0]); $records = StructuredField::getSortedRecords($id, $isAdmin); } // rename/lock/unlock record if ($save) { $recordName = $_POST['recordName']; $selectedRecord = StructuredField::readRecord($init); if ($isAdmin) { $lockVal = $_POST['lock']; } else { $lockVal = $selectedRecord[4]; } StructuredField::updateRecord($selectedRecord[0], $recordName, $selectedRecord[2], $lockVal); $records = StructuredField::getSortedRecords($id, $isAdmin); } //get default values for the textareas (either from the selecting record, or from the first record) if ($init) { $selectedRecord = StructuredField::readRecord($init); } else { $selectedRecord = $records[0]; $init = $selectedRecord[0]; } if ($init) { $textArray = StructuredFieldValue::getValues($init); $assetArray = StructuredFieldAsset::getAssets($init); $selectedRecordName = displayValue($selectedRecord[3]); // don't show locked record for non-admin users or there is no record name in the URL $lock = $selectedRecord[4];