This topic is locked
[SOLVED]

 Hide "add" button

9/26/2011 3:25:07 PM
PHPRunner General questions
J
Jeroef author

I have a signup table that visitors can add themself if wanted. I need a way to hide add button after a certain date or with a button. I have searched this forum but cant find a good way to do this. Please advice.

C
cgphp 9/26/2011

Enter the following code in the javascript Onload event of the list page:

var today = new Date();

var dd = today.getDate();

var mm = today.getMonth()+1;

var yyyy = today.getFullYear();

var current_date = dd+'/'+mm+'/'+yyyy;

var target_date = '26/9/2011';
if(current_date == target_date)

{

$("input[id^='addButton']").parents().eq(1).hide();

}
J
Jeroef author 9/26/2011



Enter the following code in the javascript Onload event of the list page:

var today = new Date();

var dd = today.getDate();

var mm = today.getMonth()+1;

var yyyy = today.getFullYear();

var current_date = dd+'/'+mm+'/'+yyyy;

var target_date = '26/9/2011';
if(current_date == target_date)

{

$("input[id^='addButton']").parents().eq(1).hide();

}



Thanks for the reply!

That worked perfectly if i set a target date, but is there a way for a admin to set the target date from list page?

C
cgphp 9/26/2011

You can create a custom view for the signup table. In the custom view disable the "Add page". Then, in the "List page: Before process" event of the signup table check for the target date. If the target date matches the current date do a redirect to the custom view.
Sample code:

$target_date = "21-09-2001"; //you can fetch this date from db
if($target_date == date("d-m-Y",time()))

{

header("Location: customviewname_list.php");

exit();

}
J
Jeroef author 9/26/2011



You can create a custom view for the signup table. In the custom view disable the "Add page". Then, in the "List page: Before process" event of the signup table check for the target date. If the target date matches the current date do a redirect to the custom view.
Sample code:

$target_date = "21-09-2001"; //you can fetch this date from db
if($target_date == date("d-m-Y",time()))

{

header("Location: customviewname_list.php");

exit();

}



Great!

Last question, i have a date field in my "main" table that shows when the competiton is starting, can i fetch that date and use it for target date?

C
cgphp 9/26/2011
$rs = CustomQuery("SELECT date_field_name FROM main_table"); //change this query according to your needs

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

{

header("Location: customviewname_list.php");

exit();

}
J
Jeroef author 9/26/2011


$rs = CustomQuery("SELECT date_field_name FROM main_table"); //change this query according to your needs

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

{

header("Location: customviewname_list.php");

exit();

}



Thanks Cristian for your petience, i am new to this so bare with me pls <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=61054&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

I cant get it to work, i do expect it has something to do with the date format, in your example d-m-Y, but im on eurotime (swedish) and the date field in my main table is YYYY-mm-dd? My edited code:

$rs = CustomQuery("SELECT datum FROM tindex");

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

{

header("Location: tanmalan2_list.php");

exit();

}


Is this right?

C
cgphp 9/26/2011
$rs = CustomQuery("SELECT datum FROM tindex");

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

{

header("Location: tanmalan2_list.php");

exit();

}
J
Jeroef author 9/26/2011


$rs = CustomQuery("SELECT datum FROM tindex");

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

{

header("Location: tanmalan2_list.php");

exit();

}



No luck yet. I added a new date field in tanmalan and pointed the customquery to that.

$rs = CustomQuery("SELECT datum FROM tanmalan");

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

{

header("Location: tanmalan2_list.php");

exit();

}


Any more ideas why this dont work?

J
Jeroef author 9/27/2011



No luck yet. I added a new date field in tanmalan and pointed the customquery to that.

$rs = CustomQuery("SELECT datum FROM tanmalan");

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

{

header("Location: tanmalan2_list.php");

exit();

}


Any more ideas why this dont work?


This code do redirect:

$rs = CustomQuery("SELECT datum FROM tindex");

$record = db_fetch_array($rs);
if($record == date("Y-m-d",time())) //changing this line..

{

header("Location: T_vlingsdeltagare_report.php");

exit();
}

}


If i change == to = i get diffrent result. If i use 1 = i get redirected, not if i use 2 == but it dont read the date.

C
cgphp 9/27/2011

How many records the query fetches from db ? Be sure that only one record is fetched.

J
Jeroef author 9/27/2011



How many records the query fetches from db ? Be sure that only one record is fetched.


Still can't get it to work with the last piece of code you posted. I have tryed all date combinations too. Any other great idea how to solv this little problem?

C
cgphp 9/27/2011

How many records the query fetches from db ? Be sure that only one record is fetched.


Did you check what I asked you ?

C
cgphp 9/27/2011

Be sure that the fetched record field is a valid date and not an empty or null value.

J
Jeroef author 9/27/2011



Did you check what I asked you ?


This is the code i used latest:

$rs = CustomQuery("SELECT datum FROM tindex");

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

{

header("Location: tanmalan2_list.php");

exit();

}



[/quote]

C
cgphp 9/27/2011

I can't help you if you can't provide me more info.
How many records in the tindex table ?

Do you get some errors ?

J
Jeroef author 9/27/2011



I can't help you if you can't provide me more info.
How many records in the tindex table ?

Do you get some errors ?


I have only 1 record so far.Theres gona be more the one in the future offcourse. I get no errors, i do not get redirected, tanmalan_list opens up.

C
cgphp 9/27/2011

Try out this code and let me know the result:

$rs = CustomQuery("SELECT datum FROM tindex");

$record = db_fetch_array($rs);
echo "Fetched record: ".date("Y-m-d",strtotime($record['datum']));

echo " Now: ".date("Y-m-d",time());
J
Jeroef author 9/27/2011



Try out this code and let me know the result:

$rs = CustomQuery("SELECT datum FROM tindex");

$record = db_fetch_array($rs);
echo "Fetched record: ".date("Y-m-d",strtotime($record['datum']));

echo " Now: ".date("Y-m-d",time());



I get this: Fetched record: 2011-09-20 Now: 2011-09-27, so that works.

C
cgphp 9/27/2011

You have solved the issue. The date value in db is prior to today. To check the script functionality, set the db field value to today date.
If you want to redirect when the target date is expired, chenge the if statement as follows:

$rs = CustomQuery("SELECT datum FROM tindex");

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

{

header("Location: tanmalan2_list.php");

exit();

}
J
Jeroef author 9/27/2011



You have solved the issue. The date value in db is prior to today. To check the script functionality, set the db field value to today date.
If you want to redirect when the target date is expired, chenge the if statement as follows:

$rs = CustomQuery("SELECT datum FROM tindex");

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

{

header("Location: tanmalan2_list.php");

exit();

}



Awsome! It works like a charm! Thank you very mutch. Now is there a way to be able to handle multible records?

C
cgphp 9/27/2011

Now is there a way to be able to handle multible records?



Please, provide more info.

J
Jeroef author 9/27/2011



Please, provide more info.


The script did work on one record, i created a new contest with a date that hasnt expired but it became locked too. I need tjhe script to check the whole tanmalan table for expire dates and only redirect them to tanmalan2.
btw, is there a way to hide a mastertable link using expired date?

C
cgphp 9/28/2011

Jeroef, what's the porpuse of this code ? I'm afraid that it may not be the best approach.

J
Jeroef author 9/28/2011



Jeroef, what's the porpuse of this code ? I'm afraid that it may not be the best approach.


Ok here is the deal. I am working on a program that lets competitors sign up for diffrent upcomming competitions. All competitions is listed in tindex table. and the signup is located in tanmalan table. I added master/child reletions between the both, now, the signup for a competition usaly last for like 3 weeks then its closed, so what i need is to find a way for a Admin to "lock" the signup form for a competition after a certain date.
The code you put togeter worked perfectly with only only 1 record added in tindex, when i added a new competition with a date that hasnt expired it got redirected too.
Hope this explains it.

C
cgphp 9/29/2011

It's not very clear how you hanlde the signup process. The competitors can signup for a competition at time. Right?

J
Jeroef author 9/29/2011



It's not very clear how you hanlde the signup process. The competitors can signup for a competition at time. Right?


The project is a admin program for track and field clubbs. They wanted a form that (instead of the club taking entrys of compeditors by email and manualy enter then into the system) handled the registrations.
When the compeditor enter tindex they get info about all the upcomming competitions. If they want to compete they klick on tanmalan (tindex = master , tanmalan = detail) and fills out the form.

Yes they sign up for one competition at the time but offcourse there can be alot of diffrent competitions to choose from.
When the date is up for a signup the club heads into another list that uses the tanmalan as lookup table, and there fills out all the compeditors that have signed up.

This is why i need to hide the Add New button on tanmalan after a choosen date has expired,

J
Jeroef author 9/30/2011



The project is a admin program for track and field clubbs. They wanted a form that (instead of the club taking entrys of compeditors by email and manualy enter then into the system) handled the registrations.
When the compeditor enter tindex they get info about all the upcomming competitions. If they want to compete they klick on tanmalan (tindex = master , tanmalan = detail) and fills out the form.

Yes they sign up for one competition at the time but offcourse there can be alot of diffrent competitions to choose from.
When the date is up for a signup the club heads into another list that uses the tanmalan as lookup table, and there fills out all the compeditors that have signed up.

This is why i need to hide the Add New button on tanmalan after a choosen date has expired,


I just woke up with the aswer to the master - detail problem on tanmalan2, i need to privide the correct link in your code .. instead of just tanmalan2_list.php i need the full link with master and deatil value in it, any hope that u can show me the correct link value?

C
cgphp 9/30/2011
tanmalan2_list.php?mastertable=your_master_table_name&masterkey1=your_details_key_field_value
J
Jeroef author 9/30/2011


tanmalan2_list.php?mastertable=your_master_table_name&masterkey1=your_details_key_field_value



You are a Guru, you know that? .. thanks alot for all help!

J
Jeroef author 9/30/2011

[quote name='Jeroef' date='27 September 2011 - 09:05 PM' timestamp='1317153905' post='61086']

[quote name='Cristian Gilè' date='27 September 2011 - 04:34 PM' timestamp='1317137648' post='61083']

You have solved the issue. The date value in db is prior to today. To check the script functionality, set the db field value to today date.
If you want to redirect when the target date is expired, chenge the if statement as follows:

$rs = CustomQuery("SELECT datum FROM tindex");

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

{

header("Location: tanmalan2_list.php?mastertable=tindex&masterkey1=tkod&masterkey2=tnamn");

exit();

}


So here is the code with the new link, not i expect i need to format the master and details values, otherwise it just gona link as is?

J
Jeroef author 10/1/2011

[quote name='Jeroef' date='30 September 2011 - 11:25 AM' timestamp='1317378353' post='61142']

[quote name='Jeroef' date='27 September 2011 - 09:05 PM' timestamp='1317153905' post='61086']
Solved, thanks Cristian for all help.