function complete_if_needed() { global $auto_restrict, $default_language; $save = false; if (!$auto_restrict) { return false; } $indexes_to_check = array('lang' => $default_language); $first = first($auto_restrict['users']); foreach ($auto_restrict['users'] as $user => $data) { foreach ($indexes_to_check as $index => $default_value) { if (empty($data[$index])) { $auto_restrict['users'][$user][$index] = $default_value; $save = true; } if (empty($data['status'])) { $auto_restrict['users'][$user]['status'] = create_status($user, $first); $save = true; } elseif ($data['status'] != 'superadmin' && $data['login'] == $first['login']) { $auto_restrict['users'][$user]['status'] = 'superadmin'; $save = true; # force first status to superadmin } } } if ($save) { save_users(); return true; } return false; }
$reply = success(); $reply->id = insert_id(); echo json_encode($reply); } function create_status($req) { $source = source_lookup_auth($req->authenticator); if (!$source) { error("auth failure"); return; } $req->source_id = $source->id; if (!status_insert($req)) { error(db_error()); return; } $reply = success(); $reply->id = insert_id(); echo json_encode($reply); } $req = json_decode($_POST['request']); switch ($req->operation) { case 'create_observation': create_observation($req); break; case 'create_status': create_status($req); break; default: error("unknown op {$req->operation}"); }