<?php
/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require('includes/application_top.php');
tep_get_last_access_file();   
$action=(isset($HTTP_GET_VARS['action'])?$HTTP_GET_VARS['action']:'');
  
	switch($action)
	{
		case 'set_value':
			// set configuration value
			$config_id = (isset($HTTP_POST_VARS['configuration_id'])?(int)$HTTP_POST_VARS['configuration_id']:0);
			$con_id = (isset($HTTP_POST_VARS['conversion_id'])?$HTTP_POST_VARS['conversion_id']:'');
			$conversion_table = array('SHOP_INDEX_PAGE_CONV','PRODUCT_CATEGORY_PAGE_CONV','PRODUCT_PAGE_CONV','CHECKOUT_SUCCESS_PAGE_CONV');
			
			$query=tep_db_query("select configuration_key from ".TABLE_CONFIGURATION ." where configuration_id='".$config_id."'");
			$result=tep_db_fetch_array($query);
			if(!in_array($result['configuration_key'],$conversion_table))	{				
			if ($config_id>0){
				if($result['configuration_key']=='DISPLAY_REVIEW'){
					$val_admin=($HTTP_POST_VARS['admin'])?$HTTP_POST_VARS['admin']:'N';
					$val_customer=($HTTP_POST_VARS['customer'])?$HTTP_POST_VARS['customer']:'N';
					$HTTP_POST_VARS['configuration_value']=$val_admin.$val_customer;
				}	
				$value=$HTTP_POST_VARS['configuration_value'];
				if (is_array($value)){
					$value=join(",",$value);
				}
			   tep_db_query("UPDATE " . TABLE_CONFIGURATION . " set configuration_value='" . tep_db_input($value) . "' where configuration_id='" . $config_id . "'");
			}
			} else {
			$con_val = htmlspecialchars($HTTP_POST_VARS['configuration_value']);
			if($con_val=="")
				$con_val=htmlspecialchars("<!--Add  Google Conversion Code Here  -->");

				if($con_id > 0){
				     tep_db_query("UPDATE " . TABLE_CONVERSION . " set conversion_value='" . tep_db_input($con_val) . "' where conversion_id='" . $con_id . "'");
				}
				else{
					 tep_db_query("insert into ".TABLE_CONVERSION ." (conversion_key,conversion_value) values('".$result['configuration_key']."','".$con_val."')")	;
				}
			}
			tep_redirect(tep_href_link(FILENAME_PRODUCTS_OPTIONS));
		case 'activate':
			/*$err='';
			if (EVENTS_SMS_KEY=='')
				$err=ERR_EMPTY_SMS_KEY;
			else if(EVENTS_SMS_EMAIL=='')
				$err=ERR_EMPTY_SMS_EMAIL;
			else if(EVENTS_SMS_TEST_PHONE=='')
				$err=ERR_EMPTY_SMS_TEST_PHONE;
			else if(EVENTS_SMS_GATEWAY=='')
				$err=ERR_EMPTY_GATEWAY;
			if ($err==''){
				$message = new email(array('X-Mailer: osCommerce'));
				
				$message->add_text('Activate');
				
				$message->build_message();
				$message->send('', tep_get_sms_address(EVENTS_SMS_TEST_PHONE), STORE_OWNER, EVENTS_SMS_EMAIL, EVENTS_SMS_KEY);
			} else {
				$messageStack->add_session($err,'error');
			}*/
		tep_redirect(tep_href_link(FILENAME_PRODUCTS_OPTIONS));
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
	<!-- header //-->
	<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
	<!-- header_eof //-->

	<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr> 
	<!-- body_text //-->
	<td width="100%" valign="top">
	<table border="0" width="100%" cellspacing="0" cellpadding="2">
		<tr>
			<td>
			<table border="0" cellspacing="0" cellpadding="4" width="95%">
			<?php
				// Group Configuration settings with headings
				$heading=array(	TEXT_PRODUCT_OPTIONS=>array("PRODUCT_LIST_IMAGE","PRODUCT_LIST_MANUFACTURER","PRODUCT_LIST_MODEL","PRODUCT_LIST_NAME","PRODUCT_LIST_PRICE","PRODUCT_LIST_QUANTITY","PRODUCT_LIST_WEIGHT","PRODUCT_LIST_BUY_NOW","PRODUCT_LIST_FILTER","PREV_NEXT_BAR_LOCATION","DISPLAY_PRODUCT_REMINDME"),	
								TEXT_FULLFILLER_OPTIONS=>array("PRODUCT_FULFILLER"),
								TEXT_DOWNLOAD_OPTIONS=>array("DOWNLOAD_ENABLED","DOWNLOAD_BY_REDIRECT","DOWNLOAD_MAX_DAYS","DOWNLOAD_MAX_COUNT"),
								TEXT_CONVERSION_CODES=>array("CONVERSION_CODES","GENERAL_CONVERSION","SHOP_INDEX_PAGE_CONV","PRODUCT_CATEGORY_PAGE_CONV","PRODUCT_PAGE_CONV","CHECKOUT_SUCCESS_PAGE_CONV"),
								TEXT_SKUOPTIONS=>array("SKU_LENGTH","SKU_COUNT"),
								TEXT_REVIEW=>array("DISPLAY_REVIEW")					
								);
				reset($heading);
				while(list($id,)=each($heading)){
				tep_content_title_top($id); 
			?>
			
						<?php
				// select event configuration settings
				$key_string=join("','",$heading[$id]);
				$configuration_query = tep_db_query("select configuration_id, configuration_key,configuration_title, configuration_description,configuration_value, set_function,sort_order from " . TABLE_CONFIGURATION . " where configuration_key in ('" . $key_string . "') order by sort_order");
				//echo "select configuration_id, configuration_key,configuration_title, configuration_description,configuration_value, set_function,sort_order from " . TABLE_CONFIGURATION . " where configuration_key in ('" . $key_string . "') order by sort_order";
				while ($configuration = tep_db_fetch_array($configuration_query)) {
					$value_field='';
					// evaluate the configuration function
					if ($configuration['set_function']) {
						 if($configuration['configuration_key']!="PRODUCT_FULFILLER" && $configuration['configuration_key']!="DOWNLOAD_ENABLED" && $configuration['configuration_key']!="DOWNLOAD_BY_REDIRECT" && $configuration['configuration_key']!="GENERAL_CONVERSION" && $configuration['configuration_key']!="SKU_LENGTH"){
						   $conversion_query = tep_db_query("select * from ".TABLE_CONVERSION ." where conversion_key= '" .$configuration['configuration_key'] . "'");
						   $conversion = tep_db_fetch_array($conversion_query);
						   
						  if( $conversion['conversion_value']=="")  $conversion['conversion_value'] =  $configuration['configuration_value']; 
						   eval('$value_field = ' . $configuration['set_function'] . '"' . html_entity_decode($conversion['conversion_value']) . '");');
						   $value_field .= '&nbsp;&nbsp;'.tep_image_submit('button_modify.gif',IMAGE_MODIFY .'&nbsp;'. $configuration['configuration_title'],'align=absmiddle');
						}else{	
						   eval('$value_field = ' . $configuration['set_function'] . '"' . $configuration['configuration_value'] . '");');
						   $value_field .= '&nbsp;&nbsp;'.tep_image_submit('button_modify.gif',IMAGE_MODIFY .'&nbsp;'. $configuration['configuration_title'],'align=absmiddle');
							}
					} else {

						$value_field = tep_draw_input_field('configuration_value', $configuration['configuration_value'],'size=10') . '&nbsp;';
						if($configuration['configuration_key']=='DISPLAY_REVIEW'){
							$value_field= tep_draw_checkbox_field('admin','Y',(substr($configuration['configuration_value'],0,1)=='Y')?true:false).' '. TEXT_ADMIN .' ' . tep_draw_checkbox_field('customer','Y',(substr($configuration['configuration_value'],1,1)=='Y')?true:false).' '.TEXT_CUSTOMER . '&nbsp;&nbsp;';
						}
							
						$value_field .= tep_image_submit('button_modify.gif',IMAGE_MODIFY . $configuration['configuration_title'],'align=absmiddle');
					}
					echo tep_draw_form('configuration_' . $configuration['configuration_id'],FILENAME_PRODUCTS_OPTIONS,'action=set_value');
			?>
			<tr><td><?php echo tep_draw_separator('pixel_trans.gif',1,3); ?></td></tr>
			<tr class='attributes-odd'>
                <td class="main" width="240"><?php echo $configuration['configuration_title']; ?></td>
                <td class="main"  width="330" valign=top>
				<?php 
					echo tep_draw_separator('pixel_trans.gif',20,1) . $value_field; 
					//if ($configuration['configuration_key']=='EVENTS_SMS_KEY')
						//echo '&nbsp;<a href="' . tep_href_link(FILENAME_EVENTS_OPTION,'action=activate') . '">' . tep_image_button('button_activate.gif',IMAGE_ACTIVATE,'align=absmiddle') . '</a>';
				?>
				</td>
				<td class="smallText" valign=top><?php echo $configuration['configuration_description']; ?></td>
				<?php echo "<input type=hidden name='conversion_id' value='" . $conversion['conversion_id'] . "'>";

				echo "<input type=hidden name='configuration_id' value='" . $configuration['configuration_id'] . "'></form>"; }?>
			</tr>
			<tr><td><?php echo tep_draw_separator('pixel_trans.gif',1,5); ?></td></tr>
			
			<?php tep_content_title_bottom();
			}
			?>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
