Merge branch '164-crash-on-patching-and-possibly-right-after-login' into 'main/atys...
[ryzomcore.git] / nelns / admin / public_html / init.php
bloba9c58139341256e600f6684f42484ea62e768e29
1 <?php
2 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
3 // Copyright (C) 2010 Winch Gate Property Limited
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 function retrieveTable($tableName, $key, $whereClause="", $selectClause="*")
20 $result = sqlquery("SELECT $selectClause FROM $tableName".($whereClause=="" ? "" : " WHERE ".$whereClause));
21 while ($result && ($arr = sqlfetch($result)))
22 $dataArray[$arr[$key]] = $arr;
23 return $dataArray;
27 // retrieve users info
28 $usersData = retrieveTable("user", "uid");
29 //$usersData = retrieveTable("user", "uid", "uid='$uid' OR uid='$gid'");
30 $userData = $usersData[$uid];
31 $userData['groupname'] = $usersData[$userData['gid']]['login'];
33 // retrieve variables info
34 $variableData = retrieveTable("variable", "vid");
36 // retrieve user variables
37 $uservariableData = retrieveTable("user_variable", "vid", "uid='$uid' OR uid='$gid'");
39 // retrieve shard list info
40 $shardList = retrieveTable("service", "shard", "", "DISTINCT shard");
42 // retrieve shard access info
43 $shardAccess = retrieveTable("shard_access", "shard", "uid='$uid' OR uid='$gid'", "DISTINCT shard");
46 function getUserVariableRights($uid, $gid)
48 // get default variable state
49 $result = sqlquery("SELECT vid, state FROM variable");
50 while ($result && ($array = sqlfetch($result)))
52 $uservariablerights[$array["vid"]][0] = 1;
53 $uservariablerights[$array["vid"]][1] = $array["state"];
56 // override from group settings
57 $result = sqlquery("SELECT vid, privilege FROM user_variable WHERE uid='$gid'");
58 while ($result && ($array = sqlfetch($result)))
60 $uservariablerights[$array["vid"]][0] = 2;
61 $uservariablerights[$array["vid"]][2] = $array["privilege"];
64 // override from user settings
65 $result = sqlquery("SELECT vid, privilege FROM user_variable WHERE uid='$uid'");
66 while ($result && ($array = sqlfetch($result)))
68 $uservariablerights[$array["vid"]][0] = 3;
69 $uservariablerights[$array["vid"]][3] = $array["privilege"];
72 return $uservariablerights;
75 $userUserVariableRights = getUserVariableRights($uid, $gid);
77 function hasAccessToVariable($vid)
79 global $userUserVariableRights;
81 $var = &$userUserVariableRights[$vid];
82 return isset($var) && $var[$var[0]] != "none";
85 function getVariableRight($vid)
87 global $userUserVariableRights;
89 $var = &$userUserVariableRights[$vid];
90 return $var[$var[0]];
93 function getShardLockState()
95 global $shardLockState, $uid, $REMOTE_ADDR, $enablelock, $shardList;
96 global $ASHost, $ASPort;
98 $shardLockState = array();
100 if (count($shardList) > 0)
102 foreach ($shardList as $shard => $s)
104 $shardLockState[$shard]['lock_state'] = ($enablelock ? 0 : 1);
108 $result = sqlquery("SELECT * FROM shard_annotation");
109 while ($result && ($arr=sqlfetch($result)))
111 if ($enablelock)
113 if ($arr['lock_user'] == 0)
115 $lockState = 0; // unlocked
117 else if ($arr['lock_user'] == $uid && $arr['lock_ip'] == $REMOTE_ADDR)
119 $lockState = 1; // locked by user
121 else
123 $lockState = 2; // locked by another user
126 else
128 $lockState = 1;
131 $shardLockState[$arr['shard']] = array( 'user_annot' => $arr['user'],
132 'annot' => htmlentities($arr['annotation'], ENT_QUOTES),
133 'post_date' => $arr['post_date'],
134 'lock_user' => $arr['lock_user'],
135 'lock_ip' => $arr['lock_ip'],
136 'lock_date' => $arr['lock_date'],
137 'lock_state' => $lockState,
138 'ASAddr' => $arr['ASAddr'],
139 'alias' => $arr['alias']);
143 getShardLockState();