Location: PHPKode > projects > Freeway > freeway_1_5_Alpha/product_info_new.php
<?php
/*
	osCommerce, Open Source E-Commerce Solutions 
	http://www.oscommerce.com 
	
	Copyright (c) 2003 osCommerce 
	
	osCommRes, Services Oline 
	http://www.oscommres.com 
	Copyright (c) 2005 osCommRes 
	
	Freeway eCommerce 
	http://www.zac-ware.com/freeway 
	Copyright (c) 2007 ZacWare
	
	Released under the GNU General Public License
*/

  	require('includes/application_top.php');
	$command = (isset($HTTP_GET_VARS['command'])?$HTTP_GET_VARS['command']:'');
	if($command == "fetch_attrib_val"){
	$att_id = (isset($HTTP_GET_VARS['sel_attrib'])?$HTTP_GET_VARS['sel_attrib']:'');
	$prd_id = (isset($HTTP_GET_VARS['product_id'])?$HTTP_GET_VARS['product_id']:'');
	$combo_name = (isset($HTTP_GET_VARS['combo_name'])?$HTTP_GET_VARS['combo_name']:'');
	$pre_id = (isset($HTTP_GET_VARS['previous_id'])?$HTTP_GET_VARS['previous_id']:'');
	$sort_order = array();
	
	
	if($pre_id != ""){
		$chk_pre = strpos($pre_id,',');
		if($chk_pre != ""){
		$pre_id = substr($pre_id,0,-1);
		$pre_ids = split(',',$pre_id);
		}else{
		$pre_ids = array();
		$pre_ids[] = $pre_id;
		}
	}
	$p = count($pre_ids);
	if($att_id==0){
		$content = 0 .':'. '-- Select --' . '#';
		echo $content . '@' . $combo_name;
		exit;
	}
	$sort_order_query=tep_db_query("select distinct popt.products_options_id, popt.products_options_name, popt.products_options_sort_order from products_options popt, products_attributes patrib where patrib.products_id = " .$prd_id ."  and patrib.options_id = popt.products_options_id and popt.language_id = 1 order by popt.products_options_sort_order");
	while($sort_orders = tep_db_fetch_array($sort_order_query)){
			$sort_order[]= $sort_orders['products_options_id'];
	}
	$m = count($sort_order);
	$count = 0;
	$products_options_query = tep_db_query("select products_options_id from products_options_values_to_products_options where products_options_values_id= " . $att_id);	
	$products_option = tep_db_fetch_array($products_options_query);
	$second_attrib_query = tep_db_query("select attributes_id from products_stock where attribute_status=1 and products_id = " . $prd_id);
	
	while($second_attrib = tep_db_fetch_array($second_attrib_query)){
	
	$temp=split('-',$second_attrib['attributes_id']);
	$n = count($temp);
	$temp_sort = array();
	
	// converting attributes list as sorted list order
	for($k=0;$k<$m;$k++){
	for($i=0;$i<$n;$i++){
		$id_pos = strpos($temp[$i],'{');
		$chk_sort = substr($temp[$i],0,$id_pos);
		if($sort_order[$k] == $chk_sort)
		   $temp_sort[] = $temp[$i];
		}
	 }	
	  if(is_array($pre_ids)){
		 for($k=0;$k<$p;$k++){
				 $split = split('{',$temp_sort[$k]);
				 $id_pos1 = strpos($split[1],'}');
				 $chk_split = substr($split[1],0,$id_pos1);
				 if($chk_split == $pre_ids[$k]){
					$count = $count + 1;
					if($pre_ids[$k+1])
					   continue;
					else {
						
					   $final_split = split('{',$temp_sort[$k+1]);
					   $id_pos2 = strpos($final_split[1],'}');
					   if($final_split[0] == $sort_order[$k+1])
					   $load_ids .= substr($final_split[1],0,$id_pos2) .',' ;
					}
					continue;
				 }else break;
		 }
	  }
	}	
	$load_ids = substr($load_ids,0,-1);
	$load_query = tep_db_query("select distinct pov.products_options_values_id,pov.products_options_values_name,pa.options_values_price,pa.price_prefix from products_options_values pov,products_attributes pa where language_id=1 and products_options_values_id  in( " . $load_ids .") and products_id= ". $prd_id ." and pov.products_options_values_id =pa.options_values_id");
	$content .= '0' .':' . '-- Select --' . '#';
	if(tep_db_num_rows($load_query)){
		while($load = tep_db_fetch_array($load_query)){
			$content .= $load['products_options_values_id'] . ':' . $load['products_options_values_name'] . '(' .$load['price_prefix']  . $currencies->format($load['options_values_price']) .')'  .'#';
		 }
	} 
	 echo $content . '@' . $combo_name;
	 exit;
	}

	require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);
  
	$product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
	$product_check = tep_db_fetch_array($product_check_query);
	
	$template_content=tep_load_template_content('product_info.tpl.php');
	if ($template_content==""){
		$content = CONTENT_PRODUCT_INFO;
		
		$javascript = 'popup_window.js';
		require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
		require(DIR_WS_INCLUDES . 'application_bottom.php');
		exit;
	}
	// load the details into merge fields
	$template_details=array();
	
	// first set the section fields to default 0
	$template_details["SECTION_ORIGINAL_HEAD"]=0;
	$template_details["SECTION_TABLE_HEAD"]=0;
	$template_details["SECTION_NO_PRODUCT"]=0;
	$template_details["SECTION_PRODUCT"]=0;
	$template_details["SECTION_BUYNOW"]=0;
	$template_details["SECTION_FIRST_IMAGE"]=0;
	$template_details["SECTION_MULTIPLE_IMAGE"]=0;
	$template_details["SECTION_ATTR"]=0;
	$template_details["SECTION_REVIEW"]=0;
	$template_details["SECTION_REVIEW"]=0;
	$template_details["VALUE_SUB_PADDING"]=0;

	$template_details['VALUE_FORM']=tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product'),'post','onSubmit="javascript:return validateForm();"');
	$template_details["VALUE_ROWSEP1"]=tep_draw_separator('pixel_trans.gif', '5', '3');
	$template_details["VALUE_ROWSEP2"]=tep_draw_separator('pixel_trans.gif', '5', '10');
	$template_details["VALUE_HIDDEN_VALUES"]=tep_draw_hidden_field('products_id', $product_info['products_id']) .  tep_draw_hidden('attribute_value');
	// find the product info
    $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image_1,p.products_image_2,p.products_image_3,p.products_image_4,p.products_image_5,
							p.products_title_1,p.products_title_2,p.products_title_3,p.products_title_4,p.products_title_5,pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.products_quantity,p.manufacturers_id,p.is_attributes from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
	if (tep_db_num_rows($product_info_query)>0){
		$template_details["SECTION_PRODUCT"]=1;
		
		$product_info = tep_db_fetch_array($product_info_query);
		tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
	
		if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
		  $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']),'1',true) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
		} else {
		  $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']),'1',true);
		}
	
		if (tep_not_null($product_info['products_model'])) {
		  $products_name = $product_info['products_name'] . '<span class="smallText" align="right">[' . $product_info['products_model'] . ']</span>';
		} else {
		  $products_name = $product_info['products_name'];
		}
		$template_details["VALUE_PRODUCTS_NAME"]=$products_name;
		$template_details["VALUE_PRODUCTS_PRICE"]=$products_price;
		// prepare for heading
		if (SHOW_HEADING_TITLE_ORIGINAL=='yes') {
			$template_details["SECTION_ORIGINAL_HEAD"]=1;
		} else {
			$value="";
			if (MAIN_TABLE_BORDER == 'yes'){
				$value=table_image_border_top(false, false, $products_name . "\tleft\t" . $products_price . "\tright","\t",true);
			}
			$template_details["VALUE_TABLE_HEAD"]=$value;
			$template_details["SECTION_TABLE_HEAD"]=1;
		}

		// prepare for the images		
		$images=array('3');
		$img_string="";
		$title_string="";
		for ($icnt=1;$icnt<=5;$icnt++){
			$show_image=trim($product_info['products_image_' . $icnt]);
			if ($show_image!="" && (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . "big/" . $show_image) ||  file_exists(DIR_WS_IMAGES . $show_image) ) ){
				$title_string.="'" . addslashes($product_info["products_title_" . $icnt]) . "',";
					$images[]=array('IMAGE'=>tep_product_small_image($show_image,$temp_images[]['title'],'onClick="javascript:set_image(' . $icnt .');" style="cursor:pointer;cursor:hand;"'),'TITLE'=>$product_info["products_title_" . $icnt]);
				if ($img_string=="") $first_image=$show_image;
				if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . "big/" . $show_image)){
					$img_string.="'" . DIR_WS_IMAGES . "big/" . $product_info["products_image_" . $icnt] . "',";
				} else {
					$img_string.="'" . DIR_WS_IMAGES . $product_info["products_image_" . $icnt] . "',";
				}
			}
		}
	
		if (count($images)>1){
			$template_details["SECTION_FIRST_IMAGE"]=1;
			if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . "big/" .$first_image)){
				$value='<image src="' . DIR_WS_IMAGES . "big/" . $first_image . '" id="imgContainer">';
			} else {
				$value='<image src="' . DIR_WS_IMAGES . $first_image . '" id="imgContainer">';
			}
			$template_details["VALUE_FIRST_IMAGE"]=$value;
			$template_details["VALUE_FIRST_IMAGE_TITLE"]=tep_output_string($product_info['products_title_1']);
		}
		$value="";
		ob_start();
		require("includes/http.js");
		require(DIR_WS_JAVASCRIPT . 'product_info.js.php');
		$value.=ob_get_contents() . "\n";
		ob_end_clean();
		
		if (count($images)>2){
			$template_details["SECTION_MULTIPLE_IMAGE"]=1;
			$template_details["REPEAT_MULTIPLE_IMAGE"]=$images;
			$img_string=substr($img_string,0,-1);
			$title_string=substr($title_string,0,-1);
			$value.='<script language="javascript">';
			
			if ($img_string!="") $value.='load_images(' . $img_string  .");\n";
			if ($title_string!="") $value.='load_titles(' . $title_string  .");\n";
			$value.='</script>' . "\n";
		}

		$template_details["VALUE_IMAGE_SCRIPT"]=$value;
		
		$template_details["VALUE_PRODUCT_DESCRIPTION"]=$product_info['products_description'];
		
		$initial =0;
		$iname = 0;
		$products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
		$products_attributes = tep_db_fetch_array($products_attributes_query);

		// fetch the attributes
		$has_attributes=false;
		if($product_info['is_attributes']=='Y' && $products_attributes['total']>0 && $product_info["products_quantity"]>0){
			  $products_options_name = tep_db_query("select distinct popt.products_options_id, popt.products_options_name, popt.products_options_sort_order from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'" . " order by popt.products_options_sort_order");
				$products_options_name = tep_db_query("select distinct popt.products_options_id, popt.products_options_name, popt.products_options_sort_order from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'" . " order by popt.products_options_sort_order");
				  while ($products_options_name_values = tep_db_fetch_array($products_options_name)) {
					$selected = 0;
					$initial++;
					$template_details["VALUE_ATTRIBUTE_TITLE"]=TEXT_PRODUCT_OPTIONS;
					$products_options_array = array();
					$products_options_array[] = array('id'=>0,'text'=>TEXT_SELECT_ATTRIBUTE);
					$attributes_array[]=array("id"=>$products_options_name_values['products_options_id']);
			// BOF: WebMakers.com Added: Attributes Copy and Sort
					  if (PRODUCTS_OPTIONS_SORT_BY_PRICE !='1' ) {
							$products_options = tep_db_query("select  pa.products_options_sort_order, pa.options_id, pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . $products_options_name_values['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . $languages_id . "'" . " order by pa.products_options_sort_order, pov.products_options_values_name");
					  } else {
							$products_options = tep_db_query("select pa.products_options_sort_order, pa.options_id, pa.options_values_id, pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . $products_options_name_values['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . $languages_id . "'" . " order by pa.products_options_sort_order, pa.options_values_price");
					  }
			// EOF: WebMakers.com Added: Attributes Copy and Sort
					  while ($products_options_values = tep_db_fetch_array($products_options)) {
						 if($initial == 1){ 
						   //echo "select attributes_id from ". TABLE_PRODUCTS_STOCK . " where attribute_status='1' and products_id=$HTTP_GET_VARS['products_id']";
						   $stock_check_query = tep_db_query("select  attributes_id from ". TABLE_PRODUCTS_STOCK . " where attribute_status='1' and products_id = '".  $HTTP_GET_VARS['products_id'] ."'");
						  
						   if(tep_db_num_rows($stock_check_query) > 0){
						   while($stock_check = tep_db_fetch_array($stock_check_query)) {
								$temp = split('-', $stock_check['attributes_id']);
								$n = count($temp);
								$allow=0;
								for($icnt=0; $icnt<$n ; $icnt++){
									$split = split('{',$temp[$icnt]);
									if($split[0] == $products_options_name_values['products_options_id']){
										$id_pos = strpos($split[1],'}');
										$opt_val_id = substr($split[1],0,$id_pos);
											 if($opt_val_id == $products_options_values['products_options_values_id'] ){
												for($icn=0;$icn<count($products_options_values);$icn++){
												   if($products_options_array[$icn]['id'] == $products_options_values['products_options_values_id']) 
												   $allow = 1;	}
												   if($allow == 0){
													  $products_options_array[] = array('id' => $products_options_values['products_options_values_id'], 'text' => $products_options_values['products_options_values_name']);
													   if ($products_options_values['options_values_price'] != '0') {
														   $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options_values['price_prefix'] . $currencies->display_price($products_options_values['options_values_price'], tep_get_tax_rate($product_info_values['products_tax_class_id']),'1',true) .') ';
														}
													}
														}
												}  
											}   
									}
								}
							} 
					  }
					  $merge_temp_attributes[]=array("NAME"=>$products_options_name_values['products_options_name'],"VALUE"=>tep_draw_pull_down_menu('sel_combo['.$products_options_name_values['products_options_id'].']', $products_options_array, $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name_values['products_options_id']],' id="sel_combo['. $products_options_name_values['products_options_id'] .']" style="width:150px" onchange="javascript:load_stock(this,\'' . $HTTP_GET_VARS['products_id'] . '\','.$iname.');"'));
					} // $while products_options_values
					$template_details["REPEAT_ATTR_OPTION"]=$merge_temp_attributes;
			 $template_details["SECTION_ATTR"]=1;
		}
		
		// fetch other products in the same category
		$selected_products_name = tep_db_query("select pd.products_id,pd.products_name,p.products_price from " . TABLE_PRODUCTS . " p," . TABLE_PRODUCTS_DESCRIPTION . " pd," . TABLE_PRODUCTS_TO_CATEGORIES . " pc where pc.categories_id=" . $current_category_id . " and pc.products_id=p.products_id and pd.products_id=p.products_id and pd.language_id=" . $languages_id . " order by rand() limit 0,3");
		$check_selected_products_name = $selected_products_name;
		$check_count = tep_db_num_rows($check_selected_products_name);
		if(tep_db_num_rows($check_selected_products_name)>1){
			$template_details["SECTION_BUYNOW"]=1;
			$template_details["VALUE_BUYNOW_TITLE"]=TEXT_BUY;
			$merge_temp=array(1);
			while($fetch_row = tep_db_fetch_array($selected_products_name)){	  		
				if(($fetch_row['products_id']!=(int)$HTTP_GET_VARS['products_id']) && ($count < 2)){
					$merge_temp[]=array('NAME'=>'<a class="brown" href="' . tep_href_link(FILENAME_PRODUCT_INFO,'cPath='.$cPath.'&products_id='.$fetch_row['products_id']) . '">' . $fetch_row['products_name'] . '</a>',
										'PRICE'=>$currencies->format($fetch_row['products_price']));
					$count++;
				} 
			}
			$template_details["REPEAT_BUYNOW"]=$merge_temp;
		}
		// check some fields from product detail
	    if (tep_not_null($product_info['products_url'])){
			$template_details["VALUE_PRODUCTS_URL"]=sprintf(TEXT_MORE_INFORMATION, tep_href_link(FILENAME_REDIRECT, 'action=url&goto=' . urlencode($product_info['products_url']), 'NONSSL', true, false)) . '<br>' .tep_draw_separator('pixel_trans.gif', '100%', '10') . '<br>';
		} else {
			$template_details["VALUE_PRODUCTS_URL"]='';
		}
		if ($product_info['products_date_available'] > getServerDate()) {
			$template_details["VALUE_PRODUCTS_DATE_AVAIL"]=sprintf(TEXT_DATE_AVAILABLE, tep_date_long($product_info['products_date_available'])) . '<br>' .tep_draw_separator('pixel_trans.gif', '100%', '10') . '<br>';
		} else {
			$template_details["VALUE_PRODUCTS_DATE_AVAIL"]=sprintf(TEXT_DATE_ADDED, tep_date_long($product_info['products_date_added'])) . '<br>' .tep_draw_separator('pixel_trans.gif', '100%', '10') . '<br>';
		}
		$template_details["VALUE_REVIEWS_BUTTON"]='<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params()) . '">' . tep_template_image_button('button_reviews.gif', IMAGE_BUTTON_REVIEWS) . '</a>';
		$template_details["VALUE_CART_BUTTON"]=tep_template_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART);
		
		
		$template_details["VALUE_STOCK_AVAILABILITY"]=TEXT_AVAILABILITY;
		$template_details["VALUE_STOCK_OUT"]=TEXT_OUT_STOCK;
		$template_details["VALUE_STOCK_OUT_DETAILS"]=TEXT_OUT_STOCK_DETAILS;
		$template_details["VALUE_STOCK_EMAIL_DETAILS"]=TEXT_EMAIL .'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . tep_draw_input_field('txt_email','','size="20"');
		$template_details["VALUE_STOCK_SUBMIT"]=tep_template_image_submit('button_remind_me.gif', IMAGE_BUTTON_REMINDME,'onclick=javascript:remindme();');
		
		$temp_script='
						<script type="text/javascript">
							if(product_stock<=0) {
								document.getElementById("out_of_stock").style.display="";
								document.getElementById("add_cart").style.display="none";
							}	
							else {
									for(j=0;j<prd_att_status.length;j++){
									  
									   if(prd_att_status[j] == 0)
										is_status = parseInt(is_status) + 1; 
									}	
							   if(is_attribute=="Y" &&  is_status == prd_att_status.length){
							   document.getElementById("out_of_stock").style.display="";
							   document.getElementById("add_cart").style.display="none";
							   document.getElementById("prd_attribs").style.display="none";
							   }
							}' . "\n";
							
			for($i=0;$i<sizeof($attributes_array);$i++){
				$temp_script.=sprintf("attrib[%s]='%s';\n",$i,$attributes_array[$i]['id']);
			}
			if($product_info['is_attributes']=='Y'){
		  		for($li=0,$max=sizeof($att_array);$li<$max;$li++){
			  		$row=$att_array[$li];
					$temp_script.=sprintf("prd_att[%s] = new Array(5);\n",$li);
					$temp_script.=sprintf("prd_att[%s][0]=%s;\n",$li, $row['stock']);
					$temp_script.=sprintf("prd_att[%s][1]='%s';\n",$li, $row['attributes']);
					$temp_script.=sprintf("prd_att[%s]='%s';\n",$li,$row['status']);
					$temp_script.=sprintf("prd_att[%s]='%s';\n",$li,$row['attributes']);
			   }
			   for($li=0,$max=sizeof($attributes_array);$li<$max;$li++)
					$temp_script.=sprintf("option_array[%s]=%s;\n",$li,$attributes_array[$li]['id']);
				$temp_script.="option_array=option_array.sort();";
		   } 
			$template_details['VALUE_STOCK_SCRIPT']=$temp_script . "</script>\n";
	} else { // $product_info
		$template_details["SECTION_NO_PRODUCT_START"]=1;
	}	// $product_info

		$replaced_content=$template_content;
		while(list($key,$value)=each($template_details)){
			switch(substr($key,0,strpos($key,'_'))){
				case "VALUE":
					$replaced_content=str_replace("{{" . $key . "}}",$value,$replaced_content);
					break;
				case "SECTION":
					if ($value!=1){
						$replaced_content=preg_replace("/\{\{" . $key ."_START\}\}((.|\n)*)\{\{" . $key . "_END\}\}/","",$replaced_content);
					} else {
						$replaced_content=str_replace(array("{{" .$key . "_START}}","{{" .$key . "_END}}"),"",$replaced_content);
					}
					break;
				case "REPEAT":
					$merged_total_content="";
					$start_pos=strpos($replaced_content,"{{" . $key . "_START}}")+strlen("{{" . $key ."_START}}");
					$end_pos=strpos($replaced_content,"{{" . $key . "_END}}");
					$repeat_content=substr($replaced_content,$start_pos,$end_pos-$start_pos);
					$total_cols=$value[0];
					$col=0;
					for ($icnt=1,$n=count($value);$icnt<$n;$icnt++){
						$merged_content=$repeat_content;
						if ($col==0){
							$merged_total_content.='<tr><td valign="top">' . "\n";
						} else {
							$merged_total_content.='<td valign="top">' . "\n";
						}
						reset($value[$icnt]);
						while(list($itemkey,)=each($value[$icnt])){
							$merged_content=str_replace("{{" . $key . "_" . $itemkey . "}}",$value[$icnt][$itemkey],$merged_content);
						}

						$merged_total_content.="\n" . $merged_content;
						$col++;
						if ($col>=$total_cols) $col=0;
					}
					//$replaced_content=preg_replace("/\{\{" . $key ."_START\}\}((.|\n)*)\{\{" . $key . "_END\}\}/",$merged_total_content,$replaced_content);
					$replaced_content=substr($replaced_content,0,$start_pos) . $merged_total_content . substr($replaced_content,$end_pos);
					$replaced_content=str_replace(array("{{" .$key . "_START}}","{{" .$key . "_END}}"),"",$replaced_content);
					break;
			}
		}
	
	echo $replaced_content;
	
	require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
Return current item: Freeway