This topic is locked

Advice on implementing secure 'rolling notes' functionality

10/30/2019 11:54:45 AM
PHPRunner General questions
G
gtothill author

Hi all,
I am hoping that someone might be able to give me a steer on the best way of implementing a feature in my app.

The app is essentially a case management system in which a user is required to make notes, which, over time, aggregate into a case history.

I'm planning to implement note entry through a simple rich text editor so the first note that is entered is stored in a single large text field or a blob.

Once a note has been entered, it must be impossible for the user to edit the field - in other words it has to be indelible / read only.

Subsequently, when the case is accessed, the user should be able to scroll through previous notes and then, probably in a text input box below that displayed data, enter new notes.

When the user has completed their new notes they will need to be appended to the main notes field along with a date and time stamp and the name of the user who is currently logged in.

My plan for doing this was going to be as follows:

  1. Have a main field in the database to store these text notes - say 'appnotes'
  2. Pre populate that note field on creation with a simple text note which indicates when the notes field was created and then make that field read only.
  3. On first submission of a note from within the application, save the entered text in a temporary database field with an appended date stamp, say 'newnote'. Then make the first field 'appnotes' writable, copy the content from the temporary field and append it to 'appnotes' and then make 'appnotes' read only again. Lastly delete the content of the temporary field 'newnote'.
    Does this seem a reasonable approach or am I over complicating this process? I'm sure that some of you will have seen (and solved!) this problem before.
    Any guidance would be very much appreciated,
    Cheers Geoff.

jadachDevClub member 10/30/2019

Why don't you use a notes table. This way you simply do not allow editing or deleting. Just add the note with a date added and added by.

A
acpan 10/30/2019

Maybe use inline add to a table, remove edit and delete rights.
Main Table: case

Child Table: logs
Inline add child table and keep adding notes.
And a view page when clicked, allows to see and print.
Very standard and basic phprunner function.
ACP

G
gtothill author 10/31/2019

Thanks both,
That's helpful, but I have a question.
If I store multiple individual notes in a table that reference the case that they belong to, how do I go about concatenating all those notes into a single, uninterrupted narrative, that represents all of the activity on the case? Ideally this should look like a single large collection of text that can me scrolled through, rather than having to click through each record in the notes table in sequence. I didn't make it clear in my first post, but this was one of the requirements that drove the approach I suggested. Your help much appreciated. Geoff.

D
DealerModulesDevClub member 10/31/2019

Take a look at GROUP_CONCAT() in MySQL, it may help with what you are trying to achieve.
Maybe something like:
SELECT GROUP_CONCAT(column1 SEPARATOR '\n') FROM table1;
Paul

A
acpan 11/1/2019

I can think of 2 methods:

  1. Easiest maybe, use PHPRunner 10 Page Designer to edit the view, drag and drop, remove lines etc,

    and make it present the child rows as different "paragraphs". Assign the view to your user.
  2. Another way, before PHPR Page Designer exist, is to create a separate SQL views, and use SQL group concat statement and group the logs entries into one block of text as what Paul suggested.
    a bit more details:
    Case Table (Master Table)
    id | user_id | case_name | date

    1 | 1234 | Something Happen | 12/12/2018
    Logs Table (Detail/Child Table)
    id | user_id | case_id | log_text | date_log

    ....

    10 | 1234 | 1 | Some updates 1 | 12/12/2018 12:12:20

    11 | 1234 | 1 | Some updates 2 | 13/12/2018 12:12:20

    12 | 1234 | 1 | Some updates 3 | 14/12/2018 12:12:20
    Eg:
    SELECT

    GROUP_CONCAT(log_text

    ORDER BY id ASC

    SEPARATOR '\n\n')

    FROM

    logs

    WHERE user_id = $SESSION["UserID"] and cases_id = 1;
    Result =>
    "Some updates 1\n\nSome updates 2\n\nSome updates 3"
    In HTML view, it appear as:
    Some updates 1
    Some updates 2
    Some updates 3
    Beware when you use MySQL group_contact for large text, you may need to expand group_concat_max_len variable in mySQL server, otherwise the text will be truncated.

    mysql group_concat_max_len
    Hope it helps.
    ACP

A
acpan 11/1/2019

One other method,which is most straight forward.
create a dummy field in your sql for update entry form, once user enter updates, you append to the master log field in before update event, and unset the dummy field.
ACP

M
MikeT 11/1/2019

Another idea: you could have notes_concatenated field in your main table that is read only in the frontend/user interface.

For the db schema I would stay with the one already suggested: case table and case_notes table.
Then you could use a server side trigger & procedure that writes a concatenated version of all case notes to the case table's read only "notes overview" field.

To add new notes you could use a dummy field in the case table and a "save" button, when pressed write a new note to the notes table with button code, which would then trigger the above mentioned db-server code to do its thing.

(to immediately see the new note in the concatenated field you'd probably have to reload the record or field).
Might give some better performance for browsing cases since you wouldn't have to include the notes table at all to display/add notes, but it might not matter.
(I'm probably just too obsessed with doing things server side ;-)).
P.S.: essentially a more complicated version of what acpan wrote above. Personally and of course depending on requirements I would think twice if you ever need to do things with individual notes, like ordering them in a different way / adding fields (like flags) to the notes etc.

For this reason I'd probably use a separate notes table to stay more flexible.

G
gtothill author 11/7/2019

Excellent!
Thanks to you all for taking the time to write such detailed and thoughtful replies. They are all most appreciated and give me several different approaches which I can build into a beta of the system.
There are several suggestions and bear traps that you have each pointed out that I would not have seen and so you have saved me a great deal of time.
I'll let you know how I get on by way of further feedback and in the hope it will help anyone else who has this challenge in their projects.
Geoff.