Auto edit MySQL data after a given time - mysql

We have a form which is stored in draft mode. That means editing any data or deleting the entire form is possible. The beginning to end process is as follows
When a person tries to submit the form for the first time, that is stored in draft. (the isDraft column is set to 0)
The user is redirected to another page where s/he can view the Form id (a generated number), name, a few other details and Edit/Delete options.
The user can click edit button to edit anything, or even delete the form.
However this will be allowed till a given date (say 15 days from the first submission date). Once that date is passed, the form can no longer be edited or deleted. In case the form isn't deleted, the isDraft column is set to 1.
Thousands of people can submit the form . So ,it is not possible to do it manually.
Our project is done using Laravel v6.2, but I want a general idea as well .
I can use a trait or ajax on the master page, but that is too risky and also, server inaccessibility can delay the process, and some users may get an advantage.
How to do it?
If there is no concrete answer, but rather only discussion , I will remove this post

Just store the date (time component depends on how accurate you want to be when you check the 15 day interval) when the form is created as draft.
When a user wants to edit it (display the edit form) or save an edit, compare the current date (and time) with the stored creation date + 15 days. If the current date is less than the creation date + 15 days, then allow the display of the edit form or save the form, otherwise display an error message.

Not sure if I understand it correctly, but I think you like to update the updated_at timestamp automatically. You can run through the Eloquent Models by create a command and just call the save Method on them.
$model->save()

Related

Unable to Save Due to Record Locking (by Current Machine)

Updated***
To quickly summarize what I said before which was lengthy and probably too roundabout confusing...
My issue was I have a main form interface with 2 subforms that does the following:
the First one is always shown for current daily event task(s) based on a label control with current date or any given dates via the prev/next toggle buttons as criteria.
The second one is part of the main subform that will be called based on the selection from the main navigation controls. This subform shows all the event tasks that are created in the database.
Both use saved query select statements with a snapshot and no record lock as recordsource in a continuous form. The table source is linked via split database in the same shared network drive and the table itself contains only 8 fields:
ID (12 chars randomly generated with specific sequence via VBA with no duplicate allowed)
Event Name (Text)
Event Desc (Long Text/Memo)
Occurrence (Text)
Start Date (Date)
Selected Day (Text)
Allow Weekend (Text)
Active (Boolean)
To edit a selected record, it will be called and populated onto a popup unbound model form via VBA. Here everything works fine as for records with fewer chars found in the Event Desc field. However, for records with a large number of chars (so far those that I noticed with issues were the ones with >4000 chars). I can call and display them fine to the detail view form (unbound) but when making edits, by the time it gets to the updating field for Event Desc, it would generate the record locking error by the same user (me) for those with large text size.
After several trials and errors, I noticed it has to do with the displayed continuous subforms that I have presenting. I noticed that the form for them were originally set as dynaset to which I tried to switch over to snapshot and it was a hit and miss (mostly miss). I don't know how much of this setting was an issue to the record updating as I had no problem saving records with smaller character counts.
Finally, I decided to before saving the record, I went and remove the recordsource for both of the continuous forms to empty ("") then save then reassign the query (saved or direct doesn't matter) and it worked without errors after. I personally don't like doing it this way as it makes the continuous forms update look ugly and not smooth (see the #Name?) in the assigned controls due to unrecognized control source since the recordsource is now empty. However, this was the best way that I could think up at the moment.
I even tried using a bounded form for editing the record instead of the unbound form and the same error outcome, but that time it gave a different record locking error# but pretty much for the same reason.
I'm sure this issue is not related to how my VBA code was written nor the queries used in the continuous forms. It's most likely the form settings themselves or just some limitation of Access?

Use an Access 2010 form based on 1 table to enter data in a linked table

First of all, I am a total NOOB! I am trying to make an Access DB for handling orders through an entire process. As such, I have created tables based on each of the individual processes. The order data, which holds only the basic information is in tblCurrentOrders. Each of the other processes is linked to tblCurrentOrders by the OrderNumber field. The first step of the process is due date information is entered in the tblPlanner table. Obviously, until data is entered in tblPlanner, no OrderNumber exists (this will hold true for the other tables, too, if I ever get that far).
I want to create a form based tblCurrentOrders that shows only the records without corresponding entries in tblPlanner (new orders) and then I want to be able to enter the tblPlanner info in a subform. I have tried making a form based on tblCurrentOrders with a subform based on tblPlanner, but I can't figure out how to only display new orders. I also tried basing the form on a query that only showed new orders, but I don't know how to make the subform based on tblPlanner to work.
Please Help!!
Well, the easiest way to link the tables would be to create your OrderNumber in the tblPlanner when you start a new order. Then add a flag and timestamp as to whether it's "released" yet.
EDIT
Since you provide a little bit more detail, I'll edit my response to more closely align for your desired approach.
Creating a "New Order" is a multi-step process. So it's usually best to create a Command Button on a form that calls VBA code. This will allow you to control each step and make sure it's correct.
Step A: First you want to:
1) Create a Control Form (if you haven't already) that allows you to put Command Buttons which will launch different VBA code or open different display Forms.
2) On the Control Form, create a List Box that allows you to select an existing OrderNumber.
3) On the Control Form, create a Command Button to open an Order Form which uses the selected List Box OrderNumber. When that Order Form opens, it will populate with the tblCurrentOrders data for that OrderNumber and also populate the subform with tblPlanner data. (As long as you have them linked properly.)
4) On the Control Form, create a Command Button to open the Order Form with a set of records which are "New Orders" only. See the more detailed process below in Step C.
5) On the Control Form, create a Command Button to Launch VBA code that will create a "New Order". This is a multi step process detailed below in Step B.
6) Create any other buttons or controls that allow you to monitor or advance your "Order" along the way to completion. (This is a ton of work to get all the pieces in place.)
Step B: When you press the Command Button to create a "New Order" you want to create VBA code that will:
1) Create a new record in the tblCurrentOrders table.
2) Create a Unique OrderNumber on the new Record. It's usually best if you control the generation of this number and don't just let it be a system generated sequence number. But whatever you desire is ok as long as it's Unique.
3) Set your ReleasedFlag to false on the new tblCurrentOrders record.
4) Make sure your ReleasedTimeStamp is null. (Or whatever value you want it to be.)
5) You may want a CreatedTimeStamp which you can populate with a date of Now().
6) Populate any other "Initalization" fields that need to be filled. (Like Backorder status, Return flags, Shorted Flags, etc. etc. etc.)
7) Create a new record in the tblPlanner table.
8) Copy the Unique OrderNumber that you created for the tblCurrentOrders record into the OrderNumber field on the new tblPlanner record. This creates a link for you to use with your subqueries and subforms.
9) Now you can open the Order Form with this new OrderNumber.
Step C: When you press the Command Button to open a set of records which are "New Orders" only:
The Command Button needs to launch a query to find "...tblCurrentOrders that shows only the records without corresponding entries in tblPlanner (new orders)":
You just need to select tblCurrentOrders that have a ReleasedFlag set to false.
`SELECT * FROM tblCurrentOrders WHERE ReleasedFlag = false`
So when you say: "...and then I want to be able to enter the tblPlanner info in a subform"... you can create a subform linking to tblPlanner based on the tblCurrentOrders OrderNumber field.
This is all reliant on you observing that when you say "...records without corresponding entries in tblPlanner..." That you really mean: records without released entries in tblPlanner. And that means: in order for a record to exist in tblCurrentOrders, it has to have a corresponding blank (or starter) record created in tblPlanner. Thus now you can display blank tblPlanner records that are linked to unreleased tblCurrentOrders records.
Then once your data entry people are done monkeying around with the New Order, they can "Release" the order (usually by clicking on a Release Command Button). At that point, you can set your ReleasedTimeStamp to Now() and set your ReleasedFlag to True in the tblCurrentOrders. It's officially no longer a "new order" and is now a live order in your system.
You are at the tip of the iceberg for creating a home grown order entry system. The complexities for building a good one are immense. Best of luck figuring it all out. Just remember to use time stamps and ID fields so you can go back and un-do what may have been done by accident.
Hope this all helps. :)

MySQL/PHP - change status depending on date

I have a MySQL Table, let's say for blog posts. They have a column status which cam be active or inactive and two columns which are optional: publish date and expire date for scheduling posts.
Which solution do you recommend for changing the status depending on the publish date and expire date? Can I do this with a PHP script or cronjob ?
EDIT 30.11.16 / 16:50
Perhaps I have to be more precise about my specific problem: I have a magento store and I would like to add the possibility to schedule teasers. I want to change the existing code as little as possible.
I would say, it depends, but as #ADyson sad you should't only work with a cronjob, because it show some posts that should have been expired.
But you think about to write a single class/function that handle the status and expiration / publish date logic. It will be a mess later, if you have the code copy in the cronjob and on different output pages.
I also would think about the status field, maybe it is not necessary, if you make some MySQL Selects like
...
WHERE publish_date>now() AND expire_date<now()

How Do I Make a Subform Controlled by Report (Which is Controlled by a Query) Update After Records Are Added?

I recently took a duty position that requires me to track our administrative actions. Previously, the office had tracked them on an Excel spreadsheet, and the historical data was corrupted/missing. So I have built a database in Access 2010. I designed the database to display a main form that provides an overview of each action, but decided to require most of the data to be added or updated on specific data entry forms. My question relates to two subforms on the main form that I cannot get to update after data is entered into the tables. Here are specifics:
1) The main form is the case detail form, and each case has a unique case ID number that links most of the forms and tables.
2) The Case Detail Form has two subforms. One displays the names of the people involved in the case (this is the Subject Subform). The other displays the case history entries (this is the Case History Subform).
3) Both of the subforms are supposed to work the same way. Each is populated by a report which displays the information in its corresponding Subform. In turn, the reports underlying each Subform are based on a query that selects the records to display based in the case number.
4) New data for the subforms cannot be entered on the Case Details Form. Instead, the user can press a command button which launches a separate form that allows the user to enter either subject details or to enter a case history update. Once the user enters the data, he or she clicks A Save Record button, which saves the record and closes the form window. Everything seems to work fine up to this point.
5) However, I've now been working on this project for two weeks (as time permits), and I am still not able to make the two subforms update automatically. If it's a new case record, the user can make the Subforms update by using the navigation arrows to leave the main Case Details Form and then returning to it. If it's an established case record, a refresh button that I have added to the main Case Details form will cause the two subforms to update.
As I've tried to make this work, I've tried a number of approaches that I've found on various boards. Right now, I have:
A) The Subject data entry form has a Me.Requery statement in After Insert Event Procedure
B) The Subject data entry form has a SaveRecord and a CloseWindow command that are executed when the Save Record Button On Click event is triggered.
C) The main Case Detail Form has a executes a Me.Case_Subjects.Form.Requery when the GotFocus Event Procedure is executed.
I apologize for the lengthy question and explanation. I'm an Army officer and a little out of my depth with this. I would greatly appreciate any help anyone might be able to offer.
Best regards!
I'm not sure having understood everything but I try to give you some suggestions about what to try.
If I'm not wrong both form and subforms have the case ID as field so when you created the report you should have put them in "link" by the wizard (you can set it manually after but it's a bit more tricky).
Did you do this? This makes the form / subforms update when you navigate them.
Please note that there must be a relation between the underlaying tables to guarantee that the reports / forms moves together!
This applies to the query too, just remember to include the ID field int the queries.
If you don't want to see the ID (in case you use an autonumbering id) you can set it Not Visible.
In case you don't want to link the two tables with a relation there is another solution but it's a bit more tricky and, if it's not your case, I don't want to make confusion.
Let me know if you solved.
Bye
Firstly, the line Me.Requery should be on the After Update event, not the After Insert event. Secondly, you will then need to change Me.Requery to Me.[insertsubformname].Requery.
As the user above said, you will need to ensure that you have created your database relationships properly, however if you used the Insert Subform, it should've asked you what you wish to use as your link between the forms.

Is the timestamp for a Google Form response event always the same as the timestamp in the linked spreadsheet?

if I get a timestamp for a Google Form submit event, using for example:
var timestamp = event.response.getTimestamp();
a time is returned e.g.
Fri Sep 26 17:54:02 GMT+12:00 2014
and in the linked spreadsheet the timestamp
is displayed in column one.
Are both timestamps always identical (i.e. is the event timestamp passed to the spreadsheet) or can they be different and the timestamp on the spreadsheet is actually the timestamp of the write to the spreadsheet?
Background: I'm making an application where when a form is submitted an email is sent to the person who has filled in the form with a confirm link. Using a query url and a webapp on the form's linked spreadsheet I can get the parameters from the query url. I now need to have a unique id to find the entry in the spreadsheet in order to to mark it as 'confirmed'. Timestamps seem a suitable way of doing this, but better ways may exist.
Thanks in advance,
Trevor
There doesn't appear to be any documentation or confirmation on this, but from my experience, the timestamp is not the time that the sheet is written to. I believe it's the form submit time, but I can't confirm that for you.
From reading your requirements however, it sounds as though there's the potential for failure as the timestamps won't be unique, and it's possible two people will submit the form simultaneously (though depending on the popularity of the form, this may be slim).
If you need a Unique ID for each entry to just confirm it was submitted, but don't need it for anything else, have you considered logging the 'Edit response URL'? That's unique to each submission, so there's no danger in mixing up submissions.
Thanks for the suggestion. Further experimentation showed that occasionally the timestamps were different at most by a second. I suspect that the event times are for submitting the form and writing to the sheet.
I've found a more elegant solution that works well. The form has a field for last name. I've attached the onformsubmit trigger to the spreadsheet that receives the form responses. By getting the current unix time in milliseconds and concatenating it to the lastname (eg.storr1411790175312) I have a unique ID to pass to the query string that is a link in the email. Further, I write the unique ID value to the correct row in the receiving spreadsheet by using the event range method, e.range, which will always return the range that triggered the current event. As the unique ID is generated once and used in both the email and the spreadsheet it is internally consistent.
Cheers
Trevor
I figured it out.
The value of event.response.getTimestamp() is same as the timestamp in linked spreadsheet.
This is because...
It seems that spreadsheet also stores timestamp in milliseconds.
If you set custom cell format to
yyyy"/"mm"/"dd" "hh":"mm":"ss":"000
you can finally make milliseconds to appear.
If you don't explicitly display milliseconds, spreadsheet automatically round it.
Ex)