2 require_once('../tools/validate_cookie.php');
3 include_once('../login/config.php');
4 include_once('../tools/domain_info.php');
5 include_once('join_session.php');
6 include_once('session_tools.php');
9 if (!validateCookie($userId, $domainId, $charId))
11 echo "Invalid cookie !";
15 echo "edit_session : user id = '$userId', char = '$charId', domain = '$domainId'<br>";
17 $domainInfo = getDomainInfo($domainId);
19 global $DBHost, $RingDBUserName, $RingDBPassword;
21 $link = mysqli_connect($DBHost, $RingDBUserName, $RingDBPassword) or die ("Can't connect to database host:$DBHost user:$RingDBUserName");
22 mysqli_select_db($link, $domainInfo['ring_db_name']) or die ("Can't access to the db dbname:" . $domainInfo['ring_db_name']);
24 // Find out if the character has an open editing session
25 $query = "SELECT session_id, state ";
26 $query .= " FROM sessions";
27 $query .= " WHERE (owner = '".$charId."')";
28 $query .= " AND (session_type = 'st_edit')";
29 $query .= " AND (NOT (state IN ('ss_closed', 'ss_locked')))";
30 $result = mysqli_query($link, $query) or die ("Can't execute the query: ".$query);
31 $num = mysqli_num_rows($result);
34 echo "Error: more than one editing sessions for char".$charId;
41 // Not found => first, create an editing session for this character, start the session and invite himself
42 $query = "SELECT char_name FROM characters WHERE char_id = $charId";
43 $result = mysqli_query($link, $query) or die ("Can't execute the query: ".$query);
44 $num = mysqli_num_rows($result);
48 $row = mysqli_fetch_assoc($result);
49 $characterName = $row['char_name'];
51 global $SessionId, $SessionToolsResult;
52 planEditSession($charId, $domainId, "st_edit", $characterName, "");
53 if ($SessionToolsResult === false)
55 startSession($charId, $domainId, $SessionId);
56 if ($SessionToolsResult === false)
58 $sessionId = $SessionId;
62 $row = mysqli_fetch_assoc($result);
63 $sessionId = $row['session_id'];
64 $state = $row['state'];
65 echo "Found your session: $sessionId ($state)<br>";
66 if ($state == "ss_planned")
68 // First, start the session
69 startSession($charId, $domainId, $sessionId);
70 global $SessionId, $SessionToolsResult;
71 if ($SessionToolsResult === false)
72 die ("Failed to start the session");
73 $sessionId = $SessionId;
75 echo "edit_session.php : the session have been started<br>";
79 // check that we character have a participation in the session and invite him if needed
80 $query = "SELECT count(*) FROM session_participant WHERE session_id = $sessionId AND char_id = $charId";
81 $result = mysqli_query($link, $query) or die ("Can't execute the query: ".$query);
82 $num = mysqli_num_rows($result);
84 die ("Invalid result whil checking participation for char $charId in session $sessionId<br>");
85 $value = mysqli_fetch_row($result);
88 // the character have not is own invitation !
89 echo "Missing participation for character $charId owner of session $sessionId, adding it<br>";
90 inviteOwnerInSession($charId, $domainId, $sessionId);
93 echo "edit_session.php : invitation ok<br>";
96 joinSessionFromId($userId, $domainId, $sessionId);