If you’ve had trouble setting a new user’s access rights “by Section”, there are a few counter-intuitive steps that need to be added to the process.
If you look at the sample signup form in the Website Membership Plugin version1.10, you’ll find this block of code.
// NOTE: You can repeat this block to grant access to multiple sections mysql_insert('_accesslist', array( 'userNum' => $userNum, 'tableName' => '_sample', // insert tablename you want to grant access to, or 'all' for all sections 'accessLevel' => '0', // access level allowed: 0=none, 6=author, 9=editor 'maxRecords' => '', // max listings allowed (leave blank for unlimited) 'randomSaveId' => '123456789', // ignore - for internal use )); }
SETTING ‘BY SECTION’ ACCESS RIGHTS You'll first have to set the access permission for that user to By Section, to allow you to set the user's permissions for individual sections.
Copy the code block above, and in the first copy of the code on the page, set the tableName to 'all', and the accessLevel to '1' (which means ‘By Section’), like this:
mysql_insert('_accesslist', array( 'userNum' => $userNum, 'tableName' => 'all', // insert tablename you want to grant access to, or 'all' for all sections 'accessLevel' => '1', // access level allowed: 0=none, 6=author, 9=editor // 'maxRecords' => '', // max listings allowed (leave blank for unlimited) 'randomSaveId' => '123456789', // ignore - for internal use ));
Notice that the maxRecords has been commented out. According to Daryl Maximo, a programmer at Interactive Tools, "This is because unless there’s a number in the maxRecords value, the value will actually be set to '0'" If that happens, you won't get the result that you're expecting, or an error will be thrown and the access levels won’t be set at all.
SETTING ACCESS RIGHTS FOR INDIVIDUAL SECTIONS Now that access by section has been set, the next code blocks can set the individual section access rights. My example below sets the access rights to the section tableName ‘listing’ for this new user to only those records where they are the Author (6). Use as many copies of this code block required to set each one of your section access scenarios.
Again, be careful about that maxRecords value. If you want to allow unlimited records, just comment out the line by putting a double forward slash // in front of it.
mysql_insert('_accesslist', array( 'userNum' => $userNum, 'tableName' => 'listing', // insert tablename you want to grant access to, or 'all' for all sections 'accessLevel' => '6', // access level allowed: 0=none, 6=author, 9=editor 'maxRecords' => '1', // max listings allowed (leave blank for unlimited) 'randomSaveId' => '123456789', // ignore - for internal use ));
So the complete code for the page would be:
<?php header('Content-type: text/html; charset=utf-8'); ?> <?php // load viewer library $libraryPath = 'cmsAdmin/lib/viewer_functions.php'; $dirsToCheck = array('/path_to_your_serverl/','','../','../../','../../../'); foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }} if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load records from 'accounts' list($accountsRecords, $accountsMetaData) = getRecords(array( 'tableName' => 'accounts', 'loadUploads' => true,
));
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>access-update2</title> </head>
<body> <?php foreach ($accountsRecords as $record): ?> <?php
$accountsRecords = mysql_select(accountsTable(), 'isAdmin != 1'); foreach($accountsRecords as $record){ $userNum = $record['num']; mysql_insert('_accesslist', array( 'userNum' => $userNum, 'tableName' => 'all', // insert tablename you want to grant access to, or 'all' for all sections 'accessLevel' => '1', // access level allowed: 0=none, 6=author, 9=editor //'maxRecords' => '', // max listings allowed (leave blank for unlimited) 'randomSaveId' => '123456789', // ignore - for internal use ), true); // NOTE: You can repeat this block to grant access to multiple sections mysql_insert('_accesslist', array( 'userNum' => $userNum, 'tableName' => 'lm_listing', // insert tablename you want to grant access to, or 'all' for all sections 'accessLevel' => '6', // access level allowed: 0=none, 6=author, 9=editor //'maxRecords' => '', // max listings allowed (leave blank for unlimited) 'randomSaveId' => '123456789', // ignore - for internal use ), true); } ?> <?php endforeach ?> </body></html>
|