<?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');

  // #CP - local dir to the template directory where you are uploading the company logo
  tep_get_last_access_file();
  $template_query = tep_db_query("select configuration_id, configuration_title, configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'DEFAULT_TEMPLATE'");
  $template = tep_db_fetch_array($template_query);
  $CURR_TEMPLATE = $template['configuration_value'] . '/';
  $server_date = getServerDate(true);	

  $upload_fs_dir = DIR_FS_TEMPLATES.$CURR_TEMPLATE.DIR_WS_IMAGES;
 
  $upload_ws_dir = DIR_WS_TEMPLATES.$CURR_TEMPLATE.DIR_WS_IMAGES;
  // #CP
	$action = (isset($HTTP_GET_VARS['action']) ? tep_db_prepare_input($HTTP_GET_VARS['action']) : '');
	$gID = (isset($HTTP_GET_VARS['gID'])) ? (int)$HTTP_GET_VARS['gID'] : 0;
	$eaction = (isset($HTTP_GET_VARS['eaction']) ? tep_db_prepare_input($HTTP_GET_VARS['eaction']) : '');

	// get gID using the current config menu elements
	if ($gID<=0){
		$config_group_query=tep_db_query("SELECT configuration_group_id from " . TABLE_CONFIGURATION_GROUP . " where lower(configuration_access_key)='" . strtolower($CONFIG_ACCESS_KEY) . "'");
		if (tep_db_num_rows($config_group_query)>0){
			$config_group_result=tep_db_fetch_array($config_group_query);
			$gID=$config_group_result['configuration_group_id'];
		} else {
			$gID=1;
		}
	}
  if(isset($HTTP_GET_VARS["search"])){
   $action = 'search';
    $search = tep_db_prepare_input($HTTP_GET_VARS["search"]);
  	}
	
	if($eaction== 'upload' ) {
		$search = tep_db_prepare_input($HTTP_GET_VARS['search']);
		if($search =="")$action = 'upload';
		}
	/*$configuration_query = tep_db_query("select configuration_group_id from " . TABLE_CONFIGURATION_GROUP . " where configuration_group_title like '%" . $search . "%' or configuration_group_description like '%" . $search . "%'" );
	
	   if(tep_db_num_rows($configuration_query)>0){
	   $configuration_array = tep_db_fetch_array($configuration_query);
	   $gID = $configuration_array["configuration_group_id"];
	   tep_redirect(tep_href_link(FILENAME_CONFIGURATION_NEW,'gID=' . $gID));
	   } */
  /* $configuration_query = tep_db_query("select configuration_id,configuration_group_id from " . TABLE_CONFIGURATION . " where configuration_title like '%" . $search . "%' or configuration_description like '%" . $search . "%'");
   
   		if(tep_db_num_rows($configuration_query)>0){
		  while($configuration_array = tep_db_fetch_array($configuration_query)){
		     //echo '<br>gID' . $configuration_array["configuration_group_id"];
			 //echo 'cID' . $configuration_array["configuration_id"];
			 //$cID = $configuration_array["configuration_id"];
			 //$gID = $configuration_array["configuration_group_id"];
		   }
		}*/
	   
	$configuration_keys = array();
	$configuration_values = array();
	$configuration1_keys = array();
	$configuration1_values = array();
	$configuration_text_keys = array();
	$configuration_text_values = array();
	$file_name_keys = array();
	$file_name_values = array();
	if(isset($GLOBALS['file_name']) && sizeof($GLOBALS['file_name'])){
		$file_name_keys = array_keys($GLOBALS['file_name']);
		$file_name_values = array_values($GLOBALS['file_name']);
	}
	if(isset($HTTP_POST_VARS['configuration_key_text']) && sizeof(tep_db_prepare_input($HTTP_POST_VARS['configuration_key_text']))){
		$configuration_text_keys = array_keys(tep_db_prepare_input($HTTP_POST_VARS['configuration_key_text']));
		$configuration_text_values = array_values(tep_db_prepare_input($HTTP_POST_VARS['configuration_key_text']));
	}
	if(isset($HTTP_POST_VARS['configuration']) && sizeof(tep_db_prepare_input($HTTP_POST_VARS['configuration']))){
		$configuration_keys = array_keys(tep_db_prepare_input($HTTP_POST_VARS['configuration']));
		$configuration_values = array_values(tep_db_prepare_input($HTTP_POST_VARS['configuration']));
	}
	if(isset($HTTP_POST_VARS['configuration1']) && sizeof(tep_db_prepare_input($HTTP_POST_VARS['configuration1']))){
		$configuration1_keys = array_keys(tep_db_prepare_input($HTTP_POST_VARS['configuration1']));
		$configuration1_values = array_values(tep_db_prepare_input($HTTP_POST_VARS['configuration1']));
	}
	print_r(tep_db_prepare_input($HTTP_POST_VARS['configuration_key_text']));
	echo "<br>";
	print_r(tep_db_prepare_input($HTTP_POST_VARS['configuration']));
	echo "<br>";
	print_r($GLOBALS['file_name']);
	echo "<br>";
  if (tep_not_null($action)) {
    switch ($action) {
      case 'save':
		for($i=0;$i<sizeof($configuration_keys);$i++){
			if(sizeof(tep_db_prepare_input($HTTP_POST_VARS['configuration']))>0 && array_key_exists($configuration_text_keys[$i],tep_db_prepare_input($HTTP_POST_VARS['configuration'])))echo "common";
			if(sizeof(tep_db_prepare_input($HTTP_POST_VARS['configuration1']))>0 && array_key_exists($configuration_text_keys[$i],tep_db_prepare_input($HTTP_POST_VARS['configuration1'])))echo "common1";
			echo "<br>";
			if($configuration_keys[$i]==$configuration_text_keys[$i]){
				echo "Configuration<br>";
				echo "SAVE:update " . TABLE_CONFIGURATION . " set configuration_value = '" . $configuration_values[$i] . "', last_modified = '" . $server_date . "' where configuration_id = '" . (int)$configuration_keys[$i] . "'<br>";
			}else if($configuration_keys[$i]==$configuration1_keys[$i]){
				echo "Configuration1<br>";
			}
		}
		exit;
        $configuration_value = tep_db_prepare_input($HTTP_POST_VARS['configuration_value']);
		$configuration_value1 = (isset($HTTP_POST_VARS['configuration_value1'])?tep_db_prepare_input($HTTP_POST_VARS['configuration_value1']):0);
		if($configuration_value1>0)
			$configuration_value=$configuration_value . ',' . $configuration_value1;
        $cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);
		
		
		   tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($configuration_value) . "', last_modified = '" . $server_date . "' where configuration_id = '" . (int)$cID . "'");
		 if($HTTP_POST_VARS['search']!=""){
		    $action = 'search';
			$search = tep_db_prepare_input($HTTP_POST_VARS['search']);
			}else{
        tep_redirect(tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cID));}
        break;
// #CP - supporting functions to upload company logo to template images directory       
      case 'processuploads':
		for($i=0;$i<sizeof($configuration_text_keys);$i++){
			if(sizeof($HTTP_POST_VARS['configuration'])>0 && array_key_exists($configuration_text_keys[$i],tep_db_prepare_input($HTTP_POST_VARS['configuration']))){
				echo "common";
			}
			if(sizeof($HTTP_POST_VARS['configuration1'])>0 && array_key_exists($configuration_text_keys[$i],tep_db_prepare_input($HTTP_POST_VARS['configuration1']))){
				echo "common1";
			}
			if(sizeof($GLOBALS['file_name'])>0 && array_key_exists($configuration_text_keys[$i],$GLOBALS['file_name'])){
				echo "File";
			}
			echo "<br>";
			/*if($configuration_keys[$i]==$configuration_text_keys[$i]){
				echo "Configuration<br>";
				echo "UPLOAD:update " . TABLE_CONFIGURATION . " set configuration_value = '" . $configuration_values[$i] . "', last_modified = '" . $server_date . "' where configuration_id = '" . (int)$configuration_keys[$i] . "'<br>";
			}else if($configuration_text_keys[$i]==$configuration1_keys[$i]){
				echo "Configuration1<br>";
			}else if($configuration_text_keys[$i]==$file_name_keys[$i]){
				echo "Filename<br>";
			}echo "<br>";*/
			//if(is_array($configuration_values[$i]))print_r($configuration_values[$i]);//SHOP_SELL_ITEMS
		}
	  	 exit;
         if (isset($GLOBALS['file_name']) && tep_not_null($GLOBALS['file_name'])){
          $up_load = new upload('file_name', $upload_fs_dir);
          $file_name = $up_load->filename;
			$error=false;          
         if($file_name != "logo.gif"){
			if( file_exists($upload_fs_dir."logo.gif") && !@unlink($upload_fs_dir."logo.gif")){
				tep_session_register("config_error");
				tep_set_session_value("config_error",sprintf(DELETE_ERROR,$upload_fs_dir."logo.gif"));
				$error=true;
			}
			if(!$error && !@rename($upload_fs_dir.$file_name, $upload_fs_dir."logo.gif")){
					tep_session_register("config_error");
					tep_set_session_value("config_error",sprintf(RENAME_ERROR,$upload_fs_dir."logo.gif"));
			}
		  }//$filename
		}//$GLOBALS
			if($HTTP_POST_VARS['search']!=""){
		    $action = 'search';
			$search = tep_db_prepare_input($HTTP_POST_VARS['search']);
			}else{
        tep_redirect(tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID));
		}
        break;
      case 'upload':
        $directory_writeable = true;
        if (!is_writeable($upload_fs_dir)) {
          $directory_writeable = false;
          $messageStack->add(sprintf(ERROR_DIRECTORY_NOT_WRITEABLE, $upload_fs_dir), 'error');
        }
        break;
    }
// #CP     
  }
  $cfg_group_query = tep_db_query("select configuration_group_title from " . TABLE_CONFIGURATION_GROUP . " where configuration_group_id = '" . (int)$gID . "'");
  
  $cfg_group = tep_db_fetch_array($cfg_group_query);
  
// check if the template image directory exists
  if (is_dir($upload_fs_dir)) {
    if (!is_writeable($upload_fs_dir)) $messageStack->add(ERROR_TEMPLATE_IMAGE_DIRECTORY_NOT_WRITEABLE . $upload_fs_dir, 'error');
  } else {
    $messageStack->add(ERROR_TEMPLATE_IMAGE_DIRECTORY_DOES_NOT_EXIST . $upload_fs_dir, 'error');
  }
  
?>
<!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>
<script language="javascript">
	var type = new Array();
	function validate_image(checkType,element){
		var frm=document.file;
		var error ="";
			if(checkType=="logo"){
				var image_types=Array(".png",".jpg",".jpeg",".gif");
				if (frm.element.value!="" && !check_mime_type(frm.element,image_types)){
					error="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
				}
			}
			if(error!=""){
				alert(error);
				return false;
			}
			return true;
	}
		function validateForm(checkType,element){
			var frm=document.configuration;
			var error="";
			if (checkType=="" || element.type!="text") return true;
				tempSplt=checkType.split("~");
				for (icnt=0;icnt<(tempSplt.length);icnt++){
					type=(tempSplt[icnt]);
					switch(type){
						// for numeric
						case 'N':
							//alert(frm.configuration_value.keyCode());
							if (element.value=="" || (element.value==" ")) error="<?php echo addslashes(ERR_VALUE_EMPTY);?>";
							else if (isNaN(configuration_value.value) || configuration_value.value<0)
								error="<?php echo addslashes(ERR_VALUE_POSTIVE_NUMBER);?>";
							break;
						//for percentage	
						case 'P':
							if(element.value=="" || isNaN(element.value) || element.value<0 || element.value>100)
								error="<?php echo addslashes(ERR_PERCENTAGE_VALUE); ?>";
							break;	
						}
					if (error!=""){
						alert(error);
						return false;
					}
				}
			if (error!=""){
				alert(error);
				return false;
			}
			return true;
		}
	</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" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo $cfg_group['configuration_group_title']; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
			    <td class="smalltext" align="right">  
			    <?php
				 echo tep_draw_form('search', FILENAME_CONFIGURATION_NEW, 'action=search', 'get');
			   	 echo TEXT_SEARCH . ' '. tep_draw_input_field('search'); 
				 echo '</form>';
				 ?> 
					 
					
				</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
		<?php if (isset($HTTP_SESSION_VARS["config_error"])){ 
					$error=$HTTP_SESSION_VARS["config_error"];
					unset($HTTP_SESSION_VARS["config_error"]);
		?>
			<tr>
				<td class="errorText">
					<?php echo $error . '<p>';?>
				</td>
				</tr>
			</tr>
		<?php } ?>
		 <tr>
		 	<td></td>
		 </tr>
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CONFIGURATION_TITLE; ?></td>
                <!--<td class="dataTableHeadingContent"><?php //echo TABLE_HEADING_CONFIGURATION_VALUE; ?></td>-->
              </tr>
			  <form name="configuration" action="configuration_new.php" method="post">
<?php  

    if( $action == 'search'  ){
	  $configuration_query = tep_db_query("select configuration_id,configuration_group_id,configuration_title,configuration_value,use_function from " . TABLE_CONFIGURATION . " where configuration_title like '%" . $search . "%' or configuration_description like '%" . $search . "%'");
	}else  	         
      $configuration_query = tep_db_query("select configuration_id, configuration_title, configuration_value, use_function from " . TABLE_CONFIGURATION . " where configuration_group_id = '" . (int)$gID . "' order by sort_order");
	$total_count= tep_db_num_rows($configuration_query);
  
   while ($configuration = tep_db_fetch_array($configuration_query)) {
    if (tep_not_null($configuration['use_function'])) {
      $use_function = $configuration['use_function'];
      if (ereg('->', $use_function)) {
        $class_method = explode('->', $use_function);
        if (!is_object(${$class_method[0]})) {
          include(DIR_WS_CLASSES . $class_method[0] . '.php');
          ${$class_method[0]} = new $class_method[0]();
        }
        $cfgValue = tep_call_function($class_method[1], $configuration['configuration_value'], ${$class_method[0]});
      } else {
        $cfgValue = tep_call_function($use_function, $configuration['configuration_value']);
		
      }
    } else {
      $cfgValue = $configuration['configuration_value'];
    }
   // if ((!isset($HTTP_GET_VARS['cID']) || (isset($HTTP_GET_VARS['cID']) && ($HTTP_GET_VARS['cID'] == $configuration['configuration_id']))) && !isset($cInfo) && (substr($action, 0, 3) != 'new')) {
      $cfg_extra_query = tep_db_query("select configuration_key, configuration_description, date_added, last_modified, use_function, set_function from " . TABLE_CONFIGURATION . " where configuration_id = '" . (int)$configuration['configuration_id'] . "'");
	  $cfg_extra = tep_db_fetch_array($cfg_extra_query);

      $cInfo_array = array_merge($configuration, $cfg_extra);
      $cInfo = new objectInfo($cInfo_array);
//    }
	
	/*if($action == 'search'  ){
   	if ( (isset($cInfo) && is_object($cInfo)) && ($configuration['configuration_id'] == $cInfo->configuration_id) ) {
    	if($cInfo->set_function == 'file_upload'){
      echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cInfo->configuration_id . '&action=upload&search=' . $search) . '\'">' . "\n";
      } else {
      echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cInfo->configuration_id . '&action=edit&search=' . $search) . '\'">' . "\n";
      }
    } else {
      echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $configuration['configuration_id'] . '&search=' . $search ) . '\'">' . "\n";
    }
	//echo "$total_count configurations found for $search"; 
	}
	
	else
	{
    if ( (isset($cInfo) && is_object($cInfo)) && ($configuration['configuration_id'] == $cInfo->configuration_id) ) {
    	if($cInfo->set_function == 'file_upload'){
      echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cInfo->configuration_id . '&action=upload') . '\'">' . "\n";
      } else {
      echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cInfo->configuration_id . '&action=edit') . '\'">' . "\n";
      }
    } else {
      echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $configuration['configuration_id']) . '\'">' . "\n";
    }
}*/
      echo '<tr class="dataTableRow">' . "\n";
?>				
               <!-- <td class="dataTableContent"><?php //echo htmlspecialchars($cfgValue); ?></td> -->
<?php
	echo "<tr><td>" . tep_draw_separator('pixel_trans.gif', '10', '5') . "</td></tr>";
	$heading = array();
	$contents = array();
	$pieces = explode("/", $cInfo->configuration_value);
	if(isset($HTTP_GET_VARS["search"]))
		$action = (isset($eaction) ? $eaction : $action);

	if (isset($cInfo) && is_object($cInfo)) {
		if ($cInfo->set_function == 'file_upload') {
			$action = "upload";
		} else if(isset($HTTP_GET_VARS["search"]) || $search != ""){
			$action = "edit";
		} else {
			$action = "edit";
		}
	}
	switch ($action) {
		case 'edit':
			//$heading[] = array('text' => '<b>' . $cInfo->configuration_title . '</b>');
			if ($cInfo->set_function) {
				eval('$value_field = ' . $cInfo->set_function . '"' . htmlspecialchars($cInfo->configuration_value) . '",' . $cInfo->configuration_id . ');');
			} else {
				$value_field = tep_draw_input_field('configuration[' . $cInfo->configuration_id . ']', $cInfo->configuration_value);
			}
			$pieces = explode("/", $cInfo->configuration_value);
			$permissions = tep_get_file_permissions(fileperms($pieces[5]));		
			$file_writeable = true;
			if (!is_writeable($pieces[5])) {
				$file_writeable = false;
				$messageStack->add(sprintf(ERROR_FILE_NOT_WRITEABLE, $pieces[5]), 'error');
			}
			$config_key=$cInfo->configuration_key;
			if ($config_key=="WALLET_MINIMUM_AMOUNT"){
				$wallet_type_query=tep_db_query("Select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key='WALLET_MINIMUM_TYPE'");
				$wallet_type_result=tep_db_fetch_array($wallet_type_query);
				$minimum_type=$wallet_type_result['configuration_value'];
				if ($minimum_type=="P"){
					$type="P~V`1`" . addslashes(sprintf(ERR_VALUE_BETWEEN,1,100));
				} else {
					$type="N~V`1`" . addslashes(sprintf(ERR_VALUE_GREATER,1));
				}
			} else if ($config_key=="WALLET_FIRST_ORDER_BALANCE"){
				$type="N~V`1`" . addslashes(sprintf(ERR_VALUE_GREATER,1));
			} else {
				$type="";
			}
			echo "<script language='javascript'>\n";
			echo "type['". $cInfo->configuration_id ."']='".$type."';\n";		 	
			echo '</script>';
			//$contents = array('form' => tep_draw_form('configuration' . $cInfo->configuration_id, FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cInfo->configuration_id . '&action=save','post','onSubmit="javascript:return validateForm(\'' . $type .'\')" '));
		    echo '<td class="dataTableContent" width="100%" valign="top">' . "\n";
			//echo tep_draw_form('configuration' . $cInfo->configuration_id, FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cInfo->configuration_id . '&action=save','post','onSubmit="javascript:return validateForm(\'' . $type .'\')" ');
			//$contents[] = array('text' => '<br><b>' . $cInfo->configuration_title . '</b><br>' . $cInfo->configuration_description . tep_draw_separator('pixel_trans.gif', '30', '10') . $value_field);
			echo '<b>' . $cInfo->configuration_title . '</b><br>' . $cInfo->configuration_description . tep_draw_separator('pixel_trans.gif', '30', '10') . $value_field;
			echo tep_draw_hidden_field('configuration_key_text[' . $cInfo->configuration_id . ']',$cInfo->configuration_key);
			if($search !=""){
				//$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&csID=' . $cInfo->configuration_id) . '&search='.$search.'">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
				//echo '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&csID=' . $cInfo->configuration_id) . '&search='.$search.'">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
			}else{
				//$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&csID=' . $cInfo->configuration_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
				//echo '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&csID=' . $cInfo->configuration_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
			}
			//$contents[]=array('text'=> tep_draw_hidden_field('search',$HTTP_GET_VARS["search"]));
			echo tep_draw_hidden_field('search',$HTTP_GET_VARS["search"]);
			//echo "</form>";
			echo '</td>' . "\n";
		break;
		case 'upload':
			//$heading[] = array('text' => '<b>' . $cInfo->configuration_title . '</b>');
			$directory_writeable = true;
			if (!is_writeable($upload_fs_dir)) {
				$directory_writeable = false;
				$messageStack->add(sprintf(ERROR_DIRECTORY_NOT_WRITEABLE, $upload_fs_dir), 'error');
			}
			$config_key=$cInfo->configuration_key;
			if($config_key=="COMPANY_LOGO"){
				$type="logo";
			}  else{
				$type="";
			}   
			echo "<script language='javascript'>\n";
			echo "type['". $cInfo->configuration_id ."']='".$type."';\n";		 	
			echo '</script>';
			//$contents = array('form' => tep_draw_form('file' . $cInfo->configuration_id, FILENAME_CONFIGURATION_NEW, 'action=processuploads&gID='.$gID.'&cID='.$HTTP_GET_VARS['cID'], 'post', 'enctype="multipart/form-data" onSubmit="javascript:return validate_image(\'' . $type .'\')"'));
		    echo '<td class="dataTableContent" width="100%" valign="top">' . "\n";
			//echo tep_draw_form('file' . $cInfo->configuration_id, FILENAME_CONFIGURATION_NEW, 'action=processuploads&gID='.$gID.'&cID='.$HTTP_GET_VARS['cID'], 'post', 'enctype="multipart/form-data" onSubmit="javascript:return validate_image(\'' . $type .'\')"');
			$file_upload = tep_draw_file_field('file_name[' . $cInfo->configuration_id . ']') . '<br>';
			echo tep_draw_hidden_field('configuration_key_text[' . $cInfo->configuration_id . ']',$cInfo->configuration_key);
			//$contents[] = array('text' => '<br>' . $file_upload);
			echo $file_upload;
			if($search !=""){
				//$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&csID=' . $cInfo->configuration_id) . '&search='.$search.'">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
				//echo '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&csID=' . $cInfo->configuration_id) . '&search='.$search.'">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
			}else{
				//$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cInfo->configuration_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
				//echo '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cInfo->configuration_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
			}
			//$contents[]=array('text'=> tep_draw_hidden_field('search',$HTTP_GET_VARS["search"]));
			echo tep_draw_hidden_field('search',tep_db_prepare_input($HTTP_GET_VARS["search"]));
			//echo "</form>";
		    echo '</td>' . "\n";
		break;
	}

  /*if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    echo '            <td width="100%" valign="top">' . "\n";
    $box = new box;
    echo $box->infoBox($heading, $contents);

    echo '            </td>' . "\n";
  }*/
  	echo "</tr>";
	//echo tep_draw_separator('pixel_trans.gif', '10', '20');
	echo "<tr><td style='border-bottom:1px solid #DCDCDC;'>" . tep_draw_separator('pixel_trans.gif', '10', '10') . "</td></tr>";
	echo "<tr><td>" . tep_draw_separator('pixel_trans.gif', '10', '5') . "</td></tr>";
  }
?>	
		  <input type="button" onClick="javascript:return validate_configuration()">
	  </form>
		<tr><td class="smallText" ><?PHP if($HTTP_GET_VARS['search']!="")// echo "$total_count configuration(s) found for '".$search."'";  ?></td>
			<td class="smallText"></td> </tr>
			<tr>
				<td class="smallText" >
					<?PHP 
						if($HTTP_GET_VARS['search']!=""){
							if($total_count>0)  echo "$total_count configuration(s) found for '".$search."'";
							else echo "0 configuration found"; 	
					?>
				</td>
				<td><?php echo '<a href="' . tep_href_link(FILENAME_CONFIGURATION_NEW, 'gID=' . $gID . '&cID=' . $cInfo->configuration_id) . '">' . tep_image_button('button_reset.gif', IMAGE_RESET) . '</a>';} ?></td>
			</tr> </table></td>
			</table></td>
		</tr>
		</tr>
	</table></td>
<!-- body_text_eof //-->
	</tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
<script language="javascript">
	var save = true;
	function validate_configuration(){
		for(i=0;i<document.configuration.elements.length;i++){
			if(document.configuration.elements[i].type.toLowerCase()=="file"){
				document.configuration.action = document.configuration.action + "?mPath=1_15_18&top=1";
				validate_image(type[document.configuration.elements[i].name.toString().substr(9,document.configuration.elements[i].name.length)],document.configuration.elements[i]);
				save = false;
			}else{
				if(document.configuration.elements[i].name.toString().substr(0,13).toLowerCase()=="configuration"){
					var type_key = document.configuration.elements[i].name.toString().substr(14,parseInt(document.configuration.elements[i].name.toString().length)-15);
					if(typeof(type[type_key])!="undefined"){
						//alert(type_key+":"+type[type_key]);
						validateForm(type[type_key],document.configuration.elements[i]);
					}
				}
			}
		}
		if(save){
			document.configuration.action = document.configuration.action + "?mPath=1_15_18&top=1&action=save";
		}else{
			document.configuration.enctype = "multipart/form-data";
			document.configuration.action = document.configuration.action + "?mPath=1_15_18&top=1&action=processuploads";
		}
		//return false;
		document.configuration.submit();
	}
</script>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
