public static function updateRecord($id, $name, $rank, $lock = 0)
 {
     $thisRecord = StructuredField::readRecord($id);
     if ($name && strcmp($thisRecord[3], $name) != 0) {
         $value[] = "name='" . urlencode($name) . "'";
     }
     if ($rank && $rank != $thisRecord[2]) {
         StructuredField::moveRankUp($thisRecord[1], $rank);
         $value[] = "rank={$rank}";
     }
     if (empty($lock)) {
         $lock = 0;
     }
     $value[] = "adminlock={$lock}";
     // create structured field
     if ($value) {
         $query = "UPDATE structured_field SET " . implode(", ", $value) . " WHERE id={$id};";
         $result = mysql_query($query) or die(sqlError(__FILE__, __LINE__, $query));
     }
     return $rank;
 }
$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':
            $recordArray = StructuredField::getSortedRecords($id);
            if (!$recordArray) {
                $result = "no record for the unit with id={$id}";
            } else {