<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/arrays.inc.php");
require_once ("../classes/settings.class.php");

$message	= "";

if (!$objDB) 
{
	$message	= "Unable to Locate Database Server.";
}//end if
else 
{
	$objM		= new settings($objDB);
	$array	= $objM->select();
	$txtFilename='../styles/'.$array['styles'];

	if (isset($_POST['SaveNow']) && $_POST['SaveNow']=='Save') 
	{
		
		    $txtContent = $_POST['txtContent'];
		    $txtFilename = $_POST['txtFilename'];
		
		
		if(@file_exists($txtFilename))
		{
			$handle = @fopen($txtFilename,'w+');
			@fwrite($handle,$txtContent);
			@rewind($handle);		
			@fclose($handle);
		}//end if
		$message	= '<font color="green">Styles updated successfully</font>.';
	}//end if
	else 
	{
		$array	= $objM->select();
		$txtFilename='../styles/'.$array['styles'];	
	}//end else
}//end else

//reading content from files for editing
if(@file_exists($txtFilename))
{
	$handle = @fopen($txtFilename,'r');

	if(@filesize($txtFilename)>0)
	{
		$txtContent = @fread($handle, @filesize($txtFilename));			
	}//end if	
			
	@fclose($handle);
}//enf if

include_once('title.inc.php');
?>
<script language="javascript" type="text/javascript">
function validateStyle()
{
	var frm	= document.frmStyle;
	
	if (frm.txtContent.value == "")
	{
		alert("Please enter content of the style.");
		frm.txtContent.focus();
		return false;
	}//end if
	return true;
}
</script>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="72%" valign="top"><?php include_once('tophtml.php');?>
			<table width="100%"  border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
              
            </table></td>
          </tr>
        </table>
		<form name="frmStyle" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" onSubmit="return validateStyle();">
          <table width="100%"  border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
				<?php if ($objDB) 
					  { 
				?>
					<?php 	if(isset($message) && $message!='')
							{
					?>
                <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="2" class="maintext2 warning"><?php echo $message;?></td>
                  </tr>
					<?php  	}//end if?>
  				<tr align="left">
                  <td width="3%" class="maintext2">&nbsp;</td>
                  <td width="27%" valign="top" class="maintext2">Style Content</td>
                  <td width="70%" valign="top" class="maintext2"><textarea name="txtContent" id="txtContent" cols="100" rows="14" class="textbox_textarea"><?php echo $txtContent;?></textarea>
                  <span class="help"><a title="Edit the CSS style sheet here."><img src="../images/question_mark.jpg" border="0" height="15"></a></span>
                  </td>
  				</tr>
				<?php 			
						}//end first if
				?>
              </table>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
                      <?php if ($objDB) 
					  { 
					?>
                      <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                      <tr>
					  <td width="30%"></td>
                        <td align="left"><table width="8%"  border="0" cellspacing="0" cellpadding="0">
                            <tr>
							
                              <td><input type="submit" class="loginbutton" name="SaveNow" value="Save"><input type="hidden" value="<?php echo $txtFilename;?>" name="txtFilename"></td>
                              </tr>
                        </table></td>
                      </tr>
                    </table>
					<?php 		
						}//end first if
				?></td>
                  </tr>
                </table></td>
            </tr>
          </table></form></td>
        </tr>
    </table>      
    </td>
  </tr>
</table>
