";
$domainInfo = getDomainInfo($domainId);
global $DBHost, $DBUserName, $DBPassword, $DBName, $RingDBName;
$link = mysql_connect($DBHost, $DBUserName, $DBPassword) or die ("Can't connect to database host:$DBHost user:$DBUserName");
mysql_select_db ($RingDBName) or die ("Can't access to the db dbname:$RingDBName");
// Find out if the character has an open editing session
$query = "SELECT session_id, state ";
$query .= " FROM sessions";
$query .= " WHERE (owner = '".$charId."')";
$query .= " AND (session_type = 'st_edit')";
$query .= " AND (NOT (state IN ('ss_closed', 'ss_locked')))";
$result = mysql_query ($query) or die ("Can't execute the query: ".$query);
$num = mysql_num_rows ($result);
if ($num > 1)
{
echo "Error: more than one editing sessions for char".$charId;
die;
}
$sessionId = 0;
if ($num == 0)
{
// Not found => first, create an editing session for this character, start the session and invite himself
$query = "SELECT char_name FROM characters WHERE char_id = $charId";
$result = mysql_query ($query) or die ("Can't execute the query: ".$query);
$num = mysql_num_rows ($result);
$characterName = "";
if ($num > 0)
$characterName = mysql_result($result, 0, 0);
global $SessionId, $SessionToolsResult;
planEditSession($charId, $domainId, "st_edit", $characterName, "");
if ($SessionToolsResult === false)
die;
startSession($charId, $domainId, $SessionId);
if ($SessionToolsResult === false)
die;
$sessionId = $SessionId;
}
else
{
$row = mysql_fetch_array($result);
$sessionId = $row['session_id'];
$state = $row['state'];
echo "Found your session: $sessionId ($state)
";
if ($state == "ss_planned")
{
// First, start the session
startSession($charId, $domainId, $sessionId);
global $SessionId, $SessionToolsResult;
if ($SessionToolsResult === false)
die ("Failed to start the session");
$sessionId = $SessionId;
echo "edit_session.php : the session have been started
";
}
}
// check that we character have a participation in the session and invite him if needed
mysql_select_db ($RingDBName) or die ("Can't access to the db dbname:$RingDBName");
$query = "SELECT count(*) FROM session_participant WHERE session_id = $sessionId AND char_id = $charId";
$result = mysql_query ($query) or die ("Can't execute the query: ".$query);
$num = mysql_num_rows ($result);
if ($num != 1)
die ("Invalid result whil checking participation for char $charId in session $sessionId
");
$value = mysql_fetch_array($result);
if ($value[0] == 0)
{
// the character have not is own invitation !
echo "Missing participation for character $charId owner of session $sessionId, adding it
";
inviteOwnerInSession($charId, $domainId, $sessionId);
}
echo "edit_session.php : invitation ok
";
// Join the session
joinSessionFromId($userId, $domainId, $sessionId);
?>