The branch, master has been updated
via 67fd7e2567009a8bc6eb605e18587efc9b7047c4 (commit)
via e194beb978f98a11777e91ee09b95b9ff3656b67 (commit)
from 46b2ed8dddac3d0bc925a9d58c652cc4e95d6cfb (commit)
- Log -----------------------------------------------------------------
commit 67fd7e2567009a8bc6eb605e18587efc9b7047c4
Author: Michal Čihař <mcihar(a)novell.com>
Date: Fri Apr 16 09:54:19 2010 +0200
CURRENT_TIMESTAMP is also valid for DATETIME.
commit e194beb978f98a11777e91ee09b95b9ff3656b67
Author: Sutharshan Balachandren <sutharshan02(a)gmail.com>
Date: Fri Apr 16 09:53:18 2010 +0200
[interface] Add javascript validation of datetime input.
patch #2983960
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 2 +
js/tbl_change.js | 170 ++++++++++++++++++++++++
tbl_change.php | 24 ++--
themes/darkblue_orange/css/theme_right.css.php | 5 +
themes/original/css/theme_right.css.php | 5 +
5 files changed, 194 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 64695b9..602ae21 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -69,6 +69,8 @@ $Id$
- patch #2985068 [engines] Fix parsing of PBXT status, thanks to Madhura Jayaratne.
- patch #2986073 [interface] Convert upload progress bar to jQuery, thanks to
Philip Frank.
+- patch #2983960 [interface] Add javascript validation of datetime input,
+ thanks to
3.3.3.0 (not yet released)
- patch #2982480 [navi] Do not group if there would be one table in group,
diff --git a/js/tbl_change.js b/js/tbl_change.js
index 97c9bf7..9539591 100644
--- a/js/tbl_change.js
+++ b/js/tbl_change.js
@@ -56,6 +56,175 @@ function nullify(theType, urlField, md5Field, multi_edit)
/**
+ * javascript DateTime format validation.
+ * its used to prevent adding default (0000-00-00 00:00:00) to database when user enter
wrong values
+ * Start of validation part
+ */
+//function checks the number of days in febuary
+function daysInFebruary (year){
+ return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ?
29 : 28 );
+}
+//function to convert single digit to double digit
+function fractionReplace(num)
+{
+ num=parseInt(num);
+ var res="00";
+ switch(num)
+ {
+ case 1:res= "01";break;
+ case 2:res= "02";break;
+ case 3:res= "03";break;
+ case 4:res= "04";break;
+ case 5:res= "05";break;
+ case 6:res= "06";break;
+ case 7:res= "07";break;
+ case 8:res= "08";break;
+ case 9:res= "09";break;
+ }
+ return res;
+}
+
+/* function to check the validity of date
+* The following patterns are accepted in this validation (accepted in mysql as well)
+* 1) 2001-12-23
+* 2) 2001-1-2
+* 3) 02-12-23
+* 4) And instead of using '-' the following punctuations can be used
(+,.,*,^,@,/) All these are accepted by mysql as well. Therefore no issues
+*/
+function isDate(val,tmstmp)
+{
+ val=val.replace(/[.|*|^|+|//|@]/g,'-');
+ var arrayVal=val.split("-");
+ for(var a=0;a<arrayVal.length;a++)
+ {
+ if(arrayVal[a].length==1)
+ arrayVal[a]=fractionReplace(arrayVal[a]);
+ }
+ val=arrayVal.join("-");
+ var pos=2;
+ dtexp=new
RegExp(/^([0-9]{4})-(((01|03|05|07|08|10|12)-((0[0-9])|([1-2][0-9])|(3[0-1])))|((02|04|06|09|11)-((0[0-9])|([1-2][0-9])|30)))$/);
+ if(val.length==8)
+ {
+ dtexp=new
RegExp(/^([0-9]{2})-(((01|03|05|07|08|10|12)-((0[0-9])|([1-2][0-9])|(3[0-1])))|((02|04|06|09|11)-((0[0-9])|([1-2][0-9])|30)))$/);
+ pos=0;
+ }
+ if(dtexp.test(val))
+ {
+ var month=parseInt(val.substring(pos+3,pos+5));
+ var day=parseInt(val.substring(pos+6,pos+8));
+ var year=parseInt(val.substring(0,pos+2));
+ if(month==2&&day>daysInFebruary(year))
+ return false;
+ if(val.substring(0,pos+2).length==2)
+ {
+ if(val.substring(0,pos+2).length==2)
+ year=parseInt("20"+val.substring(0,pos+2));
+ else
+ year=parseInt("19"+val.substring(0,pos+2));
+ }
+ if(tmstmp==true)
+ {
+ if(year<1978) return false;
+
if(year>2038||(year>2037&&day>19&&month>=1)||(year>2037&&month>1))
return false;
+ }
+ }
+ else
+ return false;
+ return true;
+}
+
+/* function to check the validity of time
+* The following patterns are accepted in this validation (accepted in mysql as well)
+* 1) 2:3:4
+* 2) 2:23:43
+*/
+function isTime(val)
+{
+ var arrayVal=val.split(":");
+ for(var a=0;a<arrayVal.length;a++)
+ {
+ if(arrayVal[a].length==1)
+ arrayVal[a]=fractionReplace(arrayVal[a]);
+ }
+ val=arrayVal.join(":");
+ tmexp=new
RegExp(/^(([0-1][0-9])|(2[0-3])):((0[0-9])|([1-5][0-9])):((0[0-9])|([1-5][0-9]))$/);
+ if(!tmexp.test(val))
+ return false;
+ return true;
+}
+//validate the datetime and integer
+function Validator(urlField, multi_edit,theType){
+ var rowForm = document.forms['insertForm'];
+ var evt = window.event || arguments.callee.caller.arguments[0];
+ var target = evt.target || evt.srcElement;
+ unNullify(urlField, multi_edit);
+
+ if(target.name.substring(0,6)=="fields")
+ {
+ var dt=rowForm.elements['fields[multi_edit][' + multi_edit + ']['
+ urlField + ']'];
+ // validate for date time
+
if(theType=="datetime"||theType=="time"||theType=="date"||theType=="timestamp")
+ {
+ if(theType=="date"){
+ if(!isDate(dt.value))
+ {
+ dt.className="invalid_value";
+ return false;
+ }
+ }
+ else if(theType=="time")
+ {
+ if(!isTime(dt.value))
+ {
+ dt.className="invalid_value";
+ return false;
+ }
+ }
+ else if(theType=="datetime"||theType=="timestamp")
+ {
+ tmstmp=false;
+ if(dt.value=="CURRENT_TIMESTAMP")
+ {
+ dt.className="";
+ return true;
+ }
+ if(theType=="timestamp")
+ {
+ tmstmp=true;
+ }
+ if(dt.value=="0000-00-00 00:00:00")
+ return true;
+ var dv=dt.value.indexOf(" ");
+ if(dv==-1)
+ {
+ dt.className="invalid_value";
+ return false;
+ }
+ else
+ {
+
if(!(isDate(dt.value.substring(0,dv),tmstmp)&&isTime(dt.value.substring(dv+1))))
+ {
+ dt.className="invalid_value";
+ return false;
+ }
+ }
+ }
+ }
+ //validate for integer type
+ if(theType.substring(0,3)=="int"){
+
+ if(isNaN(dt.value)){
+ dt.className="invalid_value";
+ return false;
+ }
+ }
+ }
+
+ dt.className="";
+ }
+ /* End of datetime validation*/
+
+/**
* Unchecks the "NULL" control when a function has been selected or a value
* entered
*
@@ -351,6 +520,7 @@ function returnDate(d) {
}
window.opener.dateField.value = txt;
+ window.opener.dateField.className='';
if (typeof(window.opener.dateFieldNull) != 'undefined') {
window.opener.dateFieldNull.checked = false;
}
diff --git a/tbl_change.php b/tbl_change.php
index 631b8f6..84e5f69 100644
--- a/tbl_change.php
+++ b/tbl_change.php
@@ -183,7 +183,7 @@ if (isset($where_clause)) {
} else { // end if (no row returned)
$meta = PMA_DBI_get_fields_meta($result[$key_id]);
list($unique_condition, $tmp_clause_is_unique) =
PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
- if (! empty($unique_condition)) {
+ if (! empty($unique_condition)) {
$found_unique_key = true;
}
unset($unique_condition, $tmp_clause_is_unique);
@@ -242,6 +242,7 @@ if (isset($clause_is_unique)) {
}
?>
+
<!-- Insert/Edit form -->
<form method="post" action="tbl_replace.php"
name="insertForm" <?php if ($is_upload) { echo '
enctype="multipart/form-data"'; } ?>>
<?php
@@ -304,7 +305,7 @@ foreach ($rows as $row_id => $vrow) {
<thead>
<tr>
<th><?php echo $strField; ?></th>
-
+
<?php
if ($cfg['ShowFieldTypesInDataEditView']) {
$this_url_params = array_merge($url_params,
@@ -345,8 +346,8 @@ foreach ($rows as $row_id => $vrow) {
// d a t e t i m e
//
// Current date should not be set as default if the field is NULL
- // for the current row, but do not put here the current datetime
- // if there is a default value (the real default value will be set
+ // for the current row, but do not put here the current datetime
+ // if there is a default value (the real default value will be set
// in the Default value logic below)
// Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
@@ -411,10 +412,9 @@ foreach ($rows as $row_id => $vrow) {
if (-1 === $field['len']) {
$field['len'] = PMA_DBI_field_len($vresult, $i);
}
-
- $unnullify_trigger = $chg_evt_handler . "=\"return
unNullify('"
- . PMA_escapeJsString($field['Field_md5']) . "', '"
- . PMA_escapeJsString($jsvkey) . "')\"";
+ //Call validation when the form submited...
+ $unnullify_trigger = $chg_evt_handler . "=\"return
Validator('". PMA_escapeJsString($field['Field_md5']) . "',
'"
+ . PMA_escapeJsString($jsvkey) .
"','".$field['pma_type']."')\"";
// Use an MD5 as an array index to avoid having special characters in the name
atttibute (see bug #1746964 )
$field_name_appendix = $vkey . '[' . $field['Field_md5'] .
']';
@@ -439,7 +439,7 @@ foreach ($rows as $row_id => $vrow) {
<td align="center"<?php echo $field['wrap'];
?>>
<?php echo $field['pma_type']; ?>
</td>
-
+
<?php } //End if
// Prepares the field value
@@ -562,12 +562,12 @@ foreach ($rows as $row_id => $vrow) {
) {
$default_function =
$cfg['DefaultFunctions']['pk_char36'];
}
-
+
// this is set only when appropriate and is always true
if (isset($field['display_binary_as_hex'])) {
$default_function = 'UNHEX';
}
-
+
// loop on the dropdown array and print all available options for that
field.
foreach ($dropdown as $each_dropdown){
echo '<option';
@@ -639,7 +639,7 @@ foreach ($rows as $row_id => $vrow) {
// foreign key in a drop-down
$onclick .= '4, ';
} elseif ($foreigners && isset($foreigners[$field['Field']])
&& $foreignData['foreign_link'] == true) {
- // foreign key with a browsing icon
+ // foreign key with a browsing icon
$onclick .= '6, ';
} else {
$onclick .= '5, ';
diff --git a/themes/darkblue_orange/css/theme_right.css.php
b/themes/darkblue_orange/css/theme_right.css.php
index 2a78ca8..38743e3 100644
--- a/themes/darkblue_orange/css/theme_right.css.php
+++ b/themes/darkblue_orange/css/theme_right.css.php
@@ -1284,3 +1284,8 @@ table#serverconnection_trg_local {
width: 85%;
padding: 0.1em;
}
+/**
+ * Validation error message styles
+ */
+.invalid_value
+{background:#F00;}
\ No newline at end of file
diff --git a/themes/original/css/theme_right.css.php
b/themes/original/css/theme_right.css.php
index acb2c7d..34c5052 100644
--- a/themes/original/css/theme_right.css.php
+++ b/themes/original/css/theme_right.css.php
@@ -1216,3 +1216,8 @@ table#serverconnection_src_local,
table#serverconnection_trg_local {
float:left;
}
+/**
+ * Validation error message styles
+ */
+.invalid_value
+{background:#F00;}
\ No newline at end of file
hooks/post-receive
--
phpMyAdmin