PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Dashboard/Forms.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 166 lines | 114 code | 16 blank | 36 comment | 50 complexity | 206034b1755eb6e97d3d6693c1c99109 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /*********************************************************************************
  3. * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
  4. * ("License"); You may not use this file except in compliance with the
  5. * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
  6. * Software distributed under the License is distributed on an "AS IS" basis,
  7. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  8. * the specific language governing rights and limitations under the License.
  9. * The Original Code is: SugarCRM Open Source
  10. * The Initial Developer of the Original Code is SugarCRM, Inc.
  11. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12. * All Rights Reserved.
  13. * Contributor(s): ______________________________________.
  14. ********************************************************************************/
  15. /*********************************************************************************
  16. * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Dashboard/Forms.php,v 1.2 2004/10/06 09:02:05 jack Exp $
  17. * Description: Contains a variety of utility functions used to display UI
  18. * components such as form vtiger_headers and footers. Intended to be modified on a per
  19. * theme basis.
  20. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  21. * All Rights Reserved.
  22. * Contributor(s): ______________________________________..
  23. ********************************************************************************/
  24. /**
  25. * Create javascript to validate the data entered into a record.
  26. */
  27. function get_validate_chart_js () {
  28. global $mod_strings;
  29. global $app_strings;
  30. $err_invalid_date_format = $app_strings['ERR_INVALID_DATE_FORMAT'];
  31. $err_invalid_month = $app_strings['ERR_INVALID_MONTH'];
  32. $err_invalid_day = $app_strings['ERR_INVALID_DAY'];
  33. $err_invalid_year = $app_strings['ERR_INVALID_YEAR'];
  34. $err_invalid_date = $app_strings['ERR_INVALID_DATE'];
  35. $the_script = <<<EOQ
  36. <script type="text/javascript" language="Javascript">
  37. <!-- to hide script contents from old browsers
  38. /**
  39. * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
  40. */
  41. // Declaring valid date character, minimum year and maximum year
  42. var dtCh= "-";
  43. var minYear=1900;
  44. var maxYear=2100;
  45. function isInteger(s){
  46. var i;
  47. for (i = 0; i < s.length; i++){
  48. // Check that current character is number.
  49. var c = s.charAt(i);
  50. if (((c < "0") || (c > "9"))) return false;
  51. }
  52. // All characters are numbers.
  53. return true;
  54. }
  55. function stripCharsInBag(s, bag){
  56. var i;
  57. var returnString = "";
  58. // Search through string's characters one by one.
  59. // If character is not in bag, append to returnString.
  60. for (i = 0; i < s.length; i++){
  61. var c = s.charAt(i);
  62. if (bag.indexOf(c) == -1) returnString += c;
  63. }
  64. return returnString;
  65. }
  66. function daysInFebruary (year){
  67. // February has 29 days in any year evenly divisible by four,
  68. // EXCEPT for centurial years which are not also divisible by 400.
  69. return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
  70. }
  71. function DaysArray(n) {
  72. for (var i = 1; i <= n; i++) {
  73. this[i] = 31
  74. if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
  75. if (i==2) {this[i] = 29}
  76. }
  77. return this
  78. }
  79. function isDate(dtStr){
  80. var daysInMonth = DaysArray(12)
  81. var pos1=dtStr.indexOf(dtCh)
  82. var pos2=dtStr.indexOf(dtCh,pos1+1)
  83. var strYear=dtStr.substring(0,pos1)
  84. var strMonth=dtStr.substring(pos1+1,pos2)
  85. var strDay=dtStr.substring(pos2+1)
  86. strYr=strYear
  87. if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
  88. if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
  89. for (var i = 1; i <= 3; i++) {
  90. if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
  91. }
  92. month=parseInt(strMonth)
  93. day=parseInt(strDay)
  94. year=parseInt(strYr)
  95. if (pos1==-1 || pos2==-1){
  96. alert("$err_invalid_date_format")
  97. return false
  98. }
  99. if (strMonth.length<1 || month<1 || month>12){
  100. alert("$err_invalid_month")
  101. return false
  102. }
  103. if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
  104. alert("$err_invalid_day")
  105. return false
  106. }
  107. if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
  108. alert("$err_invalid_year")
  109. return false
  110. }
  111. if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
  112. alert("$err_invalid_date")
  113. return false
  114. }
  115. return true
  116. }
  117. function verify_chart_data(form) {
  118. var isError = false;
  119. var errorMessage = "";
  120. if (form.date_start.value == '' && isDate(form.date_start.value)==false) {
  121. return false;
  122. }
  123. else if (form.date_end.value == '' && isDate(form.date_end.value)==false) {
  124. return false;
  125. }
  126. else
  127. return true;
  128. }
  129. function chk_form(form)//function added by sandeep
  130. {
  131. var a=form.date_start.value.split('-')
  132. var sdate=new Date(a[0],a[1],a[2])
  133. var a=form.date_end.value.split('-')
  134. var edate=new Date(a[0],a[1],a[2])
  135. if(sdate>edate)
  136. {
  137. alert("Start Date should be less than End Date")
  138. return false;
  139. }
  140. else
  141. {
  142. return verify_chart_data(form);
  143. }
  144. }
  145. // end hiding contents from old browsers -->
  146. </script>
  147. EOQ;
  148. return $the_script;
  149. }
  150. ?>