We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40288
    • 4 Posts
    Hi All,

    Is it possible to allow web users to access and download document assigned to them.

    I have all groups and permissions setup and also have a page called 'Statement'. When a web user logs in the 'Statement' page becomes visible. i need to add a statement for each web user and only allow them to see their own statement when logging in.

    any assistance would be greatly appreciated.

    Garth
    • Is the statement a file they uploaded? Or is it created dynamically? One solution might be a snippet on the Statement page that reads the user ID of the current user and then generates a link to that user's file, statement_for_user_id_123.pdf. We would need to know some more info about the files involved.

        • 40288
        • 4 Posts
        hello,

        The file is either a pdf or excel document that the manager will upload, either via ftp or via the manager plugin to a particular folder. Then the user log's in and can download his statement. I have searched but can't find a suitable snippet or module to handle this.

        Thanks
        Garth
        • You can't find a suitable Snippet or Module because it's a custom workflow. wink

          How does the manager associate a given XLS or PDF file with a user? Is it by name? Or by location? E.g. you could create a folder for each user, and then list the files in the folder -- e.g. downloads/123/ where "123" is the User ID. You can override System Settings for each user, e.g. so each user has their own file directory, but I think it'd be simplest to write a Snippet that read the user ID, then listed files from the corresponding directory. The only awkward part of that would be when the manager uploaded the file -- he would have to be very careful to name the folders using the correct IDs.
            • 40288
            • 4 Posts
            At the moment i dont know how i should do the association, hence the reason my this thread smiley

            You mention a snippet to read user id's, that might be the best option.
            Are you able to assist me with writing the snippet? Honestly i wouldn't know where to start.
            Uploading the files to the correct folder and naming them correctly, won't be a problem. There will be no more than 10 users anyway

            Thanks
            • The first snippet you should write will list all the files in a given directory $dir. There are lots of PHP tutorials for that.

              The only thing you'd need to change for the final version of your Snippet is you'll need to dynamically change the path according to the user id. You can use the getLoginUserID() function to get the ID of the user currently logged in:

              $user_id =  $modx->getLoginUserID();


              Hope that helps.