« MBS FileMaker Advent … | Home | MBS FileMaker Advent … »

MBS FileMaker Advent calendar - Door 22 - Taking Photos

candy cane Monkeybread Monkey as an elf candy cane
Day 22 - Taking Photos

Our monkey is worried that someone might log in with a coworker account who shouldn't actually have access, like Grumonky the grumpy ex-Christmas elf. Our monkey has come up with a solution. When opening the application, he wants to take a picture of who is sitting in front of the computer and save it in a table.

To record the photo, we use a separate table, which we call User. In this table we have the standard fields that are created directly with the table and also the container field Image in which the recorded image is to be found later. We create the list layout Layout User as shown in the picture:

This layout will not be visible to all users later, but more on that in a moment.

Now we want to write the script that captures the image. This should be called when our file is opened. For this reason, we call the following lines in our data script from door number 3, that is called whenever the first window of the solution opens:

...
New Window [ Style: Card ; Name: "User" ; Using layout: "User" (User) ]
Perform Script [ Specified: From list ; "logging" ; Parameter:    ]
Close Window [ Name: "User" ; Current file ]
...

We now want to write the called script logging. We use the AVRecord functions for this. With these functions we can record audio or video files as well as images. Here, too, we need a reference that we can work with. We get this from the AVRecorder.Init function. We must then define the device with which the image is to be recorded, for which we use the AVRecorder.SetVideoDevice function. In addition to the reference, we have to specify the device here. We can either specify the name of the recording device or the index. As my laptop only has one camera, I have decided to use the first device and have therefore added a 0. To be able to take a picture, we first need a preview. But we don't want to display this in our logging data records. For this reason, we create a second layout for the User table. We now want to display the preview on this layout. We can define this via a control or an exact position. In our case, we select a control and create a rectangle with the name Image in the layout. We can use the function AVRecorder.AddPreviewWithControl. To do this, we first specify the reference and then the window in which the preview should be created. In our case, it is the frontmost window, so we can specify a zero as the index. In addition, we now enter the name of the rectangle, so the name of the control. We now start the preview with the AVRecorder.StartPreview function. This may take a moment. For this reason, we pause the script for 3 seconds. Then we can capture the photo with the AVRecorder.CaptureStillPhoto function.

Set Variable [ $AV ; Value: MBS( "AVRecorder.Init" ) ]
Set Variable [ $r ; Value: MBS("AVRecorder.SetVideoDevice"; $AV; 0) ]
Set Variable [ $r ; Value: MBS("AVRecorder.AddPreviewWithControl"; $AV; 0; "Image") ]
Set Variable [ $r ; Value: MBS("AVRecorder.StartPreview"; $AV) ]
Pause/Resume Script [ Duration (seconds): 3 ]
Set Variable [ $img ; Value: MBS( "AVRecorder.CaptureStillPhoto"; $AV  ) ]

Now, regardless of whether an error occurred when the photo was taken, we want to create a new data record so that we can see that someone has opened the file. To do this, we create a new data record and place the image that we have taken in the Image field. The other fields are created automatically for each data record. After we have finished working, we must also remember to release the references again.

New Record/Request
Set Field [ User::Image ; $img ]
Set Variable [ $r ; Value: MBS( "AVRecorder.ReleaseAll" ) ]

But if our grumpy Christmas elf tries to log in, he could still access all data records at the moment and replace it with another photo. Of course we don't want that to happen. For this reason, we want to make the table for user accounts not changeable and the layout with loging entries not visible. The layout and the table should only be accessible in an account with full access. So we use the FileMaker internal security settings. To do this, we go to File > Manage > Security... and create our user. Then we select new Privilege Set and set the settings. Let's start with the simple settings first. It would be bad if an employee who has no idea about scripts could screw around here, which is why we only allow executive access. Also on the value lists the user does not need changing access and should only be able to view them. We use custom privileges for the layouts. The user should not even be able to view user info. The other layouts can be viewed, but we do not want users to be able to change our layouts. However, so that the user can work with the records, we have to enable the record in some layouts so that the user can change them.

We also have custom privileges for the records, with which the use of the record can be further specified. We do not want the user to be able to delete records, but they can add them and, with the exception of the user table, also change and view them.

Here, too, we have to activate fmplugin in the extended privileges so that our scripts work. We can now run our program and see if Grumonky has perhaps logged in.

I hope to see you again tomorrow for our second-last door.


Monkeybread Software Logo with Monkey with Santa hat
21 👈 22 of 24 👉 23
Claris FileMaker Plugin
22 12 24 - 08:41