<?php
	require_once( $GLOBALS["site_root"] . "/includes/widgets/AdminDate.inc.php" );

	class AdminDateRange extends Widget {
		protected $sFromValue = "";
		protected $sToValue = "";

		public function __construct( $id , $parent ) {
			parent::__construct( $id , $parent );
		}

		protected function initializeWidget() {
			if (!empty( $this->sFromValue )) {
				$this->setParam( "from_d_attrs",
					sprintf( "value=\"%s\"",htmlspecialchars( $this->sFromValue ) ) );
			}

			if (!empty( $this->sToValue )) {
				$this->setParam( "to_d_attrs",
					sprintf( "value=\"%s\"" , htmlspecialchars( $this->sToValue ) ) );
			}
		}

		public function isFromDate() {
			if (empty( $this->sFromValue )) return false;
			if (strlen( $this->sFromValue )!=10) return false;
			return true;
		}

		public function getFromDate() { return $this->sFromValue; }
		public function isToDate() {
			if (empty( $this->sToValue )) return false;
			if (strlen( $this->sFromValue )!=10) return false;
			return true;
		}
		public function getToDate() { return $this->sToValue; }

		public function refreshValueFromArray( $arr = null ) {
			if (!isset( $arr )) $arr = $this->aP;
			$id = $this->getId();

			$from_c =$id."_from_c";
			$from_d =$id."_from_d";
			$to_c =$id."_to_c";
			$to_d =$id."_to_d";
			if (isset( $arr[$from_c] )) $this->bFromChecked = true;
			if (isset( $arr[$from_d] )) $this->sFromValue = $arr[$from_d];
			if (isset( $arr[$to_c] )) $this->bToChecked = true;
			if (isset( $arr[$to_d] )) $this->sToValue = $arr[$to_d];
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$init = sprintf( "InitAdminDateRange( '%s' );\n" , $this->getId() );
			FNTHPage::addUniquePageFullInit( $init );
			$this->initializeWidget();
			return parent::render();
		}
	}
?>
