tbl_change.js.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require '../../../global.inc.php';
  4. ?>
  5. var day;
  6. var month;
  7. var year;
  8. var hour;
  9. var minute;
  10. var second;
  11. var clock_set = 0;
  12. /**
  13. * Opens calendar window.
  14. *
  15. * @param string form name
  16. * @param string field name
  17. */
  18. function openCalendar(form, field) {
  19. formblock= document.getElementById(form);
  20. forminputs = formblock.getElementsByTagName('select');
  21. var datevalues = new Array();
  22. var dateindex = 0;
  23. for (i = 0; i < forminputs.length; i++) {
  24. // regex here to check name attribute
  25. var regex = new RegExp(field, "i");
  26. if (regex.test(forminputs[i].getAttribute('name'))) {
  27. datevalues[dateindex++] = forminputs[i].value;
  28. }
  29. }
  30. window.open("<?php echo api_get_path(WEB_LIBRARY_PATH); ?>formvalidator/Element/calendar_popup.php", "calendar", "width=260,height=230,status=no");
  31. day = datevalues[0];
  32. month = datevalues[1];
  33. year = datevalues[2];
  34. month--;
  35. formName = form;
  36. fieldName =field;
  37. }
  38. /**
  39. * Formats number to two digits.
  40. *
  41. * @param int number to format.
  42. */
  43. function formatNum2(i, valtype) {
  44. f = (i < 10 ? '0' : '') + i;
  45. if (valtype && valtype != '') {
  46. switch(valtype) {
  47. case 'month':
  48. f = (f > 12 ? 12 : f);
  49. break;
  50. case 'day':
  51. f = (f > 31 ? 31 : f);
  52. break;
  53. }
  54. }
  55. return f;
  56. }
  57. /**
  58. * Formats number to four digits.
  59. *
  60. * @param int number to format.
  61. */
  62. function formatNum4(i) {
  63. return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
  64. }
  65. /**
  66. * Initializes calendar window.
  67. */
  68. function initCalendar() {
  69. if (!year && !month && !day) {
  70. day = window.opener.day;
  71. month = window.opener.month;
  72. year = window.opener.year;
  73. if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
  74. dt = new Date();
  75. year = dt.getFullYear();
  76. month = dt.getMonth();
  77. day = dt.getDate();
  78. }
  79. } else {
  80. /* Moving in calendar */
  81. if (month > 11) {
  82. month = 0;
  83. year++;
  84. }
  85. if (month < 0) {
  86. month = 11;
  87. year--;
  88. }
  89. }
  90. if (document.getElementById) {
  91. cnt = document.getElementById("calendar_data");
  92. } else if (document.all) {
  93. cnt = document.all["calendar_data"];
  94. }
  95. cnt.innerHTML = "";
  96. str = ""
  97. //heading table
  98. str += '<table class="calendar"><tr><th class="monthyear" width="50%">';
  99. str += '<a href="javascript:month--; initCalendar();"><?php echo Display::return_icon('action_prev.png',get_lang('Previous'));?></a> ';
  100. str += month_names[month];
  101. str += ' <a href="javascript:month++; initCalendar();"><?php echo Display::return_icon('action_next.png',get_lang('Next'));?></a>';
  102. str += '</th><th class="monthyear" width="50%">';
  103. str += '<a href="javascript:year--; initCalendar();"><?php echo Display::return_icon('action_prev.png',get_lang('Previous'));?></a> ';
  104. str += year;
  105. str += ' <a href="javascript:year++; initCalendar();"><?php echo Display::return_icon('action_next.png',get_lang('Next'));?></a>';
  106. str += '</th></tr></table>';
  107. str += '<table class="calendar"><tr>';
  108. for (i = 0; i < 7; i++) {
  109. str += "<th class='daynames'>" + day_names[i] + "</th>";
  110. }
  111. str += "</tr>";
  112. var firstDay = new Date(year, month, 1).getDay();
  113. var lastDay = new Date(year, month + 1, 0).getDate();
  114. str += "<tr>";
  115. dayInWeek = 0;
  116. for (i = 0; i < firstDay; i++) {
  117. str += "<td>&nbsp;</td>";
  118. dayInWeek++;
  119. }
  120. for (i = 1; i <= lastDay; i++) {
  121. if (dayInWeek == 7) {
  122. str += "</tr><tr>";
  123. dayInWeek = 0;
  124. }
  125. dispmonth = 1 + month;
  126. actVal = formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
  127. if (i == day) {
  128. style = ' class="selected"';
  129. } else {
  130. style = '';
  131. }
  132. str += "<td" + style + "><a href=\"javascript:returnDate(" + i +","+month+","+year + ");\" ><div>" + i + "</div></a></td>"
  133. dayInWeek++;
  134. }
  135. for (i = dayInWeek; i < 7; i++) {
  136. str += "<td>&nbsp;</td>";
  137. }
  138. str += "</tr></table>";
  139. cnt.innerHTML = str;
  140. }
  141. /**
  142. * Returns date from calendar.
  143. *
  144. * @param string date text
  145. */
  146. function returnDate(d,m,y) {
  147. formblock= window.opener.document.getElementById(window.opener.formName);
  148. forminputs = formblock.getElementsByTagName('select');
  149. var datevalues = new Array();
  150. var dateindex = 0;
  151. for (i = 0; i < forminputs.length; i++) {
  152. // regex here to check name attribute
  153. var regex = new RegExp(window.opener.fieldName, "i");
  154. if (regex.test(forminputs[i].getAttribute('name'))) {
  155. datevalues[dateindex] = forminputs[i];
  156. dateindex++;
  157. window.close();
  158. }
  159. }
  160. datevalues[0].selectedIndex = (d-1) ;
  161. datevalues[1].selectedIndex = m;
  162. date = new Date();
  163. //Selecting the first option of the year
  164. year = datevalues[2].options[0].value;
  165. datevalues[2].selectedIndex = y - year;
  166. for(i = 0; i<= 3; i++) {
  167. attributes = datevalues[i].attributes;
  168. for (attr=0; attr<attributes.length; attr++)
  169. if(attributes[attr].nodeName == 'onchange') {
  170. datevalues[i].onchange();
  171. }
  172. }
  173. window.close();
  174. }