<?php
	/*==================================================================*\
	######################################################################
	#                                                                    #
	# Copyright 2005 Arca Solutions, Inc. All Rights Reserved.           #
	#                                                                    #
	# This file may not be redistributed in whole or part.               #
	# eDirectory is licensed on a per-domain basis.                      #
	#                                                                    #
	# ---------------- eDirectory IS NOT FREE SOFTWARE ----------------- #
	#                                                                    #
	# http://www.edirectory.com | http://www.edirectory.com/license.html #
	######################################################################
	\*==================================================================*/

	# ----------------------------------------------------------------------------------------------------
	# * FILE: /includes/views/view_listing.php
	# ----------------------------------------------------------------------------------------------------


	if (is_array($listing) && !$is_object) {
		$is_object = false;
		$aux = $listing;
	} else if (is_object($listing)) {
		$is_object = true;
		$aux = $listing->data_in_array;
	} else {
		$is_object = true;
		$aux = $listing;
	}

	if ($listingviewtype == "detail") {
		$template_file_name = INCLUDES_DIR."/views/view_listing_".$listingviewtype."_code_0.php";
		$template_file_name_theme = INCLUDES_DIR."/views/view_listing_".$listingviewtype."_code_0_".EDIR_THEME.".php";
	} else {
		$template_file_name = INCLUDES_DIR."/views/view_listing_".$listingviewtype."_code.php";
		$template_file_name_theme = INCLUDES_DIR."/views/view_listing_".$listingviewtype."_code_".EDIR_THEME.".php";
	}
		$mrqaidi="ok";
		   	if ($mrqaidi =="ok") {
		
		if (htmlspecialchars($aux["listingtemplate_id"]) > 0 && CUSTOM_LISTINGTEMPLATE_FEATURE == "on") {

			if ($is_object) {
				$listingtemplate = new ListingTemplate($aux["listingtemplate_id"]);
			} else {
				unset($arrTemplate);
				$arrTemplate["id"] = htmlspecialchars($aux["listingtemplate_id"]);
				$arrTemplate["layout_id"] = htmlspecialchars($aux["template_layout_id"]);
				$arrTemplate["title"] = htmlspecialchars($aux["template_title"]);
				$arrTemplate["status"] = htmlspecialchars($aux["template_status"]);
				$arrTemplate["price"] = htmlspecialchars($aux["template_price"]);
				
				$listingtemplate = new ListingTemplate($arrTemplate);
			}

			if ((($listingtemplate) && ($listingtemplate->getNumber("id") > 0) && ($listingtemplate->getString("status") == "enabled")) || ($preview) ) {

				if ($listingviewtype == "detail") {
                    
                    if (USING_THEME_TEMPLATE && THEME_TEMPLATE_ID){
                        $isThemeTemplate = true;
                        $templateLayoutID = "0";
                    } else {
                        $templateLayoutID = $listingtemplate->getNumber("layout_id");
                        $isThemeTemplate = false;
                    }
                    
                    $template_file_name = INCLUDES_DIR."/views/view_listing_".$listingviewtype."_code_".$templateLayoutID.".php";
                    $template_file_name_theme = INCLUDES_DIR."/views/view_listing_".$listingviewtype."_code_".$templateLayoutID."_".EDIR_THEME.".php";

					if (file_exists($template_file_name) || file_exists($template_file_name_theme)) {
						$templateExtraFields = "";
						$template_fields = $listingtemplate->getListingTemplateFields("", $isThemeTemplate);
						if ($template_fields !== false) {
							foreach ($template_fields as $row) {
                                if (string_strpos($row["label"], "LANG_LABEL") !== false){
                                    $row["label"] = @constant($row["label"]);
                                }
								$var_name = strtolower('_'.preg_replace('/[^0-9a-zA-Z]/i', '', $row["label"]));
								$$var_name = htmlspecialchars($aux[$row["field"]]);
								if (strpos($row["field"], "custom_checkbox") !== false) {
									if ($$var_name == "y") $templateExtraFields .= "\t<p><strong>".$row["label"]."</strong>: ".system_showText(LANG_YES)."</p>\n";
									else $templateExtraFields .= "\t<p><strong>".$row["label"]."</strong>: ".system_showText(LANG_NO)."</p>\n";
								} elseif (strpos($row["field"], "custom_dropdown") !== false) {
									if ($$var_name) $templateExtraFields .= "\t<p><strong>".$row["label"]."</strong>: ".nl2br($$var_name)."</p>\n";
								} elseif (strpos($row["field"], "custom_text") !== false) {
									if ($$var_name) $templateExtraFields .= "\t<p><strong>".$row["label"]."</strong>: ".nl2br($$var_name)."</p>\n";
								} elseif (strpos($row["field"], "custom_short_desc") !== false) {
									if ($$var_name) $templateExtraFields .= "\t<p><strong>".$row["label"]."</strong>: ".nl2br($$var_name)."</p>\n";
								} elseif (strpos($row["field"], "custom_long_desc") !== false) {
									if ($$var_name) $templateExtraFields .= "\t<p><strong>".$row["label"]."</strong>: ".nl2br($$var_name)."</p>\n";
								}
							}
						}
                        
                        if (!file_exists($template_file_name_theme) && $template_fields && $templateExtraFields) {
							$templateExtraFields = "<h2 class=\"detailTitle\">".system_showText(LANG_EXTRA_FIELDS)."</h2>".$templateExtraFields;
						}

					}

				}

			}

		}
		
	}

    if (file_exists($template_file_name_theme)){
       include($template_file_name_theme); 
    } else {
        include($template_file_name);
    }

	unset($aux);


?>
