<?php
	FNTH_class( "Widget" );

	class FrontendCheckboxList extends FNTHWidget {
		protected $aCheckboxes = array();
		protected $sCheckboxSeparator = " ";

		public function __construct( $id = "FrontendCheckboxList" , $parent = null ) {
			$this->addMediaDirectory( $GLOBALS["site_root"] , $GLOBALS["site_www"] , "design/rp/","widgets/");
			parent::__construct( $id , $parent );
			$this->setParam("language",$GLOBALS["language"]);
			$this->setAttribute( "class" , "FrontendCheckboxList" );
		}

		public function refreshValueFromArray( $arr = null ) {
			if (!isset( $arr )) $arr = $this->aP;
			foreach ($this->aCheckboxes as $name => $chk) {
				$n = $this->getId() . "_" . $name;
				$this->aCheckboxes[$name]["checked"]=isset( $arr[$n] );
			}
		}

		public function clear() { $this->aCheckbox = array(); }
		public function addCheckbox( $name , $label , $checked = false ) {
			$this->aCheckboxes[$name] = array(
				"name" => $name,
				"label" => $label,
				"checked" => $checked );
		}
		
		public function getChecked( $name ) {
			if (!isset( $this->aCheckboxes[$name] )) return false;
			return $this->aCheckboxes[$name]["checked"];
		}

		public function setChecked( $name , $checked = true ) {
			$this->aCheckboxes[$name]["checked"]=$checked;
		}

		protected function initValues() {
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->initValues();
			$this->setParam( "checkboxes" , $this->aCheckboxes );
			$this->setParam( "chk_separator" , $this->sCheckboxSeparator );
			return parent::render();
		}

	}

?>
