<?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();                                                                                                   // This will cause it to look for 'mainpage.php'
  $HTTP_GET_VARS['filename'] = 'info_shipping.php';
  $page=(isset($HTTP_POST_VARS['pages'])?$HTTP_POST_VARS['pages']:'');
   if($page=='shipping')
     $HTTP_GET_VARS['filename'] = 'info_shipping.php';
 else if($page=='privacy')
      $HTTP_GET_VARS['filename'] = 'info_privacy.php';	
 else if($page=='conditions')
       $HTTP_GET_VARS['filename'] = 'info_conditions.php';	
  else if($page=='contact')
	    $HTTP_GET_VARS['filename'] = 'info_contact.php'; 
  else if($page=='gv_faq')	
  		 $HTTP_GET_VARS['filename'] = 'info_gv.php'; 	 
  // assign mainpage type value
/*  $products_categories=array();
  $events_categories=array();
  $subscriptions_categories=array();
  $products="-";  $events="-"; $subscriptions="-"; 
  //$services_categories=array();
 $htmlarea=array("id"=>"Default","text"=>TEXT_HTMLAREA);
  if(HIDE_FROM_BACKEND_MENU_PRODUCTS=='false'){
    $products=array("id"=>"Product","text"=>TEXT_PRODUCTS);
    $products_query=tep_db_query("select * from " . TABLE_CATEGORIES_DESCRIPTION . " where language_id='" . $languages_id ."'");
	while($result_products=tep_db_fetch_array($products_query)){
	  $products_categories[]=array('id'=>$result_products['categories_id'],'text'=>$result_products['categories_name']);
   }
  }
  if(HIDE_FROM_BACKEND_MENU_EVENTS=='false') {
    $events=array("id"=>'Event',"text"=>TEXT_EVENTS);
    $events_query=tep_db_query("select * from " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " where language_id='" . $languages_id ."'");
     while($result_events=tep_db_fetch_array($events_query)){
	  $events_categories[]=array('id'=>$result_events['events_categories_id'],'text'=>$result_events['events_categories_name']);
   }
  }
  if(HIDE_FROM_BACKEND_MENU_SUBSCRIPTIONS=='false') {
    $subscriptions=array("id"=>'Subscription',"text"=>TEXT_SUBSCRIPTIONS);
    $subscriptions_query=tep_db_query("select * from " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " where language_id='" . $languages_id ."'");
    while($result_subscriptions=tep_db_fetch_array($subscriptions_query)){
	  $subscriptions_categories[]=array('id'=>$result_subscriptions['subscription_categories_id'],'text'=>$result_subscriptions['subscription_categories_name']);
   }
  }
$mainpage_type=array($htmlarea,$products,$events,$subscriptions);*/
  switch ($HTTP_GET_VARS['action']) {
    case 'save':
        $file_contents = stripslashes($HTTP_POST_VARS['file_contents']);
		$selected_type=((isset($HTTP_POST_VARS['mainpage_type']))?$HTTP_POST_VARS['mainpage_type']:'Default');
		$selected_categories="Default";
	/*	if($selected_type=='Product'){
		    $file_contents="";
			$selected_categories=((isset($HTTP_POST_VARS['mainpage_product_categories']))?$HTTP_POST_VARS['mainpage_product_categories']:'');
		}else if($selected_type=='Event'){
		   $file_contents="";
		   $selected_categories=((isset($HTTP_POST_VARS['mainpage_event_categories']))?$HTTP_POST_VARS['mainpage_event_categories']:'');
		}else if($selected_type=='Subscription'){
		  $file_contents="";
		  $selected_categories=((isset($HTTP_POST_VARS['mainpage_subscription_categories'])) ? $HTTP_POST_VARS['mainpage_subscription_categories']:'');
		}
		   $query_type=tep_db_query("select * from configuration where configuration_key='DEFINEINFOPAGE_TYPE'");
		   $query_categories=tep_db_query("select * from configuration where configuration_key='DEFINEINFOPAGE_CATEGORIES'");
		   if(tep_db_num_rows($query_type)>0){
		     tep_db_query("update configuration set configuration_value='". $selected_type ."' where configuration_key='DEFINEINFOPAGE_TYPE'");
		   }else if(tep_db_num_rows($query_categories)==0){
		     tep_db_query("INSERT INTO configuration VALUES(NULL,'Define Mainpage type','DEFINEINFOPAGE_TYPE','" . $selected_type ."','Display the mainpage','902','15','2006-04-05 20:30:12','0000-00-00 00:00:00',NULL,NULL);"); 
		   }
		   if(tep_db_num_rows($query_type)>0){
		     tep_db_query("update  configuration set configuration_value='" . $selected_categories . "' where configuration_key='DEFINEINFOPAGE_CATEGORIES'");
		   }else if(tep_db_num_rows($query_categories)==0){
		     tep_db_query("INSERT INTO configuration VALUES(NULL,'Define Mainpage categories','DEFINEINFOPAGE_CATEGORIES','" . $selected_categories . "','Display the mainpage','902','15','2006-04-05 20:30:12','0000-00-00 00:00:00',NULL,NULL);"); 
		   }*/
		 if ( ($HTTP_GET_VARS['lngdir']) && ($HTTP_GET_VARS['filename']) ) {
        if ($HTTP_GET_VARS['filename'] == $language . '.php') {
          $file = DIR_FS_CATALOG_LANGUAGES . $HTTP_GET_VARS['filename'];
        } else {
          $file = DIR_FS_CATALOG_LANGUAGES . $HTTP_GET_VARS['lngdir'] . '/' . $HTTP_GET_VARS['filename'];
        }
        if (file_exists($file) ) {
          if (file_exists('bak' . $file)) {
            @unlink('bak' . $file);
          }
          @rename($file, 'bak' . $file);
          $new_file = fopen($file, 'w');
          fwrite($new_file, $file_contents, strlen($file_contents));
          fclose($new_file);
        }
        tep_redirect(tep_href_link(FILENAME_DEFINE_INFORMATION_PAGE, 'lngdir=' . $HTTP_GET_VARS['lngdir']));
      }
      break;
  }
 if (!$HTTP_GET_VARS['lngdir']) $HTTP_GET_VARS['lngdir'] = $language;
  $languages_array = array();
  $languages = tep_get_languages();
  $lng_exists = false;
  for ($i=0; $i<sizeof($languages); $i++) {
    if ($languages[$i]['directory'] == $HTTP_GET_VARS['lngdir']) $lng_exists = true;
    $languages_array[] = array('id' => $languages[$i]['directory'],
                               'text' => $languages[$i]['name']);
  }
  if (!$lng_exists) $HTTP_GET_VARS['lngdir'] = $language;
?>
<!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 type="text/javascript" src="htmlarea/htmlarea.js"></script>
<script type="text/javascript" src="htmlarea/editor.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">

<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); 
 if ( ($HTTP_GET_VARS['lngdir']) && ($HTTP_GET_VARS['filename']) ) {
    if ($HTTP_GET_VARS['filename'] == $language . '.php') {
      $file = DIR_FS_CATALOG_LANGUAGES . $HTTP_GET_VARS['filename'];
    } else {
      $file = DIR_FS_CATALOG_LANGUAGES . $HTTP_GET_VARS['lngdir'] . '/' . $HTTP_GET_VARS['filename'];
    }
    if (file_exists($file)) {
      $file_array = @file($file);
      $file_contents = @implode('', $file_array);

      $file_writeable = true;
      if (!is_writeable($file)) {
        $file_writeable = false;
        $messageStack->reset();
        $messageStack->add(sprintf(ERROR_FILE_NOT_WRITEABLE, $file), 'error');
        $error_msg=$messageStack->output();
      }

?>
<!-- header_eof //-->
<!-- body //-->
<script language="javascript">
	/*function select_type()
	{
	 var mainpage_type=document.language.mainpage_type.value;
	 var frm_product=document.getElementById("products");
	 var frm_event=document.getElementById("events");
	 var frm_subscription=document.getElementById("subscriptions");
	 var frm_cate=document.getElementById("cate");
	 if(("<?php echo DEFINEPAGE_TYPE;?>"!='Default')||(mainpage_type=='Product' || mainpage_type=='Event' || mainpage_type=='Subscription')) frm_cate.style.display="";
		  if(mainpage_type=='Product') {
		   document.getElementById("error_msg").style.display="none";
		   document.getElementById("save_bu").style.display="";
		   //editor._iframe.style.visibility = "hidden";
		   frm_product.style.display="";
		   frm_event.style.display="none";
		   frm_subscription.style.display="none";
		 }else if(mainpage_type=='Event'){	
		   document.getElementById("error_msg").style.display="none";
		   document.getElementById("save_bu").style.display="";
		   frm_event.style.display="";
		   frm_product.style.display="none";
		   frm_subscription.style.display="none";
		 }else if(mainpage_type=='Subscription'){
		   document.getElementById("error_msg").style.display="none";
		   document.getElementById("save_bu").style.display="";
		   frm_subscription.style.display="";
		   frm_event.style.display="none";
		   frm_product.style.display="none";
		 }else  {
		if("<?php echo $file_writeable;?>"==""){
			document.getElementById("save_bu").style.display="none";
			document.getElementById("error_msg").style.display="";
		}else {	
		   editor._iframe.style.visibility = "visible";
		}
		   frm_product.style.display="none";
		   frm_event.style.display="none";
		   frm_subscription.style.display="none";
		   frm_cate.style.display="none";
		 }
	}*/
	function validate_form(){
	var content=document.language.file_contents.value;
	if(document.language.mainpage_type.value=='Default' && content==""){
	   alert("Content Cannot empty");
	   return false;
	 }
	   return true;
	}
function do_submit(fname){
var filename= fname;
document.page.file_h.value=filename;
document.page.submit();
}	
  </script>
<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><?php echo tep_draw_form('lng', FILENAME_DEFINE_INFORMATION_PAGE, '', 'get'); ?>
            <td class="pageHeading"><?php echo BOX_CATALOG_DEFINE_INFORMATION_PAGE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', '1', HEADING_IMAGE_HEIGHT); ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_pull_down_menu('lngdir', $languages_array, '', 'onChange="this.form.submit();"'); ?></td>
		  </form></tr>
        </table></td>
      </tr>
	  <tr><?php echo tep_draw_form('page', FILENAME_DEFINE_INFORMATION_PAGE, '', 'post'); ?>
	     <td class="dataTableContent"><?php
		 		$pages_array = array(array('id'=>'shipping','text'=>'shipping'),
									 array('id'=>'privacy' ,'text'=>'privacy'),
									 array('id'=>'conditions','text'=>'conditions'),
									 array('id'=>'contact','text'=>'contact'));
									// array('id'=>'gv_faq','text'=>'gv_faq')); 
				echo 'Select Page : '.tep_draw_pull_down_menu('pages',$pages_array,'','onchange="Javascript: do_submit(this)"');
		 		echo tep_draw_hidden_field('file_h','');?>
		 </td></form>
		 </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
	<tr id="error_msg"><td><?php echo (($error_msg)?$error_msg:'');?></td></tr>
          <tr><?php echo tep_draw_form('language', FILENAME_DEFINE_INFORMATION_PAGE, 'lngdir=' . $HTTP_GET_VARS['lngdir'] . '&filename=' . $HTTP_GET_VARS['filename'] . '&action=save','post','onsubmit="javascript:return validate_form();"'); ?>
            <td><table border="0" cellspacing="0" cellpadding="2">
			  <tr>
                <td class="main"><b><?php echo $HTTP_GET_VARS['filename']; ?></b></td>
              </tr>
              <tr>
                		<td class="main"><?php echo tep_draw_textarea_field('file_contents', 'soft', '80', '24', $file_contents, 'id="file_contents"'); ?></td>
              </tr>
	    <?php if(!$file_contents){
	    }?>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
				<tr>
					<td class="TableHeading"><?php //echo TEXT_INFORMATION_PAGE_TYPE . '&nbsp;' . tep_draw_pull_down_menu('mainpage_type',$mainpage_type,DEFINEPAGE_TYPE,'onchange="javascript:select_type();"');?></td>
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<tr>
					<td class="TableHeading">
					  <?php echo  '<span id="cate" style="display:'.((DEFINEPAGE_TYPE=='Default') && (DEFINEPAGE_CATEGORIES=='Default')?'none;':"''").'">' . TEXT_MAINPAGE_CATEGORIES .'</span>'. '&nbsp;<span id="products"'.((DEFINEPAGE_TYPE=='Product') && (DEFINEPAGE_CATEGORIES)?'':'style="display:none"').'>' . tep_draw_pull_down_menu('mainpage_product_categories',$products_categories,DEFINEPAGE_CATEGORIES) . '</span><span id="events"'.(((DEFINEPAGE_TYPE=='Event') && (DEFINEPAGE_CATEGORIES))?'':'style="display:none"').'>' .  tep_draw_pull_down_menu('mainpage_event_categories',$events_categories,DEFINEPAGE_CATEGORIES) . '</span><span id="subscriptions"' . (((DEFINEPAGE_TYPE=='Subscription') && (DEFINEPAGE_CATEGORIES))?'':'style="display:none"') .'>' .  tep_draw_pull_down_menu('mainpage_subscription_categories',$subscriptions_categories,DEFINEPAGE_CATEGORIES)  . '</span>';?>
					</td>
				</tr>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td align="right"><div id="save_bu" style="<?php echo (($error_msg)?'display:none;':'display:"";');?>"><?php echo tep_image_submit('button_save.gif', IMAGE_SAVE) . '&nbsp;'?></div></td>
	     <td align="right" valign="top"><?php echo '<a href="' . tep_href_link(FILENAME_DEFINE_INFORMATION_PAGE, 'lngdir=' . $HTTP_GET_VARS['lngdir']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';  ?></td>
              </tr>
            </table></td>
          </form></tr>
<?php
    } else {
?>
          <tr>
            <td class="main"><b><?php echo TEXT_FILE_DOES_NOT_EXIST; ?></b></td>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td><?php echo '<a href="' . tep_href_link(FILENAME_DEFINE_INFORMATION_PAGE, 'lngdir=' . $HTTP_GET_VARS['lngdir']) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
          </tr>
<?php
    }
  } else {
      $filename = $HTTP_GET_VARS['lngdir'] . '.php';
?>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td class="smallText"><a href="<?php echo tep_href_link(FILENAME_DEFINE_INFORMATION_PAGE, 'lngdir=' . $HTTP_GET_VARS['lngdir'] . '&filename=' . $filename); ?>"><b><?php echo $filename; ?></b></a></td>
<?php
    $dir = dir(DIR_FS_CATALOG_LANGUAGES . $HTTP_GET_VARS['lngdir']);
    $left = false;
    if ($dir) {
      $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
      while ($file = $dir->read()) {
        if (substr($file, strrpos($file, '.')) == $file_extension) {
          echo '                <td class="smallText"><a href="' . tep_href_link(FILENAME_DEFINE_INFORMATION_PAGE, 'lngdir=' . $HTTP_GET_VARS['lngdir'] . '&filename=' . $file) . '">' . $file . '</a></td>' . "\n";
          if (!$left) {
            echo '              </tr>' . "\n" .
                 '              <tr>' . "\n";
          }
          $left = !$left;
        }
      }
      $dir->close();
    }
?>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_FILE_MANAGER, 'current_path=' . DIR_FS_CATALOG_LANGUAGES . $HTTP_GET_VARS['lngdir']) . '">' . tep_image_button('button_file_manager.gif', IMAGE_FILE_MANAGER) . '</a>'; ?></td>
          </tr>
<?php
  }
?>
<script>initEditor('file_contents');</script>
        </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'); ?>
