This topic is locked

Changing editable record to be read-only after few days

12/18/2006 6:57:12 AM
ASPRunnerPro General questions
orit author

I have a _list page to which the user can add records in an _add page. In the _add page I have a form with a date field + 3 rich text areas. following adding the record, I want that the user will be able to edit the record only for 2 days after the date he has entered in the _add page, and that the add page will be read-only right after it is added.

I want that on the record's row will be link to the _edit page only on the days that the user can edit this record. otherwise - there will not be link.
How to do that?
Thanks

Sergey Kornilov admin 12/19/2006

Orit,
you can modify generated list.asp page for this purpose.

See my changes in bold

while not rs.EOF and recno<=PageSize and col<1

col=col+1
if DateDiff("d", Now(), CDate(rs("DateCreated)))>2

row.Add col & "editable",False

else

row.Add col & "editable",True

end if

orit author 12/20/2006

Thanks,
For some reason it doesn't work for mebut from what I understand from the code, the solution is that the Edit column will be displayed or will not be displayed and and this is problematic because there will always be item\s that can be edited (that were created in the last day or 2 days - which can still be edited), so I'm looking for solution to display or to hide the link to "Edit" beside the records that were created more than 2 days ago.
Am I right in understanding what the code you provided is doing? If I'm right, can you please advise how can I display\hide the "Edit" linked word from the "Edit" column, based on how many days passed since the creation date?

If I am wrong, do you have an idea what can be the reason that it doesn't work for me?
Thanks a lot

Sergey Kornilov admin 12/20/2006

Orit,
you not getting this right.
This code does exactly what you need to do - it hides Edit link for records that are older than two days.

It doesn't hide the Edit column itself.
You can post exact piece of code that includes your changes along with a better than "it doesn't work" explanation.

orit author 12/21/2006

Thanks,
In the _list.asp file I added:

'addition for read only after 1 day

if DateDiff("d", Now(), CDate(rs("DateCreated")))>1 then

row.Add col & "editable",False

else

row.Add col & "editable",True

end if


(I changed it not to show the "Edit" link if it is older than 1 day since I wanted to see the results earlier)
The application doesn't give me error message, it only shows the link to "Edit" all the time.
Please advise.
Thanks a lot

Sergey Kornilov admin 12/21/2006

Did you replace DateCreated with the actual field name that stores creation date?

orit author 12/22/2006

Oh, no.. I though that the "DateCreated" is kind of a keyword in asprunner.

I have a field where the user selects a date. I want to make the record read-only after 2 days from the day it was created and not from the day the user selected. Is there a way to add the record's creation date automatically to the database? How to do that?
Thanks a lot

Sergey Kornilov admin 12/22/2006

Add a field to your table named DateCreated.

Set default value of this field to Now().

You can also remove this field to Add/Edit pages.
After that use the code I posted.

orit author 12/24/2006

Thanks.

I still have problem:
I added a field named: dateCreated with default value of Now() and in the asprunner defined that it will be visible in the list page, search and adv search pages, view, export and printer friendly pages (visible in all pages except in the add and edit pages).

Added the code:

if DateDiff("d", Now(), CDate(rs("dateCreated")))>2 then

row.Add col & "editable",False

else

row.Add col & "editable",True

end if



in my relevant _list page and it still shows the link to the "Edit" page for all records - also those that I changed their date to be older than 2 days.
What can be the problem?
Thanks

J
Jane 12/26/2006

Orit,
here is the correct code snippet:

if DateDiff("d", CDate(rs("ReportsTo")), Now())>2 then

row.Add col & "editable",False

else

row.Add col & "editable",True

end if

Also you need to open templates/..._list.htm file, find following lines:

<a href="TableName_edit.asp?{$row.1editlink}">

Edit</a>



and replace it with this one:

{if $row.1editable}

<a href="TableName_edit.asp?{$row.1editlink}">

Edit</a>

{/if}

orit author 12/26/2006

Perfect,
Thanks a lot