Want to set up Date Picker

nuk79

New member
I'm looking for help on setting up a javascript date picker like Calendar Popup (http://www.mattkruse.com/javascript/calendarpopup/).

Using Dadabik Ver 4.2 on linux server and MySQL.
 

amkma

New member
Hi,
I also want the same, but couldn't find the solution in the forums.
Can someone help please?
 

JP

Member
First I would like to say that I absolutely love Dadabik. I hope it's development doesn't stop.

Ok so I came across this post and another old post http://www.dadabik.org/forum/read.php?f=1&i=9187&t=9187#reply_9187 and I have emailed oneShot but have not gotten a reply Edit:(I got a reply and he no longer uses Dadabik and does not have the files anymore) and I was wondering if anyone else has successfully implemented a javascript popup calendar/date picker into Dadabik yet?

This would be a great addition to this already great program.

Thanks...



Post Edited (04-08-09 04:30)
 

billthecat

Well-known member
I have a date picker working on my test site; you can see it here:
http://quasitown.com/dadabik_files/dadabik_4.2/program_files/index.php?function=show_insert_form&table_name=Content

Here's the site I got it from:
http://javascriptkit.com/script/script2/timestamp.shtml


Following the basic rules of the install, you'll have to edit at least 2 files;
include/header.php and /include/business_logic.php

editing header.php:
Add anywhere between <head> </head>:
<script language="javascript" type="text/javascript" src="include/ts_picker.js"></script>


editing business_logic.php:
find (around line 783:)
if (($form_type == "update" or $form_type == "insert") and $fields_labels_ar[$i]["content_field"] == "city"){

Right above that line, you'll see the end of the form.
$form .= ">";

You'll want to edit this to read:

if ($field_name_temp === 'MYDATEFIELDNAME') {
$form .= "><a href=\"javascript:show_calendar('document.contacts_form.MYDATEFIELDNAME', document.contacts_form.MYDATEFIELDNAME.value);\"><img src=\"images/cal.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"Click Here to Pick up the timestamp\"></a>";
} else {
$form .= ">";
}


Obviously, change the field name to whatever you're using.

 

JP

Member
billthecat,

Thank you so much for sharing this mod. I started with your idea and changed it up just a bit.

I took the idea from the How to make a "static" field type post:
http://www.dadabik.org/forum/read.php?f=2&i=798&t=419#reply_798
(Which I am also using on the site I am making) and applied it to your mod.

What I did was add a case "pick_date" type_field to my install.

I am using the Javascript Date Time Picker from here:
http://www.rainforestnet.com/datetimepicker.htm

Made the following mods to the Dadabik files.

Added to include/header.php:
Between <head> </head>
<script type="text/javascript" src="datetimepicker_css.js"></script>

Added to include/internal_table.php:
pick_date to the list in $int_fields_ar[2][3] =

Added to include/business_logic.php:
The below case "pick_date" code was added under the case "text" break; on or about line 787. Specific javascript additions are in bold.

case "pick_date":
$form .= "<td class=\"td_input_form\">".$select_type_select."<input type=\"text\" name=\"".$field_name_temp."\"";
if ($fields_labels_ar[$i]["width_field"] != ""){
$form .= " size=\"".$fields_labels_ar[$i]["width_field"]."\"";
} // end if
$form .= " id=\"".$field_name_temp."\""; // needed for Rainforest Javascript Date Time Picker
$form .= " maxlength=\"".$fields_labels_ar[$i]["maxlength_field"]."\"";
if ($form_type == "update" or $form_type == "ext_update"){
if ($show_edit_form_after_error === 1){
if (isset($_POST[$field_name_temp])) {
$form .= " value=\"".htmlspecialchars(stripslashes($_POST[$field_name_temp]))."\"";
} // end if
} // end if
else {
$form .= " value=\"".htmlspecialchars($details_row[$field_name_temp])."\"";
} // end else
} // end if
if ($form_type == "insert"){
if ($show_insert_form_after_error === 1 && isset($_POST[$field_name_temp])) {
$form .= ' value="'.htmlspecialchars(stripslashes($_POST[$field_name_temp])).'"';
} // end if
else {
$form .= " value=\"".$fields_labels_ar[$i]["prefix_field"].$fields_labels_ar[$i]["default_value_field"]."\"";
} // end else
} // end if
$form .= ">";
if ($form_type == "update" or $form_type == "insert"){
$form .= "  <a href=\"javascript:NewCssCal('".$field_name_temp."','MMMddyyyy','arrow')\"><img src=\"images/calendar.gif\" class=\"form_calendar\" alt=\"Calendar\"></a>";
} // end if
$form .= "</td>"; // add the second coloumn to the form
break;

Added a css class for positioning of the calendar on the page. The javascript itself has css style in the script that can be modified to suit your site layout along with a standalone css stylesheet for your use.

The site I am working on is an Intranet site so I can't provide a link for you to see. I'll try and find a place I can put up a picture to show my working mod.

Thanks...



Post Edited (04-08-09 04:31)
 

nuk79

New member
Look in my DaDaBIK test area with date_picker modifications.

http://dadabik.nukuta.ru/

Thanks to JP ;-)



Post Edited (04-06-09 17:22)
 

JP

Member
To include the date picker in your search form all you need to do is add the search form type to case "pick_date". Change is in bold below.

In file include/business_logic.php:

case "pick_date":
$form .= "<td class=\"td_input_form\">".$select_type_select."<input type=\"text\" name=\"".$field_name_temp."\"";
if ($fields_labels_ar[$i]["width_field"] != ""){
$form .= " size=\"".$fields_labels_ar[$i]["width_field"]."\"";
} // end if
$form .= " id=\"".$field_name_temp."\""; // needed for Rainforest Javascript Date Time Picker
$form .= " maxlength=\"".$fields_labels_ar[$i]["maxlength_field"]."\"";
if ($form_type == "update" or $form_type == "ext_update"){
if ($show_edit_form_after_error === 1){
if (isset($_POST[$field_name_temp])) {
$form .= " value=\"".htmlspecialchars(stripslashes($_POST[$field_name_temp]))."\"";
} // end if
} // end if
else {
$form .= " value=\"".htmlspecialchars($details_row[$field_name_temp])."\"";
} // end else
} // end if
if ($form_type == "insert"){
if ($show_insert_form_after_error === 1 && isset($_POST[$field_name_temp])) {
$form .= ' value="'.htmlspecialchars(stripslashes($_POST[$field_name_temp])).'"';
} // end if
else {
$form .= " value=\"".$fields_labels_ar[$i]["prefix_field"].$fields_labels_ar[$i]["default_value_field"]."\"";
} // end else
} // end if
$form .= ">";
if ($form_type == "update" or $form_type == "insert" or $form_type == "search"){
$form .= " <a href=\"javascript:NewCssCal('".$field_name_temp."','MMMddyyyy','arrow')\"><img src=\"images/calendar.gif\" class=\"form_calendar\" alt=\"Calendar\"></a>";
} // end if
$form .= "</td>"; // add the second coloumn to the form
break;

Also make sure your date field is present in the search form and you should be good to go.



Post Edited (04-08-09 04:29)
 

JP

Member
Ok I want to try and add one more thing to the date picker form field or any field on the edit page. Going off of the case "static" idea would it be possible to make a field readonly once it has been updated? I'll give you an example.

The page I am working on is a repairlog that tracks when a part was shipped for repair and when it was received. The edit page has four fields present. The first is the shipping number which is "static" and can not be changed. The other three fields are (1) Date Received (The case "pick_date" from above). (2) Received By, which is a select single field. (3) Comments, which is a text area field. What I would like to do is make Date Received and possibly Received By readonly if this record has previously been updated. Basically if Date Received and/or Received By are already populated then do not allow edit. Comments would still be editable.

Does anyone have any ideas on how to implement this? Could the case "static" be tweaked to be readonly if the form type is update AND certain fields are already filled in?

 

corsonehtml

New member
It's work fine but only with the english format. i need the latin format, I can do this?

It also can wotks with the hours?

Thanks



Post Edited (10-20-09 14:21)
 

JP

Member
The date picker script has several formats to choose from including Latin and time. You can see all the choices here -> http://www.rainforestnet.com/demo_datetimepicker.htm

 

corsonehtml

New member
I know that Date Picker do that but the problem is the implementation with dadabik.
Tha database accept english format and dadabik change the visualization with latin still using the english format to insert/update the field when I use the date field and the latin date_format is configured in the include file.
The problem is that the date, until now inserted with the english format, being visualized from dadabik with the english format and not with the latin one.
How can I change this behaviour?
Besides datepicker can insert/update field with english format but keeping the latin visualization? I think not because the insert field is managed by dadabik and not by the datepicker.



Post Edited (10-22-09 10:28)
 

DebbieS

DaDaBIK Guru
JP ... readonly fields ...

In one of my installs, I modded the build_form function to add "readonly" (and class="readonly" - css styling to remove borders and make it look like reg text) to certain text fields. I don't believe this is possible with date/select fields.

However, you could try displaying the info to the screen AND adding a hidden input to hold the values for the fields that should not be editable (so their values are retained on edit). Did that on another install for one select field, but it should work for a date field also.

 

JP

Member
DebbieS,

Thank you for the reply. Yes I did the "readonly" mod to the build_form function which I called case "static" and that works great. Since my date input is done with a java script that field is a text field and not a date field. I created a case "pick_date" which is a text input so I think I could have it readonly IF I can figure out how to tell the form to make it readonly if it is NOT null (not empty). If it is null (empty) then you can put a date in. If it has been edited previously and is not null then it is readonly.

I don't totally understand what you mean by:

"However, you could try displaying the info to the screen AND adding a hidden input to hold the values for the fields that should not be editable (so their values are retained on edit). Did that on another install for one select field, but it should work for a date field also."

I would be interested in more information on that process if possible. The "select single" I am using in my form that I want to change is pointing to another table with a list of users who can update (receive) parts in the log. An idea I have is to have that field only show the user that is currently logged in instead of all the users from that table. I do that already as a readyonly field when a record is inserted but on edit/update I have it as a select single because the person receiving a part can be one of two options, either the person logged in or in some cases a part will not be returned and was only shipped to another location and that option in my select single is ADDRESSEE or who the part was shipped too.

So to wrap up I want to make my pick_date "readonly" only if the part has been received and the pick_date field is NOT empty. And to make my current select_single show ADDRESSEE in the pull down and the person logged in as the only choices.

I know how to call the current user logged in within PHP I just need to know how to put it in the select_single list. Maybe even a new case "select_single" just for this pull down.

Totally confused you now I know. This site is on an intranet, maybe I can copy what I have and get it put up on an internet install for you to see.

DebbieS would you happen to have any of your installs available for others to see or is your work on n intranet as well? Your technical input is always very helpful and I would like to see your work.

Thanks a million...

 

DebbieS

DaDaBIK Guru
Well for your pick_date type, you should easily be able to code that into the build_form by adding to the case/section for your pick_date type an if statement:

case "pick_date":

.......

if ($form_type == "update" or $form_type == "insert") {
.....code......
if (($details_row[$field_name_temp] != "") || ($details_row[$field_name_temp] != "0000-00-00") || ($details_row[$field_name_temp] != "0000-00-00 00:00:00")) {
$form .= " readonly style=\"border:0;\" tabindex=\"-1\"";
}

Since your date is now a text field with the date picker, this should work (and should work regardless of what the database field setting is).

For the hidden field option, You just make a hidden field in business_logic (<input type="hidden" name="field_name" value="php_variable_for_field_value">) to regain the field value for form update and then echo the field value to the screen so it displays.

To change the select_single for this field only (and assuming from your text that it is a list of users with no other keys), try adding this just below the first $form .= line after case "select_single":

if ($field_name_temp == "YOUR_FIELD_NAME") {
$form .= "<option value=\"".$var_for_current_user."\">".$var_for_current_user."</option>
<option value=\"ADDRESSEE\">ADDRESSEE</option>";
} else {

and then don't forget to close the else just before the $form .= "</select>"; line that closes the select field. Will be just above the if ($fields_labels_ar[$i]["other_choices_field"] == "1" line that starts the other options field. Haven't tested it, but it could work.

Hope this helps

I would love to let everyone here see my installs, BUT, they too are on an intranet. Maybe sometime I'll make the time to put up a test database with some of the things I talk about in here so there is a working example.

Thanks for your comments -- appreciated!

 

JP

Member
Debbie,

I added the following and the date field works perfect.

case "pick_date":
$form .= "<td class=\"td_input_form\">".$select_type_select."<input type=\"text\" name=\"".$field_name_temp."\"";
if ($details_row[$field_name_temp] != "") {
$form .= " readonly=\"readonly\" style=\"font-weight:bold; border:0;\" tabindex=\"-1\"";
} //end if

I had to leave off the below portion because it caused the date field to be read only even if it had nothing in it or it was already populated.

|| ($details_row[$field_name_temp] != "0000-00-00") || ($details_row[$field_name_temp] != "0000-00-00 00:00:00")

I was also able to add the following to select_single and it worked as well.

if ($field_name_temp == "YOUR_FIELD_NAME") {
$form .= "<option value=\"".$var_for_current_user."\">".$var_for_current_user."</option>
<option value=\"ADDRESSEE\">ADDRESSEE</option>";
} else {

But the problem I have now with this select_single is this becomes the two choices for a record that has already been updated. So if something was received by someone else this will always want to overwrite it with the current user logged in. I didn't think of that before, so I may have to try something else.

Something else I also noticed which was there before any modification is the fields that I have set as required fields and have the asterisk(*) next to them are always there even if a record has been updated (not empty). Would you have any ideas on how to get the asterisk(*) to go away for fields that are no longer empty?

Oh and I was also able to get the calendar to not be shown once the field becomes "readonly" using

if ($details_row[$field_name_temp] == "") <- only shows the calendar if the date field is empty. I just did a reverse of what you suggested for the date field readonly.

Thanks for your help :)



Post Edited (10-27-09 23:16)
 

JP

Member
Debbie,

This is what the record looks like before it is updated (part received).

update1.png


This is the record being updated and use of the JavaScript pop-up calendar.

update2.png


And this is after the record has been saved. Notice the "Date Received" is now readonly, your mod works perfect. Also notice the pop-up calendar is gone. Just need to get rid of the asterisk (*) next to "Date Received" and "Received By" I am also considering changing the "Received By" from a select_single to a text field.

update3.png




Post Edited (11-08-09 22:45)
 
Top