Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / ring / edit_session.php
blob4fef395208ae46d9bc19dfc6e44d5944d34a54e5
1 <?php
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');
8 $domainId = -1;
9 if (!validateCookie($userId, $domainId, $charId))
11 echo "Invalid cookie !";
12 die();
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);
32 if ($num > 1)
34 echo "Error: more than one editing sessions for char".$charId;
35 die;
38 $sessionId = 0;
39 if ($num == 0)
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);
45 $characterName = "";
46 if ($num > 0)
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)
54 die;
55 startSession($charId, $domainId, $SessionId);
56 if ($SessionToolsResult === false)
57 die;
58 $sessionId = $SessionId;
60 else
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);
83 if ($num != 1)
84 die ("Invalid result whil checking participation for char $charId in session $sessionId<br>");
85 $value = mysqli_fetch_row($result);
86 if ($value[0] == 0)
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>";
95 // Join the session
96 joinSessionFromId($userId, $domainId, $sessionId);