News:

CPG Release 1.6.29
During HTML5 upload, keep pseudo blank code 200 messages from triggering error condition
added Russian language
correct failure to use theme menu icons in album manager
minor vulnerabilities mitigation

Main Menu

Can admin assign pid?

Started by treehstn, August 09, 2026, 08:59:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

treehstn

I have a situation where I'm building a large multifaceted system using several programs which uses Coppermine for the images.  I need a field that is a unique image ID but I want to be able to say what the prefix is.  It might be something like FAM-PH-0000001. There will be multiple Coppermine databases so another might have the prefix of FAM-REC-0000001 or FAM-BIO-0000001. It's important that the ID's be unique across the database and the user's should not have access to add or change that field.  But it does need to be viewed on the image view by anyone looking at it. Ideally the number would be automatically assigned to each photo as they are being uploaded but if I have to go in manually and add them as images are loaded that would work also.

I tried to find the pid in the database and couldn't locate it.

Is this possible? Maybe by using one of the custom fields in the image description but I'd have to be able to limit who can change that field...

ron4mac

It's not totally clear to me what you are looking to accomplish. The 'pid' is an integer value that is entered in the database for each file that is added to the gallery. Am I correct in guessing that you want a value saved somewhere, for each uploaded image, that consists of some prefix followed by the 'pid', as recorded in the database? Example: FAM-BIO-<Db pid>
Having that happen automatically could only happen with some crafted plugin.

I think a plugin that automatically adds that value to the user4, for example, database field might work. There is a plugin that can show that field along with the thumbnail display.

treehstn

I need a unique ID number added to every uploaded file.  It needs to be in a certain format, i.e. something like FAM-PH-00001.  This number will never change. It would be ideal if the system added them itself as long as they were in a pre-determined format.  Users should be able to see the numbers on each photo but shouldn't be able to change them.  The admin should be able to change them but if working properly should not have to. 

I wasn't sure if the pid number might work but only if I could change the format of the number so that it had whatever prefix was needed for that database.  This project is going to have multiple databases. 

406man

#3
Having written a few plugins my view is that the pid (Picture ID) is too widely used to risk changing it and in any case its data type is integer so you are restricted to a number. It's not possible to use this for something like "FAM-REC-0000001" as it's the wrong data type.

Instead, I think there might be a realistic solution in changing the file name. This could include your unique identifier in some way. The file name would be changed when uploading the image. There is a plugin hook "upload_file_name" which allows you to add your own code in the right place. There are numerous places where CPG displays the file name automatically so this might provide what you need.

Another possibility is to use the add_file_data plugin to manipulate the information stored when an image is uploaded. For example adding your unique identifier as a prefix to the Title field. This will clearly show the identifier in the Title when an image is displayed.

We can guide you if you need help with creating a plugin.

treehstn

Thank you for the info!  Do you think there's any chance the "upload_file_name" plugin hook could add the unique identifier to the beginning of the user's file name so there would be both in that field?

406man

Here's the long answer to your question. A plugin hook is just a place where a custom-written PHP function - a plugin - is called.

Here's an example of a plugin call which I took from line 301 of uniload.php

$picture_name = CPGPluginAPI::filter('upload_file_name', $picture_name);
The plugin being called allows you to manipulate the file name of the image and it's definitely possible to add a prefix to the existing file name. Your plugin PHP code will include something like this in its main file of PHP code - codebase.php

function myplugin($picfilename) {
    $picfilename = `prefix` . $picfilename;
    return $picfilename;
}
There's a lot more to a plugin than just the above. The prefix has to come from somewhere, for example. Hopefully it helps with explaining some of the basic principles.

Plugins are documented here:
https://coppermine-gallery.com/docs/curr/en/dev_plugins.htm

Plugin hooks are here:
https://coppermine-gallery.com/docs/curr/en/dev_plugin_hooks.htm

ron4mac

If that method (prefix on the filename) will work for what you are tying to do, I will build a suitable plugin that you will be able to use. Let me know .. and then give me a few days to put it together.

treehstn

Quote from: ron4mac on Today at 03:28:40 PMIf that method (prefix on the filename) will work for what you are tying to do, I will build a suitable plugin that you will be able to use. Let me know .. and then give me a few days to put it together.

I'm going to need a couple of days at most for me to work through if this will work.  That is just fantastic that you'd be willing to do this!  I am no web programmer for sure and would just be fumbling through trying to do it on my own.  I really appreciate it!  I'll let you know as soon as I'm sure it will work for what I'm doing.

Thank you!!