Displaying user data in Power Grid CSV
In Sitelok V5.9 we added a new API function, slapi_getuserdata(), which can retrieve data for users who match certain conditions. One feature of the function is that it can generate a CSV file from the data which is compatible with Joe Workman's Power Grid CSV stack https://www.weavers.space/stacks/power-grid-csv
Here is an example use to display a table showing the username, name & email of members of the GOLD usergroup.
1) Secure your page using Sitelok in the usual way and add the Power Grid CSV stack.
2) We need to generate and store the CSV file in a secure folder as in most cases the user data will not be public. Sitelok already has a secure folder that you can use where backup files are stored which can be used. Go to Tools - Configuration - Install paths and copy the Full file path to backup folder to the clipboard.
3) Set the path and a file name (like users.csv) into the Power Grid CSV stack's CSV file path setting. For our example
/home/account/public_html/slbackups_dy7843rg4367/user.csv
4) Add an HTML stack on your page above the Power Grid CSV stack and paste in this snippet
<?php if (function_exists('slapi_getuserdata')) { $params=array(); $params['usergroups']="GOLD"; $params['fields']="username,name,email"; $params['csvfile']="/home/account/public_html/slbackups_dy7843rg4367/users.csv"; $params['csvheader']="Username,Name,Email"; $params['csvrefresh']="300"; slapi_getuserdata($params); } ?>
replacing the path to the file with your path.
Caching
The $params['csvrefresh'] setting determines how long the CSV file is cached (before it gets updated). In our example we have used 300 seconds (5 minutes) which means that the table only gets refreshed if it's older than 5 minutes. You can set csvrefresh to 0 for no caching if you wish.
Further information
The slapi_getuserdata function has a large number of options which you can read about in the Sitelok API section of the manual.