function apply_template(&$sid, &$character, $template_id) { if (is_valid_template_id($template_id)) { $character->template_id = $template_id; if ($character->Save($sid)) { return true; } } return false; }
include_once "{$INCLUDE_PATH}/engine/validation.php"; include_once "{$INCLUDE_PATH}/engine/templates.php"; global $rpgDB; // Respawn the session. $sid = RespawnSession(__LINE__, __FILE__); // Verify the new name is valid. $name = $_POST['newname']; $err = array(); if (!is_valid_cname($name, $err)) { $title = 'Error'; draw_page('new_badname.php'); exit; } // Verify we got a proper template for the character. $template = (int) $_POST['chartemplate']; if (!is_valid_template_id($template)) { __printFatalErr("Invalid template id."); } // Add the character to the master list. $sql = sprintf("INSERT INTO %s SET cname = '%s', editedby = '%s', template_id = %d, owner = '%s'", $TABLE_CHARS, addslashes($name), addslashes($sid->GetUserName()), (int) $template, addslashes($sid->GetUserName())); $_r = $rpgDB->query($sql); if (!$_r) { __printFatalErr("Failed to update database: {$sql}", __LINE__, __FILE__); } if ($rpgDB->num_rows() != 1) { __printFatalErr("Failed to update character list.", __LINE__, __FILE__); } // Get the character's id (the character should be the most recent character // edited by this profile, and just to be sure, we restrict the select by // cname as well). $_r = $rpgDB->query(sprintf("SELECT id FROM %s WHERE editedby = '%s' AND cname = '%s' ORDER BY lastedited DESC LIMIT 1", $TABLE_CHARS, addslashes($sid->GetUserName()), addslashes($name)));