This topic is locked

Disable Add New button on list page after date expired

4/13/2012 12:26:00 PM
PHPRunner General questions
J
Jeroef author

I brought this topic up a few months ago and thought it was solved.
Im trying with this code on List page Before process event to hide the Add New button after date expired.

It works IF i have only 1 entry in table "tavlingar" but what i need is that the event checks multiple entrys.
Here is the code:

$rs = CustomQuery("SELECT sistaanmdag FROM tavlingar");

$record = db_fetch_array($rs);
if (date("Y-m-d",strtotime($record['sistaanmdag'])) <= date("Y-m-d",time()))

{

header("Location: signup2_list.php?mastertable=aktuellt&masterkey1=".$record['tnr']."");

exit();

}


I got this code from Cristian Gilè a few months ago.
anyone have any good idea about this ?
/Regards

C
cgphp 4/13/2012

You can check multiple records with a while loop:

$rs = CustomQuery("SELECT tnr,sistaanmdag FROM tavlingar");
while($record = db_fetch_array($rs))

{

//if the n-th record <= of now redirect

if (date("Y-m-d",strtotime($record['sistaanmdag'])) <= date("Y-m-d",time()))

{

header("Location: signup2_list.php?mastertable=aktuellt&masterkey1=".$record['tnr']."");

exit();

}

}
J
Jeroef author 4/15/2012



You can check multiple records with a while loop:

$rs = CustomQuery("SELECT tnr,sistaanmdag FROM tavlingar");
while($record = db_fetch_array($rs))

{

//if the n-th record <= of now redirect

if (date("Y-m-d",strtotime($record['sistaanmdag'])) <= date("Y-m-d",time()))

{

header("Location: signup2_list.php?mastertable=aktuellt&masterkey1=".$record['tnr']."");

exit();

}

}



I checked around and put together a new code for this purpose.

$rs = CustomQuery("SELECT sistaanmdag FROM aktuellt");

while ($record = db_fetch_array($rs))
$exp_date = $record['sistaanmdag'];

$todays_date = date("Y-m-d",time());
$today = strtotime($todays_date);

$expiration_date = strtotime($exp_date);
if ($expiration_date > $today) {

echo "Yes!";

} else {

echo "No!";

}

}


Still, if i only have 1 record in table "aktuellt" this works like a charm but if i add another record with a date that has expired, i still get a Yes! when checking the new record. It seems the Query only checks the first record. I have changed to Timestamp for sistaanmdag in the db.

Hoping someone have the answer why i cant query multiple records.
// Regards

C
cgphp 4/15/2012

The while loop opening curly bracket is missing.

M
mmponline 4/16/2012

I have a similar need. Using ver 6.1
I want to add a field that says Lock. (with yes,no or 1,2)
When Lock is yes, the Edit link or button must not appear on the list page. IOW , if the admin lock a record on the table, the user must not be able to edit it.
Table Name is admin, field for lock is lock.
Please assist.

J
Jeroef author 4/23/2012

I know what the problem is, the query stays, like cashe. So if i query a date in line 1, get results and go back. II query line 2 but it still querys line 1.
Anyone have a good solution for this problem?
// Regards