PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/quicky/classes/plugins/function.html_select_time.php

https://bitbucket.org/seyar/ari100krat.local
PHP | 168 lines | 147 code | 16 blank | 5 comment | 25 complexity | 514b8e8c32656a67d62232702ac3f380 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. function quicky_function_html_select_time($params,$quicky)
  3. {
  4. require_once $quicky->fetch_plugin('shared.make_timestamp');
  5. require_once $quicky->fetch_plugin('function.html_options');
  6. /* Default values. */
  7. $prefix = "Time_";
  8. $time = time();
  9. $display_hours = true;
  10. $display_minutes = true;
  11. $display_seconds = true;
  12. $display_meridian = true;
  13. $use_24_hours = true;
  14. $minute_interval = 1;
  15. $second_interval = 1;
  16. /* Should the select boxes be part of an array when returned from PHP?
  17. e.g. setting it to "birthday", would create "birthday[Hour]",
  18. "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".
  19. Can be combined with prefix. */
  20. $field_array = null;
  21. $all_extra = null;
  22. $hour_extra = null;
  23. $minute_extra = null;
  24. $second_extra = null;
  25. $meridian_extra = null;
  26. foreach ($params as $_key=>$_value) {
  27. switch ($_key) {
  28. case 'prefix':
  29. case 'time':
  30. case 'field_array':
  31. case 'all_extra':
  32. case 'hour_extra':
  33. case 'minute_extra':
  34. case 'second_extra':
  35. case 'meridian_extra':
  36. $$_key = (string)$_value;
  37. break;
  38. case 'display_hours':
  39. case 'display_minutes':
  40. case 'display_seconds':
  41. case 'display_meridian':
  42. case 'use_24_hours':
  43. $$_key = (bool)$_value;
  44. break;
  45. case 'minute_interval':
  46. case 'second_interval':
  47. $$_key = (int)$_value;
  48. break;
  49. default:
  50. $quicky->warning("[html_select_time] unknown parameter $_key");
  51. }
  52. }
  53. $time = quicky_make_timestamp($time);
  54. $html_result = '';
  55. if ($display_hours) {
  56. $hours = $use_24_hours ? range(0, 23) : range(1, 12);
  57. $hour_fmt = $use_24_hours ? '%H' : '%I';
  58. for ($i = 0, $for_max = count($hours); $i < $for_max; $i++)
  59. $hours[$i] = sprintf('%02d', $hours[$i]);
  60. $html_result .= '<select name=';
  61. if (null !== $field_array) {
  62. $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
  63. } else {
  64. $html_result .= '"' . $prefix . 'Hour"';
  65. }
  66. if (null !== $hour_extra){
  67. $html_result .= ' ' . $hour_extra;
  68. }
  69. if (null !== $all_extra){
  70. $html_result .= ' ' . $all_extra;
  71. }
  72. $html_result .= '>'."\n";
  73. $html_result .= quicky_function_html_options(array('output' => $hours,
  74. 'values' => $hours,
  75. 'selected' => strftime($hour_fmt, $time),
  76. 'print_result' => false),
  77. $quicky);
  78. $html_result .= "</select>\n";
  79. }
  80. if ($display_minutes) {
  81. $all_minutes = range(0, 59);
  82. for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+= $minute_interval)
  83. $minutes[] = sprintf('%02d', $all_minutes[$i]);
  84. $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);
  85. $html_result .= '<select name=';
  86. if (null !== $field_array) {
  87. $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
  88. } else {
  89. $html_result .= '"' . $prefix . 'Minute"';
  90. }
  91. if (null !== $minute_extra){
  92. $html_result .= ' ' . $minute_extra;
  93. }
  94. if (null !== $all_extra){
  95. $html_result .= ' ' . $all_extra;
  96. }
  97. $html_result .= '>'."\n";
  98. $html_result .= quicky_function_html_options(array('output' => $minutes,
  99. 'values' => $minutes,
  100. 'selected' => $selected,
  101. 'print_result' => false),
  102. $quicky);
  103. $html_result .= "</select>\n";
  104. }
  105. if ($display_seconds) {
  106. $all_seconds = range(0, 59);
  107. for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+= $second_interval)
  108. $seconds[] = sprintf('%02d', $all_seconds[$i]);
  109. $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);
  110. $html_result .= '<select name=';
  111. if (null !== $field_array) {
  112. $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
  113. } else {
  114. $html_result .= '"' . $prefix . 'Second"';
  115. }
  116. if (null !== $second_extra){
  117. $html_result .= ' ' . $second_extra;
  118. }
  119. if (null !== $all_extra){
  120. $html_result .= ' ' . $all_extra;
  121. }
  122. $html_result .= '>'."\n";
  123. $html_result .= quicky_function_html_options(array('output' => $seconds,
  124. 'values' => $seconds,
  125. 'selected' => $selected,
  126. 'print_result' => false),
  127. $quicky);
  128. $html_result .= "</select>\n";
  129. }
  130. if ($display_meridian && !$use_24_hours) {
  131. $html_result .= '<select name=';
  132. if (null !== $field_array) {
  133. $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
  134. } else {
  135. $html_result .= '"' . $prefix . 'Meridian"';
  136. }
  137. if (null !== $meridian_extra){
  138. $html_result .= ' ' . $meridian_extra;
  139. }
  140. if (null !== $all_extra){
  141. $html_result .= ' ' . $all_extra;
  142. }
  143. $html_result .= '>'."\n";
  144. $html_result .= quicky_function_html_options(array('output' => array('AM', 'PM'),
  145. 'values' => array('am', 'pm'),
  146. 'selected' => strtolower(strftime('%p', $time)),
  147. 'print_result' => false),
  148. $quicky);
  149. $html_result .= "</select>\n";
  150. }
  151. return $html_result;
  152. }