<?php
	require_once dirname(__FILE__)."/../bin/web/repeater.php";
	require_once dirname(__FILE__)."/../dal/pictureDAL.php";

	class _banner extends webPartBase{
		public $is_index = false;
		public $picturetype = 30;
		public $NoPicImage;

		public function load(){
			$this->loadData();
			parent::load();
		}
		public function loadData(){
			$dalP = new pictureDAL();

			if(!$this->is_index && $this->registry->pageBannerType == "20"){
				$dalP->PictureType = $this->picturetype;
				$dalP->TypeOrderNO = "0";
				$dalP->loadRecord();
				if(trim($dalP->Image) == '' || !file_exists(".".$dalP->Image)){
					parent::addParameter("Image",$this->NoPicImage);
				}else{
					parent::addParameter("Image",$dalP->Image);
				}
				parent::addParameter("Title",$dalP->Title);
				if(trim($dalP->Link) == ''){
					parent::addParameter("Link","javascript:void(0);");
				}else{
					parent::addParameter("Link",$dalP->Link);
				}

				parent::loadTemplateFile(dirname(__FILE__)."/../templates/webParts/".$this->registry->webTemplates."/banner_sub.html");
			}else{
				$aryP = array();
				$dataP = $dalP->executeRecordset("a.`PictureType`='30'","a.`TypeOrderNO`");
				for($i=0;$i<count($dataP);$i++){
					if(trim($dataP[$i]["Image"]) != "" && file_exists(".".$dataP[$i]["Image"])){
						$ary = array();
						$ary["Image"] = $dataP[$i]["Image"];
						$ary["Title"] = $dataP[$i]["Title"];
						if(trim($dataP[$i]["Link"]) == ""){
							$ary["Link"] = "javascript:void(0);";
						}else{
							$ary["Link"] = $dataP[$i]["Link"];
						}
						$ary["BanColor"] = $dataP[$i]["BanColor"];
						$ary["DanDesc"] = $dataP[$i]["DanDesc"];
						$aryP[] = $ary;
						$aryP2[] = "\"".$dataP[$i]["Image"]."\"";
					}
				}
				$listP = new repeater();
				$listP->id = "listP";
				$listP->dataSource = $aryP;
				parent::addControl($listP);
				
				$listP2 = new repeater();
				$listP2->id = "listP2";
				$listP2->dataSource = $aryP;
				parent::addControl($listP2);
				
				$txtP2 = implode(",", $aryP2);
				parent::addParameter("txtP2", $txtP2);

				parent::loadTemplateFile(dirname(__FILE__)."/../templates/webParts/".$this->registry->webTemplates."/banner_main.html");
			}
		}
	}
?>