timepicker.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. $time_format = elgg_get_plugin_setting('timeformat', 'event_calendar');
  3. if (!$time_format) {
  4. $time_format = '24';
  5. }
  6. $value = $vars['value'];
  7. if (is_numeric($value)) {
  8. $hour = floor($value/60);
  9. $minute = ($value -60*$hour);
  10. } else {
  11. $hour = 0;
  12. $minute = 0;
  13. }
  14. $hours = array();
  15. $minutes = array();
  16. if ($time_format == '12') {
  17. $meridians = array('am'=>'am','pm'=>'pm');
  18. if ($hour == 0) {
  19. $hour = 12;
  20. $meridian = 'am';
  21. } else if ($hour == 12) {
  22. $meridian = 'pm';
  23. } else if ($hour < 12) {
  24. $meridian = 'am';
  25. } else {
  26. $hour -= 12;
  27. $meridian = 'pm';
  28. }
  29. for($h=1;$h<=12;$h++) {
  30. $hours[$h] = $h;
  31. }
  32. } else {
  33. for($h=0;$h<=23;$h++) {
  34. $hours[$h] = $h;
  35. }
  36. }
  37. for($m=0;$m<60;$m=$m+5) {
  38. $mt = sprintf("%02d",$m);
  39. $minutes[$m] = $mt;
  40. }
  41. echo elgg_view('input/dropdown',array('name'=>$vars['name'].'_hour','value'=>$hour,'options_values'=>$hours));
  42. echo " <b>:</b> ";
  43. echo elgg_view('input/dropdown',array('name'=>$vars['name'].'_minute','value'=>$minute,'options_values'=>$minutes));
  44. if ($time_format == '12') {
  45. echo elgg_view('input/dropdown',array('name'=>$vars['name'].'_meridian','value'=>$meridian,'options_values'=>$meridians));
  46. }