The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting Started (totally inexperienced coder here!)
#1
Hello,
I've got UserSpice installed and ready...but don't know where to go from there.

I have an app that allows the user to query it and pulls data from an XML file and some other resources (images, etc.)

I'd like my core app to access different files depending on the ID of the user querying it.

Is there some documentation that would point to a very simple example of this kind of functionality?

Thanks for your time, D
  Reply
#2
So there are a few ways you can tackle this. It basically depends on what sort of logic you want to use.

If you want each individual user to have their own xml file then I would do something along the lines of creating the filename with the userid as the filename.

So you would load that file as
Code:
$filename = $user->data()->id.".xml";

If you want an xml file based on a permission level (and you're not going to have crossovers where people have multiple permission levels, then what I would do is go into the admin permissions table and add your levels, let's just say level1,level2 to keep things simple. If you click on those levels, you'll see that there is an "id" there. That's the id of the permission level. Right now user is 1 and admin is 2, so that would make level1 3, and level2 4.

You could do
Code:
if(hasPerm([3],$user->data()->id)){
Code:
//open this file
Code:
}

Basically, that is checking the logged in user's id and seeing if they have that permission level.

I guess the third thing you could want to do is be able to set the xml file more specifically per user. In that case, you could add a column, maybe called xml varchar(255) into the users table and then put the xml filename that person has access to in the database. You could access that on any page by doing

Code:
$user->data()->xml;

Finally if you are really going to be more random than that, you could make a database table for each xml file and insert the id of the user into that table.

If any of these ideas sound "right" to you, let me know and I can help you follow them through.
  Reply
#3
Over a year later... but just wanted to say thank you for this detailed reply! 
I haven't implemented yet (lack of time) but hoping to have someone assist, who can likely do it faster and better.

Thanks again D
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)