<?php
/**
* @Copyright Copyright (C) 2010- xml/swf
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
**/
/** ensure this file is being included by a parent file */
defined( '_JEXEC' ) or die( 'Restricted access' ); 

/**Mobile Gallery**/
	// for joomla
	if(strstr($_SERVER['HTTP_USER_AGENT'],"iPad") || strstr($_SERVER['HTTP_USER_AGENT'],"iPhone")) {
		define('PLUGINNAME', 'mod_xmlswf_gallery_catpro');
		require_once('mobile/mobile-joomla.php');
	}
/******************/

$bannerWidth                   = intval($params->get( 'bannerWidth', 912 ));
$bannerHeight                  = intval($params->get( 'bannerHeight', 700 ));
$backgroundColor         = trim($params->get( 'backgroundColor', '#CCCCCC' ));
$baseColor         = $params->get( 'baseColor', '0x000000' );
$wmode                 = trim($params->get( 'wmode', 'transparent' )); 
$xml_fname    = trim($params->get( 'xml_fname', 'data' ));
$catppv_id = $xml_fname;
//$catppv_id = '';

//**** Generate product thumbs
if(!function_exists('create_defalultgcgallerycatpro_xml')){
function create_defalultgcgallerycatpro_xml($params,&$catppv_id)
{
$params_comg = &JComponentHelper::getParams('com_gallerycatpro');
$cat_images_path = $params_comg->get('cat_path', 'images/gallerycatpro/galleries');
$cat_images_path .= '/';
$database = & JFactory::getDBO();//new ps_DB();
$cat_ids                = trim($params->get( 'category_id', '0' ));
$add_query = '';
if ($cat_ids && $cat_ids != 0) {
	$ids  = explode(",", $cat_ids);
	if (is_array($ids)) {
		foreach ($ids as $curr_id) {
			$add_query_arr[] = " id = " . $curr_id . " ";
		}
		$add_query = " AND " . implode("OR", $add_query_arr);
	}
}

$query = "Select * FROM #__gallerycatproc  WHERE publish = 1 " . $add_query . " ORDER BY ordnum ASC ";
$database->setQuery($query);
$cat_q_res = $database->loadObjectList();

$xml_category_tags = "<content>";
if(count($cat_q_res)> 0 ){

	foreach ($cat_q_res as $curr_category) 
	{

	$ret_arr = Images_gcgallerycatproxml($curr_category->id, $params, $curr_category->linkit);
		if ($ret_arr['flag']) {
			$xml_category_tags .='
			<category>
			<title><![CDATA['.$curr_category->name.']]></title>			<thumb>'.JURI::root().$cat_images_path.$curr_category->thumb.'</thumb>	
			';			
			$xml_category_tags .= $ret_arr['xml'];
			$xml_category_tags .= '</category>';
		}
	}
	$xml_category_tags .='</content>';
}
	else{
		echo "<b style='color:#FF0000;'>Please Add Categories and Data into Gallery Catpro Component</b><br/><br/>";
	}
return $xml_category_tags;
}
}

if(!function_exists('Images_gcgallerycatproxml')){
function Images_gcgallerycatproxml($cat_id, $params, $curr_link)
{
$params_comg = &JComponentHelper::getParams('com_gallerycatpro');
$images_path = $params_comg->get('pic_path', 'images/gallerycatpro/gallery');
$images_path .= '/';
$ret_arr = array ('flag'=>false, 'xml'=>'');
$query = "Select * FROM #__gallerycatpro WHERE catid = " . $cat_id . " AND publish = 1  ORDER BY ordnum ASC ";
	$db = & JFactory::getDBO();//new ps_DB();
	$db->setQuery($query);
	$prod_q_res = $db->loadObjectList();
$xml_image_tags = "";

	foreach ($prod_q_res as $curr_product) 
{
$ret_arr['flag'] = true;
	
	if ($params->get( 'showdesc', 'yes' ) == 'yes') {
		$description = '<![CDATA['.strip_tags($curr_product->descr).']]>';
	} else {
		$description =	'';
	}

if ($params->get( 'show_price', 'yes' ) == 'yes') {
	  if($curr_product->price> 0 ){
			$price = $curr_product->price;
	  }else{
			$price = '';
	  }
	}else{
		$price = '';
	}

	$xml_image_tags .= '
	
	<item>
	<label>'.$curr_product->name.'</label>	
	<thumb>'.JURI::root().$images_path.$curr_product->thumb.'</thumb>
	<main>'.JURI::root().$images_path.$curr_product->image.'</main>
	<description>'.$description.'</description>
	<link window="'.$params->get( 'target', '_self' ).'">'.$curr_product->linkname.'</link>
		<price><regular>'.$price.'</regular><!-- <updated> --></price>
	</item>';
}
$ret_arr['xml'] = $xml_image_tags;
return $ret_arr;
}
}


$MovieScale=trim($params->get( 'MovieScale'));

$ids    = trim($params->get( 'category_id', 0 ));

if (1 == trim($params->get( 'catppv_flag', '2' ))) {
	$catppv_id .= str_replace(',', '_', $cat_ids);
}

	$module_path = dirname(__FILE__).DS;
	if (!file_exists($module_path . 'mod_xmlswf_gallery_catpro'. $catppv_id . '.swf') ) {
		copy($module_path . 'mod_xmlswf_gallery_catpro.swf', $module_path . 'mod_xmlswf_gallery_catpro'. $catppv_id . '.swf');
	}


$show_catdesc_always = $params->get( 'show_catdesc_always', 'yes');

if($show_catdesc_always == 'yes'){
	$generate_show_catdesc_always = 'true';
}
else{
		$generate_show_catdesc_always = 'false';
}

$xml_data = '<?xml version="1.0" encoding="UTF-8"?>

<slideshow>
	<mobileSettings>
		<currencySymbol>'.$params->get( 'currency', '$').'</currencySymbol>
		<width>'.$params->get( 'bannerWidth', '710').'</width>
		<height>'.$params->get( 'bannerHeight', '630').'</height>
	</mobileSettings>
	<baseDef fullscreen="'.$params->get( 'fullscreen', '1').'" showCatDescriptionAlways="'.$generate_show_catdesc_always.'"
	transitionTime="'.$params->get( 'transitionTime', '1.5').'"
	autoSlideTimer="'.$params->get( 'autoSlideTimer', '3').'"
	autoScale="'.$params->get( 'autoScale', '1').'"
	autoAlign="'.$params->get( 'autoAlign', '1').'"
	gradientColor="0x'.$params->get( 'gradientColor', 'E8EBEA').'" 
	gradientColor1="0x'.$params->get( 'gradientColor1', 'CCCCCC').'" 
	CatsWidth="'.$params->get( 'CatsWidth', '96').'" 
	catsHeight="'.$params->get( 'catsHeight', '72').'"  
	catsbackColor="0x'.$params->get( 'catsbackColor', 'E2D289').'" 
	arrowsColor= "0x'.$params->get( 'arrowsColor', '666666').'" 
	CatsTitleBarColor="0x'.$params->get( 'CatsTitleBarColor', '000000').'" CatsTextColor="0x'.$params->get( 'CatsTextColor', 'FFFFFF').'" catsImagebackColor="0x'.$params->get( 'catsImagebackColor', '00CC33').'" catsTextSize="'.$params->get( 'catsTextSize', '10').'" 
	ImageHeight="'.$params->get( 'ImageHeight', '450').'" 
	thumbListColor="0x'.$params->get( 'thumbListColor', '000000').'" thumbListAlpha="'.$params->get( 'thumbListAlpha', '50').'" 
	thumbTextColor="0x'.$params->get( 'thumbTextColor', 'FFFFFF').'" thumbButtonColor="0x'.$params->get( 'thumbButtonColor', '515151').'" thumbButtonOverColor="0x'.$params->get( 'thumbButtonOverColor', '171717').'" thumbTextSize="'.$params->get( 'thumbTextSize', '13').'" 
	descColorBack="0x'.$params->get( 'descColorBack', '000000').'" 
	descTextColor="0x'.$params->get( 'descTextColor', 'FFFFFF').'" backTransperency="'.$params->get( 'backTransperency', '0').'" 
	ActiveCat="'.$params->get( 'ActiveCat', '1').'"
	categoryStatus="'.$params->get( 'categoryStatus', 'show').'"/>

	<priceTag enabled="'.trim($params->get( 'show_price', 'yes')).'">
			<position>'.trim($params->get( 'price_position', 'TL')).'</position>
			<textSize>'.trim($params->get( 'price_textsize', '22')).'</textSize>
			
			<currency>
				<base>
					<color code="#'.trim($params->get( 'currency_basecolor1', 'FFFFFF')).'" alpha="'.trim($params->get( 'currency_basecolor1alpha', '0.8')).'" />

					<color code="#'.trim($params->get( 'currency_basecolor2', 'CECECE')).'" alpha="'.trim($params->get( 'currency_basecolor2alpha', '0.8')).'" />


				</base>

				<label color="#'.trim($params->get( 'currency_color', 'FF00CC')).'" alpha="'.trim($params->get( 'currency_coloralpha', '0.8')).'" />
				<symbol>'.trim($params->get( 'currency', '$')).'</symbol>
			</currency>

			<price>
				<base color="#'.trim($params->get( 'price_basecolor', 'FF00CC')).'" alpha="'.trim($params->get( 'price_basecoloralpha', '0.5')).'" />
				<label color="#'.trim($params->get( 'price_color', 'FFFFFF')).'" alpha="'.trim($params->get( 'price_coloralpha', '1')).'" />
			</price>
	</priceTag>

		<imageEffect>
			<type>'.trim($params->get( 'imageEffect', '1' )).'</type>
			<time>'.trim($params->get( 'imageEffectTime', '1000' )).'</time>
			<closingEffect>'.trim($params->get( 'imageClosingEffect', '1' )).'</closingEffect>
		</imageEffect>

			<descriptionEffect>
			<type>'.trim($params->get( 'descriptionEffect', '1' )).'</type>
		</descriptionEffect>';

$xml_data .= create_defalultgcgallerycatpro_xml($params,$catppv_id);
$xml_data .= "
</slideshow>";

$module_path = dirname(__FILE__).DS;
$xmlslides_filename = $module_path.'default'.$catppv_id.'.xml';
$xmlslides_file = fopen($xmlslides_filename,'w');
fwrite($xmlslides_file, $xml_data);
fclose($xmlslides_file);

///////// set chmod 0777 for creating .xml file  if server is not windows
	$os_string = php_uname('s');
	$cnt = substr_count($os_string, 'Windows');
	if($cnt =='0'){
		@chmod($xmlslides_filename, 0777);
	}

?>

<div align="center">
<script language="javascript">AC_FL_RunContent = 0;</script>
<script src="<?php echo JURI::root()?>modules/mod_xmlswf_gallery_catpro/AC_RunActiveContent.js" language="javascript"></script>
<script language="javascript">
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '<?php echo $bannerWidth; ?>',
			'height', '<?php echo $bannerHeight; ?>',
			'src', '<?php echo JURI::root().'modules/mod_xmlswf_gallery_catpro/mod_xmlswf_gallery_catpro'.$catppv_id ;?>',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', 'mod_xmlswf_gallery_catpro',
			'bgcolor', '<?php echo $backgroundColor; ?>',
			'name', 'mod_xmlswf_gallery_catpro',
			'menu', 'true',
			'mobile', '<?php echo JURI::root()?>modules/mod_xmlswf_gallery_catpro/default<?php echo $catppv_id; ?>.xml',
			'allowFullScreen', 'true',
			'allowScriptAccess','sameDomain',
			'movie', '<?php echo JURI::root().'modules/mod_xmlswf_gallery_catpro/mod_xmlswf_gallery_catpro'.$catppv_id ;?>',
			'salign', '',
			'FlashVars','xmlfileurl=<?php echo JURI::root()?>modules/mod_xmlswf_gallery_catpro/default<?php echo $catppv_id; ?>.xml&baseColor=<?php echo $baseColor; ?>'
			); //end AC code
	}
</script>

<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="<?php echo $$bannerWidth; ?>" height="<?php echo $$bannerHeight; ?>" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="wmode" value="transparent" />
<param name="FlashVars" value="xmlfileurl=http://vm.xmlswf.com/modules/mod_xmlswf_gallery_catpro/default.xml&baseColor=0x000000"/>
<param name="allowFullScreen" value="true" />	<param name="movie" value="<?php echo JURI::root().'modules/mod_xmlswf_gallery_catpro/mod_xmlswf_gallery_catpro'.$catppv_id.'.swf';?>" /><param name="quality" value="high" /><param name="bgcolor" value="<?php echo $backgroundColor; ?>" />
<embed src="<?php echo JURI::root().'modules/mod_xmlswf_gallery_catpro/mod_xmlswf_gallery_catpro'.$catppv_id.'.swf';?>" FlashVars="xmlfileurl=<?php echo JURI::root()?>modules/mod_xmlswf_gallery_catpro/default<?php echo $catppv_id; ?>.xml&baseColor=0x000000" quality="high" wmode="transparent"
 bgcolor="#FFFFFF" width="<?php echo $$bannerWidth; ?>" height="<?php echo $$bannerHeight; ?>" name="preview" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</noscript>
</div>




