In a certain snippet I want to figure out if a visitor turns out to be a logged-in administrator or other member with page-edit rights on the page. For that check i rented this snippet from EtoGal (and altered it a little.)
function access() {
global $etomite;
$userdetails=$etomite->userLoggedIn();
if($userdetails['id']) {
// check whether user is allowed to modify this page (-> $result1=1)
$rs1=$etomite->dbQuery("SELECT * FROM (" . $etomite->db . "member_groups JOIN " . $etomite->db . "membergroup_access ON user_group=membergroup) JOIN " . $etomite->db . "document_groups ON documentgroup=document_group WHERE member='" . $userdetails['id'] . "' and document='" . $etomite->documentIdentifier . "'");
$result1=mysql_num_rows($rs1);
// check if user is administrator (-> $result2=1)
$rs2=$etomite->dbQuery("SELECT * FROM " . $etomite->db . "user_attributes WHERE id='" . $userdetails['id'] . "' AND role='1'");
$result2=mysql_num_rows($rs2);
if($result1>0 || $result2>0) $access_permitted=1;
else $access_permitted=0;
}
else $access_permitted=0;
if ($access_permitted == 1) return true; else return false;
}
Testing the snippet on an 0.6.1rc3 install gives me the pain in the ass of a non-existing userLoggedIn-object (or something like that; the first evaluation in this quote is not true, so it doesn't have an 'id'-thing.)
Anyone knows what's going on here, and how to handle it?
Edited by pelleke, 17 January 2006 - 05:30 PM.










