[Vtigercrm-commits] [vtiger-commits] r10942 - in /vtigercrm/branches/5.0.3: Smarty/templates/CustomView.tpl include/js/en_us.lang.js modules/CustomView/CustomView.js modules/CustomView/EditView.php modules/CustomView/Save.php

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Wed May 16 08:26:47 EDT 2007


Author: richie
Date: Wed May 16 06:26:32 2007
New Revision: 10942

Log:
* Added validation for Advanced Filter in CustomView

Modified:
    vtigercrm/branches/5.0.3/Smarty/templates/CustomView.tpl
    vtigercrm/branches/5.0.3/include/js/en_us.lang.js
    vtigercrm/branches/5.0.3/modules/CustomView/CustomView.js
    vtigercrm/branches/5.0.3/modules/CustomView/EditView.php
    vtigercrm/branches/5.0.3/modules/CustomView/Save.php

Modified: vtigercrm/branches/5.0.3/Smarty/templates/CustomView.tpl
==============================================================================
--- vtigercrm/branches/5.0.3/Smarty/templates/CustomView.tpl (original)
+++ vtigercrm/branches/5.0.3/Smarty/templates/CustomView.tpl Wed May 16 06:26:32 2007
@@ -9,6 +9,7 @@
  ********************************************************************************/
 -->
 <link rel="stylesheet" type="text/css" media="all" href="jscalendar/calendar-win2k-cold-1.css">
+{$DATE_JS}
 <script type="text/javascript" src="jscalendar/calendar.js"></script>
 <script type="text/javascript" src="jscalendar/lang/calendar-{$APP.LBL_JSCALENDAR_LANG}.js"></script>
 <script type="text/javascript" src="jscalendar/calendar-setup.js"></script>
@@ -650,6 +651,11 @@
 				}
 			}
 		}
+
+if(!checkval())
+	return false;
+
+
 		return true;
 }
 checkDuplicate();

Modified: vtigercrm/branches/5.0.3/include/js/en_us.lang.js
==============================================================================
--- vtigercrm/branches/5.0.3/include/js/en_us.lang.js (original)
+++ vtigercrm/branches/5.0.3/include/js/en_us.lang.js Wed May 16 06:26:32 2007
@@ -126,6 +126,9 @@
                                 TIME_SHOULDNOT_PAST :'Current Time for Activities with status as Planned',
 				LBL_AND : 'And',
 				LBL_ENTER_VALID_PORT: 'Please enter valid port number',
-				IN_USERNAME :' in Username '
+				IN_USERNAME :' in Username ',
+				LBL_ENTER_VALID_NO: 'Please enter valid number',
+				LBL_PROVIDE_YES_NO: ' Invalid value.\n Please Provide Yes or No'
+
 
                        };

Modified: vtigercrm/branches/5.0.3/modules/CustomView/CustomView.js
==============================================================================
--- vtigercrm/branches/5.0.3/modules/CustomView/CustomView.js (original)
+++ vtigercrm/branches/5.0.3/modules/CustomView/CustomView.js Wed May 16 06:26:32 2007
@@ -126,5 +126,145 @@
  return true;
 }
 
-
-
+// Added for Custom View Advance Filter validation
+function checkval()
+{
+	var value,option,arr,dttime;
+	for(var i=1;i<=5;i++)
+	{
+		value=trim(getObj("fval"+i).value);
+		option=getObj("fcol"+i).value;
+		if(option !="" && value !="")
+		{
+			if(getObj("fop"+i).selectedIndex == 0)
+				getObj("fop"+i).selectedIndex=1;
+			arr=option.split(":");
+			if(arr[4] == "N" || arr[4] == "I" || arr[4] == "NN")
+			{
+				if(isNaN(value))
+				{
+					alert(alert_arr.LBL_ENTER_VALID_NO);
+					getObj("fval"+i).select();
+					return false;
+				}
+			}
+			if(arr[4] == "D")
+			{
+				if(!cv_dateValidate(trim(getObj("fval"+i).value),"Date","OTH"))
+				{
+					getObj("fval"+i).select();
+					return false;
+				}
+			}	
+			if(arr[4] == "T")
+			{
+				var dttime=value.split(" ");
+				if(!cv_dateValidate(dttime[0],"Date","OTH"))
+                                {
+                                        getObj("fval"+i).select();
+                                        return false;
+                                }
+
+
+				if(!cv_patternValidate(dttime[1],"Time","TIMESECONDS"))
+				{
+					getObj("fval"+i).select();
+					return false;
+				}
+
+			}	
+			if(arr[4] == "C")
+			{
+				if(value.toLowerCase() != "yes") if(value.toLowerCase() != "no") 
+				{
+					alert(alert_arr.LBL_PROVIDE_YES_NO);
+					getObj("fval"+i).select();
+					return false;
+				}
+			}	
+		}	
+	}
+return true;
+}
+
+//Added for Custom view validation
+//Copied from general.js and altered some lines. becos we cant send vales to function present in general.js. it accept only field names.
+function cv_dateValidate(fldval,fldLabel,type) {
+	if(cv_patternValidate(fldval,fldLabel,"DATE")==false)
+		return false;
+	dateval=fldval.replace(/^\s+/g, '').replace(/\s+$/g, '') 
+
+	var dateelements=splitDateVal(dateval)
+	
+	dd=dateelements[0]
+	mm=dateelements[1]
+	yyyy=dateelements[2]
+	
+	if (dd<1 || dd>31 || mm<1 || mm>12 || yyyy<1 || yyyy<1000) {
+		alert(alert_arr.ENTER_VALID+fldLabel)
+		return false
+	}
+	
+	if ((mm==2) && (dd>29)) {//checking of no. of days in february month
+		alert(alert_arr.ENTER_VALID+fldLabel)
+		return false
+	}
+	
+	if ((mm==2) && (dd>28) && ((yyyy%4)!=0)) {//leap year checking
+		alert(alert_arr.ENTER_VALID+fldLabel)
+		return false
+	}
+
+	switch (parseInt(mm)) {
+		case 2 : 
+		case 4 : 
+		case 6 : 
+		case 9 : 
+		case 11 :	if (dd>30) {
+						alert(alert_arr.ENTER_VALID+fldLabel)
+						return false
+					}	
+	}
+	
+	var currdate=new Date()
+	var chkdate=new Date()
+	
+	chkdate.setYear(yyyy)
+	chkdate.setMonth(mm-1)
+	chkdate.setDate(dd)
+	
+	if (type!="OTH") {
+		if (!compareDates(chkdate,fldLabel,currdate,"current date",type)) {
+			return false
+		} else return true;
+	} else return true;
+}
+
+//Added for Custom view validation
+//Copied from general.js and altered some lines. becos we cant send vales to function present in general.js. it accept only field names.
+function cv_patternValidate(fldval,fldLabel,type) {
+	if (type.toUpperCase()=="DATE") {//DATE validation 
+
+		switch (userDateFormat) {
+			case "yyyy-mm-dd" : 
+								var re = /^\d{4}(-)\d{1,2}\1\d{1,2}$/
+								break;
+			case "mm-dd-yyyy" : 
+			case "dd-mm-yyyy" : 
+								var re = /^\d{1,2}(-)\d{1,2}\1\d{4}$/								
+		}
+	}
+	
+
+	if (type.toUpperCase()=="TIMESECONDS") {//TIME validation
+		var re = new RegExp("^([0-1][0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])$");
+	}
+	if (!re.test(fldval)) {
+		alert(alert_arr.ENTER_VALID + fldLabel)
+		return false
+	}
+	else return true
+}
+
+
+

Modified: vtigercrm/branches/5.0.3/modules/CustomView/EditView.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/CustomView/EditView.php (original)
+++ vtigercrm/branches/5.0.3/modules/CustomView/EditView.php Wed May 16 06:26:32 2007
@@ -41,6 +41,7 @@
 $smarty->assign("CUSTOMVIEWID",$recordid);
 $smarty->assign("DATEFORMAT",$current_user->date_format);
 $smarty->assign("JS_DATEFORMAT",parse_calendardate($app_strings['NTC_DATE_FORMAT']));
+$smarty->assign("DATE_JS", '<script>userDateFormat = "'.$current_user->date_format.'" </script>');
 if($recordid == "")
 {
 	$oCustomView = new CustomView();
@@ -411,13 +412,12 @@
 	//Add the field details in this array if you want to change the advance filter field details
 	//Array in which we have to specify as, existing value => new value
 	$new_field_details = Array(
-				"vtiger_contactsubdetails:birthday:birthday:Contacts_Birthdate:V"=>"vtiger_contactsubdetails:birthday:birthday:Contacts_Birthdate:T",
+				"vtiger_contactsubdetails:birthday:birthday:Contacts_Birthdate:V"=>"vtiger_contactsubdetails:birthday:birthday:Contacts_Birthdate:D",
 				"vtiger_faq:product_id:product_id:Faq_Product_Name:I"=>"vtiger_faq:product_id:product_id:Faq_Product_Name:V",
 				"vtiger_troubletickets:parent_id:parent_id:HelpDesk_Related_to:I"=>"vtiger_troubletickets:parent_id:parent_id:HelpDesk_Related_to:V",
 "vtiger_campaign:product_id:product_id:Campaigns_Product:I"=>"vtiger_campaign:product_id:product_id:Campaigns_Product:V",
 "vtiger_account:email1:email1:Accounts_Email:E"=>"vtiger_account:email1:email1:Accounts_Email:V",
 "vtiger_account:email2:email2:Accounts_Other_Email:E"=>"vtiger_account:email2:email2:Accounts_Other_Email:V",
-"vtiger_contactsubdetails:birthday:birthday:Contacts_Birthdate:V "=>"vtiger_contactsubdetails:birthday:birthday:Contacts_Birthdate:T",
 "vtiger_contactdetails:email:email:Contacts_Email:E"=>"vtiger_contactdetails:email:email:Contacts_Email:V",
 "vtiger_contactdetails:yahooid:yahooid:Contacts_Yahoo_Id:E"=>"vtiger_contactdetails:yahooid:yahooid:Contacts_Yahoo_Id:V",
 "vtiger_account:accountname:accountname:Contacts_Account_Name:I"=>"vtiger_account:accountname:accountname:Contacts_Account_Name:V",
@@ -451,6 +451,13 @@
 "vtiger_purchaseorder:vendorid:vendor_id:PurchaseOrder_Vendor_Name:I"=>"vtiger_purchaseorder:vendorid:vendor_id:PurchaseOrder_Vendor_Name:V",
 "vtiger_purchaseorder:contactid:contact_id:PurchaseOrder_Contact_Name:I"=>"vtiger_purchaseorder:contactid:contact_id:PurchaseOrder_Contact_Name:V",
 
+
+        "vtiger_products:handler:assigned_user_id:Products_Handler:I"=>"vtiger_products:handler:assigned_user_id:Products_Handler:V",
+
+        "vtiger_activity:activitytype:activitytype:Calendar_Activity_Type:C"=>"vtiger_activity:activitytype:activitytype:Calendar_Activity_Type:V",
+        "vtiger_activity:time_start::Calendar_Start_Time:I"=>"vtiger_activity:time_start::Calendar_Start_Time:V",
+
+
 			  );
 
 	if(isset($new_field_details[$field]))

Modified: vtigercrm/branches/5.0.3/modules/CustomView/Save.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/CustomView/Save.php (original)
+++ vtigercrm/branches/5.0.3/modules/CustomView/Save.php Wed May 16 06:26:32 2007
@@ -87,7 +87,7 @@
    	   $string = substr($allKeys[$i], 0, 4);
 	   if($string == "fval")
    	   {
-		   $adv_filter_value[] = htmlentities($_REQUEST[$allKeys[$i]]);
+		   $adv_filter_value[] = htmlentities(trim($_REQUEST[$allKeys[$i]]));
    	   }
 	}
 	//<<<<<<<advancedfilter>>>>>>>>
@@ -242,7 +242,14 @@
 					{
 						$val = Array();
 						for($x=0;$x<count($temp_val);$x++){
-							$val[$x] = getDBInsertDateValue(trim($temp_val[$x]));
+
+								//if date and time given then we have to convert the date and leave the time as it is, if date only given then temp_time value will be empty
+								list($temp_date,$temp_time) = explode(" ",$temp_val[$x]);
+								$temp_date = getDBInsertDateValue(trim($temp_date));
+								if(trim($temp_time) != '')
+									$temp_date .= ' '.$temp_time;
+								$val[$x] = $temp_date;
+			
 						}
 						$adv_filter_value[$i] = implode(", ",$val);	
 					}





More information about the vtigercrm-commits mailing list