<?php
	require_once dirname(dirname(__FILE__))."/registry.php";
	require_once dirname(dirname(__FILE__))."/bin/web/page.php";
	require_once dirname(dirname(__FILE__))."/bin/web/tables/article.php";
	require_once dirname(dirname(__FILE__))."/bin/web/tables/news.php";
	require_once dirname(dirname(__FILE__))."/bin/web/tables/faq.php";
	require_once dirname(dirname(__FILE__))."/bin/web/tables/product.php";
	require_once dirname(dirname(__FILE__))."/bin/web/tables/book.php";
	require_once dirname(dirname(__FILE__))."/bin/web/tables/contact.php";
	require_once dirname(dirname(__FILE__))."/bin/web/tables/order.php";
	require_once dirname(dirname(__FILE__))."/dal/pictureDAL.php";
	require_once dirname(dirname(__FILE__))."/dal/templateDAL.php";
	require_once dirname(dirname(__FILE__))."/dal/webmenuDAL.php";
	require_once dirname(dirname(__FILE__))."/dal/customDAL.php";

	class webPartBase extends page {
		public $article, $news, $faq, $product, $book, $contact, $order;
		public $NoPicImage;
		
		public function __construct() {
			$classNames = [ "article", "news", "faq", "product", "book", "contact", "order" ];
			foreach ($classNames as $className) {
				$this->setComponent($className);
			}

			$dalP = new pictureDAL();
			$dalP->PictureType = "0";
			$dalP->TypeOrderNO = "0";
			$dalP->loadRecord();
			$this->NoPicImage = (parent::image_exists($dalP->Image) && $dalP->Image !== '') ? $dalP->Image : '/images/no-pic.jpg';
	
			parent::__construct();
		}
		public function load(){
			// 版型額外設定
			$dalT = new templateDAL();
			$dalT->PathName = $this->registry->webTemplates;
			$dalT->loadRecord();
			if (count($dalT->SetArray) > 0) {
				foreach ($dalT->SetArray as $row) {
					parent::addParameter($row["SetName"], $row["SetValue"]);
				}
			}
			
			//加載模板
			$htLinks = [ "htLink1" => 2, "htLink2" => 4, "htLink3" => 5, "htLink4" => 3, "htLink5" => 6, "htLink6" => 7, "htLink7" => 8 ];
			foreach ($htLinks as $name => $value) {
				parent::addParameter($name, $this->formatLink($value, 1, 0));
			}

			//側欄選單標題
			$sideNavProps = [ "sideNavInfo", "sideNavProduct", "sideNavPhoto", "sideExtraInfo" ];
			foreach ($sideNavProps as $prop) {
				$value = $this->registry->$prop;
				parent::addParameter($prop, $value);
				if ($value === "") parent::addParameter($prop . "Style", " style=\"display:none;\"");
			}

			//自訂欄位
			////迴圈
			$dalC = new customDAL();
			$arrC = [];
			$dataC = $dalC->executeRecordset(
				intoAry: [],
				filter: "a.`Visible`=1 AND a.`Disable`=0"
			);
			foreach ($dataC as $key => &$item) {
				$item["NO"] = ++$key;
				$item["CustomContent"] = str_replace("\r\n", "<br />", $item["CustomContent"]);
				$item["imageStyle"] = "";
				if ($item["CustomImage"] == "" || !parent::image_exists($item["CustomImage"])) {
					$item["CustomImage"] = $this->NoPicImage;
					$item["imageStyle"] = " style='display: none;'";
				}
				if ($item["CustomLink"] == "") $item["CustomLink"] = "javascript:void(0);";
				$arrC[] = $item;
				
				if ($key < 3) {
					parent::addParameter("customTitle" . $key, $item["CustomTitle"]);
					parent::addParameter("customContent" . $key, $item["CustomLink"]);
				}
			}
			$listC = new repeater();
			$listC->id = "listC";
			$listC->dataSource = $arrC;
			parent::addControl($listC);
			$listC2 = new repeater();
			$listC2->id = "listC2";
			$listC2->dataSource = $arrC;
			parent::addControl($listC2);
			$customClass = count($arrC) === 0 ? " noneCI" : "";
			parent::addParameter("customClass", $customClass);
			
			parent::load();
		}
		
		// 建立模板
		private function setComponent($name) {
			$propertyName = strtolower($name);
			$this->$propertyName = new $name();
		}
		
		// 產生額外資訊格式
		public function formatExtra(array $data = []): array {
			$linkTarget = (parent::generateIosDevice()) ? " target=\"_blank\"" : "";
			
			$result = [];
			foreach ($data as $row) {
				if ($row["Name"] !== "") {
					if (preg_match("/^[2-8]$/", $row["Type"])) {
						if ($row["Type"] == "6") {
							$row["HtmlCode"] = "<a href='https://line.me/R/ti/p/~" . $row["Value"] . "' title='" . $row["Value"] . "'" . $linkTarget . ">" . $row["Value"];
						} else {
							$row["HtmlCode"] = "<a href='" . $row["Link"] . "' title='" . $row["Value"] . "'";
							if (in_array($row["Type"], ["2", "8"])) $row["HtmlCode"] .= " target='_blank'";
							if ($row["Type"] == "5") $row["HtmlCode"] .= " data-fancybox";
							$row["HtmlCode"] .= ">" . $row["Value"];
						}
						
						if (in_array($row["Type"], ["2", "5", "6", "7", "8"]) && $row["Icon"] !== "" && $this->image_exists($row["Icon"])) $row["HtmlCode"] .= "<img src='" . $row["Icon"] . "'>";
						
						$row["HtmlCode"] .= "</a>";
					} else {
						$row["HtmlCode"] = $row["Value"];
					}
					
					$result[] = $row;
				}
			}
			
			return $result;
		}

		// 產生浮動按鈕格式
		public function formatFloat(array $data = []): array {
			$linkTarget = (parent::generateIosDevice()) ? " target=\"_blank\"" : "";
			
			$result = [];
			foreach ($data as &$row) {
				$arr_class = [ "1" => "fa-link", "2" => "fa-phone", "3" => "fa-commenting", "4" => "fa-wechat", "5" => "fa-envelope", "6" => "fa-facebook" ];
				$arr_link = [ "1" => $row["Value"], "2" => "tel:" . $row["Value"], "3" => "https://line.me/R/ti/p/~" . $row["Value"], "4" => $row["Value"], "5" => "mailto:" . $row["Value"], "6" => $row["Value"] ];
				if (empty($row["Class"])) {
					$row["class"] = $arr_class[$row["Type"]];
					$row["link"] = $arr_link[$row["Type"]];
					$row["target"] = ($row["Type"] == "3") ? $linkTarget : "";
				} else {
					$row["class"] = $row["Class"];
				}
    
				if (empty($row["Icon"]) || !parent::image_exists($row["Icon"])) {
					$row["Icon"] = $this->NoPicImage;
					$row["istyle"] = "";
				} else {
					$row["istyle"] = " style='background-image:url(" . $row["Icon"] . ")'";
				}

				if(!empty($row["Value"])) $result[] = $row;
			}
			return $result;
		}

		// 產生主選單結構-關於我們
		public function formatArticleWebMenu(int $childType = 1, int $childTarget = 0, int $showType = 0 , int $categoryID = 0): string {
			$dalC = new article_categoryDAL();
			$dal = new articleDAL();

			$intoAry = [];
			$dataS = [];
			$iLabel = "<b><i class=\"fa fa-plus\" aria-hidden=\"true\"></i></b>";
			$html = "";
			$subtarget = ($childTarget === 1) ? " target=\"_blank\"" : "";

			if ($childType === 1) {
				$dataS = $dalC->executeRecordset($intoAry, "a.`Visible`=1 AND a.`Disable`=0", "a.`OrderNO`");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$sublink = $this->formatLink(2, 1, $rows["CategoryID"]);
						if ($showType === 0) {
							$html .= "<li><a href=\"" . $sublink . "\"" . $subtarget . " title=\"" . $rows["CategoryName"] . "\">" . $rows["CategoryName"] . "</a></li>";
						} else {
							$html .= "<li><div><p><a href=\"" . $sublink . "\"" . $subtarget . " title=\"" . $rows["CategoryName"] . "\">" . $rows["CategoryName"] . "</a></p></div></li>";
						}
					}
					$html .= "</ul>";
				}
			} else if ($childType === 2) {
				$intoAry[] = $this->addArray(":categoryID", $categoryID, "int");
				$dataS = $dal->executeRecordset($intoAry, "a.`CategoryID`=:categoryID AND a.`Visible`=1 AND a.`Disable`=0");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$sublink = $this->formatLink(2, 0, $rows["ArticleID"]);
						if ($showType === 0) {
							$html .= "<li><a href=\"" . $sublink . "\"" . $subtarget . " title=\"" . $rows["Title"] . "\">" . $rows["Title"] . "</a></li>";
						} else {
							$html .= "<li><div><p><a href=\"" . $sublink . "\"" . $subtarget . " title=\"" . $rows["Title"] . "\">" . $rows["Title"] . "</a></p></div></li>";
						}
					}
					$html .= "</ul>";
				}
			}

			return $html;
		}

		// 產生主選單結構-產品
		public function formatProductWebMenu(int $childType = 1, int $childTarget = 0, int $showType = 0 , int $categoryID = 0): string {
			$dalC = new categoryDAL();
			$dal = new productDAL();

			$intoAry = [];
			$dataS = [];
			$iLabel = "<b><i class=\"fa fa-plus\" aria-hidden=\"true\"></i></b>";
			$html = "";
			$subtarget = ($childTarget=== 1) ? " target=\"_blank\"" : "";

			if ($childType === 1) {
				$intoAry[] = $this->addArray(":parentID", $categoryID, "int");
				$dataS = $dalC->executeRecordset($intoAry, "a.`ParentID`=:parentID AND a.`Visible`=1 AND a.`Disable`=0", "a.`OrderNO`");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$into2Ary = [ $this->addArray(":parentID", $rows["CategoryID"], "int") ];
						$dataS2 = $dalC->executeRecordset($into2Ary, "a.`ParentID`=:parentID AND a.`Visible`=1 AND a.`Disable`=0", "a.`OrderNO`");

						$sublink = $this->formatLink(3, 1, $rows["CategoryID"]);
						if ($showType === 0) $html .= "<li><a href=\"" . $sublink . "\"" . $subtarget . ">".$rows["CategoryName"]."</a>";
						if (count($dataS2) > 0) {
							if ($showType === 0) {
								$html .= "<ul class=\"sub2nav\">";
							} else {
								$html .= "<li><div class=\"sub2Title bo\"><p><a title=\"" . $rows["CategoryName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["CategoryName"] . "</a></p>" .$iLabel . "</div>";
								$html .= "<ul class=\"sub2Option\">";
							}
							foreach ($dataS2 as $rows2) {
								$into3Ary = [ $this->addArray(":parentID", $rows2["CategoryID"], "int") ];
								$dataS3 = $dalC->executeRecordset($into3Ary, "a.`ParentID`=:parentID AND a.`Visible`=1 AND a.`Disable`=0", "a.`OrderNO`");

								$sub2link = $this->formatLink(3, 1, $rows2["CategoryID"]);

								if ($showType === 0) $html .= "<li><a title=\"" . $rows2["CategoryName"] . "\" href=\"" . $sub2link . "\"" . $subtarget . ">" . $rows2["CategoryName"] . "</a>";
								if (count($dataS3) > 0) {
									if ($showType === 0) {
										$html .= "<ul class=\"sub3nav\">";
									} else {
										$html .= "<li><div class=\"sub3Title bo\"><p><a title=\"" . $rows2["CategoryName"] . "\" href=\"" . $sub2link . "\"" . $subtarget . ">" . $rows2["CategoryName"] . "</a></p>" . $iLabel . "</div>";
										$html .= "<ul class=\"sub3Option\">";
									}
									foreach ($dataS3 as $rows3) {
										$sub3link = $this->formatLink(3, 1, $rows3["CategoryID"]);
										if ($showType === 0) {
											$html .= "<li><a title=\"" . $rows3["CategoryName"] . "\" href=\"" . $sub3link . "\"" . $subtarget . ">" . $rows3["CategoryName"] . "</a></li>";
										} else {
											$html .= "<li><div><p><a title=\"" . $rows3["CategoryName"] . "\" href=\"" . $sub3link . "\"" . $subtarget . ">" . $rows3["CategoryName"] . "</a></p></div></li>";
										}
									}
									$html .= "</ul>";
								}else{
									if ($showType === 1) $html .= "<li><div class=\"sub3Title\"><p><a title=\"" . $rows2["CategoryName"] . "\" href=\"" . $sub2link . "\"" . $subtarget . ">" . $rows2["CategoryName"] . "</a></p></div>";
								}
								$html .= "</li>";
							}
							$html .= "</ul>";
						} else {
							if ($showType === 1) $html .= "<li><div class=\"sub2Title\"><p><a title=\"" . $rows["CategoryName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["CategoryName"] . "</a></p></div>";
						}
						$html .= "</li>";
					}
					$html .= "</ul>";
				}
			} else if ($childType === 2) {
				$intoAry[] = $this->addArray(":categoryID", $categoryID, "int");
				$dataS = $dal->executeRecordset($intoAry, "a.`CategoryID`=:categoryID AND a.`Visible`=1 AND a.`Disable`=0");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$sublink = $this->formatLink(3, 0, $rows["ProductID"]);
						if ($showType === 0) {
							$html .= "<li><a title=\"" . $rows["ProductName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["ProductName"] . "</a></li>";
						} else {
							$html .= "<li><div><p><a title=\"" . $rows["ProductName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["ProductName"] . "</a></p></div></li>";
						}
					}
					$html .= "</ul>";
				}
			}

			return $html;
		}

		// 產生主選單結構-最新消息
		public function formatNewsWebMenu(int $childType = 1, int $childTarget = 0, int $showType = 0 , int $categoryID = 0): string {
			$dalC = new news_categoryDAL();
			$dal = new newsDAL();

			$intoAry = [];
			$dataS = [];
			$iLabel = "<b><i class=\"fa fa-plus\" aria-hidden=\"true\"></i></b>";
			$html = "";
			$subtarget = ($childTarget=== 1) ? " target=\"_blank\"" : "";

			if ($childType === 1) {
				$dataS = $dalC->executeRecordset($intoAry, "a.`Visible`=1 AND a.`Disable`=0", "a.`OrderNO`");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$sublink = $this->formatLink(4, 1, $rows["CategoryID"]);
						if ($showType === 0) {
							$html .= "<li><a title=\"" . $rows["CategoryName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["CategoryName"] . "</a></li>";
						} else {
							$html .= "<li><div><p><a title=\"" . $rows["CategoryName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["CategoryName"] . "</a></p></div></li>";
						}
					}
					$html .= "</ul>";
				}
			} else if ($childType === 2) {
				$intoAry[] = $this->addArray(":categoryID", $categoryID, "int");
				$dataS = $dal->executeRecordset($intoAry, "a.`CategoryID`=:categoryID AND a.`Visible`=1 AND a.`Disable`=0");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$sublink = $this->formatLink(4, 0, $rows["NewsID"]);
						if ($showType === 0) {
							$html .= "<li><a title=\"" . $rows["Title"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["Title"] . "</a></li>";
						} else {
							$html .= "<li><div><p><a title=\"" . $rows["Title"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["Title"] . "</a></p></div></li>";
						}
					}
					$html .= "</ul>";
				}
			}

			return $html;
		}

		// 產生主選單結構-問與答
		public function formatFaqWebMenu(int $childType = 1, int $childTarget = 0, int $showType = 0 , int $categoryID = 0): string {
			$dalC = new faq_categoryDAL();
			$dal = new faqDAL();

			$intoAry = [];
			$dataS = [];
			$iLabel = "<b><i class=\"fa fa-plus\" aria-hidden=\"true\"></i></b>";
			$html = "";
			$subtarget = ($childTarget=== 1) ? " target=\"_blank\"" : "";

			if ($childType === 1) {
				$dataS = $dalC->executeRecordset($intoAry, "a.`Visible`=1 AND a.`Disable`=0", "a.`OrderNO`");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$sublink = $this->formatLink(5, 1, $rows["CategoryID"]);
						if ($showType === 0) {
							$html .= "<li><a title=\"" . $rows["CategoryName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["CategoryName"] . "</a></li>";
						} else {
							$html .= "<li><div><p><a title=\"" . $rows["CategoryName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["CategoryName"] . "</a></p></div></li>";
						}
					}
					$html .= "</ul>";
				}
			} else if ($childType === 2) {
				$intoAry[] = $this->addArray(":categoryID", $categoryID, "int");
				$dataS = $dal->executeRecordset($intoAry, "a.`CategoryID`=:categoryID AND a.`Visible`=1 AND a.`Disable`=0");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$sublink = $this->formatLink(4, 5, $rows["FaqID"]);
						if ($showType === 0) {
							$html .= "<li><a title=\"" . $rows["Title"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["Title"] . "</a></li>";
						} else {
							$html .= "<li><div><p><a title=\"" . $rows["Title"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["Title"] . "</a></p></div></li>";
						}
					}
					$html .= "</ul>";
				}
			}

			return $html;
		}

		// 產生主選單結構-相本
		public function formatBooksWebMenu(int $childType = 1, int $childTarget = 0, int $showType = 0 , int $categoryID = 0): string {
			$dalC = new book_categoryDAL();
			$dal = new bookDAL();

			$intoAry = [];
			$dataS = [];
			$iLabel = "<b><i class=\"fa fa-plus\" aria-hidden=\"true\"></i></b>";
			$html = "";
			$subtarget = ($childTarget=== 1) ? " target=\"_blank\"" : "";

			if ($childType === 1) {
				$intoAry[] = $this->addArray(":parentID", $categoryID, "int");
				$dataS = $dalC->executeRecordset($intoAry, "a.`ParentID`=:parentID AND a.`Visible`=1 AND a.`Disable`=0", "a.`OrderNO`");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$into2Ary = [ $this->addArray(":parentID", $rows["CategoryID"], "int") ];
						$dataS2 = $dalC->executeRecordset($into2Ary, "a.`ParentID`=:parentID AND a.`Visible`=1 AND a.`Disable`=0", "a.`OrderNO`");

						$sublink = $this->formatLink(6, 1, $rows["CategoryID"]);
						
						if ($showType === 0) $html .= "<li><a href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["CategoryName"] . "</a>";
						if (count($dataS2) > 0) {
							if ($showType === 0) {
								$html .= "<ul class=\"sub2nav\">";
							} else {
								$html .= "<li><div class=\"sub2Title bo\"><p><a title=\"" . $rows["CategoryName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["CategoryName"] . "</a></p>" . $iLabel . "</div>";
								$html .= "<ul class=\"sub2Option\">";
							}
							foreach ($dataS2 as $rows2) {
								$into3Ary = [ $this->addArray(":parentID", $rows2["CategoryID"], "int") ];
								$dataS3 = $dalC->executeRecordset($into3Ary, "a.`ParentID`=:parentID AND a.`Visible`=1 AND a.`Disable`=0", "a.`OrderNO`");

								$sub2link = $this->formatLink(6, 1, $rows2["CategoryID"]);
								if ($showType === 0) $html .= "<li><a title=\"" . $rows2["CategoryName"] . "\" href=\"" . $sub2link . "\"" . $subtarget . ">" . $rows2["CategoryName"] . "</a>";
								if (count($dataS3) > 0) {
									if ($showType === 0) {
										$data[$i]["SubList"] .= "<ul class=\"sub3nav\">";
									} else {
										$html .= "<li><div class=\"sub3Title bo\"><p><a title=\"" . $rows2["CategoryName"] . "\" href=\"" . $sub2link . "\"" . $subtarget . ">" . $rows2["CategoryName"] . "</a></p>" . $iLabel . "</div>";
										$html .= "<ul class=\"sub3Option\">";
									}
									foreach ($dataS3 as $rows3) {
										$sub3link = $this->formatLink(6, 1, $rows3["CategoryID"]);
										if ($showType === 0) {
											$html .= "<li><a title=\"" . $rows3["CategoryName"] . "\" href=\"" . $sub3link . "\"" . $subtarget . ">" . $rows3["CategoryName"] . "</a></li>";
										} else {
											$html .= "<li><div><p><a title=\"" . $rows3["CategoryName"] . "\" href=\"" . $sub3link . "\"" . $subtarget . ">" . $rows3["CategoryName"] . "</a></p></div></li>";
										}
									}
									$html .= "</ul>";
								}else{
									$html .= "<li><div class=\"sub3Title\"><p><a title=\"" . $rows2["CategoryName"] . "\" href=\"" . $sub2link . "\"" . $subtarget . ">" . $rows2["CategoryName"] . "</a></p></div>";
								}
								$html .= "</li>";
							}
							$html .= "</ul>";
						}else{
							$html .= "<li><div class=\"sub2Title\"><p><a title=\"" . $rows["CategoryName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["CategoryName"] . "</a></p></div>";
						}
						$html .= "</li>";
					}
					$html .= "</ul>";
				}
			} else if ($childType === 2) {
				$intoAry[] = $this->addArray(":categoryID", $categoryID, "int");
				$dataS = $dal->executeRecordset($intoAry, "a.`CategoryID`=:categoryID AND a.`Visible`=1 AND a.`Disable`=0");
				if (count($dataS) > 0) {
					$html .= ($showType === 0) ? "<ul class=\"subnav\">" : "<ul class=\"subOption\">";
					foreach ($dataS as $rows) {
						$sublink = $this->formatLink(6, 0, $rows["BookID"]);
						if ($showType === 0) {
							$html .= "<li><a title=\"" . $rows["BookName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["BookName"] . "</a></li>";
						} else {
							$html .= "<li><div><p><a title=\"" . $rows["BookName"] . "\" href=\"" . $sublink . "\"" . $subtarget . ">" . $rows["BookName"] . "</a></p></div></li>";
						}
					}
					$html .= "</ul>";
				}
			}

			return $html;
		}

		// 產生主選單網頁結構
		public function formatWebMenu(array $data = []): array {
			$dal = new webmenuDAL();
			$iLabel = "<b><i class=\"fa fa-plus\" aria-hidden=\"true\"></i></b>";

			// 定義 MenuType 到處理函式的映射
			$menuTypeHandlers = [
				"2" => ["formatArticleWebMenu", 0],
				"3" => ["formatProductWebMenu", 0],
				"4" => ["formatNewsWebMenu", 0],
				"5" => ["formatFaqWebMenu", 0],
				"6" => ["formatBooksWebMenu", 0]
			];
			
			foreach ($data as &$row) {
				$row["LinkTarget"] = ($row["LinkTarget"] == "1") ? " target=\"_blank\"" : "";
				
				if (empty($row["MenuIcon"]) || !parent::image_exists($row["MenuIcon"])) $row["MenuIcon"] = $this->NoPicImage;
				if (empty($row["SubIcon"]) || !parent::image_exists($row["SubIcon"])) $row["SubIcon"] = $this->NoPicImage;
		
				$row["iLabel"] = "";
				$row["SubList"] = "";
				$row["SubList2"] = "";
				
				switch ($row["ChildType"]) {
					case "1":
					case "2":
						$row["MenuLink"] = $this->formatLink($row["MenuType"], $row["LinkType"], $row["LinkID"]);
						
						if (isset($menuTypeHandlers[$row["MenuType"]])) {
							[$handlerMethod, $additionalParam] = $menuTypeHandlers[$row["MenuType"]];
							$row["ListHtml"] = $this->$handlerMethod($row["ChildType"], $row["ChildTarget"], $additionalParam, $row["LinkID"]);
			
							if (!empty($row["ListHtml"])) {
								$row["iLabel"] = $iLabel;
								$row["SubList"] .= $row["ListHtml"];
								$row["SubList2"] .= $this->$handlerMethod($row["ChildType"], $row["ChildTarget"], 1, $row["LinkID"]);
							}
						}
						break;
					case "3":
						$intoAry = [ $this->addArray(":parentID", $row["MenuID"], "int") ];
						$dataS = $dal->executeRecordset($intoAry, "a.`ParentID`=:parentID AND a.`Visible`=1", "a.`OrderNO`");
						$row["MenuLink"] = (empty($row["LinkValue"])) ? "javascript:void(0);" : $row["LinkValue"];
						
						if (count($dataS) > 0) {
							$row["iLabel"] = $iLabel;
							$row["SubList"] .= "<ul class=\"subnav\">";
							$row["SubList2"] .= "<ul class=\"subOption\">";
					
							foreach ($dataS as $subRow) {
								$sublink = ($subRow["MenuType"] === 0) ? $subRow["LinkValue"] : $this->formatLink($subRow["MenuType"], $subRow["LinkType"], $subRow["LinkID"]);
								$subtarget = ($subRow["LinkTarget"] === 1) ? " target='_blank'" : "";
								$row["SubList"] .= "<li><a title='" . $subRow["MenuTitle"] . "' href='" . $sublink . "'" . $subtarget . ">" . $subRow["MenuTitle"] . "</a></li>";
								$row["SubList2"] .= "<li><div><p><a title='" . $subRow["MenuTitle"] . "' href='" . $sublink . "'" . $subtarget . ">" . $subRow["MenuTitle"] . "</a></p></div></li>";
							}
							
							$row["SubList"] .= "</ul>";
							$row["SubList2"] .= "</ul>";
						}
						break;
					default:
						$row["MenuLink"] = ($row["MenuType"] === 0) ? $row["LinkValue"] : $this->formatLink($row["MenuType"], $row["LinkType"], $row["LinkID"]);
				}
			}
			return $data;
		}

		// 網址格式
		public function formatLink($mt = "1", $lt = "1", $id = "1"): string {
			$linkMethods = [
				"2" => ["article", "linkArticleList", "linkArticleDetail"],
				"3" => ["product", "linkProductList", "linkProductDetail"],
				"4" => ["news", "linkNewsList", "linkNewsDetail"],
				"5" => ["faq", "linkFaqList", "linkFaqDetail"],
				"6" => ["book", "linkBookList", "linkBookDetail"],
				"7" => ["contact", "linkContact", ""],
				"8" => ["order", "linkOrder", ""]
			];

			if (isset($linkMethods[$mt])) {
				[$propertyName, $listMethod, $detailMethod] = $linkMethods[$mt];
				
				$linkObject = $this->{$propertyName};
		
				if ($lt === 1) {
					$link = $linkObject->{$listMethod}($id);
				} else {
					$link = ($detailMethod !== "") ? $linkObject->{$detailMethod}($id) : "";
				}
			} else {
				$link = "/";
			}
		
			return $link;
		}
	}
?>