<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 1.0.00
// Randem Systems: https://randemsystems.support
// BotBanish Form Input Formation
// Date: 04/04/2021
// Usage: https://BotBanish/BotBanish_Report.php?rpt_date=2021-02-01&days=15
//
// Function: Include file for BotBanish.php date related functions
///////////////////////////////////////////////////////////////////////////////////////////////////////

	//Base class for a form input. Holds the 'name' parameter
	class clsFormInput {

		public $name;

		function __construct( $SelectName) {
			$this->name = $SelectName;
		}
	}

	//Base class for a <select...> input. Defines functions which print the start/end tags
	class SelectInput extends clsFormInput	{
		function printSelect($onchange = '') {
			
			//print the input
			$str = "\n\n";
			$str .= '<select name="' . $this->name . '" id="' . $this->name . '" ' . $onchange. '>';
			$str .= "\n";
			return $str;
		}

		function printEndSelect() {
			$str = "</select>\n\n";
			return $str;
		}
	}

	class HourInput extends SelectInput	{

	function create($selectedIndex = 9, $onchange = '', $hour24 = false) {
		
			$js = !empty($onchange) ? $onchange : '';
			$str = $this->printSelect($js);

			//work out whether we want to display time in 12 or 24 hour format

			if (!$hour24)
				$str .= $this->create_12hour($selectedIndex);
			else
				$str .= $this->create_24hour($selectedIndex);

			$str .= $this->printEndSelect();
			return $str;
		}

		function create_12hour($selectedIndex = -1) {
			
//			$str = '';
			$str = "<option value=\"-1\"></option>\n";
			
			for ($i=0;$i<24;$i++) {
				if ($i == 0)
					$display_time = "12 am";
				elseif ($i == 12)
					$display_time = "12 pm";
				elseif ($i > 12 && $i<24)
					$display_time = $i-12 . " pm";
				else
					$display_time = "$i am";

				if ($i == $selectedIndex)
					$str .= "<option value=\"$i\" selected>$display_time</option>\n";
				else
					$str .= "<option value=\"$i\">$display_time</option>\n";
			}
			return $str;
		}

		function create_24hour($selectedIndex = 9) {
			
			$str = '';
			
			for ($i=0;$i<24;$i++) {
				$display_time = "$i";

				if ($i == $selectedIndex)
					$str .= "<option value=\"$i\" selected>$display_time</option>\n";
				else
					$str .= "<option value=\"$i\">$display_time</option>\n";
			}
			return $str;
		}
	}

	class MinuteInput extends SelectInput {

		function create($selectedMinute = 0, $onchange = '') 	{
			
			$js = !empty($onchange) ? $onchange : '';
			$str = $this->printSelect($js);

			for ($i=0;$i<60;$i+=5) {
				$str .= "<option value=\"$i\"";
					if ($selectedMinute > $i - 2 && $selectedMinute < $i + 3)
						$str .= " selected";
				$str .= sprintf(">%02d</option>\n", $i);
			}

			$str .= $this->printEndSelect();
			return $str;
		}
	}

	class MonthInput extends SelectInput {
		function create($selectedMonth = 1, $onchange = '')	{

			$js = !empty($onchange) ? $onchange : '';
			$str = $this->printSelect($js);

			for ($i=1; $i<=12; $i++) {
				$str .= "<option value=\"$i\"";
				if ($i == $selectedMonth)
					$str .= " selected";
				$str .= ">" . date("F", mktime(0,0,0,$i,1,2000)) . "</option>\n";
			}

			$str .= $this->printEndSelect();
			return $str;
		}
	}

	class DayInput extends SelectInput {

		function create($selectedDay = 1, $onchange = '') 	{

			$js = !empty($onchange) ? $onchange : '';
			$str = $this->printSelect($js);

			for ($i=1; $i<=31; $i++) {
				$str .= "<option value=\"$i\"";
				if ($i == $selectedDay)
					$str .= " selected";
				$str .= ">$i</option>\n";
			}

			$this->printEndSelect();
			return $str;
		}
	}

?>
